17#ifndef LLVM_IR_FUNCTION_H
18#define LLVM_IR_FUNCTION_H
55enum LibFunc : unsigned;
83 friend void BasicBlock::setParent(Function *);
84 unsigned NextBlockNum = 0;
86 unsigned BlockNumEpoch = 0;
88 mutable Argument *Arguments =
nullptr;
91 std::unique_ptr<ValueSymbolTable>
93 AttributeList AttributeSets;
110 IsMaterializableBit = 0,
125 void convertToNewDbgValues();
129 bool convertFromNewDbgValues();
134 static constexpr LibFunc UnknownLibFunc = LibFunc(-1);
139 mutable LibFunc LibFuncCache = UnknownLibFunc;
141 void CheckLazyArguments()
const {
143 BuildLazyArguments();
146 void BuildLazyArguments()
const;
148 void clearArguments();
150 void deleteBodyImpl(
bool ShouldDrop);
170 unsigned AddrSpace,
const Twine &
N =
"",
172 return new (AllocMarker) Function(Ty,
Linkage, AddrSpace,
N, M);
178 return new (AllocMarker)
179 Function(Ty,
Linkage,
static_cast<unsigned>(-1),
N, M);
236 unsigned Mask = 1 << IsMaterializableBit;
257 bool isTargetIntrinsic()
const;
262 bool isConstrainedFPIntrinsic()
const;
268 void updateAfterNameChange();
278 auto ID =
static_cast<unsigned>(CC);
307 std::optional<uint64_t> getEntryCount()
const;
324 const std::string &getGC()
const;
325 void setGC(std::string Str);
336 void addAttributeAtIndex(
unsigned i,
Attribute Attr);
348 void addFnAttrs(
const AttrBuilder &Attrs);
357 void addRetAttrs(
const AttrBuilder &Attrs);
363 void addParamAttr(
unsigned ArgNo,
Attribute Attr);
366 void addParamAttrs(
unsigned ArgNo,
const AttrBuilder &Attrs);
372 void removeAttributeAtIndex(
unsigned i,
StringRef Kind);
395 void removeParamAttr(
unsigned ArgNo,
StringRef Kind);
398 void removeParamAttrs(
unsigned ArgNo,
const AttributeMask &Attrs);
404 bool hasFnAttribute(
StringRef Kind)
const;
413 bool hasParamAttribute(
unsigned ArgNo,
StringRef Kind)
const;
447 return AttributeSets.getFnStackAlignment();
451 bool hasStackProtectorFnAttr()
const;
455 void addDereferenceableParamAttr(
unsigned ArgNo,
uint64_t Bytes);
459 void addDereferenceableOrNullParamAttr(
unsigned ArgNo,
uint64_t Bytes);
465 return AttributeSets.getParamAlignment(ArgNo);
469 return AttributeSets.getParamStackAlignment(ArgNo);
474 return AttributeSets.getParamByValType(ArgNo);
479 return AttributeSets.getParamStructRetType(ArgNo);
484 return AttributeSets.getParamInAllocaType(ArgNo);
489 return AttributeSets.getParamByRefType(ArgNo);
494 return AttributeSets.getParamPreallocatedType(ArgNo);
500 return AttributeSets.getParamDereferenceableBytes(ArgNo);
506 return AttributeSets.getDeadOnReturnInfo(ArgNo);
513 return AttributeSets.getParamDereferenceableOrNullBytes(ArgNo);
518 return AttributeSets.getParamNoFPClass(ArgNo);
532 addFnAttr(Attribute::CoroDestroyOnlyWhenComplete);
539 bool doesNotAccessMemory()
const;
543 bool onlyReadsMemory()
const;
547 bool onlyWritesMemory()
const;
552 bool onlyAccessesArgMemory()
const;
557 bool onlyAccessesInaccessibleMemory()
const;
558 void setOnlyAccessesInaccessibleMemory();
562 bool onlyAccessesInaccessibleMemOrArgMem()
const;
652 return AttributeSets.getUWTableKind();
674 return AttributeSets.hasParamAttr(0, Attribute::StructRet) ||
675 AttributeSets.hasParamAttr(1, Attribute::StructRet);
681 return AttributeSets.hasRetAttr(Attribute::NoAlias);
712 void copyAttributesFrom(
const Function *Src);
718 deleteBodyImpl(
false);
725 void removeFromParent();
730 void eraseFromParent();
736 void stealArgumentListFrom(
Function &Src);
754 auto FromItNext = std::next(FromIt);
756 if (ToIt == FromIt || ToIt == FromItNext)
758 splice(ToIt, FromF, FromIt, FromItNext);
775 template <
class BB_t,
class BB_i_t,
class BI_t,
class II_t>
790 return &Function::BasicBlocks;
818 void renumberBlocks();
832 void validateBlockNumbers()
const;
843 size_t size()
const {
return BasicBlocks.size(); }
844 bool empty()
const {
return BasicBlocks.empty(); }
854 CheckLazyArguments();
858 CheckLazyArguments();
863 CheckLazyArguments();
864 return Arguments + NumArgs;
867 CheckLazyArguments();
868 return Arguments + NumArgs;
872 assert (i < NumArgs &&
"getArg() out of range!");
873 CheckLazyArguments();
874 return Arguments + i;
896 void setPersonalityFn(
Constant *Fn);
905 void setPrefixData(
Constant *PrefixData);
914 void setPrologueData(
Constant *PrologueData);
919 bool ShouldPreserveUseListOrder =
false,
920 bool IsForDebug =
false)
const;
932 void viewCFG(
const char *OutputFileName)
const;
937 const char *OutputFileName =
nullptr)
const;
944 void viewCFGOnly()
const;
948 void viewCFGOnly(
const char *OutputFileName)
const;
956 return V->getValueID() == Value::FunctionVal;
972 deleteBodyImpl(
true);
982 bool hasAddressTaken(
const User ** =
nullptr,
bool IgnoreCallbackUses =
false,
983 bool IgnoreAssumeLikeCalls =
true,
984 bool IngoreLLVMUsed =
false,
985 bool IgnoreARCAttachedCall =
false,
986 bool IgnoreCastedDirectCall =
false)
const;
992 bool isDefTriviallyDead()
const;
996 bool callsFunctionThatReturnsTwice()
const;
1010 bool shouldEmitDebugInfoForProfiling()
const;
1016 bool nullPointerIsDefined()
const;
1041 unsigned getVScaleValue()
const;
1044 void allocHungoffUselist();
1045 template<
int Idx>
void setHungoffOperand(
Constant *
C);
1049 void setValueSubclassData(
unsigned short D) {
1052 void setValueSubclassDataBit(
unsigned Bit,
bool On);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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 setMemoryEffects(Function &F, MemoryEffects ME)
static bool setOnlyAccessesInaccessibleMemOrArgMem(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)
SmallVector< BasicBlock *, 8 > BasicBlockListType
static DISubprogram * getSubprogram(bool IsDistinct, Ts &&...Args)
This file defines the DenseSet and SmallDenseSet classes.
II addRangeRetAttr(Range)
#define DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CLASS, VALUECLASS)
Macro for generating out-of-class operand accessor definitions.
static DenormalFPEnv getDenormalFPEnv(const MachineFunction &MF)
Func getContext().diagnose(DiagnosticInfoUnsupported(Func
This class represents an incoming formal argument to a Function.
This class stores enough information to efficiently remove some attributes from an existing AttrBuild...
Functions, function parameters, and return types can have attributes to indicate how they should be t...
static LLVM_ABI Attribute getWithUWTableKind(LLVMContext &Context, UWTableKind Kind)
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
LLVM Basic Block Representation.
const Instruction & back() const
friend void Instruction::removeFromParent()
friend BasicBlock::iterator Instruction::eraseFromParent()
const Instruction & front() const
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.
Subprogram description. Uses SubclassData1.
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.
void deleteBody()
deleteBody - This method deletes the body of the function, and converts the linkage to external.
void addFnAttr(Attribute::AttrKind Kind)
Add function attributes to this function.
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()
SymbolTableList< BasicBlock > BasicBlockListType
void setAlignment(MaybeAlign Align)
Sets the alignment attribute of the Function.
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 getAlign() const
Returns the alignment of the given function.
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...
friend class TargetLibraryInfoImpl
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...
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.
void addRetAttr(Attribute::AttrKind Kind)
Add return value attributes to this 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 "letgo" of all references that th...
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.
void removeFnAttr(Attribute::AttrKind Kind)
Remove function attributes from this function.
bool isIntrinsic() const
isIntrinsic - Returns true if the function's name starts with "llvm.".
const_iterator begin() const
void setPresplitCoroutine()
void setAlignment(Align Align)
Sets the alignment attribute of the Function.
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).
std::optional< uint64_t > getEntryCount() const
Get the entry count for this function.
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 hasProfileData() const
Return true if the function is annotated with profile data.
bool hasKernelCallingConv() const
Does it have a kernel calling convention?
void setPreferredAlignment(MaybeAlign Align)
Sets the prefalign attribute of the Function.
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.
friend class InstIterator
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,...
bool isStrictFP() const
Determine if the function has strict floating point sematics.
MaybeAlign getPreferredAlignment() const
Returns the prefalign of the given function.
void setCallingConv(CallingConv::ID CC)
Function(const Function &)=delete
bool hasPrologueData() const
Check whether this function has prologue data.
const Argument * const_arg_iterator
DeadOnReturnInfo getDeadOnReturnInfo(unsigned ArgNo) const
Extract the number of dead_on_return bytes for a parameter.
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.
unsigned getInstructionCount() const
Returns the number of non-debug IR instructions in this function.
bool onlyReadsMemory() const
Determine if the function does not access or only reads memory.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
void setDoesNotFreeMemory()
bool canChangeSignature() const
Determine whether interprocedural transforms may rewrite this function's signature.
MaybeAlign getAlign() const
Returns the alignment of the given variable or function.
LLVM_ABI void setAlignment(Align Align)
Sets the alignment attribute of the GlobalObject.
GlobalObject(Type *Ty, ValueTy VTy, AllocInfo AllocInfo, LinkageTypes Linkage, const Twine &Name, unsigned AddressSpace=0)
void setGlobalObjectSubClassData(unsigned Val)
unsigned getGlobalObjectSubClassData() const
Intrinsic::ID IntID
The intrinsic ID for this subclass (which must be a Function).
unsigned HasLLVMReservedName
True if the function's name starts with "llvm.".
void setLinkage(LinkageTypes LT)
LinkageTypes
An enumeration for the kinds of linkage for global values.
@ ExternalLinkage
Externally visible function.
Type * getValueType() const
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.
Represent a constant reference to a string, i.e.
List that automatically updates parent links and symbol tables.
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.
unsigned short getSubclassDataFromValue() const
void setValueSubclassData(unsigned short D)
An ilist node that can access its parent list.
typename base_list_type::iterator iterator
typename base_list_type::const_iterator const_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.
FollowingPoolPopCache erase(Autorelease)
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.
CallingConv Namespace - This namespace contains an enum with a value for the well-known calling conve...
LLVM_ABI LLVM_READNONE bool supportsNonVoidReturnType(CallingConv::ID CC)
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ AMDGPU_KERNEL
Used for AMDGPU code object kernels.
@ MaxID
The highest possible ID. Must be some 2^k - 1.
@ SPIR_KERNEL
Used for SPIR kernel functions.
@ PTX_Kernel
Call to a PTX kernel. Passes all arguments in parameter space.
This namespace contains an enum with a value for every intrinsic/builtin function known by LLVM.
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.
MemoryEffectsBase< IRMemLocation > MemoryEffects
Summary of how a function affects memory in the program.
@ None
No unwind table requested.
FPClassTest
Floating-point class tests, supported by 'is_fpclass' intrinsic.
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 ...
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
@ Default
The result value is uniform if and only if all operands are uniform.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Represents the full denormal controls for a function, including the default mode and the f32 specific...
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.