-
Notifications
You must be signed in to change notification settings - Fork 14.5k
TableGen: Use StringOffsetTable for RuntimeLibcall names #148839
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
TableGen: Use StringOffsetTable for RuntimeLibcall names #148839
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
@llvm/pr-subscribers-llvm-ir @llvm/pr-subscribers-tablegen Author: Matt Arsenault (arsenm) ChangesFull diff: https://github.com/llvm/llvm-project/pull/148839.diff 6 Files Affected:
diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.h b/llvm/include/llvm/IR/RuntimeLibcalls.h
index 85db45e27e912..8058c8a4c5510 100644
--- a/llvm/include/llvm/IR/RuntimeLibcalls.h
+++ b/llvm/include/llvm/IR/RuntimeLibcalls.h
@@ -16,6 +16,7 @@
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/Sequence.h"
+#include "llvm/ADT/StringTable.h"
#include "llvm/IR/CallingConv.h"
#include "llvm/IR/InstrTypes.h"
#include "llvm/Support/AtomicOrdering.h"
@@ -77,12 +78,16 @@ struct RuntimeLibcallsInfo {
/// Get the libcall routine name for the specified libcall.
// FIXME: This should be removed. Only LibcallImpl should have a name.
const char *getLibcallName(RTLIB::Libcall Call) const {
- return LibCallImplNames[LibcallImpls[Call]];
+ return getLibcallImplName(LibcallImpls[Call]);
}
/// Get the libcall routine name for the specified libcall implementation.
+ // FIXME: Change to return StringRef
static const char *getLibcallImplName(RTLIB::LibcallImpl CallImpl) {
- return LibCallImplNames[CallImpl];
+ if (CallImpl == RTLIB::Unsupported)
+ return nullptr;
+ return RuntimeLibcallImplNameTable[RuntimeLibcallNameOffsetTable[CallImpl]]
+ .data();
}
/// Return the lowering's selection of implementation call for \p Call
@@ -144,7 +149,9 @@ struct RuntimeLibcallsInfo {
/// Names of concrete implementations of runtime calls. e.g. __ashlsi3 for
/// SHL_I32
- LLVM_ABI static const char *const LibCallImplNames[RTLIB::NumLibcallImpls];
+ LLVM_ABI static const char RuntimeLibcallImplNameTableStorage[];
+ LLVM_ABI static const StringTable RuntimeLibcallImplNameTable;
+ LLVM_ABI static const uint16_t RuntimeLibcallNameOffsetTable[];
/// Map from a concrete LibcallImpl implementation to its RTLIB::Libcall kind.
LLVM_ABI static const RTLIB::Libcall ImplToLibcall[RTLIB::NumLibcallImpls];
diff --git a/llvm/include/llvm/TableGen/StringToOffsetTable.h b/llvm/include/llvm/TableGen/StringToOffsetTable.h
index 1550515ce3d7b..154ded8e94d7f 100644
--- a/llvm/include/llvm/TableGen/StringToOffsetTable.h
+++ b/llvm/include/llvm/TableGen/StringToOffsetTable.h
@@ -23,10 +23,15 @@ namespace llvm {
class StringToOffsetTable {
StringMap<unsigned> StringOffset;
std::string AggregateString;
+
+ /// If this is to be a static class member, the prefix to use (i.e. class name
+ /// plus ::)
+ const StringRef ClassPrefix;
const bool AppendZero;
public:
- StringToOffsetTable(bool AppendZero = true) : AppendZero(AppendZero) {
+ StringToOffsetTable(bool AppendZero = true, StringRef ClassPrefix = "")
+ : ClassPrefix(ClassPrefix), AppendZero(AppendZero) {
// Ensure we always put the empty string at offset zero. That lets empty
// initialization also be zero initialization for offsets into the table.
GetOrAddStringOffset("");
diff --git a/llvm/lib/IR/RuntimeLibcalls.cpp b/llvm/lib/IR/RuntimeLibcalls.cpp
index 6624e24cc7cf5..b1864897dafa6 100644
--- a/llvm/lib/IR/RuntimeLibcalls.cpp
+++ b/llvm/lib/IR/RuntimeLibcalls.cpp
@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/IR/RuntimeLibcalls.h"
+#include "llvm/ADT/StringTable.h"
using namespace llvm;
using namespace RTLIB;
diff --git a/llvm/lib/TableGen/StringToOffsetTable.cpp b/llvm/lib/TableGen/StringToOffsetTable.cpp
index 17e1e660c15ee..9fb41485db745 100644
--- a/llvm/lib/TableGen/StringToOffsetTable.cpp
+++ b/llvm/lib/TableGen/StringToOffsetTable.cpp
@@ -38,8 +38,8 @@ void StringToOffsetTable::EmitStringTableDef(raw_ostream &OS,
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Woverlength-strings"
#endif
-static constexpr char {}Storage[] = )",
- Name);
+{} constexpr char {}{}Storage[] = )",
+ ClassPrefix.empty() ? "static" : "", ClassPrefix, Name);
// MSVC silently miscompiles string literals longer than 64k in some
// circumstances. The build system sets EmitLongStrLiterals to false when it
@@ -83,10 +83,10 @@ static constexpr char {}Storage[] = )",
#pragma GCC diagnostic pop
#endif
-static constexpr llvm::StringTable
-{0} = {0}Storage;
+{1}constexpr llvm::StringTable
+{2}{0} = {0}Storage;
)",
- Name);
+ Name, ClassPrefix.empty() ? "static " : "", ClassPrefix);
}
void StringToOffsetTable::EmitString(raw_ostream &O) const {
diff --git a/llvm/test/TableGen/RuntimeLibcallEmitter.td b/llvm/test/TableGen/RuntimeLibcallEmitter.td
index a0061afab1db0..2a7da5dede3f6 100644
--- a/llvm/test/TableGen/RuntimeLibcallEmitter.td
+++ b/llvm/test/TableGen/RuntimeLibcallEmitter.td
@@ -116,19 +116,40 @@ def BlahLibrary : SystemRuntimeLibrary<isBlahArch, (add calloc, LibraryWithCondi
// CHECK-NEXT: RTLIB::Unsupported
// CHECK-NEXT: };
// CHECK-EMPTY:
-// CHECK-NEXT: const char *const llvm::RTLIB::RuntimeLibcallsInfo::LibCallImplNames[RTLIB::NumLibcallImpls] = {
-// CHECK-NEXT: nullptr, // RTLIB::Unsupported
-// CHECK-NEXT: "___memcpy", // RTLIB::___memcpy
-// CHECK-NEXT: "___memset", // RTLIB::___memset
-// CHECK-NEXT: "__ashlsi3", // RTLIB::__ashlsi3
-// CHECK-NEXT: "__lshrdi3", // RTLIB::__lshrdi3
-// CHECK-NEXT: "bzero", // RTLIB::bzero
-// CHECK-NEXT: "calloc", // RTLIB::calloc
-// CHECK-NEXT: "sqrtl", // RTLIB::sqrtl_f80
-// CHECK-NEXT: "sqrtl", // RTLIB::sqrtl_f128
+// CHECK-EMPTY:
+// CHECK-NEXT: #ifdef __GNUC__
+// CHECK-NEXT: #pragma GCC diagnostic push
+// CHECK-NEXT: #pragma GCC diagnostic ignored "-Woverlength-strings"
+// CHECK-NEXT: #endif
+// CHECK-NEXT: constexpr char RTLIB::RuntimeLibcallsInfo::RuntimeLibcallImplNameTableStorage[] =
+// CHECK-NEXT: "\0"
+// CHECK-NEXT: "___memcpy\0"
+// CHECK-NEXT: "___memset\0"
+// CHECK-NEXT: "__ashlsi3\0"
+// CHECK-NEXT: "__lshrdi3\0"
+// CHECK-NEXT: "bzero\0"
+// CHECK-NEXT: "calloc\0"
+// CHECK-NEXT: "sqrtl\0"
+// CHECK-NEXT: ;
+// CHECK-NEXT: #ifdef __GNUC__
+// CHECK-NEXT: #pragma GCC diagnostic pop
+// CHECK-NEXT: #endif
+// CHECK-EMPTY:
+// CHECK-NEXT: constexpr llvm::StringTable
+// CHECK-NEXT: RTLIB::RuntimeLibcallsInfo::RuntimeLibcallImplNameTable = RuntimeLibcallImplNameTableStorage;
+// CHECK-EMPTY:
+// CHECK-NEXT: const uint16_t RTLIB::RuntimeLibcallsInfo::RuntimeLibcallNameOffsetTable[] = {
+// CHECK-NEXT: 0, //
+// CHECK-NEXT: 1, // ___memcpy
+// CHECK-NEXT: 11, // ___memset
+// CHECK-NEXT: 21, // __ashlsi3
+// CHECK-NEXT: 31, // __lshrdi3
+// CHECK-NEXT: 41, // bzero
+// CHECK-NEXT: 47, // calloc
+// CHECK-NEXT: 54, // sqrtl
+// CHECK-NEXT: 54, // sqrtl
// CHECK-NEXT: };
-
-// CHECK: const RTLIB::Libcall llvm::RTLIB::RuntimeLibcallsInfo::ImplToLibcall[RTLIB::NumLibcallImpls] = {
+// CHECK-NEXT: const RTLIB::Libcall llvm::RTLIB::RuntimeLibcallsInfo::ImplToLibcall[RTLIB::NumLibcallImpls] = {
// CHECK-NEXT: RTLIB::UNKNOWN_LIBCALL, // RTLIB::Unsupported
// CHECK-NEXT: RTLIB::MEMCPY, // RTLIB::___memcpy
// CHECK-NEXT: RTLIB::MEMSET, // RTLIB::___memset
diff --git a/llvm/utils/TableGen/Basic/RuntimeLibcallsEmitter.cpp b/llvm/utils/TableGen/Basic/RuntimeLibcallsEmitter.cpp
index 68bd1b5c9cb21..652bea9dc7f65 100644
--- a/llvm/utils/TableGen/Basic/RuntimeLibcallsEmitter.cpp
+++ b/llvm/utils/TableGen/Basic/RuntimeLibcallsEmitter.cpp
@@ -8,10 +8,12 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Debug.h"
+#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/TableGen/Error.h"
#include "llvm/TableGen/Record.h"
#include "llvm/TableGen/SetTheory.h"
+#include "llvm/TableGen/StringToOffsetTable.h"
#include "llvm/TableGen/TableGenBackend.h"
using namespace llvm;
@@ -305,8 +307,6 @@ void RuntimeLibcallEmitter::emitGetRuntimeLibcallEnum(raw_ostream &OS) const {
void RuntimeLibcallEmitter::emitGetInitRuntimeLibcallNames(
raw_ostream &OS) const {
- // TODO: Emit libcall names as string offset table.
-
OS << "const RTLIB::LibcallImpl "
"llvm::RTLIB::RuntimeLibcallsInfo::"
"DefaultLibcallImpls[RTLIB::UNKNOWN_LIBCALL + 1] = {\n";
@@ -331,17 +331,24 @@ void RuntimeLibcallEmitter::emitGetInitRuntimeLibcallNames(
"};\n\n";
// Emit the implementation names
- OS << "const char *const llvm::RTLIB::RuntimeLibcallsInfo::"
- "LibCallImplNames[RTLIB::NumLibcallImpls] = {\n"
- " nullptr, // RTLIB::Unsupported\n";
+ StringToOffsetTable Table(/*AppendZero=*/true,
+ "RTLIB::RuntimeLibcallsInfo::");
+
+ for (const RuntimeLibcallImpl &LibCallImpl : RuntimeLibcallImplDefList)
+ Table.GetOrAddStringOffset(LibCallImpl.getLibcallFuncName());
+
+ Table.EmitStringTableDef(OS, "RuntimeLibcallImplNameTable");
+ OS << R"(
+const uint16_t RTLIB::RuntimeLibcallsInfo::RuntimeLibcallNameOffsetTable[] = {
+)";
+ OS << formatv(" {}, // {}\n", Table.GetStringOffset(""),
+ ""); // Unsupported entry
for (const RuntimeLibcallImpl &LibCallImpl : RuntimeLibcallImplDefList) {
- OS << " \"" << LibCallImpl.getLibcallFuncName() << "\", // ";
- LibCallImpl.emitEnumEntry(OS);
- OS << '\n';
+ StringRef ImplName = LibCallImpl.getLibcallFuncName();
+ OS << formatv(" {}, // {}\n", Table.GetStringOffset(ImplName), ImplName);
}
-
- OS << "};\n\n";
+ OS << "};\n";
// Emit the reverse mapping from implementation libraries to RTLIB::Libcall
OS << "const RTLIB::Libcall llvm::RTLIB::RuntimeLibcallsInfo::"
|
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
Merge activity
|
7545fb4
to
0798c63
Compare
0798c63
to
b113ff2
Compare
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/175/builds/22271 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/185/builds/22136 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/137/builds/22343 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/204/builds/15598 Here is the relevant piece of the build log for the reference
|
Hi there, our bot keeps failing on build with the same error. It seems related to this PR. Could you please take a look? Thanks!
Bot: https://lab.llvm.org/buildbot/#/builders/204/builds/15598 |
// CHECK-NEXT: #pragma GCC diagnostic pop | ||
// CHECK-NEXT: #endif | ||
// CHECK-EMPTY: | ||
// CHECK-NEXT: constexpr llvm::StringTable |
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.
I think this may need to be extern
, because the constexpr
variable has internal linkage by default. When built using gcc the libLLVMCore.a
does not export the symbol.
We are also seeing build failures in two of our bots:
Can you please take a look and revert if you need time to investigate? |
It looks like reverting this commit requires reverting the more recent one(s). This patch worked for me:
If someone can please confirm that it works in at least one other case, I will create a PR for it. |
This fixes the buildbots issues reported in llvm#148839.
This fixes the buildbots issues reported in #148839.
No description provided.