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
This commit is contained in:
Andreas Simbuerger 2014-06-26 13:36:52 +00:00
parent 970ff64dc5
commit 5bf774ce0e
3 changed files with 44 additions and 8 deletions

View File

@ -144,7 +144,7 @@ class ScopDetection : public FunctionPass {
RegionSet ValidRegions;
// Remember a list of errors for every region.
mutable std::map<const Region *, RejectLog> RejectLogs;
mutable RejectLogsContainer RejectLogs;
// Remember the invalid functions producted by backends;
typedef std::set<const Function *> FunctionSet;

View File

@ -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<const Region *, RejectLog> Logs;
public:
typedef std::map<const Region *, RejectLog>::iterator iterator;
typedef std::map<const Region *, RejectLog>::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<const Region *, RejectLog> New) {
auto Result = Logs.insert(New);
assert(Result.second && "Tried to replace an element in the log!");
}
std::map<const Region *, RejectLog>::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.
///

View File

@ -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<reject_iterator, bool> InsertedValue =
if (PollyTrackFailures && HasErrors)
RejectLogs.insert(std::make_pair(&R, Context.Log));
assert(InsertedValue.second && "Two logs generated for the same Region.");
}
return RegionIsValid;
}