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