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