duke@435: /* mikael@6198: * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #ifndef SHARE_VM_OPTO_CHAITIN_HPP stefank@2314: #define SHARE_VM_OPTO_CHAITIN_HPP stefank@2314: stefank@2314: #include "code/vmreg.hpp" stefank@2314: #include "libadt/port.hpp" stefank@2314: #include "memory/resourceArea.hpp" stefank@2314: #include "opto/connode.hpp" stefank@2314: #include "opto/live.hpp" stefank@2314: #include "opto/matcher.hpp" stefank@2314: #include "opto/phase.hpp" stefank@2314: #include "opto/regalloc.hpp" stefank@2314: #include "opto/regmask.hpp" stefank@2314: duke@435: class LoopTree; duke@435: class MachCallNode; duke@435: class MachSafePointNode; duke@435: class Matcher; duke@435: class PhaseCFG; duke@435: class PhaseLive; duke@435: class PhaseRegAlloc; duke@435: class PhaseChaitin; duke@435: duke@435: #define OPTO_DEBUG_SPLIT_FREQ BLOCK_FREQUENCY(0.001) duke@435: #define OPTO_LRG_HIGH_FREQ BLOCK_FREQUENCY(0.25) duke@435: duke@435: //------------------------------LRG-------------------------------------------- duke@435: // Live-RanGe structure. duke@435: class LRG : public ResourceObj { never@3138: friend class VMStructs; duke@435: public: adlertz@5916: static const uint AllStack_size = 0xFFFFF; // This mask size is used to tell that the mask of this LRG supports stack positions duke@435: enum { SPILL_REG=29999 }; // Register number of a spilled LRG duke@435: duke@435: double _cost; // 2 for loads/1 for stores times block freq duke@435: double _area; // Sum of all simultaneously live values duke@435: double score() const; // Compute score from cost and area duke@435: double _maxfreq; // Maximum frequency of any def or use duke@435: duke@435: Node *_def; // Check for multi-def live ranges duke@435: #ifndef PRODUCT duke@435: GrowableArray* _defs; duke@435: #endif duke@435: duke@435: uint _risk_bias; // Index of LRG which we want to avoid color duke@435: uint _copy_bias; // Index of LRG which we want to share color duke@435: duke@435: uint _next; // Index of next LRG in linked list duke@435: uint _prev; // Index of prev LRG in linked list duke@435: private: duke@435: uint _reg; // Chosen register; undefined if mask is plural duke@435: public: duke@435: // Return chosen register for this LRG. Error if the LRG is not bound to duke@435: // a single register. duke@435: OptoReg::Name reg() const { return OptoReg::Name(_reg); } duke@435: void set_reg( OptoReg::Name r ) { _reg = r; } duke@435: duke@435: private: duke@435: uint _eff_degree; // Effective degree: Sum of neighbors _num_regs duke@435: public: adlertz@5916: int degree() const { assert( _degree_valid , "" ); return _eff_degree; } duke@435: // Degree starts not valid and any change to the IFG neighbor duke@435: // set makes it not valid. adlertz@5916: void set_degree( uint degree ) { adlertz@5916: _eff_degree = degree; adlertz@5916: debug_only(_degree_valid = 1;) adlertz@5916: 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"); adlertz@5916: } duke@435: // Made a change that hammered degree duke@435: void invalid_degree() { debug_only(_degree_valid=0;) } duke@435: // Incrementally modify degree. If it was correct, it should remain correct adlertz@5916: void inc_degree( uint mod ) { adlertz@5916: _eff_degree += mod; adlertz@5916: 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"); adlertz@5916: } duke@435: // Compute the degree between 2 live ranges duke@435: int compute_degree( LRG &l ) const; duke@435: duke@435: private: duke@435: RegMask _mask; // Allowed registers for this LRG duke@435: uint _mask_size; // cache of _mask.Size(); duke@435: public: adlertz@5916: int compute_mask_size() const { return _mask.is_AllStack() ? AllStack_size : _mask.Size(); } duke@435: void set_mask_size( int size ) { adlertz@5916: assert((size == (int)AllStack_size) || (size == (int)_mask.Size()), ""); duke@435: _mask_size = size; kvn@3882: #ifdef ASSERT kvn@3882: _msize_valid=1; kvn@3882: if (_is_vector) { kvn@3882: assert(!_fat_proj, "sanity"); kvn@3882: _mask.verify_sets(_num_regs); kvn@3882: } else if (_num_regs == 2 && !_fat_proj) { kvn@3882: _mask.verify_pairs(); kvn@3882: } kvn@3882: #endif duke@435: } duke@435: void compute_set_mask_size() { set_mask_size(compute_mask_size()); } duke@435: int mask_size() const { assert( _msize_valid, "mask size not valid" ); duke@435: return _mask_size; } duke@435: // Get the last mask size computed, even if it does not match the duke@435: // count of bits in the current mask. duke@435: int get_invalid_mask_size() const { return _mask_size; } duke@435: const RegMask &mask() const { return _mask; } duke@435: void set_mask( const RegMask &rm ) { _mask = rm; debug_only(_msize_valid=0;)} duke@435: void AND( const RegMask &rm ) { _mask.AND(rm); debug_only(_msize_valid=0;)} duke@435: void SUBTRACT( const RegMask &rm ) { _mask.SUBTRACT(rm); debug_only(_msize_valid=0;)} duke@435: void Clear() { _mask.Clear() ; debug_only(_msize_valid=1); _mask_size = 0; } duke@435: void Set_All() { _mask.Set_All(); debug_only(_msize_valid=1); _mask_size = RegMask::CHUNK_SIZE; } duke@435: void Insert( OptoReg::Name reg ) { _mask.Insert(reg); debug_only(_msize_valid=0;) } duke@435: void Remove( OptoReg::Name reg ) { _mask.Remove(reg); debug_only(_msize_valid=0;) } kvn@3882: void clear_to_pairs() { _mask.clear_to_pairs(); debug_only(_msize_valid=0;) } kvn@3882: void clear_to_sets() { _mask.clear_to_sets(_num_regs); debug_only(_msize_valid=0;) } duke@435: duke@435: // Number of registers this live range uses when it colors duke@435: private: duke@435: uint8 _num_regs; // 2 for Longs and Doubles, 1 for all else duke@435: // except _num_regs is kill count for fat_proj duke@435: public: duke@435: int num_regs() const { return _num_regs; } duke@435: void set_num_regs( int reg ) { assert( _num_regs == reg || !_num_regs, "" ); _num_regs = reg; } duke@435: duke@435: private: duke@435: // Number of physical registers this live range uses when it colors duke@435: // Architecture and register-set dependent duke@435: uint8 _reg_pressure; duke@435: public: duke@435: void set_reg_pressure(int i) { _reg_pressure = i; } duke@435: int reg_pressure() const { return _reg_pressure; } duke@435: duke@435: // How much 'wiggle room' does this live range have? duke@435: // How many color choices can it make (scaled by _num_regs)? duke@435: int degrees_of_freedom() const { return mask_size() - _num_regs; } duke@435: // Bound LRGs have ZERO degrees of freedom. We also count duke@435: // must_spill as bound. duke@435: bool is_bound () const { return _is_bound; } duke@435: // Negative degrees-of-freedom; even with no neighbors this duke@435: // live range must spill. duke@435: bool not_free() const { return degrees_of_freedom() < 0; } duke@435: // Is this live range of "low-degree"? Trivially colorable? duke@435: bool lo_degree () const { return degree() <= degrees_of_freedom(); } duke@435: // Is this live range just barely "low-degree"? Trivially colorable? duke@435: bool just_lo_degree () const { return degree() == degrees_of_freedom(); } duke@435: duke@435: uint _is_oop:1, // Live-range holds an oop duke@435: _is_float:1, // True if in float registers kvn@3882: _is_vector:1, // True if in vector registers duke@435: _was_spilled1:1, // True if prior spilling on def duke@435: _was_spilled2:1, // True if twice prior spilling on def duke@435: _is_bound:1, // live range starts life with no duke@435: // degrees of freedom. duke@435: _direct_conflict:1, // True if def and use registers in conflict duke@435: _must_spill:1, // live range has lost all degrees of freedom duke@435: // If _fat_proj is set, live range does NOT require aligned, adjacent duke@435: // registers and has NO interferences. duke@435: // If _fat_proj is clear, live range requires num_regs() to be a power of duke@435: // 2, and it requires registers to form an aligned, adjacent set. duke@435: _fat_proj:1, // duke@435: _was_lo:1, // Was lo-degree prior to coalesce duke@435: _msize_valid:1, // _mask_size cache valid duke@435: _degree_valid:1, // _degree cache valid duke@435: _has_copy:1, // Adjacent to some copy instruction duke@435: _at_risk:1; // Simplify says this guy is at risk to spill duke@435: duke@435: duke@435: // Alive if non-zero, dead if zero duke@435: bool alive() const { return _def != NULL; } never@730: bool is_multidef() const { return _def == NodeSentinel; } never@730: bool is_singledef() const { return _def != NodeSentinel; } duke@435: duke@435: #ifndef PRODUCT duke@435: void dump( ) const; duke@435: #endif duke@435: }; duke@435: duke@435: //------------------------------IFG-------------------------------------------- duke@435: // InterFerence Graph duke@435: // An undirected graph implementation. Created with a fixed number of duke@435: // vertices. Edges can be added & tested. Vertices can be removed, then duke@435: // added back later with all edges intact. Can add edges between one vertex duke@435: // and a list of other vertices. Can union vertices (and their edges) duke@435: // together. The IFG needs to be really really fast, and also fairly duke@435: // abstract! It needs abstraction so I can fiddle with the implementation to duke@435: // get even more speed. duke@435: class PhaseIFG : public Phase { never@3138: friend class VMStructs; duke@435: // Current implementation: a triangular adjacency list. duke@435: duke@435: // Array of adjacency-lists, indexed by live-range number duke@435: IndexSet *_adjs; duke@435: duke@435: // Assertion bit for proper use of Squaring duke@435: bool _is_square; duke@435: duke@435: // Live range structure goes here duke@435: LRG *_lrgs; // Array of LRG structures duke@435: duke@435: public: duke@435: // Largest live-range number duke@435: uint _maxlrg; duke@435: duke@435: Arena *_arena; duke@435: duke@435: // Keep track of inserted and deleted Nodes duke@435: VectorSet *_yanked; duke@435: duke@435: PhaseIFG( Arena *arena ); duke@435: void init( uint maxlrg ); duke@435: duke@435: // Add edge between a and b. Returns true if actually addded. duke@435: int add_edge( uint a, uint b ); duke@435: duke@435: // Add edge between a and everything in the vector duke@435: void add_vector( uint a, IndexSet *vec ); duke@435: duke@435: // Test for edge existance duke@435: int test_edge( uint a, uint b ) const; duke@435: duke@435: // Square-up matrix for faster Union duke@435: void SquareUp(); duke@435: duke@435: // Return number of LRG neighbors duke@435: uint neighbor_cnt( uint a ) const { return _adjs[a].count(); } duke@435: // Union edges of b into a on Squared-up matrix duke@435: void Union( uint a, uint b ); duke@435: // Test for edge in Squared-up matrix duke@435: int test_edge_sq( uint a, uint b ) const; duke@435: // Yank a Node and all connected edges from the IFG. Be prepared to duke@435: // re-insert the yanked Node in reverse order of yanking. Return a duke@435: // list of neighbors (edges) yanked. duke@435: IndexSet *remove_node( uint a ); duke@435: // Reinsert a yanked Node duke@435: void re_insert( uint a ); duke@435: // Return set of neighbors duke@435: IndexSet *neighbors( uint a ) const { return &_adjs[a]; } duke@435: duke@435: #ifndef PRODUCT duke@435: // Dump the IFG duke@435: void dump() const; duke@435: void stats() const; duke@435: void verify( const PhaseChaitin * ) const; duke@435: #endif duke@435: duke@435: //--------------- Live Range Accessors duke@435: LRG &lrgs(uint idx) const { assert(idx < _maxlrg, "oob"); return _lrgs[idx]; } duke@435: duke@435: // Compute and set effective degree. Might be folded into SquareUp(). duke@435: void Compute_Effective_Degree(); duke@435: duke@435: // Compute effective degree as the sum of neighbors' _sizes. duke@435: int effective_degree( uint lidx ) const; duke@435: }; duke@435: neliasso@4949: // The LiveRangeMap class is responsible for storing node to live range id mapping. neliasso@4949: // Each node is mapped to a live range id (a virtual register). Nodes that are neliasso@4949: // not considered for register allocation are given live range id 0. neliasso@4949: class LiveRangeMap VALUE_OBJ_CLASS_SPEC { duke@435: neliasso@4949: private: neliasso@4949: neliasso@4949: uint _max_lrg_id; neliasso@4949: neliasso@4949: // Union-find map. Declared as a short for speed. neliasso@4949: // Indexed by live-range number, it returns the compacted live-range number neliasso@4949: LRG_List _uf_map; neliasso@4949: neliasso@4949: // Map from Nodes to live ranges neliasso@4949: LRG_List _names; neliasso@4949: neliasso@4949: // Straight out of Tarjan's union-find algorithm neliasso@4949: uint find_compress(const Node *node) { adlertz@5722: uint lrg_id = find_compress(_names.at(node->_idx)); adlertz@5722: _names.at_put(node->_idx, lrg_id); neliasso@4949: return lrg_id; neliasso@4949: } neliasso@4949: neliasso@4949: uint find_compress(uint lrg); neliasso@4949: neliasso@4949: public: neliasso@4949: neliasso@4949: const LRG_List& names() { neliasso@4949: return _names; neliasso@4949: } neliasso@4949: neliasso@4949: uint max_lrg_id() const { neliasso@4949: return _max_lrg_id; neliasso@4949: } neliasso@4949: neliasso@4949: void set_max_lrg_id(uint max_lrg_id) { neliasso@4949: _max_lrg_id = max_lrg_id; neliasso@4949: } neliasso@4949: neliasso@4949: uint size() const { adlertz@5722: return _names.length(); neliasso@4949: } neliasso@4949: neliasso@4949: uint live_range_id(uint idx) const { adlertz@5722: return _names.at(idx); neliasso@4949: } neliasso@4949: neliasso@4949: uint live_range_id(const Node *node) const { adlertz@5722: return _names.at(node->_idx); neliasso@4949: } neliasso@4949: neliasso@4949: uint uf_live_range_id(uint lrg_id) const { adlertz@5722: return _uf_map.at(lrg_id); neliasso@4949: } neliasso@4949: neliasso@4949: void map(uint idx, uint lrg_id) { adlertz@5722: _names.at_put(idx, lrg_id); neliasso@4949: } neliasso@4949: neliasso@4949: void uf_map(uint dst_lrg_id, uint src_lrg_id) { adlertz@5722: _uf_map.at_put(dst_lrg_id, src_lrg_id); neliasso@4949: } neliasso@4949: neliasso@4949: void extend(uint idx, uint lrg_id) { adlertz@5722: _names.at_put_grow(idx, lrg_id); neliasso@4949: } neliasso@4949: neliasso@4949: void uf_extend(uint dst_lrg_id, uint src_lrg_id) { adlertz@5722: _uf_map.at_put_grow(dst_lrg_id, src_lrg_id); neliasso@4949: } neliasso@4949: adlertz@5722: LiveRangeMap(Arena* arena, uint unique) adlertz@5722: : _names(arena, unique, unique, 0) adlertz@5722: , _uf_map(arena, unique, unique, 0) neliasso@4949: , _max_lrg_id(0) {} neliasso@4949: neliasso@4949: uint find_id( const Node *n ) { neliasso@4949: uint retval = live_range_id(n); neliasso@4949: assert(retval == find(n),"Invalid node to lidx mapping"); neliasso@4949: return retval; neliasso@4949: } neliasso@4949: neliasso@4949: // Reset the Union-Find map to identity neliasso@4949: void reset_uf_map(uint max_lrg_id); neliasso@4949: neliasso@4949: // Make all Nodes map directly to their final live range; no need for neliasso@4949: // the Union-Find mapping after this call. neliasso@4949: void compress_uf_map_for_nodes(); neliasso@4949: neliasso@4949: uint find(uint lidx) { adlertz@5722: uint uf_lidx = _uf_map.at(lidx); neliasso@4949: return (uf_lidx == lidx) ? uf_lidx : find_compress(lidx); neliasso@4949: } neliasso@4949: neliasso@4949: // Convert a Node into a Live Range Index - a lidx neliasso@4949: uint find(const Node *node) { neliasso@4949: uint lidx = live_range_id(node); adlertz@5722: uint uf_lidx = _uf_map.at(lidx); neliasso@4949: return (uf_lidx == lidx) ? uf_lidx : find_compress(node); neliasso@4949: } neliasso@4949: neliasso@4949: // Like Find above, but no path compress, so bad asymptotic behavior neliasso@4949: uint find_const(uint lrg) const; neliasso@4949: neliasso@4949: // Like Find above, but no path compress, so bad asymptotic behavior neliasso@4949: uint find_const(const Node *node) const { adlertz@5722: if(node->_idx >= (uint)_names.length()) { neliasso@4949: return 0; // not mapped, usual for debug dump neliasso@4949: } adlertz@5722: return find_const(_names.at(node->_idx)); neliasso@4949: } neliasso@4949: }; duke@435: duke@435: //------------------------------Chaitin---------------------------------------- duke@435: // Briggs-Chaitin style allocation, mostly. duke@435: class PhaseChaitin : public PhaseRegAlloc { never@3138: friend class VMStructs; duke@435: duke@435: int _trip_cnt; duke@435: int _alternate; duke@435: duke@435: LRG &lrgs(uint idx) const { return _ifg->lrgs(idx); } duke@435: PhaseLive *_live; // Liveness, used in the interference graph duke@435: PhaseIFG *_ifg; // Interference graph (for original chunk) duke@435: Node_List **_lrg_nodes; // Array of node; lists for lrgs which spill duke@435: VectorSet _spilled_once; // Nodes that have been spilled duke@435: VectorSet _spilled_twice; // Nodes that have been spilled twice duke@435: duke@435: // Combine the Live Range Indices for these 2 Nodes into a single live duke@435: // range. Future requests for any Node in either live range will duke@435: // return the live range index for the combined live range. duke@435: void Union( const Node *src, const Node *dst ); duke@435: duke@435: void new_lrg( const Node *x, uint lrg ); duke@435: duke@435: // Compact live ranges, removing unused ones. Return new maxlrg. duke@435: void compact(); duke@435: duke@435: uint _lo_degree; // Head of lo-degree LRGs list duke@435: uint _lo_stk_degree; // Head of lo-stk-degree LRGs list duke@435: uint _hi_degree; // Head of hi-degree LRGs list duke@435: uint _simplified; // Linked list head of simplified LRGs duke@435: duke@435: // Helper functions for Split() duke@435: uint split_DEF( Node *def, Block *b, int loc, uint max, Node **Reachblock, Node **debug_defs, GrowableArray splits, int slidx ); duke@435: uint split_USE( Node *def, Block *b, Node *use, uint useidx, uint max, bool def_down, bool cisc_sp, GrowableArray splits, int slidx ); neliasso@4949: neliasso@4949: //------------------------------clone_projs------------------------------------ neliasso@4949: // After cloning some rematerialized instruction, clone any MachProj's that neliasso@4949: // follow it. Example: Intel zero is XOR, kills flags. Sparc FP constants neliasso@4949: // use G3 as an address temp. kvn@5543: int clone_projs(Block* b, uint idx, Node* orig, Node* copy, uint& max_lrg_id); neliasso@4949: kvn@5543: int clone_projs(Block* b, uint idx, Node* orig, Node* copy, LiveRangeMap& lrg_map) { kvn@5543: uint max_lrg_id = lrg_map.max_lrg_id(); kvn@5543: int found_projs = clone_projs(b, idx, orig, copy, max_lrg_id); kvn@5543: if (found_projs > 0) { kvn@5543: // max_lrg_id is updated during call above kvn@5543: lrg_map.set_max_lrg_id(max_lrg_id); neliasso@4949: } neliasso@4949: return found_projs; neliasso@4949: } neliasso@4949: never@730: Node *split_Rematerialize(Node *def, Block *b, uint insidx, uint &maxlrg, GrowableArray splits, never@730: int slidx, uint *lrg2reach, Node **Reachblock, bool walkThru); duke@435: // True if lidx is used before any real register is def'd in the block duke@435: bool prompt_use( Block *b, uint lidx ); duke@435: Node *get_spillcopy_wide( Node *def, Node *use, uint uidx ); twisti@1040: // Insert the spill at chosen location. Skip over any intervening Proj's or duke@435: // Phis. Skip over a CatchNode and projs, inserting in the fall-through block duke@435: // instead. Update high-pressure indices. Create a new live range. duke@435: void insert_proj( Block *b, uint i, Node *spill, uint maxlrg ); duke@435: duke@435: bool is_high_pressure( Block *b, LRG *lrg, uint insidx ); duke@435: duke@435: uint _oldphi; // Node index which separates pre-allocation nodes duke@435: duke@435: Block **_blks; // Array of blocks sorted by frequency for coalescing duke@435: kvn@1108: float _high_frequency_lrg; // Frequency at which LRG will be spilled for debug info kvn@1108: duke@435: #ifndef PRODUCT duke@435: bool _trace_spilling; duke@435: #endif duke@435: duke@435: public: duke@435: PhaseChaitin( uint unique, PhaseCFG &cfg, Matcher &matcher ); duke@435: ~PhaseChaitin() {} duke@435: neliasso@4949: LiveRangeMap _lrg_map; duke@435: duke@435: // Do all the real work of allocate duke@435: void Register_Allocate(); duke@435: kvn@1108: float high_frequency_lrg() const { return _high_frequency_lrg; } kvn@1108: duke@435: #ifndef PRODUCT duke@435: bool trace_spilling() const { return _trace_spilling; } duke@435: #endif duke@435: duke@435: private: duke@435: // De-SSA the world. Assign registers to Nodes. Use the same register for duke@435: // all inputs to a PhiNode, effectively coalescing live ranges. Insert duke@435: // copies as needed. duke@435: void de_ssa(); duke@435: duke@435: // Add edge between reg and everything in the vector. duke@435: // Same as _ifg->add_vector(reg,live) EXCEPT use the RegMask duke@435: // information to trim the set of interferences. Return the duke@435: // count of edges added. duke@435: void interfere_with_live( uint reg, IndexSet *live ); duke@435: // Count register pressure for asserts duke@435: uint count_int_pressure( IndexSet *liveout ); duke@435: uint count_float_pressure( IndexSet *liveout ); duke@435: duke@435: // Build the interference graph using virtual registers only. duke@435: // Used for aggressive coalescing. duke@435: void build_ifg_virtual( ); duke@435: duke@435: // Build the interference graph using physical registers when available. duke@435: // That is, if 2 live ranges are simultaneously alive but in their duke@435: // acceptable register sets do not overlap, then they do not interfere. duke@435: uint build_ifg_physical( ResourceArea *a ); duke@435: duke@435: // Gather LiveRanGe information, including register masks and base pointer/ duke@435: // derived pointer relationships. duke@435: void gather_lrg_masks( bool mod_cisc_masks ); duke@435: duke@435: // Force the bases of derived pointers to be alive at GC points. duke@435: bool stretch_base_pointer_live_ranges( ResourceArea *a ); duke@435: // Helper to stretch above; recursively discover the base Node for duke@435: // a given derived Node. Easy for AddP-related machine nodes, but duke@435: // needs to be recursive for derived Phis. duke@435: Node *find_base_for_derived( Node **derived_base_map, Node *derived, uint &maxlrg ); duke@435: duke@435: // Set the was-lo-degree bit. Conservative coalescing should not change the duke@435: // colorability of the graph. If any live range was of low-degree before duke@435: // coalescing, it should Simplify. This call sets the was-lo-degree bit. duke@435: void set_was_low(); duke@435: duke@435: // Split live-ranges that must spill due to register conflicts (as opposed duke@435: // to capacity spills). Typically these are things def'd in a register duke@435: // and used on the stack or vice-versa. duke@435: void pre_spill(); duke@435: duke@435: // Init LRG caching of degree, numregs. Init lo_degree list. duke@435: void cache_lrg_info( ); duke@435: duke@435: // Simplify the IFG by removing LRGs of low degree with no copies duke@435: void Pre_Simplify(); duke@435: duke@435: // Simplify the IFG by removing LRGs of low degree duke@435: void Simplify(); duke@435: duke@435: // Select colors by re-inserting edges into the IFG. twisti@1040: // Return TRUE if any spills occurred. duke@435: uint Select( ); duke@435: // Helper function for select which allows biased coloring duke@435: OptoReg::Name choose_color( LRG &lrg, int chunk ); duke@435: // Helper function which implements biasing heuristic duke@435: OptoReg::Name bias_color( LRG &lrg, int chunk ); duke@435: duke@435: // Split uncolorable live ranges duke@435: // Return new number of live ranges kvn@4019: uint Split(uint maxlrg, ResourceArea* split_arena); duke@435: duke@435: // Copy 'was_spilled'-edness from one Node to another. duke@435: void copy_was_spilled( Node *src, Node *dst ); duke@435: // Set the 'spilled_once' or 'spilled_twice' flag on a node. duke@435: void set_was_spilled( Node *n ); duke@435: duke@435: // Convert ideal spill-nodes into machine loads & stores duke@435: // Set C->failing when fixup spills could not complete, node limit exceeded. duke@435: void fixup_spills(); duke@435: duke@435: // Post-Allocation peephole copy removal duke@435: void post_allocate_copy_removal(); duke@435: Node *skip_copies( Node *c ); never@1358: // Replace the old node with the current live version of that value never@1358: // and yank the old value if it's dead. never@1358: int replace_and_yank_if_dead( Node *old, OptoReg::Name nreg, never@1358: Block *current_block, Node_List& value, Node_List& regnd ) { never@1358: Node* v = regnd[nreg]; never@1358: assert(v->outcnt() != 0, "no dead values"); never@1358: old->replace_by(v); never@1358: return yank_if_dead(old, current_block, &value, ®nd); never@1358: } never@1358: kvn@3405: int yank_if_dead( Node *old, Block *current_block, Node_List *value, Node_List *regnd ) { kvn@3405: return yank_if_dead_recurse(old, old, current_block, value, regnd); kvn@3405: } kvn@3405: int yank_if_dead_recurse(Node *old, Node *orig_old, Block *current_block, kvn@3405: Node_List *value, Node_List *regnd); roland@3133: int yank( Node *old, Block *current_block, Node_List *value, Node_List *regnd ); duke@435: int elide_copy( Node *n, int k, Block *current_block, Node_List &value, Node_List ®nd, bool can_change_regs ); duke@435: int use_prior_register( Node *copy, uint idx, Node *def, Block *current_block, Node_List &value, Node_List ®nd ); duke@435: bool may_be_copy_of_callee( Node *def ) const; duke@435: duke@435: // If nreg already contains the same constant as val then eliminate it never@505: bool eliminate_copy_of_constant(Node* val, Node* n, never@505: Block *current_block, Node_List& value, Node_List ®nd, duke@435: OptoReg::Name nreg, OptoReg::Name nreg2); duke@435: // Extend the node to LRG mapping duke@435: void add_reference( const Node *node, const Node *old_node); duke@435: duke@435: private: duke@435: duke@435: static int _final_loads, _final_stores, _final_copies, _final_memoves; duke@435: static double _final_load_cost, _final_store_cost, _final_copy_cost, _final_memove_cost; duke@435: static int _conserv_coalesce, _conserv_coalesce_pair; duke@435: static int _conserv_coalesce_trie, _conserv_coalesce_quad; duke@435: static int _post_alloc; duke@435: static int _lost_opp_pp_coalesce, _lost_opp_cflow_coalesce; duke@435: static int _used_cisc_instructions, _unused_cisc_instructions; duke@435: static int _allocator_attempts, _allocator_successes; duke@435: duke@435: #ifndef PRODUCT duke@435: static uint _high_pressure, _low_pressure; duke@435: duke@435: void dump() const; duke@435: void dump( const Node *n ) const; duke@435: void dump( const Block * b ) const; duke@435: void dump_degree_lists() const; duke@435: void dump_simplified() const; never@2358: void dump_lrg( uint lidx, bool defs_only) const; never@2358: void dump_lrg( uint lidx) const { never@2358: // dump defs and uses by default never@2358: dump_lrg(lidx, false); never@2358: } duke@435: void dump_bb( uint pre_order ) const; duke@435: duke@435: // Verify that base pointers and derived pointers are still sane duke@435: void verify_base_ptrs( ResourceArea *a ) const; duke@435: kvn@1001: void verify( ResourceArea *a, bool verify_ifg = false ) const; kvn@1001: duke@435: void dump_for_spill_split_recycle() const; duke@435: duke@435: public: duke@435: void dump_frame() const; duke@435: char *dump_register( const Node *n, char *buf ) const; duke@435: private: duke@435: static void print_chaitin_statistics(); duke@435: #endif duke@435: friend class PhaseCoalesce; duke@435: friend class PhaseAggressiveCoalesce; duke@435: friend class PhaseConservativeCoalesce; duke@435: }; stefank@2314: stefank@2314: #endif // SHARE_VM_OPTO_CHAITIN_HPP