diff --git a/polly/include/polly/ScopDetection.h b/polly/include/polly/ScopDetection.h index 34b0844176e3..d0b588e9fdd6 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 3f6a8b3082d1..2ab7ea8f8105 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 d63db2563a18..be147cc0c238 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; }