[llvm] Revert "RuntimeLibcalls: Generate table of libcall name lengths (#153… (PR #153864)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 15 12:49:09 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lto
Author: None (gulfemsavrun)
<details>
<summary>Changes</summary>
…210)"
This reverts commit 9a14b1d254a43dc0d4445c3ffa3d393bca007ba3.
Revert "RuntimeLibcalls: Return StringRef for libcall names (#<!-- -->153209)"
This reverts commit cb1228fbd535b8f9fe78505a15292b0ba23b17de.
Revert "TableGen: Emit statically generated hash table for runtime libcalls (#<!-- -->150192)"
This reverts commit 769a9058c8d04fc920994f6a5bbb03c8a4fbcd05.
Reverted three changes because of a CMake error while building llvm-nm as reported in the following PR:
https://github.com/llvm/llvm-project/pull/150192#issuecomment-3192223073
---
Patch is 36.96 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/153864.diff
14 Files Affected:
- (modified) llvm/benchmarks/CMakeLists.txt (-17)
- (removed) llvm/benchmarks/RuntimeLibcalls.cpp (-114)
- (modified) llvm/include/llvm/CodeGen/TargetLowering.h (+4-8)
- (modified) llvm/include/llvm/IR/RuntimeLibcalls.h (+17-47)
- (modified) llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp (+1-1)
- (modified) llvm/lib/IR/RuntimeLibcalls.cpp (+41-18)
- (modified) llvm/lib/LTO/LTO.cpp (+1-1)
- (modified) llvm/lib/Object/IRSymtab.cpp (+25-22)
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyRuntimeLibcallSignatures.cpp (+2-2)
- (modified) llvm/lib/Transforms/Utils/DeclareRuntimeLibcalls.cpp (+1-1)
- (modified) llvm/test/TableGen/RuntimeLibcallEmitter.td (-39)
- (modified) llvm/unittests/IR/CMakeLists.txt (-1)
- (removed) llvm/unittests/IR/RuntimeLibcallsTest.cpp (-63)
- (modified) llvm/utils/TableGen/Basic/RuntimeLibcallsEmitter.cpp (+8-200)
``````````diff
diff --git a/llvm/benchmarks/CMakeLists.txt b/llvm/benchmarks/CMakeLists.txt
index 9613678d2e0ac..1078efa55f497 100644
--- a/llvm/benchmarks/CMakeLists.txt
+++ b/llvm/benchmarks/CMakeLists.txt
@@ -11,20 +11,3 @@ add_benchmark(FormatVariadicBM FormatVariadicBM.cpp PARTIAL_SOURCES_INTENDED)
add_benchmark(GetIntrinsicInfoTableEntriesBM GetIntrinsicInfoTableEntriesBM.cpp PARTIAL_SOURCES_INTENDED)
add_benchmark(SandboxIRBench SandboxIRBench.cpp PARTIAL_SOURCES_INTENDED)
-# Extract the list of symbols in a random utility as sample data.
-set(SYMBOL_TEST_DATA_FILE "sample_symbol_list.txt")
-set(SYMBOL_TEST_DATA_SOURCE_BINARY $<TARGET_FILE:llc>)
-
-add_custom_command(OUTPUT ${SYMBOL_TEST_DATA_FILE}
- COMMAND $<TARGET_FILE:llvm-nm> --no-demangle --no-sort
- --format=just-symbols
- ${SYMBOL_TEST_DATA_SOURCE_BINARY} > ${SYMBOL_TEST_DATA_FILE}
- DEPENDS "$<TARGET_FILE:llvm-nm>" "$<TARGET_FILE:llc>")
-
-add_custom_target(generate-runtime-libcalls-sample-symbol-list
- DEPENDS ${SYMBOL_TEST_DATA_FILE})
-add_benchmark(RuntimeLibcallsBench RuntimeLibcalls.cpp PARTIAL_SOURCES_INTENDED)
-
-add_dependencies(RuntimeLibcallsBench generate-runtime-libcalls-sample-symbol-list)
-target_compile_definitions(RuntimeLibcallsBench PRIVATE
- -DSYMBOL_TEST_DATA_FILE="${CMAKE_CURRENT_BINARY_DIR}/${SYMBOL_TEST_DATA_FILE}")
diff --git a/llvm/benchmarks/RuntimeLibcalls.cpp b/llvm/benchmarks/RuntimeLibcalls.cpp
deleted file mode 100644
index 81a5a24ec8f93..0000000000000
--- a/llvm/benchmarks/RuntimeLibcalls.cpp
+++ /dev/null
@@ -1,114 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/IR/RuntimeLibcalls.h"
-#include "benchmark/benchmark.h"
-#include "llvm/IR/DataLayout.h"
-#include "llvm/Support/Error.h"
-#include "llvm/Support/LineIterator.h"
-#include "llvm/Support/MemoryBuffer.h"
-#include "llvm/TargetParser/Triple.h"
-#include <random>
-#include <string>
-using namespace llvm;
-
-static constexpr unsigned MaxFuncNameSize = 53;
-
-static std::vector<StringRef> getLibcallNameStringRefs() {
- std::vector<StringRef> Names(RTLIB::NumLibcallImpls);
- // Keep the strlens on the StringRef construction out of the benchmark loop.
- for (RTLIB::LibcallImpl LC : RTLIB::libcall_impls())
- Names[LC] = RTLIB::RuntimeLibcallsInfo::getLibcallImplName(LC);
-
- return Names;
-}
-
-static std::vector<std::string> getRandomFuncNames() {
- std::mt19937_64 Rng;
- std::uniform_int_distribution<> StringLengthDistribution(1, MaxFuncNameSize);
- std::uniform_int_distribution<> CharDistribution(1, 255);
- int NumTestFuncs = 1 << 10;
- std::vector<std::string> TestFuncNames(NumTestFuncs);
-
- for (std::string &TestFuncName : TestFuncNames) {
- for (int I = 0, E = StringLengthDistribution(Rng); I != E; ++I)
- TestFuncName += static_cast<char>(CharDistribution(Rng));
- }
-
- return TestFuncNames;
-}
-
-static std::vector<std::string> readSymbolsFromFile(StringRef InputFile) {
- auto BufOrError = MemoryBuffer::getFileOrSTDIN(InputFile, /*IsText=*/true);
- if (!BufOrError) {
- reportFatalUsageError("failed to open \'" + Twine(InputFile) +
- "\': " + BufOrError.getError().message());
- }
-
- // Hackily figure out if there's a prefix on the symbol names - llvm-nm
- // appears to not have a flag to skip this.
- llvm::Triple HostTriple(LLVM_HOST_TRIPLE);
- std::string DummyDatalayout = "e";
- DummyDatalayout += DataLayout::getManglingComponent(HostTriple);
-
- DataLayout DL(DummyDatalayout);
- char GlobalPrefix = DL.getGlobalPrefix();
-
- std::vector<std::string> Lines;
- for (line_iterator LineIt(**BufOrError, /*SkipBlanks=*/true);
- !LineIt.is_at_eof(); ++LineIt) {
- StringRef SymbolName = *LineIt;
- SymbolName.consume_front(StringRef(&GlobalPrefix, 1));
-
- Lines.push_back(SymbolName.str());
- }
- return Lines;
-}
-
-static void BM_LookupRuntimeLibcallByNameKnownCalls(benchmark::State &State) {
- std::vector<StringRef> Names = getLibcallNameStringRefs();
-
- for (auto _ : State) {
- for (StringRef Name : Names) {
- benchmark::DoNotOptimize(
- RTLIB::RuntimeLibcallsInfo::lookupLibcallImplName(Name).empty());
- }
- }
-}
-
-static void BM_LookupRuntimeLibcallByNameRandomCalls(benchmark::State &State) {
- std::vector<std::string> TestFuncNames = getRandomFuncNames();
-
- for (auto _ : State) {
- for (const std::string &Name : TestFuncNames) {
- benchmark::DoNotOptimize(
- RTLIB::RuntimeLibcallsInfo::lookupLibcallImplName(StringRef(Name))
- .empty());
- }
- }
-}
-
-// This isn't fully representative, it doesn't include any anonymous functions.
-// nm -n --no-demangle --format=just-symbols sample-binary > sample.txt
-static void BM_LookupRuntimeLibcallByNameSampleData(benchmark::State &State) {
- std::vector<std::string> TestFuncNames =
- readSymbolsFromFile(SYMBOL_TEST_DATA_FILE);
- for (auto _ : State) {
- for (const std::string &Name : TestFuncNames) {
- benchmark::DoNotOptimize(
- RTLIB::RuntimeLibcallsInfo::lookupLibcallImplName(StringRef(Name))
- .empty());
- }
- }
-}
-
-BENCHMARK(BM_LookupRuntimeLibcallByNameKnownCalls);
-BENCHMARK(BM_LookupRuntimeLibcallByNameRandomCalls);
-BENCHMARK(BM_LookupRuntimeLibcallByNameSampleData);
-
-BENCHMARK_MAIN();
diff --git a/llvm/include/llvm/CodeGen/TargetLowering.h b/llvm/include/llvm/CodeGen/TargetLowering.h
index 272d7dd5f45e8..ec3104799bfb5 100644
--- a/llvm/include/llvm/CodeGen/TargetLowering.h
+++ b/llvm/include/llvm/CodeGen/TargetLowering.h
@@ -3557,19 +3557,15 @@ class LLVM_ABI TargetLoweringBase {
/// Get the libcall routine name for the specified libcall.
const char *getLibcallName(RTLIB::Libcall Call) const {
- // FIXME: Return StringRef
- return Libcalls.getLibcallName(Call).data();
+ return Libcalls.getLibcallName(Call);
}
/// Get the libcall routine name for the specified libcall implementation
- static StringRef getLibcallImplName(RTLIB::LibcallImpl Call) {
- return RTLIB::RuntimeLibcallsInfo::getLibcallImplName(Call);
+ const char *getLibcallImplName(RTLIB::LibcallImpl Call) const {
+ return Libcalls.getLibcallImplName(Call);
}
- const char *getMemcpyName() const {
- // FIXME: Return StringRef
- return Libcalls.getMemcpyName().data();
- }
+ const char *getMemcpyName() const { return Libcalls.getMemcpyName(); }
/// Get the comparison predicate that's to be used to test the result of the
/// comparison libcall against zero. This should only be used with
diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.h b/llvm/include/llvm/IR/RuntimeLibcalls.h
index 308be543de2bd..2d1d07c5fd81b 100644
--- a/llvm/include/llvm/IR/RuntimeLibcalls.h
+++ b/llvm/include/llvm/IR/RuntimeLibcalls.h
@@ -77,17 +77,17 @@ struct RuntimeLibcallsInfo {
/// Get the libcall routine name for the specified libcall.
// FIXME: This should be removed. Only LibcallImpl should have a name.
- StringRef getLibcallName(RTLIB::Libcall Call) const {
+ const char *getLibcallName(RTLIB::Libcall Call) const {
return getLibcallImplName(LibcallImpls[Call]);
}
/// Get the libcall routine name for the specified libcall implementation.
- static StringRef getLibcallImplName(RTLIB::LibcallImpl CallImpl) {
+ // FIXME: Change to return StringRef
+ static const char *getLibcallImplName(RTLIB::LibcallImpl CallImpl) {
if (CallImpl == RTLIB::Unsupported)
- return StringRef();
- return StringRef(RuntimeLibcallImplNameTable.getCString(
- RuntimeLibcallNameOffsetTable[CallImpl]),
- RuntimeLibcallNameSizeTable[CallImpl]);
+ return nullptr;
+ return RuntimeLibcallImplNameTable[RuntimeLibcallNameOffsetTable[CallImpl]]
+ .data();
}
/// Return the lowering's selection of implementation call for \p Call
@@ -119,10 +119,9 @@ struct RuntimeLibcallsInfo {
/// Return a function name compatible with RTLIB::MEMCPY, or nullptr if fully
/// unsupported.
- StringRef getMemcpyName() const {
- RTLIB::LibcallImpl Memcpy = getLibcallImpl(RTLIB::MEMCPY);
- if (Memcpy != RTLIB::Unsupported)
- return getLibcallImplName(Memcpy);
+ const char *getMemcpyName() const {
+ if (const char *Memcpy = getLibcallName(RTLIB::MEMCPY))
+ return Memcpy;
// Fallback to memmove if memcpy isn't available.
return getLibcallName(RTLIB::MEMMOVE);
@@ -133,41 +132,11 @@ struct RuntimeLibcallsInfo {
return ImplToLibcall[Impl];
}
- /// Check if a function name is a recognized runtime call of any kind. This
- /// does not consider if this call is available for any current compilation,
- /// just that it is a known call somewhere. This returns the set of all
- /// LibcallImpls which match the name; multiple implementations with the same
- /// name may exist but differ in interpretation based on the target context.
- ///
- /// Generated by tablegen.
- LLVM_ABI static inline iota_range<RTLIB::LibcallImpl>
- lookupLibcallImplName(StringRef Name){
- // Inlining the early exit on the string name appears to be worthwhile when
- // querying a real set of symbols
-#define GET_LOOKUP_LIBCALL_IMPL_NAME_BODY
-#include "llvm/IR/RuntimeLibcalls.inc"
-#undef GET_LOOKUP_LIBCALL_IMPL_NAME_BODY
- }
-
/// Check if this is valid libcall for the current module, otherwise
/// RTLIB::Unsupported.
- LLVM_ABI RTLIB::LibcallImpl
- getSupportedLibcallImpl(StringRef FuncName) const {
- for (RTLIB::LibcallImpl Impl : lookupLibcallImplName(FuncName)) {
- // FIXME: This should not depend on looking up ImplToLibcall, only the
- // list of libcalls for the module.
- RTLIB::LibcallImpl Recognized = LibcallImpls[ImplToLibcall[Impl]];
- if (Recognized != RTLIB::Unsupported)
- return Recognized;
- }
-
- return RTLIB::Unsupported;
- }
+ LLVM_ABI RTLIB::LibcallImpl getSupportedLibcallImpl(StringRef FuncName) const;
private:
- LLVM_ABI static iota_range<RTLIB::LibcallImpl>
- lookupLibcallImplNameImpl(StringRef Name);
-
/// Stores the implementation choice for each each libcall.
RTLIB::LibcallImpl LibcallImpls[RTLIB::UNKNOWN_LIBCALL + 1] = {
RTLIB::Unsupported};
@@ -184,16 +153,17 @@ struct RuntimeLibcallsInfo {
LLVM_ABI static const char RuntimeLibcallImplNameTableStorage[];
LLVM_ABI static const StringTable RuntimeLibcallImplNameTable;
LLVM_ABI static const uint16_t RuntimeLibcallNameOffsetTable[];
- LLVM_ABI static const uint8_t RuntimeLibcallNameSizeTable[];
/// Map from a concrete LibcallImpl implementation to its RTLIB::Libcall kind.
LLVM_ABI static const RTLIB::Libcall ImplToLibcall[RTLIB::NumLibcallImpls];
- /// Utility function for tablegenerated lookup function. Return a range of
- /// enum values that apply for the function name at \p NameOffsetEntry with
- /// the value \p StrOffset.
- static inline iota_range<RTLIB::LibcallImpl>
- libcallImplNameHit(uint16_t NameOffsetEntry, uint16_t StrOffset);
+ /// Check if a function name is a recognized runtime call of any kind. This
+ /// does not consider if this call is available for any current compilation,
+ /// just that it is a known call somewhere. This returns the set of all
+ /// LibcallImpls which match the name; multiple implementations with the same
+ /// name may exist but differ in interpretation based on the target context.
+ LLVM_ABI static iterator_range<ArrayRef<uint16_t>::const_iterator>
+ getRecognizedLibcallImpls(StringRef FuncName);
static bool darwinHasSinCosStret(const Triple &TT) {
if (!TT.isOSDarwin())
diff --git a/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp b/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
index 96c9cde622b45..9fa96e7372961 100644
--- a/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
+++ b/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
@@ -145,7 +145,7 @@ static bool lowerObjCCall(Function &F, RTLIB::LibcallImpl NewFn,
// FIXME: When RuntimeLibcalls is an analysis, check if the function is really
// supported, and go through RTLIB::Libcall.
- StringRef NewFnName = RTLIB::RuntimeLibcallsInfo::getLibcallImplName(NewFn);
+ const char *NewFnName = RTLIB::RuntimeLibcallsInfo::getLibcallImplName(NewFn);
// If we haven't already looked up this function, check to see if the
// program already contains a function with this name.
diff --git a/llvm/lib/IR/RuntimeLibcalls.cpp b/llvm/lib/IR/RuntimeLibcalls.cpp
index 88cb192c08781..ac845c4998783 100644
--- a/llvm/lib/IR/RuntimeLibcalls.cpp
+++ b/llvm/lib/IR/RuntimeLibcalls.cpp
@@ -9,7 +9,6 @@
#include "llvm/IR/RuntimeLibcalls.h"
#include "llvm/ADT/StringTable.h"
#include "llvm/Support/Debug.h"
-#include "llvm/Support/xxhash.h"
#include "llvm/TargetParser/ARMTargetParser.h"
#define DEBUG_TYPE "runtime-libcalls-info"
@@ -19,11 +18,9 @@ using namespace RTLIB;
#define GET_INIT_RUNTIME_LIBCALL_NAMES
#define GET_SET_TARGET_RUNTIME_LIBCALL_SETS
-#define DEFINE_GET_LOOKUP_LIBCALL_IMPL_NAME
#include "llvm/IR/RuntimeLibcalls.inc"
#undef GET_INIT_RUNTIME_LIBCALL_NAMES
#undef GET_SET_TARGET_RUNTIME_LIBCALL_SETS
-#undef DEFINE_GET_LOOKUP_LIBCALL_IMPL_NAME
/// Set default libcall names. If a target wants to opt-out of a libcall it
/// should be placed here.
@@ -61,23 +58,49 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT,
}
}
-LLVM_ATTRIBUTE_ALWAYS_INLINE
-iota_range<RTLIB::LibcallImpl>
-RuntimeLibcallsInfo::libcallImplNameHit(uint16_t NameOffsetEntry,
- uint16_t StrOffset) {
- int NumAliases = 1;
- for (uint16_t Entry : ArrayRef(RuntimeLibcallNameOffsetTable)
- .drop_front(NameOffsetEntry + 1)) {
- if (Entry != StrOffset)
- break;
- ++NumAliases;
+RTLIB::LibcallImpl
+RuntimeLibcallsInfo::getSupportedLibcallImpl(StringRef FuncName) const {
+ const ArrayRef<uint16_t> RuntimeLibcallNameOffsets(
+ RuntimeLibcallNameOffsetTable);
+
+ iterator_range<ArrayRef<uint16_t>::const_iterator> Range =
+ getRecognizedLibcallImpls(FuncName);
+
+ for (auto I = Range.begin(); I != Range.end(); ++I) {
+ RTLIB::LibcallImpl Impl =
+ static_cast<RTLIB::LibcallImpl>(I - RuntimeLibcallNameOffsets.begin());
+
+ // FIXME: This should not depend on looking up ImplToLibcall, only the list
+ // of libcalls for the module.
+ RTLIB::LibcallImpl Recognized = LibcallImpls[ImplToLibcall[Impl]];
+ if (Recognized != RTLIB::Unsupported)
+ return Recognized;
}
- RTLIB::LibcallImpl ImplStart = static_cast<RTLIB::LibcallImpl>(
- &RuntimeLibcallNameOffsetTable[NameOffsetEntry] -
- &RuntimeLibcallNameOffsetTable[0]);
- return enum_seq(ImplStart,
- static_cast<RTLIB::LibcallImpl>(ImplStart + NumAliases));
+ return RTLIB::Unsupported;
+}
+
+iterator_range<ArrayRef<uint16_t>::const_iterator>
+RuntimeLibcallsInfo::getRecognizedLibcallImpls(StringRef FuncName) {
+ StringTable::Iterator It = lower_bound(RuntimeLibcallImplNameTable, FuncName);
+ if (It == RuntimeLibcallImplNameTable.end() || *It != FuncName)
+ return iterator_range(ArrayRef<uint16_t>());
+
+ uint16_t IndexVal = It.offset().value();
+ const ArrayRef<uint16_t> TableRef(RuntimeLibcallNameOffsetTable);
+
+ ArrayRef<uint16_t>::const_iterator E = TableRef.end();
+ ArrayRef<uint16_t>::const_iterator EntriesBegin =
+ std::lower_bound(TableRef.begin(), E, IndexVal);
+ ArrayRef<uint16_t>::const_iterator EntriesEnd = EntriesBegin;
+
+ while (EntriesEnd != E && *EntriesEnd == IndexVal)
+ ++EntriesEnd;
+
+ assert(EntriesBegin != E &&
+ "libcall found in name table but not offset table");
+
+ return make_range(EntriesBegin, EntriesEnd);
}
bool RuntimeLibcallsInfo::isAAPCS_ABI(const Triple &TT, StringRef ABIName) {
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp
index 35d24c17bbd93..0323b4d433b87 100644
--- a/llvm/lib/LTO/LTO.cpp
+++ b/llvm/lib/LTO/LTO.cpp
@@ -1422,7 +1422,7 @@ SmallVector<const char *> LTO::getRuntimeLibcallSymbols(const Triple &TT) {
for (RTLIB::LibcallImpl Impl : LibcallImpls) {
if (Impl != RTLIB::Unsupported)
- LibcallSymbols.push_back(Libcalls.getLibcallImplName(Impl).data());
+ LibcallSymbols.push_back(Libcalls.getLibcallImplName(Impl));
}
return LibcallSymbols;
diff --git a/llvm/lib/Object/IRSymtab.cpp b/llvm/lib/Object/IRSymtab.cpp
index 0043f02107fb8..0f194953787e6 100644
--- a/llvm/lib/Object/IRSymtab.cpp
+++ b/llvm/lib/Object/IRSymtab.cpp
@@ -46,7 +46,7 @@ static cl::opt<bool> DisableBitcodeVersionUpgrade(
"disable-bitcode-version-upgrade", cl::Hidden,
cl::desc("Disable automatic bitcode upgrade for version mismatch"));
-static constexpr StringLiteral PreservedSymbols[] = {
+static const char *PreservedSymbols[] = {
// There are global variables, so put it here instead of in
// RuntimeLibcalls.td.
// TODO: Are there similar such variables?
@@ -54,10 +54,6 @@ static constexpr StringLiteral PreservedSymbols[] = {
"__stack_chk_guard",
};
-static bool isPreservedGlobalVarName(StringRef Name) {
- return PreservedSymbols[0] == Name || PreservedSymbols[1] == Name;
-}
-
namespace {
const char *getExpectedProducerName() {
@@ -85,16 +81,12 @@ struct Builder {
// The StringTableBuilder does not create a copy of any strings added to it,
// so this provides somewhere to store any strings that we create.
Builder(SmallVector<char, 0> &Symtab, StringTableBuilder &StrtabBuilder,
- BumpPtrAllocator &Alloc, const Triple &TT)
- : Symtab(Symtab), StrtabBuilder(StrtabBuilder), Saver(Alloc), TT(TT),
- Libcalls(TT) {}
+ BumpPtrAllocator &Alloc)
+ : Symtab(Symtab), StrtabBuilder(StrtabBuilder), Saver(Alloc) {}
DenseMap<const Comdat *, int> ComdatMap;
Mangler Mang;
- const Triple &TT;
-
- // FIXME: This shouldn't be here.
- RTLIB::RuntimeLibcallsInfo Libcalls;
+ Triple TT;
std::vector<storage::Comdat> Comdats;
std::vector<storage::Module> Mods;
@@ -106,10 +98,6 @@ struct Builder {
std::vector<storage::Str> DependentLibraries;
- bool isPreservedLibFuncName(StringRef Name) {
- return Libcalls.getSupportedLibcallImpl(Name) != RTLIB::Unsupported;
- }
-
void setStr(storage::Str &S, StringRef Value) {
S.Offset = StrtabBuilder.add(Value);
S.Size = Value.size();
@@ -225,6 +213,19 @@ Expected<int> Builder::getComdatIndex(const Comdat *C, const Module *M) {
return P.first->second;
}
+static StringSet<> buildPreservedSymbolsSet(const Triple &TT) {
+ StringSet<> PreservedSymbolSet;
+ PreservedSymbolSet.insert(std::begin(PreservedSymbols),
+ std::end(PreservedSymbols));
+ // FIXME: Do we need to pass in ABI fields from TargetOptions?
+ RTLIB::RuntimeLibcallsInfo Libcalls(TT);
+ for (RTLIB::LibcallImpl Impl : Libcalls.getLibcallImpls()) {
+ if (Impl != RTLIB::Unsupported)
+ PreservedSymbolSet.insert(Libcalls.getLibcallImplName(Impl));
+ }
+ return PreservedSymbolSet;
+}
+
Error Builder::addSymbol(const ModuleSymbolTable &Msymtab,
const SmallPtrSet<GlobalValue *, 4> &Used,
ModuleSymbolTable::Symbol Msym) {
@@ -278,11 +279,13 @@ Error Builder::addSymbol(const ModuleSymbolTable &Msymtab,
return Error::success();
}
- StringRef GVName = GV->getName();
- setStr(Sym.IRName, GVName);
+ setStr(Sym.IRName, GV->getName());
+
+ static const StringSet<> PreservedSymbolsSet =
+ buildPreservedSymbolsSet(GV->getParent()->getTargetTriple());
+ bool IsPreservedSymbol = PreservedSymbolsSet.contains(GV->getName());
- if (Used.count(GV) || isPreservedLibFuncName(GVName) ||
- isPreservedGlobalVarName(GVName))
+ if (Used.count(GV) || IsPreservedSymbol)
Sym.Flags |= 1 << storage::Symbol::FB_used;
if (GV->isThreadLocal())
Sym.Flags |= 1 << storage::Symbol::FB_tls;
@@ -349,6 +352,7 @@ Error Builder::build(ArrayRef<Module *> IRMods) {
setStr(Hdr.Producer, kExpectedProducerName);
setStr(Hdr.TargetTriple, IRMods[0]->getTargetTriple().str());
setStr(Hdr.SourceFileName, IRMods[0]->getSourceFileName());
+ TT = IRMods[0]->getTargetTriple();
for (au...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/153864
More information about the llvm-commits
mailing list