This is an archive of the discontinued LLVM Phabricator instance.

[HLSL] add -P option for dxc mode.
Needs ReviewPublic

Authored by python3kgae on May 15 2022, 8:02 PM.

Details

Summary

A new option -P is added for dxc mode.
The format is -P proprecossed_file_name
It will make compile preprocess only and output to proprecossed_file_name.

Internally it will be translated into -E -o proprecossed_file_name.

When -P exists, other output compile option like -Fo will be ignored because compiler will run preprocess only.
A warning will be report if this happened.

Diff Detail

Event Timeline

python3kgae created this revision.May 15 2022, 8:02 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 15 2022, 8:02 PM
python3kgae requested review of this revision.May 15 2022, 8:02 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 15 2022, 8:02 PM

Mostly just some comments on user output

clang/include/clang/Basic/DiagnosticDriverKinds.td
683

As I read it, "like -Fo" means either "-Fo" or "-o". I think saying that would be less vague.

clang/include/clang/Driver/Options.td
6924

--P is not allowed by DXC

6927

It's not the same as DXC's "-E", which is an unfortunate clash since I love redirecting preprocessed output into less 😒

I realize that we are using some of the clang defined flags to represent the weird DXC ones and in this case that is -E and -o, but this text to the user isn't going to be too helpful to the user who only has access to the DXC -E.

I'm not sure what "used alone" means in this context as you can very much include other flags alongside it

clang/lib/Driver/ToolChains/Clang.cpp
3480 ↗(On Diff #429598)

I think we need OPT_o here too in order to capture the full intent since -E doesn't include an output file

python3kgae marked 3 inline comments as done.

Rebase and fix merge conflict.

beanz added inline comments.Aug 5 2022, 2:11 PM
clang/include/clang/Driver/Options.td
6936

This is the same option as _SLASH_P right? Is there a reason not to re-use it?

python3kgae marked an inline comment as done.Aug 12 2022, 4:40 PM
python3kgae added inline comments.
clang/include/clang/Basic/DiagnosticDriverKinds.td
683

dxc mode only accept "-Fo".

clang/include/clang/Driver/Options.td
6924

To work around conflict with clang-cl option
_SLASH_P : CLFlag<"P">, HelpText<"Preprocess to file">;

6936

__SLASH_P is a flag which not accept output file name.
dxc_P is translated into -E -o filename.

-P a.txt will be -E -o a.txt for cc1.

clang/lib/Driver/ToolChains/Clang.cpp
3480 ↗(On Diff #429598)

OPT_o has NoXarchOption flag which enabled in dxc mode.
So we don't need OPT_o here.

python3kgae marked an inline comment as done.

Switch to CLMode -P and -Fi.

Not need to send -P and -Fi to cc1.

Make a full patch.

beanz added inline comments.Sep 1 2022, 12:15 PM
clang/include/clang/Basic/DiagnosticDriverKinds.td
670

We should be specific about which flags the user passed that aren't unsupported.

Update warning.

beanz added inline comments.Sep 13 2022, 11:50 AM
clang/lib/Driver/Driver.cpp
5459

Why is this change needed? Didn't we settle on having /P behave the way CL.exe does?

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

This warning should fire in CL mode too right? Should it not be dxc-specific?

python3kgae marked 3 inline comments as done.Sep 13 2022, 4:21 PM
python3kgae added inline comments.
clang/lib/Driver/Driver.cpp
5459

Removed.

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

cl mode report this warning

warning: b.txt: 'linker' input unused [-Wunused-command-line-argument]

when input is

--driver-mode=cl -Fo b.txt  -P -Fi"a.txt"

For HLSL, both -Fo and -Fi should be output.

beanz added inline comments.Sep 13 2022, 5:44 PM
clang/lib/Driver/ToolChains/HLSL.cpp
181

Then it shouldn’t be named dxc :)