LLVM 20.0.0git
DXILTranslateMetadata.cpp
Go to the documentation of this file.
1//===- DXILTranslateMetadata.cpp - Pass to emit DXIL metadata -------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10#include "DXILMetadata.h"
11#include "DXILResource.h"
13#include "DXILShaderFlags.h"
14#include "DirectX.h"
15#include "llvm/ADT/StringSet.h"
16#include "llvm/IR/Constants.h"
17#include "llvm/IR/Metadata.h"
18#include "llvm/IR/Module.h"
19#include "llvm/Pass.h"
21
22using namespace llvm;
23using namespace llvm::dxil;
24
25static void translateMetadata(Module &M, const dxil::Resources &MDResources,
26 const ComputedShaderFlags &ShaderFlags) {
27 dxil::ValidatorVersionMD ValVerMD(M);
28 if (ValVerMD.isEmpty())
29 ValVerMD.update(VersionTuple(1, 0));
32
33 MDResources.write(M);
34
35 dxil::createEntryMD(M, static_cast<uint64_t>(ShaderFlags));
36}
37
40 const dxil::Resources &MDResources = MAM.getResult<DXILResourceMDAnalysis>(M);
41 const ComputedShaderFlags &ShaderFlags =
43
44 translateMetadata(M, MDResources, ShaderFlags);
45
47}
48
49namespace {
50class DXILTranslateMetadataLegacy : public ModulePass {
51public:
52 static char ID; // Pass identification, replacement for typeid
53 explicit DXILTranslateMetadataLegacy() : ModulePass(ID) {}
54
55 StringRef getPassName() const override { return "DXIL Translate Metadata"; }
56
57 void getAnalysisUsage(AnalysisUsage &AU) const override {
58 AU.setPreservesAll();
61 }
62
63 bool runOnModule(Module &M) override {
64 const dxil::Resources &MDResources =
65 getAnalysis<DXILResourceMDWrapper>().getDXILResource();
66 const ComputedShaderFlags &ShaderFlags =
67 getAnalysis<ShaderFlagsAnalysisWrapper>().getShaderFlags();
68
69 translateMetadata(M, MDResources, ShaderFlags);
70 return true;
71 }
72};
73
74} // namespace
75
76char DXILTranslateMetadataLegacy::ID = 0;
77
79 return new DXILTranslateMetadataLegacy();
80}
81
82INITIALIZE_PASS_BEGIN(DXILTranslateMetadataLegacy, "dxil-translate-metadata",
83 "DXIL Translate Metadata", false, false)
86INITIALIZE_PASS_END(DXILTranslateMetadataLegacy, "dxil-translate-metadata",
87 "DXIL Translate Metadata", false, false)
Add AMDGPU uniform metadata
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static void translateMetadata(Module &M, const dxil::Resources &MDResources, const ComputedShaderFlags &ShaderFlags)
This file contains the declarations for metadata subclasses.
Module.h This file contains the declarations for the Module class.
ModuleAnalysisManager MAM
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:55
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:57
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:52
StringSet - A set-like wrapper for the StringMap.
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:253
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:405
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
void setPreservesAll()
Set by analyses that do not transform their input at all.
Analysis pass that exposes the DXILResource for a module.
The legacy pass manager's analysis pass to compute DXIL resource information.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &)
Root of the metadata hierarchy.
Definition: Metadata.h:62
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition: Pass.h:251
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:111
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: Analysis.h:117
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
Represents a version number in the form major[.minor[.subminor[.build]]].
Definition: VersionTuple.h:29
void write(Module &M) const
Wrapper pass for the legacy pass manager.
void update(VersionTuple ValidatorVer)
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
void createShaderModelMD(Module &M)
void createDXILVersionMD(Module &M)
void createEntryMD(Module &M, const uint64_t ShaderFlags)
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
ModulePass * createDXILTranslateMetadataLegacyPass()
Pass to emit metadata for DXIL.