blob: fa9c821b2af79e1e3a0157504f2c2d6afb9e9b0b [file] [log] [blame]
David Greene5c8aa952010-04-02 23:17:14 +00001//===-- MachineFunctionPrinterPass.cpp ------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// MachineFunctionPrinterPass implementation.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/CodeGen/Passes.h"
David Greene5c8aa952010-04-02 23:17:14 +000015#include "llvm/CodeGen/MachineFunction.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000016#include "llvm/CodeGen/MachineFunctionPass.h"
Jakob Stoklund Olesen9389ec72012-07-04 23:53:19 +000017#include "llvm/CodeGen/SlotIndexes.h"
Bob Wilson6e1b8122012-05-30 00:17:12 +000018#include "llvm/Support/Debug.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000019#include "llvm/Support/raw_ostream.h"
David Greene5c8aa952010-04-02 23:17:14 +000020
21using namespace llvm;
22
23namespace {
24/// MachineFunctionPrinterPass - This is a pass to dump the IR of a
25/// MachineFunction.
26///
27struct MachineFunctionPrinterPass : public MachineFunctionPass {
28 static char ID;
29
30 raw_ostream &OS;
31 const std::string Banner;
32
Bob Wilson6e1b8122012-05-30 00:17:12 +000033 MachineFunctionPrinterPass() : MachineFunctionPass(ID), OS(dbgs()) { }
David Greene5c8aa952010-04-02 23:17:14 +000034 MachineFunctionPrinterPass(raw_ostream &os, const std::string &banner)
Owen Anderson90c579d2010-08-06 18:33:48 +000035 : MachineFunctionPass(ID), OS(os), Banner(banner) {}
David Greene5c8aa952010-04-02 23:17:14 +000036
37 const char *getPassName() const { return "MachineFunction Printer"; }
38
39 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
40 AU.setPreservesAll();
41 MachineFunctionPass::getAnalysisUsage(AU);
42 }
43
44 bool runOnMachineFunction(MachineFunction &MF) {
45 OS << "# " << Banner << ":\n";
Jakob Stoklund Olesen9389ec72012-07-04 23:53:19 +000046 MF.print(OS, getAnalysisIfAvailable<SlotIndexes>());
David Greene5c8aa952010-04-02 23:17:14 +000047 return false;
48 }
49};
50
51char MachineFunctionPrinterPass::ID = 0;
52}
53
Benjamin Kramer63a4c2462012-10-20 12:53:26 +000054char &llvm::MachineFunctionPrinterPassID = MachineFunctionPrinterPass::ID;
Bob Wilson6e1b8122012-05-30 00:17:12 +000055INITIALIZE_PASS(MachineFunctionPrinterPass, "print-machineinstrs",
56 "Machine Function Printer", false, false)
57
David Greene5c8aa952010-04-02 23:17:14 +000058namespace llvm {
59/// Returns a newly-created MachineFunction Printer pass. The
60/// default banner is empty.
61///
62MachineFunctionPass *createMachineFunctionPrinterPass(raw_ostream &OS,
63 const std::string &Banner){
64 return new MachineFunctionPrinterPass(OS, Banner);
65}
66
67}