@@ -152,48 +152,36 @@ void tools::PS4cpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
152152 CmdArgs.push_back (Output.getFilename ());
153153 }
154154
155- const bool UseLTO = D.isUsingLTO ();
156155 const bool UseJMC =
157156 Args.hasFlag (options::OPT_fjmc, options::OPT_fno_jmc, false );
158157
159158 const char *LTOArgs = " " ;
160- auto AddCodeGenFlag = [&](Twine Flag) {
159+ auto AddLTOFlag = [&](Twine Flag) {
161160 LTOArgs = Args.MakeArgString (Twine (LTOArgs) + " " + Flag);
162161 };
163162
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" );
168173
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 ());
171176
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);
175179
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));
186181
187182 if (!Args.hasArg (options::OPT_nostdlib, options::OPT_nodefaultlibs))
188183 TC.addSanitizerArgs (Args, CmdArgs, " -l" , " " );
189184
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-
197185 Args.addAllArgs (CmdArgs, {options::OPT_L, options::OPT_T_Group,
198186 options::OPT_s, options::OPT_t});
199187
@@ -259,37 +247,34 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
259247 CmdArgs.push_back (Output.getFilename ());
260248 }
261249
262- const bool UseLTO = D.isUsingLTO ();
263250 const bool UseJMC =
264251 Args.hasFlag (options::OPT_fjmc, options::OPT_fno_jmc, false );
265252
266- auto AddCodeGenFlag = [&](Twine Flag) {
253+ auto AddLTOFlag = [&](Twine Flag) {
267254 CmdArgs.push_back (Args.MakeArgString (Twine (" -plugin-opt=" ) + Flag));
268255 };
269256
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" );
274265
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 " );
277268
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);
282274
283275 if (!Args.hasArg (options::OPT_nostdlib, options::OPT_nodefaultlibs))
284276 TC.addSanitizerArgs (Args, CmdArgs, " -l" , " " );
285277
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-
293278 Args.addAllArgs (CmdArgs, {options::OPT_L, options::OPT_T_Group,
294279 options::OPT_s, options::OPT_t});
295280
0 commit comments