[clang] [HLSL] Change default linkage of HLSL functions and groupshared variables (v2) (PR #95331)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 1 17:03:27 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-hlsl
Author: Helena Kotas (hekota)
<details>
<summary>Changes</summary>
An HLSL function has _internal_ linkage by default unless it is:
1. shader entry point function
2. marked with the `export` keyword (https://github.com/llvm/llvm-project/issues/92812)
3. patch constant function (not implemented yet)
4. a declaration without definition
This PR changes the default linkage of HLSL functions based on these rules.
For `export` functions the linkage is set to _external_ during parsing in the Clang semantic analysis phase. For shader entry point functions the linkage is set to _internal_ while in Sema and during CodeGen a function with _external_ linkage and unmangled name is created that calls the internal shader entry point function. This call will end up being inlined.
Patch constant functions are most likely going to be implemented similar way because there is no way to determine if a function is a patch constant function until the attribute that say so is parsed.
This PR also changes the linkage of groupshared variables internal to match DXC behavior. Global variables marked static already have internal linkage per C++ rules.
Related spec update: [microsoft/hlsl-specs#<!-- -->249](https://github.com/microsoft/hlsl-specs/pull/249)
Fixes https://github.com/llvm/llvm-project/issues/92071
---
Patch is 61.75 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/95331.diff
80 Files Affected:
- (modified) clang/docs/HLSL/ExpectedDifferences.rst (+46)
- (modified) clang/include/clang/Basic/Attr.td (+2-1)
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+2-1)
- (modified) clang/lib/AST/ASTContext.cpp (+4)
- (modified) clang/lib/AST/Decl.cpp (+14)
- (modified) clang/lib/CodeGen/CGHLSLRuntime.cpp (+16-1)
- (modified) clang/lib/CodeGen/CGHLSLRuntime.h (+3-4)
- (modified) clang/lib/CodeGen/CodeGenFunction.cpp (+4-3)
- (modified) clang/lib/Sema/SemaDecl.cpp (+8-1)
- (modified) clang/test/AST/Interp/hlsl.hlsl (+1-1)
- (modified) clang/test/CodeGenHLSL/ArrayTemporary.hlsl (+6-6)
- (modified) clang/test/CodeGenHLSL/BasicFeatures/standard_conversion_sequences.hlsl (+4)
- (modified) clang/test/CodeGenHLSL/buffer-array-operator.hlsl (+1-1)
- (modified) clang/test/CodeGenHLSL/builtins/ScalarSwizzles.hlsl (+4)
- (modified) clang/test/CodeGenHLSL/builtins/abs.hlsl (+4)
- (modified) clang/test/CodeGenHLSL/builtins/acos.hlsl (+4)
- (modified) clang/test/CodeGenHLSL/builtins/all.hlsl (+4)
- (modified) clang/test/CodeGenHLSL/builtins/any.hlsl (+4)
- (modified) clang/test/CodeGenHLSL/builtins/asin.hlsl (+4)
- (modified) clang/test/CodeGenHLSL/builtins/atan.hlsl (+4)
- (modified) clang/test/CodeGenHLSL/builtins/ceil.hlsl (+4)
- (modified) clang/test/CodeGenHLSL/builtins/clamp-builtin.hlsl (+1-1)
- (modified) clang/test/CodeGenHLSL/builtins/clamp.hlsl (+4)
- (modified) clang/test/CodeGenHLSL/builtins/cos.hlsl (+4)
- (modified) clang/test/CodeGenHLSL/builtins/cosh.hlsl (+4)
- (modified) clang/test/CodeGenHLSL/builtins/create_handle.hlsl (+1-1)
- (modified) clang/test/CodeGenHLSL/builtins/dot-builtin.hlsl (+3-3)
- (modified) clang/test/CodeGenHLSL/builtins/dot.hlsl (+4)
- (modified) clang/test/CodeGenHLSL/builtins/exp.hlsl (+4)
- (modified) clang/test/CodeGenHLSL/builtins/exp2.hlsl (+4)
- (modified) clang/test/CodeGenHLSL/builtins/floor.hlsl (+4)
- (modified) clang/test/CodeGenHLSL/builtins/frac.hlsl (+4)
- (modified) clang/test/CodeGenHLSL/builtins/isinf.hlsl (+4)
- (modified) clang/test/CodeGenHLSL/builtins/lerp-builtin.hlsl (+2-2)
- (modified) clang/test/CodeGenHLSL/builtins/lerp.hlsl (+3)
- (modified) clang/test/CodeGenHLSL/builtins/log.hlsl (+4)
- (modified) clang/test/CodeGenHLSL/builtins/log10.hlsl (+4)
- (modified) clang/test/CodeGenHLSL/builtins/log2.hlsl (+4)
- (modified) clang/test/CodeGenHLSL/builtins/mad.hlsl (+4)
- (modified) clang/test/CodeGenHLSL/builtins/max.hlsl (+4)
- (modified) clang/test/CodeGenHLSL/builtins/min.hlsl (+4)
- (modified) clang/test/CodeGenHLSL/builtins/pow.hlsl (+4)
- (modified) clang/test/CodeGenHLSL/builtins/rcp.hlsl (+4)
- (modified) clang/test/CodeGenHLSL/builtins/reversebits.hlsl (+4)
- (modified) clang/test/CodeGenHLSL/builtins/round.hlsl (+4)
- (modified) clang/test/CodeGenHLSL/builtins/rsqrt.hlsl (+4)
- (modified) clang/test/CodeGenHLSL/builtins/sin.hlsl (+4)
- (modified) clang/test/CodeGenHLSL/builtins/sinh.hlsl (+4)
- (modified) clang/test/CodeGenHLSL/builtins/sqrt.hlsl (+4)
- (modified) clang/test/CodeGenHLSL/builtins/tan.hlsl (+4)
- (modified) clang/test/CodeGenHLSL/builtins/tanh.hlsl (+4)
- (modified) clang/test/CodeGenHLSL/builtins/trunc.hlsl (+4)
- (modified) clang/test/CodeGenHLSL/builtins/wave_get_lane_index_do_while.hlsl (+1-1)
- (modified) clang/test/CodeGenHLSL/builtins/wave_get_lane_index_simple.hlsl (+1-1)
- (modified) clang/test/CodeGenHLSL/builtins/wave_get_lane_index_subcall.hlsl (+2-2)
- (modified) clang/test/CodeGenHLSL/cbuf.hlsl (+1-1)
- (modified) clang/test/CodeGenHLSL/cbuf_in_namespace.hlsl (+1-1)
- (modified) clang/test/CodeGenHLSL/convergence/do.while.hlsl (+4)
- (modified) clang/test/CodeGenHLSL/convergence/for.hlsl (+4)
- (modified) clang/test/CodeGenHLSL/convergence/while.hlsl (+4)
- (modified) clang/test/CodeGenHLSL/convergent-functions.hlsl (+1-1)
- (modified) clang/test/CodeGenHLSL/float3.hlsl (+1-1)
- (modified) clang/test/CodeGenHLSL/half.hlsl (+1-1)
- (added) clang/test/CodeGenHLSL/internal_linkage.hlsl (+19)
- (modified) clang/test/CodeGenHLSL/loops/unroll.hlsl (+4)
- (modified) clang/test/CodeGenHLSL/no_int_promotion.hlsl (+4)
- (modified) clang/test/CodeGenHLSL/shift-mask.hlsl (+4)
- (modified) clang/test/CodeGenHLSL/static_global_and_function_in_cb.hlsl (+1-1)
- (modified) clang/test/Options/enable_16bit_types_validation_spirv.hlsl (+2-1)
- (modified) clang/test/SemaHLSL/Availability/attr-availability-compute.hlsl (+1-1)
- (modified) clang/test/SemaHLSL/Availability/attr-availability-mesh.hlsl (+1-1)
- (modified) clang/test/SemaHLSL/Availability/attr-availability-pixel.hlsl (+1-1)
- (modified) clang/test/SemaHLSL/Availability/avail-diag-default-compute.hlsl (+1-1)
- (modified) clang/test/SemaHLSL/Availability/avail-diag-default-lib.hlsl (+2-2)
- (modified) clang/test/SemaHLSL/Availability/avail-diag-relaxed-compute.hlsl (+1-1)
- (modified) clang/test/SemaHLSL/Availability/avail-diag-relaxed-lib.hlsl (+2-2)
- (modified) clang/test/SemaHLSL/Availability/avail-diag-strict-lib.hlsl (+1-1)
- (modified) clang/test/SemaHLSL/Availability/avail-lib-multiple-stages.hlsl (+1-1)
- (modified) clang/test/SemaHLSL/VectorOverloadResolution.hlsl (+5)
- (modified) clang/test/SemaHLSL/export.hlsl (+3-3)
``````````diff
diff --git a/clang/docs/HLSL/ExpectedDifferences.rst b/clang/docs/HLSL/ExpectedDifferences.rst
index 4782eb3cda754..86007759895d5 100644
--- a/clang/docs/HLSL/ExpectedDifferences.rst
+++ b/clang/docs/HLSL/ExpectedDifferences.rst
@@ -119,3 +119,49 @@ behavior between Clang and DXC. Some examples include:
diagnostic notifying the user of the conversion rather than silently altering
precision relative to the other overloads (as FXC does) or generating code
that will fail validation (as DXC does).
+
+Correctness improvements and bug fixes
+======================================
+
+Entry point functions & ``static`` keyword
+------------------------------------------
+Marking a shader entry point function ``static`` will result in a error.
+
+In DXC using ``static`` on an entry point function will cause the function
+to have internal linkage and it will not be included in the final DXIL.
+For shaders that specify the entry function name on the commandline
+(such as ``-E main``) the compilation will produce an error:
+
+ ``error: cannot find entry function main``
+
+For shader libraries with entry points marked with ``[shader("stage")]``
+attribute the functions will simply not be included in the final DXIL
+and no error or warning is reported.
+
+Clang will always report an error if a shader entry point function is marked
+static.
+
+Library export functions
+------------------------
+
+All declarations of a shader library export function must be marked with the
+``export`` keyword. This is different from DXC where a function was considered
+a library export as long as one of the declarations was marked ``export``.
+
+This change aligns with C++ principle that a linkage of a function can be
+determined when a first declaration of that function is parsed and any
+subsequent redeclarations of the same function cannot change the it.
+
+For example:
+
+.. code-block:: c++
+
+ export void f()
+
+ void f() {}
+
+will produce an error:
+
+.. code-block:: console
+
+ redeclaration of exported function 'f' must be marked 'export'
diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td
index 8ac2079099c85..b6df64b82310f 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -158,7 +158,8 @@ def FunctionTmpl
def HLSLEntry
: SubsetSubject<Function,
- [{S->isExternallyVisible() && !isa<CXXMethodDecl>(S)}],
+ [{S->getDeclContext()->getRedeclContext()->isFileContext() &&
+ S->getStorageClass() != SC_Static}],
"global functions">;
def HLSLBufferObj : SubsetSubject<HLSLBuffer,
[{isa<HLSLBufferDecl>(S)}],
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 581434d33c5c9..af13540f4e39a 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12330,7 +12330,8 @@ def err_hlsl_missing_semantic_annotation : Error<
"function or patch constant function">;
def err_hlsl_init_priority_unsupported : Error<
"initializer priorities are not supported in HLSL">;
-
+def err_redeclaration_missing_export : Error<
+ "redeclaration of exported function %0 must be marked 'export'">;
def err_hlsl_unsupported_register_type : Error<"invalid resource class specifier '%0' used; expected 'b', 's', 't', or 'u'">;
def err_hlsl_unsupported_register_number : Error<"register number should be an integer">;
def err_hlsl_expected_space : Error<"invalid space specifier '%0' used; expected 'space' followed by an integer, like space1">;
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index b0cc7cb826f97..a50e71bd405cc 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -12363,6 +12363,10 @@ bool ASTContext::DeclMustBeEmitted(const Decl *D) {
if (D->hasAttr<AliasAttr>() || D->hasAttr<UsedAttr>())
return true;
+ // HLSL entry functions are required.
+ if (D->hasAttr<HLSLShaderAttr>())
+ return true;
+
if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
// Forward declarations aren't required.
if (!FD->doesThisDeclarationHaveABody())
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 490c4a2fc525c..f7bc62bfa9ad1 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -664,11 +664,25 @@ LinkageComputer::getLVForNamespaceScopeDecl(const NamedDecl *D,
if (PrevVar->getStorageClass() == SC_Static)
return LinkageInfo::internal();
}
+
+ if (Context.getLangOpts().HLSL &&
+ Var->hasAttr<HLSLGroupSharedAddressSpaceAttr>())
+ return LinkageInfo::internal();
+
} else if (const auto *IFD = dyn_cast<IndirectFieldDecl>(D)) {
// - a data member of an anonymous union.
const VarDecl *VD = IFD->getVarDecl();
assert(VD && "Expected a VarDecl in this IndirectFieldDecl!");
return getLVForNamespaceScopeDecl(VD, computation, IgnoreVarTypeLinkage);
+
+ } else if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
+ // HLSL: Functions that are not exported library functions have internal
+ // linkage by default. That includes shader entry point functions, which
+ // will be wrapped by an external linkage function with unmangled C-style
+ // name during CodeGen.
+ if (Context.getLangOpts().HLSL && !(FD->isInExportDeclContext())) {
+ return LinkageInfo::internal();
+ }
}
assert(!isa<FieldDecl>(D) && "Didn't expect a FieldDecl!");
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index 6a6aff594fb0f..46373102250db 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -354,6 +354,21 @@ llvm::Value *CGHLSLRuntime::emitInputSemantic(IRBuilder<> &B,
return nullptr;
}
+void CGHLSLRuntime::emitFunctionProlog(const FunctionDecl *FD,
+ llvm::Function *Fn) {
+ if (!FD || !Fn)
+ return;
+
+ if (FD->hasAttr<HLSLShaderAttr>()) {
+ emitEntryFunction(FD, Fn);
+ } else {
+ // HLSL functions declared in the current translation unit without
+ // body have external linkage by default.
+ if (!FD->isDefined())
+ Fn->setLinkage(GlobalValue::ExternalLinkage);
+ }
+}
+
void CGHLSLRuntime::emitEntryFunction(const FunctionDecl *FD,
llvm::Function *Fn) {
llvm::Module &M = CGM.getModule();
@@ -370,7 +385,7 @@ void CGHLSLRuntime::emitEntryFunction(const FunctionDecl *FD,
setHLSLEntryAttributes(FD, EntryFn);
// Set the called function as internal linkage.
- Fn->setLinkage(GlobalValue::InternalLinkage);
+ assert(Fn->getLinkage() == GlobalValue::InternalLinkage);
BasicBlock *BB = BasicBlock::Create(Ctx, "entry", EntryFn);
IRBuilder<> B(BB);
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h b/clang/lib/CodeGen/CGHLSLRuntime.h
index 8c067f4963955..f007943b50c33 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -118,12 +118,11 @@ class CGHLSLRuntime {
void addBuffer(const HLSLBufferDecl *D);
void finishCodeGen();
- void setHLSLEntryAttributes(const FunctionDecl *FD, llvm::Function *Fn);
-
- void emitEntryFunction(const FunctionDecl *FD, llvm::Function *Fn);
- void setHLSLFunctionAttributes(llvm::Function *, const FunctionDecl *);
+ void emitFunctionProlog(const FunctionDecl *FD, llvm::Function *Fn);
private:
+ void emitEntryFunction(const FunctionDecl *FD, llvm::Function *Fn);
+ void setHLSLEntryAttributes(const FunctionDecl *FD, llvm::Function *Fn);
void addBufferResourceAnnotation(llvm::GlobalVariable *GV,
llvm::hlsl::ResourceClass RC,
llvm::hlsl::ResourceKind RK, bool IsROV,
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp
index af201554898f3..4633c7903f782 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -1223,9 +1223,10 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
if (getLangOpts().OpenMP && CurCodeDecl)
CGM.getOpenMPRuntime().emitFunctionProlog(*this, CurCodeDecl);
- // Handle emitting HLSL entry functions.
- if (D && D->hasAttr<HLSLShaderAttr>())
- CGM.getHLSLRuntime().emitEntryFunction(FD, Fn);
+ // Emit HLSL specific initialization
+ if (getLangOpts().HLSL) {
+ CGM.getHLSLRuntime().emitFunctionProlog(FD, Fn);
+ }
EmitFunctionProlog(*CurFnInfo, CurFn, Args);
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index a3f8126a9f915..602ebf9732870 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -1673,8 +1673,15 @@ bool Sema::CheckRedeclarationExported(NamedDecl *New, NamedDecl *Old) {
if (!IsNewExported && !IsOldExported)
return false;
- if (IsOldExported)
+ if (IsOldExported) {
+ if (LangOpts.HLSL && !IsNewExported) {
+ Diag(New->getLocation(), diag::err_redeclaration_missing_export) << New;
+ Diag(Old->getLocation(), diag::note_previous_declaration);
+ New->setInvalidDecl();
+ return true;
+ }
return false;
+ }
// If the Old declaration are not attached to named modules
// and the New declaration are attached to global module.
diff --git a/clang/test/AST/Interp/hlsl.hlsl b/clang/test/AST/Interp/hlsl.hlsl
index cb14662c11f39..bdf00c3659bf0 100644
--- a/clang/test/AST/Interp/hlsl.hlsl
+++ b/clang/test/AST/Interp/hlsl.hlsl
@@ -12,7 +12,7 @@
// CHECK: [[splat:%.*]] = insertelement <1 x i32> poison, i32 {{.*}}, i64 0
// CHECK: [[vec2:%.*]] = shufflevector <1 x i32> [[splat]], <1 x i32> poison, <2 x i32> zeroinitializer
// CHECK: ret <2 x i32> [[vec2]]
-int2 ToTwoInts(int V){
+export int2 ToTwoInts(int V){
return V.xx;
}
diff --git a/clang/test/CodeGenHLSL/ArrayTemporary.hlsl b/clang/test/CodeGenHLSL/ArrayTemporary.hlsl
index 63a30b61440eb..b4ba97eadc993 100644
--- a/clang/test/CodeGenHLSL/ArrayTemporary.hlsl
+++ b/clang/test/CodeGenHLSL/ArrayTemporary.hlsl
@@ -8,7 +8,7 @@ void fn(float x[2]) { }
// CHECK: call void @llvm.memset.p0.i32(ptr align 4 [[Arr]], i8 0, i32 8, i1 false)
// CHECK: call void @llvm.memcpy.p0.p0.i32(ptr align 4 [[Tmp]], ptr align 4 [[Arr]], i32 8, i1 false)
// CHECK: call void {{.*}}fn{{.*}}(ptr noundef byval([2 x float]) align 4 [[Tmp]])
-void call() {
+export void call() {
float Arr[2] = {0, 0};
fn(Arr);
}
@@ -26,7 +26,7 @@ void fn2(Obj O[4]) { }
// CHECK: call void @llvm.memset.p0.i32(ptr align 4 [[Arr]], i8 0, i32 32, i1 false)
// CHECK: call void @llvm.memcpy.p0.p0.i32(ptr align 4 [[Tmp]], ptr align 4 [[Arr]], i32 32, i1 false)
// CHECK: call void {{.*}}fn2{{.*}}(ptr noundef byval([4 x %struct.Obj]) align 4 [[Tmp]])
-void call2() {
+export void call2() {
Obj Arr[4] = {};
fn2(Arr);
}
@@ -40,7 +40,7 @@ void fn3(float x[2][2]) { }
// CHECK: call void @llvm.memcpy.p0.p0.i32(ptr align 4 [[Arr]], ptr align 4 {{.*}}, i32 16, i1 false)
// CHECK: call void @llvm.memcpy.p0.p0.i32(ptr align 4 [[Tmp]], ptr align 4 [[Arr]], i32 16, i1 false)
// CHECK: call void {{.*}}fn3{{.*}}(ptr noundef byval([2 x [2 x float]]) align 4 [[Tmp]])
-void call3() {
+export void call3() {
float Arr[2][2] = {{0, 0}, {1,1}};
fn3(Arr);
}
@@ -51,7 +51,7 @@ void call3() {
// CHECK: call void @llvm.memcpy.p0.p0.i32(ptr align 4 [[Tmp]], ptr align 4 [[Arr]], i32 16, i1 false)
// CHECK: call void {{.*}}fn3{{.*}}(ptr noundef byval([2 x [2 x float]]) align 4 [[Tmp]])
-void call4(float Arr[2][2]) {
+export void call4(float Arr[2][2]) {
fn3(Arr);
}
@@ -77,7 +77,7 @@ void call4(float Arr[2][2]) {
template<typename T>
void template_fn(T Val) {}
-void template_call(float FA2[2], float FA4[4], int IA3[3]) {
+export void template_call(float FA2[2], float FA4[4], int IA3[3]) {
template_fn(FA2);
template_fn(FA4);
template_fn(IA3);
@@ -98,7 +98,7 @@ void template_call(float FA2[2], float FA4[4], int IA3[3]) {
// CHECK: [[Idx1:%.*]] = getelementptr inbounds [2 x float], ptr [[FA2]], i32 0, i32 1
// CHECK: store float [[Sum]], ptr [[Idx1]]
-void element_access(float FA2[2]) {
+export void element_access(float FA2[2]) {
template_fn(FA2[0]);
FA2[1] = FA2[0] + 5;
}
diff --git a/clang/test/CodeGenHLSL/BasicFeatures/standard_conversion_sequences.hlsl b/clang/test/CodeGenHLSL/BasicFeatures/standard_conversion_sequences.hlsl
index 5d751be6dae06..940efcbd537f6 100644
--- a/clang/test/CodeGenHLSL/BasicFeatures/standard_conversion_sequences.hlsl
+++ b/clang/test/CodeGenHLSL/BasicFeatures/standard_conversion_sequences.hlsl
@@ -1,5 +1,7 @@
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s
+export {
+
// CHECK-LABEL: f3_to_d4
// CHECK: [[f3:%.*]] = alloca <3 x float>
// CHECK: [[d4:%.*]] = alloca <4 x double>
@@ -117,3 +119,5 @@ void d4_to_b2() {
vector<double,4> d4 = 9.0;
vector<bool, 2> b2 = d4;
}
+
+} //export
diff --git a/clang/test/CodeGenHLSL/buffer-array-operator.hlsl b/clang/test/CodeGenHLSL/buffer-array-operator.hlsl
index 6bcb06106bf1c..8db7a0d4a31cd 100644
--- a/clang/test/CodeGenHLSL/buffer-array-operator.hlsl
+++ b/clang/test/CodeGenHLSL/buffer-array-operator.hlsl
@@ -3,7 +3,7 @@
const RWBuffer<float> In;
RWBuffer<float> Out;
-void fn(int Idx) {
+export void fn(int Idx) {
Out[Idx] = In[Idx];
}
diff --git a/clang/test/CodeGenHLSL/builtins/ScalarSwizzles.hlsl b/clang/test/CodeGenHLSL/builtins/ScalarSwizzles.hlsl
index 6395ddc2fee2a..4959e7c81161f 100644
--- a/clang/test/CodeGenHLSL/builtins/ScalarSwizzles.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/ScalarSwizzles.hlsl
@@ -2,6 +2,8 @@
// RUN: dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
// RUN: -o - | FileCheck %s
+export {
+
// CHECK-LABEL: ToTwoInts
// CHECK: [[splat:%.*]] = insertelement <1 x i32> poison, i32 {{.*}}, i64 0
// CHECK: [[vec2:%.*]] = shufflevector <1 x i32> [[splat]], <1 x i32> poison, <2 x i32> zeroinitializer
@@ -166,3 +168,5 @@ int AssignInt(int V){
X.x = V.x + V.x;
return X;
}
+
+} // export
diff --git a/clang/test/CodeGenHLSL/builtins/abs.hlsl b/clang/test/CodeGenHLSL/builtins/abs.hlsl
index ad65cab2721a2..070a1905c78f7 100644
--- a/clang/test/CodeGenHLSL/builtins/abs.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/abs.hlsl
@@ -8,6 +8,8 @@
using hlsl::abs;
+export {
+
#ifdef __HLSL_ENABLE_16_BIT
// NATIVE_HALF: define noundef i16 @
// NATIVE_HALF: call i16 @llvm.abs.i16(
@@ -91,3 +93,5 @@ double3 test_abs_double3(double3 p0) { return abs(p0); }
// CHECK: define noundef <4 x double> @
// CHECK: call <4 x double> @llvm.fabs.v4f64(
double4 test_abs_double4(double4 p0) { return abs(p0); }
+
+} // export
diff --git a/clang/test/CodeGenHLSL/builtins/acos.hlsl b/clang/test/CodeGenHLSL/builtins/acos.hlsl
index 78a05cadfcd43..8e0e0afe869ff 100644
--- a/clang/test/CodeGenHLSL/builtins/acos.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/acos.hlsl
@@ -6,6 +6,8 @@
// RUN: spirv-unknown-vulkan-compute %s -emit-llvm -disable-llvm-passes \
// RUN: -o - | FileCheck %s --check-prefixes=CHECK,NO_HALF
+export {
+
// CHECK-LABEL: test_acos_half
// NATIVE_HALF: call half @llvm.acos.f16
// NO_HALF: call float @llvm.acos.f32
@@ -57,3 +59,5 @@ float3 test_acos_float3 ( float3 p0 ) {
float4 test_acos_float4 ( float4 p0 ) {
return acos ( p0 );
}
+
+} // export
diff --git a/clang/test/CodeGenHLSL/builtins/all.hlsl b/clang/test/CodeGenHLSL/builtins/all.hlsl
index b48daa287480f..6811b6d3ebc53 100644
--- a/clang/test/CodeGenHLSL/builtins/all.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/all.hlsl
@@ -13,6 +13,8 @@
// RUN: dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
// RUN: -o - | FileCheck %s --check-prefixes=CHECK,DXIL_NO_HALF,DXIL_CHECK
+export {
+
#ifdef __HLSL_ENABLE_16_BIT
// DXIL_NATIVE_HALF: define noundef i1 @
// SPIR_NATIVE_HALF: define spir_func noundef i1 @
@@ -275,3 +277,5 @@ bool test_all_bool3(bool3 p0) { return all(p0); }
// SPIR_CHECK: %hlsl.all = call i1 @llvm.spv.all.v4i1
// CHECK: ret i1 %hlsl.all
bool test_all_bool4(bool4 p0) { return all(p0); }
+
+} // export
diff --git a/clang/test/CodeGenHLSL/builtins/any.hlsl b/clang/test/CodeGenHLSL/builtins/any.hlsl
index 84584281a3b7d..60b1d05c7df18 100644
--- a/clang/test/CodeGenHLSL/builtins/any.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/any.hlsl
@@ -13,6 +13,8 @@
// RUN: dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
// RUN: -o - | FileCheck %s --check-prefixes=CHECK,DXIL_NO_HALF,DXIL_CHECK
+export {
+
#ifdef __HLSL_ENABLE_16_BIT
// DXIL_NATIVE_HALF: define noundef i1 @
// SPIR_NATIVE_HALF: define spir_func noundef i1 @
@@ -302,3 +304,5 @@ bool test_any_bool3(bool3 p0) { return any(p0); }
// SPIR_CHECK: %hlsl.any = call i1 @llvm.spv.any.v4i1
// CHECK: ret i1 %hlsl.any
bool test_any_bool4(bool4 p0) { return any(p0); }
+
+} // export
diff --git a/clang/test/CodeGenHLSL/builtins/asin.hlsl b/clang/test/CodeGenHLSL/builtins/asin.hlsl
index 1d0b457e336f5..3505046d78590 100644
--- a/clang/test/CodeGenHLSL/builtins/asin.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/asin.hlsl
@@ -6,6 +6,8 @@
// RUN: spirv-unknown-vulkan-compute %s -emit-llvm -disable-llvm-passes \
// RUN: -o - | FileCheck %s --check-prefixes=CHECK,NO_HALF
+export {
+
// CHECK-LABEL: test_asin_half
// NATIVE_HALF: call half @llvm.asin.f16
// NO_HALF: call float @llvm.asin.f32
@@ -57,3 +59,5 @@ float3 test_asin_float3 ( float3 p0 ) {
float4 test_asin_float4 ( float4 p0 ) {
return asin ( p0 );
}
+
+} // export
diff --git a/clang/test/CodeGenHLSL/builtins/atan.hlsl b/clang/test/CodeGenHLSL/builtins/atan.hlsl
index faee1227f3595..dcc64f6a19d90 100644
--- a/clang/test/CodeGenHLSL/builtins/atan.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/atan.hlsl
@@ -6,6 +6,8 @@
// RUN: spirv-unknown-vulkan-compute %s -emit-llvm -disable-llvm-passes \
// RUN: -o - | FileCheck %s --check-prefixes=CHECK,NO_HALF
+export {
+
// CHECK-LABEL: test_atan_half
// NATIVE_HALF: call half @llvm.atan.f16
// NO_HALF: call float @llvm.atan.f32
@@ -57,3 +59,5 @@ float3 test_atan_float3 ( float3 p0 ) {
float4 test_atan_float4 ( float4 p0 ) {
return atan ( p0 );
}
+
+} // export
diff --git a/clang/test/CodeGenHLSL/builtins/ceil.hlsl b/clang/test/CodeGenHLSL/builtins/ceil.hlsl
index be7725cd4d66c..452a65e6d4ed3 100644
--- a/clang/test/CodeGenHLSL/builtins/ceil.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/ceil.hlsl
@@ -8,6 +8,8 @@
using hlsl::ceil;
+export {
+
// NATIVE_HALF: define noundef half @
// NATIVE_HALF: call half @llvm.ceil.f16(
// NO_HALF: define noundef float @"?test_ceil_half@@YA$halff@$halff@@Z"(
@@ -41,3 +43,5 @@ float3 test_ceil_float3(float3 p0) { return ceil(p0); }
// CHECK: define noundef <4 x float> @
// CHECK: call <4 x float> @llvm.ceil.v4f32(
float4 test_ceil_float4(float4 p0) { return ceil(p0); }
+
+} // export
diff --git a/clang/test/CodeGenHLSL/builtins/clamp-builtin.hlsl b/clang/test/CodeGenHLSL/builtins/clamp-builtin.hlsl
index e3ef26429e7e4..0be010aacada8 100644
--- a/clang/test/CodeGenHLSL/builtins/clamp-builtin.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/clamp-builtin.hlsl
@@ -3,6 +3,6 @@
// CHECK-LABEL: builtin_test_clamp_int4
// CHECK: %dx.clamp = call <4 x i32> @llvm.dx.clamp.v4i32(<4 x i32> %0, <4 x i32> %1, <4 x i32> %2)
// CHECK: ret <4 x i32> %dx.clamp
-int4 builtin_test_clamp_int4(int4 p0, int4 p1, int4 p2) {
+export int4 builtin_test_clamp_int4(int4 p0, int4 p1, int4 p2) {
return __builtin_hlsl_elementwise_clamp(p0, p1, p2);
}
diff --git a/clang/test/CodeGenHLSL/builtins/clamp.hlsl b/clang/test/CodeGenHLSL/builtins/clamp.hlsl
index 186114581e9c1..9fcb0d0f7a91e 100644
--- a/clang/test/CodeGenHLSL/builtins/clamp.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/clamp.hlsl
@@ -6,6 +6,8 @@
// RUN: dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
// RUN: -o - | FileCheck %s --check-prefixes=CHECK,NO_HALF
+export {
+
#ifdef __HLSL_ENABLE_16_BIT
// NATIVE_HALF: define noundef i16 @
// NATIVE_HALF: call i16 @llvm.dx.clamp.i16(
@@ -132,3 +134,5 @@ double3 test_clamp_double3(double3 p0, double3 p1) { return clamp(p0, p1,p1); }
// CHECK: define noundef <4 x double> @
// CHECK: call <4 x double> @llvm.dx.clamp.v4f64
double4 test_clamp_double4(double4 p0, double4 p1) { return clamp(p0, p1,p1); }
+
+} // export
diff --git a/clang/test/CodeGenHLSL/builti...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/95331
More information about the cfe-commits
mailing list