-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[NFC] Add a new Intrinsics.cpp file for intrinsic code #110078
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-llvm-ir Author: Rahul Joshi (jurahul) ChangesAdd new file Intrinsics.cpp and move Full diff: https://github.com/llvm/llvm-project/pull/110078.diff 4 Files Affected:
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;
+}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the motivation for splitting this into a separate file? Is this just so the name matches the name of the header?
The motivation for moving |
We could also rename Intrinsics.h to Intrinsic.h to match the namespace, but that may be too much busy work for questionable benefit. |
Can you please also move the functions from Function.cpp over in this PR? It's a bit hard to judge the scope otherwise. |
I did look into that, one issue is that |
These 2 to be accurate:
|
I've started #110125 |
dc2f228
to
ae77fef
Compare
Add new file Intrinsics.cpp and move `lookupLLVMIntrinsicByName` to that file.
ae77fef
to
ceaab0e
Compare
PTAL at the new version, it moves all function from the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/146/builds/1291 Here is the relevant piece of the build log for the reference
|
Add new file Intrinsics.cpp and move all functions in the `Intrinsic` namespace to it.
Add new file Intrinsics.cpp and move all functions in the
Intrinsic
namespace to it.