]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/llvm/include/llvm/IR/IRPrintingPasses.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm-project / llvm / include / llvm / IR / IRPrintingPasses.h
1 //===- IRPrintingPasses.h - Passes to print out IR constructs ---*- 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 /// \file
9 ///
10 /// This file defines passes to print out IR in various granularities. The
11 /// PrintModulePass pass simply prints out the entire module when it is
12 /// executed. The PrintFunctionPass class is designed to be pipelined with
13 /// other FunctionPass's, and prints out the functions of the module as they
14 /// are processed.
15 ///
16 //===----------------------------------------------------------------------===//
17
18 #ifndef LLVM_IR_IRPRINTINGPASSES_H
19 #define LLVM_IR_IRPRINTINGPASSES_H
20
21 #include "llvm/ADT/StringRef.h"
22 #include <string>
23
24 namespace llvm {
25 class Pass;
26 class Function;
27 class FunctionPass;
28 class Module;
29 class ModulePass;
30 class PreservedAnalyses;
31 class raw_ostream;
32 template <typename IRUnitT, typename... ExtraArgTs> class AnalysisManager;
33
34 /// Create and return a pass that writes the module to the specified
35 /// \c raw_ostream.
36 ModulePass *createPrintModulePass(raw_ostream &OS,
37                                   const std::string &Banner = "",
38                                   bool ShouldPreserveUseListOrder = false);
39
40 /// Create and return a pass that prints functions to the specified
41 /// \c raw_ostream as they are processed.
42 FunctionPass *createPrintFunctionPass(raw_ostream &OS,
43                                       const std::string &Banner = "");
44
45 /// Print out a name of an LLVM value without any prefixes.
46 ///
47 /// The name is surrounded with ""'s and escaped if it has any special or
48 /// non-printable characters in it.
49 void printLLVMNameWithoutPrefix(raw_ostream &OS, StringRef Name);
50
51 /// Return true if a pass is for IR printing.
52 bool isIRPrintingPass(Pass *P);
53
54 /// isFunctionInPrintList - returns true if a function should be printed via
55 //  debugging options like -print-after-all/-print-before-all.
56 //  Tells if the function IR should be printed by PrinterPass.
57 extern bool isFunctionInPrintList(StringRef FunctionName);
58
59 /// forcePrintModuleIR - returns true if IR printing passes should
60 //  be printing module IR (even for local-pass printers e.g. function-pass)
61 //  to provide more context, as enabled by debugging option -print-module-scope
62 //  Tells if IR printer should be printing module IR
63 extern bool forcePrintModuleIR();
64
65 extern bool shouldPrintBeforePass();
66 extern bool shouldPrintBeforePass(StringRef);
67 extern bool shouldPrintAfterPass();
68 extern bool shouldPrintAfterPass(StringRef);
69
70 /// Pass for printing a Module as LLVM's text IR assembly.
71 ///
72 /// Note: This pass is for use with the new pass manager. Use the create...Pass
73 /// functions above to create passes for use with the legacy pass manager.
74 class PrintModulePass {
75   raw_ostream &OS;
76   std::string Banner;
77   bool ShouldPreserveUseListOrder;
78
79 public:
80   PrintModulePass();
81   PrintModulePass(raw_ostream &OS, const std::string &Banner = "",
82                   bool ShouldPreserveUseListOrder = false);
83
84   PreservedAnalyses run(Module &M, AnalysisManager<Module> &);
85
86   static StringRef name() { return "PrintModulePass"; }
87 };
88
89 /// Pass for printing a Function as LLVM's text IR assembly.
90 ///
91 /// Note: This pass is for use with the new pass manager. Use the create...Pass
92 /// functions above to create passes for use with the legacy pass manager.
93 class PrintFunctionPass {
94   raw_ostream &OS;
95   std::string Banner;
96
97 public:
98   PrintFunctionPass();
99   PrintFunctionPass(raw_ostream &OS, const std::string &Banner = "");
100
101   PreservedAnalyses run(Function &F, AnalysisManager<Function> &);
102
103   static StringRef name() { return "PrintFunctionPass"; }
104 };
105
106 } // End llvm namespace
107
108 #endif