[IR] Inline some Function accessors

I checked that all of these out-of-line methods previously compiled to
simple loads and bittests, so they are pretty good candidates for
inlining. In particular, arg_size() and arg_empty() are popular and are
just two loads, so they seem worth inlining.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297963 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Reid Kleckner 2017-03-16 16:57:31 +00:00
parent 6ce086bb36
commit 800f10438a
4 changed files with 27 additions and 51 deletions

View File

@ -122,10 +122,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.
@ -133,10 +135,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
@ -582,8 +590,8 @@ public:
/// @}
size_t arg_size() const;
bool arg_empty() const;
size_t arg_size() const { return getFunctionType()->getNumParams(); }
bool arg_empty() const { return arg_size() == 0; }
/// \brief Check whether this function has a personality function.
bool hasPersonalityFn() const {

View File

@ -63,8 +63,17 @@ public:
}
void setAlignment(unsigned Align);
unsigned getGlobalObjectSubClassData() const;
void setGlobalObjectSubClassData(unsigned Val);
unsigned getGlobalObjectSubClassData() const {
unsigned ValueData = getGlobalValueSubClassData();
return ValueData >> GlobalObjectBits;
}
void setGlobalObjectSubClassData(unsigned Val) {
unsigned OldData = getGlobalValueSubClassData();
setGlobalValueSubClassData((OldData & GlobalObjectMask) |
(Val << GlobalObjectBits));
assert(getGlobalObjectSubClassData() == Val && "representation error");
}
/// Check if this global has a custom object file section.
///

View File

@ -185,32 +185,10 @@ bool Argument::hasAttribute(Attribute::AttrKind Kind) const {
// Helper Methods in Function
//===----------------------------------------------------------------------===//
bool Function::isMaterializable() const {
return getGlobalObjectSubClassData() & (1 << IsMaterializableBit);
}
void Function::setIsMaterializable(bool V) {
unsigned Mask = 1 << IsMaterializableBit;
setGlobalObjectSubClassData((~Mask & getGlobalObjectSubClassData()) |
(V ? Mask : 0u));
}
LLVMContext &Function::getContext() const {
return getType()->getContext();
}
FunctionType *Function::getFunctionType() const {
return cast<FunctionType>(getValueType());
}
bool Function::isVarArg() const {
return getFunctionType()->isVarArg();
}
Type *Function::getReturnType() const {
return getFunctionType()->getReturnType();
}
void Function::removeFromParent() {
getParent()->getFunctionList().remove(getIterator());
}
@ -296,13 +274,6 @@ void Function::stealArgumentListFrom(Function &Src) {
Src.setValueSubclassData(Src.getSubclassDataFromValue() | (1 << 0));
}
size_t Function::arg_size() const {
return getFunctionType()->getNumParams();
}
bool Function::arg_empty() const {
return getFunctionType()->getNumParams() == 0;
}
// dropAllReferences() - This function causes all the subinstructions to "let
// go" of all references that they are maintaining. This allows one to
// 'delete' a whole class at a time, even though there may be circular

View File

@ -93,18 +93,6 @@ void GlobalObject::setAlignment(unsigned Align) {
assert(getAlignment() == Align && "Alignment representation error!");
}
unsigned GlobalObject::getGlobalObjectSubClassData() const {
unsigned ValueData = getGlobalValueSubClassData();
return ValueData >> GlobalObjectBits;
}
void GlobalObject::setGlobalObjectSubClassData(unsigned Val) {
unsigned OldData = getGlobalValueSubClassData();
setGlobalValueSubClassData((OldData & GlobalObjectMask) |
(Val << GlobalObjectBits));
assert(getGlobalObjectSubClassData() == Val && "representation error");
}
void GlobalObject::copyAttributesFrom(const GlobalValue *Src) {
GlobalValue::copyAttributesFrom(Src);
if (const auto *GV = dyn_cast<GlobalObject>(Src)) {