@@ -186,6 +186,14 @@ class EmitAssemblyHelper {
186186 TargetTriple.getVendor () != llvm::Triple::Apple;
187187 }
188188
189+ // / Check whether we should emit a flag for UnifiedLTO.
190+ // / The UnifiedLTO module flag should be set when UnifiedLTO is enabled for
191+ // / ThinLTO or Full LTO with module summaries.
192+ bool shouldEmitUnifiedLTOModueFlag () const {
193+ return CodeGenOpts.UnifiedLTO &&
194+ (CodeGenOpts.PrepareForThinLTO || shouldEmitRegularLTOSummary ());
195+ }
196+
189197public:
190198 EmitAssemblyHelper (DiagnosticsEngine &_Diags,
191199 const HeaderSearchOptions &HeaderSearchOpts,
@@ -1029,7 +1037,8 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
10291037 if (!actionRequiresCodeGen (Action) && CodeGenOpts.VerifyModule )
10301038 MPM.addPass (VerifierPass ());
10311039
1032- if (Action == Backend_EmitBC || Action == Backend_EmitLL) {
1040+ if (Action == Backend_EmitBC || Action == Backend_EmitLL ||
1041+ CodeGenOpts.FatLTO ) {
10331042 if (CodeGenOpts.PrepareForThinLTO && !CodeGenOpts.DisableLLVMPasses ) {
10341043 if (!TheModule->getModuleFlag (" EnableSplitLTOUnit" ))
10351044 TheModule->addModuleFlag (llvm::Module::Error, " EnableSplitLTOUnit" ,
@@ -1040,11 +1049,9 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
10401049 if (!ThinLinkOS)
10411050 return ;
10421051 }
1043- if (CodeGenOpts.UnifiedLTO )
1044- TheModule->addModuleFlag (llvm::Module::Error, " UnifiedLTO" , uint32_t (1 ));
10451052 MPM.addPass (ThinLTOBitcodeWriterPass (
10461053 *OS, ThinLinkOS ? &ThinLinkOS->os () : nullptr ));
1047- } else {
1054+ } else if (Action == Backend_EmitLL) {
10481055 MPM.addPass (PrintModulePass (*OS, " " , CodeGenOpts.EmitLLVMUseLists ,
10491056 /* EmitLTOSummary=*/ true ));
10501057 }
@@ -1058,24 +1065,17 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
10581065 if (!TheModule->getModuleFlag (" EnableSplitLTOUnit" ))
10591066 TheModule->addModuleFlag (llvm::Module::Error, " EnableSplitLTOUnit" ,
10601067 uint32_t (1 ));
1061- if (CodeGenOpts.UnifiedLTO )
1062- TheModule->addModuleFlag (llvm::Module::Error, " UnifiedLTO" , uint32_t (1 ));
10631068 }
1064- if (Action == Backend_EmitBC)
1069+ if (Action == Backend_EmitBC) {
10651070 MPM.addPass (BitcodeWriterPass (*OS, CodeGenOpts.EmitLLVMUseLists ,
10661071 EmitLTOSummary));
1067- else
1072+ } else if (Action == Backend_EmitLL) {
10681073 MPM.addPass (PrintModulePass (*OS, " " , CodeGenOpts.EmitLLVMUseLists ,
10691074 EmitLTOSummary));
1075+ }
10701076 }
1071- }
1072- if (CodeGenOpts.FatLTO ) {
1073- // Set the EnableSplitLTOUnit and UnifiedLTO module flags, since FatLTO
1074- // uses a different action than Backend_EmitBC or Backend_EmitLL.
1075- if (!TheModule->getModuleFlag (" EnableSplitLTOUnit" ))
1076- TheModule->addModuleFlag (llvm::Module::Error, " EnableSplitLTOUnit" ,
1077- uint32_t (CodeGenOpts.EnableSplitLTOUnit ));
1078- if (CodeGenOpts.UnifiedLTO && !TheModule->getModuleFlag (" UnifiedLTO" ))
1077+
1078+ if (shouldEmitUnifiedLTOModueFlag ())
10791079 TheModule->addModuleFlag (llvm::Module::Error, " UnifiedLTO" , uint32_t (1 ));
10801080 }
10811081
0 commit comments