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