From f38ef5337c1a4640fdc984e051be38bbb67363e9 Mon Sep 17 00:00:00 2001 From: Artem Belevich Date: Mon, 20 Jul 2015 21:59:31 +0000 Subject: [PATCH] [CUDA] Moved device-side triple calculation to buildCudaActions(). Differential Revision: http://reviews.llvm.org/D11310 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@242718 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Driver/Action.h | 4 ++- lib/Driver/Action.cpp | 5 ++-- lib/Driver/Driver.cpp | 47 +++++++++++++++++------------------ 3 files changed, 29 insertions(+), 27 deletions(-) diff --git a/include/clang/Driver/Action.h b/include/clang/Driver/Action.h index ad3c31c1c8..f6d4ad579c 100644 --- a/include/clang/Driver/Action.h +++ b/include/clang/Driver/Action.h @@ -139,15 +139,17 @@ class CudaDeviceAction : public Action { virtual void anchor(); /// GPU architecture to bind -- e.g 'sm_35'. const char *GpuArchName; + const char *DeviceTriple; /// True when action results are not consumed by the host action (e.g when /// -fsyntax-only or --cuda-device-only options are used). bool AtTopLevel; public: CudaDeviceAction(std::unique_ptr Input, const char *ArchName, - bool AtTopLevel); + const char *DeviceTriple, bool AtTopLevel); const char *getGpuArchName() const { return GpuArchName; } + const char *getDeviceTriple() const { return DeviceTriple; } bool isAtTopLevel() const { return AtTopLevel; } static bool classof(const Action *A) { diff --git a/lib/Driver/Action.cpp b/lib/Driver/Action.cpp index 49dccd224b..6fe2a50346 100644 --- a/lib/Driver/Action.cpp +++ b/lib/Driver/Action.cpp @@ -58,9 +58,10 @@ BindArchAction::BindArchAction(std::unique_ptr Input, void CudaDeviceAction::anchor() {} CudaDeviceAction::CudaDeviceAction(std::unique_ptr Input, - const char *ArchName, bool AtTopLevel) + const char *ArchName, + const char *DeviceTriple, bool AtTopLevel) : Action(CudaDeviceClass, std::move(Input)), GpuArchName(ArchName), - AtTopLevel(AtTopLevel) {} + DeviceTriple(DeviceTriple), AtTopLevel(AtTopLevel) {} void CudaHostAction::anchor() {} diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index 499375f55f..faaeb3951a 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -1238,11 +1238,8 @@ void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args, // CudaHostAction which combines both host and device side actions. static std::unique_ptr buildCudaActions(const Driver &D, const ToolChain &TC, DerivedArgList &Args, - const Arg *InputArg, const types::ID InputType, - std::unique_ptr Current, ActionList &Actions) { - - assert(InputType == types::TY_CUDA && - "CUDA Actions only apply to CUDA inputs."); + const Arg *InputArg, std::unique_ptr HostAction, + ActionList &Actions) { // Collect all cuda_gpu_arch parameters, removing duplicates. SmallVector GpuArchList; @@ -1280,6 +1277,12 @@ buildCudaActions(const Driver &D, const ToolChain &TC, DerivedArgList &Args, } } + // Figure out which NVPTX triple to use for device-side compilation based on + // whether host is 64-bit. + const char *DeviceTriple = TC.getTriple().isArch64Bit() + ? "nvptx64-nvidia-cuda" + : "nvptx-nvidia-cuda"; + // Figure out what to do with device actions -- pass them as inputs to the // host action or run each of them independently. bool DeviceOnlyCompilation = Args.hasArg(options::OPT_cuda_device_only); @@ -1296,26 +1299,26 @@ buildCudaActions(const Driver &D, const ToolChain &TC, DerivedArgList &Args, } for (unsigned I = 0, E = GpuArchList.size(); I != E; ++I) - Actions.push_back( - new CudaDeviceAction(std::unique_ptr(CudaDeviceActions[I]), - GpuArchList[I], /* AtTopLevel */ true)); + Actions.push_back(new CudaDeviceAction( + std::unique_ptr(CudaDeviceActions[I]), GpuArchList[I], + DeviceTriple, /* AtTopLevel */ true)); // Kill host action in case of device-only compilation. if (DeviceOnlyCompilation) - Current.reset(nullptr); - return Current; + HostAction.reset(nullptr); + return HostAction; } // Outputs of device actions during complete CUDA compilation get created // with AtTopLevel=false and become inputs for the host action. ActionList DeviceActions; for (unsigned I = 0, E = GpuArchList.size(); I != E; ++I) - DeviceActions.push_back( - new CudaDeviceAction(std::unique_ptr(CudaDeviceActions[I]), - GpuArchList[I], /* AtTopLevel */ false)); + DeviceActions.push_back(new CudaDeviceAction( + std::unique_ptr(CudaDeviceActions[I]), GpuArchList[I], + DeviceTriple, /* AtTopLevel */ false)); // Return a new host action that incorporates original host action and all // device actions. return std::unique_ptr( - new CudaHostAction(std::move(Current), DeviceActions)); + new CudaHostAction(std::move(HostAction), DeviceActions)); } void Driver::BuildActions(const ToolChain &TC, DerivedArgList &Args, @@ -1461,7 +1464,7 @@ void Driver::BuildActions(const ToolChain &TC, DerivedArgList &Args, if (InputType == types::TY_CUDA && Phase == CudaInjectionPhase && !Args.hasArg(options::OPT_cuda_host_only)) { - Current = buildCudaActions(*this, TC, Args, InputArg, InputType, + Current = buildCudaActions(*this, TC, Args, InputArg, std::move(Current), Actions); if (!Current) break; @@ -1791,15 +1794,11 @@ void Driver::BuildJobsForAction(Compilation &C, const Action *A, } if (const CudaDeviceAction *CDA = dyn_cast(A)) { - // Figure out which NVPTX triple to use for device-side compilation based on - // whether host is 64-bit. - llvm::Triple DeviceTriple(TC->getTriple().isArch64Bit() - ? "nvptx64-nvidia-cuda" - : "nvptx-nvidia-cuda"); - BuildJobsForAction(C, *CDA->begin(), - &getToolChain(C.getArgs(), DeviceTriple), - CDA->getGpuArchName(), CDA->isAtTopLevel(), - /*MultipleArchs*/ true, LinkingOutput, Result); + BuildJobsForAction( + C, *CDA->begin(), + &getToolChain(C.getArgs(), llvm::Triple(CDA->getDeviceTriple())), + CDA->getGpuArchName(), CDA->isAtTopLevel(), + /*MultipleArchs*/ true, LinkingOutput, Result); return; } -- 2.40.0