LLVM 20.0.0git
DXILTranslateMetadata.cpp
Go to the documentation of this file.
1//===- DXILTranslateMetadata.cpp - Pass to emit DXIL metadata ---*- C++ -*-===//
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///
9//===----------------------------------------------------------------------===//
10
11#include "DXILMetadata.h"
12#include "DXILResource.h"
14#include "DXILShaderFlags.h"
15#include "DirectX.h"
16#include "llvm/ADT/StringSet.h"
17#include "llvm/IR/Constants.h"
18#include "llvm/IR/Metadata.h"
19#include "llvm/IR/Module.h"
20#include "llvm/Pass.h"
22
23using namespace llvm;
24using namespace llvm::dxil;
25
26namespace {
27class DXILTranslateMetadata : public ModulePass {
28public:
29 static char ID; // Pass identification, replacement for typeid
30 explicit DXILTranslateMetadata() : ModulePass(ID) {}
31
32 StringRef getPassName() const override { return "DXIL Translate Metadata"; }
33
34 void getAnalysisUsage(AnalysisUsage &AU) const override {
35 AU.setPreservesAll();
38 }
39
40 bool runOnModule(Module &M) override;
41};
42
43} // namespace
44
45bool DXILTranslateMetadata::runOnModule(Module &M) {
46
47 dxil::ValidatorVersionMD ValVerMD(M);
48 if (ValVerMD.isEmpty())
49 ValVerMD.update(VersionTuple(1, 0));
52
53 const dxil::Resources &Res =
54 getAnalysis<DXILResourceMDWrapper>().getDXILResource();
55 Res.write(M);
56
57 const uint64_t Flags = static_cast<uint64_t>(
58 getAnalysis<ShaderFlagsAnalysisWrapper>().getShaderFlags());
59 dxil::createEntryMD(M, Flags);
60
61 return false;
62}
63
64char DXILTranslateMetadata::ID = 0;
65
67 return new DXILTranslateMetadata();
68}
69
70INITIALIZE_PASS_BEGIN(DXILTranslateMetadata, "dxil-translate-metadata",
71 "DXIL Translate Metadata", false, false)
74INITIALIZE_PASS_END(DXILTranslateMetadata, "dxil-translate-metadata",
75 "DXIL Translate Metadata", false, false)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
dxil translate metadata
This file contains the declarations for metadata subclasses.
Module.h This file contains the declarations for the Module class.
#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.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
void setPreservesAll()
Set by analyses that do not transform their input at all.
The legacy pass manager's analysis pass to compute DXIL resource information.
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
virtual bool runOnModule(Module &M)=0
runOnModule - Virtual method overriden by subclasses to process the module being operated on.
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Definition: Pass.cpp:98
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
Definition: Pass.cpp:81
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.
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 * createDXILTranslateMetadataPass()
Pass to emit metadata for DXIL.