[llvm-exegesis] Fix missing std::move.
[llvm-complete.git] / lib / CodeGen / MIRPrintingPass.cpp
blob1a8427430ea099e35d0cca49b16885df3d70d863
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.
13 //===----------------------------------------------------------------------===//
15 #include "llvm/CodeGen/MIRPrinter.h"
17 #include "llvm/CodeGen/MachineFunctionPass.h"
18 #include "llvm/CodeGen/Passes.h"
19 #include "llvm/Support/Debug.h"
20 #include "llvm/Support/raw_ostream.h"
22 using namespace llvm;
24 namespace {
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;
33 MIRPrintingPass() : MachineFunctionPass(ID), OS(dbgs()) {}
34 MIRPrintingPass(raw_ostream &OS) : MachineFunctionPass(ID), OS(OS) {}
36 StringRef getPassName() const override { return "MIR Printing Pass"; }
38 void getAnalysisUsage(AnalysisUsage &AU) const override {
39 AU.setPreservesAll();
40 MachineFunctionPass::getAnalysisUsage(AU);
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;
51 bool doFinalization(Module &M) override {
52 printMIR(OS, M);
53 OS << MachineFunctions;
54 return false;
58 char MIRPrintingPass::ID = 0;
60 } // end anonymous namespace
62 char &llvm::MIRPrintingPassID = MIRPrintingPass::ID;
63 INITIALIZE_PASS(MIRPrintingPass, "mir-printer", "MIR Printer", false, false)
65 namespace llvm {
67 MachineFunctionPass *createPrintMIRPass(raw_ostream &OS) {
68 return new MIRPrintingPass(OS);
71 } // end namespace llvm