diff options
author | Tobias Grosser <tobias@grosser.es> | 2015-05-03 08:21:36 +0300 |
---|---|---|
committer | Tobias Grosser <tobias@grosser.es> | 2015-05-03 08:21:36 +0300 |
commit | a63b7cee66ff16485a8927d0fe86bd1ab0e21f4d (patch) | |
tree | 48ee290b469c44a976afd7373f9282765db34ce3 /polly/lib | |
parent | 4b5b1ac99702a99eaad6faccd9c55ddc83b23c5d (diff) |
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@tue.nl>
llvm-svn: 236393
Diffstat (limited to 'polly/lib')
-rw-r--r-- | polly/lib/Analysis/ScopDetection.cpp | 1 | ||||
-rw-r--r-- | polly/lib/Analysis/ScopDetectionDiagnostic.cpp | 24 | ||||
-rw-r--r-- | polly/lib/Analysis/ScopGraphPrinter.cpp | 15 | ||||
-rw-r--r-- | polly/lib/CMakeLists.txt | 1 | ||||
-rw-r--r-- | polly/lib/Exchange/JSONExporter.cpp | 11 | ||||
-rw-r--r-- | polly/lib/Makefile | 1 | ||||
-rw-r--r-- | polly/lib/Support/ScopLocation.cpp | 47 |
7 files changed, 76 insertions, 24 deletions
diff --git a/polly/lib/Analysis/ScopDetection.cpp b/polly/lib/Analysis/ScopDetection.cpp index a0385a664379..db04f0b0a88f 100644 --- a/polly/lib/Analysis/ScopDetection.cpp +++ b/polly/lib/Analysis/ScopDetection.cpp @@ -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" diff --git a/polly/lib/Analysis/ScopDetectionDiagnostic.cpp b/polly/lib/Analysis/ScopDetectionDiagnostic.cpp index c7d2b338797b..f5b57f0fc839 100644 --- a/polly/lib/Analysis/ScopDetectionDiagnostic.cpp +++ b/polly/lib/Analysis/ScopDetectionDiagnostic.cpp @@ -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 operator+(Twine LHS, const T &RHS) { 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 { diff --git a/polly/lib/Analysis/ScopGraphPrinter.cpp b/polly/lib/Analysis/ScopGraphPrinter.cpp index ca1013341c84..f39893ea8a4d 100644 --- a/polly/lib/Analysis/ScopGraphPrinter.cpp +++ b/polly/lib/Analysis/ScopGraphPrinter.cpp @@ -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 *> : public DOTGraphTraits<RegionNode *> { 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"; diff --git a/polly/lib/CMakeLists.txt b/polly/lib/CMakeLists.txt index c91dc624cff3..7b1c4a593cf8 100644 --- a/polly/lib/CMakeLists.txt +++ b/polly/lib/CMakeLists.txt @@ -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 diff --git a/polly/lib/Exchange/JSONExporter.cpp b/polly/lib/Exchange/JSONExporter.cpp index b9dcaadb9a41..3cedb0396851 100644 --- a/polly/lib/Exchange/JSONExporter.cpp +++ b/polly/lib/Exchange/JSONExporter.cpp @@ -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 &OS, Scop &S) const { S.print(OS); } 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) { diff --git a/polly/lib/Makefile b/polly/lib/Makefile index 263fa78d561c..8e2ff1b4b363 100644 --- a/polly/lib/Makefile +++ b/polly/lib/Makefile @@ -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 \ diff --git a/polly/lib/Support/ScopLocation.cpp b/polly/lib/Support/ScopLocation.cpp new file mode 100644 index 000000000000..ebf717dc709a --- /dev/null +++ b/polly/lib/Support/ScopLocation.cpp @@ -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); + } +} +} |