annotate src/share/vm/adlc/output_c.cpp @ 17810:62c54fcc0a35

Merge
author kvn
date Tue, 25 Mar 2014 17:07:36 -0700
parents 2fcab8ba885a 606acabe7b5c
children 52b4284cb496
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
17467
55fb97c4c58d 8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013
mikael
parents: 12167
diff changeset
2 * Copyright (c) 1998, 2013, 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: 1541
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1541
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: 1541
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 // output_c.cpp - Class CPP file output routines for architecture definition
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 #include "adlc.hpp"
a61af66fc99e Initial load
duke
parents:
diff changeset
28
a61af66fc99e Initial load
duke
parents:
diff changeset
29 // Utilities to characterize effect statements
a61af66fc99e Initial load
duke
parents:
diff changeset
30 static bool is_def(int usedef) {
a61af66fc99e Initial load
duke
parents:
diff changeset
31 switch(usedef) {
a61af66fc99e Initial load
duke
parents:
diff changeset
32 case Component::DEF:
a61af66fc99e Initial load
duke
parents:
diff changeset
33 case Component::USE_DEF: return true; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
34 }
a61af66fc99e Initial load
duke
parents:
diff changeset
35 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 }
a61af66fc99e Initial load
duke
parents:
diff changeset
37
a61af66fc99e Initial load
duke
parents:
diff changeset
38 static bool is_use(int usedef) {
a61af66fc99e Initial load
duke
parents:
diff changeset
39 switch(usedef) {
a61af66fc99e Initial load
duke
parents:
diff changeset
40 case Component::USE:
a61af66fc99e Initial load
duke
parents:
diff changeset
41 case Component::USE_DEF:
a61af66fc99e Initial load
duke
parents:
diff changeset
42 case Component::USE_KILL: return true; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
43 }
a61af66fc99e Initial load
duke
parents:
diff changeset
44 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
45 }
a61af66fc99e Initial load
duke
parents:
diff changeset
46
a61af66fc99e Initial load
duke
parents:
diff changeset
47 static bool is_kill(int usedef) {
a61af66fc99e Initial load
duke
parents:
diff changeset
48 switch(usedef) {
a61af66fc99e Initial load
duke
parents:
diff changeset
49 case Component::KILL:
a61af66fc99e Initial load
duke
parents:
diff changeset
50 case Component::USE_KILL: return true; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
51 }
a61af66fc99e Initial load
duke
parents:
diff changeset
52 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
53 }
a61af66fc99e Initial load
duke
parents:
diff changeset
54
a61af66fc99e Initial load
duke
parents:
diff changeset
55 // Define an array containing the machine register names, strings.
a61af66fc99e Initial load
duke
parents:
diff changeset
56 static void defineRegNames(FILE *fp, RegisterForm *registers) {
a61af66fc99e Initial load
duke
parents:
diff changeset
57 if (registers) {
a61af66fc99e Initial load
duke
parents:
diff changeset
58 fprintf(fp,"\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
59 fprintf(fp,"// An array of character pointers to machine register names.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
60 fprintf(fp,"const char *Matcher::regName[REG_COUNT] = {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
61
a61af66fc99e Initial load
duke
parents:
diff changeset
62 // Output the register name for each register in the allocation classes
a61af66fc99e Initial load
duke
parents:
diff changeset
63 RegDef *reg_def = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
64 RegDef *next = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
65 registers->reset_RegDefs();
9078
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
66 for (reg_def = registers->iter_RegDefs(); reg_def != NULL; reg_def = next) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
67 next = registers->iter_RegDefs();
a61af66fc99e Initial load
duke
parents:
diff changeset
68 const char *comma = (next != NULL) ? "," : " // no trailing comma";
9078
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
69 fprintf(fp," \"%s\"%s\n", reg_def->_regname, comma);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
70 }
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72 // Finish defining enumeration
a61af66fc99e Initial load
duke
parents:
diff changeset
73 fprintf(fp,"};\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
74
a61af66fc99e Initial load
duke
parents:
diff changeset
75 fprintf(fp,"\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
76 fprintf(fp,"// An array of character pointers to machine register names.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
77 fprintf(fp,"const VMReg OptoReg::opto2vm[REG_COUNT] = {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
78 reg_def = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
79 next = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
80 registers->reset_RegDefs();
9078
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
81 for (reg_def = registers->iter_RegDefs(); reg_def != NULL; reg_def = next) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
82 next = registers->iter_RegDefs();
a61af66fc99e Initial load
duke
parents:
diff changeset
83 const char *comma = (next != NULL) ? "," : " // no trailing comma";
9078
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
84 fprintf(fp,"\t%s%s\n", reg_def->_concrete, comma);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
85 }
a61af66fc99e Initial load
duke
parents:
diff changeset
86 // Finish defining array
a61af66fc99e Initial load
duke
parents:
diff changeset
87 fprintf(fp,"\t};\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
88 fprintf(fp,"\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
89
a61af66fc99e Initial load
duke
parents:
diff changeset
90 fprintf(fp," OptoReg::Name OptoReg::vm2opto[ConcreteRegisterImpl::number_of_registers];\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
91
a61af66fc99e Initial load
duke
parents:
diff changeset
92 }
a61af66fc99e Initial load
duke
parents:
diff changeset
93 }
a61af66fc99e Initial load
duke
parents:
diff changeset
94
a61af66fc99e Initial load
duke
parents:
diff changeset
95 // Define an array containing the machine register encoding values
a61af66fc99e Initial load
duke
parents:
diff changeset
96 static void defineRegEncodes(FILE *fp, RegisterForm *registers) {
a61af66fc99e Initial load
duke
parents:
diff changeset
97 if (registers) {
a61af66fc99e Initial load
duke
parents:
diff changeset
98 fprintf(fp,"\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
99 fprintf(fp,"// An array of the machine register encode values\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
100 fprintf(fp,"const unsigned char Matcher::_regEncode[REG_COUNT] = {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
101
a61af66fc99e Initial load
duke
parents:
diff changeset
102 // Output the register encoding for each register in the allocation classes
a61af66fc99e Initial load
duke
parents:
diff changeset
103 RegDef *reg_def = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
104 RegDef *next = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
105 registers->reset_RegDefs();
9078
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
106 for (reg_def = registers->iter_RegDefs(); reg_def != NULL; reg_def = next) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
107 next = registers->iter_RegDefs();
a61af66fc99e Initial load
duke
parents:
diff changeset
108 const char* register_encode = reg_def->register_encode();
a61af66fc99e Initial load
duke
parents:
diff changeset
109 const char *comma = (next != NULL) ? "," : " // no trailing comma";
a61af66fc99e Initial load
duke
parents:
diff changeset
110 int encval;
a61af66fc99e Initial load
duke
parents:
diff changeset
111 if (!ADLParser::is_int_token(register_encode, encval)) {
9078
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
112 fprintf(fp," %s%s // %s\n", register_encode, comma, reg_def->_regname);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
113 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
114 // Output known constants in hex char format (backward compatibility).
a61af66fc99e Initial load
duke
parents:
diff changeset
115 assert(encval < 256, "Exceeded supported width for register encoding");
9078
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
116 fprintf(fp," (unsigned char)'\\x%X'%s // %s\n", encval, comma, reg_def->_regname);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
117 }
a61af66fc99e Initial load
duke
parents:
diff changeset
118 }
a61af66fc99e Initial load
duke
parents:
diff changeset
119 // Finish defining enumeration
a61af66fc99e Initial load
duke
parents:
diff changeset
120 fprintf(fp,"};\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
121
a61af66fc99e Initial load
duke
parents:
diff changeset
122 } // Done defining array
a61af66fc99e Initial load
duke
parents:
diff changeset
123 }
a61af66fc99e Initial load
duke
parents:
diff changeset
124
a61af66fc99e Initial load
duke
parents:
diff changeset
125 // Output an enumeration of register class names
a61af66fc99e Initial load
duke
parents:
diff changeset
126 static void defineRegClassEnum(FILE *fp, RegisterForm *registers) {
a61af66fc99e Initial load
duke
parents:
diff changeset
127 if (registers) {
a61af66fc99e Initial load
duke
parents:
diff changeset
128 // Output an enumeration of register class names
a61af66fc99e Initial load
duke
parents:
diff changeset
129 fprintf(fp,"\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
130 fprintf(fp,"// Enumeration of register class names\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
131 fprintf(fp, "enum machRegisterClass {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
132 registers->_rclasses.reset();
9078
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
133 for (const char *class_name = NULL; (class_name = registers->_rclasses.iter()) != NULL;) {
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
134 const char * class_name_to_upper = toUpper(class_name);
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
135 fprintf(fp," %s,\n", class_name_to_upper);
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
136 delete[] class_name_to_upper;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
137 }
a61af66fc99e Initial load
duke
parents:
diff changeset
138 // Finish defining enumeration
a61af66fc99e Initial load
duke
parents:
diff changeset
139 fprintf(fp, " _last_Mach_Reg_Class\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
140 fprintf(fp, "};\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
141 }
a61af66fc99e Initial load
duke
parents:
diff changeset
142 }
a61af66fc99e Initial load
duke
parents:
diff changeset
143
a61af66fc99e Initial load
duke
parents:
diff changeset
144 // Declare an enumeration of user-defined register classes
a61af66fc99e Initial load
duke
parents:
diff changeset
145 // and a list of register masks, one for each class.
a61af66fc99e Initial load
duke
parents:
diff changeset
146 void ArchDesc::declare_register_masks(FILE *fp_hpp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
147 const char *rc_name;
a61af66fc99e Initial load
duke
parents:
diff changeset
148
9078
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
149 if (_register) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
150 // Build enumeration of user-defined register classes.
a61af66fc99e Initial load
duke
parents:
diff changeset
151 defineRegClassEnum(fp_hpp, _register);
a61af66fc99e Initial load
duke
parents:
diff changeset
152
a61af66fc99e Initial load
duke
parents:
diff changeset
153 // Generate a list of register masks, one for each class.
a61af66fc99e Initial load
duke
parents:
diff changeset
154 fprintf(fp_hpp,"\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
155 fprintf(fp_hpp,"// Register masks, one for each register class.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
156 _register->_rclasses.reset();
9078
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
157 for (rc_name = NULL; (rc_name = _register->_rclasses.iter()) != NULL;) {
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
158 const char *prefix = "";
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
159 RegClass *reg_class = _register->getRegClass(rc_name);
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
160 assert(reg_class, "Using an undefined register class");
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
161
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
162 const char* rc_name_to_upper = toUpper(rc_name);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
163
4121
db2e64ca2d5a 7090968: Allow adlc register class to depend on runtime conditions
roland
parents: 4114
diff changeset
164 if (reg_class->_user_defined == NULL) {
9078
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
165 fprintf(fp_hpp, "extern const RegMask _%s%s_mask;\n", prefix, rc_name_to_upper);
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
166 fprintf(fp_hpp, "inline const RegMask &%s%s_mask() { return _%s%s_mask; }\n", prefix, rc_name_to_upper, prefix, rc_name_to_upper);
4121
db2e64ca2d5a 7090968: Allow adlc register class to depend on runtime conditions
roland
parents: 4114
diff changeset
167 } else {
9078
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
168 fprintf(fp_hpp, "inline const RegMask &%s%s_mask() { %s }\n", prefix, rc_name_to_upper, reg_class->_user_defined);
4121
db2e64ca2d5a 7090968: Allow adlc register class to depend on runtime conditions
roland
parents: 4114
diff changeset
169 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
170
9078
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
171 if (reg_class->_stack_or_reg) {
4121
db2e64ca2d5a 7090968: Allow adlc register class to depend on runtime conditions
roland
parents: 4114
diff changeset
172 assert(reg_class->_user_defined == NULL, "no user defined reg class here");
9078
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
173 fprintf(fp_hpp, "extern const RegMask _%sSTACK_OR_%s_mask;\n", prefix, rc_name_to_upper);
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
174 fprintf(fp_hpp, "inline const RegMask &%sSTACK_OR_%s_mask() { return _%sSTACK_OR_%s_mask; }\n", prefix, rc_name_to_upper, prefix, rc_name_to_upper);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
175 }
9078
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
176 delete[] rc_name_to_upper;
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
177
0
a61af66fc99e Initial load
duke
parents:
diff changeset
178 }
a61af66fc99e Initial load
duke
parents:
diff changeset
179 }
a61af66fc99e Initial load
duke
parents:
diff changeset
180 }
a61af66fc99e Initial load
duke
parents:
diff changeset
181
a61af66fc99e Initial load
duke
parents:
diff changeset
182 // Generate an enumeration of user-defined register classes
a61af66fc99e Initial load
duke
parents:
diff changeset
183 // and a list of register masks, one for each class.
a61af66fc99e Initial load
duke
parents:
diff changeset
184 void ArchDesc::build_register_masks(FILE *fp_cpp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
185 const char *rc_name;
a61af66fc99e Initial load
duke
parents:
diff changeset
186
9078
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
187 if (_register) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
188 // Generate a list of register masks, one for each class.
a61af66fc99e Initial load
duke
parents:
diff changeset
189 fprintf(fp_cpp,"\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
190 fprintf(fp_cpp,"// Register masks, one for each register class.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
191 _register->_rclasses.reset();
9078
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
192 for (rc_name = NULL; (rc_name = _register->_rclasses.iter()) != NULL;) {
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
193 const char *prefix = "";
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
194 RegClass *reg_class = _register->getRegClass(rc_name);
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
195 assert(reg_class, "Using an undefined register class");
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
196
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
197 if (reg_class->_user_defined != NULL) {
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
198 continue;
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
199 }
4121
db2e64ca2d5a 7090968: Allow adlc register class to depend on runtime conditions
roland
parents: 4114
diff changeset
200
0
a61af66fc99e Initial load
duke
parents:
diff changeset
201 int len = RegisterForm::RegMask_Size();
9078
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
202 const char* rc_name_to_upper = toUpper(rc_name);
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
203 fprintf(fp_cpp, "const RegMask _%s%s_mask(", prefix, rc_name_to_upper);
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
204
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
205 {
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
206 int i;
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
207 for(i = 0; i < len - 1; i++) {
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
208 fprintf(fp_cpp," 0x%x,", reg_class->regs_in_word(i, false));
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
209 }
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
210 fprintf(fp_cpp," 0x%x );\n", reg_class->regs_in_word(i, false));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
211 }
a61af66fc99e Initial load
duke
parents:
diff changeset
212
9078
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
213 if (reg_class->_stack_or_reg) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
214 int i;
9078
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
215 fprintf(fp_cpp, "const RegMask _%sSTACK_OR_%s_mask(", prefix, rc_name_to_upper);
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
216 for(i = 0; i < len - 1; i++) {
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
217 fprintf(fp_cpp," 0x%x,",reg_class->regs_in_word(i, true));
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
218 }
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
219 fprintf(fp_cpp," 0x%x );\n",reg_class->regs_in_word(i, true));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
220 }
9078
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
221 delete[] rc_name_to_upper;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
222 }
a61af66fc99e Initial load
duke
parents:
diff changeset
223 }
a61af66fc99e Initial load
duke
parents:
diff changeset
224 }
a61af66fc99e Initial load
duke
parents:
diff changeset
225
a61af66fc99e Initial load
duke
parents:
diff changeset
226 // Compute an index for an array in the pipeline_reads_NNN arrays
a61af66fc99e Initial load
duke
parents:
diff changeset
227 static int pipeline_reads_initializer(FILE *fp_cpp, NameList &pipeline_reads, PipeClassForm *pipeclass)
a61af66fc99e Initial load
duke
parents:
diff changeset
228 {
a61af66fc99e Initial load
duke
parents:
diff changeset
229 int templen = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
230 int paramcount = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
231 const char *paramname;
a61af66fc99e Initial load
duke
parents:
diff changeset
232
a61af66fc99e Initial load
duke
parents:
diff changeset
233 if (pipeclass->_parameters.count() == 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
234 return -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
235
a61af66fc99e Initial load
duke
parents:
diff changeset
236 pipeclass->_parameters.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
237 paramname = pipeclass->_parameters.iter();
a61af66fc99e Initial load
duke
parents:
diff changeset
238 const PipeClassOperandForm *pipeopnd =
a61af66fc99e Initial load
duke
parents:
diff changeset
239 (const PipeClassOperandForm *)pipeclass->_localUsage[paramname];
a61af66fc99e Initial load
duke
parents:
diff changeset
240 if (pipeopnd && !pipeopnd->isWrite() && strcmp(pipeopnd->_stage, "Universal"))
a61af66fc99e Initial load
duke
parents:
diff changeset
241 pipeclass->_parameters.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
242
a61af66fc99e Initial load
duke
parents:
diff changeset
243 while ( (paramname = pipeclass->_parameters.iter()) != NULL ) {
603
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 415
diff changeset
244 const PipeClassOperandForm *tmppipeopnd =
0
a61af66fc99e Initial load
duke
parents:
diff changeset
245 (const PipeClassOperandForm *)pipeclass->_localUsage[paramname];
a61af66fc99e Initial load
duke
parents:
diff changeset
246
603
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 415
diff changeset
247 if (tmppipeopnd)
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 415
diff changeset
248 templen += 10 + (int)strlen(tmppipeopnd->_stage);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
249 else
a61af66fc99e Initial load
duke
parents:
diff changeset
250 templen += 19;
a61af66fc99e Initial load
duke
parents:
diff changeset
251
a61af66fc99e Initial load
duke
parents:
diff changeset
252 paramcount++;
a61af66fc99e Initial load
duke
parents:
diff changeset
253 }
a61af66fc99e Initial load
duke
parents:
diff changeset
254
a61af66fc99e Initial load
duke
parents:
diff changeset
255 // See if the count is zero
a61af66fc99e Initial load
duke
parents:
diff changeset
256 if (paramcount == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
257 return -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
258 }
a61af66fc99e Initial load
duke
parents:
diff changeset
259
a61af66fc99e Initial load
duke
parents:
diff changeset
260 char *operand_stages = new char [templen];
a61af66fc99e Initial load
duke
parents:
diff changeset
261 operand_stages[0] = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
262 int i = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
263 templen = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
264
a61af66fc99e Initial load
duke
parents:
diff changeset
265 pipeclass->_parameters.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
266 paramname = pipeclass->_parameters.iter();
a61af66fc99e Initial load
duke
parents:
diff changeset
267 pipeopnd = (const PipeClassOperandForm *)pipeclass->_localUsage[paramname];
a61af66fc99e Initial load
duke
parents:
diff changeset
268 if (pipeopnd && !pipeopnd->isWrite() && strcmp(pipeopnd->_stage, "Universal"))
a61af66fc99e Initial load
duke
parents:
diff changeset
269 pipeclass->_parameters.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
270
a61af66fc99e Initial load
duke
parents:
diff changeset
271 while ( (paramname = pipeclass->_parameters.iter()) != NULL ) {
603
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 415
diff changeset
272 const PipeClassOperandForm *tmppipeopnd =
0
a61af66fc99e Initial load
duke
parents:
diff changeset
273 (const PipeClassOperandForm *)pipeclass->_localUsage[paramname];
a61af66fc99e Initial load
duke
parents:
diff changeset
274 templen += sprintf(&operand_stages[templen], " stage_%s%c\n",
603
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 415
diff changeset
275 tmppipeopnd ? tmppipeopnd->_stage : "undefined",
0
a61af66fc99e Initial load
duke
parents:
diff changeset
276 (++i < paramcount ? ',' : ' ') );
a61af66fc99e Initial load
duke
parents:
diff changeset
277 }
a61af66fc99e Initial load
duke
parents:
diff changeset
278
a61af66fc99e Initial load
duke
parents:
diff changeset
279 // See if the same string is in the table
a61af66fc99e Initial load
duke
parents:
diff changeset
280 int ndx = pipeline_reads.index(operand_stages);
a61af66fc99e Initial load
duke
parents:
diff changeset
281
a61af66fc99e Initial load
duke
parents:
diff changeset
282 // No, add it to the table
a61af66fc99e Initial load
duke
parents:
diff changeset
283 if (ndx < 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
284 pipeline_reads.addName(operand_stages);
a61af66fc99e Initial load
duke
parents:
diff changeset
285 ndx = pipeline_reads.index(operand_stages);
a61af66fc99e Initial load
duke
parents:
diff changeset
286
a61af66fc99e Initial load
duke
parents:
diff changeset
287 fprintf(fp_cpp, "static const enum machPipelineStages pipeline_reads_%03d[%d] = {\n%s};\n\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
288 ndx+1, paramcount, operand_stages);
a61af66fc99e Initial load
duke
parents:
diff changeset
289 }
a61af66fc99e Initial load
duke
parents:
diff changeset
290 else
a61af66fc99e Initial load
duke
parents:
diff changeset
291 delete [] operand_stages;
a61af66fc99e Initial load
duke
parents:
diff changeset
292
a61af66fc99e Initial load
duke
parents:
diff changeset
293 return (ndx);
a61af66fc99e Initial load
duke
parents:
diff changeset
294 }
a61af66fc99e Initial load
duke
parents:
diff changeset
295
a61af66fc99e Initial load
duke
parents:
diff changeset
296 // Compute an index for an array in the pipeline_res_stages_NNN arrays
a61af66fc99e Initial load
duke
parents:
diff changeset
297 static int pipeline_res_stages_initializer(
a61af66fc99e Initial load
duke
parents:
diff changeset
298 FILE *fp_cpp,
a61af66fc99e Initial load
duke
parents:
diff changeset
299 PipelineForm *pipeline,
a61af66fc99e Initial load
duke
parents:
diff changeset
300 NameList &pipeline_res_stages,
a61af66fc99e Initial load
duke
parents:
diff changeset
301 PipeClassForm *pipeclass)
a61af66fc99e Initial load
duke
parents:
diff changeset
302 {
a61af66fc99e Initial load
duke
parents:
diff changeset
303 const PipeClassResourceForm *piperesource;
a61af66fc99e Initial load
duke
parents:
diff changeset
304 int * res_stages = new int [pipeline->_rescount];
a61af66fc99e Initial load
duke
parents:
diff changeset
305 int i;
a61af66fc99e Initial load
duke
parents:
diff changeset
306
a61af66fc99e Initial load
duke
parents:
diff changeset
307 for (i = 0; i < pipeline->_rescount; i++)
a61af66fc99e Initial load
duke
parents:
diff changeset
308 res_stages[i] = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
309
a61af66fc99e Initial load
duke
parents:
diff changeset
310 for (pipeclass->_resUsage.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
311 (piperesource = (const PipeClassResourceForm *)pipeclass->_resUsage.iter()) != NULL; ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
312 int used_mask = pipeline->_resdict[piperesource->_resource]->is_resource()->mask();
a61af66fc99e Initial load
duke
parents:
diff changeset
313 for (i = 0; i < pipeline->_rescount; i++)
a61af66fc99e Initial load
duke
parents:
diff changeset
314 if ((1 << i) & used_mask) {
a61af66fc99e Initial load
duke
parents:
diff changeset
315 int stage = pipeline->_stages.index(piperesource->_stage);
a61af66fc99e Initial load
duke
parents:
diff changeset
316 if (res_stages[i] < stage+1)
a61af66fc99e Initial load
duke
parents:
diff changeset
317 res_stages[i] = stage+1;
a61af66fc99e Initial load
duke
parents:
diff changeset
318 }
a61af66fc99e Initial load
duke
parents:
diff changeset
319 }
a61af66fc99e Initial load
duke
parents:
diff changeset
320
a61af66fc99e Initial load
duke
parents:
diff changeset
321 // Compute the length needed for the resource list
a61af66fc99e Initial load
duke
parents:
diff changeset
322 int commentlen = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
323 int max_stage = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
324 for (i = 0; i < pipeline->_rescount; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
325 if (res_stages[i] == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
326 if (max_stage < 9)
a61af66fc99e Initial load
duke
parents:
diff changeset
327 max_stage = 9;
a61af66fc99e Initial load
duke
parents:
diff changeset
328 }
a61af66fc99e Initial load
duke
parents:
diff changeset
329 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
330 int stagelen = (int)strlen(pipeline->_stages.name(res_stages[i]-1));
a61af66fc99e Initial load
duke
parents:
diff changeset
331 if (max_stage < stagelen)
a61af66fc99e Initial load
duke
parents:
diff changeset
332 max_stage = stagelen;
a61af66fc99e Initial load
duke
parents:
diff changeset
333 }
a61af66fc99e Initial load
duke
parents:
diff changeset
334
a61af66fc99e Initial load
duke
parents:
diff changeset
335 commentlen += (int)strlen(pipeline->_reslist.name(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
336 }
a61af66fc99e Initial load
duke
parents:
diff changeset
337
a61af66fc99e Initial load
duke
parents:
diff changeset
338 int templen = 1 + commentlen + pipeline->_rescount * (max_stage + 14);
a61af66fc99e Initial load
duke
parents:
diff changeset
339
a61af66fc99e Initial load
duke
parents:
diff changeset
340 // Allocate space for the resource list
a61af66fc99e Initial load
duke
parents:
diff changeset
341 char * resource_stages = new char [templen];
a61af66fc99e Initial load
duke
parents:
diff changeset
342
a61af66fc99e Initial load
duke
parents:
diff changeset
343 templen = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
344 for (i = 0; i < pipeline->_rescount; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
345 const char * const resname =
a61af66fc99e Initial load
duke
parents:
diff changeset
346 res_stages[i] == 0 ? "undefined" : pipeline->_stages.name(res_stages[i]-1);
a61af66fc99e Initial load
duke
parents:
diff changeset
347
a61af66fc99e Initial load
duke
parents:
diff changeset
348 templen += sprintf(&resource_stages[templen], " stage_%s%-*s // %s\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
349 resname, max_stage - (int)strlen(resname) + 1,
a61af66fc99e Initial load
duke
parents:
diff changeset
350 (i < pipeline->_rescount-1) ? "," : "",
a61af66fc99e Initial load
duke
parents:
diff changeset
351 pipeline->_reslist.name(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
352 }
a61af66fc99e Initial load
duke
parents:
diff changeset
353
a61af66fc99e Initial load
duke
parents:
diff changeset
354 // See if the same string is in the table
a61af66fc99e Initial load
duke
parents:
diff changeset
355 int ndx = pipeline_res_stages.index(resource_stages);
a61af66fc99e Initial load
duke
parents:
diff changeset
356
a61af66fc99e Initial load
duke
parents:
diff changeset
357 // No, add it to the table
a61af66fc99e Initial load
duke
parents:
diff changeset
358 if (ndx < 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
359 pipeline_res_stages.addName(resource_stages);
a61af66fc99e Initial load
duke
parents:
diff changeset
360 ndx = pipeline_res_stages.index(resource_stages);
a61af66fc99e Initial load
duke
parents:
diff changeset
361
a61af66fc99e Initial load
duke
parents:
diff changeset
362 fprintf(fp_cpp, "static const enum machPipelineStages pipeline_res_stages_%03d[%d] = {\n%s};\n\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
363 ndx+1, pipeline->_rescount, resource_stages);
a61af66fc99e Initial load
duke
parents:
diff changeset
364 }
a61af66fc99e Initial load
duke
parents:
diff changeset
365 else
a61af66fc99e Initial load
duke
parents:
diff changeset
366 delete [] resource_stages;
a61af66fc99e Initial load
duke
parents:
diff changeset
367
a61af66fc99e Initial load
duke
parents:
diff changeset
368 delete [] res_stages;
a61af66fc99e Initial load
duke
parents:
diff changeset
369
a61af66fc99e Initial load
duke
parents:
diff changeset
370 return (ndx);
a61af66fc99e Initial load
duke
parents:
diff changeset
371 }
a61af66fc99e Initial load
duke
parents:
diff changeset
372
a61af66fc99e Initial load
duke
parents:
diff changeset
373 // Compute an index for an array in the pipeline_res_cycles_NNN arrays
a61af66fc99e Initial load
duke
parents:
diff changeset
374 static int pipeline_res_cycles_initializer(
a61af66fc99e Initial load
duke
parents:
diff changeset
375 FILE *fp_cpp,
a61af66fc99e Initial load
duke
parents:
diff changeset
376 PipelineForm *pipeline,
a61af66fc99e Initial load
duke
parents:
diff changeset
377 NameList &pipeline_res_cycles,
a61af66fc99e Initial load
duke
parents:
diff changeset
378 PipeClassForm *pipeclass)
a61af66fc99e Initial load
duke
parents:
diff changeset
379 {
a61af66fc99e Initial load
duke
parents:
diff changeset
380 const PipeClassResourceForm *piperesource;
a61af66fc99e Initial load
duke
parents:
diff changeset
381 int * res_cycles = new int [pipeline->_rescount];
a61af66fc99e Initial load
duke
parents:
diff changeset
382 int i;
a61af66fc99e Initial load
duke
parents:
diff changeset
383
a61af66fc99e Initial load
duke
parents:
diff changeset
384 for (i = 0; i < pipeline->_rescount; i++)
a61af66fc99e Initial load
duke
parents:
diff changeset
385 res_cycles[i] = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
386
a61af66fc99e Initial load
duke
parents:
diff changeset
387 for (pipeclass->_resUsage.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
388 (piperesource = (const PipeClassResourceForm *)pipeclass->_resUsage.iter()) != NULL; ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
389 int used_mask = pipeline->_resdict[piperesource->_resource]->is_resource()->mask();
a61af66fc99e Initial load
duke
parents:
diff changeset
390 for (i = 0; i < pipeline->_rescount; i++)
a61af66fc99e Initial load
duke
parents:
diff changeset
391 if ((1 << i) & used_mask) {
a61af66fc99e Initial load
duke
parents:
diff changeset
392 int cycles = piperesource->_cycles;
a61af66fc99e Initial load
duke
parents:
diff changeset
393 if (res_cycles[i] < cycles)
a61af66fc99e Initial load
duke
parents:
diff changeset
394 res_cycles[i] = cycles;
a61af66fc99e Initial load
duke
parents:
diff changeset
395 }
a61af66fc99e Initial load
duke
parents:
diff changeset
396 }
a61af66fc99e Initial load
duke
parents:
diff changeset
397
a61af66fc99e Initial load
duke
parents:
diff changeset
398 // Pre-compute the string length
a61af66fc99e Initial load
duke
parents:
diff changeset
399 int templen;
a61af66fc99e Initial load
duke
parents:
diff changeset
400 int cyclelen = 0, commentlen = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
401 int max_cycles = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
402 char temp[32];
a61af66fc99e Initial load
duke
parents:
diff changeset
403
a61af66fc99e Initial load
duke
parents:
diff changeset
404 for (i = 0; i < pipeline->_rescount; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
405 if (max_cycles < res_cycles[i])
a61af66fc99e Initial load
duke
parents:
diff changeset
406 max_cycles = res_cycles[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
407 templen = sprintf(temp, "%d", res_cycles[i]);
a61af66fc99e Initial load
duke
parents:
diff changeset
408 if (cyclelen < templen)
a61af66fc99e Initial load
duke
parents:
diff changeset
409 cyclelen = templen;
a61af66fc99e Initial load
duke
parents:
diff changeset
410 commentlen += (int)strlen(pipeline->_reslist.name(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
411 }
a61af66fc99e Initial load
duke
parents:
diff changeset
412
a61af66fc99e Initial load
duke
parents:
diff changeset
413 templen = 1 + commentlen + (cyclelen + 8) * pipeline->_rescount;
a61af66fc99e Initial load
duke
parents:
diff changeset
414
a61af66fc99e Initial load
duke
parents:
diff changeset
415 // Allocate space for the resource list
a61af66fc99e Initial load
duke
parents:
diff changeset
416 char * resource_cycles = new char [templen];
a61af66fc99e Initial load
duke
parents:
diff changeset
417
a61af66fc99e Initial load
duke
parents:
diff changeset
418 templen = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
419
a61af66fc99e Initial load
duke
parents:
diff changeset
420 for (i = 0; i < pipeline->_rescount; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
421 templen += sprintf(&resource_cycles[templen], " %*d%c // %s\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
422 cyclelen, res_cycles[i], (i < pipeline->_rescount-1) ? ',' : ' ', pipeline->_reslist.name(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
423 }
a61af66fc99e Initial load
duke
parents:
diff changeset
424
a61af66fc99e Initial load
duke
parents:
diff changeset
425 // See if the same string is in the table
a61af66fc99e Initial load
duke
parents:
diff changeset
426 int ndx = pipeline_res_cycles.index(resource_cycles);
a61af66fc99e Initial load
duke
parents:
diff changeset
427
a61af66fc99e Initial load
duke
parents:
diff changeset
428 // No, add it to the table
a61af66fc99e Initial load
duke
parents:
diff changeset
429 if (ndx < 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
430 pipeline_res_cycles.addName(resource_cycles);
a61af66fc99e Initial load
duke
parents:
diff changeset
431 ndx = pipeline_res_cycles.index(resource_cycles);
a61af66fc99e Initial load
duke
parents:
diff changeset
432
a61af66fc99e Initial load
duke
parents:
diff changeset
433 fprintf(fp_cpp, "static const uint pipeline_res_cycles_%03d[%d] = {\n%s};\n\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
434 ndx+1, pipeline->_rescount, resource_cycles);
a61af66fc99e Initial load
duke
parents:
diff changeset
435 }
a61af66fc99e Initial load
duke
parents:
diff changeset
436 else
a61af66fc99e Initial load
duke
parents:
diff changeset
437 delete [] resource_cycles;
a61af66fc99e Initial load
duke
parents:
diff changeset
438
a61af66fc99e Initial load
duke
parents:
diff changeset
439 delete [] res_cycles;
a61af66fc99e Initial load
duke
parents:
diff changeset
440
a61af66fc99e Initial load
duke
parents:
diff changeset
441 return (ndx);
a61af66fc99e Initial load
duke
parents:
diff changeset
442 }
a61af66fc99e Initial load
duke
parents:
diff changeset
443
a61af66fc99e Initial load
duke
parents:
diff changeset
444 //typedef unsigned long long uint64_t;
a61af66fc99e Initial load
duke
parents:
diff changeset
445
a61af66fc99e Initial load
duke
parents:
diff changeset
446 // Compute an index for an array in the pipeline_res_mask_NNN arrays
a61af66fc99e Initial load
duke
parents:
diff changeset
447 static int pipeline_res_mask_initializer(
a61af66fc99e Initial load
duke
parents:
diff changeset
448 FILE *fp_cpp,
a61af66fc99e Initial load
duke
parents:
diff changeset
449 PipelineForm *pipeline,
a61af66fc99e Initial load
duke
parents:
diff changeset
450 NameList &pipeline_res_mask,
a61af66fc99e Initial load
duke
parents:
diff changeset
451 NameList &pipeline_res_args,
a61af66fc99e Initial load
duke
parents:
diff changeset
452 PipeClassForm *pipeclass)
a61af66fc99e Initial load
duke
parents:
diff changeset
453 {
a61af66fc99e Initial load
duke
parents:
diff changeset
454 const PipeClassResourceForm *piperesource;
a61af66fc99e Initial load
duke
parents:
diff changeset
455 const uint rescount = pipeline->_rescount;
a61af66fc99e Initial load
duke
parents:
diff changeset
456 const uint maxcycleused = pipeline->_maxcycleused;
a61af66fc99e Initial load
duke
parents:
diff changeset
457 const uint cyclemasksize = (maxcycleused + 31) >> 5;
a61af66fc99e Initial load
duke
parents:
diff changeset
458
a61af66fc99e Initial load
duke
parents:
diff changeset
459 int i, j;
a61af66fc99e Initial load
duke
parents:
diff changeset
460 int element_count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
461 uint *res_mask = new uint [cyclemasksize];
a61af66fc99e Initial load
duke
parents:
diff changeset
462 uint resources_used = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
463 uint resources_used_exclusively = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
464
a61af66fc99e Initial load
duke
parents:
diff changeset
465 for (pipeclass->_resUsage.reset();
10389
f15fe46d8c00 8015266: fix some -Wsign-compare warnings in adlc
twisti
parents: 9078
diff changeset
466 (piperesource = (const PipeClassResourceForm*)pipeclass->_resUsage.iter()) != NULL; ) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
467 element_count++;
10389
f15fe46d8c00 8015266: fix some -Wsign-compare warnings in adlc
twisti
parents: 9078
diff changeset
468 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
469
a61af66fc99e Initial load
duke
parents:
diff changeset
470 // Pre-compute the string length
a61af66fc99e Initial load
duke
parents:
diff changeset
471 int templen;
a61af66fc99e Initial load
duke
parents:
diff changeset
472 int commentlen = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
473 int max_cycles = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
474
a61af66fc99e Initial load
duke
parents:
diff changeset
475 int cyclelen = ((maxcycleused + 3) >> 2);
a61af66fc99e Initial load
duke
parents:
diff changeset
476 int masklen = (rescount + 3) >> 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
477
a61af66fc99e Initial load
duke
parents:
diff changeset
478 int cycledigit = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
479 for (i = maxcycleused; i > 0; i /= 10)
a61af66fc99e Initial load
duke
parents:
diff changeset
480 cycledigit++;
a61af66fc99e Initial load
duke
parents:
diff changeset
481
a61af66fc99e Initial load
duke
parents:
diff changeset
482 int maskdigit = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
483 for (i = rescount; i > 0; i /= 10)
a61af66fc99e Initial load
duke
parents:
diff changeset
484 maskdigit++;
a61af66fc99e Initial load
duke
parents:
diff changeset
485
10389
f15fe46d8c00 8015266: fix some -Wsign-compare warnings in adlc
twisti
parents: 9078
diff changeset
486 static const char* pipeline_use_cycle_mask = "Pipeline_Use_Cycle_Mask";
f15fe46d8c00 8015266: fix some -Wsign-compare warnings in adlc
twisti
parents: 9078
diff changeset
487 static const char* pipeline_use_element = "Pipeline_Use_Element";
0
a61af66fc99e Initial load
duke
parents:
diff changeset
488
a61af66fc99e Initial load
duke
parents:
diff changeset
489 templen = 1 +
a61af66fc99e Initial load
duke
parents:
diff changeset
490 (int)(strlen(pipeline_use_cycle_mask) + (int)strlen(pipeline_use_element) +
a61af66fc99e Initial load
duke
parents:
diff changeset
491 (cyclemasksize * 12) + masklen + (cycledigit * 2) + 30) * element_count;
a61af66fc99e Initial load
duke
parents:
diff changeset
492
a61af66fc99e Initial load
duke
parents:
diff changeset
493 // Allocate space for the resource list
a61af66fc99e Initial load
duke
parents:
diff changeset
494 char * resource_mask = new char [templen];
a61af66fc99e Initial load
duke
parents:
diff changeset
495 char * last_comma = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
496
a61af66fc99e Initial load
duke
parents:
diff changeset
497 templen = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
498
a61af66fc99e Initial load
duke
parents:
diff changeset
499 for (pipeclass->_resUsage.reset();
10389
f15fe46d8c00 8015266: fix some -Wsign-compare warnings in adlc
twisti
parents: 9078
diff changeset
500 (piperesource = (const PipeClassResourceForm*)pipeclass->_resUsage.iter()) != NULL; ) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
501 int used_mask = pipeline->_resdict[piperesource->_resource]->is_resource()->mask();
a61af66fc99e Initial load
duke
parents:
diff changeset
502
10389
f15fe46d8c00 8015266: fix some -Wsign-compare warnings in adlc
twisti
parents: 9078
diff changeset
503 if (!used_mask) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
504 fprintf(stderr, "*** used_mask is 0 ***\n");
10389
f15fe46d8c00 8015266: fix some -Wsign-compare warnings in adlc
twisti
parents: 9078
diff changeset
505 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
506
a61af66fc99e Initial load
duke
parents:
diff changeset
507 resources_used |= used_mask;
a61af66fc99e Initial load
duke
parents:
diff changeset
508
a61af66fc99e Initial load
duke
parents:
diff changeset
509 uint lb, ub;
a61af66fc99e Initial load
duke
parents:
diff changeset
510
a61af66fc99e Initial load
duke
parents:
diff changeset
511 for (lb = 0; (used_mask & (1 << lb)) == 0; lb++);
a61af66fc99e Initial load
duke
parents:
diff changeset
512 for (ub = 31; (used_mask & (1 << ub)) == 0; ub--);
a61af66fc99e Initial load
duke
parents:
diff changeset
513
10389
f15fe46d8c00 8015266: fix some -Wsign-compare warnings in adlc
twisti
parents: 9078
diff changeset
514 if (lb == ub) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
515 resources_used_exclusively |= used_mask;
10389
f15fe46d8c00 8015266: fix some -Wsign-compare warnings in adlc
twisti
parents: 9078
diff changeset
516 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
517
a61af66fc99e Initial load
duke
parents:
diff changeset
518 int formatlen =
a61af66fc99e Initial load
duke
parents:
diff changeset
519 sprintf(&resource_mask[templen], " %s(0x%0*x, %*d, %*d, %s %s(",
a61af66fc99e Initial load
duke
parents:
diff changeset
520 pipeline_use_element,
a61af66fc99e Initial load
duke
parents:
diff changeset
521 masklen, used_mask,
a61af66fc99e Initial load
duke
parents:
diff changeset
522 cycledigit, lb, cycledigit, ub,
a61af66fc99e Initial load
duke
parents:
diff changeset
523 ((used_mask & (used_mask-1)) != 0) ? "true, " : "false,",
a61af66fc99e Initial load
duke
parents:
diff changeset
524 pipeline_use_cycle_mask);
a61af66fc99e Initial load
duke
parents:
diff changeset
525
a61af66fc99e Initial load
duke
parents:
diff changeset
526 templen += formatlen;
a61af66fc99e Initial load
duke
parents:
diff changeset
527
a61af66fc99e Initial load
duke
parents:
diff changeset
528 memset(res_mask, 0, cyclemasksize * sizeof(uint));
a61af66fc99e Initial load
duke
parents:
diff changeset
529
a61af66fc99e Initial load
duke
parents:
diff changeset
530 int cycles = piperesource->_cycles;
a61af66fc99e Initial load
duke
parents:
diff changeset
531 uint stage = pipeline->_stages.index(piperesource->_stage);
10389
f15fe46d8c00 8015266: fix some -Wsign-compare warnings in adlc
twisti
parents: 9078
diff changeset
532 if ((uint)NameList::Not_in_list == stage) {
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
533 fprintf(stderr,
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
534 "pipeline_res_mask_initializer: "
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
535 "semantic error: "
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
536 "pipeline stage undeclared: %s\n",
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
537 piperesource->_stage);
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
538 exit(1);
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
539 }
10389
f15fe46d8c00 8015266: fix some -Wsign-compare warnings in adlc
twisti
parents: 9078
diff changeset
540 uint upper_limit = stage + cycles - 1;
f15fe46d8c00 8015266: fix some -Wsign-compare warnings in adlc
twisti
parents: 9078
diff changeset
541 uint lower_limit = stage - 1;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
542 uint upper_idx = upper_limit >> 5;
a61af66fc99e Initial load
duke
parents:
diff changeset
543 uint lower_idx = lower_limit >> 5;
a61af66fc99e Initial load
duke
parents:
diff changeset
544 uint upper_position = upper_limit & 0x1f;
a61af66fc99e Initial load
duke
parents:
diff changeset
545 uint lower_position = lower_limit & 0x1f;
a61af66fc99e Initial load
duke
parents:
diff changeset
546
a61af66fc99e Initial load
duke
parents:
diff changeset
547 uint mask = (((uint)1) << upper_position) - 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
548
10389
f15fe46d8c00 8015266: fix some -Wsign-compare warnings in adlc
twisti
parents: 9078
diff changeset
549 while (upper_idx > lower_idx) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
550 res_mask[upper_idx--] |= mask;
a61af66fc99e Initial load
duke
parents:
diff changeset
551 mask = (uint)-1;
a61af66fc99e Initial load
duke
parents:
diff changeset
552 }
a61af66fc99e Initial load
duke
parents:
diff changeset
553
a61af66fc99e Initial load
duke
parents:
diff changeset
554 mask -= (((uint)1) << lower_position) - 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
555 res_mask[upper_idx] |= mask;
a61af66fc99e Initial load
duke
parents:
diff changeset
556
a61af66fc99e Initial load
duke
parents:
diff changeset
557 for (j = cyclemasksize-1; j >= 0; j--) {
a61af66fc99e Initial load
duke
parents:
diff changeset
558 formatlen =
a61af66fc99e Initial load
duke
parents:
diff changeset
559 sprintf(&resource_mask[templen], "0x%08x%s", res_mask[j], j > 0 ? ", " : "");
a61af66fc99e Initial load
duke
parents:
diff changeset
560 templen += formatlen;
a61af66fc99e Initial load
duke
parents:
diff changeset
561 }
a61af66fc99e Initial load
duke
parents:
diff changeset
562
a61af66fc99e Initial load
duke
parents:
diff changeset
563 resource_mask[templen++] = ')';
a61af66fc99e Initial load
duke
parents:
diff changeset
564 resource_mask[templen++] = ')';
a61af66fc99e Initial load
duke
parents:
diff changeset
565 last_comma = &resource_mask[templen];
a61af66fc99e Initial load
duke
parents:
diff changeset
566 resource_mask[templen++] = ',';
a61af66fc99e Initial load
duke
parents:
diff changeset
567 resource_mask[templen++] = '\n';
a61af66fc99e Initial load
duke
parents:
diff changeset
568 }
a61af66fc99e Initial load
duke
parents:
diff changeset
569
a61af66fc99e Initial load
duke
parents:
diff changeset
570 resource_mask[templen] = 0;
10389
f15fe46d8c00 8015266: fix some -Wsign-compare warnings in adlc
twisti
parents: 9078
diff changeset
571 if (last_comma) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
572 last_comma[0] = ' ';
10389
f15fe46d8c00 8015266: fix some -Wsign-compare warnings in adlc
twisti
parents: 9078
diff changeset
573 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
574
a61af66fc99e Initial load
duke
parents:
diff changeset
575 // See if the same string is in the table
a61af66fc99e Initial load
duke
parents:
diff changeset
576 int ndx = pipeline_res_mask.index(resource_mask);
a61af66fc99e Initial load
duke
parents:
diff changeset
577
a61af66fc99e Initial load
duke
parents:
diff changeset
578 // No, add it to the table
a61af66fc99e Initial load
duke
parents:
diff changeset
579 if (ndx < 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
580 pipeline_res_mask.addName(resource_mask);
a61af66fc99e Initial load
duke
parents:
diff changeset
581 ndx = pipeline_res_mask.index(resource_mask);
a61af66fc99e Initial load
duke
parents:
diff changeset
582
a61af66fc99e Initial load
duke
parents:
diff changeset
583 if (strlen(resource_mask) > 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
584 fprintf(fp_cpp, "static const Pipeline_Use_Element pipeline_res_mask_%03d[%d] = {\n%s};\n\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
585 ndx+1, element_count, resource_mask);
a61af66fc99e Initial load
duke
parents:
diff changeset
586
10389
f15fe46d8c00 8015266: fix some -Wsign-compare warnings in adlc
twisti
parents: 9078
diff changeset
587 char* args = new char [9 + 2*masklen + maskdigit];
0
a61af66fc99e Initial load
duke
parents:
diff changeset
588
a61af66fc99e Initial load
duke
parents:
diff changeset
589 sprintf(args, "0x%0*x, 0x%0*x, %*d",
a61af66fc99e Initial load
duke
parents:
diff changeset
590 masklen, resources_used,
a61af66fc99e Initial load
duke
parents:
diff changeset
591 masklen, resources_used_exclusively,
a61af66fc99e Initial load
duke
parents:
diff changeset
592 maskdigit, element_count);
a61af66fc99e Initial load
duke
parents:
diff changeset
593
a61af66fc99e Initial load
duke
parents:
diff changeset
594 pipeline_res_args.addName(args);
a61af66fc99e Initial load
duke
parents:
diff changeset
595 }
10389
f15fe46d8c00 8015266: fix some -Wsign-compare warnings in adlc
twisti
parents: 9078
diff changeset
596 else {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
597 delete [] resource_mask;
10389
f15fe46d8c00 8015266: fix some -Wsign-compare warnings in adlc
twisti
parents: 9078
diff changeset
598 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
599
a61af66fc99e Initial load
duke
parents:
diff changeset
600 delete [] res_mask;
a61af66fc99e Initial load
duke
parents:
diff changeset
601 //delete [] res_masks;
a61af66fc99e Initial load
duke
parents:
diff changeset
602
a61af66fc99e Initial load
duke
parents:
diff changeset
603 return (ndx);
a61af66fc99e Initial load
duke
parents:
diff changeset
604 }
a61af66fc99e Initial load
duke
parents:
diff changeset
605
a61af66fc99e Initial load
duke
parents:
diff changeset
606 void ArchDesc::build_pipe_classes(FILE *fp_cpp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
607 const char *classname;
a61af66fc99e Initial load
duke
parents:
diff changeset
608 const char *resourcename;
a61af66fc99e Initial load
duke
parents:
diff changeset
609 int resourcenamelen = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
610 NameList pipeline_reads;
a61af66fc99e Initial load
duke
parents:
diff changeset
611 NameList pipeline_res_stages;
a61af66fc99e Initial load
duke
parents:
diff changeset
612 NameList pipeline_res_cycles;
a61af66fc99e Initial load
duke
parents:
diff changeset
613 NameList pipeline_res_masks;
a61af66fc99e Initial load
duke
parents:
diff changeset
614 NameList pipeline_res_args;
a61af66fc99e Initial load
duke
parents:
diff changeset
615 const int default_latency = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
616 const int non_operand_latency = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
617 const int node_latency = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
618
a61af66fc99e Initial load
duke
parents:
diff changeset
619 if (!_pipeline) {
a61af66fc99e Initial load
duke
parents:
diff changeset
620 fprintf(fp_cpp, "uint Node::latency(uint i) const {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
621 fprintf(fp_cpp, " // assert(false, \"pipeline functionality is not defined\");\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
622 fprintf(fp_cpp, " return %d;\n", non_operand_latency);
a61af66fc99e Initial load
duke
parents:
diff changeset
623 fprintf(fp_cpp, "}\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
624 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
625 }
a61af66fc99e Initial load
duke
parents:
diff changeset
626
a61af66fc99e Initial load
duke
parents:
diff changeset
627 fprintf(fp_cpp, "\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
628 fprintf(fp_cpp, "//------------------Pipeline Methods-----------------------------------------\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
629 fprintf(fp_cpp, "#ifndef PRODUCT\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
630 fprintf(fp_cpp, "const char * Pipeline::stageName(uint s) {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
631 fprintf(fp_cpp, " static const char * const _stage_names[] = {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
632 fprintf(fp_cpp, " \"undefined\"");
a61af66fc99e Initial load
duke
parents:
diff changeset
633
a61af66fc99e Initial load
duke
parents:
diff changeset
634 for (int s = 0; s < _pipeline->_stagecnt; s++)
a61af66fc99e Initial load
duke
parents:
diff changeset
635 fprintf(fp_cpp, ", \"%s\"", _pipeline->_stages.name(s));
a61af66fc99e Initial load
duke
parents:
diff changeset
636
a61af66fc99e Initial load
duke
parents:
diff changeset
637 fprintf(fp_cpp, "\n };\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
638 fprintf(fp_cpp, " return (s <= %d ? _stage_names[s] : \"???\");\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
639 _pipeline->_stagecnt);
a61af66fc99e Initial load
duke
parents:
diff changeset
640 fprintf(fp_cpp, "}\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
641 fprintf(fp_cpp, "#endif\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
642
a61af66fc99e Initial load
duke
parents:
diff changeset
643 fprintf(fp_cpp, "uint Pipeline::functional_unit_latency(uint start, const Pipeline *pred) const {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
644 fprintf(fp_cpp, " // See if the functional units overlap\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
645 #if 0
a61af66fc99e Initial load
duke
parents:
diff changeset
646 fprintf(fp_cpp, "\n#ifndef PRODUCT\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
647 fprintf(fp_cpp, " if (TraceOptoOutput) {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
648 fprintf(fp_cpp, " tty->print(\"# functional_unit_latency: start == %%d, this->exclusively == 0x%%03x, pred->exclusively == 0x%%03x\\n\", start, resourcesUsedExclusively(), pred->resourcesUsedExclusively());\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
649 fprintf(fp_cpp, " }\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
650 fprintf(fp_cpp, "#endif\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
651 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
652 fprintf(fp_cpp, " uint mask = resourcesUsedExclusively() & pred->resourcesUsedExclusively();\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
653 fprintf(fp_cpp, " if (mask == 0)\n return (start);\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
654 #if 0
a61af66fc99e Initial load
duke
parents:
diff changeset
655 fprintf(fp_cpp, "\n#ifndef PRODUCT\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
656 fprintf(fp_cpp, " if (TraceOptoOutput) {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
657 fprintf(fp_cpp, " tty->print(\"# functional_unit_latency: mask == 0x%%x\\n\", mask);\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
658 fprintf(fp_cpp, " }\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
659 fprintf(fp_cpp, "#endif\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
660 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
661 fprintf(fp_cpp, " for (uint i = 0; i < pred->resourceUseCount(); i++) {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
662 fprintf(fp_cpp, " const Pipeline_Use_Element *predUse = pred->resourceUseElement(i);\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
663 fprintf(fp_cpp, " if (predUse->multiple())\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
664 fprintf(fp_cpp, " continue;\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
665 fprintf(fp_cpp, " for (uint j = 0; j < resourceUseCount(); j++) {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
666 fprintf(fp_cpp, " const Pipeline_Use_Element *currUse = resourceUseElement(j);\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
667 fprintf(fp_cpp, " if (currUse->multiple())\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
668 fprintf(fp_cpp, " continue;\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
669 fprintf(fp_cpp, " if (predUse->used() & currUse->used()) {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
670 fprintf(fp_cpp, " Pipeline_Use_Cycle_Mask x = predUse->mask();\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
671 fprintf(fp_cpp, " Pipeline_Use_Cycle_Mask y = currUse->mask();\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
672 fprintf(fp_cpp, " for ( y <<= start; x.overlaps(y); start++ )\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
673 fprintf(fp_cpp, " y <<= 1;\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
674 fprintf(fp_cpp, " }\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
675 fprintf(fp_cpp, " }\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
676 fprintf(fp_cpp, " }\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
677 fprintf(fp_cpp, " // There is the potential for overlap\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
678 fprintf(fp_cpp, " return (start);\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
679 fprintf(fp_cpp, "}\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
680 fprintf(fp_cpp, "// The following two routines assume that the root Pipeline_Use entity\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
681 fprintf(fp_cpp, "// consists of exactly 1 element for each functional unit\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
682 fprintf(fp_cpp, "// start is relative to the current cycle; used for latency-based info\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
683 fprintf(fp_cpp, "uint Pipeline_Use::full_latency(uint delay, const Pipeline_Use &pred) const {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
684 fprintf(fp_cpp, " for (uint i = 0; i < pred._count; i++) {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
685 fprintf(fp_cpp, " const Pipeline_Use_Element *predUse = pred.element(i);\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
686 fprintf(fp_cpp, " if (predUse->_multiple) {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
687 fprintf(fp_cpp, " uint min_delay = %d;\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
688 _pipeline->_maxcycleused+1);
a61af66fc99e Initial load
duke
parents:
diff changeset
689 fprintf(fp_cpp, " // Multiple possible functional units, choose first unused one\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
690 fprintf(fp_cpp, " for (uint j = predUse->_lb; j <= predUse->_ub; j++) {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
691 fprintf(fp_cpp, " const Pipeline_Use_Element *currUse = element(j);\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
692 fprintf(fp_cpp, " uint curr_delay = delay;\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
693 fprintf(fp_cpp, " if (predUse->_used & currUse->_used) {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
694 fprintf(fp_cpp, " Pipeline_Use_Cycle_Mask x = predUse->_mask;\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
695 fprintf(fp_cpp, " Pipeline_Use_Cycle_Mask y = currUse->_mask;\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
696 fprintf(fp_cpp, " for ( y <<= curr_delay; x.overlaps(y); curr_delay++ )\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
697 fprintf(fp_cpp, " y <<= 1;\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
698 fprintf(fp_cpp, " }\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
699 fprintf(fp_cpp, " if (min_delay > curr_delay)\n min_delay = curr_delay;\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
700 fprintf(fp_cpp, " }\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
701 fprintf(fp_cpp, " if (delay < min_delay)\n delay = min_delay;\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
702 fprintf(fp_cpp, " }\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
703 fprintf(fp_cpp, " else {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
704 fprintf(fp_cpp, " for (uint j = predUse->_lb; j <= predUse->_ub; j++) {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
705 fprintf(fp_cpp, " const Pipeline_Use_Element *currUse = element(j);\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
706 fprintf(fp_cpp, " if (predUse->_used & currUse->_used) {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
707 fprintf(fp_cpp, " Pipeline_Use_Cycle_Mask x = predUse->_mask;\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
708 fprintf(fp_cpp, " Pipeline_Use_Cycle_Mask y = currUse->_mask;\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
709 fprintf(fp_cpp, " for ( y <<= delay; x.overlaps(y); delay++ )\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
710 fprintf(fp_cpp, " y <<= 1;\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
711 fprintf(fp_cpp, " }\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
712 fprintf(fp_cpp, " }\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
713 fprintf(fp_cpp, " }\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
714 fprintf(fp_cpp, " }\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
715 fprintf(fp_cpp, " return (delay);\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
716 fprintf(fp_cpp, "}\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
717 fprintf(fp_cpp, "void Pipeline_Use::add_usage(const Pipeline_Use &pred) {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
718 fprintf(fp_cpp, " for (uint i = 0; i < pred._count; i++) {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
719 fprintf(fp_cpp, " const Pipeline_Use_Element *predUse = pred.element(i);\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
720 fprintf(fp_cpp, " if (predUse->_multiple) {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
721 fprintf(fp_cpp, " // Multiple possible functional units, choose first unused one\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
722 fprintf(fp_cpp, " for (uint j = predUse->_lb; j <= predUse->_ub; j++) {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
723 fprintf(fp_cpp, " Pipeline_Use_Element *currUse = element(j);\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
724 fprintf(fp_cpp, " if ( !predUse->_mask.overlaps(currUse->_mask) ) {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
725 fprintf(fp_cpp, " currUse->_used |= (1 << j);\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
726 fprintf(fp_cpp, " _resources_used |= (1 << j);\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
727 fprintf(fp_cpp, " currUse->_mask.Or(predUse->_mask);\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
728 fprintf(fp_cpp, " break;\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
729 fprintf(fp_cpp, " }\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
730 fprintf(fp_cpp, " }\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
731 fprintf(fp_cpp, " }\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
732 fprintf(fp_cpp, " else {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
733 fprintf(fp_cpp, " for (uint j = predUse->_lb; j <= predUse->_ub; j++) {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
734 fprintf(fp_cpp, " Pipeline_Use_Element *currUse = element(j);\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
735 fprintf(fp_cpp, " currUse->_used |= (1 << j);\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
736 fprintf(fp_cpp, " _resources_used |= (1 << j);\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
737 fprintf(fp_cpp, " currUse->_mask.Or(predUse->_mask);\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
738 fprintf(fp_cpp, " }\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
739 fprintf(fp_cpp, " }\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
740 fprintf(fp_cpp, " }\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
741 fprintf(fp_cpp, "}\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
742
a61af66fc99e Initial load
duke
parents:
diff changeset
743 fprintf(fp_cpp, "uint Pipeline::operand_latency(uint opnd, const Pipeline *pred) const {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
744 fprintf(fp_cpp, " int const default_latency = 1;\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
745 fprintf(fp_cpp, "\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
746 #if 0
a61af66fc99e Initial load
duke
parents:
diff changeset
747 fprintf(fp_cpp, "#ifndef PRODUCT\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
748 fprintf(fp_cpp, " if (TraceOptoOutput) {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
749 fprintf(fp_cpp, " tty->print(\"# operand_latency(%%d), _read_stage_count = %%d\\n\", opnd, _read_stage_count);\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
750 fprintf(fp_cpp, " }\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
751 fprintf(fp_cpp, "#endif\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
752 #endif
1489
cff162798819 6888953: some calls to function-like macros are missing semicolons
jcoomes
parents: 1203
diff changeset
753 fprintf(fp_cpp, " assert(this, \"NULL pipeline info\");\n");
cff162798819 6888953: some calls to function-like macros are missing semicolons
jcoomes
parents: 1203
diff changeset
754 fprintf(fp_cpp, " assert(pred, \"NULL predecessor pipline info\");\n\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
755 fprintf(fp_cpp, " if (pred->hasFixedLatency())\n return (pred->fixedLatency());\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
756 fprintf(fp_cpp, " // If this is not an operand, then assume a dependence with 0 latency\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
757 fprintf(fp_cpp, " if (opnd > _read_stage_count)\n return (0);\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
758 fprintf(fp_cpp, " uint writeStage = pred->_write_stage;\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
759 fprintf(fp_cpp, " uint readStage = _read_stages[opnd-1];\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
760 #if 0
a61af66fc99e Initial load
duke
parents:
diff changeset
761 fprintf(fp_cpp, "\n#ifndef PRODUCT\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
762 fprintf(fp_cpp, " if (TraceOptoOutput) {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
763 fprintf(fp_cpp, " tty->print(\"# operand_latency: writeStage=%%s readStage=%%s, opnd=%%d\\n\", stageName(writeStage), stageName(readStage), opnd);\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
764 fprintf(fp_cpp, " }\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
765 fprintf(fp_cpp, "#endif\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
766 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
767 fprintf(fp_cpp, "\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
768 fprintf(fp_cpp, " if (writeStage == stage_undefined || readStage == stage_undefined)\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
769 fprintf(fp_cpp, " return (default_latency);\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
770 fprintf(fp_cpp, "\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
771 fprintf(fp_cpp, " int delta = writeStage - readStage;\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
772 fprintf(fp_cpp, " if (delta < 0) delta = 0;\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
773 #if 0
a61af66fc99e Initial load
duke
parents:
diff changeset
774 fprintf(fp_cpp, "\n#ifndef PRODUCT\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
775 fprintf(fp_cpp, " if (TraceOptoOutput) {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
776 fprintf(fp_cpp, " tty->print(\"# operand_latency: delta=%%d\\n\", delta);\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
777 fprintf(fp_cpp, " }\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
778 fprintf(fp_cpp, "#endif\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
779 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
780 fprintf(fp_cpp, " return (delta);\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
781 fprintf(fp_cpp, "}\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
782
a61af66fc99e Initial load
duke
parents:
diff changeset
783 if (!_pipeline)
a61af66fc99e Initial load
duke
parents:
diff changeset
784 /* Do Nothing */;
a61af66fc99e Initial load
duke
parents:
diff changeset
785
a61af66fc99e Initial load
duke
parents:
diff changeset
786 else if (_pipeline->_maxcycleused <=
a61af66fc99e Initial load
duke
parents:
diff changeset
787 #ifdef SPARC
a61af66fc99e Initial load
duke
parents:
diff changeset
788 64
a61af66fc99e Initial load
duke
parents:
diff changeset
789 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
790 32
a61af66fc99e Initial load
duke
parents:
diff changeset
791 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
792 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
793 fprintf(fp_cpp, "Pipeline_Use_Cycle_Mask operator&(const Pipeline_Use_Cycle_Mask &in1, const Pipeline_Use_Cycle_Mask &in2) {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
794 fprintf(fp_cpp, " return Pipeline_Use_Cycle_Mask(in1._mask & in2._mask);\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
795 fprintf(fp_cpp, "}\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
796 fprintf(fp_cpp, "Pipeline_Use_Cycle_Mask operator|(const Pipeline_Use_Cycle_Mask &in1, const Pipeline_Use_Cycle_Mask &in2) {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
797 fprintf(fp_cpp, " return Pipeline_Use_Cycle_Mask(in1._mask | in2._mask);\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
798 fprintf(fp_cpp, "}\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
799 }
a61af66fc99e Initial load
duke
parents:
diff changeset
800 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
801 uint l;
a61af66fc99e Initial load
duke
parents:
diff changeset
802 uint masklen = (_pipeline->_maxcycleused + 31) >> 5;
a61af66fc99e Initial load
duke
parents:
diff changeset
803 fprintf(fp_cpp, "Pipeline_Use_Cycle_Mask operator&(const Pipeline_Use_Cycle_Mask &in1, const Pipeline_Use_Cycle_Mask &in2) {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
804 fprintf(fp_cpp, " return Pipeline_Use_Cycle_Mask(");
a61af66fc99e Initial load
duke
parents:
diff changeset
805 for (l = 1; l <= masklen; l++)
a61af66fc99e Initial load
duke
parents:
diff changeset
806 fprintf(fp_cpp, "in1._mask%d & in2._mask%d%s\n", l, l, l < masklen ? ", " : "");
a61af66fc99e Initial load
duke
parents:
diff changeset
807 fprintf(fp_cpp, ");\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
808 fprintf(fp_cpp, "}\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
809 fprintf(fp_cpp, "Pipeline_Use_Cycle_Mask operator|(const Pipeline_Use_Cycle_Mask &in1, const Pipeline_Use_Cycle_Mask &in2) {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
810 fprintf(fp_cpp, " return Pipeline_Use_Cycle_Mask(");
a61af66fc99e Initial load
duke
parents:
diff changeset
811 for (l = 1; l <= masklen; l++)
a61af66fc99e Initial load
duke
parents:
diff changeset
812 fprintf(fp_cpp, "in1._mask%d | in2._mask%d%s", l, l, l < masklen ? ", " : "");
a61af66fc99e Initial load
duke
parents:
diff changeset
813 fprintf(fp_cpp, ");\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
814 fprintf(fp_cpp, "}\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
815 fprintf(fp_cpp, "void Pipeline_Use_Cycle_Mask::Or(const Pipeline_Use_Cycle_Mask &in2) {\n ");
a61af66fc99e Initial load
duke
parents:
diff changeset
816 for (l = 1; l <= masklen; l++)
a61af66fc99e Initial load
duke
parents:
diff changeset
817 fprintf(fp_cpp, " _mask%d |= in2._mask%d;", l, l);
a61af66fc99e Initial load
duke
parents:
diff changeset
818 fprintf(fp_cpp, "\n}\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
819 }
a61af66fc99e Initial load
duke
parents:
diff changeset
820
a61af66fc99e Initial load
duke
parents:
diff changeset
821 /* Get the length of all the resource names */
a61af66fc99e Initial load
duke
parents:
diff changeset
822 for (_pipeline->_reslist.reset(), resourcenamelen = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
823 (resourcename = _pipeline->_reslist.iter()) != NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
824 resourcenamelen += (int)strlen(resourcename));
a61af66fc99e Initial load
duke
parents:
diff changeset
825
a61af66fc99e Initial load
duke
parents:
diff changeset
826 // Create the pipeline class description
a61af66fc99e Initial load
duke
parents:
diff changeset
827
a61af66fc99e Initial load
duke
parents:
diff changeset
828 fprintf(fp_cpp, "static const Pipeline pipeline_class_Zero_Instructions(0, 0, true, 0, 0, false, false, false, false, NULL, NULL, NULL, Pipeline_Use(0, 0, 0, NULL));\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
829 fprintf(fp_cpp, "static const Pipeline pipeline_class_Unknown_Instructions(0, 0, true, 0, 0, false, true, true, false, NULL, NULL, NULL, Pipeline_Use(0, 0, 0, NULL));\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
830
a61af66fc99e Initial load
duke
parents:
diff changeset
831 fprintf(fp_cpp, "const Pipeline_Use_Element Pipeline_Use::elaborated_elements[%d] = {\n", _pipeline->_rescount);
a61af66fc99e Initial load
duke
parents:
diff changeset
832 for (int i1 = 0; i1 < _pipeline->_rescount; i1++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
833 fprintf(fp_cpp, " Pipeline_Use_Element(0, %d, %d, false, Pipeline_Use_Cycle_Mask(", i1, i1);
a61af66fc99e Initial load
duke
parents:
diff changeset
834 uint masklen = (_pipeline->_maxcycleused + 31) >> 5;
a61af66fc99e Initial load
duke
parents:
diff changeset
835 for (int i2 = masklen-1; i2 >= 0; i2--)
a61af66fc99e Initial load
duke
parents:
diff changeset
836 fprintf(fp_cpp, "0%s", i2 > 0 ? ", " : "");
a61af66fc99e Initial load
duke
parents:
diff changeset
837 fprintf(fp_cpp, "))%s\n", i1 < (_pipeline->_rescount-1) ? "," : "");
a61af66fc99e Initial load
duke
parents:
diff changeset
838 }
a61af66fc99e Initial load
duke
parents:
diff changeset
839 fprintf(fp_cpp, "};\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
840
a61af66fc99e Initial load
duke
parents:
diff changeset
841 fprintf(fp_cpp, "const Pipeline_Use Pipeline_Use::elaborated_use(0, 0, %d, (Pipeline_Use_Element *)&elaborated_elements[0]);\n\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
842 _pipeline->_rescount);
a61af66fc99e Initial load
duke
parents:
diff changeset
843
a61af66fc99e Initial load
duke
parents:
diff changeset
844 for (_pipeline->_classlist.reset(); (classname = _pipeline->_classlist.iter()) != NULL; ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
845 fprintf(fp_cpp, "\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
846 fprintf(fp_cpp, "// Pipeline Class \"%s\"\n", classname);
a61af66fc99e Initial load
duke
parents:
diff changeset
847 PipeClassForm *pipeclass = _pipeline->_classdict[classname]->is_pipeclass();
a61af66fc99e Initial load
duke
parents:
diff changeset
848 int maxWriteStage = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
849 int maxMoreInstrs = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
850 int paramcount = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
851 int i = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
852 const char *paramname;
a61af66fc99e Initial load
duke
parents:
diff changeset
853 int resource_count = (_pipeline->_rescount + 3) >> 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
854
a61af66fc99e Initial load
duke
parents:
diff changeset
855 // Scan the operands, looking for last output stage and number of inputs
a61af66fc99e Initial load
duke
parents:
diff changeset
856 for (pipeclass->_parameters.reset(); (paramname = pipeclass->_parameters.iter()) != NULL; ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
857 const PipeClassOperandForm *pipeopnd =
a61af66fc99e Initial load
duke
parents:
diff changeset
858 (const PipeClassOperandForm *)pipeclass->_localUsage[paramname];
a61af66fc99e Initial load
duke
parents:
diff changeset
859 if (pipeopnd) {
a61af66fc99e Initial load
duke
parents:
diff changeset
860 if (pipeopnd->_iswrite) {
a61af66fc99e Initial load
duke
parents:
diff changeset
861 int stagenum = _pipeline->_stages.index(pipeopnd->_stage);
a61af66fc99e Initial load
duke
parents:
diff changeset
862 int moreinsts = pipeopnd->_more_instrs;
a61af66fc99e Initial load
duke
parents:
diff changeset
863 if ((maxWriteStage+maxMoreInstrs) < (stagenum+moreinsts)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
864 maxWriteStage = stagenum;
a61af66fc99e Initial load
duke
parents:
diff changeset
865 maxMoreInstrs = moreinsts;
a61af66fc99e Initial load
duke
parents:
diff changeset
866 }
a61af66fc99e Initial load
duke
parents:
diff changeset
867 }
a61af66fc99e Initial load
duke
parents:
diff changeset
868 }
a61af66fc99e Initial load
duke
parents:
diff changeset
869
a61af66fc99e Initial load
duke
parents:
diff changeset
870 if (i++ > 0 || (pipeopnd && !pipeopnd->isWrite()))
a61af66fc99e Initial load
duke
parents:
diff changeset
871 paramcount++;
a61af66fc99e Initial load
duke
parents:
diff changeset
872 }
a61af66fc99e Initial load
duke
parents:
diff changeset
873
a61af66fc99e Initial load
duke
parents:
diff changeset
874 // Create the list of stages for the operands that are read
a61af66fc99e Initial load
duke
parents:
diff changeset
875 // Note that we will build a NameList to reduce the number of copies
a61af66fc99e Initial load
duke
parents:
diff changeset
876
a61af66fc99e Initial load
duke
parents:
diff changeset
877 int pipeline_reads_index = pipeline_reads_initializer(fp_cpp, pipeline_reads, pipeclass);
a61af66fc99e Initial load
duke
parents:
diff changeset
878
a61af66fc99e Initial load
duke
parents:
diff changeset
879 int pipeline_res_stages_index = pipeline_res_stages_initializer(
a61af66fc99e Initial load
duke
parents:
diff changeset
880 fp_cpp, _pipeline, pipeline_res_stages, pipeclass);
a61af66fc99e Initial load
duke
parents:
diff changeset
881
a61af66fc99e Initial load
duke
parents:
diff changeset
882 int pipeline_res_cycles_index = pipeline_res_cycles_initializer(
a61af66fc99e Initial load
duke
parents:
diff changeset
883 fp_cpp, _pipeline, pipeline_res_cycles, pipeclass);
a61af66fc99e Initial load
duke
parents:
diff changeset
884
a61af66fc99e Initial load
duke
parents:
diff changeset
885 int pipeline_res_mask_index = pipeline_res_mask_initializer(
a61af66fc99e Initial load
duke
parents:
diff changeset
886 fp_cpp, _pipeline, pipeline_res_masks, pipeline_res_args, pipeclass);
a61af66fc99e Initial load
duke
parents:
diff changeset
887
a61af66fc99e Initial load
duke
parents:
diff changeset
888 #if 0
a61af66fc99e Initial load
duke
parents:
diff changeset
889 // Process the Resources
a61af66fc99e Initial load
duke
parents:
diff changeset
890 const PipeClassResourceForm *piperesource;
a61af66fc99e Initial load
duke
parents:
diff changeset
891
a61af66fc99e Initial load
duke
parents:
diff changeset
892 unsigned resources_used = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
893 unsigned exclusive_resources_used = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
894 unsigned resource_groups = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
895 for (pipeclass->_resUsage.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
896 (piperesource = (const PipeClassResourceForm *)pipeclass->_resUsage.iter()) != NULL; ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
897 int used_mask = _pipeline->_resdict[piperesource->_resource]->is_resource()->mask();
a61af66fc99e Initial load
duke
parents:
diff changeset
898 if (used_mask)
a61af66fc99e Initial load
duke
parents:
diff changeset
899 resource_groups++;
a61af66fc99e Initial load
duke
parents:
diff changeset
900 resources_used |= used_mask;
a61af66fc99e Initial load
duke
parents:
diff changeset
901 if ((used_mask & (used_mask-1)) == 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
902 exclusive_resources_used |= used_mask;
a61af66fc99e Initial load
duke
parents:
diff changeset
903 }
a61af66fc99e Initial load
duke
parents:
diff changeset
904
a61af66fc99e Initial load
duke
parents:
diff changeset
905 if (resource_groups > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
906 fprintf(fp_cpp, "static const uint pipeline_res_or_masks_%03d[%d] = {",
a61af66fc99e Initial load
duke
parents:
diff changeset
907 pipeclass->_num, resource_groups);
a61af66fc99e Initial load
duke
parents:
diff changeset
908 for (pipeclass->_resUsage.reset(), i = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
909 (piperesource = (const PipeClassResourceForm *)pipeclass->_resUsage.iter()) != NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
910 i++ ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
911 int used_mask = _pipeline->_resdict[piperesource->_resource]->is_resource()->mask();
a61af66fc99e Initial load
duke
parents:
diff changeset
912 if (used_mask) {
a61af66fc99e Initial load
duke
parents:
diff changeset
913 fprintf(fp_cpp, " 0x%0*x%c", resource_count, used_mask, i < (int)resource_groups ? ',' : ' ');
a61af66fc99e Initial load
duke
parents:
diff changeset
914 }
a61af66fc99e Initial load
duke
parents:
diff changeset
915 }
a61af66fc99e Initial load
duke
parents:
diff changeset
916 fprintf(fp_cpp, "};\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
917 }
a61af66fc99e Initial load
duke
parents:
diff changeset
918 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
919
a61af66fc99e Initial load
duke
parents:
diff changeset
920 // Create the pipeline class description
a61af66fc99e Initial load
duke
parents:
diff changeset
921 fprintf(fp_cpp, "static const Pipeline pipeline_class_%03d(",
a61af66fc99e Initial load
duke
parents:
diff changeset
922 pipeclass->_num);
a61af66fc99e Initial load
duke
parents:
diff changeset
923 if (maxWriteStage < 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
924 fprintf(fp_cpp, "(uint)stage_undefined");
a61af66fc99e Initial load
duke
parents:
diff changeset
925 else if (maxMoreInstrs == 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
926 fprintf(fp_cpp, "(uint)stage_%s", _pipeline->_stages.name(maxWriteStage));
a61af66fc99e Initial load
duke
parents:
diff changeset
927 else
a61af66fc99e Initial load
duke
parents:
diff changeset
928 fprintf(fp_cpp, "((uint)stage_%s)+%d", _pipeline->_stages.name(maxWriteStage), maxMoreInstrs);
a61af66fc99e Initial load
duke
parents:
diff changeset
929 fprintf(fp_cpp, ", %d, %s, %d, %d, %s, %s, %s, %s,\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
930 paramcount,
a61af66fc99e Initial load
duke
parents:
diff changeset
931 pipeclass->hasFixedLatency() ? "true" : "false",
a61af66fc99e Initial load
duke
parents:
diff changeset
932 pipeclass->fixedLatency(),
a61af66fc99e Initial load
duke
parents:
diff changeset
933 pipeclass->InstructionCount(),
a61af66fc99e Initial load
duke
parents:
diff changeset
934 pipeclass->hasBranchDelay() ? "true" : "false",
a61af66fc99e Initial load
duke
parents:
diff changeset
935 pipeclass->hasMultipleBundles() ? "true" : "false",
a61af66fc99e Initial load
duke
parents:
diff changeset
936 pipeclass->forceSerialization() ? "true" : "false",
a61af66fc99e Initial load
duke
parents:
diff changeset
937 pipeclass->mayHaveNoCode() ? "true" : "false" );
a61af66fc99e Initial load
duke
parents:
diff changeset
938 if (paramcount > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
939 fprintf(fp_cpp, "\n (enum machPipelineStages * const) pipeline_reads_%03d,\n ",
a61af66fc99e Initial load
duke
parents:
diff changeset
940 pipeline_reads_index+1);
a61af66fc99e Initial load
duke
parents:
diff changeset
941 }
a61af66fc99e Initial load
duke
parents:
diff changeset
942 else
a61af66fc99e Initial load
duke
parents:
diff changeset
943 fprintf(fp_cpp, " NULL,");
a61af66fc99e Initial load
duke
parents:
diff changeset
944 fprintf(fp_cpp, " (enum machPipelineStages * const) pipeline_res_stages_%03d,\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
945 pipeline_res_stages_index+1);
a61af66fc99e Initial load
duke
parents:
diff changeset
946 fprintf(fp_cpp, " (uint * const) pipeline_res_cycles_%03d,\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
947 pipeline_res_cycles_index+1);
a61af66fc99e Initial load
duke
parents:
diff changeset
948 fprintf(fp_cpp, " Pipeline_Use(%s, (Pipeline_Use_Element *)",
a61af66fc99e Initial load
duke
parents:
diff changeset
949 pipeline_res_args.name(pipeline_res_mask_index));
a61af66fc99e Initial load
duke
parents:
diff changeset
950 if (strlen(pipeline_res_masks.name(pipeline_res_mask_index)) > 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
951 fprintf(fp_cpp, "&pipeline_res_mask_%03d[0]",
a61af66fc99e Initial load
duke
parents:
diff changeset
952 pipeline_res_mask_index+1);
a61af66fc99e Initial load
duke
parents:
diff changeset
953 else
a61af66fc99e Initial load
duke
parents:
diff changeset
954 fprintf(fp_cpp, "NULL");
a61af66fc99e Initial load
duke
parents:
diff changeset
955 fprintf(fp_cpp, "));\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
956 }
a61af66fc99e Initial load
duke
parents:
diff changeset
957
a61af66fc99e Initial load
duke
parents:
diff changeset
958 // Generate the Node::latency method if _pipeline defined
a61af66fc99e Initial load
duke
parents:
diff changeset
959 fprintf(fp_cpp, "\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
960 fprintf(fp_cpp, "//------------------Inter-Instruction Latency--------------------------------\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
961 fprintf(fp_cpp, "uint Node::latency(uint i) {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
962 if (_pipeline) {
a61af66fc99e Initial load
duke
parents:
diff changeset
963 #if 0
a61af66fc99e Initial load
duke
parents:
diff changeset
964 fprintf(fp_cpp, "#ifndef PRODUCT\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
965 fprintf(fp_cpp, " if (TraceOptoOutput) {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
966 fprintf(fp_cpp, " tty->print(\"# %%4d->latency(%%d)\\n\", _idx, i);\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
967 fprintf(fp_cpp, " }\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
968 fprintf(fp_cpp, "#endif\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
969 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
970 fprintf(fp_cpp, " uint j;\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
971 fprintf(fp_cpp, " // verify in legal range for inputs\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
972 fprintf(fp_cpp, " assert(i < len(), \"index not in range\");\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
973 fprintf(fp_cpp, " // verify input is not null\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
974 fprintf(fp_cpp, " Node *pred = in(i);\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
975 fprintf(fp_cpp, " if (!pred)\n return %d;\n\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
976 non_operand_latency);
a61af66fc99e Initial load
duke
parents:
diff changeset
977 fprintf(fp_cpp, " if (pred->is_Proj())\n pred = pred->in(0);\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
978 fprintf(fp_cpp, " // if either node does not have pipeline info, use default\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
979 fprintf(fp_cpp, " const Pipeline *predpipe = pred->pipeline();\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
980 fprintf(fp_cpp, " assert(predpipe, \"no predecessor pipeline info\");\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
981 fprintf(fp_cpp, " if (predpipe->hasFixedLatency())\n return predpipe->fixedLatency();\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
982 fprintf(fp_cpp, " const Pipeline *currpipe = pipeline();\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
983 fprintf(fp_cpp, " assert(currpipe, \"no pipeline info\");\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
984 fprintf(fp_cpp, " if (!is_Mach())\n return %d;\n\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
985 node_latency);
a61af66fc99e Initial load
duke
parents:
diff changeset
986 fprintf(fp_cpp, " const MachNode *m = as_Mach();\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
987 fprintf(fp_cpp, " j = m->oper_input_base();\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
988 fprintf(fp_cpp, " if (i < j)\n return currpipe->functional_unit_latency(%d, predpipe);\n\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
989 non_operand_latency);
a61af66fc99e Initial load
duke
parents:
diff changeset
990 fprintf(fp_cpp, " // determine which operand this is in\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
991 fprintf(fp_cpp, " uint n = m->num_opnds();\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
992 fprintf(fp_cpp, " int delta = %d;\n\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
993 non_operand_latency);
a61af66fc99e Initial load
duke
parents:
diff changeset
994 fprintf(fp_cpp, " uint k;\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
995 fprintf(fp_cpp, " for (k = 1; k < n; k++) {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
996 fprintf(fp_cpp, " j += m->_opnds[k]->num_edges();\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
997 fprintf(fp_cpp, " if (i < j)\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
998 fprintf(fp_cpp, " break;\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
999 fprintf(fp_cpp, " }\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1000 fprintf(fp_cpp, " if (k < n)\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1001 fprintf(fp_cpp, " delta = currpipe->operand_latency(k,predpipe);\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1002 fprintf(fp_cpp, " return currpipe->functional_unit_latency(delta, predpipe);\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1003 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1004 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1005 fprintf(fp_cpp, " // assert(false, \"pipeline functionality is not defined\");\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1006 fprintf(fp_cpp, " return %d;\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
1007 non_operand_latency);
a61af66fc99e Initial load
duke
parents:
diff changeset
1008 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1009 fprintf(fp_cpp, "}\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1010
a61af66fc99e Initial load
duke
parents:
diff changeset
1011 // Output the list of nop nodes
a61af66fc99e Initial load
duke
parents:
diff changeset
1012 fprintf(fp_cpp, "// Descriptions for emitting different functional unit nops\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1013 const char *nop;
a61af66fc99e Initial load
duke
parents:
diff changeset
1014 int nopcnt = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1015 for ( _pipeline->_noplist.reset(); (nop = _pipeline->_noplist.iter()) != NULL; nopcnt++ );
a61af66fc99e Initial load
duke
parents:
diff changeset
1016
a61af66fc99e Initial load
duke
parents:
diff changeset
1017 fprintf(fp_cpp, "void Bundle::initialize_nops(MachNode * nop_list[%d], Compile *C) {\n", nopcnt);
a61af66fc99e Initial load
duke
parents:
diff changeset
1018 int i = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1019 for ( _pipeline->_noplist.reset(); (nop = _pipeline->_noplist.iter()) != NULL; i++ ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1020 fprintf(fp_cpp, " nop_list[%d] = (MachNode *) new (C) %sNode();\n", i, nop);
a61af66fc99e Initial load
duke
parents:
diff changeset
1021 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1022 fprintf(fp_cpp, "};\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1023 fprintf(fp_cpp, "#ifndef PRODUCT\n");
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
1024 fprintf(fp_cpp, "void Bundle::dump(outputStream *st) const {\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1025 fprintf(fp_cpp, " static const char * bundle_flags[] = {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1026 fprintf(fp_cpp, " \"\",\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1027 fprintf(fp_cpp, " \"use nop delay\",\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1028 fprintf(fp_cpp, " \"use unconditional delay\",\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1029 fprintf(fp_cpp, " \"use conditional delay\",\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1030 fprintf(fp_cpp, " \"used in conditional delay\",\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1031 fprintf(fp_cpp, " \"used in unconditional delay\",\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1032 fprintf(fp_cpp, " \"used in all conditional delays\",\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1033 fprintf(fp_cpp, " };\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1034
a61af66fc99e Initial load
duke
parents:
diff changeset
1035 fprintf(fp_cpp, " static const char *resource_names[%d] = {", _pipeline->_rescount);
a61af66fc99e Initial load
duke
parents:
diff changeset
1036 for (i = 0; i < _pipeline->_rescount; i++)
a61af66fc99e Initial load
duke
parents:
diff changeset
1037 fprintf(fp_cpp, " \"%s\"%c", _pipeline->_reslist.name(i), i < _pipeline->_rescount-1 ? ',' : ' ');
a61af66fc99e Initial load
duke
parents:
diff changeset
1038 fprintf(fp_cpp, "};\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1039
a61af66fc99e Initial load
duke
parents:
diff changeset
1040 // See if the same string is in the table
a61af66fc99e Initial load
duke
parents:
diff changeset
1041 fprintf(fp_cpp, " bool needs_comma = false;\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1042 fprintf(fp_cpp, " if (_flags) {\n");
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
1043 fprintf(fp_cpp, " st->print(\"%%s\", bundle_flags[_flags]);\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1044 fprintf(fp_cpp, " needs_comma = true;\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1045 fprintf(fp_cpp, " };\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1046 fprintf(fp_cpp, " if (instr_count()) {\n");
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
1047 fprintf(fp_cpp, " st->print(\"%%s%%d instr%%s\", needs_comma ? \", \" : \"\", instr_count(), instr_count() != 1 ? \"s\" : \"\");\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1048 fprintf(fp_cpp, " needs_comma = true;\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1049 fprintf(fp_cpp, " };\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1050 fprintf(fp_cpp, " uint r = resources_used();\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1051 fprintf(fp_cpp, " if (r) {\n");
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
1052 fprintf(fp_cpp, " st->print(\"%%sresource%%s:\", needs_comma ? \", \" : \"\", (r & (r-1)) != 0 ? \"s\" : \"\");\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1053 fprintf(fp_cpp, " for (uint i = 0; i < %d; i++)\n", _pipeline->_rescount);
a61af66fc99e Initial load
duke
parents:
diff changeset
1054 fprintf(fp_cpp, " if ((r & (1 << i)) != 0)\n");
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
1055 fprintf(fp_cpp, " st->print(\" %%s\", resource_names[i]);\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1056 fprintf(fp_cpp, " needs_comma = true;\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1057 fprintf(fp_cpp, " };\n");
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
1058 fprintf(fp_cpp, " st->print(\"\\n\");\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1059 fprintf(fp_cpp, "}\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1060 fprintf(fp_cpp, "#endif\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1061 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1062
a61af66fc99e Initial load
duke
parents:
diff changeset
1063 // ---------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1064 //------------------------------Utilities to build Instruction Classes--------
a61af66fc99e Initial load
duke
parents:
diff changeset
1065 // ---------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1066
a61af66fc99e Initial load
duke
parents:
diff changeset
1067 static void defineOut_RegMask(FILE *fp, const char *node, const char *regMask) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1068 fprintf(fp,"const RegMask &%sNode::out_RegMask() const { return (%s); }\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
1069 node, regMask);
a61af66fc99e Initial load
duke
parents:
diff changeset
1070 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1071
603
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 415
diff changeset
1072 static void print_block_index(FILE *fp, int inst_position) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1073 assert( inst_position >= 0, "Instruction number less than zero");
a61af66fc99e Initial load
duke
parents:
diff changeset
1074 fprintf(fp, "block_index");
a61af66fc99e Initial load
duke
parents:
diff changeset
1075 if( inst_position != 0 ) {
603
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 415
diff changeset
1076 fprintf(fp, " - %d", inst_position);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1077 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1078 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1079
a61af66fc99e Initial load
duke
parents:
diff changeset
1080 // Scan the peepmatch and output a test for each instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
1081 static void check_peepmatch_instruction_sequence(FILE *fp, PeepMatch *pmatch, PeepConstraint *pconstraint) {
603
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 415
diff changeset
1082 int parent = -1;
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 415
diff changeset
1083 int inst_position = 0;
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 415
diff changeset
1084 const char* inst_name = NULL;
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 415
diff changeset
1085 int input = 0;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1086 fprintf(fp, " // Check instruction sub-tree\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1087 pmatch->reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
1088 for( pmatch->next_instruction( parent, inst_position, inst_name, input );
a61af66fc99e Initial load
duke
parents:
diff changeset
1089 inst_name != NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1090 pmatch->next_instruction( parent, inst_position, inst_name, input ) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1091 // If this is not a placeholder
a61af66fc99e Initial load
duke
parents:
diff changeset
1092 if( ! pmatch->is_placeholder() ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1093 // Define temporaries 'inst#', based on parent and parent's input index
a61af66fc99e Initial load
duke
parents:
diff changeset
1094 if( parent != -1 ) { // root was initialized
a61af66fc99e Initial load
duke
parents:
diff changeset
1095 fprintf(fp, " // Identify previous instruction if inside this block\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1096 fprintf(fp, " if( ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1097 print_block_index(fp, inst_position);
12167
650868c062a9 8023691: Create interface for nodes in class Block
adlertz
parents: 10389
diff changeset
1098 fprintf(fp, " > 0 ) {\n Node *n = block->get_node(");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1099 print_block_index(fp, inst_position);
603
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 415
diff changeset
1100 fprintf(fp, ");\n inst%d = (n->is_Mach()) ? ", inst_position);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1101 fprintf(fp, "n->as_Mach() : NULL;\n }\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1102 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1103
a61af66fc99e Initial load
duke
parents:
diff changeset
1104 // When not the root
a61af66fc99e Initial load
duke
parents:
diff changeset
1105 // Test we have the correct instruction by comparing the rule.
a61af66fc99e Initial load
duke
parents:
diff changeset
1106 if( parent != -1 ) {
603
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 415
diff changeset
1107 fprintf(fp, " matches = matches && (inst%d != NULL) && (inst%d->rule() == %s_rule);\n",
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1108 inst_position, inst_position, inst_name);
a61af66fc99e Initial load
duke
parents:
diff changeset
1109 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1110 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1111 // Check that user did not try to constrain a placeholder
a61af66fc99e Initial load
duke
parents:
diff changeset
1112 assert( ! pconstraint->constrains_instruction(inst_position),
a61af66fc99e Initial load
duke
parents:
diff changeset
1113 "fatal(): Can not constrain a placeholder instruction");
a61af66fc99e Initial load
duke
parents:
diff changeset
1114 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1115 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1116 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1117
a61af66fc99e Initial load
duke
parents:
diff changeset
1118 // Build mapping for register indices, num_edges to input
a61af66fc99e Initial load
duke
parents:
diff changeset
1119 static void build_instruction_index_mapping( FILE *fp, FormDict &globals, PeepMatch *pmatch ) {
603
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 415
diff changeset
1120 int parent = -1;
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 415
diff changeset
1121 int inst_position = 0;
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 415
diff changeset
1122 const char* inst_name = NULL;
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 415
diff changeset
1123 int input = 0;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1124 fprintf(fp, " // Build map to register info\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1125 pmatch->reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
1126 for( pmatch->next_instruction( parent, inst_position, inst_name, input );
a61af66fc99e Initial load
duke
parents:
diff changeset
1127 inst_name != NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1128 pmatch->next_instruction( parent, inst_position, inst_name, input ) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1129 // If this is not a placeholder
a61af66fc99e Initial load
duke
parents:
diff changeset
1130 if( ! pmatch->is_placeholder() ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1131 // Define temporaries 'inst#', based on self's inst_position
a61af66fc99e Initial load
duke
parents:
diff changeset
1132 InstructForm *inst = globals[inst_name]->is_instruction();
a61af66fc99e Initial load
duke
parents:
diff changeset
1133 if( inst != NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1134 char inst_prefix[] = "instXXXX_";
603
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 415
diff changeset
1135 sprintf(inst_prefix, "inst%d_", inst_position);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1136 char receiver[] = "instXXXX->";
603
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 415
diff changeset
1137 sprintf(receiver, "inst%d->", inst_position);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1138 inst->index_temps( fp, globals, inst_prefix, receiver );
a61af66fc99e Initial load
duke
parents:
diff changeset
1139 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1140 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1141 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1142 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1143
a61af66fc99e Initial load
duke
parents:
diff changeset
1144 // Generate tests for the constraints
a61af66fc99e Initial load
duke
parents:
diff changeset
1145 static void check_peepconstraints(FILE *fp, FormDict &globals, PeepMatch *pmatch, PeepConstraint *pconstraint) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1146 fprintf(fp, "\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1147 fprintf(fp, " // Check constraints on sub-tree-leaves\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1148
a61af66fc99e Initial load
duke
parents:
diff changeset
1149 // Build mapping from num_edges to local variables
a61af66fc99e Initial load
duke
parents:
diff changeset
1150 build_instruction_index_mapping( fp, globals, pmatch );
a61af66fc99e Initial load
duke
parents:
diff changeset
1151
a61af66fc99e Initial load
duke
parents:
diff changeset
1152 // Build constraint tests
a61af66fc99e Initial load
duke
parents:
diff changeset
1153 if( pconstraint != NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1154 fprintf(fp, " matches = matches &&");
a61af66fc99e Initial load
duke
parents:
diff changeset
1155 bool first_constraint = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1156 while( pconstraint != NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1157 // indentation and connecting '&&'
a61af66fc99e Initial load
duke
parents:
diff changeset
1158 const char *indentation = " ";
a61af66fc99e Initial load
duke
parents:
diff changeset
1159 fprintf(fp, "\n%s%s", indentation, (!first_constraint ? "&& " : " "));
a61af66fc99e Initial load
duke
parents:
diff changeset
1160
a61af66fc99e Initial load
duke
parents:
diff changeset
1161 // Only have '==' relation implemented
a61af66fc99e Initial load
duke
parents:
diff changeset
1162 if( strcmp(pconstraint->_relation,"==") != 0 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1163 assert( false, "Unimplemented()" );
a61af66fc99e Initial load
duke
parents:
diff changeset
1164 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1165
a61af66fc99e Initial load
duke
parents:
diff changeset
1166 // LEFT
603
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 415
diff changeset
1167 int left_index = pconstraint->_left_inst;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1168 const char *left_op = pconstraint->_left_op;
a61af66fc99e Initial load
duke
parents:
diff changeset
1169 // Access info on the instructions whose operands are compared
a61af66fc99e Initial load
duke
parents:
diff changeset
1170 InstructForm *inst_left = globals[pmatch->instruction_name(left_index)]->is_instruction();
a61af66fc99e Initial load
duke
parents:
diff changeset
1171 assert( inst_left, "Parser should guaranty this is an instruction");
a61af66fc99e Initial load
duke
parents:
diff changeset
1172 int left_op_base = inst_left->oper_input_base(globals);
a61af66fc99e Initial load
duke
parents:
diff changeset
1173 // Access info on the operands being compared
a61af66fc99e Initial load
duke
parents:
diff changeset
1174 int left_op_index = inst_left->operand_position(left_op, Component::USE);
a61af66fc99e Initial load
duke
parents:
diff changeset
1175 if( left_op_index == -1 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1176 left_op_index = inst_left->operand_position(left_op, Component::DEF);
a61af66fc99e Initial load
duke
parents:
diff changeset
1177 if( left_op_index == -1 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1178 left_op_index = inst_left->operand_position(left_op, Component::USE_DEF);
a61af66fc99e Initial load
duke
parents:
diff changeset
1179 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1180 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1181 assert( left_op_index != NameList::Not_in_list, "Did not find operand in instruction");
a61af66fc99e Initial load
duke
parents:
diff changeset
1182 ComponentList components_left = inst_left->_components;
a61af66fc99e Initial load
duke
parents:
diff changeset
1183 const char *left_comp_type = components_left.at(left_op_index)->_type;
a61af66fc99e Initial load
duke
parents:
diff changeset
1184 OpClassForm *left_opclass = globals[left_comp_type]->is_opclass();
a61af66fc99e Initial load
duke
parents:
diff changeset
1185 Form::InterfaceType left_interface_type = left_opclass->interface_type(globals);
a61af66fc99e Initial load
duke
parents:
diff changeset
1186
a61af66fc99e Initial load
duke
parents:
diff changeset
1187
a61af66fc99e Initial load
duke
parents:
diff changeset
1188 // RIGHT
a61af66fc99e Initial load
duke
parents:
diff changeset
1189 int right_op_index = -1;
603
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 415
diff changeset
1190 int right_index = pconstraint->_right_inst;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1191 const char *right_op = pconstraint->_right_op;
a61af66fc99e Initial load
duke
parents:
diff changeset
1192 if( right_index != -1 ) { // Match operand
a61af66fc99e Initial load
duke
parents:
diff changeset
1193 // Access info on the instructions whose operands are compared
a61af66fc99e Initial load
duke
parents:
diff changeset
1194 InstructForm *inst_right = globals[pmatch->instruction_name(right_index)]->is_instruction();
a61af66fc99e Initial load
duke
parents:
diff changeset
1195 assert( inst_right, "Parser should guaranty this is an instruction");
a61af66fc99e Initial load
duke
parents:
diff changeset
1196 int right_op_base = inst_right->oper_input_base(globals);
a61af66fc99e Initial load
duke
parents:
diff changeset
1197 // Access info on the operands being compared
a61af66fc99e Initial load
duke
parents:
diff changeset
1198 right_op_index = inst_right->operand_position(right_op, Component::USE);
a61af66fc99e Initial load
duke
parents:
diff changeset
1199 if( right_op_index == -1 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1200 right_op_index = inst_right->operand_position(right_op, Component::DEF);
a61af66fc99e Initial load
duke
parents:
diff changeset
1201 if( right_op_index == -1 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1202 right_op_index = inst_right->operand_position(right_op, Component::USE_DEF);
a61af66fc99e Initial load
duke
parents:
diff changeset
1203 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1204 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1205 assert( right_op_index != NameList::Not_in_list, "Did not find operand in instruction");
a61af66fc99e Initial load
duke
parents:
diff changeset
1206 ComponentList components_right = inst_right->_components;
a61af66fc99e Initial load
duke
parents:
diff changeset
1207 const char *right_comp_type = components_right.at(right_op_index)->_type;
a61af66fc99e Initial load
duke
parents:
diff changeset
1208 OpClassForm *right_opclass = globals[right_comp_type]->is_opclass();
a61af66fc99e Initial load
duke
parents:
diff changeset
1209 Form::InterfaceType right_interface_type = right_opclass->interface_type(globals);
a61af66fc99e Initial load
duke
parents:
diff changeset
1210 assert( right_interface_type == left_interface_type, "Both must be same interface");
a61af66fc99e Initial load
duke
parents:
diff changeset
1211
a61af66fc99e Initial load
duke
parents:
diff changeset
1212 } else { // Else match register
a61af66fc99e Initial load
duke
parents:
diff changeset
1213 // assert( false, "should be a register" );
a61af66fc99e Initial load
duke
parents:
diff changeset
1214 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1215
a61af66fc99e Initial load
duke
parents:
diff changeset
1216 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1217 // Check for equivalence
a61af66fc99e Initial load
duke
parents:
diff changeset
1218 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1219 // fprintf(fp, "phase->eqv( ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1220 // fprintf(fp, "inst%d->in(%d+%d) /* %s */, inst%d->in(%d+%d) /* %s */",
a61af66fc99e Initial load
duke
parents:
diff changeset
1221 // left_index, left_op_base, left_op_index, left_op,
a61af66fc99e Initial load
duke
parents:
diff changeset
1222 // right_index, right_op_base, right_op_index, right_op );
a61af66fc99e Initial load
duke
parents:
diff changeset
1223 // fprintf(fp, ")");
a61af66fc99e Initial load
duke
parents:
diff changeset
1224 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1225 switch( left_interface_type ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1226 case Form::register_interface: {
a61af66fc99e Initial load
duke
parents:
diff changeset
1227 // Check that they are allocated to the same register
a61af66fc99e Initial load
duke
parents:
diff changeset
1228 // Need parameter for index position if not result operand
a61af66fc99e Initial load
duke
parents:
diff changeset
1229 char left_reg_index[] = ",instXXXX_idxXXXX";
a61af66fc99e Initial load
duke
parents:
diff changeset
1230 if( left_op_index != 0 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1231 assert( (left_index <= 9999) && (left_op_index <= 9999), "exceed string size");
a61af66fc99e Initial load
duke
parents:
diff changeset
1232 // Must have index into operands
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
1233 sprintf(left_reg_index,",inst%d_idx%d", (int)left_index, left_op_index);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1234 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1235 strcpy(left_reg_index, "");
a61af66fc99e Initial load
duke
parents:
diff changeset
1236 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1237 fprintf(fp, "(inst%d->_opnds[%d]->reg(ra_,inst%d%s) /* %d.%s */",
a61af66fc99e Initial load
duke
parents:
diff changeset
1238 left_index, left_op_index, left_index, left_reg_index, left_index, left_op );
a61af66fc99e Initial load
duke
parents:
diff changeset
1239 fprintf(fp, " == ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1240
a61af66fc99e Initial load
duke
parents:
diff changeset
1241 if( right_index != -1 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1242 char right_reg_index[18] = ",instXXXX_idxXXXX";
a61af66fc99e Initial load
duke
parents:
diff changeset
1243 if( right_op_index != 0 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1244 assert( (right_index <= 9999) && (right_op_index <= 9999), "exceed string size");
a61af66fc99e Initial load
duke
parents:
diff changeset
1245 // Must have index into operands
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
1246 sprintf(right_reg_index,",inst%d_idx%d", (int)right_index, right_op_index);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1247 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1248 strcpy(right_reg_index, "");
a61af66fc99e Initial load
duke
parents:
diff changeset
1249 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1250 fprintf(fp, "/* %d.%s */ inst%d->_opnds[%d]->reg(ra_,inst%d%s)",
a61af66fc99e Initial load
duke
parents:
diff changeset
1251 right_index, right_op, right_index, right_op_index, right_index, right_reg_index );
a61af66fc99e Initial load
duke
parents:
diff changeset
1252 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1253 fprintf(fp, "%s_enc", right_op );
a61af66fc99e Initial load
duke
parents:
diff changeset
1254 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1255 fprintf(fp,")");
a61af66fc99e Initial load
duke
parents:
diff changeset
1256 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1257 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1258 case Form::constant_interface: {
a61af66fc99e Initial load
duke
parents:
diff changeset
1259 // Compare the '->constant()' values
a61af66fc99e Initial load
duke
parents:
diff changeset
1260 fprintf(fp, "(inst%d->_opnds[%d]->constant() /* %d.%s */",
a61af66fc99e Initial load
duke
parents:
diff changeset
1261 left_index, left_op_index, left_index, left_op );
a61af66fc99e Initial load
duke
parents:
diff changeset
1262 fprintf(fp, " == ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1263 fprintf(fp, "/* %d.%s */ inst%d->_opnds[%d]->constant())",
a61af66fc99e Initial load
duke
parents:
diff changeset
1264 right_index, right_op, right_index, right_op_index );
a61af66fc99e Initial load
duke
parents:
diff changeset
1265 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1266 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1267 case Form::memory_interface: {
a61af66fc99e Initial load
duke
parents:
diff changeset
1268 // Compare 'base', 'index', 'scale', and 'disp'
a61af66fc99e Initial load
duke
parents:
diff changeset
1269 // base
a61af66fc99e Initial load
duke
parents:
diff changeset
1270 fprintf(fp, "( \n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1271 fprintf(fp, " (inst%d->_opnds[%d]->base(ra_,inst%d,inst%d_idx%d) /* %d.%s$$base */",
a61af66fc99e Initial load
duke
parents:
diff changeset
1272 left_index, left_op_index, left_index, left_index, left_op_index, left_index, left_op );
a61af66fc99e Initial load
duke
parents:
diff changeset
1273 fprintf(fp, " == ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1274 fprintf(fp, "/* %d.%s$$base */ inst%d->_opnds[%d]->base(ra_,inst%d,inst%d_idx%d)) &&\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
1275 right_index, right_op, right_index, right_op_index, right_index, right_index, right_op_index );
a61af66fc99e Initial load
duke
parents:
diff changeset
1276 // index
a61af66fc99e Initial load
duke
parents:
diff changeset
1277 fprintf(fp, " (inst%d->_opnds[%d]->index(ra_,inst%d,inst%d_idx%d) /* %d.%s$$index */",
a61af66fc99e Initial load
duke
parents:
diff changeset
1278 left_index, left_op_index, left_index, left_index, left_op_index, left_index, left_op );
a61af66fc99e Initial load
duke
parents:
diff changeset
1279 fprintf(fp, " == ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1280 fprintf(fp, "/* %d.%s$$index */ inst%d->_opnds[%d]->index(ra_,inst%d,inst%d_idx%d)) &&\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
1281 right_index, right_op, right_index, right_op_index, right_index, right_index, right_op_index );
a61af66fc99e Initial load
duke
parents:
diff changeset
1282 // scale
a61af66fc99e Initial load
duke
parents:
diff changeset
1283 fprintf(fp, " (inst%d->_opnds[%d]->scale() /* %d.%s$$scale */",
a61af66fc99e Initial load
duke
parents:
diff changeset
1284 left_index, left_op_index, left_index, left_op );
a61af66fc99e Initial load
duke
parents:
diff changeset
1285 fprintf(fp, " == ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1286 fprintf(fp, "/* %d.%s$$scale */ inst%d->_opnds[%d]->scale()) &&\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
1287 right_index, right_op, right_index, right_op_index );
a61af66fc99e Initial load
duke
parents:
diff changeset
1288 // disp
a61af66fc99e Initial load
duke
parents:
diff changeset
1289 fprintf(fp, " (inst%d->_opnds[%d]->disp(ra_,inst%d,inst%d_idx%d) /* %d.%s$$disp */",
a61af66fc99e Initial load
duke
parents:
diff changeset
1290 left_index, left_op_index, left_index, left_index, left_op_index, left_index, left_op );
a61af66fc99e Initial load
duke
parents:
diff changeset
1291 fprintf(fp, " == ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1292 fprintf(fp, "/* %d.%s$$disp */ inst%d->_opnds[%d]->disp(ra_,inst%d,inst%d_idx%d))\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
1293 right_index, right_op, right_index, right_op_index, right_index, right_index, right_op_index );
a61af66fc99e Initial load
duke
parents:
diff changeset
1294 fprintf(fp, ") \n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1295 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1296 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1297 case Form::conditional_interface: {
a61af66fc99e Initial load
duke
parents:
diff changeset
1298 // Compare the condition code being tested
a61af66fc99e Initial load
duke
parents:
diff changeset
1299 assert( false, "Unimplemented()" );
a61af66fc99e Initial load
duke
parents:
diff changeset
1300 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1301 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1302 default: {
a61af66fc99e Initial load
duke
parents:
diff changeset
1303 assert( false, "ShouldNotReachHere()" );
a61af66fc99e Initial load
duke
parents:
diff changeset
1304 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1305 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1306 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1307
a61af66fc99e Initial load
duke
parents:
diff changeset
1308 // Advance to next constraint
a61af66fc99e Initial load
duke
parents:
diff changeset
1309 pconstraint = pconstraint->next();
a61af66fc99e Initial load
duke
parents:
diff changeset
1310 first_constraint = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1311 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1312
a61af66fc99e Initial load
duke
parents:
diff changeset
1313 fprintf(fp, ";\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1314 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1315 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1316
a61af66fc99e Initial load
duke
parents:
diff changeset
1317 // // EXPERIMENTAL -- TEMPORARY code
a61af66fc99e Initial load
duke
parents:
diff changeset
1318 // static Form::DataType get_operand_type(FormDict &globals, InstructForm *instr, const char *op_name ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1319 // int op_index = instr->operand_position(op_name, Component::USE);
a61af66fc99e Initial load
duke
parents:
diff changeset
1320 // if( op_index == -1 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1321 // op_index = instr->operand_position(op_name, Component::DEF);
a61af66fc99e Initial load
duke
parents:
diff changeset
1322 // if( op_index == -1 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1323 // op_index = instr->operand_position(op_name, Component::USE_DEF);
a61af66fc99e Initial load
duke
parents:
diff changeset
1324 // }
a61af66fc99e Initial load
duke
parents:
diff changeset
1325 // }
a61af66fc99e Initial load
duke
parents:
diff changeset
1326 // assert( op_index != NameList::Not_in_list, "Did not find operand in instruction");
a61af66fc99e Initial load
duke
parents:
diff changeset
1327 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1328 // ComponentList components_right = instr->_components;
a61af66fc99e Initial load
duke
parents:
diff changeset
1329 // char *right_comp_type = components_right.at(op_index)->_type;
a61af66fc99e Initial load
duke
parents:
diff changeset
1330 // OpClassForm *right_opclass = globals[right_comp_type]->is_opclass();
a61af66fc99e Initial load
duke
parents:
diff changeset
1331 // Form::InterfaceType right_interface_type = right_opclass->interface_type(globals);
a61af66fc99e Initial load
duke
parents:
diff changeset
1332 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1333 // return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1334 // }
a61af66fc99e Initial load
duke
parents:
diff changeset
1335
a61af66fc99e Initial load
duke
parents:
diff changeset
1336 // Construct the new sub-tree
a61af66fc99e Initial load
duke
parents:
diff changeset
1337 static void generate_peepreplace( FILE *fp, FormDict &globals, PeepMatch *pmatch, PeepConstraint *pconstraint, PeepReplace *preplace, int max_position ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1338 fprintf(fp, " // IF instructions and constraints matched\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1339 fprintf(fp, " if( matches ) {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1340 fprintf(fp, " // generate the new sub-tree\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1341 fprintf(fp, " assert( true, \"Debug stopping point\");\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1342 if( preplace != NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1343 // Get the root of the new sub-tree
a61af66fc99e Initial load
duke
parents:
diff changeset
1344 const char *root_inst = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1345 preplace->next_instruction(root_inst);
a61af66fc99e Initial load
duke
parents:
diff changeset
1346 InstructForm *root_form = globals[root_inst]->is_instruction();
a61af66fc99e Initial load
duke
parents:
diff changeset
1347 assert( root_form != NULL, "Replacement instruction was not previously defined");
a61af66fc99e Initial load
duke
parents:
diff changeset
1348 fprintf(fp, " %sNode *root = new (C) %sNode();\n", root_inst, root_inst);
a61af66fc99e Initial load
duke
parents:
diff changeset
1349
603
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 415
diff changeset
1350 int inst_num;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1351 const char *op_name;
a61af66fc99e Initial load
duke
parents:
diff changeset
1352 int opnds_index = 0; // define result operand
a61af66fc99e Initial load
duke
parents:
diff changeset
1353 // Then install the use-operands for the new sub-tree
a61af66fc99e Initial load
duke
parents:
diff changeset
1354 // preplace->reset(); // reset breaks iteration
a61af66fc99e Initial load
duke
parents:
diff changeset
1355 for( preplace->next_operand( inst_num, op_name );
a61af66fc99e Initial load
duke
parents:
diff changeset
1356 op_name != NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1357 preplace->next_operand( inst_num, op_name ) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1358 InstructForm *inst_form;
a61af66fc99e Initial load
duke
parents:
diff changeset
1359 inst_form = globals[pmatch->instruction_name(inst_num)]->is_instruction();
a61af66fc99e Initial load
duke
parents:
diff changeset
1360 assert( inst_form, "Parser should guaranty this is an instruction");
a61af66fc99e Initial load
duke
parents:
diff changeset
1361 int inst_op_num = inst_form->operand_position(op_name, Component::USE);
a61af66fc99e Initial load
duke
parents:
diff changeset
1362 if( inst_op_num == NameList::Not_in_list )
a61af66fc99e Initial load
duke
parents:
diff changeset
1363 inst_op_num = inst_form->operand_position(op_name, Component::USE_DEF);
a61af66fc99e Initial load
duke
parents:
diff changeset
1364 assert( inst_op_num != NameList::Not_in_list, "Did not find operand as USE");
a61af66fc99e Initial load
duke
parents:
diff changeset
1365 // find the name of the OperandForm from the local name
a61af66fc99e Initial load
duke
parents:
diff changeset
1366 const Form *form = inst_form->_localNames[op_name];
a61af66fc99e Initial load
duke
parents:
diff changeset
1367 OperandForm *op_form = form->is_operand();
a61af66fc99e Initial load
duke
parents:
diff changeset
1368 if( opnds_index == 0 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1369 // Initial setup of new instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
1370 fprintf(fp, " // ----- Initial setup -----\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1371 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1372 // Add control edge for this node
a61af66fc99e Initial load
duke
parents:
diff changeset
1373 fprintf(fp, " root->add_req(_in[0]); // control edge\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1374 // Add unmatched edges from root of match tree
a61af66fc99e Initial load
duke
parents:
diff changeset
1375 int op_base = root_form->oper_input_base(globals);
a61af66fc99e Initial load
duke
parents:
diff changeset
1376 for( int unmatched_edge = 1; unmatched_edge < op_base; ++unmatched_edge ) {
603
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 415
diff changeset
1377 fprintf(fp, " root->add_req(inst%d->in(%d)); // unmatched ideal edge\n",
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1378 inst_num, unmatched_edge);
a61af66fc99e Initial load
duke
parents:
diff changeset
1379 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1380 // If new instruction captures bottom type
1541
b5fdf39b9749 6953576: bottom_type for matched AddPNodes doesn't always agree with ideal
never
parents: 1489
diff changeset
1381 if( root_form->captures_bottom_type(globals) ) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1382 // Get bottom type from instruction whose result we are replacing
603
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 415
diff changeset
1383 fprintf(fp, " root->_bottom_type = inst%d->bottom_type();\n", inst_num);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1384 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1385 // Define result register and result operand
603
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 415
diff changeset
1386 fprintf(fp, " ra_->add_reference(root, inst%d);\n", inst_num);
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 415
diff changeset
1387 fprintf(fp, " ra_->set_oop (root, ra_->is_oop(inst%d));\n", inst_num);
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 415
diff changeset
1388 fprintf(fp, " ra_->set_pair(root->_idx, ra_->get_reg_second(inst%d), ra_->get_reg_first(inst%d));\n", inst_num, inst_num);
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 415
diff changeset
1389 fprintf(fp, " root->_opnds[0] = inst%d->_opnds[0]->clone(C); // result\n", inst_num);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1390 fprintf(fp, " // ----- Done with initial setup -----\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1391 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1392 if( (op_form == NULL) || (op_form->is_base_constant(globals) == Form::none) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1393 // Do not have ideal edges for constants after matching
603
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 415
diff changeset
1394 fprintf(fp, " for( unsigned x%d = inst%d_idx%d; x%d < inst%d_idx%d; x%d++ )\n",
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1395 inst_op_num, inst_num, inst_op_num,
a61af66fc99e Initial load
duke
parents:
diff changeset
1396 inst_op_num, inst_num, inst_op_num+1, inst_op_num );
603
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 415
diff changeset
1397 fprintf(fp, " root->add_req( inst%d->in(x%d) );\n",
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1398 inst_num, inst_op_num );
a61af66fc99e Initial load
duke
parents:
diff changeset
1399 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1400 fprintf(fp, " // no ideal edge for constants after matching\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1401 }
603
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 415
diff changeset
1402 fprintf(fp, " root->_opnds[%d] = inst%d->_opnds[%d]->clone(C);\n",
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1403 opnds_index, inst_num, inst_op_num );
a61af66fc99e Initial load
duke
parents:
diff changeset
1404 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1405 ++opnds_index;
a61af66fc99e Initial load
duke
parents:
diff changeset
1406 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1407 }else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1408 // Replacing subtree with empty-tree
a61af66fc99e Initial load
duke
parents:
diff changeset
1409 assert( false, "ShouldNotReachHere();");
a61af66fc99e Initial load
duke
parents:
diff changeset
1410 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1411
a61af66fc99e Initial load
duke
parents:
diff changeset
1412 // Return the new sub-tree
a61af66fc99e Initial load
duke
parents:
diff changeset
1413 fprintf(fp, " deleted = %d;\n", max_position+1 /*zero to one based*/);
a61af66fc99e Initial load
duke
parents:
diff changeset
1414 fprintf(fp, " return root; // return new root;\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1415 fprintf(fp, " }\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1416 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1417
a61af66fc99e Initial load
duke
parents:
diff changeset
1418
a61af66fc99e Initial load
duke
parents:
diff changeset
1419 // Define the Peephole method for an instruction node
a61af66fc99e Initial load
duke
parents:
diff changeset
1420 void ArchDesc::definePeephole(FILE *fp, InstructForm *node) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1421 // Generate Peephole function header
a61af66fc99e Initial load
duke
parents:
diff changeset
1422 fprintf(fp, "MachNode *%sNode::peephole( Block *block, int block_index, PhaseRegAlloc *ra_, int &deleted, Compile* C ) {\n", node->_ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
1423 fprintf(fp, " bool matches = true;\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1424
a61af66fc99e Initial load
duke
parents:
diff changeset
1425 // Identify the maximum instruction position,
a61af66fc99e Initial load
duke
parents:
diff changeset
1426 // generate temporaries that hold current instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
1427 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1428 // MachNode *inst0 = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1429 // ...
a61af66fc99e Initial load
duke
parents:
diff changeset
1430 // MachNode *instMAX = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1431 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1432 int max_position = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1433 Peephole *peep;
a61af66fc99e Initial load
duke
parents:
diff changeset
1434 for( peep = node->peepholes(); peep != NULL; peep = peep->next() ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1435 PeepMatch *pmatch = peep->match();
a61af66fc99e Initial load
duke
parents:
diff changeset
1436 assert( pmatch != NULL, "fatal(), missing peepmatch rule");
a61af66fc99e Initial load
duke
parents:
diff changeset
1437 if( max_position < pmatch->max_position() ) max_position = pmatch->max_position();
a61af66fc99e Initial load
duke
parents:
diff changeset
1438 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1439 for( int i = 0; i <= max_position; ++i ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1440 if( i == 0 ) {
603
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 415
diff changeset
1441 fprintf(fp, " MachNode *inst0 = this;\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1442 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1443 fprintf(fp, " MachNode *inst%d = NULL;\n", i);
a61af66fc99e Initial load
duke
parents:
diff changeset
1444 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1445 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1446
a61af66fc99e Initial load
duke
parents:
diff changeset
1447 // For each peephole rule in architecture description
a61af66fc99e Initial load
duke
parents:
diff changeset
1448 // Construct a test for the desired instruction sub-tree
a61af66fc99e Initial load
duke
parents:
diff changeset
1449 // then check the constraints
a61af66fc99e Initial load
duke
parents:
diff changeset
1450 // If these match, Generate the new subtree
a61af66fc99e Initial load
duke
parents:
diff changeset
1451 for( peep = node->peepholes(); peep != NULL; peep = peep->next() ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1452 int peephole_number = peep->peephole_number();
a61af66fc99e Initial load
duke
parents:
diff changeset
1453 PeepMatch *pmatch = peep->match();
a61af66fc99e Initial load
duke
parents:
diff changeset
1454 PeepConstraint *pconstraint = peep->constraints();
a61af66fc99e Initial load
duke
parents:
diff changeset
1455 PeepReplace *preplace = peep->replacement();
a61af66fc99e Initial load
duke
parents:
diff changeset
1456
a61af66fc99e Initial load
duke
parents:
diff changeset
1457 // Root of this peephole is the current MachNode
a61af66fc99e Initial load
duke
parents:
diff changeset
1458 assert( true, // %%name?%% strcmp( node->_ident, pmatch->name(0) ) == 0,
a61af66fc99e Initial load
duke
parents:
diff changeset
1459 "root of PeepMatch does not match instruction");
a61af66fc99e Initial load
duke
parents:
diff changeset
1460
a61af66fc99e Initial load
duke
parents:
diff changeset
1461 // Make each peephole rule individually selectable
a61af66fc99e Initial load
duke
parents:
diff changeset
1462 fprintf(fp, " if( (OptoPeepholeAt == -1) || (OptoPeepholeAt==%d) ) {\n", peephole_number);
a61af66fc99e Initial load
duke
parents:
diff changeset
1463 fprintf(fp, " matches = true;\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1464 // Scan the peepmatch and output a test for each instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
1465 check_peepmatch_instruction_sequence( fp, pmatch, pconstraint );
a61af66fc99e Initial load
duke
parents:
diff changeset
1466
a61af66fc99e Initial load
duke
parents:
diff changeset
1467 // Check constraints and build replacement inside scope
a61af66fc99e Initial load
duke
parents:
diff changeset
1468 fprintf(fp, " // If instruction subtree matches\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1469 fprintf(fp, " if( matches ) {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1470
a61af66fc99e Initial load
duke
parents:
diff changeset
1471 // Generate tests for the constraints
a61af66fc99e Initial load
duke
parents:
diff changeset
1472 check_peepconstraints( fp, _globalNames, pmatch, pconstraint );
a61af66fc99e Initial load
duke
parents:
diff changeset
1473
a61af66fc99e Initial load
duke
parents:
diff changeset
1474 // Construct the new sub-tree
a61af66fc99e Initial load
duke
parents:
diff changeset
1475 generate_peepreplace( fp, _globalNames, pmatch, pconstraint, preplace, max_position );
a61af66fc99e Initial load
duke
parents:
diff changeset
1476
a61af66fc99e Initial load
duke
parents:
diff changeset
1477 // End of scope for this peephole's constraints
a61af66fc99e Initial load
duke
parents:
diff changeset
1478 fprintf(fp, " }\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1479 // Closing brace '}' to make each peephole rule individually selectable
a61af66fc99e Initial load
duke
parents:
diff changeset
1480 fprintf(fp, " } // end of peephole rule #%d\n", peephole_number);
a61af66fc99e Initial load
duke
parents:
diff changeset
1481 fprintf(fp, "\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1482 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1483
a61af66fc99e Initial load
duke
parents:
diff changeset
1484 fprintf(fp, " return NULL; // No peephole rules matched\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1485 fprintf(fp, "}\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1486 fprintf(fp, "\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1487 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1488
a61af66fc99e Initial load
duke
parents:
diff changeset
1489 // Define the Expand method for an instruction node
a61af66fc99e Initial load
duke
parents:
diff changeset
1490 void ArchDesc::defineExpand(FILE *fp, InstructForm *node) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1491 unsigned cnt = 0; // Count nodes we have expand into
a61af66fc99e Initial load
duke
parents:
diff changeset
1492 unsigned i;
a61af66fc99e Initial load
duke
parents:
diff changeset
1493
a61af66fc99e Initial load
duke
parents:
diff changeset
1494 // Generate Expand function header
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
1495 fprintf(fp, "MachNode* %sNode::Expand(State* state, Node_List& proj_list, Node* mem) {\n", node->_ident);
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
1496 fprintf(fp, " Compile* C = Compile::current();\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1497 // Generate expand code
a61af66fc99e Initial load
duke
parents:
diff changeset
1498 if( node->expands() ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1499 const char *opid;
a61af66fc99e Initial load
duke
parents:
diff changeset
1500 int new_pos, exp_pos;
a61af66fc99e Initial load
duke
parents:
diff changeset
1501 const char *new_id = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1502 const Form *frm = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1503 InstructForm *new_inst = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1504 OperandForm *new_oper = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1505 unsigned numo = node->num_opnds() +
a61af66fc99e Initial load
duke
parents:
diff changeset
1506 node->_exprule->_newopers.count();
a61af66fc99e Initial load
duke
parents:
diff changeset
1507
a61af66fc99e Initial load
duke
parents:
diff changeset
1508 // If necessary, generate any operands created in expand rule
a61af66fc99e Initial load
duke
parents:
diff changeset
1509 if (node->_exprule->_newopers.count()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1510 for(node->_exprule->_newopers.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
1511 (new_id = node->_exprule->_newopers.iter()) != NULL; cnt++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1512 frm = node->_localNames[new_id];
a61af66fc99e Initial load
duke
parents:
diff changeset
1513 assert(frm, "Invalid entry in new operands list of expand rule");
a61af66fc99e Initial load
duke
parents:
diff changeset
1514 new_oper = frm->is_operand();
a61af66fc99e Initial load
duke
parents:
diff changeset
1515 char *tmp = (char *)node->_exprule->_newopconst[new_id];
a61af66fc99e Initial load
duke
parents:
diff changeset
1516 if (tmp == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1517 fprintf(fp," MachOper *op%d = new (C) %sOper();\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
1518 cnt, new_oper->_ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
1519 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1520 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1521 fprintf(fp," MachOper *op%d = new (C) %sOper(%s);\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
1522 cnt, new_oper->_ident, tmp);
a61af66fc99e Initial load
duke
parents:
diff changeset
1523 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1524 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1525 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1526 cnt = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1527 // Generate the temps to use for DAG building
a61af66fc99e Initial load
duke
parents:
diff changeset
1528 for(i = 0; i < numo; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1529 if (i < node->num_opnds()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1530 fprintf(fp," MachNode *tmp%d = this;\n", i);
a61af66fc99e Initial load
duke
parents:
diff changeset
1531 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1532 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1533 fprintf(fp," MachNode *tmp%d = NULL;\n", i);
a61af66fc99e Initial load
duke
parents:
diff changeset
1534 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1535 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1536 // Build mapping from num_edges to local variables
a61af66fc99e Initial load
duke
parents:
diff changeset
1537 fprintf(fp," unsigned num0 = 0;\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1538 for( i = 1; i < node->num_opnds(); i++ ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1539 fprintf(fp," unsigned num%d = opnd_array(%d)->num_edges();\n",i,i);
a61af66fc99e Initial load
duke
parents:
diff changeset
1540 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1541
a61af66fc99e Initial load
duke
parents:
diff changeset
1542 // Build a mapping from operand index to input edges
a61af66fc99e Initial load
duke
parents:
diff changeset
1543 fprintf(fp," unsigned idx0 = oper_input_base();\n");
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
1544
1203
844a9d73ec22 6916644: C2 compiler crash on x86
never
parents: 785
diff changeset
1545 // The order in which the memory input is added to a node is very
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
1546 // strange. Store nodes get a memory input before Expand is
1203
844a9d73ec22 6916644: C2 compiler crash on x86
never
parents: 785
diff changeset
1547 // called and other nodes get it afterwards or before depending on
844a9d73ec22 6916644: C2 compiler crash on x86
never
parents: 785
diff changeset
1548 // match order so oper_input_base is wrong during expansion. This
844a9d73ec22 6916644: C2 compiler crash on x86
never
parents: 785
diff changeset
1549 // code adjusts it so that expansion will work correctly.
844a9d73ec22 6916644: C2 compiler crash on x86
never
parents: 785
diff changeset
1550 int has_memory_edge = node->_matrule->needs_ideal_memory_edge(_globalNames);
844a9d73ec22 6916644: C2 compiler crash on x86
never
parents: 785
diff changeset
1551 if (has_memory_edge) {
844a9d73ec22 6916644: C2 compiler crash on x86
never
parents: 785
diff changeset
1552 fprintf(fp," if (mem == (Node*)1) {\n");
844a9d73ec22 6916644: C2 compiler crash on x86
never
parents: 785
diff changeset
1553 fprintf(fp," idx0--; // Adjust base because memory edge hasn't been inserted yet\n");
844a9d73ec22 6916644: C2 compiler crash on x86
never
parents: 785
diff changeset
1554 fprintf(fp," }\n");
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
1555 }
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
1556
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1557 for( i = 0; i < node->num_opnds(); i++ ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1558 fprintf(fp," unsigned idx%d = idx%d + num%d;\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
1559 i+1,i,i);
a61af66fc99e Initial load
duke
parents:
diff changeset
1560 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1561
a61af66fc99e Initial load
duke
parents:
diff changeset
1562 // Declare variable to hold root of expansion
a61af66fc99e Initial load
duke
parents:
diff changeset
1563 fprintf(fp," MachNode *result = NULL;\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1564
a61af66fc99e Initial load
duke
parents:
diff changeset
1565 // Iterate over the instructions 'node' expands into
a61af66fc99e Initial load
duke
parents:
diff changeset
1566 ExpandRule *expand = node->_exprule;
a61af66fc99e Initial load
duke
parents:
diff changeset
1567 NameAndList *expand_instr = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1568 for(expand->reset_instructions();
a61af66fc99e Initial load
duke
parents:
diff changeset
1569 (expand_instr = expand->iter_instructions()) != NULL; cnt++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1570 new_id = expand_instr->name();
a61af66fc99e Initial load
duke
parents:
diff changeset
1571
a61af66fc99e Initial load
duke
parents:
diff changeset
1572 InstructForm* expand_instruction = (InstructForm*)globalAD->globalNames()[new_id];
14431
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
1573
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
1574 if (!expand_instruction) {
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
1575 globalAD->syntax_err(node->_linenum, "In %s: instruction %s used in expand not declared\n",
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
1576 node->_ident, new_id);
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
1577 continue;
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
1578 }
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
1579
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1580 if (expand_instruction->has_temps()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1581 globalAD->syntax_err(node->_linenum, "In %s: expand rules using instructs with TEMPs aren't supported: %s",
a61af66fc99e Initial load
duke
parents:
diff changeset
1582 node->_ident, new_id);
a61af66fc99e Initial load
duke
parents:
diff changeset
1583 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1584
a61af66fc99e Initial load
duke
parents:
diff changeset
1585 // Build the node for the instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
1586 fprintf(fp,"\n %sNode *n%d = new (C) %sNode();\n", new_id, cnt, new_id);
a61af66fc99e Initial load
duke
parents:
diff changeset
1587 // Add control edge for this node
a61af66fc99e Initial load
duke
parents:
diff changeset
1588 fprintf(fp," n%d->add_req(_in[0]);\n", cnt);
a61af66fc99e Initial load
duke
parents:
diff changeset
1589 // Build the operand for the value this node defines.
a61af66fc99e Initial load
duke
parents:
diff changeset
1590 Form *form = (Form*)_globalNames[new_id];
a61af66fc99e Initial load
duke
parents:
diff changeset
1591 assert( form, "'new_id' must be a defined form name");
a61af66fc99e Initial load
duke
parents:
diff changeset
1592 // Grab the InstructForm for the new instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
1593 new_inst = form->is_instruction();
a61af66fc99e Initial load
duke
parents:
diff changeset
1594 assert( new_inst, "'new_id' must be an instruction name");
a61af66fc99e Initial load
duke
parents:
diff changeset
1595 if( node->is_ideal_if() && new_inst->is_ideal_if() ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1596 fprintf(fp, " ((MachIfNode*)n%d)->_prob = _prob;\n",cnt);
a61af66fc99e Initial load
duke
parents:
diff changeset
1597 fprintf(fp, " ((MachIfNode*)n%d)->_fcnt = _fcnt;\n",cnt);
a61af66fc99e Initial load
duke
parents:
diff changeset
1598 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1599
a61af66fc99e Initial load
duke
parents:
diff changeset
1600 if( node->is_ideal_fastlock() && new_inst->is_ideal_fastlock() ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1601 fprintf(fp, " ((MachFastLockNode*)n%d)->_counters = _counters;\n",cnt);
17780
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents: 17467
diff changeset
1602 fprintf(fp, " ((MachFastLockNode*)n%d)->_rtm_counters = _rtm_counters;\n",cnt);
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents: 17467
diff changeset
1603 fprintf(fp, " ((MachFastLockNode*)n%d)->_stack_rtm_counters = _stack_rtm_counters;\n",cnt);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1604 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1605
6802
0702f188baeb 7200233: C2: can't use expand rules for vector instruction rules
kvn
parents: 6725
diff changeset
1606 // Fill in the bottom_type where requested
0702f188baeb 7200233: C2: can't use expand rules for vector instruction rules
kvn
parents: 6725
diff changeset
1607 if (node->captures_bottom_type(_globalNames) &&
0702f188baeb 7200233: C2: can't use expand rules for vector instruction rules
kvn
parents: 6725
diff changeset
1608 new_inst->captures_bottom_type(_globalNames)) {
0702f188baeb 7200233: C2: can't use expand rules for vector instruction rules
kvn
parents: 6725
diff changeset
1609 fprintf(fp, " ((MachTypeNode*)n%d)->_bottom_type = bottom_type();\n", cnt);
0702f188baeb 7200233: C2: can't use expand rules for vector instruction rules
kvn
parents: 6725
diff changeset
1610 }
0702f188baeb 7200233: C2: can't use expand rules for vector instruction rules
kvn
parents: 6725
diff changeset
1611
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1612 const char *resultOper = new_inst->reduce_result();
a61af66fc99e Initial load
duke
parents:
diff changeset
1613 fprintf(fp," n%d->set_opnd_array(0, state->MachOperGenerator( %s, C ));\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
1614 cnt, machOperEnum(resultOper));
a61af66fc99e Initial load
duke
parents:
diff changeset
1615
a61af66fc99e Initial load
duke
parents:
diff changeset
1616 // get the formal operand NameList
a61af66fc99e Initial load
duke
parents:
diff changeset
1617 NameList *formal_lst = &new_inst->_parameters;
a61af66fc99e Initial load
duke
parents:
diff changeset
1618 formal_lst->reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
1619
a61af66fc99e Initial load
duke
parents:
diff changeset
1620 // Handle any memory operand
a61af66fc99e Initial load
duke
parents:
diff changeset
1621 int memory_operand = new_inst->memory_operand(_globalNames);
a61af66fc99e Initial load
duke
parents:
diff changeset
1622 if( memory_operand != InstructForm::NO_MEMORY_OPERAND ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1623 int node_mem_op = node->memory_operand(_globalNames);
a61af66fc99e Initial load
duke
parents:
diff changeset
1624 assert( node_mem_op != InstructForm::NO_MEMORY_OPERAND,
a61af66fc99e Initial load
duke
parents:
diff changeset
1625 "expand rule member needs memory but top-level inst doesn't have any" );
1203
844a9d73ec22 6916644: C2 compiler crash on x86
never
parents: 785
diff changeset
1626 if (has_memory_edge) {
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
1627 // Copy memory edge
1203
844a9d73ec22 6916644: C2 compiler crash on x86
never
parents: 785
diff changeset
1628 fprintf(fp," if (mem != (Node*)1) {\n");
844a9d73ec22 6916644: C2 compiler crash on x86
never
parents: 785
diff changeset
1629 fprintf(fp," n%d->add_req(_in[1]);\t// Add memory edge\n", cnt);
844a9d73ec22 6916644: C2 compiler crash on x86
never
parents: 785
diff changeset
1630 fprintf(fp," }\n");
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
1631 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1632 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1633
a61af66fc99e Initial load
duke
parents:
diff changeset
1634 // Iterate over the new instruction's operands
415
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 196
diff changeset
1635 int prev_pos = -1;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1636 for( expand_instr->reset(); (opid = expand_instr->iter()) != NULL; ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1637 // Use 'parameter' at current position in list of new instruction's formals
a61af66fc99e Initial load
duke
parents:
diff changeset
1638 // instead of 'opid' when looking up info internal to new_inst
a61af66fc99e Initial load
duke
parents:
diff changeset
1639 const char *parameter = formal_lst->iter();
14431
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
1640 if (!parameter) {
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
1641 globalAD->syntax_err(node->_linenum, "Operand %s of expand instruction %s has"
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
1642 " no equivalent in new instruction %s.",
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
1643 opid, node->_ident, new_inst->_ident);
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
1644 assert(0, "Wrong expand");
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
1645 }
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
1646
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1647 // Check for an operand which is created in the expand rule
a61af66fc99e Initial load
duke
parents:
diff changeset
1648 if ((exp_pos = node->_exprule->_newopers.index(opid)) != -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1649 new_pos = new_inst->operand_position(parameter,Component::USE);
a61af66fc99e Initial load
duke
parents:
diff changeset
1650 exp_pos += node->num_opnds();
a61af66fc99e Initial load
duke
parents:
diff changeset
1651 // If there is no use of the created operand, just skip it
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
1652 if (new_pos != NameList::Not_in_list) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1653 //Copy the operand from the original made above
a61af66fc99e Initial load
duke
parents:
diff changeset
1654 fprintf(fp," n%d->set_opnd_array(%d, op%d->clone(C)); // %s\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
1655 cnt, new_pos, exp_pos-node->num_opnds(), opid);
a61af66fc99e Initial load
duke
parents:
diff changeset
1656 // Check for who defines this operand & add edge if needed
a61af66fc99e Initial load
duke
parents:
diff changeset
1657 fprintf(fp," if(tmp%d != NULL)\n", exp_pos);
a61af66fc99e Initial load
duke
parents:
diff changeset
1658 fprintf(fp," n%d->add_req(tmp%d);\n", cnt, exp_pos);
a61af66fc99e Initial load
duke
parents:
diff changeset
1659 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1660 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1661 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1662 // Use operand name to get an index into instruction component list
a61af66fc99e Initial load
duke
parents:
diff changeset
1663 // ins = (InstructForm *) _globalNames[new_id];
a61af66fc99e Initial load
duke
parents:
diff changeset
1664 exp_pos = node->operand_position_format(opid);
a61af66fc99e Initial load
duke
parents:
diff changeset
1665 assert(exp_pos != -1, "Bad expand rule");
415
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 196
diff changeset
1666 if (prev_pos > exp_pos && expand_instruction->_matrule != NULL) {
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 196
diff changeset
1667 // For the add_req calls below to work correctly they need
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 196
diff changeset
1668 // to added in the same order that a match would add them.
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 196
diff changeset
1669 // This means that they would need to be in the order of
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 196
diff changeset
1670 // the components list instead of the formal parameters.
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 196
diff changeset
1671 // This is a sort of hidden invariant that previously
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 196
diff changeset
1672 // wasn't checked and could lead to incorrectly
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 196
diff changeset
1673 // constructed nodes.
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 196
diff changeset
1674 syntax_err(node->_linenum, "For expand in %s to work, parameter declaration order in %s must follow matchrule\n",
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 196
diff changeset
1675 node->_ident, new_inst->_ident);
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 196
diff changeset
1676 }
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 196
diff changeset
1677 prev_pos = exp_pos;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1678
a61af66fc99e Initial load
duke
parents:
diff changeset
1679 new_pos = new_inst->operand_position(parameter,Component::USE);
a61af66fc99e Initial load
duke
parents:
diff changeset
1680 if (new_pos != -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1681 // Copy the operand from the ExpandNode to the new node
a61af66fc99e Initial load
duke
parents:
diff changeset
1682 fprintf(fp," n%d->set_opnd_array(%d, opnd_array(%d)->clone(C)); // %s\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
1683 cnt, new_pos, exp_pos, opid);
a61af66fc99e Initial load
duke
parents:
diff changeset
1684 // For each operand add appropriate input edges by looking at tmp's
a61af66fc99e Initial load
duke
parents:
diff changeset
1685 fprintf(fp," if(tmp%d == this) {\n", exp_pos);
a61af66fc99e Initial load
duke
parents:
diff changeset
1686 // Grab corresponding edges from ExpandNode and insert them here
a61af66fc99e Initial load
duke
parents:
diff changeset
1687 fprintf(fp," for(unsigned i = 0; i < num%d; i++) {\n", exp_pos);
a61af66fc99e Initial load
duke
parents:
diff changeset
1688 fprintf(fp," n%d->add_req(_in[i + idx%d]);\n", cnt, exp_pos);
a61af66fc99e Initial load
duke
parents:
diff changeset
1689 fprintf(fp," }\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1690 fprintf(fp," }\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1691 // This value is generated by one of the new instructions
a61af66fc99e Initial load
duke
parents:
diff changeset
1692 fprintf(fp," else n%d->add_req(tmp%d);\n", cnt, exp_pos);
a61af66fc99e Initial load
duke
parents:
diff changeset
1693 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1694 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1695
a61af66fc99e Initial load
duke
parents:
diff changeset
1696 // Update the DAG tmp's for values defined by this instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
1697 int new_def_pos = new_inst->operand_position(parameter,Component::DEF);
a61af66fc99e Initial load
duke
parents:
diff changeset
1698 Effect *eform = (Effect *)new_inst->_effects[parameter];
a61af66fc99e Initial load
duke
parents:
diff changeset
1699 // If this operand is a definition in either an effects rule
a61af66fc99e Initial load
duke
parents:
diff changeset
1700 // or a match rule
a61af66fc99e Initial load
duke
parents:
diff changeset
1701 if((eform) && (is_def(eform->_use_def))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1702 // Update the temp associated with this operand
a61af66fc99e Initial load
duke
parents:
diff changeset
1703 fprintf(fp," tmp%d = n%d;\n", exp_pos, cnt);
a61af66fc99e Initial load
duke
parents:
diff changeset
1704 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1705 else if( new_def_pos != -1 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1706 // Instruction defines a value but user did not declare it
a61af66fc99e Initial load
duke
parents:
diff changeset
1707 // in the 'effect' clause
a61af66fc99e Initial load
duke
parents:
diff changeset
1708 fprintf(fp," tmp%d = n%d;\n", exp_pos, cnt);
a61af66fc99e Initial load
duke
parents:
diff changeset
1709 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1710 } // done iterating over a new instruction's operands
a61af66fc99e Initial load
duke
parents:
diff changeset
1711
a61af66fc99e Initial load
duke
parents:
diff changeset
1712 // Invoke Expand() for the newly created instruction.
1203
844a9d73ec22 6916644: C2 compiler crash on x86
never
parents: 785
diff changeset
1713 fprintf(fp," result = n%d->Expand( state, proj_list, mem );\n", cnt);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1714 assert( !new_inst->expands(), "Do not have complete support for recursive expansion");
a61af66fc99e Initial load
duke
parents:
diff changeset
1715 } // done iterating over new instructions
a61af66fc99e Initial load
duke
parents:
diff changeset
1716 fprintf(fp,"\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1717 } // done generating expand rule
a61af66fc99e Initial load
duke
parents:
diff changeset
1718
2254
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1719 // Generate projections for instruction's additional DEFs and KILLs
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1720 if( ! node->expands() && (node->needs_projections() || node->has_temps())) {
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1721 // Get string representing the MachNode that projections point at
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1722 const char *machNode = "this";
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1723 // Generate the projections
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1724 fprintf(fp," // Add projection edges for additional defs or kills\n");
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1725
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1726 // Examine each component to see if it is a DEF or KILL
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1727 node->_components.reset();
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1728 // Skip the first component, if already handled as (SET dst (...))
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1729 Component *comp = NULL;
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1730 // For kills, the choice of projection numbers is arbitrary
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1731 int proj_no = 1;
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1732 bool declared_def = false;
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1733 bool declared_kill = false;
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1734
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1735 while( (comp = node->_components.iter()) != NULL ) {
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1736 // Lookup register class associated with operand type
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1737 Form *form = (Form*)_globalNames[comp->_type];
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1738 assert( form, "component type must be a defined form");
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1739 OperandForm *op = form->is_operand();
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1740
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1741 if (comp->is(Component::TEMP)) {
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1742 fprintf(fp, " // TEMP %s\n", comp->_name);
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1743 if (!declared_def) {
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1744 // Define the variable "def" to hold new MachProjNodes
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1745 fprintf(fp, " MachTempNode *def;\n");
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1746 declared_def = true;
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1747 }
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1748 if (op && op->_interface && op->_interface->is_RegInterface()) {
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1749 fprintf(fp," def = new (C) MachTempNode(state->MachOperGenerator( %s, C ));\n",
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1750 machOperEnum(op->_ident));
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1751 fprintf(fp," add_req(def);\n");
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1752 // The operand for TEMP is already constructed during
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1753 // this mach node construction, see buildMachNode().
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1754 //
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1755 // int idx = node->operand_position_format(comp->_name);
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1756 // fprintf(fp," set_opnd_array(%d, state->MachOperGenerator( %s, C ));\n",
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1757 // idx, machOperEnum(op->_ident));
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1758 } else {
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1759 assert(false, "can't have temps which aren't registers");
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1760 }
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1761 } else if (comp->isa(Component::KILL)) {
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1762 fprintf(fp, " // DEF/KILL %s\n", comp->_name);
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1763
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1764 if (!declared_kill) {
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1765 // Define the variable "kill" to hold new MachProjNodes
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1766 fprintf(fp, " MachProjNode *kill;\n");
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1767 declared_kill = true;
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1768 }
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1769
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1770 assert( op, "Support additional KILLS for base operands");
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1771 const char *regmask = reg_mask(*op);
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1772 const char *ideal_type = op->ideal_type(_globalNames, _register);
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1773
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1774 if (!op->is_bound_register()) {
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1775 syntax_err(node->_linenum, "In %s only bound registers can be killed: %s %s\n",
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1776 node->_ident, comp->_type, comp->_name);
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1777 }
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1778
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1779 fprintf(fp," kill = ");
6804
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6802
diff changeset
1780 fprintf(fp,"new (C) MachProjNode( %s, %d, (%s), Op_%s );\n",
2254
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1781 machNode, proj_no++, regmask, ideal_type);
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1782 fprintf(fp," proj_list.push(kill);\n");
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1783 }
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1784 }
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1785 }
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1786
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
1787 if( !node->expands() && node->_matrule != NULL ) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1788 // Remove duplicated operands and inputs which use the same name.
a61af66fc99e Initial load
duke
parents:
diff changeset
1789 // Seach through match operands for the same name usage.
a61af66fc99e Initial load
duke
parents:
diff changeset
1790 uint cur_num_opnds = node->num_opnds();
a61af66fc99e Initial load
duke
parents:
diff changeset
1791 if( cur_num_opnds > 1 && cur_num_opnds != node->num_unique_opnds() ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1792 Component *comp = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1793 // Build mapping from num_edges to local variables
a61af66fc99e Initial load
duke
parents:
diff changeset
1794 fprintf(fp," unsigned num0 = 0;\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1795 for( i = 1; i < cur_num_opnds; i++ ) {
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
1796 fprintf(fp," unsigned num%d = opnd_array(%d)->num_edges();",i,i);
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
1797 fprintf(fp, " \t// %s\n", node->opnd_ident(i));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1798 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1799 // Build a mapping from operand index to input edges
a61af66fc99e Initial load
duke
parents:
diff changeset
1800 fprintf(fp," unsigned idx0 = oper_input_base();\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1801 for( i = 0; i < cur_num_opnds; i++ ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1802 fprintf(fp," unsigned idx%d = idx%d + num%d;\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
1803 i+1,i,i);
a61af66fc99e Initial load
duke
parents:
diff changeset
1804 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1805
a61af66fc99e Initial load
duke
parents:
diff changeset
1806 uint new_num_opnds = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
1807 node->_components.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
1808 // Skip first unique operands.
a61af66fc99e Initial load
duke
parents:
diff changeset
1809 for( i = 1; i < cur_num_opnds; i++ ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1810 comp = node->_components.iter();
10389
f15fe46d8c00 8015266: fix some -Wsign-compare warnings in adlc
twisti
parents: 9078
diff changeset
1811 if (i != node->unique_opnds_idx(i)) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1812 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1813 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1814 new_num_opnds++;
a61af66fc99e Initial load
duke
parents:
diff changeset
1815 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1816 // Replace not unique operands with next unique operands.
a61af66fc99e Initial load
duke
parents:
diff changeset
1817 for( ; i < cur_num_opnds; i++ ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1818 comp = node->_components.iter();
10389
f15fe46d8c00 8015266: fix some -Wsign-compare warnings in adlc
twisti
parents: 9078
diff changeset
1819 uint j = node->unique_opnds_idx(i);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1820 // unique_opnds_idx(i) is unique if unique_opnds_idx(j) is not unique.
a61af66fc99e Initial load
duke
parents:
diff changeset
1821 if( j != node->unique_opnds_idx(j) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1822 fprintf(fp," set_opnd_array(%d, opnd_array(%d)->clone(C)); // %s\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
1823 new_num_opnds, i, comp->_name);
a61af66fc99e Initial load
duke
parents:
diff changeset
1824 // delete not unique edges here
a61af66fc99e Initial load
duke
parents:
diff changeset
1825 fprintf(fp," for(unsigned i = 0; i < num%d; i++) {\n", i);
a61af66fc99e Initial load
duke
parents:
diff changeset
1826 fprintf(fp," set_req(i + idx%d, _in[i + idx%d]);\n", new_num_opnds, i);
a61af66fc99e Initial load
duke
parents:
diff changeset
1827 fprintf(fp," }\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1828 fprintf(fp," num%d = num%d;\n", new_num_opnds, i);
a61af66fc99e Initial load
duke
parents:
diff changeset
1829 fprintf(fp," idx%d = idx%d + num%d;\n", new_num_opnds+1, new_num_opnds, new_num_opnds);
a61af66fc99e Initial load
duke
parents:
diff changeset
1830 new_num_opnds++;
a61af66fc99e Initial load
duke
parents:
diff changeset
1831 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1832 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1833 // delete the rest of edges
a61af66fc99e Initial load
duke
parents:
diff changeset
1834 fprintf(fp," for(int i = idx%d - 1; i >= (int)idx%d; i--) {\n", cur_num_opnds, new_num_opnds);
603
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 415
diff changeset
1835 fprintf(fp," del_req(i);\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1836 fprintf(fp," }\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1837 fprintf(fp," _num_opnds = %d;\n", new_num_opnds);
785
2056494941db 6814842: Load shortening optimizations
twisti
parents: 624
diff changeset
1838 assert(new_num_opnds == node->num_unique_opnds(), "what?");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1839 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1840 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1841
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
1842 // If the node is a MachConstantNode, insert the MachConstantBaseNode edge.
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
1843 // NOTE: this edge must be the last input (see MachConstantNode::mach_constant_base_node_input).
14434
318d0622a6d7 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 14431
diff changeset
1844 // There are nodes that don't use $constantablebase, but still require that it
318d0622a6d7 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 14431
diff changeset
1845 // is an input to the node. Example: divF_reg_immN, Repl32B_imm on x86_64.
318d0622a6d7 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 14431
diff changeset
1846 if (node->is_mach_constant() || node->needs_constant_base()) {
17791
ad3b94907eed 8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents: 14444
diff changeset
1847 if (node->is_ideal_call() != Form::invalid_type &&
ad3b94907eed 8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents: 14444
diff changeset
1848 node->is_ideal_call() != Form::JAVA_LEAF) {
ad3b94907eed 8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents: 14444
diff changeset
1849 fprintf(fp, " // MachConstantBaseNode added in matcher.\n");
ad3b94907eed 8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents: 14444
diff changeset
1850 _needs_clone_jvms = true;
ad3b94907eed 8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents: 14444
diff changeset
1851 } else {
ad3b94907eed 8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents: 14444
diff changeset
1852 fprintf(fp, " add_req(C->mach_constant_base_node());\n");
ad3b94907eed 8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents: 14444
diff changeset
1853 }
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
1854 }
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
1855
17791
ad3b94907eed 8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents: 14444
diff changeset
1856 fprintf(fp, "\n");
ad3b94907eed 8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents: 14444
diff changeset
1857 if (node->expands()) {
ad3b94907eed 8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents: 14444
diff changeset
1858 fprintf(fp, " return result;\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1859 } else {
17791
ad3b94907eed 8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents: 14444
diff changeset
1860 fprintf(fp, " return this;\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1861 }
17791
ad3b94907eed 8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents: 14444
diff changeset
1862 fprintf(fp, "}\n");
ad3b94907eed 8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents: 14444
diff changeset
1863 fprintf(fp, "\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1864 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1865
a61af66fc99e Initial load
duke
parents:
diff changeset
1866
a61af66fc99e Initial load
duke
parents:
diff changeset
1867 //------------------------------Emit Routines----------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1868 // Special classes and routines for defining node emit routines which output
a61af66fc99e Initial load
duke
parents:
diff changeset
1869 // target specific instruction object encodings.
a61af66fc99e Initial load
duke
parents:
diff changeset
1870 // Define the ___Node::emit() routine
a61af66fc99e Initial load
duke
parents:
diff changeset
1871 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1872 // (1) void ___Node::emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
1873 // (2) // ... encoding defined by user
a61af66fc99e Initial load
duke
parents:
diff changeset
1874 // (3)
a61af66fc99e Initial load
duke
parents:
diff changeset
1875 // (4) }
a61af66fc99e Initial load
duke
parents:
diff changeset
1876 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1877
a61af66fc99e Initial load
duke
parents:
diff changeset
1878 class DefineEmitState {
a61af66fc99e Initial load
duke
parents:
diff changeset
1879 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
1880 enum reloc_format { RELOC_NONE = -1,
a61af66fc99e Initial load
duke
parents:
diff changeset
1881 RELOC_IMMEDIATE = 0,
a61af66fc99e Initial load
duke
parents:
diff changeset
1882 RELOC_DISP = 1,
a61af66fc99e Initial load
duke
parents:
diff changeset
1883 RELOC_CALL_DISP = 2 };
a61af66fc99e Initial load
duke
parents:
diff changeset
1884 enum literal_status{ LITERAL_NOT_SEEN = 0,
a61af66fc99e Initial load
duke
parents:
diff changeset
1885 LITERAL_SEEN = 1,
a61af66fc99e Initial load
duke
parents:
diff changeset
1886 LITERAL_ACCESSED = 2,
a61af66fc99e Initial load
duke
parents:
diff changeset
1887 LITERAL_OUTPUT = 3 };
a61af66fc99e Initial load
duke
parents:
diff changeset
1888 // Temporaries that describe current operand
a61af66fc99e Initial load
duke
parents:
diff changeset
1889 bool _cleared;
a61af66fc99e Initial load
duke
parents:
diff changeset
1890 OpClassForm *_opclass;
a61af66fc99e Initial load
duke
parents:
diff changeset
1891 OperandForm *_operand;
a61af66fc99e Initial load
duke
parents:
diff changeset
1892 int _operand_idx;
a61af66fc99e Initial load
duke
parents:
diff changeset
1893 const char *_local_name;
a61af66fc99e Initial load
duke
parents:
diff changeset
1894 const char *_operand_name;
a61af66fc99e Initial load
duke
parents:
diff changeset
1895 bool _doing_disp;
a61af66fc99e Initial load
duke
parents:
diff changeset
1896 bool _doing_constant;
a61af66fc99e Initial load
duke
parents:
diff changeset
1897 Form::DataType _constant_type;
a61af66fc99e Initial load
duke
parents:
diff changeset
1898 DefineEmitState::literal_status _constant_status;
a61af66fc99e Initial load
duke
parents:
diff changeset
1899 DefineEmitState::literal_status _reg_status;
a61af66fc99e Initial load
duke
parents:
diff changeset
1900 bool _doing_emit8;
a61af66fc99e Initial load
duke
parents:
diff changeset
1901 bool _doing_emit_d32;
a61af66fc99e Initial load
duke
parents:
diff changeset
1902 bool _doing_emit_d16;
a61af66fc99e Initial load
duke
parents:
diff changeset
1903 bool _doing_emit_hi;
a61af66fc99e Initial load
duke
parents:
diff changeset
1904 bool _doing_emit_lo;
a61af66fc99e Initial load
duke
parents:
diff changeset
1905 bool _may_reloc;
a61af66fc99e Initial load
duke
parents:
diff changeset
1906 reloc_format _reloc_form;
a61af66fc99e Initial load
duke
parents:
diff changeset
1907 const char * _reloc_type;
a61af66fc99e Initial load
duke
parents:
diff changeset
1908 bool _processing_noninput;
a61af66fc99e Initial load
duke
parents:
diff changeset
1909
a61af66fc99e Initial load
duke
parents:
diff changeset
1910 NameList _strings_to_emit;
a61af66fc99e Initial load
duke
parents:
diff changeset
1911
a61af66fc99e Initial load
duke
parents:
diff changeset
1912 // Stable state, set by constructor
a61af66fc99e Initial load
duke
parents:
diff changeset
1913 ArchDesc &_AD;
a61af66fc99e Initial load
duke
parents:
diff changeset
1914 FILE *_fp;
a61af66fc99e Initial load
duke
parents:
diff changeset
1915 EncClass &_encoding;
a61af66fc99e Initial load
duke
parents:
diff changeset
1916 InsEncode &_ins_encode;
a61af66fc99e Initial load
duke
parents:
diff changeset
1917 InstructForm &_inst;
a61af66fc99e Initial load
duke
parents:
diff changeset
1918
a61af66fc99e Initial load
duke
parents:
diff changeset
1919 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
1920 DefineEmitState(FILE *fp, ArchDesc &AD, EncClass &encoding,
a61af66fc99e Initial load
duke
parents:
diff changeset
1921 InsEncode &ins_encode, InstructForm &inst)
a61af66fc99e Initial load
duke
parents:
diff changeset
1922 : _AD(AD), _fp(fp), _encoding(encoding), _ins_encode(ins_encode), _inst(inst) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1923 clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
1924 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1925
a61af66fc99e Initial load
duke
parents:
diff changeset
1926 void clear() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1927 _cleared = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1928 _opclass = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1929 _operand = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1930 _operand_idx = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1931 _local_name = "";
a61af66fc99e Initial load
duke
parents:
diff changeset
1932 _operand_name = "";
a61af66fc99e Initial load
duke
parents:
diff changeset
1933 _doing_disp = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1934 _doing_constant= false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1935 _constant_type = Form::none;
a61af66fc99e Initial load
duke
parents:
diff changeset
1936 _constant_status = LITERAL_NOT_SEEN;
a61af66fc99e Initial load
duke
parents:
diff changeset
1937 _reg_status = LITERAL_NOT_SEEN;
a61af66fc99e Initial load
duke
parents:
diff changeset
1938 _doing_emit8 = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1939 _doing_emit_d32= false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1940 _doing_emit_d16= false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1941 _doing_emit_hi = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1942 _doing_emit_lo = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1943 _may_reloc = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1944 _reloc_form = RELOC_NONE;
a61af66fc99e Initial load
duke
parents:
diff changeset
1945 _reloc_type = AdlcVMDeps::none_reloc_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
1946 _strings_to_emit.clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
1947 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1948
a61af66fc99e Initial load
duke
parents:
diff changeset
1949 // Track necessary state when identifying a replacement variable
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
1950 // @arg rep_var: The formal parameter of the encoding.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1951 void update_state(const char *rep_var) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1952 // A replacement variable or one of its subfields
a61af66fc99e Initial load
duke
parents:
diff changeset
1953 // Obtain replacement variable from list
a61af66fc99e Initial load
duke
parents:
diff changeset
1954 if ( (*rep_var) != '$' ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1955 // A replacement variable, '$' prefix
a61af66fc99e Initial load
duke
parents:
diff changeset
1956 // check_rep_var( rep_var );
a61af66fc99e Initial load
duke
parents:
diff changeset
1957 if ( Opcode::as_opcode_type(rep_var) != Opcode::NOT_AN_OPCODE ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1958 // No state needed.
a61af66fc99e Initial load
duke
parents:
diff changeset
1959 assert( _opclass == NULL,
a61af66fc99e Initial load
duke
parents:
diff changeset
1960 "'primary', 'secondary' and 'tertiary' don't follow operand.");
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
1961 }
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
1962 else if ((strcmp(rep_var, "constanttablebase") == 0) ||
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
1963 (strcmp(rep_var, "constantoffset") == 0) ||
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
1964 (strcmp(rep_var, "constantaddress") == 0)) {
14434
318d0622a6d7 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 14431
diff changeset
1965 if (!(_inst.is_mach_constant() || _inst.needs_constant_base())) {
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
1966 _AD.syntax_err(_encoding._linenum,
14434
318d0622a6d7 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 14431
diff changeset
1967 "Replacement variable %s not allowed in instruct %s (only in MachConstantNode or MachCall).\n",
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
1968 rep_var, _encoding._name);
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
1969 }
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
1970 }
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
1971 else {
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
1972 // Lookup its position in (formal) parameter list of encoding
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1973 int param_no = _encoding.rep_var_index(rep_var);
a61af66fc99e Initial load
duke
parents:
diff changeset
1974 if ( param_no == -1 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1975 _AD.syntax_err( _encoding._linenum,
a61af66fc99e Initial load
duke
parents:
diff changeset
1976 "Replacement variable %s not found in enc_class %s.\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
1977 rep_var, _encoding._name);
a61af66fc99e Initial load
duke
parents:
diff changeset
1978 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1979
a61af66fc99e Initial load
duke
parents:
diff changeset
1980 // Lookup the corresponding ins_encode parameter
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
1981 // This is the argument (actual parameter) to the encoding.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1982 const char *inst_rep_var = _ins_encode.rep_var_name(_inst, param_no);
a61af66fc99e Initial load
duke
parents:
diff changeset
1983 if (inst_rep_var == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1984 _AD.syntax_err( _ins_encode._linenum,
a61af66fc99e Initial load
duke
parents:
diff changeset
1985 "Parameter %s not passed to enc_class %s from instruct %s.\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
1986 rep_var, _encoding._name, _inst._ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
1987 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1988
a61af66fc99e Initial load
duke
parents:
diff changeset
1989 // Check if instruction's actual parameter is a local name in the instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
1990 const Form *local = _inst._localNames[inst_rep_var];
a61af66fc99e Initial load
duke
parents:
diff changeset
1991 OpClassForm *opc = (local != NULL) ? local->is_opclass() : NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1992 // Note: assert removed to allow constant and symbolic parameters
a61af66fc99e Initial load
duke
parents:
diff changeset
1993 // assert( opc, "replacement variable was not found in local names");
a61af66fc99e Initial load
duke
parents:
diff changeset
1994 // Lookup the index position iff the replacement variable is a localName
a61af66fc99e Initial load
duke
parents:
diff changeset
1995 int idx = (opc != NULL) ? _inst.operand_position_format(inst_rep_var) : -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
1996
a61af66fc99e Initial load
duke
parents:
diff changeset
1997 if ( idx != -1 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1998 // This is a local in the instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
1999 // Update local state info.
a61af66fc99e Initial load
duke
parents:
diff changeset
2000 _opclass = opc;
a61af66fc99e Initial load
duke
parents:
diff changeset
2001 _operand_idx = idx;
a61af66fc99e Initial load
duke
parents:
diff changeset
2002 _local_name = rep_var;
a61af66fc99e Initial load
duke
parents:
diff changeset
2003 _operand_name = inst_rep_var;
a61af66fc99e Initial load
duke
parents:
diff changeset
2004
a61af66fc99e Initial load
duke
parents:
diff changeset
2005 // !!!!!
a61af66fc99e Initial load
duke
parents:
diff changeset
2006 // Do not support consecutive operands.
a61af66fc99e Initial load
duke
parents:
diff changeset
2007 assert( _operand == NULL, "Unimplemented()");
a61af66fc99e Initial load
duke
parents:
diff changeset
2008 _operand = opc->is_operand();
a61af66fc99e Initial load
duke
parents:
diff changeset
2009 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2010 else if( ADLParser::is_literal_constant(inst_rep_var) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2011 // Instruction provided a constant expression
a61af66fc99e Initial load
duke
parents:
diff changeset
2012 // Check later that encoding specifies $$$constant to resolve as constant
a61af66fc99e Initial load
duke
parents:
diff changeset
2013 _constant_status = LITERAL_SEEN;
a61af66fc99e Initial load
duke
parents:
diff changeset
2014 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2015 else if( Opcode::as_opcode_type(inst_rep_var) != Opcode::NOT_AN_OPCODE ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2016 // Instruction provided an opcode: "primary", "secondary", "tertiary"
a61af66fc99e Initial load
duke
parents:
diff changeset
2017 // Check later that encoding specifies $$$constant to resolve as constant
a61af66fc99e Initial load
duke
parents:
diff changeset
2018 _constant_status = LITERAL_SEEN;
a61af66fc99e Initial load
duke
parents:
diff changeset
2019 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2020 else if((_AD.get_registers() != NULL ) && (_AD.get_registers()->getRegDef(inst_rep_var) != NULL)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2021 // Instruction provided a literal register name for this parameter
a61af66fc99e Initial load
duke
parents:
diff changeset
2022 // Check that encoding specifies $$$reg to resolve.as register.
a61af66fc99e Initial load
duke
parents:
diff changeset
2023 _reg_status = LITERAL_SEEN;
a61af66fc99e Initial load
duke
parents:
diff changeset
2024 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2025 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2026 // Check for unimplemented functionality before hard failure
a61af66fc99e Initial load
duke
parents:
diff changeset
2027 assert( strcmp(opc->_ident,"label")==0, "Unimplemented() Label");
a61af66fc99e Initial load
duke
parents:
diff changeset
2028 assert( false, "ShouldNotReachHere()");
a61af66fc99e Initial load
duke
parents:
diff changeset
2029 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2030 } // done checking which operand this is.
a61af66fc99e Initial load
duke
parents:
diff changeset
2031 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2032 //
a61af66fc99e Initial load
duke
parents:
diff changeset
2033 // A subfield variable, '$$' prefix
a61af66fc99e Initial load
duke
parents:
diff changeset
2034 // Check for fields that may require relocation information.
a61af66fc99e Initial load
duke
parents:
diff changeset
2035 // Then check that literal register parameters are accessed with 'reg' or 'constant'
a61af66fc99e Initial load
duke
parents:
diff changeset
2036 //
a61af66fc99e Initial load
duke
parents:
diff changeset
2037 if ( strcmp(rep_var,"$disp") == 0 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2038 _doing_disp = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
2039 assert( _opclass, "Must use operand or operand class before '$disp'");
a61af66fc99e Initial load
duke
parents:
diff changeset
2040 if( _operand == NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2041 // Only have an operand class, generate run-time check for relocation
a61af66fc99e Initial load
duke
parents:
diff changeset
2042 _may_reloc = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
2043 _reloc_form = RELOC_DISP;
a61af66fc99e Initial load
duke
parents:
diff changeset
2044 _reloc_type = AdlcVMDeps::oop_reloc_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
2045 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2046 // Do precise check on operand: is it a ConP or not
a61af66fc99e Initial load
duke
parents:
diff changeset
2047 //
a61af66fc99e Initial load
duke
parents:
diff changeset
2048 // Check interface for value of displacement
a61af66fc99e Initial load
duke
parents:
diff changeset
2049 assert( ( _operand->_interface != NULL ),
a61af66fc99e Initial load
duke
parents:
diff changeset
2050 "$disp can only follow memory interface operand");
a61af66fc99e Initial load
duke
parents:
diff changeset
2051 MemInterface *mem_interface= _operand->_interface->is_MemInterface();
a61af66fc99e Initial load
duke
parents:
diff changeset
2052 assert( mem_interface != NULL,
a61af66fc99e Initial load
duke
parents:
diff changeset
2053 "$disp can only follow memory interface operand");
a61af66fc99e Initial load
duke
parents:
diff changeset
2054 const char *disp = mem_interface->_disp;
a61af66fc99e Initial load
duke
parents:
diff changeset
2055
a61af66fc99e Initial load
duke
parents:
diff changeset
2056 if( disp != NULL && (*disp == '$') ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2057 // MemInterface::disp contains a replacement variable,
a61af66fc99e Initial load
duke
parents:
diff changeset
2058 // Check if this matches a ConP
a61af66fc99e Initial load
duke
parents:
diff changeset
2059 //
a61af66fc99e Initial load
duke
parents:
diff changeset
2060 // Lookup replacement variable, in operand's component list
a61af66fc99e Initial load
duke
parents:
diff changeset
2061 const char *rep_var_name = disp + 1; // Skip '$'
a61af66fc99e Initial load
duke
parents:
diff changeset
2062 const Component *comp = _operand->_components.search(rep_var_name);
a61af66fc99e Initial load
duke
parents:
diff changeset
2063 assert( comp != NULL,"Replacement variable not found in components");
a61af66fc99e Initial load
duke
parents:
diff changeset
2064 const char *type = comp->_type;
a61af66fc99e Initial load
duke
parents:
diff changeset
2065 // Lookup operand form for replacement variable's type
a61af66fc99e Initial load
duke
parents:
diff changeset
2066 const Form *form = _AD.globalNames()[type];
a61af66fc99e Initial load
duke
parents:
diff changeset
2067 assert( form != NULL, "Replacement variable's type not found");
a61af66fc99e Initial load
duke
parents:
diff changeset
2068 OperandForm *op = form->is_operand();
a61af66fc99e Initial load
duke
parents:
diff changeset
2069 assert( op, "Attempting to emit a non-register or non-constant");
a61af66fc99e Initial load
duke
parents:
diff changeset
2070 // Check if this is a constant
a61af66fc99e Initial load
duke
parents:
diff changeset
2071 if (op->_matrule && op->_matrule->is_base_constant(_AD.globalNames())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2072 // Check which constant this name maps to: _c0, _c1, ..., _cn
a61af66fc99e Initial load
duke
parents:
diff changeset
2073 // const int idx = _operand.constant_position(_AD.globalNames(), comp);
a61af66fc99e Initial load
duke
parents:
diff changeset
2074 // assert( idx != -1, "Constant component not found in operand");
a61af66fc99e Initial load
duke
parents:
diff changeset
2075 Form::DataType dtype = op->is_base_constant(_AD.globalNames());
a61af66fc99e Initial load
duke
parents:
diff changeset
2076 if ( dtype == Form::idealP ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2077 _may_reloc = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
2078 // No longer true that idealP is always an oop
a61af66fc99e Initial load
duke
parents:
diff changeset
2079 _reloc_form = RELOC_DISP;
a61af66fc99e Initial load
duke
parents:
diff changeset
2080 _reloc_type = AdlcVMDeps::oop_reloc_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
2081 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2082 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2083
a61af66fc99e Initial load
duke
parents:
diff changeset
2084 else if( _operand->is_user_name_for_sReg() != Form::none ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2085 // The only non-constant allowed access to disp is an operand sRegX in a stackSlotX
a61af66fc99e Initial load
duke
parents:
diff changeset
2086 assert( op->ideal_to_sReg_type(type) != Form::none, "StackSlots access displacements using 'sRegs'");
a61af66fc99e Initial load
duke
parents:
diff changeset
2087 _may_reloc = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
2088 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2089 assert( false, "fatal(); Only stackSlots can access a non-constant using 'disp'");
a61af66fc99e Initial load
duke
parents:
diff changeset
2090 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2091 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2092 } // finished with precise check of operand for relocation.
a61af66fc99e Initial load
duke
parents:
diff changeset
2093 } // finished with subfield variable
a61af66fc99e Initial load
duke
parents:
diff changeset
2094 else if ( strcmp(rep_var,"$constant") == 0 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2095 _doing_constant = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
2096 if ( _constant_status == LITERAL_NOT_SEEN ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2097 // Check operand for type of constant
a61af66fc99e Initial load
duke
parents:
diff changeset
2098 assert( _operand, "Must use operand before '$$constant'");
a61af66fc99e Initial load
duke
parents:
diff changeset
2099 Form::DataType dtype = _operand->is_base_constant(_AD.globalNames());
a61af66fc99e Initial load
duke
parents:
diff changeset
2100 _constant_type = dtype;
a61af66fc99e Initial load
duke
parents:
diff changeset
2101 if ( dtype == Form::idealP ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2102 _may_reloc = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
2103 // No longer true that idealP is always an oop
a61af66fc99e Initial load
duke
parents:
diff changeset
2104 // // _must_reloc = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
2105 _reloc_form = RELOC_IMMEDIATE;
a61af66fc99e Initial load
duke
parents:
diff changeset
2106 _reloc_type = AdlcVMDeps::oop_reloc_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
2107 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2108 // No relocation information needed
a61af66fc99e Initial load
duke
parents:
diff changeset
2109 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2110 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2111 // User-provided literals may not require relocation information !!!!!
a61af66fc99e Initial load
duke
parents:
diff changeset
2112 assert( _constant_status == LITERAL_SEEN, "Must know we are processing a user-provided literal");
a61af66fc99e Initial load
duke
parents:
diff changeset
2113 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2114 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2115 else if ( strcmp(rep_var,"$label") == 0 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2116 // Calls containing labels require relocation
a61af66fc99e Initial load
duke
parents:
diff changeset
2117 if ( _inst.is_ideal_call() ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2118 _may_reloc = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
2119 // !!!!! !!!!!
a61af66fc99e Initial load
duke
parents:
diff changeset
2120 _reloc_type = AdlcVMDeps::none_reloc_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
2121 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2122 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2123
a61af66fc99e Initial load
duke
parents:
diff changeset
2124 // literal register parameter must be accessed as a 'reg' field.
a61af66fc99e Initial load
duke
parents:
diff changeset
2125 if ( _reg_status != LITERAL_NOT_SEEN ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2126 assert( _reg_status == LITERAL_SEEN, "Must have seen register literal before now");
a61af66fc99e Initial load
duke
parents:
diff changeset
2127 if (strcmp(rep_var,"$reg") == 0 || reg_conversion(rep_var) != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2128 _reg_status = LITERAL_ACCESSED;
a61af66fc99e Initial load
duke
parents:
diff changeset
2129 } else {
14431
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
2130 _AD.syntax_err(_encoding._linenum,
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
2131 "Invalid access to literal register parameter '%s' in %s.\n",
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
2132 rep_var, _encoding._name);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2133 assert( false, "invalid access to literal register parameter");
a61af66fc99e Initial load
duke
parents:
diff changeset
2134 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2135 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2136 // literal constant parameters must be accessed as a 'constant' field
14431
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
2137 if (_constant_status != LITERAL_NOT_SEEN) {
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
2138 assert(_constant_status == LITERAL_SEEN, "Must have seen constant literal before now");
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
2139 if (strcmp(rep_var,"$constant") == 0) {
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
2140 _constant_status = LITERAL_ACCESSED;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2141 } else {
14431
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
2142 _AD.syntax_err(_encoding._linenum,
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
2143 "Invalid access to literal constant parameter '%s' in %s.\n",
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
2144 rep_var, _encoding._name);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2145 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2146 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2147 } // end replacement and/or subfield
a61af66fc99e Initial load
duke
parents:
diff changeset
2148
a61af66fc99e Initial load
duke
parents:
diff changeset
2149 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2150
a61af66fc99e Initial load
duke
parents:
diff changeset
2151 void add_rep_var(const char *rep_var) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2152 // Handle subfield and replacement variables.
a61af66fc99e Initial load
duke
parents:
diff changeset
2153 if ( ( *rep_var == '$' ) && ( *(rep_var+1) == '$' ) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2154 // Check for emit prefix, '$$emit32'
a61af66fc99e Initial load
duke
parents:
diff changeset
2155 assert( _cleared, "Can not nest $$$emit32");
a61af66fc99e Initial load
duke
parents:
diff changeset
2156 if ( strcmp(rep_var,"$$emit32") == 0 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2157 _doing_emit_d32 = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
2158 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2159 else if ( strcmp(rep_var,"$$emit16") == 0 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2160 _doing_emit_d16 = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
2161 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2162 else if ( strcmp(rep_var,"$$emit_hi") == 0 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2163 _doing_emit_hi = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
2164 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2165 else if ( strcmp(rep_var,"$$emit_lo") == 0 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2166 _doing_emit_lo = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
2167 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2168 else if ( strcmp(rep_var,"$$emit8") == 0 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2169 _doing_emit8 = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
2170 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2171 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2172 _AD.syntax_err(_encoding._linenum, "Unsupported $$operation '%s'\n",rep_var);
a61af66fc99e Initial load
duke
parents:
diff changeset
2173 assert( false, "fatal();");
a61af66fc99e Initial load
duke
parents:
diff changeset
2174 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2175 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2176 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2177 // Update state for replacement variables
a61af66fc99e Initial load
duke
parents:
diff changeset
2178 update_state( rep_var );
a61af66fc99e Initial load
duke
parents:
diff changeset
2179 _strings_to_emit.addName(rep_var);
a61af66fc99e Initial load
duke
parents:
diff changeset
2180 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2181 _cleared = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
2182 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2183
a61af66fc99e Initial load
duke
parents:
diff changeset
2184 void emit_replacement() {
a61af66fc99e Initial load
duke
parents:
diff changeset
2185 // A replacement variable or one of its subfields
a61af66fc99e Initial load
duke
parents:
diff changeset
2186 // Obtain replacement variable from list
a61af66fc99e Initial load
duke
parents:
diff changeset
2187 // const char *ec_rep_var = encoding->_rep_vars.iter();
a61af66fc99e Initial load
duke
parents:
diff changeset
2188 const char *rep_var;
a61af66fc99e Initial load
duke
parents:
diff changeset
2189 _strings_to_emit.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
2190 while ( (rep_var = _strings_to_emit.iter()) != NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2191
a61af66fc99e Initial load
duke
parents:
diff changeset
2192 if ( (*rep_var) == '$' ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2193 // A subfield variable, '$$' prefix
a61af66fc99e Initial load
duke
parents:
diff changeset
2194 emit_field( rep_var );
a61af66fc99e Initial load
duke
parents:
diff changeset
2195 } else {
624
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2196 if (_strings_to_emit.peek() != NULL &&
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2197 strcmp(_strings_to_emit.peek(), "$Address") == 0) {
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2198 fprintf(_fp, "Address::make_raw(");
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2199
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2200 emit_rep_var( rep_var );
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2201 fprintf(_fp,"->base(ra_,this,idx%d), ", _operand_idx);
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2202
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2203 _reg_status = LITERAL_ACCESSED;
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2204 emit_rep_var( rep_var );
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2205 fprintf(_fp,"->index(ra_,this,idx%d), ", _operand_idx);
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2206
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2207 _reg_status = LITERAL_ACCESSED;
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2208 emit_rep_var( rep_var );
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2209 fprintf(_fp,"->scale(), ");
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2210
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2211 _reg_status = LITERAL_ACCESSED;
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2212 emit_rep_var( rep_var );
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2213 Form::DataType stack_type = _operand ? _operand->is_user_name_for_sReg() : Form::none;
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2214 if( _operand && _operand_idx==0 && stack_type != Form::none ) {
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2215 fprintf(_fp,"->disp(ra_,this,0), ");
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2216 } else {
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2217 fprintf(_fp,"->disp(ra_,this,idx%d), ", _operand_idx);
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2218 }
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2219
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2220 _reg_status = LITERAL_ACCESSED;
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2221 emit_rep_var( rep_var );
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 4121
diff changeset
2222 fprintf(_fp,"->disp_reloc())");
624
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2223
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2224 // skip trailing $Address
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2225 _strings_to_emit.iter();
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2226 } else {
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2227 // A replacement variable, '$' prefix
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2228 const char* next = _strings_to_emit.peek();
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2229 const char* next2 = _strings_to_emit.peek(2);
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2230 if (next != NULL && next2 != NULL && strcmp(next2, "$Register") == 0 &&
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2231 (strcmp(next, "$base") == 0 || strcmp(next, "$index") == 0)) {
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2232 // handle $rev_var$$base$$Register and $rev_var$$index$$Register by
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2233 // producing as_Register(opnd_array(#)->base(ra_,this,idx1)).
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2234 fprintf(_fp, "as_Register(");
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2235 // emit the operand reference
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2236 emit_rep_var( rep_var );
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2237 rep_var = _strings_to_emit.iter();
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2238 assert(strcmp(rep_var, "$base") == 0 || strcmp(rep_var, "$index") == 0, "bad pattern");
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2239 // handle base or index
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2240 emit_field(rep_var);
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2241 rep_var = _strings_to_emit.iter();
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2242 assert(strcmp(rep_var, "$Register") == 0, "bad pattern");
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2243 // close up the parens
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2244 fprintf(_fp, ")");
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2245 } else {
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2246 emit_rep_var( rep_var );
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2247 }
337400e7a5dd 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 603
diff changeset
2248 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2249 } // end replacement and/or subfield
a61af66fc99e Initial load
duke
parents:
diff changeset
2250 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2251 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2252
a61af66fc99e Initial load
duke
parents:
diff changeset
2253 void emit_reloc_type(const char* type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2254 fprintf(_fp, "%s", type)
a61af66fc99e Initial load
duke
parents:
diff changeset
2255 ;
a61af66fc99e Initial load
duke
parents:
diff changeset
2256 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2257
a61af66fc99e Initial load
duke
parents:
diff changeset
2258
a61af66fc99e Initial load
duke
parents:
diff changeset
2259 void emit() {
a61af66fc99e Initial load
duke
parents:
diff changeset
2260 //
a61af66fc99e Initial load
duke
parents:
diff changeset
2261 // "emit_d32_reloc(" or "emit_hi_reloc" or "emit_lo_reloc"
a61af66fc99e Initial load
duke
parents:
diff changeset
2262 //
a61af66fc99e Initial load
duke
parents:
diff changeset
2263 // Emit the function name when generating an emit function
a61af66fc99e Initial load
duke
parents:
diff changeset
2264 if ( _doing_emit_d32 || _doing_emit_hi || _doing_emit_lo ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2265 const char *d32_hi_lo = _doing_emit_d32 ? "d32" : (_doing_emit_hi ? "hi" : "lo");
a61af66fc99e Initial load
duke
parents:
diff changeset
2266 // In general, relocatable isn't known at compiler compile time.
a61af66fc99e Initial load
duke
parents:
diff changeset
2267 // Check results of prior scan
a61af66fc99e Initial load
duke
parents:
diff changeset
2268 if ( ! _may_reloc ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2269 // Definitely don't need relocation information
a61af66fc99e Initial load
duke
parents:
diff changeset
2270 fprintf( _fp, "emit_%s(cbuf, ", d32_hi_lo );
a61af66fc99e Initial load
duke
parents:
diff changeset
2271 emit_replacement(); fprintf(_fp, ")");
a61af66fc99e Initial load
duke
parents:
diff changeset
2272 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2273 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2274 // Emit RUNTIME CHECK to see if value needs relocation info
a61af66fc99e Initial load
duke
parents:
diff changeset
2275 // If emitting a relocatable address, use 'emit_d32_reloc'
a61af66fc99e Initial load
duke
parents:
diff changeset
2276 const char *disp_constant = _doing_disp ? "disp" : _doing_constant ? "constant" : "INVALID";
a61af66fc99e Initial load
duke
parents:
diff changeset
2277 assert( (_doing_disp || _doing_constant)
a61af66fc99e Initial load
duke
parents:
diff changeset
2278 && !(_doing_disp && _doing_constant),
a61af66fc99e Initial load
duke
parents:
diff changeset
2279 "Must be emitting either a displacement or a constant");
a61af66fc99e Initial load
duke
parents:
diff changeset
2280 fprintf(_fp,"\n");
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 4121
diff changeset
2281 fprintf(_fp,"if ( opnd_array(%d)->%s_reloc() != relocInfo::none ) {\n",
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2282 _operand_idx, disp_constant);
a61af66fc99e Initial load
duke
parents:
diff changeset
2283 fprintf(_fp," ");
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 4121
diff changeset
2284 fprintf(_fp,"emit_%s_reloc(cbuf, ", d32_hi_lo );
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 4121
diff changeset
2285 emit_replacement(); fprintf(_fp,", ");
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 4121
diff changeset
2286 fprintf(_fp,"opnd_array(%d)->%s_reloc(), ",
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 4121
diff changeset
2287 _operand_idx, disp_constant);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 4121
diff changeset
2288 fprintf(_fp, "%d", _reloc_form);fprintf(_fp, ");");
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 4121
diff changeset
2289 fprintf(_fp,"\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2290 fprintf(_fp,"} else {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2291 fprintf(_fp," emit_%s(cbuf, ", d32_hi_lo);
a61af66fc99e Initial load
duke
parents:
diff changeset
2292 emit_replacement(); fprintf(_fp, ");\n"); fprintf(_fp,"}");
a61af66fc99e Initial load
duke
parents:
diff changeset
2293 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2294 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2295 else if ( _doing_emit_d16 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2296 // Relocation of 16-bit values is not supported
a61af66fc99e Initial load
duke
parents:
diff changeset
2297 fprintf(_fp,"emit_d16(cbuf, ");
a61af66fc99e Initial load
duke
parents:
diff changeset
2298 emit_replacement(); fprintf(_fp, ")");
a61af66fc99e Initial load
duke
parents:
diff changeset
2299 // No relocation done for 16-bit values
a61af66fc99e Initial load
duke
parents:
diff changeset
2300 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2301 else if ( _doing_emit8 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2302 // Relocation of 8-bit values is not supported
a61af66fc99e Initial load
duke
parents:
diff changeset
2303 fprintf(_fp,"emit_d8(cbuf, ");
a61af66fc99e Initial load
duke
parents:
diff changeset
2304 emit_replacement(); fprintf(_fp, ")");
a61af66fc99e Initial load
duke
parents:
diff changeset
2305 // No relocation done for 8-bit values
a61af66fc99e Initial load
duke
parents:
diff changeset
2306 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2307 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2308 // Not an emit# command, just output the replacement string.
a61af66fc99e Initial load
duke
parents:
diff changeset
2309 emit_replacement();
a61af66fc99e Initial load
duke
parents:
diff changeset
2310 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2311
a61af66fc99e Initial load
duke
parents:
diff changeset
2312 // Get ready for next state collection.
a61af66fc99e Initial load
duke
parents:
diff changeset
2313 clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
2314 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2315
a61af66fc99e Initial load
duke
parents:
diff changeset
2316 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
2317
a61af66fc99e Initial load
duke
parents:
diff changeset
2318 // recognizes names which represent MacroAssembler register types
a61af66fc99e Initial load
duke
parents:
diff changeset
2319 // and return the conversion function to build them from OptoReg
a61af66fc99e Initial load
duke
parents:
diff changeset
2320 const char* reg_conversion(const char* rep_var) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2321 if (strcmp(rep_var,"$Register") == 0) return "as_Register";
a61af66fc99e Initial load
duke
parents:
diff changeset
2322 if (strcmp(rep_var,"$FloatRegister") == 0) return "as_FloatRegister";
a61af66fc99e Initial load
duke
parents:
diff changeset
2323 #if defined(IA32) || defined(AMD64)
a61af66fc99e Initial load
duke
parents:
diff changeset
2324 if (strcmp(rep_var,"$XMMRegister") == 0) return "as_XMMRegister";
a61af66fc99e Initial load
duke
parents:
diff changeset
2325 #endif
14444
492e67693373 8029888: PPC64: (part 219): adl replacement variable CondRegister
goetz
parents: 14434
diff changeset
2326 if (strcmp(rep_var,"$CondRegister") == 0) return "as_ConditionRegister";
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2327 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
2328 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2329
a61af66fc99e Initial load
duke
parents:
diff changeset
2330 void emit_field(const char *rep_var) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2331 const char* reg_convert = reg_conversion(rep_var);
a61af66fc99e Initial load
duke
parents:
diff changeset
2332
a61af66fc99e Initial load
duke
parents:
diff changeset
2333 // A subfield variable, '$$subfield'
a61af66fc99e Initial load
duke
parents:
diff changeset
2334 if ( strcmp(rep_var, "$reg") == 0 || reg_convert != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2335 // $reg form or the $Register MacroAssembler type conversions
a61af66fc99e Initial load
duke
parents:
diff changeset
2336 assert( _operand_idx != -1,
a61af66fc99e Initial load
duke
parents:
diff changeset
2337 "Must use this subfield after operand");
a61af66fc99e Initial load
duke
parents:
diff changeset
2338 if( _reg_status == LITERAL_NOT_SEEN ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2339 if (_processing_noninput) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2340 const Form *local = _inst._localNames[_operand_name];
a61af66fc99e Initial load
duke
parents:
diff changeset
2341 OperandForm *oper = local->is_operand();
a61af66fc99e Initial load
duke
parents:
diff changeset
2342 const RegDef* first = oper->get_RegClass()->find_first_elem();
a61af66fc99e Initial load
duke
parents:
diff changeset
2343 if (reg_convert != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2344 fprintf(_fp, "%s(%s_enc)", reg_convert, first->_regname);
a61af66fc99e Initial load
duke
parents:
diff changeset
2345 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2346 fprintf(_fp, "%s_enc", first->_regname);
a61af66fc99e Initial load
duke
parents:
diff changeset
2347 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2348 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2349 fprintf(_fp,"->%s(ra_,this", reg_convert != NULL ? reg_convert : "reg");
a61af66fc99e Initial load
duke
parents:
diff changeset
2350 // Add parameter for index position, if not result operand
a61af66fc99e Initial load
duke
parents:
diff changeset
2351 if( _operand_idx != 0 ) fprintf(_fp,",idx%d", _operand_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
2352 fprintf(_fp,")");
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
2353 fprintf(_fp, "/* %s */", _operand_name);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2354 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2355 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2356 assert( _reg_status == LITERAL_OUTPUT, "should have output register literal in emit_rep_var");
a61af66fc99e Initial load
duke
parents:
diff changeset
2357 // Register literal has already been sent to output file, nothing more needed
a61af66fc99e Initial load
duke
parents:
diff changeset
2358 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2359 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2360 else if ( strcmp(rep_var,"$base") == 0 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2361 assert( _operand_idx != -1,
a61af66fc99e Initial load
duke
parents:
diff changeset
2362 "Must use this subfield after operand");
a61af66fc99e Initial load
duke
parents:
diff changeset
2363 assert( ! _may_reloc, "UnImplemented()");
a61af66fc99e Initial load
duke
parents:
diff changeset
2364 fprintf(_fp,"->base(ra_,this,idx%d)", _operand_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
2365 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2366 else if ( strcmp(rep_var,"$index") == 0 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2367 assert( _operand_idx != -1,
a61af66fc99e Initial load
duke
parents:
diff changeset
2368 "Must use this subfield after operand");
a61af66fc99e Initial load
duke
parents:
diff changeset
2369 assert( ! _may_reloc, "UnImplemented()");
a61af66fc99e Initial load
duke
parents:
diff changeset
2370 fprintf(_fp,"->index(ra_,this,idx%d)", _operand_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
2371 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2372 else if ( strcmp(rep_var,"$scale") == 0 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2373 assert( ! _may_reloc, "UnImplemented()");
a61af66fc99e Initial load
duke
parents:
diff changeset
2374 fprintf(_fp,"->scale()");
a61af66fc99e Initial load
duke
parents:
diff changeset
2375 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2376 else if ( strcmp(rep_var,"$cmpcode") == 0 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2377 assert( ! _may_reloc, "UnImplemented()");
a61af66fc99e Initial load
duke
parents:
diff changeset
2378 fprintf(_fp,"->ccode()");
a61af66fc99e Initial load
duke
parents:
diff changeset
2379 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2380 else if ( strcmp(rep_var,"$constant") == 0 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2381 if( _constant_status == LITERAL_NOT_SEEN ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2382 if ( _constant_type == Form::idealD ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2383 fprintf(_fp,"->constantD()");
a61af66fc99e Initial load
duke
parents:
diff changeset
2384 } else if ( _constant_type == Form::idealF ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2385 fprintf(_fp,"->constantF()");
a61af66fc99e Initial load
duke
parents:
diff changeset
2386 } else if ( _constant_type == Form::idealL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2387 fprintf(_fp,"->constantL()");
a61af66fc99e Initial load
duke
parents:
diff changeset
2388 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2389 fprintf(_fp,"->constant()");
a61af66fc99e Initial load
duke
parents:
diff changeset
2390 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2391 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2392 assert( _constant_status == LITERAL_OUTPUT, "should have output constant literal in emit_rep_var");
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
2393 // Constant literal has already been sent to output file, nothing more needed
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2394 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2395 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2396 else if ( strcmp(rep_var,"$disp") == 0 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2397 Form::DataType stack_type = _operand ? _operand->is_user_name_for_sReg() : Form::none;
a61af66fc99e Initial load
duke
parents:
diff changeset
2398 if( _operand && _operand_idx==0 && stack_type != Form::none ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2399 fprintf(_fp,"->disp(ra_,this,0)");
a61af66fc99e Initial load
duke
parents:
diff changeset
2400 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2401 fprintf(_fp,"->disp(ra_,this,idx%d)", _operand_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
2402 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2403 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2404 else if ( strcmp(rep_var,"$label") == 0 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2405 fprintf(_fp,"->label()");
a61af66fc99e Initial load
duke
parents:
diff changeset
2406 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2407 else if ( strcmp(rep_var,"$method") == 0 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2408 fprintf(_fp,"->method()");
a61af66fc99e Initial load
duke
parents:
diff changeset
2409 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2410 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2411 printf("emit_field: %s\n",rep_var);
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
2412 globalAD->syntax_err(_inst._linenum, "Unknown replacement variable %s in format statement of %s.",
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
2413 rep_var, _inst._ident);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2414 assert( false, "UnImplemented()");
a61af66fc99e Initial load
duke
parents:
diff changeset
2415 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2416 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2417
a61af66fc99e Initial load
duke
parents:
diff changeset
2418
a61af66fc99e Initial load
duke
parents:
diff changeset
2419 void emit_rep_var(const char *rep_var) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2420 _processing_noninput = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
2421 // A replacement variable, originally '$'
a61af66fc99e Initial load
duke
parents:
diff changeset
2422 if ( Opcode::as_opcode_type(rep_var) != Opcode::NOT_AN_OPCODE ) {
415
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 196
diff changeset
2423 if (!_inst._opcode->print_opcode(_fp, Opcode::as_opcode_type(rep_var) )) {
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 196
diff changeset
2424 // Missing opcode
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 196
diff changeset
2425 _AD.syntax_err( _inst._linenum,
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 196
diff changeset
2426 "Missing $%s opcode definition in %s, used by encoding %s\n",
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 196
diff changeset
2427 rep_var, _inst._ident, _encoding._name);
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 196
diff changeset
2428 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2429 }
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2430 else if (strcmp(rep_var, "constanttablebase") == 0) {
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2431 fprintf(_fp, "as_Register(ra_->get_encode(in(mach_constant_base_node_input())))");
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2432 }
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2433 else if (strcmp(rep_var, "constantoffset") == 0) {
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2434 fprintf(_fp, "constant_offset()");
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2435 }
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2436 else if (strcmp(rep_var, "constantaddress") == 0) {
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2437 fprintf(_fp, "InternalAddress(__ code()->consts()->start() + constant_offset())");
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2438 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2439 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2440 // Lookup its position in parameter list
a61af66fc99e Initial load
duke
parents:
diff changeset
2441 int param_no = _encoding.rep_var_index(rep_var);
a61af66fc99e Initial load
duke
parents:
diff changeset
2442 if ( param_no == -1 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2443 _AD.syntax_err( _encoding._linenum,
a61af66fc99e Initial load
duke
parents:
diff changeset
2444 "Replacement variable %s not found in enc_class %s.\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
2445 rep_var, _encoding._name);
a61af66fc99e Initial load
duke
parents:
diff changeset
2446 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2447 // Lookup the corresponding ins_encode parameter
a61af66fc99e Initial load
duke
parents:
diff changeset
2448 const char *inst_rep_var = _ins_encode.rep_var_name(_inst, param_no);
a61af66fc99e Initial load
duke
parents:
diff changeset
2449
a61af66fc99e Initial load
duke
parents:
diff changeset
2450 // Check if instruction's actual parameter is a local name in the instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
2451 const Form *local = _inst._localNames[inst_rep_var];
a61af66fc99e Initial load
duke
parents:
diff changeset
2452 OpClassForm *opc = (local != NULL) ? local->is_opclass() : NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
2453 // Note: assert removed to allow constant and symbolic parameters
a61af66fc99e Initial load
duke
parents:
diff changeset
2454 // assert( opc, "replacement variable was not found in local names");
a61af66fc99e Initial load
duke
parents:
diff changeset
2455 // Lookup the index position iff the replacement variable is a localName
a61af66fc99e Initial load
duke
parents:
diff changeset
2456 int idx = (opc != NULL) ? _inst.operand_position_format(inst_rep_var) : -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
2457 if( idx != -1 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2458 if (_inst.is_noninput_operand(idx)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2459 // This operand isn't a normal input so printing it is done
a61af66fc99e Initial load
duke
parents:
diff changeset
2460 // specially.
a61af66fc99e Initial load
duke
parents:
diff changeset
2461 _processing_noninput = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
2462 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2463 // Output the emit code for this operand
a61af66fc99e Initial load
duke
parents:
diff changeset
2464 fprintf(_fp,"opnd_array(%d)",idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
2465 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2466 assert( _operand == opc->is_operand(),
a61af66fc99e Initial load
duke
parents:
diff changeset
2467 "Previous emit $operand does not match current");
a61af66fc99e Initial load
duke
parents:
diff changeset
2468 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2469 else if( ADLParser::is_literal_constant(inst_rep_var) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2470 // else check if it is a constant expression
a61af66fc99e Initial load
duke
parents:
diff changeset
2471 // Removed following assert to allow primitive C types as arguments to encodings
a61af66fc99e Initial load
duke
parents:
diff changeset
2472 // assert( _constant_status == LITERAL_ACCESSED, "Must be processing a literal constant parameter");
a61af66fc99e Initial load
duke
parents:
diff changeset
2473 fprintf(_fp,"(%s)", inst_rep_var);
a61af66fc99e Initial load
duke
parents:
diff changeset
2474 _constant_status = LITERAL_OUTPUT;
a61af66fc99e Initial load
duke
parents:
diff changeset
2475 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2476 else if( Opcode::as_opcode_type(inst_rep_var) != Opcode::NOT_AN_OPCODE ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2477 // else check if "primary", "secondary", "tertiary"
a61af66fc99e Initial load
duke
parents:
diff changeset
2478 assert( _constant_status == LITERAL_ACCESSED, "Must be processing a literal constant parameter");
415
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 196
diff changeset
2479 if (!_inst._opcode->print_opcode(_fp, Opcode::as_opcode_type(inst_rep_var) )) {
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 196
diff changeset
2480 // Missing opcode
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 196
diff changeset
2481 _AD.syntax_err( _inst._linenum,
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 196
diff changeset
2482 "Missing $%s opcode definition in %s\n",
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 196
diff changeset
2483 rep_var, _inst._ident);
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 196
diff changeset
2484
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 196
diff changeset
2485 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2486 _constant_status = LITERAL_OUTPUT;
a61af66fc99e Initial load
duke
parents:
diff changeset
2487 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2488 else if((_AD.get_registers() != NULL ) && (_AD.get_registers()->getRegDef(inst_rep_var) != NULL)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2489 // Instruction provided a literal register name for this parameter
a61af66fc99e Initial load
duke
parents:
diff changeset
2490 // Check that encoding specifies $$$reg to resolve.as register.
a61af66fc99e Initial load
duke
parents:
diff changeset
2491 assert( _reg_status == LITERAL_ACCESSED, "Must be processing a literal register parameter");
a61af66fc99e Initial load
duke
parents:
diff changeset
2492 fprintf(_fp,"(%s_enc)", inst_rep_var);
a61af66fc99e Initial load
duke
parents:
diff changeset
2493 _reg_status = LITERAL_OUTPUT;
a61af66fc99e Initial load
duke
parents:
diff changeset
2494 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2495 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2496 // Check for unimplemented functionality before hard failure
a61af66fc99e Initial load
duke
parents:
diff changeset
2497 assert( strcmp(opc->_ident,"label")==0, "Unimplemented() Label");
a61af66fc99e Initial load
duke
parents:
diff changeset
2498 assert( false, "ShouldNotReachHere()");
a61af66fc99e Initial load
duke
parents:
diff changeset
2499 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2500 // all done
a61af66fc99e Initial load
duke
parents:
diff changeset
2501 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2502 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2503
a61af66fc99e Initial load
duke
parents:
diff changeset
2504 }; // end class DefineEmitState
a61af66fc99e Initial load
duke
parents:
diff changeset
2505
a61af66fc99e Initial load
duke
parents:
diff changeset
2506
a61af66fc99e Initial load
duke
parents:
diff changeset
2507 void ArchDesc::defineSize(FILE *fp, InstructForm &inst) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2508
a61af66fc99e Initial load
duke
parents:
diff changeset
2509 //(1)
a61af66fc99e Initial load
duke
parents:
diff changeset
2510 // Output instruction's emit prototype
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
2511 fprintf(fp,"uint %sNode::size(PhaseRegAlloc *ra_) const {\n",
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2512 inst._ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
2513
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
2514 fprintf(fp, " assert(VerifyOops || MachNode::size(ra_) <= %s, \"bad fixed size\");\n", inst._size);
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
2515
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2516 //(2)
a61af66fc99e Initial load
duke
parents:
diff changeset
2517 // Print the size
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
2518 fprintf(fp, " return (VerifyOops ? MachNode::size(ra_) : %s);\n", inst._size);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2519
a61af66fc99e Initial load
duke
parents:
diff changeset
2520 // (3) and (4)
14428
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2521 fprintf(fp,"}\n\n");
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2522 }
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2523
17797
2fcab8ba885a 8033168: PPC64: gcc 4.8 warning in output_c.cpp
goetz
parents: 17795
diff changeset
2524 // Emit postalloc expand function.
14428
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2525 void ArchDesc::define_postalloc_expand(FILE *fp, InstructForm &inst) {
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2526 InsEncode *ins_encode = inst._insencode;
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2527
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2528 // Output instruction's postalloc_expand prototype.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2529 fprintf(fp, "void %sNode::postalloc_expand(GrowableArray <Node *> *nodes, PhaseRegAlloc *ra_) {\n",
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2530 inst._ident);
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2531
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2532 assert((_encode != NULL) && (ins_encode != NULL), "You must define an encode section.");
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2533
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2534 // Output each operand's offset into the array of registers.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2535 inst.index_temps(fp, _globalNames);
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2536
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2537 // Output variables "unsigned idx_<par_name>", Node *n_<par_name> and "MachOpnd *op_<par_name>"
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2538 // for each parameter <par_name> specified in the encoding.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2539 ins_encode->reset();
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2540 const char *ec_name = ins_encode->encode_class_iter();
17797
2fcab8ba885a 8033168: PPC64: gcc 4.8 warning in output_c.cpp
goetz
parents: 17795
diff changeset
2541 assert(ec_name != NULL, "Postalloc expand must specify an encoding.");
14428
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2542
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2543 EncClass *encoding = _encode->encClass(ec_name);
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2544 if (encoding == NULL) {
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2545 fprintf(stderr, "User did not define contents of this encode_class: %s\n", ec_name);
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2546 abort();
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2547 }
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2548 if (ins_encode->current_encoding_num_args() != encoding->num_args()) {
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2549 globalAD->syntax_err(ins_encode->_linenum, "In %s: passing %d arguments to %s but expecting %d",
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2550 inst._ident, ins_encode->current_encoding_num_args(),
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2551 ec_name, encoding->num_args());
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2552 }
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2553
17797
2fcab8ba885a 8033168: PPC64: gcc 4.8 warning in output_c.cpp
goetz
parents: 17795
diff changeset
2554 fprintf(fp, " // Access to ins and operands for postalloc expand.\n");
14428
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2555 const int buflen = 2000;
17797
2fcab8ba885a 8033168: PPC64: gcc 4.8 warning in output_c.cpp
goetz
parents: 17795
diff changeset
2556 char idxbuf[buflen]; char *ib = idxbuf; idxbuf[0] = '\0';
2fcab8ba885a 8033168: PPC64: gcc 4.8 warning in output_c.cpp
goetz
parents: 17795
diff changeset
2557 char nbuf [buflen]; char *nb = nbuf; nbuf[0] = '\0';
2fcab8ba885a 8033168: PPC64: gcc 4.8 warning in output_c.cpp
goetz
parents: 17795
diff changeset
2558 char opbuf [buflen]; char *ob = opbuf; opbuf[0] = '\0';
14428
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2559
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2560 encoding->_parameter_type.reset();
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2561 encoding->_parameter_name.reset();
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2562 const char *type = encoding->_parameter_type.iter();
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2563 const char *name = encoding->_parameter_name.iter();
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2564 int param_no = 0;
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2565 for (; (type != NULL) && (name != NULL);
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2566 (type = encoding->_parameter_type.iter()), (name = encoding->_parameter_name.iter())) {
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2567 const char* arg_name = ins_encode->rep_var_name(inst, param_no);
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2568 int idx = inst.operand_position_format(arg_name);
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2569 if (strcmp(arg_name, "constanttablebase") == 0) {
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2570 ib += sprintf(ib, " unsigned idx_%-5s = mach_constant_base_node_input(); \t// %s, \t%s\n",
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2571 name, type, arg_name);
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2572 nb += sprintf(nb, " Node *n_%-7s = lookup(idx_%s);\n", name, name);
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2573 // There is no operand for the constanttablebase.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2574 } else if (inst.is_noninput_operand(idx)) {
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2575 globalAD->syntax_err(inst._linenum,
17797
2fcab8ba885a 8033168: PPC64: gcc 4.8 warning in output_c.cpp
goetz
parents: 17795
diff changeset
2576 "In %s: you can not pass the non-input %s to a postalloc expand encoding.\n",
14428
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2577 inst._ident, arg_name);
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2578 } else {
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2579 ib += sprintf(ib, " unsigned idx_%-5s = idx%d; \t// %s, \t%s\n",
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2580 name, idx, type, arg_name);
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2581 nb += sprintf(nb, " Node *n_%-7s = lookup(idx_%s);\n", name, name);
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2582 ob += sprintf(ob, " %sOper *op_%s = (%sOper *)opnd_array(%d);\n", type, name, type, idx);
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2583 }
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2584 param_no++;
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2585 }
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2586 assert(ib < &idxbuf[buflen-1] && nb < &nbuf[buflen-1] && ob < &opbuf[buflen-1], "buffer overflow");
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2587
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2588 fprintf(fp, "%s", idxbuf);
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2589 fprintf(fp, " Node *n_region = lookup(0);\n");
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2590 fprintf(fp, "%s%s", nbuf, opbuf);
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2591 fprintf(fp, " Compile *C = ra_->C;\n");
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2592
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2593 // Output this instruction's encodings.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2594 fprintf(fp, " {");
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2595 const char *ec_code = NULL;
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2596 const char *ec_rep_var = NULL;
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2597 assert(encoding == _encode->encClass(ec_name), "");
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2598
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2599 DefineEmitState pending(fp, *this, *encoding, *ins_encode, inst);
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2600 encoding->_code.reset();
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2601 encoding->_rep_vars.reset();
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2602 // Process list of user-defined strings,
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2603 // and occurrences of replacement variables.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2604 // Replacement Vars are pushed into a list and then output.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2605 while ((ec_code = encoding->_code.iter()) != NULL) {
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2606 if (! encoding->_code.is_signal(ec_code)) {
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2607 // Emit pending code.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2608 pending.emit();
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2609 pending.clear();
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2610 // Emit this code section.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2611 fprintf(fp, "%s", ec_code);
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2612 } else {
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2613 // A replacement variable or one of its subfields.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2614 // Obtain replacement variable from list.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2615 ec_rep_var = encoding->_rep_vars.iter();
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2616 pending.add_rep_var(ec_rep_var);
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2617 }
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2618 }
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2619 // Emit pending code.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2620 pending.emit();
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2621 pending.clear();
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2622 fprintf(fp, " }\n");
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2623
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2624 fprintf(fp, "}\n\n");
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2625
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2626 ec_name = ins_encode->encode_class_iter();
17797
2fcab8ba885a 8033168: PPC64: gcc 4.8 warning in output_c.cpp
goetz
parents: 17795
diff changeset
2627 assert(ec_name == NULL, "Postalloc expand may only have one encoding.");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2628 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2629
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2630 // defineEmit -----------------------------------------------------------------
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2631 void ArchDesc::defineEmit(FILE* fp, InstructForm& inst) {
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2632 InsEncode* encode = inst._insencode;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2633
a61af66fc99e Initial load
duke
parents:
diff changeset
2634 // (1)
a61af66fc99e Initial load
duke
parents:
diff changeset
2635 // Output instruction's emit prototype
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2636 fprintf(fp, "void %sNode::emit(CodeBuffer& cbuf, PhaseRegAlloc* ra_) const {\n", inst._ident);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2637
a61af66fc99e Initial load
duke
parents:
diff changeset
2638 // If user did not define an encode section,
a61af66fc99e Initial load
duke
parents:
diff changeset
2639 // provide stub that does not generate any machine code.
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2640 if( (_encode == NULL) || (encode == NULL) ) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2641 fprintf(fp, " // User did not define an encode section.\n");
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2642 fprintf(fp, "}\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2643 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2644 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2645
a61af66fc99e Initial load
duke
parents:
diff changeset
2646 // Save current instruction's starting address (helps with relocation).
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2647 fprintf(fp, " cbuf.set_insts_mark();\n");
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2648
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2649 // For MachConstantNodes which are ideal jump nodes, fill the jump table.
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2650 if (inst.is_mach_constant() && inst.is_ideal_jump()) {
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2651 fprintf(fp, " ra_->C->constant_table().fill_jump_table(cbuf, (MachConstantNode*) this, _index2label);\n");
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2652 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2653
a61af66fc99e Initial load
duke
parents:
diff changeset
2654 // Output each operand's offset into the array of registers.
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2655 inst.index_temps(fp, _globalNames);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2656
a61af66fc99e Initial load
duke
parents:
diff changeset
2657 // Output this instruction's encodings
a61af66fc99e Initial load
duke
parents:
diff changeset
2658 const char *ec_name;
a61af66fc99e Initial load
duke
parents:
diff changeset
2659 bool user_defined = false;
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2660 encode->reset();
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2661 while ((ec_name = encode->encode_class_iter()) != NULL) {
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2662 fprintf(fp, " {\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2663 // Output user-defined encoding
a61af66fc99e Initial load
duke
parents:
diff changeset
2664 user_defined = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
2665
a61af66fc99e Initial load
duke
parents:
diff changeset
2666 const char *ec_code = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
2667 const char *ec_rep_var = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
2668 EncClass *encoding = _encode->encClass(ec_name);
a61af66fc99e Initial load
duke
parents:
diff changeset
2669 if (encoding == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2670 fprintf(stderr, "User did not define contents of this encode_class: %s\n", ec_name);
a61af66fc99e Initial load
duke
parents:
diff changeset
2671 abort();
a61af66fc99e Initial load
duke
parents:
diff changeset
2672 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2673
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2674 if (encode->current_encoding_num_args() != encoding->num_args()) {
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2675 globalAD->syntax_err(encode->_linenum, "In %s: passing %d arguments to %s but expecting %d",
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2676 inst._ident, encode->current_encoding_num_args(),
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2677 ec_name, encoding->num_args());
a61af66fc99e Initial load
duke
parents:
diff changeset
2678 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2679
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2680 DefineEmitState pending(fp, *this, *encoding, *encode, inst);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2681 encoding->_code.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
2682 encoding->_rep_vars.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
2683 // Process list of user-defined strings,
a61af66fc99e Initial load
duke
parents:
diff changeset
2684 // and occurrences of replacement variables.
a61af66fc99e Initial load
duke
parents:
diff changeset
2685 // Replacement Vars are pushed into a list and then output
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2686 while ((ec_code = encoding->_code.iter()) != NULL) {
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2687 if (!encoding->_code.is_signal(ec_code)) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2688 // Emit pending code
a61af66fc99e Initial load
duke
parents:
diff changeset
2689 pending.emit();
a61af66fc99e Initial load
duke
parents:
diff changeset
2690 pending.clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
2691 // Emit this code section
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2692 fprintf(fp, "%s", ec_code);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2693 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2694 // A replacement variable or one of its subfields
a61af66fc99e Initial load
duke
parents:
diff changeset
2695 // Obtain replacement variable from list
a61af66fc99e Initial load
duke
parents:
diff changeset
2696 ec_rep_var = encoding->_rep_vars.iter();
a61af66fc99e Initial load
duke
parents:
diff changeset
2697 pending.add_rep_var(ec_rep_var);
a61af66fc99e Initial load
duke
parents:
diff changeset
2698 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2699 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2700 // Emit pending code
a61af66fc99e Initial load
duke
parents:
diff changeset
2701 pending.emit();
a61af66fc99e Initial load
duke
parents:
diff changeset
2702 pending.clear();
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2703 fprintf(fp, " }\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2704 } // end while instruction's encodings
a61af66fc99e Initial load
duke
parents:
diff changeset
2705
a61af66fc99e Initial load
duke
parents:
diff changeset
2706 // Check if user stated which encoding to user
a61af66fc99e Initial load
duke
parents:
diff changeset
2707 if ( user_defined == false ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2708 fprintf(fp, " // User did not define which encode class to use.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2709 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2710
a61af66fc99e Initial load
duke
parents:
diff changeset
2711 // (3) and (4)
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
2712 fprintf(fp, "}\n\n");
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2713 }
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2714
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2715 // defineEvalConstant ---------------------------------------------------------
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2716 void ArchDesc::defineEvalConstant(FILE* fp, InstructForm& inst) {
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2717 InsEncode* encode = inst._constant;
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2718
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2719 // (1)
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2720 // Output instruction's emit prototype
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2721 fprintf(fp, "void %sNode::eval_constant(Compile* C) {\n", inst._ident);
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2722
4114
6729bbc1fcd6 7003454: order constants in constant table by number of references in code
twisti
parents: 3853
diff changeset
2723 // For ideal jump nodes, add a jump-table entry.
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2724 if (inst.is_ideal_jump()) {
4114
6729bbc1fcd6 7003454: order constants in constant table by number of references in code
twisti
parents: 3853
diff changeset
2725 fprintf(fp, " _constant = C->constant_table().add_jump_table(this);\n");
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2726 }
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2727
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2728 // If user did not define an encode section,
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2729 // provide stub that does not generate any machine code.
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2730 if ((_encode == NULL) || (encode == NULL)) {
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2731 fprintf(fp, " // User did not define an encode section.\n");
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2732 fprintf(fp, "}\n");
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2733 return;
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2734 }
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2735
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2736 // Output this instruction's encodings
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2737 const char *ec_name;
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2738 bool user_defined = false;
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2739 encode->reset();
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2740 while ((ec_name = encode->encode_class_iter()) != NULL) {
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2741 fprintf(fp, " {\n");
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2742 // Output user-defined encoding
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2743 user_defined = true;
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2744
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2745 const char *ec_code = NULL;
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2746 const char *ec_rep_var = NULL;
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2747 EncClass *encoding = _encode->encClass(ec_name);
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2748 if (encoding == NULL) {
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2749 fprintf(stderr, "User did not define contents of this encode_class: %s\n", ec_name);
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2750 abort();
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2751 }
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2752
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2753 if (encode->current_encoding_num_args() != encoding->num_args()) {
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2754 globalAD->syntax_err(encode->_linenum, "In %s: passing %d arguments to %s but expecting %d",
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2755 inst._ident, encode->current_encoding_num_args(),
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2756 ec_name, encoding->num_args());
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2757 }
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2758
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2759 DefineEmitState pending(fp, *this, *encoding, *encode, inst);
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2760 encoding->_code.reset();
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2761 encoding->_rep_vars.reset();
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2762 // Process list of user-defined strings,
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2763 // and occurrences of replacement variables.
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2764 // Replacement Vars are pushed into a list and then output
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2765 while ((ec_code = encoding->_code.iter()) != NULL) {
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2766 if (!encoding->_code.is_signal(ec_code)) {
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2767 // Emit pending code
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2768 pending.emit();
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2769 pending.clear();
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2770 // Emit this code section
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2771 fprintf(fp, "%s", ec_code);
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2772 } else {
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2773 // A replacement variable or one of its subfields
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2774 // Obtain replacement variable from list
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2775 ec_rep_var = encoding->_rep_vars.iter();
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2776 pending.add_rep_var(ec_rep_var);
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2777 }
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2778 }
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2779 // Emit pending code
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2780 pending.emit();
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2781 pending.clear();
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2782 fprintf(fp, " }\n");
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2783 } // end while instruction's encodings
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2784
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2785 // Check if user stated which encoding to user
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2786 if (user_defined == false) {
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2787 fprintf(fp, " // User did not define which encode class to use.\n");
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2788 }
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2789
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2790 // (3) and (4)
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
2791 fprintf(fp, "}\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2792 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2793
a61af66fc99e Initial load
duke
parents:
diff changeset
2794 // ---------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
2795 //--------Utilities to build MachOper and MachNode derived Classes------------
a61af66fc99e Initial load
duke
parents:
diff changeset
2796 // ---------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
2797
a61af66fc99e Initial load
duke
parents:
diff changeset
2798 //------------------------------Utilities to build Operand Classes------------
a61af66fc99e Initial load
duke
parents:
diff changeset
2799 static void defineIn_RegMask(FILE *fp, FormDict &globals, OperandForm &oper) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2800 uint num_edges = oper.num_edges(globals);
a61af66fc99e Initial load
duke
parents:
diff changeset
2801 if( num_edges != 0 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2802 // Method header
a61af66fc99e Initial load
duke
parents:
diff changeset
2803 fprintf(fp, "const RegMask *%sOper::in_RegMask(int index) const {\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
2804 oper._ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
2805
a61af66fc99e Initial load
duke
parents:
diff changeset
2806 // Assert that the index is in range.
a61af66fc99e Initial load
duke
parents:
diff changeset
2807 fprintf(fp, " assert(0 <= index && index < %d, \"index out of range\");\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
2808 num_edges);
a61af66fc99e Initial load
duke
parents:
diff changeset
2809
a61af66fc99e Initial load
duke
parents:
diff changeset
2810 // Figure out if all RegMasks are the same.
a61af66fc99e Initial load
duke
parents:
diff changeset
2811 const char* first_reg_class = oper.in_reg_class(0, globals);
a61af66fc99e Initial load
duke
parents:
diff changeset
2812 bool all_same = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
2813 assert(first_reg_class != NULL, "did not find register mask");
a61af66fc99e Initial load
duke
parents:
diff changeset
2814
a61af66fc99e Initial load
duke
parents:
diff changeset
2815 for (uint index = 1; all_same && index < num_edges; index++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2816 const char* some_reg_class = oper.in_reg_class(index, globals);
a61af66fc99e Initial load
duke
parents:
diff changeset
2817 assert(some_reg_class != NULL, "did not find register mask");
a61af66fc99e Initial load
duke
parents:
diff changeset
2818 if (strcmp(first_reg_class, some_reg_class) != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2819 all_same = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
2820 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2821 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2822
a61af66fc99e Initial load
duke
parents:
diff changeset
2823 if (all_same) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2824 // Return the sole RegMask.
a61af66fc99e Initial load
duke
parents:
diff changeset
2825 if (strcmp(first_reg_class, "stack_slots") == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2826 fprintf(fp," return &(Compile::current()->FIRST_STACK_mask());\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2827 } else {
9078
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
2828 const char* first_reg_class_to_upper = toUpper(first_reg_class);
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
2829 fprintf(fp," return &%s_mask();\n", first_reg_class_to_upper);
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
2830 delete[] first_reg_class_to_upper;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2831 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2832 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2833 // Build a switch statement to return the desired mask.
a61af66fc99e Initial load
duke
parents:
diff changeset
2834 fprintf(fp," switch (index) {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2835
a61af66fc99e Initial load
duke
parents:
diff changeset
2836 for (uint index = 0; index < num_edges; index++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2837 const char *reg_class = oper.in_reg_class(index, globals);
a61af66fc99e Initial load
duke
parents:
diff changeset
2838 assert(reg_class != NULL, "did not find register mask");
a61af66fc99e Initial load
duke
parents:
diff changeset
2839 if( !strcmp(reg_class, "stack_slots") ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2840 fprintf(fp, " case %d: return &(Compile::current()->FIRST_STACK_mask());\n", index);
a61af66fc99e Initial load
duke
parents:
diff changeset
2841 } else {
9078
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
2842 const char* reg_class_to_upper = toUpper(reg_class);
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
2843 fprintf(fp, " case %d: return &%s_mask();\n", index, reg_class_to_upper);
705ef39fcaa9 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 6850
diff changeset
2844 delete[] reg_class_to_upper;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2845 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2846 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2847 fprintf(fp," }\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2848 fprintf(fp," ShouldNotReachHere();\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2849 fprintf(fp," return NULL;\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2850 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2851
a61af66fc99e Initial load
duke
parents:
diff changeset
2852 // Method close
a61af66fc99e Initial load
duke
parents:
diff changeset
2853 fprintf(fp, "}\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2854 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2855 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2856
a61af66fc99e Initial load
duke
parents:
diff changeset
2857 // generate code to create a clone for a class derived from MachOper
a61af66fc99e Initial load
duke
parents:
diff changeset
2858 //
a61af66fc99e Initial load
duke
parents:
diff changeset
2859 // (0) MachOper *MachOperXOper::clone(Compile* C) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
2860 // (1) return new (C) MachXOper( _ccode, _c0, _c1, ..., _cn);
a61af66fc99e Initial load
duke
parents:
diff changeset
2861 // (2) }
a61af66fc99e Initial load
duke
parents:
diff changeset
2862 //
a61af66fc99e Initial load
duke
parents:
diff changeset
2863 static void defineClone(FILE *fp, FormDict &globalNames, OperandForm &oper) {
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
2864 fprintf(fp,"MachOper *%sOper::clone(Compile* C) const {\n", oper._ident);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2865 // Check for constants that need to be copied over
a61af66fc99e Initial load
duke
parents:
diff changeset
2866 const int num_consts = oper.num_consts(globalNames);
a61af66fc99e Initial load
duke
parents:
diff changeset
2867 const bool is_ideal_bool = oper.is_ideal_bool();
a61af66fc99e Initial load
duke
parents:
diff changeset
2868 if( (num_consts > 0) ) {
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
2869 fprintf(fp," return new (C) %sOper(", oper._ident);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2870 // generate parameters for constants
a61af66fc99e Initial load
duke
parents:
diff changeset
2871 int i = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
2872 fprintf(fp,"_c%d", i);
a61af66fc99e Initial load
duke
parents:
diff changeset
2873 for( i = 1; i < num_consts; ++i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2874 fprintf(fp,", _c%d", i);
a61af66fc99e Initial load
duke
parents:
diff changeset
2875 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2876 // finish line (1)
a61af66fc99e Initial load
duke
parents:
diff changeset
2877 fprintf(fp,");\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2878 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2879 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2880 assert( num_consts == 0, "Currently support zero or one constant per operand clone function");
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
2881 fprintf(fp," return new (C) %sOper();\n", oper._ident);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2882 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2883 // finish method
a61af66fc99e Initial load
duke
parents:
diff changeset
2884 fprintf(fp,"}\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2885 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2886
a61af66fc99e Initial load
duke
parents:
diff changeset
2887 // Helper functions for bug 4796752, abstracted with minimal modification
a61af66fc99e Initial load
duke
parents:
diff changeset
2888 // from define_oper_interface()
a61af66fc99e Initial load
duke
parents:
diff changeset
2889 OperandForm *rep_var_to_operand(const char *encoding, OperandForm &oper, FormDict &globals) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2890 OperandForm *op = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
2891 // Check for replacement variable
a61af66fc99e Initial load
duke
parents:
diff changeset
2892 if( *encoding == '$' ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2893 // Replacement variable
a61af66fc99e Initial load
duke
parents:
diff changeset
2894 const char *rep_var = encoding + 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
2895 // Lookup replacement variable, rep_var, in operand's component list
a61af66fc99e Initial load
duke
parents:
diff changeset
2896 const Component *comp = oper._components.search(rep_var);
a61af66fc99e Initial load
duke
parents:
diff changeset
2897 assert( comp != NULL, "Replacement variable not found in components");
a61af66fc99e Initial load
duke
parents:
diff changeset
2898 // Lookup operand form for replacement variable's type
a61af66fc99e Initial load
duke
parents:
diff changeset
2899 const char *type = comp->_type;
a61af66fc99e Initial load
duke
parents:
diff changeset
2900 Form *form = (Form*)globals[type];
a61af66fc99e Initial load
duke
parents:
diff changeset
2901 assert( form != NULL, "Replacement variable's type not found");
a61af66fc99e Initial load
duke
parents:
diff changeset
2902 op = form->is_operand();
a61af66fc99e Initial load
duke
parents:
diff changeset
2903 assert( op, "Attempting to emit a non-register or non-constant");
a61af66fc99e Initial load
duke
parents:
diff changeset
2904 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2905
a61af66fc99e Initial load
duke
parents:
diff changeset
2906 return op;
a61af66fc99e Initial load
duke
parents:
diff changeset
2907 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2908
a61af66fc99e Initial load
duke
parents:
diff changeset
2909 int rep_var_to_constant_index(const char *encoding, OperandForm &oper, FormDict &globals) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2910 int idx = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
2911 // Check for replacement variable
a61af66fc99e Initial load
duke
parents:
diff changeset
2912 if( *encoding == '$' ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2913 // Replacement variable
a61af66fc99e Initial load
duke
parents:
diff changeset
2914 const char *rep_var = encoding + 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
2915 // Lookup replacement variable, rep_var, in operand's component list
a61af66fc99e Initial load
duke
parents:
diff changeset
2916 const Component *comp = oper._components.search(rep_var);
a61af66fc99e Initial load
duke
parents:
diff changeset
2917 assert( comp != NULL, "Replacement variable not found in components");
a61af66fc99e Initial load
duke
parents:
diff changeset
2918 // Lookup operand form for replacement variable's type
a61af66fc99e Initial load
duke
parents:
diff changeset
2919 const char *type = comp->_type;
a61af66fc99e Initial load
duke
parents:
diff changeset
2920 Form *form = (Form*)globals[type];
a61af66fc99e Initial load
duke
parents:
diff changeset
2921 assert( form != NULL, "Replacement variable's type not found");
a61af66fc99e Initial load
duke
parents:
diff changeset
2922 OperandForm *op = form->is_operand();
a61af66fc99e Initial load
duke
parents:
diff changeset
2923 assert( op, "Attempting to emit a non-register or non-constant");
a61af66fc99e Initial load
duke
parents:
diff changeset
2924 // Check that this is a constant and find constant's index:
a61af66fc99e Initial load
duke
parents:
diff changeset
2925 if (op->_matrule && op->_matrule->is_base_constant(globals)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2926 idx = oper.constant_position(globals, comp);
a61af66fc99e Initial load
duke
parents:
diff changeset
2927 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2928 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2929
a61af66fc99e Initial load
duke
parents:
diff changeset
2930 return idx;
a61af66fc99e Initial load
duke
parents:
diff changeset
2931 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2932
a61af66fc99e Initial load
duke
parents:
diff changeset
2933 bool is_regI(const char *encoding, OperandForm &oper, FormDict &globals ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2934 bool is_regI = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
2935
a61af66fc99e Initial load
duke
parents:
diff changeset
2936 OperandForm *op = rep_var_to_operand(encoding, oper, globals);
a61af66fc99e Initial load
duke
parents:
diff changeset
2937 if( op != NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2938 // Check that this is a register
a61af66fc99e Initial load
duke
parents:
diff changeset
2939 if ( (op->_matrule && op->_matrule->is_base_register(globals)) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2940 // Register
a61af66fc99e Initial load
duke
parents:
diff changeset
2941 const char* ideal = op->ideal_type(globals);
a61af66fc99e Initial load
duke
parents:
diff changeset
2942 is_regI = (ideal && (op->ideal_to_Reg_type(ideal) == Form::idealI));
a61af66fc99e Initial load
duke
parents:
diff changeset
2943 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2944 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2945
a61af66fc99e Initial load
duke
parents:
diff changeset
2946 return is_regI;
a61af66fc99e Initial load
duke
parents:
diff changeset
2947 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2948
a61af66fc99e Initial load
duke
parents:
diff changeset
2949 bool is_conP(const char *encoding, OperandForm &oper, FormDict &globals ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2950 bool is_conP = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
2951
a61af66fc99e Initial load
duke
parents:
diff changeset
2952 OperandForm *op = rep_var_to_operand(encoding, oper, globals);
a61af66fc99e Initial load
duke
parents:
diff changeset
2953 if( op != NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2954 // Check that this is a constant pointer
a61af66fc99e Initial load
duke
parents:
diff changeset
2955 if (op->_matrule && op->_matrule->is_base_constant(globals)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2956 // Constant
a61af66fc99e Initial load
duke
parents:
diff changeset
2957 Form::DataType dtype = op->is_base_constant(globals);
a61af66fc99e Initial load
duke
parents:
diff changeset
2958 is_conP = (dtype == Form::idealP);
a61af66fc99e Initial load
duke
parents:
diff changeset
2959 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2960 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2961
a61af66fc99e Initial load
duke
parents:
diff changeset
2962 return is_conP;
a61af66fc99e Initial load
duke
parents:
diff changeset
2963 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2964
a61af66fc99e Initial load
duke
parents:
diff changeset
2965
a61af66fc99e Initial load
duke
parents:
diff changeset
2966 // Define a MachOper interface methods
a61af66fc99e Initial load
duke
parents:
diff changeset
2967 void ArchDesc::define_oper_interface(FILE *fp, OperandForm &oper, FormDict &globals,
a61af66fc99e Initial load
duke
parents:
diff changeset
2968 const char *name, const char *encoding) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2969 bool emit_position = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
2970 int position = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
2971
a61af66fc99e Initial load
duke
parents:
diff changeset
2972 fprintf(fp," virtual int %s", name);
a61af66fc99e Initial load
duke
parents:
diff changeset
2973 // Generate access method for base, index, scale, disp, ...
a61af66fc99e Initial load
duke
parents:
diff changeset
2974 if( (strcmp(name,"base") == 0) || (strcmp(name,"index") == 0) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2975 fprintf(fp,"(PhaseRegAlloc *ra_, const Node *node, int idx) const { \n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2976 emit_position = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
2977 } else if ( (strcmp(name,"disp") == 0) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2978 fprintf(fp,"(PhaseRegAlloc *ra_, const Node *node, int idx) const { \n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2979 } else {
14428
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
2980 fprintf(fp, "() const {\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2981 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2982
a61af66fc99e Initial load
duke
parents:
diff changeset
2983 // Check for hexadecimal value OR replacement variable
a61af66fc99e Initial load
duke
parents:
diff changeset
2984 if( *encoding == '$' ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2985 // Replacement variable
a61af66fc99e Initial load
duke
parents:
diff changeset
2986 const char *rep_var = encoding + 1;
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
2987 fprintf(fp," // Replacement variable: %s\n", encoding+1);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2988 // Lookup replacement variable, rep_var, in operand's component list
a61af66fc99e Initial load
duke
parents:
diff changeset
2989 const Component *comp = oper._components.search(rep_var);
a61af66fc99e Initial load
duke
parents:
diff changeset
2990 assert( comp != NULL, "Replacement variable not found in components");
a61af66fc99e Initial load
duke
parents:
diff changeset
2991 // Lookup operand form for replacement variable's type
a61af66fc99e Initial load
duke
parents:
diff changeset
2992 const char *type = comp->_type;
a61af66fc99e Initial load
duke
parents:
diff changeset
2993 Form *form = (Form*)globals[type];
a61af66fc99e Initial load
duke
parents:
diff changeset
2994 assert( form != NULL, "Replacement variable's type not found");
a61af66fc99e Initial load
duke
parents:
diff changeset
2995 OperandForm *op = form->is_operand();
a61af66fc99e Initial load
duke
parents:
diff changeset
2996 assert( op, "Attempting to emit a non-register or non-constant");
a61af66fc99e Initial load
duke
parents:
diff changeset
2997 // Check that this is a register or a constant and generate code:
a61af66fc99e Initial load
duke
parents:
diff changeset
2998 if ( (op->_matrule && op->_matrule->is_base_register(globals)) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2999 // Register
a61af66fc99e Initial load
duke
parents:
diff changeset
3000 int idx_offset = oper.register_position( globals, rep_var);
a61af66fc99e Initial load
duke
parents:
diff changeset
3001 position = idx_offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
3002 fprintf(fp," return (int)ra_->get_encode(node->in(idx");
a61af66fc99e Initial load
duke
parents:
diff changeset
3003 if ( idx_offset > 0 ) fprintf(fp, "+%d",idx_offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
3004 fprintf(fp,"));\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3005 } else if ( op->ideal_to_sReg_type(op->_ident) != Form::none ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3006 // StackSlot for an sReg comes either from input node or from self, when idx==0
a61af66fc99e Initial load
duke
parents:
diff changeset
3007 fprintf(fp," if( idx != 0 ) {\n");
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
3008 fprintf(fp," // Access stack offset (register number) for input operand\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3009 fprintf(fp," return ra_->reg2offset(ra_->get_reg_first(node->in(idx)));/* sReg */\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3010 fprintf(fp," }\n");
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
3011 fprintf(fp," // Access stack offset (register number) from myself\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3012 fprintf(fp," return ra_->reg2offset(ra_->get_reg_first(node));/* sReg */\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3013 } else if (op->_matrule && op->_matrule->is_base_constant(globals)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3014 // Constant
a61af66fc99e Initial load
duke
parents:
diff changeset
3015 // Check which constant this name maps to: _c0, _c1, ..., _cn
a61af66fc99e Initial load
duke
parents:
diff changeset
3016 const int idx = oper.constant_position(globals, comp);
a61af66fc99e Initial load
duke
parents:
diff changeset
3017 assert( idx != -1, "Constant component not found in operand");
a61af66fc99e Initial load
duke
parents:
diff changeset
3018 // Output code for this constant, type dependent.
a61af66fc99e Initial load
duke
parents:
diff changeset
3019 fprintf(fp," return (int)" );
a61af66fc99e Initial load
duke
parents:
diff changeset
3020 oper.access_constant(fp, globals, (uint)idx /* , const_type */);
a61af66fc99e Initial load
duke
parents:
diff changeset
3021 fprintf(fp,";\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3022 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
3023 assert( false, "Attempting to emit a non-register or non-constant");
a61af66fc99e Initial load
duke
parents:
diff changeset
3024 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3025 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3026 else if( *encoding == '0' && *(encoding+1) == 'x' ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3027 // Hex value
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
3028 fprintf(fp," return %s;\n", encoding);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3029 } else {
14428
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
3030 globalAD->syntax_err(oper._linenum, "In operand %s: Do not support this encode constant: '%s' for %s.",
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
3031 oper._ident, encoding, name);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3032 assert( false, "Do not support octal or decimal encode constants");
a61af66fc99e Initial load
duke
parents:
diff changeset
3033 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3034 fprintf(fp," }\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3035
a61af66fc99e Initial load
duke
parents:
diff changeset
3036 if( emit_position && (position != -1) && (oper.num_edges(globals) > 0) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3037 fprintf(fp," virtual int %s_position() const { return %d; }\n", name, position);
a61af66fc99e Initial load
duke
parents:
diff changeset
3038 MemInterface *mem_interface = oper._interface->is_MemInterface();
a61af66fc99e Initial load
duke
parents:
diff changeset
3039 const char *base = mem_interface->_base;
a61af66fc99e Initial load
duke
parents:
diff changeset
3040 const char *disp = mem_interface->_disp;
a61af66fc99e Initial load
duke
parents:
diff changeset
3041 if( emit_position && (strcmp(name,"base") == 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
3042 && base != NULL && is_regI(base, oper, globals)
a61af66fc99e Initial load
duke
parents:
diff changeset
3043 && disp != NULL && is_conP(disp, oper, globals) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3044 // Found a memory access using a constant pointer for a displacement
a61af66fc99e Initial load
duke
parents:
diff changeset
3045 // and a base register containing an integer offset.
a61af66fc99e Initial load
duke
parents:
diff changeset
3046 // In this case the base and disp are reversed with respect to what
a61af66fc99e Initial load
duke
parents:
diff changeset
3047 // is expected by MachNode::get_base_and_disp() and MachNode::adr_type().
a61af66fc99e Initial load
duke
parents:
diff changeset
3048 // Provide a non-NULL return for disp_as_type() that will allow adr_type()
a61af66fc99e Initial load
duke
parents:
diff changeset
3049 // to correctly compute the access type for alias analysis.
a61af66fc99e Initial load
duke
parents:
diff changeset
3050 //
a61af66fc99e Initial load
duke
parents:
diff changeset
3051 // See BugId 4796752, operand indOffset32X in i486.ad
a61af66fc99e Initial load
duke
parents:
diff changeset
3052 int idx = rep_var_to_constant_index(disp, oper, globals);
a61af66fc99e Initial load
duke
parents:
diff changeset
3053 fprintf(fp," virtual const TypePtr *disp_as_type() const { return _c%d; }\n", idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
3054 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3055 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3056 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3057
a61af66fc99e Initial load
duke
parents:
diff changeset
3058 //
a61af66fc99e Initial load
duke
parents:
diff changeset
3059 // Construct the method to copy _idx, inputs and operands to new node.
a61af66fc99e Initial load
duke
parents:
diff changeset
3060 static void define_fill_new_machnode(bool used, FILE *fp_cpp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3061 fprintf(fp_cpp, "\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3062 fprintf(fp_cpp, "// Copy _idx, inputs and operands to new node\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3063 fprintf(fp_cpp, "void MachNode::fill_new_machnode( MachNode* node, Compile* C) const {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3064 if( !used ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3065 fprintf(fp_cpp, " // This architecture does not have cisc or short branch instructions\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3066 fprintf(fp_cpp, " ShouldNotCallThis();\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3067 fprintf(fp_cpp, "}\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3068 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
3069 // New node must use same node index for access through allocator's tables
a61af66fc99e Initial load
duke
parents:
diff changeset
3070 fprintf(fp_cpp, " // New node must use same node index\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3071 fprintf(fp_cpp, " node->set_idx( _idx );\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3072 // Copy machine-independent inputs
a61af66fc99e Initial load
duke
parents:
diff changeset
3073 fprintf(fp_cpp, " // Copy machine-independent inputs\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3074 fprintf(fp_cpp, " for( uint j = 0; j < req(); j++ ) {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3075 fprintf(fp_cpp, " node->add_req(in(j));\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3076 fprintf(fp_cpp, " }\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3077 // Copy machine operands to new MachNode
a61af66fc99e Initial load
duke
parents:
diff changeset
3078 fprintf(fp_cpp, " // Copy my operands, except for cisc position\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3079 fprintf(fp_cpp, " int nopnds = num_opnds();\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3080 fprintf(fp_cpp, " assert( node->num_opnds() == (uint)nopnds, \"Must have same number of operands\");\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3081 fprintf(fp_cpp, " MachOper **to = node->_opnds;\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3082 fprintf(fp_cpp, " for( int i = 0; i < nopnds; i++ ) {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3083 fprintf(fp_cpp, " if( i != cisc_operand() ) \n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3084 fprintf(fp_cpp, " to[i] = _opnds[i]->clone(C);\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3085 fprintf(fp_cpp, " }\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3086 fprintf(fp_cpp, "}\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3087 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3088 fprintf(fp_cpp, "\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3089 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3090
a61af66fc99e Initial load
duke
parents:
diff changeset
3091 //------------------------------defineClasses----------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
3092 // Define members of MachNode and MachOper classes based on
a61af66fc99e Initial load
duke
parents:
diff changeset
3093 // operand and instruction lists
a61af66fc99e Initial load
duke
parents:
diff changeset
3094 void ArchDesc::defineClasses(FILE *fp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3095
a61af66fc99e Initial load
duke
parents:
diff changeset
3096 // Define the contents of an array containing the machine register names
a61af66fc99e Initial load
duke
parents:
diff changeset
3097 defineRegNames(fp, _register);
a61af66fc99e Initial load
duke
parents:
diff changeset
3098 // Define an array containing the machine register encoding values
a61af66fc99e Initial load
duke
parents:
diff changeset
3099 defineRegEncodes(fp, _register);
a61af66fc99e Initial load
duke
parents:
diff changeset
3100 // Generate an enumeration of user-defined register classes
a61af66fc99e Initial load
duke
parents:
diff changeset
3101 // and a list of register masks, one for each class.
a61af66fc99e Initial load
duke
parents:
diff changeset
3102 // Only define the RegMask value objects in the expand file.
a61af66fc99e Initial load
duke
parents:
diff changeset
3103 // Declare each as an extern const RegMask ...; in ad_<arch>.hpp
a61af66fc99e Initial load
duke
parents:
diff changeset
3104 declare_register_masks(_HPP_file._fp);
a61af66fc99e Initial load
duke
parents:
diff changeset
3105 // build_register_masks(fp);
a61af66fc99e Initial load
duke
parents:
diff changeset
3106 build_register_masks(_CPP_EXPAND_file._fp);
a61af66fc99e Initial load
duke
parents:
diff changeset
3107 // Define the pipe_classes
a61af66fc99e Initial load
duke
parents:
diff changeset
3108 build_pipe_classes(_CPP_PIPELINE_file._fp);
a61af66fc99e Initial load
duke
parents:
diff changeset
3109
a61af66fc99e Initial load
duke
parents:
diff changeset
3110 // Generate Machine Classes for each operand defined in AD file
a61af66fc99e Initial load
duke
parents:
diff changeset
3111 fprintf(fp,"\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3112 fprintf(fp,"\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3113 fprintf(fp,"//------------------Define classes derived from MachOper---------------------\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3114 // Iterate through all operands
a61af66fc99e Initial load
duke
parents:
diff changeset
3115 _operands.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
3116 OperandForm *oper;
a61af66fc99e Initial load
duke
parents:
diff changeset
3117 for( ; (oper = (OperandForm*)_operands.iter()) != NULL; ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3118 // Ensure this is a machine-world instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
3119 if ( oper->ideal_only() ) continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
3120 // !!!!!
a61af66fc99e Initial load
duke
parents:
diff changeset
3121 // The declaration of labelOper is in machine-independent file: machnode
a61af66fc99e Initial load
duke
parents:
diff changeset
3122 if ( strcmp(oper->_ident,"label") == 0 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3123 defineIn_RegMask(_CPP_MISC_file._fp, _globalNames, *oper);
a61af66fc99e Initial load
duke
parents:
diff changeset
3124
a61af66fc99e Initial load
duke
parents:
diff changeset
3125 fprintf(fp,"MachOper *%sOper::clone(Compile* C) const {\n", oper->_ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
3126 fprintf(fp," return new (C) %sOper(_label, _block_num);\n", oper->_ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
3127 fprintf(fp,"}\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3128
a61af66fc99e Initial load
duke
parents:
diff changeset
3129 fprintf(fp,"uint %sOper::opcode() const { return %s; }\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
3130 oper->_ident, machOperEnum(oper->_ident));
a61af66fc99e Initial load
duke
parents:
diff changeset
3131 // // Currently all XXXOper::Hash() methods are identical (990820)
a61af66fc99e Initial load
duke
parents:
diff changeset
3132 // define_hash(fp, oper->_ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
3133 // // Currently all XXXOper::Cmp() methods are identical (990820)
a61af66fc99e Initial load
duke
parents:
diff changeset
3134 // define_cmp(fp, oper->_ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
3135 fprintf(fp,"\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3136
a61af66fc99e Initial load
duke
parents:
diff changeset
3137 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
3138 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3139
a61af66fc99e Initial load
duke
parents:
diff changeset
3140 // The declaration of methodOper is in machine-independent file: machnode
a61af66fc99e Initial load
duke
parents:
diff changeset
3141 if ( strcmp(oper->_ident,"method") == 0 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3142 defineIn_RegMask(_CPP_MISC_file._fp, _globalNames, *oper);
a61af66fc99e Initial load
duke
parents:
diff changeset
3143
a61af66fc99e Initial load
duke
parents:
diff changeset
3144 fprintf(fp,"MachOper *%sOper::clone(Compile* C) const {\n", oper->_ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
3145 fprintf(fp," return new (C) %sOper(_method);\n", oper->_ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
3146 fprintf(fp,"}\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3147
a61af66fc99e Initial load
duke
parents:
diff changeset
3148 fprintf(fp,"uint %sOper::opcode() const { return %s; }\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
3149 oper->_ident, machOperEnum(oper->_ident));
a61af66fc99e Initial load
duke
parents:
diff changeset
3150 // // Currently all XXXOper::Hash() methods are identical (990820)
a61af66fc99e Initial load
duke
parents:
diff changeset
3151 // define_hash(fp, oper->_ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
3152 // // Currently all XXXOper::Cmp() methods are identical (990820)
a61af66fc99e Initial load
duke
parents:
diff changeset
3153 // define_cmp(fp, oper->_ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
3154 fprintf(fp,"\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3155
a61af66fc99e Initial load
duke
parents:
diff changeset
3156 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
3157 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3158
a61af66fc99e Initial load
duke
parents:
diff changeset
3159 defineIn_RegMask(fp, _globalNames, *oper);
a61af66fc99e Initial load
duke
parents:
diff changeset
3160 defineClone(_CPP_CLONE_file._fp, _globalNames, *oper);
a61af66fc99e Initial load
duke
parents:
diff changeset
3161 // // Currently all XXXOper::Hash() methods are identical (990820)
a61af66fc99e Initial load
duke
parents:
diff changeset
3162 // define_hash(fp, oper->_ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
3163 // // Currently all XXXOper::Cmp() methods are identical (990820)
a61af66fc99e Initial load
duke
parents:
diff changeset
3164 // define_cmp(fp, oper->_ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
3165
a61af66fc99e Initial load
duke
parents:
diff changeset
3166 // side-call to generate output that used to be in the header file:
a61af66fc99e Initial load
duke
parents:
diff changeset
3167 extern void gen_oper_format(FILE *fp, FormDict &globals, OperandForm &oper, bool for_c_file);
a61af66fc99e Initial load
duke
parents:
diff changeset
3168 gen_oper_format(_CPP_FORMAT_file._fp, _globalNames, *oper, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
3169
a61af66fc99e Initial load
duke
parents:
diff changeset
3170 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3171
a61af66fc99e Initial load
duke
parents:
diff changeset
3172
a61af66fc99e Initial load
duke
parents:
diff changeset
3173 // Generate Machine Classes for each instruction defined in AD file
a61af66fc99e Initial load
duke
parents:
diff changeset
3174 fprintf(fp,"//------------------Define members for classes derived from MachNode----------\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3175 // Output the definitions for out_RegMask() // & kill_RegMask()
a61af66fc99e Initial load
duke
parents:
diff changeset
3176 _instructions.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
3177 InstructForm *instr;
a61af66fc99e Initial load
duke
parents:
diff changeset
3178 MachNodeForm *machnode;
a61af66fc99e Initial load
duke
parents:
diff changeset
3179 for( ; (instr = (InstructForm*)_instructions.iter()) != NULL; ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3180 // Ensure this is a machine-world instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
3181 if ( instr->ideal_only() ) continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
3182
a61af66fc99e Initial load
duke
parents:
diff changeset
3183 defineOut_RegMask(_CPP_MISC_file._fp, instr->_ident, reg_mask(*instr));
a61af66fc99e Initial load
duke
parents:
diff changeset
3184 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3185
a61af66fc99e Initial load
duke
parents:
diff changeset
3186 bool used = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
3187 // Output the definitions for expand rules & peephole rules
a61af66fc99e Initial load
duke
parents:
diff changeset
3188 _instructions.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
3189 for( ; (instr = (InstructForm*)_instructions.iter()) != NULL; ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3190 // Ensure this is a machine-world instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
3191 if ( instr->ideal_only() ) continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
3192 // If there are multiple defs/kills, or an explicit expand rule, build rule
a61af66fc99e Initial load
duke
parents:
diff changeset
3193 if( instr->expands() || instr->needs_projections() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
3194 instr->has_temps() ||
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
3195 instr->is_mach_constant() ||
14434
318d0622a6d7 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 14431
diff changeset
3196 instr->needs_constant_base() ||
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3197 instr->_matrule != NULL &&
a61af66fc99e Initial load
duke
parents:
diff changeset
3198 instr->num_opnds() != instr->num_unique_opnds() )
a61af66fc99e Initial load
duke
parents:
diff changeset
3199 defineExpand(_CPP_EXPAND_file._fp, instr);
a61af66fc99e Initial load
duke
parents:
diff changeset
3200 // If there is an explicit peephole rule, build it
a61af66fc99e Initial load
duke
parents:
diff changeset
3201 if ( instr->peepholes() )
a61af66fc99e Initial load
duke
parents:
diff changeset
3202 definePeephole(_CPP_PEEPHOLE_file._fp, instr);
a61af66fc99e Initial load
duke
parents:
diff changeset
3203
a61af66fc99e Initial load
duke
parents:
diff changeset
3204 // Output code to convert to the cisc version, if applicable
a61af66fc99e Initial load
duke
parents:
diff changeset
3205 used |= instr->define_cisc_version(*this, fp);
a61af66fc99e Initial load
duke
parents:
diff changeset
3206
a61af66fc99e Initial load
duke
parents:
diff changeset
3207 // Output code to convert to the short branch version, if applicable
1541
b5fdf39b9749 6953576: bottom_type for matched AddPNodes doesn't always agree with ideal
never
parents: 1489
diff changeset
3208 used |= instr->define_short_branch_methods(*this, fp);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3209 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3210
a61af66fc99e Initial load
duke
parents:
diff changeset
3211 // Construct the method called by cisc_version() to copy inputs and operands.
a61af66fc99e Initial load
duke
parents:
diff changeset
3212 define_fill_new_machnode(used, fp);
a61af66fc99e Initial load
duke
parents:
diff changeset
3213
a61af66fc99e Initial load
duke
parents:
diff changeset
3214 // Output the definitions for labels
a61af66fc99e Initial load
duke
parents:
diff changeset
3215 _instructions.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
3216 while( (instr = (InstructForm*)_instructions.iter()) != NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3217 // Ensure this is a machine-world instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
3218 if ( instr->ideal_only() ) continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
3219
a61af66fc99e Initial load
duke
parents:
diff changeset
3220 // Access the fields for operand Label
a61af66fc99e Initial load
duke
parents:
diff changeset
3221 int label_position = instr->label_position();
a61af66fc99e Initial load
duke
parents:
diff changeset
3222 if( label_position != -1 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3223 // Set the label
3839
3d42f82cd811 7063628: Use cbcond on T4
kvn
parents: 2426
diff changeset
3224 fprintf(fp,"void %sNode::label_set( Label* label, uint block_num ) {\n", instr->_ident);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3225 fprintf(fp," labelOper* oper = (labelOper*)(opnd_array(%d));\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
3226 label_position );
3839
3d42f82cd811 7063628: Use cbcond on T4
kvn
parents: 2426
diff changeset
3227 fprintf(fp," oper->_label = label;\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3228 fprintf(fp," oper->_block_num = block_num;\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3229 fprintf(fp,"}\n");
3853
11211f7cb5a0 7079317: Incorrect branch's destination block in PrintoOptoAssembly output
kvn
parents: 3839
diff changeset
3230 // Save the label
11211f7cb5a0 7079317: Incorrect branch's destination block in PrintoOptoAssembly output
kvn
parents: 3839
diff changeset
3231 fprintf(fp,"void %sNode::save_label( Label** label, uint* block_num ) {\n", instr->_ident);
11211f7cb5a0 7079317: Incorrect branch's destination block in PrintoOptoAssembly output
kvn
parents: 3839
diff changeset
3232 fprintf(fp," labelOper* oper = (labelOper*)(opnd_array(%d));\n",
11211f7cb5a0 7079317: Incorrect branch's destination block in PrintoOptoAssembly output
kvn
parents: 3839
diff changeset
3233 label_position );
11211f7cb5a0 7079317: Incorrect branch's destination block in PrintoOptoAssembly output
kvn
parents: 3839
diff changeset
3234 fprintf(fp," *label = oper->_label;\n");
11211f7cb5a0 7079317: Incorrect branch's destination block in PrintoOptoAssembly output
kvn
parents: 3839
diff changeset
3235 fprintf(fp," *block_num = oper->_block_num;\n");
11211f7cb5a0 7079317: Incorrect branch's destination block in PrintoOptoAssembly output
kvn
parents: 3839
diff changeset
3236 fprintf(fp,"}\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3237 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3238 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3239
a61af66fc99e Initial load
duke
parents:
diff changeset
3240 // Output the definitions for methods
a61af66fc99e Initial load
duke
parents:
diff changeset
3241 _instructions.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
3242 while( (instr = (InstructForm*)_instructions.iter()) != NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3243 // Ensure this is a machine-world instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
3244 if ( instr->ideal_only() ) continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
3245
a61af66fc99e Initial load
duke
parents:
diff changeset
3246 // Access the fields for operand Label
a61af66fc99e Initial load
duke
parents:
diff changeset
3247 int method_position = instr->method_position();
a61af66fc99e Initial load
duke
parents:
diff changeset
3248 if( method_position != -1 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3249 // Access the method's address
a61af66fc99e Initial load
duke
parents:
diff changeset
3250 fprintf(fp,"void %sNode::method_set( intptr_t method ) {\n", instr->_ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
3251 fprintf(fp," ((methodOper*)opnd_array(%d))->_method = method;\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
3252 method_position );
a61af66fc99e Initial load
duke
parents:
diff changeset
3253 fprintf(fp,"}\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3254 fprintf(fp,"\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3255 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3256 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3257
a61af66fc99e Initial load
duke
parents:
diff changeset
3258 // Define this instruction's number of relocation entries, base is '0'
a61af66fc99e Initial load
duke
parents:
diff changeset
3259 _instructions.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
3260 while( (instr = (InstructForm*)_instructions.iter()) != NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3261 // Output the definition for number of relocation entries
a61af66fc99e Initial load
duke
parents:
diff changeset
3262 uint reloc_size = instr->reloc(_globalNames);
a61af66fc99e Initial load
duke
parents:
diff changeset
3263 if ( reloc_size != 0 ) {
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
3264 fprintf(fp,"int %sNode::reloc() const {\n", instr->_ident);
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
3265 fprintf(fp," return %d;\n", reloc_size);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3266 fprintf(fp,"}\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3267 fprintf(fp,"\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3268 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3269 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3270 fprintf(fp,"\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3271
a61af66fc99e Initial load
duke
parents:
diff changeset
3272 // Output the definitions for code generation
a61af66fc99e Initial load
duke
parents:
diff changeset
3273 //
a61af66fc99e Initial load
duke
parents:
diff changeset
3274 // address ___Node::emit(address ptr, PhaseRegAlloc *ra_) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
3275 // // ... encoding defined by user
a61af66fc99e Initial load
duke
parents:
diff changeset
3276 // return ptr;
a61af66fc99e Initial load
duke
parents:
diff changeset
3277 // }
a61af66fc99e Initial load
duke
parents:
diff changeset
3278 //
a61af66fc99e Initial load
duke
parents:
diff changeset
3279 _instructions.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
3280 for( ; (instr = (InstructForm*)_instructions.iter()) != NULL; ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3281 // Ensure this is a machine-world instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
3282 if ( instr->ideal_only() ) continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
3283
14428
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
3284 if (instr->_insencode) {
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
3285 if (instr->postalloc_expands()) {
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
3286 // Don't write this to _CPP_EXPAND_file, as the code generated calls C-code
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
3287 // from code sections in ad file that is dumped to fp.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
3288 define_postalloc_expand(fp, *instr);
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
3289 } else {
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
3290 defineEmit(fp, *instr);
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
3291 }
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12167
diff changeset
3292 }
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
3293 if (instr->is_mach_constant()) defineEvalConstant(fp, *instr);
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1748
diff changeset
3294 if (instr->_size) defineSize (fp, *instr);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3295
a61af66fc99e Initial load
duke
parents:
diff changeset
3296 // side-call to generate output that used to be in the header file:
a61af66fc99e Initial load
duke
parents:
diff changeset
3297 extern void gen_inst_format(FILE *fp, FormDict &globals, InstructForm &oper, bool for_c_file);
a61af66fc99e Initial load
duke
parents:
diff changeset
3298 gen_inst_format(_CPP_FORMAT_file._fp, _globalNames, *instr, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
3299 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3300
a61af66fc99e Initial load
duke
parents:
diff changeset
3301 // Output the definitions for alias analysis
a61af66fc99e Initial load
duke
parents:
diff changeset
3302 _instructions.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
3303 for( ; (instr = (InstructForm*)_instructions.iter()) != NULL; ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3304 // Ensure this is a machine-world instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
3305 if ( instr->ideal_only() ) continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
3306
a61af66fc99e Initial load
duke
parents:
diff changeset
3307 // Analyze machine instructions that either USE or DEF memory.
a61af66fc99e Initial load
duke
parents:
diff changeset
3308 int memory_operand = instr->memory_operand(_globalNames);
a61af66fc99e Initial load
duke
parents:
diff changeset
3309 // Some guys kill all of memory
a61af66fc99e Initial load
duke
parents:
diff changeset
3310 if ( instr->is_wide_memory_kill(_globalNames) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3311 memory_operand = InstructForm::MANY_MEMORY_OPERANDS;
a61af66fc99e Initial load
duke
parents:
diff changeset
3312 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3313
a61af66fc99e Initial load
duke
parents:
diff changeset
3314 if ( memory_operand != InstructForm::NO_MEMORY_OPERAND ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3315 if( memory_operand == InstructForm::MANY_MEMORY_OPERANDS ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3316 fprintf(fp,"const TypePtr *%sNode::adr_type() const { return TypePtr::BOTTOM; }\n", instr->_ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
3317 fprintf(fp,"const MachOper* %sNode::memory_operand() const { return (MachOper*)-1; }\n", instr->_ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
3318 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
3319 fprintf(fp,"const MachOper* %sNode::memory_operand() const { return _opnds[%d]; }\n", instr->_ident, memory_operand);
a61af66fc99e Initial load
duke
parents:
diff changeset
3320 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3321 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3322 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3323
a61af66fc99e Initial load
duke
parents:
diff changeset
3324 // Get the length of the longest identifier
a61af66fc99e Initial load
duke
parents:
diff changeset
3325 int max_ident_len = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
3326 _instructions.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
3327
a61af66fc99e Initial load
duke
parents:
diff changeset
3328 for ( ; (instr = (InstructForm*)_instructions.iter()) != NULL; ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3329 if (instr->_ins_pipe && _pipeline->_classlist.search(instr->_ins_pipe)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3330 int ident_len = (int)strlen(instr->_ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
3331 if( max_ident_len < ident_len )
a61af66fc99e Initial load
duke
parents:
diff changeset
3332 max_ident_len = ident_len;
a61af66fc99e Initial load
duke
parents:
diff changeset
3333 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3334 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3335
a61af66fc99e Initial load
duke
parents:
diff changeset
3336 // Emit specifically for Node(s)
a61af66fc99e Initial load
duke
parents:
diff changeset
3337 fprintf(_CPP_PIPELINE_file._fp, "const Pipeline * %*s::pipeline_class() { return %s; }\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
3338 max_ident_len, "Node", _pipeline ? "(&pipeline_class_Zero_Instructions)" : "NULL");
a61af66fc99e Initial load
duke
parents:
diff changeset
3339 fprintf(_CPP_PIPELINE_file._fp, "const Pipeline * %*s::pipeline() const { return %s; }\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
3340 max_ident_len, "Node", _pipeline ? "(&pipeline_class_Zero_Instructions)" : "NULL");
a61af66fc99e Initial load
duke
parents:
diff changeset
3341 fprintf(_CPP_PIPELINE_file._fp, "\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3342
a61af66fc99e Initial load
duke
parents:
diff changeset
3343 fprintf(_CPP_PIPELINE_file._fp, "const Pipeline * %*s::pipeline_class() { return %s; }\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
3344 max_ident_len, "MachNode", _pipeline ? "(&pipeline_class_Unknown_Instructions)" : "NULL");
a61af66fc99e Initial load
duke
parents:
diff changeset
3345 fprintf(_CPP_PIPELINE_file._fp, "const Pipeline * %*s::pipeline() const { return pipeline_class(); }\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
3346 max_ident_len, "MachNode");
a61af66fc99e Initial load
duke
parents:
diff changeset
3347 fprintf(_CPP_PIPELINE_file._fp, "\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3348
a61af66fc99e Initial load
duke
parents:
diff changeset
3349 // Output the definitions for machine node specific pipeline data
a61af66fc99e Initial load
duke
parents:
diff changeset
3350 _machnodes.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
3351
a61af66fc99e Initial load
duke
parents:
diff changeset
3352 for ( ; (machnode = (MachNodeForm*)_machnodes.iter()) != NULL; ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3353 fprintf(_CPP_PIPELINE_file._fp, "const Pipeline * %sNode::pipeline() const { return (&pipeline_class_%03d); }\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
3354 machnode->_ident, ((class PipeClassForm *)_pipeline->_classdict[machnode->_machnode_pipe])->_num);
a61af66fc99e Initial load
duke
parents:
diff changeset
3355 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3356
a61af66fc99e Initial load
duke
parents:
diff changeset
3357 fprintf(_CPP_PIPELINE_file._fp, "\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3358
a61af66fc99e Initial load
duke
parents:
diff changeset
3359 // Output the definitions for instruction pipeline static data references
a61af66fc99e Initial load
duke
parents:
diff changeset
3360 _instructions.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
3361
a61af66fc99e Initial load
duke
parents:
diff changeset
3362 for ( ; (instr = (InstructForm*)_instructions.iter()) != NULL; ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3363 if (instr->_ins_pipe && _pipeline->_classlist.search(instr->_ins_pipe)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3364 fprintf(_CPP_PIPELINE_file._fp, "\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3365 fprintf(_CPP_PIPELINE_file._fp, "const Pipeline * %*sNode::pipeline_class() { return (&pipeline_class_%03d); }\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
3366 max_ident_len, instr->_ident, ((class PipeClassForm *)_pipeline->_classdict[instr->_ins_pipe])->_num);
a61af66fc99e Initial load
duke
parents:
diff changeset
3367 fprintf(_CPP_PIPELINE_file._fp, "const Pipeline * %*sNode::pipeline() const { return (&pipeline_class_%03d); }\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
3368 max_ident_len, instr->_ident, ((class PipeClassForm *)_pipeline->_classdict[instr->_ins_pipe])->_num);
a61af66fc99e Initial load
duke
parents:
diff changeset
3369 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3370 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3371 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3372
a61af66fc99e Initial load
duke
parents:
diff changeset
3373
a61af66fc99e Initial load
duke
parents:
diff changeset
3374 // -------------------------------- maps ------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
3375
a61af66fc99e Initial load
duke
parents:
diff changeset
3376 // Information needed to generate the ReduceOp mapping for the DFA
a61af66fc99e Initial load
duke
parents:
diff changeset
3377 class OutputReduceOp : public OutputMap {
a61af66fc99e Initial load
duke
parents:
diff changeset
3378 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
3379 OutputReduceOp(FILE *hpp, FILE *cpp, FormDict &globals, ArchDesc &AD)
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
3380 : OutputMap(hpp, cpp, globals, AD, "reduceOp") {};
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3381
a61af66fc99e Initial load
duke
parents:
diff changeset
3382 void declaration() { fprintf(_hpp, "extern const int reduceOp[];\n"); }
a61af66fc99e Initial load
duke
parents:
diff changeset
3383 void definition() { fprintf(_cpp, "const int reduceOp[] = {\n"); }
a61af66fc99e Initial load
duke
parents:
diff changeset
3384 void closing() { fprintf(_cpp, " 0 // no trailing comma\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3385 OutputMap::closing();
a61af66fc99e Initial load
duke
parents:
diff changeset
3386 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3387 void map(OpClassForm &opc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3388 const char *reduce = opc._ident;
a61af66fc99e Initial load
duke
parents:
diff changeset
3389 if( reduce ) fprintf(_cpp, " %s_rule", reduce);
a61af66fc99e Initial load
duke
parents:
diff changeset
3390 else fprintf(_cpp, " 0");
a61af66fc99e Initial load
duke
parents:
diff changeset
3391 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3392 void map(OperandForm &oper) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3393 // Most operands without match rules, e.g. eFlagsReg, do not have a result operand
a61af66fc99e Initial load
duke
parents:
diff changeset
3394 const char *reduce = (oper._matrule ? oper.reduce_result() : NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
3395 // operand stackSlot does not have a match rule, but produces a stackSlot
a61af66fc99e Initial load
duke
parents:
diff changeset
3396 if( oper.is_user_name_for_sReg() != Form::none ) reduce = oper.reduce_result();
a61af66fc99e Initial load
duke
parents:
diff changeset
3397 if( reduce ) fprintf(_cpp, " %s_rule", reduce);
a61af66fc99e Initial load
duke
parents:
diff changeset
3398 else fprintf(_cpp, " 0");
a61af66fc99e Initial load
duke
parents:
diff changeset
3399 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3400 void map(InstructForm &inst) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3401 const char *reduce = (inst._matrule ? inst.reduce_result() : NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
3402 if( reduce ) fprintf(_cpp, " %s_rule", reduce);
a61af66fc99e Initial load
duke
parents:
diff changeset
3403 else fprintf(_cpp, " 0");
a61af66fc99e Initial load
duke
parents:
diff changeset
3404 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3405 void map(char *reduce) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3406 if( reduce ) fprintf(_cpp, " %s_rule", reduce);
a61af66fc99e Initial load
duke
parents:
diff changeset
3407 else fprintf(_cpp, " 0");
a61af66fc99e Initial load
duke
parents:
diff changeset
3408 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3409 };
a61af66fc99e Initial load
duke
parents:
diff changeset
3410
a61af66fc99e Initial load
duke
parents:
diff changeset
3411 // Information needed to generate the LeftOp mapping for the DFA
a61af66fc99e Initial load
duke
parents:
diff changeset
3412 class OutputLeftOp : public OutputMap {
a61af66fc99e Initial load
duke
parents:
diff changeset
3413 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
3414 OutputLeftOp(FILE *hpp, FILE *cpp, FormDict &globals, ArchDesc &AD)
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
3415 : OutputMap(hpp, cpp, globals, AD, "leftOp") {};
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3416
a61af66fc99e Initial load
duke
parents:
diff changeset
3417 void declaration() { fprintf(_hpp, "extern const int leftOp[];\n"); }
a61af66fc99e Initial load
duke
parents:
diff changeset
3418 void definition() { fprintf(_cpp, "const int leftOp[] = {\n"); }
a61af66fc99e Initial load
duke
parents:
diff changeset
3419 void closing() { fprintf(_cpp, " 0 // no trailing comma\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3420 OutputMap::closing();
a61af66fc99e Initial load
duke
parents:
diff changeset
3421 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3422 void map(OpClassForm &opc) { fprintf(_cpp, " 0"); }
a61af66fc99e Initial load
duke
parents:
diff changeset
3423 void map(OperandForm &oper) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3424 const char *reduce = oper.reduce_left(_globals);
a61af66fc99e Initial load
duke
parents:
diff changeset
3425 if( reduce ) fprintf(_cpp, " %s_rule", reduce);
a61af66fc99e Initial load
duke
parents:
diff changeset
3426 else fprintf(_cpp, " 0");
a61af66fc99e Initial load
duke
parents:
diff changeset
3427 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3428 void map(char *name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3429 const char *reduce = _AD.reduceLeft(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
3430 if( reduce ) fprintf(_cpp, " %s_rule", reduce);
a61af66fc99e Initial load
duke
parents:
diff changeset
3431 else fprintf(_cpp, " 0");
a61af66fc99e Initial load
duke
parents:
diff changeset
3432 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3433 void map(InstructForm &inst) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3434 const char *reduce = inst.reduce_left(_globals);
a61af66fc99e Initial load
duke
parents:
diff changeset
3435 if( reduce ) fprintf(_cpp, " %s_rule", reduce);
a61af66fc99e Initial load
duke
parents:
diff changeset
3436 else fprintf(_cpp, " 0");
a61af66fc99e Initial load
duke
parents:
diff changeset
3437 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3438 };
a61af66fc99e Initial load
duke
parents:
diff changeset
3439
a61af66fc99e Initial load
duke
parents:
diff changeset
3440
a61af66fc99e Initial load
duke
parents:
diff changeset
3441 // Information needed to generate the RightOp mapping for the DFA
a61af66fc99e Initial load
duke
parents:
diff changeset
3442 class OutputRightOp : public OutputMap {
a61af66fc99e Initial load
duke
parents:
diff changeset
3443 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
3444 OutputRightOp(FILE *hpp, FILE *cpp, FormDict &globals, ArchDesc &AD)
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
3445 : OutputMap(hpp, cpp, globals, AD, "rightOp") {};
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3446
a61af66fc99e Initial load
duke
parents:
diff changeset
3447 void declaration() { fprintf(_hpp, "extern const int rightOp[];\n"); }
a61af66fc99e Initial load
duke
parents:
diff changeset
3448 void definition() { fprintf(_cpp, "const int rightOp[] = {\n"); }
a61af66fc99e Initial load
duke
parents:
diff changeset
3449 void closing() { fprintf(_cpp, " 0 // no trailing comma\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3450 OutputMap::closing();
a61af66fc99e Initial load
duke
parents:
diff changeset
3451 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3452 void map(OpClassForm &opc) { fprintf(_cpp, " 0"); }
a61af66fc99e Initial load
duke
parents:
diff changeset
3453 void map(OperandForm &oper) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3454 const char *reduce = oper.reduce_right(_globals);
a61af66fc99e Initial load
duke
parents:
diff changeset
3455 if( reduce ) fprintf(_cpp, " %s_rule", reduce);
a61af66fc99e Initial load
duke
parents:
diff changeset
3456 else fprintf(_cpp, " 0");
a61af66fc99e Initial load
duke
parents:
diff changeset
3457 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3458 void map(char *name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3459 const char *reduce = _AD.reduceRight(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
3460 if( reduce ) fprintf(_cpp, " %s_rule", reduce);
a61af66fc99e Initial load
duke
parents:
diff changeset
3461 else fprintf(_cpp, " 0");
a61af66fc99e Initial load
duke
parents:
diff changeset
3462 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3463 void map(InstructForm &inst) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3464 const char *reduce = inst.reduce_right(_globals);
a61af66fc99e Initial load
duke
parents:
diff changeset
3465 if( reduce ) fprintf(_cpp, " %s_rule", reduce);
a61af66fc99e Initial load
duke
parents:
diff changeset
3466 else fprintf(_cpp, " 0");
a61af66fc99e Initial load
duke
parents:
diff changeset
3467 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3468 };
a61af66fc99e Initial load
duke
parents:
diff changeset
3469
a61af66fc99e Initial load
duke
parents:
diff changeset
3470
a61af66fc99e Initial load
duke
parents:
diff changeset
3471 // Information needed to generate the Rule names for the DFA
a61af66fc99e Initial load
duke
parents:
diff changeset
3472 class OutputRuleName : public OutputMap {
a61af66fc99e Initial load
duke
parents:
diff changeset
3473 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
3474 OutputRuleName(FILE *hpp, FILE *cpp, FormDict &globals, ArchDesc &AD)
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
3475 : OutputMap(hpp, cpp, globals, AD, "ruleName") {};
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3476
a61af66fc99e Initial load
duke
parents:
diff changeset
3477 void declaration() { fprintf(_hpp, "extern const char *ruleName[];\n"); }
a61af66fc99e Initial load
duke
parents:
diff changeset
3478 void definition() { fprintf(_cpp, "const char *ruleName[] = {\n"); }
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
3479 void closing() { fprintf(_cpp, " \"invalid rule name\" // no trailing comma\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3480 OutputMap::closing();
a61af66fc99e Initial load
duke
parents:
diff changeset
3481 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3482 void map(OpClassForm &opc) { fprintf(_cpp, " \"%s\"", _AD.machOperEnum(opc._ident) ); }
a61af66fc99e Initial load
duke
parents:
diff changeset
3483 void map(OperandForm &oper) { fprintf(_cpp, " \"%s\"", _AD.machOperEnum(oper._ident) ); }
a61af66fc99e Initial load
duke
parents:
diff changeset
3484 void map(char *name) { fprintf(_cpp, " \"%s\"", name ? name : "0"); }
a61af66fc99e Initial load
duke
parents:
diff changeset
3485 void map(InstructForm &inst){ fprintf(_cpp, " \"%s\"", inst._ident ? inst._ident : "0"); }
a61af66fc99e Initial load
duke
parents:
diff changeset
3486 };
a61af66fc99e Initial load
duke
parents:
diff changeset
3487
a61af66fc99e Initial load
duke
parents:
diff changeset
3488
a61af66fc99e Initial load
duke
parents:
diff changeset
3489 // Information needed to generate the swallowed mapping for the DFA
a61af66fc99e Initial load
duke
parents:
diff changeset
3490 class OutputSwallowed : public OutputMap {
a61af66fc99e Initial load
duke
parents:
diff changeset
3491 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
3492 OutputSwallowed(FILE *hpp, FILE *cpp, FormDict &globals, ArchDesc &AD)
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
3493 : OutputMap(hpp, cpp, globals, AD, "swallowed") {};
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3494
a61af66fc99e Initial load
duke
parents:
diff changeset
3495 void declaration() { fprintf(_hpp, "extern const bool swallowed[];\n"); }
a61af66fc99e Initial load
duke
parents:
diff changeset
3496 void definition() { fprintf(_cpp, "const bool swallowed[] = {\n"); }
a61af66fc99e Initial load
duke
parents:
diff changeset
3497 void closing() { fprintf(_cpp, " false // no trailing comma\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3498 OutputMap::closing();
a61af66fc99e Initial load
duke
parents:
diff changeset
3499 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3500 void map(OperandForm &oper) { // Generate the entry for this opcode
a61af66fc99e Initial load
duke
parents:
diff changeset
3501 const char *swallowed = oper.swallowed(_globals) ? "true" : "false";
a61af66fc99e Initial load
duke
parents:
diff changeset
3502 fprintf(_cpp, " %s", swallowed);
a61af66fc99e Initial load
duke
parents:
diff changeset
3503 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3504 void map(OpClassForm &opc) { fprintf(_cpp, " false"); }
a61af66fc99e Initial load
duke
parents:
diff changeset
3505 void map(char *name) { fprintf(_cpp, " false"); }
a61af66fc99e Initial load
duke
parents:
diff changeset
3506 void map(InstructForm &inst){ fprintf(_cpp, " false"); }
a61af66fc99e Initial load
duke
parents:
diff changeset
3507 };
a61af66fc99e Initial load
duke
parents:
diff changeset
3508
a61af66fc99e Initial load
duke
parents:
diff changeset
3509
a61af66fc99e Initial load
duke
parents:
diff changeset
3510 // Information needed to generate the decision array for instruction chain rule
a61af66fc99e Initial load
duke
parents:
diff changeset
3511 class OutputInstChainRule : public OutputMap {
a61af66fc99e Initial load
duke
parents:
diff changeset
3512 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
3513 OutputInstChainRule(FILE *hpp, FILE *cpp, FormDict &globals, ArchDesc &AD)
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
3514 : OutputMap(hpp, cpp, globals, AD, "instruction_chain_rule") {};
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3515
a61af66fc99e Initial load
duke
parents:
diff changeset
3516 void declaration() { fprintf(_hpp, "extern const bool instruction_chain_rule[];\n"); }
a61af66fc99e Initial load
duke
parents:
diff changeset
3517 void definition() { fprintf(_cpp, "const bool instruction_chain_rule[] = {\n"); }
a61af66fc99e Initial load
duke
parents:
diff changeset
3518 void closing() { fprintf(_cpp, " false // no trailing comma\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3519 OutputMap::closing();
a61af66fc99e Initial load
duke
parents:
diff changeset
3520 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3521 void map(OpClassForm &opc) { fprintf(_cpp, " false"); }
a61af66fc99e Initial load
duke
parents:
diff changeset
3522 void map(OperandForm &oper) { fprintf(_cpp, " false"); }
a61af66fc99e Initial load
duke
parents:
diff changeset
3523 void map(char *name) { fprintf(_cpp, " false"); }
a61af66fc99e Initial load
duke
parents:
diff changeset
3524 void map(InstructForm &inst) { // Check for simple chain rule
a61af66fc99e Initial load
duke
parents:
diff changeset
3525 const char *chain = inst.is_simple_chain_rule(_globals) ? "true" : "false";
a61af66fc99e Initial load
duke
parents:
diff changeset
3526 fprintf(_cpp, " %s", chain);
a61af66fc99e Initial load
duke
parents:
diff changeset
3527 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3528 };
a61af66fc99e Initial load
duke
parents:
diff changeset
3529
a61af66fc99e Initial load
duke
parents:
diff changeset
3530
a61af66fc99e Initial load
duke
parents:
diff changeset
3531 //---------------------------build_map------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
3532 // Build mapping from enumeration for densely packed operands
a61af66fc99e Initial load
duke
parents:
diff changeset
3533 // TO result and child types.
a61af66fc99e Initial load
duke
parents:
diff changeset
3534 void ArchDesc::build_map(OutputMap &map) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3535 FILE *fp_hpp = map.decl_file();
a61af66fc99e Initial load
duke
parents:
diff changeset
3536 FILE *fp_cpp = map.def_file();
a61af66fc99e Initial load
duke
parents:
diff changeset
3537 int idx = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
3538 OperandForm *op;
a61af66fc99e Initial load
duke
parents:
diff changeset
3539 OpClassForm *opc;
a61af66fc99e Initial load
duke
parents:
diff changeset
3540 InstructForm *inst;
a61af66fc99e Initial load
duke
parents:
diff changeset
3541
a61af66fc99e Initial load
duke
parents:
diff changeset
3542 // Construct this mapping
a61af66fc99e Initial load
duke
parents:
diff changeset
3543 map.declaration();
a61af66fc99e Initial load
duke
parents:
diff changeset
3544 fprintf(fp_cpp,"\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3545 map.definition();
a61af66fc99e Initial load
duke
parents:
diff changeset
3546
a61af66fc99e Initial load
duke
parents:
diff changeset
3547 // Output the mapping for operands
a61af66fc99e Initial load
duke
parents:
diff changeset
3548 map.record_position(OutputMap::BEGIN_OPERANDS, idx );
a61af66fc99e Initial load
duke
parents:
diff changeset
3549 _operands.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
3550 for(; (op = (OperandForm*)_operands.iter()) != NULL; ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3551 // Ensure this is a machine-world instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
3552 if ( op->ideal_only() ) continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
3553
a61af66fc99e Initial load
duke
parents:
diff changeset
3554 // Generate the entry for this opcode
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
3555 fprintf(fp_cpp, " /* %4d */", idx); map.map(*op); fprintf(fp_cpp, ",\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3556 ++idx;
a61af66fc99e Initial load
duke
parents:
diff changeset
3557 };
a61af66fc99e Initial load
duke
parents:
diff changeset
3558 fprintf(fp_cpp, " // last operand\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3559
a61af66fc99e Initial load
duke
parents:
diff changeset
3560 // Place all user-defined operand classes into the mapping
a61af66fc99e Initial load
duke
parents:
diff changeset
3561 map.record_position(OutputMap::BEGIN_OPCLASSES, idx );
a61af66fc99e Initial load
duke
parents:
diff changeset
3562 _opclass.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
3563 for(; (opc = (OpClassForm*)_opclass.iter()) != NULL; ) {
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
3564 fprintf(fp_cpp, " /* %4d */", idx); map.map(*opc); fprintf(fp_cpp, ",\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3565 ++idx;
a61af66fc99e Initial load
duke
parents:
diff changeset
3566 };
a61af66fc99e Initial load
duke
parents:
diff changeset
3567 fprintf(fp_cpp, " // last operand class\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3568
a61af66fc99e Initial load
duke
parents:
diff changeset
3569 // Place all internally defined operands into the mapping
a61af66fc99e Initial load
duke
parents:
diff changeset
3570 map.record_position(OutputMap::BEGIN_INTERNALS, idx );
a61af66fc99e Initial load
duke
parents:
diff changeset
3571 _internalOpNames.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
3572 char *name = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3573 for(; (name = (char *)_internalOpNames.iter()) != NULL; ) {
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
3574 fprintf(fp_cpp, " /* %4d */", idx); map.map(name); fprintf(fp_cpp, ",\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3575 ++idx;
a61af66fc99e Initial load
duke
parents:
diff changeset
3576 };
a61af66fc99e Initial load
duke
parents:
diff changeset
3577 fprintf(fp_cpp, " // last internally defined operand\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3578
a61af66fc99e Initial load
duke
parents:
diff changeset
3579 // Place all user-defined instructions into the mapping
a61af66fc99e Initial load
duke
parents:
diff changeset
3580 if( map.do_instructions() ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3581 map.record_position(OutputMap::BEGIN_INSTRUCTIONS, idx );
a61af66fc99e Initial load
duke
parents:
diff changeset
3582 // Output all simple instruction chain rules first
a61af66fc99e Initial load
duke
parents:
diff changeset
3583 map.record_position(OutputMap::BEGIN_INST_CHAIN_RULES, idx );
a61af66fc99e Initial load
duke
parents:
diff changeset
3584 {
a61af66fc99e Initial load
duke
parents:
diff changeset
3585 _instructions.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
3586 for(; (inst = (InstructForm*)_instructions.iter()) != NULL; ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3587 // Ensure this is a machine-world instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
3588 if ( inst->ideal_only() ) continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
3589 if ( ! inst->is_simple_chain_rule(_globalNames) ) continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
3590 if ( inst->rematerialize(_globalNames, get_registers()) ) continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
3591
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
3592 fprintf(fp_cpp, " /* %4d */", idx); map.map(*inst); fprintf(fp_cpp, ",\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3593 ++idx;
a61af66fc99e Initial load
duke
parents:
diff changeset
3594 };
a61af66fc99e Initial load
duke
parents:
diff changeset
3595 map.record_position(OutputMap::BEGIN_REMATERIALIZE, idx );
a61af66fc99e Initial load
duke
parents:
diff changeset
3596 _instructions.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
3597 for(; (inst = (InstructForm*)_instructions.iter()) != NULL; ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3598 // Ensure this is a machine-world instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
3599 if ( inst->ideal_only() ) continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
3600 if ( ! inst->is_simple_chain_rule(_globalNames) ) continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
3601 if ( ! inst->rematerialize(_globalNames, get_registers()) ) continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
3602
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
3603 fprintf(fp_cpp, " /* %4d */", idx); map.map(*inst); fprintf(fp_cpp, ",\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3604 ++idx;
a61af66fc99e Initial load
duke
parents:
diff changeset
3605 };
a61af66fc99e Initial load
duke
parents:
diff changeset
3606 map.record_position(OutputMap::END_INST_CHAIN_RULES, idx );
a61af66fc99e Initial load
duke
parents:
diff changeset
3607 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3608 // Output all instructions that are NOT simple chain rules
a61af66fc99e Initial load
duke
parents:
diff changeset
3609 {
a61af66fc99e Initial load
duke
parents:
diff changeset
3610 _instructions.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
3611 for(; (inst = (InstructForm*)_instructions.iter()) != NULL; ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3612 // Ensure this is a machine-world instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
3613 if ( inst->ideal_only() ) continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
3614 if ( inst->is_simple_chain_rule(_globalNames) ) continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
3615 if ( ! inst->rematerialize(_globalNames, get_registers()) ) continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
3616
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
3617 fprintf(fp_cpp, " /* %4d */", idx); map.map(*inst); fprintf(fp_cpp, ",\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3618 ++idx;
a61af66fc99e Initial load
duke
parents:
diff changeset
3619 };
a61af66fc99e Initial load
duke
parents:
diff changeset
3620 map.record_position(OutputMap::END_REMATERIALIZE, idx );
a61af66fc99e Initial load
duke
parents:
diff changeset
3621 _instructions.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
3622 for(; (inst = (InstructForm*)_instructions.iter()) != NULL; ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3623 // Ensure this is a machine-world instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
3624 if ( inst->ideal_only() ) continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
3625 if ( inst->is_simple_chain_rule(_globalNames) ) continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
3626 if ( inst->rematerialize(_globalNames, get_registers()) ) continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
3627
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
3628 fprintf(fp_cpp, " /* %4d */", idx); map.map(*inst); fprintf(fp_cpp, ",\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3629 ++idx;
a61af66fc99e Initial load
duke
parents:
diff changeset
3630 };
a61af66fc99e Initial load
duke
parents:
diff changeset
3631 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3632 fprintf(fp_cpp, " // last instruction\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3633 map.record_position(OutputMap::END_INSTRUCTIONS, idx );
a61af66fc99e Initial load
duke
parents:
diff changeset
3634 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3635 // Finish defining table
a61af66fc99e Initial load
duke
parents:
diff changeset
3636 map.closing();
a61af66fc99e Initial load
duke
parents:
diff changeset
3637 };
a61af66fc99e Initial load
duke
parents:
diff changeset
3638
a61af66fc99e Initial load
duke
parents:
diff changeset
3639
a61af66fc99e Initial load
duke
parents:
diff changeset
3640 // Helper function for buildReduceMaps
a61af66fc99e Initial load
duke
parents:
diff changeset
3641 char reg_save_policy(const char *calling_convention) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3642 char callconv;
a61af66fc99e Initial load
duke
parents:
diff changeset
3643
a61af66fc99e Initial load
duke
parents:
diff changeset
3644 if (!strcmp(calling_convention, "NS")) callconv = 'N';
a61af66fc99e Initial load
duke
parents:
diff changeset
3645 else if (!strcmp(calling_convention, "SOE")) callconv = 'E';
a61af66fc99e Initial load
duke
parents:
diff changeset
3646 else if (!strcmp(calling_convention, "SOC")) callconv = 'C';
a61af66fc99e Initial load
duke
parents:
diff changeset
3647 else if (!strcmp(calling_convention, "AS")) callconv = 'A';
a61af66fc99e Initial load
duke
parents:
diff changeset
3648 else callconv = 'Z';
a61af66fc99e Initial load
duke
parents:
diff changeset
3649
a61af66fc99e Initial load
duke
parents:
diff changeset
3650 return callconv;
a61af66fc99e Initial load
duke
parents:
diff changeset
3651 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3652
17791
ad3b94907eed 8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents: 14444
diff changeset
3653 void ArchDesc::generate_needs_clone_jvms(FILE *fp_cpp) {
ad3b94907eed 8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents: 14444
diff changeset
3654 fprintf(fp_cpp, "bool Compile::needs_clone_jvms() { return %s; }\n\n",
ad3b94907eed 8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents: 14444
diff changeset
3655 _needs_clone_jvms ? "true" : "false");
ad3b94907eed 8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents: 14444
diff changeset
3656 }
ad3b94907eed 8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents: 14444
diff changeset
3657
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3658 //---------------------------generate_assertion_checks-------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
3659 void ArchDesc::generate_adlc_verification(FILE *fp_cpp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3660 fprintf(fp_cpp, "\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3661
a61af66fc99e Initial load
duke
parents:
diff changeset
3662 fprintf(fp_cpp, "#ifndef PRODUCT\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3663 fprintf(fp_cpp, "void Compile::adlc_verification() {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3664 globalDefs().print_asserts(fp_cpp);
a61af66fc99e Initial load
duke
parents:
diff changeset
3665 fprintf(fp_cpp, "}\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3666 fprintf(fp_cpp, "#endif\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3667 fprintf(fp_cpp, "\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3668 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3669
a61af66fc99e Initial load
duke
parents:
diff changeset
3670 //---------------------------addSourceBlocks-----------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
3671 void ArchDesc::addSourceBlocks(FILE *fp_cpp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3672 if (_source.count() > 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
3673 _source.output(fp_cpp);
a61af66fc99e Initial load
duke
parents:
diff changeset
3674
a61af66fc99e Initial load
duke
parents:
diff changeset
3675 generate_adlc_verification(fp_cpp);
a61af66fc99e Initial load
duke
parents:
diff changeset
3676 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3677 //---------------------------addHeaderBlocks-----------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
3678 void ArchDesc::addHeaderBlocks(FILE *fp_hpp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3679 if (_header.count() > 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
3680 _header.output(fp_hpp);
a61af66fc99e Initial load
duke
parents:
diff changeset
3681 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3682 //-------------------------addPreHeaderBlocks----------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
3683 void ArchDesc::addPreHeaderBlocks(FILE *fp_hpp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3684 // Output #defines from definition block
a61af66fc99e Initial load
duke
parents:
diff changeset
3685 globalDefs().print_defines(fp_hpp);
a61af66fc99e Initial load
duke
parents:
diff changeset
3686
a61af66fc99e Initial load
duke
parents:
diff changeset
3687 if (_pre_header.count() > 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
3688 _pre_header.output(fp_hpp);
a61af66fc99e Initial load
duke
parents:
diff changeset
3689 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3690
a61af66fc99e Initial load
duke
parents:
diff changeset
3691 //---------------------------buildReduceMaps-----------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
3692 // Build mapping from enumeration for densely packed operands
a61af66fc99e Initial load
duke
parents:
diff changeset
3693 // TO result and child types.
a61af66fc99e Initial load
duke
parents:
diff changeset
3694 void ArchDesc::buildReduceMaps(FILE *fp_hpp, FILE *fp_cpp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3695 RegDef *rdef;
a61af66fc99e Initial load
duke
parents:
diff changeset
3696 RegDef *next;
a61af66fc99e Initial load
duke
parents:
diff changeset
3697
a61af66fc99e Initial load
duke
parents:
diff changeset
3698 // The emit bodies currently require functions defined in the source block.
a61af66fc99e Initial load
duke
parents:
diff changeset
3699
a61af66fc99e Initial load
duke
parents:
diff changeset
3700 // Build external declarations for mappings
a61af66fc99e Initial load
duke
parents:
diff changeset
3701 fprintf(fp_hpp, "\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3702 fprintf(fp_hpp, "extern const char register_save_policy[];\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3703 fprintf(fp_hpp, "extern const char c_reg_save_policy[];\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3704 fprintf(fp_hpp, "extern const int register_save_type[];\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3705 fprintf(fp_hpp, "\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3706
a61af66fc99e Initial load
duke
parents:
diff changeset
3707 // Construct Save-Policy array
a61af66fc99e Initial load
duke
parents:
diff changeset
3708 fprintf(fp_cpp, "// Map from machine-independent register number to register_save_policy\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3709 fprintf(fp_cpp, "const char register_save_policy[] = {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3710 _register->reset_RegDefs();
a61af66fc99e Initial load
duke
parents:
diff changeset
3711 for( rdef = _register->iter_RegDefs(); rdef != NULL; rdef = next ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3712 next = _register->iter_RegDefs();
a61af66fc99e Initial load
duke
parents:
diff changeset
3713 char policy = reg_save_policy(rdef->_callconv);
a61af66fc99e Initial load
duke
parents:
diff changeset
3714 const char *comma = (next != NULL) ? "," : " // no trailing comma";
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
3715 fprintf(fp_cpp, " '%c'%s // %s\n", policy, comma, rdef->_regname);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3716 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3717 fprintf(fp_cpp, "};\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3718
a61af66fc99e Initial load
duke
parents:
diff changeset
3719 // Construct Native Save-Policy array
a61af66fc99e Initial load
duke
parents:
diff changeset
3720 fprintf(fp_cpp, "// Map from machine-independent register number to c_reg_save_policy\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3721 fprintf(fp_cpp, "const char c_reg_save_policy[] = {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3722 _register->reset_RegDefs();
a61af66fc99e Initial load
duke
parents:
diff changeset
3723 for( rdef = _register->iter_RegDefs(); rdef != NULL; rdef = next ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3724 next = _register->iter_RegDefs();
a61af66fc99e Initial load
duke
parents:
diff changeset
3725 char policy = reg_save_policy(rdef->_c_conv);
a61af66fc99e Initial load
duke
parents:
diff changeset
3726 const char *comma = (next != NULL) ? "," : " // no trailing comma";
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
3727 fprintf(fp_cpp, " '%c'%s // %s\n", policy, comma, rdef->_regname);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3728 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3729 fprintf(fp_cpp, "};\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3730
a61af66fc99e Initial load
duke
parents:
diff changeset
3731 // Construct Register Save Type array
a61af66fc99e Initial load
duke
parents:
diff changeset
3732 fprintf(fp_cpp, "// Map from machine-independent register number to register_save_type\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3733 fprintf(fp_cpp, "const int register_save_type[] = {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3734 _register->reset_RegDefs();
a61af66fc99e Initial load
duke
parents:
diff changeset
3735 for( rdef = _register->iter_RegDefs(); rdef != NULL; rdef = next ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3736 next = _register->iter_RegDefs();
a61af66fc99e Initial load
duke
parents:
diff changeset
3737 const char *comma = (next != NULL) ? "," : " // no trailing comma";
a61af66fc99e Initial load
duke
parents:
diff changeset
3738 fprintf(fp_cpp, " %s%s\n", rdef->_idealtype, comma);
a61af66fc99e Initial load
duke
parents:
diff changeset
3739 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3740 fprintf(fp_cpp, "};\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3741
a61af66fc99e Initial load
duke
parents:
diff changeset
3742 // Construct the table for reduceOp
a61af66fc99e Initial load
duke
parents:
diff changeset
3743 OutputReduceOp output_reduce_op(fp_hpp, fp_cpp, _globalNames, *this);
a61af66fc99e Initial load
duke
parents:
diff changeset
3744 build_map(output_reduce_op);
a61af66fc99e Initial load
duke
parents:
diff changeset
3745 // Construct the table for leftOp
a61af66fc99e Initial load
duke
parents:
diff changeset
3746 OutputLeftOp output_left_op(fp_hpp, fp_cpp, _globalNames, *this);
a61af66fc99e Initial load
duke
parents:
diff changeset
3747 build_map(output_left_op);
a61af66fc99e Initial load
duke
parents:
diff changeset
3748 // Construct the table for rightOp
a61af66fc99e Initial load
duke
parents:
diff changeset
3749 OutputRightOp output_right_op(fp_hpp, fp_cpp, _globalNames, *this);
a61af66fc99e Initial load
duke
parents:
diff changeset
3750 build_map(output_right_op);
a61af66fc99e Initial load
duke
parents:
diff changeset
3751 // Construct the table of rule names
a61af66fc99e Initial load
duke
parents:
diff changeset
3752 OutputRuleName output_rule_name(fp_hpp, fp_cpp, _globalNames, *this);
a61af66fc99e Initial load
duke
parents:
diff changeset
3753 build_map(output_rule_name);
a61af66fc99e Initial load
duke
parents:
diff changeset
3754 // Construct the boolean table for subsumed operands
a61af66fc99e Initial load
duke
parents:
diff changeset
3755 OutputSwallowed output_swallowed(fp_hpp, fp_cpp, _globalNames, *this);
a61af66fc99e Initial load
duke
parents:
diff changeset
3756 build_map(output_swallowed);
a61af66fc99e Initial load
duke
parents:
diff changeset
3757 // // // Preserve in case we decide to use this table instead of another
a61af66fc99e Initial load
duke
parents:
diff changeset
3758 //// Construct the boolean table for instruction chain rules
a61af66fc99e Initial load
duke
parents:
diff changeset
3759 //OutputInstChainRule output_inst_chain(fp_hpp, fp_cpp, _globalNames, *this);
a61af66fc99e Initial load
duke
parents:
diff changeset
3760 //build_map(output_inst_chain);
a61af66fc99e Initial load
duke
parents:
diff changeset
3761
a61af66fc99e Initial load
duke
parents:
diff changeset
3762 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3763
a61af66fc99e Initial load
duke
parents:
diff changeset
3764
a61af66fc99e Initial load
duke
parents:
diff changeset
3765 //---------------------------buildMachOperGenerator---------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
3766
a61af66fc99e Initial load
duke
parents:
diff changeset
3767 // Recurse through match tree, building path through corresponding state tree,
a61af66fc99e Initial load
duke
parents:
diff changeset
3768 // Until we reach the constant we are looking for.
a61af66fc99e Initial load
duke
parents:
diff changeset
3769 static void path_to_constant(FILE *fp, FormDict &globals,
a61af66fc99e Initial load
duke
parents:
diff changeset
3770 MatchNode *mnode, uint idx) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3771 if ( ! mnode) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
3772
a61af66fc99e Initial load
duke
parents:
diff changeset
3773 unsigned position = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
3774 const char *result = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3775 const char *name = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3776 const char *optype = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3777
a61af66fc99e Initial load
duke
parents:
diff changeset
3778 // Base Case: access constant in ideal node linked to current state node
a61af66fc99e Initial load
duke
parents:
diff changeset
3779 // Each type of constant has its own access function
a61af66fc99e Initial load
duke
parents:
diff changeset
3780 if ( (mnode->_lChild == NULL) && (mnode->_rChild == NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
3781 && mnode->base_operand(position, globals, result, name, optype) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3782 if ( strcmp(optype,"ConI") == 0 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3783 fprintf(fp, "_leaf->get_int()");
a61af66fc99e Initial load
duke
parents:
diff changeset
3784 } else if ( (strcmp(optype,"ConP") == 0) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3785 fprintf(fp, "_leaf->bottom_type()->is_ptr()");
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
3786 } else if ( (strcmp(optype,"ConN") == 0) ) {
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
3787 fprintf(fp, "_leaf->bottom_type()->is_narrowoop()");
6848
8e47bac5643a 7054512: Compress class pointers after perm gen removal
roland
parents: 6804
diff changeset
3788 } else if ( (strcmp(optype,"ConNKlass") == 0) ) {
8e47bac5643a 7054512: Compress class pointers after perm gen removal
roland
parents: 6804
diff changeset
3789 fprintf(fp, "_leaf->bottom_type()->is_narrowklass()");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3790 } else if ( (strcmp(optype,"ConF") == 0) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3791 fprintf(fp, "_leaf->getf()");
a61af66fc99e Initial load
duke
parents:
diff changeset
3792 } else if ( (strcmp(optype,"ConD") == 0) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3793 fprintf(fp, "_leaf->getd()");
a61af66fc99e Initial load
duke
parents:
diff changeset
3794 } else if ( (strcmp(optype,"ConL") == 0) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3795 fprintf(fp, "_leaf->get_long()");
a61af66fc99e Initial load
duke
parents:
diff changeset
3796 } else if ( (strcmp(optype,"Con")==0) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3797 // !!!!! - Update if adding a machine-independent constant type
a61af66fc99e Initial load
duke
parents:
diff changeset
3798 fprintf(fp, "_leaf->get_int()");
a61af66fc99e Initial load
duke
parents:
diff changeset
3799 assert( false, "Unsupported constant type, pointer or indefinite");
a61af66fc99e Initial load
duke
parents:
diff changeset
3800 } else if ( (strcmp(optype,"Bool") == 0) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3801 fprintf(fp, "_leaf->as_Bool()->_test._test");
a61af66fc99e Initial load
duke
parents:
diff changeset
3802 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
3803 assert( false, "Unsupported constant type");
a61af66fc99e Initial load
duke
parents:
diff changeset
3804 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3805 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
3806 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3807
a61af66fc99e Initial load
duke
parents:
diff changeset
3808 // If constant is in left child, build path and recurse
a61af66fc99e Initial load
duke
parents:
diff changeset
3809 uint lConsts = (mnode->_lChild) ? (mnode->_lChild->num_consts(globals) ) : 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
3810 uint rConsts = (mnode->_rChild) ? (mnode->_rChild->num_consts(globals) ) : 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
3811 if ( (mnode->_lChild) && (lConsts > idx) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3812 fprintf(fp, "_kids[0]->");
a61af66fc99e Initial load
duke
parents:
diff changeset
3813 path_to_constant(fp, globals, mnode->_lChild, idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
3814 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
3815 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3816 // If constant is in right child, build path and recurse
a61af66fc99e Initial load
duke
parents:
diff changeset
3817 if ( (mnode->_rChild) && (rConsts > (idx - lConsts) ) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3818 idx = idx - lConsts;
a61af66fc99e Initial load
duke
parents:
diff changeset
3819 fprintf(fp, "_kids[1]->");
a61af66fc99e Initial load
duke
parents:
diff changeset
3820 path_to_constant(fp, globals, mnode->_rChild, idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
3821 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
3822 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3823 assert( false, "ShouldNotReachHere()");
a61af66fc99e Initial load
duke
parents:
diff changeset
3824 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3825
a61af66fc99e Initial load
duke
parents:
diff changeset
3826 // Generate code that is executed when generating a specific Machine Operand
a61af66fc99e Initial load
duke
parents:
diff changeset
3827 static void genMachOperCase(FILE *fp, FormDict &globalNames, ArchDesc &AD,
a61af66fc99e Initial load
duke
parents:
diff changeset
3828 OperandForm &op) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3829 const char *opName = op._ident;
a61af66fc99e Initial load
duke
parents:
diff changeset
3830 const char *opEnumName = AD.machOperEnum(opName);
a61af66fc99e Initial load
duke
parents:
diff changeset
3831 uint num_consts = op.num_consts(globalNames);
a61af66fc99e Initial load
duke
parents:
diff changeset
3832
a61af66fc99e Initial load
duke
parents:
diff changeset
3833 // Generate the case statement for this opcode
a61af66fc99e Initial load
duke
parents:
diff changeset
3834 fprintf(fp, " case %s:", opEnumName);
a61af66fc99e Initial load
duke
parents:
diff changeset
3835 fprintf(fp, "\n return new (C) %sOper(", opName);
a61af66fc99e Initial load
duke
parents:
diff changeset
3836 // Access parameters for constructor from the stat object
a61af66fc99e Initial load
duke
parents:
diff changeset
3837 //
a61af66fc99e Initial load
duke
parents:
diff changeset
3838 // Build access to condition code value
a61af66fc99e Initial load
duke
parents:
diff changeset
3839 if ( (num_consts > 0) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3840 uint i = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
3841 path_to_constant(fp, globalNames, op._matrule, i);
a61af66fc99e Initial load
duke
parents:
diff changeset
3842 for ( i = 1; i < num_consts; ++i ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3843 fprintf(fp, ", ");
a61af66fc99e Initial load
duke
parents:
diff changeset
3844 path_to_constant(fp, globalNames, op._matrule, i);
a61af66fc99e Initial load
duke
parents:
diff changeset
3845 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3846 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3847 fprintf(fp, " );\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3848 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3849
a61af66fc99e Initial load
duke
parents:
diff changeset
3850
a61af66fc99e Initial load
duke
parents:
diff changeset
3851 // Build switch to invoke "new" MachNode or MachOper
a61af66fc99e Initial load
duke
parents:
diff changeset
3852 void ArchDesc::buildMachOperGenerator(FILE *fp_cpp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3853 int idx = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
3854
a61af66fc99e Initial load
duke
parents:
diff changeset
3855 // Build switch to invoke 'new' for a specific MachOper
a61af66fc99e Initial load
duke
parents:
diff changeset
3856 fprintf(fp_cpp, "\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3857 fprintf(fp_cpp, "\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3858 fprintf(fp_cpp,
a61af66fc99e Initial load
duke
parents:
diff changeset
3859 "//------------------------- MachOper Generator ---------------\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3860 fprintf(fp_cpp,
a61af66fc99e Initial load
duke
parents:
diff changeset
3861 "// A switch statement on the dense-packed user-defined type system\n"
a61af66fc99e Initial load
duke
parents:
diff changeset
3862 "// that invokes 'new' on the corresponding class constructor.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3863 fprintf(fp_cpp, "\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3864 fprintf(fp_cpp, "MachOper *State::MachOperGenerator");
a61af66fc99e Initial load
duke
parents:
diff changeset
3865 fprintf(fp_cpp, "(int opcode, Compile* C)");
a61af66fc99e Initial load
duke
parents:
diff changeset
3866 fprintf(fp_cpp, "{\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3867 fprintf(fp_cpp, "\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3868 fprintf(fp_cpp, " switch(opcode) {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3869
a61af66fc99e Initial load
duke
parents:
diff changeset
3870 // Place all user-defined operands into the mapping
a61af66fc99e Initial load
duke
parents:
diff changeset
3871 _operands.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
3872 int opIndex = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
3873 OperandForm *op;
a61af66fc99e Initial load
duke
parents:
diff changeset
3874 for( ; (op = (OperandForm*)_operands.iter()) != NULL; ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3875 // Ensure this is a machine-world instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
3876 if ( op->ideal_only() ) continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
3877
a61af66fc99e Initial load
duke
parents:
diff changeset
3878 genMachOperCase(fp_cpp, _globalNames, *this, *op);
a61af66fc99e Initial load
duke
parents:
diff changeset
3879 };
a61af66fc99e Initial load
duke
parents:
diff changeset
3880
a61af66fc99e Initial load
duke
parents:
diff changeset
3881 // Do not iterate over operand classes for the operand generator!!!
a61af66fc99e Initial load
duke
parents:
diff changeset
3882
a61af66fc99e Initial load
duke
parents:
diff changeset
3883 // Place all internal operands into the mapping
a61af66fc99e Initial load
duke
parents:
diff changeset
3884 _internalOpNames.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
3885 const char *iopn;
a61af66fc99e Initial load
duke
parents:
diff changeset
3886 for( ; (iopn = _internalOpNames.iter()) != NULL; ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3887 const char *opEnumName = machOperEnum(iopn);
a61af66fc99e Initial load
duke
parents:
diff changeset
3888 // Generate the case statement for this opcode
a61af66fc99e Initial load
duke
parents:
diff changeset
3889 fprintf(fp_cpp, " case %s:", opEnumName);
a61af66fc99e Initial load
duke
parents:
diff changeset
3890 fprintf(fp_cpp, " return NULL;\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3891 };
a61af66fc99e Initial load
duke
parents:
diff changeset
3892
a61af66fc99e Initial load
duke
parents:
diff changeset
3893 // Generate the default case for switch(opcode)
a61af66fc99e Initial load
duke
parents:
diff changeset
3894 fprintf(fp_cpp, " \n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3895 fprintf(fp_cpp, " default:\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3896 fprintf(fp_cpp, " fprintf(stderr, \"Default MachOper Generator invoked for: \\n\");\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3897 fprintf(fp_cpp, " fprintf(stderr, \" opcode = %cd\\n\", opcode);\n", '%');
a61af66fc99e Initial load
duke
parents:
diff changeset
3898 fprintf(fp_cpp, " break;\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3899 fprintf(fp_cpp, " }\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3900
a61af66fc99e Initial load
duke
parents:
diff changeset
3901 // Generate the closing for method Matcher::MachOperGenerator
a61af66fc99e Initial load
duke
parents:
diff changeset
3902 fprintf(fp_cpp, " return NULL;\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3903 fprintf(fp_cpp, "};\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3904 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3905
a61af66fc99e Initial load
duke
parents:
diff changeset
3906
a61af66fc99e Initial load
duke
parents:
diff changeset
3907 //---------------------------buildMachNode-------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
3908 // Build a new MachNode, for MachNodeGenerator or cisc-spilling
a61af66fc99e Initial load
duke
parents:
diff changeset
3909 void ArchDesc::buildMachNode(FILE *fp_cpp, InstructForm *inst, const char *indent) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3910 const char *opType = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3911 const char *opClass = inst->_ident;
a61af66fc99e Initial load
duke
parents:
diff changeset
3912
a61af66fc99e Initial load
duke
parents:
diff changeset
3913 // Create the MachNode object
a61af66fc99e Initial load
duke
parents:
diff changeset
3914 fprintf(fp_cpp, "%s %sNode *node = new (C) %sNode();\n",indent, opClass,opClass);
a61af66fc99e Initial load
duke
parents:
diff changeset
3915
a61af66fc99e Initial load
duke
parents:
diff changeset
3916 if ( (inst->num_post_match_opnds() != 0) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3917 // Instruction that contains operands which are not in match rule.
a61af66fc99e Initial load
duke
parents:
diff changeset
3918 //
a61af66fc99e Initial load
duke
parents:
diff changeset
3919 // Check if the first post-match component may be an interesting def
a61af66fc99e Initial load
duke
parents:
diff changeset
3920 bool dont_care = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
3921 ComponentList &comp_list = inst->_components;
a61af66fc99e Initial load
duke
parents:
diff changeset
3922 Component *comp = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3923 comp_list.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
3924 if ( comp_list.match_iter() != NULL ) dont_care = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
3925
a61af66fc99e Initial load
duke
parents:
diff changeset
3926 // Insert operands that are not in match-rule.
a61af66fc99e Initial load
duke
parents:
diff changeset
3927 // Only insert a DEF if the do_care flag is set
a61af66fc99e Initial load
duke
parents:
diff changeset
3928 comp_list.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
3929 while ( comp = comp_list.post_match_iter() ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3930 // Check if we don't care about DEFs or KILLs that are not USEs
a61af66fc99e Initial load
duke
parents:
diff changeset
3931 if ( dont_care && (! comp->isa(Component::USE)) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3932 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
3933 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3934 dont_care = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
3935 // For each operand not in the match rule, call MachOperGenerator
2254
ab42c7e1cf83 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 2008
diff changeset
3936 // with the enum for the opcode that needs to be built.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3937 ComponentList clist = inst->_components;
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
3938 int index = clist.operand_position(comp->_name, comp->_usedef, inst);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3939 const char *opcode = machOperEnum(comp->_type);
a61af66fc99e Initial load
duke
parents:
diff changeset
3940 fprintf(fp_cpp, "%s node->set_opnd_array(%d, ", indent, index);
a61af66fc99e Initial load
duke
parents:
diff changeset
3941 fprintf(fp_cpp, "MachOperGenerator(%s, C));\n", opcode);
a61af66fc99e Initial load
duke
parents:
diff changeset
3942 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3943 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3944 else if ( inst->is_chain_of_constant(_globalNames, opType) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3945 // An instruction that chains from a constant!
a61af66fc99e Initial load
duke
parents:
diff changeset
3946 // In this case, we need to subsume the constant into the node
a61af66fc99e Initial load
duke
parents:
diff changeset
3947 // at operand position, oper_input_base().
a61af66fc99e Initial load
duke
parents:
diff changeset
3948 //
a61af66fc99e Initial load
duke
parents:
diff changeset
3949 // Fill in the constant
a61af66fc99e Initial load
duke
parents:
diff changeset
3950 fprintf(fp_cpp, "%s node->_opnd_array[%d] = ", indent,
a61af66fc99e Initial load
duke
parents:
diff changeset
3951 inst->oper_input_base(_globalNames));
a61af66fc99e Initial load
duke
parents:
diff changeset
3952 // #####
a61af66fc99e Initial load
duke
parents:
diff changeset
3953 // Check for multiple constants and then fill them in.
a61af66fc99e Initial load
duke
parents:
diff changeset
3954 // Just like MachOperGenerator
a61af66fc99e Initial load
duke
parents:
diff changeset
3955 const char *opName = inst->_matrule->_rChild->_opType;
a61af66fc99e Initial load
duke
parents:
diff changeset
3956 fprintf(fp_cpp, "new (C) %sOper(", opName);
a61af66fc99e Initial load
duke
parents:
diff changeset
3957 // Grab operand form
a61af66fc99e Initial load
duke
parents:
diff changeset
3958 OperandForm *op = (_globalNames[opName])->is_operand();
a61af66fc99e Initial load
duke
parents:
diff changeset
3959 // Look up the number of constants
a61af66fc99e Initial load
duke
parents:
diff changeset
3960 uint num_consts = op->num_consts(_globalNames);
a61af66fc99e Initial load
duke
parents:
diff changeset
3961 if ( (num_consts > 0) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3962 uint i = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
3963 path_to_constant(fp_cpp, _globalNames, op->_matrule, i);
a61af66fc99e Initial load
duke
parents:
diff changeset
3964 for ( i = 1; i < num_consts; ++i ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3965 fprintf(fp_cpp, ", ");
a61af66fc99e Initial load
duke
parents:
diff changeset
3966 path_to_constant(fp_cpp, _globalNames, op->_matrule, i);
a61af66fc99e Initial load
duke
parents:
diff changeset
3967 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3968 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3969 fprintf(fp_cpp, " );\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3970 // #####
a61af66fc99e Initial load
duke
parents:
diff changeset
3971 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3972
a61af66fc99e Initial load
duke
parents:
diff changeset
3973 // Fill in the bottom_type where requested
14434
318d0622a6d7 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 14431
diff changeset
3974 if (inst->captures_bottom_type(_globalNames)) {
318d0622a6d7 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 14431
diff changeset
3975 if (strncmp("MachCall", inst->mach_base_class(_globalNames), strlen("MachCall"))) {
318d0622a6d7 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 14431
diff changeset
3976 fprintf(fp_cpp, "%s node->_bottom_type = _leaf->bottom_type();\n", indent);
318d0622a6d7 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 14431
diff changeset
3977 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3978 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3979 if( inst->is_ideal_if() ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3980 fprintf(fp_cpp, "%s node->_prob = _leaf->as_If()->_prob;\n", indent);
a61af66fc99e Initial load
duke
parents:
diff changeset
3981 fprintf(fp_cpp, "%s node->_fcnt = _leaf->as_If()->_fcnt;\n", indent);
a61af66fc99e Initial load
duke
parents:
diff changeset
3982 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3983 if( inst->is_ideal_fastlock() ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3984 fprintf(fp_cpp, "%s node->_counters = _leaf->as_FastLock()->counters();\n", indent);
17780
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents: 17467
diff changeset
3985 fprintf(fp_cpp, "%s node->_rtm_counters = _leaf->as_FastLock()->rtm_counters();\n", indent);
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents: 17467
diff changeset
3986 fprintf(fp_cpp, "%s node->_stack_rtm_counters = _leaf->as_FastLock()->stack_rtm_counters();\n", indent);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3987 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3988
a61af66fc99e Initial load
duke
parents:
diff changeset
3989 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3990
a61af66fc99e Initial load
duke
parents:
diff changeset
3991 //---------------------------declare_cisc_version------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
3992 // Build CISC version of this instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
3993 void InstructForm::declare_cisc_version(ArchDesc &AD, FILE *fp_hpp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3994 if( AD.can_cisc_spill() ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3995 InstructForm *inst_cisc = cisc_spill_alternate();
a61af66fc99e Initial load
duke
parents:
diff changeset
3996 if (inst_cisc != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3997 fprintf(fp_hpp, " virtual int cisc_operand() const { return %d; }\n", cisc_spill_operand());
a61af66fc99e Initial load
duke
parents:
diff changeset
3998 fprintf(fp_hpp, " virtual MachNode *cisc_version(int offset, Compile* C);\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3999 fprintf(fp_hpp, " virtual void use_cisc_RegMask();\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4000 fprintf(fp_hpp, " virtual const RegMask *cisc_RegMask() const { return _cisc_RegMask; }\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4001 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4002 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4003 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4004
a61af66fc99e Initial load
duke
parents:
diff changeset
4005 //---------------------------define_cisc_version-------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
4006 // Build CISC version of this instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
4007 bool InstructForm::define_cisc_version(ArchDesc &AD, FILE *fp_cpp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4008 InstructForm *inst_cisc = this->cisc_spill_alternate();
a61af66fc99e Initial load
duke
parents:
diff changeset
4009 if( AD.can_cisc_spill() && (inst_cisc != NULL) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4010 const char *name = inst_cisc->_ident;
a61af66fc99e Initial load
duke
parents:
diff changeset
4011 assert( inst_cisc->num_opnds() == this->num_opnds(), "Must have same number of operands");
a61af66fc99e Initial load
duke
parents:
diff changeset
4012 OperandForm *cisc_oper = AD.cisc_spill_operand();
a61af66fc99e Initial load
duke
parents:
diff changeset
4013 assert( cisc_oper != NULL, "insanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
4014 const char *cisc_oper_name = cisc_oper->_ident;
a61af66fc99e Initial load
duke
parents:
diff changeset
4015 assert( cisc_oper_name != NULL, "insanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
4016 //
a61af66fc99e Initial load
duke
parents:
diff changeset
4017 // Set the correct reg_mask_or_stack for the cisc operand
a61af66fc99e Initial load
duke
parents:
diff changeset
4018 fprintf(fp_cpp, "\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4019 fprintf(fp_cpp, "void %sNode::use_cisc_RegMask() {\n", this->_ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
4020 // Lookup the correct reg_mask_or_stack
a61af66fc99e Initial load
duke
parents:
diff changeset
4021 const char *reg_mask_name = cisc_reg_mask_name();
a61af66fc99e Initial load
duke
parents:
diff changeset
4022 fprintf(fp_cpp, " _cisc_RegMask = &STACK_OR_%s;\n", reg_mask_name);
a61af66fc99e Initial load
duke
parents:
diff changeset
4023 fprintf(fp_cpp, "}\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4024 //
a61af66fc99e Initial load
duke
parents:
diff changeset
4025 // Construct CISC version of this instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
4026 fprintf(fp_cpp, "\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4027 fprintf(fp_cpp, "// Build CISC version of this instruction\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4028 fprintf(fp_cpp, "MachNode *%sNode::cisc_version( int offset, Compile* C ) {\n", this->_ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
4029 // Create the MachNode object
a61af66fc99e Initial load
duke
parents:
diff changeset
4030 fprintf(fp_cpp, " %sNode *node = new (C) %sNode();\n", name, name);
a61af66fc99e Initial load
duke
parents:
diff changeset
4031 // Fill in the bottom_type where requested
1541
b5fdf39b9749 6953576: bottom_type for matched AddPNodes doesn't always agree with ideal
never
parents: 1489
diff changeset
4032 if ( this->captures_bottom_type(AD.globalNames()) ) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
4033 fprintf(fp_cpp, " node->_bottom_type = bottom_type();\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4034 }
785
2056494941db 6814842: Load shortening optimizations
twisti
parents: 624
diff changeset
4035
2056494941db 6814842: Load shortening optimizations
twisti
parents: 624
diff changeset
4036 uint cur_num_opnds = num_opnds();
2056494941db 6814842: Load shortening optimizations
twisti
parents: 624
diff changeset
4037 if (cur_num_opnds > 1 && cur_num_opnds != num_unique_opnds()) {
2056494941db 6814842: Load shortening optimizations
twisti
parents: 624
diff changeset
4038 fprintf(fp_cpp," node->_num_opnds = %d;\n", num_unique_opnds());
2056494941db 6814842: Load shortening optimizations
twisti
parents: 624
diff changeset
4039 }
2056494941db 6814842: Load shortening optimizations
twisti
parents: 624
diff changeset
4040
0
a61af66fc99e Initial load
duke
parents:
diff changeset
4041 fprintf(fp_cpp, "\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4042 fprintf(fp_cpp, " // Copy _idx, inputs and operands to new node\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4043 fprintf(fp_cpp, " fill_new_machnode(node, C);\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4044 // Construct operand to access [stack_pointer + offset]
a61af66fc99e Initial load
duke
parents:
diff changeset
4045 fprintf(fp_cpp, " // Construct operand to access [stack_pointer + offset]\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4046 fprintf(fp_cpp, " node->set_opnd_array(cisc_operand(), new (C) %sOper(offset));\n", cisc_oper_name);
a61af66fc99e Initial load
duke
parents:
diff changeset
4047 fprintf(fp_cpp, "\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4048
a61af66fc99e Initial load
duke
parents:
diff changeset
4049 // Return result and exit scope
a61af66fc99e Initial load
duke
parents:
diff changeset
4050 fprintf(fp_cpp, " return node;\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4051 fprintf(fp_cpp, "}\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4052 fprintf(fp_cpp, "\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4053 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
4054 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4055 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
4056 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4057
a61af66fc99e Initial load
duke
parents:
diff changeset
4058 //---------------------------declare_short_branch_methods----------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
4059 // Build prototypes for short branch methods
a61af66fc99e Initial load
duke
parents:
diff changeset
4060 void InstructForm::declare_short_branch_methods(FILE *fp_hpp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4061 if (has_short_branch_form()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4062 fprintf(fp_hpp, " virtual MachNode *short_branch_version(Compile* C);\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4063 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4064 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4065
a61af66fc99e Initial load
duke
parents:
diff changeset
4066 //---------------------------define_short_branch_methods-----------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
4067 // Build definitions for short branch methods
1541
b5fdf39b9749 6953576: bottom_type for matched AddPNodes doesn't always agree with ideal
never
parents: 1489
diff changeset
4068 bool InstructForm::define_short_branch_methods(ArchDesc &AD, FILE *fp_cpp) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
4069 if (has_short_branch_form()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4070 InstructForm *short_branch = short_branch_form();
a61af66fc99e Initial load
duke
parents:
diff changeset
4071 const char *name = short_branch->_ident;
a61af66fc99e Initial load
duke
parents:
diff changeset
4072
a61af66fc99e Initial load
duke
parents:
diff changeset
4073 // Construct short_branch_version() method.
a61af66fc99e Initial load
duke
parents:
diff changeset
4074 fprintf(fp_cpp, "// Build short branch version of this instruction\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4075 fprintf(fp_cpp, "MachNode *%sNode::short_branch_version(Compile* C) {\n", this->_ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
4076 // Create the MachNode object
a61af66fc99e Initial load
duke
parents:
diff changeset
4077 fprintf(fp_cpp, " %sNode *node = new (C) %sNode();\n", name, name);
a61af66fc99e Initial load
duke
parents:
diff changeset
4078 if( is_ideal_if() ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4079 fprintf(fp_cpp, " node->_prob = _prob;\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4080 fprintf(fp_cpp, " node->_fcnt = _fcnt;\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4081 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4082 // Fill in the bottom_type where requested
1541
b5fdf39b9749 6953576: bottom_type for matched AddPNodes doesn't always agree with ideal
never
parents: 1489
diff changeset
4083 if ( this->captures_bottom_type(AD.globalNames()) ) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
4084 fprintf(fp_cpp, " node->_bottom_type = bottom_type();\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4085 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4086
a61af66fc99e Initial load
duke
parents:
diff changeset
4087 fprintf(fp_cpp, "\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4088 // Short branch version must use same node index for access
a61af66fc99e Initial load
duke
parents:
diff changeset
4089 // through allocator's tables
a61af66fc99e Initial load
duke
parents:
diff changeset
4090 fprintf(fp_cpp, " // Copy _idx, inputs and operands to new node\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4091 fprintf(fp_cpp, " fill_new_machnode(node, C);\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4092
a61af66fc99e Initial load
duke
parents:
diff changeset
4093 // Return result and exit scope
a61af66fc99e Initial load
duke
parents:
diff changeset
4094 fprintf(fp_cpp, " return node;\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4095 fprintf(fp_cpp, "}\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4096 fprintf(fp_cpp,"\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4097 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
4098 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4099 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
4100 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4101
a61af66fc99e Initial load
duke
parents:
diff changeset
4102
a61af66fc99e Initial load
duke
parents:
diff changeset
4103 //---------------------------buildMachNodeGenerator----------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
4104 // Build switch to invoke appropriate "new" MachNode for an opcode
a61af66fc99e Initial load
duke
parents:
diff changeset
4105 void ArchDesc::buildMachNodeGenerator(FILE *fp_cpp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4106
a61af66fc99e Initial load
duke
parents:
diff changeset
4107 // Build switch to invoke 'new' for a specific MachNode
a61af66fc99e Initial load
duke
parents:
diff changeset
4108 fprintf(fp_cpp, "\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4109 fprintf(fp_cpp, "\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4110 fprintf(fp_cpp,
a61af66fc99e Initial load
duke
parents:
diff changeset
4111 "//------------------------- MachNode Generator ---------------\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4112 fprintf(fp_cpp,
a61af66fc99e Initial load
duke
parents:
diff changeset
4113 "// A switch statement on the dense-packed user-defined type system\n"
a61af66fc99e Initial load
duke
parents:
diff changeset
4114 "// that invokes 'new' on the corresponding class constructor.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4115 fprintf(fp_cpp, "\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4116 fprintf(fp_cpp, "MachNode *State::MachNodeGenerator");
a61af66fc99e Initial load
duke
parents:
diff changeset
4117 fprintf(fp_cpp, "(int opcode, Compile* C)");
a61af66fc99e Initial load
duke
parents:
diff changeset
4118 fprintf(fp_cpp, "{\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4119 fprintf(fp_cpp, " switch(opcode) {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4120
a61af66fc99e Initial load
duke
parents:
diff changeset
4121 // Provide constructor for all user-defined instructions
a61af66fc99e Initial load
duke
parents:
diff changeset
4122 _instructions.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
4123 int opIndex = operandFormCount();
a61af66fc99e Initial load
duke
parents:
diff changeset
4124 InstructForm *inst;
a61af66fc99e Initial load
duke
parents:
diff changeset
4125 for( ; (inst = (InstructForm*)_instructions.iter()) != NULL; ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4126 // Ensure that matrule is defined.
a61af66fc99e Initial load
duke
parents:
diff changeset
4127 if ( inst->_matrule == NULL ) continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
4128
a61af66fc99e Initial load
duke
parents:
diff changeset
4129 int opcode = opIndex++;
a61af66fc99e Initial load
duke
parents:
diff changeset
4130 const char *opClass = inst->_ident;
a61af66fc99e Initial load
duke
parents:
diff changeset
4131 char *opType = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
4132
a61af66fc99e Initial load
duke
parents:
diff changeset
4133 // Generate the case statement for this instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
4134 fprintf(fp_cpp, " case %s_rule:", opClass);
a61af66fc99e Initial load
duke
parents:
diff changeset
4135
a61af66fc99e Initial load
duke
parents:
diff changeset
4136 // Start local scope
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
4137 fprintf(fp_cpp, " {\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
4138 // Generate code to construct the new MachNode
a61af66fc99e Initial load
duke
parents:
diff changeset
4139 buildMachNode(fp_cpp, inst, " ");
a61af66fc99e Initial load
duke
parents:
diff changeset
4140 // Return result and exit scope
a61af66fc99e Initial load
duke
parents:
diff changeset
4141 fprintf(fp_cpp, " return node;\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4142 fprintf(fp_cpp, " }\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4143 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4144
a61af66fc99e Initial load
duke
parents:
diff changeset
4145 // Generate the default case for switch(opcode)
a61af66fc99e Initial load
duke
parents:
diff changeset
4146 fprintf(fp_cpp, " \n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4147 fprintf(fp_cpp, " default:\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4148 fprintf(fp_cpp, " fprintf(stderr, \"Default MachNode Generator invoked for: \\n\");\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4149 fprintf(fp_cpp, " fprintf(stderr, \" opcode = %cd\\n\", opcode);\n", '%');
a61af66fc99e Initial load
duke
parents:
diff changeset
4150 fprintf(fp_cpp, " break;\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4151 fprintf(fp_cpp, " };\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4152
a61af66fc99e Initial load
duke
parents:
diff changeset
4153 // Generate the closing for method Matcher::MachNodeGenerator
a61af66fc99e Initial load
duke
parents:
diff changeset
4154 fprintf(fp_cpp, " return NULL;\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4155 fprintf(fp_cpp, "}\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4156 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4157
a61af66fc99e Initial load
duke
parents:
diff changeset
4158
a61af66fc99e Initial load
duke
parents:
diff changeset
4159 //---------------------------buildInstructMatchCheck--------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
4160 // Output the method to Matcher which checks whether or not a specific
a61af66fc99e Initial load
duke
parents:
diff changeset
4161 // instruction has a matching rule for the host architecture.
a61af66fc99e Initial load
duke
parents:
diff changeset
4162 void ArchDesc::buildInstructMatchCheck(FILE *fp_cpp) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
4163 fprintf(fp_cpp, "\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4164 fprintf(fp_cpp, "const bool Matcher::has_match_rule(int opcode) {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4165 fprintf(fp_cpp, " assert(_last_machine_leaf < opcode && opcode < _last_opcode, \"opcode in range\");\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4166 fprintf(fp_cpp, " return _hasMatchRule[opcode];\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4167 fprintf(fp_cpp, "}\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4168
a61af66fc99e Initial load
duke
parents:
diff changeset
4169 fprintf(fp_cpp, "const bool Matcher::_hasMatchRule[_last_opcode] = {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4170 int i;
a61af66fc99e Initial load
duke
parents:
diff changeset
4171 for (i = 0; i < _last_opcode - 1; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4172 fprintf(fp_cpp, " %-5s, // %s\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
4173 _has_match_rule[i] ? "true" : "false",
a61af66fc99e Initial load
duke
parents:
diff changeset
4174 NodeClassNames[i]);
a61af66fc99e Initial load
duke
parents:
diff changeset
4175 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4176 fprintf(fp_cpp, " %-5s // %s\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
4177 _has_match_rule[i] ? "true" : "false",
a61af66fc99e Initial load
duke
parents:
diff changeset
4178 NodeClassNames[i]);
a61af66fc99e Initial load
duke
parents:
diff changeset
4179 fprintf(fp_cpp, "};\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4180 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4181
a61af66fc99e Initial load
duke
parents:
diff changeset
4182 //---------------------------buildFrameMethods---------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
4183 // Output the methods to Matcher which specify frame behavior
a61af66fc99e Initial load
duke
parents:
diff changeset
4184 void ArchDesc::buildFrameMethods(FILE *fp_cpp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4185 fprintf(fp_cpp,"\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4186 // Stack Direction
a61af66fc99e Initial load
duke
parents:
diff changeset
4187 fprintf(fp_cpp,"bool Matcher::stack_direction() const { return %s; }\n\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
4188 _frame->_direction ? "true" : "false");
a61af66fc99e Initial load
duke
parents:
diff changeset
4189 // Sync Stack Slots
a61af66fc99e Initial load
duke
parents:
diff changeset
4190 fprintf(fp_cpp,"int Compile::sync_stack_slots() const { return %s; }\n\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
4191 _frame->_sync_stack_slots);
a61af66fc99e Initial load
duke
parents:
diff changeset
4192 // Java Stack Alignment
a61af66fc99e Initial load
duke
parents:
diff changeset
4193 fprintf(fp_cpp,"uint Matcher::stack_alignment_in_bytes() { return %s; }\n\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
4194 _frame->_alignment);
a61af66fc99e Initial load
duke
parents:
diff changeset
4195 // Java Return Address Location
a61af66fc99e Initial load
duke
parents:
diff changeset
4196 fprintf(fp_cpp,"OptoReg::Name Matcher::return_addr() const {");
a61af66fc99e Initial load
duke
parents:
diff changeset
4197 if (_frame->_return_addr_loc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4198 fprintf(fp_cpp," return OptoReg::Name(%s_num); }\n\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
4199 _frame->_return_addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
4200 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4201 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
4202 fprintf(fp_cpp," return OptoReg::stack2reg(%s); }\n\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
4203 _frame->_return_addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
4204 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4205 // Java Stack Slot Preservation
a61af66fc99e Initial load
duke
parents:
diff changeset
4206 fprintf(fp_cpp,"uint Compile::in_preserve_stack_slots() ");
a61af66fc99e Initial load
duke
parents:
diff changeset
4207 fprintf(fp_cpp,"{ return %s; }\n\n", _frame->_in_preserve_slots);
a61af66fc99e Initial load
duke
parents:
diff changeset
4208 // Top Of Stack Slot Preservation, for both Java and C
a61af66fc99e Initial load
duke
parents:
diff changeset
4209 fprintf(fp_cpp,"uint Compile::out_preserve_stack_slots() ");
a61af66fc99e Initial load
duke
parents:
diff changeset
4210 fprintf(fp_cpp,"{ return SharedRuntime::out_preserve_stack_slots(); }\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4211 // varargs C out slots killed
a61af66fc99e Initial load
duke
parents:
diff changeset
4212 fprintf(fp_cpp,"uint Compile::varargs_C_out_slots_killed() const ");
a61af66fc99e Initial load
duke
parents:
diff changeset
4213 fprintf(fp_cpp,"{ return %s; }\n\n", _frame->_varargs_C_out_slots_killed);
a61af66fc99e Initial load
duke
parents:
diff changeset
4214 // Java Argument Position
a61af66fc99e Initial load
duke
parents:
diff changeset
4215 fprintf(fp_cpp,"void Matcher::calling_convention(BasicType *sig_bt, VMRegPair *regs, uint length, bool is_outgoing) {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4216 fprintf(fp_cpp,"%s\n", _frame->_calling_convention);
a61af66fc99e Initial load
duke
parents:
diff changeset
4217 fprintf(fp_cpp,"}\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4218 // Native Argument Position
a61af66fc99e Initial load
duke
parents:
diff changeset
4219 fprintf(fp_cpp,"void Matcher::c_calling_convention(BasicType *sig_bt, VMRegPair *regs, uint length) {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4220 fprintf(fp_cpp,"%s\n", _frame->_c_calling_convention);
a61af66fc99e Initial load
duke
parents:
diff changeset
4221 fprintf(fp_cpp,"}\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4222 // Java Return Value Location
a61af66fc99e Initial load
duke
parents:
diff changeset
4223 fprintf(fp_cpp,"OptoRegPair Matcher::return_value(int ideal_reg, bool is_outgoing) {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4224 fprintf(fp_cpp,"%s\n", _frame->_return_value);
a61af66fc99e Initial load
duke
parents:
diff changeset
4225 fprintf(fp_cpp,"}\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4226 // Native Return Value Location
a61af66fc99e Initial load
duke
parents:
diff changeset
4227 fprintf(fp_cpp,"OptoRegPair Matcher::c_return_value(int ideal_reg, bool is_outgoing) {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4228 fprintf(fp_cpp,"%s\n", _frame->_c_return_value);
a61af66fc99e Initial load
duke
parents:
diff changeset
4229 fprintf(fp_cpp,"}\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4230
a61af66fc99e Initial load
duke
parents:
diff changeset
4231 // Inline Cache Register, mask definition, and encoding
a61af66fc99e Initial load
duke
parents:
diff changeset
4232 fprintf(fp_cpp,"OptoReg::Name Matcher::inline_cache_reg() {");
a61af66fc99e Initial load
duke
parents:
diff changeset
4233 fprintf(fp_cpp," return OptoReg::Name(%s_num); }\n\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
4234 _frame->_inline_cache_reg);
a61af66fc99e Initial load
duke
parents:
diff changeset
4235 fprintf(fp_cpp,"int Matcher::inline_cache_reg_encode() {");
a61af66fc99e Initial load
duke
parents:
diff changeset
4236 fprintf(fp_cpp," return _regEncode[inline_cache_reg()]; }\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4237
a61af66fc99e Initial load
duke
parents:
diff changeset
4238 // Interpreter's Method Oop Register, mask definition, and encoding
a61af66fc99e Initial load
duke
parents:
diff changeset
4239 fprintf(fp_cpp,"OptoReg::Name Matcher::interpreter_method_oop_reg() {");
a61af66fc99e Initial load
duke
parents:
diff changeset
4240 fprintf(fp_cpp," return OptoReg::Name(%s_num); }\n\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
4241 _frame->_interpreter_method_oop_reg);
a61af66fc99e Initial load
duke
parents:
diff changeset
4242 fprintf(fp_cpp,"int Matcher::interpreter_method_oop_reg_encode() {");
a61af66fc99e Initial load
duke
parents:
diff changeset
4243 fprintf(fp_cpp," return _regEncode[interpreter_method_oop_reg()]; }\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4244
a61af66fc99e Initial load
duke
parents:
diff changeset
4245 // Interpreter's Frame Pointer Register, mask definition, and encoding
a61af66fc99e Initial load
duke
parents:
diff changeset
4246 fprintf(fp_cpp,"OptoReg::Name Matcher::interpreter_frame_pointer_reg() {");
a61af66fc99e Initial load
duke
parents:
diff changeset
4247 if (_frame->_interpreter_frame_pointer_reg == NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
4248 fprintf(fp_cpp," return OptoReg::Bad; }\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4249 else
a61af66fc99e Initial load
duke
parents:
diff changeset
4250 fprintf(fp_cpp," return OptoReg::Name(%s_num); }\n\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
4251 _frame->_interpreter_frame_pointer_reg);
a61af66fc99e Initial load
duke
parents:
diff changeset
4252
a61af66fc99e Initial load
duke
parents:
diff changeset
4253 // Frame Pointer definition
a61af66fc99e Initial load
duke
parents:
diff changeset
4254 /* CNC - I can not contemplate having a different frame pointer between
a61af66fc99e Initial load
duke
parents:
diff changeset
4255 Java and native code; makes my head hurt to think about it.
a61af66fc99e Initial load
duke
parents:
diff changeset
4256 fprintf(fp_cpp,"OptoReg::Name Matcher::frame_pointer() const {");
a61af66fc99e Initial load
duke
parents:
diff changeset
4257 fprintf(fp_cpp," return OptoReg::Name(%s_num); }\n\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
4258 _frame->_frame_pointer);
a61af66fc99e Initial load
duke
parents:
diff changeset
4259 */
a61af66fc99e Initial load
duke
parents:
diff changeset
4260 // (Native) Frame Pointer definition
a61af66fc99e Initial load
duke
parents:
diff changeset
4261 fprintf(fp_cpp,"OptoReg::Name Matcher::c_frame_pointer() const {");
a61af66fc99e Initial load
duke
parents:
diff changeset
4262 fprintf(fp_cpp," return OptoReg::Name(%s_num); }\n\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
4263 _frame->_frame_pointer);
a61af66fc99e Initial load
duke
parents:
diff changeset
4264
a61af66fc99e Initial load
duke
parents:
diff changeset
4265 // Number of callee-save + always-save registers for calling convention
a61af66fc99e Initial load
duke
parents:
diff changeset
4266 fprintf(fp_cpp, "// Number of callee-save + always-save registers\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4267 fprintf(fp_cpp, "int Matcher::number_of_saved_registers() {\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4268 RegDef *rdef;
a61af66fc99e Initial load
duke
parents:
diff changeset
4269 int nof_saved_registers = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
4270 _register->reset_RegDefs();
a61af66fc99e Initial load
duke
parents:
diff changeset
4271 while( (rdef = _register->iter_RegDefs()) != NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4272 if( !strcmp(rdef->_callconv, "SOE") || !strcmp(rdef->_callconv, "AS") )
a61af66fc99e Initial load
duke
parents:
diff changeset
4273 ++nof_saved_registers;
a61af66fc99e Initial load
duke
parents:
diff changeset
4274 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4275 fprintf(fp_cpp, " return %d;\n", nof_saved_registers);
a61af66fc99e Initial load
duke
parents:
diff changeset
4276 fprintf(fp_cpp, "};\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4277 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4278
a61af66fc99e Initial load
duke
parents:
diff changeset
4279
a61af66fc99e Initial load
duke
parents:
diff changeset
4280
a61af66fc99e Initial load
duke
parents:
diff changeset
4281
a61af66fc99e Initial load
duke
parents:
diff changeset
4282 static int PrintAdlcCisc = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
4283 //---------------------------identify_cisc_spilling----------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
4284 // Get info for the CISC_oracle and MachNode::cisc_version()
a61af66fc99e Initial load
duke
parents:
diff changeset
4285 void ArchDesc::identify_cisc_spill_instructions() {
a61af66fc99e Initial load
duke
parents:
diff changeset
4286
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
4287 if (_frame == NULL)
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
4288 return;
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6848
diff changeset
4289
0
a61af66fc99e Initial load
duke
parents:
diff changeset
4290 // Find the user-defined operand for cisc-spilling
a61af66fc99e Initial load
duke
parents:
diff changeset
4291 if( _frame->_cisc_spilling_operand_name != NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4292 const Form *form = _globalNames[_frame->_cisc_spilling_operand_name];
a61af66fc99e Initial load
duke
parents:
diff changeset
4293 OperandForm *oper = form ? form->is_operand() : NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
4294 // Verify the user's suggestion
a61af66fc99e Initial load
duke
parents:
diff changeset
4295 if( oper != NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4296 // Ensure that match field is defined.
a61af66fc99e Initial load
duke
parents:
diff changeset
4297 if ( oper->_matrule != NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4298 MatchRule &mrule = *oper->_matrule;
a61af66fc99e Initial load
duke
parents:
diff changeset
4299 if( strcmp(mrule._opType,"AddP") == 0 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4300 MatchNode *left = mrule._lChild;
a61af66fc99e Initial load
duke
parents:
diff changeset
4301 MatchNode *right= mrule._rChild;
a61af66fc99e Initial load
duke
parents:
diff changeset
4302 if( left != NULL && right != NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4303 const Form *left_op = _globalNames[left->_opType]->is_operand();
a61af66fc99e Initial load
duke
parents:
diff changeset
4304 const Form *right_op = _globalNames[right->_opType]->is_operand();
a61af66fc99e Initial load
duke
parents:
diff changeset
4305 if( (left_op != NULL && right_op != NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
4306 && (left_op->interface_type(_globalNames) == Form::register_interface)
a61af66fc99e Initial load
duke
parents:
diff changeset
4307 && (right_op->interface_type(_globalNames) == Form::constant_interface) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4308 // Successfully verified operand
a61af66fc99e Initial load
duke
parents:
diff changeset
4309 set_cisc_spill_operand( oper );
a61af66fc99e Initial load
duke
parents:
diff changeset
4310 if( _cisc_spill_debug ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4311 fprintf(stderr, "\n\nVerified CISC-spill operand %s\n\n", oper->_ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
4312 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4313 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4314 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4315 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4316 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4317 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4318 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4319
a61af66fc99e Initial load
duke
parents:
diff changeset
4320 if( cisc_spill_operand() != NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4321 // N^2 comparison of instructions looking for a cisc-spilling version
a61af66fc99e Initial load
duke
parents:
diff changeset
4322 _instructions.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
4323 InstructForm *instr;
a61af66fc99e Initial load
duke
parents:
diff changeset
4324 for( ; (instr = (InstructForm*)_instructions.iter()) != NULL; ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4325 // Ensure that match field is defined.
a61af66fc99e Initial load
duke
parents:
diff changeset
4326 if ( instr->_matrule == NULL ) continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
4327
a61af66fc99e Initial load
duke
parents:
diff changeset
4328 MatchRule &mrule = *instr->_matrule;
a61af66fc99e Initial load
duke
parents:
diff changeset
4329 Predicate *pred = instr->build_predicate();
a61af66fc99e Initial load
duke
parents:
diff changeset
4330
a61af66fc99e Initial load
duke
parents:
diff changeset
4331 // Grab the machine type of the operand
a61af66fc99e Initial load
duke
parents:
diff changeset
4332 const char *rootOp = instr->_ident;
a61af66fc99e Initial load
duke
parents:
diff changeset
4333 mrule._machType = rootOp;
a61af66fc99e Initial load
duke
parents:
diff changeset
4334
a61af66fc99e Initial load
duke
parents:
diff changeset
4335 // Find result type for match
a61af66fc99e Initial load
duke
parents:
diff changeset
4336 const char *result = instr->reduce_result();
a61af66fc99e Initial load
duke
parents:
diff changeset
4337
a61af66fc99e Initial load
duke
parents:
diff changeset
4338 if( PrintAdlcCisc ) fprintf(stderr, " new instruction %s \n", instr->_ident ? instr->_ident : " ");
a61af66fc99e Initial load
duke
parents:
diff changeset
4339 bool found_cisc_alternate = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
4340 _instructions.reset2();
a61af66fc99e Initial load
duke
parents:
diff changeset
4341 InstructForm *instr2;
a61af66fc99e Initial load
duke
parents:
diff changeset
4342 for( ; !found_cisc_alternate && (instr2 = (InstructForm*)_instructions.iter2()) != NULL; ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4343 // Ensure that match field is defined.
a61af66fc99e Initial load
duke
parents:
diff changeset
4344 if( PrintAdlcCisc ) fprintf(stderr, " instr2 == %s \n", instr2->_ident ? instr2->_ident : " ");
a61af66fc99e Initial load
duke
parents:
diff changeset
4345 if ( instr2->_matrule != NULL
a61af66fc99e Initial load
duke
parents:
diff changeset
4346 && (instr != instr2 ) // Skip self
a61af66fc99e Initial load
duke
parents:
diff changeset
4347 && (instr2->reduce_result() != NULL) // want same result
a61af66fc99e Initial load
duke
parents:
diff changeset
4348 && (strcmp(result, instr2->reduce_result()) == 0)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4349 MatchRule &mrule2 = *instr2->_matrule;
a61af66fc99e Initial load
duke
parents:
diff changeset
4350 Predicate *pred2 = instr2->build_predicate();
a61af66fc99e Initial load
duke
parents:
diff changeset
4351 found_cisc_alternate = instr->cisc_spills_to(*this, instr2);
a61af66fc99e Initial load
duke
parents:
diff changeset
4352 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4353 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4354 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4355 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4356 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4357
a61af66fc99e Initial load
duke
parents:
diff changeset
4358 //---------------------------build_cisc_spilling-------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
4359 // Get info for the CISC_oracle and MachNode::cisc_version()
a61af66fc99e Initial load
duke
parents:
diff changeset
4360 void ArchDesc::build_cisc_spill_instructions(FILE *fp_hpp, FILE *fp_cpp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4361 // Output the table for cisc spilling
a61af66fc99e Initial load
duke
parents:
diff changeset
4362 fprintf(fp_cpp, "// The following instructions can cisc-spill\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4363 _instructions.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
4364 InstructForm *inst = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
4365 for(; (inst = (InstructForm*)_instructions.iter()) != NULL; ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4366 // Ensure this is a machine-world instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
4367 if ( inst->ideal_only() ) continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
4368 const char *inst_name = inst->_ident;
a61af66fc99e Initial load
duke
parents:
diff changeset
4369 int operand = inst->cisc_spill_operand();
a61af66fc99e Initial load
duke
parents:
diff changeset
4370 if( operand != AdlcVMDeps::Not_cisc_spillable ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4371 InstructForm *inst2 = inst->cisc_spill_alternate();
a61af66fc99e Initial load
duke
parents:
diff changeset
4372 fprintf(fp_cpp, "// %s can cisc-spill operand %d to %s\n", inst->_ident, operand, inst2->_ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
4373 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4374 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4375 fprintf(fp_cpp, "\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4376 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4377
a61af66fc99e Initial load
duke
parents:
diff changeset
4378 //---------------------------identify_short_branches----------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
4379 // Get info for our short branch replacement oracle.
a61af66fc99e Initial load
duke
parents:
diff changeset
4380 void ArchDesc::identify_short_branches() {
a61af66fc99e Initial load
duke
parents:
diff changeset
4381 // Walk over all instructions, checking to see if they match a short
a61af66fc99e Initial load
duke
parents:
diff changeset
4382 // branching alternate.
a61af66fc99e Initial load
duke
parents:
diff changeset
4383 _instructions.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
4384 InstructForm *instr;
a61af66fc99e Initial load
duke
parents:
diff changeset
4385 while( (instr = (InstructForm*)_instructions.iter()) != NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4386 // The instruction must have a match rule.
a61af66fc99e Initial load
duke
parents:
diff changeset
4387 if (instr->_matrule != NULL &&
a61af66fc99e Initial load
duke
parents:
diff changeset
4388 instr->is_short_branch()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4389
a61af66fc99e Initial load
duke
parents:
diff changeset
4390 _instructions.reset2();
a61af66fc99e Initial load
duke
parents:
diff changeset
4391 InstructForm *instr2;
a61af66fc99e Initial load
duke
parents:
diff changeset
4392 while( (instr2 = (InstructForm*)_instructions.iter2()) != NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4393 instr2->check_branch_variant(*this, instr);
a61af66fc99e Initial load
duke
parents:
diff changeset
4394 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4395 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4396 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4397 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4398
a61af66fc99e Initial load
duke
parents:
diff changeset
4399
a61af66fc99e Initial load
duke
parents:
diff changeset
4400 //---------------------------identify_unique_operands---------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
4401 // Identify unique operands.
a61af66fc99e Initial load
duke
parents:
diff changeset
4402 void ArchDesc::identify_unique_operands() {
a61af66fc99e Initial load
duke
parents:
diff changeset
4403 // Walk over all instructions.
a61af66fc99e Initial load
duke
parents:
diff changeset
4404 _instructions.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
4405 InstructForm *instr;
a61af66fc99e Initial load
duke
parents:
diff changeset
4406 while( (instr = (InstructForm*)_instructions.iter()) != NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4407 // Ensure this is a machine-world instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
4408 if (!instr->ideal_only()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4409 instr->set_unique_opnds();
a61af66fc99e Initial load
duke
parents:
diff changeset
4410 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4411 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4412 }