Skip to content

Commit 0990ceb

Browse files
committed
C++: Remove bbNotInLoop and its caller in FlowVar
This change is needed when enabling the QL CFG on certain snapshots such as notaz/picodrive. It removes the `bbNotInLoop` predicate, which was always a liability because it's inherently quadratic. The real slowdown came in `skipLoop`, where all true-upon-entry loops were crossed with all definitions of variables that should take their definition from the loop body.
1 parent eed24f1 commit 0990ceb

File tree

1 file changed

+12
-13
lines changed
  • cpp/ql/src/semmle/code/cpp/dataflow/internal

1 file changed

+12
-13
lines changed

cpp/ql/src/semmle/code/cpp/dataflow/internal/FlowVar.qll

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -513,9 +513,9 @@ module FlowVar_internal {
513513
bbInLoopCondition(bb)
514514
}
515515

516-
predicate bbNotInLoop(BasicBlock bb) {
517-
not this.bbInLoop(bb) and
518-
bb.getEnclosingFunction() = this.getEnclosingFunction()
516+
/** Holds if `sbb` is inside this loop. */
517+
predicate sbbInLoop(SubBasicBlock sbb) {
518+
this.bbInLoop(sbb.getBasicBlock())
519519
}
520520

521521
/**
@@ -537,22 +537,19 @@ module FlowVar_internal {
537537
}
538538

539539
/**
540-
* Holds if some loop always assigns to `v` before leaving through an edge
541-
* from `bbInside` in its condition to `bbOutside` outside the loop, where
542-
* (`sbbDef`, `v`) is a `BlockVar` defined outside the loop. Also, `v` must
543-
* be used outside the loop.
540+
* Holds if `loop` always assigns to `v` before leaving through an edge
541+
* from `bbInside` in its condition to `bbOutside` outside the loop. Also,
542+
* `v` must be used outside the loop.
544543
*/
545544
predicate skipLoop(
546-
SubBasicBlock sbbInside, SubBasicBlock sbbOutside, SubBasicBlock sbbDef, Variable v
545+
SubBasicBlock sbbInside, SubBasicBlock sbbOutside, Variable v, AlwaysTrueUponEntryLoop loop
547546
) {
548-
exists(AlwaysTrueUponEntryLoop loop, BasicBlock bbInside, BasicBlock bbOutside |
547+
exists(BasicBlock bbInside, BasicBlock bbOutside |
549548
loop.alwaysAssignsBeforeLeavingCondition(bbInside, bbOutside, v) and
550549
bbInside = sbbInside.getBasicBlock() and
551550
bbOutside = sbbOutside.getBasicBlock() and
552551
sbbInside.lastInBB() and
553-
sbbOutside.firstInBB() and
554-
loop.bbNotInLoop(sbbDef.getBasicBlock()) and
555-
exists(TBlockVar(sbbDef, v))
552+
sbbOutside.firstInBB()
556553
)
557554
}
558555

@@ -571,7 +568,9 @@ module FlowVar_internal {
571568
start = TBlockVar(sbbDef, v) and
572569
result = mid.getASuccessor() and
573570
variableLiveInSBB(result, v) and
574-
not skipLoop(mid, result, sbbDef, v) and
571+
forall(AlwaysTrueUponEntryLoop loop | skipLoop(mid, result, v, loop) |
572+
loop.sbbInLoop(sbbDef)
573+
) and
575574
not assignmentLikeOperation(result, v, _, _)
576575
)
577576
}

0 commit comments

Comments
 (0)