Skip to content

Commit

Permalink
Refactor isIntrinsic() to be quicker, and change classof() (and thus,…
Browse files Browse the repository at this point in the history
… isa<IntrinsicInst>()) to use it. This decreases the number of occurrences of the slow-path string matching performed by getIntrinsicID().

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@170602 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
milseman committed Dec 19, 2012
1 parent 18e7211 commit f846f16
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 7 deletions.
2 changes: 1 addition & 1 deletion include/llvm/Function.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class Function : public GlobalValue,
/// defined in llvm/Intrinsics.h.
///
unsigned getIntrinsicID() const LLVM_READONLY;
bool isIntrinsic() const { return getIntrinsicID() != 0; }
bool isIntrinsic() const { return getName().startswith("llvm."); }

/// getCallingConv()/setCallingConv(CC) - These method get and set the
/// calling convention of this function. The enum values for the known
Expand Down
2 changes: 1 addition & 1 deletion include/llvm/IntrinsicInst.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace llvm {
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const CallInst *I) {
if (const Function *CF = I->getCalledFunction())
return CF->getIntrinsicID() != 0;
return CF->isIntrinsic();
return false;
}
static inline bool classof(const Value *V) {
Expand Down
6 changes: 1 addition & 5 deletions lib/VMCore/Function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,15 +326,11 @@ void Function::copyAttributesFrom(const GlobalValue *Src) {
///
unsigned Function::getIntrinsicID() const {
const ValueName *ValName = this->getValueName();
if (!ValName)
if (!ValName || !isIntrinsic())
return 0;
unsigned Len = ValName->getKeyLength();
const char *Name = ValName->getKeyData();

if (Len < 5 || Name[4] != '.' || Name[0] != 'l' || Name[1] != 'l'
|| Name[2] != 'v' || Name[3] != 'm')
return 0; // All intrinsics start with 'llvm.'

#define GET_FUNCTION_RECOGNIZER
#include "llvm/Intrinsics.gen"
#undef GET_FUNCTION_RECOGNIZER
Expand Down

0 comments on commit f846f16

Please sign in to comment.