diff options
author | Tobias Grosser <grosser@fim.uni-passau.de> | 2012-11-01 16:45:20 +0000 |
---|---|---|
committer | Tobias Grosser <grosser@fim.uni-passau.de> | 2012-11-01 16:45:20 +0000 |
commit | 531891e980dbdd82dd3052925fecf1bbcc1b25e9 (patch) | |
tree | 215729bb6b7e37f9abc2b63b2345f2f67dc7dff1 /polly | |
parent | 5d01691d76d5f71e91a8bff8e027f9f37f291256 (diff) | |
download | llvm-531891e980dbdd82dd3052925fecf1bbcc1b25e9.zip llvm-531891e980dbdd82dd3052925fecf1bbcc1b25e9.tar.gz llvm-531891e980dbdd82dd3052925fecf1bbcc1b25e9.tar.bz2 |
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
Diffstat (limited to 'polly')
-rwxr-xr-x | polly/include/polly/ScopDetection.h | 12 | ||||
-rw-r--r-- | polly/lib/Analysis/ScopDetection.cpp | 54 |
2 files changed, 66 insertions, 0 deletions
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<bool> +ReportLevel("polly-report", + cl::desc("Print information about Polly"), + cl::Hidden, cl::init(false)); + +static cl::opt<bool> 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<AliasAnalysis>(); SE = &getAnalysis<ScalarEvolution>(); @@ -548,6 +598,10 @@ bool ScopDetection::runOnFunction(llvm::Function &F) { return false; findScops(*TopRegion); + + if (ReportLevel >= 1) + printLocations(); + return false; } |