LLVM 24.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"
14#include "IROptions.h"
16#include "llvm/ADT/ArrayRef.h"
17#include "llvm/ADT/BitVector.h"
18#include "llvm/ADT/DenseSet.h"
19#include "llvm/ADT/STLExtras.h"
22#include "llvm/ADT/StringRef.h"
24#include "llvm/IR/Argument.h"
25#include "llvm/IR/Attributes.h"
26#include "llvm/IR/BasicBlock.h"
27#include "llvm/IR/Constant.h"
29#include "llvm/IR/Constants.h"
31#include "llvm/IR/GlobalValue.h"
33#include "llvm/IR/Instruction.h"
35#include "llvm/IR/Intrinsics.h"
36#include "llvm/IR/LLVMContext.h"
37#include "llvm/IR/MDBuilder.h"
38#include "llvm/IR/Metadata.h"
39#include "llvm/IR/Module.h"
40#include "llvm/IR/Operator.h"
43#include "llvm/IR/Type.h"
44#include "llvm/IR/Use.h"
45#include "llvm/IR/User.h"
46#include "llvm/IR/Value.h"
51#include "llvm/Support/ModRef.h"
52#include <cassert>
53#include <cstddef>
54#include <cstdint>
55#include <cstring>
56#include <string>
57
58using namespace llvm;
59
60// Explicit instantiations of SymbolTableListTraits since some of the methods
61// are not in the public header file...
63
65 validateBlockNumbers();
66
67 NextBlockNum = 0;
68 for (auto &BB : *this)
69 BB.Number = NextBlockNum++;
70 BlockNumEpoch++;
71}
72
73void Function::validateBlockNumbers() const {
74#ifndef NDEBUG
75 BitVector Numbers(NextBlockNum);
76 for (const auto &BB : *this) {
77 unsigned Num = BB.getNumber();
78 assert(Num < NextBlockNum && "out of range block number");
79 assert(!Numbers[Num] && "duplicate block numbers");
80 Numbers.set(Num);
81 }
82#endif
83}
84
86 for (auto &BB : *this) {
87 BB.convertToNewDbgValues();
88 }
89}
90
92 bool Modified = false;
93 for (auto &BB : *this) {
94 if (BB.convertFromNewDbgValues())
95 Modified = true;
96 }
97 return Modified;
98}
99
100//===----------------------------------------------------------------------===//
101// Argument Implementation
102//===----------------------------------------------------------------------===//
103
104Argument::Argument(Type *Ty, const Twine &Name, Function *Par, unsigned ArgNo)
105 : Value(Ty, Value::ArgumentVal), Parent(Par), ArgNo(ArgNo) {
106 setName(Name);
107}
108
109void Argument::setParent(Function *parent) {
110 Parent = parent;
111}
112
113bool Argument::hasNonNullAttr(bool AllowUndefOrPoison) const {
114 if (!getType()->isPointerTy()) return false;
116 if (Attrs.hasAttribute(Attribute::NonNull) &&
117 (AllowUndefOrPoison || Attrs.hasAttribute(Attribute::NoUndef)))
118 return true;
119 else if (getDereferenceableBytes() > 0 &&
122 return true;
123 return false;
124}
125
126bool Argument::hasByValAttr() const {
127 if (!getType()->isPointerTy()) return false;
128 return hasAttribute(Attribute::ByVal);
129}
130
132 assert(getType()->isPointerTy() && "Only pointers have dead_on_return bytes");
133 return getParent()->getDeadOnReturnInfo(getArgNo());
134}
135
136bool Argument::hasByRefAttr() const {
137 if (!getType()->isPointerTy())
138 return false;
139 return hasAttribute(Attribute::ByRef);
140}
141
142bool Argument::hasSwiftSelfAttr() const {
143 return getParent()->hasParamAttribute(getArgNo(), Attribute::SwiftSelf);
144}
145
146bool Argument::hasSwiftErrorAttr() const {
147 return getParent()->hasParamAttribute(getArgNo(), Attribute::SwiftError);
148}
149
150bool Argument::hasInAllocaAttr() const {
151 if (!getType()->isPointerTy()) return false;
152 return hasAttribute(Attribute::InAlloca);
153}
154
156 if (!getType()->isPointerTy())
157 return false;
158 return hasAttribute(Attribute::Preallocated);
159}
160
162 if (!getType()->isPointerTy()) return false;
164 return Attrs.hasAttribute(Attribute::ByVal) ||
165 Attrs.hasAttribute(Attribute::InAlloca) ||
166 Attrs.hasAttribute(Attribute::Preallocated);
167}
168
170 if (!getType()->isPointerTy())
171 return false;
173 return Attrs.hasAttribute(Attribute::ByVal) ||
174 Attrs.hasAttribute(Attribute::StructRet) ||
175 Attrs.hasAttribute(Attribute::InAlloca) ||
176 Attrs.hasAttribute(Attribute::Preallocated) ||
177 Attrs.hasAttribute(Attribute::ByRef);
178}
179
180/// For a byval, sret, inalloca, or preallocated parameter, get the in-memory
181/// parameter type.
182static Type *getMemoryParamAllocType(AttributeSet ParamAttrs) {
183 // FIXME: All the type carrying attributes are mutually exclusive, so there
184 // should be a single query to get the stored type that handles any of them.
185 if (Type *ByValTy = ParamAttrs.getByValType())
186 return ByValTy;
187 if (Type *ByRefTy = ParamAttrs.getByRefType())
188 return ByRefTy;
189 if (Type *PreAllocTy = ParamAttrs.getPreallocatedType())
190 return PreAllocTy;
191 if (Type *InAllocaTy = ParamAttrs.getInAllocaType())
192 return InAllocaTy;
193 if (Type *SRetTy = ParamAttrs.getStructRetType())
194 return SRetTy;
195
196 return nullptr;
197}
198
200 if (Type *MemTy = getMemoryParamAllocType(getAttributes()))
201 return DL.getTypeAllocSize(MemTy);
202 return 0;
203}
204
207}
208
210 assert(getType()->isPointerTy() && "Only pointers have alignments");
211 return getParent()->getParamAlign(getArgNo());
212}
213
215 return getParent()->getParamStackAlign(getArgNo());
216}
217
218Type *Argument::getParamByValType() const {
219 assert(getType()->isPointerTy() && "Only pointers have byval types");
220 return getParent()->getParamByValType(getArgNo());
221}
222
224 assert(getType()->isPointerTy() && "Only pointers have sret types");
225 return getParent()->getParamStructRetType(getArgNo());
226}
227
228Type *Argument::getParamByRefType() const {
229 assert(getType()->isPointerTy() && "Only pointers have byref types");
230 return getParent()->getParamByRefType(getArgNo());
231}
232
233Type *Argument::getParamInAllocaType() const {
234 assert(getType()->isPointerTy() && "Only pointers have inalloca types");
235 return getParent()->getParamInAllocaType(getArgNo());
236}
237
240 "Only pointers have dereferenceable bytes");
241 return getParent()->getParamDereferenceableBytes(getArgNo());
242}
243
246 "Only pointers have dereferenceable bytes");
247 return getParent()->getParamDereferenceableOrNullBytes(getArgNo());
248}
249
250FPClassTest Argument::getNoFPClass() const {
251 return getParent()->getParamNoFPClass(getArgNo());
252}
253
254std::optional<ConstantRange> Argument::getRange() const {
255 const Attribute RangeAttr = getAttribute(llvm::Attribute::Range);
256 if (RangeAttr.isValid())
257 return RangeAttr.getRange();
258 return std::nullopt;
259}
260
261bool Argument::hasNestAttr() const {
262 if (!getType()->isPointerTy()) return false;
263 return hasAttribute(Attribute::Nest);
264}
265
266bool Argument::hasNoAliasAttr() const {
267 if (!getType()->isPointerTy()) return false;
268 return hasAttribute(Attribute::NoAlias);
269}
270
271bool Argument::hasNoCaptureAttr() const {
272 if (!getType()->isPointerTy()) return false;
273 return capturesNothing(getAttributes().getCaptureInfo());
274}
275
276bool Argument::hasNoFreeAttr() const {
277 if (!getType()->isPointerTy()) return false;
278 return hasAttribute(Attribute::NoFree);
279}
280
281bool Argument::hasStructRetAttr() const {
282 if (!getType()->isPointerTy()) return false;
283 return hasAttribute(Attribute::StructRet);
284}
285
286bool Argument::hasInRegAttr() const {
287 return hasAttribute(Attribute::InReg);
288}
289
290bool Argument::hasReturnedAttr() const {
291 return hasAttribute(Attribute::Returned);
292}
293
294bool Argument::hasZExtAttr() const {
295 return hasAttribute(Attribute::ZExt);
296}
297
298bool Argument::hasSExtAttr() const {
299 return hasAttribute(Attribute::SExt);
300}
301
302bool Argument::onlyReadsMemory() const {
304 return Attrs.hasAttribute(Attribute::ReadOnly) ||
305 Attrs.hasAttribute(Attribute::ReadNone);
306}
307
308void Argument::addAttrs(AttrBuilder &B) {
309 AttributeList AL = getParent()->getAttributes();
310 AL = AL.addParamAttributes(Parent->getContext(), getArgNo(), B);
311 getParent()->setAttributes(AL);
312}
313
315 getParent()->addParamAttr(getArgNo(), Kind);
316}
317
318void Argument::addAttr(Attribute Attr) {
319 getParent()->addParamAttr(getArgNo(), Attr);
320}
321
323 getParent()->removeParamAttr(getArgNo(), Kind);
324}
325
326void Argument::removeAttrs(const AttributeMask &AM) {
327 AttributeList AL = getParent()->getAttributes();
328 AL = AL.removeParamAttributes(Parent->getContext(), getArgNo(), AM);
329 getParent()->setAttributes(AL);
330}
331
333 return getParent()->hasParamAttribute(getArgNo(), Kind);
334}
335
336bool Argument::hasAttribute(StringRef Kind) const {
337 return getParent()->hasParamAttribute(getArgNo(), Kind);
338}
339
340Attribute Argument::getAttribute(Attribute::AttrKind Kind) const {
341 return getParent()->getParamAttribute(getArgNo(), Kind);
342}
343
345 return getParent()->getAttributes().getParamAttrs(getArgNo());
346}
347
348//===----------------------------------------------------------------------===//
349// Helper Methods in Function
350//===----------------------------------------------------------------------===//
351
353 return getType()->getContext();
354}
355
356const DataLayout &Function::getDataLayout() const {
357 return getParent()->getDataLayout();
358}
359
360unsigned Function::getInstructionCount() const {
361 unsigned NumInstrs = 0;
362 for (const BasicBlock &BB : BasicBlocks)
363 NumInstrs += BB.size();
364 return NumInstrs;
365}
366
368 const Twine &N, Module &M) {
369 return Create(Ty, Linkage, M.getDataLayout().getProgramAddressSpace(), N, &M);
370}
371
373 LinkageTypes Linkage,
374 unsigned AddrSpace, const Twine &N,
375 Module *M) {
376 auto *F = new (AllocMarker) Function(Ty, Linkage, AddrSpace, N, M);
377 AttrBuilder B(F->getContext());
378 UWTableKind UWTable = M->getUwtable();
379 if (UWTable != UWTableKind::None)
380 B.addUWTableAttr(UWTable);
381 switch (M->getFramePointer()) {
383 // 0 ("none") is the default.
384 break;
386 B.addAttribute("frame-pointer", "reserved");
387 break;
389 B.addAttribute("frame-pointer", "non-leaf");
390 break;
392 B.addAttribute("frame-pointer", "non-leaf-no-reserve");
393 break;
395 B.addAttribute("frame-pointer", "all");
396 break;
397 }
398 if (M->getModuleFlag("function_return_thunk_extern"))
399 B.addAttribute(Attribute::FnRetThunkExtern);
400 StringRef DefaultCPU = F->getContext().getDefaultTargetCPU();
401 if (!DefaultCPU.empty())
402 B.addAttribute("target-cpu", DefaultCPU);
403 StringRef DefaultFeatures = F->getContext().getDefaultTargetFeatures();
404 if (!DefaultFeatures.empty())
405 B.addAttribute("target-features", DefaultFeatures);
406
407 // Check if the module attribute is present and not zero.
408 auto isModuleAttributeSet = [&](const StringRef &ModAttr) -> bool {
409 const auto *Attr =
410 mdconst::extract_or_null<ConstantInt>(M->getModuleFlag(ModAttr));
411 return Attr && !Attr->isZero();
412 };
413
414 auto AddAttributeIfSet = [&](const StringRef &ModAttr) {
415 if (isModuleAttributeSet(ModAttr))
416 B.addAttribute(ModAttr);
417 };
418
419 StringRef SignType = "none";
420 if (isModuleAttributeSet("sign-return-address"))
421 SignType = "non-leaf";
422 if (isModuleAttributeSet("sign-return-address-all"))
423 SignType = "all";
424 if (SignType != "none") {
425 B.addAttribute("sign-return-address", SignType);
426 B.addAttribute("sign-return-address-key",
427 isModuleAttributeSet("sign-return-address-with-bkey")
428 ? "b_key"
429 : "a_key");
430 }
431
432 if (auto Value = dyn_cast_if_present<MDString>(
433 M->getModuleFlag("sign-return-address-harden")))
434 B.addAttribute("sign-return-address-harden", Value->getString());
435 AddAttributeIfSet("branch-target-enforcement");
436 AddAttributeIfSet("branch-protection-pauth-lr");
437 AddAttributeIfSet("guarded-control-stack");
438 AddAttributeIfSet("ptrauth-returns");
439 AddAttributeIfSet("ptrauth-auth-traps");
440 AddAttributeIfSet("ptrauth-indirect-gotos");
441 AddAttributeIfSet("aarch64-jump-table-hardening");
442
443 F->addFnAttrs(B);
444 return F;
445}
446
448 getParent()->getFunctionList().remove(getIterator());
449}
450
452 getParent()->getFunctionList().erase(getIterator());
453}
454
456 Function::iterator FromBeginIt,
457 Function::iterator FromEndIt) {
458#ifdef EXPENSIVE_CHECKS
459 // Check that FromBeginIt is before FromEndIt.
460 auto FromFEnd = FromF->end();
461 for (auto It = FromBeginIt; It != FromEndIt; ++It)
462 assert(It != FromFEnd && "FromBeginIt not before FromEndIt!");
463#endif // EXPENSIVE_CHECKS
464 BasicBlocks.splice(ToIt, FromF->BasicBlocks, FromBeginIt, FromEndIt);
465}
466
468 Function::iterator ToIt) {
469 return BasicBlocks.erase(FromIt, ToIt);
470}
471
472//===----------------------------------------------------------------------===//
473// Function Implementation
474//===----------------------------------------------------------------------===//
475
476static unsigned computeAddrSpace(unsigned AddrSpace, Module *M) {
477 // If AS == -1 and we are passed a valid module pointer we place the function
478 // in the program address space. Otherwise we default to AS0.
479 if (AddrSpace == static_cast<unsigned>(-1))
480 return M ? M->getDataLayout().getProgramAddressSpace() : 0;
481 return AddrSpace;
482}
483
484Function::Function(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace,
485 const Twine &name, Module *ParentModule)
486 : GlobalObject(Ty, Value::FunctionVal, AllocMarker, Linkage, name,
487 computeAddrSpace(AddrSpace, ParentModule)),
488 NumArgs(Ty->getNumParams()) {
489 assert(FunctionType::isValidReturnType(getReturnType()) &&
490 "invalid return type");
491 setGlobalObjectSubClassData(0);
492
493 // We only need a symbol table for a function if the context keeps value names
494 if (!getContext().shouldDiscardValueNames())
495 SymTab = std::make_unique<ValueSymbolTable>(
496 getIROptions(getContext()).non_global_value_max_name_size);
497
498 // If the function has arguments, mark them as lazily built.
499 if (Ty->getNumParams())
500 setValueSubclassData(1); // Set the "has lazy arguments" bit.
501
502 if (ParentModule) {
503 ParentModule->getFunctionList().push_back(this);
504 }
505
506 HasLLVMReservedName = getName().starts_with("llvm.");
507 // Ensure intrinsics have the right parameter attributes.
508 // Note, the IntID field will have been set in Value::setName if this function
509 // name is a valid intrinsic ID.
510 if (IntID) {
511 // Don't set the attributes if the intrinsic signature is invalid. This
512 // case will either be auto-upgraded or fail verification.
513 SmallVector<Type *> OverloadTys;
514 if (!Intrinsic::isSignatureValid(IntID, Ty, OverloadTys))
515 return;
516
517 setAttributes(Intrinsic::getAttributes(getContext(), IntID, Ty));
518 }
519}
520
522 validateBlockNumbers();
523
524 dropAllReferences(); // After this it is safe to delete instructions.
525
526 // Delete all of the method arguments and unlink from symbol table...
527 if (Arguments)
528 clearArguments();
529
530 // Remove the function from the on-the-side GC table.
531 clearGC();
532}
533
534void Function::BuildLazyArguments() const {
535 // Create the arguments vector, all arguments start out unnamed.
536 auto *FT = getFunctionType();
537 if (NumArgs > 0) {
538 Arguments = std::allocator<Argument>().allocate(NumArgs);
539 for (unsigned i = 0, e = NumArgs; i != e; ++i) {
540 Type *ArgTy = FT->getParamType(i);
541 assert(!ArgTy->isVoidTy() && "Cannot have void typed arguments!");
542 new (Arguments + i) Argument(ArgTy, "", const_cast<Function *>(this), i);
543 }
544 }
545
546 // Clear the lazy arguments bit.
547 unsigned SDC = getSubclassDataFromValue();
548 SDC &= ~(1 << 0);
549 const_cast<Function*>(this)->setValueSubclassData(SDC);
550 assert(!hasLazyArguments());
551}
552
554 return MutableArrayRef<Argument>(Args, Count);
555}
556
559}
560
561void Function::clearArguments() {
562 for (Argument &A : makeArgArray(Arguments, NumArgs)) {
563 A.setName("");
564 A.~Argument();
565 }
566 std::allocator<Argument>().deallocate(Arguments, NumArgs);
567 Arguments = nullptr;
568}
569
571 assert(isDeclaration() && "Expected no references to current arguments");
572
573 // Drop the current arguments, if any, and set the lazy argument bit.
574 if (!hasLazyArguments()) {
576 [](const Argument &A) { return A.use_empty(); }) &&
577 "Expected arguments to be unused in declaration");
578 clearArguments();
579 setValueSubclassData(getSubclassDataFromValue() | (1 << 0));
580 }
581
582 // Nothing to steal if Src has lazy arguments.
583 if (Src.hasLazyArguments())
584 return;
585
586 // Steal arguments from Src, and fix the lazy argument bits.
587 assert(arg_size() == Src.arg_size());
588 Arguments = Src.Arguments;
589 Src.Arguments = nullptr;
590 for (Argument &A : makeArgArray(Arguments, NumArgs)) {
591 // FIXME: This does the work of transferNodesFromList inefficiently.
593 if (A.hasName())
594 Name = A.getName();
595 if (!Name.empty())
596 A.setName("");
597 A.setParent(this);
598 if (!Name.empty())
599 A.setName(Name);
600 }
601
602 setValueSubclassData(getSubclassDataFromValue() & ~(1 << 0));
603 assert(!hasLazyArguments());
604 Src.setValueSubclassData(Src.getSubclassDataFromValue() | (1 << 0));
605}
606
607void Function::deleteBodyImpl(bool ShouldDrop) {
608 setIsMaterializable(false);
609
610 for (BasicBlock &BB : *this)
612
613 // Delete all basic blocks. They are now unused, except possibly by
614 // blockaddresses, but BasicBlock's destructor takes care of those.
615 while (!BasicBlocks.empty())
616 BasicBlocks.begin()->eraseFromParent();
617
618 if (getNumOperands()) {
619 if (ShouldDrop) {
620 // Drop uses of any optional data (real or placeholder).
622 setNumHungOffUseOperands(0);
623 } else {
624 // The code needs to match Function::allocHungoffUselist().
626 Op<0>().set(CPN);
627 Op<1>().set(CPN);
628 Op<2>().set(CPN);
629 }
630 setValueSubclassData(getSubclassDataFromValue() & ~0xe);
631 }
632
633 // Metadata is stored in a side-table.
634 clearMetadata();
635}
636
637void Function::addAttributeAtIndex(unsigned i, Attribute Attr) {
638 AttributeSets = AttributeSets.addAttributeAtIndex(getContext(), i, Attr);
639}
640
642 AttributeSets = AttributeSets.addFnAttribute(getContext(), Kind);
643}
644
646 AttributeSets = AttributeSets.addFnAttribute(getContext(), Kind, Val);
647}
648
649void Function::addFnAttr(Attribute Attr) {
650 AttributeSets = AttributeSets.addFnAttribute(getContext(), Attr);
651}
652
653void Function::addFnAttrs(const AttrBuilder &Attrs) {
654 AttributeSets = AttributeSets.addFnAttributes(getContext(), Attrs);
655}
656
658 AttributeSets = AttributeSets.addRetAttribute(getContext(), Kind);
659}
660
661void Function::addRetAttr(Attribute Attr) {
662 AttributeSets = AttributeSets.addRetAttribute(getContext(), Attr);
663}
664
665void Function::addRetAttrs(const AttrBuilder &Attrs) {
666 AttributeSets = AttributeSets.addRetAttributes(getContext(), Attrs);
667}
668
669void Function::addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) {
670 AttributeSets = AttributeSets.addParamAttribute(getContext(), ArgNo, Kind);
671}
672
673void Function::addParamAttr(unsigned ArgNo, Attribute Attr) {
674 AttributeSets = AttributeSets.addParamAttribute(getContext(), ArgNo, Attr);
675}
676
677void Function::addParamAttrs(unsigned ArgNo, const AttrBuilder &Attrs) {
678 AttributeSets = AttributeSets.addParamAttributes(getContext(), ArgNo, Attrs);
679}
680
682 AttributeSets = AttributeSets.removeAttributeAtIndex(getContext(), i, Kind);
683}
684
685void Function::removeAttributeAtIndex(unsigned i, StringRef Kind) {
686 AttributeSets = AttributeSets.removeAttributeAtIndex(getContext(), i, Kind);
687}
688
690 AttributeSets = AttributeSets.removeFnAttribute(getContext(), Kind);
691}
692
694 AttributeSets = AttributeSets.removeFnAttribute(getContext(), Kind);
695}
696
698 AttributeSets = AttributeSets.removeFnAttributes(getContext(), AM);
699}
700
702 AttributeSets = AttributeSets.removeRetAttribute(getContext(), Kind);
703}
704
706 AttributeSets = AttributeSets.removeRetAttribute(getContext(), Kind);
707}
708
709void Function::removeRetAttrs(const AttributeMask &Attrs) {
710 AttributeSets = AttributeSets.removeRetAttributes(getContext(), Attrs);
711}
712
713void Function::removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) {
714 AttributeSets = AttributeSets.removeParamAttribute(getContext(), ArgNo, Kind);
715}
716
717void Function::removeParamAttr(unsigned ArgNo, StringRef Kind) {
718 AttributeSets = AttributeSets.removeParamAttribute(getContext(), ArgNo, Kind);
719}
720
721void Function::removeParamAttrs(unsigned ArgNo, const AttributeMask &Attrs) {
722 AttributeSets =
723 AttributeSets.removeParamAttributes(getContext(), ArgNo, Attrs);
724}
725
726void Function::addDereferenceableParamAttr(unsigned ArgNo, uint64_t Bytes) {
727 AttributeSets =
728 AttributeSets.addDereferenceableParamAttr(getContext(), ArgNo, Bytes);
729}
730
732 return AttributeSets.hasFnAttr(Kind);
733}
734
735bool Function::hasFnAttribute(StringRef Kind) const {
736 return AttributeSets.hasFnAttr(Kind);
737}
738
740 return AttributeSets.hasRetAttr(Kind);
741}
742
743bool Function::hasParamAttribute(unsigned ArgNo,
744 Attribute::AttrKind Kind) const {
745 return AttributeSets.hasParamAttr(ArgNo, Kind);
746}
747
748bool Function::hasParamAttribute(unsigned ArgNo, StringRef Kind) const {
749 return AttributeSets.hasParamAttr(ArgNo, Kind);
750}
751
752Attribute Function::getAttributeAtIndex(unsigned i,
753 Attribute::AttrKind Kind) const {
754 return AttributeSets.getAttributeAtIndex(i, Kind);
755}
756
757Attribute Function::getAttributeAtIndex(unsigned i, StringRef Kind) const {
758 return AttributeSets.getAttributeAtIndex(i, Kind);
759}
760
761bool Function::hasAttributeAtIndex(unsigned Idx,
762 Attribute::AttrKind Kind) const {
763 return AttributeSets.hasAttributeAtIndex(Idx, Kind);
764}
765
766Attribute Function::getFnAttribute(Attribute::AttrKind Kind) const {
767 return AttributeSets.getFnAttr(Kind);
768}
769
770Attribute Function::getFnAttribute(StringRef Kind) const {
771 return AttributeSets.getFnAttr(Kind);
772}
773
775 return AttributeSets.getRetAttr(Kind);
776}
777
779 uint64_t Default) const {
780 Attribute A = getFnAttribute(Name);
782 if (A.isStringAttribute()) {
783 StringRef Str = A.getValueAsString();
784 if (Str.getAsInteger(0, Result))
785 getContext().emitError("cannot parse integer attribute " + Name);
786 }
787
788 return Result;
789}
790
791/// gets the specified attribute from the list of attributes.
792Attribute Function::getParamAttribute(unsigned ArgNo,
793 Attribute::AttrKind Kind) const {
794 return AttributeSets.getParamAttr(ArgNo, Kind);
795}
796
798 uint64_t Bytes) {
799 AttributeSets = AttributeSets.addDereferenceableOrNullParamAttr(getContext(),
800 ArgNo, Bytes);
801}
802
804 AttributeSets = AttributeSets.addRangeRetAttr(getContext(), CR);
805}
806
808 Attribute Attr = getFnAttribute(Attribute::DenormalFPEnv);
809 if (!Attr.isValid())
811
812 DenormalFPEnv FPEnv = Attr.getDenormalFPEnv();
813 return &FPType == &APFloat::IEEEsingle() ? FPEnv.F32Mode : FPEnv.DefaultMode;
814}
815
817 Attribute Attr = getFnAttribute(Attribute::DenormalFPEnv);
818 return Attr.isValid() ? Attr.getDenormalFPEnv() : DenormalFPEnv::getDefault();
819}
820
821const std::string &Function::getGC() const {
822 assert(hasGC() && "Function has no collector");
823 return getContext().getGC(*this);
824}
825
826void Function::setGC(std::string Str) {
827 setValueSubclassDataBit(14, !Str.empty());
828 getContext().setGC(*this, std::move(Str));
829}
830
831void Function::clearGC() {
832 if (!hasGC())
833 return;
834 getContext().deleteGC(*this);
835 setValueSubclassDataBit(14, false);
836}
837
839 return hasFnAttribute(Attribute::StackProtect) ||
840 hasFnAttribute(Attribute::StackProtectStrong) ||
841 hasFnAttribute(Attribute::StackProtectReq);
842}
843
844/// Copy all additional attributes (those not needed to create a Function) from
845/// the Function Src to this one.
846void Function::copyAttributesFrom(const Function *Src) {
848 setCallingConv(Src->getCallingConv());
849 setAttributes(Src->getAttributes());
850 if (Src->hasGC())
851 setGC(Src->getGC());
852 else
853 clearGC();
854 if (Src->hasPersonalityFn())
855 setPersonalityFn(Src->getPersonalityFn());
856 if (Src->hasPrefixData())
857 setPrefixData(Src->getPrefixData());
858 if (Src->hasPrologueData())
859 setPrologueData(Src->getPrologueData());
860}
861
863 return getAttributes().getMemoryEffects();
864}
867}
868
869/// Determine if the function does not access memory.
871 return getMemoryEffects().doesNotAccessMemory();
872}
875}
876
877/// Determine if the function does not access or only reads memory.
878bool Function::onlyReadsMemory() const {
879 return getMemoryEffects().onlyReadsMemory();
880}
882 setMemoryEffects(getMemoryEffects() & MemoryEffects::readOnly());
883}
884
885/// Determine if the function does not access or only writes memory.
886bool Function::onlyWritesMemory() const {
887 return getMemoryEffects().onlyWritesMemory();
888}
890 setMemoryEffects(getMemoryEffects() & MemoryEffects::writeOnly());
891}
892
893/// Determine if the call can access memory only using pointers based
894/// on its arguments.
896 return getMemoryEffects().onlyAccessesArgPointees();
897}
899 setMemoryEffects(getMemoryEffects() & MemoryEffects::argMemOnly());
900}
901
902/// Determine if the function may only access memory that is
903/// inaccessible from the IR.
905 return getMemoryEffects().onlyAccessesInaccessibleMem();
906}
909}
910
911/// Determine if the function may only access memory that is
912/// either inaccessible from the IR or pointed to by its arguments.
914 return getMemoryEffects().onlyAccessesInaccessibleOrArgMem();
915}
917 setMemoryEffects(getMemoryEffects() &
919}
920
921bool Function::isTargetIntrinsic() const {
922 return Intrinsic::isTargetIntrinsic(IntID);
923}
924
926 LibFuncCache = UnknownLibFunc;
928 if (!Name.starts_with("llvm.")) {
929 HasLLVMReservedName = false;
931 return;
932 }
933 HasLLVMReservedName = true;
934 IntID = Intrinsic::lookupIntrinsicID(Name);
935}
936
937/// hasAddressTaken - returns true if there are any uses of this function
938/// other than direct calls or invokes to it. Optionally ignores callback
939/// uses, assume like pointer annotation calls, and references in llvm.used
940/// and llvm.compiler.used variables.
941bool Function::hasAddressTaken(const User **PutOffender,
942 bool IgnoreCallbackUses,
943 bool IgnoreAssumeLikeCalls, bool IgnoreLLVMUsed,
944 bool IgnoreARCAttachedCall,
945 bool IgnoreCastedDirectCall) const {
946 for (const Use &U : uses()) {
947 const User *FU = U.getUser();
948 if (IgnoreCallbackUses) {
949 AbstractCallSite ACS(&U);
950 if (ACS && ACS.isCallbackCall())
951 continue;
952 }
953
954 const auto *Call = dyn_cast<CallBase>(FU);
955 if (!Call) {
956 if (IgnoreAssumeLikeCalls &&
958 all_of(FU->users(), [](const User *U) {
959 if (const auto *I = dyn_cast<IntrinsicInst>(U))
960 return I->isAssumeLikeIntrinsic();
961 return false;
962 })) {
963 continue;
964 }
965
966 if (IgnoreLLVMUsed && !FU->user_empty()) {
967 const User *FUU = FU;
969 FU->hasOneUse() && !FU->user_begin()->user_empty())
970 FUU = *FU->user_begin();
971 if (llvm::all_of(FUU->users(), [](const User *U) {
972 if (const auto *GV = dyn_cast<GlobalVariable>(U))
973 return GV->hasName() &&
974 (GV->getName() == "llvm.compiler.used" ||
975 GV->getName() == "llvm.used");
976 return false;
977 }))
978 continue;
979 }
980 if (PutOffender)
981 *PutOffender = FU;
982 return true;
983 }
984
985 if (IgnoreAssumeLikeCalls) {
986 if (const auto *I = dyn_cast<IntrinsicInst>(Call))
987 if (I->isAssumeLikeIntrinsic())
988 continue;
989 }
990
991 if (!Call->isCallee(&U) || (!IgnoreCastedDirectCall &&
992 Call->getFunctionType() != getFunctionType())) {
993 if (IgnoreARCAttachedCall &&
994 Call->isOperandBundleOfType(LLVMContext::OB_clang_arc_attachedcall,
995 U.getOperandNo()))
996 continue;
997
998 if (PutOffender)
999 *PutOffender = FU;
1000 return true;
1001 }
1002 }
1003 return false;
1004}
1005
1006bool Function::isDefTriviallyDead() const {
1007 // Check the linkage
1008 if (!hasLinkOnceLinkage() && !hasLocalLinkage() &&
1009 !hasAvailableExternallyLinkage())
1010 return false;
1011
1012 return use_empty();
1013}
1014
1015/// callsFunctionThatReturnsTwice - Return true if the function has a call to
1016/// setjmp or other function that gcc recognizes as "returning twice".
1018 for (const Instruction &I : instructions(this))
1019 if (const auto *Call = dyn_cast<CallBase>(&I))
1020 if (Call->hasFnAttr(Attribute::ReturnsTwice))
1021 return true;
1022
1023 return false;
1024}
1025
1026Constant *Function::getPersonalityFn() const {
1027 assert(hasPersonalityFn() && getNumOperands());
1028 return cast<Constant>(Op<0>());
1029}
1030
1031void Function::setPersonalityFn(Constant *Fn) {
1032 setHungoffOperand<0>(Fn);
1033 setValueSubclassDataBit(3, Fn != nullptr);
1034}
1035
1036Constant *Function::getPrefixData() const {
1037 assert(hasPrefixData() && getNumOperands());
1038 return cast<Constant>(Op<1>());
1039}
1040
1041void Function::setPrefixData(Constant *PrefixData) {
1042 setHungoffOperand<1>(PrefixData);
1043 setValueSubclassDataBit(1, PrefixData != nullptr);
1044}
1045
1046Constant *Function::getPrologueData() const {
1047 assert(hasPrologueData() && getNumOperands());
1048 return cast<Constant>(Op<2>());
1049}
1050
1051void Function::setPrologueData(Constant *PrologueData) {
1052 setHungoffOperand<2>(PrologueData);
1053 setValueSubclassDataBit(2, PrologueData != nullptr);
1054}
1055
1056void Function::allocHungoffUselist() {
1057 // If we've already allocated a uselist, stop here.
1058 if (getNumOperands())
1059 return;
1060
1061 allocHungoffUses(3, /*IsPhi=*/ false);
1062 setNumHungOffUseOperands(3);
1063
1064 // Initialize the uselist with placeholder operands to allow traversal.
1066 Op<0>().set(CPN);
1067 Op<1>().set(CPN);
1068 Op<2>().set(CPN);
1069}
1070
1071template <int Idx>
1072void Function::setHungoffOperand(Constant *C) {
1073 if (C) {
1074 allocHungoffUselist();
1075 Op<Idx>().set(C);
1076 } else if (getNumOperands()) {
1078 }
1079}
1080
1081void Function::setValueSubclassDataBit(unsigned Bit, bool On) {
1082 assert(Bit < 16 && "SubclassData contains only 16 bits");
1083 if (On)
1084 setValueSubclassData(getSubclassDataFromValue() | (1 << Bit));
1085 else
1086 setValueSubclassData(getSubclassDataFromValue() & ~(1 << Bit));
1087}
1088
1090 const DenseSet<GlobalValue::GUID> *S) {
1091 auto ImportGUIDs = getImportGUIDs();
1092 if (S == nullptr && ImportGUIDs.size())
1093 S = &ImportGUIDs;
1094
1095 MDBuilder MDB(getContext());
1096 setMetadata(LLVMContext::MD_prof, MDB.createFunctionEntryCount(Count, S));
1097}
1098
1099std::optional<uint64_t> Function::getEntryCount() const {
1100 MDNode *MD = getMetadata(LLVMContext::MD_prof);
1101 if (MD && MD->getOperand(0))
1102 if (MDString *MDS = dyn_cast<MDString>(MD->getOperand(0))) {
1103 if (MDS->getString() != MDProfLabels::FunctionEntryCount)
1104 return std::nullopt;
1107 // A value of -1 is used for SamplePGO when there were no samples.
1108 // Treat this the same as unknown.
1109 if (Count == static_cast<uint64_t>(-1))
1110 return std::nullopt;
1111 return Count;
1112 }
1113 return std::nullopt;
1114}
1115
1118 if (MDNode *MD = getMetadata(LLVMContext::MD_prof))
1119 if (MDString *MDS = dyn_cast<MDString>(MD->getOperand(0)))
1120 if (MDS->getString() == MDProfLabels::FunctionEntryCount)
1121 for (unsigned i = 2; i < MD->getNumOperands(); i++)
1123 ->getValue()
1124 .getZExtValue());
1125 return R;
1126}
1127
1128bool Function::nullPointerIsDefined() const {
1129 return hasFnAttribute(Attribute::NullPointerIsValid);
1130}
1131
1132unsigned Function::getVScaleValue() const {
1133 Attribute Attr = getFnAttribute(Attribute::VScaleRange);
1134 if (!Attr.isValid())
1135 return 0;
1136
1137 unsigned VScale = Attr.getVScaleRangeMin();
1138 if (VScale && VScale == Attr.getVScaleRangeMax())
1139 return VScale;
1140
1141 return 0;
1142}
1143
1144bool llvm::NullPointerIsDefined(const Function *F, unsigned AS) {
1145 if (F && F->nullPointerIsDefined())
1146 return true;
1147
1148 if (AS != 0)
1149 return true;
1150
1151 return false;
1152}
1153
1155 switch (CC) {
1156 case CallingConv::C:
1157 case CallingConv::Fast:
1158 case CallingConv::Cold:
1159 case CallingConv::GHC:
1160 case CallingConv::HiPE:
1164 case CallingConv::Swift:
1166 case CallingConv::Tail:
1181 case CallingConv::Win64:
1189 return true;
1194 return false;
1212 case CallingConv::GRAAL:
1229 return true;
1230 default:
1231 return false;
1232 }
1233
1234 llvm_unreachable("covered callingconv switch");
1235}
static unsigned getIntrinsicID(const SDNode *N)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
uint64_t uint64_t
AMDGPU Lower Kernel Arguments
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Expand Atomic instructions
This file contains the simple types necessary to represent the attributes associated with functions a...
static const Function * getParent(const Value *V)
This file implements the BitVector class.
static bool setMemoryEffects(Function &F, MemoryEffects ME)
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_EXPORT_TEMPLATE
Definition Compiler.h:213
This file contains the declarations for the subclasses of Constant, which represent the different fla...
DXIL Finalize Linkage
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
This file defines the DenseSet and SmallDenseSet classes.
@ Default
Module.h This file contains the declarations for the Module class.
This defines the Use class.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
Machine Check Debug Module
This file contains the declarations for metadata subclasses.
This file contains the declarations for profiling metadata utility functions.
static StringRef getName(Value *V)
Func getContext().diagnose(DiagnosticInfoUnsupported(Func
This file contains some templates that are useful if you are working with the STL at all.
static const char * name
static Type * getMemoryParamAllocType(AttributeSet ParamAttrs)
For a byval, sret, inalloca, or preallocated parameter, get the in-memory parameter type.
Definition Function.cpp:182
static MutableArrayRef< Argument > makeArgArray(Argument *Args, size_t Count)
Definition Function.cpp:553
static unsigned computeAddrSpace(unsigned AddrSpace, Module *M)
Definition Function.cpp:476
This file defines the SmallString class.
This file defines the SmallVector class.
static SymbolRef::Type getType(const Symbol *Sym)
Definition TapiFile.cpp:39
static const fltSemantics & IEEEsingle()
Definition APFloat.h:304
uint64_t getZExtValue() const
Get zero extended value.
Definition APInt.h:1560
This class represents an incoming formal argument to a Function.
Definition Argument.h:32
LLVM_ABI Type * getParamByRefType() const
If this is a byref argument, return its type.
Definition Function.cpp:228
LLVM_ABI DeadOnReturnInfo getDeadOnReturnInfo() const
Returns information on the memory marked dead_on_return for the argument.
Definition Function.cpp:131
LLVM_ABI Attribute getAttribute(Attribute::AttrKind Kind) const
Definition Function.cpp:340
LLVM_ABI bool hasNoAliasAttr() const
Return true if this argument has the noalias attribute.
Definition Function.cpp:266
LLVM_ABI bool hasNonNullAttr(bool AllowUndefOrPoison=true) const
Return true if this argument has the nonnull attribute.
Definition Function.cpp:113
LLVM_ABI bool hasByRefAttr() const
Return true if this argument has the byref attribute.
Definition Function.cpp:136
LLVM_ABI 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:244
LLVM_ABI void addAttr(Attribute::AttrKind Kind)
Definition Function.cpp:314
LLVM_ABI Argument(Type *Ty, const Twine &Name="", Function *F=nullptr, unsigned ArgNo=0)
Argument constructor.
Definition Function.cpp:104
LLVM_ABI bool onlyReadsMemory() const
Return true if this argument has the readonly or readnone attribute.
Definition Function.cpp:302
LLVM_ABI bool hasPointeeInMemoryValueAttr() const
Return true if this argument has the byval, sret, inalloca, preallocated, or byref attribute.
Definition Function.cpp:169
LLVM_ABI bool hasAttribute(Attribute::AttrKind Kind) const
Check if an argument has a given attribute.
Definition Function.cpp:332
LLVM_ABI bool hasReturnedAttr() const
Return true if this argument has the returned attribute.
Definition Function.cpp:290
LLVM_ABI Type * getParamStructRetType() const
If this is an sret argument, return its type.
Definition Function.cpp:223
LLVM_ABI bool hasInRegAttr() const
Return true if this argument has the inreg attribute.
Definition Function.cpp:286
LLVM_ABI bool hasByValAttr() const
Return true if this argument has the byval attribute.
Definition Function.cpp:126
LLVM_ABI bool hasPreallocatedAttr() const
Return true if this argument has the preallocated attribute.
Definition Function.cpp:155
LLVM_ABI bool hasSExtAttr() const
Return true if this argument has the sext attribute.
Definition Function.cpp:298
LLVM_ABI void removeAttr(Attribute::AttrKind Kind)
Remove attributes from an argument.
Definition Function.cpp:322
LLVM_ABI uint64_t getPassPointeeByValueCopySize(const DataLayout &DL) const
If this argument satisfies has hasPassPointeeByValueAttr, return the in-memory ABI size copied to the...
Definition Function.cpp:199
LLVM_ABI void removeAttrs(const AttributeMask &AM)
Definition Function.cpp:326
LLVM_ABI Type * getPointeeInMemoryValueType() const
If hasPointeeInMemoryValueAttr returns true, the in-memory ABI type is returned.
Definition Function.cpp:205
LLVM_ABI bool hasInAllocaAttr() const
Return true if this argument has the inalloca attribute.
Definition Function.cpp:150
LLVM_ABI bool hasSwiftErrorAttr() const
Return true if this argument has the swifterror attribute.
Definition Function.cpp:146
LLVM_ABI FPClassTest getNoFPClass() const
If this argument has nofpclass attribute, return the mask representing disallowed floating-point valu...
Definition Function.cpp:250
LLVM_ABI void addAttrs(AttrBuilder &B)
Add attributes to an argument.
Definition Function.cpp:308
LLVM_ABI bool hasNoFreeAttr() const
Return true if this argument has the nofree attribute.
Definition Function.cpp:276
LLVM_ABI bool hasSwiftSelfAttr() const
Return true if this argument has the swiftself attribute.
Definition Function.cpp:142
LLVM_ABI Type * getParamInAllocaType() const
If this is an inalloca argument, return its type.
Definition Function.cpp:233
LLVM_ABI bool hasZExtAttr() const
Return true if this argument has the zext attribute.
Definition Function.cpp:294
LLVM_ABI Type * getParamByValType() const
If this is a byval argument, return its type.
Definition Function.cpp:218
LLVM_ABI bool hasNestAttr() const
Return true if this argument has the nest attribute.
Definition Function.cpp:261
LLVM_ABI MaybeAlign getParamAlign() const
If this is a byval or inalloca argument, return its alignment.
Definition Function.cpp:209
LLVM_ABI std::optional< ConstantRange > getRange() const
If this argument has a range attribute, return the value range of the argument.
Definition Function.cpp:254
LLVM_ABI bool hasStructRetAttr() const
Return true if this argument has the sret attribute.
Definition Function.cpp:281
LLVM_ABI AttributeSet getAttributes() const
Definition Function.cpp:344
LLVM_ABI bool hasPassPointeeByValueCopyAttr() const
Return true if this argument has the byval, inalloca, or preallocated attribute.
Definition Function.cpp:161
LLVM_ABI MaybeAlign getParamStackAlign() const
Definition Function.cpp:214
LLVM_ABI bool hasNoCaptureAttr() const
Return true if this argument has the nocapture attribute.
Definition Function.cpp:271
LLVM_ABI uint64_t getDereferenceableBytes() const
If this argument has the dereferenceable attribute, return the number of bytes known to be dereferenc...
Definition Function.cpp:238
This class stores enough information to efficiently remove some attributes from an existing AttrBuild...
This class holds the attributes for a particular argument, parameter, function, or return value.
Definition Attributes.h:406
LLVM_ABI Type * getInAllocaType() const
LLVM_ABI Type * getByValType() const
LLVM_ABI Type * getStructRetType() const
LLVM_ABI Type * getPreallocatedType() const
LLVM_ABI Type * getByRefType() const
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
Definition Attributes.h:125
static LLVM_ABI Attribute getWithMemoryEffects(LLVMContext &Context, MemoryEffects ME)
LLVM Basic Block Representation.
Definition BasicBlock.h:62
LLVM_ABI void dropAllReferences()
Cause all subinstructions to "let go" of all the references that said subinstructions are maintaining...
This is the shared class of boolean and integer constants.
Definition Constants.h:87
const APInt & getValue() const
Return the constant as an APInt value reference.
Definition Constants.h:159
static LLVM_ABI ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
This class represents a range of values.
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
Implements a dense probed hash-table based set.
Definition DenseSet.h:281
static LLVM_ABI bool isValidReturnType(Type *RetTy)
Return true if the specified type is valid as a return type.
Definition Type.cpp:452
void addFnAttr(Attribute::AttrKind Kind)
Add function attributes to this function.
Definition Function.cpp:641
unsigned getVScaleValue() const
Return the value for vscale based on the vscale_range attribute or 0 when unknown.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
Definition Function.h:169
void addParamAttrs(unsigned ArgNo, const AttrBuilder &Attrs)
adds the attributes to the list of attributes for the given arg.
Definition Function.cpp:677
void removeRetAttr(Attribute::AttrKind Kind)
removes the attribute from the return value list of attributes.
Definition Function.cpp:701
void addRetAttrs(const AttrBuilder &Attrs)
Add return value attributes to this function.
Definition Function.cpp:665
bool isDefTriviallyDead() const
isDefTriviallyDead - Return true if it is trivially safe to remove this function definition from the ...
bool onlyAccessesInaccessibleMemOrArgMem() const
Determine if the function may only access memory that is either inaccessible from the IR or pointed t...
Definition Function.cpp:913
void splice(Function::iterator ToIt, Function *FromF)
Transfer all blocks from FromF to this function at ToIt.
Definition Function.h:746
BasicBlockListType::iterator iterator
Definition Function.h:70
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:941
void removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
removes the attribute from the list of attributes.
Definition Function.cpp:713
bool nullPointerIsDefined() const
Check if null pointer dereferencing is considered undefined behavior for the function.
bool convertFromNewDbgValues()
Definition Function.cpp:91
Attribute getParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const
gets the specified attribute from the list of attributes.
Definition Function.cpp:792
void setPrefixData(Constant *PrefixData)
bool hasStackProtectorFnAttr() const
Returns true if the function has ssp, sspstrong, or sspreq fn attrs.
Definition Function.cpp:838
void removeFromParent()
removeFromParent - This method unlinks 'this' from the containing module, but does not delete it.
Definition Function.cpp:447
const DataLayout & getDataLayout() const
Get the data layout of the module this function belongs to.
Definition Function.cpp:356
void addFnAttrs(const AttrBuilder &Attrs)
Add function attributes to this function.
Definition Function.cpp:653
void renumberBlocks()
Renumber basic blocks into a dense value range starting from 0.
Definition Function.cpp:64
void setDoesNotAccessMemory()
Definition Function.cpp:873
void setGC(std::string Str)
Definition Function.cpp:826
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
Definition Function.cpp:766
uint64_t getFnAttributeAsParsedInteger(StringRef Kind, uint64_t Default=0) const
For a string attribute Kind, parse attribute as an integer.
Definition Function.cpp:778
bool isConstrainedFPIntrinsic() const
Returns true if the function is one of the "Constrained Floating-PointIntrinsics".
Definition Function.cpp:557
void setOnlyAccessesArgMemory()
Definition Function.cpp:898
MemoryEffects getMemoryEffects() const
Definition Function.cpp:862
void setOnlyAccessesInaccessibleMemory()
Definition Function.cpp:907
void removeParamAttrs(unsigned ArgNo, const AttributeMask &Attrs)
removes the attribute from the list of attributes.
Definition Function.cpp:721
bool hasParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const
check if an attributes is in the list of attributes.
Definition Function.cpp:743
bool hasAttributeAtIndex(unsigned Idx, Attribute::AttrKind Kind) const
Check if attribute of the given kind is set at the given index.
Definition Function.cpp:761
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 and the LLVMContext applied.
Definition Function.cpp:372
void setOnlyReadsMemory()
Definition Function.cpp:881
bool isTargetIntrinsic() const
isTargetIntrinsic - Returns true if this function is an intrinsic and the intrinsic is specific to a ...
Definition Function.cpp:921
void removeFnAttrs(const AttributeMask &Attrs)
Definition Function.cpp:697
void addRetAttr(Attribute::AttrKind Kind)
Add return value attributes to this function.
Definition Function.cpp:657
DenormalFPEnv getDenormalFPEnv() const
Return the representational value of the denormal_fpenv attribute.
Definition Function.cpp:816
Constant * getPrologueData() const
Get the prologue data associated with this function.
Constant * getPersonalityFn() const
Get the personality function associated with this function.
void setOnlyWritesMemory()
Definition Function.cpp:889
void setPersonalityFn(Constant *Fn)
DenseSet< GlobalValue::GUID > getImportGUIDs() const
Returns the set of GUIDs that needs to be imported to the function for sample PGO,...
void removeAttributeAtIndex(unsigned i, Attribute::AttrKind Kind)
removes the attribute from the list of attributes.
Definition Function.cpp:681
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it.
Definition Function.cpp:451
void removeFnAttr(Attribute::AttrKind Kind)
Remove function attributes from this function.
Definition Function.cpp:689
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:797
void addRangeRetAttr(const ConstantRange &CR)
adds the range attribute to the list of attributes for the return value.
Definition Function.cpp:803
void stealArgumentListFrom(Function &Src)
Steal arguments from another function.
Definition Function.cpp:570
std::optional< uint64_t > getEntryCount() const
Get the entry count for this function.
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
Definition Function.cpp:352
const std::string & getGC() const
Definition Function.cpp:821
void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
adds the attribute to the list of attributes for the given arg.
Definition Function.cpp:669
bool doesNotAccessMemory() const
Determine if the function does not access memory.
Definition Function.cpp:870
DenormalMode getDenormalMode(const fltSemantics &FPType) const
Returns the denormal handling type for the default rounding mode of the function.
Definition Function.cpp:807
void updateAfterNameChange()
Update internal caches that depend on the function name (such as the intrinsic ID and libcall cache).
Definition Function.cpp:925
void setEntryCount(uint64_t Count, const DenseSet< GlobalValue::GUID > *Imports=nullptr)
Set the entry count for this function.
bool callsFunctionThatReturnsTwice() const
callsFunctionThatReturnsTwice - Return true if the function has a call to setjmp or other function th...
bool hasRetAttribute(Attribute::AttrKind Kind) const
check if an attribute is in the list of attributes for the return value.
Definition Function.cpp:739
bool onlyWritesMemory() const
Determine if the function does not access or only writes memory.
Definition Function.cpp:886
bool onlyAccessesInaccessibleMemory() const
Determine if the function may only access memory that is inaccessible from the IR.
Definition Function.cpp:904
void setPrologueData(Constant *PrologueData)
void removeRetAttrs(const AttributeMask &Attrs)
removes the attributes from the return value list of attributes.
Definition Function.cpp:709
bool onlyAccessesArgMemory() const
Determine if the call can access memory only using pointers based on its arguments.
Definition Function.cpp:895
Function::iterator erase(Function::iterator FromIt, Function::iterator ToIt)
Erases a range of BasicBlocks from FromIt to (not including) ToIt.
Definition Function.cpp:467
void setMemoryEffects(MemoryEffects ME)
Definition Function.cpp:865
Constant * getPrefixData() const
Get the prefix data associated with this function.
Attribute getAttributeAtIndex(unsigned i, Attribute::AttrKind Kind) const
gets the attribute from the list of attributes.
Definition Function.cpp:752
iterator end()
Definition Function.h:840
void convertToNewDbgValues()
Definition Function.cpp:85
void setOnlyAccessesInaccessibleMemOrArgMem()
Definition Function.cpp:916
void addDereferenceableParamAttr(unsigned ArgNo, uint64_t Bytes)
adds the dereferenceable attribute to the list of attributes for the given arg.
Definition Function.cpp:726
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:878
void addAttributeAtIndex(unsigned i, Attribute Attr)
adds the attribute to the list of attributes.
Definition Function.cpp:637
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition Function.cpp:731
void copyAttributesFrom(const Function *Src)
copyAttributesFrom - copy all additional attributes (those not needed to create a Function) from the ...
Definition Function.cpp:846
Attribute getRetAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind for the return value.
Definition Function.cpp:774
LLVM_ABI void copyAttributesFrom(const GlobalObject *Src)
Definition Globals.cpp:228
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:76
Metadata node.
Definition Metadata.h:1081
const MDOperand & getOperand(unsigned I) const
Definition Metadata.h:1437
unsigned getNumOperands() const
Return number of MDNode operands.
Definition Metadata.h:1443
A single uniqued string.
Definition Metadata.h:733
static MemoryEffectsBase readOnly()
Definition ModRef.h:133
static MemoryEffectsBase argMemOnly(ModRefInfo MR=ModRefInfo::ModRef)
Definition ModRef.h:143
static MemoryEffectsBase inaccessibleMemOnly(ModRefInfo MR=ModRefInfo::ModRef)
Definition ModRef.h:149
static MemoryEffectsBase writeOnly()
Definition ModRef.h:138
static MemoryEffectsBase inaccessibleOrArgMemOnly(ModRefInfo MR=ModRefInfo::ModRef)
Definition ModRef.h:166
static MemoryEffectsBase none()
Definition ModRef.h:128
const FunctionListType & getFunctionList() const
Get the Module's list of functions (constant).
Definition Module.h:714
Represent a mutable reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:294
static LLVM_ABI PointerType * get(LLVMContext &C, unsigned AddressSpace)
This constructs an opaque pointer to an object in a numbered address space.
Definition Type.cpp:887
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:26
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
constexpr bool empty() const
Check if the string is empty.
Definition StringRef.h:141
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
A Use represents the edge between a Value definition and its users.
Definition Use.h:35
void dropAllReferences()
Drop all references to operands.
Definition User.h:324
user_iterator user_begin()
Definition Value.h:404
bool hasOneUse() const
Return true if there is exactly one use of this value.
Definition Value.h:441
iterator_range< user_iterator > users()
Definition Value.h:428
bool user_empty() const
Definition Value.h:391
void push_back(pointer val)
Definition ilist.h:250
CallInst * Call
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
LLVM_ABI LLVM_READNONE bool supportsNonVoidReturnType(CallingConv::ID CC)
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
@ ARM64EC_Thunk_Native
Calling convention used in the ARM64EC ABI to implement calls between ARM64 code and thunks.
@ AArch64_VectorCall
Used between AArch64 Advanced SIMD functions.
@ X86_64_SysV
The C convention as specified in the x86-64 supplement to the System V ABI, used on most non-Windows ...
@ RISCV_VectorCall
Calling convention used for RISC-V V-extension.
@ AMDGPU_CS
Used for Mesa/AMDPAL compute shaders.
@ M68k_INTR
Used for M68k interrupt routines.
@ AMDGPU_VS
Used for Mesa vertex shaders, or AMDPAL last shader stage before rasterization (vertex shader if tess...
@ MSP430_BUILTIN
Used for special MSP430 rtlib functions which have an "optimized" convention using additional registe...
@ AVR_SIGNAL
Used for AVR signal routines.
@ HiPE
Used by the High-Performance Erlang Compiler (HiPE).
Definition CallingConv.h:53
@ Swift
Calling convention for Swift.
Definition CallingConv.h:69
@ AMDGPU_KERNEL
Used for AMDGPU code object kernels.
@ AArch64_SVE_VectorCall
Used between AArch64 SVE functions.
@ ARM_APCS
ARM Procedure Calling Standard (obsolete, but still used on some targets).
@ CFGuard_Check
Special calling convention on Windows for calling the Control Guard Check ICall funtion.
Definition CallingConv.h:82
@ AVR_INTR
Used for AVR interrupt routines.
@ PreserveMost
Used for runtime calls that preserves most registers.
Definition CallingConv.h:63
@ AnyReg
OBSOLETED - Used for stack based JavaScript calls.
Definition CallingConv.h:60
@ AMDGPU_Gfx
Used for AMD graphics targets.
@ DUMMY_HHVM
Placeholders for HHVM calling conventions (deprecated, removed).
@ AMDGPU_CS_ChainPreserve
Used on AMDGPUs to give the middle-end more control over argument placement.
@ AMDGPU_HS
Used for Mesa/AMDPAL hull shaders (= tessellation control shaders).
@ ARM_AAPCS
ARM Architecture Procedure Calling Standard calling convention (aka EABI).
@ AMDGPU_GS
Used for Mesa/AMDPAL geometry shaders.
@ AArch64_SME_ABI_Support_Routines_PreserveMost_From_X2
Preserve X2-X15, X19-X29, SP, Z0-Z31, P0-P15.
@ CXX_FAST_TLS
Used for access functions.
Definition CallingConv.h:72
@ X86_INTR
x86 hardware interrupt context.
@ RISCV_VLSCall_32
Calling convention used for RISC-V V-extension fixed vectors.
@ AArch64_SME_ABI_Support_Routines_PreserveMost_From_X0
Preserve X0-X13, X19-X29, SP, Z0-Z31, P0-P15.
@ WASM_EmscriptenInvoke
For emscripten __invoke_* functions.
@ AMDGPU_CS_Chain
Used on AMDGPUs to give the middle-end more control over argument placement.
@ AVR_BUILTIN
Used for special AVR rtlib functions which have an "optimized" convention to preserve registers.
@ GHC
Used by the Glasgow Haskell Compiler (GHC).
Definition CallingConv.h:50
@ AMDGPU_PS
Used for Mesa/AMDPAL pixel shaders.
@ Cold
Attempts to make code in the caller as efficient as possible under the assumption that the call is no...
Definition CallingConv.h:47
@ AArch64_SME_ABI_Support_Routines_PreserveMost_From_X1
Preserve X1-X15, X19-X29, SP, Z0-Z31, P0-P15.
@ X86_ThisCall
Similar to X86_StdCall.
@ PTX_Device
Call to a PTX device function.
@ SPIR_KERNEL
Used for SPIR kernel functions.
@ PreserveAll
Used for runtime calls that preserves (almost) all registers.
Definition CallingConv.h:66
@ X86_StdCall
stdcall is mostly used by the Win32 API.
Definition CallingConv.h:99
@ SPIR_FUNC
Used for SPIR non-kernel device functions.
@ Fast
Attempts to make calls as fast as possible (e.g.
Definition CallingConv.h:41
@ MSP430_INTR
Used for MSP430 interrupt routines.
@ X86_VectorCall
MSVC calling convention that passes vectors and vector aggregates in SSE registers.
@ Intel_OCL_BI
Used for Intel OpenCL built-ins.
@ PreserveNone
Used for runtime calls that preserves none general registers.
Definition CallingConv.h:90
@ AMDGPU_ES
Used for AMDPAL shader stage before geometry shader if geometry is in use.
@ Tail
Attemps to make calls as fast as possible while guaranteeing that tail call optimization can always b...
Definition CallingConv.h:76
@ Win64
The C convention as implemented on Windows/x86-64 and AArch64.
@ SwiftTail
This follows the Swift calling convention in how arguments are passed but guarantees tail calls will ...
Definition CallingConv.h:87
@ GRAAL
Used by GraalVM. Two additional registers are reserved.
@ AMDGPU_LS
Used for AMDPAL vertex shader if tessellation is in use.
@ ARM_AAPCS_VFP
Same as ARM_AAPCS, but uses hard floating point ABI.
@ ARM64EC_Thunk_X64
Calling convention used in the ARM64EC ABI to implement calls between x64 code and thunks.
@ M68k_RTD
Used for M68k rtd-based CC (similar to X86's stdcall).
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
@ X86_FastCall
'fast' analog of X86_StdCall.
LLVM_ABI bool isConstrainedFPIntrinsic(ID QID)
Returns true if the intrinsic ID is for one of the "ConstrainedFloating-Point Intrinsics".
LLVM_ABI ID lookupIntrinsicID(StringRef Name)
This does the actual lookup of an intrinsic ID which matches the given function name.
LLVM_ABI AttributeList getAttributes(LLVMContext &C, ID id, FunctionType *FT)
Return the attributes for an intrinsic.
LLVM_ABI bool isSignatureValid(Intrinsic::ID ID, FunctionType *FT, SmallVectorImpl< Type * > &OverloadTys, raw_ostream &OS=nulls())
Returns true if FT is a valid function type for intrinsic ID.
LLVM_ABI bool isTargetIntrinsic(ID IID)
isTargetIntrinsic - Returns true if IID is an intrinsic specific to a certain target.
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > extract_or_null(Y &&MD)
Extract a Value from Metadata, allowing null.
Definition Metadata.h:694
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > extract(Y &&MD)
Extract a Value from Metadata.
Definition Metadata.h:679
constexpr double e
This is an optimization pass for GlobalISel generic memory operations.
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:1755
unsigned getPointerAddressSpace(const Type *T)
Definition SPIRVUtils.h:393
auto dyn_cast_if_present(const Y &Val)
dyn_cast_if_present<X> - Functionally identical to dyn_cast, except that a null (or none in the case ...
Definition Casting.h:732
MemoryEffectsBase< IRMemLocation > MemoryEffects
Summary of how a function affects memory in the program.
Definition ModRef.h:356
UWTableKind
Definition CodeGen.h:309
@ None
No unwind table requested.
Definition CodeGen.h:310
LLVM_ABI bool NullPointerIsDefined(const Function *F, unsigned AS=0)
Check whether null pointer dereferencing is considered undefined behavior for a given function or an ...
bool isPointerTy(const Type *T)
Definition SPIRVUtils.h:381
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
Definition InstrProf.h:145
DWARFExpression::Operation Op
const IROptions & getIROptions(const LLVMContext &C)
Definition IROptions.h:27
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
bool capturesNothing(CaptureComponents CC)
Definition ModRef.h:375
#define N
Represents the full denormal controls for a function, including the default mode and the f32 specific...
static constexpr DenormalFPEnv getDefault()
Represent subnormal handling kind for floating point instruction inputs and outputs.
static constexpr DenormalMode getDefault()
Return the assumed default mode for a function without denormal-fp-math.
static LLVM_ABI const char * FunctionEntryCount
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition Alignment.h:111