Speed up Function::isIntrinsic() by adding a bit to GlobalValue. NFC

Summary:
Previously isIntrinsic() called getName().  This involves a hashtable
lookup, so is nontrivially expensive.  And isIntrinsic() is called
frequently, particularly by dyn_cast<IntrinsicInstr>.

This patch steals a bit of IntID and uses that to store whether or not
getName() starts with "llvm."

Reviewers: bogner, arsenm, joker-eph

Subscribers: sanjoy, llvm-commits

Differential Revision: https://reviews.llvm.org/D22949

llvm-svn: 290691
This commit is contained in:
Justin Lebar 2016-12-28 22:59:45 +00:00
parent e98f925834
commit 291abd3ebb
3 changed files with 18 additions and 6 deletions

View File

@ -144,7 +144,11 @@ public:
/// The particular intrinsic functions which correspond to this value are /// The particular intrinsic functions which correspond to this value are
/// defined in llvm/Intrinsics.h. /// defined in llvm/Intrinsics.h.
Intrinsic::ID getIntrinsicID() const LLVM_READONLY { return IntID; } Intrinsic::ID getIntrinsicID() const LLVM_READONLY { return IntID; }
bool isIntrinsic() const { return getName().startswith("llvm."); }
/// isIntrinsic - Returns true if the function's name starts with "llvm.".
/// It's possible for this function to return true while getIntrinsicID()
/// returns Intrinsic::not_intrinsic!
bool isIntrinsic() const { return HasLLVMReservedName; }
static Intrinsic::ID lookupIntrinsicID(StringRef Name); static Intrinsic::ID lookupIntrinsicID(StringRef Name);

View File

@ -80,7 +80,7 @@ protected:
ValueType(Ty), Linkage(Linkage), Visibility(DefaultVisibility), ValueType(Ty), Linkage(Linkage), Visibility(DefaultVisibility),
UnnamedAddrVal(unsigned(UnnamedAddr::None)), UnnamedAddrVal(unsigned(UnnamedAddr::None)),
DllStorageClass(DefaultStorageClass), ThreadLocal(NotThreadLocal), DllStorageClass(DefaultStorageClass), ThreadLocal(NotThreadLocal),
IntID((Intrinsic::ID)0U), Parent(nullptr) { IntID((Intrinsic::ID)0U), HasLLVMReservedName(false), Parent(nullptr) {
setName(Name); setName(Name);
} }
@ -137,7 +137,12 @@ protected:
/// Subclasses can use it to store their intrinsic ID, if they have one. /// Subclasses can use it to store their intrinsic ID, if they have one.
/// ///
/// This is stored here to save space in Function on 64-bit hosts. /// This is stored here to save space in Function on 64-bit hosts.
Intrinsic::ID IntID; Intrinsic::ID IntID : 31;
/// True if the function's name starts with "llvm.". This corresponds to the
/// value of Function::isIntrinsic(), which may be true even if
/// Function::intrinsicID() returns Intrinsic::not_intrinsic.
bool HasLLVMReservedName : 1;
unsigned getGlobalValueSubClassData() const { unsigned getGlobalValueSubClassData() const {
return SubClassData; return SubClassData;

View File

@ -270,6 +270,7 @@ Function::Function(FunctionType *Ty, LinkageTypes Linkage, const Twine &name,
if (ParentModule) if (ParentModule)
ParentModule->getFunctionList().push_back(this); ParentModule->getFunctionList().push_back(this);
HasLLVMReservedName = getName().startswith("llvm.");
// Ensure intrinsics have the right parameter attributes. // Ensure intrinsics have the right parameter attributes.
// Note, the IntID field will have been set in Value::setName if this function // Note, the IntID field will have been set in Value::setName if this function
// name is a valid intrinsic ID. // name is a valid intrinsic ID.
@ -500,12 +501,14 @@ Intrinsic::ID Function::lookupIntrinsicID(StringRef Name) {
} }
void Function::recalculateIntrinsicID() { void Function::recalculateIntrinsicID() {
const ValueName *ValName = this->getValueName(); StringRef Name = getName();
if (!ValName || !isIntrinsic()) { if (!Name.startswith("llvm.")) {
HasLLVMReservedName = false;
IntID = Intrinsic::not_intrinsic; IntID = Intrinsic::not_intrinsic;
return; return;
} }
IntID = lookupIntrinsicID(ValName->getKey()); HasLLVMReservedName = true;
IntID = lookupIntrinsicID(Name);
} }
/// Returns a stable mangling for the type specified for use in the name /// Returns a stable mangling for the type specified for use in the name