aboutsummaryrefslogtreecommitdiff
path: root/include/llvm/IR/Function.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/llvm/IR/Function.h')
-rw-r--r--include/llvm/IR/Function.h101
1 files changed, 57 insertions, 44 deletions
diff --git a/include/llvm/IR/Function.h b/include/llvm/IR/Function.h
index 1854d413c627..a3762a44ccb6 100644
--- a/include/llvm/IR/Function.h
+++ b/include/llvm/IR/Function.h
@@ -18,6 +18,7 @@
#ifndef LLVM_IR_FUNCTION_H
#define LLVM_IR_FUNCTION_H
+#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/ilist_node.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/ADT/StringRef.h"
@@ -47,23 +48,23 @@ class DISubprogram;
class Function : public GlobalObject, public ilist_node<Function> {
public:
- typedef SymbolTableList<Argument> ArgumentListType;
typedef SymbolTableList<BasicBlock> BasicBlockListType;
// BasicBlock iterators...
typedef BasicBlockListType::iterator iterator;
typedef BasicBlockListType::const_iterator const_iterator;
- typedef ArgumentListType::iterator arg_iterator;
- typedef ArgumentListType::const_iterator const_arg_iterator;
+ typedef Argument *arg_iterator;
+ typedef const Argument *const_arg_iterator;
private:
// Important things that make up a function!
BasicBlockListType BasicBlocks; ///< The basic blocks
- mutable ArgumentListType ArgumentList; ///< The formal arguments
+ mutable Argument *Arguments; ///< The formal arguments
+ size_t NumArgs;
std::unique_ptr<ValueSymbolTable>
SymTab; ///< Symbol table of args/instructions
- AttributeSet AttributeSets; ///< Parameter attributes
+ AttributeList AttributeSets; ///< Parameter attributes
/*
* Value::SubclassData
@@ -102,6 +103,8 @@ private:
void BuildLazyArguments() const;
+ void clearArguments();
+
/// Function ctor - If the (optional) Module argument is specified, the
/// function is automatically inserted into the end of the function list for
/// the module.
@@ -121,10 +124,12 @@ public:
// Provide fast operand accessors.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
- /// Returns the type of the ret val.
- Type *getReturnType() const;
/// Returns the FunctionType for me.
- FunctionType *getFunctionType() const;
+ FunctionType *getFunctionType() const {
+ return cast<FunctionType>(getValueType());
+ }
+ /// Returns the type of the ret val.
+ Type *getReturnType() const { return getFunctionType()->getReturnType(); }
/// getContext - Return a reference to the LLVMContext associated with this
/// function.
@@ -132,10 +137,16 @@ public:
/// isVarArg - Return true if this function takes a variable number of
/// arguments.
- bool isVarArg() const;
+ bool isVarArg() const { return getFunctionType()->isVarArg(); }
- bool isMaterializable() const;
- void setIsMaterializable(bool V);
+ bool isMaterializable() const {
+ return getGlobalObjectSubClassData() & (1 << IsMaterializableBit);
+ }
+ void setIsMaterializable(bool V) {
+ unsigned Mask = 1 << IsMaterializableBit;
+ setGlobalObjectSubClassData((~Mask & getGlobalObjectSubClassData()) |
+ (V ? Mask : 0u));
+ }
/// getIntrinsicID - This method returns the ID number of the specified
/// function, or Intrinsic::not_intrinsic if the function is not an
@@ -173,42 +184,45 @@ public:
}
/// @brief Return the attribute list for this Function.
- AttributeSet getAttributes() const { return AttributeSets; }
+ AttributeList getAttributes() const { return AttributeSets; }
/// @brief Set the attribute list for this Function.
- void setAttributes(AttributeSet Attrs) { AttributeSets = Attrs; }
+ void setAttributes(AttributeList Attrs) { AttributeSets = Attrs; }
/// @brief Add function attributes to this function.
void addFnAttr(Attribute::AttrKind Kind) {
- addAttribute(AttributeSet::FunctionIndex, Kind);
+ addAttribute(AttributeList::FunctionIndex, Kind);
}
/// @brief Add function attributes to this function.
void addFnAttr(StringRef Kind, StringRef Val = StringRef()) {
- addAttribute(AttributeSet::FunctionIndex,
+ addAttribute(AttributeList::FunctionIndex,
Attribute::get(getContext(), Kind, Val));
}
void addFnAttr(Attribute Attr) {
- addAttribute(AttributeSet::FunctionIndex, Attr);
+ addAttribute(AttributeList::FunctionIndex, Attr);
}
/// @brief Remove function attributes from this function.
void removeFnAttr(Attribute::AttrKind Kind) {
- removeAttribute(AttributeSet::FunctionIndex, Kind);
+ removeAttribute(AttributeList::FunctionIndex, Kind);
}
/// @brief Remove function attribute from this function.
void removeFnAttr(StringRef Kind) {
setAttributes(AttributeSets.removeAttribute(
- getContext(), AttributeSet::FunctionIndex, Kind));
+ getContext(), AttributeList::FunctionIndex, Kind));
}
/// \brief Set the entry count for this function.
///
/// Entry count is the number of times this function was executed based on
- /// pgo data.
- void setEntryCount(uint64_t Count);
+ /// pgo data. \p Imports points to a set of GUIDs that needs to be imported
+ /// by the function for sample PGO, to enable the same inlines as the
+ /// profiled optimized binary.
+ void setEntryCount(uint64_t Count,
+ const DenseSet<GlobalValue::GUID> *Imports = nullptr);
/// \brief Get the entry count for this function.
///
@@ -216,6 +230,10 @@ public:
/// pgo data.
Optional<uint64_t> getEntryCount() const;
+ /// Returns the set of GUIDs that needs to be imported to the function for
+ /// sample PGO, to enable the same inlines as the profiled optimized binary.
+ DenseSet<GlobalValue::GUID> getImportGUIDs() const;
+
/// Set the section prefix for this function.
void setSectionPrefix(StringRef Prefix);
@@ -232,17 +250,17 @@ public:
/// @brief Return the attribute for the given attribute kind.
Attribute getFnAttribute(Attribute::AttrKind Kind) const {
- return getAttribute(AttributeSet::FunctionIndex, Kind);
+ return getAttribute(AttributeList::FunctionIndex, Kind);
}
Attribute getFnAttribute(StringRef Kind) const {
- return getAttribute(AttributeSet::FunctionIndex, Kind);
+ return getAttribute(AttributeList::FunctionIndex, Kind);
}
/// \brief Return the stack alignment for the function.
unsigned getFnStackAlignment() const {
if (!hasFnAttribute(Attribute::StackAlignment))
return 0;
- return AttributeSets.getStackAlignment(AttributeSet::FunctionIndex);
+ return AttributeSets.getStackAlignment(AttributeList::FunctionIndex);
}
/// hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm
@@ -261,7 +279,7 @@ public:
void addAttribute(unsigned i, Attribute Attr);
/// @brief adds the attributes to the list of attributes.
- void addAttributes(unsigned i, AttributeSet Attrs);
+ void addAttributes(unsigned i, AttributeList Attrs);
/// @brief removes the attribute from the list of attributes.
void removeAttribute(unsigned i, Attribute::AttrKind Kind);
@@ -270,13 +288,18 @@ public:
void removeAttribute(unsigned i, StringRef Kind);
/// @brief removes the attributes from the list of attributes.
- void removeAttributes(unsigned i, AttributeSet Attrs);
+ void removeAttributes(unsigned i, AttributeList Attrs);
/// @brief check if an attributes is in the list of attributes.
bool hasAttribute(unsigned i, Attribute::AttrKind Kind) const {
return getAttributes().hasAttribute(i, Kind);
}
+ /// @brief check if an attributes is in the list of attributes.
+ bool hasParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const {
+ return getAttributes().hasParamAttribute(ArgNo, Kind);
+ }
+
Attribute getAttribute(unsigned i, Attribute::AttrKind Kind) const {
return AttributeSets.getAttribute(i, Kind);
}
@@ -496,19 +519,6 @@ public:
/// Get the underlying elements of the Function... the basic block list is
/// empty for external functions.
///
- const ArgumentListType &getArgumentList() const {
- CheckLazyArguments();
- return ArgumentList;
- }
- ArgumentListType &getArgumentList() {
- CheckLazyArguments();
- return ArgumentList;
- }
-
- static ArgumentListType Function::*getSublistAccess(Argument*) {
- return &Function::ArgumentList;
- }
-
const BasicBlockListType &getBasicBlockList() const { return BasicBlocks; }
BasicBlockListType &getBasicBlockList() { return BasicBlocks; }
@@ -549,20 +559,20 @@ public:
arg_iterator arg_begin() {
CheckLazyArguments();
- return ArgumentList.begin();
+ return Arguments;
}
const_arg_iterator arg_begin() const {
CheckLazyArguments();
- return ArgumentList.begin();
+ return Arguments;
}
arg_iterator arg_end() {
CheckLazyArguments();
- return ArgumentList.end();
+ return Arguments + NumArgs;
}
const_arg_iterator arg_end() const {
CheckLazyArguments();
- return ArgumentList.end();
+ return Arguments + NumArgs;
}
iterator_range<arg_iterator> args() {
@@ -574,8 +584,8 @@ public:
/// @}
- size_t arg_size() const;
- bool arg_empty() const;
+ size_t arg_size() const { return NumArgs; }
+ bool arg_empty() const { return arg_size() == 0; }
/// \brief Check whether this function has a personality function.
bool hasPersonalityFn() const {
@@ -671,6 +681,9 @@ public:
/// to \a DISubprogram.
DISubprogram *getSubprogram() const;
+ /// Returns true if we should emit debug info for profiling.
+ bool isDebugInfoForProfiling() const;
+
private:
void allocHungoffUselist();
template<int Idx> void setHungoffOperand(Constant *C);