Go to the documentation of this file.
17 #ifndef LLVM_IR_FUNCTION_H
18 #define LLVM_IR_FUNCTION_H
47 class AssemblyAnnotationWriter;
53 template <
typename T>
class Optional;
57 class BranchProbabilityInfo;
58 class BlockFrequencyInfo;
77 std::unique_ptr<ValueSymbolTable>
96 IsMaterializableBit = 0,
107 return getSubclassDataFromValue() & (1<<0);
111 void CheckLazyArguments()
const {
112 if (hasLazyArguments())
113 BuildLazyArguments();
116 void BuildLazyArguments()
const;
118 void clearArguments();
125 const Twine &
N =
"",
Module *
M =
nullptr);
128 Function(
const Function&) =
delete;
129 void operator=(
const Function&) =
delete;
138 unsigned AddrSpace,
const Twine &
N =
"",
172 unsigned getInstructionCount()
const;
176 return cast<FunctionType>(getValueType());
188 bool isVarArg()
const {
return getFunctionType()->isVarArg(); }
191 return getGlobalObjectSubClassData() & (1 << IsMaterializableBit);
194 unsigned Mask = 1 << IsMaterializableBit;
195 setGlobalObjectSubClassData((~
Mask & getGlobalObjectSubClassData()) |
219 bool isTargetIntrinsic()
const;
224 bool isConstrainedFPIntrinsic()
const;
233 void recalculateIntrinsicID();
239 return static_cast<CallingConv::ID>((getSubclassDataFromValue() >> 4) &
243 auto ID =
static_cast<unsigned>(CC);
245 setValueSubclassData((getSubclassDataFromValue() & 0xc00f) | (
ID << 4));
260 : Count(Count), PCT(PCT) {}
276 void setEntryCount(
uint64_t Count, ProfileCountType
Type = PCT_Real,
291 return getEntryCount(IncludeSynthetic).has_value();
307 return getSubclassDataFromValue() & (1<<14);
309 const std::string &getGC()
const;
310 void setGC(std::string Str);
321 void addAttributeAtIndex(
unsigned i,
Attribute Attr);
348 void addParamAttr(
unsigned ArgNo,
Attribute Attr);
414 void removeParamUndefImplyingAttrs(
unsigned ArgNo);
422 bool hasStackProtectorFnAttr()
const;
426 void addDereferenceableParamAttr(
unsigned ArgNo,
uint64_t Bytes);
430 void addDereferenceableOrNullParamAttr(
unsigned ArgNo,
uint64_t Bytes);
436 if (
const auto MA = getParamAlign(ArgNo))
489 return hasFnAttribute(Attribute::PresplitCoroutine);
496 return hasFnAttribute(Attribute::ReadNone);
499 addFnAttr(Attribute::ReadNone);
504 return doesNotAccessMemory() || hasFnAttribute(Attribute::ReadOnly);
507 addFnAttr(Attribute::ReadOnly);
512 return doesNotAccessMemory() || hasFnAttribute(Attribute::WriteOnly);
515 addFnAttr(Attribute::WriteOnly);
521 return hasFnAttribute(Attribute::ArgMemOnly);
528 return hasFnAttribute(Attribute::InaccessibleMemOnly);
531 addFnAttr(Attribute::InaccessibleMemOnly);
537 return hasFnAttribute(Attribute::InaccessibleMemOrArgMemOnly);
540 addFnAttr(Attribute::InaccessibleMemOrArgMemOnly);
545 return hasFnAttribute(Attribute::NoReturn);
548 addFnAttr(Attribute::NoReturn);
556 return hasFnAttribute(Attribute::NoUnwind);
559 addFnAttr(Attribute::NoUnwind);
564 return hasFnAttribute(Attribute::NoDuplicate);
567 addFnAttr(Attribute::NoDuplicate);
583 return hasFnAttribute(Attribute::Speculatable);
586 addFnAttr(Attribute::Speculatable);
591 return onlyReadsMemory() || hasFnAttribute(Attribute::NoFree);
594 addFnAttr(Attribute::NoFree);
599 return hasFnAttribute(Attribute::NoSync);
602 addFnAttr(Attribute::NoSync);
608 return hasFnAttribute(Attribute::NoRecurse);
611 addFnAttr(Attribute::NoRecurse);
616 return hasFnAttribute(Attribute::MustProgress) ||
617 hasFnAttribute(Attribute::WillReturn);
622 bool willReturn()
const {
return hasFnAttribute(Attribute::WillReturn); }
640 return hasUWTable() || !doesNotThrow() || hasPersonalityFn();
646 return AttributeSets.
hasParamAttr(0, Attribute::StructRet) ||
653 return AttributeSets.
hasRetAttr(Attribute::NoAlias);
658 bool hasOptNone()
const {
return hasFnAttribute(Attribute::OptimizeNone); }
661 bool hasMinSize()
const {
return hasFnAttribute(Attribute::MinSize); }
665 return hasFnAttribute(Attribute::OptimizeForSize) || hasMinSize();
674 void copyAttributesFrom(
const Function *Src);
681 setLinkage(ExternalLinkage);
687 void removeFromParent();
692 void eraseFromParent();
698 void stealArgumentListFrom(
Function &Src);
707 return &Function::BasicBlocks;
731 size_t size()
const {
return BasicBlocks.size(); }
732 bool empty()
const {
return BasicBlocks.empty(); }
742 CheckLazyArguments();
746 CheckLazyArguments();
751 CheckLazyArguments();
755 CheckLazyArguments();
760 assert (
i < NumArgs &&
"getArg() out of range!");
761 CheckLazyArguments();
779 return getSubclassDataFromValue() & (1<<3);
784 void setPersonalityFn(
Constant *Fn);
788 return getSubclassDataFromValue() & (1<<1);
793 void setPrefixData(
Constant *PrefixData);
797 return getSubclassDataFromValue() & (1<<2);
802 void setPrologueData(
Constant *PrologueData);
807 bool ShouldPreserveUseListOrder =
false,
808 bool IsForDebug =
false)
const;
827 void viewCFGOnly()
const;
850 void dropAllReferences();
858 bool hasAddressTaken(
const User ** =
nullptr,
859 bool IgnoreCallbackUses =
false,
860 bool IgnoreAssumeLikeCalls =
true,
861 bool IngoreLLVMUsed =
false,
862 bool IgnoreARCAttachedCall =
false)
const;
868 bool isDefTriviallyDead()
const;
872 bool callsFunctionThatReturnsTwice()
const;
886 bool isDebugInfoForProfiling()
const;
892 bool nullPointerIsDefined()
const;
895 void allocHungoffUselist();
896 template<
int Idx>
void setHungoffOperand(
Constant *
C);
900 void setValueSubclassData(
unsigned short D) {
903 void setValueSubclassDataBit(
unsigned Bit,
bool On);
920 #endif // LLVM_IR_FUNCTION_H
Type * getParamInAllocaType(unsigned ArgNo) const
Return the inalloca type for the specified function parameter.
BasicBlockListType & getBasicBlockList()
@ User
could "use" a pointer
This class represents an incoming formal argument to a Function.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, const Twine &N="", Module *M=nullptr)
void setOnlyAccessesInaccessibleMemOrArgMem()
bool isIntrinsic() const
isIntrinsic - Returns true if the function's name starts with "llvm.".
This is an optimization pass for GlobalISel generic memory operations.
iterator_range< arg_iterator > args()
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
bool onlyWritesMemory() const
Determine if the function does not access or only writes memory.
bool hasOptNone() const
Do not optimize this function (-O0).
const BasicBlockListType & getBasicBlockList() const
Get the underlying elements of the Function...
bool doesNoCfCheck() const
Determine if the function should not perform indirect branch tracking.
uint64_t getParamDereferenceableBytes(unsigned ArgNo) const
Extract the number of dereferenceable bytes for a parameter.
Type * getParamPreallocatedType(unsigned ArgNo) const
Return the preallocated type for the specified function parameter.
MaybeAlign getFnStackAlign() const
Return the stack alignment for the function.
@ None
No unwind table requested.
Type * getParamByValType(unsigned ArgNo) const
Extract the byval type for a parameter.
UWTableKind getUWTableKind() const
Get the unwind table kind requested for the function.
const_iterator begin() const
static void viewCFG(Function &F, const BlockFrequencyInfo *BFI, const BranchProbabilityInfo *BPI, uint64_t MaxFreq, bool CFGOnly=false)
const BasicBlock & getEntryBlock() const
Type * getParamByValType(unsigned ArgNo) const
Return the byval type for the specified function parameter.
The instances of the Type class are immutable: once they are created, they are never changed.
#define DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CLASS, VALUECLASS)
Macro for generating out-of-class operand accessor definitions.
void setCannotDuplicate()
LinkageTypes
An enumeration for the kinds of linkage for global values.
void setValueSubclassData(unsigned short D)
LLVM Basic Block Representation.
uint64_t getParamDereferenceableBytes(unsigned Index) const
Get the number of dereferenceable bytes (or zero if unknown) of an arg.
void setOnlyAccessesArgMemory()
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
MaybeAlign getParamStackAlignment(unsigned ArgNo) const
Return the stack alignment for the specified function parameter.
bool hasUWTable() const
True if the ABI mandates (or the user requested) that this function be in a unwind table.
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
static BasicBlockListType Function::* getSublistAccess(BasicBlock *)
Compile-time customization of User operands.
const_iterator end() const
BasicBlock & getEntryBlock()
bool onlyAccessesInaccessibleMemory() const
Determine if the function may only access memory that is inaccessible from the IR.
(vector float) vec_cmpeq(*A, *B) C
uint64_t getParamDereferenceableOrNullBytes(unsigned ArgNo) const
Get the number of dereferenceable_or_null bytes (or zero if unknown) of an arg.
Analysis providing branch probability information.
bool cannotDuplicate() const
Determine if the call cannot be duplicated.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
unsigned getValueID() const
Return an ID for the concrete type of this object.
ProfileCount(uint64_t Count, ProfileCountType PCT)
This class implements an extremely fast bulk output stream that can only output to a stream.
bool hasPersonalityFn() const
Check whether this function has a personality function.
void setUWTableKind(UWTableKind K)
void setPresplitCoroutine()
bool isSpeculatable() const
Determine if the call has sideeffects.
bool isMaterializable() const
bool doesNotAccessMemory() const
Determine if the function does not access memory.
Type * getParamInAllocaType(unsigned ArgNo) const
Extract the inalloca type for a parameter.
const ValueSymbolTable * getValueSymbolTable() const
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
bool hasPrologueData() const
Check whether this function has prologue data.
AttributeList getAttributes() const
Return the attribute list for this Function.
Implements a dense probed hash-table based set.
void setDoesNotFreeMemory()
This is an important base class in LLVM.
Type * getReturnType() const
Returns the type of the ret val.
bool willReturn() const
Determine if the function will return.
bool hasPrefixData() const
Check whether this function has prefix data.
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
#define LLVM_EXTERNAL_VISIBILITY
bool hasGC() const
hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm to use during code generatio...
static Attribute getWithUWTableKind(LLVMContext &Context, UWTableKind Kind)
void setDoesNotAccessMemory()
This is an important class for using LLVM in a threaded context.
iterator_range< const_arg_iterator > args() const
Represent subnormal handling kind for floating point instruction inputs and outputs.
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
Type * getParamPreallocatedType(unsigned ArgNo) const
Extract the preallocated type for a parameter.
MaybeAlign getParamAlignment(unsigned ArgNo) const
Return the alignment for the specified function parameter.
bool hasStructRetAttr() const
Determine if the function returns a structure through first or second pointer argument.
static DISubprogram * getSubprogram(bool IsDistinct, Ts &&...Args)
bool onlyAccessesInaccessibleMemOrArgMem() const
Determine if the function may only access memory that is either inaccessible from the IR or pointed t...
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
@ MaxID
The highest possible calling convention ID. Must be some 2^k - 1.
typename SuperClass::const_iterator const_iterator
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
A Module instance is used to store all the information related to an LLVM module.
bool doesNotRecurse() const
Determine if the function is known not to recurse, directly or indirectly.
const Function & getFunction() const
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
bool isConvergent() const
Determine if the call is convergent.
StringRef - Represent a constant reference to a string, i.e.
void setCallingConv(CallingConv::ID CC)
Type * getParamByRefType(unsigned ArgNo) const
Return the byref type for the specified function parameter.
MaybeAlign getParamAlign(unsigned ArgNo) const
ProfileCountType getType() const
Machine Check Debug Module
void setOnlyReadsMemory()
Linkage
Describes symbol linkage.
void setIsMaterializable(bool V)
bool doesNotFreeMemory() const
Determine if the call might deallocate memory.
bool hasOptSize() const
Optimize this function for size (-Os) or minimum size (-Oz).
uint64_t getCount() const
bool returnDoesNotAlias() const
Determine if the parameter or return value is marked with NoAlias attribute.
bool doesNotThrow() const
Determine if the function cannot unwind.
bool hasLazyArguments() const
hasLazyArguments/CheckLazyArguments - The argument list of a function is built on demand,...
uint64_t getParamAlignment(unsigned ArgNo) const
Extract the alignment for a call or parameter (0=unknown).
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
ValueSymbolTable * getValueSymbolTable()
getSymbolTable() - Return the symbol table if any, otherwise nullptr.
Argument * getArg(unsigned i) const
const BasicBlock & back() const
uint64_t getParamDereferenceableOrNullBytes(unsigned ArgNo) const
Extract the number of dereferenceable_or_null bytes for a parameter.
Type * getParamStructRetType(unsigned ArgNo) const
Return the sret type for the specified function parameter.
UWTableKind getUWTableKind() const
Get what kind of unwind table entry to generate for this function.
bool needsUnwindTableEntry() const
True if this function needs an unwind table.
AMDGPU Lower Kernel Arguments
FunctionType * getFunctionType() const
Returns the FunctionType for me.
bool hasProfileData(bool IncludeSynthetic=false) const
Return true if the function is annotated with profile data.
bool onlyAccessesArgMemory() const
Determine if the call can access memmory only using pointers based on its arguments.
bool mustProgress() const
Determine if the function is required to make forward progress.
MaybeAlign getParamStackAlign(unsigned ArgNo) const
void deleteBody()
deleteBody - This method deletes the body of the function, and converts the linkage to external.
Type * getParamByRefType(unsigned ArgNo) const
Extract the byref type for a parameter.
const BasicBlock & front() const
#define DECLARE_TRANSPARENT_OPERAND_ACCESSORS(VALUECLASS)
Macro for generating in-class operand accessor declarations.
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
const_arg_iterator arg_end() const
This class provides a symbol table of name/value pairs.
typename SuperClass::iterator iterator
bool hasRetAttr(Attribute::AttrKind Kind) const
Return true if the attribute exists for the return value.
A range adaptor for a pair of iterators.
bool doesNotReturn() const
Determine if the function cannot return.
bool onlyReadsMemory() const
Determine if the function does not access or only reads memory.
bool hasMinSize() const
Optimize this function for minimum size (-Oz).
void setOnlyAccessesInaccessibleMemory()
bool hasNoSync() const
Determine if the call can synchroize with other threads.
Class to represent profile counts.
void setOnlyWritesMemory()
HungoffOperandTraits - determine the allocation regime of the Use array when it is not a prefix to th...
bool NullPointerIsDefined(const Function *F, unsigned AS=0)
Check whether null pointer dereferencing is considered undefined behavior for a given function or an ...
const_arg_iterator arg_begin() const
bool hasParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Return true if the attribute exists for the given argument.
void setSplittedCoroutine()
Type * getParamStructRetType(unsigned ArgNo) const
Extract the sret type for a parameter.
void setAttributes(AttributeList Attrs)
Set the attribute list for this Function.
LLVM Value Representation.
bool isPresplitCoroutine() const
Determine if the function is presplit coroutine.
BasicBlockListType::const_iterator const_iterator
void setReturnDoesNotAlias()
Class to represent function types.
MaybeAlign getFnStackAlignment() const
Get the stack alignment of the function.
BasicBlockListType::iterator iterator