Move HLSL builtins into hlsl namespace
authorChris Bieneman <chris.bieneman@me.com>
Wed, 19 Oct 2022 15:18:19 +0000 (10:18 -0500)
committerChris Bieneman <chris.bieneman@me.com>
Wed, 19 Oct 2022 15:59:31 +0000 (10:59 -0500)
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

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

index e68715f..9ea605c 100644 (file)
@@ -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_
index 43f8dfe..e0099d4 100644 (file)
@@ -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_
index d26d949..15c963d 100644 (file)
@@ -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
 // CHECK:"?double3_Val@@3T?$__vector@N$02@__clang@@A" = global <3 x double> zeroinitializer, align 32
 // CHECK:"?double4_Val@@3T?$__vector@N$03@__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);
index 30b0bcb..e014680 100644 (file)
@@ -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.
index 69f2b82..5969028 100644 (file)
@@ -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"(
index c083ce1..7762693 100644 (file)
@@ -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);
index 3222a7e..9c99499 100644 (file)
@@ -4,5 +4,5 @@
 
 // expected-no-diagnostics
 unsigned foo(bool b) {
-    return WaveActiveCountBits(b);
+    return hlsl::WaveActiveCountBits(b);
 }
index 0851b90..0e45edc 100644 (file)
@@ -5,5 +5,5 @@ unsigned foo(bool b) {
     // expected-warning@#site {{'WaveActiveCountBits' is only available on HLSL ShaderModel 6.0 or newer}}
     // expected-note@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
 }