[all-commits] [llvm/llvm-project] 508ef1: [HLSL][RootSignature] Introduce `HLSLFrontendActio...

Finn Plummer via All-commits all-commits at lists.llvm.org
Mon Aug 25 16:09:55 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 508ef1796cf3fb590c79e2c76bf3339d3e4a8739
      https://github.com/llvm/llvm-project/commit/508ef1796cf3fb590c79e2c76bf3339d3e4a8739
  Author: Finn Plummer <mail at inbelic.dev>
  Date:   2025-08-25 (Mon, 25 Aug 2025)

  Changed paths:
    M clang/include/clang/Basic/LangOptions.h
    M clang/include/clang/Driver/Options.td
    M clang/include/clang/Frontend/FrontendActions.h
    M clang/include/clang/Parse/ParseHLSLRootSignature.h
    M clang/include/clang/Sema/SemaHLSL.h
    M clang/lib/CodeGen/CodeGenModule.cpp
    M clang/lib/Driver/ToolChains/Clang.cpp
    M clang/lib/Driver/ToolChains/HLSL.cpp
    M clang/lib/Frontend/CompilerInvocation.cpp
    M clang/lib/Frontend/FrontendActions.cpp
    M clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
    M clang/lib/Parse/ParseDeclCXX.cpp
    M clang/lib/Parse/ParseHLSLRootSignature.cpp
    M clang/lib/Sema/SemaHLSL.cpp
    A clang/test/AST/HLSL/rootsignature-define-ast.hlsl
    A clang/test/Driver/dxc_rootsig-define.hlsl

  Log Message:
  -----------
  [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.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list