Skip to content

Commit 3cda5ce

Browse files
committed
Address comments from NuriAmari
1 parent a71ef14 commit 3cda5ce

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

llvm/lib/CGData/CodeGenData.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ void saveModuleForTwoRounds(const Module &TheModule, unsigned Task) {
245245
if (EC)
246246
report_fatal_error(Twine("Failed to open ") + Path +
247247
" to save optimized bitcode: " + EC.message());
248-
WriteBitcodeToFile(TheModule, OS, /* ShouldPreserveUseListOrder */ true);
248+
WriteBitcodeToFile(TheModule, OS, /*ShouldPreserveUseListOrder=*/true);
249249
}
250250

251251
std::unique_ptr<Module> loadModuleForTwoRounds(BitcodeModule &OrigModule,
@@ -259,7 +259,7 @@ std::unique_ptr<Module> loadModuleForTwoRounds(BitcodeModule &OrigModule,
259259
" to load optimized bitcode: " + EC.message());
260260

261261
std::unique_ptr<MemoryBuffer> FileBuffer = std::move(*FileOrError);
262-
auto RestoredModule = llvm::parseBitcodeFile(*FileBuffer, Context);
262+
auto RestoredModule = parseBitcodeFile(*FileBuffer, Context);
263263
if (!RestoredModule)
264264
report_fatal_error(Twine("Failed to parse optimized bitcode loaded from ") +
265265
Path + "\n");

llvm/lib/LTO/LTO.cpp

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,11 +1563,14 @@ class InProcessThinBackend : public ThinBackendProc {
15631563
}
15641564
};
15651565

1566-
/// This Backend will run ThinBackend process but throw away all the output from
1567-
/// the codegen. This class facilitates the first codegen round.
1568-
class NoOutputThinBackend : public InProcessThinBackend {
1566+
/// This backend is utilized in the first round of a two-codegen round process.
1567+
/// It first saves optimized bitcode files to disk before the codegen process
1568+
/// begins. After codegen, it stores the resulting object files in a scratch
1569+
/// buffer. Note the codegen data stored in the scratch buffer will be extracted
1570+
/// and merged in the subsequent step.
1571+
class FirstRoundThinBackend : public InProcessThinBackend {
15691572
public:
1570-
NoOutputThinBackend(
1573+
FirstRoundThinBackend(
15711574
const Config &Conf, ModuleSummaryIndex &CombinedIndex,
15721575
ThreadPoolStrategy ThinLTOParallelism,
15731576
const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries,
@@ -1579,25 +1582,31 @@ class NoOutputThinBackend : public InProcessThinBackend {
15791582
return std::make_unique<CachedFileStream>(
15801583
std::make_unique<raw_svector_ostream>((*Allocation)[Task]));
15811584
},
1582-
FileCache(), nullptr, false, false),
1585+
FileCache(), /*OnWrite=*/nullptr, /*ShouldEmitIndexFiles=*/false,
1586+
/*ShouldEmitImportsFiles=*/false),
15831587
Scratch(std::move(Scratch)) {}
15841588

15851589
/// Scratch space for writing output during the codegen.
15861590
std::unique_ptr<std::vector<llvm::SmallString<0>>> Scratch;
15871591
};
15881592

1589-
/// This Backend performs codegen on bitcode that was previously saved after
1590-
/// going through optimization. This class facilitates the second codegen round.
1591-
class OptimizedBitcodeThinBackend : public InProcessThinBackend {
1593+
/// This backend operates in the second round of a two-codegen round process.
1594+
/// It starts by reading the optimized bitcode files that were saved during the
1595+
/// first round. The backend then executes the codegen only to further optimize
1596+
/// the code, utilizing the codegen data merged from the first round. Finally,
1597+
/// it writes the resulting object files as usual.
1598+
class SecondRoundThinBackend : public InProcessThinBackend {
15921599
public:
1593-
OptimizedBitcodeThinBackend(
1600+
SecondRoundThinBackend(
15941601
const Config &Conf, ModuleSummaryIndex &CombinedIndex,
15951602
ThreadPoolStrategy ThinLTOParallelism,
15961603
const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries,
15971604
AddStreamFn AddStream)
15981605
: InProcessThinBackend(Conf, CombinedIndex, ThinLTOParallelism,
15991606
ModuleToDefinedGVSummaries, AddStream, FileCache(),
1600-
nullptr, false, false) {}
1607+
/*OnWrite=*/nullptr,
1608+
/*ShouldEmitIndexFiles=*/false,
1609+
/*ShouldEmitImportsFiles=*/false) {}
16011610

16021611
virtual Error runThinLTOBackendThread(
16031612
AddStreamFn AddStream, FileCache Cache, unsigned Task, BitcodeModule BM,
@@ -1956,7 +1965,7 @@ Error LTO::runThinLTO(AddStreamFn AddStream, FileCache Cache,
19561965
// Create a scratch output to hold intermediate results.
19571966
auto Outputs =
19581967
std::make_unique<std::vector<llvm::SmallString<0>>>(getMaxTasks());
1959-
auto FirstRoundLTO = std::make_unique<NoOutputThinBackend>(
1968+
auto FirstRoundLTO = std::make_unique<FirstRoundThinBackend>(
19601969
Conf, ThinLTO.CombinedIndex, llvm::heavyweight_hardware_concurrency(),
19611970
ModuleToDefinedGVSummaries, std::move(Outputs));
19621971
// First round: Run optimization and code generation with a scratch output.
@@ -1970,7 +1979,7 @@ Error LTO::runThinLTO(AddStreamFn AddStream, FileCache Cache,
19701979

19711980
// Second round: Run code generation by reading IRs.
19721981
std::unique_ptr<ThinBackendProc> SecondRoundLTO =
1973-
std::make_unique<OptimizedBitcodeThinBackend>(
1982+
std::make_unique<SecondRoundThinBackend>(
19741983
Conf, ThinLTO.CombinedIndex, llvm::heavyweight_hardware_concurrency(),
19751984
ModuleToDefinedGVSummaries, AddStream);
19761985
Error E = RunBackends(SecondRoundLTO.get());

llvm/lib/LTO/LTOBackend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ Error lto::thinBackend(const Config &Conf, unsigned Task, AddStreamFn AddStream,
611611
// Save the current module before the first codegen round.
612612
// Note that the second codegen round runs only `codegen()` without
613613
// running `opt()`. We're not reaching here as it's bailed out earlier
614-
// with CodeGenOnly which has been set in `OptimizedBitcodeThinBackend`.
614+
// with `CodeGenOnly` which has been set in `SecondRoundThinBackend`.
615615
if (CodeGenDataThinLTOTwoRounds)
616616
cgdata::saveModuleForTwoRounds(Mod, Task);
617617

0 commit comments

Comments
 (0)