1 //===- MIRPrintingPass.cpp - Pass that prints out using the MIR format ----===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file implements a pass that prints out the LLVM module using the MIR
10 // serialization format.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/CodeGen/MIRPrinter.h"
16 #include "llvm/CodeGen/MachineFunctionPass.h"
17 #include "llvm/CodeGen/Passes.h"
18 #include "llvm/Support/Debug.h"
19 #include "llvm/Support/raw_ostream.h"
25 /// This pass prints out the LLVM IR to an output stream using the MIR
26 /// serialization format.
27 struct MIRPrintingPass
: public MachineFunctionPass
{
30 std::string MachineFunctions
;
32 MIRPrintingPass() : MachineFunctionPass(ID
), OS(dbgs()) {}
33 MIRPrintingPass(raw_ostream
&OS
) : MachineFunctionPass(ID
), OS(OS
) {}
35 StringRef
getPassName() const override
{ return "MIR Printing Pass"; }
37 void getAnalysisUsage(AnalysisUsage
&AU
) const override
{
39 MachineFunctionPass::getAnalysisUsage(AU
);
42 bool runOnMachineFunction(MachineFunction
&MF
) override
{
44 raw_string_ostream
StrOS(Str
);
46 MachineFunctions
.append(StrOS
.str());
50 bool doFinalization(Module
&M
) override
{
52 OS
<< MachineFunctions
;
57 char MIRPrintingPass::ID
= 0;
59 } // end anonymous namespace
61 char &llvm::MIRPrintingPassID
= MIRPrintingPass::ID
;
62 INITIALIZE_PASS(MIRPrintingPass
, "mir-printer", "MIR Printer", false, false)
66 MachineFunctionPass
*createPrintMIRPass(raw_ostream
&OS
) {
67 return new MIRPrintingPass(OS
);
70 } // end namespace llvm