LLVM  3.7.0
MachineFunctionPrinterPass.cpp
Go to the documentation of this file.
1 //===-- 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"
18 #include "llvm/Support/Debug.h"
20 
21 using namespace llvm;
22 
23 namespace {
24 /// MachineFunctionPrinterPass - This is a pass to dump the IR of a
25 /// MachineFunction.
26 ///
27 struct MachineFunctionPrinterPass : public MachineFunctionPass {
28  static char ID;
29 
30  raw_ostream &OS;
31  const std::string Banner;
32 
33  MachineFunctionPrinterPass() : MachineFunctionPass(ID), OS(dbgs()) { }
34  MachineFunctionPrinterPass(raw_ostream &os, const std::string &banner)
35  : MachineFunctionPass(ID), OS(os), Banner(banner) {}
36 
37  const char *getPassName() const override { return "MachineFunction Printer"; }
38 
39  void getAnalysisUsage(AnalysisUsage &AU) const override {
40  AU.setPreservesAll();
42  }
43 
44  bool runOnMachineFunction(MachineFunction &MF) override {
45  OS << "# " << Banner << ":\n";
46  MF.print(OS, getAnalysisIfAvailable<SlotIndexes>());
47  return false;
48  }
49 };
50 
52 }
53 
55 INITIALIZE_PASS(MachineFunctionPrinterPass, "machineinstr-printer",
56  "Machine Function Printer", false, false)
57 
58 namespace llvm {
59 /// Returns a newly-created MachineFunction Printer pass. The
60 /// default banner is empty.
61 ///
63  const std::string &Banner){
64  return new MachineFunctionPrinterPass(OS, Banner);
65 }
66 
67 }
char & MachineFunctionPrinterPassID
MachineFunctionPrinterPass - This pass prints out MachineInstr's.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void print(raw_ostream &OS, SlotIndexes *=nullptr) const
print - Print out the MachineFunction in a format suitable for debugging to the specified stream...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Represent the analysis usage information of a pass.
MachineFunctionPass * createMachineFunctionPrinterPass(raw_ostream &OS, const std::string &Banner="")
MachineFunctionPrinter pass - This pass prints out the machine function to the given stream as a debu...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:123
void setPreservesAll()
Set by analyses that do not transform their input at all.
INITIALIZE_PASS(MachineFunctionPrinterPass,"machineinstr-printer","Machine Function Printer", false, false) namespace llvm
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:38