[llvm] [DXIL] Add support for root signature flag element in DXContainer (PR #123147)

Damyan Pepper via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 10 12:07:37 PST 2025


================
@@ -0,0 +1,73 @@
+//===- DXILRootSignature.h - DXIL Root Signature helper objects
+//---------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file This file contains helper objects and APIs for working with DXIL
+///       Root Signatures.
+///
+//===----------------------------------------------------------------------===//
+
+#include "llvm/IR/DiagnosticInfo.h"
+#include "llvm/IR/Metadata.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/PassManager.h"
+#include "llvm/Pass.h"
+#include <optional>
+
+namespace llvm {
+namespace dxil {
+
+enum class RootSignatureElementKind {
+  None = 0,
+  RootFlags = 1,
+  RootConstants = 2,
+  RootDescriptor = 3,
+  DescriptorTable = 4,
+  StaticSampler = 5
+};
+
+struct ModuleRootSignature {
+  uint32_t Flags = 0;
+  static std::optional<ModuleRootSignature> analyzeModule(Module &M,
+                                                          const Function *F);
+};
+
+class RootSignatureAnalysis : public AnalysisInfoMixin<RootSignatureAnalysis> {
+  friend AnalysisInfoMixin<RootSignatureAnalysis>;
+  static AnalysisKey Key;
+
+public:
+  RootSignatureAnalysis() = default;
+
+  using Result = std::optional<ModuleRootSignature>;
+
+  std::optional<ModuleRootSignature> run(Module &M, ModuleAnalysisManager &AM);
+};
+
+/// Wrapper pass for the legacy pass manager.
+///
+/// This is required because the passes that will depend on this are codegen
+/// passes which run through the legacy pass manager.
+class RootSignatureAnalysisWrapper : public ModulePass {
+private:
+  std::optional<ModuleRootSignature> MRS;
+
+public:
+  static char ID;
+
+  RootSignatureAnalysisWrapper() : ModulePass(ID) {}
+
+  std::optional<ModuleRootSignature> getResult() const { return MRS; }
----------------
damyanp wrote:

```suggestion
  const std::optional<ModuleRootSignature>& getResult() const { return MRS; }
```

Sorry, my previous suggestion would result in a copy that it'd be best practice to avoid.

https://github.com/llvm/llvm-project/pull/123147


More information about the llvm-commits mailing list