30 bool ShouldPreserveUseListOrder,
Module &M) {
34 M.print(OS,
nullptr, ShouldPreserveUseListOrder);
38 bool BannerPrinted =
false;
39 for (
const auto &
F : M.functions()) {
42 if (!BannerPrinted && !Banner.empty()) {
50class PrintModulePassWrapper :
public ModulePass {
53 bool ShouldPreserveUseListOrder;
54 bool ShouldRenumberMetadata;
58 PrintModulePassWrapper()
59 : ModulePass(ID), OS(
dbgs()), ShouldPreserveUseListOrder(
false),
60 ShouldRenumberMetadata(
false) {}
61 PrintModulePassWrapper(raw_ostream &OS,
const std::string &Banner,
62 bool ShouldPreserveUseListOrder,
63 bool ShouldRenumberMetadata)
64 : ModulePass(ID), OS(OS), Banner(Banner),
65 ShouldPreserveUseListOrder(ShouldPreserveUseListOrder),
66 ShouldRenumberMetadata(ShouldRenumberMetadata) {}
68 bool runOnModule(
Module &M)
override {
69 if (ShouldRenumberMetadata)
70 M.renumberMetadataForAssembly();
71 printModule(OS, Banner, ShouldPreserveUseListOrder, M);
75 void getAnalysisUsage(AnalysisUsage &AU)
const override {
79 StringRef getPassName()
const override {
return "Print Module IR"; }
88 PrintFunctionPassWrapper() : FunctionPass(ID), OS(
dbgs()) {}
89 PrintFunctionPassWrapper(raw_ostream &OS,
const std::string &Banner)
90 : FunctionPass(ID), OS(OS), Banner(Banner) {}
96 OS << Banner <<
" (function: " <<
F.getName() <<
")\n";
97 F.getParent()->print(OS,
nullptr);
99 OS << Banner << '\n' << static_cast<Value &>(
F);
105 void getAnalysisUsage(AnalysisUsage &AU)
const override {
109 StringRef getPassName()
const override {
return "Print Function IR"; }
114char PrintModulePassWrapper::ID = 0;
116 "Print module to stderr",
false,
true)
117char PrintFunctionPassWrapper::ID = 0;
123 bool ShouldPreserveUseListOrder) {
129 const std::string &Banner,
130 bool ShouldPreserveUseListOrder,
131 bool ShouldRenumberMetadata) {
132 return new PrintModulePassWrapper(OS, Banner, ShouldPreserveUseListOrder,
133 ShouldRenumberMetadata);
137 const std::string &Banner) {
138 return new PrintFunctionPassWrapper(OS, Banner);
142 const char *PID = (
const char *)
P->getPassID();
144 return (PID == &PrintModulePassWrapper::ID) ||
145 (PID == &PrintFunctionPassWrapper::ID);
Function Alias Analysis false
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...
A Module instance is used to store all the information related to an LLVM module.
Pass interface - Implemented by all 'passes'.
Represent a constant reference to a string, i.e.
constexpr bool empty() const
Check if the string is empty.
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 isIRPrintingPass(Pass *P)
Return true if a pass is for IR printing.
LLVM_ABI bool shouldPrintFunction(const Function &F)
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.
LLVM_ABI bool shouldPrintAllFunctions()
Implement std::hash so that hash_code can be used in STL containers.