18 #ifndef LLVM_IR_FUNCTION_H 19 #define LLVM_IR_FUNCTION_H 50 class AssemblyAnnotationWriter;
55 template <
typename T>
class Optional;
76 std::unique_ptr<ValueSymbolTable>
95 IsMaterializableBit = 0,
106 return getSubclassDataFromValue() & (1<<0);
110 void CheckLazyArguments()
const {
111 if (hasLazyArguments())
112 BuildLazyArguments();
115 void BuildLazyArguments()
const;
117 void clearArguments();
128 void operator=(
const Function&) =
delete;
147 unsigned getInstructionCount();
151 return cast<FunctionType>(getValueType());
163 bool isVarArg()
const {
return getFunctionType()->isVarArg(); }
166 return getGlobalObjectSubClassData() & (1 << IsMaterializableBit);
169 unsigned Mask = 1 << IsMaterializableBit;
170 setGlobalObjectSubClassData((~Mask & getGlobalObjectSubClassData()) |
194 void recalculateIntrinsicID();
200 return static_cast<CallingConv::ID>((getSubclassDataFromValue() >> 4) &
204 auto ID =
static_cast<unsigned>(CC);
206 setValueSubclassData((getSubclassDataFromValue() & 0xc00f) | (
ID << 4));
256 : Count(Count), PCT(PCT) {}
257 bool hasValue()
const {
return PCT != PCT_Invalid; }
261 explicit operator bool() {
return hasValue(); }
328 if (!hasFnAttribute(Attribute::StackAlignment))
336 return getSubclassDataFromValue() & (1<<14);
338 const std::string &getGC()
const;
339 void setGC(std::string Str);
346 void addAttribute(
unsigned i,
Attribute Attr);
355 void addParamAttr(
unsigned ArgNo,
Attribute Attr);
358 void addParamAttrs(
unsigned ArgNo,
const AttrBuilder &Attrs);
364 void removeAttribute(
unsigned i,
StringRef Kind);
367 void removeAttributes(
unsigned i,
const AttrBuilder &Attrs);
373 void removeParamAttr(
unsigned ArgNo,
StringRef Kind);
376 void removeParamAttrs(
unsigned ArgNo,
const AttrBuilder &Attrs);
399 void addDereferenceableAttr(
unsigned i, uint64_t Bytes);
403 void addDereferenceableParamAttr(
unsigned ArgNo, uint64_t Bytes);
407 void addDereferenceableOrNullAttr(
unsigned i, uint64_t Bytes);
411 void addDereferenceableOrNullParamAttr(
unsigned ArgNo, uint64_t Bytes);
447 return hasFnAttribute(Attribute::ReadNone);
450 addFnAttr(Attribute::ReadNone);
455 return doesNotAccessMemory() || hasFnAttribute(Attribute::ReadOnly);
458 addFnAttr(Attribute::ReadOnly);
463 return doesNotAccessMemory() || hasFnAttribute(Attribute::WriteOnly);
466 addFnAttr(Attribute::WriteOnly);
472 return hasFnAttribute(Attribute::ArgMemOnly);
479 return hasFnAttribute(Attribute::InaccessibleMemOnly);
482 addFnAttr(Attribute::InaccessibleMemOnly);
488 return hasFnAttribute(Attribute::InaccessibleMemOrArgMemOnly);
491 addFnAttr(Attribute::InaccessibleMemOrArgMemOnly);
496 return hasFnAttribute(Attribute::NoReturn);
499 addFnAttr(Attribute::NoReturn);
507 return hasFnAttribute(Attribute::NoUnwind);
510 addFnAttr(Attribute::NoUnwind);
515 return hasFnAttribute(Attribute::NoDuplicate);
518 addFnAttr(Attribute::NoDuplicate);
534 return hasFnAttribute(Attribute::Speculatable);
537 addFnAttr(Attribute::Speculatable);
543 return hasFnAttribute(Attribute::NoRecurse);
546 addFnAttr(Attribute::NoRecurse);
552 return hasFnAttribute(Attribute::UWTable);
555 addFnAttr(Attribute::UWTable);
560 return hasUWTable() || !doesNotThrow();
585 return hasFnAttribute(Attribute::OptimizeForSize) || optForMinSize();
590 void copyAttributesFrom(
const Function *Src);
597 setLinkage(ExternalLinkage);
603 void removeFromParent();
608 void eraseFromParent();
614 void stealArgumentListFrom(
Function &Src);
623 return &Function::BasicBlocks;
647 size_t size()
const {
return BasicBlocks.size(); }
648 bool empty()
const {
return BasicBlocks.empty(); }
658 CheckLazyArguments();
662 CheckLazyArguments();
667 CheckLazyArguments();
668 return Arguments + NumArgs;
671 CheckLazyArguments();
672 return Arguments + NumArgs;
689 return getSubclassDataFromValue() & (1<<3);
694 void setPersonalityFn(
Constant *Fn);
698 return getSubclassDataFromValue() & (1<<1);
703 void setPrefixData(
Constant *PrefixData);
707 return getSubclassDataFromValue() & (1<<2);
712 void setPrologueData(
Constant *PrologueData);
717 bool ShouldPreserveUseListOrder =
false,
718 bool IsForDebug =
false)
const;
726 void viewCFG()
const;
733 void viewCFGOnly()
const;
752 void dropAllReferences();
758 bool hasAddressTaken(
const User** =
nullptr)
const;
764 bool isDefTriviallyDead()
const;
768 bool callsFunctionThatReturnsTwice()
const;
782 bool isDebugInfoForProfiling()
const;
788 bool nullPointerIsDefined()
const;
791 void allocHungoffUselist();
792 template<
int Idx>
void setHungoffOperand(
Constant *
C);
796 void setValueSubclassData(
unsigned short D) {
799 void setValueSubclassDataBit(
unsigned Bit,
bool On);
816 #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.".
This class provides a symbol table of name/value pairs.
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.
bool isSpeculatable() const
Determine if the call has sideeffects.
uint64_t getParamDereferenceableBytes(unsigned ArgNo) const
Extract the number of dereferenceable bytes for a parameter.
Compute iterated dominance frontiers using a linear time algorithm.
The highest possible calling convention ID. Must be some 2^k - 1.
A Module instance is used to store all the information related to an LLVM module. ...
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.
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.
unsigned getStackAlignment(unsigned Index) const
Get the stack alignment.
void setCallingConv(CallingConv::ID CC)
Type * getReturnType() const
Returns the type of the ret val.
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()
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
bool optForSize() const
Optimize this function for size (-Os) or minimum size (-Oz).
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
bool isMaterializable() const
#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).
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
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:
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
unsigned getParamAlignment(unsigned ArgNo) const
Return the alignment for the specified function 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()
bool optForMinSize() const
Optimize this function for minimum size (-Oz).
bool onlyAccessesArgMemory() const
Determine if the call can access memmory only using pointers based on its arguments.
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.
bool hasProfileData() const
Return true if the function is annotated with profile data.
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...
iterator_range< arg_iterator > args()
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results...
void setReturnDoesNotAlias()