diff options
author | Finn Plummer <mail@inbelic.dev> | 2025-08-25 16:09:34 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-08-25 16:09:34 -0700 |
commit | 508ef1796cf3fb590c79e2c76bf3339d3e4a8739 (patch) | |
tree | 04997bea0e518ebb66aea338bc1cc52a5b68d2d2 /clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp | |
parent | 1d3c302171692293f74f92236b446b9240774d4d (diff) | |
download | llvm-508ef1796cf3fb590c79e2c76bf3339d3e4a8739.zip llvm-508ef1796cf3fb590c79e2c76bf3339d3e4a8739.tar.gz llvm-508ef1796cf3fb590c79e2c76bf3339d3e4a8739.tar.bz2 |
[HLSL][RootSignature] Introduce `HLSLFrontendAction` to implement `rootsig-define` (#154639)
This pr implements the functionality of `rootsig-define` as described
[here](https://github.com/llvm/wg-hlsl/blob/main/proposals/0029-root-signature-driver-options.md#option--rootsig-define).
This is accomplished by:
- Defining the `fdx-rootsignature-define`, and `rootsig-define` alias,
driver options. It simply specifies the name of a macro that will expand
to a `LiteralString` to be interpreted as a root signature.
- Introduces a new general frontend action wrapper,
`HLSLFrontendAction`. This class allows us to introduce `HLSL` specific
behaviour on the underlying action (primarily `ASTFrontendAction`).
Which will be further extended, or modularly wrapped, when considering
future DXC options.
- Using `HLSLFrontendAction` we can add a new `PPCallback` that will
eagerly parse the root signature specified with `rootsig-define` and
push it as a `TopLevelDecl` to `Sema`. This occurs when the macro has
been lexed.
- Since the root signature is parsed early, before any function
declarations, we can then simply attach it to the entry function once it
is encountered. Overwriting any applicable root signature attrs.
Resolves https://github.com/llvm/llvm-project/issues/150274
##### Implementation considerations
To implement this feature, note that:
1. We need access to all defined macros. These are created as part of
the first `Lex` in `Parser::Initialize` after `PP->EnterMainSourceFile`
2. `RootSignatureDecl` must be added to `Sema` before
`Consumer->HandleTranslationUnit` is invoked in `ParseAST`
Therefore, we can't handle the root signature in
`HLSLFrontendAction::ExecuteAction` before (from 1.) or after (from 2.)
invoking the underlying `ASTFrontendAction`.
This means we could alternatively:
- Manually handle this case
[here](https://github.com/llvm/llvm-project/blob/ac8f0bb070c9071742b6f6ce03bebc9d87217830/clang/lib/Parse/ParseAST.cpp#L168)
before parsing the first top level decl.
- Hook into when we [return the entry function
decl](https://github.com/llvm/llvm-project/blob/ac8f0bb070c9071742b6f6ce03bebc9d87217830/clang/lib/Parse/Parser.cpp#L1190)
and then parse the root signature and override its `RootSignatureAttr`.
The proposed solution handles this in the most modular way which should
work on any `FrontendAction` that might use the `Parser` without
invoking `ParseAST`, and, is not subject to needing to call the hook in
multiple different places of function declarators.
Diffstat (limited to 'clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp')
-rw-r--r-- | clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp b/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp index 443eb4f..9a6844d 100644 --- a/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp +++ b/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp @@ -181,6 +181,9 @@ CreateFrontendAction(CompilerInstance &CI) { const FrontendOptions &FEOpts = CI.getFrontendOpts(); + if (CI.getLangOpts().HLSL) + Act = std::make_unique<HLSLFrontendAction>(std::move(Act)); + if (FEOpts.FixAndRecompile) { Act = std::make_unique<FixItRecompile>(std::move(Act)); } |