llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-amdgpu

Author: Joseph Huber (jhuber6)

<details>
<summary>Changes</summary>

Summary:
The 'new' offloading driver is the unified set of steps to produce
merged host and device output. OpenMP offloading has used it by default
since Clang 13, CUDA since Clang 21, and HIP / SYCL since Clang 23. The
support has matured in the 23 release and should now cover the remaining
use-cases.

This PR completely removes the support so we stop needing to support
both when making updates to the driver.


---

Patch is 299.81 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/211924.diff


72 Files Affected:

- (modified) clang/docs/UsersManual.md (+2-2) 
- (modified) clang/include/clang/Basic/LangOptions.def (-1) 
- (modified) clang/include/clang/Options/Options.td (+5-6) 
- (modified) clang/lib/CodeGen/CGCUDANV.cpp (+1-2) 
- (modified) clang/lib/Driver/Driver.cpp (+25-1046) 
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+3-14) 
- (modified) clang/lib/Driver/ToolChains/Cuda.cpp (+1-3) 
- (modified) clang/lib/Driver/ToolChains/HIPSPV.cpp (-10) 
- (modified) clang/lib/Driver/ToolChains/HIPSPV.h (-3) 
- (modified) clang/test/CodeGenCUDA/anon-ns.cu (+7-6) 
- (modified) clang/test/CodeGenCUDA/device-stub.cu (-49) 
- (modified) clang/test/CodeGenCUDA/device-var-linkage.cu (+18-9) 
- (modified) clang/test/CodeGenCUDA/managed-var.cu (+11-7) 
- (modified) clang/test/CodeGenCUDA/offloading-entries.cu (+5-5) 
- (modified) clang/test/CodeGenCUDA/static-device-var-rdc.cu (+13-12) 
- (modified) clang/test/CodeGenHIP/offload-pgo-sections.hip (+1-1) 
- (modified) clang/test/Driver/amdgpu-hip-system-arch.c (-6) 
- (modified) clang/test/Driver/cuda-bad-arch.cu (-8) 
- (modified) clang/test/Driver/cuda-bindings.cu (+6-33) 
- (modified) clang/test/Driver/cuda-external-tools.cu (-29) 
- (modified) clang/test/Driver/cuda-openmp-driver.cu (+4-4) 
- (modified) clang/test/Driver/cuda-phases.cu (+5-216) 
- (modified) clang/test/Driver/ftime-trace-offload.cpp (-5) 
- (modified) clang/test/Driver/gpu-libc.c (+1-1) 
- (modified) clang/test/Driver/hip-binding.hip (+6-49) 
- (modified) clang/test/Driver/hip-code-object-version.hip (-8) 
- (removed) clang/test/Driver/hip-cuid-hash.hip (-38) 
- (modified) clang/test/Driver/hip-cuid.hip (+1-106) 
- (modified) clang/test/Driver/hip-dependent-options.hip (+2-14) 
- (removed) clang/test/Driver/hip-device-compile.hip (-144) 
- (removed) clang/test/Driver/hip-link-bc-to-bc.hip (-33) 
- (removed) clang/test/Driver/hip-link-bundle-archive.hip (-86) 
- (removed) clang/test/Driver/hip-link-save-temps.hip (-49) 
- (removed) clang/test/Driver/hip-link-shared-library.hip (-15) 
- (removed) clang/test/Driver/hip-link-static-library.hip (-34) 
- (removed) clang/test/Driver/hip-offload-compress-zlib.hip (-44) 
- (modified) clang/test/Driver/hip-offload-compress-zstd.hip (+2-43) 
- (modified) clang/test/Driver/hip-options.hip (+7-7) 
- (removed) clang/test/Driver/hip-output-file-name.hip (-82) 
- (removed) clang/test/Driver/hip-partial-link.hip (-97) 
- (modified) clang/test/Driver/hip-phases.hip (+8-599) 
- (removed) clang/test/Driver/hip-rdc-device-only.hip (-184) 
- (modified) clang/test/Driver/hip-save-temps.hip (-66) 
- (modified) clang/test/Driver/hip-spirv-backend-bindings.c (+6-6) 
- (modified) clang/test/Driver/hip-spirv-backend-opt.c (+8-8) 
- (modified) clang/test/Driver/hip-spirv-backend-phases.c (+6-6) 
- (modified) clang/test/Driver/hip-spirv-translator-new-driver.c (+2-2) 
- (removed) clang/test/Driver/hip-target-id.hip (-66) 
- (removed) clang/test/Driver/hip-temps-linux.hip (-18) 
- (removed) clang/test/Driver/hip-temps-windows.hip (-18) 
- (removed) clang/test/Driver/hip-toolchain-features.hip (-73) 
- (modified) clang/test/Driver/hip-toolchain-no-rdc.hip (+3-67) 
- (removed) clang/test/Driver/hip-toolchain-rdc-flto-partitions.hip (-35) 
- (removed) clang/test/Driver/hip-toolchain-rdc-separate.hip (-157) 
- (removed) clang/test/Driver/hip-toolchain-rdc-static-lib.hip (-98) 
- (modified) clang/test/Driver/hip-toolchain-rdc.hip (+1-188) 
- (removed) clang/test/Driver/hip-unbundle-preproc.hipi (-27) 
- (modified) clang/test/Driver/hipspv-link-static-library.hip (+1-26) 
- (modified) clang/test/Driver/hipspv-pass-plugin.hip (-18) 
- (modified) clang/test/Driver/hipspv-toolchain-rdc-separate.hip (+2-2) 
- (modified) clang/test/Driver/hipspv-toolchain-rdc.hip (+1-60) 
- (modified) clang/test/Driver/hipspv-toolchain.hip (+1-27) 
- (removed) clang/test/Driver/lto.cu (-71) 
- (modified) clang/test/Driver/nvptx-cuda-system-arch.c (-6) 
- (added) clang/test/Driver/offload-new-driver-deprecated.c (+15) 
- (modified) clang/test/Driver/sycl-offload-jit.cpp (+1-1) 
- (removed) clang/test/Driver/thinlto.cu (-25) 
- (modified) clang/test/OpenMP/openmp_offload_weak_vtables.cpp (+1-1) 
- (modified) clang/unittests/Tooling/ToolingTest.cpp (+3-3) 
- (modified) libc/docs/gpu/using.rst (+4-4) 
- (modified) openmp/docs/CommandLineArgumentReference.rst (+2-2) 
- (modified) openmp/docs/SupportAndFAQ.rst (+3-5) 


``````````diff
diff --git a/clang/docs/UsersManual.md b/clang/docs/UsersManual.md
index 54891619f1924..f6e7c67b3ee63 100644
--- a/clang/docs/UsersManual.md
+++ b/clang/docs/UsersManual.md
@@ -6164,7 +6164,7 @@ Execute `clang-cl /?` to see a list of supported options:
 >   -no-hip-rt              Do not link against HIP runtime libraries
 >   --no-offload-arch=<value>
 >                           Remove CUDA/HIP offloading device architecture 
 > (e.g. sm_35, gfx906) from the list of devices to compile for. 'all' resets 
 > the list to its default value.
->   --no-offload-new-driver Don't Use the new driver for offloading 
compilation.
+>   --no-offload-new-driver Deprecated; the legacy offloading driver has been 
removed.
 >   --no-offloadlib         Do not link device library for CUDA/HIP/SYCL 
 > device compilation
 >   --no-wasm-opt           Disable the wasm-opt optimizer
 >   -nobuiltininc           Disable builtin #include directories only
@@ -6179,7 +6179,7 @@ Execute `clang-cl /?` to see a list of supported options:
 >   --offload-host-device   Compile for both the offloading host and device 
 > (default).
 >   --offload-host-only     Only compile for the offloading host.
 >   --offload-jobs=<value>  Specify the number of threads to use for device 
 > offloading tasks during compilation. Can be a positive integer or the string 
 > 'jobserver' to use the make-style jobserver from the environment.
->   --offload-new-driver    Use the new driver for offloading compilation.
+>   --offload-new-driver    Deprecated; the new driver is always used for 
offloading compilation.
 >   --offload-targets=<value>
 >                           Specify a list of target architectures to use for 
 > offloading.
 >   --offloadlib            Link device libraries for GPU device compilation
diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 3d63b9677e4df..002667e5c6c5c 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -261,7 +261,6 @@ LANGOPT(GPUAllowDeviceInit, 1, 0, NotCompatible, "allowing 
device side global in
 LANGOPT(GPUMaxThreadsPerBlock, 32, 1024, NotCompatible, "default max threads 
per block for kernel launch bounds for HIP")
 LANGOPT(GPUDeferDiag, 1, 0, NotCompatible, "defer host/device related 
diagnostic messages for CUDA/HIP")
 LANGOPT(GPUExcludeWrongSideOverloads, 1, 0, NotCompatible, "always exclude 
wrong side overloads in overloading resolution for CUDA/HIP")
-LANGOPT(OffloadingNewDriver, 1, 0, NotCompatible, "use the new driver for 
generating offloading code.")
 LANGOPT(OffloadViaLLVM, 1, 0, NotCompatible, "target LLVM/Offload as portable 
offloading runtime.")
 
 LANGOPT(SYCLIsDevice      , 1, 0, NotCompatible, "Generate code for SYCL 
device")
diff --git a/clang/include/clang/Options/Options.td 
b/clang/include/clang/Options/Options.td
index 669b6e64725c9..bd3540c9098c0 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -1268,10 +1268,10 @@ def no_offload_arch_EQ : CommaJoined<["--"], 
"no-offload-arch=">,
 
 def offload_new_driver : Flag<["--"], "offload-new-driver">,
   Visibility<[ClangOption, CC1Option]>, Group<f_Group>,
-  MarshallingInfoFlag<LangOpts<"OffloadingNewDriver">>, HelpText<"Use the new 
driver for offloading compilation.">;
+  HelpText<"Deprecated; the new driver is always used for offloading 
compilation.">;
 def no_offload_new_driver : Flag<["--"], "no-offload-new-driver">,
   Visibility<[ClangOption, CC1Option]>, Group<f_Group>,
-  HelpText<"Don't Use the new driver for offloading compilation.">;
+  HelpText<"Deprecated; the legacy offloading driver has been removed.">;
 
 def offload_device_only : Flag<["--"], "offload-device-only">,
   Visibility<[ClangOption, FlangOption]>,
@@ -4308,11 +4308,10 @@ defm openmp_optimistic_collapse : 
BoolFOption<"openmp-optimistic-collapse",
   NegFlag<SetFalse>, BothFlags<[NoArgumentUnused, HelpHidden], []>>;
 def static_openmp: Flag<["-"], "static-openmp">,
   HelpText<"Use the static host OpenMP runtime while linking.">;
-def fopenmp_new_driver : Flag<["-"], "fopenmp-new-driver">, 
Flags<[HelpHidden]>,
-  HelpText<"Use the new driver for OpenMP offloading.">;
+def fopenmp_new_driver : Flag<["-"], "fopenmp-new-driver">,
+  Flags<[HelpHidden]>, Alias<offload_new_driver>;
 def fno_openmp_new_driver : Flag<["-"], "fno-openmp-new-driver">,
-  Flags<[HelpHidden]>,
-  HelpText<"Don't use the new driver for OpenMP offloading.">;
+  Flags<[HelpHidden]>, Alias<no_offload_new_driver>;
 def fno_optimize_sibling_calls : Flag<["-"], "fno-optimize-sibling-calls">, 
Group<f_Group>,
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"Disable tail call optimization, keeping the call stack accurate">,
diff --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index 416ed935c1b30..89135e7d84a4d 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -1479,8 +1479,7 @@ llvm::Function *CGNVCUDARuntime::finalizeModule() {
     }
     return nullptr;
   }
-  if (CGM.getLangOpts().OffloadViaLLVM ||
-      (CGM.getLangOpts().OffloadingNewDriver && RelocatableDeviceCode))
+  if (CGM.getLangOpts().OffloadViaLLVM || RelocatableDeviceCode)
     createOffloadingEntries();
   else
     return makeModuleCtorFunction();
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index e606cdc4c1cf8..0408d6dd60c40 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -3306,990 +3306,6 @@ void Driver::BuildInputs(const ToolChain &TC, 
DerivedArgList &Args,
   }
 }
 
-namespace {
-/// Provides a convenient interface for different programming models to 
generate
-/// the required device actions.
-class OffloadingActionBuilder final {
-  /// Flag used to trace errors in the builder.
-  bool IsValid = false;
-
-  /// The compilation that is using this builder.
-  Compilation &C;
-
-  /// Map between an input argument and the offload kinds used to process it.
-  std::map<const Arg *, unsigned> InputArgToOffloadKindMap;
-
-  /// Map between a host action and its originating input argument.
-  std::map<Action *, const Arg *> HostActionToInputArgMap;
-
-  /// Builder interface. It doesn't build anything or keep any state.
-  class DeviceActionBuilder {
-  public:
-    typedef const llvm::SmallVectorImpl<phases::ID> PhasesTy;
-
-    enum ActionBuilderReturnCode {
-      // The builder acted successfully on the current action.
-      ABRT_Success,
-      // The builder didn't have to act on the current action.
-      ABRT_Inactive,
-      // The builder was successful and requested the host action to not be
-      // generated.
-      ABRT_Ignore_Host,
-    };
-
-  protected:
-    /// Compilation associated with this builder.
-    Compilation &C;
-
-    /// Tool chains associated with this builder. The same programming
-    /// model may have associated one or more tool chains.
-    /// There should be one entry for each TargetID.
-    SmallVector<const ToolChain *, 2> ToolChains;
-    const ToolChain *FatBinaryToolChain = nullptr;
-
-    /// The derived arguments associated with this builder.
-    DerivedArgList &Args;
-
-    /// The inputs associated with this builder.
-    const InputList &Inputs;
-
-    /// The associated offload kind.
-    Action::OffloadKind AssociatedOffloadKind = Action::OFK_None;
-
-  public:
-    DeviceActionBuilder(Compilation &C, DerivedArgList &Args,
-                        const InputList &Inputs,
-                        Action::OffloadKind AssociatedOffloadKind)
-        : C(C), Args(Args), Inputs(Inputs),
-          AssociatedOffloadKind(AssociatedOffloadKind) {}
-    virtual ~DeviceActionBuilder() {}
-
-    /// Fill up the array \a DA with all the device dependences that should be
-    /// added to the provided host action \a HostAction. By default it is
-    /// inactive.
-    virtual ActionBuilderReturnCode
-    getDeviceDependences(OffloadAction::DeviceDependences &DA,
-                         phases::ID CurPhase, phases::ID FinalPhase,
-                         PhasesTy &Phases) {
-      return ABRT_Inactive;
-    }
-
-    /// Update the state to include the provided host action \a HostAction as a
-    /// dependency of the current device action. By default it is inactive.
-    virtual ActionBuilderReturnCode addDeviceDependences(Action *HostAction) {
-      return ABRT_Inactive;
-    }
-
-    /// Append top level actions generated by the builder.
-    virtual void appendTopLevelActions(ActionList &AL) {}
-
-    /// Append linker device actions generated by the builder.
-    virtual void appendLinkDeviceActions(ActionList &AL) {}
-
-    /// Append linker host action generated by the builder.
-    virtual Action* appendLinkHostActions(ActionList &AL) { return nullptr; }
-
-    /// Append linker actions generated by the builder.
-    virtual void appendLinkDependences(OffloadAction::DeviceDependences &DA) {}
-
-    /// Initialize the builder. Return true if any initialization errors are
-    /// found.
-    virtual bool initialize() { return false; }
-
-    /// Return true if the builder can use bundling/unbundling.
-    virtual bool canUseBundlerUnbundler() const { return false; }
-
-    /// Return true if this builder is valid. We have a valid builder if we 
have
-    /// associated device tool chains.
-    bool isValid() { return !ToolChains.empty(); }
-
-    /// Return the associated offload kind.
-    Action::OffloadKind getAssociatedOffloadKind() {
-      return AssociatedOffloadKind;
-    }
-  };
-
-  /// Base class for CUDA/HIP action builder. It injects device code in
-  /// the host backend action.
-  class CudaActionBuilderBase : public DeviceActionBuilder {
-  protected:
-    /// Flags to signal if the user requested host-only or device-only
-    /// compilation.
-    bool CompileHostOnly = false;
-    bool CompileDeviceOnly = false;
-    bool EmitLLVM = false;
-    bool EmitAsm = false;
-
-    /// List of GPU architectures to use in this compilation.
-    SmallVector<BoundArch, 4> GpuArchList;
-
-    /// The CUDA actions for the current input.
-    ActionList CudaDeviceActions;
-
-    /// The CUDA fat binary if it was generated for the current input.
-    Action *CudaFatBinary = nullptr;
-
-    /// Flag that is set to true if this builder acted on the current input.
-    bool IsActive = false;
-
-    /// Flag for -fgpu-rdc.
-    bool Relocatable = false;
-
-    /// Default GPU architecture if there's no one specified.
-    OffloadArch DefaultOffloadArch = OffloadArch::Unknown;
-
-    /// Compilation unit ID specified by option '-fuse-cuid=' or'-cuid='.
-    const CUIDOptions &CUIDOpts;
-
-  public:
-    CudaActionBuilderBase(Compilation &C, DerivedArgList &Args,
-                          const InputList &Inputs, Action::OffloadKind OFKind)
-        : DeviceActionBuilder(C, Args, Inputs, OFKind),
-          CUIDOpts(C.getDriver().getCUIDOpts()) {
-
-      CompileDeviceOnly = C.getDriver().offloadDeviceOnly();
-      Relocatable = Args.hasFlag(options::OPT_fgpu_rdc,
-                                 options::OPT_fno_gpu_rdc, /*Default=*/false);
-    }
-
-    ActionBuilderReturnCode addDeviceDependences(Action *HostAction) override {
-      // While generating code for CUDA, we only depend on the host input 
action
-      // to trigger the creation of all the CUDA device actions.
-
-      // If we are dealing with an input action, replicate it for each GPU
-      // architecture. If we are in host-only mode we return 'success' so that
-      // the host uses the CUDA offload kind.
-      if (auto *IA = dyn_cast<InputAction>(HostAction)) {
-        // If the host input is not CUDA or HIP, we don't need to bother about
-        // this input.
-        if (!(IA->getType() == types::TY_CUDA ||
-              IA->getType() == types::TY_HIP ||
-              IA->getType() == types::TY_PP_HIP)) {
-          // The builder will ignore this input.
-          IsActive = false;
-          return ABRT_Inactive;
-        }
-
-        // Set the flag to true, so that the builder acts on the current input.
-        IsActive = true;
-
-        if (CUIDOpts.isEnabled())
-          IA->setId(CUIDOpts.getCUID(IA->getInputArg().getValue(), Args));
-
-        if (CompileHostOnly)
-          return ABRT_Success;
-
-        // Replicate inputs for each GPU architecture.
-        auto Ty = IA->getType() == types::TY_HIP ? types::TY_HIP_DEVICE
-                                                 : types::TY_CUDA_DEVICE;
-        for (unsigned I = 0, E = GpuArchList.size(); I != E; ++I) {
-          CudaDeviceActions.push_back(
-              C.MakeAction<InputAction>(IA->getInputArg(), Ty, IA->getId()));
-        }
-
-        return ABRT_Success;
-      }
-
-      // If this is an unbundling action use it as is for each CUDA toolchain.
-      if (auto *UA = dyn_cast<OffloadUnbundlingJobAction>(HostAction)) {
-
-        // If -fgpu-rdc is disabled, should not unbundle since there is no
-        // device code to link.
-        if (UA->getType() == types::TY_Object && !Relocatable)
-          return ABRT_Inactive;
-
-        CudaDeviceActions.clear();
-        auto *IA = cast<InputAction>(UA->getInputs().back());
-        std::string FileName = IA->getInputArg().getAsString(Args);
-        // Check if the type of the file is the same as the action. Do not
-        // unbundle it if it is not. Do not unbundle .so files, for example,
-        // which are not object files. Files with extension ".lib" is 
classified
-        // as TY_Object but they are actually archives, therefore should not be
-        // unbundled here as objects. They will be handled at other places.
-        const StringRef LibFileExt = ".lib";
-        if (IA->getType() == types::TY_Object &&
-            (!llvm::sys::path::has_extension(FileName) ||
-             types::lookupTypeForExtension(
-                 llvm::sys::path::extension(FileName).drop_front()) !=
-                 types::TY_Object ||
-             llvm::sys::path::extension(FileName) == LibFileExt))
-          return ABRT_Inactive;
-
-        for (auto [Arch, ToolChain] : llvm::zip(GpuArchList, ToolChains)) {
-          CudaDeviceActions.push_back(UA);
-          UA->registerDependentActionInfo(ToolChain, Arch,
-                                          AssociatedOffloadKind);
-        }
-        IsActive = true;
-        return ABRT_Success;
-      }
-
-      return IsActive ? ABRT_Success : ABRT_Inactive;
-    }
-
-    void appendTopLevelActions(ActionList &AL) override {
-      // Utility to append actions to the top level list.
-      auto AddTopLevel = [&](Action *A, BoundArch BA, const ToolChain *TC) {
-        OffloadAction::DeviceDependences Dep;
-        Dep.add(*A, *TC, BA, AssociatedOffloadKind);
-        AL.push_back(C.MakeAction<OffloadAction>(Dep, A->getType()));
-      };
-
-      // If we have a fat binary, add it to the list.
-      if (CudaFatBinary) {
-        AddTopLevel(CudaFatBinary, {}, FatBinaryToolChain);
-        CudaDeviceActions.clear();
-        CudaFatBinary = nullptr;
-        return;
-      }
-
-      if (CudaDeviceActions.empty())
-        return;
-
-      // If we have CUDA actions at this point, that's because we have a have
-      // partial compilation, so we should have an action for each GPU
-      // architecture.
-      assert(CudaDeviceActions.size() == GpuArchList.size() &&
-             "Expecting one action per GPU architecture.");
-      assert(ToolChains.size() == GpuArchList.size() &&
-             "Expecting to have a toolchain per GPU architecture");
-      for (unsigned I = 0, E = GpuArchList.size(); I != E; ++I)
-        AddTopLevel(CudaDeviceActions[I], GpuArchList[I], ToolChains[I]);
-
-      CudaDeviceActions.clear();
-    }
-
-    bool initialize() override {
-      assert(AssociatedOffloadKind == Action::OFK_Cuda ||
-             AssociatedOffloadKind == Action::OFK_HIP);
-
-      // We don't need to support CUDA.
-      if (AssociatedOffloadKind == Action::OFK_Cuda &&
-          !C.hasOffloadToolChain<Action::OFK_Cuda>())
-        return false;
-
-      // We don't need to support HIP.
-      if (AssociatedOffloadKind == Action::OFK_HIP &&
-          !C.hasOffloadToolChain<Action::OFK_HIP>())
-        return false;
-
-      const ToolChain *HostTC = 
C.getSingleOffloadToolChain<Action::OFK_Host>();
-      assert(HostTC && "No toolchain for host compilation.");
-      if (HostTC->getTriple().isNVPTX() || HostTC->getTriple().isAMDGCN()) {
-        // We do not support targeting NVPTX/AMDGCN for host compilation. Throw
-        // an error and abort pipeline construction early so we don't trip
-        // asserts that assume device-side compilation.
-        C.getDriver().Diag(diag::err_drv_cuda_host_arch)
-            << HostTC->getTriple().getArchName();
-        return true;
-      }
-
-      std::set<std::pair<BoundArch, const ToolChain *>> GpuArchs;
-      for (Action::OffloadKind Kind : {Action::OFK_Cuda, Action::OFK_HIP}) {
-        for (auto &I : llvm::make_range(C.getOffloadToolChains(Kind))) {
-          for (auto Arch :
-               C.getDriver().getOffloadArchs(C, C.getArgs(), Kind, *I.second))
-            GpuArchs.insert({Arch, I.second});
-        }
-      }
-
-      for (auto [Arch, TC] : GpuArchs) {
-        GpuArchList.push_back(Arch);
-        ToolChains.push_back(TC);
-      }
-
-      FatBinaryToolChain = ToolChains.front();
-      CompileHostOnly = C.getDriver().offloadHostOnly();
-      EmitLLVM = Args.getLastArg(options::OPT_emit_llvm);
-      EmitAsm = Args.getLastArg(options::OPT_S);
-
-      return false;
-    }
-  };
-
-  /// \brief CUDA action builder. It injects device code in the host backend
-  /// action.
-  class CudaActionBuilder final : public CudaActionBuilderBase {
-  public:
-    CudaActionBuilder(Compilation &C, DerivedArgList &Args,
-                      const InputList &Inputs)
-        : CudaActionBuilderBase(C, Args, Inputs, Action::OFK_Cuda) {
-      DefaultOffloadArch = OffloadArch::CudaDefault;
-    }
-
-    ActionBuilderReturnCode
-    getDeviceDependences(OffloadAction::DeviceDependences &DA,
-                         phases::ID CurPhase, phases::ID FinalPhase,
-                         PhasesTy &Phases) override {
-      if (!IsActive)
-        return ABRT_Inactive;
-
-      // If we don't have more CUDA actions, we don't have any dependences to
-      // create for the host.
-      if (CudaDeviceActions.empty())
-        return ABRT_Success;
-
-      assert(CudaDeviceActions.size() == GpuArchList.size() &&
-             "Expecting one action per GPU architecture.");
-      assert(!CompileHostOnly &&
-             "Not expecting CUDA actions in host-only compilation.");
-
-      // If we are generating code for the device or we are in a backend phase,
-      // we attempt to generate the fat binary. We compile each arch to ptx and
-      // assemble to cubin, then feed the cubin *and* the ptx into a device
-      // "link" action, which uses fatbinary to combine these cubins into one
-      // fatbin.  The fatbin is then an input to the host action if not in
-      // device-only mode.
-      if (CompileDeviceOnly || CurPhase == phases::Backend) {
-        ActionList DeviceActions;
-        for (unsigned I = 0, E = GpuArchList.size(); I != E; ++I) {
-          // Produce the device action from the current phase up to the 
assemble
-          // phase.
-          for (auto Ph : Phases) {
-            // Skip the phases that were already dealt with.
-            if (Ph < CurPhase)
-              continue;
-            // We have to be consistent with the host final phase.
-            if (Ph > FinalPhase)
-              break;
-
-            CudaDeviceActions[I] = C.getDriver().ConstructPhaseAction(
-                C, Args, Ph, CudaDeviceActions[I], Action::OFK_Cuda,
-                ToolChains[I]->getLTOMode(Args, Action::OFK_Cuda));
-
-            if (Ph == phases::Assemble)
-              break;
-          }
-
-          // If we didn't reach the assemble phase, we can't generate the fat
-          // binary. We don't need to generate the fat binary if we are not in
-          // device-only mode.
-          if (!isa<AssembleJobAction>(CudaDeviceActions[I]) ||
-              CompileDeviceOnly)
-            continue;
-
-          Action *AssembleAction = CudaDeviceActions[I];
-          assert(AssembleAction->getType() == types::TY_Object);
-          assert(AssembleAction->getInputs().size() == 1);
-
-          Action *Backen...
[truncated]

``````````

</details>


https://github.com/llvm/llvm-project/pull/211924
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to