Bug Summary

File:jdk/src/hotspot/share/adlc/output_h.cpp
Warning:line 306, column 8
Although the value stored to 'comp' is used in the enclosing expression, the value is never actually read from 'comp'

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name output_h.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model static -mthread-model posix -mframe-pointer=all -fmath-errno -fno-rounding-math -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -dwarf-column-info -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib/llvm-10/lib/clang/10.0.0 -D LINUX -D ASSERT -D AMD64 -I /home/daniel/Projects/java/jdk/src/hotspot/share -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-10/lib/clang/10.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-unused-parameter -Wno-unused -fdeprecated-macro -fdebug-compilation-dir /home/daniel/Projects/java/jdk/make/hotspot -ferror-limit 19 -fmessage-length 0 -fgnuc-version=4.2.1 -fobjc-runtime=gcc -fdiagnostics-show-option -analyzer-output=html -faddrsig -o /home/daniel/Projects/java/scan/2021-12-21-193737-8510-1 -x c++ /home/daniel/Projects/java/jdk/src/hotspot/share/adlc/output_h.cpp
1/*
2 * Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25// output_h.cpp - Class HPP file output routines for architecture definition
26#include "adlc.hpp"
27
28// The comment delimiter used in format statements after assembler instructions.
29#if defined(PPC64)
30#define commentSeperator"!" "\t//"
31#else
32#define commentSeperator"!" "!"
33#endif
34
35// Generate the #define that describes the number of registers.
36static void defineRegCount(FILE *fp, RegisterForm *registers) {
37 if (registers) {
38 int regCount = AdlcVMDeps::Physical + registers->_rdefs.count();
39 fprintf(fp,"\n");
40 fprintf(fp,"// the number of reserved registers + machine registers.\n");
41 fprintf(fp,"#define REG_COUNT %d\n", regCount);
42 }
43}
44
45// Output enumeration of machine register numbers
46// (1)
47// // Enumerate machine registers starting after reserved regs.
48// // in the order of occurrence in the register block.
49// enum MachRegisterNumbers {
50// EAX_num = 0,
51// ...
52// _last_Mach_Reg
53// }
54void ArchDesc::buildMachRegisterNumbers(FILE *fp_hpp) {
55 if (_register) {
56 RegDef *reg_def = NULL__null;
57
58 // Output a #define for the number of machine registers
59 defineRegCount(fp_hpp, _register);
60
61 // Count all the Save_On_Entry and Always_Save registers
62 int saved_on_entry = 0;
63 int c_saved_on_entry = 0;
64 _register->reset_RegDefs();
65 while( (reg_def = _register->iter_RegDefs()) != NULL__null ) {
66 if( strcmp(reg_def->_callconv,"SOE") == 0 ||
67 strcmp(reg_def->_callconv,"AS") == 0 ) ++saved_on_entry;
68 if( strcmp(reg_def->_c_conv,"SOE") == 0 ||
69 strcmp(reg_def->_c_conv,"AS") == 0 ) ++c_saved_on_entry;
70 }
71 fprintf(fp_hpp, "\n");
72 fprintf(fp_hpp, "// the number of save_on_entry + always_saved registers.\n");
73 fprintf(fp_hpp, "#define MAX_SAVED_ON_ENTRY_REG_COUNT %d\n", max(saved_on_entry,c_saved_on_entry)(((saved_on_entry)>(c_saved_on_entry)) ? (saved_on_entry) :
(c_saved_on_entry))
);
74 fprintf(fp_hpp, "#define SAVED_ON_ENTRY_REG_COUNT %d\n", saved_on_entry);
75 fprintf(fp_hpp, "#define C_SAVED_ON_ENTRY_REG_COUNT %d\n", c_saved_on_entry);
76
77 // (1)
78 // Build definition for enumeration of register numbers
79 fprintf(fp_hpp, "\n");
80 fprintf(fp_hpp, "// Enumerate machine register numbers starting after reserved regs.\n");
81 fprintf(fp_hpp, "// in the order of occurrence in the register block.\n");
82 fprintf(fp_hpp, "enum MachRegisterNumbers {\n");
83
84 // Output the register number for each register in the allocation classes
85 _register->reset_RegDefs();
86 int i = 0;
87 while( (reg_def = _register->iter_RegDefs()) != NULL__null ) {
88 fprintf(fp_hpp," %s_num,", reg_def->_regname);
89 for (int j = 0; j < 20-(int)strlen(reg_def->_regname); j++) fprintf(fp_hpp, " ");
90 fprintf(fp_hpp," // enum %3d, regnum %3d, reg encode %3s\n",
91 i++,
92 reg_def->register_num(),
93 reg_def->register_encode());
94 }
95 // Finish defining enumeration
96 fprintf(fp_hpp, " _last_Mach_Reg // %d\n", i);
97 fprintf(fp_hpp, "};\n");
98 }
99
100 fprintf(fp_hpp, "\n// Size of register-mask in ints\n");
101 fprintf(fp_hpp, "#define RM_SIZE %d\n", RegisterForm::RegMask_Size());
102 fprintf(fp_hpp, "// Unroll factor for loops over the data in a RegMask\n");
103 fprintf(fp_hpp, "#define FORALL_BODY ");
104 int len = RegisterForm::RegMask_Size();
105 for( int i = 0; i < len; i++ )
106 fprintf(fp_hpp, "BODY(%d) ",i);
107 fprintf(fp_hpp, "\n\n");
108
109 fprintf(fp_hpp,"class RegMask;\n");
110 // All RegMasks are declared "extern const ..." in ad_<arch>.hpp
111 // fprintf(fp_hpp,"extern RegMask STACK_OR_STACK_SLOTS_mask;\n\n");
112}
113
114
115// Output enumeration of machine register encodings
116// (2)
117// // Enumerate machine registers starting after reserved regs.
118// // in the order of occurrence in the alloc_class(es).
119// enum MachRegisterEncodes {
120// EAX_enc = 0x00,
121// ...
122// }
123void ArchDesc::buildMachRegisterEncodes(FILE *fp_hpp) {
124 if (_register) {
125 RegDef *reg_def = NULL__null;
126 RegDef *reg_def_next = NULL__null;
127
128 // (2)
129 // Build definition for enumeration of encode values
130 fprintf(fp_hpp, "\n");
131 fprintf(fp_hpp, "// Enumerate machine registers starting after reserved regs.\n");
132 fprintf(fp_hpp, "// in the order of occurrence in the alloc_class(es).\n");
133 fprintf(fp_hpp, "enum MachRegisterEncodes {\n");
134
135 // Find max enum string length.
136 size_t maxlen = 0;
137 _register->reset_RegDefs();
138 reg_def = _register->iter_RegDefs();
139 while (reg_def != NULL__null) {
140 size_t len = strlen(reg_def->_regname);
141 if (len > maxlen) maxlen = len;
142 reg_def = _register->iter_RegDefs();
143 }
144
145 // Output the register encoding for each register in the allocation classes
146 _register->reset_RegDefs();
147 reg_def_next = _register->iter_RegDefs();
148 while( (reg_def = reg_def_next) != NULL__null ) {
149 reg_def_next = _register->iter_RegDefs();
150 fprintf(fp_hpp," %s_enc", reg_def->_regname);
151 for (size_t i = strlen(reg_def->_regname); i < maxlen; i++) fprintf(fp_hpp, " ");
152 fprintf(fp_hpp," = %3s%s\n", reg_def->register_encode(), reg_def_next == NULL__null? "" : "," );
153 }
154 // Finish defining enumeration
155 fprintf(fp_hpp, "};\n");
156
157 } // Done with register form
158}
159
160
161// Declare an array containing the machine register names, strings.
162static void declareRegNames(FILE *fp, RegisterForm *registers) {
163 if (registers) {
164// fprintf(fp,"\n");
165// fprintf(fp,"// An array of character pointers to machine register names.\n");
166// fprintf(fp,"extern const char *regName[];\n");
167 }
168}
169
170// Declare an array containing the machine register sizes in 32-bit words.
171void ArchDesc::declareRegSizes(FILE *fp) {
172// regSize[] is not used
173}
174
175// Declare an array containing the machine register encoding values
176static void declareRegEncodes(FILE *fp, RegisterForm *registers) {
177 if (registers) {
178 // // //
179 // fprintf(fp,"\n");
180 // fprintf(fp,"// An array containing the machine register encode values\n");
181 // fprintf(fp,"extern const char regEncode[];\n");
182 }
183}
184
185
186// ---------------------------------------------------------------------------
187//------------------------------Utilities to build Instruction Classes--------
188// ---------------------------------------------------------------------------
189static void out_RegMask(FILE *fp) {
190 fprintf(fp," virtual const RegMask &out_RegMask() const;\n");
191}
192
193// ---------------------------------------------------------------------------
194//--------Utilities to build MachOper and MachNode derived Classes------------
195// ---------------------------------------------------------------------------
196
197//------------------------------Utilities to build Operand Classes------------
198static void in_RegMask(FILE *fp) {
199 fprintf(fp," virtual const RegMask *in_RegMask(int index) const;\n");
200}
201
202static void declareConstStorage(FILE *fp, FormDict &globals, OperandForm *oper) {
203 int i = 0;
204 Component *comp;
205
206 if (oper->num_consts(globals) == 0) return;
207 // Iterate over the component list looking for constants
208 oper->_components.reset();
209 if ((comp = oper->_components.iter()) == NULL__null) {
210 assert(oper->num_consts(globals) == 1, "Bad component list detected.\n"){ if (!(oper->num_consts(globals) == 1)) { fprintf(stderr,
"assert fails %s %d: %s\n", "/home/daniel/Projects/java/jdk/src/hotspot/share/adlc/output_h.cpp"
, 210, "Bad component list detected.\n"); abort(); }}
;
211 const char *type = oper->ideal_type(globals);
212 if (!strcmp(type, "ConI")) {
213 if (i > 0) fprintf(fp,", ");
214 fprintf(fp," int32_t _c%d;\n", i);
215 }
216 else if (!strcmp(type, "ConP")) {
217 if (i > 0) fprintf(fp,", ");
218 fprintf(fp," const TypePtr *_c%d;\n", i);
219 }
220 else if (!strcmp(type, "ConN")) {
221 if (i > 0) fprintf(fp,", ");
222 fprintf(fp," const TypeNarrowOop *_c%d;\n", i);
223 }
224 else if (!strcmp(type, "ConNKlass")) {
225 if (i > 0) fprintf(fp,", ");
226 fprintf(fp," const TypeNarrowKlass *_c%d;\n", i);
227 }
228 else if (!strcmp(type, "ConL")) {
229 if (i > 0) fprintf(fp,", ");
230 fprintf(fp," jlong _c%d;\n", i);
231 }
232 else if (!strcmp(type, "ConF")) {
233 if (i > 0) fprintf(fp,", ");
234 fprintf(fp," jfloat _c%d;\n", i);
235 }
236 else if (!strcmp(type, "ConD")) {
237 if (i > 0) fprintf(fp,", ");
238 fprintf(fp," jdouble _c%d;\n", i);
239 }
240 else if (!strcmp(type, "Bool")) {
241 fprintf(fp,"private:\n");
242 fprintf(fp," BoolTest::mask _c%d;\n", i);
243 fprintf(fp,"public:\n");
244 }
245 else {
246 assert(0, "Non-constant operand lacks component list."){ if (!(0)) { fprintf(stderr, "assert fails %s %d: %s\n", "/home/daniel/Projects/java/jdk/src/hotspot/share/adlc/output_h.cpp"
, 246, "Non-constant operand lacks component list."); abort()
; }}
;
247 }
248 } // end if NULL
249 else {
250 oper->_components.reset();
251 while ((comp = oper->_components.iter()) != NULL__null) {
252 if (!strcmp(comp->base_type(globals), "ConI")) {
253 fprintf(fp," jint _c%d;\n", i);
254 i++;
255 }
256 else if (!strcmp(comp->base_type(globals), "ConP")) {
257 fprintf(fp," const TypePtr *_c%d;\n", i);
258 i++;
259 }
260 else if (!strcmp(comp->base_type(globals), "ConN")) {
261 fprintf(fp," const TypePtr *_c%d;\n", i);
262 i++;
263 }
264 else if (!strcmp(comp->base_type(globals), "ConNKlass")) {
265 fprintf(fp," const TypePtr *_c%d;\n", i);
266 i++;
267 }
268 else if (!strcmp(comp->base_type(globals), "ConL")) {
269 fprintf(fp," jlong _c%d;\n", i);
270 i++;
271 }
272 else if (!strcmp(comp->base_type(globals), "ConF")) {
273 fprintf(fp," jfloat _c%d;\n", i);
274 i++;
275 }
276 else if (!strcmp(comp->base_type(globals), "ConD")) {
277 fprintf(fp," jdouble _c%d;\n", i);
278 i++;
279 }
280 }
281 }
282}
283
284// Declare constructor.
285// Parameters start with condition code, then all other constants
286//
287// (0) public:
288// (1) MachXOper(int32 ccode, int32 c0, int32 c1, ..., int32 cn)
289// (2) : _ccode(ccode), _c0(c0), _c1(c1), ..., _cn(cn) { }
290//
291static void defineConstructor(FILE *fp, const char *name, uintunsigned int num_consts,
292 ComponentList &lst, bool is_ideal_bool,
293 Form::DataType constant_type, FormDict &globals) {
294 fprintf(fp,"public:\n");
295 // generate line (1)
296 fprintf(fp," %sOper(", name);
297 if( num_consts == 0 ) {
298 fprintf(fp,") {}\n");
299 return;
300 }
301
302 // generate parameters for constants
303 uintunsigned int i = 0;
304 Component *comp;
305 lst.reset();
306 if ((comp = lst.iter()) == NULL__null) {
Although the value stored to 'comp' is used in the enclosing expression, the value is never actually read from 'comp'
307 assert(num_consts == 1, "Bad component list detected.\n"){ if (!(num_consts == 1)) { fprintf(stderr, "assert fails %s %d: %s\n"
, "/home/daniel/Projects/java/jdk/src/hotspot/share/adlc/output_h.cpp"
, 307, "Bad component list detected.\n"); abort(); }}
;
308 switch( constant_type ) {
309 case Form::idealI : {
310 fprintf(fp,is_ideal_bool ? "BoolTest::mask c%d" : "int32_t c%d", i);
311 break;
312 }
313 case Form::idealN : { fprintf(fp,"const TypeNarrowOop *c%d", i); break; }
314 case Form::idealNKlass : { fprintf(fp,"const TypeNarrowKlass *c%d", i); break; }
315 case Form::idealP : { fprintf(fp,"const TypePtr *c%d", i); break; }
316 case Form::idealL : { fprintf(fp,"jlong c%d", i); break; }
317 case Form::idealF : { fprintf(fp,"jfloat c%d", i); break; }
318 case Form::idealD : { fprintf(fp,"jdouble c%d", i); break; }
319 default:
320 assert(!is_ideal_bool, "Non-constant operand lacks component list."){ if (!(!is_ideal_bool)) { fprintf(stderr, "assert fails %s %d: %s\n"
, "/home/daniel/Projects/java/jdk/src/hotspot/share/adlc/output_h.cpp"
, 320, "Non-constant operand lacks component list."); abort()
; }}
;
321 break;
322 }
323 } // end if NULL
324 else {
325 lst.reset();
326 while((comp = lst.iter()) != NULL__null) {
327 if (!strcmp(comp->base_type(globals), "ConI")) {
328 if (i > 0) fprintf(fp,", ");
329 fprintf(fp,"int32_t c%d", i);
330 i++;
331 }
332 else if (!strcmp(comp->base_type(globals), "ConP")) {
333 if (i > 0) fprintf(fp,", ");
334 fprintf(fp,"const TypePtr *c%d", i);
335 i++;
336 }
337 else if (!strcmp(comp->base_type(globals), "ConN")) {
338 if (i > 0) fprintf(fp,", ");
339 fprintf(fp,"const TypePtr *c%d", i);
340 i++;
341 }
342 else if (!strcmp(comp->base_type(globals), "ConNKlass")) {
343 if (i > 0) fprintf(fp,", ");
344 fprintf(fp,"const TypePtr *c%d", i);
345 i++;
346 }
347 else if (!strcmp(comp->base_type(globals), "ConL")) {
348 if (i > 0) fprintf(fp,", ");
349 fprintf(fp,"jlong c%d", i);
350 i++;
351 }
352 else if (!strcmp(comp->base_type(globals), "ConF")) {
353 if (i > 0) fprintf(fp,", ");
354 fprintf(fp,"jfloat c%d", i);
355 i++;
356 }
357 else if (!strcmp(comp->base_type(globals), "ConD")) {
358 if (i > 0) fprintf(fp,", ");
359 fprintf(fp,"jdouble c%d", i);
360 i++;
361 }
362 else if (!strcmp(comp->base_type(globals), "Bool")) {
363 if (i > 0) fprintf(fp,", ");
364 fprintf(fp,"BoolTest::mask c%d", i);
365 i++;
366 }
367 }
368 }
369 // finish line (1) and start line (2)
370 fprintf(fp,") : ");
371 // generate initializers for constants
372 i = 0;
373 fprintf(fp,"_c%d(c%d)", i, i);
374 for( i = 1; i < num_consts; ++i) {
375 fprintf(fp,", _c%d(c%d)", i, i);
376 }
377 // The body for the constructor is empty
378 fprintf(fp," {}\n");
379}
380
381// ---------------------------------------------------------------------------
382// Utilities to generate format rules for machine operands and instructions
383// ---------------------------------------------------------------------------
384
385// Generate the format rule for condition codes
386static void defineCCodeDump(OperandForm* oper, FILE *fp, int i) {
387 assert(oper != NULL, "what"){ if (!(oper != __null)) { fprintf(stderr, "assert fails %s %d: %s\n"
, "/home/daniel/Projects/java/jdk/src/hotspot/share/adlc/output_h.cpp"
, 387, "what"); abort(); }}
;
388 CondInterface* cond = oper->_interface->is_CondInterface();
389 fprintf(fp, " if( _c%d == BoolTest::eq ) st->print_raw(\"%s\");\n",i,cond->_equal_format);
390 fprintf(fp, " else if( _c%d == BoolTest::ne ) st->print_raw(\"%s\");\n",i,cond->_not_equal_format);
391 fprintf(fp, " else if( _c%d == BoolTest::le ) st->print_raw(\"%s\");\n",i,cond->_less_equal_format);
392 fprintf(fp, " else if( _c%d == BoolTest::ge ) st->print_raw(\"%s\");\n",i,cond->_greater_equal_format);
393 fprintf(fp, " else if( _c%d == BoolTest::lt ) st->print_raw(\"%s\");\n",i,cond->_less_format);
394 fprintf(fp, " else if( _c%d == BoolTest::gt ) st->print_raw(\"%s\");\n",i,cond->_greater_format);
395 fprintf(fp, " else if( _c%d == BoolTest::overflow ) st->print_raw(\"%s\");\n",i,cond->_overflow_format);
396 fprintf(fp, " else if( _c%d == BoolTest::no_overflow ) st->print_raw(\"%s\");\n",i,cond->_no_overflow_format);
397}
398
399// Output code that dumps constant values, increment "i" if type is constant
400static uintunsigned int dump_spec_constant(FILE *fp, const char *ideal_type, uintunsigned int i, OperandForm* oper) {
401 if (!strcmp(ideal_type, "ConI")) {
402 fprintf(fp," st->print(\"#%%d\", _c%d);\n", i);
403 fprintf(fp," st->print(\"/0x%%08x\", _c%d);\n", i);
404 ++i;
405 }
406 else if (!strcmp(ideal_type, "ConP")) {
407 fprintf(fp," _c%d->dump_on(st);\n", i);
408 ++i;
409 }
410 else if (!strcmp(ideal_type, "ConN")) {
411 fprintf(fp," _c%d->dump_on(st);\n", i);
412 ++i;
413 }
414 else if (!strcmp(ideal_type, "ConNKlass")) {
415 fprintf(fp," _c%d->dump_on(st);\n", i);
416 ++i;
417 }
418 else if (!strcmp(ideal_type, "ConL")) {
419 fprintf(fp," st->print(\"#\" INT64_FORMAT, (int64_t)_c%d);\n", i);
420 fprintf(fp," st->print(\"/\" PTR64_FORMAT, (uint64_t)_c%d);\n", i);
421 ++i;
422 }
423 else if (!strcmp(ideal_type, "ConF")) {
424 fprintf(fp," st->print(\"#%%f\", _c%d);\n", i);
425 fprintf(fp," jint _c%di = JavaValue(_c%d).get_jint();\n", i, i);
426 fprintf(fp," st->print(\"/0x%%x/\", _c%di);\n", i);
427 ++i;
428 }
429 else if (!strcmp(ideal_type, "ConD")) {
430 fprintf(fp," st->print(\"#%%f\", _c%d);\n", i);
431 fprintf(fp," jlong _c%dl = JavaValue(_c%d).get_jlong();\n", i, i);
432 fprintf(fp," st->print(\"/\" PTR64_FORMAT, (uint64_t)_c%dl);\n", i);
433 ++i;
434 }
435 else if (!strcmp(ideal_type, "Bool")) {
436 defineCCodeDump(oper, fp,i);
437 ++i;
438 }
439
440 return i;
441}
442
443// Generate the format rule for an operand
444void gen_oper_format(FILE *fp, FormDict &globals, OperandForm &oper, bool for_c_file = false) {
445 if (!for_c_file) {
446 // invoked after output #ifndef PRODUCT to ad_<arch>.hpp
447 // compile the bodies separately, to cut down on recompilations
448 fprintf(fp," virtual void int_format(PhaseRegAlloc *ra, const MachNode *node, outputStream *st) const;\n");
449 fprintf(fp," virtual void ext_format(PhaseRegAlloc *ra, const MachNode *node, int idx, outputStream *st) const;\n");
450 return;
451 }
452
453 // Local pointer indicates remaining part of format rule
454 int idx = 0; // position of operand in match rule
455
456 // Generate internal format function, used when stored locally
457 fprintf(fp, "\n#ifndef PRODUCT\n");
458 fprintf(fp,"void %sOper::int_format(PhaseRegAlloc *ra, const MachNode *node, outputStream *st) const {\n", oper._ident);
459 // Generate the user-defined portion of the format
460 if (oper._format) {
461 if ( oper._format->_strings.count() != 0 ) {
462 // No initialization code for int_format
463
464 // Build the format from the entries in strings and rep_vars
465 const char *string = NULL__null;
466 oper._format->_rep_vars.reset();
467 oper._format->_strings.reset();
468 while ( (string = oper._format->_strings.iter()) != NULL__null ) {
469
470 // Check if this is a standard string or a replacement variable
471 if ( string != NameList::_signal ) {
472 // Normal string
473 // Pass through to st->print
474 fprintf(fp," st->print_raw(\"%s\");\n", string);
475 } else {
476 // Replacement variable
477 const char *rep_var = oper._format->_rep_vars.iter();
478 // Check that it is a local name, and an operand
479 const Form* form = oper._localNames[rep_var];
480 if (form == NULL__null) {
481 globalAD->syntax_err(oper._linenum,
482 "\'%s\' not found in format for %s\n", rep_var, oper._ident);
483 assert(form, "replacement variable was not found in local names"){ if (!(form)) { fprintf(stderr, "assert fails %s %d: %s\n", "/home/daniel/Projects/java/jdk/src/hotspot/share/adlc/output_h.cpp"
, 483, "replacement variable was not found in local names"); abort
(); }}
;
484 }
485 OperandForm *op = form->is_operand();
486 // Get index if register or constant
487 if ( op->_matrule && op->_matrule->is_base_register(globals) ) {
488 idx = oper.register_position( globals, rep_var);
489 }
490 else if (op->_matrule && op->_matrule->is_base_constant(globals)) {
491 idx = oper.constant_position( globals, rep_var);
492 } else {
493 idx = 0;
494 }
495
496 // output invocation of "$..."s format function
497 if ( op != NULL__null ) op->int_format(fp, globals, idx);
498
499 if ( idx == -1 ) {
500 fprintf(stderrstderr,
501 "Using a name, %s, that isn't in match rule\n", rep_var);
502 assert( strcmp(op->_ident,"label")==0, "Unimplemented"){ if (!(strcmp(op->_ident,"label")==0)) { fprintf(stderr, "assert fails %s %d: %s\n"
, "/home/daniel/Projects/java/jdk/src/hotspot/share/adlc/output_h.cpp"
, 502, "Unimplemented"); abort(); }}
;
503 }
504 } // Done with a replacement variable
505 } // Done with all format strings
506 } else {
507 // Default formats for base operands (RegI, RegP, ConI, ConP, ...)
508 oper.int_format(fp, globals, 0);
509 }
510
511 } else { // oper._format == NULL
512 // Provide a few special case formats where the AD writer cannot.
513 if ( strcmp(oper._ident,"Universe")==0 ) {
514 fprintf(fp, " st->print(\"$$univ\");\n");
515 }
516 // labelOper::int_format is defined in ad_<...>.cpp
517 }
518 // ALWAYS! Provide a special case output for condition codes.
519 if( oper.is_ideal_bool() ) {
520 defineCCodeDump(&oper, fp,0);
521 }
522 fprintf(fp,"}\n");
523
524 // Generate external format function, when data is stored externally
525 fprintf(fp,"void %sOper::ext_format(PhaseRegAlloc *ra, const MachNode *node, int idx, outputStream *st) const {\n", oper._ident);
526 // Generate the user-defined portion of the format
527 if (oper._format) {
528 if ( oper._format->_strings.count() != 0 ) {
529
530 // Check for a replacement string "$..."
531 if ( oper._format->_rep_vars.count() != 0 ) {
532 // Initialization code for ext_format
533 }
534
535 // Build the format from the entries in strings and rep_vars
536 const char *string = NULL__null;
537 oper._format->_rep_vars.reset();
538 oper._format->_strings.reset();
539 while ( (string = oper._format->_strings.iter()) != NULL__null ) {
540
541 // Check if this is a standard string or a replacement variable
542 if ( string != NameList::_signal ) {
543 // Normal string
544 // Pass through to st->print
545 fprintf(fp," st->print_raw(\"%s\");\n", string);
546 } else {
547 // Replacement variable
548 const char *rep_var = oper._format->_rep_vars.iter();
549 // Check that it is a local name, and an operand
550 const Form* form = oper._localNames[rep_var];
551 if (form == NULL__null) {
552 globalAD->syntax_err(oper._linenum,
553 "\'%s\' not found in format for %s\n", rep_var, oper._ident);
554 assert(form, "replacement variable was not found in local names"){ if (!(form)) { fprintf(stderr, "assert fails %s %d: %s\n", "/home/daniel/Projects/java/jdk/src/hotspot/share/adlc/output_h.cpp"
, 554, "replacement variable was not found in local names"); abort
(); }}
;
555 }
556 OperandForm *op = form->is_operand();
557 // Get index if register or constant
558 if ( op->_matrule && op->_matrule->is_base_register(globals) ) {
559 idx = oper.register_position( globals, rep_var);
560 }
561 else if (op->_matrule && op->_matrule->is_base_constant(globals)) {
562 idx = oper.constant_position( globals, rep_var);
563 } else {
564 idx = 0;
565 }
566 // output invocation of "$..."s format function
567 if ( op != NULL__null ) op->ext_format(fp, globals, idx);
568
569 // Lookup the index position of the replacement variable
570 idx = oper._components.operand_position_format(rep_var, &oper);
571 if ( idx == -1 ) {
572 fprintf(stderrstderr,
573 "Using a name, %s, that isn't in match rule\n", rep_var);
574 assert( strcmp(op->_ident,"label")==0, "Unimplemented"){ if (!(strcmp(op->_ident,"label")==0)) { fprintf(stderr, "assert fails %s %d: %s\n"
, "/home/daniel/Projects/java/jdk/src/hotspot/share/adlc/output_h.cpp"
, 574, "Unimplemented"); abort(); }}
;
575 }
576 } // Done with a replacement variable
577 } // Done with all format strings
578
579 } else {
580 // Default formats for base operands (RegI, RegP, ConI, ConP, ...)
581 oper.ext_format(fp, globals, 0);
582 }
583 } else { // oper._format == NULL
584 // Provide a few special case formats where the AD writer cannot.
585 if ( strcmp(oper._ident,"Universe")==0 ) {
586 fprintf(fp, " st->print(\"$$univ\");\n");
587 }
588 // labelOper::ext_format is defined in ad_<...>.cpp
589 }
590 // ALWAYS! Provide a special case output for condition codes.
591 if( oper.is_ideal_bool() ) {
592 defineCCodeDump(&oper, fp,0);
593 }
594 fprintf(fp, "}\n");
595 fprintf(fp, "#endif\n");
596}
597
598
599// Generate the format rule for an instruction
600void gen_inst_format(FILE *fp, FormDict &globals, InstructForm &inst, bool for_c_file = false) {
601 if (!for_c_file) {
602 // compile the bodies separately, to cut down on recompilations
603 // #ifndef PRODUCT region generated by caller
604 fprintf(fp," virtual void format(PhaseRegAlloc *ra, outputStream *st) const;\n");
605 return;
606 }
607
608 // Define the format function
609 fprintf(fp, "#ifndef PRODUCT\n");
610 fprintf(fp, "void %sNode::format(PhaseRegAlloc *ra, outputStream *st) const {\n", inst._ident);
611
612 // Generate the user-defined portion of the format
613 if( inst._format ) {
614 // If there are replacement variables,
615 // Generate index values needed for determining the operand position
616 if( inst._format->_rep_vars.count() )
617 inst.index_temps(fp, globals);
618
619 // Build the format from the entries in strings and rep_vars
620 const char *string = NULL__null;
621 inst._format->_rep_vars.reset();
622 inst._format->_strings.reset();
623 while( (string = inst._format->_strings.iter()) != NULL__null ) {
624 fprintf(fp," ");
625 // Check if this is a standard string or a replacement variable
626 if( string == NameList::_signal ) { // Replacement variable
627 const char* rep_var = inst._format->_rep_vars.iter();
628 inst.rep_var_format( fp, rep_var);
629 } else if( string == NameList::_signal3 ) { // Replacement variable in raw text
630 const char* rep_var = inst._format->_rep_vars.iter();
631 const Form *form = inst._localNames[rep_var];
632 if (form == NULL__null) {
633 fprintf(stderrstderr, "unknown replacement variable in format statement: '%s'\n", rep_var);
634 assert(false, "ShouldNotReachHere()"){ if (!(false)) { fprintf(stderr, "assert fails %s %d: %s\n",
"/home/daniel/Projects/java/jdk/src/hotspot/share/adlc/output_h.cpp"
, 634, "ShouldNotReachHere()"); abort(); }}
;
635 }
636 OpClassForm *opc = form->is_opclass();
637 assert( opc, "replacement variable was not found in local names"){ if (!(opc)) { fprintf(stderr, "assert fails %s %d: %s\n", "/home/daniel/Projects/java/jdk/src/hotspot/share/adlc/output_h.cpp"
, 637, "replacement variable was not found in local names"); abort
(); }}
;
638 // Lookup the index position of the replacement variable
639 int idx = inst.operand_position_format(rep_var);
640 if ( idx == -1 ) {
641 assert( strcmp(opc->_ident,"label")==0, "Unimplemented"){ if (!(strcmp(opc->_ident,"label")==0)) { fprintf(stderr,
"assert fails %s %d: %s\n", "/home/daniel/Projects/java/jdk/src/hotspot/share/adlc/output_h.cpp"
, 641, "Unimplemented"); abort(); }}
;
642 assert( false, "ShouldNotReachHere()"){ if (!(false)) { fprintf(stderr, "assert fails %s %d: %s\n",
"/home/daniel/Projects/java/jdk/src/hotspot/share/adlc/output_h.cpp"
, 642, "ShouldNotReachHere()"); abort(); }}
;
643 }
644
645 if (inst.is_noninput_operand(idx)) {
646 assert( false, "ShouldNotReachHere()"){ if (!(false)) { fprintf(stderr, "assert fails %s %d: %s\n",
"/home/daniel/Projects/java/jdk/src/hotspot/share/adlc/output_h.cpp"
, 646, "ShouldNotReachHere()"); abort(); }}
;
647 } else {
648 // Output the format call for this operand
649 fprintf(fp,"opnd_array(%d)",idx);
650 }
651 rep_var = inst._format->_rep_vars.iter();
652 inst._format->_strings.iter();
653 if ( strcmp(rep_var,"$constant") == 0 && opc->is_operand()) {
654 Form::DataType constant_type = form->is_operand()->is_base_constant(globals);
655 if ( constant_type == Form::idealD ) {
656 fprintf(fp,"->constantD()");
657 } else if ( constant_type == Form::idealF ) {
658 fprintf(fp,"->constantF()");
659 } else if ( constant_type == Form::idealL ) {
660 fprintf(fp,"->constantL()");
661 } else {
662 fprintf(fp,"->constant()");
663 }
664 } else if ( strcmp(rep_var,"$cmpcode") == 0) {
665 fprintf(fp,"->ccode()");
666 } else {
667 assert( false, "ShouldNotReachHere()"){ if (!(false)) { fprintf(stderr, "assert fails %s %d: %s\n",
"/home/daniel/Projects/java/jdk/src/hotspot/share/adlc/output_h.cpp"
, 667, "ShouldNotReachHere()"); abort(); }}
;
668 }
669 } else if( string == NameList::_signal2 ) // Raw program text
670 fputs(inst._format->_strings.iter(), fp);
671 else
672 fprintf(fp,"st->print_raw(\"%s\");\n", string);
673 } // Done with all format strings
674 } // Done generating the user-defined portion of the format
675
676 // Add call debug info automatically
677 Form::CallType call_type = inst.is_ideal_call();
678 if( call_type != Form::invalid_type ) {
679 switch( call_type ) {
680 case Form::JAVA_DYNAMIC:
681 fprintf(fp," _method->print_short_name(st);\n");
682 break;
683 case Form::JAVA_STATIC:
684 fprintf(fp," if( _method ) _method->print_short_name(st);\n");
685 fprintf(fp," else st->print(\" wrapper for: %%s\", _name);\n");
686 fprintf(fp," if( !_method ) dump_trap_args(st);\n");
687 break;
688 case Form::JAVA_COMPILED:
689 case Form::JAVA_INTERP:
690 break;
691 case Form::JAVA_RUNTIME:
692 case Form::JAVA_LEAF:
693 case Form::JAVA_NATIVE:
694 fprintf(fp," st->print(\" %%s\", _name);");
695 break;
696 default:
697 assert(0,"ShouldNotReachHere"){ if (!(0)) { fprintf(stderr, "assert fails %s %d: %s\n", "/home/daniel/Projects/java/jdk/src/hotspot/share/adlc/output_h.cpp"
, 697, "ShouldNotReachHere"); abort(); }}
;
698 }
699 fprintf(fp, " st->cr();\n" );
700 fprintf(fp, " if (_jvms) _jvms->format(ra, this, st); else st->print_cr(\" No JVM State Info\");\n" );
701 fprintf(fp, " st->print(\" # \");\n" );
702 fprintf(fp, " if( _jvms && _oop_map ) _oop_map->print_on(st);\n");
703 }
704 else if(inst.is_ideal_safepoint()) {
705 fprintf(fp, " st->print_raw(\"\");\n" );
706 fprintf(fp, " if (_jvms) _jvms->format(ra, this, st); else st->print_cr(\" No JVM State Info\");\n" );
707 fprintf(fp, " st->print(\" # \");\n" );
708 fprintf(fp, " if( _jvms && _oop_map ) _oop_map->print_on(st);\n");
709 }
710 else if( inst.is_ideal_if() ) {
711 fprintf(fp, " st->print(\" P=%%f C=%%f\",_prob,_fcnt);\n" );
712 }
713 else if( inst.is_ideal_mem() ) {
714 // Print out the field name if available to improve readability
715 fprintf(fp, " if (ra->C->alias_type(adr_type())->field() != NULL) {\n");
716 fprintf(fp, " ciField* f = ra->C->alias_type(adr_type())->field();\n");
717 fprintf(fp, " st->print(\" %s Field: \");\n", commentSeperator"!");
718 fprintf(fp, " if (f->is_volatile())\n");
719 fprintf(fp, " st->print(\"volatile \");\n");
720 fprintf(fp, " f->holder()->name()->print_symbol_on(st);\n");
721 fprintf(fp, " st->print(\".\");\n");
722 fprintf(fp, " f->name()->print_symbol_on(st);\n");
723 fprintf(fp, " if (f->is_constant())\n");
724 fprintf(fp, " st->print(\" (constant)\");\n");
725 fprintf(fp, " } else {\n");
726 // Make sure 'Volatile' gets printed out
727 fprintf(fp, " if (ra->C->alias_type(adr_type())->is_volatile())\n");
728 fprintf(fp, " st->print(\" volatile!\");\n");
729 fprintf(fp, " }\n");
730 }
731
732 // Complete the definition of the format function
733 fprintf(fp, "}\n#endif\n");
734}
735
736void ArchDesc::declare_pipe_classes(FILE *fp_hpp) {
737 if (!_pipeline)
738 return;
739
740 fprintf(fp_hpp, "\n");
741 fprintf(fp_hpp, "// Pipeline_Use_Cycle_Mask Class\n");
742 fprintf(fp_hpp, "class Pipeline_Use_Cycle_Mask {\n");
743
744 if (_pipeline->_maxcycleused <= 32) {
745 fprintf(fp_hpp, "protected:\n");
746 fprintf(fp_hpp, " %s _mask;\n\n", _pipeline->_maxcycleused <= 32 ? "uint" : "uint64_t" );
747 fprintf(fp_hpp, "public:\n");
748 fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask() : _mask(0) {}\n\n");
749 if (_pipeline->_maxcycleused <= 32)
750 fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask(uint mask) : _mask(mask) {}\n\n");
751 else {
752 fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask(uint mask1, uint mask2) : _mask((((uint64_t)mask1) << 32) | mask2) {}\n\n");
753 fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask(uint64_t mask) : _mask(mask) {}\n\n");
754 }
755 fprintf(fp_hpp, " bool overlaps(const Pipeline_Use_Cycle_Mask &in2) const {\n");
756 fprintf(fp_hpp, " return ((_mask & in2._mask) != 0);\n");
757 fprintf(fp_hpp, " }\n\n");
758 fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask& operator<<=(int n) {\n");
759 fprintf(fp_hpp, " _mask <<= n;\n");
760 fprintf(fp_hpp, " return *this;\n");
761 fprintf(fp_hpp, " }\n\n");
762 fprintf(fp_hpp, " void Or(const Pipeline_Use_Cycle_Mask &in2) {\n");
763 fprintf(fp_hpp, " _mask |= in2._mask;\n");
764 fprintf(fp_hpp, " }\n\n");
765 fprintf(fp_hpp, " friend Pipeline_Use_Cycle_Mask operator&(const Pipeline_Use_Cycle_Mask &, const Pipeline_Use_Cycle_Mask &);\n");
766 fprintf(fp_hpp, " friend Pipeline_Use_Cycle_Mask operator|(const Pipeline_Use_Cycle_Mask &, const Pipeline_Use_Cycle_Mask &);\n\n");
767 }
768 else {
769 fprintf(fp_hpp, "protected:\n");
770 uintunsigned int masklen = (_pipeline->_maxcycleused + 31) >> 5;
771 uintunsigned int l;
772 fprintf(fp_hpp, " uint ");
773 for (l = 1; l <= masklen; l++)
774 fprintf(fp_hpp, "_mask%d%s", l, l < masklen ? ", " : ";\n\n");
775 fprintf(fp_hpp, "public:\n");
776 fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask() : ");
777 for (l = 1; l <= masklen; l++)
778 fprintf(fp_hpp, "_mask%d(0)%s", l, l < masklen ? ", " : " {}\n\n");
779 fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask(");
780 for (l = 1; l <= masklen; l++)
781 fprintf(fp_hpp, "uint mask%d%s", l, l < masklen ? ", " : ") : ");
782 for (l = 1; l <= masklen; l++)
783 fprintf(fp_hpp, "_mask%d(mask%d)%s", l, l, l < masklen ? ", " : " {}\n\n");
784
785 fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask intersect(const Pipeline_Use_Cycle_Mask &in2) {\n");
786 fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask out;\n");
787 for (l = 1; l <= masklen; l++)
788 fprintf(fp_hpp, " out._mask%d = _mask%d & in2._mask%d;\n", l, l, l);
789 fprintf(fp_hpp, " return out;\n");
790 fprintf(fp_hpp, " }\n\n");
791 fprintf(fp_hpp, " bool overlaps(const Pipeline_Use_Cycle_Mask &in2) const {\n");
792 fprintf(fp_hpp, " return (");
793 for (l = 1; l <= masklen; l++)
794 fprintf(fp_hpp, "((_mask%d & in2._mask%d) != 0)%s", l, l, l < masklen ? " || " : "");
795 fprintf(fp_hpp, ") ? true : false;\n");
796 fprintf(fp_hpp, " }\n\n");
797 fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask& operator<<=(int n) {\n");
798 fprintf(fp_hpp, " if (n >= 32)\n");
799 fprintf(fp_hpp, " do {\n ");
800 for (l = masklen; l > 1; l--)
801 fprintf(fp_hpp, " _mask%d = _mask%d;", l, l-1);
802 fprintf(fp_hpp, " _mask%d = 0;\n", 1);
803 fprintf(fp_hpp, " } while ((n -= 32) >= 32);\n\n");
804 fprintf(fp_hpp, " if (n > 0) {\n");
805 fprintf(fp_hpp, " uint m = 32 - n;\n");
806 fprintf(fp_hpp, " uint mask = (1 << n) - 1;\n");
807 fprintf(fp_hpp, " uint temp%d = mask & (_mask%d >> m); _mask%d <<= n;\n", 2, 1, 1);
808 for (l = 2; l < masklen; l++) {
809 fprintf(fp_hpp, " uint temp%d = mask & (_mask%d >> m); _mask%d <<= n; _mask%d |= temp%d;\n", l+1, l, l, l, l);
810 }
811 fprintf(fp_hpp, " _mask%d <<= n; _mask%d |= temp%d;\n", masklen, masklen, masklen);
812 fprintf(fp_hpp, " }\n");
813
814 fprintf(fp_hpp, " return *this;\n");
815 fprintf(fp_hpp, " }\n\n");
816 fprintf(fp_hpp, " void Or(const Pipeline_Use_Cycle_Mask &);\n\n");
817 fprintf(fp_hpp, " friend Pipeline_Use_Cycle_Mask operator&(const Pipeline_Use_Cycle_Mask &, const Pipeline_Use_Cycle_Mask &);\n");
818 fprintf(fp_hpp, " friend Pipeline_Use_Cycle_Mask operator|(const Pipeline_Use_Cycle_Mask &, const Pipeline_Use_Cycle_Mask &);\n\n");
819 }
820
821 fprintf(fp_hpp, " friend class Pipeline_Use;\n\n");
822 fprintf(fp_hpp, " friend class Pipeline_Use_Element;\n\n");
823 fprintf(fp_hpp, "};\n\n");
824
825 uintunsigned int rescount = 0;
826 const char *resource;
827
828 for ( _pipeline->_reslist.reset(); (resource = _pipeline->_reslist.iter()) != NULL__null; ) {
829 int mask = _pipeline->_resdict[resource]->is_resource()->mask();
830 if ((mask & (mask-1)) == 0)
831 rescount++;
832 }
833
834 fprintf(fp_hpp, "// Pipeline_Use_Element Class\n");
835 fprintf(fp_hpp, "class Pipeline_Use_Element {\n");
836 fprintf(fp_hpp, "protected:\n");
837 fprintf(fp_hpp, " // Mask of used functional units\n");
838 fprintf(fp_hpp, " uint _used;\n\n");
839 fprintf(fp_hpp, " // Lower and upper bound of functional unit number range\n");
840 fprintf(fp_hpp, " uint _lb, _ub;\n\n");
841 fprintf(fp_hpp, " // Indicates multiple functionals units available\n");
842 fprintf(fp_hpp, " bool _multiple;\n\n");
843 fprintf(fp_hpp, " // Mask of specific used cycles\n");
844 fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask _mask;\n\n");
845 fprintf(fp_hpp, "public:\n");
846 fprintf(fp_hpp, " Pipeline_Use_Element() {}\n\n");
847 fprintf(fp_hpp, " Pipeline_Use_Element(uint used, uint lb, uint ub, bool multiple, Pipeline_Use_Cycle_Mask mask)\n");
848 fprintf(fp_hpp, " : _used(used), _lb(lb), _ub(ub), _multiple(multiple), _mask(mask) {}\n\n");
849 fprintf(fp_hpp, " uint used() const { return _used; }\n\n");
850 fprintf(fp_hpp, " uint lowerBound() const { return _lb; }\n\n");
851 fprintf(fp_hpp, " uint upperBound() const { return _ub; }\n\n");
852 fprintf(fp_hpp, " bool multiple() const { return _multiple; }\n\n");
853 fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask mask() const { return _mask; }\n\n");
854 fprintf(fp_hpp, " bool overlaps(const Pipeline_Use_Element &in2) const {\n");
855 fprintf(fp_hpp, " return ((_used & in2._used) != 0 && _mask.overlaps(in2._mask));\n");
856 fprintf(fp_hpp, " }\n\n");
857 fprintf(fp_hpp, " void step(uint cycles) {\n");
858 fprintf(fp_hpp, " _used = 0;\n");
859 fprintf(fp_hpp, " _mask <<= cycles;\n");
860 fprintf(fp_hpp, " }\n\n");
861 fprintf(fp_hpp, " friend class Pipeline_Use;\n");
862 fprintf(fp_hpp, "};\n\n");
863
864 fprintf(fp_hpp, "// Pipeline_Use Class\n");
865 fprintf(fp_hpp, "class Pipeline_Use {\n");
866 fprintf(fp_hpp, "protected:\n");
867 fprintf(fp_hpp, " // These resources can be used\n");
868 fprintf(fp_hpp, " uint _resources_used;\n\n");
869 fprintf(fp_hpp, " // These resources are used; excludes multiple choice functional units\n");
870 fprintf(fp_hpp, " uint _resources_used_exclusively;\n\n");
871 fprintf(fp_hpp, " // Number of elements\n");
872 fprintf(fp_hpp, " uint _count;\n\n");
873 fprintf(fp_hpp, " // This is the array of Pipeline_Use_Elements\n");
874 fprintf(fp_hpp, " Pipeline_Use_Element * _elements;\n\n");
875 fprintf(fp_hpp, "public:\n");
876 fprintf(fp_hpp, " Pipeline_Use(uint resources_used, uint resources_used_exclusively, uint count, Pipeline_Use_Element *elements)\n");
877 fprintf(fp_hpp, " : _resources_used(resources_used)\n");
878 fprintf(fp_hpp, " , _resources_used_exclusively(resources_used_exclusively)\n");
879 fprintf(fp_hpp, " , _count(count)\n");
880 fprintf(fp_hpp, " , _elements(elements)\n");
881 fprintf(fp_hpp, " {}\n\n");
882 fprintf(fp_hpp, " uint resourcesUsed() const { return _resources_used; }\n\n");
883 fprintf(fp_hpp, " uint resourcesUsedExclusively() const { return _resources_used_exclusively; }\n\n");
884 fprintf(fp_hpp, " uint count() const { return _count; }\n\n");
885 fprintf(fp_hpp, " Pipeline_Use_Element * element(uint i) const { return &_elements[i]; }\n\n");
886 fprintf(fp_hpp, " uint full_latency(uint delay, const Pipeline_Use &pred) const;\n\n");
887 fprintf(fp_hpp, " void add_usage(const Pipeline_Use &pred);\n\n");
888 fprintf(fp_hpp, " void reset() {\n");
889 fprintf(fp_hpp, " _resources_used = _resources_used_exclusively = 0;\n");
890 fprintf(fp_hpp, " };\n\n");
891 fprintf(fp_hpp, " void step(uint cycles) {\n");
892 fprintf(fp_hpp, " reset();\n");
893 fprintf(fp_hpp, " for (uint i = 0; i < %d; i++)\n",
894 rescount);
895 fprintf(fp_hpp, " (&_elements[i])->step(cycles);\n");
896 fprintf(fp_hpp, " };\n\n");
897 fprintf(fp_hpp, " static const Pipeline_Use elaborated_use;\n");
898 fprintf(fp_hpp, " static const Pipeline_Use_Element elaborated_elements[%d];\n\n",
899 rescount);
900 fprintf(fp_hpp, " friend class Pipeline;\n");
901 fprintf(fp_hpp, "};\n\n");
902
903 fprintf(fp_hpp, "// Pipeline Class\n");
904 fprintf(fp_hpp, "class Pipeline {\n");
905 fprintf(fp_hpp, "public:\n");
906
907 fprintf(fp_hpp, " static bool enabled() { return %s; }\n\n",
908 _pipeline ? "true" : "false" );
909
910 assert( _pipeline->_maxInstrsPerBundle &&{ if (!(_pipeline->_maxInstrsPerBundle && ( _pipeline
->_instrUnitSize || _pipeline->_bundleUnitSize) &&
_pipeline->_instrFetchUnitSize && _pipeline->_instrFetchUnits
)) { fprintf(stderr, "assert fails %s %d: %s\n", "/home/daniel/Projects/java/jdk/src/hotspot/share/adlc/output_h.cpp"
, 914, "unspecified pipeline architecture units"); abort(); }
}
911 ( _pipeline->_instrUnitSize || _pipeline->_bundleUnitSize) &&{ if (!(_pipeline->_maxInstrsPerBundle && ( _pipeline
->_instrUnitSize || _pipeline->_bundleUnitSize) &&
_pipeline->_instrFetchUnitSize && _pipeline->_instrFetchUnits
)) { fprintf(stderr, "assert fails %s %d: %s\n", "/home/daniel/Projects/java/jdk/src/hotspot/share/adlc/output_h.cpp"
, 914, "unspecified pipeline architecture units"); abort(); }
}
912 _pipeline->_instrFetchUnitSize &&{ if (!(_pipeline->_maxInstrsPerBundle && ( _pipeline
->_instrUnitSize || _pipeline->_bundleUnitSize) &&
_pipeline->_instrFetchUnitSize && _pipeline->_instrFetchUnits
)) { fprintf(stderr, "assert fails %s %d: %s\n", "/home/daniel/Projects/java/jdk/src/hotspot/share/adlc/output_h.cpp"
, 914, "unspecified pipeline architecture units"); abort(); }
}
913 _pipeline->_instrFetchUnits,{ if (!(_pipeline->_maxInstrsPerBundle && ( _pipeline
->_instrUnitSize || _pipeline->_bundleUnitSize) &&
_pipeline->_instrFetchUnitSize && _pipeline->_instrFetchUnits
)) { fprintf(stderr, "assert fails %s %d: %s\n", "/home/daniel/Projects/java/jdk/src/hotspot/share/adlc/output_h.cpp"
, 914, "unspecified pipeline architecture units"); abort(); }
}
914 "unspecified pipeline architecture units"){ if (!(_pipeline->_maxInstrsPerBundle && ( _pipeline
->_instrUnitSize || _pipeline->_bundleUnitSize) &&
_pipeline->_instrFetchUnitSize && _pipeline->_instrFetchUnits
)) { fprintf(stderr, "assert fails %s %d: %s\n", "/home/daniel/Projects/java/jdk/src/hotspot/share/adlc/output_h.cpp"
, 914, "unspecified pipeline architecture units"); abort(); }
}
;
915
916 uintunsigned int unitSize = _pipeline->_instrUnitSize ? _pipeline->_instrUnitSize : _pipeline->_bundleUnitSize;
917
918 fprintf(fp_hpp, " enum {\n");
919 fprintf(fp_hpp, " _variable_size_instructions = %d,\n",
920 _pipeline->_variableSizeInstrs ? 1 : 0);
921 fprintf(fp_hpp, " _fixed_size_instructions = %d,\n",
922 _pipeline->_variableSizeInstrs ? 0 : 1);
923 fprintf(fp_hpp, " _branch_has_delay_slot = %d,\n",
924 _pipeline->_branchHasDelaySlot ? 1 : 0);
925 fprintf(fp_hpp, " _max_instrs_per_bundle = %d,\n",
926 _pipeline->_maxInstrsPerBundle);
927 fprintf(fp_hpp, " _max_bundles_per_cycle = %d,\n",
928 _pipeline->_maxBundlesPerCycle);
929 fprintf(fp_hpp, " _max_instrs_per_cycle = %d\n",
930 _pipeline->_maxBundlesPerCycle * _pipeline->_maxInstrsPerBundle);
931 fprintf(fp_hpp, " };\n\n");
932
933 fprintf(fp_hpp, " static bool instr_has_unit_size() { return %s; }\n\n",
934 _pipeline->_instrUnitSize != 0 ? "true" : "false" );
935 if( _pipeline->_bundleUnitSize != 0 )
936 if( _pipeline->_instrUnitSize != 0 )
937 fprintf(fp_hpp, "// Individual Instructions may be bundled together by the hardware\n\n");
938 else
939 fprintf(fp_hpp, "// Instructions exist only in bundles\n\n");
940 else
941 fprintf(fp_hpp, "// Bundling is not supported\n\n");
942 if( _pipeline->_instrUnitSize != 0 )
943 fprintf(fp_hpp, " // Size of an instruction\n");
944 else
945 fprintf(fp_hpp, " // Size of an individual instruction does not exist - unsupported\n");
946 fprintf(fp_hpp, " static uint instr_unit_size() {");
947 if( _pipeline->_instrUnitSize == 0 )
948 fprintf(fp_hpp, " assert( false, \"Instructions are only in bundles\" );");
949 fprintf(fp_hpp, " return %d; };\n\n", _pipeline->_instrUnitSize);
950
951 if( _pipeline->_bundleUnitSize != 0 )
952 fprintf(fp_hpp, " // Size of a bundle\n");
953 else
954 fprintf(fp_hpp, " // Bundles do not exist - unsupported\n");
955 fprintf(fp_hpp, " static uint bundle_unit_size() {");
956 if( _pipeline->_bundleUnitSize == 0 )
957 fprintf(fp_hpp, " assert( false, \"Bundles are not supported\" );");
958 fprintf(fp_hpp, " return %d; };\n\n", _pipeline->_bundleUnitSize);
959
960 fprintf(fp_hpp, " static bool requires_bundling() { return %s; }\n\n",
961 _pipeline->_bundleUnitSize != 0 && _pipeline->_instrUnitSize == 0 ? "true" : "false" );
962
963 fprintf(fp_hpp, "private:\n");
964 fprintf(fp_hpp, " Pipeline(); // Not a legal constructor\n");
965 fprintf(fp_hpp, "\n");
966 fprintf(fp_hpp, " const unsigned char _read_stage_count;\n");
967 fprintf(fp_hpp, " const unsigned char _write_stage;\n");
968 fprintf(fp_hpp, " const unsigned char _fixed_latency;\n");
969 fprintf(fp_hpp, " const unsigned char _instruction_count;\n");
970 fprintf(fp_hpp, " const bool _has_fixed_latency;\n");
971 fprintf(fp_hpp, " const bool _has_branch_delay;\n");
972 fprintf(fp_hpp, " const bool _has_multiple_bundles;\n");
973 fprintf(fp_hpp, " const bool _force_serialization;\n");
974 fprintf(fp_hpp, " const bool _may_have_no_code;\n");
975 fprintf(fp_hpp, " const enum machPipelineStages * const _read_stages;\n");
976 fprintf(fp_hpp, " const enum machPipelineStages * const _resource_stage;\n");
977 fprintf(fp_hpp, " const uint * const _resource_cycles;\n");
978 fprintf(fp_hpp, " const Pipeline_Use _resource_use;\n");
979 fprintf(fp_hpp, "\n");
980 fprintf(fp_hpp, "public:\n");
981 fprintf(fp_hpp, " Pipeline(uint write_stage,\n");
982 fprintf(fp_hpp, " uint count,\n");
983 fprintf(fp_hpp, " bool has_fixed_latency,\n");
984 fprintf(fp_hpp, " uint fixed_latency,\n");
985 fprintf(fp_hpp, " uint instruction_count,\n");
986 fprintf(fp_hpp, " bool has_branch_delay,\n");
987 fprintf(fp_hpp, " bool has_multiple_bundles,\n");
988 fprintf(fp_hpp, " bool force_serialization,\n");
989 fprintf(fp_hpp, " bool may_have_no_code,\n");
990 fprintf(fp_hpp, " enum machPipelineStages * const dst,\n");
991 fprintf(fp_hpp, " enum machPipelineStages * const stage,\n");
992 fprintf(fp_hpp, " uint * const cycles,\n");
993 fprintf(fp_hpp, " Pipeline_Use resource_use)\n");
994 fprintf(fp_hpp, " : _read_stage_count(count)\n");
995 fprintf(fp_hpp, " , _write_stage(write_stage)\n");
996 fprintf(fp_hpp, " , _fixed_latency(fixed_latency)\n");
997 fprintf(fp_hpp, " , _instruction_count(instruction_count)\n");
998 fprintf(fp_hpp, " , _has_fixed_latency(has_fixed_latency)\n");
999 fprintf(fp_hpp, " , _has_branch_delay(has_branch_delay)\n");
1000 fprintf(fp_hpp, " , _has_multiple_bundles(has_multiple_bundles)\n");
1001 fprintf(fp_hpp, " , _force_serialization(force_serialization)\n");
1002 fprintf(fp_hpp, " , _may_have_no_code(may_have_no_code)\n");
1003 fprintf(fp_hpp, " , _read_stages(dst)\n");
1004 fprintf(fp_hpp, " , _resource_stage(stage)\n");
1005 fprintf(fp_hpp, " , _resource_cycles(cycles)\n");
1006 fprintf(fp_hpp, " , _resource_use(resource_use)\n");
1007 fprintf(fp_hpp, " {};\n");
1008 fprintf(fp_hpp, "\n");
1009 fprintf(fp_hpp, " uint writeStage() const {\n");
1010 fprintf(fp_hpp, " return (_write_stage);\n");
1011 fprintf(fp_hpp, " }\n");
1012 fprintf(fp_hpp, "\n");
1013 fprintf(fp_hpp, " enum machPipelineStages readStage(int ndx) const {\n");
1014 fprintf(fp_hpp, " return (ndx < _read_stage_count ? _read_stages[ndx] : stage_undefined);");
1015 fprintf(fp_hpp, " }\n\n");
1016 fprintf(fp_hpp, " uint resourcesUsed() const {\n");
1017 fprintf(fp_hpp, " return _resource_use.resourcesUsed();\n }\n\n");
1018 fprintf(fp_hpp, " uint resourcesUsedExclusively() const {\n");
1019 fprintf(fp_hpp, " return _resource_use.resourcesUsedExclusively();\n }\n\n");
1020 fprintf(fp_hpp, " bool hasFixedLatency() const {\n");
1021 fprintf(fp_hpp, " return (_has_fixed_latency);\n }\n\n");
1022 fprintf(fp_hpp, " uint fixedLatency() const {\n");
1023 fprintf(fp_hpp, " return (_fixed_latency);\n }\n\n");
1024 fprintf(fp_hpp, " uint functional_unit_latency(uint start, const Pipeline *pred) const;\n\n");
1025 fprintf(fp_hpp, " uint operand_latency(uint opnd, const Pipeline *pred) const;\n\n");
1026 fprintf(fp_hpp, " const Pipeline_Use& resourceUse() const {\n");
1027 fprintf(fp_hpp, " return (_resource_use); }\n\n");
1028 fprintf(fp_hpp, " const Pipeline_Use_Element * resourceUseElement(uint i) const {\n");
1029 fprintf(fp_hpp, " return (&_resource_use._elements[i]); }\n\n");
1030 fprintf(fp_hpp, " uint resourceUseCount() const {\n");
1031 fprintf(fp_hpp, " return (_resource_use._count); }\n\n");
1032 fprintf(fp_hpp, " uint instructionCount() const {\n");
1033 fprintf(fp_hpp, " return (_instruction_count); }\n\n");
1034 fprintf(fp_hpp, " bool hasBranchDelay() const {\n");
1035 fprintf(fp_hpp, " return (_has_branch_delay); }\n\n");
1036 fprintf(fp_hpp, " bool hasMultipleBundles() const {\n");
1037 fprintf(fp_hpp, " return (_has_multiple_bundles); }\n\n");
1038 fprintf(fp_hpp, " bool forceSerialization() const {\n");
1039 fprintf(fp_hpp, " return (_force_serialization); }\n\n");
1040 fprintf(fp_hpp, " bool mayHaveNoCode() const {\n");
1041 fprintf(fp_hpp, " return (_may_have_no_code); }\n\n");
1042 fprintf(fp_hpp, "//const Pipeline_Use_Cycle_Mask& resourceUseMask(int resource) const {\n");
1043 fprintf(fp_hpp, "// return (_resource_use_masks[resource]); }\n\n");
1044 fprintf(fp_hpp, "\n#ifndef PRODUCT\n");
1045 fprintf(fp_hpp, " static const char * stageName(uint i);\n");
1046 fprintf(fp_hpp, "#endif\n");
1047 fprintf(fp_hpp, "};\n\n");
1048
1049 fprintf(fp_hpp, "// Bundle class\n");
1050 fprintf(fp_hpp, "class Bundle {\n");
1051
1052 uintunsigned int mshift = 0;
1053 for (uintunsigned int msize = _pipeline->_maxInstrsPerBundle * _pipeline->_maxBundlesPerCycle; msize != 0; msize >>= 1)
1054 mshift++;
1055
1056 uintunsigned int rshift = rescount;
1057
1058 fprintf(fp_hpp, "protected:\n");
1059 fprintf(fp_hpp, " enum {\n");
1060 fprintf(fp_hpp, " _unused_delay = 0x%x,\n", 0);
1061 fprintf(fp_hpp, " _use_nop_delay = 0x%x,\n", 1);
1062 fprintf(fp_hpp, " _use_unconditional_delay = 0x%x,\n", 2);
1063 fprintf(fp_hpp, " _use_conditional_delay = 0x%x,\n", 3);
1064 fprintf(fp_hpp, " _used_in_conditional_delay = 0x%x,\n", 4);
1065 fprintf(fp_hpp, " _used_in_unconditional_delay = 0x%x,\n", 5);
1066 fprintf(fp_hpp, " _used_in_all_conditional_delays = 0x%x,\n", 6);
1067 fprintf(fp_hpp, "\n");
1068 fprintf(fp_hpp, " _use_delay = 0x%x,\n", 3);
1069 fprintf(fp_hpp, " _used_in_delay = 0x%x\n", 4);
1070 fprintf(fp_hpp, " };\n\n");
1071 fprintf(fp_hpp, " uint _flags : 3,\n");
1072 fprintf(fp_hpp, " _starts_bundle : 1,\n");
1073 fprintf(fp_hpp, " _instr_count : %d,\n", mshift);
1074 fprintf(fp_hpp, " _resources_used : %d;\n", rshift);
1075 fprintf(fp_hpp, "public:\n");
1076 fprintf(fp_hpp, " Bundle() : _flags(_unused_delay), _starts_bundle(0), _instr_count(0), _resources_used(0) {}\n\n");
1077 fprintf(fp_hpp, " void set_instr_count(uint i) { _instr_count = i; }\n");
1078 fprintf(fp_hpp, " void set_resources_used(uint i) { _resources_used = i; }\n");
1079 fprintf(fp_hpp, " void clear_usage() { _flags = _unused_delay; }\n");
1080 fprintf(fp_hpp, " void set_starts_bundle() { _starts_bundle = true; }\n");
1081
1082 fprintf(fp_hpp, " uint flags() const { return (_flags); }\n");
1083 fprintf(fp_hpp, " uint instr_count() const { return (_instr_count); }\n");
1084 fprintf(fp_hpp, " uint resources_used() const { return (_resources_used); }\n");
1085 fprintf(fp_hpp, " bool starts_bundle() const { return (_starts_bundle != 0); }\n");
1086
1087 fprintf(fp_hpp, " void set_use_nop_delay() { _flags = _use_nop_delay; }\n");
1088 fprintf(fp_hpp, " void set_use_unconditional_delay() { _flags = _use_unconditional_delay; }\n");
1089 fprintf(fp_hpp, " void set_use_conditional_delay() { _flags = _use_conditional_delay; }\n");
1090 fprintf(fp_hpp, " void set_used_in_unconditional_delay() { _flags = _used_in_unconditional_delay; }\n");
1091 fprintf(fp_hpp, " void set_used_in_conditional_delay() { _flags = _used_in_conditional_delay; }\n");
1092 fprintf(fp_hpp, " void set_used_in_all_conditional_delays() { _flags = _used_in_all_conditional_delays; }\n");
1093
1094 fprintf(fp_hpp, " bool use_nop_delay() { return (_flags == _use_nop_delay); }\n");
1095 fprintf(fp_hpp, " bool use_unconditional_delay() { return (_flags == _use_unconditional_delay); }\n");
1096 fprintf(fp_hpp, " bool use_conditional_delay() { return (_flags == _use_conditional_delay); }\n");
1097 fprintf(fp_hpp, " bool used_in_unconditional_delay() { return (_flags == _used_in_unconditional_delay); }\n");
1098 fprintf(fp_hpp, " bool used_in_conditional_delay() { return (_flags == _used_in_conditional_delay); }\n");
1099 fprintf(fp_hpp, " bool used_in_all_conditional_delays() { return (_flags == _used_in_all_conditional_delays); }\n");
1100 fprintf(fp_hpp, " bool use_delay() { return ((_flags & _use_delay) != 0); }\n");
1101 fprintf(fp_hpp, " bool used_in_delay() { return ((_flags & _used_in_delay) != 0); }\n\n");
1102
1103 fprintf(fp_hpp, " enum {\n");
1104 fprintf(fp_hpp, " _nop_count = %d\n",
1105 _pipeline->_nopcnt);
1106 fprintf(fp_hpp, " };\n\n");
1107 fprintf(fp_hpp, " static void initialize_nops(MachNode *nop_list[%d]);\n\n",
1108 _pipeline->_nopcnt);
1109 fprintf(fp_hpp, "#ifndef PRODUCT\n");
1110 fprintf(fp_hpp, " void dump(outputStream *st = tty) const;\n");
1111 fprintf(fp_hpp, "#endif\n");
1112 fprintf(fp_hpp, "};\n\n");
1113
1114// const char *classname;
1115// for (_pipeline->_classlist.reset(); (classname = _pipeline->_classlist.iter()) != NULL; ) {
1116// PipeClassForm *pipeclass = _pipeline->_classdict[classname]->is_pipeclass();
1117// fprintf(fp_hpp, "// Pipeline Class Instance for \"%s\"\n", classname);
1118// }
1119}
1120
1121//------------------------------declareClasses---------------------------------
1122// Construct the class hierarchy of MachNode classes from the instruction &
1123// operand lists
1124void ArchDesc::declareClasses(FILE *fp) {
1125
1126 // Declare an array containing the machine register names, strings.
1127 declareRegNames(fp, _register);
1128
1129 // Declare an array containing the machine register encoding values
1130 declareRegEncodes(fp, _register);
1131
1132 // Generate declarations for the total number of operands
1133 fprintf(fp,"\n");
1134 fprintf(fp,"// Total number of operands defined in architecture definition\n");
1135 int num_operands = 0;
1136 OperandForm *op;
1137 for (_operands.reset(); (op = (OperandForm*)_operands.iter()) != NULL__null; ) {
1138 // Ensure this is a machine-world instruction
1139 if (op->ideal_only()) continue;
1140
1141 ++num_operands;
1142 }
1143 int first_operand_class = num_operands;
1144 OpClassForm *opc;
1145 for (_opclass.reset(); (opc = (OpClassForm*)_opclass.iter()) != NULL__null; ) {
1146 // Ensure this is a machine-world instruction
1147 if (opc->ideal_only()) continue;
1148
1149 ++num_operands;
1150 }
1151 fprintf(fp,"#define FIRST_OPERAND_CLASS %d\n", first_operand_class);
1152 fprintf(fp,"#define NUM_OPERANDS %d\n", num_operands);
1153 fprintf(fp,"\n");
1154 // Generate declarations for the total number of instructions
1155 fprintf(fp,"// Total number of instructions defined in architecture definition\n");
1156 fprintf(fp,"#define NUM_INSTRUCTIONS %d\n",instructFormCount());
1157
1158
1159 // Generate Machine Classes for each operand defined in AD file
1160 fprintf(fp,"\n");
1161 fprintf(fp,"//----------------------------Declare classes derived from MachOper----------\n");
1162 // Iterate through all operands
1163 _operands.reset();
1164 OperandForm *oper;
1165 for( ; (oper = (OperandForm*)_operands.iter()) != NULL__null;) {
1166 // Ensure this is a machine-world instruction
1167 if (oper->ideal_only() ) continue;
1168 // The declaration of labelOper is in machine-independent file: machnode
1169 if ( strcmp(oper->_ident,"label") == 0 ) continue;
1170 // The declaration of methodOper is in machine-independent file: machnode
1171 if ( strcmp(oper->_ident,"method") == 0 ) continue;
1172
1173 // Build class definition for this operand
1174 fprintf(fp,"\n");
1175 fprintf(fp,"class %sOper : public MachOper { \n",oper->_ident);
1176 fprintf(fp,"private:\n");
1177 // Operand definitions that depend upon number of input edges
1178 {
1179 uintunsigned int num_edges = oper->num_edges(_globalNames);
1180 if( num_edges != 1 ) { // Use MachOper::num_edges() {return 1;}
1181 fprintf(fp," virtual uint num_edges() const { return %d; }\n",
1182 num_edges );
1183 }
1184 if( num_edges > 0 ) {
1185 in_RegMask(fp);
1186 }
1187 }
1188
1189 // Support storing constants inside the MachOper
1190 declareConstStorage(fp,_globalNames,oper);
1191
1192 // Support storage of the condition codes
1193 if( oper->is_ideal_bool() ) {
1194 fprintf(fp," virtual int ccode() const { \n");
1195 fprintf(fp," switch (_c0) {\n");
1196 fprintf(fp," case BoolTest::eq : return equal();\n");
1197 fprintf(fp," case BoolTest::gt : return greater();\n");
1198 fprintf(fp," case BoolTest::lt : return less();\n");
1199 fprintf(fp," case BoolTest::ne : return not_equal();\n");
1200 fprintf(fp," case BoolTest::le : return less_equal();\n");
1201 fprintf(fp," case BoolTest::ge : return greater_equal();\n");
1202 fprintf(fp," case BoolTest::overflow : return overflow();\n");
1203 fprintf(fp," case BoolTest::no_overflow: return no_overflow();\n");
1204 fprintf(fp," default : ShouldNotReachHere(); return 0;\n");
1205 fprintf(fp," }\n");
1206 fprintf(fp," };\n");
1207 }
1208
1209 // Support storage of the condition codes
1210 if( oper->is_ideal_bool() ) {
1211 fprintf(fp," virtual void negate() { \n");
1212 fprintf(fp," _c0 = (BoolTest::mask)((int)_c0^0x4); \n");
1213 fprintf(fp," };\n");
1214 }
1215
1216 // Declare constructor.
1217 // Parameters start with condition code, then all other constants
1218 //
1219 // (1) MachXOper(int32 ccode, int32 c0, int32 c1, ..., int32 cn)
1220 // (2) : _ccode(ccode), _c0(c0), _c1(c1), ..., _cn(cn) { }
1221 //
1222 Form::DataType constant_type = oper->simple_type(_globalNames);
1223 defineConstructor(fp, oper->_ident, oper->num_consts(_globalNames),
1224 oper->_components, oper->is_ideal_bool(),
1225 constant_type, _globalNames);
1226
1227 // Clone function
1228 fprintf(fp," virtual MachOper *clone() const;\n");
1229
1230 // Support setting a spill offset into a constant operand.
1231 // We only support setting an 'int' offset, while in the
1232 // LP64 build spill offsets are added with an AddP which
1233 // requires a long constant. Thus we don't support spilling
1234 // in frames larger than 4Gig.
1235 if( oper->has_conI(_globalNames) ||
1236 oper->has_conL(_globalNames) )
1237 fprintf(fp, " virtual void set_con( jint c0 ) { _c0 = c0; }\n");
1238
1239 // virtual functions for encoding and format
1240 // fprintf(fp," virtual void encode() const {\n %s }\n",
1241 // (oper->_encrule)?(oper->_encrule->_encrule):"");
1242 // Check the interface type, and generate the correct query functions
1243 // encoding queries based upon MEMORY_INTER, REG_INTER, CONST_INTER.
1244
1245 fprintf(fp," virtual uint opcode() const { return %s; }\n",
1246 machOperEnum(oper->_ident));
1247
1248 // virtual function to look up ideal return type of machine instruction
1249 //
1250 // (1) virtual const Type *type() const { return .....; }
1251 //
1252 if ((oper->_matrule) && (oper->_matrule->_lChild == NULL__null) &&
1253 (oper->_matrule->_rChild == NULL__null)) {
1254 unsigned int position = 0;
1255 const char *opret, *opname, *optype;
1256 oper->_matrule->base_operand(position,_globalNames,opret,opname,optype);
1257 fprintf(fp," virtual const Type *type() const {");
1258 const char *type = getIdealType(optype);
1259 if( type != NULL__null ) {
1260 Form::DataType data_type = oper->is_base_constant(_globalNames);
1261 // Check if we are an ideal pointer type
1262 if( data_type == Form::idealP || data_type == Form::idealN || data_type == Form::idealNKlass ) {
1263 // Return the ideal type we already have: <TypePtr *>
1264 fprintf(fp," return _c0;");
1265 } else {
1266 // Return the appropriate bottom type
1267 fprintf(fp," return %s;", getIdealType(optype));
1268 }
1269 } else {
1270 fprintf(fp," ShouldNotCallThis(); return Type::BOTTOM;");
1271 }
1272 fprintf(fp," }\n");
1273 } else {
1274 // Check for user-defined stack slots, based upon sRegX
1275 Form::DataType data_type = oper->is_user_name_for_sReg();
1276 if( data_type != Form::none ){
1277 const char *type = NULL__null;
1278 switch( data_type ) {
1279 case Form::idealI: type = "TypeInt::INT"; break;
1280 case Form::idealP: type = "TypePtr::BOTTOM";break;
1281 case Form::idealF: type = "Type::FLOAT"; break;
1282 case Form::idealD: type = "Type::DOUBLE"; break;
1283 case Form::idealL: type = "TypeLong::LONG"; break;
1284 case Form::none: // fall through
1285 default:
1286 assert( false, "No support for this type of stackSlot"){ if (!(false)) { fprintf(stderr, "assert fails %s %d: %s\n",
"/home/daniel/Projects/java/jdk/src/hotspot/share/adlc/output_h.cpp"
, 1286, "No support for this type of stackSlot"); abort(); }}
;
1287 }
1288 fprintf(fp," virtual const Type *type() const { return %s; } // stackSlotX\n", type);
1289 }
1290 }
1291
1292
1293 //
1294 // virtual functions for defining the encoding interface.
1295 //
1296 // Access the linearized ideal register mask,
1297 // map to physical register encoding
1298 if ( oper->_matrule && oper->_matrule->is_base_register(_globalNames) ) {
1299 // Just use the default virtual 'reg' call
1300 } else if ( oper->ideal_to_sReg_type(oper->_ident) != Form::none ) {
1301 // Special handling for operand 'sReg', a Stack Slot Register.
1302 // Map linearized ideal register mask to stack slot number
1303 fprintf(fp," virtual int reg(PhaseRegAlloc *ra_, const Node *node) const {\n");
1304 fprintf(fp," return (int)OptoReg::reg2stack(ra_->get_reg_first(node));/* sReg */\n");
1305 fprintf(fp," }\n");
1306 fprintf(fp," virtual int reg(PhaseRegAlloc *ra_, const Node *node, int idx) const {\n");
1307 fprintf(fp," return (int)OptoReg::reg2stack(ra_->get_reg_first(node->in(idx)));/* sReg */\n");
1308 fprintf(fp," }\n");
1309 }
1310
1311 // Output the operand specific access functions used by an enc_class
1312 // These are only defined when we want to override the default virtual func
1313 if (oper->_interface != NULL__null) {
1314 fprintf(fp,"\n");
1315 // Check if it is a Memory Interface
1316 if ( oper->_interface->is_MemInterface() != NULL__null ) {
1317 MemInterface *mem_interface = oper->_interface->is_MemInterface();
1318 const char *base = mem_interface->_base;
1319 if( base != NULL__null ) {
1320 define_oper_interface(fp, *oper, _globalNames, "base", base);
1321 }
1322 char *index = mem_interface->_index;
1323 if( index != NULL__null ) {
1324 define_oper_interface(fp, *oper, _globalNames, "index", index);
1325 }
1326 const char *scale = mem_interface->_scale;
1327 if( scale != NULL__null ) {
1328 define_oper_interface(fp, *oper, _globalNames, "scale", scale);
1329 }
1330 const char *disp = mem_interface->_disp;
1331 if( disp != NULL__null ) {
1332 define_oper_interface(fp, *oper, _globalNames, "disp", disp);
1333 oper->disp_is_oop(fp, _globalNames);
1334 }
1335 if( oper->stack_slots_only(_globalNames) ) {
1336 // should not call this:
1337 fprintf(fp," virtual int constant_disp() const { return Type::OffsetBot; }");
1338 } else if ( disp != NULL__null ) {
1339 define_oper_interface(fp, *oper, _globalNames, "constant_disp", disp);
1340 }
1341 } // end Memory Interface
1342 // Check if it is a Conditional Interface
1343 else if (oper->_interface->is_CondInterface() != NULL__null) {
1344 CondInterface *cInterface = oper->_interface->is_CondInterface();
1345 const char *equal = cInterface->_equal;
1346 if( equal != NULL__null ) {
1347 define_oper_interface(fp, *oper, _globalNames, "equal", equal);
1348 }
1349 const char *not_equal = cInterface->_not_equal;
1350 if( not_equal != NULL__null ) {
1351 define_oper_interface(fp, *oper, _globalNames, "not_equal", not_equal);
1352 }
1353 const char *less = cInterface->_less;
1354 if( less != NULL__null ) {
1355 define_oper_interface(fp, *oper, _globalNames, "less", less);
1356 }
1357 const char *greater_equal = cInterface->_greater_equal;
1358 if( greater_equal != NULL__null ) {
1359 define_oper_interface(fp, *oper, _globalNames, "greater_equal", greater_equal);
1360 }
1361 const char *less_equal = cInterface->_less_equal;
1362 if( less_equal != NULL__null ) {
1363 define_oper_interface(fp, *oper, _globalNames, "less_equal", less_equal);
1364 }
1365 const char *greater = cInterface->_greater;
1366 if( greater != NULL__null ) {
1367 define_oper_interface(fp, *oper, _globalNames, "greater", greater);
1368 }
1369 const char *overflow = cInterface->_overflow;
1370 if( overflow != NULL__null ) {
1371 define_oper_interface(fp, *oper, _globalNames, "overflow", overflow);
1372 }
1373 const char *no_overflow = cInterface->_no_overflow;
1374 if( no_overflow != NULL__null ) {
1375 define_oper_interface(fp, *oper, _globalNames, "no_overflow", no_overflow);
1376 }
1377 } // end Conditional Interface
1378 // Check if it is a Constant Interface
1379 else if (oper->_interface->is_ConstInterface() != NULL__null ) {
1380 assert( oper->num_consts(_globalNames) == 1,{ if (!(oper->num_consts(_globalNames) == 1)) { fprintf(stderr
, "assert fails %s %d: %s\n", "/home/daniel/Projects/java/jdk/src/hotspot/share/adlc/output_h.cpp"
, 1381, "Must have one constant when using CONST_INTER encoding"
); abort(); }}
1381 "Must have one constant when using CONST_INTER encoding"){ if (!(oper->num_consts(_globalNames) == 1)) { fprintf(stderr
, "assert fails %s %d: %s\n", "/home/daniel/Projects/java/jdk/src/hotspot/share/adlc/output_h.cpp"
, 1381, "Must have one constant when using CONST_INTER encoding"
); abort(); }}
;
1382 if (!strcmp(oper->ideal_type(_globalNames), "ConI")) {
1383 // Access the locally stored constant
1384 fprintf(fp," virtual intptr_t constant() const {");
1385 fprintf(fp, " return (intptr_t)_c0;");
1386 fprintf(fp," }\n");
1387 }
1388 else if (!strcmp(oper->ideal_type(_globalNames), "ConP")) {
1389 // Access the locally stored constant
1390 fprintf(fp," virtual intptr_t constant() const {");
1391 fprintf(fp, " return _c0->get_con();");
1392 fprintf(fp, " }\n");
1393 // Generate query to determine if this pointer is an oop
1394 fprintf(fp," virtual relocInfo::relocType constant_reloc() const {");
1395 fprintf(fp, " return _c0->reloc();");
1396 fprintf(fp, " }\n");
1397 }
1398 else if (!strcmp(oper->ideal_type(_globalNames), "ConN")) {
1399 // Access the locally stored constant
1400 fprintf(fp," virtual intptr_t constant() const {");
1401 fprintf(fp, " return _c0->get_ptrtype()->get_con();");
1402 fprintf(fp, " }\n");
1403 // Generate query to determine if this pointer is an oop
1404 fprintf(fp," virtual relocInfo::relocType constant_reloc() const {");
1405 fprintf(fp, " return _c0->get_ptrtype()->reloc();");
1406 fprintf(fp, " }\n");
1407 }
1408 else if (!strcmp(oper->ideal_type(_globalNames), "ConNKlass")) {
1409 // Access the locally stored constant
1410 fprintf(fp," virtual intptr_t constant() const {");
1411 fprintf(fp, " return _c0->get_ptrtype()->get_con();");
1412 fprintf(fp, " }\n");
1413 // Generate query to determine if this pointer is an oop
1414 fprintf(fp," virtual relocInfo::relocType constant_reloc() const {");
1415 fprintf(fp, " return _c0->get_ptrtype()->reloc();");
1416 fprintf(fp, " }\n");
1417 }
1418 else if (!strcmp(oper->ideal_type(_globalNames), "ConL")) {
1419 fprintf(fp," virtual intptr_t constant() const {");
1420 // We don't support addressing modes with > 4Gig offsets.
1421 // Truncate to int.
1422 fprintf(fp, " return (intptr_t)_c0;");
1423 fprintf(fp, " }\n");
1424 fprintf(fp," virtual jlong constantL() const {");
1425 fprintf(fp, " return _c0;");
1426 fprintf(fp, " }\n");
1427 }
1428 else if (!strcmp(oper->ideal_type(_globalNames), "ConF")) {
1429 fprintf(fp," virtual intptr_t constant() const {");
1430 fprintf(fp, " ShouldNotReachHere(); return 0; ");
1431 fprintf(fp, " }\n");
1432 fprintf(fp," virtual jfloat constantF() const {");
1433 fprintf(fp, " return (jfloat)_c0;");
1434 fprintf(fp, " }\n");
1435 }
1436 else if (!strcmp(oper->ideal_type(_globalNames), "ConD")) {
1437 fprintf(fp," virtual intptr_t constant() const {");
1438 fprintf(fp, " ShouldNotReachHere(); return 0; ");
1439 fprintf(fp, " }\n");
1440 fprintf(fp," virtual jdouble constantD() const {");
1441 fprintf(fp, " return _c0;");
1442 fprintf(fp, " }\n");
1443 }
1444 }
1445 else if (oper->_interface->is_RegInterface() != NULL__null) {
1446 // make sure that a fixed format string isn't used for an
1447 // operand which might be assiged to multiple registers.
1448 // Otherwise the opto assembly output could be misleading.
1449 if (oper->_format->_strings.count() != 0 && !oper->is_bound_register()) {
1450 syntax_err(oper->_linenum,
1451 "Only bound registers can have fixed formats: %s\n",
1452 oper->_ident);
1453 }
1454 }
1455 else {
1456 assert( false, "ShouldNotReachHere();"){ if (!(false)) { fprintf(stderr, "assert fails %s %d: %s\n",
"/home/daniel/Projects/java/jdk/src/hotspot/share/adlc/output_h.cpp"
, 1456, "ShouldNotReachHere();"); abort(); }}
;
1457 }
1458 }
1459
1460 fprintf(fp,"\n");
1461 // // Currently all XXXOper::hash() methods are identical (990820)
1462 // declare_hash(fp);
1463 // // Currently all XXXOper::Cmp() methods are identical (990820)
1464 // declare_cmp(fp);
1465
1466 // Do not place dump_spec() and Name() into PRODUCT code
1467 // int_format and ext_format are not needed in PRODUCT code either
1468 fprintf(fp, "#ifndef PRODUCT\n");
1469
1470 // Declare int_format() and ext_format()
1471 gen_oper_format(fp, _globalNames, *oper);
1472
1473 // Machine independent print functionality for debugging
1474 // IF we have constants, create a dump_spec function for the derived class
1475 //
1476 // (1) virtual void dump_spec() const {
1477 // (2) st->print("#%d", _c#); // Constant != ConP
1478 // OR _c#->dump_on(st); // Type ConP
1479 // ...
1480 // (3) }
1481 uintunsigned int num_consts = oper->num_consts(_globalNames);
1482 if( num_consts > 0 ) {
1483 // line (1)
1484 fprintf(fp, " virtual void dump_spec(outputStream *st) const {\n");
1485 // generate format string for st->print
1486 // Iterate over the component list & spit out the right thing
1487 uintunsigned int i = 0;
1488 const char *type = oper->ideal_type(_globalNames);
1489 Component *comp;
1490 oper->_components.reset();
1491 if ((comp = oper->_components.iter()) == NULL__null) {
1492 assert(num_consts == 1, "Bad component list detected.\n"){ if (!(num_consts == 1)) { fprintf(stderr, "assert fails %s %d: %s\n"
, "/home/daniel/Projects/java/jdk/src/hotspot/share/adlc/output_h.cpp"
, 1492, "Bad component list detected.\n"); abort(); }}
;
1493 i = dump_spec_constant( fp, type, i, oper );
1494 // Check that type actually matched
1495 assert( i != 0, "Non-constant operand lacks component list."){ if (!(i != 0)) { fprintf(stderr, "assert fails %s %d: %s\n"
, "/home/daniel/Projects/java/jdk/src/hotspot/share/adlc/output_h.cpp"
, 1495, "Non-constant operand lacks component list."); abort(
); }}
;
1496 } // end if NULL
1497 else {
1498 // line (2)
1499 // dump all components
1500 oper->_components.reset();
1501 while((comp = oper->_components.iter()) != NULL__null) {
1502 type = comp->base_type(_globalNames);
1503 i = dump_spec_constant( fp, type, i, NULL__null );
1504 }
1505 }
1506 // finish line (3)
1507 fprintf(fp," }\n");
1508 }
1509
1510 fprintf(fp," virtual const char *Name() const { return \"%s\";}\n",
1511 oper->_ident);
1512
1513 fprintf(fp,"#endif\n");
1514
1515 // Close definition of this XxxMachOper
1516 fprintf(fp,"};\n");
1517 }
1518
1519
1520 // Generate Machine Classes for each instruction defined in AD file
1521 fprintf(fp,"\n");
1522 fprintf(fp,"//----------------------------Declare classes for Pipelines-----------------\n");
1523 declare_pipe_classes(fp);
1524
1525 // Generate Machine Classes for each instruction defined in AD file
1526 fprintf(fp,"\n");
1527 fprintf(fp,"//----------------------------Declare classes derived from MachNode----------\n");
1528 _instructions.reset();
1529 InstructForm *instr;
1530 for( ; (instr = (InstructForm*)_instructions.iter()) != NULL__null; ) {
1531 // Ensure this is a machine-world instruction
1532 if ( instr->ideal_only() ) continue;
1533
1534 // Build class definition for this instruction
1535 fprintf(fp,"\n");
1536 fprintf(fp,"class %sNode : public %s { \n",
1537 instr->_ident, instr->mach_base_class(_globalNames) );
1538 fprintf(fp,"private:\n");
1539 fprintf(fp," MachOper *_opnd_array[%d];\n", instr->num_opnds() );
1540 if ( instr->is_ideal_jump() ) {
1541 fprintf(fp, " GrowableArray<Label*> _index2label;\n");
1542 }
1543
1544 fprintf(fp, "public:\n");
1545
1546 Attribute *att = instr->_attribs;
1547 // Fields of the node specified in the ad file.
1548 while (att != NULL__null) {
1549 if (strncmp(att->_ident, "ins_field_", 10) == 0) {
1550 const char *field_name = att->_ident+10;
1551 const char *field_type = att->_val;
1552 fprintf(fp, " %s _%s;\n", field_type, field_name);
1553 }
1554 att = (Attribute *)att->_next;
1555 }
1556
1557 fprintf(fp," MachOper *opnd_array(uint operand_index) const {\n");
1558 fprintf(fp," assert(operand_index < _num_opnds, \"invalid _opnd_array index\");\n");
1559 fprintf(fp," return _opnd_array[operand_index];\n");
1560 fprintf(fp," }\n");
1561 fprintf(fp," void set_opnd_array(uint operand_index, MachOper *operand) {\n");
1562 fprintf(fp," assert(operand_index < _num_opnds, \"invalid _opnd_array index\");\n");
1563 fprintf(fp," _opnd_array[operand_index] = operand;\n");
1564 fprintf(fp," }\n");
1565 fprintf(fp," virtual uint rule() const { return %s_rule; }\n",
1566 instr->_ident);
1567 fprintf(fp,"private:\n");
1568 if ( instr->is_ideal_jump() ) {
1569 fprintf(fp," virtual void add_case_label(int index_num, Label* blockLabel) {\n");
1570 fprintf(fp," _index2label.at_put_grow(index_num, blockLabel);\n");
1571 fprintf(fp," }\n");
1572 }
1573 if( can_cisc_spill() && (instr->cisc_spill_alternate() != NULL__null) ) {
1574 fprintf(fp," const RegMask *_cisc_RegMask;\n");
1575 }
1576
1577 out_RegMask(fp); // output register mask
1578
1579 // If this instruction contains a labelOper
1580 // Declare Node::methods that set operand Label's contents
1581 int label_position = instr->label_position();
1582 if( label_position != -1 ) {
1583 // Set/Save the label, stored in labelOper::_branch_label
1584 fprintf(fp," virtual void label_set( Label* label, uint block_num );\n");
1585 fprintf(fp," virtual void save_label( Label** label, uint* block_num );\n");
1586 }
1587
1588 // If this instruction contains a methodOper
1589 // Declare Node::methods that set operand method's contents
1590 int method_position = instr->method_position();
1591 if( method_position != -1 ) {
1592 // Set the address method, stored in methodOper::_method
1593 fprintf(fp," virtual void method_set( intptr_t method );\n");
1594 }
1595
1596 // virtual functions for attributes
1597 //
1598 // Each instruction attribute results in a virtual call of same name.
1599 // The ins_cost is not handled here.
1600 Attribute *attr = instr->_attribs;
1601 Attribute *avoid_back_to_back_attr = NULL__null;
1602 while (attr != NULL__null) {
1603 if (strcmp (attr->_ident, "ins_is_TrapBasedCheckNode") == 0) {
1604 fprintf(fp, " virtual bool is_TrapBasedCheckNode() const { return %s; }\n", attr->_val);
1605 } else if (strcmp (attr->_ident, "ins_cost") != 0 &&
1606 strncmp(attr->_ident, "ins_field_", 10) != 0 &&
1607 // Must match function in node.hpp: return type bool, no prefix "ins_".
1608 strcmp (attr->_ident, "ins_is_TrapBasedCheckNode") != 0 &&
1609 strcmp (attr->_ident, "ins_short_branch") != 0) {
1610 fprintf(fp, " virtual int %s() const { return %s; }\n", attr->_ident, attr->_val);
1611 }
1612 if (strcmp(attr->_ident, "ins_avoid_back_to_back") == 0) {
1613 avoid_back_to_back_attr = attr;
1614 }
1615 attr = (Attribute *)attr->_next;
1616 }
1617
1618 // virtual functions for encode and format
1619
1620 // Virtual function for evaluating the constant.
1621 if (instr->is_mach_constant()) {
1622 fprintf(fp," virtual void eval_constant(Compile* C);\n");
1623 }
1624
1625 // Output the opcode function and the encode function here using the
1626 // encoding class information in the _insencode slot.
1627 if ( instr->_insencode ) {
1628 if (instr->postalloc_expands()) {
1629 fprintf(fp," virtual bool requires_postalloc_expand() const { return true; }\n");
1630 fprintf(fp," virtual void postalloc_expand(GrowableArray <Node *> *nodes, PhaseRegAlloc *ra_);\n");
1631 } else {
1632 fprintf(fp," virtual void emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const;\n");
1633 }
1634 }
1635
1636 // virtual function for getting the size of an instruction
1637 if ( instr->_size ) {
1638 fprintf(fp," virtual uint size(PhaseRegAlloc *ra_) const;\n");
1639 }
1640
1641 // Return the top-level ideal opcode.
1642 // Use MachNode::ideal_Opcode() for nodes based on MachNode class
1643 // if the ideal_Opcode == Op_Node.
1644 if ( strcmp("Node", instr->ideal_Opcode(_globalNames)) != 0 ||
1645 strcmp("MachNode", instr->mach_base_class(_globalNames)) != 0 ) {
1646 fprintf(fp," virtual int ideal_Opcode() const { return Op_%s; }\n",
1647 instr->ideal_Opcode(_globalNames) );
1648 }
1649
1650 if (instr->needs_constant_base() &&
1651 !instr->is_mach_constant()) { // These inherit the funcion from MachConstantNode.
1652 fprintf(fp," virtual uint mach_constant_base_node_input() const { ");
1653 if (instr->is_ideal_call() != Form::invalid_type &&
1654 instr->is_ideal_call() != Form::JAVA_LEAF) {
1655 // MachConstantBase goes behind arguments, but before jvms.
1656 fprintf(fp,"assert(tf() && tf()->domain(), \"\"); return tf()->domain()->cnt();");
1657 } else {
1658 fprintf(fp,"return req()-1;");
1659 }
1660 fprintf(fp," }\n");
1661 }
1662
1663 // Allow machine-independent optimization, invert the sense of the IF test
1664 if( instr->is_ideal_if() ) {
1665 fprintf(fp," virtual void negate() { \n");
1666 // Identify which operand contains the negate(able) ideal condition code
1667 int idx = 0;
1668 instr->_components.reset();
1669 for( Component *comp; (comp = instr->_components.iter()) != NULL__null; ) {
1670 // Check that component is an operand
1671 Form *form = (Form*)_globalNames[comp->_type];
1672 OperandForm *opForm = form ? form->is_operand() : NULL__null;
1673 if( opForm == NULL__null ) continue;
1674
1675 // Lookup the position of the operand in the instruction.
1676 if( opForm->is_ideal_bool() ) {
1677 idx = instr->operand_position(comp->_name, comp->_usedef);
1678 assert( idx != NameList::Not_in_list, "Did not find component in list that contained it."){ if (!(idx != NameList::Not_in_list)) { fprintf(stderr, "assert fails %s %d: %s\n"
, "/home/daniel/Projects/java/jdk/src/hotspot/share/adlc/output_h.cpp"
, 1678, "Did not find component in list that contained it.");
abort(); }}
;
1679 break;
1680 }
1681 }
1682 fprintf(fp," opnd_array(%d)->negate();\n", idx);
1683 fprintf(fp," _prob = 1.0f - _prob;\n");
1684 fprintf(fp," };\n");
1685 }
1686
1687
1688 // Identify which input register matches the input register.
1689 uintunsigned int matching_input = instr->two_address(_globalNames);
1690
1691 // Generate the method if it returns != 0 otherwise use MachNode::two_adr()
1692 if( matching_input != 0 ) {
1693 fprintf(fp," virtual uint two_adr() const ");
1694 fprintf(fp,"{ return oper_input_base()");
1695 for( uintunsigned int i = 2; i <= matching_input; i++ )
1696 fprintf(fp," + opnd_array(%d)->num_edges()",i-1);
1697 fprintf(fp,"; }\n");
1698 }
1699
1700 // Declare cisc_version, if applicable
1701 // MachNode *cisc_version( int offset /* ,... */ );
1702 instr->declare_cisc_version(*this, fp);
1703
1704 // If there is an explicit peephole rule, build it
1705 if ( instr->peepholes() != NULL__null ) {
1706 fprintf(fp," virtual MachNode *peephole(Block *block, int block_index, PhaseRegAlloc *ra_, int &deleted);\n");
1707 }
1708
1709 // Output the declaration for number of relocation entries
1710 if ( instr->reloc(_globalNames) != 0 ) {
1711 fprintf(fp," virtual int reloc() const;\n");
1712 }
1713
1714 if (instr->alignment() != 1) {
1715 fprintf(fp," virtual int alignment_required() const { return %d; }\n", instr->alignment());
1716 fprintf(fp," virtual int compute_padding(int current_offset) const;\n");
1717 }
1718
1719 // Starting point for inputs matcher wants.
1720 // Use MachNode::oper_input_base() for nodes based on MachNode class
1721 // if the base == 1.
1722 if ( instr->oper_input_base(_globalNames) != 1 ||
1723 strcmp("MachNode", instr->mach_base_class(_globalNames)) != 0 ) {
1724 fprintf(fp," virtual uint oper_input_base() const { return %d; }\n",
1725 instr->oper_input_base(_globalNames));
1726 }
1727
1728 // Make the constructor and following methods 'public:'
1729 fprintf(fp,"public:\n");
1730
1731 // Constructor
1732 if ( instr->is_ideal_jump() ) {
1733 fprintf(fp," %sNode() : _index2label(MinJumpTableSize*2) { ", instr->_ident);
1734 } else {
1735 fprintf(fp," %sNode() { ", instr->_ident);
1736 if( can_cisc_spill() && (instr->cisc_spill_alternate() != NULL__null) ) {
1737 fprintf(fp,"_cisc_RegMask = NULL; ");
1738 }
1739 }
1740
1741 fprintf(fp," _num_opnds = %d; _opnds = _opnd_array; ", instr->num_opnds());
1742
1743 bool node_flags_set = false;
1744 // flag: if this instruction matches an ideal 'Copy*' node
1745 if ( instr->is_ideal_copy() != 0 ) {
1746 fprintf(fp,"init_flags(Flag_is_Copy");
1747 node_flags_set = true;
1748 }
1749
1750 // Is an instruction is a constant? If so, get its type
1751 Form::DataType data_type;
1752 const char *opType = NULL__null;
1753 const char *result = NULL__null;
1754 data_type = instr->is_chain_of_constant(_globalNames, opType, result);
1755 // Check if this instruction is a constant
1756 if ( data_type != Form::none ) {
1757 if ( node_flags_set ) {
1758 fprintf(fp," | Flag_is_Con");
1759 } else {
1760 fprintf(fp,"init_flags(Flag_is_Con");
1761 node_flags_set = true;
1762 }
1763 }
1764
1765 // flag: if this instruction is cisc alternate
1766 if ( can_cisc_spill() && instr->is_cisc_alternate() ) {
1767 if ( node_flags_set ) {
1768 fprintf(fp," | Flag_is_cisc_alternate");
1769 } else {
1770 fprintf(fp,"init_flags(Flag_is_cisc_alternate");
1771 node_flags_set = true;
1772 }
1773 }
1774
1775 // flag: if this instruction has short branch form
1776 if ( instr->has_short_branch_form() ) {
1777 if ( node_flags_set ) {
1778 fprintf(fp," | Flag_may_be_short_branch");
1779 } else {
1780 fprintf(fp,"init_flags(Flag_may_be_short_branch");
1781 node_flags_set = true;
1782 }
1783 }
1784
1785 // flag: if this instruction should not be generated back to back.
1786 if (avoid_back_to_back_attr != NULL__null) {
1787 if (node_flags_set) {
1788 fprintf(fp," | (%s)", avoid_back_to_back_attr->_val);
1789 } else {
1790 fprintf(fp,"init_flags((%s)", avoid_back_to_back_attr->_val);
1791 node_flags_set = true;
1792 }
1793 }
1794
1795 // Check if machine instructions that USE memory, but do not DEF memory,
1796 // depend upon a node that defines memory in machine-independent graph.
1797 if ( instr->needs_anti_dependence_check(_globalNames) ) {
1798 if ( node_flags_set ) {
1799 fprintf(fp," | Flag_needs_anti_dependence_check");
1800 } else {
1801 fprintf(fp,"init_flags(Flag_needs_anti_dependence_check");
1802 node_flags_set = true;
1803 }
1804 }
1805
1806 // flag: if this instruction is implemented with a call
1807 if ( instr->_has_call ) {
1808 if ( node_flags_set ) {
1809 fprintf(fp," | Flag_has_call");
1810 } else {
1811 fprintf(fp,"init_flags(Flag_has_call");
1812 node_flags_set = true;
1813 }
1814 }
1815
1816 if ( node_flags_set ) {
1817 fprintf(fp,"); ");
1818 }
1819
1820 fprintf(fp,"}\n");
1821
1822 // size_of, used by base class's clone to obtain the correct size.
1823 fprintf(fp," virtual uint size_of() const {");
1824 fprintf(fp, " return sizeof(%sNode);", instr->_ident);
1825 fprintf(fp, " }\n");
1826
1827 // Virtual methods which are only generated to override base class
1828 if( instr->expands() || instr->needs_projections() ||
1829 instr->has_temps() ||
1830 instr->is_mach_constant() ||
1831 instr->needs_constant_base() ||
1832 (instr->_matrule != NULL__null &&
1833 instr->num_opnds() != instr->num_unique_opnds()) ) {
1834 fprintf(fp," virtual MachNode *Expand(State *state, Node_List &proj_list, Node* mem);\n");
1835 }
1836
1837 if (instr->is_pinned(_globalNames)) {
1838 fprintf(fp," virtual bool pinned() const { return ");
1839 if (instr->is_parm(_globalNames)) {
1840 fprintf(fp,"_in[0]->pinned();");
1841 } else {
1842 fprintf(fp,"true;");
1843 }
1844 fprintf(fp," }\n");
1845 }
1846 if (instr->is_projection(_globalNames)) {
1847 fprintf(fp," virtual const Node *is_block_proj() const { return this; }\n");
1848 }
1849 if ( instr->num_post_match_opnds() != 0
1850 || instr->is_chain_of_constant(_globalNames) ) {
1851 fprintf(fp," friend MachNode *State::MachNodeGenerator(int opcode);\n");
1852 }
1853 if ( instr->rematerialize(_globalNames, get_registers()) ) {
1854 fprintf(fp," // Rematerialize %s\n", instr->_ident);
1855 }
1856
1857 // Declare short branch methods, if applicable
1858 instr->declare_short_branch_methods(fp);
1859
1860 // See if there is an "ins_pipe" declaration for this instruction
1861 if (instr->_ins_pipe) {
1862 fprintf(fp," static const Pipeline *pipeline_class();\n");
1863 fprintf(fp," virtual const Pipeline *pipeline() const;\n");
1864 }
1865
1866 // Generate virtual function for MachNodeX::bottom_type when necessary
1867 //
1868 // Note on accuracy: Pointer-types of machine nodes need to be accurate,
1869 // or else alias analysis on the matched graph may produce bad code.
1870 // Moreover, the aliasing decisions made on machine-node graph must be
1871 // no less accurate than those made on the ideal graph, or else the graph
1872 // may fail to schedule. (Reason: Memory ops which are reordered in
1873 // the ideal graph might look interdependent in the machine graph,
1874 // thereby removing degrees of scheduling freedom that the optimizer
1875 // assumed would be available.)
1876 //
1877 // %%% We should handle many of these cases with an explicit ADL clause:
1878 // instruct foo() %{ ... bottom_type(TypeRawPtr::BOTTOM); ... %}
1879 if( data_type != Form::none ) {
1880 // A constant's bottom_type returns a Type containing its constant value
1881
1882 // !!!!!
1883 // Convert all ints, floats, ... to machine-independent TypeXs
1884 // as is done for pointers
1885 //
1886 // Construct appropriate constant type containing the constant value.
1887 fprintf(fp," virtual const class Type *bottom_type() const {\n");
1888 switch( data_type ) {
1889 case Form::idealI:
1890 fprintf(fp," return TypeInt::make(opnd_array(1)->constant());\n");
1891 break;
1892 case Form::idealP:
1893 case Form::idealN:
1894 case Form::idealNKlass:
1895 fprintf(fp," return opnd_array(1)->type();\n");
1896 break;
1897 case Form::idealD:
1898 fprintf(fp," return TypeD::make(opnd_array(1)->constantD());\n");
1899 break;
1900 case Form::idealF:
1901 fprintf(fp," return TypeF::make(opnd_array(1)->constantF());\n");
1902 break;
1903 case Form::idealL:
1904 fprintf(fp," return TypeLong::make(opnd_array(1)->constantL());\n");
1905 break;
1906 default:
1907 assert( false, "Unimplemented()" ){ if (!(false)) { fprintf(stderr, "assert fails %s %d: %s\n",
"/home/daniel/Projects/java/jdk/src/hotspot/share/adlc/output_h.cpp"
, 1907, "Unimplemented()"); abort(); }}
;
1908 break;
1909 }
1910 fprintf(fp," };\n");
1911 }
1912/* else if ( instr->_matrule && instr->_matrule->_rChild &&
1913 ( strcmp("ConvF2I",instr->_matrule->_rChild->_opType)==0
1914 || strcmp("ConvD2I",instr->_matrule->_rChild->_opType)==0 ) ) {
1915 // !!!!! !!!!!
1916 // Provide explicit bottom type for conversions to int
1917 // On Intel the result operand is a stackSlot, untyped.
1918 fprintf(fp," virtual const class Type *bottom_type() const {");
1919 fprintf(fp, " return TypeInt::INT;");
1920 fprintf(fp, " };\n");
1921 }*/
1922 else if( instr->is_ideal_copy() &&
1923 !strcmp(instr->_matrule->_lChild->_opType,"stackSlotP") ) {
1924 // !!!!!
1925 // Special hack for ideal Copy of pointer. Bottom type is oop or not depending on input.
1926 fprintf(fp," const Type *bottom_type() const { return in(1)->bottom_type(); } // Copy?\n");
1927 }
1928 else if( instr->is_ideal_loadPC() ) {
1929 // LoadPCNode provides the return address of a call to native code.
1930 // Define its bottom type to be TypeRawPtr::BOTTOM instead of TypePtr::BOTTOM
1931 // since it is a pointer to an internal VM location and must have a zero offset.
1932 // Allocation detects derived pointers, in part, by their non-zero offsets.
1933 fprintf(fp," const Type *bottom_type() const { return TypeRawPtr::BOTTOM; } // LoadPC?\n");
1934 }
1935 else if( instr->is_ideal_box() ) {
1936 // BoxNode provides the address of a stack slot.
1937 // Define its bottom type to be TypeRawPtr::BOTTOM instead of TypePtr::BOTTOM
1938 // This prevent s insert_anti_dependencies from complaining. It will
1939 // complain if it sees that the pointer base is TypePtr::BOTTOM since
1940 // it doesn't understand what that might alias.
1941 fprintf(fp," const Type *bottom_type() const { return TypeRawPtr::BOTTOM; } // Box?\n");
1942 }
1943 else if (instr->_matrule && instr->_matrule->_rChild &&
1944 (!strcmp(instr->_matrule->_rChild->_opType,"CMoveP") || !strcmp(instr->_matrule->_rChild->_opType,"CMoveN")) ) {
1945 int offset = 1;
1946 // Special special hack to see if the Cmp? has been incorporated in the conditional move
1947 MatchNode *rl = instr->_matrule->_rChild->_lChild;
1948 if (rl && !strcmp(rl->_opType, "Binary") && rl->_rChild && strncmp(rl->_rChild->_opType, "Cmp", 3) == 0) {
1949 offset = 2;
1950 fprintf(fp," const Type *bottom_type() const { if (req() == 3) return in(2)->bottom_type();\n\tconst Type *t = in(oper_input_base()+%d)->bottom_type(); return (req() <= oper_input_base()+%d) ? t : t->meet(in(oper_input_base()+%d)->bottom_type()); } // %s\n",
1951 offset, offset+1, offset+1, instr->_matrule->_rChild->_opType);
1952 } else {
1953 // Special hack for ideal CMove; ideal type depends on inputs
1954 fprintf(fp," const Type *bottom_type() const { const Type *t = in(oper_input_base()+%d)->bottom_type(); return (req() <= oper_input_base()+%d) ? t : t->meet(in(oper_input_base()+%d)->bottom_type()); } // %s\n",
1955 offset, offset+1, offset+1, instr->_matrule->_rChild->_opType);
1956 }
1957 }
1958 else if (instr->is_tls_instruction()) {
1959 // Special hack for tlsLoadP
1960 fprintf(fp," const Type *bottom_type() const { return TypeRawPtr::BOTTOM; } // tlsLoadP\n");
1961 }
1962 else if ( instr->is_ideal_if() ) {
1963 fprintf(fp," const Type *bottom_type() const { return TypeTuple::IFBOTH; } // matched IfNode\n");
1964 }
1965 else if ( instr->is_ideal_membar() ) {
1966 fprintf(fp," const Type *bottom_type() const { return TypeTuple::MEMBAR; } // matched MemBar\n");
1967 }
1968
1969 // Check where 'ideal_type' must be customized
1970 /*
1971 if ( instr->_matrule && instr->_matrule->_rChild &&
1972 ( strcmp("ConvF2I",instr->_matrule->_rChild->_opType)==0
1973 || strcmp("ConvD2I",instr->_matrule->_rChild->_opType)==0 ) ) {
1974 fprintf(fp," virtual uint ideal_reg() const { return Compile::current()->matcher()->base2reg[Type::Int]; }\n");
1975 }*/
1976
1977 // Analyze machine instructions that either USE or DEF memory.
1978 int memory_operand = instr->memory_operand(_globalNames);
1979 if ( memory_operand != InstructForm::NO_MEMORY_OPERAND ) {
1980 if( memory_operand == InstructForm::MANY_MEMORY_OPERANDS ) {
1981 fprintf(fp," virtual const TypePtr *adr_type() const;\n");
1982 }
1983 fprintf(fp," virtual const MachOper *memory_operand() const;\n");
1984 }
1985
1986 fprintf(fp, "#ifndef PRODUCT\n");
1987
1988 // virtual function for generating the user's assembler output
1989 gen_inst_format(fp, _globalNames,*instr);
1990
1991 // Machine independent print functionality for debugging
1992 fprintf(fp," virtual const char *Name() const { return \"%s\";}\n",
1993 instr->_ident);
1994
1995 fprintf(fp, "#endif\n");
1996
1997 // Close definition of this XxxMachNode
1998 fprintf(fp,"};\n");
1999 };
2000
2001}
2002
2003void ArchDesc::defineStateClass(FILE *fp) {
2004 static const char *state__valid = "_rule[index] & 0x1";
2005
2006 fprintf(fp,"\n");
2007 fprintf(fp,"// MACROS to inline and constant fold State::valid(index)...\n");
2008 fprintf(fp,"// when given a constant 'index' in dfa_<arch>.cpp\n");
2009 fprintf(fp,"#define STATE__NOT_YET_VALID(index) ");
2010 fprintf(fp," ( (%s) == 0 )\n", state__valid);
2011 fprintf(fp,"\n");
2012 fprintf(fp,"#define STATE__VALID_CHILD(state,index) ");
2013 fprintf(fp," ( state && (state->%s) )\n", state__valid);
2014 fprintf(fp,"\n");
2015 fprintf(fp,
2016 "//---------------------------State-------------------------------------------\n");
2017 fprintf(fp,"// State contains an integral cost vector, indexed by machine operand opcodes,\n");
2018 fprintf(fp,"// a rule vector consisting of machine operand/instruction opcodes, and also\n");
2019 fprintf(fp,"// indexed by machine operand opcodes, pointers to the children in the label\n");
2020 fprintf(fp,"// tree generated by the Label routines in ideal nodes (currently limited to\n");
2021 fprintf(fp,"// two for convenience, but this could change).\n");
2022 fprintf(fp,"class State : public ResourceObj {\n");
2023 fprintf(fp,"private:\n");
2024 fprintf(fp," unsigned int _cost[_LAST_MACH_OPER]; // Costs, indexed by operand opcodes\n");
2025 fprintf(fp," uint16_t _rule[_LAST_MACH_OPER]; // Rule and validity, indexed by operand opcodes\n");
2026 fprintf(fp," // Lowest bit encodes validity\n");
2027
2028 fprintf(fp,"public:\n");
2029 fprintf(fp," int _id; // State identifier\n");
2030 fprintf(fp," Node *_leaf; // Ideal (non-machine-node) leaf of match tree\n");
2031 fprintf(fp," State *_kids[2]; // Children of state node in label tree\n");
2032 fprintf(fp,"\n");
2033 fprintf(fp," State(void);\n");
2034 fprintf(fp," DEBUG_ONLY( ~State(void); )\n");
2035 fprintf(fp,"\n");
2036 fprintf(fp," // Methods created by ADLC and invoked by Reduce\n");
2037 fprintf(fp," MachOper *MachOperGenerator(int opcode);\n");
2038 fprintf(fp," MachNode *MachNodeGenerator(int opcode);\n");
2039 fprintf(fp,"\n");
2040 fprintf(fp," // Assign a state to a node, definition of method produced by ADLC\n");
2041 fprintf(fp," bool DFA( int opcode, const Node *ideal );\n");
2042 fprintf(fp,"\n");
2043 fprintf(fp," bool valid(uint index) {\n");
2044 fprintf(fp," return %s;\n", state__valid);
2045 fprintf(fp," }\n");
2046 fprintf(fp," unsigned int rule(uint index) {\n");
2047 fprintf(fp," return _rule[index] >> 1;\n");
2048 fprintf(fp," }\n");
2049 fprintf(fp," unsigned int cost(uint index) {\n");
2050 fprintf(fp," return _cost[index];\n");
2051 fprintf(fp," }\n");
2052 fprintf(fp,"\n");
2053 fprintf(fp,"#ifndef PRODUCT\n");
2054 fprintf(fp," void dump(); // Debugging prints\n");
2055 fprintf(fp," void dump(int depth);\n");
2056 fprintf(fp,"#endif\n");
2057 if (_dfa_small) {
2058 // Generate the routine name we'll need
2059 for (int i = 1; i < _last_opcode; i++) {
2060 if (_mlistab[i] == NULL__null) continue;
2061 fprintf(fp, " void _sub_Op_%s(const Node *n);\n", NodeClassNames[i]);
2062 }
2063 }
2064 fprintf(fp,"};\n");
2065 fprintf(fp,"\n");
2066 fprintf(fp,"\n");
2067
2068}
2069
2070
2071//---------------------------buildMachOperEnum---------------------------------
2072// Build enumeration for densely packed operands.
2073// This enumeration is used to index into the arrays in the State objects
2074// that indicate cost and a successfull rule match.
2075
2076// Information needed to generate the ReduceOp mapping for the DFA
2077class OutputMachOperands : public OutputMap {
2078public:
2079 OutputMachOperands(FILE *hpp, FILE *cpp, FormDict &globals, ArchDesc &AD)
2080 : OutputMap(hpp, cpp, globals, AD, "MachOperands") {};
2081
2082 void declaration() { }
2083 void definition() { fprintf(_cpp, "enum MachOperands {\n"); }
2084 void closing() { fprintf(_cpp, " _LAST_MACH_OPER\n");
2085 OutputMap::closing();
2086 }
2087 void map(OpClassForm &opc) {
2088 const char* opc_ident_to_upper = _AD.machOperEnum(opc._ident);
2089 fprintf(_cpp, " %s", opc_ident_to_upper);
2090 delete[] opc_ident_to_upper;
2091 }
2092 void map(OperandForm &oper) {
2093 const char* oper_ident_to_upper = _AD.machOperEnum(oper._ident);
2094 fprintf(_cpp, " %s", oper_ident_to_upper);
2095 delete[] oper_ident_to_upper;
2096 }
2097 void map(char *name) {
2098 const char* name_to_upper = _AD.machOperEnum(name);
2099 fprintf(_cpp, " %s", name_to_upper);
2100 delete[] name_to_upper;
2101 }
2102
2103 bool do_instructions() { return false; }
2104 void map(InstructForm &inst){ assert( false, "ShouldNotCallThis()"){ if (!(false)) { fprintf(stderr, "assert fails %s %d: %s\n",
"/home/daniel/Projects/java/jdk/src/hotspot/share/adlc/output_h.cpp"
, 2104, "ShouldNotCallThis()"); abort(); }}
; }
2105};
2106
2107
2108void ArchDesc::buildMachOperEnum(FILE *fp_hpp) {
2109 // Construct the table for MachOpcodes
2110 OutputMachOperands output_mach_operands(fp_hpp, fp_hpp, _globalNames, *this);
2111 build_map(output_mach_operands);
2112}
2113
2114
2115//---------------------------buildMachEnum----------------------------------
2116// Build enumeration for all MachOpers and all MachNodes
2117
2118// Information needed to generate the ReduceOp mapping for the DFA
2119class OutputMachOpcodes : public OutputMap {
2120 int begin_inst_chain_rule;
2121 int end_inst_chain_rule;
2122 int begin_rematerialize;
2123 int end_rematerialize;
2124 int end_instructions;
2125public:
2126 OutputMachOpcodes(FILE *hpp, FILE *cpp, FormDict &globals, ArchDesc &AD)
2127 : OutputMap(hpp, cpp, globals, AD, "MachOpcodes"),
2128 begin_inst_chain_rule(-1), end_inst_chain_rule(-1),
2129 begin_rematerialize(-1), end_rematerialize(-1),
2130 end_instructions(-1)
2131 {};
2132
2133 void declaration() { }
2134 void definition() { fprintf(_cpp, "enum MachOpcodes {\n"); }
2135 void closing() {
2136 if( begin_inst_chain_rule != -1 )
2137 fprintf(_cpp, " _BEGIN_INST_CHAIN_RULE = %d,\n", begin_inst_chain_rule);
2138 if( end_inst_chain_rule != -1 )
2139 fprintf(_cpp, " _END_INST_CHAIN_RULE = %d,\n", end_inst_chain_rule);
2140 if( begin_rematerialize != -1 )
2141 fprintf(_cpp, " _BEGIN_REMATERIALIZE = %d,\n", begin_rematerialize);
2142 if( end_rematerialize != -1 )
2143 fprintf(_cpp, " _END_REMATERIALIZE = %d,\n", end_rematerialize);
2144 // always execute since do_instructions() is true, and avoids trailing comma
2145 fprintf(_cpp, " _last_Mach_Node = %d \n", end_instructions);
2146 OutputMap::closing();
2147 }
2148 void map(OpClassForm &opc) { fprintf(_cpp, " %s_rule", opc._ident ); }
2149 void map(OperandForm &oper) { fprintf(_cpp, " %s_rule", oper._ident ); }
2150 void map(char *name) { if (name) fprintf(_cpp, " %s_rule", name);
2151 else fprintf(_cpp, " 0"); }
2152 void map(InstructForm &inst) {fprintf(_cpp, " %s_rule", inst._ident ); }
2153
2154 void record_position(OutputMap::position place, int idx ) {
2155 switch(place) {
2156 case OutputMap::BEGIN_INST_CHAIN_RULES :
2157 begin_inst_chain_rule = idx;
2158 break;
2159 case OutputMap::END_INST_CHAIN_RULES :
2160 end_inst_chain_rule = idx;
2161 break;
2162 case OutputMap::BEGIN_REMATERIALIZE :
2163 begin_rematerialize = idx;
2164 break;
2165 case OutputMap::END_REMATERIALIZE :
2166 end_rematerialize = idx;
2167 break;
2168 case OutputMap::END_INSTRUCTIONS :
2169 end_instructions = idx;
2170 break;
2171 default:
2172 break;
2173 }
2174 }
2175};
2176
2177
2178void ArchDesc::buildMachOpcodesEnum(FILE *fp_hpp) {
2179 // Construct the table for MachOpcodes
2180 OutputMachOpcodes output_mach_opcodes(fp_hpp, fp_hpp, _globalNames, *this);
2181 build_map(output_mach_opcodes);
2182}
2183
2184
2185// Generate an enumeration of the pipeline states, and both
2186// the functional units (resources) and the masks for
2187// specifying resources
2188void ArchDesc::build_pipeline_enums(FILE *fp_hpp) {
2189 int stagelen = (int)strlen("undefined");
2190 int stagenum = 0;
2191
2192 if (_pipeline) { // Find max enum string length
2193 const char *stage;
2194 for ( _pipeline->_stages.reset(); (stage = _pipeline->_stages.iter()) != NULL__null; ) {
2195 int len = (int)strlen(stage);
2196 if (stagelen < len) stagelen = len;
2197 }
2198 }
2199
2200 // Generate a list of stages
2201 fprintf(fp_hpp, "\n");
2202 fprintf(fp_hpp, "// Pipeline Stages\n");
2203 fprintf(fp_hpp, "enum machPipelineStages {\n");
2204 fprintf(fp_hpp, " stage_%-*s = 0,\n", stagelen, "undefined");
2205
2206 if( _pipeline ) {
2207 const char *stage;
2208 for ( _pipeline->_stages.reset(); (stage = _pipeline->_stages.iter()) != NULL__null; )
2209 fprintf(fp_hpp, " stage_%-*s = %d,\n", stagelen, stage, ++stagenum);
2210 }
2211
2212 fprintf(fp_hpp, " stage_%-*s = %d\n", stagelen, "count", stagenum);
2213 fprintf(fp_hpp, "};\n");
2214
2215 fprintf(fp_hpp, "\n");
2216 fprintf(fp_hpp, "// Pipeline Resources\n");
2217 fprintf(fp_hpp, "enum machPipelineResources {\n");
2218 int rescount = 0;
2219
2220 if( _pipeline ) {
2221 const char *resource;
2222 int reslen = 0;
2223
2224 // Generate a list of resources, and masks
2225 for ( _pipeline->_reslist.reset(); (resource = _pipeline->_reslist.iter()) != NULL__null; ) {
2226 int len = (int)strlen(resource);
2227 if (reslen < len)
2228 reslen = len;
2229 }
2230
2231 for ( _pipeline->_reslist.reset(); (resource = _pipeline->_reslist.iter()) != NULL__null; ) {
2232 const ResourceForm *resform = _pipeline->_resdict[resource]->is_resource();
2233 int mask = resform->mask();
2234 if ((mask & (mask-1)) == 0)
2235 fprintf(fp_hpp, " resource_%-*s = %d,\n", reslen, resource, rescount++);
2236 }
2237 fprintf(fp_hpp, "\n");
2238 for ( _pipeline->_reslist.reset(); (resource = _pipeline->_reslist.iter()) != NULL__null; ) {
2239 const ResourceForm *resform = _pipeline->_resdict[resource]->is_resource();
2240 fprintf(fp_hpp, " res_mask_%-*s = 0x%08x,\n", reslen, resource, resform->mask());
2241 }
2242 fprintf(fp_hpp, "\n");
2243 }
2244 fprintf(fp_hpp, " resource_count = %d\n", rescount);
2245 fprintf(fp_hpp, "};\n");
2246}