LLVM 17.0.0git
DXILPrettyPrinter.cpp
Go to the documentation of this file.
1//===- DXILPrettyPrinter.cpp - DXIL Resource helper objects ---------------===//
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/// \file This file contains a pass for pretty printing DXIL metadata into IR
10/// comments when printing assembly output.
11///
12//===----------------------------------------------------------------------===//
13
15#include "DirectX.h"
16#include "llvm/ADT/StringRef.h"
17#include "llvm/IR/PassManager.h"
18#include "llvm/Pass.h"
20
21using namespace llvm;
22
23namespace {
24class DXILPrettyPrinter : public llvm::ModulePass {
25 raw_ostream &OS; // raw_ostream to print to.
26
27public:
28 static char ID;
29 DXILPrettyPrinter() : ModulePass(ID), OS(dbgs()) {
31 }
32
33 explicit DXILPrettyPrinter(raw_ostream &O) : ModulePass(ID), OS(O) {
35 }
36
37 StringRef getPassName() const override {
38 return "DXIL Metadata Pretty Printer";
39 }
40
41 bool runOnModule(Module &M) override;
42 void getAnalysisUsage(AnalysisUsage &AU) const override {
43 AU.setPreservesAll();
45 }
46};
47} // namespace
48
49char DXILPrettyPrinter::ID = 0;
50INITIALIZE_PASS_BEGIN(DXILPrettyPrinter, "dxil-pretty-printer",
51 "DXIL Metadata Pretty Printer", true, true)
53INITIALIZE_PASS_END(DXILPrettyPrinter, "dxil-pretty-printer",
54 "DXIL Metadata Pretty Printer", true, true)
55
56bool DXILPrettyPrinter::runOnModule(Module &M) {
57 dxil::Resources &Res = getAnalysis<DXILResourceWrapper>().getDXILResource();
58 Res.print(OS);
59 return false;
60}
61
63 return new DXILPrettyPrinter(OS);
64}
dxil pretty printer
dxil pretty DXIL Metadata Pretty Printer
dxil pretty DXIL Metadata Pretty true
This header defines various interfaces for pass management in LLVM.
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:55
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:59
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:52
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:61
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition: Pass.h:248
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
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
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
void print(raw_ostream &O) const
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void initializeDXILPrettyPrinterPass(PassRegistry &)
Initializer for DXILPrettyPrinter.
ModulePass * createDXILPrettyPrinterPass(raw_ostream &OS)
Pass to pretty print DXIL metadata.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163