From 6786928c4fe1f9daf720d3b604987de2b013e70b Mon Sep 17 00:00:00 2001 From: Rahul Joshi Date: Wed, 25 Sep 2024 12:01:43 -0700 Subject: [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. --- llvm/lib/IR/Function.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'llvm/lib/IR/Function.cpp') 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 findTargetSubtable(StringRef Name) { +/// Returns the relevant slice of \c IntrinsicNameTable and the target name. +static std::pair, StringRef> +findTargetSubtable(StringRef Name) { assert(Name.starts_with("llvm.")); ArrayRef Targets(TargetInfos); @@ -976,14 +977,14 @@ static ArrayRef 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 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; -- cgit v1.1