Skip to content

Commit a961210

Browse files
committed
Revert "RuntimeLibcalls: Add methods to recognize libcall names (#149001)"
This reverts commit 45477ad. This causes a significant LTO compile-time regression.
1 parent 64a0478 commit a961210

File tree

5 files changed

+24
-100
lines changed

5 files changed

+24
-100
lines changed

llvm/include/llvm/ADT/StringTable.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,6 @@ class StringTable {
118118
constexpr Iterator(const Iterator &RHS) = default;
119119
constexpr Iterator(Iterator &&RHS) = default;
120120

121-
Iterator &operator=(const Iterator &RHS) {
122-
Table = RHS.Table;
123-
O = RHS.O;
124-
S = RHS.S;
125-
return *this;
126-
}
127-
128121
bool operator==(const Iterator &RHS) const {
129122
assert(Table == RHS.Table && "Compared iterators for unrelated tables!");
130123
return O == RHS.O;
@@ -139,8 +132,6 @@ class StringTable {
139132
O = O.value() + (*Table)[O].size() + 1;
140133
return *this;
141134
}
142-
143-
Offset offset() const { return O; }
144135
};
145136

146137
constexpr Iterator begin() const { return Iterator(*this, 0); }

llvm/include/llvm/IR/RuntimeLibcalls.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,6 @@ struct RuntimeLibcallsInfo {
132132
return ImplToLibcall[Impl];
133133
}
134134

135-
/// Check if this is valid libcall for the current module, otherwise
136-
/// RTLIB::Unsupported.
137-
RTLIB::LibcallImpl getSupportedLibcallImpl(StringRef FuncName) const;
138-
139135
private:
140136
static const RTLIB::LibcallImpl
141137
DefaultLibcallImpls[RTLIB::UNKNOWN_LIBCALL + 1];
@@ -160,14 +156,6 @@ struct RuntimeLibcallsInfo {
160156
/// Map from a concrete LibcallImpl implementation to its RTLIB::Libcall kind.
161157
LLVM_ABI static const RTLIB::Libcall ImplToLibcall[RTLIB::NumLibcallImpls];
162158

163-
/// Check if a function name is a recognized runtime call of any kind. This
164-
/// does not consider if this call is available for any current compilation,
165-
/// just that it is a known call somewhere. This returns the set of all
166-
/// LibcallImpls which match the name; multiple implementations with the same
167-
/// name may exist but differ in interpretation based on the target context.
168-
LLVM_ABI static iterator_range<ArrayRef<uint16_t>::const_iterator>
169-
getRecognizedLibcallImpls(StringRef FuncName);
170-
171159
static bool darwinHasSinCosStret(const Triple &TT) {
172160
if (!TT.isOSDarwin())
173161
return false;

llvm/lib/IR/RuntimeLibcalls.cpp

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -135,51 +135,6 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT,
135135
}
136136
}
137137

138-
RTLIB::LibcallImpl
139-
RuntimeLibcallsInfo::getSupportedLibcallImpl(StringRef FuncName) const {
140-
const ArrayRef<uint16_t> RuntimeLibcallNameOffsets(
141-
RuntimeLibcallNameOffsetTable);
142-
143-
iterator_range<ArrayRef<uint16_t>::const_iterator> Range =
144-
getRecognizedLibcallImpls(FuncName);
145-
146-
for (auto I = Range.begin(); I != Range.end(); ++I) {
147-
RTLIB::LibcallImpl Impl =
148-
static_cast<RTLIB::LibcallImpl>(I - RuntimeLibcallNameOffsets.begin());
149-
150-
// FIXME: This should not depend on looking up ImplToLibcall, only the list
151-
// of libcalls for the module.
152-
RTLIB::LibcallImpl Recognized = LibcallImpls[ImplToLibcall[Impl]];
153-
if (Recognized != RTLIB::Unsupported)
154-
return Recognized;
155-
}
156-
157-
return RTLIB::Unsupported;
158-
}
159-
160-
iterator_range<ArrayRef<uint16_t>::const_iterator>
161-
RuntimeLibcallsInfo::getRecognizedLibcallImpls(StringRef FuncName) {
162-
StringTable::Iterator It = lower_bound(RuntimeLibcallImplNameTable, FuncName);
163-
if (It == RuntimeLibcallImplNameTable.end() || *It != FuncName)
164-
return iterator_range(ArrayRef<uint16_t>());
165-
166-
uint16_t IndexVal = It.offset().value();
167-
const ArrayRef<uint16_t> TableRef(RuntimeLibcallNameOffsetTable);
168-
169-
ArrayRef<uint16_t>::const_iterator E = TableRef.end();
170-
ArrayRef<uint16_t>::const_iterator EntriesBegin =
171-
std::lower_bound(TableRef.begin(), E, IndexVal);
172-
ArrayRef<uint16_t>::const_iterator EntriesEnd = EntriesBegin;
173-
174-
while (EntriesEnd != E && *EntriesEnd == IndexVal)
175-
++EntriesEnd;
176-
177-
assert(EntriesBegin != E &&
178-
"libcall found in name table but not offset table");
179-
180-
return make_range(EntriesBegin, EntriesEnd);
181-
}
182-
183138
bool RuntimeLibcallsInfo::darwinHasExp10(const Triple &TT) {
184139
switch (TT.getOS()) {
185140
case Triple::MacOSX:

llvm/lib/Object/IRSymtab.cpp

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,6 @@ static const char *PreservedSymbols[] = {
5454
"__stack_chk_guard",
5555
};
5656

57-
static bool isPreservedGlobalVarName(StringRef Name) {
58-
return StringRef(PreservedSymbols[0]) == Name ||
59-
StringRef(PreservedSymbols[1]) == Name;
60-
}
61-
6257
namespace {
6358

6459
const char *getExpectedProducerName() {
@@ -86,16 +81,12 @@ struct Builder {
8681
// The StringTableBuilder does not create a copy of any strings added to it,
8782
// so this provides somewhere to store any strings that we create.
8883
Builder(SmallVector<char, 0> &Symtab, StringTableBuilder &StrtabBuilder,
89-
BumpPtrAllocator &Alloc, const Triple &TT)
90-
: Symtab(Symtab), StrtabBuilder(StrtabBuilder), Saver(Alloc), TT(TT),
91-
Libcalls(TT) {}
84+
BumpPtrAllocator &Alloc)
85+
: Symtab(Symtab), StrtabBuilder(StrtabBuilder), Saver(Alloc) {}
9286

9387
DenseMap<const Comdat *, int> ComdatMap;
9488
Mangler Mang;
95-
const Triple &TT;
96-
97-
// FIXME: This shouldn't be here.
98-
RTLIB::RuntimeLibcallsInfo Libcalls;
89+
Triple TT;
9990

10091
std::vector<storage::Comdat> Comdats;
10192
std::vector<storage::Module> Mods;
@@ -107,10 +98,6 @@ struct Builder {
10798

10899
std::vector<storage::Str> DependentLibraries;
109100

110-
bool isPreservedLibFuncName(StringRef Name) {
111-
return Libcalls.getSupportedLibcallImpl(Name) != RTLIB::Unsupported;
112-
}
113-
114101
void setStr(storage::Str &S, StringRef Value) {
115102
S.Offset = StrtabBuilder.add(Value);
116103
S.Size = Value.size();
@@ -226,6 +213,18 @@ Expected<int> Builder::getComdatIndex(const Comdat *C, const Module *M) {
226213
return P.first->second;
227214
}
228215

216+
static DenseSet<StringRef> buildPreservedSymbolsSet(const Triple &TT) {
217+
DenseSet<StringRef> PreservedSymbolSet(std::begin(PreservedSymbols),
218+
std::end(PreservedSymbols));
219+
// FIXME: Do we need to pass in ABI fields from TargetOptions?
220+
RTLIB::RuntimeLibcallsInfo Libcalls(TT);
221+
for (RTLIB::LibcallImpl Impl : Libcalls.getLibcallImpls()) {
222+
if (Impl != RTLIB::Unsupported)
223+
PreservedSymbolSet.insert(Libcalls.getLibcallImplName(Impl));
224+
}
225+
return PreservedSymbolSet;
226+
}
227+
229228
Error Builder::addSymbol(const ModuleSymbolTable &Msymtab,
230229
const SmallPtrSet<GlobalValue *, 4> &Used,
231230
ModuleSymbolTable::Symbol Msym) {
@@ -279,11 +278,13 @@ Error Builder::addSymbol(const ModuleSymbolTable &Msymtab,
279278
return Error::success();
280279
}
281280

282-
StringRef GVName = GV->getName();
283-
setStr(Sym.IRName, GVName);
281+
setStr(Sym.IRName, GV->getName());
282+
283+
static const DenseSet<StringRef> PreservedSymbolsSet =
284+
buildPreservedSymbolsSet(GV->getParent()->getTargetTriple());
285+
bool IsPreservedSymbol = PreservedSymbolsSet.contains(GV->getName());
284286

285-
if (Used.count(GV) || isPreservedLibFuncName(GVName) ||
286-
isPreservedGlobalVarName(GVName))
287+
if (Used.count(GV) || IsPreservedSymbol)
287288
Sym.Flags |= 1 << storage::Symbol::FB_used;
288289
if (GV->isThreadLocal())
289290
Sym.Flags |= 1 << storage::Symbol::FB_tls;
@@ -350,6 +351,7 @@ Error Builder::build(ArrayRef<Module *> IRMods) {
350351
setStr(Hdr.Producer, kExpectedProducerName);
351352
setStr(Hdr.TargetTriple, IRMods[0]->getTargetTriple().str());
352353
setStr(Hdr.SourceFileName, IRMods[0]->getSourceFileName());
354+
TT = IRMods[0]->getTargetTriple();
353355

354356
for (auto *M : IRMods)
355357
if (Error Err = addModule(M))
@@ -375,8 +377,7 @@ Error Builder::build(ArrayRef<Module *> IRMods) {
375377
Error irsymtab::build(ArrayRef<Module *> Mods, SmallVector<char, 0> &Symtab,
376378
StringTableBuilder &StrtabBuilder,
377379
BumpPtrAllocator &Alloc) {
378-
const Triple &TT = Mods[0]->getTargetTriple();
379-
return Builder(Symtab, StrtabBuilder, Alloc, TT).build(Mods);
380+
return Builder(Symtab, StrtabBuilder, Alloc).build(Mods);
380381
}
381382

382383
// Upgrade a vector of bitcode modules created by an old version of LLVM by

llvm/utils/TableGen/Basic/RuntimeLibcallsEmitter.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -236,19 +236,8 @@ class RuntimeLibcallEmitter {
236236
for (RuntimeLibcall &LibCall : RuntimeLibcallDefList)
237237
Def2RuntimeLibcall[LibCall.getDef()] = &LibCall;
238238

239-
ArrayRef<const Record *> AllRuntimeLibcallImplsRaw =
239+
ArrayRef<const Record *> AllRuntimeLibcallImpls =
240240
Records.getAllDerivedDefinitions("RuntimeLibcallImpl");
241-
242-
SmallVector<const Record *, 1024> AllRuntimeLibcallImpls(
243-
AllRuntimeLibcallImplsRaw);
244-
245-
// Sort by libcall impl name, not the enum name. This keeps the order
246-
// suitable for using the name table for libcall recognition binary search.
247-
llvm::sort(AllRuntimeLibcallImpls, [](const Record *A, const Record *B) {
248-
return A->getValueAsString("LibCallFuncName") <
249-
B->getValueAsString("LibCallFuncName");
250-
});
251-
252241
RuntimeLibcallImplDefList.reserve(AllRuntimeLibcallImpls.size());
253242

254243
size_t LibCallImplEnumVal = 1;

0 commit comments

Comments
 (0)