C++: Optimize SubBasicBlock::getNode(int)

This commit is contained in:
Jonas Jensen
2019-08-26 12:22:07 +02:00
parent be24c6418b
commit d4f1cf97fd

View File

@@ -97,16 +97,24 @@ class SubBasicBlock extends ControlFlowNodeBase {
* start from 0, and the node at position 0 always exists and compares equal
* to `this`.
*/
pragma[nomagic]
ControlFlowNode getNode(int pos) {
exists(BasicBlock bb | bb = this.getBasicBlock() |
exists(int thisPos | this = bb.getNode(thisPos) |
result = bb.getNode(thisPos + pos) and
pos >= 0 and
pos < this.getNumberOfNodes()
exists(BasicBlock bb |
exists(int outerPos |
result = bb.getNode(outerPos) and
pos = outerPosToInnerPos(bb, outerPos)
)
)
}
pragma[nomagic]
private int outerPosToInnerPos(BasicBlock bb, int posInBB) {
exists(int thisPosInBB | this = bb.getNode(thisPosInBB) |
posInBB = result + thisPosInBB and
result = [ 0 .. this.getNumberOfNodes() - 1 ]
)
}
/** Gets a control-flow node in this `SubBasicBlock`. */
ControlFlowNode getANode() {
result = this.getNode(_)