[PATCH] D77923: OpenCL: Fix some missing predefined macros

Matt Arsenault via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 15 05:59:19 PDT 2020


arsenm updated this revision to Diff 257681.
arsenm added a comment.

Check triple for support. Report 2.0 for -amdhsa and -amdpal with flat support, but 1.2 for clover/-mesa3d. Also require targets to explicitly set a value to define, rather than defaulting.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77923/new/

https://reviews.llvm.org/D77923

Files:
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/Basic/Targets/AMDGPU.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/test/Preprocessor/predefined-macros.c


Index: clang/test/Preprocessor/predefined-macros.c
===================================================================
--- clang/test/Preprocessor/predefined-macros.c
+++ clang/test/Preprocessor/predefined-macros.c
@@ -183,10 +183,21 @@
 // CHECK-AMDGCN-GFX6: #define __IMAGE_SUPPORT__ 1
 // CHECK-AMDGCN-GFX6: #define __OPENCL_VERSION__ 120{{$}}
 
+// No set OS or mesa3d, assume CL1.2
 // RUN: %clang_cc1 %s -E -dM -o - -x cl -triple amdgcn-unknown-unknown -target-cpu gfx700 \
 // RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-AMDGCN-GFX7
+// RUN: %clang_cc1 %s -E -dM -o - -x cl -triple amdgcn-unknown-mesa3d -target-cpu gfx700 \
+// RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-AMDGCN-GFX7
 // CHECK-AMDGCN-GFX7: #define __IMAGE_SUPPORT__ 1
-// CHECK-AMDGCN-GFX7: #define __OPENCL_VERSION__ 200{{$}}
+// CHECK-AMDGCN-GFX7: #define __OPENCL_VERSION__ 120{{$}}
+
+// Assume CL2.0 support for HSA and PAL
+// RUN: %clang_cc1 %s -E -dM -o - -x cl -triple amdgcn-unknown-amdhsa -target-cpu gfx700 \
+// RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-AMDGCN-AMDHSAPAL
+// RUN: %clang_cc1 %s -E -dM -o - -x cl -triple amdgcn-unknown-amdpal -target-cpu gfx700 \
+// RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-AMDGCN-AMDHSAPAL
+// CHECK-AMDGCN-AMDHSAPAL: #define __IMAGE_SUPPORT__ 1
+// CHECK-AMDGCN-AMDHSAPAL: #define __OPENCL_VERSION__ 200{{$}}
 
 
 // RUN: %clang_cc1 %s -E -dM -o - -x hip -triple amdgcn-amd-amdhsa \
Index: clang/lib/Frontend/InitPreprocessor.cpp
===================================================================
--- clang/lib/Frontend/InitPreprocessor.cpp
+++ clang/lib/Frontend/InitPreprocessor.cpp
@@ -450,8 +450,10 @@
       }
     }
 
-    Builder.defineMacro("__OPENCL_VERSION__",
-                        Twine(TI.getMaxOpenCLSupportedVersion()));
+    if (TI.getMaxOpenCLSupportedVersion() != 0) {
+      Builder.defineMacro("__OPENCL_VERSION__",
+                          Twine(TI.getMaxOpenCLSupportedVersion()));
+    }
 
     Builder.defineMacro("CL_VERSION_1_0", "100");
     Builder.defineMacro("CL_VERSION_1_1", "110");
Index: clang/lib/Basic/Targets/AMDGPU.cpp
===================================================================
--- clang/lib/Basic/Targets/AMDGPU.cpp
+++ clang/lib/Basic/Targets/AMDGPU.cpp
@@ -306,7 +306,13 @@
   MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
 
   SupportsOpenCLImages = true;
-  MaxOpenCLSupportedVersion =  hasFlatAddressSpace() ? 200 : 120;
+
+  // CL2.0 features require flat instruction support. ROCm supports CL2.0, but
+  // Clover does not.
+  const bool SupportsCL2 = hasFlatAddressSpace() &&
+    (Triple.getOS() == llvm::Triple::AMDHSA ||
+     Triple.getOS() == llvm::Triple::AMDPAL);
+  MaxOpenCLSupportedVersion =  SupportsCL2 ? 200 : 120;
 }
 
 void AMDGPUTargetInfo::adjust(LangOptions &Opts) {
Index: clang/include/clang/Basic/TargetInfo.h
===================================================================
--- clang/include/clang/Basic/TargetInfo.h
+++ clang/include/clang/Basic/TargetInfo.h
@@ -215,7 +215,10 @@
   unsigned MaxOpenCLWorkGroupSize;
 
   bool SupportsOpenCLImages = false;
-  unsigned MaxOpenCLSupportedVersion = 100;
+
+  /// Maximum supported device OpenCL version, corresponding to the values
+  /// expected for __OPENCL_VERSION__. If 0, the macro is not defined.
+  unsigned MaxOpenCLSupportedVersion = 0;
 
   // TargetInfo Constructor.  Default initializes all fields.
   TargetInfo(const llvm::Triple &T);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77923.257681.patch
Type: text/x-patch
Size: 3487 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200415/c2ab6444/attachment-0001.bin>


More information about the cfe-commits mailing list