LLVM  13.0.0git
PrintPasses.cpp
Go to the documentation of this file.
1 //===- PrintPasses.cpp ----------------------------------------------------===//
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 #include "llvm/IR/PrintPasses.h"
11 #include <unordered_set>
12 
13 using namespace llvm;
14 
15 // Print IR out before/after specified passes.
17  PrintBefore("print-before",
18  llvm::cl::desc("Print IR before specified passes"),
20 
22  PrintAfter("print-after", llvm::cl::desc("Print IR after specified passes"),
24 
25 static cl::opt<bool> PrintBeforeAll("print-before-all",
26  llvm::cl::desc("Print IR before each pass"),
27  cl::init(false), cl::Hidden);
28 static cl::opt<bool> PrintAfterAll("print-after-all",
29  llvm::cl::desc("Print IR after each pass"),
30  cl::init(false), cl::Hidden);
31 
32 static cl::opt<bool>
33  PrintModuleScope("print-module-scope",
34  cl::desc("When printing IR for print-[before|after]{-all} "
35  "always print a module IR"),
36  cl::init(false), cl::Hidden);
37 
39  PrintFuncsList("filter-print-funcs", cl::value_desc("function names"),
40  cl::desc("Only print IR for functions whose name "
41  "match this for all print-[before|after][-all] "
42  "options"),
44 
45 /// This is a helper to determine whether to print IR before or
46 /// after a pass.
47 
49  return PrintBeforeAll || !PrintBefore.empty();
50 }
51 
53  return PrintAfterAll || !PrintAfter.empty();
54 }
55 
57  ArrayRef<std::string> PassesToPrint) {
58  return llvm::is_contained(PassesToPrint, PassID);
59 }
60 
62 
64 
67 }
68 
71 }
72 
73 std::vector<std::string> llvm::printBeforePasses() {
74  return std::vector<std::string>(PrintBefore);
75 }
76 
77 std::vector<std::string> llvm::printAfterPasses() {
78  return std::vector<std::string>(PrintAfter);
79 }
80 
82 
84  static std::unordered_set<std::string> PrintFuncNames(PrintFuncsList.begin(),
85  PrintFuncsList.end());
86  return PrintFuncNames.empty() ||
87  PrintFuncNames.count(std::string(FunctionName));
88 }
llvm
Definition: AllocatorList.h:23
llvm::cl::CommaSeparated
@ CommaSeparated
Definition: CommandLine.h:169
llvm::cl::Hidden
@ Hidden
Definition: CommandLine.h:143
PrintAfter
static cl::list< std::string > PrintAfter("print-after", llvm::cl::desc("Print IR after specified passes"), cl::CommaSeparated, cl::Hidden)
llvm::shouldPrintBeforeAll
bool shouldPrintBeforeAll()
Definition: PrintPasses.cpp:61
llvm::shouldPrintAfterSomePass
bool shouldPrintAfterSomePass()
Definition: PrintPasses.cpp:52
CommandLine.h
PrintBefore
static cl::list< std::string > PrintBefore("print-before", llvm::cl::desc("Print IR before specified passes"), cl::CommaSeparated, cl::Hidden)
PrintModuleScope
static cl::opt< bool > PrintModuleScope("print-module-scope", cl::desc("When printing IR for print-[before|after]{-all} " "always print a module IR"), cl::init(false), cl::Hidden)
llvm::shouldPrintBeforeSomePass
bool shouldPrintBeforeSomePass()
This is a helper to determine whether to print IR before or after a pass.
Definition: PrintPasses.cpp:48
PrintPasses.h
llvm::cl::opt< bool >
llvm::shouldPrintAfterAll
bool shouldPrintAfterAll()
Definition: PrintPasses.cpp:63
PrintFuncsList
static cl::list< std::string > PrintFuncsList("filter-print-funcs", cl::value_desc("function names"), cl::desc("Only print IR for functions whose name " "match this for all print-[before|after][-all] " "options"), cl::CommaSeparated, cl::Hidden)
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:443
llvm::is_contained
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.
Definition: STLExtras.h:1547
llvm::isFunctionInPrintList
bool isFunctionInPrintList(StringRef FunctionName)
Definition: PrintPasses.cpp:83
llvm::printBeforePasses
std::vector< std::string > printBeforePasses()
Definition: PrintPasses.cpp:73
llvm::printAfterPasses
std::vector< std::string > printAfterPasses()
Definition: PrintPasses.cpp:77
llvm::ArrayRef< std::string >
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
PrintBeforeAll
static cl::opt< bool > PrintBeforeAll("print-before-all", llvm::cl::desc("Print IR before each pass"), cl::init(false), cl::Hidden)
PrintAfterAll
static cl::opt< bool > PrintAfterAll("print-after-all", llvm::cl::desc("Print IR after each pass"), cl::init(false), cl::Hidden)
llvm::shouldPrintAfterPass
bool shouldPrintAfterPass(StringRef PassID)
Definition: PrintPasses.cpp:69
llvm::cl::value_desc
Definition: CommandLine.h:424
llvm::shouldPrintBeforePass
bool shouldPrintBeforePass(StringRef PassID)
Definition: PrintPasses.cpp:65
shouldPrintBeforeOrAfterPass
static bool shouldPrintBeforeOrAfterPass(StringRef PassID, ArrayRef< std::string > PassesToPrint)
Definition: PrintPasses.cpp:56
llvm::forcePrintModuleIR
bool forcePrintModuleIR()
Definition: PrintPasses.cpp:81
llvm::cl::desc
Definition: CommandLine.h:414
llvm::cl::list
Definition: CommandLine.h:1630