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