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
#ifndef _HLSL_HLSL_BASIC_TYPES_H_
#define _HLSL_HLSL_BASIC_TYPES_H_
+namespace hlsl {
// built-in scalar data types:
#ifdef __HLSL_ENABLE_16_BIT
typedef vector<double, 3> double3;
typedef vector<double, 4> double4;
+} // namespace hlsl
+
#endif //_HLSL_HLSL_BASIC_TYPES_H_
#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);
__attribute__((clang_builtin_alias(__builtin_elementwise_ceil)))
double4 ceil(double4);
+} // namespace hlsl
+
#endif //_HLSL_HLSL_INTRINSICS_H_
// 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);
// 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.
// 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"(
// 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);
// expected-no-diagnostics
unsigned foo(bool b) {
- return WaveActiveCountBits(b);
+ return hlsl::WaveActiveCountBits(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
}