@@ -1517,11 +1517,14 @@ class InProcessThinBackend : public ThinBackendProc {
1517
1517
}
1518
1518
};
1519
1519
1520
- // / This Backend will run ThinBackend process but throw away all the output from
1521
- // / the codegen. This class facilitates the first codegen round.
1522
- class NoOutputThinBackend : public InProcessThinBackend {
1520
+ // / This backend is utilized in the first round of a two-codegen round process.
1521
+ // / It first saves optimized bitcode files to disk before the codegen process
1522
+ // / begins. After codegen, it stores the resulting object files in a scratch
1523
+ // / buffer. Note the codegen data stored in the scratch buffer will be extracted
1524
+ // / and merged in the subsequent step.
1525
+ class FirstRoundThinBackend : public InProcessThinBackend {
1523
1526
public:
1524
- NoOutputThinBackend (
1527
+ FirstRoundThinBackend (
1525
1528
const Config &Conf, ModuleSummaryIndex &CombinedIndex,
1526
1529
ThreadPoolStrategy ThinLTOParallelism,
1527
1530
const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries,
@@ -1533,25 +1536,31 @@ class NoOutputThinBackend : public InProcessThinBackend {
1533
1536
return std::make_unique<CachedFileStream>(
1534
1537
std::make_unique<raw_svector_ostream>((*Allocation)[Task]));
1535
1538
},
1536
- FileCache (), nullptr , false , false ),
1539
+ FileCache (), /* OnWrite=*/ nullptr , /* ShouldEmitIndexFiles=*/ false ,
1540
+ /* ShouldEmitImportsFiles=*/ false ),
1537
1541
Scratch (std::move(Scratch)) {}
1538
1542
1539
1543
// / Scratch space for writing output during the codegen.
1540
1544
std::unique_ptr<std::vector<llvm::SmallString<0 >>> Scratch;
1541
1545
};
1542
1546
1543
- // / This Backend performs codegen on bitcode that was previously saved after
1544
- // / going through optimization. This class facilitates the second codegen round.
1545
- class OptimizedBitcodeThinBackend : public InProcessThinBackend {
1547
+ // / This backend operates in the second round of a two-codegen round process.
1548
+ // / It starts by reading the optimized bitcode files that were saved during the
1549
+ // / first round. The backend then executes the codegen only to further optimize
1550
+ // / the code, utilizing the codegen data merged from the first round. Finally,
1551
+ // / it writes the resulting object files as usual.
1552
+ class SecondRoundThinBackend : public InProcessThinBackend {
1546
1553
public:
1547
- OptimizedBitcodeThinBackend (
1554
+ SecondRoundThinBackend (
1548
1555
const Config &Conf, ModuleSummaryIndex &CombinedIndex,
1549
1556
ThreadPoolStrategy ThinLTOParallelism,
1550
1557
const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries,
1551
1558
AddStreamFn AddStream)
1552
1559
: InProcessThinBackend(Conf, CombinedIndex, ThinLTOParallelism,
1553
1560
ModuleToDefinedGVSummaries, AddStream, FileCache(),
1554
- nullptr , false , false ) {}
1561
+ /* OnWrite=*/ nullptr ,
1562
+ /* ShouldEmitIndexFiles=*/ false ,
1563
+ /* ShouldEmitImportsFiles=*/ false ) {}
1555
1564
1556
1565
virtual Error runThinLTOBackendThread (
1557
1566
AddStreamFn AddStream, FileCache Cache, unsigned Task, BitcodeModule BM,
@@ -1932,7 +1941,7 @@ Error LTO::runThinLTO(AddStreamFn AddStream, FileCache Cache,
1932
1941
// Create a scratch output to hold intermediate results.
1933
1942
auto Outputs =
1934
1943
std::make_unique<std::vector<llvm::SmallString<0 >>>(getMaxTasks ());
1935
- auto FirstRoundLTO = std::make_unique<NoOutputThinBackend >(
1944
+ auto FirstRoundLTO = std::make_unique<FirstRoundThinBackend >(
1936
1945
Conf, ThinLTO.CombinedIndex , llvm::heavyweight_hardware_concurrency (),
1937
1946
ModuleToDefinedGVSummaries, std::move (Outputs));
1938
1947
// First round: Run optimization and code generation with a scratch output.
@@ -1946,7 +1955,7 @@ Error LTO::runThinLTO(AddStreamFn AddStream, FileCache Cache,
1946
1955
1947
1956
// Second round: Run code generation by reading IRs.
1948
1957
std::unique_ptr<ThinBackendProc> SecondRoundLTO =
1949
- std::make_unique<OptimizedBitcodeThinBackend >(
1958
+ std::make_unique<SecondRoundThinBackend >(
1950
1959
Conf, ThinLTO.CombinedIndex , llvm::heavyweight_hardware_concurrency (),
1951
1960
ModuleToDefinedGVSummaries, AddStream);
1952
1961
Error E = RunBackends (SecondRoundLTO.get ());
0 commit comments