Skip to content

Commit 7e441d9

Browse files
committed
SSA: Fold getImmediateBasicBlockDominator into loop-invariant predicate.
1 parent 77ccff6 commit 7e441d9

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

shared/ssa/codeql/ssa/Ssa.qll

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,13 @@ module Make<LocationSig Location, InputSig<Location> Input> {
424424
rnk = ssaRefRank(bb, _, v, SsaActualRead())
425425
}
426426

427+
/**
428+
* Holds if `v` is live at the end of basic block `bb` with the same value as at
429+
* the end of the immediate dominator, `idom`, of `bb`.
430+
*/
427431
pragma[nomagic]
428-
private predicate liveThrough(BasicBlock bb, SourceVariable v) {
432+
private predicate liveThrough(BasicBlock idom, BasicBlock bb, SourceVariable v) {
433+
idom = getImmediateBasicBlockDominator(bb) and
429434
liveAtExit(bb, v) and
430435
not ssaRef(bb, _, v, SsaDef())
431436
}
@@ -443,14 +448,16 @@ module Make<LocationSig Location, InputSig<Location> Input> {
443448
liveAtExit(bb, v)
444449
)
445450
or
446-
// The construction of SSA form ensures that each read of a variable is
447-
// dominated by its definition. An SSA definition therefore reaches a
448-
// control flow node if it is the _closest_ SSA definition that dominates
449-
// the node. If two definitions dominate a node then one must dominate the
450-
// other, so therefore the definition of _closest_ is given by the dominator
451-
// tree. Thus, reaching definitions can be calculated in terms of dominance.
452-
ssaDefReachesEndOfBlock(getImmediateBasicBlockDominator(bb), def, pragma[only_bind_into](v)) and
453-
liveThrough(bb, pragma[only_bind_into](v))
451+
exists(BasicBlock idom |
452+
// The construction of SSA form ensures that each read of a variable is
453+
// dominated by its definition. An SSA definition therefore reaches a
454+
// control flow node if it is the _closest_ SSA definition that dominates
455+
// the node. If two definitions dominate a node then one must dominate the
456+
// other, so therefore the definition of _closest_ is given by the dominator
457+
// tree. Thus, reaching definitions can be calculated in terms of dominance.
458+
ssaDefReachesEndOfBlock(idom, def, v) and
459+
liveThrough(idom, bb, v)
460+
)
454461
}
455462

456463
/**

0 commit comments

Comments
 (0)