@@ -1019,24 +1019,40 @@ void CodeGenAction::runOptimizationPipeline(llvm::raw_pwrite_stream &os) {
10191019
10201020 // Create the pass manager.
10211021 llvm::ModulePassManager mpm;
1022- if (opts. PrepareForFatLTO ) {
1023- // The module summary should be emitted by default for regular LTO
1024- // except for ld64 targets.
1025- bool emitSummary = opts.PrepareForThinLTO || opts. PrepareForFullLTO ||
1026- triple. getVendor () != llvm::Triple::Apple;
1022+ // The module summary should be emitted by default for regular LTO
1023+ // except for ld64 targets.
1024+ bool emitSummary =
1025+ opts.PrepareForFullLTO && (triple. getVendor () != llvm::Triple::Apple);
1026+ if (opts. PrepareForFatLTO )
10271027 mpm = pb.buildFatLTODefaultPipeline (level, opts.PrepareForThinLTO ,
10281028 emitSummary);
1029- } else if (opts.PrepareForFullLTO )
1029+ else if (opts.PrepareForFullLTO )
10301030 mpm = pb.buildLTOPreLinkDefaultPipeline (level);
10311031 else if (opts.PrepareForThinLTO )
10321032 mpm = pb.buildThinLTOPreLinkDefaultPipeline (level);
10331033 else
10341034 mpm = pb.buildPerModuleDefaultPipeline (level);
10351035
1036- if (action == BackendActionTy::Backend_EmitBC)
1037- mpm.addPass (llvm::BitcodeWriterPass (os));
1038- else if (action == BackendActionTy::Backend_EmitLL)
1039- mpm.addPass (llvm::PrintModulePass (os));
1036+ if (action == BackendActionTy::Backend_EmitBC ||
1037+ action == BackendActionTy::Backend_EmitLL || opts.PrepareForFatLTO ) {
1038+ if (opts.PrepareForThinLTO ) {
1039+ // TODO: ThinLTO module summary support is yet to be enabled.
1040+ if (action == BackendActionTy::Backend_EmitBC)
1041+ mpm.addPass (llvm::BitcodeWriterPass (os));
1042+ else if (action == BackendActionTy::Backend_EmitLL)
1043+ mpm.addPass (llvm::PrintModulePass (os));
1044+ } else {
1045+ if (emitSummary && !llvmModule->getModuleFlag (" ThinLTO" ))
1046+ llvmModule->addModuleFlag (llvm::Module::Error, " ThinLTO" , uint32_t (0 ));
1047+ if (action == BackendActionTy::Backend_EmitBC)
1048+ mpm.addPass (llvm::BitcodeWriterPass (
1049+ os, /* ShouldPreserveUseListOrder=*/ false , emitSummary));
1050+ else if (action == BackendActionTy::Backend_EmitLL)
1051+ mpm.addPass (llvm::PrintModulePass (os, /* Banner=*/ " " ,
1052+ /* ShouldPreserveUseListOrder=*/ false ,
1053+ emitSummary));
1054+ }
1055+ }
10401056
10411057 // FIXME: This should eventually be replaced by a first-class driver option.
10421058 // This should be done for both flang and clang simultaneously.
0 commit comments