@@ -490,26 +490,11 @@ private module Cached {
490490 )
491491 }
492492
493- pragma [ nomagic]
494- private predicate captureDefReaches ( Definition def , SsaInput:: BasicBlock bb2 , int i2 ) {
495- variableCapture ( def .getSourceVariable ( ) , _, _, _) and
496- exists ( SsaInput:: BasicBlock bb1 , int i1 |
497- Impl:: adjacentDefRead ( def , bb1 , i1 , bb2 , i2 ) and
498- def .definesAt ( _, bb1 , i1 )
499- )
500- or
501- exists ( SsaInput:: BasicBlock bb3 , int i3 |
502- captureDefReaches ( def , bb3 , i3 ) and
503- SsaInput:: variableRead ( bb3 , i3 , _, _) and
504- Impl:: adjacentDefRead ( def , bb3 , i3 , bb2 , i2 )
505- )
506- }
507-
508493 /** Holds if `init` is a closure variable that captures the value of `capturedvar`. */
509494 cached
510495 predicate captures ( SsaImplicitInit init , SsaVariable capturedvar ) {
511496 exists ( BasicBlock bb , int i |
512- captureDefReaches ( capturedvar , bb , i ) and
497+ Impl :: ssaDefReachesRead ( _ , capturedvar , bb , i ) and
513498 variableCapture ( capturedvar .getSourceVariable ( ) , init .getSourceVariable ( ) , bb , i )
514499 )
515500 }
@@ -523,34 +508,15 @@ private module Cached {
523508 Impl:: uncertainWriteDefinitionInput ( redef , def )
524509 }
525510
526- pragma [ nomagic]
527- private predicate defReaches ( Definition def , DataFlowIntegration:: Node node ) {
528- exists ( DataFlowIntegration:: SsaDefinitionExtNode nodeFrom |
529- nodeFrom .getDefinitionExt ( ) = def and
530- DataFlowIntegrationImpl:: localFlowStep ( _, nodeFrom , node , false )
531- )
532- or
533- exists ( DataFlowIntegration:: Node mid |
534- defReaches ( def , mid ) and
535- DataFlowIntegrationImpl:: localFlowStep ( _, mid , node , _)
536- |
537- // flow into phi input node
538- mid instanceof DataFlowIntegration:: SsaInputNode
539- or
540- // flow into definition
541- mid instanceof DataFlowIntegration:: SsaDefinitionExtNode
542- )
543- }
544-
545511 /**
546512 * Holds if the value defined at `def` can reach `use` without passing through
547513 * any other uses, but possibly through phi nodes and uncertain implicit updates.
548514 */
549515 cached
550516 predicate firstUse ( Definition def , VarRead use ) {
551- exists ( DataFlowIntegration :: ExprNode nodeTo |
552- nodeTo . getExpr ( ) = use and
553- defReaches ( def , nodeTo )
517+ exists ( BasicBlock bb , int i |
518+ Impl :: firstUse ( def , bb , i , _ ) and
519+ use . getControlFlowNode ( ) = bb . getNode ( i )
554520 )
555521 }
556522
@@ -609,40 +575,17 @@ private module Cached {
609575
610576 cached
611577 module SsaPublic {
612- pragma [ nomagic]
613- private predicate useReaches ( VarRead use , DataFlowIntegration:: Node node , boolean sameVar ) {
614- exists ( DataFlowIntegration:: ExprNode nodeFrom |
615- nodeFrom .getExpr ( ) = use and
616- DataFlowIntegration:: localFlowStep ( _, nodeFrom , node , true ) and
617- sameVar = true
618- )
619- or
620- exists ( DataFlowIntegration:: Node mid , boolean sameVarMid |
621- useReaches ( use , mid , sameVarMid ) and
622- DataFlowIntegration:: localFlowStep ( _, mid , node , _)
623- |
624- exists ( Impl:: DefinitionExt def |
625- // flow into definition
626- def = mid .( DataFlowIntegration:: SsaDefinitionExtNode ) .getDefinitionExt ( )
627- or
628- // flow into phi input node
629- def = mid .( DataFlowIntegration:: SsaInputNode ) .getDefinitionExt ( )
630- |
631- if def instanceof Impl:: PhiReadNode then sameVar = sameVarMid else sameVar = false
632- )
633- )
634- }
635-
636578 /**
637579 * Holds if `use1` and `use2` form an adjacent use-use-pair of the same SSA
638580 * variable, that is, the value read in `use1` can reach `use2` without passing
639581 * through any other use or any SSA definition of the variable.
640582 */
641583 cached
642584 predicate adjacentUseUseSameVar ( VarRead use1 , VarRead use2 ) {
643- exists ( DataFlowIntegration:: ExprNode nodeTo |
644- nodeTo .getExpr ( ) = use2 and
645- useReaches ( use1 , nodeTo , true )
585+ exists ( BasicBlock bb1 , int i1 , BasicBlock bb2 , int i2 |
586+ use1 .getControlFlowNode ( ) = bb1 .getNode ( i1 ) and
587+ use2 .getControlFlowNode ( ) = bb2 .getNode ( i2 ) and
588+ Impl:: adjacentUseUse ( bb1 , i1 , bb2 , i2 , _, true )
646589 )
647590 }
648591
@@ -654,9 +597,10 @@ private module Cached {
654597 */
655598 cached
656599 predicate adjacentUseUse ( VarRead use1 , VarRead use2 ) {
657- exists ( DataFlowIntegration:: ExprNode nodeTo |
658- nodeTo .getExpr ( ) = use2 and
659- useReaches ( use1 , nodeTo , _)
600+ exists ( BasicBlock bb1 , int i1 , BasicBlock bb2 , int i2 |
601+ use1 .getControlFlowNode ( ) = bb1 .getNode ( i1 ) and
602+ use2 .getControlFlowNode ( ) = bb2 .getNode ( i2 ) and
603+ Impl:: adjacentUseUse ( bb1 , i1 , bb2 , i2 , _, _)
660604 )
661605 }
662606 }
0 commit comments