summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/include/llvm/IR/Function.h6
-rw-r--r--llvm/include/llvm/IR/GlobalValue.h9
-rw-r--r--llvm/lib/IR/Function.cpp9
3 files changed, 18 insertions, 6 deletions
diff --git a/llvm/include/llvm/IR/Function.h b/llvm/include/llvm/IR/Function.h
index e9b3badef5e..1854d413c62 100644
--- a/llvm/include/llvm/IR/Function.h
+++ b/llvm/include/llvm/IR/Function.h
@@ -144,7 +144,11 @@ public:
/// The particular intrinsic functions which correspond to this value are
/// defined in llvm/Intrinsics.h.
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);
diff --git a/llvm/include/llvm/IR/GlobalValue.h b/llvm/include/llvm/IR/GlobalValue.h
index 93970075614..b43d3127d96 100644
--- a/llvm/include/llvm/IR/GlobalValue.h
+++ b/llvm/include/llvm/IR/GlobalValue.h
@@ -80,7 +80,7 @@ protected:
ValueType(Ty), Linkage(Linkage), Visibility(DefaultVisibility),
UnnamedAddrVal(unsigned(UnnamedAddr::None)),
DllStorageClass(DefaultStorageClass), ThreadLocal(NotThreadLocal),
- IntID((Intrinsic::ID)0U), Parent(nullptr) {
+ IntID((Intrinsic::ID)0U), HasLLVMReservedName(false), Parent(nullptr) {
setName(Name);
}
@@ -137,7 +137,12 @@ protected:
/// 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.
- 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 {
return SubClassData;
diff --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp
index b87c85e44a8..05419aa3d2b 100644
--- a/llvm/lib/IR/Function.cpp
+++ b/llvm/lib/IR/Function.cpp
@@ -270,6 +270,7 @@ Function::Function(FunctionType *Ty, LinkageTypes Linkage, const Twine &name,
if (ParentModule)
ParentModule->getFunctionList().push_back(this);
+ HasLLVMReservedName = getName().startswith("llvm.");
// Ensure intrinsics have the right parameter attributes.
// Note, the IntID field will have been set in Value::setName if this function
// name is a valid intrinsic ID.
@@ -500,12 +501,14 @@ Intrinsic::ID Function::lookupIntrinsicID(StringRef Name) {
}
void Function::recalculateIntrinsicID() {
- const ValueName *ValName = this->getValueName();
- if (!ValName || !isIntrinsic()) {
+ StringRef Name = getName();
+ if (!Name.startswith("llvm.")) {
+ HasLLVMReservedName = false;
IntID = Intrinsic::not_intrinsic;
return;
}
- IntID = lookupIntrinsicID(ValName->getKey());
+ HasLLVMReservedName = true;
+ IntID = lookupIntrinsicID(Name);
}
/// Returns a stable mangling for the type specified for use in the name
OpenPOWER on IntegriCloud