diff options
Diffstat (limited to 'clang/lib/Driver')
-rw-r--r-- | clang/lib/Driver/Action.cpp | 36 | ||||
-rw-r--r-- | clang/lib/Driver/Driver.cpp | 29 | ||||
-rw-r--r-- | clang/lib/Driver/Tools.cpp | 7 |
3 files changed, 22 insertions, 50 deletions
diff --git a/clang/lib/Driver/Action.cpp b/clang/lib/Driver/Action.cpp index f9e1024f920..425f315ccd6 100644 --- a/clang/lib/Driver/Action.cpp +++ b/clang/lib/Driver/Action.cpp @@ -51,43 +51,11 @@ void BindArchAction::anchor() {} BindArchAction::BindArchAction(Action *Input, const char *_ArchName) : Action(BindArchClass, Input), ArchName(_ArchName) {} -// Converts CUDA GPU architecture, e.g. "sm_21", to its corresponding virtual -// compute arch, e.g. "compute_20". Returns null if the input arch is null or -// doesn't match an existing arch. -static const char* GpuArchToComputeName(const char *ArchName) { - if (!ArchName) - return nullptr; - return llvm::StringSwitch<const char *>(ArchName) - .Cases("sm_20", "sm_21", "compute_20") - .Case("sm_30", "compute_30") - .Case("sm_32", "compute_32") - .Case("sm_35", "compute_35") - .Case("sm_37", "compute_37") - .Case("sm_50", "compute_50") - .Case("sm_52", "compute_52") - .Case("sm_53", "compute_53") - .Case("sm_60", "compute_60") - .Case("sm_61", "compute_61") - .Case("sm_62", "compute_62") - .Default(nullptr); -} - void CudaDeviceAction::anchor() {} -CudaDeviceAction::CudaDeviceAction(Action *Input, const char *ArchName, +CudaDeviceAction::CudaDeviceAction(Action *Input, CudaArch Arch, bool AtTopLevel) - : Action(CudaDeviceClass, Input), GpuArchName(ArchName), - AtTopLevel(AtTopLevel) { - assert(!GpuArchName || IsValidGpuArchName(GpuArchName)); -} - -const char *CudaDeviceAction::getComputeArchName() const { - return GpuArchToComputeName(GpuArchName); -} - -bool CudaDeviceAction::IsValidGpuArchName(llvm::StringRef ArchName) { - return GpuArchToComputeName(ArchName.data()) != nullptr; -} + : Action(CudaDeviceClass, Input), GpuArch(Arch), AtTopLevel(AtTopLevel) {} void CudaHostAction::anchor() {} diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 7235bd0efc8..78c3125cdb6 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -23,6 +23,7 @@ #include "clang/Driver/ToolChain.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/SmallSet.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringSet.h" #include "llvm/ADT/StringSwitch.h" @@ -1022,9 +1023,10 @@ static unsigned PrintActions1(const Compilation &C, Action *A, os << '"' << BIA->getArchName() << '"' << ", {" << PrintActions1(C, *BIA->input_begin(), Ids) << "}"; } else if (CudaDeviceAction *CDA = dyn_cast<CudaDeviceAction>(A)) { - os << '"' - << (CDA->getGpuArchName() ? CDA->getGpuArchName() : "(multiple archs)") - << '"' << ", {" << PrintActions1(C, *CDA->input_begin(), Ids) << "}"; + CudaArch Arch = CDA->getGpuArch(); + if (Arch != CudaArch::UNKNOWN) + os << "'" << CudaArchToString(Arch) << "', "; + os << "{" << PrintActions1(C, *CDA->input_begin(), Ids) << "}"; } else { const ActionList *AL; if (CudaHostAction *CHA = dyn_cast<CudaHostAction>(A)) { @@ -1380,24 +1382,25 @@ static Action *buildCudaActions(Compilation &C, DerivedArgList &Args, return C.MakeAction<CudaHostAction>(HostAction, ActionList()); // Collect all cuda_gpu_arch parameters, removing duplicates. - SmallVector<const char *, 4> GpuArchList; - llvm::StringSet<> GpuArchNames; + SmallVector<CudaArch, 4> GpuArchList; + llvm::SmallSet<CudaArch, 4> GpuArchs; for (Arg *A : Args) { if (!A->getOption().matches(options::OPT_cuda_gpu_arch_EQ)) continue; A->claim(); - const auto& Arch = A->getValue(); - if (!CudaDeviceAction::IsValidGpuArchName(Arch)) - C.getDriver().Diag(clang::diag::err_drv_cuda_bad_gpu_arch) << Arch; - else if (GpuArchNames.insert(Arch).second) + const auto &ArchStr = A->getValue(); + CudaArch Arch = StringToCudaArch(ArchStr); + if (Arch == CudaArch::UNKNOWN) + C.getDriver().Diag(clang::diag::err_drv_cuda_bad_gpu_arch) << ArchStr; + else if (GpuArchs.insert(Arch).second) GpuArchList.push_back(Arch); } // Default to sm_20 which is the lowest common denominator for supported GPUs. // sm_20 code should work correctly, if suboptimally, on all newer GPUs. if (GpuArchList.empty()) - GpuArchList.push_back("sm_20"); + GpuArchList.push_back(CudaArch::SM_20); // Replicate inputs for each GPU architecture. Driver::InputList CudaDeviceInputs; @@ -1463,7 +1466,7 @@ static Action *buildCudaActions(Compilation &C, DerivedArgList &Args, } auto FatbinAction = C.MakeAction<CudaDeviceAction>( C.MakeAction<LinkJobAction>(DeviceActions, types::TY_CUDA_FATBIN), - /* GpuArchName = */ nullptr, + CudaArch::UNKNOWN, /* AtTopLevel = */ false); // Return a new host action that incorporates original host action and all // device actions. @@ -2047,8 +2050,8 @@ InputInfo Driver::BuildJobsForActionNoCache( // Call BuildJobsForAction() again, now with correct device parameters. InputInfo II = BuildJobsForAction( C, *CDA->input_begin(), C.getSingleOffloadToolChain<Action::OFK_Cuda>(), - CDA->getGpuArchName(), CDA->isAtTopLevel(), /*MultipleArchs=*/true, - LinkingOutput, CachedResults); + CudaArchToString(CDA->getGpuArch()), CDA->isAtTopLevel(), + /*MultipleArchs=*/true, LinkingOutput, CachedResults); // Currently II's Action is *CDA->input_begin(). Set it to CDA instead, so // that one can retrieve II's GPU arch. II.setAction(A); diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index 2425619d4c9..14ed0d4e3ed 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -11222,9 +11222,10 @@ void NVPTX::Linker::ConstructJob(Compilation &C, const JobAction &JA, auto* A = cast<const CudaDeviceAction>(II.getAction()); // We need to pass an Arch of the form "sm_XX" for cubin files and // "compute_XX" for ptx. - const char *Arch = (II.getType() == types::TY_PP_Asm) - ? A->getComputeArchName() - : A->getGpuArchName(); + const char *Arch = + (II.getType() == types::TY_PP_Asm) + ? CudaVirtualArchToString(VirtualArchForCudaArch(A->getGpuArch())) + : CudaArchToString(A->getGpuArch()); CmdArgs.push_back(Args.MakeArgString(llvm::Twine("--image=profile=") + Arch + ",file=" + II.getFilename())); } |