@@ -1563,11 +1563,14 @@ class InProcessThinBackend : public ThinBackendProc {
1563
1563
}
1564
1564
};
1565
1565
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 {
1569
1572
public:
1570
- NoOutputThinBackend (
1573
+ FirstRoundThinBackend (
1571
1574
const Config &Conf, ModuleSummaryIndex &CombinedIndex,
1572
1575
ThreadPoolStrategy ThinLTOParallelism,
1573
1576
const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries,
@@ -1579,25 +1582,31 @@ class NoOutputThinBackend : public InProcessThinBackend {
1579
1582
return std::make_unique<CachedFileStream>(
1580
1583
std::make_unique<raw_svector_ostream>((*Allocation)[Task]));
1581
1584
},
1582
- FileCache (), nullptr , false , false ),
1585
+ FileCache (), /* OnWrite=*/ nullptr , /* ShouldEmitIndexFiles=*/ false ,
1586
+ /* ShouldEmitImportsFiles=*/ false ),
1583
1587
Scratch (std::move(Scratch)) {}
1584
1588
1585
1589
// / Scratch space for writing output during the codegen.
1586
1590
std::unique_ptr<std::vector<llvm::SmallString<0 >>> Scratch;
1587
1591
};
1588
1592
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 {
1592
1599
public:
1593
- OptimizedBitcodeThinBackend (
1600
+ SecondRoundThinBackend (
1594
1601
const Config &Conf, ModuleSummaryIndex &CombinedIndex,
1595
1602
ThreadPoolStrategy ThinLTOParallelism,
1596
1603
const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries,
1597
1604
AddStreamFn AddStream)
1598
1605
: InProcessThinBackend(Conf, CombinedIndex, ThinLTOParallelism,
1599
1606
ModuleToDefinedGVSummaries, AddStream, FileCache(),
1600
- nullptr , false , false ) {}
1607
+ /* OnWrite=*/ nullptr ,
1608
+ /* ShouldEmitIndexFiles=*/ false ,
1609
+ /* ShouldEmitImportsFiles=*/ false ) {}
1601
1610
1602
1611
virtual Error runThinLTOBackendThread (
1603
1612
AddStreamFn AddStream, FileCache Cache, unsigned Task, BitcodeModule BM,
@@ -1956,7 +1965,7 @@ Error LTO::runThinLTO(AddStreamFn AddStream, FileCache Cache,
1956
1965
// Create a scratch output to hold intermediate results.
1957
1966
auto Outputs =
1958
1967
std::make_unique<std::vector<llvm::SmallString<0 >>>(getMaxTasks ());
1959
- auto FirstRoundLTO = std::make_unique<NoOutputThinBackend >(
1968
+ auto FirstRoundLTO = std::make_unique<FirstRoundThinBackend >(
1960
1969
Conf, ThinLTO.CombinedIndex , llvm::heavyweight_hardware_concurrency (),
1961
1970
ModuleToDefinedGVSummaries, std::move (Outputs));
1962
1971
// First round: Run optimization and code generation with a scratch output.
@@ -1970,7 +1979,7 @@ Error LTO::runThinLTO(AddStreamFn AddStream, FileCache Cache,
1970
1979
1971
1980
// Second round: Run code generation by reading IRs.
1972
1981
std::unique_ptr<ThinBackendProc> SecondRoundLTO =
1973
- std::make_unique<OptimizedBitcodeThinBackend >(
1982
+ std::make_unique<SecondRoundThinBackend >(
1974
1983
Conf, ThinLTO.CombinedIndex , llvm::heavyweight_hardware_concurrency (),
1975
1984
ModuleToDefinedGVSummaries, AddStream);
1976
1985
Error E = RunBackends (SecondRoundLTO.get ());
0 commit comments