From 5bf774ce0e1b69ad6f1324acfc65658812e7958b Mon Sep 17 00:00:00 2001 From: Andreas Simbuerger Date: Thu, 26 Jun 2014 13:36:52 +0000 Subject: [PATCH] Use own class for storing the RejectLogs Use a container class to store the reject logs. Delegating most calls to the internal std::map and add a few convenient shortcuts (e.g., hasErrors()). llvm-svn: 211780 --- polly/include/polly/ScopDetection.h | 2 +- polly/include/polly/ScopDetectionDiagnostic.h | 42 ++++++++++++++++++++++++++- polly/lib/Analysis/ScopDetection.cpp | 8 ++--- 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/polly/include/polly/ScopDetection.h b/polly/include/polly/ScopDetection.h index 34b0844..d0b588e 100644 --- a/polly/include/polly/ScopDetection.h +++ b/polly/include/polly/ScopDetection.h @@ -144,7 +144,7 @@ class ScopDetection : public FunctionPass { RegionSet ValidRegions; // Remember a list of errors for every region. - mutable std::map RejectLogs; + mutable RejectLogsContainer RejectLogs; // Remember the invalid functions producted by backends; typedef std::set FunctionSet; diff --git a/polly/include/polly/ScopDetectionDiagnostic.h b/polly/include/polly/ScopDetectionDiagnostic.h index 3f6a8b3..2ab7ea8 100644 --- a/polly/include/polly/ScopDetectionDiagnostic.h +++ b/polly/include/polly/ScopDetectionDiagnostic.h @@ -173,12 +173,52 @@ public: iterator begin() const { return ErrorReports.begin(); } iterator end() const { return ErrorReports.end(); } - size_t size() { return ErrorReports.size(); } + size_t size() const { return ErrorReports.size(); } const Region *region() const { return R; } void report(RejectReasonPtr Reject) { ErrorReports.push_back(Reject); } }; +/// @brief Store reject logs +class RejectLogsContainer { + std::map Logs; + +public: + typedef std::map::iterator iterator; + typedef std::map::const_iterator const_iterator; + + iterator begin() { return Logs.begin(); } + iterator end() { return Logs.end(); } + + const_iterator begin() const { return Logs.begin(); } + const_iterator end() const { return Logs.end(); } + + void insert(std::pair New) { + auto Result = Logs.insert(New); + assert(Result.second && "Tried to replace an element in the log!"); + } + + std::map::mapped_type at(const Region *R) { + return Logs.at(R); + } + + void clear() { Logs.clear(); } + + size_t count(const Region *R) const { return Logs.count(R); } + + size_t size(const Region *R) const { + if (!Logs.count(R)) + return 0; + return Logs.at(R).size(); + } + + bool hasErrors(const Region *R) const { + return (Logs.count(R) && Logs.at(R).size() > 0); + } + + bool hasErrors(Region *R) const { return hasErrors((const Region *)R); } +}; + //===----------------------------------------------------------------------===// /// @brief Base class for CFG related reject reasons. /// diff --git a/polly/lib/Analysis/ScopDetection.cpp b/polly/lib/Analysis/ScopDetection.cpp index d63db25..be147cc 100644 --- a/polly/lib/Analysis/ScopDetection.cpp +++ b/polly/lib/Analysis/ScopDetection.cpp @@ -707,12 +707,8 @@ bool ScopDetection::isValidRegion(Region &R) const { bool RegionIsValid = isValidRegion(Context); bool HasErrors = !RegionIsValid || Context.Log.size() > 0; - if (PollyTrackFailures && HasErrors) { - // 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."); - } + if (PollyTrackFailures && HasErrors) + RejectLogs.insert(std::make_pair(&R, Context.Log)); return RegionIsValid; } -- 2.7.4