@@ -632,25 +632,30 @@ def execute_build_pipeline(timer: Timer, pipeline: Pipeline, final_build_args: L
632
632
env ["LDFLAGS" ] = "-Wl,-q"
633
633
634
634
# Stage 3: Build PGO optimized rustc + PGO optimized LLVM
635
- # FIXME: Because "dist" is run here, I think we will end up packaging the libLLVM.so
636
- # at this point, so the optimization below won't apply to the shipped artifacts.
637
635
with timer .stage ("Build rustc (rustc PGO use, LLVM PGO use)" ):
638
- cmd (final_build_args , env )
636
+ build_rustc (pipeline , [
637
+ "--llvm-profile-use" , pipeline .llvm_profile_merged_file (),
638
+ "--rust-profile-use" , pipeline .rustc_profile_merged_file (),
639
+ ], env )
639
640
640
641
# Stage 4: BOLT optimize LLVM.
641
642
if pipeline .supports_bolt ():
642
- lib_llvm = pipeline .stage2_lib_llvm ()
643
+ # Instrument the stage2 libLLVM...
644
+ stage2_lib_llvm = pipeline .stage2_lib_llvm ()
645
+ # ...and write the optimized one into the LLVM build directory,
646
+ # because we'll copy it from there when reassembling the stage2 compiler.
647
+ build_lib_llvm = pipeline .build_artifacts () / "llvm" / "lib" / stage2_lib_llvm .name
643
648
644
649
# Back up the original libLLVM shared object.
645
650
orig_lib_llvm = pipeline .opt_artifacts () / "libLLVM.orig"
646
- shutil .move (lib_llvm , orig_lib_llvm )
651
+ shutil .move (stage2_lib_llvm , orig_lib_llvm )
647
652
648
653
with timer .stage ("Bolt instrument LLVM" ):
649
654
cmd ([
650
655
"llvm-bolt" , "-instrument" , orig_lib_llvm ,
651
656
# Make sure that each process will write its profiles into a separate file
652
657
"--instrumentation-file-append-pid" ,
653
- "-o" , lib_llvm
658
+ "-o" , stage2_lib_llvm
654
659
])
655
660
656
661
with timer .stage ("Gather profiles (LLVM BOLT)" ):
@@ -660,7 +665,7 @@ def execute_build_pipeline(timer: Timer, pipeline: Pipeline, final_build_args: L
660
665
cmd ([
661
666
"llvm-bolt" , orig_lib_llvm ,
662
667
"-data" , pipeline .llvm_bolt_profile_merged_file (),
663
- "-o" , lib_llvm ,
668
+ "-o" , build_lib_llvm ,
664
669
# Reorder basic blocks within functions
665
670
"-reorder-blocks=ext-tsp" ,
666
671
# Reorder functions within the binary
@@ -682,6 +687,11 @@ def execute_build_pipeline(timer: Timer, pipeline: Pipeline, final_build_args: L
682
687
"-dyno-stats" ,
683
688
])
684
689
690
+ # Stage 5: Execute the orinal dist command.
691
+ # This is supposed to reuse the already built rustc and LLVM.
692
+ with timer .stage ("Dist rustc" ):
693
+ cmd (final_build_args , env )
694
+
685
695
if __name__ == "__main__" :
686
696
logging .basicConfig (
687
697
level = logging .DEBUG ,
0 commit comments