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
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()) {
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
49char DXILPrettyPrinter::ID = 0;
50INITIALIZE_PASS_BEGIN(DXILPrettyPrinter, "dxil-pretty-printer",
51 "DXIL Metadata Pretty Printer", true, true)
52INITIALIZE_PASS_DEPENDENCY(DXILResourceWrapper)
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(O&: OS);
59 return false;
60}
61
62ModulePass *llvm::createDXILPrettyPrinterPass(raw_ostream &OS) {
63 return new DXILPrettyPrinter(OS);
64}
65

source code of llvm/lib/Target/DirectX/DXILPrettyPrinter.cpp