17#ifndef LLVM_IR_FUNCTION_H
18#define LLVM_IR_FUNCTION_H
47class AssemblyAnnotationWriter;
57class TargetLibraryInfoImpl;
60class BranchProbabilityInfo;
61class BlockFrequencyInfo;
82 unsigned NextBlockNum = 0;
84 unsigned BlockNumEpoch = 0;
88 std::unique_ptr<ValueSymbolTable>
107 IsMaterializableBit = 0,
123 return getSubclassDataFromValue() & (1<<0);
127 void convertToNewDbgValues();
130 void convertFromNewDbgValues();
132 void setIsNewDbgInfoFormat(
bool NewVal);
133 void setNewDbgInfoFormatFlag(
bool NewVal);
143 mutable LibFunc LibFuncCache = UnknownLibFunc;
145 void CheckLazyArguments()
const {
146 if (hasLazyArguments())
147 BuildLazyArguments();
150 void BuildLazyArguments()
const;
152 void clearArguments();
154 void deleteBodyImpl(
bool ShouldDrop);
174 unsigned AddrSpace,
const Twine &
N =
"",
182 return new (AllocMarker)
213 unsigned getInstructionCount()
const;
234 bool isVarArg()
const {
return getFunctionType()->isVarArg(); }
237 return getGlobalObjectSubClassData() & (1 << IsMaterializableBit);
240 unsigned Mask = 1 << IsMaterializableBit;
241 setGlobalObjectSubClassData((~Mask & getGlobalObjectSubClassData()) |
261 bool isTargetIntrinsic()
const;
266 bool isConstrainedFPIntrinsic()
const;
272 void updateAfterNameChange();
278 return static_cast<CallingConv::ID>((getSubclassDataFromValue() >> 4) &
282 auto ID =
static_cast<unsigned>(
CC);
283 assert(!(
ID & ~CallingConv::MaxID) &&
"Unsupported calling convention");
284 setValueSubclassData((getSubclassDataFromValue() & 0xc00f) | (
ID << 4));
299 : Count(Count), PCT(PCT) {}
315 void setEntryCount(
uint64_t Count, ProfileCountType
Type = PCT_Real,
322 std::optional<ProfileCount> getEntryCount(
bool AllowSynthetic =
false)
const;
330 return getEntryCount(IncludeSynthetic).has_value();
341 std::optional<StringRef> getSectionPrefix()
const;
346 return getSubclassDataFromValue() & (1<<14);
348 const std::string &getGC()
const;
349 void setGC(std::string Str);
360 void addAttributeAtIndex(
unsigned i,
Attribute Attr);
387 void addParamAttr(
unsigned ArgNo,
Attribute Attr);
390 void addParamAttrs(
unsigned ArgNo,
const AttrBuilder &Attrs);
396 void removeAttributeAtIndex(
unsigned i,
StringRef Kind);
419 void removeParamAttr(
unsigned ArgNo,
StringRef Kind);
422 void removeParamAttrs(
unsigned ArgNo,
const AttributeMask &Attrs);
428 bool hasFnAttribute(
StringRef Kind)
const;
437 bool hasParamAttribute(
unsigned ArgNo,
StringRef Kind)
const;
475 bool hasStackProtectorFnAttr()
const;
479 void addDereferenceableParamAttr(
unsigned ArgNo,
uint64_t Bytes);
483 void addDereferenceableOrNullParamAttr(
unsigned ArgNo,
uint64_t Bytes);
541 return hasFnAttribute(Attribute::PresplitCoroutine);
547 return hasFnAttribute(Attribute::CoroDestroyOnlyWhenComplete);
550 addFnAttr(Attribute::CoroDestroyOnlyWhenComplete);
557 bool doesNotAccessMemory()
const;
561 bool onlyReadsMemory()
const;
565 bool onlyWritesMemory()
const;
570 bool onlyAccessesArgMemory()
const;
575 bool onlyAccessesInaccessibleMemory()
const;
580 bool onlyAccessesInaccessibleMemOrArgMem()
const;
585 return hasFnAttribute(Attribute::NoReturn);
588 addFnAttr(Attribute::NoReturn);
596 return hasFnAttribute(Attribute::NoUnwind);
599 addFnAttr(Attribute::NoUnwind);
604 return hasFnAttribute(Attribute::NoDuplicate);
607 addFnAttr(Attribute::NoDuplicate);
612 return hasFnAttribute(Attribute::Convergent);
615 addFnAttr(Attribute::Convergent);
618 removeFnAttr(Attribute::Convergent);
623 return hasFnAttribute(Attribute::Speculatable);
626 addFnAttr(Attribute::Speculatable);
631 return onlyReadsMemory() || hasFnAttribute(Attribute::NoFree);
634 addFnAttr(Attribute::NoFree);
639 return hasFnAttribute(Attribute::NoSync);
642 addFnAttr(Attribute::NoSync);
648 return hasFnAttribute(Attribute::NoRecurse);
651 addFnAttr(Attribute::NoRecurse);
656 return hasFnAttribute(Attribute::MustProgress) ||
657 hasFnAttribute(Attribute::WillReturn);
662 bool willReturn()
const {
return hasFnAttribute(Attribute::WillReturn); }
673 return getUWTableKind() != UWTableKind::None;
676 if (K == UWTableKind::None)
677 removeFnAttr(Attribute::UWTable);
679 addFnAttr(Attribute::getWithUWTableKind(getContext(), K));
683 return hasUWTable() || !doesNotThrow() || hasPersonalityFn();
689 return AttributeSets.
hasParamAttr(0, Attribute::StructRet) ||
696 return AttributeSets.
hasRetAttr(Attribute::NoAlias);
701 bool hasOptNone()
const {
return hasFnAttribute(Attribute::OptimizeNone); }
704 bool hasMinSize()
const {
return hasFnAttribute(Attribute::MinSize); }
708 return hasFnAttribute(Attribute::OptimizeForSize) || hasMinSize();
726 void copyAttributesFrom(
const Function *Src);
732 deleteBodyImpl(
false);
733 setLinkage(ExternalLinkage);
739 void removeFromParent();
744 void eraseFromParent();
750 void stealArgumentListFrom(
Function &Src);
762 splice(ToIt, FromF, FromF->
begin(), FromF->
end());
769 auto FromItNext = std::next(FromIt);
771 if (ToIt == FromIt || ToIt == FromItNext)
773 splice(ToIt, FromF, FromIt, FromItNext);
788 friend void BasicBlock::removeFromParent();
790 template <
class BB_t,
class BB_i_t,
class BI_t,
class II_t>
805 return &Function::BasicBlocks;
833 void renumberBlocks();
847 void validateBlockNumbers()
const;
869 CheckLazyArguments();
873 CheckLazyArguments();
878 CheckLazyArguments();
882 CheckLazyArguments();
887 assert (i < NumArgs &&
"getArg() out of range!");
888 CheckLazyArguments();
906 return getSubclassDataFromValue() & (1<<3);
911 void setPersonalityFn(
Constant *Fn);
915 return getSubclassDataFromValue() & (1<<1);
920 void setPrefixData(
Constant *PrefixData);
924 return getSubclassDataFromValue() & (1<<2);
929 void setPrologueData(
Constant *PrologueData);
934 bool ShouldPreserveUseListOrder =
false,
935 bool IsForDebug =
false)
const;
947 void viewCFG(
const char *OutputFileName)
const;
952 const char *OutputFileName =
nullptr)
const;
959 void viewCFGOnly()
const;
963 void viewCFGOnly(
const char *OutputFileName)
const;
971 return V->getValueID() == Value::FunctionVal;
987 deleteBodyImpl(
true);
997 bool hasAddressTaken(
const User ** =
nullptr,
bool IgnoreCallbackUses =
false,
998 bool IgnoreAssumeLikeCalls =
true,
999 bool IngoreLLVMUsed =
false,
1000 bool IgnoreARCAttachedCall =
false,
1001 bool IgnoreCastedDirectCall =
false)
const;
1007 bool isDefTriviallyDead()
const;
1011 bool callsFunctionThatReturnsTwice()
const;
1025 bool shouldEmitDebugInfoForProfiling()
const;
1031 bool nullPointerIsDefined()
const;
1034 void allocHungoffUselist();
1035 template<
int Idx>
void setHungoffOperand(
Constant *
C);
1039 void setValueSubclassData(
unsigned short D) {
1040 Value::setValueSubclassData(
D);
1042 void setValueSubclassDataBit(
unsigned Bit,
bool On);
AMDGPU Lower Kernel Arguments
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
This file contains the simple types necessary to represent the attributes associated with functions a...
static bool setDoesNotAccessMemory(Function &F)
static bool setOnlyAccessesInaccessibleMemOrArgMem(Function &F)
static bool setOnlyAccessesInaccessibleMemory(Function &F)
static bool setOnlyAccessesArgMemory(Function &F)
static bool setOnlyWritesMemory(Function &F)
static bool setOnlyReadsMemory(Function &F)
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static void viewCFG(Function &F, const BlockFrequencyInfo *BFI, const BranchProbabilityInfo *BPI, uint64_t MaxFreq, bool CFGOnly=false)
static DISubprogram * getSubprogram(bool IsDistinct, Ts &&...Args)
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.
Machine Check Debug Module
II addRangeRetAttr(Range)
ToRemove erase(NewLastIter, ToRemove.end())
#define DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CLASS, VALUECLASS)
Macro for generating out-of-class operand accessor definitions.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static Type * getValueType(Value *V)
Returns the type of the given value/instruction V.
This class represents an incoming formal argument to a Function.
Type * getParamStructRetType(unsigned ArgNo) const
Return the sret type for the specified function parameter.
uint64_t getParamDereferenceableBytes(unsigned Index) const
Get the number of dereferenceable bytes (or zero if unknown) of an arg.
MaybeAlign getParamAlignment(unsigned ArgNo) const
Return the alignment for the specified function parameter.
Type * getParamInAllocaType(unsigned ArgNo) const
Return the inalloca type for the specified function parameter.
UWTableKind getUWTableKind() const
Get the unwind table kind requested for the function.
Type * getParamPreallocatedType(unsigned ArgNo) const
Return the preallocated type for the specified function parameter.
bool hasParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Return true if the attribute exists for the given argument.
MaybeAlign getFnStackAlignment() const
Get the stack alignment of the function.
Type * getParamByValType(unsigned ArgNo) const
Return the byval type for the specified function parameter.
MaybeAlign getParamStackAlignment(unsigned ArgNo) const
Return the stack alignment for the specified function parameter.
uint64_t getParamDereferenceableOrNullBytes(unsigned ArgNo) const
Get the number of dereferenceable_or_null bytes (or zero if unknown) of an arg.
FPClassTest getParamNoFPClass(unsigned ArgNo) const
Get the disallowed floating-point classes of the argument value.
Type * getParamByRefType(unsigned ArgNo) const
Return the byref type for the specified function parameter.
bool hasRetAttr(Attribute::AttrKind Kind) const
Return true if the attribute exists for the return value.
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
LLVM Basic Block Representation.
void setIsNewDbgInfoFormat(bool NewFlag)
Ensure the block is in "old" dbg.value format (NewFlag == false) or in the new format (NewFlag == tru...
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
Analysis providing branch probability information.
This class represents a range of values.
This is an important base class in LLVM.
A parsed version of the target data layout string in and methods for querying it.
Implements a dense probed hash-table based set.
Class to represent function types.
Class to represent profile counts.
uint64_t getCount() const
ProfileCount(uint64_t Count, ProfileCountType PCT)
ProfileCountType getType() const
void deleteBody()
deleteBody - This method deletes the body of the function, and converts the linkage to external.
const ValueSymbolTable * getValueSymbolTable() const
bool isConvergent() const
Determine if the call is convergent.
void setCoroDestroyOnlyWhenComplete()
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
BasicBlock & getEntryBlock()
void splice(Function::iterator ToIt, Function *FromF)
Transfer all blocks from FromF to this function at ToIt.
const BasicBlock & getEntryBlock() const
BasicBlockListType::iterator iterator
bool hasOptSize() const
Optimize this function for size (-Os) or minimum size (-Oz).
void splice(Function::iterator ToIt, Function *FromF, Function::iterator FromIt)
Transfer one BasicBlock from FromF at FromIt to this function at ToIt.
FunctionType * getFunctionType() const
Returns the FunctionType for me.
bool isMaterializable() const
MaybeAlign getFnStackAlign() const
Return the stack alignment for the function.
iterator_range< const_arg_iterator > args() const
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
const BasicBlock & front() const
const_arg_iterator arg_end() const
const_arg_iterator arg_begin() const
bool mustProgress() const
Determine if the function is required to make forward progress.
bool returnDoesNotAlias() const
Determine if the parameter or return value is marked with NoAlias attribute.
bool cannotDuplicate() const
Determine if the call cannot be duplicated.
const BasicBlock & back() const
unsigned getMaxBlockNumber() const
Return a value larger than the largest block number.
bool willReturn() const
Determine if the function will return.
iterator_range< arg_iterator > args()
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
bool doesNotRecurse() const
Determine if the function is known not to recurse, directly or indirectly.
bool hasMinSize() const
Optimize this function for minimum size (-Oz).
bool doesNoCfCheck() const
Determine if the function should not perform indirect branch tracking.
void setIsMaterializable(bool V)
uint64_t getParamDereferenceableBytes(unsigned ArgNo) const
Extract the number of dereferenceable bytes for a parameter.
bool isSpeculatable() const
Determine if the call has sideeffects.
bool hasGC() const
hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm to use during code generatio...
bool IsNewDbgInfoFormat
Is this function using intrinsics to record the position of debugging information,...
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Type * getParamByValType(unsigned ArgNo) const
Extract the byval type for a parameter.
FPClassTest getParamNoFPClass(unsigned ArgNo) const
Extract the nofpclass attribute for a parameter.
bool hasPrefixData() const
Check whether this function has prefix data.
void setReturnDoesNotAlias()
bool hasPersonalityFn() const
Check whether this function has a personality function.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, const Twine &N="", Module *M=nullptr)
AttributeList getAttributes() const
Return the attribute list for this Function.
void dropAllReferences()
dropAllReferences() - This method causes all the subinstructions to "let go" of all references that t...
unsigned getBlockNumberEpoch() const
Return the "epoch" of current block numbers.
void setUWTableKind(UWTableKind K)
BasicBlockListType::const_iterator const_iterator
UWTableKind getUWTableKind() const
Get what kind of unwind table entry to generate for this function.
Type * getParamByRefType(unsigned ArgNo) const
Extract the byref type for a parameter.
bool hasNoSync() const
Determine if the call can synchroize with other threads.
bool doesNotThrow() const
Determine if the function cannot unwind.
const Function & getFunction() const
const_iterator end() const
uint64_t getParamDereferenceableOrNullBytes(unsigned ArgNo) const
Extract the number of dereferenceable_or_null bytes for a parameter.
bool isIntrinsic() const
isIntrinsic - Returns true if the function's name starts with "llvm.".
bool hasProfileData(bool IncludeSynthetic=false) const
Return true if the function is annotated with profile data.
const_iterator begin() const
void setPresplitCoroutine()
MaybeAlign getParamAlign(unsigned ArgNo) const
ValueSymbolTable * getValueSymbolTable()
getSymbolTable() - Return the symbol table if any, otherwise nullptr.
bool hasOptNone() const
Do not optimize this function (-O0).
void setCannotDuplicate()
Type * getParamPreallocatedType(unsigned ArgNo) const
Extract the preallocated type for a parameter.
void setAttributes(AttributeList Attrs)
Set the attribute list for this Function.
bool isPresplitCoroutine() const
Determine if the function is presplit coroutine.
bool hasStructRetAttr() const
Determine if the function returns a structure through first or second pointer argument.
Function::iterator insert(Function::iterator Position, BasicBlock *BB)
Insert BB in the basic block list at Position.
bool doesNotFreeMemory() const
Determine if the call might deallocate memory.
Type * getParamInAllocaType(unsigned ArgNo) const
Extract the inalloca type for a parameter.
bool doesNotReturn() const
Determine if the function cannot return.
bool isCoroOnlyDestroyWhenComplete() const
void setSplittedCoroutine()
MaybeAlign getParamStackAlign(unsigned ArgNo) const
bool hasUWTable() const
True if the ABI mandates (or the user requested) that this function be in a unwind table.
void operator=(const Function &)=delete
Type * getReturnType() const
Returns the type of the ret val.
bool needsUnwindTableEntry() const
True if this function needs an unwind table.
bool hasLazyArguments() const
hasLazyArguments/CheckLazyArguments - The argument list of a function is built on demand,...
void setCallingConv(CallingConv::ID CC)
Function(const Function &)=delete
bool hasPrologueData() const
Check whether this function has prologue data.
Type * getParamStructRetType(unsigned ArgNo) const
Extract the sret type for a parameter.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Argument * getArg(unsigned i) const
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
void setDoesNotFreeMemory()
LinkageTypes
An enumeration for the kinds of linkage for global values.
This is an important class for using LLVM in a threaded context.
A Module instance is used to store all the information related to an LLVM module.
iterator insert(iterator I, T &&Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
Implementation of the target library information.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
This class provides a symbol table of name/value pairs.
LLVM Value Representation.
An ilist node that can access its parent list.
base_list_type::iterator iterator
A range adaptor for a pair of iterators.
This class implements an extremely fast bulk output stream that can only output to a stream.
This file defines the ilist_node class template, which is a convenient base class for creating classe...
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
@ User
could "use" a pointer
This is an optimization pass for GlobalISel generic memory operations.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
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 ...
Represent subnormal handling kind for floating point instruction inputs and outputs.
HungoffOperandTraits - determine the allocation regime of the Use array when it is not a prefix to th...
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Compile-time customization of User operands.
Indicates this User has operands "hung off" in another allocation.