annotate src/share/vm/adlc/formsopt.cpp @ 4121:db2e64ca2d5a

7090968: Allow adlc register class to depend on runtime conditions Summary: allow reg_class definition as a function. Reviewed-by: kvn, never
author roland
date Tue, 22 Nov 2011 09:45:57 +0100
parents f95d63e2154a
children 8c92982cbbc4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
2 * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
0
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 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 603
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 603
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 603
diff changeset
21 * questions.
0
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 // FORMS.CPP - Definitions for ADL Parser Forms Classes
a61af66fc99e Initial load
duke
parents:
diff changeset
26 #include "adlc.hpp"
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28 //==============================Register Allocation============================
a61af66fc99e Initial load
duke
parents:
diff changeset
29 int RegisterForm::_reg_ctr = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
30
a61af66fc99e Initial load
duke
parents:
diff changeset
31 //------------------------------RegisterForm-----------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
32 // Constructor
a61af66fc99e Initial load
duke
parents:
diff changeset
33 RegisterForm::RegisterForm()
a61af66fc99e Initial load
duke
parents:
diff changeset
34 : _regDef(cmpstr,hashstr, Form::arena),
a61af66fc99e Initial load
duke
parents:
diff changeset
35 _regClass(cmpstr,hashstr, Form::arena),
a61af66fc99e Initial load
duke
parents:
diff changeset
36 _allocClass(cmpstr,hashstr, Form::arena) {
a61af66fc99e Initial load
duke
parents:
diff changeset
37 }
a61af66fc99e Initial load
duke
parents:
diff changeset
38 RegisterForm::~RegisterForm() {
a61af66fc99e Initial load
duke
parents:
diff changeset
39 }
a61af66fc99e Initial load
duke
parents:
diff changeset
40
a61af66fc99e Initial load
duke
parents:
diff changeset
41 // record a new register definition
a61af66fc99e Initial load
duke
parents:
diff changeset
42 void RegisterForm::addRegDef(char *name, char *callingConv, char *c_conv,
a61af66fc99e Initial load
duke
parents:
diff changeset
43 char *idealtype, char *encoding, char* concrete) {
a61af66fc99e Initial load
duke
parents:
diff changeset
44 RegDef *regDef = new RegDef(name, callingConv, c_conv, idealtype, encoding, concrete);
a61af66fc99e Initial load
duke
parents:
diff changeset
45 _rdefs.addName(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
46 _regDef.Insert(name,regDef);
a61af66fc99e Initial load
duke
parents:
diff changeset
47 }
a61af66fc99e Initial load
duke
parents:
diff changeset
48
a61af66fc99e Initial load
duke
parents:
diff changeset
49 // record a new register class
a61af66fc99e Initial load
duke
parents:
diff changeset
50 RegClass *RegisterForm::addRegClass(const char *className) {
a61af66fc99e Initial load
duke
parents:
diff changeset
51 RegClass *regClass = new RegClass(className);
a61af66fc99e Initial load
duke
parents:
diff changeset
52 _rclasses.addName(className);
a61af66fc99e Initial load
duke
parents:
diff changeset
53 _regClass.Insert(className,regClass);
a61af66fc99e Initial load
duke
parents:
diff changeset
54 return regClass;
a61af66fc99e Initial load
duke
parents:
diff changeset
55 }
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57 // record a new register class
a61af66fc99e Initial load
duke
parents:
diff changeset
58 AllocClass *RegisterForm::addAllocClass(char *className) {
a61af66fc99e Initial load
duke
parents:
diff changeset
59 AllocClass *allocClass = new AllocClass(className);
a61af66fc99e Initial load
duke
parents:
diff changeset
60 _aclasses.addName(className);
a61af66fc99e Initial load
duke
parents:
diff changeset
61 _allocClass.Insert(className,allocClass);
a61af66fc99e Initial load
duke
parents:
diff changeset
62 return allocClass;
a61af66fc99e Initial load
duke
parents:
diff changeset
63 }
a61af66fc99e Initial load
duke
parents:
diff changeset
64
a61af66fc99e Initial load
duke
parents:
diff changeset
65 // Called after parsing the Register block. Record the register class
a61af66fc99e Initial load
duke
parents:
diff changeset
66 // for spill-slots/regs.
a61af66fc99e Initial load
duke
parents:
diff changeset
67 void RegisterForm::addSpillRegClass() {
a61af66fc99e Initial load
duke
parents:
diff changeset
68 // Stack slots start at the next available even register number.
a61af66fc99e Initial load
duke
parents:
diff changeset
69 _reg_ctr = (_reg_ctr+1) & ~1;
a61af66fc99e Initial load
duke
parents:
diff changeset
70 const char *rc_name = "stack_slots";
a61af66fc99e Initial load
duke
parents:
diff changeset
71 RegClass *reg_class = new RegClass(rc_name);
a61af66fc99e Initial load
duke
parents:
diff changeset
72 reg_class->_stack_or_reg = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
73 _rclasses.addName(rc_name);
a61af66fc99e Initial load
duke
parents:
diff changeset
74 _regClass.Insert(rc_name,reg_class);
a61af66fc99e Initial load
duke
parents:
diff changeset
75 }
a61af66fc99e Initial load
duke
parents:
diff changeset
76
a61af66fc99e Initial load
duke
parents:
diff changeset
77
a61af66fc99e Initial load
duke
parents:
diff changeset
78 // Provide iteration over all register definitions
a61af66fc99e Initial load
duke
parents:
diff changeset
79 // in the order used by the register allocator
a61af66fc99e Initial load
duke
parents:
diff changeset
80 void RegisterForm::reset_RegDefs() {
a61af66fc99e Initial load
duke
parents:
diff changeset
81 _current_ac = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
82 _aclasses.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
83 }
a61af66fc99e Initial load
duke
parents:
diff changeset
84
a61af66fc99e Initial load
duke
parents:
diff changeset
85 RegDef *RegisterForm::iter_RegDefs() {
a61af66fc99e Initial load
duke
parents:
diff changeset
86 // Check if we need to get the next AllocClass
a61af66fc99e Initial load
duke
parents:
diff changeset
87 if ( _current_ac == NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
88 const char *ac_name = _aclasses.iter();
a61af66fc99e Initial load
duke
parents:
diff changeset
89 if( ac_name == NULL ) return NULL; // No more allocation classes
a61af66fc99e Initial load
duke
parents:
diff changeset
90 _current_ac = (AllocClass*)_allocClass[ac_name];
a61af66fc99e Initial load
duke
parents:
diff changeset
91 _current_ac->_regDefs.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
92 assert( _current_ac != NULL, "Name must match an allocation class");
a61af66fc99e Initial load
duke
parents:
diff changeset
93 }
a61af66fc99e Initial load
duke
parents:
diff changeset
94
a61af66fc99e Initial load
duke
parents:
diff changeset
95 const char *rd_name = _current_ac->_regDefs.iter();
a61af66fc99e Initial load
duke
parents:
diff changeset
96 if( rd_name == NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
97 // At end of this allocation class, check the next
a61af66fc99e Initial load
duke
parents:
diff changeset
98 _current_ac = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
99 return iter_RegDefs();
a61af66fc99e Initial load
duke
parents:
diff changeset
100 }
a61af66fc99e Initial load
duke
parents:
diff changeset
101 RegDef *reg_def = (RegDef*)_current_ac->_regDef[rd_name];
a61af66fc99e Initial load
duke
parents:
diff changeset
102 assert( reg_def != NULL, "Name must match a register definition");
a61af66fc99e Initial load
duke
parents:
diff changeset
103 return reg_def;
a61af66fc99e Initial load
duke
parents:
diff changeset
104 }
a61af66fc99e Initial load
duke
parents:
diff changeset
105
a61af66fc99e Initial load
duke
parents:
diff changeset
106 // return the register definition with name 'regName'
a61af66fc99e Initial load
duke
parents:
diff changeset
107 RegDef *RegisterForm::getRegDef(const char *regName) {
a61af66fc99e Initial load
duke
parents:
diff changeset
108 RegDef *regDef = (RegDef*)_regDef[regName];
a61af66fc99e Initial load
duke
parents:
diff changeset
109 return regDef;
a61af66fc99e Initial load
duke
parents:
diff changeset
110 }
a61af66fc99e Initial load
duke
parents:
diff changeset
111
a61af66fc99e Initial load
duke
parents:
diff changeset
112 // return the register class with name 'className'
a61af66fc99e Initial load
duke
parents:
diff changeset
113 RegClass *RegisterForm::getRegClass(const char *className) {
a61af66fc99e Initial load
duke
parents:
diff changeset
114 RegClass *regClass = (RegClass*)_regClass[className];
a61af66fc99e Initial load
duke
parents:
diff changeset
115 return regClass;
a61af66fc99e Initial load
duke
parents:
diff changeset
116 }
a61af66fc99e Initial load
duke
parents:
diff changeset
117
a61af66fc99e Initial load
duke
parents:
diff changeset
118
a61af66fc99e Initial load
duke
parents:
diff changeset
119 // Check that register classes are compatible with chunks
a61af66fc99e Initial load
duke
parents:
diff changeset
120 bool RegisterForm::verify() {
a61af66fc99e Initial load
duke
parents:
diff changeset
121 bool valid = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
122
a61af66fc99e Initial load
duke
parents:
diff changeset
123 // Verify Register Classes
a61af66fc99e Initial load
duke
parents:
diff changeset
124 // check that each register class contains registers from one chunk
a61af66fc99e Initial load
duke
parents:
diff changeset
125 const char *rc_name = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
126 _rclasses.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
127 while ( (rc_name = _rclasses.iter()) != NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
128 // Check the chunk value for all registers in this class
a61af66fc99e Initial load
duke
parents:
diff changeset
129 RegClass *reg_class = getRegClass(rc_name);
a61af66fc99e Initial load
duke
parents:
diff changeset
130 assert( reg_class != NULL, "InternalError() no matching register class");
a61af66fc99e Initial load
duke
parents:
diff changeset
131 } // end of RegClasses
a61af66fc99e Initial load
duke
parents:
diff changeset
132
a61af66fc99e Initial load
duke
parents:
diff changeset
133 // Verify that every register has been placed into an allocation class
a61af66fc99e Initial load
duke
parents:
diff changeset
134 RegDef *reg_def = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
135 reset_RegDefs();
a61af66fc99e Initial load
duke
parents:
diff changeset
136 uint num_register_zero = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
137 while ( (reg_def = iter_RegDefs()) != NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
138 if( reg_def->register_num() == 0 ) ++num_register_zero;
a61af66fc99e Initial load
duke
parents:
diff changeset
139 }
a61af66fc99e Initial load
duke
parents:
diff changeset
140 if( num_register_zero > 1 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
141 fprintf(stderr,
a61af66fc99e Initial load
duke
parents:
diff changeset
142 "ERROR: More than one register has been assigned register-number 0.\n"
a61af66fc99e Initial load
duke
parents:
diff changeset
143 "Probably because a register has not been entered into an allocation class.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
144 }
a61af66fc99e Initial load
duke
parents:
diff changeset
145
a61af66fc99e Initial load
duke
parents:
diff changeset
146 return valid;
a61af66fc99e Initial load
duke
parents:
diff changeset
147 }
a61af66fc99e Initial load
duke
parents:
diff changeset
148
a61af66fc99e Initial load
duke
parents:
diff changeset
149 // Compute RegMask size
a61af66fc99e Initial load
duke
parents:
diff changeset
150 int RegisterForm::RegMask_Size() {
a61af66fc99e Initial load
duke
parents:
diff changeset
151 // Need at least this many words
a61af66fc99e Initial load
duke
parents:
diff changeset
152 int words_for_regs = (_reg_ctr + 31)>>5;
a61af66fc99e Initial load
duke
parents:
diff changeset
153 // Add a few for incoming & outgoing arguments to calls.
a61af66fc99e Initial load
duke
parents:
diff changeset
154 // Round up to the next doubleword size.
a61af66fc99e Initial load
duke
parents:
diff changeset
155 return (words_for_regs + 2 + 1) & ~1;
a61af66fc99e Initial load
duke
parents:
diff changeset
156 }
a61af66fc99e Initial load
duke
parents:
diff changeset
157
a61af66fc99e Initial load
duke
parents:
diff changeset
158 void RegisterForm::dump() { // Debug printer
a61af66fc99e Initial load
duke
parents:
diff changeset
159 output(stderr);
a61af66fc99e Initial load
duke
parents:
diff changeset
160 }
a61af66fc99e Initial load
duke
parents:
diff changeset
161
a61af66fc99e Initial load
duke
parents:
diff changeset
162 void RegisterForm::output(FILE *fp) { // Write info to output files
a61af66fc99e Initial load
duke
parents:
diff changeset
163 const char *name;
a61af66fc99e Initial load
duke
parents:
diff changeset
164 fprintf(fp,"\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
165 fprintf(fp,"-------------------- Dump RegisterForm --------------------\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
166 for(_rdefs.reset(); (name = _rdefs.iter()) != NULL;) {
a61af66fc99e Initial load
duke
parents:
diff changeset
167 ((RegDef*)_regDef[name])->output(fp);
a61af66fc99e Initial load
duke
parents:
diff changeset
168 }
a61af66fc99e Initial load
duke
parents:
diff changeset
169 fprintf(fp,"\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
170 for (_rclasses.reset(); (name = _rclasses.iter()) != NULL;) {
a61af66fc99e Initial load
duke
parents:
diff changeset
171 ((RegClass*)_regClass[name])->output(fp);
a61af66fc99e Initial load
duke
parents:
diff changeset
172 }
a61af66fc99e Initial load
duke
parents:
diff changeset
173 fprintf(fp,"\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
174 for (_aclasses.reset(); (name = _aclasses.iter()) != NULL;) {
a61af66fc99e Initial load
duke
parents:
diff changeset
175 ((AllocClass*)_allocClass[name])->output(fp);
a61af66fc99e Initial load
duke
parents:
diff changeset
176 }
a61af66fc99e Initial load
duke
parents:
diff changeset
177 fprintf(fp,"-------------------- end RegisterForm --------------------\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
178 }
a61af66fc99e Initial load
duke
parents:
diff changeset
179
a61af66fc99e Initial load
duke
parents:
diff changeset
180 //------------------------------RegDef-----------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
181 // Constructor
a61af66fc99e Initial load
duke
parents:
diff changeset
182 RegDef::RegDef(char *regname, char *callconv, char *c_conv, char * idealtype, char * encode, char * concrete)
a61af66fc99e Initial load
duke
parents:
diff changeset
183 : _regname(regname), _callconv(callconv), _c_conv(c_conv),
a61af66fc99e Initial load
duke
parents:
diff changeset
184 _idealtype(idealtype),
a61af66fc99e Initial load
duke
parents:
diff changeset
185 _register_encode(encode),
a61af66fc99e Initial load
duke
parents:
diff changeset
186 _concrete(concrete),
a61af66fc99e Initial load
duke
parents:
diff changeset
187 _register_num(0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
188
a61af66fc99e Initial load
duke
parents:
diff changeset
189 // Chunk and register mask are determined by the register number
a61af66fc99e Initial load
duke
parents:
diff changeset
190 // _register_num is set when registers are added to an allocation class
a61af66fc99e Initial load
duke
parents:
diff changeset
191 }
a61af66fc99e Initial load
duke
parents:
diff changeset
192 RegDef::~RegDef() { // Destructor
a61af66fc99e Initial load
duke
parents:
diff changeset
193 }
a61af66fc99e Initial load
duke
parents:
diff changeset
194
a61af66fc99e Initial load
duke
parents:
diff changeset
195 void RegDef::set_register_num(uint32 register_num) {
a61af66fc99e Initial load
duke
parents:
diff changeset
196 _register_num = register_num;
a61af66fc99e Initial load
duke
parents:
diff changeset
197 }
a61af66fc99e Initial load
duke
parents:
diff changeset
198
a61af66fc99e Initial load
duke
parents:
diff changeset
199 // Bit pattern used for generating machine code
a61af66fc99e Initial load
duke
parents:
diff changeset
200 const char* RegDef::register_encode() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
201 return _register_encode;
a61af66fc99e Initial load
duke
parents:
diff changeset
202 }
a61af66fc99e Initial load
duke
parents:
diff changeset
203
a61af66fc99e Initial load
duke
parents:
diff changeset
204 // Register number used in machine-independent code
a61af66fc99e Initial load
duke
parents:
diff changeset
205 uint32 RegDef::register_num() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
206 return _register_num;
a61af66fc99e Initial load
duke
parents:
diff changeset
207 }
a61af66fc99e Initial load
duke
parents:
diff changeset
208
a61af66fc99e Initial load
duke
parents:
diff changeset
209 void RegDef::dump() {
a61af66fc99e Initial load
duke
parents:
diff changeset
210 output(stderr);
a61af66fc99e Initial load
duke
parents:
diff changeset
211 }
a61af66fc99e Initial load
duke
parents:
diff changeset
212
a61af66fc99e Initial load
duke
parents:
diff changeset
213 void RegDef::output(FILE *fp) { // Write info to output files
a61af66fc99e Initial load
duke
parents:
diff changeset
214 fprintf(fp,"RegDef: %s (%s) encode as %s using number %d\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
215 _regname, (_callconv?_callconv:""), _register_encode, _register_num);
a61af66fc99e Initial load
duke
parents:
diff changeset
216 fprintf(fp,"\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
217 }
a61af66fc99e Initial load
duke
parents:
diff changeset
218
a61af66fc99e Initial load
duke
parents:
diff changeset
219
a61af66fc99e Initial load
duke
parents:
diff changeset
220 //------------------------------RegClass---------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
221 // Construct a register class into which registers will be inserted
4121
db2e64ca2d5a 7090968: Allow adlc register class to depend on runtime conditions
roland
parents: 1972
diff changeset
222 RegClass::RegClass(const char *classid) : _stack_or_reg(false), _classid(classid), _regDef(cmpstr,hashstr, Form::arena),
db2e64ca2d5a 7090968: Allow adlc register class to depend on runtime conditions
roland
parents: 1972
diff changeset
223 _user_defined(NULL)
db2e64ca2d5a 7090968: Allow adlc register class to depend on runtime conditions
roland
parents: 1972
diff changeset
224 {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
225 }
a61af66fc99e Initial load
duke
parents:
diff changeset
226
a61af66fc99e Initial load
duke
parents:
diff changeset
227 // record a register in this class
a61af66fc99e Initial load
duke
parents:
diff changeset
228 void RegClass::addReg(RegDef *regDef) {
a61af66fc99e Initial load
duke
parents:
diff changeset
229 _regDefs.addName(regDef->_regname);
a61af66fc99e Initial load
duke
parents:
diff changeset
230 _regDef.Insert((void*)regDef->_regname, regDef);
a61af66fc99e Initial load
duke
parents:
diff changeset
231 }
a61af66fc99e Initial load
duke
parents:
diff changeset
232
a61af66fc99e Initial load
duke
parents:
diff changeset
233 // Number of registers in class
a61af66fc99e Initial load
duke
parents:
diff changeset
234 uint RegClass::size() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
235 return _regDef.Size();
a61af66fc99e Initial load
duke
parents:
diff changeset
236 }
a61af66fc99e Initial load
duke
parents:
diff changeset
237
a61af66fc99e Initial load
duke
parents:
diff changeset
238 const RegDef *RegClass::get_RegDef(const char *rd_name) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
239 return (const RegDef*)_regDef[rd_name];
a61af66fc99e Initial load
duke
parents:
diff changeset
240 }
a61af66fc99e Initial load
duke
parents:
diff changeset
241
a61af66fc99e Initial load
duke
parents:
diff changeset
242 void RegClass::reset() {
a61af66fc99e Initial load
duke
parents:
diff changeset
243 _regDefs.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
244 }
a61af66fc99e Initial load
duke
parents:
diff changeset
245
a61af66fc99e Initial load
duke
parents:
diff changeset
246 const char *RegClass::rd_name_iter() {
a61af66fc99e Initial load
duke
parents:
diff changeset
247 return _regDefs.iter();
a61af66fc99e Initial load
duke
parents:
diff changeset
248 }
a61af66fc99e Initial load
duke
parents:
diff changeset
249
a61af66fc99e Initial load
duke
parents:
diff changeset
250 RegDef *RegClass::RegDef_iter() {
a61af66fc99e Initial load
duke
parents:
diff changeset
251 const char *rd_name = rd_name_iter();
a61af66fc99e Initial load
duke
parents:
diff changeset
252 RegDef *reg_def = rd_name ? (RegDef*)_regDef[rd_name] : NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
253 return reg_def;
a61af66fc99e Initial load
duke
parents:
diff changeset
254 }
a61af66fc99e Initial load
duke
parents:
diff changeset
255
a61af66fc99e Initial load
duke
parents:
diff changeset
256 const RegDef* RegClass::find_first_elem() {
a61af66fc99e Initial load
duke
parents:
diff changeset
257 const RegDef* first = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
258 const RegDef* def = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
259
a61af66fc99e Initial load
duke
parents:
diff changeset
260 reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
261 while ((def = RegDef_iter()) != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
262 if (first == NULL || def->register_num() < first->register_num()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
263 first = def;
a61af66fc99e Initial load
duke
parents:
diff changeset
264 }
a61af66fc99e Initial load
duke
parents:
diff changeset
265 }
a61af66fc99e Initial load
duke
parents:
diff changeset
266
a61af66fc99e Initial load
duke
parents:
diff changeset
267 assert(first != NULL, "empty mask?");
a61af66fc99e Initial load
duke
parents:
diff changeset
268 return first;;
a61af66fc99e Initial load
duke
parents:
diff changeset
269 }
a61af66fc99e Initial load
duke
parents:
diff changeset
270
a61af66fc99e Initial load
duke
parents:
diff changeset
271 // Collect all the registers in this register-word. One bit per register.
a61af66fc99e Initial load
duke
parents:
diff changeset
272 int RegClass::regs_in_word( int wordnum, bool stack_also ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
273 int word = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
274 const char *name;
a61af66fc99e Initial load
duke
parents:
diff changeset
275 for(_regDefs.reset(); (name = _regDefs.iter()) != NULL;) {
a61af66fc99e Initial load
duke
parents:
diff changeset
276 int rnum = ((RegDef*)_regDef[name])->register_num();
a61af66fc99e Initial load
duke
parents:
diff changeset
277 if( (rnum >> 5) == wordnum )
603
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 0
diff changeset
278 word |= (1 << (rnum & 31));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
279 }
a61af66fc99e Initial load
duke
parents:
diff changeset
280 if( stack_also ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
281 // Now also collect stack bits
a61af66fc99e Initial load
duke
parents:
diff changeset
282 for( int i = 0; i < 32; i++ )
a61af66fc99e Initial load
duke
parents:
diff changeset
283 if( wordnum*32+i >= RegisterForm::_reg_ctr )
603
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 0
diff changeset
284 word |= (1 << i);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
285 }
a61af66fc99e Initial load
duke
parents:
diff changeset
286
a61af66fc99e Initial load
duke
parents:
diff changeset
287 return word;
a61af66fc99e Initial load
duke
parents:
diff changeset
288 }
a61af66fc99e Initial load
duke
parents:
diff changeset
289
a61af66fc99e Initial load
duke
parents:
diff changeset
290 void RegClass::dump() {
a61af66fc99e Initial load
duke
parents:
diff changeset
291 output(stderr);
a61af66fc99e Initial load
duke
parents:
diff changeset
292 }
a61af66fc99e Initial load
duke
parents:
diff changeset
293
a61af66fc99e Initial load
duke
parents:
diff changeset
294 void RegClass::output(FILE *fp) { // Write info to output files
a61af66fc99e Initial load
duke
parents:
diff changeset
295 fprintf(fp,"RegClass: %s\n",_classid);
a61af66fc99e Initial load
duke
parents:
diff changeset
296 const char *name;
a61af66fc99e Initial load
duke
parents:
diff changeset
297 for(_regDefs.reset(); (name = _regDefs.iter()) != NULL;) {
a61af66fc99e Initial load
duke
parents:
diff changeset
298 ((RegDef*)_regDef[name])->output(fp);
a61af66fc99e Initial load
duke
parents:
diff changeset
299 }
a61af66fc99e Initial load
duke
parents:
diff changeset
300 fprintf(fp,"--- done with entries for reg_class %s\n\n",_classid);
a61af66fc99e Initial load
duke
parents:
diff changeset
301 }
a61af66fc99e Initial load
duke
parents:
diff changeset
302
a61af66fc99e Initial load
duke
parents:
diff changeset
303
a61af66fc99e Initial load
duke
parents:
diff changeset
304 //------------------------------AllocClass-------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
305 AllocClass::AllocClass(char *classid) : _classid(classid), _regDef(cmpstr,hashstr, Form::arena) {
a61af66fc99e Initial load
duke
parents:
diff changeset
306 }
a61af66fc99e Initial load
duke
parents:
diff changeset
307
a61af66fc99e Initial load
duke
parents:
diff changeset
308 // record a register in this class
a61af66fc99e Initial load
duke
parents:
diff changeset
309 void AllocClass::addReg(RegDef *regDef) {
a61af66fc99e Initial load
duke
parents:
diff changeset
310 assert( regDef != NULL, "Can not add a NULL to an allocation class");
a61af66fc99e Initial load
duke
parents:
diff changeset
311 regDef->set_register_num( RegisterForm::_reg_ctr++ );
a61af66fc99e Initial load
duke
parents:
diff changeset
312 // Add regDef to this allocation class
a61af66fc99e Initial load
duke
parents:
diff changeset
313 _regDefs.addName(regDef->_regname);
a61af66fc99e Initial load
duke
parents:
diff changeset
314 _regDef.Insert((void*)regDef->_regname, regDef);
a61af66fc99e Initial load
duke
parents:
diff changeset
315 }
a61af66fc99e Initial load
duke
parents:
diff changeset
316
a61af66fc99e Initial load
duke
parents:
diff changeset
317 void AllocClass::dump() {
a61af66fc99e Initial load
duke
parents:
diff changeset
318 output(stderr);
a61af66fc99e Initial load
duke
parents:
diff changeset
319 }
a61af66fc99e Initial load
duke
parents:
diff changeset
320
a61af66fc99e Initial load
duke
parents:
diff changeset
321 void AllocClass::output(FILE *fp) { // Write info to output files
a61af66fc99e Initial load
duke
parents:
diff changeset
322 fprintf(fp,"AllocClass: %s \n",_classid);
a61af66fc99e Initial load
duke
parents:
diff changeset
323 const char *name;
a61af66fc99e Initial load
duke
parents:
diff changeset
324 for(_regDefs.reset(); (name = _regDefs.iter()) != NULL;) {
a61af66fc99e Initial load
duke
parents:
diff changeset
325 ((RegDef*)_regDef[name])->output(fp);
a61af66fc99e Initial load
duke
parents:
diff changeset
326 }
a61af66fc99e Initial load
duke
parents:
diff changeset
327 fprintf(fp,"--- done with entries for alloc_class %s\n\n",_classid);
a61af66fc99e Initial load
duke
parents:
diff changeset
328 }
a61af66fc99e Initial load
duke
parents:
diff changeset
329
a61af66fc99e Initial load
duke
parents:
diff changeset
330 //==============================Frame Handling=================================
a61af66fc99e Initial load
duke
parents:
diff changeset
331 //------------------------------FrameForm--------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
332 FrameForm::FrameForm() {
a61af66fc99e Initial load
duke
parents:
diff changeset
333 _frame_pointer = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
334 _c_frame_pointer = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
335 _alignment = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
336 _return_addr = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
337 _c_return_addr = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
338 _in_preserve_slots = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
339 _varargs_C_out_slots_killed = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
340 _calling_convention = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
341 _c_calling_convention = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
342 _return_value = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
343 _c_return_value = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
344 _interpreter_frame_pointer_reg = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
345 }
a61af66fc99e Initial load
duke
parents:
diff changeset
346
a61af66fc99e Initial load
duke
parents:
diff changeset
347 FrameForm::~FrameForm() {
a61af66fc99e Initial load
duke
parents:
diff changeset
348 }
a61af66fc99e Initial load
duke
parents:
diff changeset
349
a61af66fc99e Initial load
duke
parents:
diff changeset
350 void FrameForm::dump() {
a61af66fc99e Initial load
duke
parents:
diff changeset
351 output(stderr);
a61af66fc99e Initial load
duke
parents:
diff changeset
352 }
a61af66fc99e Initial load
duke
parents:
diff changeset
353
a61af66fc99e Initial load
duke
parents:
diff changeset
354 void FrameForm::output(FILE *fp) { // Write info to output files
a61af66fc99e Initial load
duke
parents:
diff changeset
355 fprintf(fp,"\nFrame:\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
356 }
a61af66fc99e Initial load
duke
parents:
diff changeset
357
a61af66fc99e Initial load
duke
parents:
diff changeset
358 //==============================Scheduling=====================================
a61af66fc99e Initial load
duke
parents:
diff changeset
359 //------------------------------PipelineForm-----------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
360 PipelineForm::PipelineForm()
a61af66fc99e Initial load
duke
parents:
diff changeset
361 : _reslist ()
a61af66fc99e Initial load
duke
parents:
diff changeset
362 , _resdict (cmpstr, hashstr, Form::arena)
a61af66fc99e Initial load
duke
parents:
diff changeset
363 , _classdict (cmpstr, hashstr, Form::arena)
a61af66fc99e Initial load
duke
parents:
diff changeset
364 , _rescount (0)
a61af66fc99e Initial load
duke
parents:
diff changeset
365 , _maxcycleused (0)
a61af66fc99e Initial load
duke
parents:
diff changeset
366 , _stages ()
a61af66fc99e Initial load
duke
parents:
diff changeset
367 , _stagecnt (0)
a61af66fc99e Initial load
duke
parents:
diff changeset
368 , _classlist ()
a61af66fc99e Initial load
duke
parents:
diff changeset
369 , _classcnt (0)
a61af66fc99e Initial load
duke
parents:
diff changeset
370 , _noplist ()
a61af66fc99e Initial load
duke
parents:
diff changeset
371 , _nopcnt (0)
a61af66fc99e Initial load
duke
parents:
diff changeset
372 , _variableSizeInstrs (false)
a61af66fc99e Initial load
duke
parents:
diff changeset
373 , _branchHasDelaySlot (false)
a61af66fc99e Initial load
duke
parents:
diff changeset
374 , _maxInstrsPerBundle (0)
a61af66fc99e Initial load
duke
parents:
diff changeset
375 , _maxBundlesPerCycle (1)
a61af66fc99e Initial load
duke
parents:
diff changeset
376 , _instrUnitSize (0)
a61af66fc99e Initial load
duke
parents:
diff changeset
377 , _bundleUnitSize (0)
a61af66fc99e Initial load
duke
parents:
diff changeset
378 , _instrFetchUnitSize (0)
a61af66fc99e Initial load
duke
parents:
diff changeset
379 , _instrFetchUnits (0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
380 }
a61af66fc99e Initial load
duke
parents:
diff changeset
381 PipelineForm::~PipelineForm() {
a61af66fc99e Initial load
duke
parents:
diff changeset
382 }
a61af66fc99e Initial load
duke
parents:
diff changeset
383
a61af66fc99e Initial load
duke
parents:
diff changeset
384 void PipelineForm::dump() {
a61af66fc99e Initial load
duke
parents:
diff changeset
385 output(stderr);
a61af66fc99e Initial load
duke
parents:
diff changeset
386 }
a61af66fc99e Initial load
duke
parents:
diff changeset
387
a61af66fc99e Initial load
duke
parents:
diff changeset
388 void PipelineForm::output(FILE *fp) { // Write info to output files
a61af66fc99e Initial load
duke
parents:
diff changeset
389 const char *res;
a61af66fc99e Initial load
duke
parents:
diff changeset
390 const char *stage;
a61af66fc99e Initial load
duke
parents:
diff changeset
391 const char *cls;
a61af66fc99e Initial load
duke
parents:
diff changeset
392 const char *nop;
a61af66fc99e Initial load
duke
parents:
diff changeset
393 int count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
394
a61af66fc99e Initial load
duke
parents:
diff changeset
395 fprintf(fp,"\nPipeline:");
a61af66fc99e Initial load
duke
parents:
diff changeset
396 if (_variableSizeInstrs)
a61af66fc99e Initial load
duke
parents:
diff changeset
397 if (_instrUnitSize > 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
398 fprintf(fp," variable-sized instructions in %d byte units", _instrUnitSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
399 else
a61af66fc99e Initial load
duke
parents:
diff changeset
400 fprintf(fp," variable-sized instructions");
a61af66fc99e Initial load
duke
parents:
diff changeset
401 else
a61af66fc99e Initial load
duke
parents:
diff changeset
402 if (_instrUnitSize > 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
403 fprintf(fp," fixed-sized instructions of %d bytes", _instrUnitSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
404 else if (_bundleUnitSize > 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
405 fprintf(fp," fixed-sized bundles of %d bytes", _bundleUnitSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
406 else
a61af66fc99e Initial load
duke
parents:
diff changeset
407 fprintf(fp," fixed-sized instructions");
a61af66fc99e Initial load
duke
parents:
diff changeset
408 if (_branchHasDelaySlot)
a61af66fc99e Initial load
duke
parents:
diff changeset
409 fprintf(fp,", branch has delay slot");
a61af66fc99e Initial load
duke
parents:
diff changeset
410 if (_maxInstrsPerBundle > 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
411 fprintf(fp,", max of %d instruction%s in parallel",
a61af66fc99e Initial load
duke
parents:
diff changeset
412 _maxInstrsPerBundle, _maxInstrsPerBundle > 1 ? "s" : "");
a61af66fc99e Initial load
duke
parents:
diff changeset
413 if (_maxBundlesPerCycle > 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
414 fprintf(fp,", max of %d bundle%s in parallel",
a61af66fc99e Initial load
duke
parents:
diff changeset
415 _maxBundlesPerCycle, _maxBundlesPerCycle > 1 ? "s" : "");
a61af66fc99e Initial load
duke
parents:
diff changeset
416 if (_instrFetchUnitSize > 0 && _instrFetchUnits)
a61af66fc99e Initial load
duke
parents:
diff changeset
417 fprintf(fp, ", fetch %d x % d bytes per cycle", _instrFetchUnits, _instrFetchUnitSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
418
a61af66fc99e Initial load
duke
parents:
diff changeset
419 fprintf(fp,"\nResource:");
a61af66fc99e Initial load
duke
parents:
diff changeset
420 for ( _reslist.reset(); (res = _reslist.iter()) != NULL; )
a61af66fc99e Initial load
duke
parents:
diff changeset
421 fprintf(fp," %s(0x%08x)", res, _resdict[res]->is_resource()->mask());
a61af66fc99e Initial load
duke
parents:
diff changeset
422 fprintf(fp,"\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
423
a61af66fc99e Initial load
duke
parents:
diff changeset
424 fprintf(fp,"\nDescription:\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
425 for ( _stages.reset(); (stage = _stages.iter()) != NULL; )
a61af66fc99e Initial load
duke
parents:
diff changeset
426 fprintf(fp," %s(%d)", stage, count++);
a61af66fc99e Initial load
duke
parents:
diff changeset
427 fprintf(fp,"\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
428
a61af66fc99e Initial load
duke
parents:
diff changeset
429 fprintf(fp,"\nClasses:\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
430 for ( _classlist.reset(); (cls = _classlist.iter()) != NULL; )
a61af66fc99e Initial load
duke
parents:
diff changeset
431 _classdict[cls]->is_pipeclass()->output(fp);
a61af66fc99e Initial load
duke
parents:
diff changeset
432
a61af66fc99e Initial load
duke
parents:
diff changeset
433 fprintf(fp,"\nNop Instructions:");
a61af66fc99e Initial load
duke
parents:
diff changeset
434 for ( _noplist.reset(); (nop = _noplist.iter()) != NULL; )
a61af66fc99e Initial load
duke
parents:
diff changeset
435 fprintf(fp, " \"%s\"", nop);
a61af66fc99e Initial load
duke
parents:
diff changeset
436 fprintf(fp,"\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
437 }
a61af66fc99e Initial load
duke
parents:
diff changeset
438
a61af66fc99e Initial load
duke
parents:
diff changeset
439
a61af66fc99e Initial load
duke
parents:
diff changeset
440 //------------------------------ResourceForm-----------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
441 ResourceForm::ResourceForm(unsigned resmask)
a61af66fc99e Initial load
duke
parents:
diff changeset
442 : _resmask(resmask) {
a61af66fc99e Initial load
duke
parents:
diff changeset
443 }
a61af66fc99e Initial load
duke
parents:
diff changeset
444 ResourceForm::~ResourceForm() {
a61af66fc99e Initial load
duke
parents:
diff changeset
445 }
a61af66fc99e Initial load
duke
parents:
diff changeset
446
a61af66fc99e Initial load
duke
parents:
diff changeset
447 ResourceForm *ResourceForm::is_resource() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
448 return (ResourceForm *)(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
449 }
a61af66fc99e Initial load
duke
parents:
diff changeset
450
a61af66fc99e Initial load
duke
parents:
diff changeset
451 void ResourceForm::dump() {
a61af66fc99e Initial load
duke
parents:
diff changeset
452 output(stderr);
a61af66fc99e Initial load
duke
parents:
diff changeset
453 }
a61af66fc99e Initial load
duke
parents:
diff changeset
454
a61af66fc99e Initial load
duke
parents:
diff changeset
455 void ResourceForm::output(FILE *fp) { // Write info to output files
a61af66fc99e Initial load
duke
parents:
diff changeset
456 fprintf(fp, "resource: 0x%08x;\n", mask());
a61af66fc99e Initial load
duke
parents:
diff changeset
457 }
a61af66fc99e Initial load
duke
parents:
diff changeset
458
a61af66fc99e Initial load
duke
parents:
diff changeset
459
a61af66fc99e Initial load
duke
parents:
diff changeset
460 //------------------------------PipeClassOperandForm----------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
461
a61af66fc99e Initial load
duke
parents:
diff changeset
462 void PipeClassOperandForm::dump() {
a61af66fc99e Initial load
duke
parents:
diff changeset
463 output(stderr);
a61af66fc99e Initial load
duke
parents:
diff changeset
464 }
a61af66fc99e Initial load
duke
parents:
diff changeset
465
a61af66fc99e Initial load
duke
parents:
diff changeset
466 void PipeClassOperandForm::output(FILE *fp) { // Write info to output files
a61af66fc99e Initial load
duke
parents:
diff changeset
467 fprintf(stderr,"PipeClassOperandForm: %s", _stage);
a61af66fc99e Initial load
duke
parents:
diff changeset
468 fflush(stderr);
a61af66fc99e Initial load
duke
parents:
diff changeset
469 if (_more_instrs > 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
470 fprintf(stderr,"+%d", _more_instrs);
a61af66fc99e Initial load
duke
parents:
diff changeset
471 fprintf(stderr," (%s)\n", _iswrite ? "write" : "read");
a61af66fc99e Initial load
duke
parents:
diff changeset
472 fflush(stderr);
a61af66fc99e Initial load
duke
parents:
diff changeset
473 fprintf(fp,"PipeClassOperandForm: %s", _stage);
a61af66fc99e Initial load
duke
parents:
diff changeset
474 if (_more_instrs > 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
475 fprintf(fp,"+%d", _more_instrs);
a61af66fc99e Initial load
duke
parents:
diff changeset
476 fprintf(fp," (%s)\n", _iswrite ? "write" : "read");
a61af66fc99e Initial load
duke
parents:
diff changeset
477 }
a61af66fc99e Initial load
duke
parents:
diff changeset
478
a61af66fc99e Initial load
duke
parents:
diff changeset
479
a61af66fc99e Initial load
duke
parents:
diff changeset
480 //------------------------------PipeClassResourceForm----------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
481
a61af66fc99e Initial load
duke
parents:
diff changeset
482 void PipeClassResourceForm::dump() {
a61af66fc99e Initial load
duke
parents:
diff changeset
483 output(stderr);
a61af66fc99e Initial load
duke
parents:
diff changeset
484 }
a61af66fc99e Initial load
duke
parents:
diff changeset
485
a61af66fc99e Initial load
duke
parents:
diff changeset
486 void PipeClassResourceForm::output(FILE *fp) { // Write info to output files
a61af66fc99e Initial load
duke
parents:
diff changeset
487 fprintf(fp,"PipeClassResourceForm: %s at stage %s for %d cycles\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
488 _resource, _stage, _cycles);
a61af66fc99e Initial load
duke
parents:
diff changeset
489 }
a61af66fc99e Initial load
duke
parents:
diff changeset
490
a61af66fc99e Initial load
duke
parents:
diff changeset
491
a61af66fc99e Initial load
duke
parents:
diff changeset
492 //------------------------------PipeClassForm----------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
493 PipeClassForm::PipeClassForm(const char *id, int num)
a61af66fc99e Initial load
duke
parents:
diff changeset
494 : _ident(id)
a61af66fc99e Initial load
duke
parents:
diff changeset
495 , _num(num)
a61af66fc99e Initial load
duke
parents:
diff changeset
496 , _localNames(cmpstr, hashstr, Form::arena)
a61af66fc99e Initial load
duke
parents:
diff changeset
497 , _localUsage(cmpstr, hashstr, Form::arena)
a61af66fc99e Initial load
duke
parents:
diff changeset
498 , _has_fixed_latency(0)
a61af66fc99e Initial load
duke
parents:
diff changeset
499 , _fixed_latency(0)
a61af66fc99e Initial load
duke
parents:
diff changeset
500 , _instruction_count(0)
a61af66fc99e Initial load
duke
parents:
diff changeset
501 , _has_multiple_bundles(false)
a61af66fc99e Initial load
duke
parents:
diff changeset
502 , _has_branch_delay_slot(false)
a61af66fc99e Initial load
duke
parents:
diff changeset
503 , _force_serialization(false)
a61af66fc99e Initial load
duke
parents:
diff changeset
504 , _may_have_no_code(false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
505 }
a61af66fc99e Initial load
duke
parents:
diff changeset
506
a61af66fc99e Initial load
duke
parents:
diff changeset
507 PipeClassForm::~PipeClassForm() {
a61af66fc99e Initial load
duke
parents:
diff changeset
508 }
a61af66fc99e Initial load
duke
parents:
diff changeset
509
a61af66fc99e Initial load
duke
parents:
diff changeset
510 PipeClassForm *PipeClassForm::is_pipeclass() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
511 return (PipeClassForm *)(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
512 }
a61af66fc99e Initial load
duke
parents:
diff changeset
513
a61af66fc99e Initial load
duke
parents:
diff changeset
514 void PipeClassForm::dump() {
a61af66fc99e Initial load
duke
parents:
diff changeset
515 output(stderr);
a61af66fc99e Initial load
duke
parents:
diff changeset
516 }
a61af66fc99e Initial load
duke
parents:
diff changeset
517
a61af66fc99e Initial load
duke
parents:
diff changeset
518 void PipeClassForm::output(FILE *fp) { // Write info to output files
a61af66fc99e Initial load
duke
parents:
diff changeset
519 fprintf(fp,"PipeClassForm: #%03d", _num);
a61af66fc99e Initial load
duke
parents:
diff changeset
520 if (_ident)
a61af66fc99e Initial load
duke
parents:
diff changeset
521 fprintf(fp," \"%s\":", _ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
522 if (_has_fixed_latency)
a61af66fc99e Initial load
duke
parents:
diff changeset
523 fprintf(fp," latency %d", _fixed_latency);
a61af66fc99e Initial load
duke
parents:
diff changeset
524 if (_force_serialization)
a61af66fc99e Initial load
duke
parents:
diff changeset
525 fprintf(fp, ", force serialization");
a61af66fc99e Initial load
duke
parents:
diff changeset
526 if (_may_have_no_code)
a61af66fc99e Initial load
duke
parents:
diff changeset
527 fprintf(fp, ", may have no code");
a61af66fc99e Initial load
duke
parents:
diff changeset
528 fprintf(fp, ", %d instruction%s\n", InstructionCount(), InstructionCount() != 1 ? "s" : "");
a61af66fc99e Initial load
duke
parents:
diff changeset
529 }
a61af66fc99e Initial load
duke
parents:
diff changeset
530
a61af66fc99e Initial load
duke
parents:
diff changeset
531
a61af66fc99e Initial load
duke
parents:
diff changeset
532 //==============================Peephole Optimization==========================
a61af66fc99e Initial load
duke
parents:
diff changeset
533 int Peephole::_peephole_counter = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
534 //------------------------------Peephole---------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
535 Peephole::Peephole() : _match(NULL), _constraint(NULL), _replace(NULL), _next(NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
536 _peephole_number = _peephole_counter++;
a61af66fc99e Initial load
duke
parents:
diff changeset
537 }
a61af66fc99e Initial load
duke
parents:
diff changeset
538 Peephole::~Peephole() {
a61af66fc99e Initial load
duke
parents:
diff changeset
539 }
a61af66fc99e Initial load
duke
parents:
diff changeset
540
a61af66fc99e Initial load
duke
parents:
diff changeset
541 // Append a peephole rule with the same root instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
542 void Peephole::append_peephole(Peephole *next_peephole) {
a61af66fc99e Initial load
duke
parents:
diff changeset
543 if( _next == NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
544 _next = next_peephole;
a61af66fc99e Initial load
duke
parents:
diff changeset
545 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
546 _next->append_peephole( next_peephole );
a61af66fc99e Initial load
duke
parents:
diff changeset
547 }
a61af66fc99e Initial load
duke
parents:
diff changeset
548 }
a61af66fc99e Initial load
duke
parents:
diff changeset
549
a61af66fc99e Initial load
duke
parents:
diff changeset
550 // Store the components of this peephole rule
a61af66fc99e Initial load
duke
parents:
diff changeset
551 void Peephole::add_match(PeepMatch *match) {
a61af66fc99e Initial load
duke
parents:
diff changeset
552 assert( _match == NULL, "fatal()" );
a61af66fc99e Initial load
duke
parents:
diff changeset
553 _match = match;
a61af66fc99e Initial load
duke
parents:
diff changeset
554 }
a61af66fc99e Initial load
duke
parents:
diff changeset
555
a61af66fc99e Initial load
duke
parents:
diff changeset
556 void Peephole::append_constraint(PeepConstraint *next_constraint) {
a61af66fc99e Initial load
duke
parents:
diff changeset
557 if( _constraint == NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
558 _constraint = next_constraint;
a61af66fc99e Initial load
duke
parents:
diff changeset
559 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
560 _constraint->append( next_constraint );
a61af66fc99e Initial load
duke
parents:
diff changeset
561 }
a61af66fc99e Initial load
duke
parents:
diff changeset
562 }
a61af66fc99e Initial load
duke
parents:
diff changeset
563
a61af66fc99e Initial load
duke
parents:
diff changeset
564 void Peephole::add_replace(PeepReplace *replace) {
a61af66fc99e Initial load
duke
parents:
diff changeset
565 assert( _replace == NULL, "fatal()" );
a61af66fc99e Initial load
duke
parents:
diff changeset
566 _replace = replace;
a61af66fc99e Initial load
duke
parents:
diff changeset
567 }
a61af66fc99e Initial load
duke
parents:
diff changeset
568
a61af66fc99e Initial load
duke
parents:
diff changeset
569 // class Peephole accessor methods are in the declaration.
a61af66fc99e Initial load
duke
parents:
diff changeset
570
a61af66fc99e Initial load
duke
parents:
diff changeset
571
a61af66fc99e Initial load
duke
parents:
diff changeset
572 void Peephole::dump() {
a61af66fc99e Initial load
duke
parents:
diff changeset
573 output(stderr);
a61af66fc99e Initial load
duke
parents:
diff changeset
574 }
a61af66fc99e Initial load
duke
parents:
diff changeset
575
a61af66fc99e Initial load
duke
parents:
diff changeset
576 void Peephole::output(FILE *fp) { // Write info to output files
a61af66fc99e Initial load
duke
parents:
diff changeset
577 fprintf(fp,"Peephole:\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
578 if( _match != NULL ) _match->output(fp);
a61af66fc99e Initial load
duke
parents:
diff changeset
579 if( _constraint != NULL ) _constraint->output(fp);
a61af66fc99e Initial load
duke
parents:
diff changeset
580 if( _replace != NULL ) _replace->output(fp);
a61af66fc99e Initial load
duke
parents:
diff changeset
581 // Output the next entry
a61af66fc99e Initial load
duke
parents:
diff changeset
582 if( _next ) _next->output(fp);
a61af66fc99e Initial load
duke
parents:
diff changeset
583 }
a61af66fc99e Initial load
duke
parents:
diff changeset
584
a61af66fc99e Initial load
duke
parents:
diff changeset
585 //------------------------------PeepMatch--------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
586 PeepMatch::PeepMatch(char *rule) : _max_position(0), _rule(rule) {
a61af66fc99e Initial load
duke
parents:
diff changeset
587 }
a61af66fc99e Initial load
duke
parents:
diff changeset
588 PeepMatch::~PeepMatch() {
a61af66fc99e Initial load
duke
parents:
diff changeset
589 }
a61af66fc99e Initial load
duke
parents:
diff changeset
590
a61af66fc99e Initial load
duke
parents:
diff changeset
591
a61af66fc99e Initial load
duke
parents:
diff changeset
592 // Insert info into the match-rule
a61af66fc99e Initial load
duke
parents:
diff changeset
593 void PeepMatch::add_instruction(int parent, int position, const char *name,
a61af66fc99e Initial load
duke
parents:
diff changeset
594 int input) {
a61af66fc99e Initial load
duke
parents:
diff changeset
595 if( position > _max_position ) _max_position = position;
a61af66fc99e Initial load
duke
parents:
diff changeset
596
603
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 0
diff changeset
597 _parent.addName((char*) (intptr_t) parent);
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 0
diff changeset
598 _position.addName((char*) (intptr_t) position);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
599 _instrs.addName(name);
603
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 0
diff changeset
600 _input.addName((char*) (intptr_t) input);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
601 }
a61af66fc99e Initial load
duke
parents:
diff changeset
602
a61af66fc99e Initial load
duke
parents:
diff changeset
603 // Access info about instructions in the peep-match rule
a61af66fc99e Initial load
duke
parents:
diff changeset
604 int PeepMatch::max_position() {
a61af66fc99e Initial load
duke
parents:
diff changeset
605 return _max_position;
a61af66fc99e Initial load
duke
parents:
diff changeset
606 }
a61af66fc99e Initial load
duke
parents:
diff changeset
607
603
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 0
diff changeset
608 const char *PeepMatch::instruction_name(int position) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
609 return _instrs.name(position);
a61af66fc99e Initial load
duke
parents:
diff changeset
610 }
a61af66fc99e Initial load
duke
parents:
diff changeset
611
a61af66fc99e Initial load
duke
parents:
diff changeset
612 // Iterate through all info on matched instructions
a61af66fc99e Initial load
duke
parents:
diff changeset
613 void PeepMatch::reset() {
a61af66fc99e Initial load
duke
parents:
diff changeset
614 _parent.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
615 _position.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
616 _instrs.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
617 _input.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
618 }
a61af66fc99e Initial load
duke
parents:
diff changeset
619
603
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 0
diff changeset
620 void PeepMatch::next_instruction(int &parent, int &position, const char* &name, int &input) {
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 0
diff changeset
621 parent = (int) (intptr_t) _parent.iter();
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 0
diff changeset
622 position = (int) (intptr_t) _position.iter();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
623 name = _instrs.iter();
603
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 0
diff changeset
624 input = (int) (intptr_t) _input.iter();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
625 }
a61af66fc99e Initial load
duke
parents:
diff changeset
626
a61af66fc99e Initial load
duke
parents:
diff changeset
627 // 'true' if current position in iteration is a placeholder, not matched.
a61af66fc99e Initial load
duke
parents:
diff changeset
628 bool PeepMatch::is_placeholder() {
a61af66fc99e Initial load
duke
parents:
diff changeset
629 return _instrs.current_is_signal();
a61af66fc99e Initial load
duke
parents:
diff changeset
630 }
a61af66fc99e Initial load
duke
parents:
diff changeset
631
a61af66fc99e Initial load
duke
parents:
diff changeset
632
a61af66fc99e Initial load
duke
parents:
diff changeset
633 void PeepMatch::dump() {
a61af66fc99e Initial load
duke
parents:
diff changeset
634 output(stderr);
a61af66fc99e Initial load
duke
parents:
diff changeset
635 }
a61af66fc99e Initial load
duke
parents:
diff changeset
636
a61af66fc99e Initial load
duke
parents:
diff changeset
637 void PeepMatch::output(FILE *fp) { // Write info to output files
a61af66fc99e Initial load
duke
parents:
diff changeset
638 fprintf(fp,"PeepMatch:\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
639 }
a61af66fc99e Initial load
duke
parents:
diff changeset
640
a61af66fc99e Initial load
duke
parents:
diff changeset
641 //------------------------------PeepConstraint---------------------------------
603
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 0
diff changeset
642 PeepConstraint::PeepConstraint(int left_inst, char* left_op, char* relation,
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 0
diff changeset
643 int right_inst, char* right_op)
0
a61af66fc99e Initial load
duke
parents:
diff changeset
644 : _left_inst(left_inst), _left_op(left_op), _relation(relation),
a61af66fc99e Initial load
duke
parents:
diff changeset
645 _right_inst(right_inst), _right_op(right_op), _next(NULL) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
646 PeepConstraint::~PeepConstraint() {
a61af66fc99e Initial load
duke
parents:
diff changeset
647 }
a61af66fc99e Initial load
duke
parents:
diff changeset
648
a61af66fc99e Initial load
duke
parents:
diff changeset
649 // Check if constraints use instruction at position
603
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 0
diff changeset
650 bool PeepConstraint::constrains_instruction(int position) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
651 // Check local instruction constraints
a61af66fc99e Initial load
duke
parents:
diff changeset
652 if( _left_inst == position ) return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
653 if( _right_inst == position ) return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
654
a61af66fc99e Initial load
duke
parents:
diff changeset
655 // Check remaining constraints in list
a61af66fc99e Initial load
duke
parents:
diff changeset
656 if( _next == NULL ) return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
657 else return _next->constrains_instruction(position);
a61af66fc99e Initial load
duke
parents:
diff changeset
658 }
a61af66fc99e Initial load
duke
parents:
diff changeset
659
a61af66fc99e Initial load
duke
parents:
diff changeset
660 // Add another constraint
a61af66fc99e Initial load
duke
parents:
diff changeset
661 void PeepConstraint::append(PeepConstraint *next_constraint) {
a61af66fc99e Initial load
duke
parents:
diff changeset
662 if( _next == NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
663 _next = next_constraint;
a61af66fc99e Initial load
duke
parents:
diff changeset
664 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
665 _next->append( next_constraint );
a61af66fc99e Initial load
duke
parents:
diff changeset
666 }
a61af66fc99e Initial load
duke
parents:
diff changeset
667 }
a61af66fc99e Initial load
duke
parents:
diff changeset
668
a61af66fc99e Initial load
duke
parents:
diff changeset
669 // Access the next constraint in the list
a61af66fc99e Initial load
duke
parents:
diff changeset
670 PeepConstraint *PeepConstraint::next() {
a61af66fc99e Initial load
duke
parents:
diff changeset
671 return _next;
a61af66fc99e Initial load
duke
parents:
diff changeset
672 }
a61af66fc99e Initial load
duke
parents:
diff changeset
673
a61af66fc99e Initial load
duke
parents:
diff changeset
674
a61af66fc99e Initial load
duke
parents:
diff changeset
675 void PeepConstraint::dump() {
a61af66fc99e Initial load
duke
parents:
diff changeset
676 output(stderr);
a61af66fc99e Initial load
duke
parents:
diff changeset
677 }
a61af66fc99e Initial load
duke
parents:
diff changeset
678
a61af66fc99e Initial load
duke
parents:
diff changeset
679 void PeepConstraint::output(FILE *fp) { // Write info to output files
a61af66fc99e Initial load
duke
parents:
diff changeset
680 fprintf(fp,"PeepConstraint:\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
681 }
a61af66fc99e Initial load
duke
parents:
diff changeset
682
a61af66fc99e Initial load
duke
parents:
diff changeset
683 //------------------------------PeepReplace------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
684 PeepReplace::PeepReplace(char *rule) : _rule(rule) {
a61af66fc99e Initial load
duke
parents:
diff changeset
685 }
a61af66fc99e Initial load
duke
parents:
diff changeset
686 PeepReplace::~PeepReplace() {
a61af66fc99e Initial load
duke
parents:
diff changeset
687 }
a61af66fc99e Initial load
duke
parents:
diff changeset
688
a61af66fc99e Initial load
duke
parents:
diff changeset
689 // Add contents of peepreplace
a61af66fc99e Initial load
duke
parents:
diff changeset
690 void PeepReplace::add_instruction(char *root) {
a61af66fc99e Initial load
duke
parents:
diff changeset
691 _instruction.addName(root);
a61af66fc99e Initial load
duke
parents:
diff changeset
692 _operand_inst_num.add_signal();
a61af66fc99e Initial load
duke
parents:
diff changeset
693 _operand_op_name.add_signal();
a61af66fc99e Initial load
duke
parents:
diff changeset
694 }
a61af66fc99e Initial load
duke
parents:
diff changeset
695 void PeepReplace::add_operand( int inst_num, char *inst_operand ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
696 _instruction.add_signal();
603
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 0
diff changeset
697 _operand_inst_num.addName((char*) (intptr_t) inst_num);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
698 _operand_op_name.addName(inst_operand);
a61af66fc99e Initial load
duke
parents:
diff changeset
699 }
a61af66fc99e Initial load
duke
parents:
diff changeset
700
a61af66fc99e Initial load
duke
parents:
diff changeset
701 // Access contents of peepreplace
a61af66fc99e Initial load
duke
parents:
diff changeset
702 void PeepReplace::reset() {
a61af66fc99e Initial load
duke
parents:
diff changeset
703 _instruction.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
704 _operand_inst_num.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
705 _operand_op_name.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
706 }
603
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 0
diff changeset
707 void PeepReplace::next_instruction(const char* &inst){
0
a61af66fc99e Initial load
duke
parents:
diff changeset
708 inst = _instruction.iter();
603
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 0
diff changeset
709 int inst_num = (int) (intptr_t) _operand_inst_num.iter();
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 0
diff changeset
710 const char* inst_operand = _operand_op_name.iter();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
711 }
603
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 0
diff changeset
712 void PeepReplace::next_operand(int &inst_num, const char* &inst_operand) {
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 0
diff changeset
713 const char* inst = _instruction.iter();
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 0
diff changeset
714 inst_num = (int) (intptr_t) _operand_inst_num.iter();
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 0
diff changeset
715 inst_operand = _operand_op_name.iter();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
716 }
a61af66fc99e Initial load
duke
parents:
diff changeset
717
a61af66fc99e Initial load
duke
parents:
diff changeset
718
a61af66fc99e Initial load
duke
parents:
diff changeset
719
a61af66fc99e Initial load
duke
parents:
diff changeset
720 void PeepReplace::dump() {
a61af66fc99e Initial load
duke
parents:
diff changeset
721 output(stderr);
a61af66fc99e Initial load
duke
parents:
diff changeset
722 }
a61af66fc99e Initial load
duke
parents:
diff changeset
723
a61af66fc99e Initial load
duke
parents:
diff changeset
724 void PeepReplace::output(FILE *fp) { // Write info to output files
a61af66fc99e Initial load
duke
parents:
diff changeset
725 fprintf(fp,"PeepReplace:\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
726 }