@@ -51,16 +51,6 @@ signature module InputSig<LocationSig Location> {
5151module Make< LocationSig Location, InputSig< Location > Input> {
5252 private import Input
5353
54- private Node nodeGetAPredecessor ( Node node , SuccessorType s ) {
55- nodeGetASuccessor ( result , s ) = node
56- }
57-
58- /** Holds if this node has more than one predecessor. */
59- private predicate nodeIsJoin ( Node node ) { strictcount ( nodeGetAPredecessor ( node , _) ) > 1 }
60-
61- /** Holds if this node has more than one successor. */
62- private predicate nodeIsBranch ( Node node ) { strictcount ( nodeGetASuccessor ( node , _) ) > 1 }
63-
6454 /**
6555 * A basic block, that is, a maximal straight-line sequence of control flow nodes
6656 * without branches or joins.
@@ -76,9 +66,7 @@ module Make<LocationSig Location, InputSig<Location> Input> {
7666 BasicBlock getASuccessor ( ) { result = this .getASuccessor ( _) }
7767
7868 /** Gets an immediate successor of this basic block of a given type, if any. */
79- BasicBlock getASuccessor ( SuccessorType t ) {
80- result .getFirstNode ( ) = nodeGetASuccessor ( this .getLastNode ( ) , t )
81- }
69+ BasicBlock getASuccessor ( SuccessorType t ) { bbSuccessor ( this , result , t ) }
8270
8371 /** Gets an immediate predecessor of this basic block, if any. */
8472 BasicBlock getAPredecessor ( ) { result .getASuccessor ( _) = this }
@@ -287,6 +275,16 @@ module Make<LocationSig Location, InputSig<Location> Input> {
287275
288276 cached
289277 private module Cached {
278+ private Node nodeGetAPredecessor ( Node node , SuccessorType s ) {
279+ nodeGetASuccessor ( result , s ) = node
280+ }
281+
282+ /** Holds if this node has more than one predecessor. */
283+ private predicate nodeIsJoin ( Node node ) { strictcount ( nodeGetAPredecessor ( node , _) ) > 1 }
284+
285+ /** Holds if this node has more than one successor. */
286+ private predicate nodeIsBranch ( Node node ) { strictcount ( nodeGetASuccessor ( node , _) ) > 1 }
287+
290288 /**
291289 * Internal representation of basic blocks. A basic block is represented
292290 * by its first CFG node.
@@ -343,11 +341,19 @@ module Make<LocationSig Location, InputSig<Location> Input> {
343341 cached
344342 Node getNode ( BasicBlock bb , int pos ) { bbIndex ( bb .getFirstNode ( ) , result , pos ) }
345343
344+ /** Holds if `bb` is an entry basic block. */
345+ private predicate entryBB ( BasicBlock bb ) { nodeIsDominanceEntry ( bb .getFirstNode ( ) ) }
346+
347+ cached
348+ predicate bbSuccessor ( BasicBlock bb1 , BasicBlock bb2 , SuccessorType t ) {
349+ bb2 .getFirstNode ( ) = nodeGetASuccessor ( bb1 .getLastNode ( ) , t )
350+ }
351+
346352 /**
347353 * Holds if the first node of basic block `succ` is a control flow
348354 * successor of the last node of basic block `pred`.
349355 */
350- private predicate succBB ( BasicBlock pred , BasicBlock succ ) { pred . getASuccessor ( _ ) = succ }
356+ private predicate succBB ( BasicBlock pred , BasicBlock succ ) { bbSuccessor ( pred , succ , _ ) }
351357
352358 /** Holds if `dom` is an immediate dominator of `bb`. */
353359 cached
@@ -367,7 +373,4 @@ module Make<LocationSig Location, InputSig<Location> Input> {
367373 }
368374
369375 private import Cached
370-
371- /** Holds if `bb` is an entry basic block. */
372- private predicate entryBB ( BasicBlock bb ) { nodeIsDominanceEntry ( bb .getFirstNode ( ) ) }
373376}
0 commit comments