17 #ifndef LLVM_IR_FUNCTION_H 18 #define LLVM_IR_FUNCTION_H 49 class AssemblyAnnotationWriter;
54 template <
typename T>
class Optional;
75 std::unique_ptr<ValueSymbolTable>
94 IsMaterializableBit = 0,
105 return getSubclassDataFromValue() & (1<<0);
109 void CheckLazyArguments()
const {
110 if (hasLazyArguments())
111 BuildLazyArguments();
114 void BuildLazyArguments()
const;
116 void clearArguments();
127 void operator=(
const Function&) =
delete;
136 unsigned AddrSpace,
const Twine &
N =
"",
138 return new Function(Ty, Linkage, AddrSpace,
N, M);
144 return new Function(Ty, Linkage, static_cast<unsigned>(-1),
N, M);
160 unsigned getInstructionCount()
const;
164 return cast<FunctionType>(getValueType());
176 bool isVarArg()
const {
return getFunctionType()->isVarArg(); }
179 return getGlobalObjectSubClassData() & (1 << IsMaterializableBit);
182 unsigned Mask = 1 << IsMaterializableBit;
183 setGlobalObjectSubClassData((~Mask & getGlobalObjectSubClassData()) |
207 void recalculateIntrinsicID();
213 return static_cast<CallingConv::ID>((getSubclassDataFromValue() >> 4) &
217 auto ID =
static_cast<unsigned>(CC);
219 setValueSubclassData((getSubclassDataFromValue() & 0xc00f) | (
ID << 4));
269 : Count(Count), PCT(PCT) {}
270 bool hasValue()
const {
return PCT != PCT_Invalid; }
274 explicit operator bool() {
return hasValue(); }
301 ProfileCount getEntryCount(
bool AllowSynthetic =
false)
const;
309 return getEntryCount(IncludeSynthetic).
hasValue();
344 if (!hasFnAttribute(Attribute::StackAlignment))
355 return getSubclassDataFromValue() & (1<<14);
357 const std::string &getGC()
const;
358 void setGC(std::string Str);
365 void addAttribute(
unsigned i,
Attribute Attr);
374 void addParamAttr(
unsigned ArgNo,
Attribute Attr);
377 void addParamAttrs(
unsigned ArgNo,
const AttrBuilder &Attrs);
383 void removeAttribute(
unsigned i,
StringRef Kind);
386 void removeAttributes(
unsigned i,
const AttrBuilder &Attrs);
392 void removeParamAttr(
unsigned ArgNo,
StringRef Kind);
395 void removeParamAttrs(
unsigned ArgNo,
const AttrBuilder &Attrs);
423 void addDereferenceableAttr(
unsigned i, uint64_t Bytes);
427 void addDereferenceableParamAttr(
unsigned ArgNo, uint64_t Bytes);
431 void addDereferenceableOrNullAttr(
unsigned i, uint64_t Bytes);
435 void addDereferenceableOrNullParamAttr(
unsigned ArgNo, uint64_t Bytes);
441 if (
const auto MA = getParamAlign(ArgNo))
485 return hasFnAttribute(Attribute::ReadNone);
488 addFnAttr(Attribute::ReadNone);
493 return doesNotAccessMemory() || hasFnAttribute(Attribute::ReadOnly);
496 addFnAttr(Attribute::ReadOnly);
501 return doesNotAccessMemory() || hasFnAttribute(Attribute::WriteOnly);
504 addFnAttr(Attribute::WriteOnly);
510 return hasFnAttribute(Attribute::ArgMemOnly);
517 return hasFnAttribute(Attribute::InaccessibleMemOnly);
520 addFnAttr(Attribute::InaccessibleMemOnly);
526 return hasFnAttribute(Attribute::InaccessibleMemOrArgMemOnly);
529 addFnAttr(Attribute::InaccessibleMemOrArgMemOnly);
534 return hasFnAttribute(Attribute::NoReturn);
537 addFnAttr(Attribute::NoReturn);
545 return hasFnAttribute(Attribute::NoUnwind);
548 addFnAttr(Attribute::NoUnwind);
553 return hasFnAttribute(Attribute::NoDuplicate);
556 addFnAttr(Attribute::NoDuplicate);
572 return hasFnAttribute(Attribute::Speculatable);
575 addFnAttr(Attribute::Speculatable);
580 return onlyReadsMemory() || hasFnAttribute(Attribute::NoFree);
583 addFnAttr(Attribute::NoFree);
589 return hasFnAttribute(Attribute::NoRecurse);
592 addFnAttr(Attribute::NoRecurse);
598 return hasFnAttribute(Attribute::UWTable);
601 addFnAttr(Attribute::UWTable);
606 return hasUWTable() || !doesNotThrow() || hasPersonalityFn();
627 bool hasOptNone()
const {
return hasFnAttribute(Attribute::OptimizeNone); }
630 bool hasMinSize()
const {
return hasFnAttribute(Attribute::MinSize); }
634 return hasFnAttribute(Attribute::OptimizeForSize) || hasMinSize();
639 void copyAttributesFrom(
const Function *Src);
646 setLinkage(ExternalLinkage);
652 void removeFromParent();
657 void eraseFromParent();
663 void stealArgumentListFrom(
Function &Src);
672 return &Function::BasicBlocks;
696 size_t size()
const {
return BasicBlocks.size(); }
697 bool empty()
const {
return BasicBlocks.empty(); }
707 CheckLazyArguments();
711 CheckLazyArguments();
716 CheckLazyArguments();
717 return Arguments + NumArgs;
720 CheckLazyArguments();
721 return Arguments + NumArgs;
725 assert (i < NumArgs &&
"getArg() out of range!");
726 CheckLazyArguments();
727 return Arguments + i;
744 return getSubclassDataFromValue() & (1<<3);
749 void setPersonalityFn(
Constant *Fn);
753 return getSubclassDataFromValue() & (1<<1);
758 void setPrefixData(
Constant *PrefixData);
762 return getSubclassDataFromValue() & (1<<2);
767 void setPrologueData(
Constant *PrologueData);
772 bool ShouldPreserveUseListOrder =
false,
773 bool IsForDebug =
false)
const;
781 void viewCFG()
const;
788 void viewCFGOnly()
const;
807 void dropAllReferences();
813 bool hasAddressTaken(
const User** =
nullptr)
const;
819 bool isDefTriviallyDead()
const;
823 bool callsFunctionThatReturnsTwice()
const;
837 bool isDebugInfoForProfiling()
const;
843 bool nullPointerIsDefined()
const;
846 void allocHungoffUselist();
847 template<
int Idx>
void setHungoffOperand(
Constant *
C);
851 void setValueSubclassData(
unsigned short D) {
854 void setValueSubclassDataBit(
unsigned Bit,
bool On);
871 #endif // LLVM_IR_FUNCTION_H
const Function & getFunction() const
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
bool onlyReadsMemory() const
Determine if the function does not access or only reads memory.
bool isIntrinsic() const
isIntrinsic - Returns true if the function's name starts with "llvm.".
MaybeAlign getParamAlignment(unsigned ArgNo) const
Return the alignment for the specified function parameter.
Attribute getParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Return the attribute object that exists at the arg index.
This class provides a symbol table of name/value pairs.
MaybeAlign getStackAlignment(unsigned Index) const
Get the stack alignment.
unsigned getFnStackAlignment() const
Return the stack alignment for the function.
const_iterator begin() const
This class represents an incoming formal argument to a Function.
unsigned getValueID() const
Return an ID for the concrete type of this object.
typename SuperClass::const_iterator const_iterator
bool isSpeculatable() const
Determine if the call has sideeffects.
uint64_t getParamDereferenceableBytes(unsigned ArgNo) const
Extract the number of dereferenceable bytes for a parameter.
This class represents lattice values for constants.
bool hasOptNone() const
Do not optimize this function (-O0).
A Module instance is used to store all the information related to an LLVM module. ...
bool hasOptSize() const
Optimize this function for size (-Os) or minimum size (-Oz).
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
Implements a dense probed hash-table based set.
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
unsigned getParamAlignment(unsigned ArgNo) const
Extract the alignment for a call or parameter (0=unknown).
bool hasFnAttribute(StringRef Kind) const
Return true if the function has the attribute.
The two locations do not alias at all.
const BasicBlock & back() const
bool hasPrologueData() const
Check whether this function has prologue data.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
bool hasAttribute(unsigned Index, Attribute::AttrKind Kind) const
Return true if the attribute exists at the given index.
void setDoesNotReadMemory()
bool hasStructRetAttr() const
Determine if the function returns a structure through first or second pointer argument.
bool hasPrefixData() const
Check whether this function has prefix data.
Type * getPointerElementType() const
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
uint64_t getDereferenceableBytes(unsigned Index) const
Get the number of dereferenceable bytes (or zero if unknown).
uint64_t getDereferenceableBytes(unsigned i) const
Extract the number of dereferenceable bytes for a call or parameter (0=unknown).
bool hasUWTable() const
True if the ABI mandates (or the user requested) that this function be in a unwind table...
This file contains the simple types necessary to represent the attributes associated with functions a...
Attribute getAttribute(unsigned i, StringRef Kind) const
gets the attribute from the list of attributes.
bool hasParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const
check if an attributes is in the list of attributes.
bool onlyAccessesInaccessibleMemory() const
Determine if the function may only access memory that is inaccessible from the IR.
AttributeList getAttributes(LLVMContext &C, ID id)
Return the attributes for an intrinsic.
#define DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CLASS, VALUECLASS)
Macro for generating out-of-class operand accessor definitions.
Class to represent function types.
static BasicBlockListType Function::* getSublistAccess(BasicBlock *)
bool hasAttribute(unsigned i, Attribute::AttrKind Kind) const
check if an attributes is in the list of attributes.
uint64_t getDereferenceableOrNullBytes(unsigned Index) const
Get the number of dereferenceable_or_null bytes (or zero if unknown).
AttributeList getAttributes() const
Return the attribute list for this Function.
bool hasPersonalityFn() const
Check whether this function has a personality function.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
uint64_t getParamDereferenceableOrNullBytes(unsigned ArgNo) const
Extract the number of dereferenceable_or_null bytes for a parameter.
void setIsMaterializable(bool V)
void setOnlyAccessesArgMemory()
bool doesNotAccessMemory() const
Determine if the function does not access memory.
static xmlAttrPtr getAttribute(xmlNodePtr Node, const unsigned char *AttributeName)
uint64_t getDereferenceableOrNullBytes(unsigned i) const
Extract the number of dereferenceable_or_null bytes for a call or parameter (0=unknown).
const BasicBlock & getEntryBlock() const
bool cannotDuplicate() const
Determine if the call cannot be duplicated.
void setCallingConv(CallingConv::ID CC)
Type * getReturnType() const
Returns the type of the ret val.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
void setOnlyReadsMemory()
uint64_t getCount() const
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
void deleteBody()
deleteBody - This method deletes the body of the function, and converts the linkage to external...
This is an important base class in LLVM.
bool returnDoesNotAlias() const
Determine if the parameter or return value is marked with NoAlias attribute.
BasicBlock & getEntryBlock()
bool doesNotFreeMemory() const
Determine if the call might deallocate memory.
void addFnAttr(StringRef Kind, StringRef Val=StringRef())
Add function attributes to this function.
AMDGPU Lower Kernel Arguments
bool doesNotReturn() const
Determine if the function cannot return.
iterator_range< const_arg_iterator > args() const
Attribute getParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const
gets the specified attribute from the list of attributes.
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
Argument * getArg(unsigned i) const
bool isMaterializable() const
bool hasProfileData(bool IncludeSynthetic=false) const
Return true if the function is annotated with profile data.
The highest possible calling convention ID. Must be some 2^k - 1.
void setDoesNotFreeMemory()
#define DECLARE_TRANSPARENT_OPERAND_ACCESSORS(VALUECLASS)
Macro for generating in-class operand accessor declarations.
Attribute getAttribute(unsigned Index, Attribute::AttrKind Kind) const
Return the attribute object that exists at the given index.
static DISubprogram * getSubprogram(bool IsDistinct, Ts &&... Args)
Class to represent profile counts.
void setCannotDuplicate()
void addFnAttr(Attribute Attr)
Add function attributes to this function.
BasicBlockListType & getBasicBlockList()
bool doesNotRecurse() const
Determine if the function is known not to recurse, directly or indirectly.
bool doesNotThrow() const
Determine if the function cannot unwind.
ProfileCount & setCount(uint64_t C)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Iterator for intrusive lists based on ilist_node.
bool hasParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const
Equivalent to hasAttribute(ArgNo + FirstArgIndex, Kind).
This struct is a compact representation of a valid (power of two) or undefined (0) alignment...
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
MaybeAlign getParamAlign(unsigned ArgNo) const
FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type *> Tys=None)
Return the function type for an intrinsic.
void setOnlyAccessesInaccessibleMemOrArgMem()
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static ProfileCount getInvalid()
ProfileCount(uint64_t Count, ProfileCountType PCT)
bool NullPointerIsDefined(const Function *F, unsigned AS=0)
Check whether null pointer dereferencing is considered undefined behavior for a given function or an ...
void setOnlyAccessesInaccessibleMemory()
void setValueSubclassData(unsigned short D)
void setAttributes(AttributeList Attrs)
Set the attribute list for this Function.
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
ValueSymbolTable * getValueSymbolTable()
getSymbolTable() - Return the symbol table if any, otherwise nullptr.
bool needsUnwindTableEntry() const
True if this function needs an unwind table.
FunctionType * getFunctionType() const
Returns the FunctionType for me.
A range adaptor for a pair of iterators.
LinkageTypes
An enumeration for the kinds of linkage for global values.
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
typename SuperClass::iterator iterator
uint64_t getParamDereferenceableBytes(unsigned ArgNo) const
Get the number of dereferenceable bytes (or zero if unknown) of an arg.
const_arg_iterator arg_end() const
Function::ProfileCount ProfileCount
Type * getParamByValType(unsigned ArgNo) const
Extract the byval type for a parameter.
bool hasGC() const
hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm to use during code generatio...
uint64_t getParamDereferenceableOrNullBytes(unsigned ArgNo) const
Get the number of dereferenceable_or_null bytes (or zero if unknown) of an arg.
void setDoesNotAccessMemory()
Linkage
Describes symbol linkage.
bool onlyAccessesArgMemory() const
Determine if the call can access memmory only using pointers based on its arguments.
bool hasMinSize() const
Optimize this function for minimum size (-Oz).
bool doesNotReadMemory() const
Determine if the function does not access or only writes memory.
Compile-time customization of User operands.
bool onlyAccessesInaccessibleMemOrArgMem() const
Determine if the function may only access memory that is either inaccessible from the IR or pointed t...
const_arg_iterator arg_begin() const
const BasicBlockListType & getBasicBlockList() const
Get the underlying elements of the Function...
static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
const ValueSymbolTable * getValueSymbolTable() const
void removeFnAttr(Attribute::AttrKind Kind)
Remove function attributes from this function.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Equivalent to hasAttribute(AttributeList::FunctionIndex, Kind) but may be faster. ...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const BasicBlock & front() const
LLVM Value Representation.
HungoffOperandTraits - determine the allocation regime of the Use array when it is not a prefix to th...
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
ProfileCountType getType() const
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
This class implements an extremely fast bulk output stream that can only output to a stream...
void addFnAttr(Attribute::AttrKind Kind)
Add function attributes to this function.
StringRef - Represent a constant reference to a string, i.e.
Attribute getAttribute(unsigned i, Attribute::AttrKind Kind) const
gets the attribute from the list of attributes.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, const Twine &N="", Module *M=nullptr)
Attribute getFnAttribute(StringRef Kind) const
Return the attribute for the given attribute kind.
bool doesNoCfCheck() const
Determine if the function should not perform indirect branch tracking.
const_iterator end() const
bool isConvergent() const
Determine if the call is convergent.
void removeFnAttr(StringRef Kind)
Remove function attribute from this function.
bool hasLazyArguments() const
hasLazyArguments/CheckLazyArguments - The argument list of a function is built on demand...
Type * getParamByValType(unsigned ArgNo) const
Return the byval type for the specified function parameter.
iterator_range< arg_iterator > args()
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results...
void setReturnDoesNotAlias()