annotate src/share/vm/opto/regalloc.hpp @ 196:d1605aabd0a1 jdk7-b30

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