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