Summary:
getName() involves a hashtable lookup, so is expensive given how
frequently isIntrinsic() is called. (In particular, many users cast to
IntrinsicInstr or one of its subclasses before calling
getIntrinsicID().)
This has an incidental functional change: Before, isIntrinsic() would
return true for any function whose name started with "llvm.", even if it
wasn't properly an intrinsic. The new behavior seems more correct to
me, because it's strange to say that isIntrinsic() is true, but
getIntrinsicId() returns "not an intrinsic".
Some callers want the old behavior -- they want to know whether the
caller is a recognized intrinsic, or might be one in some other version
of LLVM. For them, we added Function::hasLLVMReservedName(), which
checks whether the name starts with "llvm.".
This change is good for a 1.5% e2e speedup compiling a large Eigen
benchmark.
Reviewers: bogner
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D22065
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@276942
91177308-0d34-0410-b5e6-
96231b3b80d8
/// 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."); }
+ bool isIntrinsic() const {
+ // Intrinsic::not_intrinsic must be 0.
+ return IntID != 0;
+ }
+ /// Return true if the function's name starts with "llvm.". All intrinsics
+ /// have this prefix.
+ bool hasLLVMReservedName() const { return getName().startswith("llvm."); }
/// \brief Recalculate the ID for this function if it is an Intrinsic defined
/// in llvm/Intrinsics.h. Sets the intrinsic ID to Intrinsic::not_intrinsic
continue;
// Skip call sites which are nounwind intrinsics or inline asm.
+ //
+ // FIXME: Should this check isIntrinsic() instead of
+ // hasLLVMReservedName? The latter is conservative.
auto *CalledFn =
dyn_cast<Function>(CS.getCalledValue()->stripPointerCasts());
- if (CalledFn && ((CalledFn->isIntrinsic() && CS.doesNotThrow()) ||
- CS.isInlineAsm()))
+ if (CalledFn &&
+ ((CalledFn->hasLLVMReservedName() && CS.doesNotThrow()) ||
+ CS.isInlineAsm()))
continue;
// This call site was not part of this funclet, remove it.
// Process metadata used directly by intrinsics.
if (const CallInst *CI = dyn_cast<CallInst>(&I))
if (Function *F = CI->getCalledFunction())
- if (F->isIntrinsic())
+ if (F->hasLLVMReservedName())
for (auto &Op : I.operands())
if (auto *V = dyn_cast_or_null<MetadataAsValue>(Op))
if (MDNode *N = dyn_cast<MDNode>(V->getMetadata()))
static bool isReferencingMDNode(const Instruction &I) {
if (const auto *CI = dyn_cast<CallInst>(&I))
if (Function *F = CI->getCalledFunction())
- if (F->isIntrinsic())
+ if (F->hasLLVMReservedName())
for (auto &Op : I.operands())
if (auto *V = dyn_cast_or_null<MetadataAsValue>(Op))
if (isa<MDNode>(V->getMetadata()))
/// \brief This does the actual lookup of an intrinsic ID which
/// matches the given function name.
-static Intrinsic::ID lookupIntrinsicID(const ValueName *ValName) {
- StringRef Name = ValName->getKey();
-
+static Intrinsic::ID lookupIntrinsicID(StringRef Name) {
ArrayRef<const char *> NameTable = findTargetSubtable(Name);
int Idx = Intrinsic::lookupLLVMIntrinsicByName(NameTable, Name);
if (Idx == -1)
}
void Function::recalculateIntrinsicID() {
- const ValueName *ValName = this->getValueName();
- if (!ValName || !isIntrinsic()) {
+ if (!hasLLVMReservedName()) {
IntID = Intrinsic::not_intrinsic;
return;
}
- IntID = lookupIntrinsicID(ValName);
+ IntID = lookupIntrinsicID(getName());
}
/// Returns a stable mangling for the type specified for use in the name
// Check to make sure that the "address of" an intrinsic function is never
// taken.
Assert(
- !F->isIntrinsic() ||
+ !F->hasLLVMReservedName() ||
i == (isa<CallInst>(I) ? e - 1 : isa<InvokeInst>(I) ? e - 3 : 0),
"Cannot take the address of an intrinsic!", &I);
Assert(