[clang] a591c7c - [HLSL] Change WaveActiveCountBits to wrapper of __builtin_hlsl_wave_active_count_bits

Xiang Li via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 30 06:16:57 PDT 2022


Author: Xiang Li
Date: 2022-06-30T06:16:51-07:00
New Revision: a591c7ca0d9fe47223127ee13df60689f36ba112

URL: https://github.com/llvm/llvm-project/commit/a591c7ca0d9fe47223127ee13df60689f36ba112
DIFF: https://github.com/llvm/llvm-project/commit/a591c7ca0d9fe47223127ee13df60689f36ba112.diff

LOG: [HLSL] Change WaveActiveCountBits to wrapper of __builtin_hlsl_wave_active_count_bits

Change WaveActiveCountBits from builtin into wrapper of __builtin_hlsl_wave_active_count_bits.
For comment at
https://reviews.llvm.org/D126857#inline-1235949

Reviewed By: beanz

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

Added: 
    clang/lib/Headers/hlsl/hlsl_intrinsics.h

Modified: 
    clang/include/clang/Basic/Builtins.def
    clang/include/clang/Basic/DiagnosticSemaKinds.td
    clang/lib/Headers/CMakeLists.txt
    clang/lib/Headers/hlsl.h
    clang/lib/Sema/SemaDeclAttr.cpp
    clang/test/SemaHLSL/Wave.hlsl

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/Builtins.def b/clang/include/clang/Basic/Builtins.def
index c084cc2c4cbdf..f19807dbbb0bb 100644
--- a/clang/include/clang/Basic/Builtins.def
+++ b/clang/include/clang/Basic/Builtins.def
@@ -1699,7 +1699,7 @@ BUILTIN(__builtin_os_log_format, "v*v*cC*.", "p:0:nt")
 LANGBUILTIN(__builtin_get_device_side_mangled_name, "cC*.", "ncT", CUDA_LANG)
 
 // HLSL
-LANGBUILTIN(WaveActiveCountBits, "Uib", "nc", HLSL_LANG)
+LANGBUILTIN(__builtin_hlsl_wave_active_count_bits, "Uib", "nc", HLSL_LANG)
 
 // Builtins for XRay
 BUILTIN(__xray_customevent, "vcC*z", "")

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index dc9ca4bd18e2e..880fe0d18a02e 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4183,7 +4183,7 @@ def err_attribute_preferred_name_arg_invalid : Error<
   "argument %0 to 'preferred_name' attribute is not a typedef for "
   "a specialization of %1">;
 def err_attribute_builtin_alias : Error<
-  "%0 attribute can only be applied to a ARM or RISC-V builtin">;
+  "%0 attribute can only be applied to a ARM, HLSL or RISC-V builtin">;
 
 // called-once attribute diagnostics.
 def err_called_once_attribute_wrong_type : Error<

diff  --git a/clang/lib/Headers/CMakeLists.txt b/clang/lib/Headers/CMakeLists.txt
index dfa3602b557b1..5a0268da14a5f 100644
--- a/clang/lib/Headers/CMakeLists.txt
+++ b/clang/lib/Headers/CMakeLists.txt
@@ -65,6 +65,7 @@ set(hip_files
 set(hlsl_files
   hlsl.h
   hlsl/hlsl_basic_types.h
+  hlsl/hlsl_intrinsics.h
   )
 
 set(mips_msa_files

diff  --git a/clang/lib/Headers/hlsl.h b/clang/lib/Headers/hlsl.h
index 0db8a4ed1fe40..a9dce4503ddd9 100644
--- a/clang/lib/Headers/hlsl.h
+++ b/clang/lib/Headers/hlsl.h
@@ -10,5 +10,6 @@
 #define _HLSL_H_
 
 #include "hlsl/hlsl_basic_types.h"
+#include "hlsl/hlsl_intrinsics.h"
 
 #endif //_HLSL_H_

diff  --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
new file mode 100644
index 0000000000000..b5cdb8b449709
--- /dev/null
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -0,0 +1,15 @@
+//===----- hlsl_intrinsics.h - HLSL definitions for intrinsics ----------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _HLSL_HLSL_INTRINSICS_H_
+#define _HLSL_HLSL_INTRINSICS_H_
+
+__attribute__((clang_builtin_alias(__builtin_hlsl_wave_active_count_bits))) uint
+WaveActiveCountBits(bool bBit);
+
+#endif //_HLSL_HLSL_INTRINSICS_H_

diff  --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 52fd5fc637d36..f79523983ed89 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -5629,11 +5629,12 @@ static void handleBuiltinAliasAttr(Sema &S, Decl *D,
   bool IsAArch64 = S.Context.getTargetInfo().getTriple().isAArch64();
   bool IsARM = S.Context.getTargetInfo().getTriple().isARM();
   bool IsRISCV = S.Context.getTargetInfo().getTriple().isRISCV();
+  bool IsHLSL = S.Context.getLangOpts().HLSL;
   if ((IsAArch64 && !ArmSveAliasValid(S.Context, BuiltinID, AliasName)) ||
       (IsARM && !ArmMveAliasValid(BuiltinID, AliasName) &&
        !ArmCdeAliasValid(BuiltinID, AliasName)) ||
       (IsRISCV && !RISCVAliasValid(BuiltinID, AliasName)) ||
-      (!IsAArch64 && !IsARM && !IsRISCV)) {
+      (!IsAArch64 && !IsARM && !IsRISCV && !IsHLSL)) {
     S.Diag(AL.getLoc(), diag::err_attribute_builtin_alias) << AL;
     return;
   }

diff  --git a/clang/test/SemaHLSL/Wave.hlsl b/clang/test/SemaHLSL/Wave.hlsl
index ed64d1a5a55ba..3222a7e9366ad 100644
--- a/clang/test/SemaHLSL/Wave.hlsl
+++ b/clang/test/SemaHLSL/Wave.hlsl
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1  -x hlsl -triple dxil--shadermodel6.7-library  %s  -verify
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple dxil--shadermodel6.7-library  %s  -verify
 
 // Make sure WaveActiveCountBits is accepted.
 


        


More information about the cfe-commits mailing list