1
|
1 |
/*
|
|
2 |
* Copyright 2000-2006 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 |
* have any questions.
|
|
22 |
*
|
|
23 |
*/
|
|
24 |
|
|
25 |
class Node;
|
|
26 |
class Matcher;
|
|
27 |
class PhaseCFG;
|
|
28 |
|
|
29 |
#define MAX_REG_ALLOCATORS 10
|
|
30 |
|
|
31 |
//------------------------------PhaseRegAlloc------------------------------------
|
|
32 |
// Abstract register allocator
|
|
33 |
class PhaseRegAlloc : public Phase {
|
|
34 |
static void (*_alloc_statistics[MAX_REG_ALLOCATORS])();
|
|
35 |
static int _num_allocators;
|
|
36 |
|
|
37 |
protected:
|
|
38 |
OptoRegPair *_node_regs;
|
|
39 |
uint _node_regs_max_index;
|
|
40 |
VectorSet _node_oops; // Mapping from node indices to oopiness
|
|
41 |
|
|
42 |
void alloc_node_regs(int size); // allocate _node_regs table with at least "size" elements
|
|
43 |
|
|
44 |
PhaseRegAlloc( uint unique, PhaseCFG &cfg, Matcher &matcher,
|
|
45 |
void (*pr_stats)());
|
|
46 |
public:
|
|
47 |
PhaseCFG &_cfg; // Control flow graph
|
|
48 |
uint _framesize; // Size of frame in stack-slots. not counting preserve area
|
|
49 |
OptoReg::Name _max_reg; // Past largest register seen
|
|
50 |
Matcher &_matcher; // Convert Ideal to MachNodes
|
|
51 |
uint node_regs_max_index() const { return _node_regs_max_index; }
|
|
52 |
|
|
53 |
// Get the register associated with the Node
|
|
54 |
OptoReg::Name get_reg_first( const Node *n ) const {
|
|
55 |
debug_only( if( n->_idx >= _node_regs_max_index ) n->dump(); );
|
|
56 |
assert( n->_idx < _node_regs_max_index, "Exceeded _node_regs array");
|
|
57 |
return _node_regs[n->_idx].first();
|
|
58 |
}
|
|
59 |
OptoReg::Name get_reg_second( const Node *n ) const {
|
|
60 |
debug_only( if( n->_idx >= _node_regs_max_index ) n->dump(); );
|
|
61 |
assert( n->_idx < _node_regs_max_index, "Exceeded _node_regs array");
|
|
62 |
return _node_regs[n->_idx].second();
|
|
63 |
}
|
|
64 |
|
|
65 |
// Do all the real work of allocate
|
|
66 |
virtual void Register_Allocate() = 0;
|
|
67 |
|
|
68 |
|
|
69 |
// notify the register allocator that "node" is a new reference
|
|
70 |
// to the value produced by "old_node"
|
|
71 |
virtual void add_reference( const Node *node, const Node *old_node) = 0;
|
|
72 |
|
|
73 |
|
|
74 |
// Set the register associated with a new Node
|
|
75 |
void set_bad( uint idx ) {
|
|
76 |
assert( idx < _node_regs_max_index, "Exceeded _node_regs array");
|
|
77 |
_node_regs[idx].set_bad();
|
|
78 |
}
|
|
79 |
void set1( uint idx, OptoReg::Name reg ) {
|
|
80 |
assert( idx < _node_regs_max_index, "Exceeded _node_regs array");
|
|
81 |
_node_regs[idx].set1(reg);
|
|
82 |
}
|
|
83 |
void set2( uint idx, OptoReg::Name reg ) {
|
|
84 |
assert( idx < _node_regs_max_index, "Exceeded _node_regs array");
|
|
85 |
_node_regs[idx].set2(reg);
|
|
86 |
}
|
|
87 |
void set_pair( uint idx, OptoReg::Name hi, OptoReg::Name lo ) {
|
|
88 |
assert( idx < _node_regs_max_index, "Exceeded _node_regs array");
|
|
89 |
_node_regs[idx].set_pair(hi, lo);
|
|
90 |
}
|
|
91 |
void set_ptr( uint idx, OptoReg::Name reg ) {
|
|
92 |
assert( idx < _node_regs_max_index, "Exceeded _node_regs array");
|
|
93 |
_node_regs[idx].set_ptr(reg);
|
|
94 |
}
|
|
95 |
// Set and query if a node produces an oop
|
|
96 |
void set_oop( const Node *n, bool );
|
|
97 |
bool is_oop( const Node *n ) const;
|
|
98 |
|
|
99 |
// Convert a register number to a stack offset
|
|
100 |
int reg2offset ( OptoReg::Name reg ) const;
|
|
101 |
int reg2offset_unchecked( OptoReg::Name reg ) const;
|
|
102 |
|
|
103 |
// Convert a stack offset to a register number
|
|
104 |
OptoReg::Name offset2reg( int stk_offset ) const;
|
|
105 |
|
|
106 |
// Get the register encoding associated with the Node
|
|
107 |
int get_encode( const Node *n ) const {
|
|
108 |
assert( n->_idx < _node_regs_max_index, "Exceeded _node_regs array");
|
|
109 |
OptoReg::Name first = _node_regs[n->_idx].first();
|
|
110 |
OptoReg::Name second = _node_regs[n->_idx].second();
|
|
111 |
assert( !OptoReg::is_valid(second) || second == first+1, "" );
|
|
112 |
assert(OptoReg::is_reg(first), "out of range");
|
|
113 |
return Matcher::_regEncode[first];
|
|
114 |
}
|
|
115 |
|
|
116 |
// Platform dependent hook for actions prior to allocation
|
|
117 |
void pd_preallocate_hook();
|
|
118 |
|
|
119 |
#ifdef ASSERT
|
|
120 |
// Platform dependent hook for verification after allocation. Will
|
|
121 |
// only get called when compiling with asserts.
|
|
122 |
void pd_postallocate_verify_hook();
|
|
123 |
#endif
|
|
124 |
|
|
125 |
#ifndef PRODUCT
|
|
126 |
static int _total_framesize;
|
|
127 |
static int _max_framesize;
|
|
128 |
|
|
129 |
virtual void dump_frame() const = 0;
|
|
130 |
virtual char *dump_register( const Node *n, char *buf ) const = 0;
|
|
131 |
static void print_statistics();
|
|
132 |
#endif
|
|
133 |
};
|