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 | |
14 | #include "DXILResourceAnalysis.h" |
15 | #include "DirectX.h" |
16 | #include "llvm/ADT/StringRef.h" |
17 | #include "llvm/IR/PassManager.h" |
18 | #include "llvm/Pass.h" |
19 | #include "llvm/Support/raw_ostream.h" |
20 | |
21 | using namespace llvm; |
22 | |
23 | namespace { |
24 | class DXILPrettyPrinter : public llvm::ModulePass { |
25 | raw_ostream &OS; // raw_ostream to print to. |
26 | |
27 | public: |
28 | static char ID; |
29 | DXILPrettyPrinter() : ModulePass(ID), OS(dbgs()) { |
30 | initializeDXILPrettyPrinterPass(*PassRegistry::getPassRegistry()); |
31 | } |
32 | |
33 | explicit DXILPrettyPrinter(raw_ostream &O) : ModulePass(ID), OS(O) { |
34 | initializeDXILPrettyPrinterPass(*PassRegistry::getPassRegistry()); |
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(); |
44 | AU.addRequired<DXILResourceWrapper>(); |
45 | } |
46 | }; |
47 | } // namespace |
48 | |
49 | char DXILPrettyPrinter::ID = 0; |
50 | INITIALIZE_PASS_BEGIN(DXILPrettyPrinter, "dxil-pretty-printer" , |
51 | "DXIL Metadata Pretty Printer" , true, true) |
52 | INITIALIZE_PASS_DEPENDENCY(DXILResourceWrapper) |
53 | INITIALIZE_PASS_END(DXILPrettyPrinter, "dxil-pretty-printer" , |
54 | "DXIL Metadata Pretty Printer" , true, true) |
55 | |
56 | bool DXILPrettyPrinter::runOnModule(Module &M) { |
57 | dxil::Resources &Res = getAnalysis<DXILResourceWrapper>().getDXILResource(); |
58 | Res.print(O&: OS); |
59 | return false; |
60 | } |
61 | |
62 | ModulePass *llvm::createDXILPrettyPrinterPass(raw_ostream &OS) { |
63 | return new DXILPrettyPrinter(OS); |
64 | } |
65 | |