36 if (any_isa<const Module *>(IR))
37 return std::make_pair(any_cast<const Module *>(IR), std::string());
39 if (any_isa<const Function *>(IR)) {
44 return std::make_pair(M,
formatv(
" (function: {0})", F->
getName()).str());
47 if (any_isa<const LazyCallGraph::SCC *>(IR)) {
53 return std::make_pair(M,
formatv(
" (scc: {0})", C->getName()).str());
59 if (any_isa<const Loop *>(IR)) {
64 const Module *M = F->getParent();
68 return std::make_pair(M,
formatv(
" (loop: {0})", ss.str()).str());
75 dbgs() << Banner << Extra <<
"\n";
82 dbgs() << Banner << Extra <<
"\n" <<
static_cast<const Value &
>(*F);
86 bool BannerPrinted =
false;
91 dbgs() << Banner << Extra <<
"\n";
107 void unwrapAndPrint(
Any IR,
StringRef Banner,
bool ForceModule =
false) {
109 if (
auto UnwrappedModule = unwrapModule(IR))
110 printIR(UnwrappedModule->first, Banner, UnwrappedModule->second);
114 if (any_isa<const Module *>(IR)) {
116 assert(M &&
"module should be valid for printing");
121 if (any_isa<const Function *>(IR)) {
123 assert(F &&
"function should be valid for printing");
128 if (any_isa<const LazyCallGraph::SCC *>(IR)) {
130 assert(C &&
"scc should be valid for printing");
132 printIR(C, Banner, Extra);
136 if (any_isa<const Loop *>(IR)) {
138 assert(L &&
"Loop should be valid for printing");
148 assert(ModuleDescStack.
empty() &&
"ModuleDescStack is not empty at exit");
151 void PrintIRInstrumentation::pushModuleDesc(
StringRef PassID,
Any IR) {
153 const Module *M =
nullptr;
155 if (
auto UnwrappedModule = unwrapModule(IR))
156 std::tie(M, Extra) = UnwrappedModule.getValue();
160 PrintIRInstrumentation::PrintModuleDesc
161 PrintIRInstrumentation::popModuleDesc(
StringRef PassID) {
162 assert(!ModuleDescStack.
empty() &&
"empty ModuleDescStack");
163 PrintModuleDesc ModuleDesc = ModuleDescStack.
pop_back_val();
164 assert(std::get<2>(ModuleDesc).equals(PassID) &&
"malformed ModuleDescStack");
168 bool PrintIRInstrumentation::printBeforePass(
StringRef PassID,
Any IR) {
177 pushModuleDesc(PassID, IR);
187 void PrintIRInstrumentation::printAfterPass(
StringRef PassID,
Any IR) {
195 popModuleDesc(PassID);
201 void PrintIRInstrumentation::printAfterPassInvalidated(
StringRef PassID) {
211 std::tie(M, Extra, StoredPassID) = popModuleDesc(PassID);
218 formatv(
"*** IR Dump After {0} *** invalidated: ", PassID);
219 printIR(M, Banner, Extra);
229 [
this](
StringRef P,
Any IR) {
return this->printBeforePass(P, IR); });
233 [
this](
StringRef P,
Any IR) { this->printAfterPass(P, IR); });
235 [
this](
StringRef P) { this->printAfterPassInvalidated(P); });
241 PrintIR.registerCallbacks(PIC);
242 TimePasses.registerCallbacks(PIC);
bool shouldPrintAfterPass()
bool forcePrintModuleIR()
forcePrintModuleIR - returns true if IR printing passes should
This class represents lattice values for constants.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool contains(StringRef Other) const
Return true if the given string is a substring of *this, and false otherwise.
A Module instance is used to store all the information related to an LLVM module. ...
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
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
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)
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