@@ -186,6 +186,14 @@ class EmitAssemblyHelper {
186
186
TargetTriple.getVendor () != llvm::Triple::Apple;
187
187
}
188
188
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
+
189
197
public:
190
198
EmitAssemblyHelper (DiagnosticsEngine &_Diags,
191
199
const HeaderSearchOptions &HeaderSearchOpts,
@@ -1029,7 +1037,8 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
1029
1037
if (!actionRequiresCodeGen (Action) && CodeGenOpts.VerifyModule )
1030
1038
MPM.addPass (VerifierPass ());
1031
1039
1032
- if (Action == Backend_EmitBC || Action == Backend_EmitLL) {
1040
+ if (Action == Backend_EmitBC || Action == Backend_EmitLL ||
1041
+ CodeGenOpts.FatLTO ) {
1033
1042
if (CodeGenOpts.PrepareForThinLTO && !CodeGenOpts.DisableLLVMPasses ) {
1034
1043
if (!TheModule->getModuleFlag (" EnableSplitLTOUnit" ))
1035
1044
TheModule->addModuleFlag (llvm::Module::Error, " EnableSplitLTOUnit" ,
@@ -1040,11 +1049,9 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
1040
1049
if (!ThinLinkOS)
1041
1050
return ;
1042
1051
}
1043
- if (CodeGenOpts.UnifiedLTO )
1044
- TheModule->addModuleFlag (llvm::Module::Error, " UnifiedLTO" , uint32_t (1 ));
1045
1052
MPM.addPass (ThinLTOBitcodeWriterPass (
1046
1053
*OS, ThinLinkOS ? &ThinLinkOS->os () : nullptr ));
1047
- } else {
1054
+ } else if (Action == Backend_EmitLL) {
1048
1055
MPM.addPass (PrintModulePass (*OS, " " , CodeGenOpts.EmitLLVMUseLists ,
1049
1056
/* EmitLTOSummary=*/ true ));
1050
1057
}
@@ -1058,24 +1065,17 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
1058
1065
if (!TheModule->getModuleFlag (" EnableSplitLTOUnit" ))
1059
1066
TheModule->addModuleFlag (llvm::Module::Error, " EnableSplitLTOUnit" ,
1060
1067
uint32_t (1 ));
1061
- if (CodeGenOpts.UnifiedLTO )
1062
- TheModule->addModuleFlag (llvm::Module::Error, " UnifiedLTO" , uint32_t (1 ));
1063
1068
}
1064
- if (Action == Backend_EmitBC)
1069
+ if (Action == Backend_EmitBC) {
1065
1070
MPM.addPass (BitcodeWriterPass (*OS, CodeGenOpts.EmitLLVMUseLists ,
1066
1071
EmitLTOSummary));
1067
- else
1072
+ } else if (Action == Backend_EmitLL) {
1068
1073
MPM.addPass (PrintModulePass (*OS, " " , CodeGenOpts.EmitLLVMUseLists ,
1069
1074
EmitLTOSummary));
1075
+ }
1070
1076
}
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 ())
1079
1079
TheModule->addModuleFlag (llvm::Module::Error, " UnifiedLTO" , uint32_t (1 ));
1080
1080
}
1081
1081
0 commit comments