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