xref: /llvm-project/llvm/include/llvm/CodeGen/MIRPrinter.h (revision fe6366928201b7500ee7e903c01bf4bbd661ee2d)
1 //===- MIRPrinter.h - MIR serialization format printer ----------*- C++ -*-===//
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 declares the functions that print out the LLVM IR and the machine
10 // functions using the MIR serialization format.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CODEGEN_MIRPRINTER_H
15 #define LLVM_CODEGEN_MIRPRINTER_H
16 
17 #include "llvm/CodeGen/MachinePassManager.h"
18 #include "llvm/Support/raw_ostream.h"
19 
20 namespace llvm {
21 
22 class MachineBasicBlock;
23 class MachineFunction;
24 class MachineModuleInfo;
25 class Module;
26 template <typename T> class SmallVectorImpl;
27 
28 class PrintMIRPreparePass : public PassInfoMixin<PrintMIRPreparePass> {
29   raw_ostream &OS;
30 
31 public:
32   PrintMIRPreparePass(raw_ostream &OS = errs()) : OS(OS) {}
33   PreservedAnalyses run(Module &M, ModuleAnalysisManager &MFAM);
34   static bool isRequired() { return true; }
35 };
36 
37 class PrintMIRPass : public PassInfoMixin<PrintMIRPass> {
38   raw_ostream &OS;
39 
40 public:
41   PrintMIRPass(raw_ostream &OS = errs()) : OS(OS) {}
42   PreservedAnalyses run(MachineFunction &MF,
43                         MachineFunctionAnalysisManager &MFAM);
44   static bool isRequired() { return true; }
45 };
46 
47 /// Print LLVM IR using the MIR serialization format to the given output stream.
48 void printMIR(raw_ostream &OS, const Module &M);
49 
50 /// Print a machine function using the MIR serialization format to the given
51 /// output stream.
52 void printMIR(raw_ostream &OS, const MachineModuleInfo &MMI,
53               const MachineFunction &MF);
54 
55 /// Determine a possible list of successors of a basic block based on the
56 /// basic block machine operand being used inside the block. This should give
57 /// you the correct list of successor blocks in most cases except for things
58 /// like jump tables where the basic block references can't easily be found.
59 /// The MIRPRinter will skip printing successors if they match the result of
60 /// this function and the parser will use this function to construct a list if
61 /// it is missing.
62 void guessSuccessors(const MachineBasicBlock &MBB,
63                      SmallVectorImpl<MachineBasicBlock*> &Result,
64                      bool &IsFallthrough);
65 
66 } // end namespace llvm
67 
68 #endif
69