diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 7557cb8408921..4967c1f11dd2e 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -56,6 +56,7 @@ #include "llvm/Target/TargetOptions.h" #include "llvm/TargetParser/SubtargetFeature.h" #include "llvm/TargetParser/Triple.h" +#include "llvm/Transforms/HLSL/HLSLFinalizeLinkage.h" #include "llvm/Transforms/HipStdPar/HipStdPar.h" #include "llvm/Transforms/IPO/EmbedBitcodePass.h" #include "llvm/Transforms/IPO/LowerTypeTests.h" @@ -1115,6 +1116,11 @@ void EmitAssemblyHelper::RunOptimizationPipeline( if (CodeGenOpts.LinkBitcodePostopt) MPM.addPass(LinkInModulesPass(BC)); + if (LangOpts.HLSL && !CodeGenOpts.DisableLLVMPasses) { + // Passes required by HLSL for every backend. + MPM.addPass(HLSLFinalizeLinkage()); + } + // Add a verifier pass if requested. We don't have to do this if the action // requires code generation because there will already be a verifier pass in // the code-generation pipeline. diff --git a/clang/lib/CodeGen/CMakeLists.txt b/clang/lib/CodeGen/CMakeLists.txt index ebe2fbd7db295..65a23291029b4 100644 --- a/clang/lib/CodeGen/CMakeLists.txt +++ b/clang/lib/CodeGen/CMakeLists.txt @@ -14,6 +14,7 @@ set(LLVM_LINK_COMPONENTS FrontendOpenMP FrontendOffloading HIPStdPar + HLSL IPO IRPrinter IRReader diff --git a/clang/test/CodeGenHLSL/builtins/D3DCOLORtoUBYTE4.hlsl b/clang/test/CodeGenHLSL/builtins/D3DCOLORtoUBYTE4.hlsl index 990f0aa910f30..d376efa9307db 100644 --- a/clang/test/CodeGenHLSL/builtins/D3DCOLORtoUBYTE4.hlsl +++ b/clang/test/CodeGenHLSL/builtins/D3DCOLORtoUBYTE4.hlsl @@ -3,7 +3,7 @@ // RUN: -emit-llvm -O1 -o - | FileCheck %s --check-prefixes=CHECK // CHECK-LABEL: D3DCOLORtoUBYTE4 -int4 test_D3DCOLORtoUBYTE4(float4 p1) { +export int4 test_D3DCOLORtoUBYTE4(float4 p1) { // CHECK: %[[SCALED:.*]] = fmul [[FMFLAGS:.*]][[FLOAT_TYPE:<4 x float>]] %{{.*}}, splat (float 0x406FE01000000000) // CHECK: %[[CONVERTED:.*]] = fptoui [[FLOAT_TYPE]] %[[SCALED]] to [[INT_TYPE:<4 x i32>]] // CHECK: %[[SHUFFLED:.*]] = shufflevector [[INT_TYPE]] %[[CONVERTED]], [[INT_TYPE]] poison, <4 x i32> diff --git a/clang/test/CodeGenHLSL/builtins/and.hlsl b/clang/test/CodeGenHLSL/builtins/and.hlsl index b77889cd9ae70..7c008f8eee469 100644 --- a/clang/test/CodeGenHLSL/builtins/and.hlsl +++ b/clang/test/CodeGenHLSL/builtins/and.hlsl @@ -9,7 +9,7 @@ // CHECK-NEXT: [[HLSL_AND:%.*]] = and i1 [[X]], [[Y]] // CHECK-NEXT: ret i1 [[HLSL_AND]] // -bool test_and_scalar(bool x, bool y) { +export bool test_and_scalar(bool x, bool y) { return and(x, y); } @@ -19,7 +19,7 @@ bool test_and_scalar(bool x, bool y) { // CHECK-NEXT: [[HLSL_AND:%.*]] = and <2 x i1> [[X]], [[Y]] // CHECK-NEXT: ret <2 x i1> [[HLSL_AND]] // -bool2 test_and_bool2(bool2 x, bool2 y) { +export bool2 test_and_bool2(bool2 x, bool2 y) { return and(x, y); } @@ -29,7 +29,7 @@ bool2 test_and_bool2(bool2 x, bool2 y) { // CHECK-NEXT: [[HLSL_AND:%.*]] = and <3 x i1> [[X]], [[Y]] // CHECK-NEXT: ret <3 x i1> [[HLSL_AND]] // -bool3 test_and_bool3(bool3 x, bool3 y) { +export bool3 test_and_bool3(bool3 x, bool3 y) { return and(x, y); } @@ -39,7 +39,7 @@ bool3 test_and_bool3(bool3 x, bool3 y) { // CHECK-NEXT: [[HLSL_AND:%.*]] = and <4 x i1> [[X]], [[Y]] // CHECK-NEXT: ret <4 x i1> [[HLSL_AND]] // -bool4 test_and_bool4(bool4 x, bool4 y) { +export bool4 test_and_bool4(bool4 x, bool4 y) { return and(x, y); } @@ -51,7 +51,7 @@ bool4 test_and_bool4(bool4 x, bool4 y) { // CHECK-NEXT: [[HLSL_AND:%.*]] = and <4 x i1> [[TOBOOL]], [[TOBOOL1]] // CHECK-NEXT: ret <4 x i1> [[HLSL_AND]] // -bool4 test_and_int4(int4 x, int4 y) { +export bool4 test_and_int4(int4 x, int4 y) { return and(x, y); } @@ -63,6 +63,6 @@ bool4 test_and_int4(int4 x, int4 y) { // CHECK-NEXT: [[HLSL_AND:%.*]] = and <4 x i1> [[TOBOOL]], [[TOBOOL1]] // CHECK-NEXT: ret <4 x i1> [[HLSL_AND]] // -bool4 test_and_float4(float4 x, float4 y) { +export bool4 test_and_float4(float4 x, float4 y) { return and(x, y); } diff --git a/clang/test/CodeGenHLSL/builtins/asfloat.hlsl b/clang/test/CodeGenHLSL/builtins/asfloat.hlsl index 59fc15fa60b1e..f991eb8f78e61 100644 --- a/clang/test/CodeGenHLSL/builtins/asfloat.hlsl +++ b/clang/test/CodeGenHLSL/builtins/asfloat.hlsl @@ -2,39 +2,39 @@ // CHECK: define {{.*}}test_uint{{.*}}(i32 {{.*}} [[VAL:%.*]]){{.*}} // CHECK: bitcast i32 [[VAL]] to float -float test_uint(uint p0) { +export float test_uint(uint p0) { return asfloat(p0); } // CHECK: define {{.*}}test_int{{.*}}(i32 {{.*}} [[VAL:%.*]]){{.*}} // CHECK: bitcast i32 [[VAL]] to float -float test_int(int p0) { +export float test_int(int p0) { return asfloat(p0); } // CHECK: define {{.*}}test_float{{.*}}(float {{.*}} [[VAL:%.*]]){{.*}} // CHECK-NOT: bitcast // CHECK: ret float [[VAL]] -float test_float(float p0) { +export float test_float(float p0) { return asfloat(p0); } // CHECK: define {{.*}}test_vector_uint{{.*}}(<4 x i32> {{.*}} [[VAL:%.*]]){{.*}} // CHECK: bitcast <4 x i32> [[VAL]] to <4 x float> -float4 test_vector_uint(uint4 p0) { +export float4 test_vector_uint(uint4 p0) { return asfloat(p0); } // CHECK: define {{.*}}test_vector_int{{.*}}(<4 x i32> {{.*}} [[VAL:%.*]]){{.*}} // CHECK: bitcast <4 x i32> [[VAL]] to <4 x float> -float4 test_vector_int(int4 p0) { +export float4 test_vector_int(int4 p0) { return asfloat(p0); } // CHECK: define {{.*}}test_vector_float{{.*}}(<4 x float> {{.*}} [[VAL:%.*]]){{.*}} // CHECK-NOT: bitcast // CHECK: ret <4 x float> [[VAL]] -float4 test_vector_float(float4 p0) { +export float4 test_vector_float(float4 p0) { return asfloat(p0); } diff --git a/clang/test/CodeGenHLSL/builtins/asint.hlsl b/clang/test/CodeGenHLSL/builtins/asint.hlsl index e1d80df5015c9..a5d3320a3f580 100644 --- a/clang/test/CodeGenHLSL/builtins/asint.hlsl +++ b/clang/test/CodeGenHLSL/builtins/asint.hlsl @@ -3,39 +3,39 @@ // CHECK: define {{.*}}test_int{{.*}}(i32 {{.*}} [[VAL:%.*]]){{.*}} // CHECK-NOT: bitcast // CHECK: ret i32 [[VAL]] -int test_int(int p0) { +export int test_int(int p0) { return asint(p0); } // CHECK: define {{.*}}test_uint{{.*}}(i32 {{.*}} [[VAL:%.*]]){{.*}} // CHECK-NOT: bitcast // CHECK: ret i32 [[VAL]] -int test_uint(uint p0) { +export int test_uint(uint p0) { return asint(p0); } // CHECK: define {{.*}}test_float{{.*}}(float {{.*}} [[VAL:%.*]]){{.*}} // CHECK: bitcast float [[VAL]] to i32 -int test_float(float p0) { +export int test_float(float p0) { return asint(p0); } // CHECK: define {{.*}}test_vector_int{{.*}}(<4 x i32> {{.*}} [[VAL:%.*]]){{.*}} // CHECK-NOT: bitcast // CHECK: ret <4 x i32> [[VAL]] -int4 test_vector_int(int4 p0) { +export int4 test_vector_int(int4 p0) { return asint(p0); } // CHECK: define {{.*}}test_vector_uint{{.*}}(<4 x i32> {{.*}} [[VAL:%.*]]){{.*}} // CHECK-NOT: bitcast // CHECK: ret <4 x i32> [[VAL]] -int4 test_vector_uint(uint4 p0) { +export int4 test_vector_uint(uint4 p0) { return asint(p0); } // CHECK: define {{.*}}test_vector_float{{.*}}(<4 x float> {{.*}} [[VAL:%.*]]){{.*}} // CHECK: bitcast <4 x float> [[VAL]] to <4 x i32> -int4 test_vector_float(float4 p0) { +export int4 test_vector_float(float4 p0) { return asint(p0); } diff --git a/clang/test/CodeGenHLSL/builtins/asint16.hlsl b/clang/test/CodeGenHLSL/builtins/asint16.hlsl index 1d35125bfb8cc..63f99ec5b53ad 100644 --- a/clang/test/CodeGenHLSL/builtins/asint16.hlsl +++ b/clang/test/CodeGenHLSL/builtins/asint16.hlsl @@ -5,7 +5,7 @@ //CHECK-NOT: bitcast //CHECK: entry: //CHECK-NEXT: ret i16 [[VAL]] -int16_t test_int(int16_t p0) +export int16_t test_int(int16_t p0) { return asint16(p0); } @@ -15,7 +15,7 @@ int16_t test_int(int16_t p0) //CHECK-NOT:bitcast //CHECK: entry: //CHECK-NEXT: ret i16 [[VAL]] -int16_t test_uint(uint16_t p0) +export int16_t test_uint(uint16_t p0) { return asint16(p0); } @@ -24,7 +24,7 @@ int16_t test_uint(uint16_t p0) //CHECK-SAME: {{.*}}(half {{.*}} [[VAL:%.*]]){{.*}} //CHECK: [[RES:%.*]] = bitcast half [[VAL]] to i16 //CHECK-NEXT : ret i16 [[RES]] -int16_t test_half(half p0) +export int16_t test_half(half p0) { return asint16(p0); } @@ -34,7 +34,7 @@ int16_t test_half(half p0) //CHECK-NOT: bitcast //CHECK: entry: //CHECK-NEXT: ret <4 x i16> [[VAL]] -int16_t4 test_vector_int(int16_t4 p0) +export int16_t4 test_vector_int(int16_t4 p0) { return asint16(p0); } @@ -44,7 +44,7 @@ int16_t4 test_vector_int(int16_t4 p0) //CHECK-NOT: bitcast //CHECK-NEXT: entry: //CHECK-NEXT: ret <4 x i16> [[VAL]] -int16_t4 test_vector_uint(uint16_t4 p0) +export int16_t4 test_vector_uint(uint16_t4 p0) { return asint16(p0); } @@ -53,7 +53,7 @@ int16_t4 test_vector_uint(uint16_t4 p0) //CHECK-SAME: {{.*}}(<4 x half> {{.*}} [[VAL:%.*]]){{.*}} //CHECK: [[RES:%.*]] = bitcast <4 x half> [[VAL]] to <4 x i16> //CHECK-NEXT: ret <4 x i16> [[RES]] -int16_t4 fn(half4 p1) +export int16_t4 fn(half4 p1) { return asint16(p1); } diff --git a/clang/test/CodeGenHLSL/builtins/asuint.hlsl b/clang/test/CodeGenHLSL/builtins/asuint.hlsl index 252a434ccce0d..a56271e4ad033 100644 --- a/clang/test/CodeGenHLSL/builtins/asuint.hlsl +++ b/clang/test/CodeGenHLSL/builtins/asuint.hlsl @@ -3,39 +3,39 @@ // CHECK: define {{.*}}test_uint{{.*}}(i32 {{.*}} [[VAL:%.*]]){{.*}} // CHECK-NOT: bitcast // CHECK: ret i32 [[VAL]] -uint test_uint(uint p0) { +export uint test_uint(uint p0) { return asuint(p0); } // CHECK: define {{.*}}test_int{{.*}}(i32 {{.*}} [[VAL:%.*]]){{.*}} // CHECK-NOT: bitcast // CHECK: ret i32 [[VAL]] -uint test_int(int p0) { +export uint test_int(int p0) { return asuint(p0); } // CHECK: define {{.*}}test_float{{.*}}(float {{.*}} [[VAL:%.*]]){{.*}} // CHECK: bitcast float [[VAL]] to i32 -uint test_float(float p0) { +export uint test_float(float p0) { return asuint(p0); } // CHECK: define {{.*}}test_vector_uint{{.*}}(<4 x i32> {{.*}} [[VAL:%.*]]){{.*}} // CHECK-NOT: bitcast // CHECK: ret <4 x i32> [[VAL]] -uint4 test_vector_uint(uint4 p0) { +export uint4 test_vector_uint(uint4 p0) { return asuint(p0); } // CHECK: define {{.*}}test_vector_int{{.*}}(<4 x i32> {{.*}} [[VAL:%.*]]){{.*}} // CHECK-NOT: bitcast // CHECK: ret <4 x i32> [[VAL]] -uint4 test_vector_int(int4 p0) { +export uint4 test_vector_int(int4 p0) { return asuint(p0); } // CHECK: define {{.*}}test_vector_float{{.*}}(<4 x float> {{.*}} [[VAL:%.*]]){{.*}} // CHECK: bitcast <4 x float> [[VAL]] to <4 x i32> -uint4 test_vector_float(float4 p0) { +export uint4 test_vector_float(float4 p0) { return asuint(p0); } diff --git a/clang/test/CodeGenHLSL/builtins/asuint16.hlsl b/clang/test/CodeGenHLSL/builtins/asuint16.hlsl index 3ed7de9dffbe5..8b698d6a983e1 100644 --- a/clang/test/CodeGenHLSL/builtins/asuint16.hlsl +++ b/clang/test/CodeGenHLSL/builtins/asuint16.hlsl @@ -5,7 +5,7 @@ //CHECK-NOT: bitcast //CHECK: entry: //CHECK: ret i16 [[VAL]] -uint16_t test_int(int16_t p0) +export uint16_t test_int(int16_t p0) { return asuint16(p0); } @@ -15,7 +15,7 @@ uint16_t test_int(int16_t p0) //CHECK-NOT: bitcast //CHECK: entry: //CHECK-NEXT: ret i16 [[VAL]] -uint16_t test_uint(uint16_t p0) +export uint16_t test_uint(uint16_t p0) { return asuint16(p0); } @@ -24,7 +24,7 @@ uint16_t test_uint(uint16_t p0) //CHECK-SAME: {{.*}}(half {{.*}} [[VAL:%.*]]){{.*}} //CHECK: [[RES:%.*]] = bitcast half [[VAL]] to i16 //CHECK-NEXT: ret i16 [[RES]] -uint16_t test_half(half p0) +export uint16_t test_half(half p0) { return asuint16(p0); } @@ -34,7 +34,7 @@ uint16_t test_half(half p0) //CHECK-NOT: bitcast //CHECK: entry: //CHECK-NEXT: ret <4 x i16> [[VAL]] -uint16_t4 test_vector_int(int16_t4 p0) +export uint16_t4 test_vector_int(int16_t4 p0) { return asuint16(p0); } @@ -44,7 +44,7 @@ uint16_t4 test_vector_int(int16_t4 p0) //CHECK-NOT: bitcast //CHECK: entry: //CHECK-NEXT: ret <4 x i16> [[VAL]] -uint16_t4 test_vector_uint(uint16_t4 p0) +export uint16_t4 test_vector_uint(uint16_t4 p0) { return asuint16(p0); } @@ -53,7 +53,7 @@ uint16_t4 test_vector_uint(uint16_t4 p0) //CHECK-SAME: {{.*}}(<4 x half> {{.*}} [[VAL:%.*]]){{.*}} //CHECK: [[RES:%.*]] = bitcast <4 x half> [[VAL]] to <4 x i16> //CHECK-NEXT: ret <4 x i16> [[RES]] -uint16_t4 fn(half4 p1) +export uint16_t4 fn(half4 p1) { return asuint16(p1); } diff --git a/clang/test/CodeGenHLSL/builtins/clip.hlsl b/clang/test/CodeGenHLSL/builtins/clip.hlsl index 5a1753766a8a1..155a38de0a35f 100644 --- a/clang/test/CodeGenHLSL/builtins/clip.hlsl +++ b/clang/test/CodeGenHLSL/builtins/clip.hlsl @@ -2,7 +2,7 @@ // RUN: %clang_cc1 -finclude-default-header -triple spirv-vulkan-pixel %s -fnative-half-type -emit-llvm -o - | FileCheck %s --check-prefix=SPIRV -void test_scalar(float Buf) { +export void test_scalar(float Buf) { // CHECK: define void @{{.*}}test_scalar{{.*}}(float {{.*}} [[VALP:%.*]]) // CHECK: [[LOAD:%.*]] = load float, ptr [[VALP]].addr, align 4 // CHECK-NEXT: [[FCMP:%.*]] = fcmp reassoc nnan ninf nsz arcp afn olt float [[LOAD]], 0.000000e+00 @@ -20,7 +20,7 @@ void test_scalar(float Buf) { clip(Buf); } -void test_vector4(float4 Buf) { +export void test_vector4(float4 Buf) { // CHECK: define void @{{.*}}test_vector{{.*}}(<4 x float> {{.*}} [[VALP:%.*]]) // CHECK: [[LOAD:%.*]] = load <4 x float>, ptr [[VALP]].addr, align 16 // CHECK-NEXT: [[FCMP:%.*]] = fcmp reassoc nnan ninf nsz arcp afn olt <4 x float> [[LOAD]], zeroinitializer diff --git a/clang/test/CodeGenHLSL/builtins/distance.hlsl b/clang/test/CodeGenHLSL/builtins/distance.hlsl index e830903261c8c..437fbec095126 100644 --- a/clang/test/CodeGenHLSL/builtins/distance.hlsl +++ b/clang/test/CodeGenHLSL/builtins/distance.hlsl @@ -20,7 +20,7 @@ // SPVCHECK-NEXT: [[ELT_ABS_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn noundef half @llvm.fabs.f16(half [[SUB_I]]) // SPVCHECK-NEXT: ret half [[ELT_ABS_I]] // -half test_distance_half(half X, half Y) { return distance(X, Y); } +export half test_distance_half(half X, half Y) { return distance(X, Y); } // CHECK-LABEL: define noundef nofpclass(nan inf) half @_Z19test_distance_half2Dv2_DhS_( // CHECK-SAME: <2 x half> noundef nofpclass(nan inf) [[X:%.*]], <2 x half> noundef nofpclass(nan inf) [[Y:%.*]]) local_unnamed_addr #[[ATTR0]] { @@ -37,7 +37,7 @@ half test_distance_half(half X, half Y) { return distance(X, Y); } // SPVCHECK-NEXT: [[SPV_LENGTH_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn noundef half @llvm.spv.length.v2f16(<2 x half> [[SUB_I]]) // SPVCHECK-NEXT: ret half [[SPV_LENGTH_I]] // -half test_distance_half2(half2 X, half2 Y) { return distance(X, Y); } +export half test_distance_half2(half2 X, half2 Y) { return distance(X, Y); } // CHECK-LABEL: define noundef nofpclass(nan inf) half @_Z19test_distance_half3Dv3_DhS_( // CHECK-SAME: <3 x half> noundef nofpclass(nan inf) [[X:%.*]], <3 x half> noundef nofpclass(nan inf) [[Y:%.*]]) local_unnamed_addr #[[ATTR0]] { @@ -54,7 +54,7 @@ half test_distance_half2(half2 X, half2 Y) { return distance(X, Y); } // SPVCHECK-NEXT: [[SPV_LENGTH_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn noundef half @llvm.spv.length.v3f16(<3 x half> [[SUB_I]]) // SPVCHECK-NEXT: ret half [[SPV_LENGTH_I]] // -half test_distance_half3(half3 X, half3 Y) { return distance(X, Y); } +export half test_distance_half3(half3 X, half3 Y) { return distance(X, Y); } // CHECK-LABEL: define noundef nofpclass(nan inf) half @_Z19test_distance_half4Dv4_DhS_( // CHECK-SAME: <4 x half> noundef nofpclass(nan inf) [[X:%.*]], <4 x half> noundef nofpclass(nan inf) [[Y:%.*]]) local_unnamed_addr #[[ATTR0]] { @@ -71,7 +71,7 @@ half test_distance_half3(half3 X, half3 Y) { return distance(X, Y); } // SPVCHECK-NEXT: [[SPV_LENGTH_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn noundef half @llvm.spv.length.v4f16(<4 x half> [[SUB_I]]) // SPVCHECK-NEXT: ret half [[SPV_LENGTH_I]] // -half test_distance_half4(half4 X, half4 Y) { return distance(X, Y); } +export half test_distance_half4(half4 X, half4 Y) { return distance(X, Y); } // CHECK-LABEL: define noundef nofpclass(nan inf) float @_Z19test_distance_floatff( // CHECK-SAME: float noundef nofpclass(nan inf) [[X:%.*]], float noundef nofpclass(nan inf) [[Y:%.*]]) local_unnamed_addr #[[ATTR0]] { @@ -87,7 +87,7 @@ half test_distance_half4(half4 X, half4 Y) { return distance(X, Y); } // SPVCHECK-NEXT: [[ELT_ABS_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn noundef float @llvm.fabs.f32(float [[SUB_I]]) // SPVCHECK-NEXT: ret float [[ELT_ABS_I]] // -float test_distance_float(float X, float Y) { return distance(X, Y); } +export float test_distance_float(float X, float Y) { return distance(X, Y); } // CHECK-LABEL: define noundef nofpclass(nan inf) float @_Z20test_distance_float2Dv2_fS_( // CHECK-SAME: <2 x float> noundef nofpclass(nan inf) [[X:%.*]], <2 x float> noundef nofpclass(nan inf) [[Y:%.*]]) local_unnamed_addr #[[ATTR0]] { @@ -104,7 +104,7 @@ float test_distance_float(float X, float Y) { return distance(X, Y); } // SPVCHECK-NEXT: [[SPV_LENGTH_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn noundef float @llvm.spv.length.v2f32(<2 x float> [[SUB_I]]) // SPVCHECK-NEXT: ret float [[SPV_LENGTH_I]] // -float test_distance_float2(float2 X, float2 Y) { return distance(X, Y); } +export float test_distance_float2(float2 X, float2 Y) { return distance(X, Y); } // CHECK-LABEL: define noundef nofpclass(nan inf) float @_Z20test_distance_float3Dv3_fS_( // CHECK-SAME: <3 x float> noundef nofpclass(nan inf) [[X:%.*]], <3 x float> noundef nofpclass(nan inf) [[Y:%.*]]) local_unnamed_addr #[[ATTR0]] { @@ -121,7 +121,7 @@ float test_distance_float2(float2 X, float2 Y) { return distance(X, Y); } // SPVCHECK-NEXT: [[SPV_LENGTH_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn noundef float @llvm.spv.length.v3f32(<3 x float> [[SUB_I]]) // SPVCHECK-NEXT: ret float [[SPV_LENGTH_I]] // -float test_distance_float3(float3 X, float3 Y) { return distance(X, Y); } +export float test_distance_float3(float3 X, float3 Y) { return distance(X, Y); } // CHECK-LABEL: define noundef nofpclass(nan inf) float @_Z20test_distance_float4Dv4_fS_( // CHECK-SAME: <4 x float> noundef nofpclass(nan inf) [[X:%.*]], <4 x float> noundef nofpclass(nan inf) [[Y:%.*]]) local_unnamed_addr #[[ATTR0]] { @@ -138,4 +138,4 @@ float test_distance_float3(float3 X, float3 Y) { return distance(X, Y); } // SPVCHECK-NEXT: [[SPV_LENGTH_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn noundef float @llvm.spv.length.v4f32(<4 x float> [[SUB_I]]) // SPVCHECK-NEXT: ret float [[SPV_LENGTH_I]] // -float test_distance_float4(float4 X, float4 Y) { return distance(X, Y); } +export float test_distance_float4(float4 X, float4 Y) { return distance(X, Y); } diff --git a/clang/test/CodeGenHLSL/builtins/fmod.hlsl b/clang/test/CodeGenHLSL/builtins/fmod.hlsl index 7ecc5854b3988..76b1ddcd2b50a 100644 --- a/clang/test/CodeGenHLSL/builtins/fmod.hlsl +++ b/clang/test/CodeGenHLSL/builtins/fmod.hlsl @@ -47,7 +47,7 @@ // CHECK: define [[FNATTRS]] [[TYPE]] @ // CHECK: %fmod.i = frem reassoc nnan ninf nsz arcp afn [[TYPE]] // CHECK: ret [[TYPE]] %fmod.i -half test_fmod_half(half p0, half p1) { return fmod(p0, p1); } +export half test_fmod_half(half p0, half p1) { return fmod(p0, p1); } // DXCHECK: define [[FNATTRS]] <2 x [[TYPE]]> @ // DXCHECK: %div1.i = fdiv reassoc nnan ninf nsz arcp afn <2 x [[TYPE]]> %{{.*}}, %{{.*}} @@ -61,7 +61,7 @@ half test_fmod_half(half p0, half p1) { return fmod(p0, p1); } // CHECK: define [[FNATTRS]] <2 x [[TYPE]]> @ // CHECK: %fmod.i = frem reassoc nnan ninf nsz arcp afn <2 x [[TYPE]]> // CHECK: ret <2 x [[TYPE]]> %fmod.i -half2 test_fmod_half2(half2 p0, half2 p1) { return fmod(p0, p1); } +export half2 test_fmod_half2(half2 p0, half2 p1) { return fmod(p0, p1); } // DXCHECK: define [[FNATTRS]] <3 x [[TYPE]]> @ // DXCHECK: %div1.i = fdiv reassoc nnan ninf nsz arcp afn <3 x [[TYPE]]> %{{.*}}, %{{.*}} @@ -75,7 +75,7 @@ half2 test_fmod_half2(half2 p0, half2 p1) { return fmod(p0, p1); } // CHECK: define [[FNATTRS]] <3 x [[TYPE]]> @ // CHECK: %fmod.i = frem reassoc nnan ninf nsz arcp afn <3 x [[TYPE]]> // CHECK: ret <3 x [[TYPE]]> %fmod.i -half3 test_fmod_half3(half3 p0, half3 p1) { return fmod(p0, p1); } +export half3 test_fmod_half3(half3 p0, half3 p1) { return fmod(p0, p1); } // DXCHECK: define [[FNATTRS]] <4 x [[TYPE]]> @ // DXCHECK: %div1.i = fdiv reassoc nnan ninf nsz arcp afn <4 x [[TYPE]]> %{{.*}}, %{{.*}} @@ -89,7 +89,7 @@ half3 test_fmod_half3(half3 p0, half3 p1) { return fmod(p0, p1); } // CHECK: define [[FNATTRS]] <4 x [[TYPE]]> @ // CHECK: %fmod.i = frem reassoc nnan ninf nsz arcp afn <4 x [[TYPE]]> // CHECK: ret <4 x [[TYPE]]> %fmod.i -half4 test_fmod_half4(half4 p0, half4 p1) { return fmod(p0, p1); } +export half4 test_fmod_half4(half4 p0, half4 p1) { return fmod(p0, p1); } // DXCHECK: define [[FNATTRS]] float @ // DXCHECK: %div1.i = fdiv reassoc nnan ninf nsz arcp afn float %{{.*}}, %{{.*}} @@ -103,7 +103,7 @@ half4 test_fmod_half4(half4 p0, half4 p1) { return fmod(p0, p1); } // CHECK: define [[FNATTRS]] float @ // CHECK: %fmod.i = frem reassoc nnan ninf nsz arcp afn float // CHECK: ret float %fmod.i -float test_fmod_float(float p0, float p1) { return fmod(p0, p1); } +export float test_fmod_float(float p0, float p1) { return fmod(p0, p1); } // DXCHECK: define [[FNATTRS]] <2 x float> @ // DXCHECK: %div1.i = fdiv reassoc nnan ninf nsz arcp afn <2 x float> %{{.*}}, %{{.*}} @@ -117,7 +117,7 @@ float test_fmod_float(float p0, float p1) { return fmod(p0, p1); } // CHECK: define [[FNATTRS]] <2 x float> @ // CHECK: %fmod.i = frem reassoc nnan ninf nsz arcp afn <2 x float> // CHECK: ret <2 x float> %fmod.i -float2 test_fmod_float2(float2 p0, float2 p1) { return fmod(p0, p1); } +export float2 test_fmod_float2(float2 p0, float2 p1) { return fmod(p0, p1); } // DXCHECK: define [[FNATTRS]] <3 x float> @ // DXCHECK: %div1.i = fdiv reassoc nnan ninf nsz arcp afn <3 x float> %{{.*}}, %{{.*}} @@ -131,7 +131,7 @@ float2 test_fmod_float2(float2 p0, float2 p1) { return fmod(p0, p1); } // CHECK: define [[FNATTRS]] <3 x float> @ // CHECK: %fmod.i = frem reassoc nnan ninf nsz arcp afn <3 x float> // CHECK: ret <3 x float> %fmod.i -float3 test_fmod_float3(float3 p0, float3 p1) { return fmod(p0, p1); } +export float3 test_fmod_float3(float3 p0, float3 p1) { return fmod(p0, p1); } // DXCHECK: define [[FNATTRS]] <4 x float> @ // DXCHECK: %div1.i = fdiv reassoc nnan ninf nsz arcp afn <4 x float> %{{.*}}, %{{.*}} @@ -145,5 +145,5 @@ float3 test_fmod_float3(float3 p0, float3 p1) { return fmod(p0, p1); } // CHECK: define [[FNATTRS]] <4 x float> @ // CHECK: %fmod.i = frem reassoc nnan ninf nsz arcp afn <4 x float> // CHECK: ret <4 x float> %fmod.i -float4 test_fmod_float4(float4 p0, float4 p1) { return fmod(p0, p1); } +export float4 test_fmod_float4(float4 p0, float4 p1) { return fmod(p0, p1); } diff --git a/clang/test/CodeGenHLSL/builtins/hlsl_resource_t.hlsl b/clang/test/CodeGenHLSL/builtins/hlsl_resource_t.hlsl index fda034ce7f203..dc5fbf98aea0e 100644 --- a/clang/test/CodeGenHLSL/builtins/hlsl_resource_t.hlsl +++ b/clang/test/CodeGenHLSL/builtins/hlsl_resource_t.hlsl @@ -8,29 +8,29 @@ using handle_float_t = __hlsl_resource_t [[hlsl::resource_class(UAV)]] [[hlsl::c // CHECK: define void @_Z2faU9_Res_u_CTfu17__hlsl_resource_t(target("dx.TypedBuffer", float, 1, 0, 0) %a) // CHECK: call void @_Z4foo1U9_Res_u_CTfu17__hlsl_resource_t(target("dx.TypedBuffer", float, 1, 0, 0) %0) -// CHECK: declare void @_Z4foo1U9_Res_u_CTfu17__hlsl_resource_t(target("dx.TypedBuffer", float, 1, 0, 0)) +// CHECK: declare internal void @_Z4foo1U9_Res_u_CTfu17__hlsl_resource_t(target("dx.TypedBuffer", float, 1, 0, 0)) -void foo1(handle_float_t res); +export void foo1(handle_float_t res); -void fa(handle_float_t a) { +export void fa(handle_float_t a) { foo1(a); } // CHECK: define void @_Z2fbU9_Res_u_CTfu17__hlsl_resource_t(target("dx.TypedBuffer", float, 1, 0, 0) %a) -void fb(handle_float_t a) { +export void fb(handle_float_t a) { handle_float_t b = a; } // CHECK: define void @_Z2fcN4hlsl8RWBufferIDv4_fEE(ptr noundef byval(%"class.hlsl::RWBuffer") align 4 %a) // CHECK: call void @_Z4foo2N4hlsl8RWBufferIDv4_fEE(ptr noundef byval(%"class.hlsl::RWBuffer") align 4 %agg.tmp) -// CHECK: declare void @_Z4foo2N4hlsl8RWBufferIDv4_fEE(ptr noundef byval(%"class.hlsl::RWBuffer") align 4) -void foo2(RWBuffer buf); +// CHECK: declare internal void @_Z4foo2N4hlsl8RWBufferIDv4_fEE(ptr noundef byval(%"class.hlsl::RWBuffer") align 4) +export void foo2(RWBuffer buf); -void fc(RWBuffer a) { +export void fc(RWBuffer a) { foo2(a); } -void fd(RWBuffer a) { +export void fd(RWBuffer a) { RWBuffer b = a; } @@ -41,13 +41,13 @@ struct MyStruct { // CHECK: define void @_Z2feN4hlsl16StructuredBufferI8MyStructEE(ptr noundef byval(%"class.hlsl::StructuredBuffer") align 4 %a) // CHECK: call void @_Z4foo3N4hlsl16StructuredBufferI8MyStructEE(ptr noundef byval(%"class.hlsl::StructuredBuffer") align 4 %agg.tmp) -// CHECK: declare void @_Z4foo3N4hlsl16StructuredBufferI8MyStructEE(ptr noundef byval(%"class.hlsl::StructuredBuffer") align 4) -void foo3(StructuredBuffer buf); +// CHECK: declare internal void @_Z4foo3N4hlsl16StructuredBufferI8MyStructEE(ptr noundef byval(%"class.hlsl::StructuredBuffer") align 4) +export void foo3(StructuredBuffer buf); -void fe(StructuredBuffer a) { +export void fe(StructuredBuffer a) { foo3(a); } -void ff(StructuredBuffer a) { +export void ff(StructuredBuffer a) { StructuredBuffer b = a; } diff --git a/clang/test/CodeGenHLSL/builtins/length.hlsl b/clang/test/CodeGenHLSL/builtins/length.hlsl index 2d4bbd995298f..7d98e366dcbae 100644 --- a/clang/test/CodeGenHLSL/builtins/length.hlsl +++ b/clang/test/CodeGenHLSL/builtins/length.hlsl @@ -23,7 +23,7 @@ // SPVCHECK-NEXT: [[ELT_ABS_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn noundef half @llvm.fabs.f16(half [[P0]]) // SPVCHECK-NEXT: ret half [[ELT_ABS_I]] // -half test_length_half(half p0) +export half test_length_half(half p0) { return length(p0); } @@ -45,7 +45,7 @@ half test_length_half(half p0) // SPVCHECK-NEXT: [[SPV_LENGTH_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn noundef half @llvm.spv.length.v2f16(<2 x half> [[P0]]) // SPVCHECK-NEXT: ret half [[SPV_LENGTH_I]] // -half test_length_half2(half2 p0) +export half test_length_half2(half2 p0) { return length(p0); } @@ -64,7 +64,7 @@ half test_length_half2(half2 p0) // SPVCHECK-NEXT: [[SPV_LENGTH_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn noundef half @llvm.spv.length.v3f16(<3 x half> [[P0]]) // SPVCHECK-NEXT: ret half [[SPV_LENGTH_I]] // -half test_length_half3(half3 p0) +export half test_length_half3(half3 p0) { return length(p0); } @@ -83,7 +83,7 @@ half test_length_half3(half3 p0) // SPVCHECK-NEXT: [[SPV_LENGTH_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn noundef half @llvm.spv.length.v4f16(<4 x half> [[P0]]) // SPVCHECK-NEXT: ret half [[SPV_LENGTH_I]] // -half test_length_half4(half4 p0) +export half test_length_half4(half4 p0) { return length(p0); } @@ -101,7 +101,7 @@ half test_length_half4(half4 p0) // SPVCHECK-NEXT: [[ELT_ABS_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn noundef float @llvm.fabs.f32(float [[P0]]) // SPVCHECK-NEXT: ret float [[ELT_ABS_I]] // -float test_length_float(float p0) +export float test_length_float(float p0) { return length(p0); } @@ -120,7 +120,7 @@ float test_length_float(float p0) // SPVCHECK-NEXT: [[SPV_LENGTH_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn noundef float @llvm.spv.length.v2f32(<2 x float> [[P0]]) // SPVCHECK-NEXT: ret float [[SPV_LENGTH_I]] // -float test_length_float2(float2 p0) +export float test_length_float2(float2 p0) { return length(p0); } @@ -139,7 +139,7 @@ float test_length_float2(float2 p0) // SPVCHECK-NEXT: [[SPV_LENGTH_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn noundef float @llvm.spv.length.v3f32(<3 x float> [[P0]]) // SPVCHECK-NEXT: ret float [[SPV_LENGTH_I]] // -float test_length_float3(float3 p0) +export float test_length_float3(float3 p0) { return length(p0); } @@ -158,7 +158,7 @@ float test_length_float3(float3 p0) // SPVCHECK-NEXT: [[SPV_LENGTH_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn noundef float @llvm.spv.length.v4f32(<4 x float> [[P0]]) // SPVCHECK-NEXT: ret float [[SPV_LENGTH_I]] // -float test_length_float4(float4 p0) +export float test_length_float4(float4 p0) { return length(p0); } diff --git a/clang/test/CodeGenHLSL/builtins/reflect.hlsl b/clang/test/CodeGenHLSL/builtins/reflect.hlsl index 35ee059697c4b..c1f27362c717d 100644 --- a/clang/test/CodeGenHLSL/builtins/reflect.hlsl +++ b/clang/test/CodeGenHLSL/builtins/reflect.hlsl @@ -24,7 +24,7 @@ // SPVCHECK-NEXT: [[SUB_I:%.*]] = fsub reassoc nnan ninf nsz arcp afn half [[I]], [[MUL2_I]] // SPVCHECK-NEXT: ret half [[SUB_I]] // -half test_reflect_half(half I, half N) { +export half test_reflect_half(half I, half N) { return reflect(I, N); } @@ -45,7 +45,7 @@ half test_reflect_half(half I, half N) { // SPVCHECK-NEXT: [[SPV_REFLECT_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn noundef <2 x half> @llvm.spv.reflect.v2f16(<2 x half> [[I]], <2 x half> [[N]]) // SPVCHECK-NEXT: ret <2 x half> [[SPV_REFLECT_I]] // -half2 test_reflect_half2(half2 I, half2 N) { +export half2 test_reflect_half2(half2 I, half2 N) { return reflect(I, N); } @@ -66,7 +66,7 @@ half2 test_reflect_half2(half2 I, half2 N) { // SPVCHECK-NEXT: [[SPV_REFLECT_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn noundef <3 x half> @llvm.spv.reflect.v3f16(<3 x half> [[I]], <3 x half> [[N]]) // SPVCHECK-NEXT: ret <3 x half> [[SPV_REFLECT_I]] // -half3 test_reflect_half3(half3 I, half3 N) { +export half3 test_reflect_half3(half3 I, half3 N) { return reflect(I, N); } @@ -87,7 +87,7 @@ half3 test_reflect_half3(half3 I, half3 N) { // SPVCHECK-NEXT: [[SPV_REFLECT_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn noundef <4 x half> @llvm.spv.reflect.v4f16(<4 x half> [[I]], <4 x half> [[N]]) // SPVCHECK-NEXT: ret <4 x half> [[SPV_REFLECT_I]] // -half4 test_reflect_half4(half4 I, half4 N) { +export half4 test_reflect_half4(half4 I, half4 N) { return reflect(I, N); } @@ -109,7 +109,7 @@ half4 test_reflect_half4(half4 I, half4 N) { // SPVCHECK-NEXT: [[SUB_I:%.*]] = fsub reassoc nnan ninf nsz arcp afn float [[I]], [[MUL2_I]] // SPVCHECK-NEXT: ret float [[SUB_I]] // -float test_reflect_float(float I, float N) { +export float test_reflect_float(float I, float N) { return reflect(I, N); } @@ -130,7 +130,7 @@ float test_reflect_float(float I, float N) { // SPVCHECK-NEXT: [[SPV_REFLECT_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn noundef <2 x float> @llvm.spv.reflect.v2f32(<2 x float> [[I]], <2 x float> [[N]]) // SPVCHECK-NEXT: ret <2 x float> [[SPV_REFLECT_I]] // -float2 test_reflect_float2(float2 I, float2 N) { +export float2 test_reflect_float2(float2 I, float2 N) { return reflect(I, N); } @@ -151,7 +151,7 @@ float2 test_reflect_float2(float2 I, float2 N) { // SPVCHECK-NEXT: [[SPV_REFLECT_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn noundef <3 x float> @llvm.spv.reflect.v3f32(<3 x float> [[I]], <3 x float> [[N]]) // SPVCHECK-NEXT: ret <3 x float> [[SPV_REFLECT_I]] // -float3 test_reflect_float3(float3 I, float3 N) { +export float3 test_reflect_float3(float3 I, float3 N) { return reflect(I, N); } @@ -172,6 +172,6 @@ float3 test_reflect_float3(float3 I, float3 N) { // SPVCHECK-NEXT: [[SPV_REFLECT_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn noundef <4 x float> @llvm.spv.reflect.v4f32(<4 x float> [[I]], <4 x float> [[N]]) // SPVCHECK-NEXT: ret <4 x float> [[SPV_REFLECT_I]] // -float4 test_reflect_float4(float4 I, float4 N) { +export float4 test_reflect_float4(float4 I, float4 N) { return reflect(I, N); } diff --git a/clang/test/CodeGenHLSL/builtins/smoothstep.hlsl b/clang/test/CodeGenHLSL/builtins/smoothstep.hlsl index f2328c7330e6c..91b4372d5093e 100644 --- a/clang/test/CodeGenHLSL/builtins/smoothstep.hlsl +++ b/clang/test/CodeGenHLSL/builtins/smoothstep.hlsl @@ -25,7 +25,7 @@ // SPVCHECK-NEXT: [[SPV_SMOOTHSTEP_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn noundef half @llvm.spv.smoothstep.f16(half [[MIN]], half [[MAX]], half [[X]]) // SPVCHECK-NEXT: ret half [[SPV_SMOOTHSTEP_I]] // -half test_smoothstep_half(half Min, half Max, half X) { return smoothstep(Min, Max, X); } +export half test_smoothstep_half(half Min, half Max, half X) { return smoothstep(Min, Max, X); } // CHECK-LABEL: define noundef nofpclass(nan inf) <2 x half> @_Z21test_smoothstep_half2Dv2_DhS_S_( // CHECK-SAME: <2 x half> noundef nofpclass(nan inf) [[MIN:%.*]], <2 x half> noundef nofpclass(nan inf) [[MAX:%.*]], <2 x half> noundef nofpclass(nan inf) [[X:%.*]]) local_unnamed_addr #[[ATTR0]] { @@ -46,7 +46,7 @@ half test_smoothstep_half(half Min, half Max, half X) { return smoothstep(Min, M // SPVCHECK-NEXT: [[SPV_SMOOTHSTEP_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn noundef <2 x half> @llvm.spv.smoothstep.v2f16(<2 x half> [[MIN]], <2 x half> [[MAX]], <2 x half> [[X]]) // SPVCHECK-NEXT: ret <2 x half> [[SPV_SMOOTHSTEP_I]] // -half2 test_smoothstep_half2(half2 Min, half2 Max, half2 X) { return smoothstep(Min, Max, X); } +export half2 test_smoothstep_half2(half2 Min, half2 Max, half2 X) { return smoothstep(Min, Max, X); } // CHECK-LABEL: define noundef nofpclass(nan inf) <3 x half> @_Z21test_smoothstep_half3Dv3_DhS_S_( // CHECK-SAME: <3 x half> noundef nofpclass(nan inf) [[MIN:%.*]], <3 x half> noundef nofpclass(nan inf) [[MAX:%.*]], <3 x half> noundef nofpclass(nan inf) [[X:%.*]]) local_unnamed_addr #[[ATTR0]] { @@ -67,7 +67,7 @@ half2 test_smoothstep_half2(half2 Min, half2 Max, half2 X) { return smoothstep(M // SPVCHECK-NEXT: [[SPV_SMOOTHSTEP_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn noundef <3 x half> @llvm.spv.smoothstep.v3f16(<3 x half> [[MIN]], <3 x half> [[MAX]], <3 x half> [[X]]) // SPVCHECK-NEXT: ret <3 x half> [[SPV_SMOOTHSTEP_I]] // -half3 test_smoothstep_half3(half3 Min, half3 Max, half3 X) { return smoothstep(Min, Max, X); } +export half3 test_smoothstep_half3(half3 Min, half3 Max, half3 X) { return smoothstep(Min, Max, X); } // CHECK-LABEL: define noundef nofpclass(nan inf) <4 x half> @_Z21test_smoothstep_half4Dv4_DhS_S_( // CHECK-SAME: <4 x half> noundef nofpclass(nan inf) [[MIN:%.*]], <4 x half> noundef nofpclass(nan inf) [[MAX:%.*]], <4 x half> noundef nofpclass(nan inf) [[X:%.*]]) local_unnamed_addr #[[ATTR0]] { @@ -88,7 +88,7 @@ half3 test_smoothstep_half3(half3 Min, half3 Max, half3 X) { return smoothstep(M // SPVCHECK-NEXT: [[SPV_SMOOTHSTEP_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn noundef <4 x half> @llvm.spv.smoothstep.v4f16(<4 x half> [[MIN]], <4 x half> [[MAX]], <4 x half> [[X]]) // SPVCHECK-NEXT: ret <4 x half> [[SPV_SMOOTHSTEP_I]] // -half4 test_smoothstep_half4(half4 Min, half4 Max, half4 X) { return smoothstep(Min, Max, X); } +export half4 test_smoothstep_half4(half4 Min, half4 Max, half4 X) { return smoothstep(Min, Max, X); } // CHECK-LABEL: define noundef nofpclass(nan inf) float @_Z21test_smoothstep_floatfff( // CHECK-SAME: float noundef nofpclass(nan inf) [[MIN:%.*]], float noundef nofpclass(nan inf) [[MAX:%.*]], float noundef nofpclass(nan inf) [[X:%.*]]) local_unnamed_addr #[[ATTR0]] { @@ -109,7 +109,7 @@ half4 test_smoothstep_half4(half4 Min, half4 Max, half4 X) { return smoothstep(M // SPVCHECK-NEXT: [[SPV_SMOOTHSTEP_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn noundef float @llvm.spv.smoothstep.f32(float [[MIN]], float [[MAX]], float [[X]]) // SPVCHECK-NEXT: ret float [[SPV_SMOOTHSTEP_I]] // -float test_smoothstep_float(float Min, float Max, float X) { return smoothstep(Min, Max, X); } +export float test_smoothstep_float(float Min, float Max, float X) { return smoothstep(Min, Max, X); } // CHECK-LABEL: define noundef nofpclass(nan inf) <2 x float> @_Z22test_smoothstep_float2Dv2_fS_S_( // CHECK-SAME: <2 x float> noundef nofpclass(nan inf) [[MIN:%.*]], <2 x float> noundef nofpclass(nan inf) [[MAX:%.*]], <2 x float> noundef nofpclass(nan inf) [[X:%.*]]) local_unnamed_addr #[[ATTR0]] { @@ -130,7 +130,7 @@ float test_smoothstep_float(float Min, float Max, float X) { return smoothstep(M // SPVCHECK-NEXT: [[SPV_SMOOTHSTEP_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn noundef <2 x float> @llvm.spv.smoothstep.v2f32(<2 x float> [[MIN]], <2 x float> [[MAX]], <2 x float> [[X]]) // SPVCHECK-NEXT: ret <2 x float> [[SPV_SMOOTHSTEP_I]] // -float2 test_smoothstep_float2(float2 Min, float2 Max, float2 X) { return smoothstep(Min, Max, X); } +export float2 test_smoothstep_float2(float2 Min, float2 Max, float2 X) { return smoothstep(Min, Max, X); } // CHECK-LABEL: define noundef nofpclass(nan inf) <3 x float> @_Z22test_smoothstep_float3Dv3_fS_S_( // CHECK-SAME: <3 x float> noundef nofpclass(nan inf) [[MIN:%.*]], <3 x float> noundef nofpclass(nan inf) [[MAX:%.*]], <3 x float> noundef nofpclass(nan inf) [[X:%.*]]) local_unnamed_addr #[[ATTR0]] { @@ -151,7 +151,7 @@ float2 test_smoothstep_float2(float2 Min, float2 Max, float2 X) { return smooths // SPVCHECK-NEXT: [[SPV_SMOOTHSTEP_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn noundef <3 x float> @llvm.spv.smoothstep.v3f32(<3 x float> [[MIN]], <3 x float> [[MAX]], <3 x float> [[X]]) // SPVCHECK-NEXT: ret <3 x float> [[SPV_SMOOTHSTEP_I]] // -float3 test_smoothstep_float3(float3 Min, float3 Max, float3 X) { return smoothstep(Min, Max, X); } +export float3 test_smoothstep_float3(float3 Min, float3 Max, float3 X) { return smoothstep(Min, Max, X); } // CHECK-LABEL: define noundef nofpclass(nan inf) <4 x float> @_Z22test_smoothstep_float4Dv4_fS_S_( // CHECK-SAME: <4 x float> noundef nofpclass(nan inf) [[MIN:%.*]], <4 x float> noundef nofpclass(nan inf) [[MAX:%.*]], <4 x float> noundef nofpclass(nan inf) [[X:%.*]]) local_unnamed_addr #[[ATTR0]] { @@ -172,4 +172,4 @@ float3 test_smoothstep_float3(float3 Min, float3 Max, float3 X) { return smooths // SPVCHECK-NEXT: [[SPV_SMOOTHSTEP_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn noundef <4 x float> @llvm.spv.smoothstep.v4f32(<4 x float> [[MIN]], <4 x float> [[MAX]], <4 x float> [[X]]) // SPVCHECK-NEXT: ret <4 x float> [[SPV_SMOOTHSTEP_I]] // -float4 test_smoothstep_float4(float4 Min, float4 Max, float4 X) { return smoothstep(Min, Max, X); } +export float4 test_smoothstep_float4(float4 Min, float4 Max, float4 X) { return smoothstep(Min, Max, X); } diff --git a/clang/test/CodeGenHLSL/builtins/splitdouble.hlsl b/clang/test/CodeGenHLSL/builtins/splitdouble.hlsl index a883c9d5cc355..673fd89da394c 100644 --- a/clang/test/CodeGenHLSL/builtins/splitdouble.hlsl +++ b/clang/test/CodeGenHLSL/builtins/splitdouble.hlsl @@ -14,7 +14,7 @@ // SPIRV-NEXT: [[CAST:%.*]] = bitcast double [[LOAD]] to <2 x i32> // SPIRV-NEXT: extractelement <2 x i32> [[CAST]], i64 0 // SPIRV-NEXT: extractelement <2 x i32> [[CAST]], i64 1 -uint test_scalar(double D) { +export uint test_scalar(double D) { uint A, B; asuint(D, A, B); return A + B; @@ -33,7 +33,7 @@ uint test_scalar(double D) { // SPIRV-NEXT: [[CAST:%.*]] = bitcast double [[TRUNC]] to <2 x i32> // SPIRV-NEXT: extractelement <2 x i32> [[CAST]], i64 0 // SPIRV-NEXT: extractelement <2 x i32> [[CAST]], i64 1 -uint1 test_double1(double1 D) { +export uint1 test_double1(double1 D) { uint A, B; asuint(D, A, B); return A + B; @@ -50,7 +50,7 @@ uint1 test_double1(double1 D) { // SPIRV-NEXT: [[CAST1:%.*]] = bitcast <2 x double> [[LOAD]] to <4 x i32> // SPIRV-NEXT: [[SHUF1:%.*]] = shufflevector <4 x i32> [[CAST1]], <4 x i32> poison, <2 x i32> // SPIRV-NEXT: [[SHUF2:%.*]] = shufflevector <4 x i32> [[CAST1]], <4 x i32> poison, <2 x i32> -uint2 test_vector2(double2 D) { +export uint2 test_vector2(double2 D) { uint2 A, B; asuint(D, A, B); return A + B; @@ -67,7 +67,7 @@ uint2 test_vector2(double2 D) { // SPIRV-NEXT: [[CAST1:%.*]] = bitcast <3 x double> [[LOAD]] to <6 x i32> // SPIRV-NEXT: [[SHUF1:%.*]] = shufflevector <6 x i32> [[CAST1]], <6 x i32> poison, <3 x i32> // SPIRV-NEXT: [[SHUF2:%.*]] = shufflevector <6 x i32> [[CAST1]], <6 x i32> poison, <3 x i32> -uint3 test_vector3(double3 D) { +export uint3 test_vector3(double3 D) { uint3 A, B; asuint(D, A, B); return A + B; @@ -84,7 +84,7 @@ uint3 test_vector3(double3 D) { // SPIRV-NEXT: [[CAST1:%.*]] = bitcast <4 x double> [[LOAD]] to <8 x i32> // SPIRV-NEXT: [[SHUF1:%.*]] = shufflevector <8 x i32> [[CAST1]], <8 x i32> poison, <4 x i32> // SPIRV-NEXT: [[SHUF2:%.*]] = shufflevector <8 x i32> [[CAST1]], <8 x i32> poison, <4 x i32> -uint4 test_vector4(double4 D) { +export uint4 test_vector4(double4 D) { uint4 A, B; asuint(D, A, B); return A + B; diff --git a/clang/test/CodeGenHLSL/inline-functions.hlsl b/clang/test/CodeGenHLSL/inline-functions.hlsl index 4748eeee7475f..426e778e06a0c 100644 --- a/clang/test/CodeGenHLSL/inline-functions.hlsl +++ b/clang/test/CodeGenHLSL/inline-functions.hlsl @@ -61,7 +61,7 @@ unsigned RemoveDupes(unsigned Buf[MAX], unsigned size) { } -RWBuffer Indices; +RWBuffer Indices : register(u0); // The mangled version of main only remains without inlining // because it has internal linkage from the start diff --git a/llvm/lib/Target/DirectX/DXILFinalizeLinkage.h b/llvm/include/llvm/Transforms/HLSL/HLSLFinalizeLinkage.h similarity index 59% rename from llvm/lib/Target/DirectX/DXILFinalizeLinkage.h rename to llvm/include/llvm/Transforms/HLSL/HLSLFinalizeLinkage.h index aab1bc3f7a28e..2da4a41673ef0 100644 --- a/llvm/lib/Target/DirectX/DXILFinalizeLinkage.h +++ b/llvm/include/llvm/Transforms/HLSL/HLSLFinalizeLinkage.h @@ -1,4 +1,4 @@ -//===- DXILFinalizeLinkage.h - Finalize linkage of functions --------------===// +//===- HLSLFinalizeLinkage.h - Finalize linkage of functions --------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,34 +6,34 @@ // //===----------------------------------------------------------------------===// /// -/// DXILFinalizeLinkage pass updates the linkage of functions to make sure only +/// HLSLFinalizeLinkage pass updates the linkage of functions to make sure only /// shader entry points and exported functions are visible from the module (have -/// program linkage). All other functions will be updated to have internal -/// linkage. +/// program linkage). All other functions and variables will be updated to have +/// internal linkage. /// //===----------------------------------------------------------------------===// -#ifndef LLVM_TARGET_DIRECTX_DXILFINALIZELINKAGE_H -#define LLVM_TARGET_DIRECTX_DXILFINALIZELINKAGE_H +#ifndef LLVM_TRANSFORMS_HLSL_HLSLFINALIZELINKAGE_H +#define LLVM_TRANSFORMS_HLSL_HLSLFINALIZELINKAGE_H #include "llvm/IR/PassManager.h" #include "llvm/Pass.h" namespace llvm { -class DXILFinalizeLinkage : public PassInfoMixin { +class HLSLFinalizeLinkage : public PassInfoMixin { public: PreservedAnalyses run(Module &M, ModuleAnalysisManager &); static bool isRequired() { return true; } }; -class DXILFinalizeLinkageLegacy : public ModulePass { +class HLSLFinalizeLinkageLegacy : public ModulePass { public: - DXILFinalizeLinkageLegacy() : ModulePass(ID) {} + HLSLFinalizeLinkageLegacy() : ModulePass(ID) {} bool runOnModule(Module &M) override; static char ID; // Pass identification. }; } // namespace llvm -#endif // LLVM_TARGET_DIRECTX_DXILFINALIZELINKAGE_H +#endif // LLVM_TRANSFORMS_HLSL_HLSLFINALIZELINKAGE_H diff --git a/llvm/lib/Target/DirectX/CMakeLists.txt b/llvm/lib/Target/DirectX/CMakeLists.txt index 13f8adbe4f132..c981b5f34e91a 100644 --- a/llvm/lib/Target/DirectX/CMakeLists.txt +++ b/llvm/lib/Target/DirectX/CMakeLists.txt @@ -21,7 +21,6 @@ add_llvm_target(DirectXCodeGen DirectXTargetTransformInfo.cpp DXContainerGlobals.cpp DXILDataScalarization.cpp - DXILFinalizeLinkage.cpp DXILFlattenArrays.cpp DXILIntrinsicExpansion.cpp DXILOpBuilder.cpp diff --git a/llvm/lib/Target/DirectX/DirectXTargetMachine.cpp b/llvm/lib/Target/DirectX/DirectXTargetMachine.cpp index ce408b4034f83..7d0ec4ab232b6 100644 --- a/llvm/lib/Target/DirectX/DirectXTargetMachine.cpp +++ b/llvm/lib/Target/DirectX/DirectXTargetMachine.cpp @@ -63,7 +63,6 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeDirectXTarget() { initializeDXILTranslateMetadataLegacyPass(*PR); initializeShaderFlagsAnalysisWrapperPass(*PR); initializeRootSignatureAnalysisWrapperPass(*PR); - initializeDXILFinalizeLinkageLegacyPass(*PR); } class DXILTargetObjectFile : public TargetLoweringObjectFile { @@ -93,7 +92,6 @@ class DirectXPassConfig : public TargetPassConfig { FunctionPass *createTargetRegisterAllocator(bool) override { return nullptr; } void addCodeGenPrepare() override { - addPass(createDXILFinalizeLinkageLegacyPass()); addPass(createDXILIntrinsicExpansionLegacyPass()); addPass(createDXILDataScalarizationLegacyPass()); addPass(createDXILFlattenArraysLegacyPass()); diff --git a/llvm/lib/Transforms/CMakeLists.txt b/llvm/lib/Transforms/CMakeLists.txt index 7046f2f4b1d2c..e3c13a19f6de1 100644 --- a/llvm/lib/Transforms/CMakeLists.txt +++ b/llvm/lib/Transforms/CMakeLists.txt @@ -9,3 +9,4 @@ add_subdirectory(ObjCARC) add_subdirectory(Coroutines) add_subdirectory(CFGuard) add_subdirectory(HipStdPar) +add_subdirectory(HLSL) diff --git a/llvm/lib/Transforms/HLSL/CMakeLists.txt b/llvm/lib/Transforms/HLSL/CMakeLists.txt new file mode 100644 index 0000000000000..df6af5a6469cb --- /dev/null +++ b/llvm/lib/Transforms/HLSL/CMakeLists.txt @@ -0,0 +1,18 @@ +add_llvm_component_library(LLVMHlsl + HLSLFinalizeLinkage.cpp + + ADDITIONAL_HEADER_DIRS + ${LLVM_MAIN_INCLUDE_DIR}/llvm/Transforms/HLSL + + DEPENDS + intrinsics_gen + LLVMAnalysis + + COMPONENT_NAME + HLSL + + LINK_COMPONENTS + Analysis + Core + Support + TransformUtils) diff --git a/llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp b/llvm/lib/Transforms/HLSL/HLSLFinalizeLinkage.cpp similarity index 68% rename from llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp rename to llvm/lib/Transforms/HLSL/HLSLFinalizeLinkage.cpp index 7651617adc43b..fe5df32c86ac8 100644 --- a/llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp +++ b/llvm/lib/Transforms/HLSL/HLSLFinalizeLinkage.cpp @@ -1,4 +1,4 @@ -//===- DXILFinalizeLinkage.cpp - Finalize linkage of functions ------------===// +//===- HLSLFinalizeLinkage.cpp - Finalize linkage of functions ------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,11 +6,9 @@ // //===----------------------------------------------------------------------===// -#include "DXILFinalizeLinkage.h" -#include "DirectX.h" +#include "llvm/Transforms/HLSL/HLSLFinalizeLinkage.h" #include "llvm/IR/Function.h" #include "llvm/IR/GlobalValue.h" -#include "llvm/IR/Metadata.h" #include "llvm/IR/Module.h" #define DEBUG_TYPE "dxil-finalize-linkage" @@ -47,24 +45,9 @@ static bool finalizeLinkage(Module &M) { return false; } -PreservedAnalyses DXILFinalizeLinkage::run(Module &M, +PreservedAnalyses HLSLFinalizeLinkage::run(Module &M, ModuleAnalysisManager &AM) { if (finalizeLinkage(M)) return PreservedAnalyses::none(); return PreservedAnalyses::all(); -} - -bool DXILFinalizeLinkageLegacy::runOnModule(Module &M) { - return finalizeLinkage(M); -} - -char DXILFinalizeLinkageLegacy::ID = 0; - -INITIALIZE_PASS_BEGIN(DXILFinalizeLinkageLegacy, DEBUG_TYPE, - "DXIL Finalize Linkage", false, false) -INITIALIZE_PASS_END(DXILFinalizeLinkageLegacy, DEBUG_TYPE, - "DXIL Finalize Linkage", false, false) - -ModulePass *llvm::createDXILFinalizeLinkageLegacyPass() { - return new DXILFinalizeLinkageLegacy(); -} +} \ No newline at end of file