summaryrefslogtreecommitdiffstats
path: root/polly/lib/Analysis/ScopDetection.cpp
diff options
context:
space:
mode:
authorJohannes Doerfert <doerfert@cs.uni-saarland.de>2016-05-12 18:50:01 +0000
committerJohannes Doerfert <doerfert@cs.uni-saarland.de>2016-05-12 18:50:01 +0000
commit6c7639b380a3830c60c52525e470767a64f57248 (patch)
tree3634bebbe152b5d35868ed09f0ac7a083bf584e0 /polly/lib/Analysis/ScopDetection.cpp
parent851f879f32bdb4487b3ee82c8e9139e0acdb4729 (diff)
downloadbcm5719-llvm-6c7639b380a3830c60c52525e470767a64f57248.tar.gz
bcm5719-llvm-6c7639b380a3830c60c52525e470767a64f57248.zip
Cleanup rejection log handling [NFC]
This patch cleans up the rejection log handling during the ScopDetection. It consists of two interconnected parts: - We keep all detection contexts for a function in order to provide more information to the user, e.g., about the rejection of extended/intermediate regions. - We remove the mutable "RejectLogs" member as the information is available through the detection contexts. llvm-svn: 269323
Diffstat (limited to 'polly/lib/Analysis/ScopDetection.cpp')
-rw-r--r--polly/lib/Analysis/ScopDetection.cpp82
1 files changed, 30 insertions, 52 deletions
diff --git a/polly/lib/Analysis/ScopDetection.cpp b/polly/lib/Analysis/ScopDetection.cpp
index 34f439bae0b..fedca6fd206 100644
--- a/polly/lib/Analysis/ScopDetection.cpp
+++ b/polly/lib/Analysis/ScopDetection.cpp
@@ -262,10 +262,10 @@ bool ScopDetection::isMaxRegionInScop(const Region &R, bool Verify) const {
return false;
if (Verify) {
- DetectionContextMap.erase(&R);
- const auto &It = DetectionContextMap.insert(
- std::make_pair(&R, DetectionContext(const_cast<Region &>(R), *AA,
- false /*verifying*/)));
+ DetectionContextMap.erase(getBBPairForRegion(&R));
+ const auto &It = DetectionContextMap.insert(std::make_pair(
+ getBBPairForRegion(&R),
+ DetectionContext(const_cast<Region &>(R), *AA, false /*verifying*/)));
DetectionContext &Context = It.first->second;
return isValidRegion(Context);
}
@@ -274,19 +274,16 @@ bool ScopDetection::isMaxRegionInScop(const Region &R, bool Verify) const {
}
std::string ScopDetection::regionIsInvalidBecause(const Region *R) const {
- if (!RejectLogs.count(R))
- return "";
-
// Get the first error we found. Even in keep-going mode, this is the first
// reason that caused the candidate to be rejected.
- RejectLog Errors = RejectLogs.at(R);
+ auto *Log = lookupRejectionLog(R);
// This can happen when we marked a region invalid, but didn't track
// an error for it.
- if (Errors.size() == 0)
+ if (!Log || !Log->hasErrors())
return "";
- RejectReasonPtr RR = *Errors.begin();
+ RejectReasonPtr RR = *Log->begin();
return RR->getMessage();
}
@@ -1093,7 +1090,7 @@ Region *ScopDetection::expandRegion(Region &R) {
while (ExpandedRegion) {
const auto &It = DetectionContextMap.insert(std::make_pair(
- ExpandedRegion.get(),
+ getBBPairForRegion(ExpandedRegion.get()),
DetectionContext(*ExpandedRegion, *AA, false /*verifying*/)));
DetectionContext &Context = It.first->second;
DEBUG(dbgs() << "\t\tTrying " << ExpandedRegion->getNameStr() << "\n");
@@ -1156,12 +1153,11 @@ unsigned ScopDetection::removeCachedResultsRecursively(const Region &R) {
void ScopDetection::removeCachedResults(const Region &R) {
ValidRegions.remove(&R);
- DetectionContextMap.erase(&R);
}
void ScopDetection::findScops(Region &R) {
- const auto &It = DetectionContextMap.insert(
- std::make_pair(&R, DetectionContext(R, *AA, false /*verifying*/)));
+ const auto &It = DetectionContextMap.insert(std::make_pair(
+ getBBPairForRegion(&R), DetectionContext(R, *AA, false /*verifying*/)));
DetectionContext &Context = It.first->second;
bool RegionIsValid = false;
@@ -1172,9 +1168,6 @@ void ScopDetection::findScops(Region &R) {
bool HasErrors = !RegionIsValid || Context.Log.size() > 0;
- if (PollyTrackFailures && HasErrors)
- RejectLogs.insert(std::make_pair(&R, Context.Log));
-
if (HasErrors) {
removeCachedResults(R);
} else {
@@ -1198,16 +1191,16 @@ void ScopDetection::findScops(Region &R) {
ToExpand.push_back(SubRegion.get());
for (Region *CurrentRegion : ToExpand) {
- // Skip regions that had errors.
- bool HadErrors = RejectLogs.hasErrors(CurrentRegion);
- if (HadErrors)
- continue;
-
// Skip invalid regions. Regions may become invalid, if they are element of
// an already expanded region.
if (!ValidRegions.count(CurrentRegion))
continue;
+ // Skip regions that had errors.
+ bool HadErrors = lookupRejectionLog(CurrentRegion)->hasErrors();
+ if (HadErrors)
+ continue;
+
Region *ExpandedR = expandRegion(*CurrentRegion);
if (!ExpandedR)
@@ -1295,6 +1288,7 @@ bool ScopDetection::isProfitableRegion(DetectionContext &Context) const {
if (PollyProcessUnprofitable)
return true;
+ errs() << "Context: " << Context.CurRegion << "\n";
// We can probably not do a lot on scops that only write or only read
// data.
if (!Context.hasStores || !Context.hasLoads)
@@ -1382,29 +1376,11 @@ void ScopDetection::printLocations(llvm::Function &F) {
}
}
-void ScopDetection::emitMissedRemarksForValidRegions(const Function &F) {
- for (const Region *R : ValidRegions) {
- const Region *Parent = R->getParent();
- if (Parent && !Parent->isTopLevelRegion() && RejectLogs.count(Parent))
- emitRejectionRemarks(F, RejectLogs.at(Parent));
- }
-}
-
-void ScopDetection::emitMissedRemarksForLeaves(const Function &F,
- const Region *R) {
- for (const std::unique_ptr<Region> &Child : *R) {
- bool IsValid = DetectionContextMap.count(Child.get());
- if (IsValid)
- continue;
-
- bool IsLeaf = Child->begin() == Child->end();
- if (!IsLeaf)
- emitMissedRemarksForLeaves(F, Child.get());
- else {
- if (RejectLogs.count(Child.get())) {
- emitRejectionRemarks(F, RejectLogs.at(Child.get()));
- }
- }
+void ScopDetection::emitMissedRemarks(const Function &F) {
+ for (auto &DIt : DetectionContextMap) {
+ auto &DC = DIt.getSecond();
+ if (DC.Log.hasErrors())
+ emitRejectionRemarks(DIt.getFirst(), DC.Log);
}
}
@@ -1497,15 +1473,13 @@ bool ScopDetection::runOnFunction(llvm::Function &F) {
findScops(*TopRegion);
// Only makes sense when we tracked errors.
- if (PollyTrackFailures) {
- emitMissedRemarksForValidRegions(F);
- emitMissedRemarksForLeaves(F, TopRegion);
- }
+ if (PollyTrackFailures)
+ emitMissedRemarks(F);
if (ReportLevel)
printLocations(F);
- assert(ValidRegions.size() == DetectionContextMap.size() &&
+ assert(ValidRegions.size() <= DetectionContextMap.size() &&
"Cached more results than valid regions");
return false;
}
@@ -1519,7 +1493,7 @@ bool ScopDetection::isNonAffineSubRegion(const Region *SubR,
const ScopDetection::DetectionContext *
ScopDetection::getDetectionContext(const Region *R) const {
- auto DCMIt = DetectionContextMap.find(R);
+ auto DCMIt = DetectionContextMap.find(getBBPairForRegion(R));
if (DCMIt == DetectionContextMap.end())
return nullptr;
return &DCMIt->second;
@@ -1546,6 +1520,11 @@ ScopDetection::getRequiredInvariantLoads(const Region *R) const {
return &DC->RequiredILS;
}
+const RejectLog *ScopDetection::lookupRejectionLog(const Region *R) const {
+ const DetectionContext *DC = getDetectionContext(R);
+ return DC ? &DC->Log : nullptr;
+}
+
void polly::ScopDetection::verifyRegion(const Region &R) const {
assert(isMaxRegionInScop(R) && "Expect R is a valid region.");
@@ -1579,7 +1558,6 @@ void ScopDetection::print(raw_ostream &OS, const Module *) const {
}
void ScopDetection::releaseMemory() {
- RejectLogs.clear();
ValidRegions.clear();
DetectionContextMap.clear();
OpenPOWER on IntegriCloud