Index: lib/Basic/Targets.h =================================================================== --- lib/Basic/Targets.h +++ lib/Basic/Targets.h @@ -16,7 +16,6 @@ #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_H #define LLVM_CLANG_LIB_BASIC_TARGETS_H -#include "clang/Basic/Cuda.h" #include "clang/Basic/LangOptions.h" #include "clang/Basic/MacroBuilder.h" #include "clang/Basic/TargetInfo.h" @@ -47,9 +46,6 @@ LLVM_LIBRARY_VISIBILITY void addCygMingDefines(const clang::LangOptions &Opts, clang::MacroBuilder &Builder); - -LLVM_LIBRARY_VISIBILITY -void defineCudaArchMacro(CudaArch GPU, clang::MacroBuilder &Builder); } // namespace targets } // namespace clang #endif // LLVM_CLANG_LIB_BASIC_TARGETS_H Index: lib/Basic/Targets.cpp =================================================================== --- lib/Basic/Targets.cpp +++ lib/Basic/Targets.cpp @@ -112,61 +112,6 @@ addCygMingDefines(Opts, Builder); } -void defineCudaArchMacro(CudaArch GPU, clang::MacroBuilder &Builder) { - std::string CUDAArchCode = [GPU] { - switch (GPU) { - case CudaArch::LAST: - break; - case CudaArch::SM_20: - return "200"; - case CudaArch::SM_21: - return "210"; - case CudaArch::SM_30: - return "300"; - case CudaArch::SM_32: - return "320"; - case CudaArch::SM_35: - return "350"; - case CudaArch::SM_37: - return "370"; - case CudaArch::SM_50: - return "500"; - case CudaArch::SM_52: - return "520"; - case CudaArch::SM_53: - return "530"; - case CudaArch::SM_60: - return "600"; - case CudaArch::SM_61: - return "610"; - case CudaArch::SM_62: - return "620"; - case CudaArch::SM_70: - return "700"; - case CudaArch::SM_72: - return "720"; - case CudaArch::GFX600: - case CudaArch::GFX601: - case CudaArch::GFX700: - case CudaArch::GFX701: - case CudaArch::GFX702: - case CudaArch::GFX703: - case CudaArch::GFX704: - case CudaArch::GFX801: - case CudaArch::GFX802: - case CudaArch::GFX803: - case CudaArch::GFX810: - case CudaArch::GFX900: - case CudaArch::GFX902: - return "320"; - case CudaArch::UNKNOWN: - llvm_unreachable("unhandled Cuda/HIP Arch"); - } - llvm_unreachable("unhandled Cuda/HIP Arch"); - }(); - Builder.defineMacro("__CUDA_ARCH__", CUDAArchCode); -} - //===----------------------------------------------------------------------===// // Driver code //===----------------------------------------------------------------------===// Index: lib/Basic/Targets/AMDGPU.h =================================================================== --- lib/Basic/Targets/AMDGPU.h +++ lib/Basic/Targets/AMDGPU.h @@ -14,7 +14,6 @@ #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_AMDGPU_H #define LLVM_CLANG_LIB_BASIC_TARGETS_AMDGPU_H -#include "clang/Basic/Cuda.h" #include "clang/Basic/TargetInfo.h" #include "clang/Basic/TargetOptions.h" #include "llvm/ADT/StringSet.h" @@ -175,7 +174,6 @@ static bool isAMDGCN(const llvm::Triple &TT) { return TT.getArch() == llvm::Triple::amdgcn; } - CudaArch GCN_Subarch; public: AMDGPUTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts); @@ -332,7 +330,6 @@ else GPU = parseR600Name(Name); - GCN_Subarch = StringToCudaArch(Name); return GK_NONE != GPU.Kind; } Index: lib/Basic/Targets/AMDGPU.cpp =================================================================== --- lib/Basic/Targets/AMDGPU.cpp +++ lib/Basic/Targets/AMDGPU.cpp @@ -12,7 +12,6 @@ //===----------------------------------------------------------------------===// #include "AMDGPU.h" -#include "Targets.h" #include "clang/Basic/Builtins.h" #include "clang/Basic/LangOptions.h" #include "clang/Basic/MacroBuilder.h" @@ -264,7 +263,6 @@ resetDataLayout(isAMDGCN(getTriple()) ? DataLayoutStringAMDGCN : DataLayoutStringR600); assert(DataLayout->getAllocaAddrSpace() == Private); - GCN_Subarch = CudaArch::GFX803; // Default to fiji setAddressSpaceMap(Triple.getOS() == llvm::Triple::Mesa3D || !isAMDGCN(Triple)); @@ -309,9 +307,6 @@ if (GPU.Kind != GK_NONE) Builder.defineMacro(Twine("__") + Twine(GPU.CanonicalName) + Twine("__")); - if (Opts.CUDAIsDevice) - defineCudaArchMacro(GCN_Subarch, Builder); - // TODO: __HAS_FMAF__, __HAS_LDEXPF__, __HAS_FP64__ are deprecated and will be // removed in the near future. if (GPU.HasFMAF) Index: lib/Basic/Targets/NVPTX.cpp =================================================================== --- lib/Basic/Targets/NVPTX.cpp +++ lib/Basic/Targets/NVPTX.cpp @@ -153,8 +153,61 @@ MacroBuilder &Builder) const { Builder.defineMacro("__PTX__"); Builder.defineMacro("__NVPTX__"); - if (Opts.CUDAIsDevice) - defineCudaArchMacro(GPU, Builder); + if (Opts.CUDAIsDevice) { + // Set __CUDA_ARCH__ for the GPU specified. + std::string CUDAArchCode = [this] { + switch (GPU) { + case CudaArch::GFX600: + case CudaArch::GFX601: + case CudaArch::GFX700: + case CudaArch::GFX701: + case CudaArch::GFX702: + case CudaArch::GFX703: + case CudaArch::GFX704: + case CudaArch::GFX801: + case CudaArch::GFX802: + case CudaArch::GFX803: + case CudaArch::GFX810: + case CudaArch::GFX900: + case CudaArch::GFX902: + case CudaArch::LAST: + break; + case CudaArch::UNKNOWN: + assert(false && "No GPU arch when compiling CUDA device code."); + return ""; + case CudaArch::SM_20: + return "200"; + case CudaArch::SM_21: + return "210"; + case CudaArch::SM_30: + return "300"; + case CudaArch::SM_32: + return "320"; + case CudaArch::SM_35: + return "350"; + case CudaArch::SM_37: + return "370"; + case CudaArch::SM_50: + return "500"; + case CudaArch::SM_52: + return "520"; + case CudaArch::SM_53: + return "530"; + case CudaArch::SM_60: + return "600"; + case CudaArch::SM_61: + return "610"; + case CudaArch::SM_62: + return "620"; + case CudaArch::SM_70: + return "700"; + case CudaArch::SM_72: + return "720"; + } + llvm_unreachable("unhandled CudaArch"); + }(); + Builder.defineMacro("__CUDA_ARCH__", CUDAArchCode); + } } ArrayRef NVPTXTargetInfo::getTargetBuiltins() const {