duke@435: /* duke@435: * Copyright 2000-2006 Sun Microsystems, Inc. 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: * duke@435: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@435: * CA 95054 USA or visit www.sun.com if you need additional information or duke@435: * have any questions. duke@435: * duke@435: */ duke@435: duke@435: class Node; duke@435: class Matcher; duke@435: class PhaseCFG; duke@435: duke@435: #define MAX_REG_ALLOCATORS 10 duke@435: duke@435: //------------------------------PhaseRegAlloc------------------------------------ duke@435: // Abstract register allocator duke@435: class PhaseRegAlloc : public Phase { duke@435: static void (*_alloc_statistics[MAX_REG_ALLOCATORS])(); duke@435: static int _num_allocators; duke@435: duke@435: protected: duke@435: OptoRegPair *_node_regs; duke@435: uint _node_regs_max_index; duke@435: VectorSet _node_oops; // Mapping from node indices to oopiness duke@435: duke@435: void alloc_node_regs(int size); // allocate _node_regs table with at least "size" elements duke@435: duke@435: PhaseRegAlloc( uint unique, PhaseCFG &cfg, Matcher &matcher, duke@435: void (*pr_stats)()); duke@435: public: duke@435: PhaseCFG &_cfg; // Control flow graph duke@435: uint _framesize; // Size of frame in stack-slots. not counting preserve area duke@435: OptoReg::Name _max_reg; // Past largest register seen duke@435: Matcher &_matcher; // Convert Ideal to MachNodes duke@435: uint node_regs_max_index() const { return _node_regs_max_index; } duke@435: duke@435: // Get the register associated with the Node duke@435: OptoReg::Name get_reg_first( const Node *n ) const { duke@435: debug_only( if( n->_idx >= _node_regs_max_index ) n->dump(); ); duke@435: assert( n->_idx < _node_regs_max_index, "Exceeded _node_regs array"); duke@435: return _node_regs[n->_idx].first(); duke@435: } duke@435: OptoReg::Name get_reg_second( const Node *n ) const { duke@435: debug_only( if( n->_idx >= _node_regs_max_index ) n->dump(); ); duke@435: assert( n->_idx < _node_regs_max_index, "Exceeded _node_regs array"); duke@435: return _node_regs[n->_idx].second(); duke@435: } duke@435: duke@435: // Do all the real work of allocate duke@435: virtual void Register_Allocate() = 0; duke@435: duke@435: duke@435: // notify the register allocator that "node" is a new reference duke@435: // to the value produced by "old_node" duke@435: virtual void add_reference( const Node *node, const Node *old_node) = 0; duke@435: duke@435: duke@435: // Set the register associated with a new Node duke@435: void set_bad( uint idx ) { duke@435: assert( idx < _node_regs_max_index, "Exceeded _node_regs array"); duke@435: _node_regs[idx].set_bad(); duke@435: } duke@435: void set1( uint idx, OptoReg::Name reg ) { duke@435: assert( idx < _node_regs_max_index, "Exceeded _node_regs array"); duke@435: _node_regs[idx].set1(reg); duke@435: } duke@435: void set2( uint idx, OptoReg::Name reg ) { duke@435: assert( idx < _node_regs_max_index, "Exceeded _node_regs array"); duke@435: _node_regs[idx].set2(reg); duke@435: } duke@435: void set_pair( uint idx, OptoReg::Name hi, OptoReg::Name lo ) { duke@435: assert( idx < _node_regs_max_index, "Exceeded _node_regs array"); duke@435: _node_regs[idx].set_pair(hi, lo); duke@435: } duke@435: void set_ptr( uint idx, OptoReg::Name reg ) { duke@435: assert( idx < _node_regs_max_index, "Exceeded _node_regs array"); duke@435: _node_regs[idx].set_ptr(reg); duke@435: } duke@435: // Set and query if a node produces an oop duke@435: void set_oop( const Node *n, bool ); duke@435: bool is_oop( const Node *n ) const; duke@435: duke@435: // Convert a register number to a stack offset duke@435: int reg2offset ( OptoReg::Name reg ) const; duke@435: int reg2offset_unchecked( OptoReg::Name reg ) const; duke@435: duke@435: // Convert a stack offset to a register number duke@435: OptoReg::Name offset2reg( int stk_offset ) const; duke@435: duke@435: // Get the register encoding associated with the Node duke@435: int get_encode( const Node *n ) const { duke@435: assert( n->_idx < _node_regs_max_index, "Exceeded _node_regs array"); duke@435: OptoReg::Name first = _node_regs[n->_idx].first(); duke@435: OptoReg::Name second = _node_regs[n->_idx].second(); duke@435: assert( !OptoReg::is_valid(second) || second == first+1, "" ); duke@435: assert(OptoReg::is_reg(first), "out of range"); duke@435: return Matcher::_regEncode[first]; duke@435: } duke@435: duke@435: // Platform dependent hook for actions prior to allocation duke@435: void pd_preallocate_hook(); duke@435: duke@435: #ifdef ASSERT duke@435: // Platform dependent hook for verification after allocation. Will duke@435: // only get called when compiling with asserts. duke@435: void pd_postallocate_verify_hook(); duke@435: #endif duke@435: duke@435: #ifndef PRODUCT duke@435: static int _total_framesize; duke@435: static int _max_framesize; duke@435: duke@435: virtual void dump_frame() const = 0; duke@435: virtual char *dump_register( const Node *n, char *buf ) const = 0; duke@435: static void print_statistics(); duke@435: #endif duke@435: };