[PATCH] D88370: Emit predefined macro for wavefront size for amdgcn

Yaxun Liu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Sep 26 19:41:24 PDT 2020


yaxunl created this revision.
yaxunl added reviewers: arsenm, b-sumner.
Herald added subscribers: kerbowa, nhaehnle, jvesely.
yaxunl requested review of this revision.
Herald added a subscriber: wdng.

https://reviews.llvm.org/D88370

Files:
  clang/lib/Basic/Targets/AMDGPU.cpp
  clang/lib/Basic/Targets/AMDGPU.h
  clang/test/Driver/amdgpu-macros.cl


Index: clang/test/Driver/amdgpu-macros.cl
===================================================================
--- clang/test/Driver/amdgpu-macros.cl
+++ clang/test/Driver/amdgpu-macros.cl
@@ -347,3 +347,37 @@
 // GFX1012-DAG: #define __amdgcn_processor__ "gfx1012"
 // GFX1030-DAG: #define __amdgcn_processor__ "gfx1030"
 // GFX1031-DAG: #define __amdgcn_processor__ "gfx1031"
+
+// GFX600-DAG: #define __amdgcn_wavefront_size 64
+// GFX601-DAG: #define __amdgcn_wavefront_size 64
+// GFX700-DAG: #define __amdgcn_wavefront_size 64
+// GFX701-DAG: #define __amdgcn_wavefront_size 64
+// GFX702-DAG: #define __amdgcn_wavefront_size 64
+// GFX703-DAG: #define __amdgcn_wavefront_size 64
+// GFX704-DAG: #define __amdgcn_wavefront_size 64
+// GFX801-DAG: #define __amdgcn_wavefront_size 64
+// GFX802-DAG: #define __amdgcn_wavefront_size 64
+// GFX803-DAG: #define __amdgcn_wavefront_size 64
+// GFX810-DAG: #define __amdgcn_wavefront_size 64
+// GFX900-DAG: #define __amdgcn_wavefront_size 64
+// GFX902-DAG: #define __amdgcn_wavefront_size 64
+// GFX904-DAG: #define __amdgcn_wavefront_size 64
+// GFX906-DAG: #define __amdgcn_wavefront_size 64
+// GFX908-DAG: #define __amdgcn_wavefront_size 64
+// GFX909-DAG: #define __amdgcn_wavefront_size 64
+// GFX1010-DAG: #define __amdgcn_wavefront_size 32
+// GFX1011-DAG: #define __amdgcn_wavefront_size 32
+// GFX1012-DAG: #define __amdgcn_wavefront_size 32
+// GFX1030-DAG: #define __amdgcn_wavefront_size 32
+// GFX1031-DAG: #define __amdgcn_wavefront_size 32
+
+// RUN: %clang -E -dM -target amdgcn -mcpu=gfx906 -mwavefrontsize64 \
+// RUN:   %s 2>&1 | FileCheck --check-prefixes=WAVE64 %s
+// RUN: %clang -E -dM -target amdgcn -mcpu=gfx1010 -mwavefrontsize64 \
+// RUN:   %s 2>&1 | FileCheck --check-prefixes=WAVE64 %s
+// RUN: %clang -E -dM -target amdgcn -mcpu=gfx906 -mwavefrontsize64 \
+// RUN:   -mno-wavefrontsize64 %s 2>&1 | FileCheck --check-prefixes=WAVE64 %s
+// RUN: %clang -E -dM -target amdgcn -mcpu=gfx1010 -mwavefrontsize64 \
+// RUN:   -mno-wavefrontsize64 %s 2>&1 | FileCheck --check-prefixes=WAVE32 %s
+// WAVE64-DAG: #define __amdgcn_wavefront_size 64
+// WAVE32-DAG: #define __amdgcn_wavefront_size 32
Index: clang/lib/Basic/Targets/AMDGPU.h
===================================================================
--- clang/lib/Basic/Targets/AMDGPU.h
+++ clang/lib/Basic/Targets/AMDGPU.h
@@ -41,6 +41,7 @@
 
   llvm::AMDGPU::GPUKind GPUKind;
   unsigned GPUFeatures;
+  unsigned WavefrontSize;
 
   /// Target ID is device name followed by optional feature name postfixed
   /// by plus or minus sign delimitted by colon, e.g. gfx908:xnack+:sram-ecc-.
@@ -414,6 +415,9 @@
       assert(OffloadArchFeatures.find(Name) == OffloadArchFeatures.end());
       OffloadArchFeatures[Name] = IsOn;
     });
+
+    if (llvm::find(Features, "+wavefrontsize64") != Features.end())
+      WavefrontSize = 64;
     return true;
   }
 
Index: clang/lib/Basic/Targets/AMDGPU.cpp
===================================================================
--- clang/lib/Basic/Targets/AMDGPU.cpp
+++ clang/lib/Basic/Targets/AMDGPU.cpp
@@ -316,6 +316,7 @@
 
   HasLegalHalfType = true;
   HasFloat16 = true;
+  WavefrontSize = GPUFeatures & llvm::AMDGPU::FEATURE_WAVE32 ? 32 : 64;
 
   // Set pointer width and alignment for target address space 0.
   PointerWidth = PointerAlign = DataLayout->getPointerSizeInBits();
@@ -388,6 +389,8 @@
     Builder.defineMacro("__HAS_FP64__");
   if (hasFastFMA())
     Builder.defineMacro("FP_FAST_FMA");
+
+  Builder.defineMacro("__amdgcn_wavefront_size" + Twine(WavefrontSize));
 }
 
 void AMDGPUTargetInfo::setAuxTarget(const TargetInfo *Aux) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88370.294532.patch
Type: text/x-patch
Size: 3622 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200927/42fb9b71/attachment.bin>


More information about the cfe-commits mailing list