1 //===-- MachineFunctionPrinterPass.cpp ------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // MachineFunctionPrinterPass implementation.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/CodeGen/Passes.h"
15 #include "llvm/CodeGen/MachineFunction.h"
16 #include "llvm/CodeGen/MachineFunctionPass.h"
17 #include "llvm/CodeGen/SlotIndexes.h"
18 #include "llvm/Support/Debug.h"
19 #include "llvm/Support/raw_ostream.h"
24 /// MachineFunctionPrinterPass - This is a pass to dump the IR of a
27 struct MachineFunctionPrinterPass : public MachineFunctionPass {
31 const std::string Banner;
33 MachineFunctionPrinterPass() : MachineFunctionPass(ID), OS(dbgs()) { }
34 MachineFunctionPrinterPass(raw_ostream &os, const std::string &banner)
35 : MachineFunctionPass(ID), OS(os), Banner(banner) {}
37 const char *getPassName() const override { return "MachineFunction Printer"; }
39 void getAnalysisUsage(AnalysisUsage &AU) const override {
41 MachineFunctionPass::getAnalysisUsage(AU);
44 bool runOnMachineFunction(MachineFunction &MF) override {
45 OS << "# " << Banner << ":\n";
46 MF.print(OS, getAnalysisIfAvailable<SlotIndexes>());
51 char MachineFunctionPrinterPass::ID = 0;
54 char &llvm::MachineFunctionPrinterPassID = MachineFunctionPrinterPass::ID;
55 INITIALIZE_PASS(MachineFunctionPrinterPass, "machineinstr-printer",
56 "Machine Function Printer", false, false)
59 /// Returns a newly-created MachineFunction Printer pass. The
60 /// default banner is empty.
62 MachineFunctionPass *createMachineFunctionPrinterPass(raw_ostream &OS,
63 const std::string &Banner){
64 return new MachineFunctionPrinterPass(OS, Banner);