LLVM  8.0.1
MIRPrintingPass.cpp
Go to the documentation of this file.
1 //===- MIRPrintingPass.cpp - Pass that prints out using the MIR format ----===//
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 // This file implements a pass that prints out the LLVM module using the MIR
11 // serialization format.
12 //
13 //===----------------------------------------------------------------------===//
14 
16 
18 #include "llvm/CodeGen/Passes.h"
19 #include "llvm/Support/Debug.h"
21 
22 using namespace llvm;
23 
24 namespace {
25 
26 /// This pass prints out the LLVM IR to an output stream using the MIR
27 /// serialization format.
28 struct MIRPrintingPass : public MachineFunctionPass {
29  static char ID;
30  raw_ostream &OS;
31  std::string MachineFunctions;
32 
33  MIRPrintingPass() : MachineFunctionPass(ID), OS(dbgs()) {}
34  MIRPrintingPass(raw_ostream &OS) : MachineFunctionPass(ID), OS(OS) {}
35 
36  StringRef getPassName() const override { return "MIR Printing Pass"; }
37 
38  void getAnalysisUsage(AnalysisUsage &AU) const override {
39  AU.setPreservesAll();
41  }
42 
43  bool runOnMachineFunction(MachineFunction &MF) override {
44  std::string Str;
45  raw_string_ostream StrOS(Str);
46  printMIR(StrOS, MF);
47  MachineFunctions.append(StrOS.str());
48  return false;
49  }
50 
51  bool doFinalization(Module &M) override {
52  printMIR(OS, M);
53  OS << MachineFunctions;
54  return false;
55  }
56 };
57 
58 char MIRPrintingPass::ID = 0;
59 
60 } // end anonymous namespace
61 
63 INITIALIZE_PASS(MIRPrintingPass, "mir-printer", "MIR Printer", false, false)
64 
65 namespace llvm {
66 
68  return new MIRPrintingPass(OS);
69 }
70 
71 } // end namespace llvm
This class represents lattice values for constants.
Definition: AllocatorList.h:24
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:65
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Represent the analysis usage information of a pass.
char & MIRPrintingPassID
MIRPrintingPass - this pass prints out the LLVM IR using the MIR serialization format.
void printMIR(raw_ostream &OS, const Module &M)
Print LLVM IR using the MIR serialization format to the given output stream.
Definition: MIRPrinter.cpp:821
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:34
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:133
void setPreservesAll()
Set by analyses that do not transform their input at all.
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:483
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
MachineFunctionPass * createPrintMIRPass(raw_ostream &OS)
MIRPrinting pass - this pass prints out the LLVM IR into the given stream using the MIR serialization...