[clang] [flang] [clang] Add option to specify opt pipeline during offload lto (PR #114401)
jhuber6 wrote: > Just out of curiosity: Are all these things documented reasonably well > somewhere? It's in the clang reference, but probably could be part of a better tutorial or something. https://github.com/llvm/llvm-project/pull/114401 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [clang] Add option to specify opt pipeline during offload lto (PR #114401)
jplehr wrote: Just out of curiosity: Are all these things documented reasonably well somewhere? https://github.com/llvm/llvm-project/pull/114401 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [clang] Add option to specify opt pipeline during offload lto (PR #114401)
jhuber6 wrote: > For the purposes of experimentation, `-Xoffload-linker` is sufficient that > this change is not necessary. Also worth noting that `-Xoffload-linker-amdgcn-amd-amdhsa` should work if you just want to target a single toolchain. https://github.com/llvm/llvm-project/pull/114401 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [clang] Add option to specify opt pipeline during offload lto (PR #114401)
macurtis-amd wrote: For the purposes of experimentation, `-Xoffload-linker` is sufficient that this change is not necessary. https://github.com/llvm/llvm-project/pull/114401 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [clang] Add option to specify opt pipeline during offload lto (PR #114401)
https://github.com/macurtis-amd closed https://github.com/llvm/llvm-project/pull/114401 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [clang] Add option to specify opt pipeline during offload lto (PR #114401)
macurtis-amd wrote: > Can this be done through `-Xoffload-linker`? No. I tried several different things, but was not able to get the right command line option passed to lld (in the clang->clang-linker-wrapper->clang->lld chain). https://github.com/llvm/llvm-project/pull/114401 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [clang] Add option to specify opt pipeline during offload lto (PR #114401)
macurtis-amd wrote: > > > Can this be done through `-Xoffload-linker`? > > > > > > No. I tried several different things, but was not able to get the right > > command line option passed to lld (in the > > clang->clang-linker-wrapper->clang->lld chain). > > This works for me, > > ``` > $ clang input.c -fopenmp --offload-arch=gfx1030 -Xoffload-linker > --lto-newpm-passes='default' -v > ld.lld ... --lto-newpm-passes=default ... > ``` You are right. That works. I thought I had tried `-Xoffload-linker` but I guess not. https://github.com/llvm/llvm-project/pull/114401 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [clang] Add option to specify opt pipeline during offload lto (PR #114401)
jhuber6 wrote: > > Can this be done through `-Xoffload-linker`? > > No. I tried several different things, but was not able to get the right > command line option passed to lld (in the > clang->clang-linker-wrapper->clang->lld chain). This works for me, ```console $ clang input.c -fopenmp --offload-arch=gfx1030 -Xoffload-linker --lto-newpm-passes='default' -v ld.lld ... --lto-newpm-passes=default ... ``` https://github.com/llvm/llvm-project/pull/114401 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [clang] Add option to specify opt pipeline during offload lto (PR #114401)
https://github.com/macurtis-amd created https://github.com/llvm/llvm-project/pull/114401 Especially useful for experimenting with 'default' vs 'lto' pipelines. New driver option '-offload-lto-opt-pipeline=' is forwarded to clang-linker-wrapper as '-lto-opt-pipeline=' which is then forwarded to clang as '-Xlinker --lto-newpm-passes=' and then finally as '--lto-newpm-passes=' to lld. >From 2c4ddda58ee35141a1b59e92f1894d76b7bac43e Mon Sep 17 00:00:00 2001 From: Matthew Curtis Date: Thu, 31 Oct 2024 08:06:29 -0500 Subject: [PATCH] [clang] Add option to specify opt pipeline during offload lto Especially useful for experimenting with 'default' vs 'lto' pipelines. New driver option '-offload-lto-opt-pipeline=' is forwarded to clang-linker-wrapper as '-lto-opt-pipeline=' which is then forwarded to clang as '-Xlinker --lto-newpm-passes=' and then finally as '--lto-newpm-passes=' to lld. --- clang/include/clang/Driver/Options.td | 4 +++ clang/lib/Driver/ToolChains/Clang.cpp | 6 clang/test/Driver/amdgpu-openmp-toolchain.c | 18 ++ clang/test/Driver/linker-wrapper.c| 34 +-- .../ClangLinkerWrapper.cpp| 12 +++ .../clang-linker-wrapper/LinkerWrapperOpts.td | 4 +++ flang/test/Driver/offload-lto-pipeline.f90| 20 +++ 7 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 flang/test/Driver/offload-lto-pipeline.f90 diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 2b9ee1a0e669ed..c78eb23e134e04 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1231,6 +1231,10 @@ def offload_host_device : Flag<["--"], "offload-host-device">, Visibility<[ClangOption, FlangOption]>, HelpText<"Compile for both the offloading host and device (default).">; +def offload_lto_opt_pipeline_EQ : Joined<["-"], "offload-lto-opt-pipeline=">, + Visibility<[ClangOption, FlangOption]>, Flags<[HelpHidden]>, + HelpText<"Optimization pipeline to use during offload linking.">; + def gpu_use_aux_triple_only : Flag<["--"], "gpu-use-aux-triple-only">, InternalDriverOpt, HelpText<"Prepare '-aux-triple' only without populating " "'-aux-target-cpu' and '-aux-target-feature'.">; diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 4c6f508f1f24a6..128b9f29358bf4 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -9228,6 +9228,12 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA, if (Args.getLastArg(options::OPT_save_temps_EQ)) CmdArgs.push_back("--save-temps"); + if (const Arg *A = + Args.getLastArg(options::OPT_offload_lto_opt_pipeline_EQ)) { +CmdArgs.push_back( +Args.MakeArgString(Twine("--lto-opt-pipeline=") + A->getValue())); + } + // Construct the link job so we can wrap around it. Linker->ConstructJob(C, JA, Output, Inputs, Args, LinkingOutput); const auto &LinkCommand = C.getJobs().getJobs().back(); diff --git a/clang/test/Driver/amdgpu-openmp-toolchain.c b/clang/test/Driver/amdgpu-openmp-toolchain.c index f596708047c154..57aedb35024ac1 100644 --- a/clang/test/Driver/amdgpu-openmp-toolchain.c +++ b/clang/test/Driver/amdgpu-openmp-toolchain.c @@ -81,3 +81,21 @@ // RUN: %clang -### --target=x86_64-unknown-linux-gnu -emit-llvm -S -fopenmp --offload-arch=gfx803 \ // RUN: -stdlib=libc++ -nogpulib %s 2>&1 | FileCheck %s --check-prefix=LIBCXX // LIBCXX-NOT: include/amdgcn-amd-amdhsa/c++/v1 + +// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fopenmp \ +// RUN: -fopenmp-targets=amdgcn-amd-amdhsa -Xopenmp-target=amdgcn-amd-amdhsa \ +// RUN: -march=gfx803 -nogpulib %s \ +// RUN: 2>&1 | FileCheck %s --check-prefix=CHECK-LTO-OPT-PL-00 +// CHECK-LTO-OPT-PL-00-NOT: clang-linker-wrapper{{.*}} "--lto-opt-pipeline" + +// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fopenmp \ +// RUN: -fopenmp-targets=amdgcn-amd-amdhsa -Xopenmp-target=amdgcn-amd-amdhsa \ +// RUN: -march=gfx803 -nogpulib -offload-lto-opt-pipeline=lto %s \ +// RUN: 2>&1 | FileCheck %s --check-prefix=CHECK-LTO-OPT-PL-01 +// CHECK-LTO-OPT-PL-01: clang-linker-wrapper{{.*}} "--lto-opt-pipeline=lto" + +// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fopenmp \ +// RUN: -fopenmp-targets=amdgcn-amd-amdhsa -Xopenmp-target=amdgcn-amd-amdhsa \ +// RUN: -march=gfx803 -nogpulib "-offload-lto-opt-pipeline=default" %s \ +// RUN: 2>&1 | FileCheck %s --check-prefix=CHECK-LTO-OPT-PL-02 +// CHECK-LTO-OPT-PL-02: clang-linker-wrapper{{.*}} "--lto-opt-pipeline=default" diff --git a/clang/test/Driver/linker-wrapper.c b/clang/test/Driver/linker-wrapper.c index 470af4d5d70cac..da4a3fe31afd07 100644 --- a/clang/test/Driver/linker-wrapper.c +++ b/clang/test/Driver/linker-wrapper.c @@ -30,7 +30,7 @@ __attribute__((visibility("protected"), used
[clang] [flang] [clang] Add option to specify opt pipeline during offload lto (PR #114401)
jhuber6 wrote: Can this be done through `-Xoffload-linker`? https://github.com/llvm/llvm-project/pull/114401 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [clang] Add option to specify opt pipeline during offload lto (PR #114401)
llvmbot wrote: @llvm/pr-subscribers-clang-driver @llvm/pr-subscribers-clang Author: None (macurtis-amd) Changes Especially useful for experimenting with 'default' vs 'lto' pipelines. New driver option '-offload-lto-opt-pipeline=' is forwarded to clang-linker-wrapper as '-lto-opt-pipeline= ' which is then forwarded to clang as '-Xlinker --lto-newpm-passes= ' and then finally as '--lto-newpm-passes= ' to lld. --- Full diff: https://github.com/llvm/llvm-project/pull/114401.diff 7 Files Affected: - (modified) clang/include/clang/Driver/Options.td (+4) - (modified) clang/lib/Driver/ToolChains/Clang.cpp (+6) - (modified) clang/test/Driver/amdgpu-openmp-toolchain.c (+18) - (modified) clang/test/Driver/linker-wrapper.c (+32-2) - (modified) clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp (+12) - (modified) clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td (+4) - (added) flang/test/Driver/offload-lto-pipeline.f90 (+20) ``diff diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 2b9ee1a0e669ed..c78eb23e134e04 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1231,6 +1231,10 @@ def offload_host_device : Flag<["--"], "offload-host-device">, Visibility<[ClangOption, FlangOption]>, HelpText<"Compile for both the offloading host and device (default).">; +def offload_lto_opt_pipeline_EQ : Joined<["-"], "offload-lto-opt-pipeline=">, + Visibility<[ClangOption, FlangOption]>, Flags<[HelpHidden]>, + HelpText<"Optimization pipeline to use during offload linking.">; + def gpu_use_aux_triple_only : Flag<["--"], "gpu-use-aux-triple-only">, InternalDriverOpt, HelpText<"Prepare '-aux-triple' only without populating " "'-aux-target-cpu' and '-aux-target-feature'.">; diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 4c6f508f1f24a6..128b9f29358bf4 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -9228,6 +9228,12 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA, if (Args.getLastArg(options::OPT_save_temps_EQ)) CmdArgs.push_back("--save-temps"); + if (const Arg *A = + Args.getLastArg(options::OPT_offload_lto_opt_pipeline_EQ)) { +CmdArgs.push_back( +Args.MakeArgString(Twine("--lto-opt-pipeline=") + A->getValue())); + } + // Construct the link job so we can wrap around it. Linker->ConstructJob(C, JA, Output, Inputs, Args, LinkingOutput); const auto &LinkCommand = C.getJobs().getJobs().back(); diff --git a/clang/test/Driver/amdgpu-openmp-toolchain.c b/clang/test/Driver/amdgpu-openmp-toolchain.c index f596708047c154..57aedb35024ac1 100644 --- a/clang/test/Driver/amdgpu-openmp-toolchain.c +++ b/clang/test/Driver/amdgpu-openmp-toolchain.c @@ -81,3 +81,21 @@ // RUN: %clang -### --target=x86_64-unknown-linux-gnu -emit-llvm -S -fopenmp --offload-arch=gfx803 \ // RUN: -stdlib=libc++ -nogpulib %s 2>&1 | FileCheck %s --check-prefix=LIBCXX // LIBCXX-NOT: include/amdgcn-amd-amdhsa/c++/v1 + +// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fopenmp \ +// RUN: -fopenmp-targets=amdgcn-amd-amdhsa -Xopenmp-target=amdgcn-amd-amdhsa \ +// RUN: -march=gfx803 -nogpulib %s \ +// RUN: 2>&1 | FileCheck %s --check-prefix=CHECK-LTO-OPT-PL-00 +// CHECK-LTO-OPT-PL-00-NOT: clang-linker-wrapper{{.*}} "--lto-opt-pipeline" + +// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fopenmp \ +// RUN: -fopenmp-targets=amdgcn-amd-amdhsa -Xopenmp-target=amdgcn-amd-amdhsa \ +// RUN: -march=gfx803 -nogpulib -offload-lto-opt-pipeline=lto %s \ +// RUN: 2>&1 | FileCheck %s --check-prefix=CHECK-LTO-OPT-PL-01 +// CHECK-LTO-OPT-PL-01: clang-linker-wrapper{{.*}} "--lto-opt-pipeline=lto" + +// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fopenmp \ +// RUN: -fopenmp-targets=amdgcn-amd-amdhsa -Xopenmp-target=amdgcn-amd-amdhsa \ +// RUN: -march=gfx803 -nogpulib "-offload-lto-opt-pipeline=default" %s \ +// RUN: 2>&1 | FileCheck %s --check-prefix=CHECK-LTO-OPT-PL-02 +// CHECK-LTO-OPT-PL-02: clang-linker-wrapper{{.*}} "--lto-opt-pipeline=default" diff --git a/clang/test/Driver/linker-wrapper.c b/clang/test/Driver/linker-wrapper.c index 470af4d5d70cac..da4a3fe31afd07 100644 --- a/clang/test/Driver/linker-wrapper.c +++ b/clang/test/Driver/linker-wrapper.c @@ -30,7 +30,7 @@ __attribute__((visibility("protected"), used)) int x; // RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run --device-debug -O0 \ // RUN: --linker-path=/usr/bin/ld %t.o -o a.out 2>&1 | FileCheck %s --check-prefix=NVPTX-LINK-DEBUG -// NVPTX-LINK-DEBUG: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda -march=sm_70 -O2 -flto {{.*}}.o {{.*}}.o -g +// NVPTX-LINK-DEBUG: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda -march=sm_70 -O2 -flto {{.*}}.