aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/Function.cpp
diff options
context:
space:
mode:
authorRahul Joshi <rjoshi@nvidia.com>2024-09-25 12:01:43 -0700
committerGitHub <noreply@github.com>2024-09-25 12:01:43 -0700
commit6786928c4fe1f9daf720d3b604987de2b013e70b (patch)
tree6019e52986dad7fa3b6440574413ab42db1df05d /llvm/lib/IR/Function.cpp
parent2f43e65955565f92d3103b4bd57f17d02385d0e3 (diff)
downloadllvm-6786928c4fe1f9daf720d3b604987de2b013e70b.zip
llvm-6786928c4fe1f9daf720d3b604987de2b013e70b.tar.gz
llvm-6786928c4fe1f9daf720d3b604987de2b013e70b.tar.bz2
[Core] Skip over target name in intrinsic name lookup (#109971)
When searching for an intrinsic name in a target specific slice of the intrinsic name table, skip over the target prefix. For such cases, currently the first loop iteration in `lookupLLVMIntrinsicByName` does nothing (i.e., `Low` and `High` stay unchanged and it does not shrink down the search window), so we can skip this useless first iteration by skipping over the target prefix.
Diffstat (limited to 'llvm/lib/IR/Function.cpp')
-rw-r--r--llvm/lib/IR/Function.cpp19
1 files changed, 10 insertions, 9 deletions
diff --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp
index 8767c29..863900c 100644
--- a/llvm/lib/IR/Function.cpp
+++ b/llvm/lib/IR/Function.cpp
@@ -940,8 +940,8 @@ void Function::setOnlyAccessesInaccessibleMemOrArgMem() {
}
/// Table of string intrinsic names indexed by enum value.
-static const char * const IntrinsicNameTable[] = {
- "not_intrinsic",
+static constexpr const char *const IntrinsicNameTable[] = {
+ "not_intrinsic",
#define GET_INTRINSIC_NAME_TABLE
#include "llvm/IR/IntrinsicImpl.inc"
#undef GET_INTRINSIC_NAME_TABLE
@@ -963,8 +963,9 @@ bool Function::isTargetIntrinsic() const {
/// Find the segment of \c IntrinsicNameTable for intrinsics with the same
/// target as \c Name, or the generic table if \c Name is not target specific.
///
-/// Returns the relevant slice of \c IntrinsicNameTable
-static ArrayRef<const char *> findTargetSubtable(StringRef Name) {
+/// Returns the relevant slice of \c IntrinsicNameTable and the target name.
+static std::pair<ArrayRef<const char *>, StringRef>
+findTargetSubtable(StringRef Name) {
assert(Name.starts_with("llvm."));
ArrayRef<IntrinsicTargetInfo> Targets(TargetInfos);
@@ -976,14 +977,14 @@ static ArrayRef<const char *> findTargetSubtable(StringRef Name) {
// We've either found the target or just fall back to the generic set, which
// is always first.
const auto &TI = It != Targets.end() && It->Name == Target ? *It : Targets[0];
- return ArrayRef(&IntrinsicNameTable[1] + TI.Offset, TI.Count);
+ return {ArrayRef(&IntrinsicNameTable[1] + TI.Offset, TI.Count), TI.Name};
}
-/// This does the actual lookup of an intrinsic ID which
-/// matches the given function name.
+/// This does the actual lookup of an intrinsic ID which matches the given
+/// function name.
Intrinsic::ID Function::lookupIntrinsicID(StringRef Name) {
- ArrayRef<const char *> NameTable = findTargetSubtable(Name);
- int Idx = Intrinsic::lookupLLVMIntrinsicByName(NameTable, Name);
+ auto [NameTable, Target] = findTargetSubtable(Name);
+ int Idx = Intrinsic::lookupLLVMIntrinsicByName(NameTable, Name, Target);
if (Idx == -1)
return Intrinsic::not_intrinsic;