From 4870e091ec99cd73bc80a8618c00369c836b20d3 Mon Sep 17 00:00:00 2001 From: Andreas Simbuerger Date: Sat, 24 May 2014 09:25:01 +0000 Subject: [PATCH] Store all RejectReasons that occurred in a log. This stores all RejectReasons created for one region in a RejectLog inside the DetectionContext. For now this only keeps track of the last error. A separate patch will enable the tracking of all errors. This patch itself does no harm (yet). llvm-svn: 209572 --- polly/include/polly/ScopDetection.h | 24 +++++++++++++++++++++++- polly/include/polly/ScopDetectionDiagnostic.h | 19 +++++++++++++++++++ polly/lib/Analysis/ScopDetection.cpp | 25 ++++++++++++++++++++----- 3 files changed, 62 insertions(+), 6 deletions(-) diff --git a/polly/include/polly/ScopDetection.h b/polly/include/polly/ScopDetection.h index 5e3f753..8a7da64 100644 --- a/polly/include/polly/ScopDetection.h +++ b/polly/include/polly/ScopDetection.h @@ -50,6 +50,8 @@ #include "llvm/Pass.h" #include "llvm/Analysis/AliasSetTracker.h" +#include "polly/ScopDetectionDiagnostic.h" + #include #include @@ -100,12 +102,13 @@ class ScopDetection : public FunctionPass { Region &CurRegion; // The region to check. AliasSetTracker AST; // The AliasSetTracker to hold the alias information. bool Verifying; // If we are in the verification phase? + RejectLog Log; // Map a base pointer to all access functions accessing it. BaseToAFs NonAffineAccesses, AffineAccesses; DetectionContext(Region &R, AliasAnalysis &AA, bool Verify) - : CurRegion(R), AST(AA), Verifying(Verify) {} + : CurRegion(R), AST(AA), Verifying(Verify), Log(&R) {} }; // Remember the valid regions @@ -115,6 +118,9 @@ class ScopDetection : public FunctionPass { // Invalid regions and the reason they fail. std::map InvalidRegions; + // Remember a list of errors for every region. + mutable std::map RejectLogs; + // Remember the invalid functions producted by backends; typedef std::set FunctionSet; FunctionSet InvalidFunctions; @@ -289,6 +295,22 @@ public: const_iterator end() const { return ValidRegions.end(); } //@} + /// @name Reject log iterators + /// + /// These iterators iterate over the logs of all rejected regions of this + // function. + //@{ + typedef std::map::iterator reject_iterator; + typedef std::map::const_iterator + const_reject_iterator; + + reject_iterator reject_begin() { return RejectLogs.begin(); } + reject_iterator reject_end() { return RejectLogs.end(); } + + const_reject_iterator reject_begin() const { return RejectLogs.begin(); } + const_reject_iterator reject_end() const { return RejectLogs.end(); } + //@} + /// @brief Mark the function as invalid so we will not extract any scop from /// the function. /// diff --git a/polly/include/polly/ScopDetectionDiagnostic.h b/polly/include/polly/ScopDetectionDiagnostic.h index 26441c0..44b39b87 100644 --- a/polly/include/polly/ScopDetectionDiagnostic.h +++ b/polly/include/polly/ScopDetectionDiagnostic.h @@ -59,6 +59,25 @@ public: virtual std::string getMessage() const = 0; }; +typedef std::shared_ptr RejectReasonPtr; + +/// @brief Stores all errors that ocurred during the detection. +class RejectLog { + Region *R; + llvm::SmallVector ErrorReports; + +public: + explicit RejectLog(Region *R) : R(R) {}; + + typedef llvm::SmallVector::iterator iterator; + + iterator begin() { return ErrorReports.begin(); } + iterator end() { return ErrorReports.end(); } + + const Region *region() const { return R; } + void report(RejectReasonPtr Reject) { ErrorReports.push_back(Reject); } +}; + //===----------------------------------------------------------------------===// /// @brief Base class for CFG related reject reasons. /// diff --git a/polly/lib/Analysis/ScopDetection.cpp b/polly/lib/Analysis/ScopDetection.cpp index dcdf018..90a5c1b 100644 --- a/polly/lib/Analysis/ScopDetection.cpp +++ b/polly/lib/Analysis/ScopDetection.cpp @@ -182,11 +182,15 @@ inline bool ScopDetection::invalid(DetectionContext &Context, bool Assert, Args &&... Arguments) const { if (!Context.Verifying) { - RR RejectReason = RR(Arguments...); - if (PollyTrackFailures) - LastFailure = RejectReason.getMessage(); + RejectLog &Log = Context.Log; + std::shared_ptr RejectReason = std::make_shared(Arguments...); - DEBUG(dbgs() << RejectReason.getMessage()); + if (PollyTrackFailures) { + Log.report(RejectReason); + LastFailure = RejectReason->getMessage(); + } + + DEBUG(dbgs() << RejectReason->getMessage()); DEBUG(dbgs() << "\n"); } else { assert(!Assert && "Verification of detected scop failed"); @@ -668,7 +672,16 @@ bool ScopDetection::isValidExit(DetectionContext &Context) const { bool ScopDetection::isValidRegion(Region &R) const { DetectionContext Context(R, *AA, false /*verifying*/); - return isValidRegion(Context); + + bool RegionIsValid = isValidRegion(Context); + if (PollyTrackFailures && !RegionIsValid) { + // std::map::insert does not replace. + std::pair InsertedValue = + RejectLogs.insert(std::make_pair(&R, Context.Log)); + assert(InsertedValue.second && "Two logs generated for the same Region."); + } + + return RegionIsValid; } bool ScopDetection::isValidRegion(DetectionContext &Context) const { @@ -821,6 +834,8 @@ void ScopDetection::print(raw_ostream &OS, const Module *) const { void ScopDetection::releaseMemory() { ValidRegions.clear(); InvalidRegions.clear(); + RejectLogs.clear(); + // Do not clear the invalid function set. } -- 2.7.4