1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 03:33:20 +01:00

Merge isReachable into isBackedge.

Prefer using RPO.lookup() instead of RPO[] which can mutate the map.

llvm-svn: 184891
This commit is contained in:
Jakob Stoklund Olesen 2013-06-25 23:32:10 +00:00
parent a8fba65221
commit 105986a600

View File

@ -123,7 +123,7 @@ class BlockFrequencyImpl {
rpot_iterator rpot_at(BlockT *BB) { rpot_iterator rpot_at(BlockT *BB) {
rpot_iterator I = rpot_begin(); rpot_iterator I = rpot_begin();
unsigned idx = RPO[BB]; unsigned idx = RPO.lookup(BB);
assert(idx); assert(idx);
std::advance(I, idx - 1); std::advance(I, idx - 1);
@ -131,22 +131,14 @@ class BlockFrequencyImpl {
return I; return I;
} }
/// isBackedge - Return if edge Src -> Dst is a reachable backedge.
/// isReachable - Returns if BB block is reachable from the entry.
///
bool isReachable(BlockT *BB) {
return RPO.count(BB);
}
/// isBackedge - Return if edge Src -> Dst is a backedge.
/// ///
bool isBackedge(BlockT *Src, BlockT *Dst) { bool isBackedge(BlockT *Src, BlockT *Dst) {
assert(isReachable(Src)); unsigned a = RPO.lookup(Src);
assert(isReachable(Dst)); if (!a)
return false;
unsigned a = RPO[Src]; unsigned b = RPO.lookup(Dst);
unsigned b = RPO[Dst]; assert(b && "Destination block should be reachable");
return a >= b; return a >= b;
} }
@ -196,7 +188,7 @@ class BlockFrequencyImpl {
PI != PE; ++PI) { PI != PE; ++PI) {
BlockT *Pred = *PI; BlockT *Pred = *PI;
if (isReachable(Pred) && isBackedge(Pred, BB)) { if (isBackedge(Pred, BB)) {
isLoopHead = true; isLoopHead = true;
} else if (BlocksInLoop.count(Pred)) { } else if (BlocksInLoop.count(Pred)) {
incBlockFreq(BB, getEdgeFreq(Pred, BB)); incBlockFreq(BB, getEdgeFreq(Pred, BB));
@ -240,7 +232,7 @@ class BlockFrequencyImpl {
PI != PE; ++PI) { PI != PE; ++PI) {
BlockT *Pred = *PI; BlockT *Pred = *PI;
assert(Pred); assert(Pred);
if (isReachable(Pred) && isBackedge(Pred, Head)) { if (isBackedge(Pred, Head)) {
uint64_t N = getEdgeFreq(Pred, Head).getFrequency(); uint64_t N = getEdgeFreq(Pred, Head).getFrequency();
uint64_t D = getBlockFreq(Head).getFrequency(); uint64_t D = getBlockFreq(Head).getFrequency();
assert(N <= EntryFreq && "Backedge frequency must be <= EntryFreq!"); assert(N <= EntryFreq && "Backedge frequency must be <= EntryFreq!");
@ -292,8 +284,7 @@ class BlockFrequencyImpl {
PI != PE; ++PI) { PI != PE; ++PI) {
BlockT *Pred = *PI; BlockT *Pred = *PI;
if (isReachable(Pred) && isBackedge(Pred, BB) if (isBackedge(Pred, BB) && (!LastTail || RPO[Pred] > RPO[LastTail]))
&& (!LastTail || RPO[Pred] > RPO[LastTail]))
LastTail = Pred; LastTail = Pred;
} }