forked from OSchip/llvm-project
[analyzer; alternate arrows] don't increment the path iterator when we just deleted the next iterator.
This is an optimization. It is possible that by deleting the next edge we will pattern match again at the current spot. llvm-svn: 181256
This commit is contained in:
parent
18ee1193bf
commit
9af6baaaa3
|
@ -1798,16 +1798,19 @@ static bool optimizeEdges(PathPieces &path, SourceManager &SM,
|
||||||
assert(LC);
|
assert(LC);
|
||||||
bool isFirst = true;
|
bool isFirst = true;
|
||||||
|
|
||||||
for (PathPieces::iterator I = path.begin(), E = path.end(); I != E; ++I) {
|
for (PathPieces::iterator I = path.begin(), E = path.end(); I != E; ) {
|
||||||
bool wasFirst = isFirst;
|
bool wasFirst = isFirst;
|
||||||
isFirst = false;
|
isFirst = false;
|
||||||
|
|
||||||
// Optimize subpaths.
|
// Optimize subpaths.
|
||||||
if (PathDiagnosticCallPiece *CallI = dyn_cast<PathDiagnosticCallPiece>(*I)){
|
if (PathDiagnosticCallPiece *CallI = dyn_cast<PathDiagnosticCallPiece>(*I)){
|
||||||
|
// Record the fact that a call has been optimized so we only do the
|
||||||
|
// effort once.
|
||||||
if (!OCS.count(CallI)) {
|
if (!OCS.count(CallI)) {
|
||||||
while (optimizeEdges(CallI->path, SM, CFBS, OCS, LCM)) {}
|
while (optimizeEdges(CallI->path, SM, CFBS, OCS, LCM)) {}
|
||||||
OCS.insert(CallI);
|
OCS.insert(CallI);
|
||||||
}
|
}
|
||||||
|
++I;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1815,8 +1818,10 @@ static bool optimizeEdges(PathPieces &path, SourceManager &SM,
|
||||||
PathDiagnosticControlFlowPiece *PieceI =
|
PathDiagnosticControlFlowPiece *PieceI =
|
||||||
dyn_cast<PathDiagnosticControlFlowPiece>(*I);
|
dyn_cast<PathDiagnosticControlFlowPiece>(*I);
|
||||||
|
|
||||||
if (!PieceI)
|
if (!PieceI) {
|
||||||
|
++I;
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
ParentMap &PM = LC->getParentMap();
|
ParentMap &PM = LC->getParentMap();
|
||||||
const Stmt *s1Start = getLocStmt(PieceI->getStartLocation());
|
const Stmt *s1Start = getLocStmt(PieceI->getStartLocation());
|
||||||
|
@ -1852,8 +1857,10 @@ static bool optimizeEdges(PathPieces &path, SourceManager &SM,
|
||||||
PathDiagnosticControlFlowPiece *PieceNextI =
|
PathDiagnosticControlFlowPiece *PieceNextI =
|
||||||
dyn_cast<PathDiagnosticControlFlowPiece>(*NextI);
|
dyn_cast<PathDiagnosticControlFlowPiece>(*NextI);
|
||||||
|
|
||||||
if (!PieceNextI)
|
if (!PieceNextI) {
|
||||||
|
++I;
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
const Stmt *s2Start = getLocStmt(PieceNextI->getStartLocation());
|
const Stmt *s2Start = getLocStmt(PieceNextI->getStartLocation());
|
||||||
const Stmt *s2End = getLocStmt(PieceNextI->getEndLocation());
|
const Stmt *s2End = getLocStmt(PieceNextI->getEndLocation());
|
||||||
|
@ -1863,18 +1870,19 @@ static bool optimizeEdges(PathPieces &path, SourceManager &SM,
|
||||||
// Rule I.
|
// Rule I.
|
||||||
//
|
//
|
||||||
// If we have two consecutive control edges whose end/begin locations
|
// If we have two consecutive control edges whose end/begin locations
|
||||||
// are at the same level (i.e., parents), merge them.
|
// are at the same level (e.g. statements or top-level expressions within
|
||||||
|
// a compound statement, or siblings share a single ancestor expression),
|
||||||
|
// then merge them if they have no interesting intermediate event.
|
||||||
//
|
//
|
||||||
// For example:
|
// For example:
|
||||||
//
|
//
|
||||||
// (1.1 -> 1.2) -> (1.2 -> 1.3) becomes (1.1 -> 1.3) because the common
|
// (1.1 -> 1.2) -> (1.2 -> 1.3) becomes (1.1 -> 1.3) because the common
|
||||||
// parent is '1'. Here '1.1' represents the hierarchy of statements.
|
// parent is '1'. Here 'x.y.z' represents the hierarchy of statements.
|
||||||
//
|
//
|
||||||
// NOTE: this will be limited later in cases where we add barriers
|
// NOTE: this will be limited later in cases where we add barriers
|
||||||
// to prevent this optimization.
|
// to prevent this optimization.
|
||||||
//
|
//
|
||||||
if (!isBarrier(CFBS, PieceNextI) &&
|
if (level1 && level1 == level2 && level1 == level3 && level1 == level4) {
|
||||||
level1 && level1 == level2 && level1 == level3 && level1 == level4) {
|
|
||||||
PieceI->setEndLocation(PieceNextI->getEndLocation());
|
PieceI->setEndLocation(PieceNextI->getEndLocation());
|
||||||
path.erase(NextI);
|
path.erase(NextI);
|
||||||
hasChanges = true;
|
hasChanges = true;
|
||||||
|
@ -1892,8 +1900,7 @@ static bool optimizeEdges(PathPieces &path, SourceManager &SM,
|
||||||
// For example:
|
// For example:
|
||||||
//
|
//
|
||||||
// (1.1 -> 1.1.1) -> (1.1.1 -> 1.2) becomes (1.1 -> 1.2).
|
// (1.1 -> 1.1.1) -> (1.1.1 -> 1.2) becomes (1.1 -> 1.2).
|
||||||
if (!isBarrier(CFBS, PieceNextI) &&
|
if (level1 && level2 &&
|
||||||
level1 && level2 &&
|
|
||||||
level1 == level4 &&
|
level1 == level4 &&
|
||||||
level2 == level3 && PM.getParentIgnoreParens(level2) == level1) {
|
level2 == level3 && PM.getParentIgnoreParens(level2) == level1) {
|
||||||
PieceI->setEndLocation(PieceNextI->getEndLocation());
|
PieceI->setEndLocation(PieceNextI->getEndLocation());
|
||||||
|
@ -1914,8 +1921,7 @@ static bool optimizeEdges(PathPieces &path, SourceManager &SM,
|
||||||
//
|
//
|
||||||
// (1.1 -> 1.1.1) -> (1.1.1 -> X) becomes (1.1 -> X).
|
// (1.1 -> 1.1.1) -> (1.1.1 -> X) becomes (1.1 -> X).
|
||||||
//
|
//
|
||||||
if (!isBarrier(CFBS, PieceNextI) &&
|
if (level1 && level2 && level1 == PM.getParentIgnoreParens(level2)) {
|
||||||
level1 && level2 && level1 == PM.getParentIgnoreParens(level2)) {
|
|
||||||
PieceI->setEndLocation(PieceNextI->getEndLocation());
|
PieceI->setEndLocation(PieceNextI->getEndLocation());
|
||||||
path.erase(NextI);
|
path.erase(NextI);
|
||||||
hasChanges = true;
|
hasChanges = true;
|
||||||
|
@ -1935,8 +1941,7 @@ static bool optimizeEdges(PathPieces &path, SourceManager &SM,
|
||||||
// (X -> 1.1.1) -> (1.1.1 -> 1.1) becomes (X -> 1.1).
|
// (X -> 1.1.1) -> (1.1.1 -> 1.1) becomes (X -> 1.1).
|
||||||
// [first edge] (1.1.1 -> 1.1) -> eliminate
|
// [first edge] (1.1.1 -> 1.1) -> eliminate
|
||||||
//
|
//
|
||||||
if (!isBarrier(CFBS, PieceNextI) &&
|
if (level2 && level4 && level2 == level3 && level4 == PM.getParent(level2)){
|
||||||
level2 && level4 && level2 == level3 && level4 == PM.getParent(level2)){
|
|
||||||
PieceI->setEndLocation(PieceNextI->getEndLocation());
|
PieceI->setEndLocation(PieceNextI->getEndLocation());
|
||||||
path.erase(NextI);
|
path.erase(NextI);
|
||||||
hasChanges = true;
|
hasChanges = true;
|
||||||
|
@ -1965,8 +1970,12 @@ static bool optimizeEdges(PathPieces &path, SourceManager &SM,
|
||||||
hasChanges = true;
|
hasChanges = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// No changes at this index? Move to the next one.
|
||||||
|
++I;
|
||||||
}
|
}
|
||||||
|
|
||||||
// No changes.
|
// No changes.
|
||||||
|
|
Loading…
Reference in New Issue