Path: blob/master/src/hotspot/share/opto/chaitin.hpp
40930 views
/*1* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_OPTO_CHAITIN_HPP25#define SHARE_OPTO_CHAITIN_HPP2627#include "code/vmreg.hpp"28#include "memory/resourceArea.hpp"29#include "opto/connode.hpp"30#include "opto/live.hpp"31#include "opto/machnode.hpp"32#include "opto/matcher.hpp"33#include "opto/phase.hpp"34#include "opto/regalloc.hpp"35#include "opto/regmask.hpp"3637class Matcher;38class PhaseCFG;39class PhaseLive;40class PhaseRegAlloc;41class PhaseChaitin;4243#define OPTO_DEBUG_SPLIT_FREQ BLOCK_FREQUENCY(0.001)44#define OPTO_LRG_HIGH_FREQ BLOCK_FREQUENCY(0.25)4546//------------------------------LRG--------------------------------------------47// Live-RanGe structure.48class LRG : public ResourceObj {49friend class VMStructs;50public:51static const uint AllStack_size = 0xFFFFF; // This mask size is used to tell that the mask of this LRG supports stack positions52enum { SPILL_REG=29999 }; // Register number of a spilled LRG5354double _cost; // 2 for loads/1 for stores times block freq55double _area; // Sum of all simultaneously live values56double score() const; // Compute score from cost and area57double _maxfreq; // Maximum frequency of any def or use5859Node *_def; // Check for multi-def live ranges60#ifndef PRODUCT61GrowableArray<Node*>* _defs;62#endif6364uint _risk_bias; // Index of LRG which we want to avoid color65uint _copy_bias; // Index of LRG which we want to share color6667uint _next; // Index of next LRG in linked list68uint _prev; // Index of prev LRG in linked list69private:70uint _reg; // Chosen register; undefined if mask is plural71public:72// Return chosen register for this LRG. Error if the LRG is not bound to73// a single register.74OptoReg::Name reg() const { return OptoReg::Name(_reg); }75void set_reg( OptoReg::Name r ) { _reg = r; }7677private:78uint _eff_degree; // Effective degree: Sum of neighbors _num_regs79public:80int degree() const { assert( _degree_valid , "" ); return _eff_degree; }81// Degree starts not valid and any change to the IFG neighbor82// set makes it not valid.83void set_degree( uint degree ) {84_eff_degree = degree;85debug_only(_degree_valid = 1;)86assert(!_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");87}88// Made a change that hammered degree89void invalid_degree() { debug_only(_degree_valid=0;) }90// Incrementally modify degree. If it was correct, it should remain correct91void inc_degree( uint mod ) {92_eff_degree += mod;93assert(!_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");94}95// Compute the degree between 2 live ranges96int compute_degree( LRG &l ) const;97bool mask_is_nonempty_and_up() const {98return mask().is_UP() && mask_size();99}100bool is_float_or_vector() const {101return _is_float || _is_vector;102}103104private:105RegMask _mask; // Allowed registers for this LRG106uint _mask_size; // cache of _mask.Size();107public:108int compute_mask_size() const { return _mask.is_AllStack() ? AllStack_size : _mask.Size(); }109void set_mask_size( int size ) {110assert((size == (int)AllStack_size) || (size == (int)_mask.Size()), "");111_mask_size = size;112#ifdef ASSERT113_msize_valid=1;114if (_is_vector) {115assert(!_fat_proj, "sanity");116if (!(_is_scalable && OptoReg::is_stack(_reg))) {117assert(_mask.is_aligned_sets(_num_regs), "mask is not aligned, adjacent sets");118}119} else if (_num_regs == 2 && !_fat_proj) {120assert(_mask.is_aligned_pairs(), "mask is not aligned, adjacent pairs");121}122#endif123}124void compute_set_mask_size() { set_mask_size(compute_mask_size()); }125int mask_size() const { assert( _msize_valid, "mask size not valid" );126return _mask_size; }127// Get the last mask size computed, even if it does not match the128// count of bits in the current mask.129int get_invalid_mask_size() const { return _mask_size; }130const RegMask &mask() const { return _mask; }131void set_mask( const RegMask &rm ) { _mask = rm; debug_only(_msize_valid=0;)}132void AND( const RegMask &rm ) { _mask.AND(rm); debug_only(_msize_valid=0;)}133void SUBTRACT( const RegMask &rm ) { _mask.SUBTRACT(rm); debug_only(_msize_valid=0;)}134void Clear() { _mask.Clear() ; debug_only(_msize_valid=1); _mask_size = 0; }135void Set_All() { _mask.Set_All(); debug_only(_msize_valid=1); _mask_size = RegMask::CHUNK_SIZE; }136137void Insert( OptoReg::Name reg ) { _mask.Insert(reg); debug_only(_msize_valid=0;) }138void Remove( OptoReg::Name reg ) { _mask.Remove(reg); debug_only(_msize_valid=0;) }139void clear_to_sets() { _mask.clear_to_sets(_num_regs); debug_only(_msize_valid=0;) }140141private:142// Number of registers this live range uses when it colors143uint16_t _num_regs; // 2 for Longs and Doubles, 1 for all else144// except _num_regs is kill count for fat_proj145146// For scalable register, num_regs may not be the actual physical register size.147// We need to get the actual physical length of scalable register when scalable148// register is spilled. The size of one slot is 32-bit.149uint _scalable_reg_slots; // Actual scalable register length of slots.150// Meaningful only when _is_scalable is true.151public:152int num_regs() const { return _num_regs; }153void set_num_regs( int reg ) { assert( _num_regs == reg || !_num_regs, "" ); _num_regs = reg; }154155uint scalable_reg_slots() { return _scalable_reg_slots; }156void set_scalable_reg_slots(uint slots) {157assert(_is_scalable, "scalable register");158assert(slots > 0, "slots of scalable register is not valid");159_scalable_reg_slots = slots;160}161162bool is_scalable() {163#ifdef ASSERT164if (_is_scalable) {165// Should only be a vector for now, but it could also be a RegVectMask in future.166assert(_is_vector && (_num_regs == RegMask::SlotsPerVecA), "unexpected scalable reg");167}168#endif169return Matcher::implements_scalable_vector && _is_scalable;170}171172private:173// Number of physical registers this live range uses when it colors174// Architecture and register-set dependent175uint16_t _reg_pressure;176public:177void set_reg_pressure(int i) { _reg_pressure = i; }178int reg_pressure() const { return _reg_pressure; }179180// How much 'wiggle room' does this live range have?181// How many color choices can it make (scaled by _num_regs)?182int degrees_of_freedom() const { return mask_size() - _num_regs; }183// Bound LRGs have ZERO degrees of freedom. We also count184// must_spill as bound.185bool is_bound () const { return _is_bound; }186// Negative degrees-of-freedom; even with no neighbors this187// live range must spill.188bool not_free() const { return degrees_of_freedom() < 0; }189// Is this live range of "low-degree"? Trivially colorable?190bool lo_degree () const { return degree() <= degrees_of_freedom(); }191// Is this live range just barely "low-degree"? Trivially colorable?192bool just_lo_degree () const { return degree() == degrees_of_freedom(); }193194uint _is_oop:1, // Live-range holds an oop195_is_float:1, // True if in float registers196_is_vector:1, // True if in vector registers197_is_scalable:1, // True if register size is scalable198// e.g. Arm SVE vector/predicate registers.199_was_spilled1:1, // True if prior spilling on def200_was_spilled2:1, // True if twice prior spilling on def201_is_bound:1, // live range starts life with no202// degrees of freedom.203_direct_conflict:1, // True if def and use registers in conflict204_must_spill:1, // live range has lost all degrees of freedom205// If _fat_proj is set, live range does NOT require aligned, adjacent206// registers and has NO interferences.207// If _fat_proj is clear, live range requires num_regs() to be a power of208// 2, and it requires registers to form an aligned, adjacent set.209_fat_proj:1, //210_was_lo:1, // Was lo-degree prior to coalesce211_msize_valid:1, // _mask_size cache valid212_degree_valid:1, // _degree cache valid213_has_copy:1, // Adjacent to some copy instruction214_at_risk:1; // Simplify says this guy is at risk to spill215216217// Alive if non-zero, dead if zero218bool alive() const { return _def != NULL; }219bool is_multidef() const { return _def == NodeSentinel; }220bool is_singledef() const { return _def != NodeSentinel; }221222#ifndef PRODUCT223void dump( ) const;224#endif225};226227//------------------------------IFG--------------------------------------------228// InterFerence Graph229// An undirected graph implementation. Created with a fixed number of230// vertices. Edges can be added & tested. Vertices can be removed, then231// added back later with all edges intact. Can add edges between one vertex232// and a list of other vertices. Can union vertices (and their edges)233// together. The IFG needs to be really really fast, and also fairly234// abstract! It needs abstraction so I can fiddle with the implementation to235// get even more speed.236class PhaseIFG : public Phase {237friend class VMStructs;238// Current implementation: a triangular adjacency list.239240// Array of adjacency-lists, indexed by live-range number241IndexSet *_adjs;242243// Assertion bit for proper use of Squaring244bool _is_square;245246// Live range structure goes here247LRG *_lrgs; // Array of LRG structures248249public:250// Largest live-range number251uint _maxlrg;252253Arena *_arena;254255// Keep track of inserted and deleted Nodes256VectorSet *_yanked;257258PhaseIFG( Arena *arena );259void init( uint maxlrg );260261// Add edge between a and b. Returns true if actually addded.262int add_edge( uint a, uint b );263264// Test for edge existance265int test_edge( uint a, uint b ) const;266267// Square-up matrix for faster Union268void SquareUp();269270// Return number of LRG neighbors271uint neighbor_cnt( uint a ) const { return _adjs[a].count(); }272// Union edges of b into a on Squared-up matrix273void Union( uint a, uint b );274// Test for edge in Squared-up matrix275int test_edge_sq( uint a, uint b ) const;276// Yank a Node and all connected edges from the IFG. Be prepared to277// re-insert the yanked Node in reverse order of yanking. Return a278// list of neighbors (edges) yanked.279IndexSet *remove_node( uint a );280// Reinsert a yanked Node281void re_insert( uint a );282// Return set of neighbors283IndexSet *neighbors( uint a ) const { return &_adjs[a]; }284285#ifndef PRODUCT286// Dump the IFG287void dump() const;288void stats() const;289void verify( const PhaseChaitin * ) const;290#endif291292//--------------- Live Range Accessors293LRG &lrgs(uint idx) const { assert(idx < _maxlrg, "oob"); return _lrgs[idx]; }294295// Compute and set effective degree. Might be folded into SquareUp().296void Compute_Effective_Degree();297298// Compute effective degree as the sum of neighbors' _sizes.299int effective_degree( uint lidx ) const;300};301302// The LiveRangeMap class is responsible for storing node to live range id mapping.303// Each node is mapped to a live range id (a virtual register). Nodes that are304// not considered for register allocation are given live range id 0.305class LiveRangeMap {306307private:308309uint _max_lrg_id;310311// Union-find map. Declared as a short for speed.312// Indexed by live-range number, it returns the compacted live-range number313LRG_List _uf_map;314315// Map from Nodes to live ranges316LRG_List _names;317318// Straight out of Tarjan's union-find algorithm319uint find_compress(const Node *node) {320uint lrg_id = find_compress(_names.at(node->_idx));321_names.at_put(node->_idx, lrg_id);322return lrg_id;323}324325uint find_compress(uint lrg);326327public:328329const LRG_List& names() {330return _names;331}332333uint max_lrg_id() const {334return _max_lrg_id;335}336337void set_max_lrg_id(uint max_lrg_id) {338_max_lrg_id = max_lrg_id;339}340341uint size() const {342return _names.length();343}344345uint live_range_id(uint idx) const {346return _names.at(idx);347}348349uint live_range_id(const Node *node) const {350return _names.at(node->_idx);351}352353uint uf_live_range_id(uint lrg_id) const {354return _uf_map.at(lrg_id);355}356357void map(uint idx, uint lrg_id) {358_names.at_put(idx, lrg_id);359}360361void uf_map(uint dst_lrg_id, uint src_lrg_id) {362_uf_map.at_put(dst_lrg_id, src_lrg_id);363}364365void extend(uint idx, uint lrg_id) {366_names.at_put_grow(idx, lrg_id);367}368369void uf_extend(uint dst_lrg_id, uint src_lrg_id) {370_uf_map.at_put_grow(dst_lrg_id, src_lrg_id);371}372373LiveRangeMap(Arena* arena, uint unique)374: _max_lrg_id(0)375, _uf_map(arena, unique, unique, 0)376, _names(arena, unique, unique, 0) {}377378uint find_id( const Node *n ) {379uint retval = live_range_id(n);380assert(retval == find(n),"Invalid node to lidx mapping");381return retval;382}383384// Reset the Union-Find map to identity385void reset_uf_map(uint max_lrg_id);386387// Make all Nodes map directly to their final live range; no need for388// the Union-Find mapping after this call.389void compress_uf_map_for_nodes();390391uint find(uint lidx) {392uint uf_lidx = _uf_map.at(lidx);393return (uf_lidx == lidx) ? uf_lidx : find_compress(lidx);394}395396// Convert a Node into a Live Range Index - a lidx397uint find(const Node *node) {398uint lidx = live_range_id(node);399uint uf_lidx = _uf_map.at(lidx);400return (uf_lidx == lidx) ? uf_lidx : find_compress(node);401}402403// Like Find above, but no path compress, so bad asymptotic behavior404uint find_const(uint lrg) const;405406// Like Find above, but no path compress, so bad asymptotic behavior407uint find_const(const Node *node) const {408if(node->_idx >= (uint)_names.length()) {409return 0; // not mapped, usual for debug dump410}411return find_const(_names.at(node->_idx));412}413};414415//------------------------------Chaitin----------------------------------------416// Briggs-Chaitin style allocation, mostly.417class PhaseChaitin : public PhaseRegAlloc {418friend class VMStructs;419420int _trip_cnt;421int _alternate;422423PhaseLive *_live; // Liveness, used in the interference graph424PhaseIFG *_ifg; // Interference graph (for original chunk)425VectorSet _spilled_once; // Nodes that have been spilled426VectorSet _spilled_twice; // Nodes that have been spilled twice427428// Combine the Live Range Indices for these 2 Nodes into a single live429// range. Future requests for any Node in either live range will430// return the live range index for the combined live range.431void Union( const Node *src, const Node *dst );432433void new_lrg( const Node *x, uint lrg );434435// Compact live ranges, removing unused ones. Return new maxlrg.436void compact();437438uint _lo_degree; // Head of lo-degree LRGs list439uint _lo_stk_degree; // Head of lo-stk-degree LRGs list440uint _hi_degree; // Head of hi-degree LRGs list441uint _simplified; // Linked list head of simplified LRGs442443// Helper functions for Split()444uint split_DEF(Node *def, Block *b, int loc, uint max, Node **Reachblock, Node **debug_defs, GrowableArray<uint> splits, int slidx );445int split_USE(MachSpillCopyNode::SpillType spill_type, Node *def, Block *b, Node *use, uint useidx, uint max, bool def_down, bool cisc_sp, GrowableArray<uint> splits, int slidx );446447//------------------------------clone_projs------------------------------------448// After cloning some rematerialized instruction, clone any MachProj's that449// follow it. Example: Intel zero is XOR, kills flags. Sparc FP constants450// use G3 as an address temp.451int clone_projs(Block* b, uint idx, Node* orig, Node* copy, uint& max_lrg_id);452453int clone_projs(Block* b, uint idx, Node* orig, Node* copy, LiveRangeMap& lrg_map) {454uint max_lrg_id = lrg_map.max_lrg_id();455int found_projs = clone_projs(b, idx, orig, copy, max_lrg_id);456if (found_projs > 0) {457// max_lrg_id is updated during call above458lrg_map.set_max_lrg_id(max_lrg_id);459}460return found_projs;461}462463Node *split_Rematerialize(Node *def, Block *b, uint insidx, uint &maxlrg, GrowableArray<uint> splits,464int slidx, uint *lrg2reach, Node **Reachblock, bool walkThru);465// True if lidx is used before any real register is def'd in the block466bool prompt_use( Block *b, uint lidx );467Node *get_spillcopy_wide(MachSpillCopyNode::SpillType spill_type, Node *def, Node *use, uint uidx );468// Insert the spill at chosen location. Skip over any intervening Proj's or469// Phis. Skip over a CatchNode and projs, inserting in the fall-through block470// instead. Update high-pressure indices. Create a new live range.471void insert_proj( Block *b, uint i, Node *spill, uint maxlrg );472473bool is_high_pressure( Block *b, LRG *lrg, uint insidx );474475uint _oldphi; // Node index which separates pre-allocation nodes476477Block **_blks; // Array of blocks sorted by frequency for coalescing478479float _high_frequency_lrg; // Frequency at which LRG will be spilled for debug info480481#ifndef PRODUCT482bool _trace_spilling;483#endif484485public:486PhaseChaitin(uint unique, PhaseCFG &cfg, Matcher &matcher, bool track_liveout_pressure);487~PhaseChaitin() {}488489LiveRangeMap _lrg_map;490491LRG &lrgs(uint idx) const { return _ifg->lrgs(idx); }492493// Do all the real work of allocate494void Register_Allocate();495496float high_frequency_lrg() const { return _high_frequency_lrg; }497498// Used when scheduling info generated, not in general register allocation499bool _scheduling_info_generated;500501void set_ifg(PhaseIFG &ifg) { _ifg = &ifg; }502void set_live(PhaseLive &live) { _live = &live; }503PhaseLive* get_live() { return _live; }504505// Populate the live range maps with ssa info for scheduling506void mark_ssa();507508#ifndef PRODUCT509bool trace_spilling() const { return _trace_spilling; }510#endif511512private:513// De-SSA the world. Assign registers to Nodes. Use the same register for514// all inputs to a PhiNode, effectively coalescing live ranges. Insert515// copies as needed.516void de_ssa();517518// Add edge between reg and everything in the vector.519// Use the RegMask information to trim the set of interferences. Return the520// count of edges added.521void interfere_with_live(uint lid, IndexSet* liveout);522#ifdef ASSERT523// Count register pressure for asserts524uint count_int_pressure(IndexSet* liveout);525uint count_float_pressure(IndexSet* liveout);526#endif527528// Build the interference graph using virtual registers only.529// Used for aggressive coalescing.530void build_ifg_virtual( );531532// used when computing the register pressure for each block in the CFG. This533// is done during IFG creation.534class Pressure {535// keeps track of the register pressure at the current536// instruction (used when stepping backwards in the block)537uint _current_pressure;538539// keeps track of the instruction index of the first low to high register pressure540// transition (starting from the top) in the block541// if high_pressure_index == 0 then the whole block is high pressure542// if high_pressure_index = b.end_idx() + 1 then the whole block is low pressure543uint _high_pressure_index;544545// stores the highest pressure we find546uint _final_pressure;547548// number of live ranges that constitute high register pressure549uint _high_pressure_limit;550551// initial pressure observed552uint _start_pressure;553554public:555556// lower the register pressure and look for a low to high pressure557// transition558void lower(LRG& lrg, uint& location) {559_current_pressure -= lrg.reg_pressure();560if (_current_pressure == _high_pressure_limit) {561_high_pressure_index = location;562}563}564565// raise the pressure and store the pressure if it's the biggest566// pressure so far567void raise(LRG &lrg) {568_current_pressure += lrg.reg_pressure();569if (_current_pressure > _final_pressure) {570_final_pressure = _current_pressure;571}572}573574void init(int limit) {575_current_pressure = 0;576_high_pressure_index = 0;577_final_pressure = 0;578_high_pressure_limit = limit;579_start_pressure = 0;580}581582uint high_pressure_index() const {583return _high_pressure_index;584}585586uint final_pressure() const {587return _final_pressure;588}589590uint start_pressure() const {591return _start_pressure;592}593594uint current_pressure() const {595return _current_pressure;596}597598uint high_pressure_limit() const {599return _high_pressure_limit;600}601602void lower_high_pressure_index() {603_high_pressure_index--;604}605606void set_high_pressure_index_to_block_start() {607_high_pressure_index = 0;608}609610void set_start_pressure(int value) {611_start_pressure = value;612_final_pressure = value;613}614615void set_current_pressure(int value) {616_current_pressure = value;617}618619void check_pressure_at_fatproj(uint fatproj_location, RegMask& fatproj_mask) {620// this pressure is only valid at this instruction, i.e. we don't need to lower621// the register pressure since the fat proj was never live before (going backwards)622uint new_pressure = current_pressure() + fatproj_mask.Size();623if (new_pressure > final_pressure()) {624_final_pressure = new_pressure;625}626627// if we were at a low pressure and now and the fat proj is at high pressure, record the fat proj location628// as coming from a low to high (to low again)629if (current_pressure() <= high_pressure_limit() && new_pressure > high_pressure_limit()) {630_high_pressure_index = fatproj_location;631}632}633634Pressure(uint high_pressure_index, uint high_pressure_limit)635: _current_pressure(0)636, _high_pressure_index(high_pressure_index)637, _final_pressure(0)638, _high_pressure_limit(high_pressure_limit)639, _start_pressure(0) {}640};641642void check_for_high_pressure_transition_at_fatproj(uint& block_reg_pressure, uint location, LRG& lrg, Pressure& pressure, const int op_regtype);643void add_input_to_liveout(Block* b, Node* n, IndexSet* liveout, double cost, Pressure& int_pressure, Pressure& float_pressure);644void compute_initial_block_pressure(Block* b, IndexSet* liveout, Pressure& int_pressure, Pressure& float_pressure, double cost);645bool remove_node_if_not_used(Block* b, uint location, Node* n, uint lid, IndexSet* liveout);646void assign_high_score_to_immediate_copies(Block* b, Node* n, LRG& lrg, uint next_inst, uint last_inst);647void remove_interference_from_copy(Block* b, uint location, uint lid_copy, IndexSet* liveout, double cost, Pressure& int_pressure, Pressure& float_pressure);648void remove_bound_register_from_interfering_live_ranges(LRG& lrg, IndexSet* liveout, uint& must_spill);649void check_for_high_pressure_block(Pressure& pressure);650void adjust_high_pressure_index(Block* b, uint& hrp_index, Pressure& pressure);651652// Build the interference graph using physical registers when available.653// That is, if 2 live ranges are simultaneously alive but in their654// acceptable register sets do not overlap, then they do not interfere.655uint build_ifg_physical( ResourceArea *a );656657public:658// Gather LiveRanGe information, including register masks and base pointer/659// derived pointer relationships.660void gather_lrg_masks( bool mod_cisc_masks );661662// user visible pressure variables for scheduling663Pressure _sched_int_pressure;664Pressure _sched_float_pressure;665Pressure _scratch_int_pressure;666Pressure _scratch_float_pressure;667668// Pressure functions for user context669void lower_pressure(Block* b, uint location, LRG& lrg, IndexSet* liveout, Pressure& int_pressure, Pressure& float_pressure);670void raise_pressure(Block* b, LRG& lrg, Pressure& int_pressure, Pressure& float_pressure);671void compute_entry_block_pressure(Block* b);672void compute_exit_block_pressure(Block* b);673void print_pressure_info(Pressure& pressure, const char *str);674675private:676// Force the bases of derived pointers to be alive at GC points.677bool stretch_base_pointer_live_ranges( ResourceArea *a );678// Helper to stretch above; recursively discover the base Node for679// a given derived Node. Easy for AddP-related machine nodes, but680// needs to be recursive for derived Phis.681Node *find_base_for_derived( Node **derived_base_map, Node *derived, uint &maxlrg );682683// Set the was-lo-degree bit. Conservative coalescing should not change the684// colorability of the graph. If any live range was of low-degree before685// coalescing, it should Simplify. This call sets the was-lo-degree bit.686void set_was_low();687688// Init LRG caching of degree, numregs. Init lo_degree list.689void cache_lrg_info( );690691// Simplify the IFG by removing LRGs of low degree692void Simplify();693694// Select colors by re-inserting edges into the IFG.695// Return TRUE if any spills occurred.696uint Select( );697// Helper function for select which allows biased coloring698OptoReg::Name choose_color( LRG &lrg, int chunk );699// Helper function which implements biasing heuristic700OptoReg::Name bias_color( LRG &lrg, int chunk );701702// Split uncolorable live ranges703// Return new number of live ranges704uint Split(uint maxlrg, ResourceArea* split_arena);705706// Set the 'spilled_once' or 'spilled_twice' flag on a node.707void set_was_spilled( Node *n );708709// Convert ideal spill-nodes into machine loads & stores710// Set C->failing when fixup spills could not complete, node limit exceeded.711void fixup_spills();712713// Post-Allocation peephole copy removal714void post_allocate_copy_removal();715Node *skip_copies( Node *c );716// Replace the old node with the current live version of that value717// and yank the old value if it's dead.718int replace_and_yank_if_dead( Node *old, OptoReg::Name nreg,719Block *current_block, Node_List& value, Node_List& regnd ) {720Node* v = regnd[nreg];721assert(v->outcnt() != 0, "no dead values");722old->replace_by(v);723return yank_if_dead(old, current_block, &value, ®nd);724}725726int yank_if_dead( Node *old, Block *current_block, Node_List *value, Node_List *regnd ) {727return yank_if_dead_recurse(old, old, current_block, value, regnd);728}729int yank_if_dead_recurse(Node *old, Node *orig_old, Block *current_block,730Node_List *value, Node_List *regnd);731int yank( Node *old, Block *current_block, Node_List *value, Node_List *regnd );732int elide_copy( Node *n, int k, Block *current_block, Node_List &value, Node_List ®nd, bool can_change_regs );733int use_prior_register( Node *copy, uint idx, Node *def, Block *current_block, Node_List &value, Node_List ®nd );734bool may_be_copy_of_callee( Node *def ) const;735736// If nreg already contains the same constant as val then eliminate it737bool eliminate_copy_of_constant(Node* val, Node* n,738Block *current_block, Node_List& value, Node_List ®nd,739OptoReg::Name nreg, OptoReg::Name nreg2);740// Extend the node to LRG mapping741void add_reference( const Node *node, const Node *old_node);742743// Record the first use of a def in the block for a register.744class RegDefUse {745Node* _def;746Node* _first_use;747public:748RegDefUse() : _def(NULL), _first_use(NULL) { }749Node* def() const { return _def; }750Node* first_use() const { return _first_use; }751752void update(Node* def, Node* use) {753if (_def != def) {754_def = def;755_first_use = use;756}757}758void clear() {759_def = NULL;760_first_use = NULL;761}762};763typedef GrowableArray<RegDefUse> RegToDefUseMap;764int possibly_merge_multidef(Node *n, uint k, Block *block, RegToDefUseMap& reg2defuse);765766// Merge nodes that are a part of a multidef lrg and produce the same value within a block.767void merge_multidefs();768769private:770771static int _final_loads, _final_stores, _final_copies, _final_memoves;772static double _final_load_cost, _final_store_cost, _final_copy_cost, _final_memove_cost;773static int _conserv_coalesce, _conserv_coalesce_pair;774static int _conserv_coalesce_trie, _conserv_coalesce_quad;775static int _post_alloc;776static int _lost_opp_pp_coalesce, _lost_opp_cflow_coalesce;777static int _used_cisc_instructions, _unused_cisc_instructions;778static int _allocator_attempts, _allocator_successes;779780#ifdef ASSERT781// Verify that base pointers and derived pointers are still sane782void verify_base_ptrs(ResourceArea* a) const;783void verify(ResourceArea* a, bool verify_ifg = false) const;784#endif // ASSERT785786#ifndef PRODUCT787static uint _high_pressure, _low_pressure;788789void dump() const;790void dump(const Node* n) const;791void dump(const Block* b) const;792void dump_degree_lists() const;793void dump_simplified() const;794void dump_lrg(uint lidx, bool defs_only) const;795void dump_lrg(uint lidx) const {796// dump defs and uses by default797dump_lrg(lidx, false);798}799void dump_bb(uint pre_order) const;800void dump_for_spill_split_recycle() const;801802public:803void dump_frame() const;804char *dump_register(const Node* n, char* buf) const;805private:806static void print_chaitin_statistics();807#endif // not PRODUCT808friend class PhaseCoalesce;809friend class PhaseAggressiveCoalesce;810friend class PhaseConservativeCoalesce;811};812813#endif // SHARE_OPTO_CHAITIN_HPP814815816