@@ -9140,81 +9140,78 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
91409140 const InputInfoList &Inputs,
91419141 const ArgList &Args,
91429142 const char *LinkingOutput) const {
9143- const Driver &D = getToolChain ().getDriver ();
9144- const llvm::Triple TheTriple = getToolChain ().getTriple ();
9145- ArgStringList CmdArgs;
9143+ using namespace options ;
9144+
9145+ // A list of permitted options that will be forwarded to the embedded device
9146+ // compilation job.
9147+ const llvm::DenseSet<unsigned > CompilerOptions{
9148+ OPT_v,
9149+ OPT_cuda_path_EQ,
9150+ OPT_rocm_path_EQ,
9151+ OPT_O_Group,
9152+ OPT_g_Group,
9153+ OPT_g_flags_Group,
9154+ OPT_R_value_Group,
9155+ OPT_R_Group,
9156+ OPT_Xcuda_ptxas,
9157+ OPT_ftime_report,
9158+ OPT_ftime_trace,
9159+ OPT_ftime_trace_EQ,
9160+ OPT_ftime_trace_granularity_EQ,
9161+ OPT_ftime_trace_verbose,
9162+ OPT_opt_record_file,
9163+ OPT_opt_record_format,
9164+ OPT_opt_record_passes,
9165+ OPT_fsave_optimization_record,
9166+ OPT_fsave_optimization_record_EQ,
9167+ OPT_fno_save_optimization_record,
9168+ OPT_foptimization_record_file_EQ,
9169+ OPT_foptimization_record_passes_EQ,
9170+ OPT_save_temps,
9171+ OPT_mcode_object_version_EQ,
9172+ OPT_load,
9173+ OPT_fno_lto,
9174+ OPT_flto,
9175+ OPT_flto_EQ};
9176+ const llvm::DenseSet<unsigned > LinkerOptions{OPT_mllvm};
9177+ auto ShouldForward = [&](const llvm::DenseSet<unsigned > &Set, Arg *A) {
9178+ return Set.contains (A->getOption ().getID ()) ||
9179+ (A->getOption ().getGroup ().isValid () &&
9180+ Set.contains (A->getOption ().getGroup ().getID ()));
9181+ };
91469182
9147- // Pass the CUDA path to the linker wrapper tool.
9183+ ArgStringList CmdArgs;
91489184 for (Action::OffloadKind Kind : {Action::OFK_Cuda, Action::OFK_OpenMP}) {
91499185 auto TCRange = C.getOffloadToolChains (Kind);
91509186 for (auto &I : llvm::make_range (TCRange)) {
91519187 const ToolChain *TC = I.second ;
9152- if (TC->getTriple ().isNVPTX ()) {
9153- CudaInstallationDetector CudaInstallation (D, TheTriple, Args);
9154- if (CudaInstallation.isValid ())
9155- CmdArgs.push_back (Args.MakeArgString (
9156- " --cuda-path=" + CudaInstallation.getInstallPath ()));
9157- break ;
9188+
9189+ // We do not use a bound architecture here so options passed only to a
9190+ // specific architecture via -Xarch_<cpu> will not be forwarded.
9191+ ArgStringList CompilerArgs;
9192+ ArgStringList LinkerArgs;
9193+ for (Arg *A : C.getArgsForToolChain (TC, /* BoundArch=*/ " " , Kind)) {
9194+ if (ShouldForward (CompilerOptions, A))
9195+ A->render (Args, CompilerArgs);
9196+ else if (ShouldForward (LinkerOptions, A))
9197+ A->render (Args, LinkerArgs);
91589198 }
9159- }
9160- }
91619199
9162- // Pass in the optimization level to use for LTO.
9163- if (const Arg *A = Args.getLastArg (options::OPT_O_Group)) {
9164- StringRef OOpt;
9165- if (A->getOption ().matches (options::OPT_O4) ||
9166- A->getOption ().matches (options::OPT_Ofast))
9167- OOpt = " 3" ;
9168- else if (A->getOption ().matches (options::OPT_O)) {
9169- OOpt = A->getValue ();
9170- if (OOpt == " g" )
9171- OOpt = " 1" ;
9172- else if (OOpt == " s" || OOpt == " z" )
9173- OOpt = " 2" ;
9174- } else if (A->getOption ().matches (options::OPT_O0))
9175- OOpt = " 0" ;
9176- if (!OOpt.empty ())
9177- CmdArgs.push_back (Args.MakeArgString (Twine (" --opt-level=O" ) + OOpt));
9200+ // Forward all of these to the appropriate toolchain.
9201+ for (StringRef Arg : CompilerArgs)
9202+ CmdArgs.push_back (Args.MakeArgString (
9203+ " --device-compiler=" + TC->getTripleString () + " =" + Arg));
9204+ for (StringRef Arg : LinkerArgs)
9205+ CmdArgs.push_back (Args.MakeArgString (
9206+ " --device-linker=" + TC->getTripleString () + " =" + Arg));
9207+ }
91789208 }
91799209
91809210 CmdArgs.push_back (
9181- Args.MakeArgString (" --host-triple=" + TheTriple. getTriple ()));
9211+ Args.MakeArgString (" --host-triple=" + getToolChain (). getTripleString ()));
91829212 if (Args.hasArg (options::OPT_v))
91839213 CmdArgs.push_back (" --wrapper-verbose" );
91849214
9185- if (const Arg *A = Args.getLastArg (options::OPT_g_Group)) {
9186- if (!A->getOption ().matches (options::OPT_g0))
9187- CmdArgs.push_back (" --device-debug" );
9188- }
9189-
9190- // code-object-version=X needs to be passed to clang-linker-wrapper to ensure
9191- // that it is used by lld.
9192- if (const Arg *A = Args.getLastArg (options::OPT_mcode_object_version_EQ)) {
9193- CmdArgs.push_back (Args.MakeArgString (" -mllvm" ));
9194- CmdArgs.push_back (Args.MakeArgString (
9195- Twine (" --amdhsa-code-object-version=" ) + A->getValue ()));
9196- }
9197-
9198- for (const auto &A : Args.getAllArgValues (options::OPT_Xcuda_ptxas))
9199- CmdArgs.push_back (Args.MakeArgString (" --ptxas-arg=" + A));
9200-
9201- // Forward remarks passes to the LLVM backend in the wrapper.
9202- if (const Arg *A = Args.getLastArg (options::OPT_Rpass_EQ))
9203- CmdArgs.push_back (Args.MakeArgString (Twine (" --offload-opt=-pass-remarks=" ) +
9204- A->getValue ()));
9205- if (const Arg *A = Args.getLastArg (options::OPT_Rpass_missed_EQ))
9206- CmdArgs.push_back (Args.MakeArgString (
9207- Twine (" --offload-opt=-pass-remarks-missed=" ) + A->getValue ()));
9208- if (const Arg *A = Args.getLastArg (options::OPT_Rpass_analysis_EQ))
9209- CmdArgs.push_back (Args.MakeArgString (
9210- Twine (" --offload-opt=-pass-remarks-analysis=" ) + A->getValue ()));
9211-
9212- if (Args.getLastArg (options::OPT_ftime_report))
9213- CmdArgs.push_back (" --device-compiler=-ftime-report" );
9214-
9215- if (Args.getLastArg (options::OPT_save_temps_EQ))
9216- CmdArgs.push_back (" --save-temps" );
9217-
92189215 // Construct the link job so we can wrap around it.
92199216 Linker->ConstructJob (C, JA, Output, Inputs, Args, LinkingOutput);
92209217 const auto &LinkCommand = C.getJobs ().getJobs ().back ();
@@ -9238,13 +9235,6 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
92389235 options::OPT_fno_openmp_target_jit, false ))
92399236 CmdArgs.push_back (" --embed-bitcode" );
92409237
9241- // Forward `-mllvm` arguments to the LLVM invocations if present.
9242- for (Arg *A : Args.filtered (options::OPT_mllvm)) {
9243- CmdArgs.push_back (" -mllvm" );
9244- CmdArgs.push_back (A->getValue ());
9245- A->claim ();
9246- }
9247-
92489238 // Pass in the C library for GPUs if present and not disabled.
92499239 if (!Args.hasArg (options::OPT_nostdlib, options::OPT_r, options::OPT_nogpulib,
92509240 options::OPT_nodefaultlibs, options::OPT_nolibc,
@@ -9270,11 +9260,6 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
92709260 });
92719261 }
92729262
9273- // If we disable the GPU C library support it needs to be forwarded to the
9274- // link job.
9275- if (!Args.hasFlag (options::OPT_gpulibc, options::OPT_nogpulibc, true ))
9276- CmdArgs.push_back (" --device-compiler=-nolibc" );
9277-
92789263 // Add the linker arguments to be forwarded by the wrapper.
92799264 CmdArgs.push_back (Args.MakeArgString (Twine (" --linker-path=" ) +
92809265 LinkCommand->getExecutable ()));
0 commit comments