hotspot/src/share/vm/opto/live.cpp
author twisti
Fri, 27 Feb 2009 13:27:09 -0800
changeset 2131 98f9cef66a34
parent 2030 39d55e4534b4
child 2154 72a9b7284ccf
permissions -rw-r--r--
6810672: Comment typos Summary: I have collected some typos I have found while looking at the code. Reviewed-by: kvn, never
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2005 Sun Microsystems, Inc.  All Rights Reserved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
#include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
#include "incls/_live.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
//------------------------------PhaseLive--------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// Compute live-in/live-out.  We use a totally incremental algorithm.  The LIVE
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// problem is monotonic.  The steady-state solution looks like this: pull a
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// block from the worklist.  It has a set of delta's - values which are newly
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// live-in from the block.  Push these to the live-out sets of all predecessor
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// blocks.  At each predecessor, the new live-out values are ANDed with what is
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// already live-out (extra stuff is added to the live-out sets).  Then the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
// remaining new live-out values are ANDed with what is locally defined.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// Leftover bits become the new live-in for the predecessor block, and the pred
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
// block is put on the worklist.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
//   The locally live-in stuff is computed once and added to predecessor
2131
98f9cef66a34 6810672: Comment typos
twisti
parents: 2030
diff changeset
    42
// live-out sets.  This separate compilation is done in the outer loop below.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
PhaseLive::PhaseLive( const PhaseCFG &cfg, LRG_List &names, Arena *arena ) : Phase(LIVE), _cfg(cfg), _names(names), _arena(arena), _live(0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
void PhaseLive::compute(uint maxlrg) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  _maxlrg   = maxlrg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  _worklist = new (_arena) Block_List();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  // Init the sparse live arrays.  This data is live on exit from here!
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  // The _live info is the live-out info.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  _live = (IndexSet*)_arena->Amalloc(sizeof(IndexSet)*_cfg._num_blocks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  uint i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  for( i=0; i<_cfg._num_blocks; i++ ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    _live[i].initialize(_maxlrg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  // Init the sparse arrays for delta-sets.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  ResourceMark rm;              // Nuke temp storage on exit
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  // Does the memory used by _defs and _deltas get reclaimed?  Does it matter?  TT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  // Array of values defined locally in blocks
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  _defs = NEW_RESOURCE_ARRAY(IndexSet,_cfg._num_blocks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  for( i=0; i<_cfg._num_blocks; i++ ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    _defs[i].initialize(_maxlrg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  // Array of delta-set pointers, indexed by block pre_order-1.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  _deltas = NEW_RESOURCE_ARRAY(IndexSet*,_cfg._num_blocks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  memset( _deltas, 0, sizeof(IndexSet*)* _cfg._num_blocks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  _free_IndexSet = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  // Blocks having done pass-1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  VectorSet first_pass(Thread::current()->resource_area());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  // Outer loop: must compute local live-in sets and push into predecessors.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  uint iters = _cfg._num_blocks;        // stat counters
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  for( uint j=_cfg._num_blocks; j>0; j-- ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    Block *b = _cfg._blocks[j-1];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    // Compute the local live-in set.  Start with any new live-out bits.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    IndexSet *use = getset( b );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    IndexSet *def = &_defs[b->_pre_order-1];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    DEBUG_ONLY(IndexSet *def_outside = getfreeset();)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    uint i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    for( i=b->_nodes.size(); i>1; i-- ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
      Node *n = b->_nodes[i-1];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
      if( n->is_Phi() ) break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
      uint r = _names[n->_idx];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
      assert(!def_outside->member(r), "Use of external LRG overlaps the same LRG defined in this block");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
      def->insert( r );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
      use->remove( r );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
      uint cnt = n->req();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
      for( uint k=1; k<cnt; k++ ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
        Node *nk = n->in(k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
        uint nkidx = nk->_idx;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
        if( _cfg._bbs[nkidx] != b ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
          uint u = _names[nkidx];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
          use->insert( u );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
          DEBUG_ONLY(def_outside->insert( u );)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    def_outside->set_next(_free_IndexSet);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    _free_IndexSet = def_outside;     // Drop onto free list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    // Remove anything defined by Phis and the block start instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    for( uint k=i; k>0; k-- ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
      uint r = _names[b->_nodes[k-1]->_idx];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
      def->insert( r );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
      use->remove( r );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    // Push these live-in things to predecessors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    for( uint l=1; l<b->num_preds(); l++ ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
      Block *p = _cfg._bbs[b->pred(l)->_idx];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
      add_liveout( p, use, first_pass );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
      // PhiNode uses go in the live-out set of prior blocks.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
      for( uint k=i; k>0; k-- )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
        add_liveout( p, _names[b->_nodes[k-1]->in(l)->_idx], first_pass );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    freeset( b );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    first_pass.set(b->_pre_order);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    // Inner loop: blocks that picked up new live-out values to be propagated
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    while( _worklist->size() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
        // !!!!!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
// #ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
      iters++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
// #endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
      Block *b = _worklist->pop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
      IndexSet *delta = getset(b);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
      assert( delta->count(), "missing delta set" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
      // Add new-live-in to predecessors live-out sets
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
      for( uint l=1; l<b->num_preds(); l++ )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
        add_liveout( _cfg._bbs[b->pred(l)->_idx], delta, first_pass );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
      freeset(b);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
    } // End of while-worklist-not-empty
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  } // End of for-all-blocks-outer-loop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  // We explicitly clear all of the IndexSets which we are about to release.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  // This allows us to recycle their internal memory into IndexSet's free list.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  for( i=0; i<_cfg._num_blocks; i++ ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
    _defs[i].clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
    if (_deltas[i]) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
      // Is this always true?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
      _deltas[i]->clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  IndexSet *free = _free_IndexSet;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  while (free != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
    IndexSet *temp = free;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
    free = free->next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
    temp->clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
//------------------------------stats------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
void PhaseLive::stats(uint iters) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
//------------------------------getset-----------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
// Get an IndexSet for a block.  Return existing one, if any.  Make a new
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
// empty one if a prior one does not exist.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
IndexSet *PhaseLive::getset( Block *p ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  IndexSet *delta = _deltas[p->_pre_order-1];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  if( !delta )                  // Not on worklist?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    // Get a free set; flag as being on worklist
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    delta = _deltas[p->_pre_order-1] = getfreeset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  return delta;                 // Return set of new live-out items
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
//------------------------------getfreeset-------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
// Pull from free list, or allocate.  Internal allocation on the returned set
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
// is always from thread local storage.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
IndexSet *PhaseLive::getfreeset( ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  IndexSet *f = _free_IndexSet;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  if( !f ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
    f = new IndexSet;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
//    f->set_arena(Thread::current()->resource_area());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
    f->initialize(_maxlrg, Thread::current()->resource_area());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    // Pull from free list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
    _free_IndexSet = f->next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  //f->_cnt = 0;                        // Reset to empty
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
//    f->set_arena(Thread::current()->resource_area());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
    f->initialize(_maxlrg, Thread::current()->resource_area());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  return f;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
//------------------------------freeset----------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
// Free an IndexSet from a block.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
void PhaseLive::freeset( const Block *p ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  IndexSet *f = _deltas[p->_pre_order-1];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  f->set_next(_free_IndexSet);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  _free_IndexSet = f;           // Drop onto free list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  _deltas[p->_pre_order-1] = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
//------------------------------add_liveout------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
// Add a live-out value to a given blocks live-out set.  If it is new, then
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
// also add it to the delta set and stick the block on the worklist.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
void PhaseLive::add_liveout( Block *p, uint r, VectorSet &first_pass ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  IndexSet *live = &_live[p->_pre_order-1];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  if( live->insert(r) ) {       // If actually inserted...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
    // We extended the live-out set.  See if the value is generated locally.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
    // If it is not, then we must extend the live-in set.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
    if( !_defs[p->_pre_order-1].member( r ) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
      if( !_deltas[p->_pre_order-1] && // Not on worklist?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
          first_pass.test(p->_pre_order) )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
        _worklist->push(p);     // Actually go on worklist if already 1st pass
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
      getset(p)->insert(r);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
//------------------------------add_liveout------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
// Add a vector of live-out values to a given blocks live-out set.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
void PhaseLive::add_liveout( Block *p, IndexSet *lo, VectorSet &first_pass ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  IndexSet *live = &_live[p->_pre_order-1];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  IndexSet *defs = &_defs[p->_pre_order-1];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  IndexSet *on_worklist = _deltas[p->_pre_order-1];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  IndexSet *delta = on_worklist ? on_worklist : getfreeset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  IndexSetIterator elements(lo);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  uint r;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  while ((r = elements.next()) != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
    if( live->insert(r) &&      // If actually inserted...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
        !defs->member( r ) )    // and not defined locally
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
      delta->insert(r);         // Then add to live-in set
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  if( delta->count() ) {                // If actually added things
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
    _deltas[p->_pre_order-1] = delta; // Flag as on worklist now
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
    if( !on_worklist &&         // Not on worklist?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
        first_pass.test(p->_pre_order) )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
      _worklist->push(p);       // Actually go on worklist if already 1st pass
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  } else {                      // Nothing there; just free it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
    delta->set_next(_free_IndexSet);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
    _free_IndexSet = delta;     // Drop onto free list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
//------------------------------dump-------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
// Dump the live-out set for a block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
void PhaseLive::dump( const Block *b ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  tty->print("Block %d: ",b->_pre_order);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  tty->print("LiveOut: ");  _live[b->_pre_order-1].dump();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  uint cnt = b->_nodes.size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  for( uint i=0; i<cnt; i++ ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
    tty->print("L%d/", _names[b->_nodes[i]->_idx] );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
    b->_nodes[i]->dump();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  tty->print("\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
//------------------------------verify_base_ptrs-------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
// Verify that base pointers and derived pointers are still sane.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
void PhaseChaitin::verify_base_ptrs( ResourceArea *a ) const {
2014
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   275
#ifdef ASSERT
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   276
  Unique_Node_List worklist(a);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  for( uint i = 0; i < _cfg._num_blocks; i++ ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
    Block *b = _cfg._blocks[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
    for( uint j = b->end_idx() + 1; j > 1; j-- ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
      Node *n = b->_nodes[j-1];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
      if( n->is_Phi() ) break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
      // Found a safepoint?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
      if( n->is_MachSafePoint() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
        MachSafePointNode *sfpt = n->as_MachSafePoint();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
        JVMState* jvms = sfpt->jvms();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
        if (jvms != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
          // Now scan for a live derived pointer
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
          if (jvms->oopoff() < sfpt->req()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
            // Check each derived/base pair
2014
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   290
            for (uint idx = jvms->oopoff(); idx < sfpt->req(); idx++) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
              Node *check = sfpt->in(idx);
2014
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   292
              bool is_derived = ((idx - jvms->oopoff()) & 1) == 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
              // search upwards through spills and spill phis for AddP
2014
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   294
              worklist.clear();
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   295
              worklist.push(check);
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   296
              uint k = 0;
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   297
              while( k < worklist.size() ) {
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   298
                check = worklist.at(k);
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   299
                assert(check,"Bad base or derived pointer");
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   300
                // See PhaseChaitin::find_base_for_derived() for all cases.
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   301
                int isc = check->is_Copy();
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   302
                if( isc ) {
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   303
                  worklist.push(check->in(isc));
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   304
                } else if( check->is_Phi() ) {
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   305
                  for (uint m = 1; m < check->req(); m++)
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   306
                    worklist.push(check->in(m));
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   307
                } else if( check->is_Con() ) {
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   308
                  if (is_derived) {
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   309
                    // Derived is NULL+offset
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   310
                    assert(!is_derived || check->bottom_type()->is_ptr()->ptr() == TypePtr::Null,"Bad derived pointer");
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   311
                  } else {
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   312
                    assert(check->bottom_type()->is_ptr()->_offset == 0,"Bad base pointer");
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   313
                    // Base either ConP(NULL) or loadConP
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   314
                    if (check->is_Mach()) {
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   315
                      assert(check->as_Mach()->ideal_Opcode() == Op_ConP,"Bad base pointer");
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   316
                    } else {
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   317
                      assert(check->Opcode() == Op_ConP &&
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   318
                             check->bottom_type()->is_ptr()->ptr() == TypePtr::Null,"Bad base pointer");
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   319
                    }
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   320
                  }
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   321
                } else if( check->bottom_type()->is_ptr()->_offset == 0 ) {
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   322
                  if(check->is_Proj() || check->is_Mach() &&
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   323
                     (check->as_Mach()->ideal_Opcode() == Op_CreateEx ||
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   324
                      check->as_Mach()->ideal_Opcode() == Op_ThreadLocal ||
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   325
                      check->as_Mach()->ideal_Opcode() == Op_CMoveP ||
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   326
                      check->as_Mach()->ideal_Opcode() == Op_CheckCastPP ||
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   327
#ifdef _LP64
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   328
                      UseCompressedOops && check->as_Mach()->ideal_Opcode() == Op_CastPP ||
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   329
                      UseCompressedOops && check->as_Mach()->ideal_Opcode() == Op_DecodeN ||
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   330
#endif
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   331
                      check->as_Mach()->ideal_Opcode() == Op_LoadP ||
2030
39d55e4534b4 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 2014
diff changeset
   332
                      check->as_Mach()->ideal_Opcode() == Op_LoadKlass)) {
39d55e4534b4 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 2014
diff changeset
   333
                    // Valid nodes
39d55e4534b4 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 2014
diff changeset
   334
                  } else {
39d55e4534b4 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 2014
diff changeset
   335
                    check->dump();
2014
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   336
                    assert(false,"Bad base or derived pointer");
2030
39d55e4534b4 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 2014
diff changeset
   337
                  }
2014
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   338
                } else {
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   339
                  assert(is_derived,"Bad base pointer");
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   340
                  assert(check->is_Mach() && check->as_Mach()->ideal_Opcode() == Op_AddP,"Bad derived pointer");
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   341
                }
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   342
                k++;
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   343
                assert(k < 100000,"Derived pointer checking in infinite loop");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
              } // End while
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
          } // End of check for derived pointers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
        } // End of Kcheck for debug info
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
      } // End of if found a safepoint
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
    } // End of forall instructions in block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
  } // End of forall blocks
2014
5510e7394f2d 6782232: assert("CreateEx must be first instruction in block" )
kvn
parents: 1
diff changeset
   351
#endif
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
}
2030
39d55e4534b4 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 2014
diff changeset
   353
39d55e4534b4 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 2014
diff changeset
   354
//------------------------------verify-------------------------------------
39d55e4534b4 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 2014
diff changeset
   355
// Verify that graphs and base pointers are still sane.
39d55e4534b4 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 2014
diff changeset
   356
void PhaseChaitin::verify( ResourceArea *a, bool verify_ifg ) const {
39d55e4534b4 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 2014
diff changeset
   357
#ifdef ASSERT
39d55e4534b4 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 2014
diff changeset
   358
  if( VerifyOpto || VerifyRegisterAllocator ) {
39d55e4534b4 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 2014
diff changeset
   359
    _cfg.verify();
39d55e4534b4 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 2014
diff changeset
   360
    verify_base_ptrs(a);
39d55e4534b4 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 2014
diff changeset
   361
    if(verify_ifg)
39d55e4534b4 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 2014
diff changeset
   362
      _ifg->verify(this);
39d55e4534b4 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 2014
diff changeset
   363
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
#endif
2030
39d55e4534b4 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 2014
diff changeset
   365
}
39d55e4534b4 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 2014
diff changeset
   366
39d55e4534b4 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 2014
diff changeset
   367
#endif