aoqi@0: /* aoqi@0: * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #ifndef SHARE_VM_OPTO_REGALLOC_HPP aoqi@0: #define SHARE_VM_OPTO_REGALLOC_HPP aoqi@0: aoqi@0: #include "code/vmreg.hpp" aoqi@0: #include "opto/block.hpp" aoqi@0: #include "opto/matcher.hpp" aoqi@0: #include "opto/phase.hpp" aoqi@0: aoqi@0: class Node; aoqi@0: class Matcher; aoqi@0: class PhaseCFG; aoqi@0: aoqi@0: #define MAX_REG_ALLOCATORS 10 aoqi@0: aoqi@0: //------------------------------PhaseRegAlloc------------------------------------ aoqi@0: // Abstract register allocator aoqi@0: class PhaseRegAlloc : public Phase { aoqi@0: friend class VMStructs; aoqi@0: static void (*_alloc_statistics[MAX_REG_ALLOCATORS])(); aoqi@0: static int _num_allocators; aoqi@0: aoqi@0: protected: aoqi@0: OptoRegPair *_node_regs; aoqi@0: uint _node_regs_max_index; aoqi@0: VectorSet _node_oops; // Mapping from node indices to oopiness aoqi@0: aoqi@0: void alloc_node_regs(int size); // allocate _node_regs table with at least "size" elements aoqi@0: aoqi@0: PhaseRegAlloc( uint unique, PhaseCFG &cfg, Matcher &matcher, aoqi@0: void (*pr_stats)()); aoqi@0: public: aoqi@0: PhaseCFG &_cfg; // Control flow graph aoqi@0: uint _framesize; // Size of frame in stack-slots. not counting preserve area aoqi@0: OptoReg::Name _max_reg; // Past largest register seen aoqi@0: Matcher &_matcher; // Convert Ideal to MachNodes aoqi@0: uint node_regs_max_index() const { return _node_regs_max_index; } aoqi@0: aoqi@0: // Get the register associated with the Node aoqi@0: OptoReg::Name get_reg_first( const Node *n ) const { aoqi@0: debug_only( if( n->_idx >= _node_regs_max_index ) n->dump(); ); aoqi@0: assert( n->_idx < _node_regs_max_index, "Exceeded _node_regs array"); aoqi@0: return _node_regs[n->_idx].first(); aoqi@0: } aoqi@0: OptoReg::Name get_reg_second( const Node *n ) const { aoqi@0: debug_only( if( n->_idx >= _node_regs_max_index ) n->dump(); ); aoqi@0: assert( n->_idx < _node_regs_max_index, "Exceeded _node_regs array"); aoqi@0: return _node_regs[n->_idx].second(); aoqi@0: } aoqi@0: aoqi@0: // Do all the real work of allocate aoqi@0: virtual void Register_Allocate() = 0; aoqi@0: aoqi@0: aoqi@0: // notify the register allocator that "node" is a new reference aoqi@0: // to the value produced by "old_node" aoqi@0: virtual void add_reference( const Node *node, const Node *old_node) = 0; aoqi@0: aoqi@0: aoqi@0: // Set the register associated with a new Node aoqi@0: void set_bad( uint idx ) { aoqi@0: assert( idx < _node_regs_max_index, "Exceeded _node_regs array"); aoqi@0: _node_regs[idx].set_bad(); aoqi@0: } aoqi@0: void set1( uint idx, OptoReg::Name reg ) { aoqi@0: assert( idx < _node_regs_max_index, "Exceeded _node_regs array"); aoqi@0: _node_regs[idx].set1(reg); aoqi@0: } aoqi@0: void set2( uint idx, OptoReg::Name reg ) { aoqi@0: assert( idx < _node_regs_max_index, "Exceeded _node_regs array"); aoqi@0: _node_regs[idx].set2(reg); aoqi@0: } aoqi@0: void set_pair( uint idx, OptoReg::Name hi, OptoReg::Name lo ) { aoqi@0: assert( idx < _node_regs_max_index, "Exceeded _node_regs array"); aoqi@0: _node_regs[idx].set_pair(hi, lo); aoqi@0: } aoqi@0: void set_ptr( uint idx, OptoReg::Name reg ) { aoqi@0: assert( idx < _node_regs_max_index, "Exceeded _node_regs array"); aoqi@0: _node_regs[idx].set_ptr(reg); aoqi@0: } aoqi@0: // Set and query if a node produces an oop aoqi@0: void set_oop( const Node *n, bool ); aoqi@0: bool is_oop( const Node *n ) const; aoqi@0: aoqi@0: // Convert a register number to a stack offset aoqi@0: int reg2offset ( OptoReg::Name reg ) const; aoqi@0: int reg2offset_unchecked( OptoReg::Name reg ) const; aoqi@0: aoqi@0: // Convert a stack offset to a register number aoqi@0: OptoReg::Name offset2reg( int stk_offset ) const; aoqi@0: aoqi@0: // Get the register encoding associated with the Node aoqi@0: int get_encode(const Node *n) const { aoqi@0: assert( n->_idx < _node_regs_max_index, "Exceeded _node_regs array"); aoqi@0: OptoReg::Name first = _node_regs[n->_idx].first(); aoqi@0: OptoReg::Name second = _node_regs[n->_idx].second(); aoqi@0: assert( !OptoReg::is_valid(second) || second == first+1, "" ); aoqi@0: assert(OptoReg::is_reg(first), "out of range"); aoqi@0: return Matcher::_regEncode[first]; aoqi@0: } aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: static int _total_framesize; aoqi@0: static int _max_framesize; aoqi@0: aoqi@0: virtual void dump_frame() const = 0; aoqi@0: virtual char *dump_register( const Node *n, char *buf ) const = 0; aoqi@0: static void print_statistics(); aoqi@0: #endif aoqi@0: }; aoqi@0: aoqi@0: #endif // SHARE_VM_OPTO_REGALLOC_HPP