LLVM 19.0.0git
MIRPrintingPass.cpp
Go to the documentation of this file.
1//===- MIRPrintingPass.cpp - Pass that prints out using the MIR format ----===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements a pass that prints out the LLVM module using the MIR
10// serialization format.
11//
12//===----------------------------------------------------------------------===//
13
16#include "llvm/CodeGen/Passes.h"
18
19using namespace llvm;
20
22 printMIR(OS, M);
24}
25
28 printMIR(OS, MF);
30}
31
32namespace {
33
34/// This pass prints out the LLVM IR to an output stream using the MIR
35/// serialization format.
36struct MIRPrintingPass : public MachineFunctionPass {
37 static char ID;
39 std::string MachineFunctions;
40
41 MIRPrintingPass() : MachineFunctionPass(ID), OS(dbgs()) {}
42 MIRPrintingPass(raw_ostream &OS) : MachineFunctionPass(ID), OS(OS) {}
43
44 StringRef getPassName() const override { return "MIR Printing Pass"; }
45
46 void getAnalysisUsage(AnalysisUsage &AU) const override {
47 AU.setPreservesAll();
49 }
50
51 bool runOnMachineFunction(MachineFunction &MF) override {
52 std::string Str;
53 raw_string_ostream StrOS(Str);
54 printMIR(StrOS, MF);
55 MachineFunctions.append(StrOS.str());
56 return false;
57 }
58
59 bool doFinalization(Module &M) override {
60 printMIR(OS, M);
61 OS << MachineFunctions;
62 return false;
63 }
64};
65
66char MIRPrintingPass::ID = 0;
67
68} // end anonymous namespace
69
70char &llvm::MIRPrintingPassID = MIRPrintingPass::ID;
71INITIALIZE_PASS(MIRPrintingPass, "mir-printer", "MIR Printer", false, false)
72
73namespace llvm {
74
76 return new MIRPrintingPass(OS);
77}
78
79} // end namespace llvm
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:38
raw_pwrite_stream & OS
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:242
Represent the analysis usage information of a pass.
void setPreservesAll()
Set by analyses that do not transform their input at all.
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.
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:109
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: Analysis.h:115
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MFAM)
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:661
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
MachineFunctionPass * createPrintMIRPass(raw_ostream &OS)
MIRPrinting pass - this pass prints out the LLVM IR into the given stream using the MIR serialization...
void printMIR(raw_ostream &OS, const Module &M)
Print LLVM IR using the MIR serialization format to the given output stream.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
char & MIRPrintingPassID
MIRPrintingPass - this pass prints out the LLVM IR using the MIR serialization format.