diff options
author | Reid Kleckner <rnk@google.com> | 2016-01-26 22:33:19 +0000 |
---|---|---|
committer | Reid Kleckner <rnk@google.com> | 2016-01-26 22:33:19 +0000 |
commit | c2752daa6bf70786ebbb448208af8fb62a431ecc (patch) | |
tree | 30f5d3485a097097f1b05b97a178e64753b9a89d /llvm/lib/IR/Function.cpp | |
parent | 7da47b8ef5efc16caef8cbd45f495baf9b383370 (diff) | |
download | llvm-c2752daa6bf70786ebbb448208af8fb62a431ecc.zip llvm-c2752daa6bf70786ebbb448208af8fb62a431ecc.tar.gz llvm-c2752daa6bf70786ebbb448208af8fb62a431ecc.tar.bz2 |
Handle more edge cases in intrinsic name binary search
I tried to make the AMDGPU intrinsic info table use this instead of
another StringMatcher, and some issues arose.
llvm-svn: 258871
Diffstat (limited to 'llvm/lib/IR/Function.cpp')
-rw-r--r-- | llvm/lib/IR/Function.cpp | 41 |
1 files changed, 1 insertions, 40 deletions
diff --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp index 4e08000..40a8ec6 100644 --- a/llvm/lib/IR/Function.cpp +++ b/llvm/lib/IR/Function.cpp @@ -414,53 +414,14 @@ static const char * const IntrinsicNameTable[] = { #undef GET_INTRINSIC_NAME_TABLE }; -static int lookupLLVMIntrinsicByName(ArrayRef<const char *> NameTable, - StringRef Name) { - // Do a binary search over the table of intrinsic names. - const char *const *NameEntry = - std::lower_bound(NameTable.begin(), NameTable.end(), Name.data(), - [](const char *LHS, const char *RHS) { - // Don't compare the first 5 characters, they are - // always "llvm.". - return strcmp(LHS + 5, RHS + 5) < 0; - }); - unsigned Idx = NameEntry - NameTable.begin(); - - // Check if this is a direct match. - if (Idx < NameTable.size() && strcmp(Name.data(), NameTable[Idx]) == 0) - return Idx; - - // Otherwise, back up one entry to look for a prefix of Name where the next - // character in Name is a dot. - if (Idx == 0) - return -1; - --Idx; - bool CheckPrefixes = true; - while (CheckPrefixes) { - StringRef FoundName = NameTable[Idx]; - if (Name.startswith(FoundName) && Name[FoundName.size()] == '.') - return Idx; - if (Idx == 0) - return -1; - --Idx; - // We have to keep scanning backwards until the previous entry is not a - // prefix of the current entry. Consider a key of llvm.foo.f64 and a table - // of llvm.foo and llvm.foo.bar. - CheckPrefixes = FoundName.startswith(NameTable[Idx]); - } - - return -1; -} - /// \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(); - assert(Name.data()[Name.size()] == '\0' && "non-null terminated ValueName"); ArrayRef<const char *> NameTable(&IntrinsicNameTable[1], std::end(IntrinsicNameTable)); - int Idx = lookupLLVMIntrinsicByName(NameTable, Name); + int Idx = Intrinsic::lookupLLVMIntrinsicByName(NameTable, Name); Intrinsic::ID ID = static_cast<Intrinsic::ID>(Idx + 1); if (ID == Intrinsic::not_intrinsic) return ID; |