예제 #1
0
 /**
  * @covers ::isLiveVar
  */
 public function testIsLiveVarWithCycleAndLaterValue()
 {
     $graph = new DirectedAdjacencyList();
     $var = new Variable();
     $vertex = $this->getMock(Vertex::class);
     $graph->ensureVertex($vertex);
     $vertex->expects($this->once())->method('getVariables')->will($this->returnValue([]));
     $v1 = $this->getMock(Vertex::class);
     $v1->expects($this->once())->method('getVariables')->will($this->returnValue([$var]));
     $graph->ensureArc($vertex, $v1);
     $this->assertTrue(Helper::isLiveVar($var, $vertex, $graph));
 }
예제 #2
0
 public function findPhiNodes(Variable $var, array $assignments, Dominator $dominator, Digraph $graph)
 {
     $allDf = new \SplObjectStorage();
     $new = $assignments;
     do {
         $runAgain = false;
         $new = $this->findFrontier($new, $dominator);
         foreach ($new as $obj) {
             if (!$allDf->contains($obj)) {
                 $allDf->attach($obj);
                 // found a new one!!!
                 $runAgain = true;
             }
         }
     } while ($runAgain);
     $phiNodes = new \SplObjectStorage();
     foreach ($allDf as $node) {
         if ($node instanceof JitNoOp) {
             if (Helper::isLiveVar($var, $node, $graph)) {
                 // only add the phi node if the variable is live afterwards
                 $phiNodes[$node] = true;
             }
         } elseif (!$node instanceof End) {
             throw new \RuntimeException('A non-NoOp Phi Node was found, possible corrupted graph');
         }
     }
     return $phiNodes;
 }