5
5
6
6
private import SsaImplSpecific
7
7
8
+ private BasicBlock getABasicBlockPredecessor ( BasicBlock bb ) { getABasicBlockSuccessor ( result ) = bb }
9
+
8
10
cached
9
11
private module Cached {
10
12
/**
@@ -109,7 +111,7 @@ private module Cached {
109
111
* The read that witnesses the liveness of `v` is of kind `rk`.
110
112
*/
111
113
predicate liveAtExit ( BasicBlock bb , SourceVariable v , ReadKind rk ) {
112
- liveAtEntry ( bb . getASuccessor ( ) , v , rk )
114
+ liveAtEntry ( getABasicBlockSuccessor ( bb ) , v , rk )
113
115
}
114
116
115
117
/**
@@ -144,6 +146,26 @@ private module Cached {
144
146
145
147
private import Liveness
146
148
149
+ /** Holds if `bb1` strictly dominates `bb2`. */
150
+ private predicate strictlyDominates ( BasicBlock bb1 , BasicBlock bb2 ) {
151
+ bb1 = getImmediateBasicBlockDominator + ( bb2 )
152
+ }
153
+
154
+ /** Holds if `bb1` dominates a predecessor of `bb2`. */
155
+ private predicate dominatesPredecessor ( BasicBlock bb1 , BasicBlock bb2 ) {
156
+ exists ( BasicBlock pred | pred = getABasicBlockPredecessor ( bb2 ) |
157
+ bb1 = pred
158
+ or
159
+ strictlyDominates ( bb1 , pred )
160
+ )
161
+ }
162
+
163
+ /** Holds if `df` is in the dominance frontier of `bb`. */
164
+ private predicate inDominanceFrontier ( BasicBlock bb , BasicBlock df ) {
165
+ dominatesPredecessor ( bb , df ) and
166
+ not strictlyDominates ( bb , df )
167
+ }
168
+
147
169
/**
148
170
* Holds if `bb` is in the dominance frontier of a block containing a
149
171
* definition of `v`.
@@ -152,7 +174,7 @@ private module Cached {
152
174
private predicate inDefDominanceFrontier ( BasicBlock bb , SourceVariable v ) {
153
175
exists ( BasicBlock defbb , Definition def |
154
176
def .definesAt ( v , defbb , _) and
155
- defbb . inDominanceFrontier ( bb )
177
+ inDominanceFrontier ( defbb , bb )
156
178
)
157
179
}
158
180
@@ -311,7 +333,7 @@ private module Cached {
311
333
312
334
pragma [ noinline]
313
335
private BasicBlock getAMaybeLiveSuccessor ( Definition def , BasicBlock bb ) {
314
- result = bb . getASuccessor ( ) and
336
+ result = getABasicBlockSuccessor ( bb ) and
315
337
not defOccursInBlock ( _, bb , def .getSourceVariable ( ) ) and
316
338
ssaDefReachesEndOfBlock ( bb , def , _)
317
339
}
@@ -324,7 +346,7 @@ private module Cached {
324
346
*/
325
347
predicate varBlockReaches ( Definition def , BasicBlock bb1 , BasicBlock bb2 ) {
326
348
defOccursInBlock ( def , bb1 , _) and
327
- bb2 = bb1 . getASuccessor ( )
349
+ bb2 = getABasicBlockSuccessor ( bb1 )
328
350
or
329
351
exists ( BasicBlock mid | varBlockReaches ( def , bb1 , mid ) |
330
352
bb2 = getAMaybeLiveSuccessor ( def , mid )
@@ -355,7 +377,7 @@ private module Cached {
355
377
// the node. If two definitions dominate a node then one must dominate the
356
378
// other, so therefore the definition of _closest_ is given by the dominator
357
379
// tree. Thus, reaching definitions can be calculated in terms of dominance.
358
- idom = getImmediateDominator ( bb )
380
+ idom = getImmediateBasicBlockDominator ( bb )
359
381
)
360
382
}
361
383
@@ -386,7 +408,7 @@ private module Cached {
386
408
ssaDefReachesReadWithinBlock ( v , def , bb , i , rk )
387
409
or
388
410
variableRead ( bb , i , v , rk ) and
389
- ssaDefReachesEndOfBlock ( bb . getAPredecessor ( ) , def , v ) and
411
+ ssaDefReachesEndOfBlock ( getABasicBlockPredecessor ( bb ) , def , v ) and
390
412
not ssaDefReachesReadWithinBlock ( v , _, bb , i , _)
391
413
}
392
414
@@ -402,7 +424,7 @@ private module Cached {
402
424
or
403
425
exists ( BasicBlock bb |
404
426
redef .definesAt ( v , bb , _) and
405
- ssaDefReachesEndOfBlock ( bb . getAPredecessor ( ) , def , v ) and
427
+ ssaDefReachesEndOfBlock ( getABasicBlockPredecessor ( bb ) , def , v ) and
406
428
not ssaDefReachesUncertainDefWithinBlock ( v , _, redef )
407
429
)
408
430
}
@@ -526,15 +548,15 @@ class PhiNode extends Definition, TPhiNode {
526
548
Definition getAnInput ( ) {
527
549
exists ( BasicBlock bb , BasicBlock pred , SourceVariable v |
528
550
this .definesAt ( v , bb , _) and
529
- bb . getAPredecessor ( ) = pred and
551
+ getABasicBlockPredecessor ( bb ) = pred and
530
552
ssaDefReachesEndOfBlock ( pred , result , v )
531
553
)
532
554
}
533
555
534
556
/** Holds if `inp` is an input to the phi node along the edge originating in `bb`. */
535
557
predicate hasInputFromBlock ( Definition inp , BasicBlock bb ) {
536
558
inp = this .getAnInput ( ) and
537
- this .getBasicBlock ( ) . getAPredecessor ( ) = bb and
559
+ getABasicBlockPredecessor ( this .getBasicBlock ( ) ) = bb and
538
560
ssaDefReachesEndOfBlock ( bb , inp , _)
539
561
}
540
562
0 commit comments