Skip to content

Commit dddc84d

Browse files
thurstondtmsri
authored andcommitted
Revert "[HLSL] set alwaysinline on HLSL functions (llvm#106588)"
This reverts commit a729e70. Reason:bBuildbot failure (https://lab.llvm.org/buildbot/#/builders/25/builds/2541): 'Clang :: CodeGenHLSL/builtins/StructuredBuffer-subscript.hlsl' failed
1 parent 66561eb commit dddc84d

9 files changed

+42
-282
lines changed

clang/lib/CodeGen/CGHLSLRuntime.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,6 @@ void clang::CodeGen::CGHLSLRuntime::setHLSLEntryAttributes(
338338
NumThreadsAttr->getZ());
339339
Fn->addFnAttr(NumThreadsKindStr, NumThreadsStr);
340340
}
341-
Fn->addFnAttr(llvm::Attribute::NoInline);
342341
}
343342

344343
static Value *buildVectorInput(IRBuilder<> &B, Function *F, llvm::Type *Ty) {

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2473,14 +2473,11 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D,
24732473
B.addAttribute(llvm::Attribute::StackProtectReq);
24742474

24752475
if (!D) {
2476-
// Non-entry HLSL functions must always be inlined.
2477-
if (getLangOpts().HLSL && !F->hasFnAttribute(llvm::Attribute::NoInline))
2478-
B.addAttribute(llvm::Attribute::AlwaysInline);
24792476
// If we don't have a declaration to control inlining, the function isn't
24802477
// explicitly marked as alwaysinline for semantic reasons, and inlining is
24812478
// disabled, mark the function as noinline.
2482-
else if (!F->hasFnAttribute(llvm::Attribute::AlwaysInline) &&
2483-
CodeGenOpts.getInlining() == CodeGenOptions::OnlyAlwaysInlining)
2479+
if (!F->hasFnAttribute(llvm::Attribute::AlwaysInline) &&
2480+
CodeGenOpts.getInlining() == CodeGenOptions::OnlyAlwaysInlining)
24842481
B.addAttribute(llvm::Attribute::NoInline);
24852482

24862483
F->addFnAttrs(B);
@@ -2507,13 +2504,9 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D,
25072504
ShouldAddOptNone &= !D->hasAttr<MinSizeAttr>();
25082505
ShouldAddOptNone &= !D->hasAttr<AlwaysInlineAttr>();
25092506

2510-
// Non-entry HLSL functions must always be inlined.
2511-
if (getLangOpts().HLSL && !F->hasFnAttribute(llvm::Attribute::NoInline) &&
2512-
!D->hasAttr<NoInlineAttr>()) {
2513-
B.addAttribute(llvm::Attribute::AlwaysInline);
2514-
} else if ((ShouldAddOptNone || D->hasAttr<OptimizeNoneAttr>()) &&
2515-
!F->hasFnAttribute(llvm::Attribute::AlwaysInline)) {
2516-
// Add optnone, but do so only if the function isn't always_inline.
2507+
// Add optnone, but do so only if the function isn't always_inline.
2508+
if ((ShouldAddOptNone || D->hasAttr<OptimizeNoneAttr>()) &&
2509+
!F->hasFnAttribute(llvm::Attribute::AlwaysInline)) {
25172510
B.addAttribute(llvm::Attribute::OptimizeNone);
25182511

25192512
// OptimizeNone implies noinline; we should not be inlining such functions.
@@ -2533,8 +2526,7 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D,
25332526
B.addAttribute(llvm::Attribute::NoInline);
25342527
} else if (D->hasAttr<NoDuplicateAttr>()) {
25352528
B.addAttribute(llvm::Attribute::NoDuplicate);
2536-
} else if (D->hasAttr<NoInlineAttr>() &&
2537-
!F->hasFnAttribute(llvm::Attribute::AlwaysInline)) {
2529+
} else if (D->hasAttr<NoInlineAttr>() && !F->hasFnAttribute(llvm::Attribute::AlwaysInline)) {
25382530
// Add noinline if the function isn't always_inline.
25392531
B.addAttribute(llvm::Attribute::NoInline);
25402532
} else if (D->hasAttr<AlwaysInlineAttr>() &&
Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -emit-llvm -disable-llvm-passes %s -o - | FileCheck %s --check-prefixes=CHECK,NOINLINE
2-
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -emit-llvm -O0 %s -o - | FileCheck %s --check-prefixes=CHECK,INLINE
1+
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -emit-llvm -disable-llvm-passes %s -o - | FileCheck %s
32

43
int i;
54

@@ -8,7 +7,7 @@ __attribute__((constructor)) void call_me_first(void) {
87
}
98

109
__attribute__((constructor)) void then_call_me(void) {
11-
i = 13;
10+
i = 12;
1211
}
1312

1413
__attribute__((destructor)) void call_me_last(void) {
@@ -22,21 +21,11 @@ void main(unsigned GI : SV_GroupIndex) {}
2221
// CHECK-NOT:@llvm.global_ctors
2322
// CHECK-NOT:@llvm.global_dtors
2423

25-
// CHECK: define void @main()
26-
// CHECK-NEXT: entry:
27-
// Verify function constructors are emitted
28-
// NOINLINE-NEXT: call void @"?call_me_first@@YAXXZ"()
29-
// NOINLINE-NEXT: call void @"?then_call_me@@YAXXZ"()
30-
// NOINLINE-NEXT: %0 = call i32 @llvm.dx.flattened.thread.id.in.group()
31-
// NOINLINE-NEXT: call void @"?main@@YAXI@Z"(i32 %0)
32-
// NOINLINE-NEXT: call void @"?call_me_last@@YAXXZ"(
33-
// NOINLINE-NEXT: ret void
34-
35-
// Verify constructor calls are inlined when AlwaysInline is run
36-
// INLINE-NEXT: alloca
37-
// INLINE-NEXT: store i32 12
38-
// INLINE-NEXT: store i32 13
39-
// INLINE-NEXT: %0 = call i32 @llvm.dx.flattened.thread.id.in.group()
40-
// INLINE-NEXT: store i32 %
41-
// INLINE-NEXT: store i32 0
42-
// INLINE: ret void
24+
//CHECK: define void @main()
25+
//CHECK-NEXT: entry:
26+
//CHECK-NEXT: call void @"?call_me_first@@YAXXZ"()
27+
//CHECK-NEXT: call void @"?then_call_me@@YAXXZ"()
28+
//CHECK-NEXT: %0 = call i32 @llvm.dx.flattened.thread.id.in.group()
29+
//CHECK-NEXT: call void @"?main@@YAXI@Z"(i32 %0)
30+
//CHECK-NEXT: call void @"?call_me_last@@YAXXZ"(
31+
//CHECK-NEXT: ret void
Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -emit-llvm -disable-llvm-passes %s -o - | FileCheck %s --check-prefixes=CHECK,NOINLINE
2-
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -emit-llvm -O0 %s -o - | FileCheck %s --check-prefixes=CHECK,INLINE
1+
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -emit-llvm -disable-llvm-passes %s -o - | FileCheck %s
32

43
// Make sure global variable for ctors exist for lib profile.
54
// CHECK:@llvm.global_ctors
@@ -12,27 +11,13 @@ void FirstEntry() {}
1211

1312
// CHECK: define void @FirstEntry()
1413
// CHECK-NEXT: entry:
15-
// NOINLINE-NEXT: call void @_GLOBAL__sub_I_GlobalConstructorLib.hlsl()
16-
// NOINLINE-NEXT: call void @"?FirstEntry@@YAXXZ"()
17-
// Verify inlining leaves only calls to "llvm." intrinsics
18-
// INLINE-NOT: call {{[^@]*}} @{{[^l][^l][^v][^m][^\.]}}
19-
// CHECK: ret void
14+
// CHECK-NEXT: call void @_GLOBAL__sub_I_GlobalConstructorLib.hlsl()
2015

2116
[shader("compute")]
2217
[numthreads(1,1,1)]
2318
void SecondEntry() {}
2419

2520
// CHECK: define void @SecondEntry()
2621
// CHECK-NEXT: entry:
27-
// NOINLINE-NEXT: call void @_GLOBAL__sub_I_GlobalConstructorLib.hlsl()
28-
// NOINLINE-NEXT: call void @"?SecondEntry@@YAXXZ"()
29-
// Verify inlining leaves only calls to "llvm." intrinsics
30-
// INLINE-NOT: call {{[^@]*}} @{{[^l][^l][^v][^m][^\.]}}
31-
// CHECK: ret void
32-
33-
34-
// Verify the constructor is alwaysinline
35-
// NOINLINE: ; Function Attrs: {{.*}}alwaysinline
36-
// NOINLINE-NEXT: define internal void @_GLOBAL__sub_I_GlobalConstructorLib.hlsl() [[IntAttr:\#[0-9]+]]
37-
38-
// NOINLINE: attributes [[IntAttr]] = {{.*}} alwaysinline
22+
// CHECK-NEXT: call void @_GLOBAL__sub_I_GlobalConstructorLib.hlsl()
23+
// CHECK-NEXT: call void @"?SecondEntry@@YAXXZ"()

clang/test/CodeGenHLSL/GlobalDestructors.hlsl

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
1-
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -std=hlsl202x -emit-llvm -disable-llvm-passes %s -o - | FileCheck %s --check-prefixes=CS,NOINLINE,CHECK
2-
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -std=hlsl202x -emit-llvm -disable-llvm-passes %s -o - | FileCheck %s --check-prefixes=LIB,NOINLINE,CHECK
3-
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -std=hlsl202x -emit-llvm -O0 %s -o - | FileCheck %s --check-prefixes=INLINE,CHECK
4-
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -std=hlsl202x -emit-llvm -O0 %s -o - | FileCheck %s --check-prefixes=INLINE,CHECK
1+
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -std=hlsl202x -emit-llvm -disable-llvm-passes %s -o - | FileCheck %s --check-prefixes=CS,CHECK
2+
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -std=hlsl202x -emit-llvm -disable-llvm-passes %s -o - | FileCheck %s --check-prefixes=LIB,CHECK
53

6-
// Tests that constructors and destructors are appropriately generated for globals
7-
// and that their calls are inlined when AlwaysInline is run
8-
// but global variables are retained for the library profiles
9-
10-
// Make sure global variable for ctors/dtors exist for lib profile.
11-
// LIB:@llvm.global_ctors
4+
// Make sure global variable for dtors exist for lib profile.
125
// LIB:@llvm.global_dtors
13-
// Make sure global variable for ctors/dtors removed for compute profile.
14-
// CS-NOT:@llvm.global_ctors
15-
// CS-NOT:@llvm.global_dtors
6+
// Make sure global variable for dtors removed for compute profile.
7+
// CS-NOT:llvm.global_dtors
168

179
struct Tail {
1810
Tail() {
@@ -54,25 +46,22 @@ void main(unsigned GI : SV_GroupIndex) {
5446
Wag();
5547
}
5648

57-
// CHECK: define void @main()
58-
// CHECK-NEXT: entry:
59-
// Verify destructor is emitted
60-
// NOINLINE-NEXT: call void @_GLOBAL__sub_I_GlobalDestructors.hlsl()
61-
// NOINLINE-NEXT: %0 = call i32 @llvm.dx.flattened.thread.id.in.group()
62-
// NOINLINE-NEXT: call void @"?main@@YAXI@Z"(i32 %0)
63-
// NOINLINE-NEXT: call void @_GLOBAL__D_a()
64-
// NOINLINE-NEXT: ret void
65-
// Verify inlining leaves only calls to "llvm." intrinsics
66-
// INLINE-NOT: call {{[^@]*}} @{{[^l][^l][^v][^m][^\.]}}
67-
// INLINE: ret void
49+
// Make sure global variable for ctors/dtors removed.
50+
// CHECK-NOT:@llvm.global_ctors
51+
// CHECK-NOT:@llvm.global_dtors
52+
//CHECK: define void @main()
53+
//CHECK-NEXT: entry:
54+
//CHECK-NEXT: call void @_GLOBAL__sub_I_GlobalDestructors.hlsl()
55+
//CHECK-NEXT: %0 = call i32 @llvm.dx.flattened.thread.id.in.group()
56+
//CHECK-NEXT: call void @"?main@@YAXI@Z"(i32 %0)
57+
//CHECK-NEXT: call void @_GLOBAL__D_a()
58+
//CHECK-NEXT: ret void
6859

6960
// This is really just a sanity check I needed for myself to verify that
7061
// function scope static variables also get destroyed properly.
7162

72-
// NOINLINE: define internal void @_GLOBAL__D_a() [[IntAttr:\#[0-9]+]]
73-
// NOINLINE-NEXT: entry:
74-
// NOINLINE-NEXT: call void @"??1Tail@@QAA@XZ"(ptr @"?T@?1??Wag@@YAXXZ@4UTail@@A")
75-
// NOINLINE-NEXT: call void @"??1Pupper@@QAA@XZ"(ptr @"?GlobalPup@@3UPupper@@A")
76-
// NOINLINE-NEXT: ret void
77-
78-
// NOINLINE: attributes [[IntAttr]] = {{.*}} alwaysinline
63+
//CHECK: define internal void @_GLOBAL__D_a()
64+
//CHECK-NEXT: entry:
65+
//CHECK-NEXT: call void @"??1Tail@@QAA@XZ"(ptr @"?T@?1??Wag@@YAXXZ@4UTail@@A")
66+
//CHECK-NEXT: call void @"??1Pupper@@QAA@XZ"(ptr @"?GlobalPup@@3UPupper@@A")
67+
//CHECK-NEXT: ret void

clang/test/CodeGenHLSL/builtins/RWBuffer-constructor.hlsl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s
21
// RUN: %clang_cc1 -triple spirv-vulkan-library -x hlsl -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s --check-prefix=CHECK-SPIRV
32

43
RWBuffer<float> Buf;

clang/test/CodeGenHLSL/builtins/RWBuffer-subscript.hlsl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ void main(unsigned GI : SV_GroupIndex) {
1111
// Even at -O0 the subscript operators get inlined. The -O0 IR is a bit messy
1212
// and confusing to follow so the match here is pretty weak.
1313

14-
// CHECK: define void @main()
15-
// Verify inlining leaves only calls to "llvm." intrinsics
16-
// CHECK-NOT: call {{[^@]*}} @{{[^l][^l][^v][^m][^\.]}}
14+
// CHECK: define internal void @"?main@@YAXI@Z"
15+
// CHECK-NOT: call
1716
// CHECK: ret void

clang/test/CodeGenHLSL/inline-constructors.hlsl

Lines changed: 0 additions & 76 deletions
This file was deleted.

0 commit comments

Comments
 (0)