From: Reid Kleckner Date: Thu, 16 Mar 2017 16:57:31 +0000 (+0000) Subject: [IR] Inline some Function accessors X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=800f10438aa67eb9d040db2a101106e35d92b475;p=llvm [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 --- diff --git a/include/llvm/IR/Function.h b/include/llvm/IR/Function.h index f9e8fcc52c9..ced85a95893 100644 --- a/include/llvm/IR/Function.h +++ b/include/llvm/IR/Function.h @@ -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(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 { diff --git a/include/llvm/IR/GlobalObject.h b/include/llvm/IR/GlobalObject.h index 1057f564aab..f3789bafefe 100644 --- a/include/llvm/IR/GlobalObject.h +++ b/include/llvm/IR/GlobalObject.h @@ -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. /// diff --git a/lib/IR/Function.cpp b/lib/IR/Function.cpp index 7b5d49c34b3..1318b5163be 100644 --- a/lib/IR/Function.cpp +++ b/lib/IR/Function.cpp @@ -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(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 diff --git a/lib/IR/Globals.cpp b/lib/IR/Globals.cpp index 675c515b21f..54917e596b7 100644 --- a/lib/IR/Globals.cpp +++ b/lib/IR/Globals.cpp @@ -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(Src)) {