Skip to content

Commit 5e67482

Browse files
committed
C++: Optimize SubBasicBlock::getPosInBasicBlock()
1 parent d4f1cf9 commit 5e67482

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,18 @@ class SubBasicBlock extends ControlFlowNodeBase {
7575
* `bb`, where `bb` is equal to `getBasicBlock()`.
7676
*/
7777
int getPosInBasicBlock(BasicBlock bb) {
78-
exists(int nodePos, int rnk |
79-
this = bb.getNode(nodePos) and
80-
nodePos = rank[rnk](int i | exists(SubBasicBlock n | n = bb.getNode(i))) and
78+
exists(int thisIndexInBB, int rnk |
79+
thisIndexInBB = this.getIndexInBasicBlock(bb) and
80+
thisIndexInBB = rank[rnk](int i | i = any(SubBasicBlock n).getIndexInBasicBlock(bb)) and
8181
result = rnk - 1
8282
)
8383
}
8484

85+
pragma[noinline]
86+
private int getIndexInBasicBlock(BasicBlock bb) {
87+
this = bb.getNode(result)
88+
}
89+
8590
/** Gets a successor in the control-flow graph of `SubBasicBlock`s. */
8691
SubBasicBlock getASuccessor() {
8792
this.lastInBB() and
@@ -109,10 +114,8 @@ class SubBasicBlock extends ControlFlowNodeBase {
109114

110115
pragma[nomagic]
111116
private int outerPosToInnerPos(BasicBlock bb, int posInBB) {
112-
exists(int thisPosInBB | this = bb.getNode(thisPosInBB) |
113-
posInBB = result + thisPosInBB and
114-
result = [ 0 .. this.getNumberOfNodes() - 1 ]
115-
)
117+
posInBB = result + this.getIndexInBasicBlock(bb) and
118+
result = [ 0 .. this.getNumberOfNodes() - 1 ]
116119
}
117120

118121
/** Gets a control-flow node in this `SubBasicBlock`. */

0 commit comments

Comments
 (0)