[llvm-commits] [polly] r167235 - in /polly/trunk: include/polly/ScopDetection.h lib/Analysis/ScopDetection.cpp

Tobias Grosser grosser at fim.uni-passau.de
Thu Nov 1 09:45:20 PDT 2012


Author: grosser
Date: Thu Nov  1 11:45:20 2012
New Revision: 167235

URL: http://llvm.org/viewvc/llvm-project?rev=167235&view=rev
Log:
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

Modified:
    polly/trunk/include/polly/ScopDetection.h
    polly/trunk/lib/Analysis/ScopDetection.cpp

Modified: polly/trunk/include/polly/ScopDetection.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/ScopDetection.h?rev=167235&r1=167234&r2=167235&view=diff
==============================================================================
--- polly/trunk/include/polly/ScopDetection.h (original)
+++ polly/trunk/include/polly/ScopDetection.h Thu Nov  1 11:45:20 2012
@@ -204,6 +204,18 @@
   /// @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) {}

Modified: polly/trunk/lib/Analysis/ScopDetection.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopDetection.cpp?rev=167235&r1=167234&r2=167235&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopDetection.cpp (original)
+++ polly/trunk/lib/Analysis/ScopDetection.cpp Thu Nov  1 11:45:20 2012
@@ -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 @@
                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 @@
   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 @@
     return false;
 
   findScops(*TopRegion);
+
+  if (ReportLevel >= 1)
+    printLocations();
+
   return false;
 }
 





More information about the llvm-commits mailing list