[polly] r236393 - Adding debug location information to Polly's JSCOP and dot exports

Tobias Grosser tobias at grosser.es
Sat May 2 22:21:37 PDT 2015


Author: grosser
Date: Sun May  3 00:21:36 2015
New Revision: 236393

URL: http://llvm.org/viewvc/llvm-project?rev=236393&view=rev
Log:
Adding debug location information to Polly's JSCOP and dot exports

This change adds location information for the detected regions in Polly when the
required debug information is available.

The JSCOP output format is extended with a "location" field which contains the
information in the format "source.c:start-end"

The dot output is extended to contain the location information for each nested
region in the analyzed function.

As part of this change, the existing getDebugLocation function has been moved
into lib/Support/ScopLocation.cpp to avoid having to include
polly/ScopDetectionDiagnostics.h.

Differential Revision: http://reviews.llvm.org/D9431

Contributed-by: Roal Jordans <r.jordans at tue.nl>

Added:
    polly/trunk/include/polly/Support/ScopLocation.h
    polly/trunk/lib/Support/ScopLocation.cpp
Modified:
    polly/trunk/include/polly/ScopDetectionDiagnostic.h
    polly/trunk/lib/Analysis/ScopDetection.cpp
    polly/trunk/lib/Analysis/ScopDetectionDiagnostic.cpp
    polly/trunk/lib/Analysis/ScopGraphPrinter.cpp
    polly/trunk/lib/CMakeLists.txt
    polly/trunk/lib/Exchange/JSONExporter.cpp
    polly/trunk/lib/Makefile

Modified: polly/trunk/include/polly/ScopDetectionDiagnostic.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/ScopDetectionDiagnostic.h?rev=236393&r1=236392&r2=236393&view=diff
==============================================================================
--- polly/trunk/include/polly/ScopDetectionDiagnostic.h (original)
+++ polly/trunk/include/polly/ScopDetectionDiagnostic.h Sun May  3 00:21:36 2015
@@ -44,15 +44,6 @@ class Region;
 
 namespace polly {
 
-/// @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);
-
 class RejectLog;
 /// @brief Emit optimization remarks about the rejected regions to the user.
 ///

Added: polly/trunk/include/polly/Support/ScopLocation.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/Support/ScopLocation.h?rev=236393&view=auto
==============================================================================
--- polly/trunk/include/polly/Support/ScopLocation.h (added)
+++ polly/trunk/include/polly/Support/ScopLocation.h Sun May  3 00:21:36 2015
@@ -0,0 +1,35 @@
+//=== ScopLocation.h -- Debug location helper for ScopDetection -*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Helper function for extracting region debug information.
+//
+//===----------------------------------------------------------------------===//
+//
+#ifndef POLLY_SCOP_LOCATION_H
+#define POLLY_SCOP_LOCATION_H
+
+#include <string>
+
+namespace llvm {
+class Region;
+}
+
+namespace polly {
+
+/// @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 llvm::Region *R, unsigned &LineBegin,
+                      unsigned &LineEnd, std::string &FileName);
+}
+
+#endif // POLLY_SCOP_LOCATION_H

Modified: polly/trunk/lib/Analysis/ScopDetection.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopDetection.cpp?rev=236393&r1=236392&r2=236393&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopDetection.cpp (original)
+++ polly/trunk/lib/Analysis/ScopDetection.cpp Sun May  3 00:21:36 2015
@@ -51,6 +51,7 @@
 #include "polly/ScopDetection.h"
 #include "polly/Support/SCEVValidator.h"
 #include "polly/Support/ScopHelper.h"
+#include "polly/Support/ScopLocation.h"
 #include "polly/CodeGen/CodeGeneration.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Analysis/AliasAnalysis.h"

Modified: polly/trunk/lib/Analysis/ScopDetectionDiagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopDetectionDiagnostic.cpp?rev=236393&r1=236392&r2=236393&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopDetectionDiagnostic.cpp (original)
+++ polly/trunk/lib/Analysis/ScopDetectionDiagnostic.cpp Sun May  3 00:21:36 2015
@@ -18,6 +18,7 @@
 //
 //===----------------------------------------------------------------------===//
 #include "polly/ScopDetectionDiagnostic.h"
+#include "polly/Support/ScopLocation.h"
 
 #include "llvm/Analysis/LoopInfo.h"
 #include "llvm/Analysis/AliasSetTracker.h"
@@ -60,29 +61,6 @@ template <typename T> std::string operat
 
   return LHS.concat(Buf).str();
 }
-
-void getDebugLocation(const Region *R, unsigned &LineBegin, unsigned &LineEnd,
-                      std::string &FileName) {
-  LineBegin = -1;
-  LineEnd = 0;
-
-  for (const BasicBlock *BB : R->blocks())
-    for (const Instruction &Inst : *BB) {
-      DebugLoc DL = Inst.getDebugLoc();
-      if (!DL)
-        continue;
-
-      auto *Scope = cast<DIScope>(DL.getScope());
-
-      if (FileName.empty())
-        FileName = Scope->getFilename();
-
-      unsigned NewLine = DL.getLine();
-
-      LineBegin = std::min(LineBegin, NewLine);
-      LineEnd = std::max(LineEnd, NewLine);
-    }
-}
 }
 
 namespace llvm {

Modified: polly/trunk/lib/Analysis/ScopGraphPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopGraphPrinter.cpp?rev=236393&r1=236392&r2=236393&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopGraphPrinter.cpp (original)
+++ polly/trunk/lib/Analysis/ScopGraphPrinter.cpp Sun May  3 00:21:36 2015
@@ -16,6 +16,7 @@
 
 #include "polly/LinkAllPasses.h"
 #include "polly/ScopDetection.h"
+#include "polly/Support/ScopLocation.h"
 #include "llvm/Analysis/DOTGraphTraitsPass.h"
 #include "llvm/Analysis/RegionInfo.h"
 #include "llvm/Analysis/RegionIterator.h"
@@ -112,9 +113,21 @@ struct DOTGraphTraits<ScopDetection *> :
                                  raw_ostream &O, unsigned depth = 0) {
     O.indent(2 * depth) << "subgraph cluster_" << static_cast<const void *>(R)
                         << " {\n";
+    unsigned LineBegin, LineEnd;
+    std::string FileName;
+
+    getDebugLocation(R, LineBegin, LineEnd, FileName);
+
+    std::string Location;
+    if (LineBegin != (unsigned)-1) {
+      Location = escapeString(FileName + ":" + std::to_string(LineBegin) + "-" +
+                              std::to_string(LineEnd) + "\n");
+    }
+
     std::string ErrorMessage = SD->regionIsInvalidBecause(R);
     ErrorMessage = escapeString(ErrorMessage);
-    O.indent(2 * (depth + 1)) << "label = \"" << ErrorMessage << "\";\n";
+    O.indent(2 * (depth + 1)) << "label = \"" << Location << ErrorMessage
+                              << "\";\n";
 
     if (SD->isMaxRegionInScop(*R)) {
       O.indent(2 * (depth + 1)) << "style = filled;\n";

Modified: polly/trunk/lib/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CMakeLists.txt?rev=236393&r1=236392&r2=236393&view=diff
==============================================================================
--- polly/trunk/lib/CMakeLists.txt (original)
+++ polly/trunk/lib/CMakeLists.txt Sun May  3 00:21:36 2015
@@ -120,6 +120,7 @@ add_polly_library(Polly
   Support/SCEVValidator.cpp
   Support/RegisterPasses.cpp
   Support/ScopHelper.cpp
+  Support/ScopLocation.cpp
   ${POLLY_JSON_FILES}
   Transform/Canonicalization.cpp
   Transform/CodePreparation.cpp

Modified: polly/trunk/lib/Exchange/JSONExporter.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Exchange/JSONExporter.cpp?rev=236393&r1=236392&r2=236393&view=diff
==============================================================================
--- polly/trunk/lib/Exchange/JSONExporter.cpp (original)
+++ polly/trunk/lib/Exchange/JSONExporter.cpp Sun May  3 00:21:36 2015
@@ -16,6 +16,7 @@
 #include "polly/Options.h"
 #include "polly/ScopInfo.h"
 #include "polly/ScopPass.h"
+#include "polly/Support/ScopLocation.h"
 
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Analysis/RegionInfo.h"
@@ -90,9 +91,19 @@ void JSONExporter::printScop(raw_ostream
 
 Json::Value JSONExporter::getJSON(Scop &S) const {
   Json::Value root;
+  unsigned LineBegin, LineEnd;
+  std::string FileName;
+
+  getDebugLocation(&S.getRegion(), LineBegin, LineEnd, FileName);
+  std::string Location;
+  if (LineBegin != (unsigned)-1)
+    Location = FileName + ":" + std::to_string(LineBegin) + "-" +
+               std::to_string(LineEnd);
 
   root["name"] = S.getRegion().getNameStr();
   root["context"] = S.getContextStr();
+  if (LineBegin != (unsigned)-1)
+    root["location"] = Location;
   root["statements"];
 
   for (Scop::iterator SI = S.begin(), SE = S.end(); SI != SE; ++SI) {

Modified: polly/trunk/lib/Makefile
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Makefile?rev=236393&r1=236392&r2=236393&view=diff
==============================================================================
--- polly/trunk/lib/Makefile (original)
+++ polly/trunk/lib/Makefile Sun May  3 00:21:36 2015
@@ -116,6 +116,7 @@ SOURCES= Polly.cpp \
 	 Support/SCEVValidator.cpp \
 	 Support/RegisterPasses.cpp \
 	 Support/ScopHelper.cpp \
+	 Support/ScopLocation.cpp \
 	 Analysis/DependenceInfo.cpp \
 	 Analysis/ScopDetection.cpp \
 	 Analysis/ScopDetectionDiagnostic.cpp \

Added: polly/trunk/lib/Support/ScopLocation.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Support/ScopLocation.cpp?rev=236393&view=auto
==============================================================================
--- polly/trunk/lib/Support/ScopLocation.cpp (added)
+++ polly/trunk/lib/Support/ScopLocation.cpp Sun May  3 00:21:36 2015
@@ -0,0 +1,47 @@
+//=== ScopLocation.cpp - Debug location for ScopDetection ----- -*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Helper function for extracting region debug information.
+//
+//===----------------------------------------------------------------------===//
+//
+#include "polly/Support/ScopLocation.h"
+
+#include "llvm/IR/BasicBlock.h"
+#include "llvm/IR/DebugInfo.h"
+#include "llvm/IR/DebugLoc.h"
+#include "llvm/Analysis/RegionInfo.h"
+
+using namespace llvm;
+
+namespace polly {
+
+void getDebugLocation(const Region *R, unsigned &LineBegin, unsigned &LineEnd,
+                      std::string &FileName) {
+  LineBegin = -1;
+  LineEnd = 0;
+
+  for (const BasicBlock *BB : R->blocks())
+    for (const Instruction &Inst : *BB) {
+      DebugLoc DL = Inst.getDebugLoc();
+      if (!DL)
+        continue;
+
+      auto *Scope = cast<DIScope>(DL.getScope());
+
+      if (FileName.empty())
+        FileName = Scope->getFilename();
+
+      unsigned NewLine = DL.getLine();
+
+      LineBegin = std::min(LineBegin, NewLine);
+      LineEnd = std::max(LineEnd, NewLine);
+    }
+}
+}





More information about the llvm-commits mailing list