LLVM  10.0.0svn
IRPrintingPasses.h
Go to the documentation of this file.
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 BasicBlockPass;
27 class Function;
28 class FunctionPass;
29 class Module;
30 class ModulePass;
31 class PreservedAnalyses;
32 class raw_ostream;
33 template <typename IRUnitT, typename... ExtraArgTs> class AnalysisManager;
34 
35 /// Create and return a pass that writes the module to the specified
36 /// \c raw_ostream.
37 ModulePass *createPrintModulePass(raw_ostream &OS,
38  const std::string &Banner = "",
39  bool ShouldPreserveUseListOrder = false);
40 
41 /// Create and return a pass that prints functions to the specified
42 /// \c raw_ostream as they are processed.
43 FunctionPass *createPrintFunctionPass(raw_ostream &OS,
44  const std::string &Banner = "");
45 
46 /// Create and return a pass that writes the BB to the specified
47 /// \c raw_ostream.
48 BasicBlockPass *createPrintBasicBlockPass(raw_ostream &OS,
49  const std::string &Banner = "");
50 
51 /// Print out a name of an LLVM value without any prefixes.
52 ///
53 /// The name is surrounded with ""'s and escaped if it has any special or
54 /// non-printable characters in it.
55 void printLLVMNameWithoutPrefix(raw_ostream &OS, StringRef Name);
56 
57 /// Return true if a pass is for IR printing.
58 bool isIRPrintingPass(Pass *P);
59 
60 /// isFunctionInPrintList - returns true if a function should be printed via
61 // debugging options like -print-after-all/-print-before-all.
62 // Tells if the function IR should be printed by PrinterPass.
63 extern bool isFunctionInPrintList(StringRef FunctionName);
64 
65 /// forcePrintModuleIR - returns true if IR printing passes should
66 // be printing module IR (even for local-pass printers e.g. function-pass)
67 // to provide more context, as enabled by debugging option -print-module-scope
68 // Tells if IR printer should be printing module IR
69 extern bool forcePrintModuleIR();
70 
71 extern bool shouldPrintBeforePass();
72 extern bool shouldPrintBeforePass(StringRef);
73 extern bool shouldPrintAfterPass();
74 extern bool shouldPrintAfterPass(StringRef);
75 
76 /// Pass for printing a Module as LLVM's text IR assembly.
77 ///
78 /// Note: This pass is for use with the new pass manager. Use the create...Pass
79 /// functions above to create passes for use with the legacy pass manager.
81  raw_ostream &OS;
82  std::string Banner;
83  bool ShouldPreserveUseListOrder;
84 
85 public:
87  PrintModulePass(raw_ostream &OS, const std::string &Banner = "",
88  bool ShouldPreserveUseListOrder = false);
89 
91 
92  static StringRef name() { return "PrintModulePass"; }
93 };
94 
95 /// Pass for printing a Function as LLVM's text IR assembly.
96 ///
97 /// Note: This pass is for use with the new pass manager. Use the create...Pass
98 /// functions above to create passes for use with the legacy pass manager.
100  raw_ostream &OS;
101  std::string Banner;
102 
103 public:
105  PrintFunctionPass(raw_ostream &OS, const std::string &Banner = "");
106 
108 
109  static StringRef name() { return "PrintFunctionPass"; }
110 };
111 
112 } // End llvm namespace
113 
114 #endif
bool shouldPrintAfterPass()
bool forcePrintModuleIR()
forcePrintModuleIR - returns true if IR printing passes should
This class represents lattice values for constants.
Definition: AllocatorList.h:23
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:66
Pass for printing a Module as LLVM&#39;s text IR assembly.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
bool shouldPrintBeforePass()
This is a helper to determine whether to print IR before or after a pass.
FunctionPass * createPrintFunctionPass(raw_ostream &OS, const std::string &Banner="")
Create and return a pass that prints functions to the specified raw_ostream as they are processed...
static StringRef name()
F(f)
bool isIRPrintingPass(Pass *P)
Return true if a pass is for IR printing.
static StringRef name()
#define P(N)
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:154
print lazy value Lazy Value Info Printer Pass
void printLLVMNameWithoutPrefix(raw_ostream &OS, StringRef Name)
Print out a name of an LLVM value without any prefixes.
Definition: AsmWriter.cpp:398
BasicBlockPass * createPrintBasicBlockPass(raw_ostream &OS, const std::string &Banner="")
Create and return a pass that writes the BB to the specified raw_ostream.
bool isFunctionInPrintList(StringRef FunctionName)
isFunctionInPrintList - returns true if a function should be printed via
PreservedAnalyses run(Module &M, AnalysisManager< Module > &)
ModulePass * createPrintModulePass(raw_ostream &OS, const std::string &Banner="", bool ShouldPreserveUseListOrder=false)
Create and return a pass that writes the module to the specified raw_ostream.
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
A container for analyses that lazily runs them and caches their results.
Pass for printing a Function as LLVM&#39;s text IR assembly.