From cd4c977b8b998a078f5416c8d71bc5b552a6df2d Mon Sep 17 00:00:00 2001 From: Michael Kruse Date: Fri, 21 Jul 2017 15:35:53 +0000 Subject: [PATCH] [ScopInfo] Print instructions in dump(). Print a statement's instruction on dump() regardless of -polly-print-instructions. dump() is supposed to be used in the debugger only and never in regression tests. While debugging, get all the information we have and we are not bound to break anything. For non-dump purposes of print, forward the setting of -polly-print-instructions as parameters. Some calls to print() had to be changed because the PollyPrintInstructions setting is only available in ScopInfo.cpp. In ScheduleOptimizer.cpp, dump() was used in regression tests. That's not what dump() is for. The print parameter "PrintInstructions" will also be useful for an explicit print SCoP pass in a future patch. llvm-svn: 308746 --- polly/include/polly/ScopInfo.h | 22 +++++++------- polly/lib/Analysis/ScopBuilder.cpp | 2 +- polly/lib/Analysis/ScopInfo.cpp | 36 +++++++++++++++-------- polly/lib/CodeGen/CodeGeneration.cpp | 2 +- polly/lib/Exchange/JSONExporter.cpp | 4 +-- polly/lib/Transform/DeLICM.cpp | 2 +- polly/lib/Transform/ScheduleOptimizer.cpp | 2 +- polly/lib/Transform/Simplify.cpp | 2 +- 8 files changed, 41 insertions(+), 31 deletions(-) diff --git a/polly/include/polly/ScopInfo.h b/polly/include/polly/ScopInfo.h index 215405bc8201..c68c81544544 100644 --- a/polly/include/polly/ScopInfo.h +++ b/polly/include/polly/ScopInfo.h @@ -1611,8 +1611,10 @@ public: /// Print the ScopStmt. /// - /// @param OS The output stream the ScopStmt is printed to. - void print(raw_ostream &OS) const; + /// @param OS The output stream the ScopStmt is printed to. + /// @param PrintInstructions Whether to print the statement's instructions as + /// well. + void print(raw_ostream &OS, bool PrintInstructions) const; /// Print the instructions in ScopStmt. /// @@ -1623,10 +1625,7 @@ public: }; /// Print ScopStmt S to raw_ostream O. -static inline raw_ostream &operator<<(raw_ostream &O, const ScopStmt &S) { - S.print(O); - return O; -} +raw_ostream &operator<<(raw_ostream &O, const ScopStmt &S); /// Static Control Part /// @@ -2318,7 +2317,7 @@ private: //@{ void printContext(raw_ostream &OS) const; void printArrayInfo(raw_ostream &OS) const; - void printStatements(raw_ostream &OS) const; + void printStatements(raw_ostream &OS, bool PrintInstructions) const; void printAliasAssumptions(raw_ostream &OS) const; //@} @@ -2811,7 +2810,9 @@ public: /// Print the static control part. /// /// @param OS The output stream the static control part is printed to. - void print(raw_ostream &OS) const; + /// @param PrintInstructions Whether to print the statement's instructions as + /// well. + void print(raw_ostream &OS, bool PrintInstructions) const; /// Print the ScopStmt to stderr. void dump() const; @@ -2956,10 +2957,7 @@ public: }; /// Print Scop scop to raw_ostream O. -static inline raw_ostream &operator<<(raw_ostream &O, const Scop &scop) { - scop.print(O); - return O; -} +raw_ostream &operator<<(raw_ostream &O, const Scop &scop); /// The legacy pass manager's analysis pass to compute scop information /// for a region. diff --git a/polly/lib/Analysis/ScopBuilder.cpp b/polly/lib/Analysis/ScopBuilder.cpp index 2d2918f4eebd..f6b929ab73e1 100644 --- a/polly/lib/Analysis/ScopBuilder.cpp +++ b/polly/lib/Analysis/ScopBuilder.cpp @@ -1048,7 +1048,7 @@ ScopBuilder::ScopBuilder(Region *R, AssumptionCache &AC, AliasAnalysis &AA, buildScop(*R, AC); - DEBUG(scop->print(dbgs())); + DEBUG(dbgs() << *scop); if (!scop->hasFeasibleRuntimeContext()) { InfeasibleScops++; diff --git a/polly/lib/Analysis/ScopInfo.cpp b/polly/lib/Analysis/ScopInfo.cpp index 88206f04252f..2c1445b08eb9 100644 --- a/polly/lib/Analysis/ScopInfo.cpp +++ b/polly/lib/Analysis/ScopInfo.cpp @@ -1974,7 +1974,7 @@ void ScopStmt::printInstructions(raw_ostream &OS) const { OS.indent(16) << "}\n"; } -void ScopStmt::print(raw_ostream &OS) const { +void ScopStmt::print(raw_ostream &OS, bool PrintInstructions) const { OS << "\t" << getBaseName() << "\n"; OS.indent(12) << "Domain :=\n"; @@ -1993,11 +1993,11 @@ void ScopStmt::print(raw_ostream &OS) const { for (MemoryAccess *Access : MemAccs) Access->print(OS); - if (PollyPrintInstructions) + if (PrintInstructions) printInstructions(OS.indent(12)); } -void ScopStmt::dump() const { print(dbgs()); } +void ScopStmt::dump() const { print(dbgs(), true); } void ScopStmt::removeAccessData(MemoryAccess *MA) { if (MA->isRead() && MA->isOriginalValueKind()) { @@ -2059,6 +2059,11 @@ void ScopStmt::removeSingleMemoryAccess(MemoryAccess *MA) { } } +raw_ostream &polly::operator<<(raw_ostream &O, const ScopStmt &S) { + S.print(O, PollyPrintInstructions); + return O; +} + //===----------------------------------------------------------------------===// /// Scop class implement @@ -4605,11 +4610,13 @@ void Scop::printAliasAssumptions(raw_ostream &OS) const { } } -void Scop::printStatements(raw_ostream &OS) const { +void Scop::printStatements(raw_ostream &OS, bool PrintInstructions) const { OS << "Statements {\n"; - for (const ScopStmt &Stmt : *this) - OS.indent(4) << Stmt; + for (const ScopStmt &Stmt : *this) { + OS.indent(4); + Stmt.print(OS, PrintInstructions); + } OS.indent(4) << "}\n"; } @@ -4630,7 +4637,7 @@ void Scop::printArrayInfo(raw_ostream &OS) const { OS.indent(4) << "}\n"; } -void Scop::print(raw_ostream &OS) const { +void Scop::print(raw_ostream &OS, bool PrintInstructions) const { OS.indent(4) << "Function: " << getFunction().getName() << "\n"; OS.indent(4) << "Region: " << getNameStr() << "\n"; OS.indent(4) << "Max Loop Depth: " << getMaxLoopDepth() << "\n"; @@ -4649,10 +4656,10 @@ void Scop::print(raw_ostream &OS) const { printContext(OS.indent(4)); printArrayInfo(OS.indent(4)); printAliasAssumptions(OS); - printStatements(OS.indent(4)); + printStatements(OS.indent(4), PrintInstructions); } -void Scop::dump() const { print(dbgs()); } +void Scop::dump() const { print(dbgs(), true); } isl_ctx *Scop::getIslCtx() const { return IslCtx.get(); } @@ -5128,6 +5135,11 @@ ArrayRef Scop::getPHIIncomings(const ScopArrayInfo *SAI) const { return It->second; } +raw_ostream &polly::operator<<(raw_ostream &O, const Scop &scop) { + scop.print(O, PollyPrintInstructions); + return O; +} + //===----------------------------------------------------------------------===// void ScopInfoRegionPass::getAnalysisUsage(AnalysisUsage &AU) const { AU.addRequired(); @@ -5187,7 +5199,7 @@ bool ScopInfoRegionPass::runOnRegion(Region *R, RGPassManager &RGM) { void ScopInfoRegionPass::print(raw_ostream &OS, const Module *) const { if (S) - S->print(OS); + S->print(OS, PollyPrintInstructions); else OS << "Invalid Scop!\n"; } @@ -5250,7 +5262,7 @@ PreservedAnalyses ScopInfoPrinterPass::run(Function &F, auto &SI = FAM.getResult(F); for (auto &It : SI) { if (It.second) - It.second->print(Stream); + It.second->print(Stream, PollyPrintInstructions); else Stream << "Invalid Scop!\n"; } @@ -5284,7 +5296,7 @@ bool ScopInfoWrapperPass::runOnFunction(Function &F) { void ScopInfoWrapperPass::print(raw_ostream &OS, const Module *) const { for (auto &It : *Result) { if (It.second) - It.second->print(OS); + It.second->print(OS, PollyPrintInstructions); else OS << "Invalid Scop!\n"; } diff --git a/polly/lib/CodeGen/CodeGeneration.cpp b/polly/lib/CodeGen/CodeGeneration.cpp index 5e845f1ae331..51b90860c58c 100644 --- a/polly/lib/CodeGen/CodeGeneration.cpp +++ b/polly/lib/CodeGen/CodeGeneration.cpp @@ -63,7 +63,7 @@ static void verifyGeneratedFunction(Scop &S, Function &F, IslAstInfo &AI) { DEBUG({ errs() << "== ISL Codegen created an invalid function ==\n\n== The " "SCoP ==\n"; - S.print(errs()); + errs() << S; errs() << "\n== The isl AST ==\n"; AI.print(errs()); errs() << "\n== The invalid function ==\n"; diff --git a/polly/lib/Exchange/JSONExporter.cpp b/polly/lib/Exchange/JSONExporter.cpp index 39af8a52fc7a..743471ad9b41 100644 --- a/polly/lib/Exchange/JSONExporter.cpp +++ b/polly/lib/Exchange/JSONExporter.cpp @@ -134,7 +134,7 @@ std::string JSONExporter::getFileName(Scop &S) const { return FileName; } -void JSONExporter::printScop(raw_ostream &OS, Scop &S) const { S.print(OS); } +void JSONExporter::printScop(raw_ostream &OS, Scop &S) const { OS << S; } /// Export all arrays from the Scop. /// @@ -263,7 +263,7 @@ std::string JSONImporter::getFileName(Scop &S) const { } void JSONImporter::printScop(raw_ostream &OS, Scop &S) const { - S.print(OS); + OS << S; for (std::vector::const_iterator I = NewAccessStrings.begin(), E = NewAccessStrings.end(); I != E; I++) diff --git a/polly/lib/Transform/DeLICM.cpp b/polly/lib/Transform/DeLICM.cpp index 117448c02d29..3d794e264e31 100644 --- a/polly/lib/Transform/DeLICM.cpp +++ b/polly/lib/Transform/DeLICM.cpp @@ -2155,7 +2155,7 @@ private: Impl->greedyCollapse(); DEBUG(dbgs() << "\nFinal Scop:\n"); - DEBUG(S.print(dbgs())); + DEBUG(dbgs() << S); } public: diff --git a/polly/lib/Transform/ScheduleOptimizer.cpp b/polly/lib/Transform/ScheduleOptimizer.cpp index 969ea1046cd3..277e0b6e4b51 100644 --- a/polly/lib/Transform/ScheduleOptimizer.cpp +++ b/polly/lib/Transform/ScheduleOptimizer.cpp @@ -1596,7 +1596,7 @@ bool IslScheduleOptimizer::runOnScop(Scop &S) { S.markAsOptimized(); if (OptimizedScops) - S.dump(); + errs() << S; return false; } diff --git a/polly/lib/Transform/Simplify.cpp b/polly/lib/Transform/Simplify.cpp index bd518fffbe12..a97fcef98fce 100644 --- a/polly/lib/Transform/Simplify.cpp +++ b/polly/lib/Transform/Simplify.cpp @@ -434,7 +434,7 @@ public: if (isModified()) ScopsModified++; DEBUG(dbgs() << "\nFinal Scop:\n"); - DEBUG(S.print(dbgs())); + DEBUG(dbgs() << S); return false; }