1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/opto/regalloc.hpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,133 @@ 1.4 +/* 1.5 + * Copyright 2000-2006 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +class Node; 1.29 +class Matcher; 1.30 +class PhaseCFG; 1.31 + 1.32 +#define MAX_REG_ALLOCATORS 10 1.33 + 1.34 +//------------------------------PhaseRegAlloc------------------------------------ 1.35 +// Abstract register allocator 1.36 +class PhaseRegAlloc : public Phase { 1.37 + static void (*_alloc_statistics[MAX_REG_ALLOCATORS])(); 1.38 + static int _num_allocators; 1.39 + 1.40 +protected: 1.41 + OptoRegPair *_node_regs; 1.42 + uint _node_regs_max_index; 1.43 + VectorSet _node_oops; // Mapping from node indices to oopiness 1.44 + 1.45 + void alloc_node_regs(int size); // allocate _node_regs table with at least "size" elements 1.46 + 1.47 + PhaseRegAlloc( uint unique, PhaseCFG &cfg, Matcher &matcher, 1.48 + void (*pr_stats)()); 1.49 +public: 1.50 + PhaseCFG &_cfg; // Control flow graph 1.51 + uint _framesize; // Size of frame in stack-slots. not counting preserve area 1.52 + OptoReg::Name _max_reg; // Past largest register seen 1.53 + Matcher &_matcher; // Convert Ideal to MachNodes 1.54 + uint node_regs_max_index() const { return _node_regs_max_index; } 1.55 + 1.56 + // Get the register associated with the Node 1.57 + OptoReg::Name get_reg_first( const Node *n ) const { 1.58 + debug_only( if( n->_idx >= _node_regs_max_index ) n->dump(); ); 1.59 + assert( n->_idx < _node_regs_max_index, "Exceeded _node_regs array"); 1.60 + return _node_regs[n->_idx].first(); 1.61 + } 1.62 + OptoReg::Name get_reg_second( const Node *n ) const { 1.63 + debug_only( if( n->_idx >= _node_regs_max_index ) n->dump(); ); 1.64 + assert( n->_idx < _node_regs_max_index, "Exceeded _node_regs array"); 1.65 + return _node_regs[n->_idx].second(); 1.66 + } 1.67 + 1.68 + // Do all the real work of allocate 1.69 + virtual void Register_Allocate() = 0; 1.70 + 1.71 + 1.72 + // notify the register allocator that "node" is a new reference 1.73 + // to the value produced by "old_node" 1.74 + virtual void add_reference( const Node *node, const Node *old_node) = 0; 1.75 + 1.76 + 1.77 + // Set the register associated with a new Node 1.78 + void set_bad( uint idx ) { 1.79 + assert( idx < _node_regs_max_index, "Exceeded _node_regs array"); 1.80 + _node_regs[idx].set_bad(); 1.81 + } 1.82 + void set1( uint idx, OptoReg::Name reg ) { 1.83 + assert( idx < _node_regs_max_index, "Exceeded _node_regs array"); 1.84 + _node_regs[idx].set1(reg); 1.85 + } 1.86 + void set2( uint idx, OptoReg::Name reg ) { 1.87 + assert( idx < _node_regs_max_index, "Exceeded _node_regs array"); 1.88 + _node_regs[idx].set2(reg); 1.89 + } 1.90 + void set_pair( uint idx, OptoReg::Name hi, OptoReg::Name lo ) { 1.91 + assert( idx < _node_regs_max_index, "Exceeded _node_regs array"); 1.92 + _node_regs[idx].set_pair(hi, lo); 1.93 + } 1.94 + void set_ptr( uint idx, OptoReg::Name reg ) { 1.95 + assert( idx < _node_regs_max_index, "Exceeded _node_regs array"); 1.96 + _node_regs[idx].set_ptr(reg); 1.97 + } 1.98 + // Set and query if a node produces an oop 1.99 + void set_oop( const Node *n, bool ); 1.100 + bool is_oop( const Node *n ) const; 1.101 + 1.102 + // Convert a register number to a stack offset 1.103 + int reg2offset ( OptoReg::Name reg ) const; 1.104 + int reg2offset_unchecked( OptoReg::Name reg ) const; 1.105 + 1.106 + // Convert a stack offset to a register number 1.107 + OptoReg::Name offset2reg( int stk_offset ) const; 1.108 + 1.109 + // Get the register encoding associated with the Node 1.110 + int get_encode( const Node *n ) const { 1.111 + assert( n->_idx < _node_regs_max_index, "Exceeded _node_regs array"); 1.112 + OptoReg::Name first = _node_regs[n->_idx].first(); 1.113 + OptoReg::Name second = _node_regs[n->_idx].second(); 1.114 + assert( !OptoReg::is_valid(second) || second == first+1, "" ); 1.115 + assert(OptoReg::is_reg(first), "out of range"); 1.116 + return Matcher::_regEncode[first]; 1.117 + } 1.118 + 1.119 + // Platform dependent hook for actions prior to allocation 1.120 + void pd_preallocate_hook(); 1.121 + 1.122 +#ifdef ASSERT 1.123 + // Platform dependent hook for verification after allocation. Will 1.124 + // only get called when compiling with asserts. 1.125 + void pd_postallocate_verify_hook(); 1.126 +#endif 1.127 + 1.128 +#ifndef PRODUCT 1.129 + static int _total_framesize; 1.130 + static int _max_framesize; 1.131 + 1.132 + virtual void dump_frame() const = 0; 1.133 + virtual char *dump_register( const Node *n, char *buf ) const = 0; 1.134 + static void print_statistics(); 1.135 +#endif 1.136 +};