예제 #1
0
//------------------------------DFS--------------------------------------------
// Perform DFS search.  Setup 'vertex' as DFS to vertex mapping.  Setup      
// 'semi' as vertex to DFS mapping.  Set 'parent' to DFS parent.             
uint PhaseCFG::DFS( Tarjan *tarjan ) {
  Block *b = _broot;
  uint pre_order = 1;
  // Allocate stack of size _num_blocks+1 to avoid frequent realloc
  Block_Stack bstack(tarjan, _num_blocks+1);

  // Push on stack the state for the first block
  bstack.push(pre_order, b); 
  ++pre_order;

  while (bstack.is_nonempty()) {
    if (!bstack.last_successor()) { 
      // Walk over all successors in pre-order (DFS).
      Block *s = bstack.next_successor();
      if (s->_pre_order == 0) { // Check for no-pre-order, not-visited
        // Push on stack the state of successor
        bstack.push(pre_order, s); 
        ++pre_order;
      }
    }
    else {
      // Build a reverse post-order in the CFG _blocks array
      _blocks.map(--_rpo_ctr, bstack.pop());
    }
  }
  return pre_order;
}
예제 #2
0
파일: domgraph.cpp 프로젝트: eregon/jvmci
// Perform DFS search.  Setup 'vertex' as DFS to vertex mapping.  Setup
// 'semi' as vertex to DFS mapping.  Set 'parent' to DFS parent.
uint PhaseCFG::do_DFS(Tarjan *tarjan, uint rpo_counter) {
  Block* root_block = get_root_block();
  uint pre_order = 1;
  // Allocate stack of size number_of_blocks() + 1 to avoid frequent realloc
  Block_Stack bstack(tarjan, number_of_blocks() + 1);

  // Push on stack the state for the first block
  bstack.push(pre_order, root_block);
  ++pre_order;

  while (bstack.is_nonempty()) {
    if (!bstack.last_successor()) {
      // Walk over all successors in pre-order (DFS).
      Block* next_block = bstack.next_successor();
      if (next_block->_pre_order == 0) { // Check for no-pre-order, not-visited
        // Push on stack the state of successor
        bstack.push(pre_order, next_block);
        ++pre_order;
      }
    }
    else {
      // Build a reverse post-order in the CFG _blocks array
      Block *stack_top = bstack.pop();
      stack_top->_rpo = --rpo_counter;
      _blocks.map(stack_top->_rpo, stack_top);
    }
  }
  return pre_order;
}