Path: blob/main/contrib/llvm-project/llvm/lib/Target/DirectX/DXILPrettyPrinter.cpp
35266 views
//===- DXILPrettyPrinter.cpp - DXIL Resource helper objects ---------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7///8/// \file This file contains a pass for pretty printing DXIL metadata into IR9/// comments when printing assembly output.10///11//===----------------------------------------------------------------------===//1213#include "DXILResourceAnalysis.h"14#include "DirectX.h"15#include "llvm/ADT/StringRef.h"16#include "llvm/IR/PassManager.h"17#include "llvm/Pass.h"18#include "llvm/Support/raw_ostream.h"1920using namespace llvm;2122namespace {23class DXILPrettyPrinter : public llvm::ModulePass {24raw_ostream &OS; // raw_ostream to print to.2526public:27static char ID;28DXILPrettyPrinter() : ModulePass(ID), OS(dbgs()) {29initializeDXILPrettyPrinterPass(*PassRegistry::getPassRegistry());30}3132explicit DXILPrettyPrinter(raw_ostream &O) : ModulePass(ID), OS(O) {33initializeDXILPrettyPrinterPass(*PassRegistry::getPassRegistry());34}3536StringRef getPassName() const override {37return "DXIL Metadata Pretty Printer";38}3940bool runOnModule(Module &M) override;41void getAnalysisUsage(AnalysisUsage &AU) const override {42AU.setPreservesAll();43AU.addRequired<DXILResourceWrapper>();44}45};46} // namespace4748char DXILPrettyPrinter::ID = 0;49INITIALIZE_PASS_BEGIN(DXILPrettyPrinter, "dxil-pretty-printer",50"DXIL Metadata Pretty Printer", true, true)51INITIALIZE_PASS_DEPENDENCY(DXILResourceWrapper)52INITIALIZE_PASS_END(DXILPrettyPrinter, "dxil-pretty-printer",53"DXIL Metadata Pretty Printer", true, true)5455bool DXILPrettyPrinter::runOnModule(Module &M) {56dxil::Resources &Res = getAnalysis<DXILResourceWrapper>().getDXILResource();57Res.print(OS);58return false;59}6061ModulePass *llvm::createDXILPrettyPrinterPass(raw_ostream &OS) {62return new DXILPrettyPrinter(OS);63}646566