LLVM 17.0.0git
Function.cpp
Go to the documentation of this file.
1//===- Function.cpp - Implement the Global object classes -----------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the Function class for the IR library.
10//
11//===----------------------------------------------------------------------===//
12
13#include "llvm/IR/Function.h"
15#include "llvm/ADT/ArrayRef.h"
16#include "llvm/ADT/DenseSet.h"
17#include "llvm/ADT/STLExtras.h"
21#include "llvm/ADT/StringRef.h"
23#include "llvm/IR/Argument.h"
24#include "llvm/IR/Attributes.h"
25#include "llvm/IR/BasicBlock.h"
26#include "llvm/IR/Constant.h"
27#include "llvm/IR/Constants.h"
29#include "llvm/IR/GlobalValue.h"
31#include "llvm/IR/Instruction.h"
33#include "llvm/IR/Intrinsics.h"
34#include "llvm/IR/IntrinsicsAArch64.h"
35#include "llvm/IR/IntrinsicsAMDGPU.h"
36#include "llvm/IR/IntrinsicsARM.h"
37#include "llvm/IR/IntrinsicsBPF.h"
38#include "llvm/IR/IntrinsicsDirectX.h"
39#include "llvm/IR/IntrinsicsHexagon.h"
40#include "llvm/IR/IntrinsicsMips.h"
41#include "llvm/IR/IntrinsicsNVPTX.h"
42#include "llvm/IR/IntrinsicsPowerPC.h"
43#include "llvm/IR/IntrinsicsR600.h"
44#include "llvm/IR/IntrinsicsRISCV.h"
45#include "llvm/IR/IntrinsicsS390.h"
46#include "llvm/IR/IntrinsicsVE.h"
47#include "llvm/IR/IntrinsicsWebAssembly.h"
48#include "llvm/IR/IntrinsicsX86.h"
49#include "llvm/IR/IntrinsicsXCore.h"
50#include "llvm/IR/LLVMContext.h"
51#include "llvm/IR/MDBuilder.h"
52#include "llvm/IR/Metadata.h"
53#include "llvm/IR/Module.h"
54#include "llvm/IR/Operator.h"
56#include "llvm/IR/Type.h"
57#include "llvm/IR/Use.h"
58#include "llvm/IR/User.h"
59#include "llvm/IR/Value.h"
65#include "llvm/Support/ModRef.h"
66#include <cassert>
67#include <cstddef>
68#include <cstdint>
69#include <cstring>
70#include <string>
71
72using namespace llvm;
74
75// Explicit instantiations of SymbolTableListTraits since some of the methods
76// are not in the public header file...
78
80 "non-global-value-max-name-size", cl::Hidden, cl::init(1024),
81 cl::desc("Maximum size for the name of non-global values."));
82
83//===----------------------------------------------------------------------===//
84// Argument Implementation
85//===----------------------------------------------------------------------===//
86
87Argument::Argument(Type *Ty, const Twine &Name, Function *Par, unsigned ArgNo)
88 : Value(Ty, Value::ArgumentVal), Parent(Par), ArgNo(ArgNo) {
90}
91
92void Argument::setParent(Function *parent) {
93 Parent = parent;
94}
95
96bool Argument::hasNonNullAttr(bool AllowUndefOrPoison) const {
97 if (!getType()->isPointerTy()) return false;
98 if (getParent()->hasParamAttribute(getArgNo(), Attribute::NonNull) &&
99 (AllowUndefOrPoison ||
100 getParent()->hasParamAttribute(getArgNo(), Attribute::NoUndef)))
101 return true;
102 else if (getDereferenceableBytes() > 0 &&
104 getType()->getPointerAddressSpace()))
105 return true;
106 return false;
107}
108
110 if (!getType()->isPointerTy()) return false;
111 return hasAttribute(Attribute::ByVal);
112}
113
115 if (!getType()->isPointerTy())
116 return false;
117 return hasAttribute(Attribute::ByRef);
118}
119
121 return getParent()->hasParamAttribute(getArgNo(), Attribute::SwiftSelf);
122}
123
125 return getParent()->hasParamAttribute(getArgNo(), Attribute::SwiftError);
126}
127
129 if (!getType()->isPointerTy()) return false;
130 return hasAttribute(Attribute::InAlloca);
131}
132
134 if (!getType()->isPointerTy())
135 return false;
136 return hasAttribute(Attribute::Preallocated);
137}
138
140 if (!getType()->isPointerTy()) return false;
142 return Attrs.hasParamAttr(getArgNo(), Attribute::ByVal) ||
143 Attrs.hasParamAttr(getArgNo(), Attribute::InAlloca) ||
144 Attrs.hasParamAttr(getArgNo(), Attribute::Preallocated);
145}
146
148 if (!getType()->isPointerTy())
149 return false;
151 return Attrs.hasParamAttr(getArgNo(), Attribute::ByVal) ||
152 Attrs.hasParamAttr(getArgNo(), Attribute::StructRet) ||
153 Attrs.hasParamAttr(getArgNo(), Attribute::InAlloca) ||
154 Attrs.hasParamAttr(getArgNo(), Attribute::Preallocated) ||
155 Attrs.hasParamAttr(getArgNo(), Attribute::ByRef);
156}
157
158/// For a byval, sret, inalloca, or preallocated parameter, get the in-memory
159/// parameter type.
161 // FIXME: All the type carrying attributes are mutually exclusive, so there
162 // should be a single query to get the stored type that handles any of them.
163 if (Type *ByValTy = ParamAttrs.getByValType())
164 return ByValTy;
165 if (Type *ByRefTy = ParamAttrs.getByRefType())
166 return ByRefTy;
167 if (Type *PreAllocTy = ParamAttrs.getPreallocatedType())
168 return PreAllocTy;
169 if (Type *InAllocaTy = ParamAttrs.getInAllocaType())
170 return InAllocaTy;
171 if (Type *SRetTy = ParamAttrs.getStructRetType())
172 return SRetTy;
173
174 return nullptr;
175}
176
178 AttributeSet ParamAttrs =
180 if (Type *MemTy = getMemoryParamAllocType(ParamAttrs))
181 return DL.getTypeAllocSize(MemTy);
182 return 0;
183}
184
186 AttributeSet ParamAttrs =
188 return getMemoryParamAllocType(ParamAttrs);
189}
190
192 assert(getType()->isPointerTy() && "Only pointers have alignments");
193 return getParent()->getParamAlign(getArgNo());
194}
195
198}
199
201 assert(getType()->isPointerTy() && "Only pointers have byval types");
203}
204
206 assert(getType()->isPointerTy() && "Only pointers have sret types");
208}
209
211 assert(getType()->isPointerTy() && "Only pointers have byref types");
213}
214
216 assert(getType()->isPointerTy() && "Only pointers have inalloca types");
218}
219
221 assert(getType()->isPointerTy() &&
222 "Only pointers have dereferenceable bytes");
224}
225
227 assert(getType()->isPointerTy() &&
228 "Only pointers have dereferenceable bytes");
230}
231
234}
235
237 if (!getType()->isPointerTy()) return false;
238 return hasAttribute(Attribute::Nest);
239}
240
242 if (!getType()->isPointerTy()) return false;
243 return hasAttribute(Attribute::NoAlias);
244}
245
247 if (!getType()->isPointerTy()) return false;
248 return hasAttribute(Attribute::NoCapture);
249}
250
252 if (!getType()->isPointerTy()) return false;
253 return hasAttribute(Attribute::NoFree);
254}
255
257 if (!getType()->isPointerTy()) return false;
258 return hasAttribute(Attribute::StructRet);
259}
260
262 return hasAttribute(Attribute::InReg);
263}
264
266 return hasAttribute(Attribute::Returned);
267}
268
270 return hasAttribute(Attribute::ZExt);
271}
272
274 return hasAttribute(Attribute::SExt);
275}
276
279 return Attrs.hasParamAttr(getArgNo(), Attribute::ReadOnly) ||
280 Attrs.hasParamAttr(getArgNo(), Attribute::ReadNone);
281}
282
285 AL = AL.addParamAttributes(Parent->getContext(), getArgNo(), B);
287}
288
290 getParent()->addParamAttr(getArgNo(), Kind);
291}
292
294 getParent()->addParamAttr(getArgNo(), Attr);
295}
296
299}
300
303 AL = AL.removeParamAttributes(Parent->getContext(), getArgNo(), AM);
305}
306
308 return getParent()->hasParamAttribute(getArgNo(), Kind);
309}
310
312 return getParent()->getParamAttribute(getArgNo(), Kind);
313}
314
315//===----------------------------------------------------------------------===//
316// Helper Methods in Function
317//===----------------------------------------------------------------------===//
318
320 return getType()->getContext();
321}
322
324 unsigned NumInstrs = 0;
325 for (const BasicBlock &BB : BasicBlocks)
326 NumInstrs += std::distance(BB.instructionsWithoutDebug().begin(),
327 BB.instructionsWithoutDebug().end());
328 return NumInstrs;
329}
330
332 const Twine &N, Module &M) {
333 return Create(Ty, Linkage, M.getDataLayout().getProgramAddressSpace(), N, &M);
334}
335
337 LinkageTypes Linkage,
338 unsigned AddrSpace, const Twine &N,
339 Module *M) {
340 auto *F = new Function(Ty, Linkage, AddrSpace, N, M);
341 AttrBuilder B(F->getContext());
342 UWTableKind UWTable = M->getUwtable();
343 if (UWTable != UWTableKind::None)
344 B.addUWTableAttr(UWTable);
345 switch (M->getFramePointer()) {
347 // 0 ("none") is the default.
348 break;
350 B.addAttribute("frame-pointer", "non-leaf");
351 break;
353 B.addAttribute("frame-pointer", "all");
354 break;
355 }
356 if (M->getModuleFlag("function_return_thunk_extern"))
357 B.addAttribute(Attribute::FnRetThunkExtern);
358 F->addFnAttrs(B);
359 return F;
360}
361
364}
365
368}
369
371 Function::iterator FromBeginIt,
372 Function::iterator FromEndIt) {
373#ifdef EXPENSIVE_CHECKS
374 // Check that FromBeginIt is before FromEndIt.
375 auto FromFEnd = FromF->end();
376 for (auto It = FromBeginIt; It != FromEndIt; ++It)
377 assert(It != FromFEnd && "FromBeginIt not before FromEndIt!");
378#endif // EXPENSIVE_CHECKS
379 BasicBlocks.splice(ToIt, FromF->BasicBlocks, FromBeginIt, FromEndIt);
380}
381
383 Function::iterator ToIt) {
384 return BasicBlocks.erase(FromIt, ToIt);
385}
386
387//===----------------------------------------------------------------------===//
388// Function Implementation
389//===----------------------------------------------------------------------===//
390
391static unsigned computeAddrSpace(unsigned AddrSpace, Module *M) {
392 // If AS == -1 and we are passed a valid module pointer we place the function
393 // in the program address space. Otherwise we default to AS0.
394 if (AddrSpace == static_cast<unsigned>(-1))
395 return M ? M->getDataLayout().getProgramAddressSpace() : 0;
396 return AddrSpace;
397}
398
399Function::Function(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace,
400 const Twine &name, Module *ParentModule)
401 : GlobalObject(Ty, Value::FunctionVal,
402 OperandTraits<Function>::op_begin(this), 0, Linkage, name,
403 computeAddrSpace(AddrSpace, ParentModule)),
404 NumArgs(Ty->getNumParams()) {
405 assert(FunctionType::isValidReturnType(getReturnType()) &&
406 "invalid return type");
407 setGlobalObjectSubClassData(0);
408
409 // We only need a symbol table for a function if the context keeps value names
410 if (!getContext().shouldDiscardValueNames())
411 SymTab = std::make_unique<ValueSymbolTable>(NonGlobalValueMaxNameSize);
412
413 // If the function has arguments, mark them as lazily built.
414 if (Ty->getNumParams())
415 setValueSubclassData(1); // Set the "has lazy arguments" bit.
416
417 if (ParentModule)
418 ParentModule->getFunctionList().push_back(this);
419
420 HasLLVMReservedName = getName().startswith("llvm.");
421 // Ensure intrinsics have the right parameter attributes.
422 // Note, the IntID field will have been set in Value::setName if this function
423 // name is a valid intrinsic ID.
424 if (IntID)
425 setAttributes(Intrinsic::getAttributes(getContext(), IntID));
426}
427
429 dropAllReferences(); // After this it is safe to delete instructions.
430
431 // Delete all of the method arguments and unlink from symbol table...
432 if (Arguments)
433 clearArguments();
434
435 // Remove the function from the on-the-side GC table.
436 clearGC();
437}
438
439void Function::BuildLazyArguments() const {
440 // Create the arguments vector, all arguments start out unnamed.
441 auto *FT = getFunctionType();
442 if (NumArgs > 0) {
443 Arguments = std::allocator<Argument>().allocate(NumArgs);
444 for (unsigned i = 0, e = NumArgs; i != e; ++i) {
445 Type *ArgTy = FT->getParamType(i);
446 assert(!ArgTy->isVoidTy() && "Cannot have void typed arguments!");
447 new (Arguments + i) Argument(ArgTy, "", const_cast<Function *>(this), i);
448 }
449 }
450
451 // Clear the lazy arguments bit.
452 unsigned SDC = getSubclassDataFromValue();
453 SDC &= ~(1 << 0);
454 const_cast<Function*>(this)->setValueSubclassData(SDC);
456}
457
459 return MutableArrayRef<Argument>(Args, Count);
460}
461
463 switch (getIntrinsicID()) {
464#define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC) \
465 case Intrinsic::INTRINSIC:
466#include "llvm/IR/ConstrainedOps.def"
467 return true;
468#undef INSTRUCTION
469 default:
470 return false;
471 }
472}
473
474void Function::clearArguments() {
475 for (Argument &A : makeArgArray(Arguments, NumArgs)) {
476 A.setName("");
477 A.~Argument();
478 }
479 std::allocator<Argument>().deallocate(Arguments, NumArgs);
480 Arguments = nullptr;
481}
482
484 assert(isDeclaration() && "Expected no references to current arguments");
485
486 // Drop the current arguments, if any, and set the lazy argument bit.
487 if (!hasLazyArguments()) {
488 assert(llvm::all_of(makeArgArray(Arguments, NumArgs),
489 [](const Argument &A) { return A.use_empty(); }) &&
490 "Expected arguments to be unused in declaration");
491 clearArguments();
492 setValueSubclassData(getSubclassDataFromValue() | (1 << 0));
493 }
494
495 // Nothing to steal if Src has lazy arguments.
496 if (Src.hasLazyArguments())
497 return;
498
499 // Steal arguments from Src, and fix the lazy argument bits.
500 assert(arg_size() == Src.arg_size());
501 Arguments = Src.Arguments;
502 Src.Arguments = nullptr;
503 for (Argument &A : makeArgArray(Arguments, NumArgs)) {
504 // FIXME: This does the work of transferNodesFromList inefficiently.
506 if (A.hasName())
507 Name = A.getName();
508 if (!Name.empty())
509 A.setName("");
510 A.setParent(this);
511 if (!Name.empty())
512 A.setName(Name);
513 }
514
515 setValueSubclassData(getSubclassDataFromValue() & ~(1 << 0));
517 Src.setValueSubclassData(Src.getSubclassDataFromValue() | (1 << 0));
518}
519
520// dropAllReferences() - This function causes all the subinstructions to "let
521// go" of all references that they are maintaining. This allows one to
522// 'delete' a whole class at a time, even though there may be circular
523// references... first all references are dropped, and all use counts go to
524// zero. Then everything is deleted for real. Note that no operations are
525// valid on an object that has "dropped all references", except operator
526// delete.
527//
529 setIsMaterializable(false);
530
531 for (BasicBlock &BB : *this)
533
534 // Delete all basic blocks. They are now unused, except possibly by
535 // blockaddresses, but BasicBlock's destructor takes care of those.
536 while (!BasicBlocks.empty())
537 BasicBlocks.begin()->eraseFromParent();
538
539 // Drop uses of any optional data (real or placeholder).
540 if (getNumOperands()) {
543 setValueSubclassData(getSubclassDataFromValue() & ~0xe);
544 }
545
546 // Metadata is stored in a side-table.
548}
549
551 AttributeSets = AttributeSets.addAttributeAtIndex(getContext(), i, Attr);
552}
553
555 AttributeSets = AttributeSets.addFnAttribute(getContext(), Kind);
556}
557
559 AttributeSets = AttributeSets.addFnAttribute(getContext(), Kind, Val);
560}
561
563 AttributeSets = AttributeSets.addFnAttribute(getContext(), Attr);
564}
565
567 AttributeSets = AttributeSets.addFnAttributes(getContext(), Attrs);
568}
569
571 AttributeSets = AttributeSets.addRetAttribute(getContext(), Kind);
572}
573
575 AttributeSets = AttributeSets.addRetAttribute(getContext(), Attr);
576}
577
579 AttributeSets = AttributeSets.addRetAttributes(getContext(), Attrs);
580}
581
582void Function::addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) {
583 AttributeSets = AttributeSets.addParamAttribute(getContext(), ArgNo, Kind);
584}
585
586void Function::addParamAttr(unsigned ArgNo, Attribute Attr) {
587 AttributeSets = AttributeSets.addParamAttribute(getContext(), ArgNo, Attr);
588}
589
590void Function::addParamAttrs(unsigned ArgNo, const AttrBuilder &Attrs) {
591 AttributeSets = AttributeSets.addParamAttributes(getContext(), ArgNo, Attrs);
592}
593
595 AttributeSets = AttributeSets.removeAttributeAtIndex(getContext(), i, Kind);
596}
597
599 AttributeSets = AttributeSets.removeAttributeAtIndex(getContext(), i, Kind);
600}
601
603 AttributeSets = AttributeSets.removeFnAttribute(getContext(), Kind);
604}
605
607 AttributeSets = AttributeSets.removeFnAttribute(getContext(), Kind);
608}
609
611 AttributeSets = AttributeSets.removeFnAttributes(getContext(), AM);
612}
613
615 AttributeSets = AttributeSets.removeRetAttribute(getContext(), Kind);
616}
617
619 AttributeSets = AttributeSets.removeRetAttribute(getContext(), Kind);
620}
621
623 AttributeSets = AttributeSets.removeRetAttributes(getContext(), Attrs);
624}
625
627 AttributeSets = AttributeSets.removeParamAttribute(getContext(), ArgNo, Kind);
628}
629
630void Function::removeParamAttr(unsigned ArgNo, StringRef Kind) {
631 AttributeSets = AttributeSets.removeParamAttribute(getContext(), ArgNo, Kind);
632}
633
634void Function::removeParamAttrs(unsigned ArgNo, const AttributeMask &Attrs) {
635 AttributeSets =
636 AttributeSets.removeParamAttributes(getContext(), ArgNo, Attrs);
637}
638
640 AttributeSets =
641 AttributeSets.addDereferenceableParamAttr(getContext(), ArgNo, Bytes);
642}
643
645 return AttributeSets.hasFnAttr(Kind);
646}
647
649 return AttributeSets.hasFnAttr(Kind);
650}
651
653 return AttributeSets.hasRetAttr(Kind);
654}
655
656bool Function::hasParamAttribute(unsigned ArgNo,
657 Attribute::AttrKind Kind) const {
658 return AttributeSets.hasParamAttr(ArgNo, Kind);
659}
660
662 Attribute::AttrKind Kind) const {
663 return AttributeSets.getAttributeAtIndex(i, Kind);
664}
665
667 return AttributeSets.getAttributeAtIndex(i, Kind);
668}
669
671 return AttributeSets.getFnAttr(Kind);
672}
673
675 return AttributeSets.getFnAttr(Kind);
676}
677
679 uint64_t Default) const {
681 uint64_t Result = Default;
682 if (A.isStringAttribute()) {
683 StringRef Str = A.getValueAsString();
684 if (Str.getAsInteger(0, Result))
685 getContext().emitError("cannot parse integer attribute " + Name);
686 }
687
688 return Result;
689}
690
691/// gets the specified attribute from the list of attributes.
693 Attribute::AttrKind Kind) const {
694 return AttributeSets.getParamAttr(ArgNo, Kind);
695}
696
698 uint64_t Bytes) {
699 AttributeSets = AttributeSets.addDereferenceableOrNullParamAttr(getContext(),
700 ArgNo, Bytes);
701}
702
704 if (&FPType == &APFloat::IEEEsingle()) {
706 // If the f32 variant of the attribute isn't specified, try to use the
707 // generic one.
708 if (Mode.isValid())
709 return Mode;
710 }
711
712 return getDenormalModeRaw();
713}
714
716 Attribute Attr = getFnAttribute("denormal-fp-math");
717 StringRef Val = Attr.getValueAsString();
718 return parseDenormalFPAttribute(Val);
719}
720
722 Attribute Attr = getFnAttribute("denormal-fp-math-f32");
723 if (Attr.isValid()) {
724 StringRef Val = Attr.getValueAsString();
725 return parseDenormalFPAttribute(Val);
726 }
727
729}
730
731const std::string &Function::getGC() const {
732 assert(hasGC() && "Function has no collector");
733 return getContext().getGC(*this);
734}
735
736void Function::setGC(std::string Str) {
737 setValueSubclassDataBit(14, !Str.empty());
738 getContext().setGC(*this, std::move(Str));
739}
740
742 if (!hasGC())
743 return;
744 getContext().deleteGC(*this);
745 setValueSubclassDataBit(14, false);
746}
747
749 return hasFnAttribute(Attribute::StackProtect) ||
750 hasFnAttribute(Attribute::StackProtectStrong) ||
751 hasFnAttribute(Attribute::StackProtectReq);
752}
753
754/// Copy all additional attributes (those not needed to create a Function) from
755/// the Function Src to this one.
758 setCallingConv(Src->getCallingConv());
759 setAttributes(Src->getAttributes());
760 if (Src->hasGC())
761 setGC(Src->getGC());
762 else
763 clearGC();
764 if (Src->hasPersonalityFn())
765 setPersonalityFn(Src->getPersonalityFn());
766 if (Src->hasPrefixData())
767 setPrefixData(Src->getPrefixData());
768 if (Src->hasPrologueData())
769 setPrologueData(Src->getPrologueData());
770}
771
774}
777}
778
779/// Determine if the function does not access memory.
782}
785}
786
787/// Determine if the function does not access or only reads memory.
790}
793}
794
795/// Determine if the function does not access or only writes memory.
798}
801}
802
803/// Determine if the call can access memmory only using pointers based
804/// on its arguments.
807}
810}
811
812/// Determine if the function may only access memory that is
813/// inaccessible from the IR.
816}
819}
820
821/// Determine if the function may only access memory that is
822/// either inaccessible from the IR or pointed to by its arguments.
825}
829}
830
831/// Table of string intrinsic names indexed by enum value.
832static const char * const IntrinsicNameTable[] = {
833 "not_intrinsic",
834#define GET_INTRINSIC_NAME_TABLE
835#include "llvm/IR/IntrinsicImpl.inc"
836#undef GET_INTRINSIC_NAME_TABLE
837};
838
839/// Table of per-target intrinsic name tables.
840#define GET_INTRINSIC_TARGET_DATA
841#include "llvm/IR/IntrinsicImpl.inc"
842#undef GET_INTRINSIC_TARGET_DATA
843
845 return IID > TargetInfos[0].Count;
846}
847
849 return isTargetIntrinsic(IntID);
850}
851
852/// Find the segment of \c IntrinsicNameTable for intrinsics with the same
853/// target as \c Name, or the generic table if \c Name is not target specific.
854///
855/// Returns the relevant slice of \c IntrinsicNameTable
857 assert(Name.startswith("llvm."));
858
860 // Drop "llvm." and take the first dotted component. That will be the target
861 // if this is target specific.
862 StringRef Target = Name.drop_front(5).split('.').first;
863 auto It = partition_point(
864 Targets, [=](const IntrinsicTargetInfo &TI) { return TI.Name < Target; });
865 // We've either found the target or just fall back to the generic set, which
866 // is always first.
867 const auto &TI = It != Targets.end() && It->Name == Target ? *It : Targets[0];
868 return ArrayRef(&IntrinsicNameTable[1] + TI.Offset, TI.Count);
869}
870
871/// This does the actual lookup of an intrinsic ID which
872/// matches the given function name.
876 if (Idx == -1)
878
879 // Intrinsic IDs correspond to the location in IntrinsicNameTable, but we have
880 // an index into a sub-table.
881 int Adjust = NameTable.data() - IntrinsicNameTable;
882 Intrinsic::ID ID = static_cast<Intrinsic::ID>(Idx + Adjust);
883
884 // If the intrinsic is not overloaded, require an exact match. If it is
885 // overloaded, require either exact or prefix match.
886 const auto MatchSize = strlen(NameTable[Idx]);
887 assert(Name.size() >= MatchSize && "Expected either exact or prefix match");
888 bool IsExactMatch = Name.size() == MatchSize;
889 return IsExactMatch || Intrinsic::isOverloaded(ID) ? ID
891}
892
895 if (!Name.startswith("llvm.")) {
896 HasLLVMReservedName = false;
898 return;
899 }
900 HasLLVMReservedName = true;
902}
903
904/// Returns a stable mangling for the type specified for use in the name
905/// mangling scheme used by 'any' types in intrinsic signatures. The mangling
906/// of named types is simply their name. Manglings for unnamed types consist
907/// of a prefix ('p' for pointers, 'a' for arrays, 'f_' for functions)
908/// combined with the mangling of their component types. A vararg function
909/// type will have a suffix of 'vararg'. Since function types can contain
910/// other function types, we close a function type mangling with suffix 'f'
911/// which can't be confused with it's prefix. This ensures we don't have
912/// collisions between two unrelated function types. Otherwise, you might
913/// parse ffXX as f(fXX) or f(fX)X. (X is a placeholder for any other type.)
914/// The HasUnnamedType boolean is set if an unnamed type was encountered,
915/// indicating that extra care must be taken to ensure a unique name.
916static std::string getMangledTypeStr(Type *Ty, bool &HasUnnamedType) {
917 std::string Result;
918 if (PointerType *PTyp = dyn_cast<PointerType>(Ty)) {
919 Result += "p" + utostr(PTyp->getAddressSpace());
920 // Opaque pointer doesn't have pointee type information, so we just mangle
921 // address space for opaque pointer.
922 if (!PTyp->isOpaque())
923 Result += getMangledTypeStr(PTyp->getNonOpaquePointerElementType(),
924 HasUnnamedType);
925 } else if (ArrayType *ATyp = dyn_cast<ArrayType>(Ty)) {
926 Result += "a" + utostr(ATyp->getNumElements()) +
927 getMangledTypeStr(ATyp->getElementType(), HasUnnamedType);
928 } else if (StructType *STyp = dyn_cast<StructType>(Ty)) {
929 if (!STyp->isLiteral()) {
930 Result += "s_";
931 if (STyp->hasName())
932 Result += STyp->getName();
933 else
934 HasUnnamedType = true;
935 } else {
936 Result += "sl_";
937 for (auto *Elem : STyp->elements())
938 Result += getMangledTypeStr(Elem, HasUnnamedType);
939 }
940 // Ensure nested structs are distinguishable.
941 Result += "s";
942 } else if (FunctionType *FT = dyn_cast<FunctionType>(Ty)) {
943 Result += "f_" + getMangledTypeStr(FT->getReturnType(), HasUnnamedType);
944 for (size_t i = 0; i < FT->getNumParams(); i++)
945 Result += getMangledTypeStr(FT->getParamType(i), HasUnnamedType);
946 if (FT->isVarArg())
947 Result += "vararg";
948 // Ensure nested function types are distinguishable.
949 Result += "f";
950 } else if (VectorType *VTy = dyn_cast<VectorType>(Ty)) {
951 ElementCount EC = VTy->getElementCount();
952 if (EC.isScalable())
953 Result += "nx";
954 Result += "v" + utostr(EC.getKnownMinValue()) +
955 getMangledTypeStr(VTy->getElementType(), HasUnnamedType);
956 } else if (TargetExtType *TETy = dyn_cast<TargetExtType>(Ty)) {
957 Result += "t";
958 Result += TETy->getName();
959 for (Type *ParamTy : TETy->type_params())
960 Result += "_" + getMangledTypeStr(ParamTy, HasUnnamedType);
961 for (unsigned IntParam : TETy->int_params())
962 Result += "_" + utostr(IntParam);
963 // Ensure nested target extension types are distinguishable.
964 Result += "t";
965 } else if (Ty) {
966 switch (Ty->getTypeID()) {
967 default: llvm_unreachable("Unhandled type");
968 case Type::VoidTyID: Result += "isVoid"; break;
969 case Type::MetadataTyID: Result += "Metadata"; break;
970 case Type::HalfTyID: Result += "f16"; break;
971 case Type::BFloatTyID: Result += "bf16"; break;
972 case Type::FloatTyID: Result += "f32"; break;
973 case Type::DoubleTyID: Result += "f64"; break;
974 case Type::X86_FP80TyID: Result += "f80"; break;
975 case Type::FP128TyID: Result += "f128"; break;
976 case Type::PPC_FP128TyID: Result += "ppcf128"; break;
977 case Type::X86_MMXTyID: Result += "x86mmx"; break;
978 case Type::X86_AMXTyID: Result += "x86amx"; break;
980 Result += "i" + utostr(cast<IntegerType>(Ty)->getBitWidth());
981 break;
982 }
983 }
984 return Result;
985}
986
988 assert(id < num_intrinsics && "Invalid intrinsic ID!");
989 return IntrinsicNameTable[id];
990}
991
993 assert(id < num_intrinsics && "Invalid intrinsic ID!");
995 "This version of getName does not support overloading");
996 return getBaseName(id);
997}
998
1000 Module *M, FunctionType *FT,
1001 bool EarlyModuleCheck) {
1002
1003 assert(Id < Intrinsic::num_intrinsics && "Invalid intrinsic ID!");
1004 assert((Tys.empty() || Intrinsic::isOverloaded(Id)) &&
1005 "This version of getName is for overloaded intrinsics only");
1006 (void)EarlyModuleCheck;
1007 assert((!EarlyModuleCheck || M ||
1008 !any_of(Tys, [](Type *T) { return isa<PointerType>(T); })) &&
1009 "Intrinsic overloading on pointer types need to provide a Module");
1010 bool HasUnnamedType = false;
1011 std::string Result(Intrinsic::getBaseName(Id));
1012 for (Type *Ty : Tys)
1013 Result += "." + getMangledTypeStr(Ty, HasUnnamedType);
1014 if (HasUnnamedType) {
1015 assert(M && "unnamed types need a module");
1016 if (!FT)
1017 FT = Intrinsic::getType(M->getContext(), Id, Tys);
1018 else
1019 assert((FT == Intrinsic::getType(M->getContext(), Id, Tys)) &&
1020 "Provided FunctionType must match arguments");
1021 return M->getUniqueIntrinsicName(Result, Id, FT);
1022 }
1023 return Result;
1024}
1025
1027 FunctionType *FT) {
1028 assert(M && "We need to have a Module");
1029 return getIntrinsicNameImpl(Id, Tys, M, FT, true);
1030}
1031
1033 return getIntrinsicNameImpl(Id, Tys, nullptr, nullptr, false);
1034}
1035
1036/// IIT_Info - These are enumerators that describe the entries returned by the
1037/// getIntrinsicInfoTableEntries function.
1038///
1039/// Defined in Intrinsics.td.
1041#define GET_INTRINSIC_IITINFO
1042#include "llvm/IR/IntrinsicImpl.inc"
1043#undef GET_INTRINSIC_IITINFO
1044};
1045
1046static void DecodeIITType(unsigned &NextElt, ArrayRef<unsigned char> Infos,
1047 IIT_Info LastInfo,
1049 using namespace Intrinsic;
1050
1051 bool IsScalableVector = (LastInfo == IIT_SCALABLE_VEC);
1052
1053 IIT_Info Info = IIT_Info(Infos[NextElt++]);
1054 unsigned StructElts = 2;
1055
1056 switch (Info) {
1057 case IIT_Done:
1058 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Void, 0));
1059 return;
1060 case IIT_VARARG:
1061 OutputTable.push_back(IITDescriptor::get(IITDescriptor::VarArg, 0));
1062 return;
1063 case IIT_MMX:
1064 OutputTable.push_back(IITDescriptor::get(IITDescriptor::MMX, 0));
1065 return;
1066 case IIT_AMX:
1067 OutputTable.push_back(IITDescriptor::get(IITDescriptor::AMX, 0));
1068 return;
1069 case IIT_TOKEN:
1070 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Token, 0));
1071 return;
1072 case IIT_METADATA:
1073 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Metadata, 0));
1074 return;
1075 case IIT_F16:
1076 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Half, 0));
1077 return;
1078 case IIT_BF16:
1079 OutputTable.push_back(IITDescriptor::get(IITDescriptor::BFloat, 0));
1080 return;
1081 case IIT_F32:
1082 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Float, 0));
1083 return;
1084 case IIT_F64:
1085 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Double, 0));
1086 return;
1087 case IIT_F128:
1088 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Quad, 0));
1089 return;
1090 case IIT_PPCF128:
1091 OutputTable.push_back(IITDescriptor::get(IITDescriptor::PPCQuad, 0));
1092 return;
1093 case IIT_I1:
1094 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 1));
1095 return;
1096 case IIT_I2:
1097 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 2));
1098 return;
1099 case IIT_I4:
1100 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 4));
1101 return;
1102 case IIT_AARCH64_SVCOUNT:
1103 OutputTable.push_back(IITDescriptor::get(IITDescriptor::AArch64Svcount, 0));
1104 return;
1105 case IIT_I8:
1106 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 8));
1107 return;
1108 case IIT_I16:
1109 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer,16));
1110 return;
1111 case IIT_I32:
1112 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 32));
1113 return;
1114 case IIT_I64:
1115 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 64));
1116 return;
1117 case IIT_I128:
1118 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 128));
1119 return;
1120 case IIT_V1:
1121 OutputTable.push_back(IITDescriptor::getVector(1, IsScalableVector));
1122 DecodeIITType(NextElt, Infos, Info, OutputTable);
1123 return;
1124 case IIT_V2:
1125 OutputTable.push_back(IITDescriptor::getVector(2, IsScalableVector));
1126 DecodeIITType(NextElt, Infos, Info, OutputTable);
1127 return;
1128 case IIT_V3:
1129 OutputTable.push_back(IITDescriptor::getVector(3, IsScalableVector));
1130 DecodeIITType(NextElt, Infos, Info, OutputTable);
1131 return;
1132 case IIT_V4:
1133 OutputTable.push_back(IITDescriptor::getVector(4, IsScalableVector));
1134 DecodeIITType(NextElt, Infos, Info, OutputTable);
1135 return;
1136 case IIT_V8:
1137 OutputTable.push_back(IITDescriptor::getVector(8, IsScalableVector));
1138 DecodeIITType(NextElt, Infos, Info, OutputTable);
1139 return;
1140 case IIT_V16:
1141 OutputTable.push_back(IITDescriptor::getVector(16, IsScalableVector));
1142 DecodeIITType(NextElt, Infos, Info, OutputTable);
1143 return;
1144 case IIT_V32:
1145 OutputTable.push_back(IITDescriptor::getVector(32, IsScalableVector));
1146 DecodeIITType(NextElt, Infos, Info, OutputTable);
1147 return;
1148 case IIT_V64:
1149 OutputTable.push_back(IITDescriptor::getVector(64, IsScalableVector));
1150 DecodeIITType(NextElt, Infos, Info, OutputTable);
1151 return;
1152 case IIT_V128:
1153 OutputTable.push_back(IITDescriptor::getVector(128, IsScalableVector));
1154 DecodeIITType(NextElt, Infos, Info, OutputTable);
1155 return;
1156 case IIT_V256:
1157 OutputTable.push_back(IITDescriptor::getVector(256, IsScalableVector));
1158 DecodeIITType(NextElt, Infos, Info, OutputTable);
1159 return;
1160 case IIT_V512:
1161 OutputTable.push_back(IITDescriptor::getVector(512, IsScalableVector));
1162 DecodeIITType(NextElt, Infos, Info, OutputTable);
1163 return;
1164 case IIT_V1024:
1165 OutputTable.push_back(IITDescriptor::getVector(1024, IsScalableVector));
1166 DecodeIITType(NextElt, Infos, Info, OutputTable);
1167 return;
1168 case IIT_EXTERNREF:
1169 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Pointer, 10));
1170 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Struct, 0));
1171 return;
1172 case IIT_FUNCREF:
1173 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Pointer, 20));
1174 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 8));
1175 return;
1176 case IIT_PTR:
1177 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Pointer, 0));
1178 DecodeIITType(NextElt, Infos, Info, OutputTable);
1179 return;
1180 case IIT_ANYPTR: { // [ANYPTR addrspace, subtype]
1181 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Pointer,
1182 Infos[NextElt++]));
1183 DecodeIITType(NextElt, Infos, Info, OutputTable);
1184 return;
1185 }
1186 case IIT_ARG: {
1187 unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
1188 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Argument, ArgInfo));
1189 return;
1190 }
1191 case IIT_EXTEND_ARG: {
1192 unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
1193 OutputTable.push_back(IITDescriptor::get(IITDescriptor::ExtendArgument,
1194 ArgInfo));
1195 return;
1196 }
1197 case IIT_TRUNC_ARG: {
1198 unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
1199 OutputTable.push_back(IITDescriptor::get(IITDescriptor::TruncArgument,
1200 ArgInfo));
1201 return;
1202 }
1203 case IIT_HALF_VEC_ARG: {
1204 unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
1205 OutputTable.push_back(IITDescriptor::get(IITDescriptor::HalfVecArgument,
1206 ArgInfo));
1207 return;
1208 }
1209 case IIT_SAME_VEC_WIDTH_ARG: {
1210 unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
1211 OutputTable.push_back(IITDescriptor::get(IITDescriptor::SameVecWidthArgument,
1212 ArgInfo));
1213 return;
1214 }
1215 case IIT_PTR_TO_ARG: {
1216 unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
1217 OutputTable.push_back(IITDescriptor::get(IITDescriptor::PtrToArgument,
1218 ArgInfo));
1219 return;
1220 }
1221 case IIT_PTR_TO_ELT: {
1222 unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
1223 OutputTable.push_back(IITDescriptor::get(IITDescriptor::PtrToElt, ArgInfo));
1224 return;
1225 }
1226 case IIT_ANYPTR_TO_ELT: {
1227 unsigned short ArgNo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
1228 unsigned short RefNo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
1229 OutputTable.push_back(
1230 IITDescriptor::get(IITDescriptor::AnyPtrToElt, ArgNo, RefNo));
1231 return;
1232 }
1233 case IIT_VEC_OF_ANYPTRS_TO_ELT: {
1234 unsigned short ArgNo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
1235 unsigned short RefNo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
1236 OutputTable.push_back(
1237 IITDescriptor::get(IITDescriptor::VecOfAnyPtrsToElt, ArgNo, RefNo));
1238 return;
1239 }
1240 case IIT_EMPTYSTRUCT:
1241 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Struct, 0));
1242 return;
1243 case IIT_STRUCT9: ++StructElts; [[fallthrough]];
1244 case IIT_STRUCT8: ++StructElts; [[fallthrough]];
1245 case IIT_STRUCT7: ++StructElts; [[fallthrough]];
1246 case IIT_STRUCT6: ++StructElts; [[fallthrough]];
1247 case IIT_STRUCT5: ++StructElts; [[fallthrough]];
1248 case IIT_STRUCT4: ++StructElts; [[fallthrough]];
1249 case IIT_STRUCT3: ++StructElts; [[fallthrough]];
1250 case IIT_STRUCT2: {
1251 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Struct,StructElts));
1252
1253 for (unsigned i = 0; i != StructElts; ++i)
1254 DecodeIITType(NextElt, Infos, Info, OutputTable);
1255 return;
1256 }
1257 case IIT_SUBDIVIDE2_ARG: {
1258 unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
1259 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Subdivide2Argument,
1260 ArgInfo));
1261 return;
1262 }
1263 case IIT_SUBDIVIDE4_ARG: {
1264 unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
1265 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Subdivide4Argument,
1266 ArgInfo));
1267 return;
1268 }
1269 case IIT_VEC_ELEMENT: {
1270 unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
1271 OutputTable.push_back(IITDescriptor::get(IITDescriptor::VecElementArgument,
1272 ArgInfo));
1273 return;
1274 }
1275 case IIT_SCALABLE_VEC: {
1276 DecodeIITType(NextElt, Infos, Info, OutputTable);
1277 return;
1278 }
1279 case IIT_VEC_OF_BITCASTS_TO_INT: {
1280 unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
1281 OutputTable.push_back(IITDescriptor::get(IITDescriptor::VecOfBitcastsToInt,
1282 ArgInfo));
1283 return;
1284 }
1285 }
1286 llvm_unreachable("unhandled");
1287}
1288
1289#define GET_INTRINSIC_GENERATOR_GLOBAL
1290#include "llvm/IR/IntrinsicImpl.inc"
1291#undef GET_INTRINSIC_GENERATOR_GLOBAL
1292
1295 // Check to see if the intrinsic's type was expressible by the table.
1296 unsigned TableVal = IIT_Table[id-1];
1297
1298 // Decode the TableVal into an array of IITValues.
1300 ArrayRef<unsigned char> IITEntries;
1301 unsigned NextElt = 0;
1302 if ((TableVal >> 31) != 0) {
1303 // This is an offset into the IIT_LongEncodingTable.
1304 IITEntries = IIT_LongEncodingTable;
1305
1306 // Strip sentinel bit.
1307 NextElt = (TableVal << 1) >> 1;
1308 } else {
1309 // Decode the TableVal into an array of IITValues. If the entry was encoded
1310 // into a single word in the table itself, decode it now.
1311 do {
1312 IITValues.push_back(TableVal & 0xF);
1313 TableVal >>= 4;
1314 } while (TableVal);
1315
1316 IITEntries = IITValues;
1317 NextElt = 0;
1318 }
1319
1320 // Okay, decode the table into the output vector of IITDescriptors.
1321 DecodeIITType(NextElt, IITEntries, IIT_Done, T);
1322 while (NextElt != IITEntries.size() && IITEntries[NextElt] != 0)
1323 DecodeIITType(NextElt, IITEntries, IIT_Done, T);
1324}
1325
1327 ArrayRef<Type*> Tys, LLVMContext &Context) {
1328 using namespace Intrinsic;
1329
1330 IITDescriptor D = Infos.front();
1331 Infos = Infos.slice(1);
1332
1333 switch (D.Kind) {
1334 case IITDescriptor::Void: return Type::getVoidTy(Context);
1335 case IITDescriptor::VarArg: return Type::getVoidTy(Context);
1336 case IITDescriptor::MMX: return Type::getX86_MMXTy(Context);
1337 case IITDescriptor::AMX: return Type::getX86_AMXTy(Context);
1338 case IITDescriptor::Token: return Type::getTokenTy(Context);
1339 case IITDescriptor::Metadata: return Type::getMetadataTy(Context);
1340 case IITDescriptor::Half: return Type::getHalfTy(Context);
1341 case IITDescriptor::BFloat: return Type::getBFloatTy(Context);
1342 case IITDescriptor::Float: return Type::getFloatTy(Context);
1343 case IITDescriptor::Double: return Type::getDoubleTy(Context);
1344 case IITDescriptor::Quad: return Type::getFP128Ty(Context);
1345 case IITDescriptor::PPCQuad: return Type::getPPC_FP128Ty(Context);
1346 case IITDescriptor::AArch64Svcount:
1347 return TargetExtType::get(Context, "aarch64.svcount");
1348
1349 case IITDescriptor::Integer:
1350 return IntegerType::get(Context, D.Integer_Width);
1351 case IITDescriptor::Vector:
1352 return VectorType::get(DecodeFixedType(Infos, Tys, Context),
1353 D.Vector_Width);
1354 case IITDescriptor::Pointer:
1355 return PointerType::get(DecodeFixedType(Infos, Tys, Context),
1356 D.Pointer_AddressSpace);
1357 case IITDescriptor::Struct: {
1359 for (unsigned i = 0, e = D.Struct_NumElements; i != e; ++i)
1360 Elts.push_back(DecodeFixedType(Infos, Tys, Context));
1361 return StructType::get(Context, Elts);
1362 }
1363 case IITDescriptor::Argument:
1364 return Tys[D.getArgumentNumber()];
1365 case IITDescriptor::ExtendArgument: {
1366 Type *Ty = Tys[D.getArgumentNumber()];
1367 if (VectorType *VTy = dyn_cast<VectorType>(Ty))
1369
1370 return IntegerType::get(Context, 2 * cast<IntegerType>(Ty)->getBitWidth());
1371 }
1372 case IITDescriptor::TruncArgument: {
1373 Type *Ty = Tys[D.getArgumentNumber()];
1374 if (VectorType *VTy = dyn_cast<VectorType>(Ty))
1376
1377 IntegerType *ITy = cast<IntegerType>(Ty);
1378 assert(ITy->getBitWidth() % 2 == 0);
1379 return IntegerType::get(Context, ITy->getBitWidth() / 2);
1380 }
1381 case IITDescriptor::Subdivide2Argument:
1382 case IITDescriptor::Subdivide4Argument: {
1383 Type *Ty = Tys[D.getArgumentNumber()];
1384 VectorType *VTy = dyn_cast<VectorType>(Ty);
1385 assert(VTy && "Expected an argument of Vector Type");
1386 int SubDivs = D.Kind == IITDescriptor::Subdivide2Argument ? 1 : 2;
1387 return VectorType::getSubdividedVectorType(VTy, SubDivs);
1388 }
1389 case IITDescriptor::HalfVecArgument:
1390 return VectorType::getHalfElementsVectorType(cast<VectorType>(
1391 Tys[D.getArgumentNumber()]));
1392 case IITDescriptor::SameVecWidthArgument: {
1393 Type *EltTy = DecodeFixedType(Infos, Tys, Context);
1394 Type *Ty = Tys[D.getArgumentNumber()];
1395 if (auto *VTy = dyn_cast<VectorType>(Ty))
1396 return VectorType::get(EltTy, VTy->getElementCount());
1397 return EltTy;
1398 }
1399 case IITDescriptor::PtrToArgument: {
1400 Type *Ty = Tys[D.getArgumentNumber()];
1401 return PointerType::getUnqual(Ty);
1402 }
1403 case IITDescriptor::PtrToElt: {
1404 Type *Ty = Tys[D.getArgumentNumber()];
1405 VectorType *VTy = dyn_cast<VectorType>(Ty);
1406 if (!VTy)
1407 llvm_unreachable("Expected an argument of Vector Type");
1408 Type *EltTy = VTy->getElementType();
1409 return PointerType::getUnqual(EltTy);
1410 }
1411 case IITDescriptor::VecElementArgument: {
1412 Type *Ty = Tys[D.getArgumentNumber()];
1413 if (VectorType *VTy = dyn_cast<VectorType>(Ty))
1414 return VTy->getElementType();
1415 llvm_unreachable("Expected an argument of Vector Type");
1416 }
1417 case IITDescriptor::VecOfBitcastsToInt: {
1418 Type *Ty = Tys[D.getArgumentNumber()];
1419 VectorType *VTy = dyn_cast<VectorType>(Ty);
1420 assert(VTy && "Expected an argument of Vector Type");
1421 return VectorType::getInteger(VTy);
1422 }
1423 case IITDescriptor::VecOfAnyPtrsToElt:
1424 // Return the overloaded type (which determines the pointers address space)
1425 return Tys[D.getOverloadArgNumber()];
1426 case IITDescriptor::AnyPtrToElt:
1427 // Return the overloaded type (which determines the pointers address space)
1428 return Tys[D.getOverloadArgNumber()];
1429 }
1430 llvm_unreachable("unhandled");
1431}
1432
1434 ID id, ArrayRef<Type*> Tys) {
1437
1439 Type *ResultTy = DecodeFixedType(TableRef, Tys, Context);
1440
1441 SmallVector<Type*, 8> ArgTys;
1442 while (!TableRef.empty())
1444
1445 // DecodeFixedType returns Void for IITDescriptor::Void and IITDescriptor::VarArg
1446 // If we see void type as the type of the last argument, it is vararg intrinsic
1447 if (!ArgTys.empty() && ArgTys.back()->isVoidTy()) {
1448 ArgTys.pop_back();
1449 return FunctionType::get(ResultTy, ArgTys, true);
1450 }
1451 return FunctionType::get(ResultTy, ArgTys, false);
1452}
1453
1455#define GET_INTRINSIC_OVERLOAD_TABLE
1456#include "llvm/IR/IntrinsicImpl.inc"
1457#undef GET_INTRINSIC_OVERLOAD_TABLE
1458}
1459
1460/// This defines the "Intrinsic::getAttributes(ID id)" method.
1461#define GET_INTRINSIC_ATTRIBUTES
1462#include "llvm/IR/IntrinsicImpl.inc"
1463#undef GET_INTRINSIC_ATTRIBUTES
1464
1466 // There can never be multiple globals with the same name of different types,
1467 // because intrinsics must be a specific type.
1468 auto *FT = getType(M->getContext(), id, Tys);
1469 return cast<Function>(
1470 M->getOrInsertFunction(
1471 Tys.empty() ? getName(id) : getName(id, Tys, M, FT), FT)
1472 .getCallee());
1473}
1474
1475// This defines the "Intrinsic::getIntrinsicForClangBuiltin()" method.
1476#define GET_LLVM_INTRINSIC_FOR_CLANG_BUILTIN
1477#include "llvm/IR/IntrinsicImpl.inc"
1478#undef GET_LLVM_INTRINSIC_FOR_CLANG_BUILTIN
1479
1480// This defines the "Intrinsic::getIntrinsicForMSBuiltin()" method.
1481#define GET_LLVM_INTRINSIC_FOR_MS_BUILTIN
1482#include "llvm/IR/IntrinsicImpl.inc"
1483#undef GET_LLVM_INTRINSIC_FOR_MS_BUILTIN
1484
1486 std::pair<Type *, ArrayRef<Intrinsic::IITDescriptor>>;
1487
1492 bool IsDeferredCheck) {
1493 using namespace Intrinsic;
1494
1495 // If we ran out of descriptors, there are too many arguments.
1496 if (Infos.empty()) return true;
1497
1498 // Do this before slicing off the 'front' part
1499 auto InfosRef = Infos;
1500 auto DeferCheck = [&DeferredChecks, &InfosRef](Type *T) {
1501 DeferredChecks.emplace_back(T, InfosRef);
1502 return false;
1503 };
1504
1505 IITDescriptor D = Infos.front();
1506 Infos = Infos.slice(1);
1507
1508 switch (D.Kind) {
1509 case IITDescriptor::Void: return !Ty->isVoidTy();
1510 case IITDescriptor::VarArg: return true;
1511 case IITDescriptor::MMX: return !Ty->isX86_MMXTy();
1512 case IITDescriptor::AMX: return !Ty->isX86_AMXTy();
1513 case IITDescriptor::Token: return !Ty->isTokenTy();
1514 case IITDescriptor::Metadata: return !Ty->isMetadataTy();
1515 case IITDescriptor::Half: return !Ty->isHalfTy();
1516 case IITDescriptor::BFloat: return !Ty->isBFloatTy();
1517 case IITDescriptor::Float: return !Ty->isFloatTy();
1518 case IITDescriptor::Double: return !Ty->isDoubleTy();
1519 case IITDescriptor::Quad: return !Ty->isFP128Ty();
1520 case IITDescriptor::PPCQuad: return !Ty->isPPC_FP128Ty();
1521 case IITDescriptor::Integer: return !Ty->isIntegerTy(D.Integer_Width);
1522 case IITDescriptor::AArch64Svcount:
1523 return !isa<TargetExtType>(Ty) ||
1524 cast<TargetExtType>(Ty)->getName() != "aarch64.svcount";
1525 case IITDescriptor::Vector: {
1526 VectorType *VT = dyn_cast<VectorType>(Ty);
1527 return !VT || VT->getElementCount() != D.Vector_Width ||
1528 matchIntrinsicType(VT->getElementType(), Infos, ArgTys,
1529 DeferredChecks, IsDeferredCheck);
1530 }
1531 case IITDescriptor::Pointer: {
1532 PointerType *PT = dyn_cast<PointerType>(Ty);
1533 if (!PT || PT->getAddressSpace() != D.Pointer_AddressSpace)
1534 return true;
1535 if (!PT->isOpaque()) {
1536 /* Manually consume a pointer to empty struct descriptor, which is
1537 * used for externref. We don't want to enforce that the struct is
1538 * anonymous in this case. (This renders externref intrinsics
1539 * non-unique, but this will go away with opaque pointers anyway.) */
1540 if (Infos.front().Kind == IITDescriptor::Struct &&
1541 Infos.front().Struct_NumElements == 0) {
1542 Infos = Infos.slice(1);
1543 return false;
1544 }
1545 return matchIntrinsicType(PT->getNonOpaquePointerElementType(), Infos,
1546 ArgTys, DeferredChecks, IsDeferredCheck);
1547 }
1548 // Consume IIT descriptors relating to the pointer element type.
1549 // FIXME: Intrinsic type matching of nested single value types or even
1550 // aggregates doesn't work properly with opaque pointers but hopefully
1551 // doesn't happen in practice.
1552 while (Infos.front().Kind == IITDescriptor::Pointer ||
1553 Infos.front().Kind == IITDescriptor::Vector)
1554 Infos = Infos.slice(1);
1555 assert((Infos.front().Kind != IITDescriptor::Argument ||
1556 Infos.front().getArgumentKind() == IITDescriptor::AK_MatchType) &&
1557 "Unsupported polymorphic pointer type with opaque pointer");
1558 Infos = Infos.slice(1);
1559 return false;
1560 }
1561
1562 case IITDescriptor::Struct: {
1563 StructType *ST = dyn_cast<StructType>(Ty);
1564 if (!ST || !ST->isLiteral() || ST->isPacked() ||
1565 ST->getNumElements() != D.Struct_NumElements)
1566 return true;
1567
1568 for (unsigned i = 0, e = D.Struct_NumElements; i != e; ++i)
1569 if (matchIntrinsicType(ST->getElementType(i), Infos, ArgTys,
1570 DeferredChecks, IsDeferredCheck))
1571 return true;
1572 return false;
1573 }
1574
1575 case IITDescriptor::Argument:
1576 // If this is the second occurrence of an argument,
1577 // verify that the later instance matches the previous instance.
1578 if (D.getArgumentNumber() < ArgTys.size())
1579 return Ty != ArgTys[D.getArgumentNumber()];
1580
1581 if (D.getArgumentNumber() > ArgTys.size() ||
1582 D.getArgumentKind() == IITDescriptor::AK_MatchType)
1583 return IsDeferredCheck || DeferCheck(Ty);
1584
1585 assert(D.getArgumentNumber() == ArgTys.size() && !IsDeferredCheck &&
1586 "Table consistency error");
1587 ArgTys.push_back(Ty);
1588
1589 switch (D.getArgumentKind()) {
1590 case IITDescriptor::AK_Any: return false; // Success
1591 case IITDescriptor::AK_AnyInteger: return !Ty->isIntOrIntVectorTy();
1592 case IITDescriptor::AK_AnyFloat: return !Ty->isFPOrFPVectorTy();
1593 case IITDescriptor::AK_AnyVector: return !isa<VectorType>(Ty);
1594 case IITDescriptor::AK_AnyPointer: return !isa<PointerType>(Ty);
1595 default: break;
1596 }
1597 llvm_unreachable("all argument kinds not covered");
1598
1599 case IITDescriptor::ExtendArgument: {
1600 // If this is a forward reference, defer the check for later.
1601 if (D.getArgumentNumber() >= ArgTys.size())
1602 return IsDeferredCheck || DeferCheck(Ty);
1603
1604 Type *NewTy = ArgTys[D.getArgumentNumber()];
1605 if (VectorType *VTy = dyn_cast<VectorType>(NewTy))
1607 else if (IntegerType *ITy = dyn_cast<IntegerType>(NewTy))
1608 NewTy = IntegerType::get(ITy->getContext(), 2 * ITy->getBitWidth());
1609 else
1610 return true;
1611
1612 return Ty != NewTy;
1613 }
1614 case IITDescriptor::TruncArgument: {
1615 // If this is a forward reference, defer the check for later.
1616 if (D.getArgumentNumber() >= ArgTys.size())
1617 return IsDeferredCheck || DeferCheck(Ty);
1618
1619 Type *NewTy = ArgTys[D.getArgumentNumber()];
1620 if (VectorType *VTy = dyn_cast<VectorType>(NewTy))
1622 else if (IntegerType *ITy = dyn_cast<IntegerType>(NewTy))
1623 NewTy = IntegerType::get(ITy->getContext(), ITy->getBitWidth() / 2);
1624 else
1625 return true;
1626
1627 return Ty != NewTy;
1628 }
1629 case IITDescriptor::HalfVecArgument:
1630 // If this is a forward reference, defer the check for later.
1631 if (D.getArgumentNumber() >= ArgTys.size())
1632 return IsDeferredCheck || DeferCheck(Ty);
1633 return !isa<VectorType>(ArgTys[D.getArgumentNumber()]) ||
1635 cast<VectorType>(ArgTys[D.getArgumentNumber()])) != Ty;
1636 case IITDescriptor::SameVecWidthArgument: {
1637 if (D.getArgumentNumber() >= ArgTys.size()) {
1638 // Defer check and subsequent check for the vector element type.
1639 Infos = Infos.slice(1);
1640 return IsDeferredCheck || DeferCheck(Ty);
1641 }
1642 auto *ReferenceType = dyn_cast<VectorType>(ArgTys[D.getArgumentNumber()]);
1643 auto *ThisArgType = dyn_cast<VectorType>(Ty);
1644 // Both must be vectors of the same number of elements or neither.
1645 if ((ReferenceType != nullptr) != (ThisArgType != nullptr))
1646 return true;
1647 Type *EltTy = Ty;
1648 if (ThisArgType) {
1649 if (ReferenceType->getElementCount() !=
1650 ThisArgType->getElementCount())
1651 return true;
1652 EltTy = ThisArgType->getElementType();
1653 }
1654 return matchIntrinsicType(EltTy, Infos, ArgTys, DeferredChecks,
1655 IsDeferredCheck);
1656 }
1657 case IITDescriptor::PtrToArgument: {
1658 if (D.getArgumentNumber() >= ArgTys.size())
1659 return IsDeferredCheck || DeferCheck(Ty);
1660 Type * ReferenceType = ArgTys[D.getArgumentNumber()];
1661 PointerType *ThisArgType = dyn_cast<PointerType>(Ty);
1662 return (!ThisArgType ||
1663 !ThisArgType->isOpaqueOrPointeeTypeMatches(ReferenceType));
1664 }
1665 case IITDescriptor::PtrToElt: {
1666 if (D.getArgumentNumber() >= ArgTys.size())
1667 return IsDeferredCheck || DeferCheck(Ty);
1669 dyn_cast<VectorType> (ArgTys[D.getArgumentNumber()]);
1670 PointerType *ThisArgType = dyn_cast<PointerType>(Ty);
1671
1672 if (!ThisArgType || !ReferenceType)
1673 return true;
1674 return !ThisArgType->isOpaqueOrPointeeTypeMatches(
1675 ReferenceType->getElementType());
1676 }
1677 case IITDescriptor::AnyPtrToElt: {
1678 unsigned RefArgNumber = D.getRefArgNumber();
1679 if (RefArgNumber >= ArgTys.size()) {
1680 if (IsDeferredCheck)
1681 return true;
1682 // If forward referencing, already add the pointer type and
1683 // defer the checks for later.
1684 ArgTys.push_back(Ty);
1685 return DeferCheck(Ty);
1686 }
1687
1688 if (!IsDeferredCheck) {
1689 assert(D.getOverloadArgNumber() == ArgTys.size() &&
1690 "Table consistency error");
1691 ArgTys.push_back(Ty);
1692 }
1693
1694 auto *ReferenceType = dyn_cast<VectorType>(ArgTys[RefArgNumber]);
1695 auto *ThisArgType = dyn_cast<PointerType>(Ty);
1696 if (!ThisArgType || !ReferenceType)
1697 return true;
1698 return !ThisArgType->isOpaqueOrPointeeTypeMatches(
1699 ReferenceType->getElementType());
1700 }
1701 case IITDescriptor::VecOfAnyPtrsToElt: {
1702 unsigned RefArgNumber = D.getRefArgNumber();
1703 if (RefArgNumber >= ArgTys.size()) {
1704 if (IsDeferredCheck)
1705 return true;
1706 // If forward referencing, already add the pointer-vector type and
1707 // defer the checks for later.
1708 ArgTys.push_back(Ty);
1709 return DeferCheck(Ty);
1710 }
1711
1712 if (!IsDeferredCheck){
1713 assert(D.getOverloadArgNumber() == ArgTys.size() &&
1714 "Table consistency error");
1715 ArgTys.push_back(Ty);
1716 }
1717
1718 // Verify the overloaded type "matches" the Ref type.
1719 // i.e. Ty is a vector with the same width as Ref.
1720 // Composed of pointers to the same element type as Ref.
1721 auto *ReferenceType = dyn_cast<VectorType>(ArgTys[RefArgNumber]);
1722 auto *ThisArgVecTy = dyn_cast<VectorType>(Ty);
1723 if (!ThisArgVecTy || !ReferenceType ||
1724 (ReferenceType->getElementCount() != ThisArgVecTy->getElementCount()))
1725 return true;
1726 PointerType *ThisArgEltTy =
1727 dyn_cast<PointerType>(ThisArgVecTy->getElementType());
1728 if (!ThisArgEltTy)
1729 return true;
1730 return !ThisArgEltTy->isOpaqueOrPointeeTypeMatches(
1731 ReferenceType->getElementType());
1732 }
1733 case IITDescriptor::VecElementArgument: {
1734 if (D.getArgumentNumber() >= ArgTys.size())
1735 return IsDeferredCheck ? true : DeferCheck(Ty);
1736 auto *ReferenceType = dyn_cast<VectorType>(ArgTys[D.getArgumentNumber()]);
1737 return !ReferenceType || Ty != ReferenceType->getElementType();
1738 }
1739 case IITDescriptor::Subdivide2Argument:
1740 case IITDescriptor::Subdivide4Argument: {
1741 // If this is a forward reference, defer the check for later.
1742 if (D.getArgumentNumber() >= ArgTys.size())
1743 return IsDeferredCheck || DeferCheck(Ty);
1744
1745 Type *NewTy = ArgTys[D.getArgumentNumber()];
1746 if (auto *VTy = dyn_cast<VectorType>(NewTy)) {
1747 int SubDivs = D.Kind == IITDescriptor::Subdivide2Argument ? 1 : 2;
1748 NewTy = VectorType::getSubdividedVectorType(VTy, SubDivs);
1749 return Ty != NewTy;
1750 }
1751 return true;
1752 }
1753 case IITDescriptor::VecOfBitcastsToInt: {
1754 if (D.getArgumentNumber() >= ArgTys.size())
1755 return IsDeferredCheck || DeferCheck(Ty);
1756 auto *ReferenceType = dyn_cast<VectorType>(ArgTys[D.getArgumentNumber()]);
1757 auto *ThisArgVecTy = dyn_cast<VectorType>(Ty);
1758 if (!ThisArgVecTy || !ReferenceType)
1759 return true;
1760 return ThisArgVecTy != VectorType::getInteger(ReferenceType);
1761 }
1762 }
1763 llvm_unreachable("unhandled");
1764}
1765
1769 SmallVectorImpl<Type *> &ArgTys) {
1771 if (matchIntrinsicType(FTy->getReturnType(), Infos, ArgTys, DeferredChecks,
1772 false))
1774
1775 unsigned NumDeferredReturnChecks = DeferredChecks.size();
1776
1777 for (auto *Ty : FTy->params())
1778 if (matchIntrinsicType(Ty, Infos, ArgTys, DeferredChecks, false))
1780
1781 for (unsigned I = 0, E = DeferredChecks.size(); I != E; ++I) {
1782 DeferredIntrinsicMatchPair &Check = DeferredChecks[I];
1783 if (matchIntrinsicType(Check.first, Check.second, ArgTys, DeferredChecks,
1784 true))
1785 return I < NumDeferredReturnChecks ? MatchIntrinsicTypes_NoMatchRet
1787 }
1788
1790}
1791
1792bool
1795 // If there are no descriptors left, then it can't be a vararg.
1796 if (Infos.empty())
1797 return isVarArg;
1798
1799 // There should be only one descriptor remaining at this point.
1800 if (Infos.size() != 1)
1801 return true;
1802
1803 // Check and verify the descriptor.
1804 IITDescriptor D = Infos.front();
1805 Infos = Infos.slice(1);
1806 if (D.Kind == IITDescriptor::VarArg)
1807 return !isVarArg;
1808
1809 return true;
1810}
1811
1813 SmallVectorImpl<Type *> &ArgTys) {
1814 Intrinsic::ID ID = F->getIntrinsicID();
1815 if (!ID)
1816 return false;
1817
1821
1822 if (Intrinsic::matchIntrinsicSignature(F->getFunctionType(), TableRef,
1823 ArgTys) !=
1825 return false;
1826 }
1827 if (Intrinsic::matchIntrinsicVarArg(F->getFunctionType()->isVarArg(),
1828 TableRef))
1829 return false;
1830 return true;
1831}
1832
1835 if (!getIntrinsicSignature(F, ArgTys))
1836 return std::nullopt;
1837
1838 Intrinsic::ID ID = F->getIntrinsicID();
1839 StringRef Name = F->getName();
1840 std::string WantedName =
1841 Intrinsic::getName(ID, ArgTys, F->getParent(), F->getFunctionType());
1842 if (Name == WantedName)
1843 return std::nullopt;
1844
1845 Function *NewDecl = [&] {
1846 if (auto *ExistingGV = F->getParent()->getNamedValue(WantedName)) {
1847 if (auto *ExistingF = dyn_cast<Function>(ExistingGV))
1848 if (ExistingF->getFunctionType() == F->getFunctionType())
1849 return ExistingF;
1850
1851 // The name already exists, but is not a function or has the wrong
1852 // prototype. Make place for the new one by renaming the old version.
1853 // Either this old version will be removed later on or the module is
1854 // invalid and we'll get an error.
1855 ExistingGV->setName(WantedName + ".renamed");
1856 }
1857 return Intrinsic::getDeclaration(F->getParent(), ID, ArgTys);
1858 }();
1859
1860 NewDecl->setCallingConv(F->getCallingConv());
1861 assert(NewDecl->getFunctionType() == F->getFunctionType() &&
1862 "Shouldn't change the signature");
1863 return NewDecl;
1864}
1865
1866/// hasAddressTaken - returns true if there are any uses of this function
1867/// other than direct calls or invokes to it. Optionally ignores callback
1868/// uses, assume like pointer annotation calls, and references in llvm.used
1869/// and llvm.compiler.used variables.
1870bool Function::hasAddressTaken(const User **PutOffender,
1871 bool IgnoreCallbackUses,
1872 bool IgnoreAssumeLikeCalls, bool IgnoreLLVMUsed,
1873 bool IgnoreARCAttachedCall) const {
1874 for (const Use &U : uses()) {
1875 const User *FU = U.getUser();
1876 if (isa<BlockAddress>(FU))
1877 continue;
1878
1879 if (IgnoreCallbackUses) {
1880 AbstractCallSite ACS(&U);
1881 if (ACS && ACS.isCallbackCall())
1882 continue;
1883 }
1884
1885 const auto *Call = dyn_cast<CallBase>(FU);
1886 if (!Call) {
1887 if (IgnoreAssumeLikeCalls &&
1888 isa<BitCastOperator, AddrSpaceCastOperator>(FU) &&
1889 all_of(FU->users(), [](const User *U) {
1890 if (const auto *I = dyn_cast<IntrinsicInst>(U))
1891 return I->isAssumeLikeIntrinsic();
1892 return false;
1893 })) {
1894 continue;
1895 }
1896
1897 if (IgnoreLLVMUsed && !FU->user_empty()) {
1898 const User *FUU = FU;
1899 if (isa<BitCastOperator, AddrSpaceCastOperator>(FU) &&
1900 FU->hasOneUse() && !FU->user_begin()->user_empty())
1901 FUU = *FU->user_begin();
1902 if (llvm::all_of(FUU->users(), [](const User *U) {
1903 if (const auto *GV = dyn_cast<GlobalVariable>(U))
1904 return GV->hasName() &&
1905 (GV->getName().equals("llvm.compiler.used") ||
1906 GV->getName().equals("llvm.used"));
1907 return false;
1908 }))
1909 continue;
1910 }
1911 if (PutOffender)
1912 *PutOffender = FU;
1913 return true;
1914 }
1915
1916 if (IgnoreAssumeLikeCalls) {
1917 if (const auto *I = dyn_cast<IntrinsicInst>(Call))
1918 if (I->isAssumeLikeIntrinsic())
1919 continue;
1920 }
1921
1922 if (!Call->isCallee(&U) || Call->getFunctionType() != getFunctionType()) {
1923 if (IgnoreARCAttachedCall &&
1924 Call->isOperandBundleOfType(LLVMContext::OB_clang_arc_attachedcall,
1925 U.getOperandNo()))
1926 continue;
1927
1928 if (PutOffender)
1929 *PutOffender = FU;
1930 return true;
1931 }
1932 }
1933 return false;
1934}
1935
1937 // Check the linkage
1938 if (!hasLinkOnceLinkage() && !hasLocalLinkage() &&
1940 return false;
1941
1942 // Check if the function is used by anything other than a blockaddress.
1943 for (const User *U : users())
1944 if (!isa<BlockAddress>(U))
1945 return false;
1946
1947 return true;
1948}
1949
1950/// callsFunctionThatReturnsTwice - Return true if the function has a call to
1951/// setjmp or other function that gcc recognizes as "returning twice".
1953 for (const Instruction &I : instructions(this))
1954 if (const auto *Call = dyn_cast<CallBase>(&I))
1955 if (Call->hasFnAttr(Attribute::ReturnsTwice))
1956 return true;
1957
1958 return false;
1959}
1960
1963 return cast<Constant>(Op<0>());
1964}
1965
1967 setHungoffOperand<0>(Fn);
1968 setValueSubclassDataBit(3, Fn != nullptr);
1969}
1970
1973 return cast<Constant>(Op<1>());
1974}
1975
1977 setHungoffOperand<1>(PrefixData);
1978 setValueSubclassDataBit(1, PrefixData != nullptr);
1979}
1980
1983 return cast<Constant>(Op<2>());
1984}
1985
1987 setHungoffOperand<2>(PrologueData);
1988 setValueSubclassDataBit(2, PrologueData != nullptr);
1989}
1990
1991void Function::allocHungoffUselist() {
1992 // If we've already allocated a uselist, stop here.
1993 if (getNumOperands())
1994 return;
1995
1996 allocHungoffUses(3, /*IsPhi=*/ false);
1998
1999 // Initialize the uselist with placeholder operands to allow traversal.
2001 Op<0>().set(CPN);
2002 Op<1>().set(CPN);
2003 Op<2>().set(CPN);
2004}
2005
2006template <int Idx>
2007void Function::setHungoffOperand(Constant *C) {
2008 if (C) {
2009 allocHungoffUselist();
2010 Op<Idx>().set(C);
2011 } else if (getNumOperands()) {
2012 Op<Idx>().set(
2014 }
2015}
2016
2017void Function::setValueSubclassDataBit(unsigned Bit, bool On) {
2018 assert(Bit < 16 && "SubclassData contains only 16 bits");
2019 if (On)
2020 setValueSubclassData(getSubclassDataFromValue() | (1 << Bit));
2021 else
2022 setValueSubclassData(getSubclassDataFromValue() & ~(1 << Bit));
2023}
2024
2026 const DenseSet<GlobalValue::GUID> *S) {
2027#if !defined(NDEBUG)
2028 auto PrevCount = getEntryCount();
2029 assert(!PrevCount || PrevCount->getType() == Count.getType());
2030#endif
2031
2032 auto ImportGUIDs = getImportGUIDs();
2033 if (S == nullptr && ImportGUIDs.size())
2034 S = &ImportGUIDs;
2035
2036 MDBuilder MDB(getContext());
2038 LLVMContext::MD_prof,
2039 MDB.createFunctionEntryCount(Count.getCount(), Count.isSynthetic(), S));
2040}
2041
2043 const DenseSet<GlobalValue::GUID> *Imports) {
2044 setEntryCount(ProfileCount(Count, Type), Imports);
2045}
2046
2047std::optional<ProfileCount> Function::getEntryCount(bool AllowSynthetic) const {
2048 MDNode *MD = getMetadata(LLVMContext::MD_prof);
2049 if (MD && MD->getOperand(0))
2050 if (MDString *MDS = dyn_cast<MDString>(MD->getOperand(0))) {
2051 if (MDS->getString().equals("function_entry_count")) {
2052 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(1));
2053 uint64_t Count = CI->getValue().getZExtValue();
2054 // A value of -1 is used for SamplePGO when there were no samples.
2055 // Treat this the same as unknown.
2056 if (Count == (uint64_t)-1)
2057 return std::nullopt;
2058 return ProfileCount(Count, PCT_Real);
2059 } else if (AllowSynthetic &&
2060 MDS->getString().equals("synthetic_function_entry_count")) {
2061 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(1));
2062 uint64_t Count = CI->getValue().getZExtValue();
2063 return ProfileCount(Count, PCT_Synthetic);
2064 }
2065 }
2066 return std::nullopt;
2067}
2068
2071 if (MDNode *MD = getMetadata(LLVMContext::MD_prof))
2072 if (MDString *MDS = dyn_cast<MDString>(MD->getOperand(0)))
2073 if (MDS->getString().equals("function_entry_count"))
2074 for (unsigned i = 2; i < MD->getNumOperands(); i++)
2075 R.insert(mdconst::extract<ConstantInt>(MD->getOperand(i))
2076 ->getValue()
2077 .getZExtValue());
2078 return R;
2079}
2080
2082 MDBuilder MDB(getContext());
2083 setMetadata(LLVMContext::MD_section_prefix,
2084 MDB.createFunctionSectionPrefix(Prefix));
2085}
2086
2087std::optional<StringRef> Function::getSectionPrefix() const {
2088 if (MDNode *MD = getMetadata(LLVMContext::MD_section_prefix)) {
2089 assert(cast<MDString>(MD->getOperand(0))
2090 ->getString()
2091 .equals("function_section_prefix") &&
2092 "Metadata not match");
2093 return cast<MDString>(MD->getOperand(1))->getString();
2094 }
2095 return std::nullopt;
2096}
2097
2099 return hasFnAttribute(Attribute::NullPointerIsValid);
2100}
2101
2102bool llvm::NullPointerIsDefined(const Function *F, unsigned AS) {
2103 if (F && F->nullPointerIsDefined())
2104 return true;
2105
2106 if (AS != 0)
2107 return true;
2108
2109 return false;
2110}
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file contains the simple types necessary to represent the attributes associated with functions a...
basic Basic Alias true
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
This file defines the DenseSet and SmallDenseSet classes.
std::string Name
static Type * getMemoryParamAllocType(AttributeSet ParamAttrs)
For a byval, sret, inalloca, or preallocated parameter, get the in-memory parameter type.
Definition: Function.cpp:160
static cl::opt< unsigned > NonGlobalValueMaxNameSize("non-global-value-max-name-size", cl::Hidden, cl::init(1024), cl::desc("Maximum size for the name of non-global values."))
static bool matchIntrinsicType(Type *Ty, ArrayRef< Intrinsic::IITDescriptor > &Infos, SmallVectorImpl< Type * > &ArgTys, SmallVectorImpl< DeferredIntrinsicMatchPair > &DeferredChecks, bool IsDeferredCheck)
Definition: Function.cpp:1488
static std::string getIntrinsicNameImpl(Intrinsic::ID Id, ArrayRef< Type * > Tys, Module *M, FunctionType *FT, bool EarlyModuleCheck)
Definition: Function.cpp:999
static MutableArrayRef< Argument > makeArgArray(Argument *Args, size_t Count)
Definition: Function.cpp:458
std::pair< Type *, ArrayRef< Intrinsic::IITDescriptor > > DeferredIntrinsicMatchPair
Definition: Function.cpp:1486
static ArrayRef< const char * > findTargetSubtable(StringRef Name)
Find the segment of IntrinsicNameTable for intrinsics with the same target as Name,...
Definition: Function.cpp:856
static void DecodeIITType(unsigned &NextElt, ArrayRef< unsigned char > Infos, IIT_Info LastInfo, SmallVectorImpl< Intrinsic::IITDescriptor > &OutputTable)
Definition: Function.cpp:1046
IIT_Info
IIT_Info - These are enumerators that describe the entries returned by the getIntrinsicInfoTableEntri...
Definition: Function.cpp:1040
static Type * DecodeFixedType(ArrayRef< Intrinsic::IITDescriptor > &Infos, ArrayRef< Type * > Tys, LLVMContext &Context)
Definition: Function.cpp:1326
static const char *const IntrinsicNameTable[]
Table of string intrinsic names indexed by enum value.
Definition: Function.cpp:832
static std::string getMangledTypeStr(Type *Ty, bool &HasUnnamedType)
Returns a stable mangling for the type specified for use in the name mangling scheme used by 'any' ty...
Definition: Function.cpp:916
static unsigned computeAddrSpace(unsigned AddrSpace, Module *M)
Definition: Function.cpp:391
iv users
Definition: IVUsers.cpp:48
#define Check(C,...)
Definition: Lint.cpp:168
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
This file contains the declarations for metadata subclasses.
Module.h This file contains the declarations for the Module class.
print must be executed print the must be executed context for all instructions
LLVMContext & Context
static StringRef getName(Value *V)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static const char * name
Definition: SMEABIPass.cpp:49
This file contains some templates that are useful if you are working with the STL at all.
This file defines the SmallString class.
This file defines the SmallVector class.
This file contains some functions that are useful when dealing with strings.
static SymbolRef::Type getType(const Symbol *Sym)
Definition: TapiFile.cpp:40
@ Targets
Definition: TextStubV5.cpp:90
This defines the Use class.
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
uint64_t getZExtValue() const
Get zero extended value.
Definition: APInt.h:1498
AbstractCallSite.
bool isCallbackCall() const
Return true if this ACS represents a callback call.
This class represents an incoming formal argument to a Function.
Definition: Argument.h:28
Type * getParamByRefType() const
If this is a byref argument, return its type.
Definition: Function.cpp:210
Attribute getAttribute(Attribute::AttrKind Kind) const
Definition: Function.cpp:311
bool hasNoAliasAttr() const
Return true if this argument has the noalias attribute.
Definition: Function.cpp:241
bool hasNonNullAttr(bool AllowUndefOrPoison=true) const
Return true if this argument has the nonnull attribute.
Definition: Function.cpp:96
bool hasByRefAttr() const
Return true if this argument has the byref attribute.
Definition: Function.cpp:114
uint64_t getDereferenceableOrNullBytes() const
If this argument has the dereferenceable_or_null attribute, return the number of bytes known to be de...
Definition: Function.cpp:226
void addAttr(Attribute::AttrKind Kind)
Definition: Function.cpp:289
Argument(Type *Ty, const Twine &Name="", Function *F=nullptr, unsigned ArgNo=0)
Argument constructor.
Definition: Function.cpp:87
bool onlyReadsMemory() const
Return true if this argument has the readonly or readnone attribute.
Definition: Function.cpp:277
bool hasPointeeInMemoryValueAttr() const
Return true if this argument has the byval, sret, inalloca, preallocated, or byref attribute.
Definition: Function.cpp:147
bool hasAttribute(Attribute::AttrKind Kind) const
Check if an argument has a given attribute.
Definition: Function.cpp:307
bool hasReturnedAttr() const
Return true if this argument has the returned attribute.
Definition: Function.cpp:265
Type * getParamStructRetType() const
If this is an sret argument, return its type.
Definition: Function.cpp:205
bool hasInRegAttr() const
Return true if this argument has the inreg attribute.
Definition: Function.cpp:261
bool hasByValAttr() const
Return true if this argument has the byval attribute.
Definition: Function.cpp:109
bool hasPreallocatedAttr() const
Return true if this argument has the preallocated attribute.
Definition: Function.cpp:133
bool hasSExtAttr() const
Return true if this argument has the sext attribute.
Definition: Function.cpp:273
void removeAttr(Attribute::AttrKind Kind)
Remove attributes from an argument.
Definition: Function.cpp:297
uint64_t getPassPointeeByValueCopySize(const DataLayout &DL) const
If this argument satisfies has hasPassPointeeByValueAttr, return the in-memory ABI size copied to the...
Definition: Function.cpp:177
void removeAttrs(const AttributeMask &AM)
Definition: Function.cpp:301
const Function * getParent() const
Definition: Argument.h:40
Type * getPointeeInMemoryValueType() const
If hasPointeeInMemoryValueAttr returns true, the in-memory ABI type is returned.
Definition: Function.cpp:185
bool hasInAllocaAttr() const
Return true if this argument has the inalloca attribute.
Definition: Function.cpp:128
bool hasSwiftErrorAttr() const
Return true if this argument has the swifterror attribute.
Definition: Function.cpp:124
FPClassTest getNoFPClass() const
If this argument has nofpclass attribute, return the mask representing disallowed floating-point valu...
Definition: Function.cpp:232
void addAttrs(AttrBuilder &B)
Add attributes to an argument.
Definition: Function.cpp:283
bool hasNoFreeAttr() const
Return true if this argument has the nofree attribute.
Definition: Function.cpp:251
bool hasSwiftSelfAttr() const
Return true if this argument has the swiftself attribute.
Definition: Function.cpp:120
Type * getParamInAllocaType() const
If this is an inalloca argument, return its type.
Definition: Function.cpp:215
bool hasZExtAttr() const
Return true if this argument has the zext attribute.
Definition: Function.cpp:269
unsigned getArgNo() const
Return the index of this formal argument in its containing function.
Definition: Argument.h:46
Type * getParamByValType() const
If this is a byval argument, return its type.
Definition: Function.cpp:200
bool hasNestAttr() const
Return true if this argument has the nest attribute.
Definition: Function.cpp:236
MaybeAlign getParamAlign() const
If this is a byval or inalloca argument, return its alignment.
Definition: Function.cpp:191
bool hasStructRetAttr() const
Return true if this argument has the sret attribute.
Definition: Function.cpp:256
bool hasPassPointeeByValueCopyAttr() const
Return true if this argument has the byval, inalloca, or preallocated attribute.
Definition: Function.cpp:139
MaybeAlign getParamStackAlign() const
Definition: Function.cpp:196
bool hasNoCaptureAttr() const
Return true if this argument has the nocapture attribute.
Definition: Function.cpp:246
uint64_t getDereferenceableBytes() const
If this argument has the dereferenceable attribute, return the number of bytes known to be dereferenc...
Definition: Function.cpp:220
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
const T & front() const
front - Get the first element.
Definition: ArrayRef.h:166
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:163
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:158
const T * data() const
Definition: ArrayRef.h:160
ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array.
Definition: ArrayRef.h:193
AttributeList addDereferenceableParamAttr(LLVMContext &C, unsigned ArgNo, uint64_t Bytes) const
Add the dereferenceable attribute to the attribute set at the given arg index.
AttributeList removeAttributeAtIndex(LLVMContext &C, unsigned Index, Attribute::AttrKind Kind) const
Remove the specified attribute at the specified index from this attribute list.
AttributeList removeParamAttributes(LLVMContext &C, unsigned ArgNo, const AttributeMask &AttrsToRemove) const
Remove the specified attribute at the specified arg index from this attribute list.
Definition: Attributes.h:695
AttributeList addRetAttribute(LLVMContext &C, Attribute::AttrKind Kind) const
Add a return value attribute to the list.
Definition: Attributes.h:554
AttributeList addRetAttributes(LLVMContext &C, const AttrBuilder &B) const
Add a return value attribute to the list.
Definition: Attributes.h:568
AttributeList removeRetAttributes(LLVMContext &C, const AttributeMask &AttrsToRemove) const
Remove the specified attribute at the return value index from this attribute list.
Definition: Attributes.h:672
Attribute getParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Return the attribute object that exists at the arg index.
Definition: Attributes.h:819
AttributeList addFnAttribute(LLVMContext &C, Attribute::AttrKind Kind) const
Add a function attribute to the list.
Definition: Attributes.h:525
AttributeList addFnAttributes(LLVMContext &C, const AttrBuilder &B) const
Add function attribute to the list.
Definition: Attributes.h:547
bool hasFnAttr(Attribute::AttrKind Kind) const
Return true if the attribute exists for the function.
Attribute getFnAttr(Attribute::AttrKind Kind) const
Return the attribute object that exists for the function.
Definition: Attributes.h:829
Attribute getAttributeAtIndex(unsigned Index, Attribute::AttrKind Kind) const
Return the attribute object that exists at the given index.
AttributeList removeParamAttribute(LLVMContext &C, unsigned ArgNo, Attribute::AttrKind Kind) const
Remove the specified attribute at the specified arg index from this attribute list.
Definition: Attributes.h:680
bool hasParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Return true if the attribute exists for the given argument.
Definition: Attributes.h:770
AttributeList removeFnAttribute(LLVMContext &C, Attribute::AttrKind Kind) const
Remove the specified attribute at the function index from this attribute list.
Definition: Attributes.h:631
AttributeList addDereferenceableOrNullParamAttr(LLVMContext &C, unsigned ArgNo, uint64_t Bytes) const
Add the dereferenceable_or_null attribute to the attribute set at the given arg index.
AttributeList removeFnAttributes(LLVMContext &C, const AttributeMask &AttrsToRemove) const
Remove the specified attribute at the function index from this attribute list.
Definition: Attributes.h:645
AttributeList addAttributeAtIndex(LLVMContext &C, unsigned Index, Attribute::AttrKind Kind) const
Add an attribute to the attribute set at the given index.
AttributeSet getParamAttrs(unsigned ArgNo) const
The attributes for the argument or parameter at the given index are returned.
AttributeList addParamAttributes(LLVMContext &C, unsigned ArgNo, const AttrBuilder &B) const
Add an argument attribute to the list.
Definition: Attributes.h:597
AttributeList removeRetAttribute(LLVMContext &C, Attribute::AttrKind Kind) const
Remove the specified attribute at the return value index from this attribute list.
Definition: Attributes.h:658
AttributeList addParamAttribute(LLVMContext &C, unsigned ArgNo, Attribute::AttrKind Kind) const
Add an argument attribute to the list.
Definition: Attributes.h:576
MemoryEffects getMemoryEffects() const
Returns memory effects of the function.
bool hasRetAttr(Attribute::AttrKind Kind) const
Return true if the attribute exists for the return value.
Definition: Attributes.h:785
Type * getInAllocaType() const
Definition: Attributes.cpp:826
Type * getByValType() const
Definition: Attributes.cpp:814
Type * getStructRetType() const
Definition: Attributes.cpp:818
Type * getPreallocatedType() const
Definition: Attributes.cpp:822
Type * getByRefType() const
Definition: Attributes.cpp:810
StringRef getValueAsString() const
Return the attribute's value as a string.
Definition: Attributes.cpp:317
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
Definition: Attributes.h:87
static Attribute getWithMemoryEffects(LLVMContext &Context, MemoryEffects ME)
Definition: Attributes.cpp:214
bool isValid() const
Return true if the attribute is any kind of attribute.
Definition: Attributes.h:187
LLVM Basic Block Representation.
Definition: BasicBlock.h:56
void dropAllReferences()
Cause all subinstructions to "let go" of all the references that said subinstructions are maintaining...
Definition: BasicBlock.cpp:287
This is the shared class of boolean and integer constants.
Definition: Constants.h:78
const APInt & getValue() const
Return the constant as an APInt value reference.
Definition: Constants.h:136
static ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
Definition: Constants.cpp:1691
This is an important base class in LLVM.
Definition: Constant.h:41
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:110
Implements a dense probed hash-table based set.
Definition: DenseSet.h:271
Class to represent function types.
Definition: DerivedTypes.h:103
ArrayRef< Type * > params() const
Definition: DerivedTypes.h:130
Type * getReturnType() const
Definition: DerivedTypes.h:124
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
Class to represent profile counts.
Definition: Function.h:252
uint64_t getCount() const
Definition: Function.h:260
ProfileCountType getType() const
Definition: Function.h:261
void addFnAttr(Attribute::AttrKind Kind)
Add function attributes to this function.
Definition: Function.cpp:554
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
Definition: Function.h:136
void addParamAttrs(unsigned ArgNo, const AttrBuilder &Attrs)
adds the attributes to the list of attributes for the given arg.
Definition: Function.cpp:590
void removeRetAttr(Attribute::AttrKind Kind)
removes the attribute from the return value list of attributes.
Definition: Function.cpp:614
void addRetAttrs(const AttrBuilder &Attrs)
Add return value attributes to this function.
Definition: Function.cpp:578
std::optional< StringRef > getSectionPrefix() const
Get the section prefix for this function.
Definition: Function.cpp:2087
bool isDefTriviallyDead() const
isDefTriviallyDead - Return true if it is trivially safe to remove this function definition from the ...
Definition: Function.cpp:1936
bool onlyAccessesInaccessibleMemOrArgMem() const
Determine if the function may only access memory that is either inaccessible from the IR or pointed t...
Definition: Function.cpp:823
void splice(Function::iterator ToIt, Function *FromF)
Transfer all blocks from FromF to this function at ToIt.
Definition: Function.h:697
BasicBlockListType::iterator iterator
Definition: Function.h:65
void removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
removes the attribute from the list of attributes.
Definition: Function.cpp:626
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Definition: Function.h:174
bool nullPointerIsDefined() const
Check if null pointer dereferencing is considered undefined behavior for the function.
Definition: Function.cpp:2098
void dropAllReferences()
dropAllReferences() - This method causes all the subinstructions to "let go" of all references that t...
Definition: Function.cpp:528
Attribute getParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const
gets the specified attribute from the list of attributes.
Definition: Function.cpp:692
void setPrefixData(Constant *PrefixData)
Definition: Function.cpp:1976
bool hasStackProtectorFnAttr() const
Returns true if the function has ssp, sspstrong, or sspreq fn attrs.
Definition: Function.cpp:748
void removeFromParent()
removeFromParent - This method unlinks 'this' from the containing module, but does not delete it.
Definition: Function.cpp:362
void addFnAttrs(const AttrBuilder &Attrs)
Add function attributes to this function.
Definition: Function.cpp:566
void setDoesNotAccessMemory()
Definition: Function.cpp:783
static Intrinsic::ID lookupIntrinsicID(StringRef Name)
This does the actual lookup of an intrinsic ID which matches the given function name.
Definition: Function.cpp:873
void setGC(std::string Str)
Definition: Function.cpp:736
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
Definition: Function.cpp:670
uint64_t getFnAttributeAsParsedInteger(StringRef Kind, uint64_t Default=0) const
For a string attribute Kind, parse attribute as an integer.
Definition: Function.cpp:678
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
Definition: Function.h:204
bool isConstrainedFPIntrinsic() const
Returns true if the function is one of the "Constrained Floating-Point Intrinsics".
Definition: Function.cpp:462
void setOnlyAccessesArgMemory()
Definition: Function.cpp:808
MemoryEffects getMemoryEffects() const
Definition: Function.cpp:772
void setOnlyAccessesInaccessibleMemory()
Definition: Function.cpp:817
void removeParamAttrs(unsigned ArgNo, const AttributeMask &Attrs)
removes the attribute from the list of attributes.
Definition: Function.cpp:634
void setIsMaterializable(bool V)
Definition: Function.h:192
uint64_t getParamDereferenceableBytes(unsigned ArgNo) const
Extract the number of dereferenceable bytes for a parameter.
Definition: Function.h:471
bool hasParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const
check if an attributes is in the list of attributes.
Definition: Function.cpp:656
void recalculateIntrinsicID()
Recalculate the ID for this function if it is an Intrinsic defined in llvm/Intrinsics....
Definition: Function.cpp:893
static Function * createWithDefaultAttr(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
Creates a function with some attributes recorded in llvm.module.flags applied.
Definition: Function.cpp:336
bool hasGC() const
hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm to use during code generatio...
Definition: Function.h:305
void setSectionPrefix(StringRef Prefix)
Set the section prefix for this function.
Definition: Function.cpp:2081
void setOnlyReadsMemory()
Definition: Function.cpp:791
bool isTargetIntrinsic() const
isTargetIntrinsic - Returns true if this function is an intrinsic and the intrinsic is specific to a ...
Definition: Function.cpp:848
Type * getParamByValType(unsigned ArgNo) const
Extract the byval type for a parameter.
Definition: Function.h:445
FPClassTest getParamNoFPClass(unsigned ArgNo) const
Extract the nofpclass attribute for a parameter.
Definition: Function.h:483
void removeFnAttrs(const AttributeMask &Attrs)
Definition: Function.cpp:610
DenormalMode getDenormalModeRaw() const
Return the representational value of "denormal-fp-math".
Definition: Function.cpp:715
bool hasPrefixData() const
Check whether this function has prefix data.
Definition: Function.h:822
bool hasPersonalityFn() const
Check whether this function has a personality function.
Definition: Function.h:813
void addRetAttr(Attribute::AttrKind Kind)
Add return value attributes to this function.
Definition: Function.cpp:570
DenormalMode getDenormalModeF32Raw() const
Return the representational value of "denormal-fp-math-f32".
Definition: Function.cpp:721
Constant * getPrologueData() const
Get the prologue data associated with this function.
Definition: Function.cpp:1981
Constant * getPersonalityFn() const
Get the personality function associated with this function.
Definition: Function.cpp:1961
void setOnlyWritesMemory()
Definition: Function.cpp:799
void setPersonalityFn(Constant *Fn)
Definition: Function.cpp:1966
AttributeList getAttributes() const
Return the attribute list for this Function.
Definition: Function.h:313
DenseSet< GlobalValue::GUID > getImportGUIDs() const
Returns the set of GUIDs that needs to be imported to the function for sample PGO,...
Definition: Function.cpp:2069
Type * getParamByRefType(unsigned ArgNo) const
Extract the byref type for a parameter.
Definition: Function.h:460
void removeAttributeAtIndex(unsigned i, Attribute::AttrKind Kind)
removes the attribute from the list of attributes.
Definition: Function.cpp:594
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it.
Definition: Function.cpp:366
uint64_t getParamDereferenceableOrNullBytes(unsigned ArgNo) const
Extract the number of dereferenceable_or_null bytes for a parameter.
Definition: Function.h:478
void removeFnAttr(Attribute::AttrKind Kind)
Remove function attributes from this function.
Definition: Function.cpp:602
void addDereferenceableOrNullParamAttr(unsigned ArgNo, uint64_t Bytes)
adds the dereferenceable_or_null attribute to the list of attributes for the given arg.
Definition: Function.cpp:697
MaybeAlign getParamAlign(unsigned ArgNo) const
Definition: Function.h:436
void stealArgumentListFrom(Function &Src)
Steal arguments from another function.
Definition: Function.cpp:483
void setAttributes(AttributeList Attrs)
Set the attribute list for this Function.
Definition: Function.h:316
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
Definition: Function.cpp:319
const std::string & getGC() const
Definition: Function.cpp:731
void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
adds the attribute to the list of attributes for the given arg.
Definition: Function.cpp:582
bool doesNotAccessMemory() const
Determine if the function does not access memory.
Definition: Function.cpp:780
DenormalMode getDenormalMode(const fltSemantics &FPType) const
Returns the denormal handling type for the default rounding mode of the function.
Definition: Function.cpp:703
Type * getParamInAllocaType(unsigned ArgNo) const
Extract the inalloca type for a parameter.
Definition: Function.h:455
bool callsFunctionThatReturnsTwice() const
callsFunctionThatReturnsTwice - Return true if the function has a call to setjmp or other function th...
Definition: Function.cpp:1952
bool hasRetAttribute(Attribute::AttrKind Kind) const
check if an attribute is in the list of attributes for the return value.
Definition: Function.cpp:652
bool onlyWritesMemory() const
Determine if the function does not access or only writes memory.
Definition: Function.cpp:796
std::optional< ProfileCount > getEntryCount(bool AllowSynthetic=false) const
Get the entry count for this function.
Definition: Function.cpp:2047
bool onlyAccessesInaccessibleMemory() const
Determine if the function may only access memory that is inaccessible from the IR.
Definition: Function.cpp:814
MaybeAlign getParamStackAlign(unsigned ArgNo) const
Definition: Function.h:440
size_t arg_size() const
Definition: Function.h:809
void setPrologueData(Constant *PrologueData)
Definition: Function.cpp:1986
bool hasAddressTaken(const User **=nullptr, bool IgnoreCallbackUses=false, bool IgnoreAssumeLikeCalls=true, bool IngoreLLVMUsed=false, bool IgnoreARCAttachedCall=false) const
hasAddressTaken - returns true if there are any uses of this function other than direct calls or invo...
Definition: Function.cpp:1870
void removeRetAttrs(const AttributeMask &Attrs)
removes the attributes from the return value list of attributes.
Definition: Function.cpp:622
void clearGC()
Definition: Function.cpp:741
bool hasLazyArguments() const
hasLazyArguments/CheckLazyArguments - The argument list of a function is built on demand,...
Definition: Function.h:105
bool onlyAccessesArgMemory() const
Determine if the call can access memmory only using pointers based on its arguments.
Definition: Function.cpp:805
Function::iterator erase(Function::iterator FromIt, Function::iterator ToIt)
Erases a range of BasicBlocks from FromIt to (not including) ToIt.
Definition: Function.cpp:382
void setMemoryEffects(MemoryEffects ME)
Definition: Function.cpp:775
Constant * getPrefixData() const
Get the prefix data associated with this function.
Definition: Function.cpp:1971
Attribute getAttributeAtIndex(unsigned i, Attribute::AttrKind Kind) const
gets the attribute from the list of attributes.
Definition: Function.cpp:661
iterator end()
Definition: Function.h:763
void setCallingConv(CallingConv::ID CC)
Definition: Function.h:241
void setOnlyAccessesInaccessibleMemOrArgMem()
Definition: Function.cpp:826
bool hasPrologueData() const
Check whether this function has prologue data.
Definition: Function.h:831
Type * getParamStructRetType(unsigned ArgNo) const
Extract the sret type for a parameter.
Definition: Function.h:450
void setEntryCount(ProfileCount Count, const DenseSet< GlobalValue::GUID > *Imports=nullptr)
Set the entry count for this function.
Definition: Function.cpp:2025
void addDereferenceableParamAttr(unsigned ArgNo, uint64_t Bytes)
adds the dereferenceable attribute to the list of attributes for the given arg.
Definition: Function.cpp:639
unsigned getInstructionCount() const
Returns the number of non-debug IR instructions in this function.
Definition: Function.cpp:323
bool onlyReadsMemory() const
Determine if the function does not access or only reads memory.
Definition: Function.cpp:788
void addAttributeAtIndex(unsigned i, Attribute Attr)
adds the attribute to the list of attributes.
Definition: Function.cpp:550
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition: Function.cpp:644
void copyAttributesFrom(const Function *Src)
copyAttributesFrom - copy all additional attributes (those not needed to create a Function) from the ...
Definition: Function.cpp:756
void setMetadata(unsigned KindID, MDNode *Node)
Set a particular kind of metadata attachment.
Definition: Metadata.cpp:1391
MDNode * getMetadata(unsigned KindID) const
Get the current metadata attachments for the given kind, if any.
Definition: Metadata.cpp:1354
void copyAttributesFrom(const GlobalObject *Src)
Definition: Globals.cpp:138
void clearMetadata()
Erase all metadata attached to this Value.
Definition: Metadata.cpp:1448
bool hasLinkOnceLinkage() const
Definition: GlobalValue.h:510
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Definition: Globals.cpp:273
bool hasLocalLinkage() const
Definition: GlobalValue.h:523
Intrinsic::ID IntID
The intrinsic ID for this subclass (which must be a Function).
Definition: GlobalValue.h:169
unsigned HasLLVMReservedName
True if the function's name starts with "llvm.".
Definition: GlobalValue.h:105
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:652
PointerType * getType() const
Global values are always pointers.
Definition: GlobalValue.h:290
unsigned Linkage
Definition: GlobalValue.h:94
bool hasAvailableExternallyLinkage() const
Definition: GlobalValue.h:507
LinkageTypes
An enumeration for the kinds of linkage for global values.
Definition: GlobalValue.h:47
Class to represent integer types.
Definition: DerivedTypes.h:40
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition: Type.cpp:339
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
Definition: DerivedTypes.h:72
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
void deleteGC(const Function &Fn)
Remove the GC for a function.
const std::string & getGC(const Function &Fn)
Return the GC for a function.
void setGC(const Function &Fn, std::string GCName)
Define the GC for a function.
void emitError(uint64_t LocCookie, const Twine &ErrorStr)
emitError - Emit an error message to the currently installed error handler with optional location inf...
MDNode * createFunctionEntryCount(uint64_t Count, bool Synthetic, const DenseSet< GlobalValue::GUID > *Imports)
Return metadata containing the entry Count for a function, a boolean \Synthetic indicating whether th...
Definition: MDBuilder.cpp:59
MDNode * createFunctionSectionPrefix(StringRef Prefix)
Return metadata containing the section prefix for a function.
Definition: MDBuilder.cpp:78
Metadata node.
Definition: Metadata.h:950
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:1303
A single uniqued string.
Definition: Metadata.h:611
Summary of how a function affects memory in the program.
Definition: ModRef.h:63
bool onlyAccessesArgPointees() const
Whether this function only (at most) accesses argument memory.
Definition: ModRef.h:200
static MemoryEffects writeOnly()
Create MemoryEffects that can write any memory.
Definition: ModRef.h:128
static MemoryEffects readOnly()
Create MemoryEffects that can read any memory.
Definition: ModRef.h:123
static MemoryEffects inaccessibleMemOnly(ModRefInfo MR=ModRefInfo::ModRef)
Create MemoryEffects that can only access inaccessible memory.
Definition: ModRef.h:138
bool onlyReadsMemory() const
Whether this function only (at most) reads memory.
Definition: ModRef.h:194
bool onlyWritesMemory() const
Whether this function only (at most) writes memory.
Definition: ModRef.h:197
static MemoryEffects inaccessibleOrArgMemOnly(ModRefInfo MR=ModRefInfo::ModRef)
Create MemoryEffects that can only access inaccessible or argument memory.
Definition: ModRef.h:144
bool onlyAccessesInaccessibleMem() const
Whether this function only (at most) accesses inaccessible memory.
Definition: ModRef.h:210
bool doesNotAccessMemory() const
Whether this function accesses no memory.
Definition: ModRef.h:191
bool onlyAccessesInaccessibleOrArgMem() const
Whether this function only (at most) accesses argument and inaccessible memory.
Definition: ModRef.h:216
static MemoryEffects none()
Create MemoryEffects that cannot read or write any memory.
Definition: ModRef.h:118
static MemoryEffects argMemOnly(ModRefInfo MR=ModRefInfo::ModRef)
Create MemoryEffects that can only access argument memory.
Definition: ModRef.h:133
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
const FunctionListType & getFunctionList() const
Get the Module's list of functions (constant).
Definition: Module.h:579
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:305
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
Definition: DerivedTypes.h:662
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:26
bool empty() const
Definition: SmallVector.h:94
size_t size() const
Definition: SmallVector.h:91
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:577
reference emplace_back(ArgTypes &&... Args)
Definition: SmallVector.h:941
void push_back(const T &Elt)
Definition: SmallVector.h:416
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1200
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
bool startswith(StringRef Prefix) const
Definition: StringRef.h:261
Class to represent struct types.
Definition: DerivedTypes.h:213
static StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
Definition: Type.cpp:434
Class to represent target extensions types, which are generally unintrospectable from target-independ...
Definition: DerivedTypes.h:750
static TargetExtType * get(LLVMContext &Context, StringRef Name, ArrayRef< Type * > Types=std::nullopt, ArrayRef< unsigned > Ints=std::nullopt)
Return a target extension type having the specified name and optional type and integer parameters.
Definition: Type.cpp:877
Target - Wrapper for Target specific information.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
static Type * getHalfTy(LLVMContext &C)
static Type * getDoubleTy(LLVMContext &C)
static PointerType * getInt1PtrTy(LLVMContext &C, unsigned AS=0)
static Type * getBFloatTy(LLVMContext &C)
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
Definition: Type.h:235
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
Definition: Type.h:154
static Type * getX86_AMXTy(LLVMContext &C)
bool isBFloatTy() const
Return true if this is 'bfloat', a 16-bit bfloat type.
Definition: Type.h:146
static Type * getMetadataTy(LLVMContext &C)
@ X86_MMXTyID
MMX vectors (64 bits, X86 specific)
Definition: Type.h:66
@ X86_AMXTyID
AMX vectors (8192 bits, X86 specific)
Definition: Type.h:67
@ HalfTyID
16-bit floating point type
Definition: Type.h:56
@ VoidTyID
type with no size
Definition: Type.h:63
@ FloatTyID
32-bit floating point type
Definition: Type.h:58
@ IntegerTyID
Arbitrary bit width integers.
Definition: Type.h:71
@ BFloatTyID
16-bit floating point type (7-bit significand)
Definition: Type.h:57
@ DoubleTyID
64-bit floating point type
Definition: Type.h:59
@ X86_FP80TyID
80-bit floating point type (X87)
Definition: Type.h:60
@ PPC_FP128TyID
128-bit floating point type (two 64-bits, PowerPC)
Definition: Type.h:62
@ MetadataTyID
Metadata.
Definition: Type.h:65
@ FP128TyID
128-bit floating point type (112-bit significand)
Definition: Type.h:61
bool isX86_MMXTy() const
Return true if this is X86 MMX.
Definition: Type.h:201
bool isPPC_FP128Ty() const
Return true if this is powerpc long double.
Definition: Type.h:166
static Type * getX86_MMXTy(LLVMContext &C)
bool isFP128Ty() const
Return true if this is 'fp128'.
Definition: Type.h:163
static Type * getVoidTy(LLVMContext &C)
static Type * getFP128Ty(LLVMContext &C)
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
Definition: Type.h:143
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition: Type.h:129
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
Definition: Type.h:157
static Type * getTokenTy(LLVMContext &C)
bool isX86_AMXTy() const
Return true if this is X86 AMX.
Definition: Type.h:204
static Type * getFloatTy(LLVMContext &C)
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition: Type.h:229
TypeID getTypeID() const
Return the type id for the type.
Definition: Type.h:137
bool isTokenTy() const
Return true if this is 'token'.
Definition: Type.h:226
bool isFPOrFPVectorTy() const
Return true if this is a FP type or a vector of FP.
Definition: Type.h:217
static Type * getPPC_FP128Ty(LLVMContext &C)
bool isVoidTy() const
Return true if this is 'void'.
Definition: Type.h:140
bool isMetadataTy() const
Return true if this is 'metadata'.
Definition: Type.h:223
A Use represents the edge between a Value definition and its users.
Definition: Use.h:43
void allocHungoffUses(unsigned N, bool IsPhi=false)
Allocate the array of Uses, followed by a pointer (with bottom bit set) to the User.
Definition: User.cpp:50
void dropAllReferences()
Drop all references to operands.
Definition: User.h:299
void setNumHungOffUseOperands(unsigned NumOps)
Subclasses with hung off uses need to manage the operand count themselves.
Definition: User.h:215
unsigned getNumOperands() const
Definition: User.h:191
LLVM Value Representation.
Definition: Value.h:74
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
unsigned short getSubclassDataFromValue() const
Definition: Value.h:854
user_iterator user_begin()
Definition: Value.h:397
void setName(const Twine &Name)
Change the name of the value.
Definition: Value.cpp:378
bool hasOneUse() const
Return true if there is exactly one use of this value.
Definition: Value.h:434
iterator_range< user_iterator > users()
Definition: Value.h:421
iterator_range< use_iterator > uses()
Definition: Value.h:376
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:309
bool user_empty() const
Definition: Value.h:385
static VectorType * getHalfElementsVectorType(VectorType *VTy)
This static method returns a VectorType with half as many elements as the input type and the same ele...
Definition: DerivedTypes.h:504
static VectorType * getExtendedElementVectorType(VectorType *VTy)
This static method is like getInteger except that the element types are twice as wide as the elements...
Definition: DerivedTypes.h:460
static VectorType * getSubdividedVectorType(VectorType *VTy, int NumSubdivs)
Definition: DerivedTypes.h:494
static VectorType * getInteger(VectorType *VTy)
This static method gets a VectorType with the same number of elements as the input type,...
Definition: DerivedTypes.h:451
static VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
Definition: Type.cpp:738
static VectorType * getTruncatedElementVectorType(VectorType *VTy)
Definition: DerivedTypes.h:469
size_type size() const
Definition: DenseSet.h:81
self_iterator getIterator()
Definition: ilist_node.h:82
void splice(iterator where, iplist_impl &L2)
Definition: ilist.h:266
void push_back(pointer val)
Definition: ilist.h:250
iterator erase(iterator where)
Definition: ilist.h:204
pointer remove(iterator &IT)
Definition: ilist.h:188
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type * > Tys=std::nullopt)
Return the function type for an intrinsic.
Definition: Function.cpp:1433
MatchIntrinsicTypesResult matchIntrinsicSignature(FunctionType *FTy, ArrayRef< IITDescriptor > &Infos, SmallVectorImpl< Type * > &ArgTys)
Match the specified function type with the type constraints specified by the .td file.
Definition: Function.cpp:1767
void getIntrinsicInfoTableEntries(ID id, SmallVectorImpl< IITDescriptor > &T)
Return the IIT table descriptor for the specified intrinsic into an array of IITDescriptors.
Definition: Function.cpp:1293
@ MatchIntrinsicTypes_Match
Definition: Intrinsics.h:214
@ MatchIntrinsicTypes_NoMatchRet
Definition: Intrinsics.h:215
@ MatchIntrinsicTypes_NoMatchArg
Definition: Intrinsics.h:216
int lookupLLVMIntrinsicByName(ArrayRef< const char * > NameTable, StringRef Name)
Looks up Name in NameTable via binary search.
std::string getNameNoUnnamedTypes(ID Id, ArrayRef< Type * > Tys)
Return the LLVM name for an intrinsic.
Definition: Function.cpp:1032
std::optional< Function * > remangleIntrinsicFunction(Function *F)
Definition: Function.cpp:1833
StringRef getName(ID id)
Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
Definition: Function.cpp:992
bool getIntrinsicSignature(Function *F, SmallVectorImpl< Type * > &ArgTys)
Gets the type arguments of an intrinsic call by matching type contraints specified by the ....
Definition: Function.cpp:1812
AttributeList getAttributes(LLVMContext &C, ID id)
Return the attributes for an intrinsic.
StringRef getBaseName(ID id)
Return the LLVM name for an intrinsic, without encoded types for overloading, such as "llvm....
Definition: Function.cpp:987
bool isOverloaded(ID id)
Returns true if the intrinsic can be overloaded.
Definition: Function.cpp:1454
Function * getDeclaration(Module *M, ID id, ArrayRef< Type * > Tys=std::nullopt)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
Definition: Function.cpp:1465
bool matchIntrinsicVarArg(bool isVarArg, ArrayRef< IITDescriptor > &Infos)
Verify if the intrinsic has variable arguments.
Definition: Function.cpp:1793
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:445
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1819
auto partition_point(R &&Range, Predicate P)
Binary search for the first iterator in a range where a predicate is false.
Definition: STLExtras.h:2076
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1826
UWTableKind
Definition: CodeGen.h:121
@ None
No unwind table requested.
FPClassTest
Floating-point class tests, supported by 'is_fpclass' intrinsic.
bool NullPointerIsDefined(const Function *F, unsigned AS=0)
Check whether null pointer dereferencing is considered undefined behavior for a given function or an ...
Definition: Function.cpp:2102
DenormalMode parseDenormalFPAttribute(StringRef Str)
Returns the denormal mode to use for inputs and outputs.
@ Default
The result values are uniform if and only if all operands are uniform.
#define N
static const fltSemantics & IEEEsingle() LLVM_READNONE
Definition: APFloat.cpp:244
Helper struct shared between Function Specialization and SCCP Solver.
Definition: SCCPSolver.h:43
Represent subnormal handling kind for floating point instruction inputs and outputs.
static constexpr DenormalMode getInvalid()
This is a type descriptor which explains the type requirements of an intrinsic.
Definition: Intrinsics.h:110
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition: Alignment.h:117
Compile-time customization of User operands.
Definition: User.h:42