python3kgae created this revision. python3kgae added reviewers: svenvh, asavonic, beanz, pow2clk. Herald added subscribers: Anastasia, mgorny. Herald added a project: All. python3kgae requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Vector types in hlsl is using clang ext_vector_type. Declaration of vector types is in builtin header hlsl.h. hlsl.h will be included by default for hlsl shader. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D125052 Files: clang/lib/Basic/LangOptions.cpp clang/lib/Frontend/CompilerInvocation.cpp clang/lib/Frontend/InitPreprocessor.cpp clang/lib/Headers/CMakeLists.txt clang/lib/Headers/hlsl.h clang/lib/Headers/hlsl/hlsl_basic_types.h clang/test/CodeGenHLSL/basic_types.hlsl
Index: clang/test/CodeGenHLSL/basic_types.hlsl =================================================================== --- /dev/null +++ clang/test/CodeGenHLSL/basic_types.hlsl @@ -0,0 +1,76 @@ +// RUN: %clang_dxc -Tlib_6_7 -Fo - %s | FileCheck %s + +// FIXME: check 16bit types once enable-16bit-types is ready. + +// CHECK:@uint_Val = global i32 0, align 4 +// CHECK:@uint64_t_Val = global i64 0, align 8 +// CHECK:@int64_t_Val = global i64 0, align 8 +// CHECK:@int2_Val = global <2 x i32> zeroinitializer, align 8 +// CHECK:@int3_Val = global <3 x i32> zeroinitializer, align 16 +// CHECK:@int4_Val = global <4 x i32> zeroinitializer, align 16 +// CHECK:@uint2_Val = global <2 x i32> zeroinitializer, align 8 +// CHECK:@uint3_Val = global <3 x i32> zeroinitializer, align 16 +// CHECK:@uint4_Val = global <4 x i32> zeroinitializer, align 16 +// CHECK:@int64_t2_Val = global <2 x i64> zeroinitializer, align 16 +// CHECK:@int64_t3_Val = global <3 x i64> zeroinitializer, align 32 +// CHECK:@int64_t4_Val = global <4 x i64> zeroinitializer, align 32 +// CHECK:@uint64_t2_Val = global <2 x i64> zeroinitializer, align 16 +// CHECK:@uint64_t3_Val = global <3 x i64> zeroinitializer, align 32 +// CHECK:@uint64_t4_Val = global <4 x i64> zeroinitializer, align 32 +// CHECK:@float2_Val = global <2 x float> zeroinitializer, align 8 +// CHECK:@float3_Val = global <3 x float> zeroinitializer, align 16 +// CHECK:@float4_Val = global <4 x float> zeroinitializer, align 16 +// CHECK:@double2_Val = global <2 x double> zeroinitializer, align 16 +// CHECK:@double3_Val = global <3 x double> zeroinitializer, align 32 +// CHECK:@double4_Val = global <4 x double> zeroinitializer, align 32 + +#define TYPE_DECL(T) T T##_Val + +#ifdef __HLSL_ENABLE_16_BIT +TYPE_DECL(uint16_t); +TYPE_DECL(int16_t); +#endif + +// unsigned 32-bit integer. +TYPE_DECL(uint); + +// 64-bit integer. +TYPE_DECL(uint64_t); +TYPE_DECL(int64_t); + +// built-in vector data types: + +#ifdef __HLSL_ENABLE_16_BIT +TYPE_DECL(int16_t2 ); +TYPE_DECL(int16_t3 ); +TYPE_DECL(int16_t4 ); +TYPE_DECL( uint16_t2 ); +TYPE_DECL( uint16_t3 ); +TYPE_DECL( uint16_t4 ); +#endif + +TYPE_DECL( int2 ); +TYPE_DECL( int3 ); +TYPE_DECL( int4 ); +TYPE_DECL( uint2 ); +TYPE_DECL( uint3 ); +TYPE_DECL( uint4 ); +TYPE_DECL( int64_t2 ); +TYPE_DECL( int64_t3 ); +TYPE_DECL( int64_t4 ); +TYPE_DECL( uint64_t2 ); +TYPE_DECL( uint64_t3 ); +TYPE_DECL( uint64_t4 ); + +#ifdef __HLSL_ENABLE_16_BIT +TYPE_DECL(half2 ); +TYPE_DECL(half3 ); +TYPE_DECL(half4 ); +#endif + +TYPE_DECL( float2 ); +TYPE_DECL( float3 ); +TYPE_DECL( float4 ); +TYPE_DECL( double2 ); +TYPE_DECL( double3 ); +TYPE_DECL( double4 ); Index: clang/lib/Headers/hlsl/hlsl_basic_types.h =================================================================== --- /dev/null +++ clang/lib/Headers/hlsl/hlsl_basic_types.h @@ -0,0 +1,64 @@ +//===----- hlsl_basic_types.h - HLSL definitions for basic types ----------===// +// +// 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_BASIC_TYPES_H_ +#define _HLSL_HLSL_BASIC_TYPES_H_ + +// built-in scalar data types: + +#ifdef __HLSL_ENABLE_16_BIT +// 16-bit integer. +typedef unsigned short uint16_t; +typedef short int16_t; +#endif + +// unsigned 32-bit integer. +typedef unsigned int uint; + +// 64-bit integer. +typedef unsigned long uint64_t; +typedef long int64_t; + +// built-in vector data types: + +#ifdef __HLSL_ENABLE_16_BIT +typedef int16_t int16_t2 __attribute__((ext_vector_type(2))); +typedef int16_t int16_t3 __attribute__((ext_vector_type(3))); +typedef int16_t int16_t4 __attribute__((ext_vector_type(4))); +typedef uint16_t uint16_t2 __attribute__((ext_vector_type(2))); +typedef uint16_t uint16_t3 __attribute__((ext_vector_type(3))); +typedef uint16_t uint16_t4 __attribute__((ext_vector_type(4))); +#endif + +typedef int int2 __attribute__((ext_vector_type(2))); +typedef int int3 __attribute__((ext_vector_type(3))); +typedef int int4 __attribute__((ext_vector_type(4))); +typedef uint uint2 __attribute__((ext_vector_type(2))); +typedef uint uint3 __attribute__((ext_vector_type(3))); +typedef uint uint4 __attribute__((ext_vector_type(4))); +typedef int64_t int64_t2 __attribute__((ext_vector_type(2))); +typedef int64_t int64_t3 __attribute__((ext_vector_type(3))); +typedef int64_t int64_t4 __attribute__((ext_vector_type(4))); +typedef uint64_t uint64_t2 __attribute__((ext_vector_type(2))); +typedef uint64_t uint64_t3 __attribute__((ext_vector_type(3))); +typedef uint64_t uint64_t4 __attribute__((ext_vector_type(4))); + +#ifdef __HLSL_ENABLE_16_BIT +typedef half half2 __attribute__((ext_vector_type(2))); +typedef half half3 __attribute__((ext_vector_type(3))); +typedef half half4 __attribute__((ext_vector_type(4))); +#endif + +typedef float float2 __attribute__((ext_vector_type(2))); +typedef float float3 __attribute__((ext_vector_type(3))); +typedef float float4 __attribute__((ext_vector_type(4))); +typedef double double2 __attribute__((ext_vector_type(2))); +typedef double double3 __attribute__((ext_vector_type(3))); +typedef double double4 __attribute__((ext_vector_type(4))); + +#endif //_HLSL_HLSL_BASIC_TYPES_H_ Index: clang/lib/Headers/hlsl.h =================================================================== --- /dev/null +++ clang/lib/Headers/hlsl.h @@ -0,0 +1,14 @@ +//===----- hlsl.h - HLSL definitions --------------------------------------===// +// +// 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_H_ +#define _HLSL_H_ + +#include "hlsl/hlsl_basic_types.h" + +#endif //_HLSL_H_ Index: clang/lib/Headers/CMakeLists.txt =================================================================== --- clang/lib/Headers/CMakeLists.txt +++ clang/lib/Headers/CMakeLists.txt @@ -62,6 +62,11 @@ __clang_hip_runtime_wrapper.h ) +set(hlsl_files + hlsl.h + hlsl/hlsl_basic_types.h + ) + set(mips_msa_files msa.h ) @@ -209,6 +214,7 @@ ${cuda_files} ${hexagon_files} ${hip_files} + ${hlsl_files} ${mips_msa_files} ${opencl_files} ${ppc_files} @@ -399,6 +405,7 @@ add_header_target("x86-resource-headers" "${x86_files}") # Other header groupings +add_header_target("hlsl-resource-headers" ${hlsl_files}) add_header_target("opencl-resource-headers" ${opencl_files}) add_header_target("openmp-resource-headers" ${openmp_wrapper_files}) add_header_target("windows-resource-headers" ${windows_only_files}) @@ -526,6 +533,12 @@ EXCLUDE_FROM_ALL COMPONENT x86-resource-headers) +install( + FILES ${hlsl_files} + DESTINATION ${header_install_dir} + EXCLUDE_FROM_ALL + COMPONENT hlsl-resource-headers) + install( FILES ${opencl_files} DESTINATION ${header_install_dir} @@ -599,6 +612,9 @@ DEPENDS webassembly-resource-headers COMPONENT webassembly-resource-headers) + add_llvm_install_targets(install-hlsl-resource-headers + DEPENDS hlsl-resource-headers + COMPONENT hlsl-resource-headers) add_llvm_install_targets(install-opencl-resource-headers DEPENDS opencl-resource-headers COMPONENT opencl-resource-headers) Index: clang/lib/Frontend/InitPreprocessor.cpp =================================================================== --- clang/lib/Frontend/InitPreprocessor.cpp +++ clang/lib/Frontend/InitPreprocessor.cpp @@ -377,6 +377,10 @@ Builder.defineMacro("__HLSL_VERSION", Twine((unsigned)LangOpts.getHLSLVersion())); + if (LangOpts.NativeHalfType) + Builder.defineMacro("__HLSL_ENABLE_16_BIT", + Twine((unsigned)LangOpts.getHLSLVersion())); + // Shader target information // "enums" for shader stages Builder.defineMacro("__SHADER_STAGE_VERTEX", Index: clang/lib/Frontend/CompilerInvocation.cpp =================================================================== --- clang/lib/Frontend/CompilerInvocation.cpp +++ clang/lib/Frontend/CompilerInvocation.cpp @@ -4216,6 +4216,10 @@ ((LangOpts.DeclareOpenCLBuiltins && I == "opencl-c-base.h") || I == "opencl-c.h")) continue; + // Don't generate HLSL includes. They are implied by other flags that are + // generated elsewhere. + if (LangOpts.HLSL && I == "hlsl.h") + continue; GenerateArg(Args, OPT_include, I, SA); } Index: clang/lib/Basic/LangOptions.cpp =================================================================== --- clang/lib/Basic/LangOptions.cpp +++ clang/lib/Basic/LangOptions.cpp @@ -118,6 +118,8 @@ Opts.Digraphs = Std.hasDigraphs(); Opts.HLSL = Lang == Language::HLSL; + if (Opts.HLSL) + Includes.push_back("hlsl.h"); // Set OpenCL Version. Opts.OpenCL = Std.isOpenCL();
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits