Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -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'.">;
Expand Down
6 changes: 6 additions & 0 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
18 changes: 18 additions & 0 deletions clang/test/Driver/amdgpu-openmp-toolchain.c
Original file line number Diff line number Diff line change
Expand Up @@ -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<O3>" %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<O3>"
34 changes: 32 additions & 2 deletions clang/test/Driver/linker-wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {{.*}}.o {{.*}}.o -g

// RUN: clang-offload-packager -o %t.out \
// RUN: --image=file=%t.elf.o,kind=openmp,triple=amdgcn-amd-amdhsa,arch=gfx908 \
Expand Down Expand Up @@ -93,7 +93,7 @@ __attribute__((visibility("protected"), used)) int x;

// CUDA: clang{{.*}} -o [[IMG_SM70:.+]] --target=nvptx64-nvidia-cuda -march=sm_70
// CUDA: clang{{.*}} -o [[IMG_SM52:.+]] --target=nvptx64-nvidia-cuda -march=sm_52
// CUDA: fatbinary{{.*}}-64 --create {{.*}}.fatbin --image=profile=sm_70,file=[[IMG_SM70]] --image=profile=sm_52,file=[[IMG_SM52]]
// CUDA: fatbinary{{.*}}-64 --create {{.*}}.fatbin --image=profile=sm_70,file=[[IMG_SM70]] --image=profile=sm_52,file=[[IMG_SM52]]
// CUDA: usr/bin/ld{{.*}} {{.*}}.openmp.image.{{.*}}.o {{.*}}.cuda.image.{{.*}}.o

// RUN: clang-offload-packager -o %t.out \
Expand Down Expand Up @@ -254,3 +254,33 @@ __attribute__((visibility("protected"), used)) int x;
// Error handling when --linker-path is not provided for clang-linker-wrapper
// RUN: not clang-linker-wrapper 2>&1 | FileCheck --check-prefix=LINKER-PATH-NOT-PROVIDED %s
// LINKER-PATH-NOT-PROVIDED: linker path missing, must pass 'linker-path'

// RUN: clang-linker-wrapper --lto-opt-pipeline=default \
// RUN: --dry-run --wrapper-verbose --host-triple=x86_64-unknown-linux-gnu \
// RUN: --linker-path=/usr/bin/ld %t.o -o a.out \
// RUN: 2>&1 | FileCheck %s --check-prefix=LTO-OPT-PL-00
// LTO-OPT-PL-00: "{{.*}}clang" {{.*}} -Xlinker --lto-newpm-passes=default<O2>

// RUN: clang-linker-wrapper --lto-opt-pipeline=default --opt-level=O3 \
// RUN: --dry-run --wrapper-verbose --host-triple=x86_64-unknown-linux-gnu \
// RUN: --linker-path=/usr/bin/ld %t.o -o a.out \
// RUN: 2>&1 | FileCheck %s --check-prefix=LTO-OPT-PL-01
// LTO-OPT-PL-01: "{{.*}}clang" {{.*}} -Xlinker --lto-newpm-passes=default<O3>

// RUN: clang-linker-wrapper --lto-opt-pipeline=lto \
// RUN: --dry-run --wrapper-verbose --host-triple=x86_64-unknown-linux-gnu \
// RUN: --linker-path=/usr/bin/ld %t.o -o a.out \
// RUN: 2>&1 | FileCheck %s --check-prefix=LTO-OPT-PL-02
// LTO-OPT-PL-02: "{{.*}}clang" {{.*}} -Xlinker --lto-newpm-passes=lto<O2>

// RUN: clang-linker-wrapper --lto-opt-pipeline=lto --opt-level=O0 \
// RUN: --dry-run --wrapper-verbose --host-triple=x86_64-unknown-linux-gnu \
// RUN: --linker-path=/usr/bin/ld %t.o -o a.out \
// RUN: 2>&1 | FileCheck %s --check-prefix=LTO-OPT-PL-03
// LTO-OPT-PL-03: "{{.*}}clang" {{.*}} -Xlinker --lto-newpm-passes=lto<O0>

// RUN: clang-linker-wrapper \
// RUN: --dry-run --wrapper-verbose --host-triple=x86_64-unknown-linux-gnu \
// RUN: --linker-path=/usr/bin/ld %t.o -o a.out \
// RUN: 2>&1 | FileCheck %s --check-prefix=LTO-OPT-PL-04
// LTO-OPT-PL-04-NOT: --lto-newpm-passes
12 changes: 12 additions & 0 deletions clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,18 @@ Expected<StringRef> clang(ArrayRef<StringRef> InputFiles, const ArgList &Args) {

for (StringRef Arg : Args.getAllArgValues(OPT_linker_arg_EQ))
CmdArgs.append({"-Xlinker", Args.MakeArgString(Arg)});

StringRef LTOOptPipeline = Args.getLastArgValue(OPT_lto_opt_pipeline_EQ, "");
if (LTOOptPipeline == "default" || LTOOptPipeline == "lto" ||
LTOOptPipeline == "thinlto") {
// for convenience, add "<On>"
LTOOptPipeline = Args.MakeArgString(LTOOptPipeline + "<" + OptLevel + ">");
}
if (LTOOptPipeline.size()) {
CmdArgs.append({"-Xlinker", Args.MakeArgString("--lto-newpm-passes=" +
LTOOptPipeline)});
}

for (StringRef Arg : Args.getAllArgValues(OPT_compiler_arg_EQ))
CmdArgs.push_back(Args.MakeArgString(Arg));

Expand Down
4 changes: 4 additions & 0 deletions clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ def override_image : Joined<["--"], "override-image=">,
Flags<[WrapperOnlyOption]>, MetaVarName<"<kind=file>">,
HelpText<"Uses the provided file as if it were the output of the device link step">;

def lto_opt_pipeline_EQ : Joined<["--"], "lto-opt-pipeline=">,
Flags<[WrapperOnlyOption]>,
HelpText<"Optimization pipeline to use during LTO.">;

// Flags passed to the device linker.
def arch_EQ : Joined<["--"], "arch=">,
Flags<[DeviceOnlyOption, HelpHidden]>, MetaVarName<"<arch>">,
Expand Down
20 changes: 20 additions & 0 deletions flang/test/Driver/offload-lto-pipeline.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
! Test forwarding/generation of -lto-opt-pipeline to the clang-linker-wrapper

! RUN: %flang -### %s -o %t 2>&1 -fopenmp --offload-arch=gfx90a \
! RUN: --target=aarch64-unknown-linux-gnu -nogpulib \
! RUN: | FileCheck %s --check-prefix=CHECK-LTO-OPT-PL-00
! CHECK-LTO-OPT-PL-00-NOT: clang-linker-wrapper{{.*}} "--lto-opt-pipeline"

! RUN: %flang -### %s -o %t 2>&1 -fopenmp --offload-arch=gfx90a \
! RUN: --target=aarch64-unknown-linux-gnu -nogpulib \
! RUN: -offload-lto-opt-pipeline=lto \
! RUN: | FileCheck %s --check-prefix=CHECK-LTO-OPT-PL-01
! CHECK-LTO-OPT-PL-01: clang-linker-wrapper{{.*}} "--lto-opt-pipeline=lto"

! RUN: %flang -### %s -o %t 2>&1 -fopenmp --offload-arch=gfx90a \
! RUN: --target=aarch64-unknown-linux-gnu -nogpulib \
! RUN: "-offload-lto-opt-pipeline=default<O3>" \
! RUN: | FileCheck %s --check-prefix=CHECK-LTO-OPT-PL-02
! CHECK-LTO-OPT-PL-02: clang-linker-wrapper{{.*}} "--lto-opt-pipeline=default<O3>"


Loading