[clang] d146a52 - Move HLSL builtins into hlsl namespace

Chris Bieneman via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 19 08:59:40 PDT 2022


Author: Chris Bieneman
Date: 2022-10-19T10:59:31-05:00
New Revision: d146a5241c5039fd25e8bf5a4ae1200ad201d06c

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

LOG: Move HLSL builtins into hlsl namespace

Should have done this from the start. Since all the injected AST types
are in the hlsl namespace we should also put the header-defined types
and functions in there too.

This updates the basic_types test to run once with the namespaced types
and once without, and adds using declarations or namespaces calls in
other tests.

Reviewed By: python3kgae

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

Added: 
    

Modified: 
    clang/lib/Headers/hlsl/hlsl_basic_types.h
    clang/lib/Headers/hlsl/hlsl_intrinsics.h
    clang/test/CodeGenHLSL/basic_types.hlsl
    clang/test/CodeGenHLSL/builtins/abs.hlsl
    clang/test/CodeGenHLSL/builtins/ceil.hlsl
    clang/test/CodeGenHLSL/builtins/sqrt.hlsl
    clang/test/SemaHLSL/Wave.hlsl
    clang/test/SemaHLSL/WaveBuiltinAvailability.hlsl

Removed: 
    


################################################################################
diff  --git a/clang/lib/Headers/hlsl/hlsl_basic_types.h b/clang/lib/Headers/hlsl/hlsl_basic_types.h
index e68715f1a6a45..9ea605cfa840a 100644
--- a/clang/lib/Headers/hlsl/hlsl_basic_types.h
+++ b/clang/lib/Headers/hlsl/hlsl_basic_types.h
@@ -9,6 +9,7 @@
 #ifndef _HLSL_HLSL_BASIC_TYPES_H_
 #define _HLSL_HLSL_BASIC_TYPES_H_
 
+namespace hlsl {
 // built-in scalar data types:
 
 #ifdef __HLSL_ENABLE_16_BIT
@@ -61,4 +62,6 @@ typedef vector<double, 2> double2;
 typedef vector<double, 3> double3;
 typedef vector<double, 4> double4;
 
+} // namespace hlsl
+
 #endif //_HLSL_HLSL_BASIC_TYPES_H_

diff  --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 43f8dfee7a5f1..e0099d435308b 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -9,6 +9,8 @@
 #ifndef _HLSL_HLSL_INTRINSICS_H_
 #define _HLSL_HLSL_INTRINSICS_H_
 
+namespace hlsl {
+
 __attribute__((availability(shadermodel, introduced = 6.0)))
 __attribute__((clang_builtin_alias(__builtin_hlsl_wave_active_count_bits))) uint
 WaveActiveCountBits(bool bBit);
@@ -99,4 +101,6 @@ double3 ceil(double3);
 __attribute__((clang_builtin_alias(__builtin_elementwise_ceil)))
 double4 ceil(double4);
 
+} // namespace hlsl
+
 #endif //_HLSL_HLSL_INTRINSICS_H_

diff  --git a/clang/test/CodeGenHLSL/basic_types.hlsl b/clang/test/CodeGenHLSL/basic_types.hlsl
index d26d94910c2d8..15c963dfa666f 100644
--- a/clang/test/CodeGenHLSL/basic_types.hlsl
+++ b/clang/test/CodeGenHLSL/basic_types.hlsl
@@ -1,6 +1,9 @@
 // RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
 // RUN:   dxil-pc-shadermodel6.3-library %s -fnative-half-type \
 // RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -fnative-half-type \
+// RUN:   -emit-llvm -disable-llvm-passes -o - -DNAMESPACED| FileCheck %s
 
 
 // CHECK:"?uint16_t_Val@@3GA" = global i16 0, align 2
@@ -36,7 +39,11 @@
 // CHECK:"?double3_Val@@3T?$__vector at N$02 at __clang@@A" = global <3 x double> zeroinitializer, align 32
 // CHECK:"?double4_Val@@3T?$__vector at N$03 at __clang@@A" = global <4 x double> zeroinitializer, align 32
 
+#ifdef NAMESPACED
+#define TYPE_DECL(T)  hlsl::T T##_Val
+#else
 #define TYPE_DECL(T)  T T##_Val
+#endif
 
 #ifdef __HLSL_ENABLE_16_BIT
 TYPE_DECL(uint16_t);

diff  --git a/clang/test/CodeGenHLSL/builtins/abs.hlsl b/clang/test/CodeGenHLSL/builtins/abs.hlsl
index 30b0bcb8837ca..e014680ff2c1c 100644
--- a/clang/test/CodeGenHLSL/builtins/abs.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/abs.hlsl
@@ -5,6 +5,7 @@
 // RUN:   dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
 // RUN:   -D__HLSL_ENABLE_16_BIT -o - | FileCheck %s --check-prefix=NO_HALF
 
+using hlsl::abs;
 
 // CHECK: define noundef signext i16 @
 // FIXME: int16_t is promoted to i32 now. Change to abs.i16 once it is fixed.

diff  --git a/clang/test/CodeGenHLSL/builtins/ceil.hlsl b/clang/test/CodeGenHLSL/builtins/ceil.hlsl
index 69f2b82730673..5969028d56d1a 100644
--- a/clang/test/CodeGenHLSL/builtins/ceil.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/ceil.hlsl
@@ -5,6 +5,8 @@
 // RUN:   dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
 // RUN:   -D__HLSL_ENABLE_16_BIT -o - | FileCheck %s --check-prefix=NO_HALF
 
+using hlsl::ceil;
+
 // CHECK: define noundef half @
 // CHECK: call half @llvm.ceil.f16(
 // NO_HALF: define noundef float @"?test_ceil_half@@YA$halff@$halff@@Z"(

diff  --git a/clang/test/CodeGenHLSL/builtins/sqrt.hlsl b/clang/test/CodeGenHLSL/builtins/sqrt.hlsl
index c083ce1175e59..776269395a662 100644
--- a/clang/test/CodeGenHLSL/builtins/sqrt.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/sqrt.hlsl
@@ -5,6 +5,8 @@
 // RUN:   dxil-pc-shadermodel6.2-library %s -emit-llvm -disable-llvm-passes \
 // RUN:   -o - | FileCheck %s --check-prefix=NO_HALF
 
+using hlsl::sqrt;
+
 double sqrt_d(double x)
 {
   return sqrt(x);

diff  --git a/clang/test/SemaHLSL/Wave.hlsl b/clang/test/SemaHLSL/Wave.hlsl
index 3222a7e9366ad..9c99499d22509 100644
--- a/clang/test/SemaHLSL/Wave.hlsl
+++ b/clang/test/SemaHLSL/Wave.hlsl
@@ -4,5 +4,5 @@
 
 // expected-no-diagnostics
 unsigned foo(bool b) {
-    return WaveActiveCountBits(b);
+    return hlsl::WaveActiveCountBits(b);
 }

diff  --git a/clang/test/SemaHLSL/WaveBuiltinAvailability.hlsl b/clang/test/SemaHLSL/WaveBuiltinAvailability.hlsl
index 0851b90eb9765..0e45edc6a4c86 100644
--- a/clang/test/SemaHLSL/WaveBuiltinAvailability.hlsl
+++ b/clang/test/SemaHLSL/WaveBuiltinAvailability.hlsl
@@ -5,5 +5,5 @@ unsigned foo(bool b) {
     // expected-warning@#site {{'WaveActiveCountBits' is only available on HLSL ShaderModel 6.0 or newer}}
     // expected-note at hlsl/hlsl_intrinsics.h:* {{'WaveActiveCountBits' has been marked as being introduced in HLSL ShaderModel 6.0 here, but the deployment target is HLSL ShaderModel 5.0}}
     // expected-note@#site {{enclose 'WaveActiveCountBits' in a __builtin_available check to silence this warning}}
-    return WaveActiveCountBits(b); // #site
+    return hlsl::WaveActiveCountBits(b); // #site
 }


        


More information about the cfe-commits mailing list