Skip to content

Commit d310338

Browse files
committed
C++: Implement dominanceFrontier with recursion
This implementation is borrowed from Java's QL library and offers a great performance improvement. For example, on Wireshark the performance goes from Dominance::bbDominates#ff ....... 40.3s SSAUtils::dominanceFrontier#ff .. 30s to SSAUtils::dominanceFrontier#ff .. 418ms (executed 67 times) The big performance problem before was the need to materialize `bbDominates`, which is the reflexive-transitive "basic block dominates" relation. It had 79 million rows on Wireshark.
1 parent a3f452b commit d310338

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

cpp/ql/src/semmle/code/cpp/controlflow/SSAUtils.qll

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,19 @@ import semmle.code.cpp.controlflow.SSA // must be imported for proper caching of
44
import semmle.code.cpp.rangeanalysis.RangeSSA // must be imported for proper caching of SSAHelper
55

66
/* The dominance frontier of a block `x` is the set of all blocks `w` such that
7-
* `x` dominates a predecessor of `w` but does not strictly dominate `w`. */
8-
pragma[noinline]
7+
* `x` dominates a predecessor of `w` but does not strictly dominate `w`.
8+
*
9+
* This implementation is equivalent to:
10+
*
11+
* bbDominates(x, w.getAPredecessor()) and not bbStrictlyDominates(x, w)
12+
*/
913
private predicate dominanceFrontier(BasicBlock x, BasicBlock w) {
10-
bbDominates(x, w.getAPredecessor()) and not bbStrictlyDominates(x, w)
14+
x = w.getAPredecessor() and not bbIDominates(x, w)
15+
or
16+
exists(BasicBlock prev | dominanceFrontier(prev, w) |
17+
bbIDominates(x, prev) and
18+
not bbIDominates(x, w)
19+
)
1120
}
1221

1322
/**

0 commit comments

Comments
 (0)