1//===- IRPrintingPasses.h - Passes to print out IR constructs ---*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9/// \file
10///
11/// This file defines passes to print out IR in various granularities. The
12/// PrintModulePass pass simply prints out the entire module when it is
13/// executed. The PrintFunctionPass class is designed to be pipelined with
14/// other FunctionPass's, and prints out the functions of the module as they
15/// are processed.
16///
17//===----------------------------------------------------------------------===//
18
19#ifndef LLVM_IR_IR_PRINTING_PASSES_H
20#define LLVM_IR_IR_PRINTING_PASSES_H
21
22#include "llvm/ADT/StringRef.h"
23#include <string>
24
25namespace llvm {
26class BasicBlockPass;
27class Function;
28class FunctionPass;
29class Module;
30class ModulePass;
31class PreservedAnalyses;
32class raw_ostream;
33
34/// \brief Create and return a pass that writes the module to the specified
35/// \c raw_ostream.
36ModulePass *createPrintModulePass(raw_ostream &OS,
37                                  const std::string &Banner = "");
38
39/// \brief Create and return a pass that prints functions to the specified
40/// \c raw_ostream as they are processed.
41FunctionPass *createPrintFunctionPass(raw_ostream &OS,
42                                      const std::string &Banner = "");
43
44/// \brief Create and return a pass that writes the BB to the specified
45/// \c raw_ostream.
46BasicBlockPass *createPrintBasicBlockPass(raw_ostream &OS,
47                                          const std::string &Banner = "");
48
49/// \brief Pass for printing a Module as LLVM's text IR assembly.
50///
51/// Note: This pass is for use with the new pass manager. Use the create...Pass
52/// functions above to create passes for use with the legacy pass manager.
53class PrintModulePass {
54  raw_ostream &OS;
55  std::string Banner;
56
57public:
58  PrintModulePass();
59  PrintModulePass(raw_ostream &OS, const std::string &Banner = "");
60
61  PreservedAnalyses run(Module *M);
62
63  static StringRef name() { return "PrintModulePass"; }
64};
65
66/// \brief Pass for printing a Function as LLVM's text IR assembly.
67///
68/// Note: This pass is for use with the new pass manager. Use the create...Pass
69/// functions above to create passes for use with the legacy pass manager.
70class PrintFunctionPass {
71  raw_ostream &OS;
72  std::string Banner;
73
74public:
75  PrintFunctionPass();
76  PrintFunctionPass(raw_ostream &OS, const std::string &Banner = "");
77
78  PreservedAnalyses run(Function *F);
79
80  static StringRef name() { return "PrintFunctionPass"; }
81};
82
83} // End llvm namespace
84
85#endif
86