Index: clang/lib/Driver/ToolChains/HIP.cpp =================================================================== --- clang/lib/Driver/ToolChains/HIP.cpp +++ clang/lib/Driver/ToolChains/HIP.cpp @@ -57,14 +57,36 @@ const llvm::opt::ArgList &Args) const { // Construct lld command. // The output from ld.lld is an HSA code object file. - ArgStringList LldArgs{"-flavor", - "gnu", - "--no-undefined", - "-shared", - "-mllvm", - "-amdgpu-internalize-symbols", - "-o", - Output.getFilename()}; + ArgStringList LldArgs{"-flavor", "gnu", "--no-undefined", + "-shared", "-mllvm", "-amdgpu-internalize-symbols"}; + + LldArgs.push_back("-mllvm"); + LldArgs.push_back( + Args.MakeArgString(llvm::Twine("-mcpu=") + JA.getOffloadingArch())); + + // Extract all the -m options + std::vector Features; + handleTargetFeaturesGroup(Args, Features, + options::OPT_m_amdgpu_Features_Group); + + // Add features to mattr such as cumode + std::string MAttrString = "-mattr="; + for (auto OneFeature : Features) { + MAttrString.append(Args.MakeArgString(OneFeature)); + if (OneFeature != Features.back()) + MAttrString.append(","); + } + if (!Features.empty()) + LldArgs.append({"-mllvm", Args.MakeArgString(MAttrString)}); + + for (const Arg *A : Args.filtered(options::OPT_mllvm)) { + LldArgs.append({"-mllvm", A->getValue(0)}); + } + + if (C.getDriver().isSaveTempsEnabled()) + LldArgs.push_back("-save-temps"); + + LldArgs.append({"-o", Output.getFilename()}); for (auto Input : Inputs) LldArgs.push_back(Input.getFilename()); const char *Lld = Args.MakeArgString(getToolChain().GetProgramPath("lld")); Index: clang/test/Driver/hip-save-temps.hip =================================================================== --- clang/test/Driver/hip-save-temps.hip +++ clang/test/Driver/hip-save-temps.hip @@ -54,7 +54,7 @@ // CHECK-NOT: "{{.*}}opt" // CHECK-NOT: "{{.*}}llc" // NORDC: {{.*lld.*}}"-o" "hip-save-temps-hip-amdgcn-amd-amdhsa-gfx900.out" -// RDCL: "{{.*lld.*}}" {{.*}} "-mllvm" "-amdgpu-internalize-symbols" +// RDCL: "{{.*lld.*}}" {{.*}} "-mllvm" "-amdgpu-internalize-symbols" {{.*}}"-save-temps" // RDCL-SAME: "-o" "a.out-hip-amdgcn-amd-amdhsa-gfx900" // RDCC: "{{.*clang.*}}" "-cc1" {{.*}} "-E" {{.*}} "-o" "hip-save-temps-host-x86_64-unknown-linux-gnu.cui" // RDCC: "{{.*clang.*}}" "-cc1" {{.*}} "-emit-llvm-bc" {{.*}} "-o" "hip-save-temps-host-x86_64-unknown-linux-gnu.bc" Index: clang/test/Driver/hip-toolchain-features.hip =================================================================== --- clang/test/Driver/hip-toolchain-features.hip +++ clang/test/Driver/hip-toolchain-features.hip @@ -2,36 +2,42 @@ // REQUIRES: x86-registered-target // REQUIRES: amdgpu-registered-target -// RUN: %clang -### -c -target x86_64-linux-gnu -fgpu-rdc \ +// RUN: %clang -### -target x86_64-linux-gnu -fgpu-rdc -nogpulib \ // RUN: --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 %s \ // RUN: -mxnack 2>&1 | FileCheck %s -check-prefix=XNACK -// RUN: %clang -### -c -target x86_64-linux-gnu -fgpu-rdc \ +// RUN: %clang -### -target x86_64-linux-gnu -fgpu-rdc -nogpulib \ // RUN: --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 %s \ // RUN: -mno-xnack 2>&1 | FileCheck %s -check-prefix=NOXNACK // XNACK: {{.*}}clang{{.*}}"-target-feature" "+xnack" +// XNACK: {{.*}}lld{{.*}}"-mllvm" "-mattr=+xnack" // NOXNACK: {{.*}}clang{{.*}}"-target-feature" "-xnack" +// NOXNACK: {{.*}}lld{{.*}}"-mllvm" "-mattr=-xnack" -// RUN: %clang -### -c -target x86_64-linux-gnu -fgpu-rdc \ +// RUN: %clang -### -target x86_64-linux-gnu -fgpu-rdc -nogpulib \ // RUN: --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 %s \ // RUN: -msram-ecc 2>&1 | FileCheck %s -check-prefix=SRAM -// RUN: %clang -### -c -target x86_64-linux-gnu -fgpu-rdc \ +// RUN: %clang -### -target x86_64-linux-gnu -fgpu-rdc -nogpulib \ // RUN: --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 %s \ // RUN: -mno-sram-ecc 2>&1 | FileCheck %s -check-prefix=NOSRAM // SRAM: {{.*}}clang{{.*}}"-target-feature" "+sram-ecc" +// SRAM: {{.*}}lld{{.*}}"-mllvm" "-mattr=+sram-ecc" // NOSRAM: {{.*}}clang{{.*}}"-target-feature" "-sram-ecc" +// NOSRAM: {{.*}}lld{{.*}}"-mllvm" "-mattr=-sram-ecc" -// RUN: %clang -### -c -target x86_64-linux-gnu -fgpu-rdc \ +// RUN: %clang -### -target x86_64-linux-gnu -fgpu-rdc -nogpulib \ // RUN: --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 %s \ // RUN: -mxnack -msram-ecc \ // RUN: 2>&1 | FileCheck %s -check-prefix=ALL3 -// RUN: %clang -### -c -target x86_64-linux-gnu -fgpu-rdc \ +// RUN: %clang -### -target x86_64-linux-gnu -fgpu-rdc -nogpulib \ // RUN: --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 %s \ // RUN: -mno-xnack -mno-sram-ecc \ // RUN: 2>&1 | FileCheck %s -check-prefix=NOALL3 // ALL3: {{.*}}clang{{.*}}"-target-feature" "+xnack" "-target-feature" "+sram-ecc" +// ALL3: {{.*}}lld{{.*}}"-mllvm" "-mattr=+xnack,+sram-ecc" // NOALL3: {{.*}}clang{{.*}}"-target-feature" "-xnack" "-target-feature" "-sram-ecc" +// NOALL3: {{.*}}lld{{.*}}"-mllvm" "-mattr=-xnack,-sram-ecc" Index: clang/test/Driver/hip-toolchain-mllvm.hip =================================================================== --- clang/test/Driver/hip-toolchain-mllvm.hip +++ clang/test/Driver/hip-toolchain-mllvm.hip @@ -7,20 +7,25 @@ // RUN: -mllvm -amdgpu-function-calls=0 \ // RUN: %s 2>&1 | FileCheck %s +// RUN: %clang -### -target x86_64-linux-gnu \ +// RUN: --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 \ +// RUN: -fgpu-rdc -mllvm -amdgpu-function-calls=0 \ +// RUN: %s 2>&1 | FileCheck -check-prefixes=CHECK,RDC %s + // CHECK: [[CLANG:".*clang.*"]] "-cc1" "-triple" "amdgcn-amd-amdhsa" // CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu" -// CHECK-SAME: "-emit-obj" // CHECK-SAME: {{.*}} "-target-cpu" "gfx803" // CHECK-SAME: {{.*}} "-mllvm" "-amdgpu-function-calls=0" {{.*}} // CHECK-NOT: {{".*opt"}} // CHECK-NOT: {{".*llc"}} +// RDC: [[LLD:".*lld.*"]] {{.*}} "-mllvm" "-amdgpu-function-calls=0" // CHECK: [[CLANG]] "-cc1" "-triple" "amdgcn-amd-amdhsa" // CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu" -// CHECK-SAME: "-emit-obj" // CHECK-SAME: {{.*}} "-target-cpu" "gfx900" // CHECK-SAME: {{.*}} "-mllvm" "-amdgpu-function-calls=0" {{.*}} // CHECK-NOT: {{".*opt"}} // CHECK-NOT: {{".*llc"}} +// RDC: [[LLD:".*lld.*"]] {{.*}} "-mllvm" "-amdgpu-function-calls=0" Index: clang/test/Driver/hip-toolchain-rdc-separate.hip =================================================================== --- clang/test/Driver/hip-toolchain-rdc-separate.hip +++ clang/test/Driver/hip-toolchain-rdc-separate.hip @@ -108,12 +108,14 @@ // LINK-NOT: ".*opt" // LINK-NOT: ".*llc" // LINK: {{".*lld.*"}} {{.*}} "-mllvm" "-amdgpu-internalize-symbols" +// LINK: "-mllvm" "-mcpu=gfx803" // LINK-SAME: "-o" "[[IMG_DEV1:.*.out]]" "[[A_BC1]]" "[[B_BC1]]" // LINK-NOT: "*.llvm-link" // LINK-NOT: ".*opt" // LINK-NOT: ".*llc" // LINK: {{".*lld.*"}} {{.*}} "-mllvm" "-amdgpu-internalize-symbols" +// LINK: "-mllvm" "-mcpu=gfx900" // LINK-SAME: "-o" "[[IMG_DEV2:.*.out]]" "[[A_BC2]]" "[[B_BC2]]" // LINK: [[BUNDLER:".*clang-offload-bundler"]] "-type=o" Index: clang/test/Driver/hip-toolchain-rdc.hip =================================================================== --- clang/test/Driver/hip-toolchain-rdc.hip +++ clang/test/Driver/hip-toolchain-rdc.hip @@ -54,6 +54,7 @@ // CHECK-NOT: ".*opt" // CHECK-NOT: ".*llc" // CHECK: {{".*lld.*"}} {{.*}} "-mllvm" "-amdgpu-internalize-symbols" +// CHECK-SAME: "-mllvm" "-mcpu=gfx803" // CHECK-SAME: "-o" "[[IMG_DEV1:.*.out]]" [[A_BC1]] [[B_BC1]] // generate image for device side path on gfx900 @@ -81,6 +82,7 @@ // CHECK-NOT: ".*opt" // CHECK-NOT: ".*llc" // CHECK: {{".*lld.*"}} {{.*}} "-mllvm" "-amdgpu-internalize-symbols" +// CHECK-SAME: "-mllvm" "-mcpu=gfx900" // CHECK-SAME: "-o" "[[IMG_DEV2:.*.out]]" [[A_BC2]] [[B_BC2]] // combine images generated into hip fat binary object