-
Notifications
You must be signed in to change notification settings - Fork 11.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[HLSL] set alwaysinline on HLSL functions #106588
Merged
Merged
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1225381
[HLSL] set alwaysinline on HLSL functions
pow2clk b7e367a
update RWBuffer-AST test for later alwaysinline marking
pow2clk bdfb8dc
Respond to feedback
pow2clk fc22a5a
Default to safer behavior respecting noinline
pow2clk 5d970dd
clang-format
pow2clk 7709a26
Revise approach entirely
pow2clk cc719cc
clang-format again
pow2clk 09c5141
reformat comments
pow2clk 71a4ea7
noinline adjustments: warning, entry function
pow2clk b688023
clang-format (again)
pow2clk 91e68a3
Add test for new warning I left out of last commit
pow2clk a554a72
remove warning and respect noinline
pow2clk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -std=hlsl202x -emit-llvm -o - -disable-llvm-passes %s | FileCheck %s --check-prefixes=CHECK,NOINLINE | ||
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -std=hlsl202x -emit-llvm -o - -disable-llvm-passes %s | FileCheck %s --check-prefixes=CHECK,NOINLINE | ||
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -std=hlsl202x -emit-llvm -o - -O0 %s | FileCheck %s --check-prefixes=CHECK,INLINE | ||
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -std=hlsl202x -emit-llvm -o - -O0 %s | FileCheck %s --check-prefixes=CHECK,INLINE | ||
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -std=hlsl202x -emit-llvm -o - -O1 %s | FileCheck %s --check-prefixes=CHECK,INLINE | ||
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -std=hlsl202x -emit-llvm -o - -O1 %s | FileCheck %s --check-prefixes=CHECK,INLINE | ||
|
||
// Tests that implicit constructor calls for user classes will always be inlined. | ||
|
||
struct Weed { | ||
Weed() {Count += 1;} | ||
[[maybe_unused]] void pull() {Count--;} | ||
static int weedCount() { return Count; } | ||
private: | ||
static int Count; | ||
|
||
} YardWeeds; | ||
|
||
int Weed::Count = 1; // It begins. . . | ||
|
||
struct Kitty { | ||
unsigned burrsInFur; | ||
|
||
Kitty() { | ||
burrsInFur = 0; | ||
} | ||
|
||
void wanderInYard(int hours) { | ||
burrsInFur = hours*Weed::weedCount()/8; | ||
} | ||
|
||
void lick() { | ||
if(burrsInFur) { | ||
burrsInFur--; | ||
Weed w; | ||
} | ||
} | ||
|
||
} Nion; | ||
|
||
void NionsDay(int hours) { | ||
static Kitty Nion; | ||
Nion.wanderInYard(hours); | ||
while(Nion.burrsInFur) Nion.lick(); | ||
} | ||
|
||
// CHECK: define void @main() | ||
// CHECK-NEXT: entry: | ||
// Verify constructor is emitted | ||
// NOINLINE-NEXT: call void @_GLOBAL__sub_I_inline_constructors.hlsl() | ||
// NOINLINE-NEXT: %0 = call i32 @llvm.dx.flattened.thread.id.in.group() | ||
// NOINLINE-NEXT: call void @"?main@@YAXI@Z"(i32 %0) | ||
// Verify inlining leaves only calls to "llvm." intrinsics | ||
// INLINE-NOT: call {{[^@]*}} @{{[^l][^l][^v][^m][^\.]}} | ||
// CHECK: ret void | ||
[shader("compute")] | ||
[numthreads(1,1,1)] | ||
void main(unsigned GI : SV_GroupIndex) { | ||
NionsDay(10); | ||
} | ||
|
||
|
||
// CHECK: define void @rainyMain() | ||
// CHECK-NEXT: entry: | ||
// Verify constructor is emitted | ||
// NOINLINE-NEXT: call void @_GLOBAL__sub_I_inline_constructors.hlsl() | ||
// NOINLINE-NEXT: call void @"?rainyMain@@YAXXZ"() | ||
// Verify inlining leaves only calls to "llvm." intrinsics | ||
// INLINE-NOT: call {{[^@]*}} @{{[^l][^l][^v][^m][^\.]}} | ||
// CHECK: ret void | ||
[shader("compute")] | ||
[numthreads(1,1,1)] | ||
void rainyMain() { | ||
NionsDay(1); | ||
} | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we put
noinline
on the entry function? Does that simplify this logic? Since we'll also at some point need to support thenoinline
keyword we'll need to be checking that attribute somewhere.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In earlier discussion, we resolved to make this the default and not worry about noinline as of yet seeing as there are a lot of issues to resolve before that can work properly. In a previous version, I was forced to check for noinline as it was a sign that a function had passed through this function, but my preference is to not respect it until we've worked out the issues that prevent it from working right.
It wouldn't simplify the logic since the entry function doesn't get marked inline until it is passed into this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just an update. As a result of the waning minutes of a design discussion, we resolved to produce a warning when users apply noinline and explicitly set noinline for the outermost entry function which would allow checking for that in place of hlsl.shader here, which might allow graceful resolution of any other functions that happen to get it applied here which we could have an assert for.