29class PrintModulePassWrapper :
public ModulePass {
32 bool ShouldPreserveUseListOrder;
36 PrintModulePassWrapper() : ModulePass(ID), OS(
dbgs()) {}
37 PrintModulePassWrapper(raw_ostream &OS,
const std::string &Banner,
38 bool ShouldPreserveUseListOrder)
39 : ModulePass(ID), OS(OS), Banner(Banner),
40 ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) {}
42 bool runOnModule(
Module &M)
override {
46 M.print(OS,
nullptr, ShouldPreserveUseListOrder);
48 bool BannerPrinted =
false;
49 for (
const auto &
F :
M.functions()) {
51 if (!BannerPrinted && !Banner.empty()) {
63 void getAnalysisUsage(AnalysisUsage &AU)
const override {
67 StringRef getPassName()
const override {
return "Print Module IR"; }
76 PrintFunctionPassWrapper() : FunctionPass(ID), OS(
dbgs()) {}
77 PrintFunctionPassWrapper(raw_ostream &OS,
const std::string &Banner)
78 : FunctionPass(ID), OS(OS), Banner(Banner) {}
84 OS << Banner <<
" (function: " <<
F.getName() <<
")\n"
87 OS << Banner << '\n' << static_cast<Value &>(
F);
93 void getAnalysisUsage(AnalysisUsage &AU)
const override {
97 StringRef getPassName()
const override {
return "Print Function IR"; }
102char PrintModulePassWrapper::ID = 0;
104 "Print module to stderr",
false,
true)
105char PrintFunctionPassWrapper::ID = 0;
111 bool ShouldPreserveUseListOrder) {
112 return new PrintModulePassWrapper(OS, Banner, ShouldPreserveUseListOrder);
116 const std::string &Banner) {
117 return new PrintFunctionPassWrapper(OS, Banner);
121 const char *PID = (
const char *)
P->getPassID();
123 return (PID == &PrintModulePassWrapper::ID) ||
124 (PID == &PrintFunctionPassWrapper::ID);
static bool runOnFunction(Function &F, bool PostInlining)
This file contains an interface for creating legacy passes to print out IR in various granularities.
Module.h This file contains the declarations for the Module class.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
void setPreservesAll()
Set by analyses that do not transform their input at all.
FunctionPass class - This class is used to implement most global optimizations.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Pass interface - Implemented by all 'passes'.
This class implements an extremely fast bulk output stream that can only output to a stream.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI bool forcePrintModuleIR()
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI bool isFunctionInPrintList(StringRef FunctionName)
LLVM_ABI bool isIRPrintingPass(Pass *P)
Return true if a pass is for IR printing.
LLVM_ABI 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.
LLVM_ABI 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.
Implement std::hash so that hash_code can be used in STL containers.