From 531891e980dbdd82dd3052925fecf1bbcc1b25e9 Mon Sep 17 00:00:00 2001 From: Tobias Grosser Date: Thu, 1 Nov 2012 16:45:20 +0000 Subject: [PATCH] ScopDetection: Print line numbers of detected scops If the flags '-polly-report -g' are given, we print file name and line numbers for the beginning and end of all detected scops. linear-algebra/kernels/gemm/gemm.c:23: Scop start linear-algebra/kernels/gemm/gemm.c:42: Scop end linear-algebra/kernels/gemm/gemm.c:77: Scop start linear-algebra/kernels/gemm/gemm.c:82: Scop end llvm-svn: 167235 --- polly/include/polly/ScopDetection.h | 12 ++++++++ polly/lib/Analysis/ScopDetection.cpp | 54 ++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/polly/include/polly/ScopDetection.h b/polly/include/polly/ScopDetection.h index f9480aa..36a634c 100755 --- a/polly/include/polly/ScopDetection.h +++ b/polly/include/polly/ScopDetection.h @@ -204,6 +204,18 @@ class ScopDetection : public FunctionPass { /// @return True if the function is not an OpenMP subfunction. bool isValidFunction(llvm::Function &F); + /// @brief Get the location of a region from the debug info. + /// + /// @param R The region to get debug info for. + /// @param LineBegin The first line in the region. + /// @param LineEnd The last line in the region. + /// @param FileName The filename where the region was defined. + void getDebugLocation(const Region *R, unsigned &LineBegin, unsigned &LineEnd, + std::string &FileName); + + /// @brief Print the locations of all detected scops. + void printLocations(); + public: static char ID; explicit ScopDetection() : FunctionPass(ID) {} diff --git a/polly/lib/Analysis/ScopDetection.cpp b/polly/lib/Analysis/ScopDetection.cpp index 826c434..f4c3a9c 100644 --- a/polly/lib/Analysis/ScopDetection.cpp +++ b/polly/lib/Analysis/ScopDetection.cpp @@ -57,6 +57,7 @@ #include "llvm/Analysis/RegionIterator.h" #include "llvm/Analysis/ScalarEvolution.h" #include "llvm/Analysis/ScalarEvolutionExpressions.h" +#include "llvm/DebugInfo.h" #include "llvm/Support/CommandLine.h" #include "llvm/Assembly/Writer.h" @@ -80,6 +81,11 @@ IgnoreAliasing("polly-ignore-aliasing", cl::Hidden, cl::init(false)); static cl::opt +ReportLevel("polly-report", + cl::desc("Print information about Polly"), + cl::Hidden, cl::init(false)); + +static cl::opt AllowNonAffine("polly-allow-nonaffine", cl::desc("Allow non affine access functions in arrays"), cl::Hidden, cl::init(false)); @@ -532,6 +538,50 @@ bool ScopDetection::isValidFunction(llvm::Function &F) { return !InvalidFunctions.count(&F); } +void ScopDetection::getDebugLocation(const Region *R, unsigned &LineBegin, + unsigned &LineEnd, std::string &FileName) { + LineBegin = -1; + LineEnd = 0; + + for (Region::const_block_iterator RI = R->block_begin(), RE = R->block_end(); + RI != RE; ++RI) + for (BasicBlock::iterator BI = (*RI)->begin(), BE = (*RI)->end(); BI != BE; + ++BI) { + DebugLoc DL = BI->getDebugLoc(); + if (DL.isUnknown()) + continue; + + DIScope Scope(DL.getScope(BI->getContext())); + + if (FileName.empty()) + FileName = Scope.getFilename(); + + unsigned NewLine = DL.getLine(); + + LineBegin = std::min(LineBegin, NewLine); + LineEnd = std::max(LineEnd, NewLine); + break; + } +} + +void ScopDetection::printLocations() { + for (iterator RI = begin(), RE = end(); RI != RE; ++RI) { + unsigned LineEntry, LineExit; + std::string FileName; + + getDebugLocation(*RI, LineEntry, LineExit, FileName); + + if (FileName.empty()) { + outs() << "Scop detected at unknown location. Compile with debug info " + "(-g) to get more precise information. \n"; + return; + } + + outs() << FileName << ":" << LineEntry << ": Scop start\n"; + outs() << FileName << ":" << LineExit << ": Scop end\n"; + } +} + bool ScopDetection::runOnFunction(llvm::Function &F) { AA = &getAnalysis(); SE = &getAnalysis(); @@ -548,6 +598,10 @@ bool ScopDetection::runOnFunction(llvm::Function &F) { return false; findScops(*TopRegion); + + if (ReportLevel >= 1) + printLocations(); + return false; } -- 2.7.4