]> granicus.if.org Git - clang/commitdiff
[CUDA] Revert defining __CUDA_ARCH__ for amdgcn targets
authorYaxun Liu <Yaxun.Liu@amd.com>
Mon, 9 Apr 2018 15:43:01 +0000 (15:43 +0000)
committerYaxun Liu <Yaxun.Liu@amd.com>
Mon, 9 Apr 2018 15:43:01 +0000 (15:43 +0000)
amdgcn targets only support HIP, which does not define __CUDA_ARCH__.

this is a partial unroll of r329232 / D45277.

Differential Revision: https://reviews.llvm.org/D45387

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@329584 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Basic/Targets.cpp
lib/Basic/Targets.h
lib/Basic/Targets/AMDGPU.cpp
lib/Basic/Targets/AMDGPU.h
lib/Basic/Targets/NVPTX.cpp

index f46858880453a123b6742c8926d1f865fa79ce5f..e325403a1fa26137e1b8542f0beb54b3ca38f70c 100644 (file)
@@ -112,61 +112,6 @@ void addMinGWDefines(const llvm::Triple &Triple, const LangOptions &Opts,
   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 "1";
-    case CudaArch::UNKNOWN:
-      llvm_unreachable("unhandled Cuda/HIP Arch");
-    }
-    llvm_unreachable("unhandled Cuda/HIP Arch");
-  }();
-  Builder.defineMacro("__CUDA_ARCH__", CUDAArchCode);
-}
-
 //===----------------------------------------------------------------------===//
 // Driver code
 //===----------------------------------------------------------------------===//
index bb933c00a34184b3eb188bb4313fce6dd501b32a..6fc967ddabee04b8180c4a5d3c733f2e1d768cf8 100644 (file)
@@ -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 @@ void addMinGWDefines(const llvm::Triple &Triple, const clang::LangOptions &Opts,
 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 51943c737a101d93ac3743bab6e75c252ed35055..d956d132a5b641409e104639ff140d7435f52411 100644 (file)
@@ -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 @@ AMDGPUTargetInfo::AMDGPUTargetInfo(const llvm::Triple &Triple,
   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 @@ void AMDGPUTargetInfo::getTargetDefines(const LangOptions &Opts,
   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 1249031d0668d772830378017afc15076d130da7..f7c477659dc1a6491c98883f1e8bb166d9c8119f 100644 (file)
@@ -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 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
   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 @@ public:
     else
       GPU = parseR600Name(Name);
 
-    GCN_Subarch = StringToCudaArch(Name);
     return GK_NONE != GPU.Kind;
   }
 
index cb24fd9c3e9c62e8b9aed564b88fb1dfabdf7b03..c497e2e17a2c91126ebff6a299093833c7109980 100644 (file)
@@ -153,8 +153,61 @@ void NVPTXTargetInfo::getTargetDefines(const LangOptions &Opts,
                                        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<Builtin::Info> NVPTXTargetInfo::getTargetBuiltins() const {