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
This commit is contained in:
Tobias Grosser 2012-11-01 16:45:20 +00:00
parent 5d01691d76
commit 531891e980
2 changed files with 66 additions and 0 deletions

View File

@ -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) {}

View File

@ -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"
@ -79,6 +80,11 @@ IgnoreAliasing("polly-ignore-aliasing",
cl::desc("Ignore possible aliasing of the array bases"),
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"),
@ -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;
}