Skip to content

Commit e2a001f

Browse files
authored
Merge pull request #285 from jbj/primitive-bb-joinorder
C++: Speed up primitive basic block calculation
2 parents 7691c0a + 11e03b3 commit e2a001f

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

cpp/ql/src/semmle/code/cpp/controlflow/internal/PrimitiveBasicBlocks.qll

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@ private cached module Cached {
3131
// or the node's predecessor has more than one successor,
3232
// then the node is the start of a new primitive basic block.
3333
or
34-
strictcount (Node pred, Node other
35-
| successors_extended(pred,node) and successors_extended(pred,other)) > 1
34+
strictcount(Node pred | successors_extended(pred, node)) > 1
35+
or
36+
exists(ControlFlowNode pred | successors_extended(pred, node) |
37+
strictcount(ControlFlowNode other | successors_extended(pred, other)) > 1
38+
)
3639

3740
// If the node has zero predecessors then it is the start of
3841
// a BB. However, the C++ AST contains many nodes with zero
@@ -63,8 +66,14 @@ private cached module Cached {
6366
/** Holds if `node` is the `pos`th control-flow node in primitive basic block `bb`. */
6467
cached
6568
predicate primitive_basic_block_member(Node node, PrimitiveBasicBlock bb, int pos) {
66-
pos = getMemberIndex(node) and
67-
member_step*(bb, node)
69+
primitive_basic_block_entry_node(bb) and
70+
(
71+
pos = 0 and
72+
node = bb
73+
or
74+
pos = getMemberIndex(node) and
75+
member_step+(bb, node)
76+
)
6877
}
6978

7079
/** Gets the number of control-flow nodes in the primitive basic block `bb`. */

0 commit comments

Comments
 (0)