xref: /openbsd-src/gnu/llvm/llvm/lib/Target/DirectX/DXILPrettyPrinter.cpp (revision d415bd752c734aee168c4ee86ff32e8cc249eb16)
1*d415bd75Srobert //===- DXILPrettyPrinter.cpp - DXIL Resource helper objects ---------------===//
2*d415bd75Srobert //
3*d415bd75Srobert // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*d415bd75Srobert // See https://llvm.org/LICENSE.txt for license information.
5*d415bd75Srobert // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*d415bd75Srobert //
7*d415bd75Srobert //===----------------------------------------------------------------------===//
8*d415bd75Srobert ///
9*d415bd75Srobert /// \file This file contains a pass for pretty printing DXIL metadata into IR
10*d415bd75Srobert /// comments when printing assembly output.
11*d415bd75Srobert ///
12*d415bd75Srobert //===----------------------------------------------------------------------===//
13*d415bd75Srobert 
14*d415bd75Srobert #include "DXILResourceAnalysis.h"
15*d415bd75Srobert #include "DirectX.h"
16*d415bd75Srobert #include "llvm/ADT/StringRef.h"
17*d415bd75Srobert #include "llvm/IR/PassManager.h"
18*d415bd75Srobert #include "llvm/Pass.h"
19*d415bd75Srobert #include "llvm/Support/raw_ostream.h"
20*d415bd75Srobert 
21*d415bd75Srobert using namespace llvm;
22*d415bd75Srobert 
23*d415bd75Srobert namespace {
24*d415bd75Srobert class DXILPrettyPrinter : public llvm::ModulePass {
25*d415bd75Srobert   raw_ostream &OS; // raw_ostream to print to.
26*d415bd75Srobert 
27*d415bd75Srobert public:
28*d415bd75Srobert   static char ID;
DXILPrettyPrinter()29*d415bd75Srobert   DXILPrettyPrinter() : ModulePass(ID), OS(dbgs()) {
30*d415bd75Srobert     initializeDXILPrettyPrinterPass(*PassRegistry::getPassRegistry());
31*d415bd75Srobert   }
32*d415bd75Srobert 
DXILPrettyPrinter(raw_ostream & O)33*d415bd75Srobert   explicit DXILPrettyPrinter(raw_ostream &O) : ModulePass(ID), OS(O) {
34*d415bd75Srobert     initializeDXILPrettyPrinterPass(*PassRegistry::getPassRegistry());
35*d415bd75Srobert   }
36*d415bd75Srobert 
getPassName() const37*d415bd75Srobert   StringRef getPassName() const override {
38*d415bd75Srobert     return "DXIL Metadata Pretty Printer";
39*d415bd75Srobert   }
40*d415bd75Srobert 
41*d415bd75Srobert   bool runOnModule(Module &M) override;
getAnalysisUsage(AnalysisUsage & AU) const42*d415bd75Srobert   void getAnalysisUsage(AnalysisUsage &AU) const override {
43*d415bd75Srobert     AU.setPreservesAll();
44*d415bd75Srobert     AU.addRequired<DXILResourceWrapper>();
45*d415bd75Srobert   }
46*d415bd75Srobert };
47*d415bd75Srobert } // namespace
48*d415bd75Srobert 
49*d415bd75Srobert char DXILPrettyPrinter::ID = 0;
50*d415bd75Srobert INITIALIZE_PASS_BEGIN(DXILPrettyPrinter, "dxil-pretty-printer",
51*d415bd75Srobert                       "DXIL Metadata Pretty Printer", true, true)
INITIALIZE_PASS_DEPENDENCY(DXILResourceWrapper)52*d415bd75Srobert INITIALIZE_PASS_DEPENDENCY(DXILResourceWrapper)
53*d415bd75Srobert INITIALIZE_PASS_END(DXILPrettyPrinter, "dxil-pretty-printer",
54*d415bd75Srobert                     "DXIL Metadata Pretty Printer", true, true)
55*d415bd75Srobert 
56*d415bd75Srobert bool DXILPrettyPrinter::runOnModule(Module &M) {
57*d415bd75Srobert   dxil::Resources &Res = getAnalysis<DXILResourceWrapper>().getDXILResource();
58*d415bd75Srobert   Res.print(OS);
59*d415bd75Srobert   return false;
60*d415bd75Srobert }
61*d415bd75Srobert 
createDXILPrettyPrinterPass(raw_ostream & OS)62*d415bd75Srobert ModulePass *llvm::createDXILPrettyPrinterPass(raw_ostream &OS) {
63*d415bd75Srobert   return new DXILPrettyPrinter(OS);
64*d415bd75Srobert }
65