diff options
author | Justin Lebar <jlebar@google.com> | 2016-07-06 21:21:39 +0000 |
---|---|---|
committer | Justin Lebar <jlebar@google.com> | 2016-07-06 21:21:39 +0000 |
commit | 629076178a5eed7f6650eb429a61cc0653be9924 (patch) | |
tree | a83dc16f3a21cd2e1444fa689512f1c5e1d31461 /clang/lib/Driver/Action.cpp | |
parent | ef1aaac3ccb01e43fb02584a5a1d08faf822189f (diff) | |
download | bcm5719-llvm-629076178a5eed7f6650eb429a61cc0653be9924.tar.gz bcm5719-llvm-629076178a5eed7f6650eb429a61cc0653be9924.zip |
[CUDA] Add utility functions for dealing with CUDA versions / architectures.
Summary:
Currently our handling of CUDA architectures is scattered all around
clang. This patch centralizes it.
A key advantage of this centralization is that you can now write a C++
switch on e.g. CudaArch and get a compile error if you don't handle one
of the enum values.
Reviewers: tra
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D21867
llvm-svn: 274681
Diffstat (limited to 'clang/lib/Driver/Action.cpp')
-rw-r--r-- | clang/lib/Driver/Action.cpp | 36 |
1 files changed, 2 insertions, 34 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() {} |