@@ -631,8 +631,11 @@ void amdgpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
631631 getToolChain ().AddFilePathLibArgs (Args, CmdArgs);
632632 AddLinkerInputs (getToolChain (), Inputs, Args, CmdArgs, JA);
633633 if (C.getDriver ().isUsingLTO ()) {
634- addLTOOptions (getToolChain (), Args, CmdArgs, Output, Inputs[0 ],
635- C.getDriver ().getLTOMode () == LTOK_Thin);
634+ const bool ThinLTO = (C.getDriver ().getLTOMode () == LTOK_Thin);
635+ addLTOOptions (getToolChain (), Args, CmdArgs, Output, Inputs[0 ], ThinLTO);
636+
637+ if (!ThinLTO)
638+ addFullLTOPartitionOption (C.getDriver (), Args, CmdArgs);
636639 } else if (Args.hasArg (options::OPT_mcpu_EQ)) {
637640 CmdArgs.push_back (Args.MakeArgString (
638641 " -plugin-opt=mcpu=" +
@@ -760,6 +763,33 @@ llvm::SmallVector<std::string, 12> amdgpu::dlr::getCommonDeviceLibNames(
760763 FastRelaxedMath, CorrectSqrt, ABIVer, isOpenMP);
761764}
762765
766+ static unsigned getFullLTOPartitions (const Driver &D, const ArgList &Args) {
767+ const Arg *A = Args.getLastArg (options::OPT_flto_partitions_EQ);
768+ // In the absence of an option, use 8 as the default.
769+ if (!A)
770+ return 8 ;
771+ int Value = 0 ;
772+ if (StringRef (A->getValue ()).getAsInteger (10 , Value) || (Value < 1 )) {
773+ D.Diag (diag::err_drv_invalid_int_value)
774+ << A->getAsString (Args) << A->getValue ();
775+ return 1 ;
776+ }
777+
778+ return Value;
779+ }
780+
781+ void amdgpu::addFullLTOPartitionOption (const Driver &D,
782+ const llvm::opt::ArgList &Args,
783+ llvm::opt::ArgStringList &CmdArgs) {
784+ // TODO: Should this be restricted to fgpu-rdc only ? Currently we'll
785+ // also do it for non gpu-rdc LTO
786+
787+ if (unsigned NumParts = getFullLTOPartitions (D, Args); NumParts > 1 ) {
788+ CmdArgs.push_back (
789+ Args.MakeArgString (" --lto-partitions=" + Twine (NumParts)));
790+ }
791+ }
792+
763793// / AMDGPU Toolchain
764794AMDGPUToolChain::AMDGPUToolChain (const Driver &D, const llvm::Triple &Triple,
765795 const ArgList &Args)
0 commit comments