python3kgae updated this revision to Diff 461271. python3kgae added a comment. Herald added a reviewer: aaron.ballman.
Add test for dtor in lib. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D133993/new/ https://reviews.llvm.org/D133993 Files: clang/lib/CodeGen/CGHLSLRuntime.cpp clang/lib/Sema/SemaDeclAttr.cpp clang/test/CodeGenHLSL/GlobalConstructorFunction.hlsl clang/test/CodeGenHLSL/GlobalConstructorLib.hlsl clang/test/CodeGenHLSL/GlobalConstructors.hlsl clang/test/CodeGenHLSL/GlobalDestructors.hlsl clang/test/CodeGenHLSL/GlobalDestructorsLib.hlsl
Index: clang/test/CodeGenHLSL/GlobalDestructorsLib.hlsl =================================================================== --- clang/test/CodeGenHLSL/GlobalDestructorsLib.hlsl +++ clang/test/CodeGenHLSL/GlobalDestructorsLib.hlsl @@ -1,4 +1,7 @@ -// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -std=hlsl202x -S -emit-llvm -disable-llvm-passes %s -o - | FileCheck %s +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -std=hlsl202x -S -emit-llvm -disable-llvm-passes %s -o - | FileCheck %s + +// Make sure global variable for dtors exist for lib profile. +// CHECK:@llvm.global_dtors struct Tail { Tail() { @@ -39,9 +42,10 @@ Wag(); } + //CHECK: define void @main() //CHECK-NEXT: entry: -//CHECK-NEXT: call void @_GLOBAL__sub_I_GlobalDestructors.hlsl() +//CHECK-NEXT: call void @_GLOBAL__sub_I_GlobalDestructorsLib.hlsl() //CHECK-NEXT: %0 = call i32 @llvm.dx.flattened.thread.id.in.group() //CHECK-NEXT: call void @"?main@@YAXI@Z"(i32 %0) //CHECK-NEXT: call void @_GLOBAL__D_a() Index: clang/test/CodeGenHLSL/GlobalDestructors.hlsl =================================================================== --- clang/test/CodeGenHLSL/GlobalDestructors.hlsl +++ clang/test/CodeGenHLSL/GlobalDestructors.hlsl @@ -39,6 +39,9 @@ Wag(); } +// Make sure global variable for ctors/dtors removed. +// CHECK-NOT:@llvm.global_ctors +// CHECK-NOT:@llvm.global_dtors //CHECK: define void @main() //CHECK-NEXT: entry: //CHECK-NEXT: call void @_GLOBAL__sub_I_GlobalDestructors.hlsl() Index: clang/test/CodeGenHLSL/GlobalConstructors.hlsl =================================================================== --- clang/test/CodeGenHLSL/GlobalConstructors.hlsl +++ clang/test/CodeGenHLSL/GlobalConstructors.hlsl @@ -5,6 +5,9 @@ [numthreads(1,1,1)] void main(unsigned GI : SV_GroupIndex) {} +// Make sure global variable for ctors/dtors removed. +// CHECK-NOT:@llvm.global_ctors +// CHECK-NOT:@llvm.global_dtors //CHECK: define void @main() //CHECK-NEXT: entry: //CHECK-NEXT: call void @_GLOBAL__sub_I_GlobalConstructors.hlsl() Index: clang/test/CodeGenHLSL/GlobalConstructorLib.hlsl =================================================================== --- clang/test/CodeGenHLSL/GlobalConstructorLib.hlsl +++ clang/test/CodeGenHLSL/GlobalConstructorLib.hlsl @@ -1,5 +1,8 @@ // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -S -emit-llvm -disable-llvm-passes %s -o - | FileCheck %s +// Make sure global variable for ctors exist for lib profile. +// CHECK:@llvm.global_ctors + RWBuffer<float> Buffer; [shader("compute")] Index: clang/test/CodeGenHLSL/GlobalConstructorFunction.hlsl =================================================================== --- clang/test/CodeGenHLSL/GlobalConstructorFunction.hlsl +++ clang/test/CodeGenHLSL/GlobalConstructorFunction.hlsl @@ -17,6 +17,10 @@ [numthreads(1,1,1)] void main(unsigned GI : SV_GroupIndex) {} +// Make sure global variable for ctors/dtors removed. +// CHECK-NOT:@llvm.global_ctors +// CHECK-NOT:@llvm.global_dtors + //CHECK: define void @main() //CHECK-NEXT: entry: //CHECK-NEXT: call void @"?call_me_first@@YAXXZ"() Index: clang/lib/Sema/SemaDeclAttr.cpp =================================================================== --- clang/lib/Sema/SemaDeclAttr.cpp +++ clang/lib/Sema/SemaDeclAttr.cpp @@ -6895,7 +6895,10 @@ static void handleHLSLSVGroupIndexAttr(Sema &S, Decl *D, const ParsedAttr &AL) { using llvm::Triple; Triple Target = S.Context.getTargetInfo().getTriple(); - if (Target.getEnvironment() != Triple::Compute) { + if (Target.getEnvironment() != Triple::Compute && + Target.getEnvironment() != Triple::Library) { + // FIXME: it is OK for a compute shader entry and pixel shader entry live in + // same HLSL file. uint32_t Pipeline = (uint32_t)S.Context.getTargetInfo().getTriple().getEnvironment() - (uint32_t)llvm::Triple::Pixel; Index: clang/lib/CodeGen/CGHLSLRuntime.cpp =================================================================== --- clang/lib/CodeGen/CGHLSLRuntime.cpp +++ clang/lib/CodeGen/CGHLSLRuntime.cpp @@ -202,4 +202,14 @@ for (auto *Fn : DtorFns) B.CreateCall(FunctionCallee(Fn)); } + + // No need to keep global ctors/dtors for non-lib profile after call to + // ctors/dtors added for entry. + Triple T(M.getTargetTriple()); + if (T.getEnvironment() != Triple::EnvironmentType::Library) { + if (auto *GV = M.getNamedGlobal("llvm.global_ctors")) + GV->eraseFromParent(); + if (auto *GV = M.getNamedGlobal("llvm.global_dtors")) + GV->eraseFromParent(); + } }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits