Fri, 25 May 2012 07:53:11 -0700
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
Summary: optimize this code pattern obj.getClass() == A.class.
Reviewed-by: jrose, kvn
Contributed-by: Krystal Mok <sajia@taobao.com>
duke@435 | 1 | /* |
never@3138 | 2 | * Copyright (c) 1997, 2011, 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 | #ifndef SHARE_VM_OPTO_CHAITIN_HPP |
stefank@2314 | 26 | #define SHARE_VM_OPTO_CHAITIN_HPP |
stefank@2314 | 27 | |
stefank@2314 | 28 | #include "code/vmreg.hpp" |
stefank@2314 | 29 | #include "libadt/port.hpp" |
stefank@2314 | 30 | #include "memory/resourceArea.hpp" |
stefank@2314 | 31 | #include "opto/connode.hpp" |
stefank@2314 | 32 | #include "opto/live.hpp" |
stefank@2314 | 33 | #include "opto/matcher.hpp" |
stefank@2314 | 34 | #include "opto/phase.hpp" |
stefank@2314 | 35 | #include "opto/regalloc.hpp" |
stefank@2314 | 36 | #include "opto/regmask.hpp" |
stefank@2314 | 37 | |
duke@435 | 38 | class LoopTree; |
duke@435 | 39 | class MachCallNode; |
duke@435 | 40 | class MachSafePointNode; |
duke@435 | 41 | class Matcher; |
duke@435 | 42 | class PhaseCFG; |
duke@435 | 43 | class PhaseLive; |
duke@435 | 44 | class PhaseRegAlloc; |
duke@435 | 45 | class PhaseChaitin; |
duke@435 | 46 | |
duke@435 | 47 | #define OPTO_DEBUG_SPLIT_FREQ BLOCK_FREQUENCY(0.001) |
duke@435 | 48 | #define OPTO_LRG_HIGH_FREQ BLOCK_FREQUENCY(0.25) |
duke@435 | 49 | |
duke@435 | 50 | //------------------------------LRG-------------------------------------------- |
duke@435 | 51 | // Live-RanGe structure. |
duke@435 | 52 | class LRG : public ResourceObj { |
never@3138 | 53 | friend class VMStructs; |
duke@435 | 54 | public: |
duke@435 | 55 | enum { SPILL_REG=29999 }; // Register number of a spilled LRG |
duke@435 | 56 | |
duke@435 | 57 | double _cost; // 2 for loads/1 for stores times block freq |
duke@435 | 58 | double _area; // Sum of all simultaneously live values |
duke@435 | 59 | double score() const; // Compute score from cost and area |
duke@435 | 60 | double _maxfreq; // Maximum frequency of any def or use |
duke@435 | 61 | |
duke@435 | 62 | Node *_def; // Check for multi-def live ranges |
duke@435 | 63 | #ifndef PRODUCT |
duke@435 | 64 | GrowableArray<Node*>* _defs; |
duke@435 | 65 | #endif |
duke@435 | 66 | |
duke@435 | 67 | uint _risk_bias; // Index of LRG which we want to avoid color |
duke@435 | 68 | uint _copy_bias; // Index of LRG which we want to share color |
duke@435 | 69 | |
duke@435 | 70 | uint _next; // Index of next LRG in linked list |
duke@435 | 71 | uint _prev; // Index of prev LRG in linked list |
duke@435 | 72 | private: |
duke@435 | 73 | uint _reg; // Chosen register; undefined if mask is plural |
duke@435 | 74 | public: |
duke@435 | 75 | // Return chosen register for this LRG. Error if the LRG is not bound to |
duke@435 | 76 | // a single register. |
duke@435 | 77 | OptoReg::Name reg() const { return OptoReg::Name(_reg); } |
duke@435 | 78 | void set_reg( OptoReg::Name r ) { _reg = r; } |
duke@435 | 79 | |
duke@435 | 80 | private: |
duke@435 | 81 | uint _eff_degree; // Effective degree: Sum of neighbors _num_regs |
duke@435 | 82 | public: |
duke@435 | 83 | int degree() const { assert( _degree_valid, "" ); return _eff_degree; } |
duke@435 | 84 | // Degree starts not valid and any change to the IFG neighbor |
duke@435 | 85 | // set makes it not valid. |
duke@435 | 86 | void set_degree( uint degree ) { _eff_degree = degree; debug_only(_degree_valid = 1;) } |
duke@435 | 87 | // Made a change that hammered degree |
duke@435 | 88 | void invalid_degree() { debug_only(_degree_valid=0;) } |
duke@435 | 89 | // Incrementally modify degree. If it was correct, it should remain correct |
duke@435 | 90 | void inc_degree( uint mod ) { _eff_degree += mod; } |
duke@435 | 91 | // Compute the degree between 2 live ranges |
duke@435 | 92 | int compute_degree( LRG &l ) const; |
duke@435 | 93 | |
duke@435 | 94 | private: |
duke@435 | 95 | RegMask _mask; // Allowed registers for this LRG |
duke@435 | 96 | uint _mask_size; // cache of _mask.Size(); |
duke@435 | 97 | public: |
duke@435 | 98 | int compute_mask_size() const { return _mask.is_AllStack() ? 65535 : _mask.Size(); } |
duke@435 | 99 | void set_mask_size( int size ) { |
duke@435 | 100 | assert((size == 65535) || (size == (int)_mask.Size()), ""); |
duke@435 | 101 | _mask_size = size; |
duke@435 | 102 | debug_only(_msize_valid=1;) |
duke@435 | 103 | debug_only( if( _num_regs == 2 && !_fat_proj ) _mask.VerifyPairs(); ) |
duke@435 | 104 | } |
duke@435 | 105 | void compute_set_mask_size() { set_mask_size(compute_mask_size()); } |
duke@435 | 106 | int mask_size() const { assert( _msize_valid, "mask size not valid" ); |
duke@435 | 107 | return _mask_size; } |
duke@435 | 108 | // Get the last mask size computed, even if it does not match the |
duke@435 | 109 | // count of bits in the current mask. |
duke@435 | 110 | int get_invalid_mask_size() const { return _mask_size; } |
duke@435 | 111 | const RegMask &mask() const { return _mask; } |
duke@435 | 112 | void set_mask( const RegMask &rm ) { _mask = rm; debug_only(_msize_valid=0;)} |
duke@435 | 113 | void AND( const RegMask &rm ) { _mask.AND(rm); debug_only(_msize_valid=0;)} |
duke@435 | 114 | void SUBTRACT( const RegMask &rm ) { _mask.SUBTRACT(rm); debug_only(_msize_valid=0;)} |
duke@435 | 115 | void Clear() { _mask.Clear() ; debug_only(_msize_valid=1); _mask_size = 0; } |
duke@435 | 116 | void Set_All() { _mask.Set_All(); debug_only(_msize_valid=1); _mask_size = RegMask::CHUNK_SIZE; } |
duke@435 | 117 | void Insert( OptoReg::Name reg ) { _mask.Insert(reg); debug_only(_msize_valid=0;) } |
duke@435 | 118 | void Remove( OptoReg::Name reg ) { _mask.Remove(reg); debug_only(_msize_valid=0;) } |
duke@435 | 119 | void ClearToPairs() { _mask.ClearToPairs(); debug_only(_msize_valid=0;) } |
duke@435 | 120 | |
duke@435 | 121 | // Number of registers this live range uses when it colors |
duke@435 | 122 | private: |
duke@435 | 123 | uint8 _num_regs; // 2 for Longs and Doubles, 1 for all else |
duke@435 | 124 | // except _num_regs is kill count for fat_proj |
duke@435 | 125 | public: |
duke@435 | 126 | int num_regs() const { return _num_regs; } |
duke@435 | 127 | void set_num_regs( int reg ) { assert( _num_regs == reg || !_num_regs, "" ); _num_regs = reg; } |
duke@435 | 128 | |
duke@435 | 129 | private: |
duke@435 | 130 | // Number of physical registers this live range uses when it colors |
duke@435 | 131 | // Architecture and register-set dependent |
duke@435 | 132 | uint8 _reg_pressure; |
duke@435 | 133 | public: |
duke@435 | 134 | void set_reg_pressure(int i) { _reg_pressure = i; } |
duke@435 | 135 | int reg_pressure() const { return _reg_pressure; } |
duke@435 | 136 | |
duke@435 | 137 | // How much 'wiggle room' does this live range have? |
duke@435 | 138 | // How many color choices can it make (scaled by _num_regs)? |
duke@435 | 139 | int degrees_of_freedom() const { return mask_size() - _num_regs; } |
duke@435 | 140 | // Bound LRGs have ZERO degrees of freedom. We also count |
duke@435 | 141 | // must_spill as bound. |
duke@435 | 142 | bool is_bound () const { return _is_bound; } |
duke@435 | 143 | // Negative degrees-of-freedom; even with no neighbors this |
duke@435 | 144 | // live range must spill. |
duke@435 | 145 | bool not_free() const { return degrees_of_freedom() < 0; } |
duke@435 | 146 | // Is this live range of "low-degree"? Trivially colorable? |
duke@435 | 147 | bool lo_degree () const { return degree() <= degrees_of_freedom(); } |
duke@435 | 148 | // Is this live range just barely "low-degree"? Trivially colorable? |
duke@435 | 149 | bool just_lo_degree () const { return degree() == degrees_of_freedom(); } |
duke@435 | 150 | |
duke@435 | 151 | uint _is_oop:1, // Live-range holds an oop |
duke@435 | 152 | _is_float:1, // True if in float registers |
duke@435 | 153 | _was_spilled1:1, // True if prior spilling on def |
duke@435 | 154 | _was_spilled2:1, // True if twice prior spilling on def |
duke@435 | 155 | _is_bound:1, // live range starts life with no |
duke@435 | 156 | // degrees of freedom. |
duke@435 | 157 | _direct_conflict:1, // True if def and use registers in conflict |
duke@435 | 158 | _must_spill:1, // live range has lost all degrees of freedom |
duke@435 | 159 | // If _fat_proj is set, live range does NOT require aligned, adjacent |
duke@435 | 160 | // registers and has NO interferences. |
duke@435 | 161 | // If _fat_proj is clear, live range requires num_regs() to be a power of |
duke@435 | 162 | // 2, and it requires registers to form an aligned, adjacent set. |
duke@435 | 163 | _fat_proj:1, // |
duke@435 | 164 | _was_lo:1, // Was lo-degree prior to coalesce |
duke@435 | 165 | _msize_valid:1, // _mask_size cache valid |
duke@435 | 166 | _degree_valid:1, // _degree cache valid |
duke@435 | 167 | _has_copy:1, // Adjacent to some copy instruction |
duke@435 | 168 | _at_risk:1; // Simplify says this guy is at risk to spill |
duke@435 | 169 | |
duke@435 | 170 | |
duke@435 | 171 | // Alive if non-zero, dead if zero |
duke@435 | 172 | bool alive() const { return _def != NULL; } |
never@730 | 173 | bool is_multidef() const { return _def == NodeSentinel; } |
never@730 | 174 | bool is_singledef() const { return _def != NodeSentinel; } |
duke@435 | 175 | |
duke@435 | 176 | #ifndef PRODUCT |
duke@435 | 177 | void dump( ) const; |
duke@435 | 178 | #endif |
duke@435 | 179 | }; |
duke@435 | 180 | |
duke@435 | 181 | //------------------------------LRG_List--------------------------------------- |
duke@435 | 182 | // Map Node indices to Live RanGe indices. |
duke@435 | 183 | // Array lookup in the optimized case. |
duke@435 | 184 | class LRG_List : public ResourceObj { |
never@3138 | 185 | friend class VMStructs; |
duke@435 | 186 | uint _cnt, _max; |
duke@435 | 187 | uint* _lidxs; |
duke@435 | 188 | ReallocMark _nesting; // assertion check for reallocations |
duke@435 | 189 | public: |
duke@435 | 190 | LRG_List( uint max ); |
duke@435 | 191 | |
duke@435 | 192 | uint lookup( uint nidx ) const { |
duke@435 | 193 | return _lidxs[nidx]; |
duke@435 | 194 | } |
duke@435 | 195 | uint operator[] (uint nidx) const { return lookup(nidx); } |
duke@435 | 196 | |
duke@435 | 197 | void map( uint nidx, uint lidx ) { |
duke@435 | 198 | assert( nidx < _cnt, "oob" ); |
duke@435 | 199 | _lidxs[nidx] = lidx; |
duke@435 | 200 | } |
duke@435 | 201 | void extend( uint nidx, uint lidx ); |
duke@435 | 202 | |
duke@435 | 203 | uint Size() const { return _cnt; } |
duke@435 | 204 | }; |
duke@435 | 205 | |
duke@435 | 206 | //------------------------------IFG-------------------------------------------- |
duke@435 | 207 | // InterFerence Graph |
duke@435 | 208 | // An undirected graph implementation. Created with a fixed number of |
duke@435 | 209 | // vertices. Edges can be added & tested. Vertices can be removed, then |
duke@435 | 210 | // added back later with all edges intact. Can add edges between one vertex |
duke@435 | 211 | // and a list of other vertices. Can union vertices (and their edges) |
duke@435 | 212 | // together. The IFG needs to be really really fast, and also fairly |
duke@435 | 213 | // abstract! It needs abstraction so I can fiddle with the implementation to |
duke@435 | 214 | // get even more speed. |
duke@435 | 215 | class PhaseIFG : public Phase { |
never@3138 | 216 | friend class VMStructs; |
duke@435 | 217 | // Current implementation: a triangular adjacency list. |
duke@435 | 218 | |
duke@435 | 219 | // Array of adjacency-lists, indexed by live-range number |
duke@435 | 220 | IndexSet *_adjs; |
duke@435 | 221 | |
duke@435 | 222 | // Assertion bit for proper use of Squaring |
duke@435 | 223 | bool _is_square; |
duke@435 | 224 | |
duke@435 | 225 | // Live range structure goes here |
duke@435 | 226 | LRG *_lrgs; // Array of LRG structures |
duke@435 | 227 | |
duke@435 | 228 | public: |
duke@435 | 229 | // Largest live-range number |
duke@435 | 230 | uint _maxlrg; |
duke@435 | 231 | |
duke@435 | 232 | Arena *_arena; |
duke@435 | 233 | |
duke@435 | 234 | // Keep track of inserted and deleted Nodes |
duke@435 | 235 | VectorSet *_yanked; |
duke@435 | 236 | |
duke@435 | 237 | PhaseIFG( Arena *arena ); |
duke@435 | 238 | void init( uint maxlrg ); |
duke@435 | 239 | |
duke@435 | 240 | // Add edge between a and b. Returns true if actually addded. |
duke@435 | 241 | int add_edge( uint a, uint b ); |
duke@435 | 242 | |
duke@435 | 243 | // Add edge between a and everything in the vector |
duke@435 | 244 | void add_vector( uint a, IndexSet *vec ); |
duke@435 | 245 | |
duke@435 | 246 | // Test for edge existance |
duke@435 | 247 | int test_edge( uint a, uint b ) const; |
duke@435 | 248 | |
duke@435 | 249 | // Square-up matrix for faster Union |
duke@435 | 250 | void SquareUp(); |
duke@435 | 251 | |
duke@435 | 252 | // Return number of LRG neighbors |
duke@435 | 253 | uint neighbor_cnt( uint a ) const { return _adjs[a].count(); } |
duke@435 | 254 | // Union edges of b into a on Squared-up matrix |
duke@435 | 255 | void Union( uint a, uint b ); |
duke@435 | 256 | // Test for edge in Squared-up matrix |
duke@435 | 257 | int test_edge_sq( uint a, uint b ) const; |
duke@435 | 258 | // Yank a Node and all connected edges from the IFG. Be prepared to |
duke@435 | 259 | // re-insert the yanked Node in reverse order of yanking. Return a |
duke@435 | 260 | // list of neighbors (edges) yanked. |
duke@435 | 261 | IndexSet *remove_node( uint a ); |
duke@435 | 262 | // Reinsert a yanked Node |
duke@435 | 263 | void re_insert( uint a ); |
duke@435 | 264 | // Return set of neighbors |
duke@435 | 265 | IndexSet *neighbors( uint a ) const { return &_adjs[a]; } |
duke@435 | 266 | |
duke@435 | 267 | #ifndef PRODUCT |
duke@435 | 268 | // Dump the IFG |
duke@435 | 269 | void dump() const; |
duke@435 | 270 | void stats() const; |
duke@435 | 271 | void verify( const PhaseChaitin * ) const; |
duke@435 | 272 | #endif |
duke@435 | 273 | |
duke@435 | 274 | //--------------- Live Range Accessors |
duke@435 | 275 | LRG &lrgs(uint idx) const { assert(idx < _maxlrg, "oob"); return _lrgs[idx]; } |
duke@435 | 276 | |
duke@435 | 277 | // Compute and set effective degree. Might be folded into SquareUp(). |
duke@435 | 278 | void Compute_Effective_Degree(); |
duke@435 | 279 | |
duke@435 | 280 | // Compute effective degree as the sum of neighbors' _sizes. |
duke@435 | 281 | int effective_degree( uint lidx ) const; |
duke@435 | 282 | }; |
duke@435 | 283 | |
duke@435 | 284 | // TEMPORARILY REPLACED WITH COMMAND LINE FLAG |
duke@435 | 285 | |
duke@435 | 286 | //// !!!!! Magic Constants need to move into ad file |
duke@435 | 287 | #ifdef SPARC |
duke@435 | 288 | //#define FLOAT_PRESSURE 30 /* SFLT_REG_mask.Size() - 1 */ |
duke@435 | 289 | //#define INT_PRESSURE 23 /* NOTEMP_I_REG_mask.Size() - 1 */ |
duke@435 | 290 | #define FLOAT_INCREMENT(regs) regs |
duke@435 | 291 | #else |
duke@435 | 292 | //#define FLOAT_PRESSURE 6 |
duke@435 | 293 | //#define INT_PRESSURE 6 |
duke@435 | 294 | #define FLOAT_INCREMENT(regs) 1 |
duke@435 | 295 | #endif |
duke@435 | 296 | |
duke@435 | 297 | //------------------------------Chaitin---------------------------------------- |
duke@435 | 298 | // Briggs-Chaitin style allocation, mostly. |
duke@435 | 299 | class PhaseChaitin : public PhaseRegAlloc { |
never@3138 | 300 | friend class VMStructs; |
duke@435 | 301 | |
duke@435 | 302 | int _trip_cnt; |
duke@435 | 303 | int _alternate; |
duke@435 | 304 | |
duke@435 | 305 | uint _maxlrg; // Max live range number |
duke@435 | 306 | LRG &lrgs(uint idx) const { return _ifg->lrgs(idx); } |
duke@435 | 307 | PhaseLive *_live; // Liveness, used in the interference graph |
duke@435 | 308 | PhaseIFG *_ifg; // Interference graph (for original chunk) |
duke@435 | 309 | Node_List **_lrg_nodes; // Array of node; lists for lrgs which spill |
duke@435 | 310 | VectorSet _spilled_once; // Nodes that have been spilled |
duke@435 | 311 | VectorSet _spilled_twice; // Nodes that have been spilled twice |
duke@435 | 312 | |
duke@435 | 313 | LRG_List _names; // Map from Nodes to Live RanGes |
duke@435 | 314 | |
duke@435 | 315 | // Union-find map. Declared as a short for speed. |
duke@435 | 316 | // Indexed by live-range number, it returns the compacted live-range number |
duke@435 | 317 | LRG_List _uf_map; |
duke@435 | 318 | // Reset the Union-Find map to identity |
duke@435 | 319 | void reset_uf_map( uint maxlrg ); |
duke@435 | 320 | // Remove the need for the Union-Find mapping |
duke@435 | 321 | void compress_uf_map_for_nodes( ); |
duke@435 | 322 | |
duke@435 | 323 | // Combine the Live Range Indices for these 2 Nodes into a single live |
duke@435 | 324 | // range. Future requests for any Node in either live range will |
duke@435 | 325 | // return the live range index for the combined live range. |
duke@435 | 326 | void Union( const Node *src, const Node *dst ); |
duke@435 | 327 | |
duke@435 | 328 | void new_lrg( const Node *x, uint lrg ); |
duke@435 | 329 | |
duke@435 | 330 | // Compact live ranges, removing unused ones. Return new maxlrg. |
duke@435 | 331 | void compact(); |
duke@435 | 332 | |
duke@435 | 333 | uint _lo_degree; // Head of lo-degree LRGs list |
duke@435 | 334 | uint _lo_stk_degree; // Head of lo-stk-degree LRGs list |
duke@435 | 335 | uint _hi_degree; // Head of hi-degree LRGs list |
duke@435 | 336 | uint _simplified; // Linked list head of simplified LRGs |
duke@435 | 337 | |
duke@435 | 338 | // Helper functions for Split() |
duke@435 | 339 | uint split_DEF( Node *def, Block *b, int loc, uint max, Node **Reachblock, Node **debug_defs, GrowableArray<uint> splits, int slidx ); |
duke@435 | 340 | uint split_USE( Node *def, Block *b, Node *use, uint useidx, uint max, bool def_down, bool cisc_sp, GrowableArray<uint> splits, int slidx ); |
duke@435 | 341 | int clone_projs( Block *b, uint idx, Node *con, Node *copy, uint &maxlrg ); |
never@730 | 342 | Node *split_Rematerialize(Node *def, Block *b, uint insidx, uint &maxlrg, GrowableArray<uint> splits, |
never@730 | 343 | int slidx, uint *lrg2reach, Node **Reachblock, bool walkThru); |
duke@435 | 344 | // True if lidx is used before any real register is def'd in the block |
duke@435 | 345 | bool prompt_use( Block *b, uint lidx ); |
duke@435 | 346 | Node *get_spillcopy_wide( Node *def, Node *use, uint uidx ); |
twisti@1040 | 347 | // Insert the spill at chosen location. Skip over any intervening Proj's or |
duke@435 | 348 | // Phis. Skip over a CatchNode and projs, inserting in the fall-through block |
duke@435 | 349 | // instead. Update high-pressure indices. Create a new live range. |
duke@435 | 350 | void insert_proj( Block *b, uint i, Node *spill, uint maxlrg ); |
duke@435 | 351 | |
duke@435 | 352 | bool is_high_pressure( Block *b, LRG *lrg, uint insidx ); |
duke@435 | 353 | |
duke@435 | 354 | uint _oldphi; // Node index which separates pre-allocation nodes |
duke@435 | 355 | |
duke@435 | 356 | Block **_blks; // Array of blocks sorted by frequency for coalescing |
duke@435 | 357 | |
kvn@1108 | 358 | float _high_frequency_lrg; // Frequency at which LRG will be spilled for debug info |
kvn@1108 | 359 | |
duke@435 | 360 | #ifndef PRODUCT |
duke@435 | 361 | bool _trace_spilling; |
duke@435 | 362 | #endif |
duke@435 | 363 | |
duke@435 | 364 | public: |
duke@435 | 365 | PhaseChaitin( uint unique, PhaseCFG &cfg, Matcher &matcher ); |
duke@435 | 366 | ~PhaseChaitin() {} |
duke@435 | 367 | |
duke@435 | 368 | // Convert a Node into a Live Range Index - a lidx |
duke@435 | 369 | uint Find( const Node *n ) { |
duke@435 | 370 | uint lidx = n2lidx(n); |
duke@435 | 371 | uint uf_lidx = _uf_map[lidx]; |
duke@435 | 372 | return (uf_lidx == lidx) ? uf_lidx : Find_compress(n); |
duke@435 | 373 | } |
duke@435 | 374 | uint Find_const( uint lrg ) const; |
duke@435 | 375 | uint Find_const( const Node *n ) const; |
duke@435 | 376 | |
duke@435 | 377 | // Do all the real work of allocate |
duke@435 | 378 | void Register_Allocate(); |
duke@435 | 379 | |
duke@435 | 380 | uint n2lidx( const Node *n ) const { return _names[n->_idx]; } |
duke@435 | 381 | |
kvn@1108 | 382 | float high_frequency_lrg() const { return _high_frequency_lrg; } |
kvn@1108 | 383 | |
duke@435 | 384 | #ifndef PRODUCT |
duke@435 | 385 | bool trace_spilling() const { return _trace_spilling; } |
duke@435 | 386 | #endif |
duke@435 | 387 | |
duke@435 | 388 | private: |
duke@435 | 389 | // De-SSA the world. Assign registers to Nodes. Use the same register for |
duke@435 | 390 | // all inputs to a PhiNode, effectively coalescing live ranges. Insert |
duke@435 | 391 | // copies as needed. |
duke@435 | 392 | void de_ssa(); |
duke@435 | 393 | uint Find_compress( const Node *n ); |
duke@435 | 394 | uint Find( uint lidx ) { |
duke@435 | 395 | uint uf_lidx = _uf_map[lidx]; |
duke@435 | 396 | return (uf_lidx == lidx) ? uf_lidx : Find_compress(lidx); |
duke@435 | 397 | } |
duke@435 | 398 | uint Find_compress( uint lidx ); |
duke@435 | 399 | |
duke@435 | 400 | uint Find_id( const Node *n ) { |
duke@435 | 401 | uint retval = n2lidx(n); |
duke@435 | 402 | assert(retval == Find(n),"Invalid node to lidx mapping"); |
duke@435 | 403 | return retval; |
duke@435 | 404 | } |
duke@435 | 405 | |
duke@435 | 406 | // Add edge between reg and everything in the vector. |
duke@435 | 407 | // Same as _ifg->add_vector(reg,live) EXCEPT use the RegMask |
duke@435 | 408 | // information to trim the set of interferences. Return the |
duke@435 | 409 | // count of edges added. |
duke@435 | 410 | void interfere_with_live( uint reg, IndexSet *live ); |
duke@435 | 411 | // Count register pressure for asserts |
duke@435 | 412 | uint count_int_pressure( IndexSet *liveout ); |
duke@435 | 413 | uint count_float_pressure( IndexSet *liveout ); |
duke@435 | 414 | |
duke@435 | 415 | // Build the interference graph using virtual registers only. |
duke@435 | 416 | // Used for aggressive coalescing. |
duke@435 | 417 | void build_ifg_virtual( ); |
duke@435 | 418 | |
duke@435 | 419 | // Build the interference graph using physical registers when available. |
duke@435 | 420 | // That is, if 2 live ranges are simultaneously alive but in their |
duke@435 | 421 | // acceptable register sets do not overlap, then they do not interfere. |
duke@435 | 422 | uint build_ifg_physical( ResourceArea *a ); |
duke@435 | 423 | |
duke@435 | 424 | // Gather LiveRanGe information, including register masks and base pointer/ |
duke@435 | 425 | // derived pointer relationships. |
duke@435 | 426 | void gather_lrg_masks( bool mod_cisc_masks ); |
duke@435 | 427 | |
duke@435 | 428 | // Force the bases of derived pointers to be alive at GC points. |
duke@435 | 429 | bool stretch_base_pointer_live_ranges( ResourceArea *a ); |
duke@435 | 430 | // Helper to stretch above; recursively discover the base Node for |
duke@435 | 431 | // a given derived Node. Easy for AddP-related machine nodes, but |
duke@435 | 432 | // needs to be recursive for derived Phis. |
duke@435 | 433 | Node *find_base_for_derived( Node **derived_base_map, Node *derived, uint &maxlrg ); |
duke@435 | 434 | |
duke@435 | 435 | // Set the was-lo-degree bit. Conservative coalescing should not change the |
duke@435 | 436 | // colorability of the graph. If any live range was of low-degree before |
duke@435 | 437 | // coalescing, it should Simplify. This call sets the was-lo-degree bit. |
duke@435 | 438 | void set_was_low(); |
duke@435 | 439 | |
duke@435 | 440 | // Split live-ranges that must spill due to register conflicts (as opposed |
duke@435 | 441 | // to capacity spills). Typically these are things def'd in a register |
duke@435 | 442 | // and used on the stack or vice-versa. |
duke@435 | 443 | void pre_spill(); |
duke@435 | 444 | |
duke@435 | 445 | // Init LRG caching of degree, numregs. Init lo_degree list. |
duke@435 | 446 | void cache_lrg_info( ); |
duke@435 | 447 | |
duke@435 | 448 | // Simplify the IFG by removing LRGs of low degree with no copies |
duke@435 | 449 | void Pre_Simplify(); |
duke@435 | 450 | |
duke@435 | 451 | // Simplify the IFG by removing LRGs of low degree |
duke@435 | 452 | void Simplify(); |
duke@435 | 453 | |
duke@435 | 454 | // Select colors by re-inserting edges into the IFG. |
twisti@1040 | 455 | // Return TRUE if any spills occurred. |
duke@435 | 456 | uint Select( ); |
duke@435 | 457 | // Helper function for select which allows biased coloring |
duke@435 | 458 | OptoReg::Name choose_color( LRG &lrg, int chunk ); |
duke@435 | 459 | // Helper function which implements biasing heuristic |
duke@435 | 460 | OptoReg::Name bias_color( LRG &lrg, int chunk ); |
duke@435 | 461 | |
duke@435 | 462 | // Split uncolorable live ranges |
duke@435 | 463 | // Return new number of live ranges |
duke@435 | 464 | uint Split( uint maxlrg ); |
duke@435 | 465 | |
duke@435 | 466 | // Copy 'was_spilled'-edness from one Node to another. |
duke@435 | 467 | void copy_was_spilled( Node *src, Node *dst ); |
duke@435 | 468 | // Set the 'spilled_once' or 'spilled_twice' flag on a node. |
duke@435 | 469 | void set_was_spilled( Node *n ); |
duke@435 | 470 | |
duke@435 | 471 | // Convert ideal spill-nodes into machine loads & stores |
duke@435 | 472 | // Set C->failing when fixup spills could not complete, node limit exceeded. |
duke@435 | 473 | void fixup_spills(); |
duke@435 | 474 | |
duke@435 | 475 | // Post-Allocation peephole copy removal |
duke@435 | 476 | void post_allocate_copy_removal(); |
duke@435 | 477 | Node *skip_copies( Node *c ); |
never@1358 | 478 | // Replace the old node with the current live version of that value |
never@1358 | 479 | // and yank the old value if it's dead. |
never@1358 | 480 | int replace_and_yank_if_dead( Node *old, OptoReg::Name nreg, |
never@1358 | 481 | Block *current_block, Node_List& value, Node_List& regnd ) { |
never@1358 | 482 | Node* v = regnd[nreg]; |
never@1358 | 483 | assert(v->outcnt() != 0, "no dead values"); |
never@1358 | 484 | old->replace_by(v); |
never@1358 | 485 | return yank_if_dead(old, current_block, &value, ®nd); |
never@1358 | 486 | } |
never@1358 | 487 | |
kvn@3405 | 488 | int yank_if_dead( Node *old, Block *current_block, Node_List *value, Node_List *regnd ) { |
kvn@3405 | 489 | return yank_if_dead_recurse(old, old, current_block, value, regnd); |
kvn@3405 | 490 | } |
kvn@3405 | 491 | int yank_if_dead_recurse(Node *old, Node *orig_old, Block *current_block, |
kvn@3405 | 492 | Node_List *value, Node_List *regnd); |
roland@3133 | 493 | int yank( Node *old, Block *current_block, Node_List *value, Node_List *regnd ); |
duke@435 | 494 | int elide_copy( Node *n, int k, Block *current_block, Node_List &value, Node_List ®nd, bool can_change_regs ); |
duke@435 | 495 | int use_prior_register( Node *copy, uint idx, Node *def, Block *current_block, Node_List &value, Node_List ®nd ); |
duke@435 | 496 | bool may_be_copy_of_callee( Node *def ) const; |
duke@435 | 497 | |
duke@435 | 498 | // If nreg already contains the same constant as val then eliminate it |
never@505 | 499 | bool eliminate_copy_of_constant(Node* val, Node* n, |
never@505 | 500 | Block *current_block, Node_List& value, Node_List ®nd, |
duke@435 | 501 | OptoReg::Name nreg, OptoReg::Name nreg2); |
duke@435 | 502 | // Extend the node to LRG mapping |
duke@435 | 503 | void add_reference( const Node *node, const Node *old_node); |
duke@435 | 504 | |
duke@435 | 505 | private: |
duke@435 | 506 | |
duke@435 | 507 | static int _final_loads, _final_stores, _final_copies, _final_memoves; |
duke@435 | 508 | static double _final_load_cost, _final_store_cost, _final_copy_cost, _final_memove_cost; |
duke@435 | 509 | static int _conserv_coalesce, _conserv_coalesce_pair; |
duke@435 | 510 | static int _conserv_coalesce_trie, _conserv_coalesce_quad; |
duke@435 | 511 | static int _post_alloc; |
duke@435 | 512 | static int _lost_opp_pp_coalesce, _lost_opp_cflow_coalesce; |
duke@435 | 513 | static int _used_cisc_instructions, _unused_cisc_instructions; |
duke@435 | 514 | static int _allocator_attempts, _allocator_successes; |
duke@435 | 515 | |
duke@435 | 516 | #ifndef PRODUCT |
duke@435 | 517 | static uint _high_pressure, _low_pressure; |
duke@435 | 518 | |
duke@435 | 519 | void dump() const; |
duke@435 | 520 | void dump( const Node *n ) const; |
duke@435 | 521 | void dump( const Block * b ) const; |
duke@435 | 522 | void dump_degree_lists() const; |
duke@435 | 523 | void dump_simplified() const; |
never@2358 | 524 | void dump_lrg( uint lidx, bool defs_only) const; |
never@2358 | 525 | void dump_lrg( uint lidx) const { |
never@2358 | 526 | // dump defs and uses by default |
never@2358 | 527 | dump_lrg(lidx, false); |
never@2358 | 528 | } |
duke@435 | 529 | void dump_bb( uint pre_order ) const; |
duke@435 | 530 | |
duke@435 | 531 | // Verify that base pointers and derived pointers are still sane |
duke@435 | 532 | void verify_base_ptrs( ResourceArea *a ) const; |
duke@435 | 533 | |
kvn@1001 | 534 | void verify( ResourceArea *a, bool verify_ifg = false ) const; |
kvn@1001 | 535 | |
duke@435 | 536 | void dump_for_spill_split_recycle() const; |
duke@435 | 537 | |
duke@435 | 538 | public: |
duke@435 | 539 | void dump_frame() const; |
duke@435 | 540 | char *dump_register( const Node *n, char *buf ) const; |
duke@435 | 541 | private: |
duke@435 | 542 | static void print_chaitin_statistics(); |
duke@435 | 543 | #endif |
duke@435 | 544 | friend class PhaseCoalesce; |
duke@435 | 545 | friend class PhaseAggressiveCoalesce; |
duke@435 | 546 | friend class PhaseConservativeCoalesce; |
duke@435 | 547 | }; |
stefank@2314 | 548 | |
stefank@2314 | 549 | #endif // SHARE_VM_OPTO_CHAITIN_HPP |