[llvm] [NFC] Add a new Intrinsics.cpp file for intrinsic code (PR #110078)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 26 03:12:25 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-ir
Author: Rahul Joshi (jurahul)
<details>
<summary>Changes</summary>
Add new file Intrinsics.cpp and move `lookupLLVMIntrinsicByName` to that file.
---
Full diff: https://github.com/llvm/llvm-project/pull/110078.diff
4 Files Affected:
- (modified) llvm/include/llvm/IR/Intrinsics.h (+1-1)
- (modified) llvm/lib/IR/CMakeLists.txt (+1)
- (modified) llvm/lib/IR/IntrinsicInst.cpp (-42)
- (added) llvm/lib/IR/Intrinsics.cpp (+57)
``````````diff
diff --git a/llvm/include/llvm/IR/Intrinsics.h b/llvm/include/llvm/IR/Intrinsics.h
index 0ec7e47812af44..99dd87d3719640 100644
--- a/llvm/include/llvm/IR/Intrinsics.h
+++ b/llvm/include/llvm/IR/Intrinsics.h
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
//
// This file defines a set of enums which allow processing of intrinsic
-// functions. Values of these enum types are returned by
+// functions. Values of these enum types are returned by
// Function::getIntrinsicID.
//
//===----------------------------------------------------------------------===//
diff --git a/llvm/lib/IR/CMakeLists.txt b/llvm/lib/IR/CMakeLists.txt
index e5756940dd5a03..544f4ea9223d0e 100644
--- a/llvm/lib/IR/CMakeLists.txt
+++ b/llvm/lib/IR/CMakeLists.txt
@@ -32,6 +32,7 @@ add_llvm_component_library(LLVMCore
GCStrategy.cpp
GVMaterializer.cpp
Globals.cpp
+ Intrinsics.cpp
IRBuilder.cpp
IRPrintingPasses.cpp
SSAContext.cpp
diff --git a/llvm/lib/IR/IntrinsicInst.cpp b/llvm/lib/IR/IntrinsicInst.cpp
index 5654a3a3236c6d..0a6c93fde6302f 100644
--- a/llvm/lib/IR/IntrinsicInst.cpp
+++ b/llvm/lib/IR/IntrinsicInst.cpp
@@ -236,48 +236,6 @@ void DbgAssignIntrinsic::setValue(Value *V) {
MetadataAsValue::get(getContext(), ValueAsMetadata::get(V)));
}
-int llvm::Intrinsic::lookupLLVMIntrinsicByName(ArrayRef<const char *> NameTable,
- StringRef Name,
- StringRef Target) {
- assert(Name.starts_with("llvm.") && "Unexpected intrinsic prefix");
- assert(Name.drop_front(5).starts_with(Target) && "Unexpected target");
-
- // Do successive binary searches of the dotted name components. For
- // "llvm.gc.experimental.statepoint.p1i8.p1i32", we will find the range of
- // intrinsics starting with "llvm.gc", then "llvm.gc.experimental", then
- // "llvm.gc.experimental.statepoint", and then we will stop as the range is
- // size 1. During the search, we can skip the prefix that we already know is
- // identical. By using strncmp we consider names with differing suffixes to
- // be part of the equal range.
- size_t CmpEnd = 4; // Skip the "llvm" component.
- if (!Target.empty())
- CmpEnd += 1 + Target.size(); // skip the .target component.
-
- const char *const *Low = NameTable.begin();
- const char *const *High = NameTable.end();
- const char *const *LastLow = Low;
- while (CmpEnd < Name.size() && High - Low > 0) {
- size_t CmpStart = CmpEnd;
- CmpEnd = Name.find('.', CmpStart + 1);
- CmpEnd = CmpEnd == StringRef::npos ? Name.size() : CmpEnd;
- auto Cmp = [CmpStart, CmpEnd](const char *LHS, const char *RHS) {
- return strncmp(LHS + CmpStart, RHS + CmpStart, CmpEnd - CmpStart) < 0;
- };
- LastLow = Low;
- std::tie(Low, High) = std::equal_range(Low, High, Name.data(), Cmp);
- }
- if (High - Low > 0)
- LastLow = Low;
-
- if (LastLow == NameTable.end())
- return -1;
- StringRef NameFound = *LastLow;
- if (Name == NameFound ||
- (Name.starts_with(NameFound) && Name[NameFound.size()] == '.'))
- return LastLow - NameTable.begin();
- return -1;
-}
-
ConstantInt *InstrProfCntrInstBase::getNumCounters() const {
if (InstrProfValueProfileInst::classof(this))
llvm_unreachable("InstrProfValueProfileInst does not have counters!");
diff --git a/llvm/lib/IR/Intrinsics.cpp b/llvm/lib/IR/Intrinsics.cpp
new file mode 100644
index 00000000000000..c1d2ad31897a20
--- /dev/null
+++ b/llvm/lib/IR/Intrinsics.cpp
@@ -0,0 +1,57 @@
+//===-- Intrinsics.cpp - Intrinsic Function Handling ------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements functions required for supporting intrinsic functions.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/IR/Intrinsics.h"
+
+using namespace llvm;
+
+int llvm::Intrinsic::lookupLLVMIntrinsicByName(ArrayRef<const char *> NameTable,
+ StringRef Name,
+ StringRef Target) {
+ assert(Name.starts_with("llvm.") && "Unexpected intrinsic prefix");
+ assert(Name.drop_front(5).starts_with(Target) && "Unexpected target");
+
+ // Do successive binary searches of the dotted name components. For
+ // "llvm.gc.experimental.statepoint.p1i8.p1i32", we will find the range of
+ // intrinsics starting with "llvm.gc", then "llvm.gc.experimental", then
+ // "llvm.gc.experimental.statepoint", and then we will stop as the range is
+ // size 1. During the search, we can skip the prefix that we already know is
+ // identical. By using strncmp we consider names with differing suffixes to
+ // be part of the equal range.
+ size_t CmpEnd = 4; // Skip the "llvm" component.
+ if (!Target.empty())
+ CmpEnd += 1 + Target.size(); // skip the .target component.
+
+ const char *const *Low = NameTable.begin();
+ const char *const *High = NameTable.end();
+ const char *const *LastLow = Low;
+ while (CmpEnd < Name.size() && High - Low > 0) {
+ size_t CmpStart = CmpEnd;
+ CmpEnd = Name.find('.', CmpStart + 1);
+ CmpEnd = CmpEnd == StringRef::npos ? Name.size() : CmpEnd;
+ auto Cmp = [CmpStart, CmpEnd](const char *LHS, const char *RHS) {
+ return strncmp(LHS + CmpStart, RHS + CmpStart, CmpEnd - CmpStart) < 0;
+ };
+ LastLow = Low;
+ std::tie(Low, High) = std::equal_range(Low, High, Name.data(), Cmp);
+ }
+ if (High - Low > 0)
+ LastLow = Low;
+
+ if (LastLow == NameTable.end())
+ return -1;
+ StringRef NameFound = *LastLow;
+ if (Name == NameFound ||
+ (Name.starts_with(NameFound) && Name[NameFound.size()] == '.'))
+ return LastLow - NameTable.begin();
+ return -1;
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/110078
More information about the llvm-commits
mailing list