Skip to content

Commit 2ede941

Browse files
authored
Merge pull request #1291 from jbj/backEdgeSuccessor-perf
Approved by dave-bartolomeo
2 parents 0ffba8b + 5fd425a commit 2ede941

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/IRBlock.qll

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,20 @@ private cached module Cached {
180180
)
181181
}
182182

183+
pragma[noinline]
184+
private predicate blockIdentity(TIRBlock b1, TIRBlock b2) { b1 = b2 }
185+
186+
pragma[noopt]
183187
cached predicate backEdgeSuccessor(TIRBlock pred, TIRBlock succ, EdgeKind kind) {
184188
backEdgeSuccessorRaw(pred, succ, kind)
185189
or
186-
forwardEdgeRaw+(pred, pred) and
190+
// See the QLDoc on `backEdgeSuccessorRaw`.
191+
exists(TIRBlock pred2 |
192+
// Joining with `blockIdentity` is a performance trick to get
193+
// `forwardEdgeRaw` on the RHS of a join, where it's fast.
194+
blockIdentity(pred, pred2) and
195+
forwardEdgeRaw+(pred, pred2)
196+
) and
187197
blockSuccessor(pred, succ, kind)
188198
}
189199

cpp/ql/src/semmle/code/cpp/ir/implementation/raw/IRBlock.qll

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,20 @@ private cached module Cached {
180180
)
181181
}
182182

183+
pragma[noinline]
184+
private predicate blockIdentity(TIRBlock b1, TIRBlock b2) { b1 = b2 }
185+
186+
pragma[noopt]
183187
cached predicate backEdgeSuccessor(TIRBlock pred, TIRBlock succ, EdgeKind kind) {
184188
backEdgeSuccessorRaw(pred, succ, kind)
185189
or
186-
forwardEdgeRaw+(pred, pred) and
190+
// See the QLDoc on `backEdgeSuccessorRaw`.
191+
exists(TIRBlock pred2 |
192+
// Joining with `blockIdentity` is a performance trick to get
193+
// `forwardEdgeRaw` on the RHS of a join, where it's fast.
194+
blockIdentity(pred, pred2) and
195+
forwardEdgeRaw+(pred, pred2)
196+
) and
187197
blockSuccessor(pred, succ, kind)
188198
}
189199

cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/IRBlock.qll

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,20 @@ private cached module Cached {
180180
)
181181
}
182182

183+
pragma[noinline]
184+
private predicate blockIdentity(TIRBlock b1, TIRBlock b2) { b1 = b2 }
185+
186+
pragma[noopt]
183187
cached predicate backEdgeSuccessor(TIRBlock pred, TIRBlock succ, EdgeKind kind) {
184188
backEdgeSuccessorRaw(pred, succ, kind)
185189
or
186-
forwardEdgeRaw+(pred, pred) and
190+
// See the QLDoc on `backEdgeSuccessorRaw`.
191+
exists(TIRBlock pred2 |
192+
// Joining with `blockIdentity` is a performance trick to get
193+
// `forwardEdgeRaw` on the RHS of a join, where it's fast.
194+
blockIdentity(pred, pred2) and
195+
forwardEdgeRaw+(pred, pred2)
196+
) and
187197
blockSuccessor(pred, succ, kind)
188198
}
189199

0 commit comments

Comments
 (0)