src/share/vm/opto/block.cpp

changeset 5509
d1034bd8cefc
parent 4889
cc32ccaaf47f
child 5539
adb9a7d94cb5
     1.1 --- a/src/share/vm/opto/block.cpp	Mon Aug 05 15:03:40 2013 -0700
     1.2 +++ b/src/share/vm/opto/block.cpp	Wed Aug 07 17:56:19 2013 +0200
     1.3 @@ -221,7 +221,7 @@
     1.4  //------------------------------is_uncommon------------------------------------
     1.5  // True if block is low enough frequency or guarded by a test which
     1.6  // mostly does not go here.
     1.7 -bool Block::is_uncommon( Block_Array &bbs ) const {
     1.8 +bool Block::is_uncommon(PhaseCFG* cfg) const {
     1.9    // Initial blocks must never be moved, so are never uncommon.
    1.10    if (head()->is_Root() || head()->is_Start())  return false;
    1.11  
    1.12 @@ -238,7 +238,7 @@
    1.13    uint uncommon_for_freq_preds = 0;
    1.14  
    1.15    for( uint i=1; i<num_preds(); i++ ) {
    1.16 -    Block* guard = bbs[pred(i)->_idx];
    1.17 +    Block* guard = cfg->get_block_for_node(pred(i));
    1.18      // Check to see if this block follows its guard 1 time out of 10000
    1.19      // or less.
    1.20      //
    1.21 @@ -285,11 +285,11 @@
    1.22    }
    1.23  }
    1.24  
    1.25 -void Block::dump_pred(const Block_Array *bbs, Block* orig, outputStream* st) const {
    1.26 +void Block::dump_pred(const PhaseCFG* cfg, Block* orig, outputStream* st) const {
    1.27    if (is_connector()) {
    1.28      for (uint i=1; i<num_preds(); i++) {
    1.29 -      Block *p = ((*bbs)[pred(i)->_idx]);
    1.30 -      p->dump_pred(bbs, orig, st);
    1.31 +      Block *p = cfg->get_block_for_node(pred(i));
    1.32 +      p->dump_pred(cfg, orig, st);
    1.33      }
    1.34    } else {
    1.35      dump_bidx(orig, st);
    1.36 @@ -297,7 +297,7 @@
    1.37    }
    1.38  }
    1.39  
    1.40 -void Block::dump_head( const Block_Array *bbs, outputStream* st ) const {
    1.41 +void Block::dump_head(const PhaseCFG* cfg, outputStream* st) const {
    1.42    // Print the basic block
    1.43    dump_bidx(this, st);
    1.44    st->print(": #\t");
    1.45 @@ -311,26 +311,28 @@
    1.46    if( head()->is_block_start() ) {
    1.47      for (uint i=1; i<num_preds(); i++) {
    1.48        Node *s = pred(i);
    1.49 -      if (bbs) {
    1.50 -        Block *p = (*bbs)[s->_idx];
    1.51 -        p->dump_pred(bbs, p, st);
    1.52 +      if (cfg != NULL) {
    1.53 +        Block *p = cfg->get_block_for_node(s);
    1.54 +        p->dump_pred(cfg, p, st);
    1.55        } else {
    1.56          while (!s->is_block_start())
    1.57            s = s->in(0);
    1.58          st->print("N%d ", s->_idx );
    1.59        }
    1.60      }
    1.61 -  } else
    1.62 +  } else {
    1.63      st->print("BLOCK HEAD IS JUNK  ");
    1.64 +  }
    1.65  
    1.66    // Print loop, if any
    1.67    const Block *bhead = this;    // Head of self-loop
    1.68    Node *bh = bhead->head();
    1.69 -  if( bbs && bh->is_Loop() && !head()->is_Root() ) {
    1.70 +
    1.71 +  if ((cfg != NULL) && bh->is_Loop() && !head()->is_Root()) {
    1.72      LoopNode *loop = bh->as_Loop();
    1.73 -    const Block *bx = (*bbs)[loop->in(LoopNode::LoopBackControl)->_idx];
    1.74 +    const Block *bx = cfg->get_block_for_node(loop->in(LoopNode::LoopBackControl));
    1.75      while (bx->is_connector()) {
    1.76 -      bx = (*bbs)[bx->pred(1)->_idx];
    1.77 +      bx = cfg->get_block_for_node(bx->pred(1));
    1.78      }
    1.79      st->print("\tLoop: B%d-B%d ", bhead->_pre_order, bx->_pre_order);
    1.80      // Dump any loop-specific bits, especially for CountedLoops.
    1.81 @@ -349,29 +351,32 @@
    1.82    st->print_cr("");
    1.83  }
    1.84  
    1.85 -void Block::dump() const { dump(NULL); }
    1.86 +void Block::dump() const {
    1.87 +  dump(NULL);
    1.88 +}
    1.89  
    1.90 -void Block::dump( const Block_Array *bbs ) const {
    1.91 -  dump_head(bbs);
    1.92 -  uint cnt = _nodes.size();
    1.93 -  for( uint i=0; i<cnt; i++ )
    1.94 +void Block::dump(const PhaseCFG* cfg) const {
    1.95 +  dump_head(cfg);
    1.96 +  for (uint i=0; i< _nodes.size(); i++) {
    1.97      _nodes[i]->dump();
    1.98 +  }
    1.99    tty->print("\n");
   1.100  }
   1.101  #endif
   1.102  
   1.103  //=============================================================================
   1.104  //------------------------------PhaseCFG---------------------------------------
   1.105 -PhaseCFG::PhaseCFG( Arena *a, RootNode *r, Matcher &m ) :
   1.106 -  Phase(CFG),
   1.107 -  _bbs(a),
   1.108 -  _root(r),
   1.109 -  _node_latency(NULL)
   1.110 +PhaseCFG::PhaseCFG(Arena* arena, RootNode* root, Matcher& matcher)
   1.111 +: Phase(CFG)
   1.112 +, _block_arena(arena)
   1.113 +, _node_to_block_mapping(arena)
   1.114 +, _root(root)
   1.115 +, _node_latency(NULL)
   1.116  #ifndef PRODUCT
   1.117 -  , _trace_opto_pipelining(TraceOptoPipelining || C->method_has_option("TraceOptoPipelining"))
   1.118 +, _trace_opto_pipelining(TraceOptoPipelining || C->method_has_option("TraceOptoPipelining"))
   1.119  #endif
   1.120  #ifdef ASSERT
   1.121 -  , _raw_oops(a)
   1.122 +, _raw_oops(arena)
   1.123  #endif
   1.124  {
   1.125    ResourceMark rm;
   1.126 @@ -380,13 +385,13 @@
   1.127    // Node on demand.
   1.128    Node *x = new (C) GotoNode(NULL);
   1.129    x->init_req(0, x);
   1.130 -  _goto = m.match_tree(x);
   1.131 +  _goto = matcher.match_tree(x);
   1.132    assert(_goto != NULL, "");
   1.133    _goto->set_req(0,_goto);
   1.134  
   1.135    // Build the CFG in Reverse Post Order
   1.136    _num_blocks = build_cfg();
   1.137 -  _broot = _bbs[_root->_idx];
   1.138 +  _broot = get_block_for_node(_root);
   1.139  }
   1.140  
   1.141  //------------------------------build_cfg--------------------------------------
   1.142 @@ -440,9 +445,9 @@
   1.143        // 'p' now points to the start of this basic block
   1.144  
   1.145        // Put self in array of basic blocks
   1.146 -      Block *bb = new (_bbs._arena) Block(_bbs._arena,p);
   1.147 -      _bbs.map(p->_idx,bb);
   1.148 -      _bbs.map(x->_idx,bb);
   1.149 +      Block *bb = new (_block_arena) Block(_block_arena, p);
   1.150 +      map_node_to_block(p, bb);
   1.151 +      map_node_to_block(x, bb);
   1.152        if( x != p ) {                // Only for root is x == p
   1.153          bb->_nodes.push((Node*)x);
   1.154        }
   1.155 @@ -473,16 +478,16 @@
   1.156        // Check if it the fist node pushed on stack at the beginning.
   1.157        if (idx == 0) break;          // end of the build
   1.158        // Find predecessor basic block
   1.159 -      Block *pb = _bbs[x->_idx];
   1.160 +      Block *pb = get_block_for_node(x);
   1.161        // Insert into nodes array, if not already there
   1.162 -      if( !_bbs.lookup(proj->_idx) ) {
   1.163 +      if (!has_block(proj)) {
   1.164          assert( x != proj, "" );
   1.165          // Map basic block of projection
   1.166 -        _bbs.map(proj->_idx,pb);
   1.167 +        map_node_to_block(proj, pb);
   1.168          pb->_nodes.push(proj);
   1.169        }
   1.170        // Insert self as a child of my predecessor block
   1.171 -      pb->_succs.map(pb->_num_succs++, _bbs[np->_idx]);
   1.172 +      pb->_succs.map(pb->_num_succs++, get_block_for_node(np));
   1.173        assert( pb->_nodes[ pb->_nodes.size() - pb->_num_succs ]->is_block_proj(),
   1.174                "too many control users, not a CFG?" );
   1.175      }
   1.176 @@ -511,15 +516,15 @@
   1.177    RegionNode* region = new (C) RegionNode(2);
   1.178    region->init_req(1, proj);
   1.179    // setup corresponding basic block
   1.180 -  Block* block = new (_bbs._arena) Block(_bbs._arena, region);
   1.181 -  _bbs.map(region->_idx, block);
   1.182 +  Block* block = new (_block_arena) Block(_block_arena, region);
   1.183 +  map_node_to_block(region, block);
   1.184    C->regalloc()->set_bad(region->_idx);
   1.185    // add a goto node
   1.186    Node* gto = _goto->clone(); // get a new goto node
   1.187    gto->set_req(0, region);
   1.188    // add it to the basic block
   1.189    block->_nodes.push(gto);
   1.190 -  _bbs.map(gto->_idx, block);
   1.191 +  map_node_to_block(gto, block);
   1.192    C->regalloc()->set_bad(gto->_idx);
   1.193    // hook up successor block
   1.194    block->_succs.map(block->_num_succs++, out);
   1.195 @@ -570,7 +575,7 @@
   1.196    gto->set_req(0, b->head());
   1.197    Node *bp = b->_nodes[end_idx];
   1.198    b->_nodes.map(end_idx,gto); // Slam over NeverBranch
   1.199 -  _bbs.map(gto->_idx, b);
   1.200 +  map_node_to_block(gto, b);
   1.201    C->regalloc()->set_bad(gto->_idx);
   1.202    b->_nodes.pop();              // Yank projections
   1.203    b->_nodes.pop();              // Yank projections
   1.204 @@ -613,7 +618,7 @@
   1.205    // If the previous block conditionally falls into bx, return false,
   1.206    // because moving bx will create an extra jump.
   1.207    for(uint k = 1; k < bx->num_preds(); k++ ) {
   1.208 -    Block* pred = _bbs[bx->pred(k)->_idx];
   1.209 +    Block* pred = get_block_for_node(bx->pred(k));
   1.210      if (pred == _blocks[bx_index-1]) {
   1.211        if (pred->_num_succs != 1) {
   1.212          return false;
   1.213 @@ -682,7 +687,7 @@
   1.214  
   1.215      // Look for uncommon blocks and move to end.
   1.216      if (!C->do_freq_based_layout()) {
   1.217 -      if( b->is_uncommon(_bbs) ) {
   1.218 +      if (b->is_uncommon(this)) {
   1.219          move_to_end(b, i);
   1.220          last--;                   // No longer check for being uncommon!
   1.221          if( no_flip_branch(b) ) { // Fall-thru case must follow?
   1.222 @@ -870,28 +875,31 @@
   1.223    } while( !p->is_block_start() );
   1.224  
   1.225    // Recursively visit
   1.226 -  for( uint i=1; i<p->req(); i++ )
   1.227 -    _dump_cfg(p->in(i),visited);
   1.228 +  for (uint i = 1; i < p->req(); i++) {
   1.229 +    _dump_cfg(p->in(i), visited);
   1.230 +  }
   1.231  
   1.232    // Dump the block
   1.233 -  _bbs[p->_idx]->dump(&_bbs);
   1.234 +  get_block_for_node(p)->dump(this);
   1.235  }
   1.236  
   1.237  void PhaseCFG::dump( ) const {
   1.238    tty->print("\n--- CFG --- %d BBs\n",_num_blocks);
   1.239 -  if( _blocks.size() ) {        // Did we do basic-block layout?
   1.240 -    for( uint i=0; i<_num_blocks; i++ )
   1.241 -      _blocks[i]->dump(&_bbs);
   1.242 +  if (_blocks.size()) {        // Did we do basic-block layout?
   1.243 +    for (uint i = 0; i < _num_blocks; i++) {
   1.244 +      _blocks[i]->dump(this);
   1.245 +    }
   1.246    } else {                      // Else do it with a DFS
   1.247 -    VectorSet visited(_bbs._arena);
   1.248 +    VectorSet visited(_block_arena);
   1.249      _dump_cfg(_root,visited);
   1.250    }
   1.251  }
   1.252  
   1.253  void PhaseCFG::dump_headers() {
   1.254    for( uint i = 0; i < _num_blocks; i++ ) {
   1.255 -    if( _blocks[i] == NULL ) continue;
   1.256 -    _blocks[i]->dump_head(&_bbs);
   1.257 +    if (_blocks[i]) {
   1.258 +      _blocks[i]->dump_head(this);
   1.259 +    }
   1.260    }
   1.261  }
   1.262  
   1.263 @@ -904,7 +912,7 @@
   1.264      uint j;
   1.265      for (j = 0; j < cnt; j++)  {
   1.266        Node *n = b->_nodes[j];
   1.267 -      assert( _bbs[n->_idx] == b, "" );
   1.268 +      assert(get_block_for_node(n) == b, "");
   1.269        if (j >= 1 && n->is_Mach() &&
   1.270            n->as_Mach()->ideal_Opcode() == Op_CreateEx) {
   1.271          assert(j == 1 || b->_nodes[j-1]->is_Phi(),
   1.272 @@ -913,13 +921,12 @@
   1.273        for (uint k = 0; k < n->req(); k++) {
   1.274          Node *def = n->in(k);
   1.275          if (def && def != n) {
   1.276 -          assert(_bbs[def->_idx] || def->is_Con(),
   1.277 -                 "must have block; constants for debug info ok");
   1.278 +          assert(get_block_for_node(def) || def->is_Con(), "must have block; constants for debug info ok");
   1.279            // Verify that instructions in the block is in correct order.
   1.280            // Uses must follow their definition if they are at the same block.
   1.281            // Mostly done to check that MachSpillCopy nodes are placed correctly
   1.282            // when CreateEx node is moved in build_ifg_physical().
   1.283 -          if (_bbs[def->_idx] == b &&
   1.284 +          if (get_block_for_node(def) == b &&
   1.285                !(b->head()->is_Loop() && n->is_Phi()) &&
   1.286                // See (+++) comment in reg_split.cpp
   1.287                !(n->jvms() != NULL && n->jvms()->is_monitor_use(k))) {

mercurial