src/share/vm/opto/live.cpp

Wed, 07 Aug 2013 17:56:19 +0200

author
adlertz
date
Wed, 07 Aug 2013 17:56:19 +0200
changeset 5509
d1034bd8cefc
parent 4949
8373c19be854
child 5539
adb9a7d94cb5
permissions
-rw-r--r--

8022284: Hide internal data structure in PhaseCFG
Summary: Hide private node to block mapping using public interface
Reviewed-by: kvn, roland

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

mercurial