1 //===- DXILPrettyPrinter.cpp - DXIL Resource helper objects ---------------===//
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
7 //===----------------------------------------------------------------------===//
9 /// \file This file contains a pass for pretty printing DXIL metadata into IR
10 /// comments when printing assembly output.
12 //===----------------------------------------------------------------------===//
14 #include "DXILResourceAnalysis.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"
24 class DXILPrettyPrinter
: public llvm::ModulePass
{
25 raw_ostream
&OS
; // raw_ostream to print to.
29 DXILPrettyPrinter() : ModulePass(ID
), OS(dbgs()) {
30 initializeDXILPrettyPrinterPass(*PassRegistry::getPassRegistry());
33 explicit DXILPrettyPrinter(raw_ostream
&O
) : ModulePass(ID
), OS(O
) {
34 initializeDXILPrettyPrinterPass(*PassRegistry::getPassRegistry());
37 StringRef
getPassName() const override
{
38 return "DXIL Metadata Pretty Printer";
41 bool runOnModule(Module
&M
) override
;
42 void getAnalysisUsage(AnalysisUsage
&AU
) const override
{
44 AU
.addRequired
<DXILResourceWrapper
>();
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)
56 bool DXILPrettyPrinter::runOnModule(Module
&M
) {
57 dxil::Resources
&Res
= getAnalysis
<DXILResourceWrapper
>().getDXILResource();
62 ModulePass
*llvm::createDXILPrettyPrinterPass(raw_ostream
&OS
) {
63 return new DXILPrettyPrinter(OS
);