This is an archive of the discontinued LLVM Phabricator instance.

[HLSL]Add -O and -Od option for dxc mode.
ClosedPublic

Authored by python3kgae on Jun 29 2022, 12:29 PM.

Details

Summary

Two new dxc mode options -O and -Od are added for dxc mode.
-O is just alias of existing cc1 -O option.
-Od will be lowered into -O0 and -dxc-opt-disable.

-dxc-opt-disable is cc1 option added to for build ShaderFlags.

Diff Detail

Event Timeline

python3kgae created this revision.Jun 29 2022, 12:29 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 29 2022, 12:29 PM
python3kgae requested review of this revision.Jun 29 2022, 12:29 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 29 2022, 12:29 PM

Fix test fail.

Looks good apart from my uncertainty as to what -fcgl should or shouldn't imply

clang/test/Driver/dxc_O.hlsl
10

It looks to me that these are added when -Od is specified, not -fcgl (aka pristine-llvm I guess ;))

Is the comment wrong or should these be added as part of pristine-llvm too?

beanz added inline comments.Jul 12 2022, 6:58 AM
clang/lib/Frontend/CompilerInvocation.cpp
575 ↗(On Diff #443070)

Is there a way to tie this to using the DXC driver instead of the language option?

It would be nice in the future to have a more clang-conformant driver mode.

python3kgae marked an inline comment as done.

Change default to O3 implement to HLSL driver and update test.

Use CLDXCOption for opt level.

Rebase and fix test fail.

beanz added inline comments.Aug 12 2022, 2:45 PM
clang/lib/CodeGen/CGHLSLRuntime.cpp
50

What does this translate to in codegen?

clang/lib/Driver/ToolChains/HLSL.cpp
170

Since dxc_opt_disable is paired with passing -O0 do we need the flag at all, or can we just set the module flag if OptimizationLevel is 0?

python3kgae marked 2 inline comments as done.Aug 12 2022, 2:54 PM
python3kgae added inline comments.
clang/lib/CodeGen/CGHLSLRuntime.cpp
50
clang/lib/Driver/ToolChains/HLSL.cpp
170

-O0 and -Od will generate different ShaderFlags in dxc.

python3kgae marked 2 inline comments as done.

Make O0 the same as Od.

beanz added inline comments.Sep 13 2022, 11:11 AM
clang/include/clang/Basic/TargetOptions.h
120 ↗(On Diff #457470)

If Od and O0 are the same you shouldn't need to track this, or have the extra command line option to set the flag, you should imply the shader flag from the optimization level.

Use O0 instead of DxcOptDisable since Od is same as O0.

python3kgae marked an inline comment as done.Sep 13 2022, 11:56 AM
beanz accepted this revision.Sep 13 2022, 12:32 PM

Two nits, please fix them before merging otherwise looks good.

clang/include/clang/Driver/Options.td
6941

nit: remove extra whitespace change.

clang/test/Driver/dxc_O.hlsl
11

nit: out of date comment.

This revision is now accepted and ready to land.Sep 13 2022, 12:32 PM
python3kgae marked an inline comment as done.

Cleanup per comments.

python3kgae marked an inline comment as done.Sep 13 2022, 2:51 PM
This revision was automatically updated to reflect the committed changes.