]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm/IR/IRPrintingPasses.h
Merge clang 7.0.1 and several follow-up changes
[FreeBSD/FreeBSD.git] / contrib / llvm / include / llvm / IR / IRPrintingPasses.h
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_IRPRINTINGPASSES_H
20 #define LLVM_IR_IRPRINTINGPASSES_H
21
22 #include "llvm/ADT/StringRef.h"
23 #include <string>
24
25 namespace llvm {
26 class Pass;
27 class BasicBlockPass;
28 class Function;
29 class FunctionPass;
30 class Module;
31 class ModulePass;
32 class PreservedAnalyses;
33 class raw_ostream;
34 template <typename IRUnitT, typename... ExtraArgTs> class AnalysisManager;
35
36 /// Create and return a pass that writes the module to the specified
37 /// \c raw_ostream.
38 ModulePass *createPrintModulePass(raw_ostream &OS,
39                                   const std::string &Banner = "",
40                                   bool ShouldPreserveUseListOrder = false);
41
42 /// Create and return a pass that prints functions to the specified
43 /// \c raw_ostream as they are processed.
44 FunctionPass *createPrintFunctionPass(raw_ostream &OS,
45                                       const std::string &Banner = "");
46
47 /// Create and return a pass that writes the BB to the specified
48 /// \c raw_ostream.
49 BasicBlockPass *createPrintBasicBlockPass(raw_ostream &OS,
50                                           const std::string &Banner = "");
51
52 /// Print out a name of an LLVM value without any prefixes.
53 ///
54 /// The name is surrounded with ""'s and escaped if it has any special or
55 /// non-printable characters in it.
56 void printLLVMNameWithoutPrefix(raw_ostream &OS, StringRef Name);
57
58 /// Return true if a pass is for IR printing.
59 bool isIRPrintingPass(Pass *P);
60
61 /// Pass for printing a Module as LLVM's text IR assembly.
62 ///
63 /// Note: This pass is for use with the new pass manager. Use the create...Pass
64 /// functions above to create passes for use with the legacy pass manager.
65 class PrintModulePass {
66   raw_ostream &OS;
67   std::string Banner;
68   bool ShouldPreserveUseListOrder;
69
70 public:
71   PrintModulePass();
72   PrintModulePass(raw_ostream &OS, const std::string &Banner = "",
73                   bool ShouldPreserveUseListOrder = false);
74
75   PreservedAnalyses run(Module &M, AnalysisManager<Module> &);
76
77   static StringRef name() { return "PrintModulePass"; }
78 };
79
80 /// Pass for printing a Function as LLVM's text IR assembly.
81 ///
82 /// Note: This pass is for use with the new pass manager. Use the create...Pass
83 /// functions above to create passes for use with the legacy pass manager.
84 class PrintFunctionPass {
85   raw_ostream &OS;
86   std::string Banner;
87
88 public:
89   PrintFunctionPass();
90   PrintFunctionPass(raw_ostream &OS, const std::string &Banner = "");
91
92   PreservedAnalyses run(Function &F, AnalysisManager<Function> &);
93
94   static StringRef name() { return "PrintFunctionPass"; }
95 };
96
97 } // End llvm namespace
98
99 #endif