@@ -152,48 +152,36 @@ void tools::PS4cpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
152
152
CmdArgs.push_back (Output.getFilename ());
153
153
}
154
154
155
- const bool UseLTO = D.isUsingLTO ();
156
155
const bool UseJMC =
157
156
Args.hasFlag (options::OPT_fjmc, options::OPT_fno_jmc, false );
158
157
159
158
const char *LTOArgs = " " ;
160
- auto AddCodeGenFlag = [&](Twine Flag) {
159
+ auto AddLTOFlag = [&](Twine Flag) {
161
160
LTOArgs = Args.MakeArgString (Twine (LTOArgs) + " " + Flag);
162
161
};
163
162
164
- if (UseLTO) {
165
- // This tells LTO to perform JustMyCode instrumentation.
166
- if (UseJMC)
167
- AddCodeGenFlag (" -enable-jmc-instrument" );
163
+ // If the linker sees bitcode objects it will perform LTO. We can't tell
164
+ // whether or not that will be the case at this point. So, unconditionally
165
+ // pass LTO options to ensure proper codegen, metadata production, etc if
166
+ // LTO indeed occurs.
167
+ if (Args.hasFlag (options::OPT_funified_lto, options::OPT_fno_unified_lto,
168
+ true ))
169
+ CmdArgs.push_back (D.getLTOMode () == LTOK_Thin ? " --lto=thin"
170
+ : " --lto=full" );
171
+ if (UseJMC)
172
+ AddLTOFlag (" -enable-jmc-instrument" );
168
173
169
- if (Arg *A = Args.getLastArg (options::OPT_fcrash_diagnostics_dir))
170
- AddCodeGenFlag (Twine (" -crash-diagnostics-dir=" ) + A->getValue ());
174
+ if (Arg *A = Args.getLastArg (options::OPT_fcrash_diagnostics_dir))
175
+ AddLTOFlag (Twine (" -crash-diagnostics-dir=" ) + A->getValue ());
171
176
172
- StringRef Parallelism = getLTOParallelism (Args, D);
173
- if (!Parallelism.empty ())
174
- AddCodeGenFlag (Twine (" -threads=" ) + Parallelism);
177
+ if (StringRef Threads = getLTOParallelism (Args, D); !Threads.empty ())
178
+ AddLTOFlag (Twine (" -threads=" ) + Threads);
175
179
176
- const char *Prefix = nullptr ;
177
- if (D.getLTOMode () == LTOK_Thin)
178
- Prefix = " -lto-thin-debug-options=" ;
179
- else if (D.getLTOMode () == LTOK_Full)
180
- Prefix = " -lto-debug-options=" ;
181
- else
182
- llvm_unreachable (" new LTO mode?" );
183
-
184
- CmdArgs.push_back (Args.MakeArgString (Twine (Prefix) + LTOArgs));
185
- }
180
+ CmdArgs.push_back (Args.MakeArgString (Twine (" -lto-debug-options=" ) + LTOArgs));
186
181
187
182
if (!Args.hasArg (options::OPT_nostdlib, options::OPT_nodefaultlibs))
188
183
TC.addSanitizerArgs (Args, CmdArgs, " -l" , " " );
189
184
190
- if (D.isUsingLTO () && Args.hasArg (options::OPT_funified_lto)) {
191
- if (D.getLTOMode () == LTOK_Thin)
192
- CmdArgs.push_back (" --lto=thin" );
193
- else if (D.getLTOMode () == LTOK_Full)
194
- CmdArgs.push_back (" --lto=full" );
195
- }
196
-
197
185
Args.addAllArgs (CmdArgs, {options::OPT_L, options::OPT_T_Group,
198
186
options::OPT_s, options::OPT_t});
199
187
@@ -259,37 +247,34 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
259
247
CmdArgs.push_back (Output.getFilename ());
260
248
}
261
249
262
- const bool UseLTO = D.isUsingLTO ();
263
250
const bool UseJMC =
264
251
Args.hasFlag (options::OPT_fjmc, options::OPT_fno_jmc, false );
265
252
266
- auto AddCodeGenFlag = [&](Twine Flag) {
253
+ auto AddLTOFlag = [&](Twine Flag) {
267
254
CmdArgs.push_back (Args.MakeArgString (Twine (" -plugin-opt=" ) + Flag));
268
255
};
269
256
270
- if (UseLTO) {
271
- // This tells LTO to perform JustMyCode instrumentation.
272
- if (UseJMC)
273
- AddCodeGenFlag (" -enable-jmc-instrument" );
257
+ // If the linker sees bitcode objects it will perform LTO. We can't tell
258
+ // whether or not that will be the case at this point. So, unconditionally
259
+ // pass LTO options to ensure proper codegen, metadata production, etc if
260
+ // LTO indeed occurs.
261
+ if (Args.hasFlag (options::OPT_funified_lto, options::OPT_fno_unified_lto,
262
+ true ))
263
+ CmdArgs.push_back (D.getLTOMode () == LTOK_Thin ? " --lto=thin"
264
+ : " --lto=full" );
274
265
275
- if (Arg *A = Args. getLastArg (options::OPT_fcrash_diagnostics_dir) )
276
- AddCodeGenFlag ( Twine ( " -crash-diagnostics-dir= " ) + A-> getValue () );
266
+ if (UseJMC )
267
+ AddLTOFlag ( " -enable-jmc-instrument " );
277
268
278
- StringRef Parallelism = getLTOParallelism (Args, D);
279
- if (!Parallelism.empty ())
280
- CmdArgs.push_back (Args.MakeArgString (Twine (" -plugin-opt=jobs=" ) + Parallelism));
281
- }
269
+ if (Arg *A = Args.getLastArg (options::OPT_fcrash_diagnostics_dir))
270
+ AddLTOFlag (Twine (" -crash-diagnostics-dir=" ) + A->getValue ());
271
+
272
+ if (StringRef Jobs = getLTOParallelism (Args, D); !Jobs.empty ())
273
+ AddLTOFlag (Twine (" jobs=" ) + Jobs);
282
274
283
275
if (!Args.hasArg (options::OPT_nostdlib, options::OPT_nodefaultlibs))
284
276
TC.addSanitizerArgs (Args, CmdArgs, " -l" , " " );
285
277
286
- if (D.isUsingLTO () && Args.hasArg (options::OPT_funified_lto)) {
287
- if (D.getLTOMode () == LTOK_Thin)
288
- CmdArgs.push_back (" --lto=thin" );
289
- else if (D.getLTOMode () == LTOK_Full)
290
- CmdArgs.push_back (" --lto=full" );
291
- }
292
-
293
278
Args.addAllArgs (CmdArgs, {options::OPT_L, options::OPT_T_Group,
294
279
options::OPT_s, options::OPT_t});
295
280
0 commit comments