35 if (any_isa<const Module *>(IR))
36 return std::make_pair(any_cast<const Module *>(IR), std::string());
38 if (any_isa<const Function *>(IR)) {
43 return std::make_pair(M,
formatv(
" (function: {0})", F->
getName()).str());
46 if (any_isa<const LazyCallGraph::SCC *>(IR)) {
52 return std::make_pair(M,
formatv(
" (scc: {0})", C->getName()).str());
58 if (any_isa<const Loop *>(IR)) {
63 const Module *M = F->getParent();
67 return std::make_pair(M,
formatv(
" (loop: {0})", ss.str()).str());
74 dbgs() << Banner << Extra <<
"\n";
81 dbgs() << Banner << Extra <<
"\n" <<
static_cast<const Value &
>(*F);
85 bool BannerPrinted =
false;
90 dbgs() << Banner << Extra <<
"\n";
106 void unwrapAndPrint(
Any IR,
StringRef Banner,
bool ForceModule =
false) {
108 if (
auto UnwrappedModule = unwrapModule(IR))
109 printIR(UnwrappedModule->first, Banner, UnwrappedModule->second);
113 if (any_isa<const Module *>(IR)) {
115 assert(M &&
"module should be valid for printing");
120 if (any_isa<const Function *>(IR)) {
122 assert(F &&
"function should be valid for printing");
127 if (any_isa<const LazyCallGraph::SCC *>(IR)) {
129 assert(C &&
"scc should be valid for printing");
131 printIR(C, Banner, Extra);
135 if (any_isa<const Loop *>(IR)) {
137 assert(L &&
"Loop should be valid for printing");
147 assert(ModuleDescStack.
empty() &&
"ModuleDescStack is not empty at exit");
150 void PrintIRInstrumentation::pushModuleDesc(
StringRef PassID,
Any IR) {
152 const Module *M =
nullptr;
154 if (
auto UnwrappedModule = unwrapModule(IR))
155 std::tie(M, Extra) = UnwrappedModule.getValue();
159 PrintIRInstrumentation::PrintModuleDesc
160 PrintIRInstrumentation::popModuleDesc(
StringRef PassID) {
161 assert(!ModuleDescStack.
empty() &&
"empty ModuleDescStack");
162 PrintModuleDesc ModuleDesc = ModuleDescStack.
pop_back_val();
163 assert(std::get<2>(ModuleDesc).equals(PassID) &&
"malformed ModuleDescStack");
167 bool PrintIRInstrumentation::printBeforePass(
StringRef PassID,
Any IR) {
176 pushModuleDesc(PassID, IR);
186 void PrintIRInstrumentation::printAfterPass(
StringRef PassID,
Any IR) {
194 popModuleDesc(PassID);
200 void PrintIRInstrumentation::printAfterPassInvalidated(
StringRef PassID) {
210 std::tie(M, Extra, StoredPassID) = popModuleDesc(PassID);
217 formatv(
"*** IR Dump After {0} *** invalidated: ", PassID);
218 printIR(M, Banner, Extra);
228 [
this](
StringRef P,
Any IR) {
return this->printBeforePass(P, IR); });
232 [
this](
StringRef P,
Any IR) { this->printAfterPass(P, IR); });
234 [
this](
StringRef P) { this->printAfterPassInvalidated(P); });
240 PrintIR.registerCallbacks(PIC);
241 TimePasses.registerCallbacks(PIC);
bool shouldPrintAfterPass()
bool forcePrintModuleIR()
forcePrintModuleIR - returns true if IR printing passes should
This class represents lattice values for constants.
A Module instance is used to store all the information related to an LLVM module. ...
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
bool shouldPrintBeforePass()
This is a helper to determine whether to print IR before or after a pass.
Implements a lazy call graph analysis and related passes for the new pass manager.
auto formatv(const char *Fmt, Ts &&... Vals) -> formatv_object< decltype(std::make_tuple(detail::build_format_adapter(std::forward< Ts >(Vals))...))>
void registerCallbacks(PassInstrumentationCallbacks &PIC)
BlockT * getHeader() const
T any_cast(const Any &Value)
void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW=nullptr, bool ShouldPreserveUseListOrder=false, bool IsForDebug=false) const
Print the function to an output stream with an optional AssemblyAnnotationWriter. ...
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This file defines the Pass Instrumentation classes that provide instrumentation points into the pass ...
~PrintIRInstrumentation()
void registerBeforePassCallback(CallableT C)
A node in the call graph.
void registerCallbacks(PassInstrumentationCallbacks &PIC)
LLVM_NODISCARD bool contains(StringRef Other) const
Return true if the given string is a substring of *this, and false otherwise.
void printAsOperand(raw_ostream &O, bool PrintType=true, const Module *M=nullptr) const
Print the name of this Value out to the specified raw_ostream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW, bool ShouldPreserveUseListOrder=false, bool IsForDebug=false) const
Print the module to an output stream with an optional AssemblyAnnotationWriter.
Module.h This file contains the declarations for the Module class.
LLVM_NODISCARD T pop_back_val()
bool isFunctionInPrintList(StringRef FunctionName)
isFunctionInPrintList - returns true if a function should be printed via
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
This header defines a class that provides bookkeeping for all standard (i.e in-tree) pass instrumenta...
void registerAfterPassInvalidatedCallback(CallableT C)
void emplace_back(ArgTypes &&... Args)
LLVM_NODISCARD bool empty() const
Represents a single loop in the control flow graph.
StringRef getName() const
Return a constant reference to the value's name.
const Function * getParent() const
Return the enclosing method, or null if none.
This file defines passes to print out IR in various granularities.
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
std::string getName() const
Provide a short name by printing this SCC to a std::string.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
A raw_ostream that writes to an std::string.
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
An SCC of the call graph.
void registerAfterPassCallback(CallableT C)
This class manages callbacks registration, as well as provides a way for PassInstrumentation to pass ...
StringRef - Represent a constant reference to a string, i.e.
void printLoop(Loop &L, raw_ostream &OS, const std::string &Banner="")
Function to print a loop's contents as LLVM's text IR assembly.
Statically lint checks LLVM IR