summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/IR')
-rw-r--r--llvm/lib/IR/Function.cpp35
-rw-r--r--llvm/lib/IR/LLVMContextImpl.h5
-rw-r--r--llvm/lib/IR/Value.cpp11
3 files changed, 16 insertions, 35 deletions
diff --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp
index 71e07ea04cb..cbba2ee90a1 100644
--- a/llvm/lib/IR/Function.cpp
+++ b/llvm/lib/IR/Function.cpp
@@ -266,9 +266,10 @@ Function::Function(FunctionType *Ty, LinkageTypes Linkage, const Twine &name,
ParentModule->getFunctionList().push_back(this);
// Ensure intrinsics have the right parameter attributes.
- if (unsigned IID = getIntrinsicID())
- setAttributes(Intrinsic::getAttributes(getContext(), Intrinsic::ID(IID)));
-
+ // Note, the IntID field will have been set in Value::setName if this function
+ // name is a valid intrinsic ID.
+ if (IntID)
+ setAttributes(Intrinsic::getAttributes(getContext(), IntID));
}
Function::~Function() {
@@ -280,10 +281,6 @@ Function::~Function() {
// Remove the function from the on-the-side GC table.
clearGC();
-
- // Remove the intrinsicID from the Cache.
- if (getValueName() && isIntrinsic())
- getContext().pImpl->IntrinsicIDCache.erase(this);
}
void Function::BuildLazyArguments() const {
@@ -446,27 +443,13 @@ static Intrinsic::ID lookupIntrinsicID(const ValueName *ValName) {
return Intrinsic::not_intrinsic;
}
-/// getIntrinsicID - This method returns the ID number of the specified
-/// function, or Intrinsic::not_intrinsic if the function is not an
-/// intrinsic, or if the pointer is null. This value is always defined to be
-/// zero to allow easy checking for whether a function is intrinsic or not. The
-/// particular intrinsic functions which correspond to this value are defined in
-/// llvm/Intrinsics.h. Results are cached in the LLVM context, subsequent
-/// requests for the same ID return results much faster from the cache.
-///
-unsigned Function::getIntrinsicID() const {
+void Function::recalculateIntrinsicID() {
const ValueName *ValName = this->getValueName();
- if (!ValName || !isIntrinsic())
- return 0;
-
- LLVMContextImpl::IntrinsicIDCacheTy &IntrinsicIDCache =
- getContext().pImpl->IntrinsicIDCache;
- if (!IntrinsicIDCache.count(this)) {
- unsigned Id = lookupIntrinsicID(ValName);
- IntrinsicIDCache[this]=Id;
- return Id;
+ if (!ValName || !isIntrinsic()) {
+ IntID = Intrinsic::not_intrinsic;
+ return;
}
- return IntrinsicIDCache[this];
+ IntID = lookupIntrinsicID(ValName);
}
/// Returns a stable mangling for the type specified for use in the name
diff --git a/llvm/lib/IR/LLVMContextImpl.h b/llvm/lib/IR/LLVMContextImpl.h
index 09c28838fe8..95292509f50 100644
--- a/llvm/lib/IR/LLVMContextImpl.h
+++ b/llvm/lib/IR/LLVMContextImpl.h
@@ -1000,11 +1000,6 @@ public:
/// instructions in different blocks at the same location.
DenseMap<std::pair<const char *, unsigned>, unsigned> DiscriminatorTable;
- /// IntrinsicIDCache - Cache of intrinsic name (string) to numeric ID mappings
- /// requested in this context
- typedef DenseMap<const Function*, unsigned> IntrinsicIDCacheTy;
- IntrinsicIDCacheTy IntrinsicIDCache;
-
/// \brief Mapping from a function to its prefix data, which is stored as the
/// operand of an unparented ReturnInst so that the prefix data has a Use.
typedef DenseMap<const Function *, ReturnInst *> PrefixDataMapTy;
diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp
index 18f6b1e9c35..fd0ed31ccc6 100644
--- a/llvm/lib/IR/Value.cpp
+++ b/llvm/lib/IR/Value.cpp
@@ -166,7 +166,7 @@ StringRef Value::getName() const {
return getValueName()->getKey();
}
-void Value::setName(const Twine &NewName) {
+void Value::setNameImpl(const Twine &NewName) {
// Fast path for common IRBuilder case of setName("") when there is no name.
if (NewName.isTriviallyEmpty() && !hasName())
return;
@@ -187,9 +187,6 @@ void Value::setName(const Twine &NewName) {
if (getSymTab(this, ST))
return; // Cannot set a name on this value (e.g. constant).
- if (Function *F = dyn_cast<Function>(this))
- getContext().pImpl->IntrinsicIDCache.erase(F);
-
if (!ST) { // No symbol table to update? Just do the change.
if (NameRef.empty()) {
// Free the name for this value.
@@ -222,6 +219,12 @@ void Value::setName(const Twine &NewName) {
setValueName(ST->createValueName(NameRef, this));
}
+void Value::setName(const Twine &NewName) {
+ setNameImpl(NewName);
+ if (Function *F = dyn_cast<Function>(this))
+ F->recalculateIntrinsicID();
+}
+
void Value::takeName(Value *V) {
ValueSymbolTable *ST = nullptr;
// If this value has a name, drop it.
OpenPOWER on IntegriCloud