blob: 09354cf70c3c1a7ed7368494eacb38ae57f31942 [file] [log] [blame]
Alex Lorenz2bdb4e12015-05-27 18:02:19 +00001//===- 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
Matthias Braun89401142017-05-05 21:09:30 +000015#include "llvm/CodeGen/MIRPrinter.h"
16
Alex Lorenz78d78312015-05-28 22:41:12 +000017#include "llvm/CodeGen/MIRYamlMapping.h"
Chandler Carruth6bda14b2017-06-06 11:49:48 +000018#include "llvm/CodeGen/MachineFunctionPass.h"
19#include "llvm/CodeGen/Passes.h"
Alex Lorenz2bdb4e12015-05-27 18:02:19 +000020#include "llvm/Support/Debug.h"
21#include "llvm/Support/raw_ostream.h"
Alex Lorenz2bdb4e12015-05-27 18:02:19 +000022
23using namespace llvm;
24
Alex Lorenz2bdb4e12015-05-27 18:02:19 +000025namespace {
26
27/// This pass prints out the LLVM IR to an output stream using the MIR
28/// serialization format.
29struct MIRPrintingPass : public MachineFunctionPass {
30 static char ID;
31 raw_ostream &OS;
Alex Lorenz78d78312015-05-28 22:41:12 +000032 std::string MachineFunctions;
Alex Lorenz2bdb4e12015-05-27 18:02:19 +000033
34 MIRPrintingPass() : MachineFunctionPass(ID), OS(dbgs()) {}
35 MIRPrintingPass(raw_ostream &OS) : MachineFunctionPass(ID), OS(OS) {}
36
Mehdi Amini117296c2016-10-01 02:56:57 +000037 StringRef getPassName() const override { return "MIR Printing Pass"; }
Alex Lorenz2bdb4e12015-05-27 18:02:19 +000038
39 void getAnalysisUsage(AnalysisUsage &AU) const override {
40 AU.setPreservesAll();
41 MachineFunctionPass::getAnalysisUsage(AU);
42 }
43
Hans Wennborgaa15bff2015-09-10 16:49:58 +000044 bool runOnMachineFunction(MachineFunction &MF) override {
Alex Lorenz78d78312015-05-28 22:41:12 +000045 std::string Str;
46 raw_string_ostream StrOS(Str);
Alex Lorenz345c1442015-06-15 23:52:35 +000047 printMIR(StrOS, MF);
Alex Lorenz78d78312015-05-28 22:41:12 +000048 MachineFunctions.append(StrOS.str());
Alex Lorenz2bdb4e12015-05-27 18:02:19 +000049 return false;
50 }
51
Hans Wennborgaa15bff2015-09-10 16:49:58 +000052 bool doFinalization(Module &M) override {
Alex Lorenz345c1442015-06-15 23:52:35 +000053 printMIR(OS, M);
Alex Lorenz78d78312015-05-28 22:41:12 +000054 OS << MachineFunctions;
Alex Lorenz2bdb4e12015-05-27 18:02:19 +000055 return false;
56 }
57};
58
59char MIRPrintingPass::ID = 0;
60
61} // end anonymous namespace
62
63char &llvm::MIRPrintingPassID = MIRPrintingPass::ID;
64INITIALIZE_PASS(MIRPrintingPass, "mir-printer", "MIR Printer", false, false)
65
66namespace llvm {
67
68MachineFunctionPass *createPrintMIRPass(raw_ostream &OS) {
69 return new MIRPrintingPass(OS);
70}
71
72} // end namespace llvm