@@ -632,25 +632,30 @@ def execute_build_pipeline(timer: Timer, pipeline: Pipeline, final_build_args: L
632632 env ["LDFLAGS" ] = "-Wl,-q"
633633
634634 # 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.
637635 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 )
639640
640641 # Stage 4: BOLT optimize LLVM.
641642 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
643648
644649 # Back up the original libLLVM shared object.
645650 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 )
647652
648653 with timer .stage ("Bolt instrument LLVM" ):
649654 cmd ([
650655 "llvm-bolt" , "-instrument" , orig_lib_llvm ,
651656 # Make sure that each process will write its profiles into a separate file
652657 "--instrumentation-file-append-pid" ,
653- "-o" , lib_llvm
658+ "-o" , stage2_lib_llvm
654659 ])
655660
656661 with timer .stage ("Gather profiles (LLVM BOLT)" ):
@@ -660,7 +665,7 @@ def execute_build_pipeline(timer: Timer, pipeline: Pipeline, final_build_args: L
660665 cmd ([
661666 "llvm-bolt" , orig_lib_llvm ,
662667 "-data" , pipeline .llvm_bolt_profile_merged_file (),
663- "-o" , lib_llvm ,
668+ "-o" , build_lib_llvm ,
664669 # Reorder basic blocks within functions
665670 "-reorder-blocks=ext-tsp" ,
666671 # Reorder functions within the binary
@@ -682,6 +687,11 @@ def execute_build_pipeline(timer: Timer, pipeline: Pipeline, final_build_args: L
682687 "-dyno-stats" ,
683688 ])
684689
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+
685695if __name__ == "__main__" :
686696 logging .basicConfig (
687697 level = logging .DEBUG ,
0 commit comments