Skip to content

Commit 4ac2225

Browse files
committed
C++: Speed up variableLiveOnEntryToBlock in IR
This predicate computed a local CP between all defs and uses of the same virtual variable in a basic block. This wasn't a problem in `unaliased_ssa`, but it became a huge problem in `aliased_ssa`, probably because many variables can be modelled with a single virtual variable there. Before this commit, evaluation of `aliased_ssa`'s `variableLiveOnEntryToBlock#ff#antijoin_rhs` on Wireshark took 80 _minutes_. After this commit, that predicate and its immediate dependencies take around 5 _seconds_.
1 parent 6243c72 commit 4ac2225

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/internal/SSAConstruction.qll

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,9 +392,15 @@ cached private module Cached {
392392
}
393393

394394
private predicate variableLiveOnEntryToBlock(Alias::VirtualVariable vvar, OldBlock block) {
395-
exists (int index | hasUse(vvar, _, block, index) |
396-
not exists (int j | ssa_variableUpdate(vvar, _, block, j) | j < index)
397-
) or
395+
exists(int firstAccess |
396+
hasUse(vvar, _, block, firstAccess) and
397+
firstAccess = min(int index |
398+
hasUse(vvar, _, block, index)
399+
or
400+
ssa_variableUpdate(vvar, _, block, index)
401+
)
402+
)
403+
or
398404
(variableLiveOnExitFromBlock(vvar, block) and not ssa_variableUpdate(vvar, _, block, _))
399405
}
400406

cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/internal/SSAConstruction.qll

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,9 +392,15 @@ cached private module Cached {
392392
}
393393

394394
private predicate variableLiveOnEntryToBlock(Alias::VirtualVariable vvar, OldBlock block) {
395-
exists (int index | hasUse(vvar, _, block, index) |
396-
not exists (int j | ssa_variableUpdate(vvar, _, block, j) | j < index)
397-
) or
395+
exists(int firstAccess |
396+
hasUse(vvar, _, block, firstAccess) and
397+
firstAccess = min(int index |
398+
hasUse(vvar, _, block, index)
399+
or
400+
ssa_variableUpdate(vvar, _, block, index)
401+
)
402+
)
403+
or
398404
(variableLiveOnExitFromBlock(vvar, block) and not ssa_variableUpdate(vvar, _, block, _))
399405
}
400406

0 commit comments

Comments
 (0)