Skip to content
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

[DXIL] Always inline HLSL functions by default #89282

Closed
Tracked by #27 ...
pow2clk opened this issue Apr 18, 2024 · 2 comments · Fixed by #106588
Closed
Tracked by #27 ...

[DXIL] Always inline HLSL functions by default #89282

pow2clk opened this issue Apr 18, 2024 · 2 comments · Fixed by #106588

Comments

@pow2clk
Copy link
Contributor

pow2clk commented Apr 18, 2024

Summary

At present, inlining in HLSL follows the existing heuristics which will inline if the function is short enough. To be correct in HLSL, we need to inline all non-entry functions. To do this we need to annotate either calls or function definitions (or some combination of both) as alwaysinline so that the inliner forces them to be inlined.

For HLSL shader and library targets, automatically apply the alwaysinline attribute to non-entry functions with tests regardless of qualifiers. The exception is the autogenerated unmangled main() function

Note that there are cases where not everything should be inlined (eg noinline attribute). This is out of scope for this issue.

@pow2clk
Copy link
Contributor Author

pow2clk commented Apr 18, 2024

More details to come as investigation of what's needed reveals them.

@damyanp damyanp moved this to Planning in HLSL Support Apr 22, 2024
@pow2clk pow2clk moved this from Planning to Active in HLSL Support Aug 26, 2024
@pow2clk pow2clk changed the title [DXIL] Always inline non-entry functions [DXIL] Always inline HLSL functions by default Aug 28, 2024
pow2clk added a commit to pow2clk/llvm-project that referenced this issue Aug 29, 2024
HLSL inlines all its functions by default. This uses the alwaysinline
attribute to force that in the corresponding pass for user functions
by default and overrides the default noinline of some implicit functions.
This makes an instance of explicit inlining for buffer subscripts unnecessary.

Adds tests for function and constructor inlining and augments some existing
tests to verify correct inlining of implicitly created functions as well.

incidentally restore RUN line that I believe was mistakenly removed as part of llvm#88918

fixes llvm#89282
@pow2clk pow2clk moved this from Active to Ready in HLSL Support Aug 29, 2024
pow2clk added a commit that referenced this issue Sep 17, 2024
HLSL inlines all its functions by default. This uses the alwaysinline
attribute to make the alwaysinliner pass inline any function not
explicitly marked noinline by the user or autogeneration. The
alwayslinline marking takes place in `SetLLVMFunctionAttributesForDefinitions`
where all other inlining interactions are determined.

The outermost entry function is marked noinline because there's no
reason to inline it. Any user calls to an entry function will instead call
the internal mangled version of the entry function.

Adds tests for function and constructor inlining and augments some
existing tests to verify correct inlining of implicitly created
functions as well.

Incidentally restore RUN line that I believe was mistakenly removed as
part of #88918

Fixes #89282
@github-project-automation github-project-automation bot moved this from Ready to Done in HLSL Support Sep 17, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 17, 2024

@llvm/issue-subscribers-clang-codegen

Author: Greg Roth (pow2clk)

### Summary

At present, inlining in HLSL follows the existing heuristics which will inline if the function is short enough. To be correct in HLSL, we need to inline all non-entry functions. To do this we need to annotate either calls or function definitions (or some combination of both) as alwaysinline so that the inliner forces them to be inlined.

For HLSL shader and library targets, automatically apply the alwaysinline attribute to non-entry functions with tests regardless of qualifiers. The exception is the autogenerated unmangled main() function

Note that there are cases where not everything should be inlined (eg noinline attribute). This is out of scope for this issue.

pow2clk added a commit that referenced this issue Sep 17, 2024
The Alwaysinline change made the mangled form of entry points get
removed. The StructuredBuffer-subscript.hlsl test was introduced in the
meantime depending on that version of the entry point. This revises it
in the same way as RWBuffer-subscript

Follow up to #89282
hamphet pushed a commit to hamphet/llvm-project that referenced this issue Sep 18, 2024
HLSL inlines all its functions by default. This uses the alwaysinline
attribute to make the alwaysinliner pass inline any function not
explicitly marked noinline by the user or autogeneration. The
alwayslinline marking takes place in `SetLLVMFunctionAttributesForDefinitions`
where all other inlining interactions are determined.

The outermost entry function is marked noinline because there's no
reason to inline it. Any user calls to an entry function will instead call
the internal mangled version of the entry function.

Adds tests for function and constructor inlining and augments some
existing tests to verify correct inlining of implicitly created
functions as well.

Incidentally restore RUN line that I believe was mistakenly removed as
part of llvm#88918

Fixes llvm#89282
hamphet pushed a commit to hamphet/llvm-project that referenced this issue Sep 18, 2024
…109023)

The Alwaysinline change made the mangled form of entry points get
removed. The StructuredBuffer-subscript.hlsl test was introduced in the
meantime depending on that version of the entry point. This revises it
in the same way as RWBuffer-subscript

Follow up to llvm#89282
tmsri pushed a commit to tmsri/llvm-project that referenced this issue Sep 19, 2024
HLSL inlines all its functions by default. This uses the alwaysinline
attribute to make the alwaysinliner pass inline any function not
explicitly marked noinline by the user or autogeneration. The
alwayslinline marking takes place in `SetLLVMFunctionAttributesForDefinitions`
where all other inlining interactions are determined.

The outermost entry function is marked noinline because there's no
reason to inline it. Any user calls to an entry function will instead call
the internal mangled version of the entry function.

Adds tests for function and constructor inlining and augments some
existing tests to verify correct inlining of implicitly created
functions as well.

Incidentally restore RUN line that I believe was mistakenly removed as
part of llvm#88918

Fixes llvm#89282
tmsri pushed a commit to tmsri/llvm-project that referenced this issue Sep 19, 2024
…109023)

The Alwaysinline change made the mangled form of entry points get
removed. The StructuredBuffer-subscript.hlsl test was introduced in the
meantime depending on that version of the entry point. This revises it
in the same way as RWBuffer-subscript

Follow up to llvm#89282
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

3 participants