1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/opto/chaitin.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,625 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#ifndef SHARE_VM_OPTO_CHAITIN_HPP 1.29 +#define SHARE_VM_OPTO_CHAITIN_HPP 1.30 + 1.31 +#include "code/vmreg.hpp" 1.32 +#include "libadt/port.hpp" 1.33 +#include "memory/resourceArea.hpp" 1.34 +#include "opto/connode.hpp" 1.35 +#include "opto/live.hpp" 1.36 +#include "opto/matcher.hpp" 1.37 +#include "opto/phase.hpp" 1.38 +#include "opto/regalloc.hpp" 1.39 +#include "opto/regmask.hpp" 1.40 + 1.41 +class LoopTree; 1.42 +class MachCallNode; 1.43 +class MachSafePointNode; 1.44 +class Matcher; 1.45 +class PhaseCFG; 1.46 +class PhaseLive; 1.47 +class PhaseRegAlloc; 1.48 +class PhaseChaitin; 1.49 + 1.50 +#define OPTO_DEBUG_SPLIT_FREQ BLOCK_FREQUENCY(0.001) 1.51 +#define OPTO_LRG_HIGH_FREQ BLOCK_FREQUENCY(0.25) 1.52 + 1.53 +//------------------------------LRG-------------------------------------------- 1.54 +// Live-RanGe structure. 1.55 +class LRG : public ResourceObj { 1.56 + friend class VMStructs; 1.57 +public: 1.58 + static const uint AllStack_size = 0xFFFFF; // This mask size is used to tell that the mask of this LRG supports stack positions 1.59 + enum { SPILL_REG=29999 }; // Register number of a spilled LRG 1.60 + 1.61 + double _cost; // 2 for loads/1 for stores times block freq 1.62 + double _area; // Sum of all simultaneously live values 1.63 + double score() const; // Compute score from cost and area 1.64 + double _maxfreq; // Maximum frequency of any def or use 1.65 + 1.66 + Node *_def; // Check for multi-def live ranges 1.67 +#ifndef PRODUCT 1.68 + GrowableArray<Node*>* _defs; 1.69 +#endif 1.70 + 1.71 + uint _risk_bias; // Index of LRG which we want to avoid color 1.72 + uint _copy_bias; // Index of LRG which we want to share color 1.73 + 1.74 + uint _next; // Index of next LRG in linked list 1.75 + uint _prev; // Index of prev LRG in linked list 1.76 +private: 1.77 + uint _reg; // Chosen register; undefined if mask is plural 1.78 +public: 1.79 + // Return chosen register for this LRG. Error if the LRG is not bound to 1.80 + // a single register. 1.81 + OptoReg::Name reg() const { return OptoReg::Name(_reg); } 1.82 + void set_reg( OptoReg::Name r ) { _reg = r; } 1.83 + 1.84 +private: 1.85 + uint _eff_degree; // Effective degree: Sum of neighbors _num_regs 1.86 +public: 1.87 + int degree() const { assert( _degree_valid , "" ); return _eff_degree; } 1.88 + // Degree starts not valid and any change to the IFG neighbor 1.89 + // set makes it not valid. 1.90 + void set_degree( uint degree ) { 1.91 + _eff_degree = degree; 1.92 + debug_only(_degree_valid = 1;) 1.93 + assert(!_mask.is_AllStack() || (_mask.is_AllStack() && lo_degree()), "_eff_degree can't be bigger than AllStack_size - _num_regs if the mask supports stack registers"); 1.94 + } 1.95 + // Made a change that hammered degree 1.96 + void invalid_degree() { debug_only(_degree_valid=0;) } 1.97 + // Incrementally modify degree. If it was correct, it should remain correct 1.98 + void inc_degree( uint mod ) { 1.99 + _eff_degree += mod; 1.100 + assert(!_mask.is_AllStack() || (_mask.is_AllStack() && lo_degree()), "_eff_degree can't be bigger than AllStack_size - _num_regs if the mask supports stack registers"); 1.101 + } 1.102 + // Compute the degree between 2 live ranges 1.103 + int compute_degree( LRG &l ) const; 1.104 + 1.105 +private: 1.106 + RegMask _mask; // Allowed registers for this LRG 1.107 + uint _mask_size; // cache of _mask.Size(); 1.108 +public: 1.109 + int compute_mask_size() const { return _mask.is_AllStack() ? AllStack_size : _mask.Size(); } 1.110 + void set_mask_size( int size ) { 1.111 + assert((size == (int)AllStack_size) || (size == (int)_mask.Size()), ""); 1.112 + _mask_size = size; 1.113 +#ifdef ASSERT 1.114 + _msize_valid=1; 1.115 + if (_is_vector) { 1.116 + assert(!_fat_proj, "sanity"); 1.117 + _mask.verify_sets(_num_regs); 1.118 + } else if (_num_regs == 2 && !_fat_proj) { 1.119 + _mask.verify_pairs(); 1.120 + } 1.121 +#endif 1.122 + } 1.123 + void compute_set_mask_size() { set_mask_size(compute_mask_size()); } 1.124 + int mask_size() const { assert( _msize_valid, "mask size not valid" ); 1.125 + return _mask_size; } 1.126 + // Get the last mask size computed, even if it does not match the 1.127 + // count of bits in the current mask. 1.128 + int get_invalid_mask_size() const { return _mask_size; } 1.129 + const RegMask &mask() const { return _mask; } 1.130 + void set_mask( const RegMask &rm ) { _mask = rm; debug_only(_msize_valid=0;)} 1.131 + void AND( const RegMask &rm ) { _mask.AND(rm); debug_only(_msize_valid=0;)} 1.132 + void SUBTRACT( const RegMask &rm ) { _mask.SUBTRACT(rm); debug_only(_msize_valid=0;)} 1.133 + void Clear() { _mask.Clear() ; debug_only(_msize_valid=1); _mask_size = 0; } 1.134 + void Set_All() { _mask.Set_All(); debug_only(_msize_valid=1); _mask_size = RegMask::CHUNK_SIZE; } 1.135 + void Insert( OptoReg::Name reg ) { _mask.Insert(reg); debug_only(_msize_valid=0;) } 1.136 + void Remove( OptoReg::Name reg ) { _mask.Remove(reg); debug_only(_msize_valid=0;) } 1.137 + void clear_to_pairs() { _mask.clear_to_pairs(); debug_only(_msize_valid=0;) } 1.138 + void clear_to_sets() { _mask.clear_to_sets(_num_regs); debug_only(_msize_valid=0;) } 1.139 + 1.140 + // Number of registers this live range uses when it colors 1.141 +private: 1.142 + uint8 _num_regs; // 2 for Longs and Doubles, 1 for all else 1.143 + // except _num_regs is kill count for fat_proj 1.144 +public: 1.145 + int num_regs() const { return _num_regs; } 1.146 + void set_num_regs( int reg ) { assert( _num_regs == reg || !_num_regs, "" ); _num_regs = reg; } 1.147 + 1.148 +private: 1.149 + // Number of physical registers this live range uses when it colors 1.150 + // Architecture and register-set dependent 1.151 + uint8 _reg_pressure; 1.152 +public: 1.153 + void set_reg_pressure(int i) { _reg_pressure = i; } 1.154 + int reg_pressure() const { return _reg_pressure; } 1.155 + 1.156 + // How much 'wiggle room' does this live range have? 1.157 + // How many color choices can it make (scaled by _num_regs)? 1.158 + int degrees_of_freedom() const { return mask_size() - _num_regs; } 1.159 + // Bound LRGs have ZERO degrees of freedom. We also count 1.160 + // must_spill as bound. 1.161 + bool is_bound () const { return _is_bound; } 1.162 + // Negative degrees-of-freedom; even with no neighbors this 1.163 + // live range must spill. 1.164 + bool not_free() const { return degrees_of_freedom() < 0; } 1.165 + // Is this live range of "low-degree"? Trivially colorable? 1.166 + bool lo_degree () const { return degree() <= degrees_of_freedom(); } 1.167 + // Is this live range just barely "low-degree"? Trivially colorable? 1.168 + bool just_lo_degree () const { return degree() == degrees_of_freedom(); } 1.169 + 1.170 + uint _is_oop:1, // Live-range holds an oop 1.171 + _is_float:1, // True if in float registers 1.172 + _is_vector:1, // True if in vector registers 1.173 + _was_spilled1:1, // True if prior spilling on def 1.174 + _was_spilled2:1, // True if twice prior spilling on def 1.175 + _is_bound:1, // live range starts life with no 1.176 + // degrees of freedom. 1.177 + _direct_conflict:1, // True if def and use registers in conflict 1.178 + _must_spill:1, // live range has lost all degrees of freedom 1.179 + // If _fat_proj is set, live range does NOT require aligned, adjacent 1.180 + // registers and has NO interferences. 1.181 + // If _fat_proj is clear, live range requires num_regs() to be a power of 1.182 + // 2, and it requires registers to form an aligned, adjacent set. 1.183 + _fat_proj:1, // 1.184 + _was_lo:1, // Was lo-degree prior to coalesce 1.185 + _msize_valid:1, // _mask_size cache valid 1.186 + _degree_valid:1, // _degree cache valid 1.187 + _has_copy:1, // Adjacent to some copy instruction 1.188 + _at_risk:1; // Simplify says this guy is at risk to spill 1.189 + 1.190 + 1.191 + // Alive if non-zero, dead if zero 1.192 + bool alive() const { return _def != NULL; } 1.193 + bool is_multidef() const { return _def == NodeSentinel; } 1.194 + bool is_singledef() const { return _def != NodeSentinel; } 1.195 + 1.196 +#ifndef PRODUCT 1.197 + void dump( ) const; 1.198 +#endif 1.199 +}; 1.200 + 1.201 +//------------------------------IFG-------------------------------------------- 1.202 +// InterFerence Graph 1.203 +// An undirected graph implementation. Created with a fixed number of 1.204 +// vertices. Edges can be added & tested. Vertices can be removed, then 1.205 +// added back later with all edges intact. Can add edges between one vertex 1.206 +// and a list of other vertices. Can union vertices (and their edges) 1.207 +// together. The IFG needs to be really really fast, and also fairly 1.208 +// abstract! It needs abstraction so I can fiddle with the implementation to 1.209 +// get even more speed. 1.210 +class PhaseIFG : public Phase { 1.211 + friend class VMStructs; 1.212 + // Current implementation: a triangular adjacency list. 1.213 + 1.214 + // Array of adjacency-lists, indexed by live-range number 1.215 + IndexSet *_adjs; 1.216 + 1.217 + // Assertion bit for proper use of Squaring 1.218 + bool _is_square; 1.219 + 1.220 + // Live range structure goes here 1.221 + LRG *_lrgs; // Array of LRG structures 1.222 + 1.223 +public: 1.224 + // Largest live-range number 1.225 + uint _maxlrg; 1.226 + 1.227 + Arena *_arena; 1.228 + 1.229 + // Keep track of inserted and deleted Nodes 1.230 + VectorSet *_yanked; 1.231 + 1.232 + PhaseIFG( Arena *arena ); 1.233 + void init( uint maxlrg ); 1.234 + 1.235 + // Add edge between a and b. Returns true if actually addded. 1.236 + int add_edge( uint a, uint b ); 1.237 + 1.238 + // Add edge between a and everything in the vector 1.239 + void add_vector( uint a, IndexSet *vec ); 1.240 + 1.241 + // Test for edge existance 1.242 + int test_edge( uint a, uint b ) const; 1.243 + 1.244 + // Square-up matrix for faster Union 1.245 + void SquareUp(); 1.246 + 1.247 + // Return number of LRG neighbors 1.248 + uint neighbor_cnt( uint a ) const { return _adjs[a].count(); } 1.249 + // Union edges of b into a on Squared-up matrix 1.250 + void Union( uint a, uint b ); 1.251 + // Test for edge in Squared-up matrix 1.252 + int test_edge_sq( uint a, uint b ) const; 1.253 + // Yank a Node and all connected edges from the IFG. Be prepared to 1.254 + // re-insert the yanked Node in reverse order of yanking. Return a 1.255 + // list of neighbors (edges) yanked. 1.256 + IndexSet *remove_node( uint a ); 1.257 + // Reinsert a yanked Node 1.258 + void re_insert( uint a ); 1.259 + // Return set of neighbors 1.260 + IndexSet *neighbors( uint a ) const { return &_adjs[a]; } 1.261 + 1.262 +#ifndef PRODUCT 1.263 + // Dump the IFG 1.264 + void dump() const; 1.265 + void stats() const; 1.266 + void verify( const PhaseChaitin * ) const; 1.267 +#endif 1.268 + 1.269 + //--------------- Live Range Accessors 1.270 + LRG &lrgs(uint idx) const { assert(idx < _maxlrg, "oob"); return _lrgs[idx]; } 1.271 + 1.272 + // Compute and set effective degree. Might be folded into SquareUp(). 1.273 + void Compute_Effective_Degree(); 1.274 + 1.275 + // Compute effective degree as the sum of neighbors' _sizes. 1.276 + int effective_degree( uint lidx ) const; 1.277 +}; 1.278 + 1.279 +// The LiveRangeMap class is responsible for storing node to live range id mapping. 1.280 +// Each node is mapped to a live range id (a virtual register). Nodes that are 1.281 +// not considered for register allocation are given live range id 0. 1.282 +class LiveRangeMap VALUE_OBJ_CLASS_SPEC { 1.283 + 1.284 +private: 1.285 + 1.286 + uint _max_lrg_id; 1.287 + 1.288 + // Union-find map. Declared as a short for speed. 1.289 + // Indexed by live-range number, it returns the compacted live-range number 1.290 + LRG_List _uf_map; 1.291 + 1.292 + // Map from Nodes to live ranges 1.293 + LRG_List _names; 1.294 + 1.295 + // Straight out of Tarjan's union-find algorithm 1.296 + uint find_compress(const Node *node) { 1.297 + uint lrg_id = find_compress(_names.at(node->_idx)); 1.298 + _names.at_put(node->_idx, lrg_id); 1.299 + return lrg_id; 1.300 + } 1.301 + 1.302 + uint find_compress(uint lrg); 1.303 + 1.304 +public: 1.305 + 1.306 + const LRG_List& names() { 1.307 + return _names; 1.308 + } 1.309 + 1.310 + uint max_lrg_id() const { 1.311 + return _max_lrg_id; 1.312 + } 1.313 + 1.314 + void set_max_lrg_id(uint max_lrg_id) { 1.315 + _max_lrg_id = max_lrg_id; 1.316 + } 1.317 + 1.318 + uint size() const { 1.319 + return _names.length(); 1.320 + } 1.321 + 1.322 + uint live_range_id(uint idx) const { 1.323 + return _names.at(idx); 1.324 + } 1.325 + 1.326 + uint live_range_id(const Node *node) const { 1.327 + return _names.at(node->_idx); 1.328 + } 1.329 + 1.330 + uint uf_live_range_id(uint lrg_id) const { 1.331 + return _uf_map.at(lrg_id); 1.332 + } 1.333 + 1.334 + void map(uint idx, uint lrg_id) { 1.335 + _names.at_put(idx, lrg_id); 1.336 + } 1.337 + 1.338 + void uf_map(uint dst_lrg_id, uint src_lrg_id) { 1.339 + _uf_map.at_put(dst_lrg_id, src_lrg_id); 1.340 + } 1.341 + 1.342 + void extend(uint idx, uint lrg_id) { 1.343 + _names.at_put_grow(idx, lrg_id); 1.344 + } 1.345 + 1.346 + void uf_extend(uint dst_lrg_id, uint src_lrg_id) { 1.347 + _uf_map.at_put_grow(dst_lrg_id, src_lrg_id); 1.348 + } 1.349 + 1.350 + LiveRangeMap(Arena* arena, uint unique) 1.351 + : _names(arena, unique, unique, 0) 1.352 + , _uf_map(arena, unique, unique, 0) 1.353 + , _max_lrg_id(0) {} 1.354 + 1.355 + uint find_id( const Node *n ) { 1.356 + uint retval = live_range_id(n); 1.357 + assert(retval == find(n),"Invalid node to lidx mapping"); 1.358 + return retval; 1.359 + } 1.360 + 1.361 + // Reset the Union-Find map to identity 1.362 + void reset_uf_map(uint max_lrg_id); 1.363 + 1.364 + // Make all Nodes map directly to their final live range; no need for 1.365 + // the Union-Find mapping after this call. 1.366 + void compress_uf_map_for_nodes(); 1.367 + 1.368 + uint find(uint lidx) { 1.369 + uint uf_lidx = _uf_map.at(lidx); 1.370 + return (uf_lidx == lidx) ? uf_lidx : find_compress(lidx); 1.371 + } 1.372 + 1.373 + // Convert a Node into a Live Range Index - a lidx 1.374 + uint find(const Node *node) { 1.375 + uint lidx = live_range_id(node); 1.376 + uint uf_lidx = _uf_map.at(lidx); 1.377 + return (uf_lidx == lidx) ? uf_lidx : find_compress(node); 1.378 + } 1.379 + 1.380 + // Like Find above, but no path compress, so bad asymptotic behavior 1.381 + uint find_const(uint lrg) const; 1.382 + 1.383 + // Like Find above, but no path compress, so bad asymptotic behavior 1.384 + uint find_const(const Node *node) const { 1.385 + if(node->_idx >= (uint)_names.length()) { 1.386 + return 0; // not mapped, usual for debug dump 1.387 + } 1.388 + return find_const(_names.at(node->_idx)); 1.389 + } 1.390 +}; 1.391 + 1.392 +//------------------------------Chaitin---------------------------------------- 1.393 +// Briggs-Chaitin style allocation, mostly. 1.394 +class PhaseChaitin : public PhaseRegAlloc { 1.395 + friend class VMStructs; 1.396 + 1.397 + int _trip_cnt; 1.398 + int _alternate; 1.399 + 1.400 + LRG &lrgs(uint idx) const { return _ifg->lrgs(idx); } 1.401 + PhaseLive *_live; // Liveness, used in the interference graph 1.402 + PhaseIFG *_ifg; // Interference graph (for original chunk) 1.403 + Node_List **_lrg_nodes; // Array of node; lists for lrgs which spill 1.404 + VectorSet _spilled_once; // Nodes that have been spilled 1.405 + VectorSet _spilled_twice; // Nodes that have been spilled twice 1.406 + 1.407 + // Combine the Live Range Indices for these 2 Nodes into a single live 1.408 + // range. Future requests for any Node in either live range will 1.409 + // return the live range index for the combined live range. 1.410 + void Union( const Node *src, const Node *dst ); 1.411 + 1.412 + void new_lrg( const Node *x, uint lrg ); 1.413 + 1.414 + // Compact live ranges, removing unused ones. Return new maxlrg. 1.415 + void compact(); 1.416 + 1.417 + uint _lo_degree; // Head of lo-degree LRGs list 1.418 + uint _lo_stk_degree; // Head of lo-stk-degree LRGs list 1.419 + uint _hi_degree; // Head of hi-degree LRGs list 1.420 + uint _simplified; // Linked list head of simplified LRGs 1.421 + 1.422 + // Helper functions for Split() 1.423 + uint split_DEF( Node *def, Block *b, int loc, uint max, Node **Reachblock, Node **debug_defs, GrowableArray<uint> splits, int slidx ); 1.424 + uint split_USE( Node *def, Block *b, Node *use, uint useidx, uint max, bool def_down, bool cisc_sp, GrowableArray<uint> splits, int slidx ); 1.425 + 1.426 + //------------------------------clone_projs------------------------------------ 1.427 + // After cloning some rematerialized instruction, clone any MachProj's that 1.428 + // follow it. Example: Intel zero is XOR, kills flags. Sparc FP constants 1.429 + // use G3 as an address temp. 1.430 + int clone_projs(Block* b, uint idx, Node* orig, Node* copy, uint& max_lrg_id); 1.431 + 1.432 + int clone_projs(Block* b, uint idx, Node* orig, Node* copy, LiveRangeMap& lrg_map) { 1.433 + uint max_lrg_id = lrg_map.max_lrg_id(); 1.434 + int found_projs = clone_projs(b, idx, orig, copy, max_lrg_id); 1.435 + if (found_projs > 0) { 1.436 + // max_lrg_id is updated during call above 1.437 + lrg_map.set_max_lrg_id(max_lrg_id); 1.438 + } 1.439 + return found_projs; 1.440 + } 1.441 + 1.442 + Node *split_Rematerialize(Node *def, Block *b, uint insidx, uint &maxlrg, GrowableArray<uint> splits, 1.443 + int slidx, uint *lrg2reach, Node **Reachblock, bool walkThru); 1.444 + // True if lidx is used before any real register is def'd in the block 1.445 + bool prompt_use( Block *b, uint lidx ); 1.446 + Node *get_spillcopy_wide( Node *def, Node *use, uint uidx ); 1.447 + // Insert the spill at chosen location. Skip over any intervening Proj's or 1.448 + // Phis. Skip over a CatchNode and projs, inserting in the fall-through block 1.449 + // instead. Update high-pressure indices. Create a new live range. 1.450 + void insert_proj( Block *b, uint i, Node *spill, uint maxlrg ); 1.451 + 1.452 + bool is_high_pressure( Block *b, LRG *lrg, uint insidx ); 1.453 + 1.454 + uint _oldphi; // Node index which separates pre-allocation nodes 1.455 + 1.456 + Block **_blks; // Array of blocks sorted by frequency for coalescing 1.457 + 1.458 + float _high_frequency_lrg; // Frequency at which LRG will be spilled for debug info 1.459 + 1.460 +#ifndef PRODUCT 1.461 + bool _trace_spilling; 1.462 +#endif 1.463 + 1.464 +public: 1.465 + PhaseChaitin( uint unique, PhaseCFG &cfg, Matcher &matcher ); 1.466 + ~PhaseChaitin() {} 1.467 + 1.468 + LiveRangeMap _lrg_map; 1.469 + 1.470 + // Do all the real work of allocate 1.471 + void Register_Allocate(); 1.472 + 1.473 + float high_frequency_lrg() const { return _high_frequency_lrg; } 1.474 + 1.475 +#ifndef PRODUCT 1.476 + bool trace_spilling() const { return _trace_spilling; } 1.477 +#endif 1.478 + 1.479 +private: 1.480 + // De-SSA the world. Assign registers to Nodes. Use the same register for 1.481 + // all inputs to a PhiNode, effectively coalescing live ranges. Insert 1.482 + // copies as needed. 1.483 + void de_ssa(); 1.484 + 1.485 + // Add edge between reg and everything in the vector. 1.486 + // Same as _ifg->add_vector(reg,live) EXCEPT use the RegMask 1.487 + // information to trim the set of interferences. Return the 1.488 + // count of edges added. 1.489 + void interfere_with_live( uint reg, IndexSet *live ); 1.490 + // Count register pressure for asserts 1.491 + uint count_int_pressure( IndexSet *liveout ); 1.492 + uint count_float_pressure( IndexSet *liveout ); 1.493 + 1.494 + // Build the interference graph using virtual registers only. 1.495 + // Used for aggressive coalescing. 1.496 + void build_ifg_virtual( ); 1.497 + 1.498 + // Build the interference graph using physical registers when available. 1.499 + // That is, if 2 live ranges are simultaneously alive but in their 1.500 + // acceptable register sets do not overlap, then they do not interfere. 1.501 + uint build_ifg_physical( ResourceArea *a ); 1.502 + 1.503 + // Gather LiveRanGe information, including register masks and base pointer/ 1.504 + // derived pointer relationships. 1.505 + void gather_lrg_masks( bool mod_cisc_masks ); 1.506 + 1.507 + // Force the bases of derived pointers to be alive at GC points. 1.508 + bool stretch_base_pointer_live_ranges( ResourceArea *a ); 1.509 + // Helper to stretch above; recursively discover the base Node for 1.510 + // a given derived Node. Easy for AddP-related machine nodes, but 1.511 + // needs to be recursive for derived Phis. 1.512 + Node *find_base_for_derived( Node **derived_base_map, Node *derived, uint &maxlrg ); 1.513 + 1.514 + // Set the was-lo-degree bit. Conservative coalescing should not change the 1.515 + // colorability of the graph. If any live range was of low-degree before 1.516 + // coalescing, it should Simplify. This call sets the was-lo-degree bit. 1.517 + void set_was_low(); 1.518 + 1.519 + // Split live-ranges that must spill due to register conflicts (as opposed 1.520 + // to capacity spills). Typically these are things def'd in a register 1.521 + // and used on the stack or vice-versa. 1.522 + void pre_spill(); 1.523 + 1.524 + // Init LRG caching of degree, numregs. Init lo_degree list. 1.525 + void cache_lrg_info( ); 1.526 + 1.527 + // Simplify the IFG by removing LRGs of low degree with no copies 1.528 + void Pre_Simplify(); 1.529 + 1.530 + // Simplify the IFG by removing LRGs of low degree 1.531 + void Simplify(); 1.532 + 1.533 + // Select colors by re-inserting edges into the IFG. 1.534 + // Return TRUE if any spills occurred. 1.535 + uint Select( ); 1.536 + // Helper function for select which allows biased coloring 1.537 + OptoReg::Name choose_color( LRG &lrg, int chunk ); 1.538 + // Helper function which implements biasing heuristic 1.539 + OptoReg::Name bias_color( LRG &lrg, int chunk ); 1.540 + 1.541 + // Split uncolorable live ranges 1.542 + // Return new number of live ranges 1.543 + uint Split(uint maxlrg, ResourceArea* split_arena); 1.544 + 1.545 + // Copy 'was_spilled'-edness from one Node to another. 1.546 + void copy_was_spilled( Node *src, Node *dst ); 1.547 + // Set the 'spilled_once' or 'spilled_twice' flag on a node. 1.548 + void set_was_spilled( Node *n ); 1.549 + 1.550 + // Convert ideal spill-nodes into machine loads & stores 1.551 + // Set C->failing when fixup spills could not complete, node limit exceeded. 1.552 + void fixup_spills(); 1.553 + 1.554 + // Post-Allocation peephole copy removal 1.555 + void post_allocate_copy_removal(); 1.556 + Node *skip_copies( Node *c ); 1.557 + // Replace the old node with the current live version of that value 1.558 + // and yank the old value if it's dead. 1.559 + int replace_and_yank_if_dead( Node *old, OptoReg::Name nreg, 1.560 + Block *current_block, Node_List& value, Node_List& regnd ) { 1.561 + Node* v = regnd[nreg]; 1.562 + assert(v->outcnt() != 0, "no dead values"); 1.563 + old->replace_by(v); 1.564 + return yank_if_dead(old, current_block, &value, ®nd); 1.565 + } 1.566 + 1.567 + int yank_if_dead( Node *old, Block *current_block, Node_List *value, Node_List *regnd ) { 1.568 + return yank_if_dead_recurse(old, old, current_block, value, regnd); 1.569 + } 1.570 + int yank_if_dead_recurse(Node *old, Node *orig_old, Block *current_block, 1.571 + Node_List *value, Node_List *regnd); 1.572 + int yank( Node *old, Block *current_block, Node_List *value, Node_List *regnd ); 1.573 + int elide_copy( Node *n, int k, Block *current_block, Node_List &value, Node_List ®nd, bool can_change_regs ); 1.574 + int use_prior_register( Node *copy, uint idx, Node *def, Block *current_block, Node_List &value, Node_List ®nd ); 1.575 + bool may_be_copy_of_callee( Node *def ) const; 1.576 + 1.577 + // If nreg already contains the same constant as val then eliminate it 1.578 + bool eliminate_copy_of_constant(Node* val, Node* n, 1.579 + Block *current_block, Node_List& value, Node_List ®nd, 1.580 + OptoReg::Name nreg, OptoReg::Name nreg2); 1.581 + // Extend the node to LRG mapping 1.582 + void add_reference( const Node *node, const Node *old_node); 1.583 + 1.584 +private: 1.585 + 1.586 + static int _final_loads, _final_stores, _final_copies, _final_memoves; 1.587 + static double _final_load_cost, _final_store_cost, _final_copy_cost, _final_memove_cost; 1.588 + static int _conserv_coalesce, _conserv_coalesce_pair; 1.589 + static int _conserv_coalesce_trie, _conserv_coalesce_quad; 1.590 + static int _post_alloc; 1.591 + static int _lost_opp_pp_coalesce, _lost_opp_cflow_coalesce; 1.592 + static int _used_cisc_instructions, _unused_cisc_instructions; 1.593 + static int _allocator_attempts, _allocator_successes; 1.594 + 1.595 +#ifndef PRODUCT 1.596 + static uint _high_pressure, _low_pressure; 1.597 + 1.598 + void dump() const; 1.599 + void dump( const Node *n ) const; 1.600 + void dump( const Block * b ) const; 1.601 + void dump_degree_lists() const; 1.602 + void dump_simplified() const; 1.603 + void dump_lrg( uint lidx, bool defs_only) const; 1.604 + void dump_lrg( uint lidx) const { 1.605 + // dump defs and uses by default 1.606 + dump_lrg(lidx, false); 1.607 + } 1.608 + void dump_bb( uint pre_order ) const; 1.609 + 1.610 + // Verify that base pointers and derived pointers are still sane 1.611 + void verify_base_ptrs( ResourceArea *a ) const; 1.612 + 1.613 + void verify( ResourceArea *a, bool verify_ifg = false ) const; 1.614 + 1.615 + void dump_for_spill_split_recycle() const; 1.616 + 1.617 +public: 1.618 + void dump_frame() const; 1.619 + char *dump_register( const Node *n, char *buf ) const; 1.620 +private: 1.621 + static void print_chaitin_statistics(); 1.622 +#endif 1.623 + friend class PhaseCoalesce; 1.624 + friend class PhaseAggressiveCoalesce; 1.625 + friend class PhaseConservativeCoalesce; 1.626 +}; 1.627 + 1.628 +#endif // SHARE_VM_OPTO_CHAITIN_HPP