Index: clang/lib/Driver/ToolChains/Clang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Clang.cpp +++ clang/lib/Driver/ToolChains/Clang.cpp @@ -5692,6 +5692,8 @@ } if (IsCuda || IsHIP) { + if (Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false)) + CmdArgs.push_back("-fgpu-rdc"); if (Args.hasFlag(options::OPT_fgpu_defer_diag, options::OPT_fno_gpu_defer_diag, false)) CmdArgs.push_back("-fgpu-defer-diag"); Index: clang/lib/Driver/ToolChains/Cuda.cpp =================================================================== --- clang/lib/Driver/ToolChains/Cuda.cpp +++ clang/lib/Driver/ToolChains/Cuda.cpp @@ -689,10 +689,6 @@ if (DriverArgs.hasFlag(options::OPT_fcuda_approx_transcendentals, options::OPT_fno_cuda_approx_transcendentals, false)) CC1Args.push_back("-fcuda-approx-transcendentals"); - - if (DriverArgs.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, - false)) - CC1Args.push_back("-fgpu-rdc"); } if (DriverArgs.hasArg(options::OPT_nogpulib)) Index: clang/lib/Driver/ToolChains/HIP.cpp =================================================================== --- clang/lib/Driver/ToolChains/HIP.cpp +++ clang/lib/Driver/ToolChains/HIP.cpp @@ -261,10 +261,8 @@ options::OPT_fno_cuda_approx_transcendentals, false)) CC1Args.push_back("-fcuda-approx-transcendentals"); - if (DriverArgs.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, - false)) - CC1Args.push_back("-fgpu-rdc"); - else + if (!DriverArgs.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, + false)) CC1Args.append({"-mllvm", "-amdgpu-internalize-symbols"}); StringRef MaxThreadsPerBlock = Index: clang/test/Driver/hip-rdc-device-only.hip =================================================================== --- clang/test/Driver/hip-rdc-device-only.hip +++ clang/test/Driver/hip-rdc-device-only.hip @@ -52,9 +52,10 @@ // EMITBC-SAME: "-emit-llvm-bc" // EMITLL-SAME: "-emit-llvm" // COMMON-SAME: {{.*}} "-main-file-name" "a.cu" -// COMMON-SAME: "-fcuda-is-device" "-fgpu-rdc" "-fcuda-allow-variadic-functions" "-fvisibility" "hidden" +// COMMON-SAME: "-fcuda-is-device" "-fcuda-allow-variadic-functions" "-fvisibility" "hidden" // COMMON-SAME: "-fapply-global-visibility-to-externs" // COMMON-SAME: "-target-cpu" "gfx803" +// COMMON-SAME: "-fgpu-rdc" // EMITBC-SAME: {{.*}} "-o" {{"a.*bc"}} "-x" "hip" // EMITLL-SAME: {{.*}} "-o" {{"a.*ll"}} "-x" "hip" // CHECK-SAME: {{.*}} {{".*a.cu"}} @@ -64,9 +65,10 @@ // EMITBC-SAME: "-emit-llvm-bc" // EMITLL-SAME: "-emit-llvm" // COMMON-SAME: {{.*}} "-main-file-name" "a.cu" -// COMMON-SAME: "-fcuda-is-device" "-fgpu-rdc" "-fcuda-allow-variadic-functions" "-fvisibility" "hidden" +// COMMON-SAME: "-fcuda-is-device" "-fcuda-allow-variadic-functions" "-fvisibility" "hidden" // COMMON-SAME: "-fapply-global-visibility-to-externs" // COMMON-SAME: "-target-cpu" "gfx900" +// COMMON-SAME: "-fgpu-rdc" // EMITBC-SAME: {{.*}} "-o" {{"a.*bc"}} "-x" "hip" // EMITLL-SAME: {{.*}} "-o" {{"a.*ll"}} "-x" "hip" // COMMON-SAME: {{.*}} {{".*a.cu"}} @@ -76,9 +78,10 @@ // EMITBC-SAME: "-emit-llvm-bc" // EMITLL-SAME: "-emit-llvm" // COMMON-SAME: {{.*}} "-main-file-name" "b.hip" -// COMMON-SAME: "-fcuda-is-device" "-fgpu-rdc" "-fcuda-allow-variadic-functions" "-fvisibility" "hidden" +// COMMON-SAME: "-fcuda-is-device" "-fcuda-allow-variadic-functions" "-fvisibility" "hidden" // COMMON-SAME: "-fapply-global-visibility-to-externs" // COMMON-SAME: "-target-cpu" "gfx803" +// COMMON-SAME: "-fgpu-rdc" // EMITBC-SAME: {{.*}} "-o" {{"b.*bc"}} "-x" "hip" // EMITLL-SAME: {{.*}} "-o" {{"b.*ll"}} "-x" "hip" // COMMON-SAME: {{.*}} {{".*b.hip"}} @@ -88,9 +91,10 @@ // EMITBC-SAME: "-emit-llvm-bc" // EMITLL-SAME: "-emit-llvm" // COMMON-SAME: {{.*}} "-main-file-name" "b.hip" -// COMMON-SAME: "-fcuda-is-device" "-fgpu-rdc" "-fcuda-allow-variadic-functions" "-fvisibility" "hidden" +// COMMON-SAME: "-fcuda-is-device" "-fcuda-allow-variadic-functions" "-fvisibility" "hidden" // COMMON-SAME: "-fapply-global-visibility-to-externs" // COMMON-SAME: "-target-cpu" "gfx900" +// COMMON-SAME: "-fgpu-rdc" // EMITBC-SAME: {{.*}} "-o" {{"b.*bc"}} "-x" "hip" // EMITLL-SAME: {{.*}} "-o" {{"b.*ll"}} "-x" "hip" // COMMON-SAME: {{.*}} {{".*b.hip"}} 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 @@ -16,10 +16,11 @@ // CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu" // CHECK-SAME: "-emit-llvm-bc" // CHECK-SAME: {{.*}} "-main-file-name" "a.cu" -// CHECK-SAME: "-fcuda-is-device" "-fgpu-rdc" "-fcuda-allow-variadic-functions" "-fvisibility" "hidden" +// CHECK-SAME: "-fcuda-is-device" "-fcuda-allow-variadic-functions" "-fvisibility" "hidden" // CHECK-SAME: "-fapply-global-visibility-to-externs" // CHECK-SAME: "{{.*}}lib1.bc" "{{.*}}lib2.bc" // CHECK-SAME: "-target-cpu" "gfx803" +// CHECK-SAME: "-fgpu-rdc" // CHECK-SAME: {{.*}} "-o" "[[A_BC1:.*bc]]" "-x" "hip" // CHECK-SAME: {{.*}} [[A_SRC:".*a.cu"]] @@ -27,9 +28,10 @@ // CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu" // CHECK-SAME: "-emit-llvm-bc" // CHECK-SAME: {{.*}} "-main-file-name" "a.cu" -// CHECK-SAME: "-fcuda-is-device" "-fgpu-rdc" +// CHECK-SAME: "-fcuda-is-device" // CHECK-SAME: "{{.*}}lib1.bc" "{{.*}}lib2.bc" // CHECK-SAME: "-target-cpu" "gfx900" +// CHECK-SAME: "-fgpu-rdc" // CHECK-SAME: {{.*}} "-o" "[[A_BC2:.*bc]]" "-x" "hip" // CHECK-SAME: {{.*}} [[A_SRC]] @@ -37,6 +39,7 @@ // CHECK-SAME: "-aux-triple" "amdgcn-amd-amdhsa" // CHECK-SAME: "-emit-obj" // CHECK-SAME: {{.*}} "-main-file-name" "a.cu" +// CHECK-SAME: "-fgpu-rdc" // CHECK-SAME: {{.*}} "-o" "[[A_OBJ_HOST:.*o]]" "-x" "hip" // CHECK-SAME: {{.*}} [[A_SRC]] @@ -48,10 +51,11 @@ // CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu" // CHECK-SAME: "-emit-llvm-bc" // CHECK-SAME: {{.*}} "-main-file-name" "b.hip" -// CHECK-SAME: "-fcuda-is-device" "-fgpu-rdc" "-fcuda-allow-variadic-functions" "-fvisibility" "hidden" +// CHECK-SAME: "-fcuda-is-device" "-fcuda-allow-variadic-functions" "-fvisibility" "hidden" // CHECK-SAME: "-fapply-global-visibility-to-externs" // CHECK-SAME: "{{.*}}lib1.bc" "{{.*}}lib2.bc" // CHECK-SAME: "-target-cpu" "gfx803" +// CHECK-SAME: "-fgpu-rdc" // CHECK-SAME: {{.*}} "-o" "[[B_BC1:.*bc]]" "-x" "hip" // CHECK-SAME: {{.*}} [[B_SRC:".*b.hip"]] @@ -59,9 +63,10 @@ // CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu" // CHECK-SAME: "-emit-llvm-bc" // CHECK-SAME: {{.*}} "-main-file-name" "b.hip" -// CHECK-SAME: "-fcuda-is-device" "-fgpu-rdc" +// CHECK-SAME: "-fcuda-is-device" // CHECK-SAME: "{{.*}}lib1.bc" "{{.*}}lib2.bc" // CHECK-SAME: "-target-cpu" "gfx900" +// CHECK-SAME: "-fgpu-rdc" // CHECK-SAME: {{.*}} "-o" "[[B_BC2:.*bc]]" "-x" "hip" // CHECK-SAME: {{.*}} [[B_SRC]] @@ -69,6 +74,7 @@ // CHECK-SAME: "-aux-triple" "amdgcn-amd-amdhsa" // CHECK-SAME: "-emit-obj" // CHECK-SAME: {{.*}} "-main-file-name" "b.hip" +// CHECK-SAME: "-fgpu-rdc" // CHECK-SAME: {{.*}} "-o" "[[B_OBJ_HOST:.*o]]" "-x" "hip" // CHECK-SAME: {{.*}} [[B_SRC]] Index: clang/test/Driver/hip-toolchain-rdc-static-lib.hip =================================================================== --- clang/test/Driver/hip-toolchain-rdc-static-lib.hip +++ clang/test/Driver/hip-toolchain-rdc-static-lib.hip @@ -15,6 +15,7 @@ // CHECK-SAME: "-aux-triple" "amdgcn-amd-amdhsa" // CHECK-SAME: "-emit-obj" // CHECK-SAME: {{.*}} "-main-file-name" "a.cu" +// CHECK-SAME: "-fgpu-rdc" // CHECK-SAME: {{.*}} "-o" [[A_OBJ_HOST:".*o"]] "-x" "hip" // CHECK-SAME: {{.*}} [[A_SRC:".*a.cu"]] @@ -22,6 +23,7 @@ // CHECK-SAME: "-aux-triple" "amdgcn-amd-amdhsa" // CHECK-SAME: "-emit-obj" // CHECK-SAME: {{.*}} "-main-file-name" "b.hip" +// CHECK-SAME: "-fgpu-rdc" // CHECK-SAME: {{.*}} "-o" [[B_OBJ_HOST:".*o"]] "-x" "hip" // CHECK-SAME: {{.*}} [[B_SRC:".*b.hip"]] @@ -30,8 +32,9 @@ // CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu" // CHECK-SAME: "-emit-llvm-bc" // CHECK-SAME: {{.*}} "-main-file-name" "a.cu" -// CHECK-SAME: "-fcuda-is-device" "-fgpu-rdc" +// CHECK-SAME: "-fcuda-is-device" // CHECK-SAME: "-target-cpu" "gfx803" +// CHECK-SAME: "-fgpu-rdc" // CHECK-SAME: {{.*}} "-o" [[A_BC1:".*bc"]] "-x" "hip" // CHECK-SAME: {{.*}} [[A_SRC]] @@ -39,8 +42,9 @@ // CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu" // CHECK-SAME: "-emit-llvm-bc" // CHECK-SAME: {{.*}} "-main-file-name" "b.hip" -// CHECK-SAME: "-fcuda-is-device" "-fgpu-rdc" +// CHECK-SAME: "-fcuda-is-device" // CHECK-SAME: "-target-cpu" "gfx803" +// CHECK-SAME: "-fgpu-rdc" // CHECK-SAME: {{.*}} "-o" [[B_BC1:".*bc"]] "-x" "hip" // CHECK-SAME: {{.*}} [[B_SRC]] @@ -56,8 +60,9 @@ // CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu" // CHECK-SAME: "-emit-llvm-bc" // CHECK-SAME: {{.*}} "-main-file-name" "a.cu" -// CHECK-SAME: "-fcuda-is-device" "-fgpu-rdc" +// CHECK-SAME: "-fcuda-is-device" // CHECK-SAME: "-target-cpu" "gfx900" +// CHECK-SAME: "-fgpu-rdc" // CHECK-SAME: {{.*}} "-o" [[A_BC2:".*bc"]] "-x" "hip" // CHECK-SAME: {{.*}} [[A_SRC]] @@ -65,8 +70,9 @@ // CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu" // CHECK-SAME: "-emit-llvm-bc" // CHECK-SAME: {{.*}} "-main-file-name" "b.hip" -// CHECK-SAME: "-fcuda-is-device" "-fgpu-rdc" +// CHECK-SAME: "-fcuda-is-device" // CHECK-SAME: "-target-cpu" "gfx900" +// CHECK-SAME: "-fgpu-rdc" // CHECK-SAME: {{.*}} "-o" [[B_BC2:".*bc"]] "-x" "hip" // CHECK-SAME: {{.*}} [[B_SRC]] Index: clang/test/Driver/hip-toolchain-rdc.hip =================================================================== --- clang/test/Driver/hip-toolchain-rdc.hip +++ clang/test/Driver/hip-toolchain-rdc.hip @@ -21,6 +21,7 @@ // CHECK-SAME: "-aux-triple" "amdgcn-amd-amdhsa" // CHECK-SAME: "-emit-obj" // CHECK-SAME: {{.*}} "-main-file-name" "a.cu" +// CHECK-SAME: "-fgpu-rdc" // CHECK-SAME: {{.*}} "-o" [[A_OBJ_HOST:".*o"]] "-x" "hip" // CHECK-SAME: {{.*}} [[A_SRC:".*a.cu"]] @@ -28,6 +29,7 @@ // CHECK-SAME: "-aux-triple" "amdgcn-amd-amdhsa" // CHECK-SAME: "-emit-obj" // CHECK-SAME: {{.*}} "-main-file-name" "b.hip" +// CHECK-SAME: "-fgpu-rdc" // CHECK-SAME: {{.*}} "-o" [[B_OBJ_HOST:".*o"]] "-x" "hip" // CHECK-SAME: {{.*}} [[B_SRC:".*b.hip"]] @@ -36,10 +38,11 @@ // CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu" // CHECK-SAME: "-emit-llvm-bc" // CHECK-SAME: {{.*}} "-main-file-name" "a.cu" -// CHECK-SAME: "-fcuda-is-device" "-fgpu-rdc" "-fcuda-allow-variadic-functions" "-fvisibility" "hidden" +// CHECK-SAME: "-fcuda-is-device" "-fcuda-allow-variadic-functions" "-fvisibility" "hidden" // CHECK-SAME: "-fapply-global-visibility-to-externs" // CHECK-SAME: "{{.*}}lib1.bc" "{{.*}}lib2.bc" // CHECK-SAME: "-target-cpu" "gfx803" +// CHECK-SAME: "-fgpu-rdc" // CHECK-SAME: {{.*}} "-o" [[A_BC1:".*bc"]] "-x" "hip" // CHECK-SAME: {{.*}} [[A_SRC]] @@ -47,10 +50,11 @@ // CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu" // CHECK-SAME: "-emit-llvm-bc" // CHECK-SAME: {{.*}} "-main-file-name" "b.hip" -// CHECK-SAME: "-fcuda-is-device" "-fgpu-rdc" "-fcuda-allow-variadic-functions" "-fvisibility" "hidden" +// CHECK-SAME: "-fcuda-is-device" "-fcuda-allow-variadic-functions" "-fvisibility" "hidden" // CHECK-SAME: "-fapply-global-visibility-to-externs" // CHECK-SAME: "{{.*}}lib1.bc" "{{.*}}lib2.bc" // CHECK-SAME: "-target-cpu" "gfx803" +// CHECK-SAME: "-fgpu-rdc" // CHECK-SAME: {{.*}} "-o" [[B_BC1:".*bc"]] "-x" "hip" // CHECK-SAME: {{.*}} [[B_SRC]] @@ -66,7 +70,7 @@ // CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu" // CHECK-SAME: "-emit-llvm-bc" // CHECK-SAME: {{.*}} "-main-file-name" "a.cu" -// CHECK-SAME: "-fcuda-is-device" "-fgpu-rdc" +// CHECK-SAME: "-fcuda-is-device" // CHECK-SAME: "{{.*}}lib1.bc" "{{.*}}lib2.bc" // CHECK-SAME: "-target-cpu" "gfx900" // CHECK-SAME: {{.*}} "-o" [[A_BC2:".*bc"]] "-x" "hip" @@ -76,9 +80,10 @@ // CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu" // CHECK-SAME: "-emit-llvm-bc" // CHECK-SAME: {{.*}} "-main-file-name" "b.hip" -// CHECK-SAME: "-fcuda-is-device" "-fgpu-rdc" +// CHECK-SAME: "-fcuda-is-device" // CHECK-SAME: "{{.*}}lib1.bc" "{{.*}}lib2.bc" // CHECK-SAME: "-target-cpu" "gfx900" +// CHECK-SAME: "-fgpu-rdc" // CHECK-SAME: {{.*}} "-o" [[B_BC2:".*bc"]] "-x" "hip" // CHECK-SAME: {{.*}} [[B_SRC]]