xref: /aosp_15_r20/external/llvm/lib/CodeGen/MIRPrintingPass.cpp (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker //===- MIRPrintingPass.cpp - Pass that prints out using the MIR format ----===//
2*9880d681SAndroid Build Coastguard Worker //
3*9880d681SAndroid Build Coastguard Worker //                     The LLVM Compiler Infrastructure
4*9880d681SAndroid Build Coastguard Worker //
5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source
6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details.
7*9880d681SAndroid Build Coastguard Worker //
8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*9880d681SAndroid Build Coastguard Worker //
10*9880d681SAndroid Build Coastguard Worker // This file implements a pass that prints out the LLVM module using the MIR
11*9880d681SAndroid Build Coastguard Worker // serialization format.
12*9880d681SAndroid Build Coastguard Worker //
13*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
14*9880d681SAndroid Build Coastguard Worker 
15*9880d681SAndroid Build Coastguard Worker #include "MIRPrinter.h"
16*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/Passes.h"
17*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/MachineFunctionPass.h"
18*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/MIRYamlMapping.h"
19*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/Debug.h"
20*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/raw_ostream.h"
21*9880d681SAndroid Build Coastguard Worker 
22*9880d681SAndroid Build Coastguard Worker using namespace llvm;
23*9880d681SAndroid Build Coastguard Worker 
24*9880d681SAndroid Build Coastguard Worker namespace {
25*9880d681SAndroid Build Coastguard Worker 
26*9880d681SAndroid Build Coastguard Worker /// This pass prints out the LLVM IR to an output stream using the MIR
27*9880d681SAndroid Build Coastguard Worker /// serialization format.
28*9880d681SAndroid Build Coastguard Worker struct MIRPrintingPass : public MachineFunctionPass {
29*9880d681SAndroid Build Coastguard Worker   static char ID;
30*9880d681SAndroid Build Coastguard Worker   raw_ostream &OS;
31*9880d681SAndroid Build Coastguard Worker   std::string MachineFunctions;
32*9880d681SAndroid Build Coastguard Worker 
MIRPrintingPass__anon9ad07a560111::MIRPrintingPass33*9880d681SAndroid Build Coastguard Worker   MIRPrintingPass() : MachineFunctionPass(ID), OS(dbgs()) {}
MIRPrintingPass__anon9ad07a560111::MIRPrintingPass34*9880d681SAndroid Build Coastguard Worker   MIRPrintingPass(raw_ostream &OS) : MachineFunctionPass(ID), OS(OS) {}
35*9880d681SAndroid Build Coastguard Worker 
getPassName__anon9ad07a560111::MIRPrintingPass36*9880d681SAndroid Build Coastguard Worker   const char *getPassName() const override { return "MIR Printing Pass"; }
37*9880d681SAndroid Build Coastguard Worker 
getAnalysisUsage__anon9ad07a560111::MIRPrintingPass38*9880d681SAndroid Build Coastguard Worker   void getAnalysisUsage(AnalysisUsage &AU) const override {
39*9880d681SAndroid Build Coastguard Worker     AU.setPreservesAll();
40*9880d681SAndroid Build Coastguard Worker     MachineFunctionPass::getAnalysisUsage(AU);
41*9880d681SAndroid Build Coastguard Worker   }
42*9880d681SAndroid Build Coastguard Worker 
runOnMachineFunction__anon9ad07a560111::MIRPrintingPass43*9880d681SAndroid Build Coastguard Worker   bool runOnMachineFunction(MachineFunction &MF) override {
44*9880d681SAndroid Build Coastguard Worker     std::string Str;
45*9880d681SAndroid Build Coastguard Worker     raw_string_ostream StrOS(Str);
46*9880d681SAndroid Build Coastguard Worker     printMIR(StrOS, MF);
47*9880d681SAndroid Build Coastguard Worker     MachineFunctions.append(StrOS.str());
48*9880d681SAndroid Build Coastguard Worker     return false;
49*9880d681SAndroid Build Coastguard Worker   }
50*9880d681SAndroid Build Coastguard Worker 
doFinalization__anon9ad07a560111::MIRPrintingPass51*9880d681SAndroid Build Coastguard Worker   bool doFinalization(Module &M) override {
52*9880d681SAndroid Build Coastguard Worker     printMIR(OS, M);
53*9880d681SAndroid Build Coastguard Worker     OS << MachineFunctions;
54*9880d681SAndroid Build Coastguard Worker     return false;
55*9880d681SAndroid Build Coastguard Worker   }
56*9880d681SAndroid Build Coastguard Worker };
57*9880d681SAndroid Build Coastguard Worker 
58*9880d681SAndroid Build Coastguard Worker char MIRPrintingPass::ID = 0;
59*9880d681SAndroid Build Coastguard Worker 
60*9880d681SAndroid Build Coastguard Worker } // end anonymous namespace
61*9880d681SAndroid Build Coastguard Worker 
62*9880d681SAndroid Build Coastguard Worker char &llvm::MIRPrintingPassID = MIRPrintingPass::ID;
63*9880d681SAndroid Build Coastguard Worker INITIALIZE_PASS(MIRPrintingPass, "mir-printer", "MIR Printer", false, false)
64*9880d681SAndroid Build Coastguard Worker 
65*9880d681SAndroid Build Coastguard Worker namespace llvm {
66*9880d681SAndroid Build Coastguard Worker 
createPrintMIRPass(raw_ostream & OS)67*9880d681SAndroid Build Coastguard Worker MachineFunctionPass *createPrintMIRPass(raw_ostream &OS) {
68*9880d681SAndroid Build Coastguard Worker   return new MIRPrintingPass(OS);
69*9880d681SAndroid Build Coastguard Worker }
70*9880d681SAndroid Build Coastguard Worker 
71*9880d681SAndroid Build Coastguard Worker } // end namespace llvm
72