jhuber6 created this revision. jhuber6 added reviewers: jdoerfert, JonChesterfield, tra, yaxunl. Herald added a subscriber: inglorion. Herald added a project: All. jhuber6 requested review of this revision. Herald added subscribers: cfe-commits, MaskRay. Herald added a project: clang.
The new driver supports LTO for RDC-mode compilations. However, this was not correctly handled for non-LTO compilations. HIP can handle this as it is fed to `lld` which will perform the LTO itself. CUDA however would require every work which is wholly useless in non-RDC mode so it should report an error. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D135305 Files: clang/lib/Driver/Driver.cpp clang/lib/Driver/ToolChains/Clang.cpp clang/test/Driver/cuda-bindings.cu clang/test/Driver/hip-binding.hip Index: clang/test/Driver/hip-binding.hip =================================================================== --- clang/test/Driver/hip-binding.hip +++ clang/test/Driver/hip-binding.hip @@ -79,3 +79,24 @@ // SYNTAX-ONLY: "-cc1" "-triple" "amdgcn-amd-amdhsa"{{.*}}"-fsyntax-only" // SYNTAX-ONLY: "-cc1" "-triple" "amdgcn-amd-amdhsa"{{.*}}"-fsyntax-only" // SYNTAX-ONLY: "-cc1" "-triple" "x86_64-unknown-linux-gnu"{{.*}}"-fsyntax-only" + +// +// Test the bindings using the new driver in LTO-mode. +// +// RUN: %clang -### --target=x86_64-linux-gnu --offload-new-driver -ccc-print-bindings \ +// RUN: --offload-arch=gfx90a --offload-arch=gfx908 -foffload-lto -fgpu-rdc -c %s 2>&1 \ +// RUN: | FileCheck -check-prefix=LTO %s +// LTO: # "amdgcn-amd-amdhsa" - "clang", inputs: ["[[INPUT:.+]]"], output: "[[LTO_908:.+]]" +// LTO-NEXT: # "amdgcn-amd-amdhsa" - "clang", inputs: ["[[INPUT]]"], output: "[[LTO_90A:.+]]" + +// +// Check to ensure that we can use '-foffload' when not operating in RDC-mode. +// +// RUN: %clang -### --target=x86_64-linux-gnu -fno-gpu-rdc --offload-new-driver -ccc-print-bindings \ +// RUN: -foffload-lto --offload-arch=gfx90a --offload-arch=gfx908 -c %s 2>&1 \ +// RUN: | FileCheck -check-prefix=LTO-NO-RDC %s +// LTO-NO-RDC: # "amdgcn-amd-amdhsa" - "clang", inputs: ["[[INPUT:.+]]"], output: "[[LTO_908:.+]]" +// LTO-NO-RDC-NEXT: # "amdgcn-amd-amdhsa" - "AMDGCN::Linker", inputs: ["[[LTO_908]]"], output: "[[OBJ_908:.+]]" +// LTO-NO-RDC-NEXT: # "amdgcn-amd-amdhsa" - "clang", inputs: ["[[INPUT]]"], output: "[[LTO_90A:.+]]" +// LTO-NO-RDC-NEXT: # "amdgcn-amd-amdhsa" - "AMDGCN::Linker", inputs: ["[[LTO_90A]]"], output: "[[OBJ_90A:.+]]" +// LTO-NO-RDC-NEXT: # "amdgcn-amd-amdhsa" - "AMDGCN::Linker", inputs: ["[[OBJ_908]]", "[[OBJ_90A]]"], output: "[[HIPFB:.+]]" Index: clang/test/Driver/cuda-bindings.cu =================================================================== --- clang/test/Driver/cuda-bindings.cu +++ clang/test/Driver/cuda-bindings.cu @@ -234,3 +234,20 @@ // SAVE-TEMPS: "-cc1" "-triple" "nvptx64-nvidia-cuda"{{.*}}"-target-cpu" "sm_52" // SAVE-TEMPS: "-cc1" "-triple" "nvptx64-nvidia-cuda"{{.*}}"-target-cpu" "sm_70" // SAVE-TEMPS: "-cc1" "-triple" "powerpc64le-ibm-linux-gnu" + +// +// Test the bindings using the new driver in LTO-mode. +// +// RUN: %clang -### -target powerpc64le-ibm-linux-gnu --offload-new-driver -ccc-print-bindings \ +// RUN: --offload-arch=sm_70 --offload-arch=sm_52 -foffload-lto -fgpu-rdc -c %s 2>&1 \ +// RUN: | FileCheck -check-prefix=LTO %s +// LTO: # "nvptx64-nvidia-cuda" - "clang", inputs: ["[[INPUT:.+]]"], output: "[[LTO_52:.+]]" +// LTO-NEXT: # "nvptx64-nvidia-cuda" - "clang", inputs: ["[[INPUT]]"], output: "[[LTO_70:.+]]" + +// +// Check to ensure that we cannot use '-foffload' when not operating in RDC-mode. +// +// RUN: %clang -### -target powerpc64le-ibm-linux-gnu -fno-gpu-rdc --offload-new-driver \ +// RUN: -foffload-lto --offload-arch=sm_70 --offload-arch=sm_52 -c %s 2>&1 \ +// RUN: | FileCheck -check-prefix=LTO-NO-RDC %s +// LTO-NO-RDC: error: unsupported option '-foffload-lto' for language mode '-fno-gpu-rdc' Index: clang/lib/Driver/ToolChains/Clang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Clang.cpp +++ clang/lib/Driver/ToolChains/Clang.cpp @@ -4842,7 +4842,6 @@ CmdArgs.push_back("-emit-llvm-uselists"); if (IsUsingLTO) { - // Only AMDGPU supports device-side LTO. if (IsDeviceOffloadAction && !JA.isDeviceOffloading(Action::OFK_OpenMP) && !Args.hasFlag(options::OPT_offload_new_driver, options::OPT_no_offload_new_driver, false) && @@ -4852,6 +4851,12 @@ options::OPT_foffload_lto_EQ) ->getAsString(Args) << Triple.getTriple(); + } else if (Triple.isNVPTX() && !IsRDCMode) { + D.Diag(diag::err_drv_unsupported_opt_for_language_mode) + << Args.getLastArg(options::OPT_foffload_lto, + options::OPT_foffload_lto_EQ) + ->getAsString(Args) + << "-fno-gpu-rdc"; } else { assert(LTOMode == LTOK_Full || LTOMode == LTOK_Thin); CmdArgs.push_back(Args.MakeArgString( Index: clang/lib/Driver/Driver.cpp =================================================================== --- clang/lib/Driver/Driver.cpp +++ clang/lib/Driver/Driver.cpp @@ -4375,7 +4375,9 @@ // Compiling HIP in non-RDC mode requires linking each action individually. for (Action *&A : DeviceActions) { - if (A->getType() != types::TY_Object || Kind != Action::OFK_HIP || + if ((A->getType() != types::TY_Object && + A->getType() != types::TY_LTO_BC) || + Kind != Action::OFK_HIP || Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false)) continue; ActionList LinkerInput = {A};
Index: clang/test/Driver/hip-binding.hip =================================================================== --- clang/test/Driver/hip-binding.hip +++ clang/test/Driver/hip-binding.hip @@ -79,3 +79,24 @@ // SYNTAX-ONLY: "-cc1" "-triple" "amdgcn-amd-amdhsa"{{.*}}"-fsyntax-only" // SYNTAX-ONLY: "-cc1" "-triple" "amdgcn-amd-amdhsa"{{.*}}"-fsyntax-only" // SYNTAX-ONLY: "-cc1" "-triple" "x86_64-unknown-linux-gnu"{{.*}}"-fsyntax-only" + +// +// Test the bindings using the new driver in LTO-mode. +// +// RUN: %clang -### --target=x86_64-linux-gnu --offload-new-driver -ccc-print-bindings \ +// RUN: --offload-arch=gfx90a --offload-arch=gfx908 -foffload-lto -fgpu-rdc -c %s 2>&1 \ +// RUN: | FileCheck -check-prefix=LTO %s +// LTO: # "amdgcn-amd-amdhsa" - "clang", inputs: ["[[INPUT:.+]]"], output: "[[LTO_908:.+]]" +// LTO-NEXT: # "amdgcn-amd-amdhsa" - "clang", inputs: ["[[INPUT]]"], output: "[[LTO_90A:.+]]" + +// +// Check to ensure that we can use '-foffload' when not operating in RDC-mode. +// +// RUN: %clang -### --target=x86_64-linux-gnu -fno-gpu-rdc --offload-new-driver -ccc-print-bindings \ +// RUN: -foffload-lto --offload-arch=gfx90a --offload-arch=gfx908 -c %s 2>&1 \ +// RUN: | FileCheck -check-prefix=LTO-NO-RDC %s +// LTO-NO-RDC: # "amdgcn-amd-amdhsa" - "clang", inputs: ["[[INPUT:.+]]"], output: "[[LTO_908:.+]]" +// LTO-NO-RDC-NEXT: # "amdgcn-amd-amdhsa" - "AMDGCN::Linker", inputs: ["[[LTO_908]]"], output: "[[OBJ_908:.+]]" +// LTO-NO-RDC-NEXT: # "amdgcn-amd-amdhsa" - "clang", inputs: ["[[INPUT]]"], output: "[[LTO_90A:.+]]" +// LTO-NO-RDC-NEXT: # "amdgcn-amd-amdhsa" - "AMDGCN::Linker", inputs: ["[[LTO_90A]]"], output: "[[OBJ_90A:.+]]" +// LTO-NO-RDC-NEXT: # "amdgcn-amd-amdhsa" - "AMDGCN::Linker", inputs: ["[[OBJ_908]]", "[[OBJ_90A]]"], output: "[[HIPFB:.+]]" Index: clang/test/Driver/cuda-bindings.cu =================================================================== --- clang/test/Driver/cuda-bindings.cu +++ clang/test/Driver/cuda-bindings.cu @@ -234,3 +234,20 @@ // SAVE-TEMPS: "-cc1" "-triple" "nvptx64-nvidia-cuda"{{.*}}"-target-cpu" "sm_52" // SAVE-TEMPS: "-cc1" "-triple" "nvptx64-nvidia-cuda"{{.*}}"-target-cpu" "sm_70" // SAVE-TEMPS: "-cc1" "-triple" "powerpc64le-ibm-linux-gnu" + +// +// Test the bindings using the new driver in LTO-mode. +// +// RUN: %clang -### -target powerpc64le-ibm-linux-gnu --offload-new-driver -ccc-print-bindings \ +// RUN: --offload-arch=sm_70 --offload-arch=sm_52 -foffload-lto -fgpu-rdc -c %s 2>&1 \ +// RUN: | FileCheck -check-prefix=LTO %s +// LTO: # "nvptx64-nvidia-cuda" - "clang", inputs: ["[[INPUT:.+]]"], output: "[[LTO_52:.+]]" +// LTO-NEXT: # "nvptx64-nvidia-cuda" - "clang", inputs: ["[[INPUT]]"], output: "[[LTO_70:.+]]" + +// +// Check to ensure that we cannot use '-foffload' when not operating in RDC-mode. +// +// RUN: %clang -### -target powerpc64le-ibm-linux-gnu -fno-gpu-rdc --offload-new-driver \ +// RUN: -foffload-lto --offload-arch=sm_70 --offload-arch=sm_52 -c %s 2>&1 \ +// RUN: | FileCheck -check-prefix=LTO-NO-RDC %s +// LTO-NO-RDC: error: unsupported option '-foffload-lto' for language mode '-fno-gpu-rdc' Index: clang/lib/Driver/ToolChains/Clang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Clang.cpp +++ clang/lib/Driver/ToolChains/Clang.cpp @@ -4842,7 +4842,6 @@ CmdArgs.push_back("-emit-llvm-uselists"); if (IsUsingLTO) { - // Only AMDGPU supports device-side LTO. if (IsDeviceOffloadAction && !JA.isDeviceOffloading(Action::OFK_OpenMP) && !Args.hasFlag(options::OPT_offload_new_driver, options::OPT_no_offload_new_driver, false) && @@ -4852,6 +4851,12 @@ options::OPT_foffload_lto_EQ) ->getAsString(Args) << Triple.getTriple(); + } else if (Triple.isNVPTX() && !IsRDCMode) { + D.Diag(diag::err_drv_unsupported_opt_for_language_mode) + << Args.getLastArg(options::OPT_foffload_lto, + options::OPT_foffload_lto_EQ) + ->getAsString(Args) + << "-fno-gpu-rdc"; } else { assert(LTOMode == LTOK_Full || LTOMode == LTOK_Thin); CmdArgs.push_back(Args.MakeArgString( Index: clang/lib/Driver/Driver.cpp =================================================================== --- clang/lib/Driver/Driver.cpp +++ clang/lib/Driver/Driver.cpp @@ -4375,7 +4375,9 @@ // Compiling HIP in non-RDC mode requires linking each action individually. for (Action *&A : DeviceActions) { - if (A->getType() != types::TY_Object || Kind != Action::OFK_HIP || + if ((A->getType() != types::TY_Object && + A->getType() != types::TY_LTO_BC) || + Kind != Action::OFK_HIP || Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false)) continue; ActionList LinkerInput = {A};
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits