Skip to content

Commit 05a358c

Browse files
[ThinLTO] Fix ThinLTOCodegenerator to export llvm.used symbols
Summary: Reapply r357931 with fixes to ThinLTO testcases and llvm-lto tool. ThinLTOCodeGenerator currently does not preserve llvm.used symbols and it can internalize them. In order to pass the necessary information to the legacy ThinLTOCodeGenerator, the input to the code generator is rewritten to be based on lto::InputFile. Now ThinLTO using the legacy LTO API will requires data layout in Module. "internalize" thinlto action in llvm-lto is updated to run both "promote" and "internalize" with the same configuration as ThinLTOCodeGenerator. The old "promote" + "internalize" option does not produce the same output as ThinLTOCodeGenerator. This fixes: PR41236 rdar://problem/49293439 Reviewers: tejohnson, pcc, kromanova, dexonsmith Reviewed By: tejohnson Subscribers: ormris, bd1976llvm, mehdi_amini, inglorion, eraman, hiraditya, jkorous, dexonsmith, arphaman, dang, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D60421 llvm-svn: 358601
1 parent 8867971 commit 05a358c

26 files changed

+224
-109
lines changed

llvm/include/llvm/LTO/LTO.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ class InputFile {
131131
using irsymtab::Symbol::isWeak;
132132
using irsymtab::Symbol::isIndirect;
133133
using irsymtab::Symbol::getName;
134+
using irsymtab::Symbol::getIRName;
134135
using irsymtab::Symbol::getVisibility;
135136
using irsymtab::Symbol::canBeOmittedFromSymbolTable;
136137
using irsymtab::Symbol::isTLS;
@@ -161,6 +162,9 @@ class InputFile {
161162
// Returns a table with all the comdats used by this file.
162163
ArrayRef<StringRef> getComdatTable() const { return ComdatTable; }
163164

165+
// Returns the only BitcodeModule from InputFile.
166+
BitcodeModule &getSingleBitcodeModule();
167+
164168
private:
165169
ArrayRef<Symbol> module_symbols(unsigned I) const {
166170
const auto &Indices = ModuleSymIndices[I];

llvm/include/llvm/LTO/legacy/ThinLTOCodeGenerator.h

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "llvm/ADT/StringSet.h"
2020
#include "llvm/ADT/Triple.h"
2121
#include "llvm/IR/ModuleSummaryIndex.h"
22+
#include "llvm/LTO/LTO.h"
2223
#include "llvm/Support/CachePruning.h"
2324
#include "llvm/Support/CodeGen.h"
2425
#include "llvm/Support/MemoryBuffer.h"
@@ -31,23 +32,6 @@ class StringRef;
3132
class LLVMContext;
3233
class TargetMachine;
3334

34-
/// Wrapper around MemoryBufferRef, owning the identifier
35-
class ThinLTOBuffer {
36-
std::string OwnedIdentifier;
37-
StringRef Buffer;
38-
39-
public:
40-
ThinLTOBuffer(StringRef Buffer, StringRef Identifier)
41-
: OwnedIdentifier(Identifier), Buffer(Buffer) {}
42-
43-
MemoryBufferRef getMemBuffer() const {
44-
return MemoryBufferRef(Buffer,
45-
{OwnedIdentifier.c_str(), OwnedIdentifier.size()});
46-
}
47-
StringRef getBuffer() const { return Buffer; }
48-
StringRef getBufferIdentifier() const { return OwnedIdentifier; }
49-
};
50-
5135
/// Helper to gather options relevant to the target machine creation
5236
struct TargetMachineBuilder {
5337
Triple TheTriple;
@@ -267,31 +251,36 @@ class ThinLTOCodeGenerator {
267251
* and additionally resolve weak and linkonce symbols.
268252
* Index is updated to reflect linkage changes from weak resolution.
269253
*/
270-
void promote(Module &Module, ModuleSummaryIndex &Index);
254+
void promote(Module &Module, ModuleSummaryIndex &Index,
255+
const lto::InputFile &File);
271256

272257
/**
273258
* Compute and emit the imported files for module at \p ModulePath.
274259
*/
275260
void emitImports(Module &Module, StringRef OutputName,
276-
ModuleSummaryIndex &Index);
261+
ModuleSummaryIndex &Index,
262+
const lto::InputFile &File);
277263

278264
/**
279265
* Perform cross-module importing for the module identified by
280266
* ModuleIdentifier.
281267
*/
282-
void crossModuleImport(Module &Module, ModuleSummaryIndex &Index);
268+
void crossModuleImport(Module &Module, ModuleSummaryIndex &Index,
269+
const lto::InputFile &File);
283270

284271
/**
285272
* Compute the list of summaries needed for importing into module.
286273
*/
287274
void gatherImportedSummariesForModule(
288275
Module &Module, ModuleSummaryIndex &Index,
289-
std::map<std::string, GVSummaryMapTy> &ModuleToSummariesForIndex);
276+
std::map<std::string, GVSummaryMapTy> &ModuleToSummariesForIndex,
277+
const lto::InputFile &File);
290278

291279
/**
292280
* Perform internalization. Index is updated to reflect linkage changes.
293281
*/
294-
void internalize(Module &Module, ModuleSummaryIndex &Index);
282+
void internalize(Module &Module, ModuleSummaryIndex &Index,
283+
const lto::InputFile &File);
295284

296285
/**
297286
* Perform post-importing ThinLTO optimizations.
@@ -313,7 +302,7 @@ class ThinLTOCodeGenerator {
313302

314303
/// Vector holding the input buffers containing the bitcode modules to
315304
/// process.
316-
std::vector<ThinLTOBuffer> Modules;
305+
std::vector<std::unique_ptr<lto::InputFile>> Modules;
317306

318307
/// Set of symbols that need to be preserved outside of the set of bitcode
319308
/// files.

llvm/lib/LTO/LTO.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,11 @@ StringRef InputFile::getName() const {
420420
return Mods[0].getModuleIdentifier();
421421
}
422422

423+
BitcodeModule &InputFile::getSingleBitcodeModule() {
424+
assert(Mods.size() == 1 && "Expect only one bitcode module");
425+
return Mods[0];
426+
}
427+
423428
LTO::RegularLTOState::RegularLTOState(unsigned ParallelCodeGenParallelismLevel,
424429
Config &Conf)
425430
: ParallelCodeGenParallelismLevel(ParallelCodeGenParallelismLevel),

0 commit comments

Comments
 (0)