@@ -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,
@@ -1036,7 +1044,8 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
1036
1044
if (!actionRequiresCodeGen (Action) && CodeGenOpts.VerifyModule )
1037
1045
MPM.addPass (VerifierPass ());
1038
1046
1039
- if (Action == Backend_EmitBC || Action == Backend_EmitLL) {
1047
+ if (Action == Backend_EmitBC || Action == Backend_EmitLL ||
1048
+ CodeGenOpts.FatLTO ) {
1040
1049
if (CodeGenOpts.PrepareForThinLTO && !CodeGenOpts.DisableLLVMPasses ) {
1041
1050
if (!TheModule->getModuleFlag (" EnableSplitLTOUnit" ))
1042
1051
TheModule->addModuleFlag (llvm::Module::Error, " EnableSplitLTOUnit" ,
@@ -1047,11 +1056,9 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
1047
1056
if (!ThinLinkOS)
1048
1057
return ;
1049
1058
}
1050
- if (CodeGenOpts.UnifiedLTO )
1051
- TheModule->addModuleFlag (llvm::Module::Error, " UnifiedLTO" , uint32_t (1 ));
1052
1059
MPM.addPass (ThinLTOBitcodeWriterPass (
1053
1060
*OS, ThinLinkOS ? &ThinLinkOS->os () : nullptr ));
1054
- } else {
1061
+ } else if (Action == Backend_EmitLL) {
1055
1062
MPM.addPass (PrintModulePass (*OS, " " , CodeGenOpts.EmitLLVMUseLists ,
1056
1063
/* EmitLTOSummary=*/ true ));
1057
1064
}
@@ -1065,24 +1072,17 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
1065
1072
if (!TheModule->getModuleFlag (" EnableSplitLTOUnit" ))
1066
1073
TheModule->addModuleFlag (llvm::Module::Error, " EnableSplitLTOUnit" ,
1067
1074
uint32_t (1 ));
1068
- if (CodeGenOpts.UnifiedLTO )
1069
- TheModule->addModuleFlag (llvm::Module::Error, " UnifiedLTO" , uint32_t (1 ));
1070
1075
}
1071
- if (Action == Backend_EmitBC)
1076
+ if (Action == Backend_EmitBC) {
1072
1077
MPM.addPass (BitcodeWriterPass (*OS, CodeGenOpts.EmitLLVMUseLists ,
1073
1078
EmitLTOSummary));
1074
- else
1079
+ } else if (Action == Backend_EmitLL) {
1075
1080
MPM.addPass (PrintModulePass (*OS, " " , CodeGenOpts.EmitLLVMUseLists ,
1076
1081
EmitLTOSummary));
1082
+ }
1077
1083
}
1078
- }
1079
- if (CodeGenOpts.FatLTO ) {
1080
- // Set the EnableSplitLTOUnit and UnifiedLTO module flags, since FatLTO
1081
- // uses a different action than Backend_EmitBC or Backend_EmitLL.
1082
- if (!TheModule->getModuleFlag (" EnableSplitLTOUnit" ))
1083
- TheModule->addModuleFlag (llvm::Module::Error, " EnableSplitLTOUnit" ,
1084
- uint32_t (CodeGenOpts.EnableSplitLTOUnit ));
1085
- if (CodeGenOpts.UnifiedLTO && !TheModule->getModuleFlag (" UnifiedLTO" ))
1084
+
1085
+ if (shouldEmitUnifiedLTOModueFlag ())
1086
1086
TheModule->addModuleFlag (llvm::Module::Error, " UnifiedLTO" , uint32_t (1 ));
1087
1087
}
1088
1088
0 commit comments