src/share/vm/adlc/formssel.cpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 // FORMS.CPP - Definitions for ADL Parser Forms Classes
aoqi@0 26 #include "adlc.hpp"
aoqi@0 27
aoqi@0 28 //==============================Instructions===================================
aoqi@0 29 //------------------------------InstructForm-----------------------------------
aoqi@0 30 InstructForm::InstructForm(const char *id, bool ideal_only)
aoqi@0 31 : _ident(id), _ideal_only(ideal_only),
aoqi@0 32 _localNames(cmpstr, hashstr, Form::arena),
aoqi@0 33 _effects(cmpstr, hashstr, Form::arena),
aoqi@0 34 _is_mach_constant(false),
aoqi@0 35 _needs_constant_base(false),
aoqi@0 36 _has_call(false)
aoqi@0 37 {
aoqi@0 38 _ftype = Form::INS;
aoqi@0 39
aoqi@0 40 _matrule = NULL;
aoqi@0 41 _insencode = NULL;
aoqi@0 42 _constant = NULL;
aoqi@0 43 _is_postalloc_expand = false;
aoqi@0 44 _opcode = NULL;
aoqi@0 45 _size = NULL;
aoqi@0 46 _attribs = NULL;
aoqi@0 47 _predicate = NULL;
aoqi@0 48 _exprule = NULL;
aoqi@0 49 _rewrule = NULL;
aoqi@0 50 _format = NULL;
aoqi@0 51 _peephole = NULL;
aoqi@0 52 _ins_pipe = NULL;
aoqi@0 53 _uniq_idx = NULL;
aoqi@0 54 _num_uniq = 0;
aoqi@0 55 _cisc_spill_operand = Not_cisc_spillable;// Which operand may cisc-spill
aoqi@0 56 _cisc_spill_alternate = NULL; // possible cisc replacement
aoqi@0 57 _cisc_reg_mask_name = NULL;
aoqi@0 58 _is_cisc_alternate = false;
aoqi@0 59 _is_short_branch = false;
aoqi@0 60 _short_branch_form = NULL;
aoqi@0 61 _alignment = 1;
aoqi@0 62 }
aoqi@0 63
aoqi@0 64 InstructForm::InstructForm(const char *id, InstructForm *instr, MatchRule *rule)
aoqi@0 65 : _ident(id), _ideal_only(false),
aoqi@0 66 _localNames(instr->_localNames),
aoqi@0 67 _effects(instr->_effects),
aoqi@0 68 _is_mach_constant(false),
aoqi@0 69 _needs_constant_base(false),
aoqi@0 70 _has_call(false)
aoqi@0 71 {
aoqi@0 72 _ftype = Form::INS;
aoqi@0 73
aoqi@0 74 _matrule = rule;
aoqi@0 75 _insencode = instr->_insencode;
aoqi@0 76 _constant = instr->_constant;
aoqi@0 77 _is_postalloc_expand = instr->_is_postalloc_expand;
aoqi@0 78 _opcode = instr->_opcode;
aoqi@0 79 _size = instr->_size;
aoqi@0 80 _attribs = instr->_attribs;
aoqi@0 81 _predicate = instr->_predicate;
aoqi@0 82 _exprule = instr->_exprule;
aoqi@0 83 _rewrule = instr->_rewrule;
aoqi@0 84 _format = instr->_format;
aoqi@0 85 _peephole = instr->_peephole;
aoqi@0 86 _ins_pipe = instr->_ins_pipe;
aoqi@0 87 _uniq_idx = instr->_uniq_idx;
aoqi@0 88 _num_uniq = instr->_num_uniq;
aoqi@0 89 _cisc_spill_operand = Not_cisc_spillable; // Which operand may cisc-spill
aoqi@0 90 _cisc_spill_alternate = NULL; // possible cisc replacement
aoqi@0 91 _cisc_reg_mask_name = NULL;
aoqi@0 92 _is_cisc_alternate = false;
aoqi@0 93 _is_short_branch = false;
aoqi@0 94 _short_branch_form = NULL;
aoqi@0 95 _alignment = 1;
aoqi@0 96 // Copy parameters
aoqi@0 97 const char *name;
aoqi@0 98 instr->_parameters.reset();
aoqi@0 99 for (; (name = instr->_parameters.iter()) != NULL;)
aoqi@0 100 _parameters.addName(name);
aoqi@0 101 }
aoqi@0 102
aoqi@0 103 InstructForm::~InstructForm() {
aoqi@0 104 }
aoqi@0 105
aoqi@0 106 InstructForm *InstructForm::is_instruction() const {
aoqi@0 107 return (InstructForm*)this;
aoqi@0 108 }
aoqi@0 109
aoqi@0 110 bool InstructForm::ideal_only() const {
aoqi@0 111 return _ideal_only;
aoqi@0 112 }
aoqi@0 113
aoqi@0 114 bool InstructForm::sets_result() const {
aoqi@0 115 return (_matrule != NULL && _matrule->sets_result());
aoqi@0 116 }
aoqi@0 117
aoqi@0 118 bool InstructForm::needs_projections() {
aoqi@0 119 _components.reset();
aoqi@0 120 for( Component *comp; (comp = _components.iter()) != NULL; ) {
aoqi@0 121 if (comp->isa(Component::KILL)) {
aoqi@0 122 return true;
aoqi@0 123 }
aoqi@0 124 }
aoqi@0 125 return false;
aoqi@0 126 }
aoqi@0 127
aoqi@0 128
aoqi@0 129 bool InstructForm::has_temps() {
aoqi@0 130 if (_matrule) {
aoqi@0 131 // Examine each component to see if it is a TEMP
aoqi@0 132 _components.reset();
aoqi@0 133 // Skip the first component, if already handled as (SET dst (...))
aoqi@0 134 Component *comp = NULL;
aoqi@0 135 if (sets_result()) comp = _components.iter();
aoqi@0 136 while ((comp = _components.iter()) != NULL) {
aoqi@0 137 if (comp->isa(Component::TEMP)) {
aoqi@0 138 return true;
aoqi@0 139 }
aoqi@0 140 }
aoqi@0 141 }
aoqi@0 142
aoqi@0 143 return false;
aoqi@0 144 }
aoqi@0 145
aoqi@0 146 uint InstructForm::num_defs_or_kills() {
aoqi@0 147 uint defs_or_kills = 0;
aoqi@0 148
aoqi@0 149 _components.reset();
aoqi@0 150 for( Component *comp; (comp = _components.iter()) != NULL; ) {
aoqi@0 151 if( comp->isa(Component::DEF) || comp->isa(Component::KILL) ) {
aoqi@0 152 ++defs_or_kills;
aoqi@0 153 }
aoqi@0 154 }
aoqi@0 155
aoqi@0 156 return defs_or_kills;
aoqi@0 157 }
aoqi@0 158
aoqi@0 159 // This instruction has an expand rule?
aoqi@0 160 bool InstructForm::expands() const {
aoqi@0 161 return ( _exprule != NULL );
aoqi@0 162 }
aoqi@0 163
aoqi@0 164 // This instruction has a late expand rule?
aoqi@0 165 bool InstructForm::postalloc_expands() const {
aoqi@0 166 return _is_postalloc_expand;
aoqi@0 167 }
aoqi@0 168
aoqi@0 169 // This instruction has a peephole rule?
aoqi@0 170 Peephole *InstructForm::peepholes() const {
aoqi@0 171 return _peephole;
aoqi@0 172 }
aoqi@0 173
aoqi@0 174 // This instruction has a peephole rule?
aoqi@0 175 void InstructForm::append_peephole(Peephole *peephole) {
aoqi@0 176 if( _peephole == NULL ) {
aoqi@0 177 _peephole = peephole;
aoqi@0 178 } else {
aoqi@0 179 _peephole->append_peephole(peephole);
aoqi@0 180 }
aoqi@0 181 }
aoqi@0 182
aoqi@0 183
aoqi@0 184 // ideal opcode enumeration
aoqi@0 185 const char *InstructForm::ideal_Opcode( FormDict &globalNames ) const {
aoqi@0 186 if( !_matrule ) return "Node"; // Something weird
aoqi@0 187 // Chain rules do not really have ideal Opcodes; use their source
aoqi@0 188 // operand ideal Opcode instead.
aoqi@0 189 if( is_simple_chain_rule(globalNames) ) {
aoqi@0 190 const char *src = _matrule->_rChild->_opType;
aoqi@0 191 OperandForm *src_op = globalNames[src]->is_operand();
aoqi@0 192 assert( src_op, "Not operand class of chain rule" );
aoqi@0 193 if( !src_op->_matrule ) return "Node";
aoqi@0 194 return src_op->_matrule->_opType;
aoqi@0 195 }
aoqi@0 196 // Operand chain rules do not really have ideal Opcodes
aoqi@0 197 if( _matrule->is_chain_rule(globalNames) )
aoqi@0 198 return "Node";
aoqi@0 199 return strcmp(_matrule->_opType,"Set")
aoqi@0 200 ? _matrule->_opType
aoqi@0 201 : _matrule->_rChild->_opType;
aoqi@0 202 }
aoqi@0 203
aoqi@0 204 // Recursive check on all operands' match rules in my match rule
aoqi@0 205 bool InstructForm::is_pinned(FormDict &globals) {
aoqi@0 206 if ( ! _matrule) return false;
aoqi@0 207
aoqi@0 208 int index = 0;
aoqi@0 209 if (_matrule->find_type("Goto", index)) return true;
aoqi@0 210 if (_matrule->find_type("If", index)) return true;
aoqi@0 211 if (_matrule->find_type("CountedLoopEnd",index)) return true;
aoqi@0 212 if (_matrule->find_type("Return", index)) return true;
aoqi@0 213 if (_matrule->find_type("Rethrow", index)) return true;
aoqi@0 214 if (_matrule->find_type("TailCall", index)) return true;
aoqi@0 215 if (_matrule->find_type("TailJump", index)) return true;
aoqi@0 216 if (_matrule->find_type("Halt", index)) return true;
aoqi@0 217 if (_matrule->find_type("Jump", index)) return true;
aoqi@0 218
aoqi@0 219 return is_parm(globals);
aoqi@0 220 }
aoqi@0 221
aoqi@0 222 // Recursive check on all operands' match rules in my match rule
aoqi@0 223 bool InstructForm::is_projection(FormDict &globals) {
aoqi@0 224 if ( ! _matrule) return false;
aoqi@0 225
aoqi@0 226 int index = 0;
aoqi@0 227 if (_matrule->find_type("Goto", index)) return true;
aoqi@0 228 if (_matrule->find_type("Return", index)) return true;
aoqi@0 229 if (_matrule->find_type("Rethrow", index)) return true;
aoqi@0 230 if (_matrule->find_type("TailCall",index)) return true;
aoqi@0 231 if (_matrule->find_type("TailJump",index)) return true;
aoqi@0 232 if (_matrule->find_type("Halt", index)) return true;
aoqi@0 233
aoqi@0 234 return false;
aoqi@0 235 }
aoqi@0 236
aoqi@0 237 // Recursive check on all operands' match rules in my match rule
aoqi@0 238 bool InstructForm::is_parm(FormDict &globals) {
aoqi@0 239 if ( ! _matrule) return false;
aoqi@0 240
aoqi@0 241 int index = 0;
aoqi@0 242 if (_matrule->find_type("Parm",index)) return true;
aoqi@0 243
aoqi@0 244 return false;
aoqi@0 245 }
aoqi@0 246
aoqi@0 247 bool InstructForm::is_ideal_negD() const {
aoqi@0 248 return (_matrule && _matrule->_rChild && strcmp(_matrule->_rChild->_opType, "NegD") == 0);
aoqi@0 249 }
aoqi@0 250
aoqi@0 251 // Return 'true' if this instruction matches an ideal 'Copy*' node
aoqi@0 252 int InstructForm::is_ideal_copy() const {
aoqi@0 253 return _matrule ? _matrule->is_ideal_copy() : 0;
aoqi@0 254 }
aoqi@0 255
aoqi@0 256 // Return 'true' if this instruction is too complex to rematerialize.
aoqi@0 257 int InstructForm::is_expensive() const {
aoqi@0 258 // We can prove it is cheap if it has an empty encoding.
aoqi@0 259 // This helps with platform-specific nops like ThreadLocal and RoundFloat.
aoqi@0 260 if (is_empty_encoding())
aoqi@0 261 return 0;
aoqi@0 262
aoqi@0 263 if (is_tls_instruction())
aoqi@0 264 return 1;
aoqi@0 265
aoqi@0 266 if (_matrule == NULL) return 0;
aoqi@0 267
aoqi@0 268 return _matrule->is_expensive();
aoqi@0 269 }
aoqi@0 270
aoqi@0 271 // Has an empty encoding if _size is a constant zero or there
aoqi@0 272 // are no ins_encode tokens.
aoqi@0 273 int InstructForm::is_empty_encoding() const {
aoqi@0 274 if (_insencode != NULL) {
aoqi@0 275 _insencode->reset();
aoqi@0 276 if (_insencode->encode_class_iter() == NULL) {
aoqi@0 277 return 1;
aoqi@0 278 }
aoqi@0 279 }
aoqi@0 280 if (_size != NULL && strcmp(_size, "0") == 0) {
aoqi@0 281 return 1;
aoqi@0 282 }
aoqi@0 283 return 0;
aoqi@0 284 }
aoqi@0 285
aoqi@0 286 int InstructForm::is_tls_instruction() const {
aoqi@0 287 if (_ident != NULL &&
aoqi@0 288 ( ! strcmp( _ident,"tlsLoadP") ||
aoqi@0 289 ! strncmp(_ident,"tlsLoadP_",9)) ) {
aoqi@0 290 return 1;
aoqi@0 291 }
aoqi@0 292
aoqi@0 293 if (_matrule != NULL && _insencode != NULL) {
aoqi@0 294 const char* opType = _matrule->_opType;
aoqi@0 295 if (strcmp(opType, "Set")==0)
aoqi@0 296 opType = _matrule->_rChild->_opType;
aoqi@0 297 if (strcmp(opType,"ThreadLocal")==0) {
aoqi@0 298 fprintf(stderr, "Warning: ThreadLocal instruction %s should be named 'tlsLoadP_*'\n",
aoqi@0 299 (_ident == NULL ? "NULL" : _ident));
aoqi@0 300 return 1;
aoqi@0 301 }
aoqi@0 302 }
aoqi@0 303
aoqi@0 304 return 0;
aoqi@0 305 }
aoqi@0 306
aoqi@0 307
aoqi@0 308 // Return 'true' if this instruction matches an ideal 'If' node
aoqi@0 309 bool InstructForm::is_ideal_if() const {
aoqi@0 310 if( _matrule == NULL ) return false;
aoqi@0 311
aoqi@0 312 return _matrule->is_ideal_if();
aoqi@0 313 }
aoqi@0 314
aoqi@0 315 // Return 'true' if this instruction matches an ideal 'FastLock' node
aoqi@0 316 bool InstructForm::is_ideal_fastlock() const {
aoqi@0 317 if( _matrule == NULL ) return false;
aoqi@0 318
aoqi@0 319 return _matrule->is_ideal_fastlock();
aoqi@0 320 }
aoqi@0 321
aoqi@0 322 // Return 'true' if this instruction matches an ideal 'MemBarXXX' node
aoqi@0 323 bool InstructForm::is_ideal_membar() const {
aoqi@0 324 if( _matrule == NULL ) return false;
aoqi@0 325
aoqi@0 326 return _matrule->is_ideal_membar();
aoqi@0 327 }
aoqi@0 328
aoqi@0 329 // Return 'true' if this instruction matches an ideal 'LoadPC' node
aoqi@0 330 bool InstructForm::is_ideal_loadPC() const {
aoqi@0 331 if( _matrule == NULL ) return false;
aoqi@0 332
aoqi@0 333 return _matrule->is_ideal_loadPC();
aoqi@0 334 }
aoqi@0 335
aoqi@0 336 // Return 'true' if this instruction matches an ideal 'Box' node
aoqi@0 337 bool InstructForm::is_ideal_box() const {
aoqi@0 338 if( _matrule == NULL ) return false;
aoqi@0 339
aoqi@0 340 return _matrule->is_ideal_box();
aoqi@0 341 }
aoqi@0 342
aoqi@0 343 // Return 'true' if this instruction matches an ideal 'Goto' node
aoqi@0 344 bool InstructForm::is_ideal_goto() const {
aoqi@0 345 if( _matrule == NULL ) return false;
aoqi@0 346
aoqi@0 347 return _matrule->is_ideal_goto();
aoqi@0 348 }
aoqi@0 349
aoqi@0 350 // Return 'true' if this instruction matches an ideal 'Jump' node
aoqi@0 351 bool InstructForm::is_ideal_jump() const {
aoqi@0 352 if( _matrule == NULL ) return false;
aoqi@0 353
aoqi@0 354 return _matrule->is_ideal_jump();
aoqi@0 355 }
aoqi@0 356
aoqi@0 357 // Return 'true' if instruction matches ideal 'If' | 'Goto' | 'CountedLoopEnd'
aoqi@0 358 bool InstructForm::is_ideal_branch() const {
aoqi@0 359 if( _matrule == NULL ) return false;
aoqi@0 360
aoqi@0 361 return _matrule->is_ideal_if() || _matrule->is_ideal_goto();
aoqi@0 362 }
aoqi@0 363
aoqi@0 364
aoqi@0 365 // Return 'true' if this instruction matches an ideal 'Return' node
aoqi@0 366 bool InstructForm::is_ideal_return() const {
aoqi@0 367 if( _matrule == NULL ) return false;
aoqi@0 368
aoqi@0 369 // Check MatchRule to see if the first entry is the ideal "Return" node
aoqi@0 370 int index = 0;
aoqi@0 371 if (_matrule->find_type("Return",index)) return true;
aoqi@0 372 if (_matrule->find_type("Rethrow",index)) return true;
aoqi@0 373 if (_matrule->find_type("TailCall",index)) return true;
aoqi@0 374 if (_matrule->find_type("TailJump",index)) return true;
aoqi@0 375
aoqi@0 376 return false;
aoqi@0 377 }
aoqi@0 378
aoqi@0 379 // Return 'true' if this instruction matches an ideal 'Halt' node
aoqi@0 380 bool InstructForm::is_ideal_halt() const {
aoqi@0 381 int index = 0;
aoqi@0 382 return _matrule && _matrule->find_type("Halt",index);
aoqi@0 383 }
aoqi@0 384
aoqi@0 385 // Return 'true' if this instruction matches an ideal 'SafePoint' node
aoqi@0 386 bool InstructForm::is_ideal_safepoint() const {
aoqi@0 387 int index = 0;
aoqi@0 388 return _matrule && _matrule->find_type("SafePoint",index);
aoqi@0 389 }
aoqi@0 390
aoqi@0 391 // Return 'true' if this instruction matches an ideal 'Nop' node
aoqi@0 392 bool InstructForm::is_ideal_nop() const {
aoqi@0 393 return _ident && _ident[0] == 'N' && _ident[1] == 'o' && _ident[2] == 'p' && _ident[3] == '_';
aoqi@0 394 }
aoqi@0 395
aoqi@0 396 bool InstructForm::is_ideal_control() const {
aoqi@0 397 if ( ! _matrule) return false;
aoqi@0 398
aoqi@0 399 return is_ideal_return() || is_ideal_branch() || _matrule->is_ideal_jump() || is_ideal_halt();
aoqi@0 400 }
aoqi@0 401
aoqi@0 402 // Return 'true' if this instruction matches an ideal 'Call' node
aoqi@0 403 Form::CallType InstructForm::is_ideal_call() const {
aoqi@0 404 if( _matrule == NULL ) return Form::invalid_type;
aoqi@0 405
aoqi@0 406 // Check MatchRule to see if the first entry is the ideal "Call" node
aoqi@0 407 int idx = 0;
aoqi@0 408 if(_matrule->find_type("CallStaticJava",idx)) return Form::JAVA_STATIC;
aoqi@0 409 idx = 0;
aoqi@0 410 if(_matrule->find_type("Lock",idx)) return Form::JAVA_STATIC;
aoqi@0 411 idx = 0;
aoqi@0 412 if(_matrule->find_type("Unlock",idx)) return Form::JAVA_STATIC;
aoqi@0 413 idx = 0;
aoqi@0 414 if(_matrule->find_type("CallDynamicJava",idx)) return Form::JAVA_DYNAMIC;
aoqi@0 415 idx = 0;
aoqi@0 416 if(_matrule->find_type("CallRuntime",idx)) return Form::JAVA_RUNTIME;
aoqi@0 417 idx = 0;
aoqi@0 418 if(_matrule->find_type("CallLeaf",idx)) return Form::JAVA_LEAF;
aoqi@0 419 idx = 0;
aoqi@0 420 if(_matrule->find_type("CallLeafNoFP",idx)) return Form::JAVA_LEAF;
aoqi@0 421 idx = 0;
aoqi@0 422
aoqi@0 423 return Form::invalid_type;
aoqi@0 424 }
aoqi@0 425
aoqi@0 426 // Return 'true' if this instruction matches an ideal 'Load?' node
aoqi@0 427 Form::DataType InstructForm::is_ideal_load() const {
aoqi@0 428 if( _matrule == NULL ) return Form::none;
aoqi@0 429
aoqi@0 430 return _matrule->is_ideal_load();
aoqi@0 431 }
aoqi@0 432
aoqi@0 433 // Return 'true' if this instruction matches an ideal 'LoadKlass' node
aoqi@0 434 bool InstructForm::skip_antidep_check() const {
aoqi@0 435 if( _matrule == NULL ) return false;
aoqi@0 436
aoqi@0 437 return _matrule->skip_antidep_check();
aoqi@0 438 }
aoqi@0 439
aoqi@0 440 // Return 'true' if this instruction matches an ideal 'Load?' node
aoqi@0 441 Form::DataType InstructForm::is_ideal_store() const {
aoqi@0 442 if( _matrule == NULL ) return Form::none;
aoqi@0 443
aoqi@0 444 return _matrule->is_ideal_store();
aoqi@0 445 }
aoqi@0 446
aoqi@0 447 // Return 'true' if this instruction matches an ideal vector node
aoqi@0 448 bool InstructForm::is_vector() const {
aoqi@0 449 if( _matrule == NULL ) return false;
aoqi@0 450
aoqi@0 451 return _matrule->is_vector();
aoqi@0 452 }
aoqi@0 453
aoqi@0 454
aoqi@0 455 // Return the input register that must match the output register
aoqi@0 456 // If this is not required, return 0
aoqi@0 457 uint InstructForm::two_address(FormDict &globals) {
aoqi@0 458 uint matching_input = 0;
aoqi@0 459 if(_components.count() == 0) return 0;
aoqi@0 460
aoqi@0 461 _components.reset();
aoqi@0 462 Component *comp = _components.iter();
aoqi@0 463 // Check if there is a DEF
aoqi@0 464 if( comp->isa(Component::DEF) ) {
aoqi@0 465 // Check that this is a register
aoqi@0 466 const char *def_type = comp->_type;
aoqi@0 467 const Form *form = globals[def_type];
aoqi@0 468 OperandForm *op = form->is_operand();
aoqi@0 469 if( op ) {
aoqi@0 470 if( op->constrained_reg_class() != NULL &&
aoqi@0 471 op->interface_type(globals) == Form::register_interface ) {
aoqi@0 472 // Remember the local name for equality test later
aoqi@0 473 const char *def_name = comp->_name;
aoqi@0 474 // Check if a component has the same name and is a USE
aoqi@0 475 do {
aoqi@0 476 if( comp->isa(Component::USE) && strcmp(comp->_name,def_name)==0 ) {
aoqi@0 477 return operand_position_format(def_name);
aoqi@0 478 }
aoqi@0 479 } while( (comp = _components.iter()) != NULL);
aoqi@0 480 }
aoqi@0 481 }
aoqi@0 482 }
aoqi@0 483
aoqi@0 484 return 0;
aoqi@0 485 }
aoqi@0 486
aoqi@0 487
aoqi@0 488 // when chaining a constant to an instruction, returns 'true' and sets opType
aoqi@0 489 Form::DataType InstructForm::is_chain_of_constant(FormDict &globals) {
aoqi@0 490 const char *dummy = NULL;
aoqi@0 491 const char *dummy2 = NULL;
aoqi@0 492 return is_chain_of_constant(globals, dummy, dummy2);
aoqi@0 493 }
aoqi@0 494 Form::DataType InstructForm::is_chain_of_constant(FormDict &globals,
aoqi@0 495 const char * &opTypeParam) {
aoqi@0 496 const char *result = NULL;
aoqi@0 497
aoqi@0 498 return is_chain_of_constant(globals, opTypeParam, result);
aoqi@0 499 }
aoqi@0 500
aoqi@0 501 Form::DataType InstructForm::is_chain_of_constant(FormDict &globals,
aoqi@0 502 const char * &opTypeParam, const char * &resultParam) {
aoqi@0 503 Form::DataType data_type = Form::none;
aoqi@0 504 if ( ! _matrule) return data_type;
aoqi@0 505
aoqi@0 506 // !!!!!
aoqi@0 507 // The source of the chain rule is 'position = 1'
aoqi@0 508 uint position = 1;
aoqi@0 509 const char *result = NULL;
aoqi@0 510 const char *name = NULL;
aoqi@0 511 const char *opType = NULL;
aoqi@0 512 // Here base_operand is looking for an ideal type to be returned (opType).
aoqi@0 513 if ( _matrule->is_chain_rule(globals)
aoqi@0 514 && _matrule->base_operand(position, globals, result, name, opType) ) {
aoqi@0 515 data_type = ideal_to_const_type(opType);
aoqi@0 516
aoqi@0 517 // if it isn't an ideal constant type, just return
aoqi@0 518 if ( data_type == Form::none ) return data_type;
aoqi@0 519
aoqi@0 520 // Ideal constant types also adjust the opType parameter.
aoqi@0 521 resultParam = result;
aoqi@0 522 opTypeParam = opType;
aoqi@0 523 return data_type;
aoqi@0 524 }
aoqi@0 525
aoqi@0 526 return data_type;
aoqi@0 527 }
aoqi@0 528
aoqi@0 529 // Check if a simple chain rule
aoqi@0 530 bool InstructForm::is_simple_chain_rule(FormDict &globals) const {
aoqi@0 531 if( _matrule && _matrule->sets_result()
aoqi@0 532 && _matrule->_rChild->_lChild == NULL
aoqi@0 533 && globals[_matrule->_rChild->_opType]
aoqi@0 534 && globals[_matrule->_rChild->_opType]->is_opclass() ) {
aoqi@0 535 return true;
aoqi@0 536 }
aoqi@0 537 return false;
aoqi@0 538 }
aoqi@0 539
aoqi@0 540 // check for structural rematerialization
aoqi@0 541 bool InstructForm::rematerialize(FormDict &globals, RegisterForm *registers ) {
aoqi@0 542 bool rematerialize = false;
aoqi@0 543
aoqi@0 544 Form::DataType data_type = is_chain_of_constant(globals);
aoqi@0 545 if( data_type != Form::none )
aoqi@0 546 rematerialize = true;
aoqi@0 547
aoqi@0 548 // Constants
aoqi@0 549 if( _components.count() == 1 && _components[0]->is(Component::USE_DEF) )
aoqi@0 550 rematerialize = true;
aoqi@0 551
aoqi@0 552 // Pseudo-constants (values easily available to the runtime)
aoqi@0 553 if (is_empty_encoding() && is_tls_instruction())
aoqi@0 554 rematerialize = true;
aoqi@0 555
aoqi@0 556 // 1-input, 1-output, such as copies or increments.
aoqi@0 557 if( _components.count() == 2 &&
aoqi@0 558 _components[0]->is(Component::DEF) &&
aoqi@0 559 _components[1]->isa(Component::USE) )
aoqi@0 560 rematerialize = true;
aoqi@0 561
aoqi@0 562 // Check for an ideal 'Load?' and eliminate rematerialize option
aoqi@0 563 if ( is_ideal_load() != Form::none || // Ideal load? Do not rematerialize
aoqi@0 564 is_ideal_copy() != Form::none || // Ideal copy? Do not rematerialize
aoqi@0 565 is_expensive() != Form::none) { // Expensive? Do not rematerialize
aoqi@0 566 rematerialize = false;
aoqi@0 567 }
aoqi@0 568
aoqi@0 569 // Always rematerialize the flags. They are more expensive to save &
aoqi@0 570 // restore than to recompute (and possibly spill the compare's inputs).
aoqi@0 571 if( _components.count() >= 1 ) {
aoqi@0 572 Component *c = _components[0];
aoqi@0 573 const Form *form = globals[c->_type];
aoqi@0 574 OperandForm *opform = form->is_operand();
aoqi@0 575 if( opform ) {
aoqi@0 576 // Avoid the special stack_slots register classes
aoqi@0 577 const char *rc_name = opform->constrained_reg_class();
aoqi@0 578 if( rc_name ) {
aoqi@0 579 if( strcmp(rc_name,"stack_slots") ) {
aoqi@0 580 // Check for ideal_type of RegFlags
aoqi@0 581 const char *type = opform->ideal_type( globals, registers );
aoqi@0 582 if( (type != NULL) && !strcmp(type, "RegFlags") )
aoqi@0 583 rematerialize = true;
aoqi@0 584 } else
aoqi@0 585 rematerialize = false; // Do not rematerialize things target stk
aoqi@0 586 }
aoqi@0 587 }
aoqi@0 588 }
aoqi@0 589
aoqi@0 590 return rematerialize;
aoqi@0 591 }
aoqi@0 592
aoqi@0 593 // loads from memory, so must check for anti-dependence
aoqi@0 594 bool InstructForm::needs_anti_dependence_check(FormDict &globals) const {
aoqi@0 595 if ( skip_antidep_check() ) return false;
aoqi@0 596
aoqi@0 597 // Machine independent loads must be checked for anti-dependences
aoqi@0 598 if( is_ideal_load() != Form::none ) return true;
aoqi@0 599
aoqi@0 600 // !!!!! !!!!! !!!!!
aoqi@0 601 // TEMPORARY
aoqi@0 602 // if( is_simple_chain_rule(globals) ) return false;
aoqi@0 603
aoqi@0 604 // String.(compareTo/equals/indexOf) and Arrays.equals use many memorys edges,
aoqi@0 605 // but writes none
aoqi@0 606 if( _matrule && _matrule->_rChild &&
aoqi@0 607 ( strcmp(_matrule->_rChild->_opType,"StrComp" )==0 ||
aoqi@0 608 strcmp(_matrule->_rChild->_opType,"StrEquals" )==0 ||
aoqi@0 609 strcmp(_matrule->_rChild->_opType,"StrIndexOf" )==0 ||
aoqi@0 610 strcmp(_matrule->_rChild->_opType,"AryEq" )==0 ))
aoqi@0 611 return true;
aoqi@0 612
aoqi@0 613 // Check if instruction has a USE of a memory operand class, but no defs
aoqi@0 614 bool USE_of_memory = false;
aoqi@0 615 bool DEF_of_memory = false;
aoqi@0 616 Component *comp = NULL;
aoqi@0 617 ComponentList &components = (ComponentList &)_components;
aoqi@0 618
aoqi@0 619 components.reset();
aoqi@0 620 while( (comp = components.iter()) != NULL ) {
aoqi@0 621 const Form *form = globals[comp->_type];
aoqi@0 622 if( !form ) continue;
aoqi@0 623 OpClassForm *op = form->is_opclass();
aoqi@0 624 if( !op ) continue;
aoqi@0 625 if( form->interface_type(globals) == Form::memory_interface ) {
aoqi@0 626 if( comp->isa(Component::USE) ) USE_of_memory = true;
aoqi@0 627 if( comp->isa(Component::DEF) ) {
aoqi@0 628 OperandForm *oper = form->is_operand();
aoqi@0 629 if( oper && oper->is_user_name_for_sReg() ) {
aoqi@0 630 // Stack slots are unaliased memory handled by allocator
aoqi@0 631 oper = oper; // debug stopping point !!!!!
aoqi@0 632 } else {
aoqi@0 633 DEF_of_memory = true;
aoqi@0 634 }
aoqi@0 635 }
aoqi@0 636 }
aoqi@0 637 }
aoqi@0 638 return (USE_of_memory && !DEF_of_memory);
aoqi@0 639 }
aoqi@0 640
aoqi@0 641
aoqi@0 642 bool InstructForm::is_wide_memory_kill(FormDict &globals) const {
aoqi@0 643 if( _matrule == NULL ) return false;
aoqi@0 644 if( !_matrule->_opType ) return false;
aoqi@0 645
aoqi@0 646 if( strcmp(_matrule->_opType,"MemBarRelease") == 0 ) return true;
aoqi@0 647 if( strcmp(_matrule->_opType,"MemBarAcquire") == 0 ) return true;
aoqi@0 648 if( strcmp(_matrule->_opType,"MemBarReleaseLock") == 0 ) return true;
aoqi@0 649 if( strcmp(_matrule->_opType,"MemBarAcquireLock") == 0 ) return true;
aoqi@0 650 if( strcmp(_matrule->_opType,"MemBarStoreStore") == 0 ) return true;
aoqi@0 651 if( strcmp(_matrule->_opType,"StoreFence") == 0 ) return true;
aoqi@0 652 if( strcmp(_matrule->_opType,"LoadFence") == 0 ) return true;
aoqi@0 653
aoqi@0 654 return false;
aoqi@0 655 }
aoqi@0 656
aoqi@0 657 int InstructForm::memory_operand(FormDict &globals) const {
aoqi@0 658 // Machine independent loads must be checked for anti-dependences
aoqi@0 659 // Check if instruction has a USE of a memory operand class, or a def.
aoqi@0 660 int USE_of_memory = 0;
aoqi@0 661 int DEF_of_memory = 0;
aoqi@0 662 const char* last_memory_DEF = NULL; // to test DEF/USE pairing in asserts
aoqi@0 663 const char* last_memory_USE = NULL;
aoqi@0 664 Component *unique = NULL;
aoqi@0 665 Component *comp = NULL;
aoqi@0 666 ComponentList &components = (ComponentList &)_components;
aoqi@0 667
aoqi@0 668 components.reset();
aoqi@0 669 while( (comp = components.iter()) != NULL ) {
aoqi@0 670 const Form *form = globals[comp->_type];
aoqi@0 671 if( !form ) continue;
aoqi@0 672 OpClassForm *op = form->is_opclass();
aoqi@0 673 if( !op ) continue;
aoqi@0 674 if( op->stack_slots_only(globals) ) continue;
aoqi@0 675 if( form->interface_type(globals) == Form::memory_interface ) {
aoqi@0 676 if( comp->isa(Component::DEF) ) {
aoqi@0 677 last_memory_DEF = comp->_name;
aoqi@0 678 DEF_of_memory++;
aoqi@0 679 unique = comp;
aoqi@0 680 } else if( comp->isa(Component::USE) ) {
aoqi@0 681 if( last_memory_DEF != NULL ) {
aoqi@0 682 assert(0 == strcmp(last_memory_DEF, comp->_name), "every memory DEF is followed by a USE of the same name");
aoqi@0 683 last_memory_DEF = NULL;
aoqi@0 684 }
aoqi@0 685 // Handles same memory being used multiple times in the case of BMI1 instructions.
aoqi@0 686 if (last_memory_USE != NULL) {
aoqi@0 687 if (strcmp(comp->_name, last_memory_USE) != 0) {
aoqi@0 688 USE_of_memory++;
aoqi@0 689 }
aoqi@0 690 } else {
aoqi@0 691 USE_of_memory++;
aoqi@0 692 }
aoqi@0 693 last_memory_USE = comp->_name;
aoqi@0 694
aoqi@0 695 if (DEF_of_memory == 0) // defs take precedence
aoqi@0 696 unique = comp;
aoqi@0 697 } else {
aoqi@0 698 assert(last_memory_DEF == NULL, "unpaired memory DEF");
aoqi@0 699 }
aoqi@0 700 }
aoqi@0 701 }
aoqi@0 702 assert(last_memory_DEF == NULL, "unpaired memory DEF");
aoqi@0 703 assert(USE_of_memory >= DEF_of_memory, "unpaired memory DEF");
aoqi@0 704 USE_of_memory -= DEF_of_memory; // treat paired DEF/USE as one occurrence
aoqi@0 705 if( (USE_of_memory + DEF_of_memory) > 0 ) {
aoqi@0 706 if( is_simple_chain_rule(globals) ) {
aoqi@0 707 //fprintf(stderr, "Warning: chain rule is not really a memory user.\n");
aoqi@0 708 //((InstructForm*)this)->dump();
aoqi@0 709 // Preceding code prints nothing on sparc and these insns on intel:
aoqi@0 710 // leaP8 leaP32 leaPIdxOff leaPIdxScale leaPIdxScaleOff leaP8 leaP32
aoqi@0 711 // leaPIdxOff leaPIdxScale leaPIdxScaleOff
aoqi@0 712 return NO_MEMORY_OPERAND;
aoqi@0 713 }
aoqi@0 714
aoqi@0 715 if( DEF_of_memory == 1 ) {
aoqi@0 716 assert(unique != NULL, "");
aoqi@0 717 if( USE_of_memory == 0 ) {
aoqi@0 718 // unique def, no uses
aoqi@0 719 } else {
aoqi@0 720 // // unique def, some uses
aoqi@0 721 // // must return bottom unless all uses match def
aoqi@0 722 // unique = NULL;
aoqi@0 723 }
aoqi@0 724 } else if( DEF_of_memory > 0 ) {
aoqi@0 725 // multiple defs, don't care about uses
aoqi@0 726 unique = NULL;
aoqi@0 727 } else if( USE_of_memory == 1) {
aoqi@0 728 // unique use, no defs
aoqi@0 729 assert(unique != NULL, "");
aoqi@0 730 } else if( USE_of_memory > 0 ) {
aoqi@0 731 // multiple uses, no defs
aoqi@0 732 unique = NULL;
aoqi@0 733 } else {
aoqi@0 734 assert(false, "bad case analysis");
aoqi@0 735 }
aoqi@0 736 // process the unique DEF or USE, if there is one
aoqi@0 737 if( unique == NULL ) {
aoqi@0 738 return MANY_MEMORY_OPERANDS;
aoqi@0 739 } else {
aoqi@0 740 int pos = components.operand_position(unique->_name);
aoqi@0 741 if( unique->isa(Component::DEF) ) {
aoqi@0 742 pos += 1; // get corresponding USE from DEF
aoqi@0 743 }
aoqi@0 744 assert(pos >= 1, "I was just looking at it!");
aoqi@0 745 return pos;
aoqi@0 746 }
aoqi@0 747 }
aoqi@0 748
aoqi@0 749 // missed the memory op??
aoqi@0 750 if( true ) { // %%% should not be necessary
aoqi@0 751 if( is_ideal_store() != Form::none ) {
aoqi@0 752 fprintf(stderr, "Warning: cannot find memory opnd in instr.\n");
aoqi@0 753 ((InstructForm*)this)->dump();
aoqi@0 754 // pretend it has multiple defs and uses
aoqi@0 755 return MANY_MEMORY_OPERANDS;
aoqi@0 756 }
aoqi@0 757 if( is_ideal_load() != Form::none ) {
aoqi@0 758 fprintf(stderr, "Warning: cannot find memory opnd in instr.\n");
aoqi@0 759 ((InstructForm*)this)->dump();
aoqi@0 760 // pretend it has multiple uses and no defs
aoqi@0 761 return MANY_MEMORY_OPERANDS;
aoqi@0 762 }
aoqi@0 763 }
aoqi@0 764
aoqi@0 765 return NO_MEMORY_OPERAND;
aoqi@0 766 }
aoqi@0 767
aoqi@0 768
aoqi@0 769 // This instruction captures the machine-independent bottom_type
aoqi@0 770 // Expected use is for pointer vs oop determination for LoadP
aoqi@0 771 bool InstructForm::captures_bottom_type(FormDict &globals) const {
aoqi@0 772 if( _matrule && _matrule->_rChild &&
aoqi@0 773 (!strcmp(_matrule->_rChild->_opType,"CastPP") || // new result type
aoqi@0 774 !strcmp(_matrule->_rChild->_opType,"CastX2P") || // new result type
aoqi@0 775 !strcmp(_matrule->_rChild->_opType,"DecodeN") ||
aoqi@0 776 !strcmp(_matrule->_rChild->_opType,"EncodeP") ||
aoqi@0 777 !strcmp(_matrule->_rChild->_opType,"DecodeNKlass") ||
aoqi@0 778 !strcmp(_matrule->_rChild->_opType,"EncodePKlass") ||
aoqi@0 779 !strcmp(_matrule->_rChild->_opType,"LoadN") ||
aoqi@0 780 !strcmp(_matrule->_rChild->_opType,"LoadNKlass") ||
aoqi@0 781 !strcmp(_matrule->_rChild->_opType,"CreateEx") || // type of exception
aoqi@0 782 !strcmp(_matrule->_rChild->_opType,"CheckCastPP") ||
aoqi@0 783 !strcmp(_matrule->_rChild->_opType,"GetAndSetP") ||
aoqi@0 784 !strcmp(_matrule->_rChild->_opType,"GetAndSetN")) ) return true;
aoqi@0 785 else if ( is_ideal_load() == Form::idealP ) return true;
aoqi@0 786 else if ( is_ideal_store() != Form::none ) return true;
aoqi@0 787
aoqi@0 788 if (needs_base_oop_edge(globals)) return true;
aoqi@0 789
aoqi@0 790 if (is_vector()) return true;
aoqi@0 791 if (is_mach_constant()) return true;
aoqi@0 792
aoqi@0 793 return false;
aoqi@0 794 }
aoqi@0 795
aoqi@0 796
aoqi@0 797 // Access instr_cost attribute or return NULL.
aoqi@0 798 const char* InstructForm::cost() {
aoqi@0 799 for (Attribute* cur = _attribs; cur != NULL; cur = (Attribute*)cur->_next) {
aoqi@0 800 if( strcmp(cur->_ident,AttributeForm::_ins_cost) == 0 ) {
aoqi@0 801 return cur->_val;
aoqi@0 802 }
aoqi@0 803 }
aoqi@0 804 return NULL;
aoqi@0 805 }
aoqi@0 806
aoqi@0 807 // Return count of top-level operands.
aoqi@0 808 uint InstructForm::num_opnds() {
aoqi@0 809 int num_opnds = _components.num_operands();
aoqi@0 810
aoqi@0 811 // Need special handling for matching some ideal nodes
aoqi@0 812 // i.e. Matching a return node
aoqi@0 813 /*
aoqi@0 814 if( _matrule ) {
aoqi@0 815 if( strcmp(_matrule->_opType,"Return" )==0 ||
aoqi@0 816 strcmp(_matrule->_opType,"Halt" )==0 )
aoqi@0 817 return 3;
aoqi@0 818 }
aoqi@0 819 */
aoqi@0 820 return num_opnds;
aoqi@0 821 }
aoqi@0 822
aoqi@0 823 const char* InstructForm::opnd_ident(int idx) {
aoqi@0 824 return _components.at(idx)->_name;
aoqi@0 825 }
aoqi@0 826
aoqi@0 827 const char* InstructForm::unique_opnd_ident(uint idx) {
aoqi@0 828 uint i;
aoqi@0 829 for (i = 1; i < num_opnds(); ++i) {
aoqi@0 830 if (unique_opnds_idx(i) == idx) {
aoqi@0 831 break;
aoqi@0 832 }
aoqi@0 833 }
aoqi@0 834 return (_components.at(i) != NULL) ? _components.at(i)->_name : "";
aoqi@0 835 }
aoqi@0 836
aoqi@0 837 // Return count of unmatched operands.
aoqi@0 838 uint InstructForm::num_post_match_opnds() {
aoqi@0 839 uint num_post_match_opnds = _components.count();
aoqi@0 840 uint num_match_opnds = _components.match_count();
aoqi@0 841 num_post_match_opnds = num_post_match_opnds - num_match_opnds;
aoqi@0 842
aoqi@0 843 return num_post_match_opnds;
aoqi@0 844 }
aoqi@0 845
aoqi@0 846 // Return the number of leaves below this complex operand
aoqi@0 847 uint InstructForm::num_consts(FormDict &globals) const {
aoqi@0 848 if ( ! _matrule) return 0;
aoqi@0 849
aoqi@0 850 // This is a recursive invocation on all operands in the matchrule
aoqi@0 851 return _matrule->num_consts(globals);
aoqi@0 852 }
aoqi@0 853
aoqi@0 854 // Constants in match rule with specified type
aoqi@0 855 uint InstructForm::num_consts(FormDict &globals, Form::DataType type) const {
aoqi@0 856 if ( ! _matrule) return 0;
aoqi@0 857
aoqi@0 858 // This is a recursive invocation on all operands in the matchrule
aoqi@0 859 return _matrule->num_consts(globals, type);
aoqi@0 860 }
aoqi@0 861
aoqi@0 862
aoqi@0 863 // Return the register class associated with 'leaf'.
aoqi@0 864 const char *InstructForm::out_reg_class(FormDict &globals) {
aoqi@0 865 assert( false, "InstructForm::out_reg_class(FormDict &globals); Not Implemented");
aoqi@0 866
aoqi@0 867 return NULL;
aoqi@0 868 }
aoqi@0 869
aoqi@0 870
aoqi@0 871
aoqi@0 872 // Lookup the starting position of inputs we are interested in wrt. ideal nodes
aoqi@0 873 uint InstructForm::oper_input_base(FormDict &globals) {
aoqi@0 874 if( !_matrule ) return 1; // Skip control for most nodes
aoqi@0 875
aoqi@0 876 // Need special handling for matching some ideal nodes
aoqi@0 877 // i.e. Matching a return node
aoqi@0 878 if( strcmp(_matrule->_opType,"Return" )==0 ||
aoqi@0 879 strcmp(_matrule->_opType,"Rethrow" )==0 ||
aoqi@0 880 strcmp(_matrule->_opType,"TailCall" )==0 ||
aoqi@0 881 strcmp(_matrule->_opType,"TailJump" )==0 ||
aoqi@0 882 strcmp(_matrule->_opType,"SafePoint" )==0 ||
aoqi@0 883 strcmp(_matrule->_opType,"Halt" )==0 )
aoqi@0 884 return AdlcVMDeps::Parms; // Skip the machine-state edges
aoqi@0 885
aoqi@0 886 if( _matrule->_rChild &&
aoqi@0 887 ( strcmp(_matrule->_rChild->_opType,"AryEq" )==0 ||
aoqi@0 888 strcmp(_matrule->_rChild->_opType,"StrComp" )==0 ||
aoqi@0 889 strcmp(_matrule->_rChild->_opType,"StrEquals" )==0 ||
aoqi@0 890 strcmp(_matrule->_rChild->_opType,"StrIndexOf")==0 ||
aoqi@0 891 strcmp(_matrule->_rChild->_opType,"EncodeISOArray")==0)) {
aoqi@0 892 // String.(compareTo/equals/indexOf) and Arrays.equals
aoqi@0 893 // and sun.nio.cs.iso8859_1$Encoder.EncodeISOArray
aoqi@0 894 // take 1 control and 1 memory edges.
aoqi@0 895 return 2;
aoqi@0 896 }
aoqi@0 897
aoqi@0 898 // Check for handling of 'Memory' input/edge in the ideal world.
aoqi@0 899 // The AD file writer is shielded from knowledge of these edges.
aoqi@0 900 int base = 1; // Skip control
aoqi@0 901 base += _matrule->needs_ideal_memory_edge(globals);
aoqi@0 902
aoqi@0 903 // Also skip the base-oop value for uses of derived oops.
aoqi@0 904 // The AD file writer is shielded from knowledge of these edges.
aoqi@0 905 base += needs_base_oop_edge(globals);
aoqi@0 906
aoqi@0 907 return base;
aoqi@0 908 }
aoqi@0 909
aoqi@0 910 // This function determines the order of the MachOper in _opnds[]
aoqi@0 911 // by writing the operand names into the _components list.
aoqi@0 912 //
aoqi@0 913 // Implementation does not modify state of internal structures
aoqi@0 914 void InstructForm::build_components() {
aoqi@0 915 // Add top-level operands to the components
aoqi@0 916 if (_matrule) _matrule->append_components(_localNames, _components);
aoqi@0 917
aoqi@0 918 // Add parameters that "do not appear in match rule".
aoqi@0 919 bool has_temp = false;
aoqi@0 920 const char *name;
aoqi@0 921 const char *kill_name = NULL;
aoqi@0 922 for (_parameters.reset(); (name = _parameters.iter()) != NULL;) {
aoqi@0 923 OperandForm *opForm = (OperandForm*)_localNames[name];
aoqi@0 924
aoqi@0 925 Effect* e = NULL;
aoqi@0 926 {
aoqi@0 927 const Form* form = _effects[name];
aoqi@0 928 e = form ? form->is_effect() : NULL;
aoqi@0 929 }
aoqi@0 930
aoqi@0 931 if (e != NULL) {
aoqi@0 932 has_temp |= e->is(Component::TEMP);
aoqi@0 933
aoqi@0 934 // KILLs must be declared after any TEMPs because TEMPs are real
aoqi@0 935 // uses so their operand numbering must directly follow the real
aoqi@0 936 // inputs from the match rule. Fixing the numbering seems
aoqi@0 937 // complex so simply enforce the restriction during parse.
aoqi@0 938 if (kill_name != NULL &&
aoqi@0 939 e->isa(Component::TEMP) && !e->isa(Component::DEF)) {
aoqi@0 940 OperandForm* kill = (OperandForm*)_localNames[kill_name];
aoqi@0 941 globalAD->syntax_err(_linenum, "%s: %s %s must be at the end of the argument list\n",
aoqi@0 942 _ident, kill->_ident, kill_name);
aoqi@0 943 } else if (e->isa(Component::KILL) && !e->isa(Component::USE)) {
aoqi@0 944 kill_name = name;
aoqi@0 945 }
aoqi@0 946 }
aoqi@0 947
aoqi@0 948 const Component *component = _components.search(name);
aoqi@0 949 if ( component == NULL ) {
aoqi@0 950 if (e) {
aoqi@0 951 _components.insert(name, opForm->_ident, e->_use_def, false);
aoqi@0 952 component = _components.search(name);
aoqi@0 953 if (component->isa(Component::USE) && !component->isa(Component::TEMP) && _matrule) {
aoqi@0 954 const Form *form = globalAD->globalNames()[component->_type];
aoqi@0 955 assert( form, "component type must be a defined form");
aoqi@0 956 OperandForm *op = form->is_operand();
aoqi@0 957 if (op->_interface && op->_interface->is_RegInterface()) {
aoqi@0 958 globalAD->syntax_err(_linenum, "%s: illegal USE of non-input: %s %s\n",
aoqi@0 959 _ident, opForm->_ident, name);
aoqi@0 960 }
aoqi@0 961 }
aoqi@0 962 } else {
aoqi@0 963 // This would be a nice warning but it triggers in a few places in a benign way
aoqi@0 964 // if (_matrule != NULL && !expands()) {
aoqi@0 965 // globalAD->syntax_err(_linenum, "%s: %s %s not mentioned in effect or match rule\n",
aoqi@0 966 // _ident, opForm->_ident, name);
aoqi@0 967 // }
aoqi@0 968 _components.insert(name, opForm->_ident, Component::INVALID, false);
aoqi@0 969 }
aoqi@0 970 }
aoqi@0 971 else if (e) {
aoqi@0 972 // Component was found in the list
aoqi@0 973 // Check if there is a new effect that requires an extra component.
aoqi@0 974 // This happens when adding 'USE' to a component that is not yet one.
aoqi@0 975 if ((!component->isa( Component::USE) && ((e->_use_def & Component::USE) != 0))) {
aoqi@0 976 if (component->isa(Component::USE) && _matrule) {
aoqi@0 977 const Form *form = globalAD->globalNames()[component->_type];
aoqi@0 978 assert( form, "component type must be a defined form");
aoqi@0 979 OperandForm *op = form->is_operand();
aoqi@0 980 if (op->_interface && op->_interface->is_RegInterface()) {
aoqi@0 981 globalAD->syntax_err(_linenum, "%s: illegal USE of non-input: %s %s\n",
aoqi@0 982 _ident, opForm->_ident, name);
aoqi@0 983 }
aoqi@0 984 }
aoqi@0 985 _components.insert(name, opForm->_ident, e->_use_def, false);
aoqi@0 986 } else {
aoqi@0 987 Component *comp = (Component*)component;
aoqi@0 988 comp->promote_use_def_info(e->_use_def);
aoqi@0 989 }
aoqi@0 990 // Component positions are zero based.
aoqi@0 991 int pos = _components.operand_position(name);
aoqi@0 992 assert( ! (component->isa(Component::DEF) && (pos >= 1)),
aoqi@0 993 "Component::DEF can only occur in the first position");
aoqi@0 994 }
aoqi@0 995 }
aoqi@0 996
aoqi@0 997 // Resolving the interactions between expand rules and TEMPs would
aoqi@0 998 // be complex so simply disallow it.
aoqi@0 999 if (_matrule == NULL && has_temp) {
aoqi@0 1000 globalAD->syntax_err(_linenum, "%s: TEMPs without match rule isn't supported\n", _ident);
aoqi@0 1001 }
aoqi@0 1002
aoqi@0 1003 return;
aoqi@0 1004 }
aoqi@0 1005
aoqi@0 1006 // Return zero-based position in component list; -1 if not in list.
aoqi@0 1007 int InstructForm::operand_position(const char *name, int usedef) {
aoqi@0 1008 return unique_opnds_idx(_components.operand_position(name, usedef, this));
aoqi@0 1009 }
aoqi@0 1010
aoqi@0 1011 int InstructForm::operand_position_format(const char *name) {
aoqi@0 1012 return unique_opnds_idx(_components.operand_position_format(name, this));
aoqi@0 1013 }
aoqi@0 1014
aoqi@0 1015 // Return zero-based position in component list; -1 if not in list.
aoqi@0 1016 int InstructForm::label_position() {
aoqi@0 1017 return unique_opnds_idx(_components.label_position());
aoqi@0 1018 }
aoqi@0 1019
aoqi@0 1020 int InstructForm::method_position() {
aoqi@0 1021 return unique_opnds_idx(_components.method_position());
aoqi@0 1022 }
aoqi@0 1023
aoqi@0 1024 // Return number of relocation entries needed for this instruction.
aoqi@0 1025 uint InstructForm::reloc(FormDict &globals) {
aoqi@0 1026 uint reloc_entries = 0;
aoqi@0 1027 // Check for "Call" nodes
aoqi@0 1028 if ( is_ideal_call() ) ++reloc_entries;
aoqi@0 1029 if ( is_ideal_return() ) ++reloc_entries;
aoqi@0 1030 if ( is_ideal_safepoint() ) ++reloc_entries;
aoqi@0 1031
aoqi@0 1032
aoqi@0 1033 // Check if operands MAYBE oop pointers, by checking for ConP elements
aoqi@0 1034 // Proceed through the leaves of the match-tree and check for ConPs
aoqi@0 1035 if ( _matrule != NULL ) {
aoqi@0 1036 uint position = 0;
aoqi@0 1037 const char *result = NULL;
aoqi@0 1038 const char *name = NULL;
aoqi@0 1039 const char *opType = NULL;
aoqi@0 1040 while (_matrule->base_operand(position, globals, result, name, opType)) {
aoqi@0 1041 if ( strcmp(opType,"ConP") == 0 ) {
aoqi@0 1042 #ifdef SPARC
aoqi@0 1043 reloc_entries += 2; // 1 for sethi + 1 for setlo
aoqi@0 1044 #else
aoqi@0 1045 ++reloc_entries;
aoqi@0 1046 #endif
aoqi@0 1047 }
aoqi@0 1048 ++position;
aoqi@0 1049 }
aoqi@0 1050 }
aoqi@0 1051
aoqi@0 1052 // Above is only a conservative estimate
aoqi@0 1053 // because it did not check contents of operand classes.
aoqi@0 1054 // !!!!! !!!!!
aoqi@0 1055 // Add 1 to reloc info for each operand class in the component list.
aoqi@0 1056 Component *comp;
aoqi@0 1057 _components.reset();
aoqi@0 1058 while ( (comp = _components.iter()) != NULL ) {
aoqi@0 1059 const Form *form = globals[comp->_type];
aoqi@0 1060 assert( form, "Did not find component's type in global names");
aoqi@0 1061 const OpClassForm *opc = form->is_opclass();
aoqi@0 1062 const OperandForm *oper = form->is_operand();
aoqi@0 1063 if ( opc && (oper == NULL) ) {
aoqi@0 1064 ++reloc_entries;
aoqi@0 1065 } else if ( oper ) {
aoqi@0 1066 // floats and doubles loaded out of method's constant pool require reloc info
aoqi@0 1067 Form::DataType type = oper->is_base_constant(globals);
aoqi@0 1068 if ( (type == Form::idealF) || (type == Form::idealD) ) {
aoqi@0 1069 ++reloc_entries;
aoqi@0 1070 }
aoqi@0 1071 }
aoqi@0 1072 }
aoqi@0 1073
aoqi@0 1074 // Float and Double constants may come from the CodeBuffer table
aoqi@0 1075 // and require relocatable addresses for access
aoqi@0 1076 // !!!!!
aoqi@0 1077 // Check for any component being an immediate float or double.
aoqi@0 1078 Form::DataType data_type = is_chain_of_constant(globals);
aoqi@0 1079 if( data_type==idealD || data_type==idealF ) {
aoqi@0 1080 #ifdef SPARC
aoqi@0 1081 // sparc required more relocation entries for floating constants
aoqi@0 1082 // (expires 9/98)
aoqi@0 1083 reloc_entries += 6;
aoqi@0 1084 #else
aoqi@0 1085 reloc_entries++;
aoqi@0 1086 #endif
aoqi@0 1087 }
aoqi@0 1088
aoqi@0 1089 return reloc_entries;
aoqi@0 1090 }
aoqi@0 1091
aoqi@0 1092 // Utility function defined in archDesc.cpp
aoqi@0 1093 extern bool is_def(int usedef);
aoqi@0 1094
aoqi@0 1095 // Return the result of reducing an instruction
aoqi@0 1096 const char *InstructForm::reduce_result() {
aoqi@0 1097 const char* result = "Universe"; // default
aoqi@0 1098 _components.reset();
aoqi@0 1099 Component *comp = _components.iter();
aoqi@0 1100 if (comp != NULL && comp->isa(Component::DEF)) {
aoqi@0 1101 result = comp->_type;
aoqi@0 1102 // Override this if the rule is a store operation:
aoqi@0 1103 if (_matrule && _matrule->_rChild &&
aoqi@0 1104 is_store_to_memory(_matrule->_rChild->_opType))
aoqi@0 1105 result = "Universe";
aoqi@0 1106 }
aoqi@0 1107 return result;
aoqi@0 1108 }
aoqi@0 1109
aoqi@0 1110 // Return the name of the operand on the right hand side of the binary match
aoqi@0 1111 // Return NULL if there is no right hand side
aoqi@0 1112 const char *InstructForm::reduce_right(FormDict &globals) const {
aoqi@0 1113 if( _matrule == NULL ) return NULL;
aoqi@0 1114 return _matrule->reduce_right(globals);
aoqi@0 1115 }
aoqi@0 1116
aoqi@0 1117 // Similar for left
aoqi@0 1118 const char *InstructForm::reduce_left(FormDict &globals) const {
aoqi@0 1119 if( _matrule == NULL ) return NULL;
aoqi@0 1120 return _matrule->reduce_left(globals);
aoqi@0 1121 }
aoqi@0 1122
aoqi@0 1123
aoqi@0 1124 // Base class for this instruction, MachNode except for calls
aoqi@0 1125 const char *InstructForm::mach_base_class(FormDict &globals) const {
aoqi@0 1126 if( is_ideal_call() == Form::JAVA_STATIC ) {
aoqi@0 1127 return "MachCallStaticJavaNode";
aoqi@0 1128 }
aoqi@0 1129 else if( is_ideal_call() == Form::JAVA_DYNAMIC ) {
aoqi@0 1130 return "MachCallDynamicJavaNode";
aoqi@0 1131 }
aoqi@0 1132 else if( is_ideal_call() == Form::JAVA_RUNTIME ) {
aoqi@0 1133 return "MachCallRuntimeNode";
aoqi@0 1134 }
aoqi@0 1135 else if( is_ideal_call() == Form::JAVA_LEAF ) {
aoqi@0 1136 return "MachCallLeafNode";
aoqi@0 1137 }
aoqi@0 1138 else if (is_ideal_return()) {
aoqi@0 1139 return "MachReturnNode";
aoqi@0 1140 }
aoqi@0 1141 else if (is_ideal_halt()) {
aoqi@0 1142 return "MachHaltNode";
aoqi@0 1143 }
aoqi@0 1144 else if (is_ideal_safepoint()) {
aoqi@0 1145 return "MachSafePointNode";
aoqi@0 1146 }
aoqi@0 1147 else if (is_ideal_if()) {
aoqi@0 1148 return "MachIfNode";
aoqi@0 1149 }
aoqi@0 1150 else if (is_ideal_goto()) {
aoqi@0 1151 return "MachGotoNode";
aoqi@0 1152 }
aoqi@0 1153 else if (is_ideal_fastlock()) {
aoqi@0 1154 return "MachFastLockNode";
aoqi@0 1155 }
aoqi@0 1156 else if (is_ideal_nop()) {
aoqi@0 1157 return "MachNopNode";
aoqi@0 1158 }
aoqi@0 1159 else if (is_mach_constant()) {
aoqi@0 1160 return "MachConstantNode";
aoqi@0 1161 }
aoqi@0 1162 else if (captures_bottom_type(globals)) {
aoqi@0 1163 return "MachTypeNode";
aoqi@0 1164 } else {
aoqi@0 1165 return "MachNode";
aoqi@0 1166 }
aoqi@0 1167 assert( false, "ShouldNotReachHere()");
aoqi@0 1168 return NULL;
aoqi@0 1169 }
aoqi@0 1170
aoqi@0 1171 // Compare the instruction predicates for textual equality
aoqi@0 1172 bool equivalent_predicates( const InstructForm *instr1, const InstructForm *instr2 ) {
aoqi@0 1173 const Predicate *pred1 = instr1->_predicate;
aoqi@0 1174 const Predicate *pred2 = instr2->_predicate;
aoqi@0 1175 if( pred1 == NULL && pred2 == NULL ) {
aoqi@0 1176 // no predicates means they are identical
aoqi@0 1177 return true;
aoqi@0 1178 }
aoqi@0 1179 if( pred1 != NULL && pred2 != NULL ) {
aoqi@0 1180 // compare the predicates
aoqi@0 1181 if (ADLParser::equivalent_expressions(pred1->_pred, pred2->_pred)) {
aoqi@0 1182 return true;
aoqi@0 1183 }
aoqi@0 1184 }
aoqi@0 1185
aoqi@0 1186 return false;
aoqi@0 1187 }
aoqi@0 1188
aoqi@0 1189 // Check if this instruction can cisc-spill to 'alternate'
aoqi@0 1190 bool InstructForm::cisc_spills_to(ArchDesc &AD, InstructForm *instr) {
aoqi@0 1191 assert( _matrule != NULL && instr->_matrule != NULL, "must have match rules");
aoqi@0 1192 // Do not replace if a cisc-version has been found.
aoqi@0 1193 if( cisc_spill_operand() != Not_cisc_spillable ) return false;
aoqi@0 1194
aoqi@0 1195 int cisc_spill_operand = Maybe_cisc_spillable;
aoqi@0 1196 char *result = NULL;
aoqi@0 1197 char *result2 = NULL;
aoqi@0 1198 const char *op_name = NULL;
aoqi@0 1199 const char *reg_type = NULL;
aoqi@0 1200 FormDict &globals = AD.globalNames();
aoqi@0 1201 cisc_spill_operand = _matrule->matchrule_cisc_spill_match(globals, AD.get_registers(), instr->_matrule, op_name, reg_type);
aoqi@0 1202 if( (cisc_spill_operand != Not_cisc_spillable) && (op_name != NULL) && equivalent_predicates(this, instr) ) {
aoqi@0 1203 cisc_spill_operand = operand_position(op_name, Component::USE);
aoqi@0 1204 int def_oper = operand_position(op_name, Component::DEF);
aoqi@0 1205 if( def_oper == NameList::Not_in_list && instr->num_opnds() == num_opnds()) {
aoqi@0 1206 // Do not support cisc-spilling for destination operands and
aoqi@0 1207 // make sure they have the same number of operands.
aoqi@0 1208 _cisc_spill_alternate = instr;
aoqi@0 1209 instr->set_cisc_alternate(true);
aoqi@0 1210 if( AD._cisc_spill_debug ) {
aoqi@0 1211 fprintf(stderr, "Instruction %s cisc-spills-to %s\n", _ident, instr->_ident);
aoqi@0 1212 fprintf(stderr, " using operand %s %s at index %d\n", reg_type, op_name, cisc_spill_operand);
aoqi@0 1213 }
aoqi@0 1214 // Record that a stack-version of the reg_mask is needed
aoqi@0 1215 // !!!!!
aoqi@0 1216 OperandForm *oper = (OperandForm*)(globals[reg_type]->is_operand());
aoqi@0 1217 assert( oper != NULL, "cisc-spilling non operand");
aoqi@0 1218 const char *reg_class_name = oper->constrained_reg_class();
aoqi@0 1219 AD.set_stack_or_reg(reg_class_name);
aoqi@0 1220 const char *reg_mask_name = AD.reg_mask(*oper);
aoqi@0 1221 set_cisc_reg_mask_name(reg_mask_name);
aoqi@0 1222 const char *stack_or_reg_mask_name = AD.stack_or_reg_mask(*oper);
aoqi@0 1223 } else {
aoqi@0 1224 cisc_spill_operand = Not_cisc_spillable;
aoqi@0 1225 }
aoqi@0 1226 } else {
aoqi@0 1227 cisc_spill_operand = Not_cisc_spillable;
aoqi@0 1228 }
aoqi@0 1229
aoqi@0 1230 set_cisc_spill_operand(cisc_spill_operand);
aoqi@0 1231 return (cisc_spill_operand != Not_cisc_spillable);
aoqi@0 1232 }
aoqi@0 1233
aoqi@0 1234 // Check to see if this instruction can be replaced with the short branch
aoqi@0 1235 // instruction `short-branch'
aoqi@0 1236 bool InstructForm::check_branch_variant(ArchDesc &AD, InstructForm *short_branch) {
aoqi@0 1237 if (_matrule != NULL &&
aoqi@0 1238 this != short_branch && // Don't match myself
aoqi@0 1239 !is_short_branch() && // Don't match another short branch variant
aoqi@0 1240 reduce_result() != NULL &&
aoqi@0 1241 strcmp(reduce_result(), short_branch->reduce_result()) == 0 &&
aoqi@0 1242 _matrule->equivalent(AD.globalNames(), short_branch->_matrule)) {
aoqi@0 1243 // The instructions are equivalent.
aoqi@0 1244
aoqi@0 1245 // Now verify that both instructions have the same parameters and
aoqi@0 1246 // the same effects. Both branch forms should have the same inputs
aoqi@0 1247 // and resulting projections to correctly replace a long branch node
aoqi@0 1248 // with corresponding short branch node during code generation.
aoqi@0 1249
aoqi@0 1250 bool different = false;
aoqi@0 1251 if (short_branch->_components.count() != _components.count()) {
aoqi@0 1252 different = true;
aoqi@0 1253 } else if (_components.count() > 0) {
aoqi@0 1254 short_branch->_components.reset();
aoqi@0 1255 _components.reset();
aoqi@0 1256 Component *comp;
aoqi@0 1257 while ((comp = _components.iter()) != NULL) {
aoqi@0 1258 Component *short_comp = short_branch->_components.iter();
aoqi@0 1259 if (short_comp == NULL ||
aoqi@0 1260 short_comp->_type != comp->_type ||
aoqi@0 1261 short_comp->_usedef != comp->_usedef) {
aoqi@0 1262 different = true;
aoqi@0 1263 break;
aoqi@0 1264 }
aoqi@0 1265 }
aoqi@0 1266 if (short_branch->_components.iter() != NULL)
aoqi@0 1267 different = true;
aoqi@0 1268 }
aoqi@0 1269 if (different) {
aoqi@0 1270 globalAD->syntax_err(short_branch->_linenum, "Instruction %s and its short form %s have different parameters\n", _ident, short_branch->_ident);
aoqi@0 1271 }
aoqi@0 1272 if (AD._adl_debug > 1 || AD._short_branch_debug) {
aoqi@0 1273 fprintf(stderr, "Instruction %s has short form %s\n", _ident, short_branch->_ident);
aoqi@0 1274 }
aoqi@0 1275 _short_branch_form = short_branch;
aoqi@0 1276 return true;
aoqi@0 1277 }
aoqi@0 1278 return false;
aoqi@0 1279 }
aoqi@0 1280
aoqi@0 1281
aoqi@0 1282 // --------------------------- FILE *output_routines
aoqi@0 1283 //
aoqi@0 1284 // Generate the format call for the replacement variable
aoqi@0 1285 void InstructForm::rep_var_format(FILE *fp, const char *rep_var) {
aoqi@0 1286 // Handle special constant table variables.
aoqi@0 1287 if (strcmp(rep_var, "constanttablebase") == 0) {
aoqi@0 1288 fprintf(fp, "char reg[128]; ra->dump_register(in(mach_constant_base_node_input()), reg);\n");
aoqi@0 1289 fprintf(fp, " st->print(\"%%s\", reg);\n");
aoqi@0 1290 return;
aoqi@0 1291 }
aoqi@0 1292 if (strcmp(rep_var, "constantoffset") == 0) {
aoqi@0 1293 fprintf(fp, "st->print(\"#%%d\", constant_offset_unchecked());\n");
aoqi@0 1294 return;
aoqi@0 1295 }
aoqi@0 1296 if (strcmp(rep_var, "constantaddress") == 0) {
aoqi@0 1297 fprintf(fp, "st->print(\"constant table base + #%%d\", constant_offset_unchecked());\n");
aoqi@0 1298 return;
aoqi@0 1299 }
aoqi@0 1300
aoqi@0 1301 // Find replacement variable's type
aoqi@0 1302 const Form *form = _localNames[rep_var];
aoqi@0 1303 if (form == NULL) {
aoqi@0 1304 globalAD->syntax_err(_linenum, "Unknown replacement variable %s in format statement of %s.",
aoqi@0 1305 rep_var, _ident);
aoqi@0 1306 return;
aoqi@0 1307 }
aoqi@0 1308 OpClassForm *opc = form->is_opclass();
aoqi@0 1309 assert( opc, "replacement variable was not found in local names");
aoqi@0 1310 // Lookup the index position of the replacement variable
aoqi@0 1311 int idx = operand_position_format(rep_var);
aoqi@0 1312 if ( idx == -1 ) {
aoqi@0 1313 globalAD->syntax_err(_linenum, "Could not find replacement variable %s in format statement of %s.\n",
aoqi@0 1314 rep_var, _ident);
aoqi@0 1315 assert(strcmp(opc->_ident, "label") == 0, "Unimplemented");
aoqi@0 1316 return;
aoqi@0 1317 }
aoqi@0 1318
aoqi@0 1319 if (is_noninput_operand(idx)) {
aoqi@0 1320 // This component isn't in the input array. Print out the static
aoqi@0 1321 // name of the register.
aoqi@0 1322 OperandForm* oper = form->is_operand();
aoqi@0 1323 if (oper != NULL && oper->is_bound_register()) {
aoqi@0 1324 const RegDef* first = oper->get_RegClass()->find_first_elem();
aoqi@0 1325 fprintf(fp, " st->print_raw(\"%s\");\n", first->_regname);
aoqi@0 1326 } else {
aoqi@0 1327 globalAD->syntax_err(_linenum, "In %s can't find format for %s %s", _ident, opc->_ident, rep_var);
aoqi@0 1328 }
aoqi@0 1329 } else {
aoqi@0 1330 // Output the format call for this operand
aoqi@0 1331 fprintf(fp,"opnd_array(%d)->",idx);
aoqi@0 1332 if (idx == 0)
aoqi@0 1333 fprintf(fp,"int_format(ra, this, st); // %s\n", rep_var);
aoqi@0 1334 else
aoqi@0 1335 fprintf(fp,"ext_format(ra, this,idx%d, st); // %s\n", idx, rep_var );
aoqi@0 1336 }
aoqi@0 1337 }
aoqi@0 1338
aoqi@0 1339 // Seach through operands to determine parameters unique positions.
aoqi@0 1340 void InstructForm::set_unique_opnds() {
aoqi@0 1341 uint* uniq_idx = NULL;
aoqi@0 1342 uint nopnds = num_opnds();
aoqi@0 1343 uint num_uniq = nopnds;
aoqi@0 1344 uint i;
aoqi@0 1345 _uniq_idx_length = 0;
aoqi@0 1346 if (nopnds > 0) {
aoqi@0 1347 // Allocate index array. Worst case we're mapping from each
aoqi@0 1348 // component back to an index and any DEF always goes at 0 so the
aoqi@0 1349 // length of the array has to be the number of components + 1.
aoqi@0 1350 _uniq_idx_length = _components.count() + 1;
aoqi@0 1351 uniq_idx = (uint*) malloc(sizeof(uint) * _uniq_idx_length);
aoqi@0 1352 for (i = 0; i < _uniq_idx_length; i++) {
aoqi@0 1353 uniq_idx[i] = i;
aoqi@0 1354 }
aoqi@0 1355 }
aoqi@0 1356 // Do it only if there is a match rule and no expand rule. With an
aoqi@0 1357 // expand rule it is done by creating new mach node in Expand()
aoqi@0 1358 // method.
aoqi@0 1359 if (nopnds > 0 && _matrule != NULL && _exprule == NULL) {
aoqi@0 1360 const char *name;
aoqi@0 1361 uint count;
aoqi@0 1362 bool has_dupl_use = false;
aoqi@0 1363
aoqi@0 1364 _parameters.reset();
aoqi@0 1365 while ((name = _parameters.iter()) != NULL) {
aoqi@0 1366 count = 0;
aoqi@0 1367 uint position = 0;
aoqi@0 1368 uint uniq_position = 0;
aoqi@0 1369 _components.reset();
aoqi@0 1370 Component *comp = NULL;
aoqi@0 1371 if (sets_result()) {
aoqi@0 1372 comp = _components.iter();
aoqi@0 1373 position++;
aoqi@0 1374 }
aoqi@0 1375 // The next code is copied from the method operand_position().
aoqi@0 1376 for (; (comp = _components.iter()) != NULL; ++position) {
aoqi@0 1377 // When the first component is not a DEF,
aoqi@0 1378 // leave space for the result operand!
aoqi@0 1379 if (position==0 && (!comp->isa(Component::DEF))) {
aoqi@0 1380 ++position;
aoqi@0 1381 }
aoqi@0 1382 if (strcmp(name, comp->_name) == 0) {
aoqi@0 1383 if (++count > 1) {
aoqi@0 1384 assert(position < _uniq_idx_length, "out of bounds");
aoqi@0 1385 uniq_idx[position] = uniq_position;
aoqi@0 1386 has_dupl_use = true;
aoqi@0 1387 } else {
aoqi@0 1388 uniq_position = position;
aoqi@0 1389 }
aoqi@0 1390 }
aoqi@0 1391 if (comp->isa(Component::DEF) && comp->isa(Component::USE)) {
aoqi@0 1392 ++position;
aoqi@0 1393 if (position != 1)
aoqi@0 1394 --position; // only use two slots for the 1st USE_DEF
aoqi@0 1395 }
aoqi@0 1396 }
aoqi@0 1397 }
aoqi@0 1398 if (has_dupl_use) {
aoqi@0 1399 for (i = 1; i < nopnds; i++) {
aoqi@0 1400 if (i != uniq_idx[i]) {
aoqi@0 1401 break;
aoqi@0 1402 }
aoqi@0 1403 }
aoqi@0 1404 uint j = i;
aoqi@0 1405 for (; i < nopnds; i++) {
aoqi@0 1406 if (i == uniq_idx[i]) {
aoqi@0 1407 uniq_idx[i] = j++;
aoqi@0 1408 }
aoqi@0 1409 }
aoqi@0 1410 num_uniq = j;
aoqi@0 1411 }
aoqi@0 1412 }
aoqi@0 1413 _uniq_idx = uniq_idx;
aoqi@0 1414 _num_uniq = num_uniq;
aoqi@0 1415 }
aoqi@0 1416
aoqi@0 1417 // Generate index values needed for determining the operand position
aoqi@0 1418 void InstructForm::index_temps(FILE *fp, FormDict &globals, const char *prefix, const char *receiver) {
aoqi@0 1419 uint idx = 0; // position of operand in match rule
aoqi@0 1420 int cur_num_opnds = num_opnds();
aoqi@0 1421
aoqi@0 1422 // Compute the index into vector of operand pointers:
aoqi@0 1423 // idx0=0 is used to indicate that info comes from this same node, not from input edge.
aoqi@0 1424 // idx1 starts at oper_input_base()
aoqi@0 1425 if ( cur_num_opnds >= 1 ) {
aoqi@0 1426 fprintf(fp," // Start at oper_input_base() and count operands\n");
aoqi@0 1427 fprintf(fp," unsigned %sidx0 = %d;\n", prefix, oper_input_base(globals));
aoqi@0 1428 fprintf(fp," unsigned %sidx1 = %d;", prefix, oper_input_base(globals));
aoqi@0 1429 fprintf(fp," \t// %s\n", unique_opnd_ident(1));
aoqi@0 1430
aoqi@0 1431 // Generate starting points for other unique operands if they exist
aoqi@0 1432 for ( idx = 2; idx < num_unique_opnds(); ++idx ) {
aoqi@0 1433 if( *receiver == 0 ) {
aoqi@0 1434 fprintf(fp," unsigned %sidx%d = %sidx%d + opnd_array(%d)->num_edges();",
aoqi@0 1435 prefix, idx, prefix, idx-1, idx-1 );
aoqi@0 1436 } else {
aoqi@0 1437 fprintf(fp," unsigned %sidx%d = %sidx%d + %s_opnds[%d]->num_edges();",
aoqi@0 1438 prefix, idx, prefix, idx-1, receiver, idx-1 );
aoqi@0 1439 }
aoqi@0 1440 fprintf(fp," \t// %s\n", unique_opnd_ident(idx));
aoqi@0 1441 }
aoqi@0 1442 }
aoqi@0 1443 if( *receiver != 0 ) {
aoqi@0 1444 // This value is used by generate_peepreplace when copying a node.
aoqi@0 1445 // Don't emit it in other cases since it can hide bugs with the
aoqi@0 1446 // use invalid idx's.
aoqi@0 1447 fprintf(fp," unsigned %sidx%d = %sreq(); \n", prefix, idx, receiver);
aoqi@0 1448 }
aoqi@0 1449
aoqi@0 1450 }
aoqi@0 1451
aoqi@0 1452 // ---------------------------
aoqi@0 1453 bool InstructForm::verify() {
aoqi@0 1454 // !!!!! !!!!!
aoqi@0 1455 // Check that a "label" operand occurs last in the operand list, if present
aoqi@0 1456 return true;
aoqi@0 1457 }
aoqi@0 1458
aoqi@0 1459 void InstructForm::dump() {
aoqi@0 1460 output(stderr);
aoqi@0 1461 }
aoqi@0 1462
aoqi@0 1463 void InstructForm::output(FILE *fp) {
aoqi@0 1464 fprintf(fp,"\nInstruction: %s\n", (_ident?_ident:""));
aoqi@0 1465 if (_matrule) _matrule->output(fp);
aoqi@0 1466 if (_insencode) _insencode->output(fp);
aoqi@0 1467 if (_constant) _constant->output(fp);
aoqi@0 1468 if (_opcode) _opcode->output(fp);
aoqi@0 1469 if (_attribs) _attribs->output(fp);
aoqi@0 1470 if (_predicate) _predicate->output(fp);
aoqi@0 1471 if (_effects.Size()) {
aoqi@0 1472 fprintf(fp,"Effects\n");
aoqi@0 1473 _effects.dump();
aoqi@0 1474 }
aoqi@0 1475 if (_exprule) _exprule->output(fp);
aoqi@0 1476 if (_rewrule) _rewrule->output(fp);
aoqi@0 1477 if (_format) _format->output(fp);
aoqi@0 1478 if (_peephole) _peephole->output(fp);
aoqi@0 1479 }
aoqi@0 1480
aoqi@0 1481 void MachNodeForm::dump() {
aoqi@0 1482 output(stderr);
aoqi@0 1483 }
aoqi@0 1484
aoqi@0 1485 void MachNodeForm::output(FILE *fp) {
aoqi@0 1486 fprintf(fp,"\nMachNode: %s\n", (_ident?_ident:""));
aoqi@0 1487 }
aoqi@0 1488
aoqi@0 1489 //------------------------------build_predicate--------------------------------
aoqi@0 1490 // Build instruction predicates. If the user uses the same operand name
aoqi@0 1491 // twice, we need to check that the operands are pointer-eequivalent in
aoqi@0 1492 // the DFA during the labeling process.
aoqi@0 1493 Predicate *InstructForm::build_predicate() {
aoqi@0 1494 char buf[1024], *s=buf;
aoqi@0 1495 Dict names(cmpstr,hashstr,Form::arena); // Map Names to counts
aoqi@0 1496
aoqi@0 1497 MatchNode *mnode =
aoqi@0 1498 strcmp(_matrule->_opType, "Set") ? _matrule : _matrule->_rChild;
aoqi@0 1499 mnode->count_instr_names(names);
aoqi@0 1500
aoqi@0 1501 uint first = 1;
aoqi@0 1502 // Start with the predicate supplied in the .ad file.
aoqi@0 1503 if( _predicate ) {
aoqi@0 1504 if( first ) first=0;
aoqi@0 1505 strcpy(s,"("); s += strlen(s);
aoqi@0 1506 strcpy(s,_predicate->_pred);
aoqi@0 1507 s += strlen(s);
aoqi@0 1508 strcpy(s,")"); s += strlen(s);
aoqi@0 1509 }
aoqi@0 1510 for( DictI i(&names); i.test(); ++i ) {
aoqi@0 1511 uintptr_t cnt = (uintptr_t)i._value;
aoqi@0 1512 if( cnt > 1 ) { // Need a predicate at all?
aoqi@0 1513 assert( cnt == 2, "Unimplemented" );
aoqi@0 1514 // Handle many pairs
aoqi@0 1515 if( first ) first=0;
aoqi@0 1516 else { // All tests must pass, so use '&&'
aoqi@0 1517 strcpy(s," && ");
aoqi@0 1518 s += strlen(s);
aoqi@0 1519 }
aoqi@0 1520 // Add predicate to working buffer
aoqi@0 1521 sprintf(s,"/*%s*/(",(char*)i._key);
aoqi@0 1522 s += strlen(s);
aoqi@0 1523 mnode->build_instr_pred(s,(char*)i._key,0);
aoqi@0 1524 s += strlen(s);
aoqi@0 1525 strcpy(s," == "); s += strlen(s);
aoqi@0 1526 mnode->build_instr_pred(s,(char*)i._key,1);
aoqi@0 1527 s += strlen(s);
aoqi@0 1528 strcpy(s,")"); s += strlen(s);
aoqi@0 1529 }
aoqi@0 1530 }
aoqi@0 1531 if( s == buf ) s = NULL;
aoqi@0 1532 else {
aoqi@0 1533 assert( strlen(buf) < sizeof(buf), "String buffer overflow" );
aoqi@0 1534 s = strdup(buf);
aoqi@0 1535 }
aoqi@0 1536 return new Predicate(s);
aoqi@0 1537 }
aoqi@0 1538
aoqi@0 1539 //------------------------------EncodeForm-------------------------------------
aoqi@0 1540 // Constructor
aoqi@0 1541 EncodeForm::EncodeForm()
aoqi@0 1542 : _encClass(cmpstr,hashstr, Form::arena) {
aoqi@0 1543 }
aoqi@0 1544 EncodeForm::~EncodeForm() {
aoqi@0 1545 }
aoqi@0 1546
aoqi@0 1547 // record a new register class
aoqi@0 1548 EncClass *EncodeForm::add_EncClass(const char *className) {
aoqi@0 1549 EncClass *encClass = new EncClass(className);
aoqi@0 1550 _eclasses.addName(className);
aoqi@0 1551 _encClass.Insert(className,encClass);
aoqi@0 1552 return encClass;
aoqi@0 1553 }
aoqi@0 1554
aoqi@0 1555 // Lookup the function body for an encoding class
aoqi@0 1556 EncClass *EncodeForm::encClass(const char *className) {
aoqi@0 1557 assert( className != NULL, "Must provide a defined encoding name");
aoqi@0 1558
aoqi@0 1559 EncClass *encClass = (EncClass*)_encClass[className];
aoqi@0 1560 return encClass;
aoqi@0 1561 }
aoqi@0 1562
aoqi@0 1563 // Lookup the function body for an encoding class
aoqi@0 1564 const char *EncodeForm::encClassBody(const char *className) {
aoqi@0 1565 if( className == NULL ) return NULL;
aoqi@0 1566
aoqi@0 1567 EncClass *encClass = (EncClass*)_encClass[className];
aoqi@0 1568 assert( encClass != NULL, "Encode Class is missing.");
aoqi@0 1569 encClass->_code.reset();
aoqi@0 1570 const char *code = (const char*)encClass->_code.iter();
aoqi@0 1571 assert( code != NULL, "Found an empty encode class body.");
aoqi@0 1572
aoqi@0 1573 return code;
aoqi@0 1574 }
aoqi@0 1575
aoqi@0 1576 // Lookup the function body for an encoding class
aoqi@0 1577 const char *EncodeForm::encClassPrototype(const char *className) {
aoqi@0 1578 assert( className != NULL, "Encode class name must be non NULL.");
aoqi@0 1579
aoqi@0 1580 return className;
aoqi@0 1581 }
aoqi@0 1582
aoqi@0 1583 void EncodeForm::dump() { // Debug printer
aoqi@0 1584 output(stderr);
aoqi@0 1585 }
aoqi@0 1586
aoqi@0 1587 void EncodeForm::output(FILE *fp) { // Write info to output files
aoqi@0 1588 const char *name;
aoqi@0 1589 fprintf(fp,"\n");
aoqi@0 1590 fprintf(fp,"-------------------- Dump EncodeForm --------------------\n");
aoqi@0 1591 for (_eclasses.reset(); (name = _eclasses.iter()) != NULL;) {
aoqi@0 1592 ((EncClass*)_encClass[name])->output(fp);
aoqi@0 1593 }
aoqi@0 1594 fprintf(fp,"-------------------- end EncodeForm --------------------\n");
aoqi@0 1595 }
aoqi@0 1596 //------------------------------EncClass---------------------------------------
aoqi@0 1597 EncClass::EncClass(const char *name)
aoqi@0 1598 : _localNames(cmpstr,hashstr, Form::arena), _name(name) {
aoqi@0 1599 }
aoqi@0 1600 EncClass::~EncClass() {
aoqi@0 1601 }
aoqi@0 1602
aoqi@0 1603 // Add a parameter <type,name> pair
aoqi@0 1604 void EncClass::add_parameter(const char *parameter_type, const char *parameter_name) {
aoqi@0 1605 _parameter_type.addName( parameter_type );
aoqi@0 1606 _parameter_name.addName( parameter_name );
aoqi@0 1607 }
aoqi@0 1608
aoqi@0 1609 // Verify operand types in parameter list
aoqi@0 1610 bool EncClass::check_parameter_types(FormDict &globals) {
aoqi@0 1611 // !!!!!
aoqi@0 1612 return false;
aoqi@0 1613 }
aoqi@0 1614
aoqi@0 1615 // Add the decomposed "code" sections of an encoding's code-block
aoqi@0 1616 void EncClass::add_code(const char *code) {
aoqi@0 1617 _code.addName(code);
aoqi@0 1618 }
aoqi@0 1619
aoqi@0 1620 // Add the decomposed "replacement variables" of an encoding's code-block
aoqi@0 1621 void EncClass::add_rep_var(char *replacement_var) {
aoqi@0 1622 _code.addName(NameList::_signal);
aoqi@0 1623 _rep_vars.addName(replacement_var);
aoqi@0 1624 }
aoqi@0 1625
aoqi@0 1626 // Lookup the function body for an encoding class
aoqi@0 1627 int EncClass::rep_var_index(const char *rep_var) {
aoqi@0 1628 uint position = 0;
aoqi@0 1629 const char *name = NULL;
aoqi@0 1630
aoqi@0 1631 _parameter_name.reset();
aoqi@0 1632 while ( (name = _parameter_name.iter()) != NULL ) {
aoqi@0 1633 if ( strcmp(rep_var,name) == 0 ) return position;
aoqi@0 1634 ++position;
aoqi@0 1635 }
aoqi@0 1636
aoqi@0 1637 return -1;
aoqi@0 1638 }
aoqi@0 1639
aoqi@0 1640 // Check after parsing
aoqi@0 1641 bool EncClass::verify() {
aoqi@0 1642 // 1!!!!
aoqi@0 1643 // Check that each replacement variable, '$name' in architecture description
aoqi@0 1644 // is actually a local variable for this encode class, or a reserved name
aoqi@0 1645 // "primary, secondary, tertiary"
aoqi@0 1646 return true;
aoqi@0 1647 }
aoqi@0 1648
aoqi@0 1649 void EncClass::dump() {
aoqi@0 1650 output(stderr);
aoqi@0 1651 }
aoqi@0 1652
aoqi@0 1653 // Write info to output files
aoqi@0 1654 void EncClass::output(FILE *fp) {
aoqi@0 1655 fprintf(fp,"EncClass: %s", (_name ? _name : ""));
aoqi@0 1656
aoqi@0 1657 // Output the parameter list
aoqi@0 1658 _parameter_type.reset();
aoqi@0 1659 _parameter_name.reset();
aoqi@0 1660 const char *type = _parameter_type.iter();
aoqi@0 1661 const char *name = _parameter_name.iter();
aoqi@0 1662 fprintf(fp, " ( ");
aoqi@0 1663 for ( ; (type != NULL) && (name != NULL);
aoqi@0 1664 (type = _parameter_type.iter()), (name = _parameter_name.iter()) ) {
aoqi@0 1665 fprintf(fp, " %s %s,", type, name);
aoqi@0 1666 }
aoqi@0 1667 fprintf(fp, " ) ");
aoqi@0 1668
aoqi@0 1669 // Output the code block
aoqi@0 1670 _code.reset();
aoqi@0 1671 _rep_vars.reset();
aoqi@0 1672 const char *code;
aoqi@0 1673 while ( (code = _code.iter()) != NULL ) {
aoqi@0 1674 if ( _code.is_signal(code) ) {
aoqi@0 1675 // A replacement variable
aoqi@0 1676 const char *rep_var = _rep_vars.iter();
aoqi@0 1677 fprintf(fp,"($%s)", rep_var);
aoqi@0 1678 } else {
aoqi@0 1679 // A section of code
aoqi@0 1680 fprintf(fp,"%s", code);
aoqi@0 1681 }
aoqi@0 1682 }
aoqi@0 1683
aoqi@0 1684 }
aoqi@0 1685
aoqi@0 1686 //------------------------------Opcode-----------------------------------------
aoqi@0 1687 Opcode::Opcode(char *primary, char *secondary, char *tertiary)
aoqi@0 1688 : _primary(primary), _secondary(secondary), _tertiary(tertiary) {
aoqi@0 1689 }
aoqi@0 1690
aoqi@0 1691 Opcode::~Opcode() {
aoqi@0 1692 }
aoqi@0 1693
aoqi@0 1694 Opcode::opcode_type Opcode::as_opcode_type(const char *param) {
aoqi@0 1695 if( strcmp(param,"primary") == 0 ) {
aoqi@0 1696 return Opcode::PRIMARY;
aoqi@0 1697 }
aoqi@0 1698 else if( strcmp(param,"secondary") == 0 ) {
aoqi@0 1699 return Opcode::SECONDARY;
aoqi@0 1700 }
aoqi@0 1701 else if( strcmp(param,"tertiary") == 0 ) {
aoqi@0 1702 return Opcode::TERTIARY;
aoqi@0 1703 }
aoqi@0 1704 return Opcode::NOT_AN_OPCODE;
aoqi@0 1705 }
aoqi@0 1706
aoqi@0 1707 bool Opcode::print_opcode(FILE *fp, Opcode::opcode_type desired_opcode) {
aoqi@0 1708 // Default values previously provided by MachNode::primary()...
aoqi@0 1709 const char *description = NULL;
aoqi@0 1710 const char *value = NULL;
aoqi@0 1711 // Check if user provided any opcode definitions
aoqi@0 1712 if( this != NULL ) {
aoqi@0 1713 // Update 'value' if user provided a definition in the instruction
aoqi@0 1714 switch (desired_opcode) {
aoqi@0 1715 case PRIMARY:
aoqi@0 1716 description = "primary()";
aoqi@0 1717 if( _primary != NULL) { value = _primary; }
aoqi@0 1718 break;
aoqi@0 1719 case SECONDARY:
aoqi@0 1720 description = "secondary()";
aoqi@0 1721 if( _secondary != NULL ) { value = _secondary; }
aoqi@0 1722 break;
aoqi@0 1723 case TERTIARY:
aoqi@0 1724 description = "tertiary()";
aoqi@0 1725 if( _tertiary != NULL ) { value = _tertiary; }
aoqi@0 1726 break;
aoqi@0 1727 default:
aoqi@0 1728 assert( false, "ShouldNotReachHere();");
aoqi@0 1729 break;
aoqi@0 1730 }
aoqi@0 1731 }
aoqi@0 1732 if (value != NULL) {
aoqi@0 1733 fprintf(fp, "(%s /*%s*/)", value, description);
aoqi@0 1734 }
aoqi@0 1735 return value != NULL;
aoqi@0 1736 }
aoqi@0 1737
aoqi@0 1738 void Opcode::dump() {
aoqi@0 1739 output(stderr);
aoqi@0 1740 }
aoqi@0 1741
aoqi@0 1742 // Write info to output files
aoqi@0 1743 void Opcode::output(FILE *fp) {
aoqi@0 1744 if (_primary != NULL) fprintf(fp,"Primary opcode: %s\n", _primary);
aoqi@0 1745 if (_secondary != NULL) fprintf(fp,"Secondary opcode: %s\n", _secondary);
aoqi@0 1746 if (_tertiary != NULL) fprintf(fp,"Tertiary opcode: %s\n", _tertiary);
aoqi@0 1747 }
aoqi@0 1748
aoqi@0 1749 //------------------------------InsEncode--------------------------------------
aoqi@0 1750 InsEncode::InsEncode() {
aoqi@0 1751 }
aoqi@0 1752 InsEncode::~InsEncode() {
aoqi@0 1753 }
aoqi@0 1754
aoqi@0 1755 // Add "encode class name" and its parameters
aoqi@0 1756 NameAndList *InsEncode::add_encode(char *encoding) {
aoqi@0 1757 assert( encoding != NULL, "Must provide name for encoding");
aoqi@0 1758
aoqi@0 1759 // add_parameter(NameList::_signal);
aoqi@0 1760 NameAndList *encode = new NameAndList(encoding);
aoqi@0 1761 _encoding.addName((char*)encode);
aoqi@0 1762
aoqi@0 1763 return encode;
aoqi@0 1764 }
aoqi@0 1765
aoqi@0 1766 // Access the list of encodings
aoqi@0 1767 void InsEncode::reset() {
aoqi@0 1768 _encoding.reset();
aoqi@0 1769 // _parameter.reset();
aoqi@0 1770 }
aoqi@0 1771 const char* InsEncode::encode_class_iter() {
aoqi@0 1772 NameAndList *encode_class = (NameAndList*)_encoding.iter();
aoqi@0 1773 return ( encode_class != NULL ? encode_class->name() : NULL );
aoqi@0 1774 }
aoqi@0 1775 // Obtain parameter name from zero based index
aoqi@0 1776 const char *InsEncode::rep_var_name(InstructForm &inst, uint param_no) {
aoqi@0 1777 NameAndList *params = (NameAndList*)_encoding.current();
aoqi@0 1778 assert( params != NULL, "Internal Error");
aoqi@0 1779 const char *param = (*params)[param_no];
aoqi@0 1780
aoqi@0 1781 // Remove '$' if parser placed it there.
aoqi@0 1782 return ( param != NULL && *param == '$') ? (param+1) : param;
aoqi@0 1783 }
aoqi@0 1784
aoqi@0 1785 void InsEncode::dump() {
aoqi@0 1786 output(stderr);
aoqi@0 1787 }
aoqi@0 1788
aoqi@0 1789 // Write info to output files
aoqi@0 1790 void InsEncode::output(FILE *fp) {
aoqi@0 1791 NameAndList *encoding = NULL;
aoqi@0 1792 const char *parameter = NULL;
aoqi@0 1793
aoqi@0 1794 fprintf(fp,"InsEncode: ");
aoqi@0 1795 _encoding.reset();
aoqi@0 1796
aoqi@0 1797 while ( (encoding = (NameAndList*)_encoding.iter()) != 0 ) {
aoqi@0 1798 // Output the encoding being used
aoqi@0 1799 fprintf(fp,"%s(", encoding->name() );
aoqi@0 1800
aoqi@0 1801 // Output its parameter list, if any
aoqi@0 1802 bool first_param = true;
aoqi@0 1803 encoding->reset();
aoqi@0 1804 while ( (parameter = encoding->iter()) != 0 ) {
aoqi@0 1805 // Output the ',' between parameters
aoqi@0 1806 if ( ! first_param ) fprintf(fp,", ");
aoqi@0 1807 first_param = false;
aoqi@0 1808 // Output the parameter
aoqi@0 1809 fprintf(fp,"%s", parameter);
aoqi@0 1810 } // done with parameters
aoqi@0 1811 fprintf(fp,") ");
aoqi@0 1812 } // done with encodings
aoqi@0 1813
aoqi@0 1814 fprintf(fp,"\n");
aoqi@0 1815 }
aoqi@0 1816
aoqi@0 1817 //------------------------------Effect-----------------------------------------
aoqi@0 1818 static int effect_lookup(const char *name) {
aoqi@0 1819 if(!strcmp(name, "USE")) return Component::USE;
aoqi@0 1820 if(!strcmp(name, "DEF")) return Component::DEF;
aoqi@0 1821 if(!strcmp(name, "USE_DEF")) return Component::USE_DEF;
aoqi@0 1822 if(!strcmp(name, "KILL")) return Component::KILL;
aoqi@0 1823 if(!strcmp(name, "USE_KILL")) return Component::USE_KILL;
aoqi@0 1824 if(!strcmp(name, "TEMP")) return Component::TEMP;
aoqi@0 1825 if(!strcmp(name, "INVALID")) return Component::INVALID;
aoqi@0 1826 if(!strcmp(name, "CALL")) return Component::CALL;
aoqi@0 1827 assert( false,"Invalid effect name specified\n");
aoqi@0 1828 return Component::INVALID;
aoqi@0 1829 }
aoqi@0 1830
aoqi@0 1831 const char *Component::getUsedefName() {
aoqi@0 1832 switch (_usedef) {
aoqi@0 1833 case Component::INVALID: return "INVALID"; break;
aoqi@0 1834 case Component::USE: return "USE"; break;
aoqi@0 1835 case Component::USE_DEF: return "USE_DEF"; break;
aoqi@0 1836 case Component::USE_KILL: return "USE_KILL"; break;
aoqi@0 1837 case Component::KILL: return "KILL"; break;
aoqi@0 1838 case Component::TEMP: return "TEMP"; break;
aoqi@0 1839 case Component::DEF: return "DEF"; break;
aoqi@0 1840 case Component::CALL: return "CALL"; break;
aoqi@0 1841 default: assert(false, "unknown effect");
aoqi@0 1842 }
aoqi@0 1843 return "Undefined Use/Def info";
aoqi@0 1844 }
aoqi@0 1845
aoqi@0 1846 Effect::Effect(const char *name) : _name(name), _use_def(effect_lookup(name)) {
aoqi@0 1847 _ftype = Form::EFF;
aoqi@0 1848 }
aoqi@0 1849
aoqi@0 1850 Effect::~Effect() {
aoqi@0 1851 }
aoqi@0 1852
aoqi@0 1853 // Dynamic type check
aoqi@0 1854 Effect *Effect::is_effect() const {
aoqi@0 1855 return (Effect*)this;
aoqi@0 1856 }
aoqi@0 1857
aoqi@0 1858
aoqi@0 1859 // True if this component is equal to the parameter.
aoqi@0 1860 bool Effect::is(int use_def_kill_enum) const {
aoqi@0 1861 return (_use_def == use_def_kill_enum ? true : false);
aoqi@0 1862 }
aoqi@0 1863 // True if this component is used/def'd/kill'd as the parameter suggests.
aoqi@0 1864 bool Effect::isa(int use_def_kill_enum) const {
aoqi@0 1865 return (_use_def & use_def_kill_enum) == use_def_kill_enum;
aoqi@0 1866 }
aoqi@0 1867
aoqi@0 1868 void Effect::dump() {
aoqi@0 1869 output(stderr);
aoqi@0 1870 }
aoqi@0 1871
aoqi@0 1872 void Effect::output(FILE *fp) { // Write info to output files
aoqi@0 1873 fprintf(fp,"Effect: %s\n", (_name?_name:""));
aoqi@0 1874 }
aoqi@0 1875
aoqi@0 1876 //------------------------------ExpandRule-------------------------------------
aoqi@0 1877 ExpandRule::ExpandRule() : _expand_instrs(),
aoqi@0 1878 _newopconst(cmpstr, hashstr, Form::arena) {
aoqi@0 1879 _ftype = Form::EXP;
aoqi@0 1880 }
aoqi@0 1881
aoqi@0 1882 ExpandRule::~ExpandRule() { // Destructor
aoqi@0 1883 }
aoqi@0 1884
aoqi@0 1885 void ExpandRule::add_instruction(NameAndList *instruction_name_and_operand_list) {
aoqi@0 1886 _expand_instrs.addName((char*)instruction_name_and_operand_list);
aoqi@0 1887 }
aoqi@0 1888
aoqi@0 1889 void ExpandRule::reset_instructions() {
aoqi@0 1890 _expand_instrs.reset();
aoqi@0 1891 }
aoqi@0 1892
aoqi@0 1893 NameAndList* ExpandRule::iter_instructions() {
aoqi@0 1894 return (NameAndList*)_expand_instrs.iter();
aoqi@0 1895 }
aoqi@0 1896
aoqi@0 1897
aoqi@0 1898 void ExpandRule::dump() {
aoqi@0 1899 output(stderr);
aoqi@0 1900 }
aoqi@0 1901
aoqi@0 1902 void ExpandRule::output(FILE *fp) { // Write info to output files
aoqi@0 1903 NameAndList *expand_instr = NULL;
aoqi@0 1904 const char *opid = NULL;
aoqi@0 1905
aoqi@0 1906 fprintf(fp,"\nExpand Rule:\n");
aoqi@0 1907
aoqi@0 1908 // Iterate over the instructions 'node' expands into
aoqi@0 1909 for(reset_instructions(); (expand_instr = iter_instructions()) != NULL; ) {
aoqi@0 1910 fprintf(fp,"%s(", expand_instr->name());
aoqi@0 1911
aoqi@0 1912 // iterate over the operand list
aoqi@0 1913 for( expand_instr->reset(); (opid = expand_instr->iter()) != NULL; ) {
aoqi@0 1914 fprintf(fp,"%s ", opid);
aoqi@0 1915 }
aoqi@0 1916 fprintf(fp,");\n");
aoqi@0 1917 }
aoqi@0 1918 }
aoqi@0 1919
aoqi@0 1920 //------------------------------RewriteRule------------------------------------
aoqi@0 1921 RewriteRule::RewriteRule(char* params, char* block)
aoqi@0 1922 : _tempParams(params), _tempBlock(block) { }; // Constructor
aoqi@0 1923 RewriteRule::~RewriteRule() { // Destructor
aoqi@0 1924 }
aoqi@0 1925
aoqi@0 1926 void RewriteRule::dump() {
aoqi@0 1927 output(stderr);
aoqi@0 1928 }
aoqi@0 1929
aoqi@0 1930 void RewriteRule::output(FILE *fp) { // Write info to output files
aoqi@0 1931 fprintf(fp,"\nRewrite Rule:\n%s\n%s\n",
aoqi@0 1932 (_tempParams?_tempParams:""),
aoqi@0 1933 (_tempBlock?_tempBlock:""));
aoqi@0 1934 }
aoqi@0 1935
aoqi@0 1936
aoqi@0 1937 //==============================MachNodes======================================
aoqi@0 1938 //------------------------------MachNodeForm-----------------------------------
aoqi@0 1939 MachNodeForm::MachNodeForm(char *id)
aoqi@0 1940 : _ident(id) {
aoqi@0 1941 }
aoqi@0 1942
aoqi@0 1943 MachNodeForm::~MachNodeForm() {
aoqi@0 1944 }
aoqi@0 1945
aoqi@0 1946 MachNodeForm *MachNodeForm::is_machnode() const {
aoqi@0 1947 return (MachNodeForm*)this;
aoqi@0 1948 }
aoqi@0 1949
aoqi@0 1950 //==============================Operand Classes================================
aoqi@0 1951 //------------------------------OpClassForm------------------------------------
aoqi@0 1952 OpClassForm::OpClassForm(const char* id) : _ident(id) {
aoqi@0 1953 _ftype = Form::OPCLASS;
aoqi@0 1954 }
aoqi@0 1955
aoqi@0 1956 OpClassForm::~OpClassForm() {
aoqi@0 1957 }
aoqi@0 1958
aoqi@0 1959 bool OpClassForm::ideal_only() const { return 0; }
aoqi@0 1960
aoqi@0 1961 OpClassForm *OpClassForm::is_opclass() const {
aoqi@0 1962 return (OpClassForm*)this;
aoqi@0 1963 }
aoqi@0 1964
aoqi@0 1965 Form::InterfaceType OpClassForm::interface_type(FormDict &globals) const {
aoqi@0 1966 if( _oplst.count() == 0 ) return Form::no_interface;
aoqi@0 1967
aoqi@0 1968 // Check that my operands have the same interface type
aoqi@0 1969 Form::InterfaceType interface;
aoqi@0 1970 bool first = true;
aoqi@0 1971 NameList &op_list = (NameList &)_oplst;
aoqi@0 1972 op_list.reset();
aoqi@0 1973 const char *op_name;
aoqi@0 1974 while( (op_name = op_list.iter()) != NULL ) {
aoqi@0 1975 const Form *form = globals[op_name];
aoqi@0 1976 OperandForm *operand = form->is_operand();
aoqi@0 1977 assert( operand, "Entry in operand class that is not an operand");
aoqi@0 1978 if( first ) {
aoqi@0 1979 first = false;
aoqi@0 1980 interface = operand->interface_type(globals);
aoqi@0 1981 } else {
aoqi@0 1982 interface = (interface == operand->interface_type(globals) ? interface : Form::no_interface);
aoqi@0 1983 }
aoqi@0 1984 }
aoqi@0 1985 return interface;
aoqi@0 1986 }
aoqi@0 1987
aoqi@0 1988 bool OpClassForm::stack_slots_only(FormDict &globals) const {
aoqi@0 1989 if( _oplst.count() == 0 ) return false; // how?
aoqi@0 1990
aoqi@0 1991 NameList &op_list = (NameList &)_oplst;
aoqi@0 1992 op_list.reset();
aoqi@0 1993 const char *op_name;
aoqi@0 1994 while( (op_name = op_list.iter()) != NULL ) {
aoqi@0 1995 const Form *form = globals[op_name];
aoqi@0 1996 OperandForm *operand = form->is_operand();
aoqi@0 1997 assert( operand, "Entry in operand class that is not an operand");
aoqi@0 1998 if( !operand->stack_slots_only(globals) ) return false;
aoqi@0 1999 }
aoqi@0 2000 return true;
aoqi@0 2001 }
aoqi@0 2002
aoqi@0 2003
aoqi@0 2004 void OpClassForm::dump() {
aoqi@0 2005 output(stderr);
aoqi@0 2006 }
aoqi@0 2007
aoqi@0 2008 void OpClassForm::output(FILE *fp) {
aoqi@0 2009 const char *name;
aoqi@0 2010 fprintf(fp,"\nOperand Class: %s\n", (_ident?_ident:""));
aoqi@0 2011 fprintf(fp,"\nCount = %d\n", _oplst.count());
aoqi@0 2012 for(_oplst.reset(); (name = _oplst.iter()) != NULL;) {
aoqi@0 2013 fprintf(fp,"%s, ",name);
aoqi@0 2014 }
aoqi@0 2015 fprintf(fp,"\n");
aoqi@0 2016 }
aoqi@0 2017
aoqi@0 2018
aoqi@0 2019 //==============================Operands=======================================
aoqi@0 2020 //------------------------------OperandForm------------------------------------
aoqi@0 2021 OperandForm::OperandForm(const char* id)
aoqi@0 2022 : OpClassForm(id), _ideal_only(false),
aoqi@0 2023 _localNames(cmpstr, hashstr, Form::arena) {
aoqi@0 2024 _ftype = Form::OPER;
aoqi@0 2025
aoqi@0 2026 _matrule = NULL;
aoqi@0 2027 _interface = NULL;
aoqi@0 2028 _attribs = NULL;
aoqi@0 2029 _predicate = NULL;
aoqi@0 2030 _constraint= NULL;
aoqi@0 2031 _construct = NULL;
aoqi@0 2032 _format = NULL;
aoqi@0 2033 }
aoqi@0 2034 OperandForm::OperandForm(const char* id, bool ideal_only)
aoqi@0 2035 : OpClassForm(id), _ideal_only(ideal_only),
aoqi@0 2036 _localNames(cmpstr, hashstr, Form::arena) {
aoqi@0 2037 _ftype = Form::OPER;
aoqi@0 2038
aoqi@0 2039 _matrule = NULL;
aoqi@0 2040 _interface = NULL;
aoqi@0 2041 _attribs = NULL;
aoqi@0 2042 _predicate = NULL;
aoqi@0 2043 _constraint= NULL;
aoqi@0 2044 _construct = NULL;
aoqi@0 2045 _format = NULL;
aoqi@0 2046 }
aoqi@0 2047 OperandForm::~OperandForm() {
aoqi@0 2048 }
aoqi@0 2049
aoqi@0 2050
aoqi@0 2051 OperandForm *OperandForm::is_operand() const {
aoqi@0 2052 return (OperandForm*)this;
aoqi@0 2053 }
aoqi@0 2054
aoqi@0 2055 bool OperandForm::ideal_only() const {
aoqi@0 2056 return _ideal_only;
aoqi@0 2057 }
aoqi@0 2058
aoqi@0 2059 Form::InterfaceType OperandForm::interface_type(FormDict &globals) const {
aoqi@0 2060 if( _interface == NULL ) return Form::no_interface;
aoqi@0 2061
aoqi@0 2062 return _interface->interface_type(globals);
aoqi@0 2063 }
aoqi@0 2064
aoqi@0 2065
aoqi@0 2066 bool OperandForm::stack_slots_only(FormDict &globals) const {
aoqi@0 2067 if( _constraint == NULL ) return false;
aoqi@0 2068 return _constraint->stack_slots_only();
aoqi@0 2069 }
aoqi@0 2070
aoqi@0 2071
aoqi@0 2072 // Access op_cost attribute or return NULL.
aoqi@0 2073 const char* OperandForm::cost() {
aoqi@0 2074 for (Attribute* cur = _attribs; cur != NULL; cur = (Attribute*)cur->_next) {
aoqi@0 2075 if( strcmp(cur->_ident,AttributeForm::_op_cost) == 0 ) {
aoqi@0 2076 return cur->_val;
aoqi@0 2077 }
aoqi@0 2078 }
aoqi@0 2079 return NULL;
aoqi@0 2080 }
aoqi@0 2081
aoqi@0 2082 // Return the number of leaves below this complex operand
aoqi@0 2083 uint OperandForm::num_leaves() const {
aoqi@0 2084 if ( ! _matrule) return 0;
aoqi@0 2085
aoqi@0 2086 int num_leaves = _matrule->_numleaves;
aoqi@0 2087 return num_leaves;
aoqi@0 2088 }
aoqi@0 2089
aoqi@0 2090 // Return the number of constants contained within this complex operand
aoqi@0 2091 uint OperandForm::num_consts(FormDict &globals) const {
aoqi@0 2092 if ( ! _matrule) return 0;
aoqi@0 2093
aoqi@0 2094 // This is a recursive invocation on all operands in the matchrule
aoqi@0 2095 return _matrule->num_consts(globals);
aoqi@0 2096 }
aoqi@0 2097
aoqi@0 2098 // Return the number of constants in match rule with specified type
aoqi@0 2099 uint OperandForm::num_consts(FormDict &globals, Form::DataType type) const {
aoqi@0 2100 if ( ! _matrule) return 0;
aoqi@0 2101
aoqi@0 2102 // This is a recursive invocation on all operands in the matchrule
aoqi@0 2103 return _matrule->num_consts(globals, type);
aoqi@0 2104 }
aoqi@0 2105
aoqi@0 2106 // Return the number of pointer constants contained within this complex operand
aoqi@0 2107 uint OperandForm::num_const_ptrs(FormDict &globals) const {
aoqi@0 2108 if ( ! _matrule) return 0;
aoqi@0 2109
aoqi@0 2110 // This is a recursive invocation on all operands in the matchrule
aoqi@0 2111 return _matrule->num_const_ptrs(globals);
aoqi@0 2112 }
aoqi@0 2113
aoqi@0 2114 uint OperandForm::num_edges(FormDict &globals) const {
aoqi@0 2115 uint edges = 0;
aoqi@0 2116 uint leaves = num_leaves();
aoqi@0 2117 uint consts = num_consts(globals);
aoqi@0 2118
aoqi@0 2119 // If we are matching a constant directly, there are no leaves.
aoqi@0 2120 edges = ( leaves > consts ) ? leaves - consts : 0;
aoqi@0 2121
aoqi@0 2122 // !!!!!
aoqi@0 2123 // Special case operands that do not have a corresponding ideal node.
aoqi@0 2124 if( (edges == 0) && (consts == 0) ) {
aoqi@0 2125 if( constrained_reg_class() != NULL ) {
aoqi@0 2126 edges = 1;
aoqi@0 2127 } else {
aoqi@0 2128 if( _matrule
aoqi@0 2129 && (_matrule->_lChild == NULL) && (_matrule->_rChild == NULL) ) {
aoqi@0 2130 const Form *form = globals[_matrule->_opType];
aoqi@0 2131 OperandForm *oper = form ? form->is_operand() : NULL;
aoqi@0 2132 if( oper ) {
aoqi@0 2133 return oper->num_edges(globals);
aoqi@0 2134 }
aoqi@0 2135 }
aoqi@0 2136 }
aoqi@0 2137 }
aoqi@0 2138
aoqi@0 2139 return edges;
aoqi@0 2140 }
aoqi@0 2141
aoqi@0 2142
aoqi@0 2143 // Check if this operand is usable for cisc-spilling
aoqi@0 2144 bool OperandForm::is_cisc_reg(FormDict &globals) const {
aoqi@0 2145 const char *ideal = ideal_type(globals);
aoqi@0 2146 bool is_cisc_reg = (ideal && (ideal_to_Reg_type(ideal) != none));
aoqi@0 2147 return is_cisc_reg;
aoqi@0 2148 }
aoqi@0 2149
aoqi@0 2150 bool OpClassForm::is_cisc_mem(FormDict &globals) const {
aoqi@0 2151 Form::InterfaceType my_interface = interface_type(globals);
aoqi@0 2152 return (my_interface == memory_interface);
aoqi@0 2153 }
aoqi@0 2154
aoqi@0 2155
aoqi@0 2156 // node matches ideal 'Bool'
aoqi@0 2157 bool OperandForm::is_ideal_bool() const {
aoqi@0 2158 if( _matrule == NULL ) return false;
aoqi@0 2159
aoqi@0 2160 return _matrule->is_ideal_bool();
aoqi@0 2161 }
aoqi@0 2162
aoqi@0 2163 // Require user's name for an sRegX to be stackSlotX
aoqi@0 2164 Form::DataType OperandForm::is_user_name_for_sReg() const {
aoqi@0 2165 DataType data_type = none;
aoqi@0 2166 if( _ident != NULL ) {
aoqi@0 2167 if( strcmp(_ident,"stackSlotI") == 0 ) data_type = Form::idealI;
aoqi@0 2168 else if( strcmp(_ident,"stackSlotP") == 0 ) data_type = Form::idealP;
aoqi@0 2169 else if( strcmp(_ident,"stackSlotD") == 0 ) data_type = Form::idealD;
aoqi@0 2170 else if( strcmp(_ident,"stackSlotF") == 0 ) data_type = Form::idealF;
aoqi@0 2171 else if( strcmp(_ident,"stackSlotL") == 0 ) data_type = Form::idealL;
aoqi@0 2172 }
aoqi@0 2173 assert((data_type == none) || (_matrule == NULL), "No match-rule for stackSlotX");
aoqi@0 2174
aoqi@0 2175 return data_type;
aoqi@0 2176 }
aoqi@0 2177
aoqi@0 2178
aoqi@0 2179 // Return ideal type, if there is a single ideal type for this operand
aoqi@0 2180 const char *OperandForm::ideal_type(FormDict &globals, RegisterForm *registers) const {
aoqi@0 2181 const char *type = NULL;
aoqi@0 2182 if (ideal_only()) type = _ident;
aoqi@0 2183 else if( _matrule == NULL ) {
aoqi@0 2184 // Check for condition code register
aoqi@0 2185 const char *rc_name = constrained_reg_class();
aoqi@0 2186 // !!!!!
aoqi@0 2187 if (rc_name == NULL) return NULL;
aoqi@0 2188 // !!!!! !!!!!
aoqi@0 2189 // Check constraints on result's register class
aoqi@0 2190 if( registers ) {
aoqi@0 2191 RegClass *reg_class = registers->getRegClass(rc_name);
aoqi@0 2192 assert( reg_class != NULL, "Register class is not defined");
aoqi@0 2193
aoqi@0 2194 // Check for ideal type of entries in register class, all are the same type
aoqi@0 2195 reg_class->reset();
aoqi@0 2196 RegDef *reg_def = reg_class->RegDef_iter();
aoqi@0 2197 assert( reg_def != NULL, "No entries in register class");
aoqi@0 2198 assert( reg_def->_idealtype != NULL, "Did not define ideal type for register");
aoqi@0 2199 // Return substring that names the register's ideal type
aoqi@0 2200 type = reg_def->_idealtype + 3;
aoqi@0 2201 assert( *(reg_def->_idealtype + 0) == 'O', "Expect Op_ prefix");
aoqi@0 2202 assert( *(reg_def->_idealtype + 1) == 'p', "Expect Op_ prefix");
aoqi@0 2203 assert( *(reg_def->_idealtype + 2) == '_', "Expect Op_ prefix");
aoqi@0 2204 }
aoqi@0 2205 }
aoqi@0 2206 else if( _matrule->_lChild == NULL && _matrule->_rChild == NULL ) {
aoqi@0 2207 // This operand matches a single type, at the top level.
aoqi@0 2208 // Check for ideal type
aoqi@0 2209 type = _matrule->_opType;
aoqi@0 2210 if( strcmp(type,"Bool") == 0 )
aoqi@0 2211 return "Bool";
aoqi@0 2212 // transitive lookup
aoqi@0 2213 const Form *frm = globals[type];
aoqi@0 2214 OperandForm *op = frm->is_operand();
aoqi@0 2215 type = op->ideal_type(globals, registers);
aoqi@0 2216 }
aoqi@0 2217 return type;
aoqi@0 2218 }
aoqi@0 2219
aoqi@0 2220
aoqi@0 2221 // If there is a single ideal type for this interface field, return it.
aoqi@0 2222 const char *OperandForm::interface_ideal_type(FormDict &globals,
aoqi@0 2223 const char *field) const {
aoqi@0 2224 const char *ideal_type = NULL;
aoqi@0 2225 const char *value = NULL;
aoqi@0 2226
aoqi@0 2227 // Check if "field" is valid for this operand's interface
aoqi@0 2228 if ( ! is_interface_field(field, value) ) return ideal_type;
aoqi@0 2229
aoqi@0 2230 // !!!!! !!!!! !!!!!
aoqi@0 2231 // If a valid field has a constant value, identify "ConI" or "ConP" or ...
aoqi@0 2232
aoqi@0 2233 // Else, lookup type of field's replacement variable
aoqi@0 2234
aoqi@0 2235 return ideal_type;
aoqi@0 2236 }
aoqi@0 2237
aoqi@0 2238
aoqi@0 2239 RegClass* OperandForm::get_RegClass() const {
aoqi@0 2240 if (_interface && !_interface->is_RegInterface()) return NULL;
aoqi@0 2241 return globalAD->get_registers()->getRegClass(constrained_reg_class());
aoqi@0 2242 }
aoqi@0 2243
aoqi@0 2244
aoqi@0 2245 bool OperandForm::is_bound_register() const {
aoqi@0 2246 RegClass* reg_class = get_RegClass();
aoqi@0 2247 if (reg_class == NULL) {
aoqi@0 2248 return false;
aoqi@0 2249 }
aoqi@0 2250
aoqi@0 2251 const char* name = ideal_type(globalAD->globalNames());
aoqi@0 2252 if (name == NULL) {
aoqi@0 2253 return false;
aoqi@0 2254 }
aoqi@0 2255
aoqi@0 2256 uint size = 0;
aoqi@0 2257 if (strcmp(name, "RegFlags") == 0) size = 1;
aoqi@0 2258 if (strcmp(name, "RegI") == 0) size = 1;
aoqi@0 2259 if (strcmp(name, "RegF") == 0) size = 1;
aoqi@0 2260 if (strcmp(name, "RegD") == 0) size = 2;
aoqi@0 2261 if (strcmp(name, "RegL") == 0) size = 2;
aoqi@0 2262 if (strcmp(name, "RegN") == 0) size = 1;
aoqi@0 2263 if (strcmp(name, "RegP") == 0) size = globalAD->get_preproc_def("_LP64") ? 2 : 1;
aoqi@0 2264 if (size == 0) {
aoqi@0 2265 return false;
aoqi@0 2266 }
aoqi@0 2267 return size == reg_class->size();
aoqi@0 2268 }
aoqi@0 2269
aoqi@0 2270
aoqi@0 2271 // Check if this is a valid field for this operand,
aoqi@0 2272 // Return 'true' if valid, and set the value to the string the user provided.
aoqi@0 2273 bool OperandForm::is_interface_field(const char *field,
aoqi@0 2274 const char * &value) const {
aoqi@0 2275 return false;
aoqi@0 2276 }
aoqi@0 2277
aoqi@0 2278
aoqi@0 2279 // Return register class name if a constraint specifies the register class.
aoqi@0 2280 const char *OperandForm::constrained_reg_class() const {
aoqi@0 2281 const char *reg_class = NULL;
aoqi@0 2282 if ( _constraint ) {
aoqi@0 2283 // !!!!!
aoqi@0 2284 Constraint *constraint = _constraint;
aoqi@0 2285 if ( strcmp(_constraint->_func,"ALLOC_IN_RC") == 0 ) {
aoqi@0 2286 reg_class = _constraint->_arg;
aoqi@0 2287 }
aoqi@0 2288 }
aoqi@0 2289
aoqi@0 2290 return reg_class;
aoqi@0 2291 }
aoqi@0 2292
aoqi@0 2293
aoqi@0 2294 // Return the register class associated with 'leaf'.
aoqi@0 2295 const char *OperandForm::in_reg_class(uint leaf, FormDict &globals) {
aoqi@0 2296 const char *reg_class = NULL; // "RegMask::Empty";
aoqi@0 2297
aoqi@0 2298 if((_matrule == NULL) || (_matrule->is_chain_rule(globals))) {
aoqi@0 2299 reg_class = constrained_reg_class();
aoqi@0 2300 return reg_class;
aoqi@0 2301 }
aoqi@0 2302 const char *result = NULL;
aoqi@0 2303 const char *name = NULL;
aoqi@0 2304 const char *type = NULL;
aoqi@0 2305 // iterate through all base operands
aoqi@0 2306 // until we reach the register that corresponds to "leaf"
aoqi@0 2307 // This function is not looking for an ideal type. It needs the first
aoqi@0 2308 // level user type associated with the leaf.
aoqi@0 2309 for(uint idx = 0;_matrule->base_operand(idx,globals,result,name,type);++idx) {
aoqi@0 2310 const Form *form = (_localNames[name] ? _localNames[name] : globals[result]);
aoqi@0 2311 OperandForm *oper = form ? form->is_operand() : NULL;
aoqi@0 2312 if( oper ) {
aoqi@0 2313 reg_class = oper->constrained_reg_class();
aoqi@0 2314 if( reg_class ) {
aoqi@0 2315 reg_class = reg_class;
aoqi@0 2316 } else {
aoqi@0 2317 // ShouldNotReachHere();
aoqi@0 2318 }
aoqi@0 2319 } else {
aoqi@0 2320 // ShouldNotReachHere();
aoqi@0 2321 }
aoqi@0 2322
aoqi@0 2323 // Increment our target leaf position if current leaf is not a candidate.
aoqi@0 2324 if( reg_class == NULL) ++leaf;
aoqi@0 2325 // Exit the loop with the value of reg_class when at the correct index
aoqi@0 2326 if( idx == leaf ) break;
aoqi@0 2327 // May iterate through all base operands if reg_class for 'leaf' is NULL
aoqi@0 2328 }
aoqi@0 2329 return reg_class;
aoqi@0 2330 }
aoqi@0 2331
aoqi@0 2332
aoqi@0 2333 // Recursive call to construct list of top-level operands.
aoqi@0 2334 // Implementation does not modify state of internal structures
aoqi@0 2335 void OperandForm::build_components() {
aoqi@0 2336 if (_matrule) _matrule->append_components(_localNames, _components);
aoqi@0 2337
aoqi@0 2338 // Add parameters that "do not appear in match rule".
aoqi@0 2339 const char *name;
aoqi@0 2340 for (_parameters.reset(); (name = _parameters.iter()) != NULL;) {
aoqi@0 2341 OperandForm *opForm = (OperandForm*)_localNames[name];
aoqi@0 2342
aoqi@0 2343 if ( _components.operand_position(name) == -1 ) {
aoqi@0 2344 _components.insert(name, opForm->_ident, Component::INVALID, false);
aoqi@0 2345 }
aoqi@0 2346 }
aoqi@0 2347
aoqi@0 2348 return;
aoqi@0 2349 }
aoqi@0 2350
aoqi@0 2351 int OperandForm::operand_position(const char *name, int usedef) {
aoqi@0 2352 return _components.operand_position(name, usedef, this);
aoqi@0 2353 }
aoqi@0 2354
aoqi@0 2355
aoqi@0 2356 // Return zero-based position in component list, only counting constants;
aoqi@0 2357 // Return -1 if not in list.
aoqi@0 2358 int OperandForm::constant_position(FormDict &globals, const Component *last) {
aoqi@0 2359 // Iterate through components and count constants preceding 'constant'
aoqi@0 2360 int position = 0;
aoqi@0 2361 Component *comp;
aoqi@0 2362 _components.reset();
aoqi@0 2363 while( (comp = _components.iter()) != NULL && (comp != last) ) {
aoqi@0 2364 // Special case for operands that take a single user-defined operand
aoqi@0 2365 // Skip the initial definition in the component list.
aoqi@0 2366 if( strcmp(comp->_name,this->_ident) == 0 ) continue;
aoqi@0 2367
aoqi@0 2368 const char *type = comp->_type;
aoqi@0 2369 // Lookup operand form for replacement variable's type
aoqi@0 2370 const Form *form = globals[type];
aoqi@0 2371 assert( form != NULL, "Component's type not found");
aoqi@0 2372 OperandForm *oper = form ? form->is_operand() : NULL;
aoqi@0 2373 if( oper ) {
aoqi@0 2374 if( oper->_matrule->is_base_constant(globals) != Form::none ) {
aoqi@0 2375 ++position;
aoqi@0 2376 }
aoqi@0 2377 }
aoqi@0 2378 }
aoqi@0 2379
aoqi@0 2380 // Check for being passed a component that was not in the list
aoqi@0 2381 if( comp != last ) position = -1;
aoqi@0 2382
aoqi@0 2383 return position;
aoqi@0 2384 }
aoqi@0 2385 // Provide position of constant by "name"
aoqi@0 2386 int OperandForm::constant_position(FormDict &globals, const char *name) {
aoqi@0 2387 const Component *comp = _components.search(name);
aoqi@0 2388 int idx = constant_position( globals, comp );
aoqi@0 2389
aoqi@0 2390 return idx;
aoqi@0 2391 }
aoqi@0 2392
aoqi@0 2393
aoqi@0 2394 // Return zero-based position in component list, only counting constants;
aoqi@0 2395 // Return -1 if not in list.
aoqi@0 2396 int OperandForm::register_position(FormDict &globals, const char *reg_name) {
aoqi@0 2397 // Iterate through components and count registers preceding 'last'
aoqi@0 2398 uint position = 0;
aoqi@0 2399 Component *comp;
aoqi@0 2400 _components.reset();
aoqi@0 2401 while( (comp = _components.iter()) != NULL
aoqi@0 2402 && (strcmp(comp->_name,reg_name) != 0) ) {
aoqi@0 2403 // Special case for operands that take a single user-defined operand
aoqi@0 2404 // Skip the initial definition in the component list.
aoqi@0 2405 if( strcmp(comp->_name,this->_ident) == 0 ) continue;
aoqi@0 2406
aoqi@0 2407 const char *type = comp->_type;
aoqi@0 2408 // Lookup operand form for component's type
aoqi@0 2409 const Form *form = globals[type];
aoqi@0 2410 assert( form != NULL, "Component's type not found");
aoqi@0 2411 OperandForm *oper = form ? form->is_operand() : NULL;
aoqi@0 2412 if( oper ) {
aoqi@0 2413 if( oper->_matrule->is_base_register(globals) ) {
aoqi@0 2414 ++position;
aoqi@0 2415 }
aoqi@0 2416 }
aoqi@0 2417 }
aoqi@0 2418
aoqi@0 2419 return position;
aoqi@0 2420 }
aoqi@0 2421
aoqi@0 2422
aoqi@0 2423 const char *OperandForm::reduce_result() const {
aoqi@0 2424 return _ident;
aoqi@0 2425 }
aoqi@0 2426 // Return the name of the operand on the right hand side of the binary match
aoqi@0 2427 // Return NULL if there is no right hand side
aoqi@0 2428 const char *OperandForm::reduce_right(FormDict &globals) const {
aoqi@0 2429 return ( _matrule ? _matrule->reduce_right(globals) : NULL );
aoqi@0 2430 }
aoqi@0 2431
aoqi@0 2432 // Similar for left
aoqi@0 2433 const char *OperandForm::reduce_left(FormDict &globals) const {
aoqi@0 2434 return ( _matrule ? _matrule->reduce_left(globals) : NULL );
aoqi@0 2435 }
aoqi@0 2436
aoqi@0 2437
aoqi@0 2438 // --------------------------- FILE *output_routines
aoqi@0 2439 //
aoqi@0 2440 // Output code for disp_is_oop, if true.
aoqi@0 2441 void OperandForm::disp_is_oop(FILE *fp, FormDict &globals) {
aoqi@0 2442 // Check it is a memory interface with a non-user-constant disp field
aoqi@0 2443 if ( this->_interface == NULL ) return;
aoqi@0 2444 MemInterface *mem_interface = this->_interface->is_MemInterface();
aoqi@0 2445 if ( mem_interface == NULL ) return;
aoqi@0 2446 const char *disp = mem_interface->_disp;
aoqi@0 2447 if ( *disp != '$' ) return;
aoqi@0 2448
aoqi@0 2449 // Lookup replacement variable in operand's component list
aoqi@0 2450 const char *rep_var = disp + 1;
aoqi@0 2451 const Component *comp = this->_components.search(rep_var);
aoqi@0 2452 assert( comp != NULL, "Replacement variable not found in components");
aoqi@0 2453 // Lookup operand form for replacement variable's type
aoqi@0 2454 const char *type = comp->_type;
aoqi@0 2455 Form *form = (Form*)globals[type];
aoqi@0 2456 assert( form != NULL, "Replacement variable's type not found");
aoqi@0 2457 OperandForm *op = form->is_operand();
aoqi@0 2458 assert( op, "Memory Interface 'disp' can only emit an operand form");
aoqi@0 2459 // Check if this is a ConP, which may require relocation
aoqi@0 2460 if ( op->is_base_constant(globals) == Form::idealP ) {
aoqi@0 2461 // Find the constant's index: _c0, _c1, _c2, ... , _cN
aoqi@0 2462 uint idx = op->constant_position( globals, rep_var);
aoqi@0 2463 fprintf(fp," virtual relocInfo::relocType disp_reloc() const {");
aoqi@0 2464 fprintf(fp, " return _c%d->reloc();", idx);
aoqi@0 2465 fprintf(fp, " }\n");
aoqi@0 2466 }
aoqi@0 2467 }
aoqi@0 2468
aoqi@0 2469 // Generate code for internal and external format methods
aoqi@0 2470 //
aoqi@0 2471 // internal access to reg# node->_idx
aoqi@0 2472 // access to subsumed constant _c0, _c1,
aoqi@0 2473 void OperandForm::int_format(FILE *fp, FormDict &globals, uint index) {
aoqi@0 2474 Form::DataType dtype;
aoqi@0 2475 if (_matrule && (_matrule->is_base_register(globals) ||
aoqi@0 2476 strcmp(ideal_type(globalAD->globalNames()), "RegFlags") == 0)) {
aoqi@0 2477 // !!!!! !!!!!
aoqi@0 2478 fprintf(fp," { char reg_str[128];\n");
aoqi@0 2479 fprintf(fp," ra->dump_register(node,reg_str);\n");
aoqi@0 2480 fprintf(fp," st->print(\"%cs\",reg_str);\n",'%');
aoqi@0 2481 fprintf(fp," }\n");
aoqi@0 2482 } else if (_matrule && (dtype = _matrule->is_base_constant(globals)) != Form::none) {
aoqi@0 2483 format_constant( fp, index, dtype );
aoqi@0 2484 } else if (ideal_to_sReg_type(_ident) != Form::none) {
aoqi@0 2485 // Special format for Stack Slot Register
aoqi@0 2486 fprintf(fp," { char reg_str[128];\n");
aoqi@0 2487 fprintf(fp," ra->dump_register(node,reg_str);\n");
aoqi@0 2488 fprintf(fp," st->print(\"%cs\",reg_str);\n",'%');
aoqi@0 2489 fprintf(fp," }\n");
aoqi@0 2490 } else {
aoqi@0 2491 fprintf(fp," st->print(\"No format defined for %s\n\");\n", _ident);
aoqi@0 2492 fflush(fp);
aoqi@0 2493 fprintf(stderr,"No format defined for %s\n", _ident);
aoqi@0 2494 dump();
aoqi@0 2495 assert( false,"Internal error:\n output_internal_operand() attempting to output other than a Register or Constant");
aoqi@0 2496 }
aoqi@0 2497 }
aoqi@0 2498
aoqi@0 2499 // Similar to "int_format" but for cases where data is external to operand
aoqi@0 2500 // external access to reg# node->in(idx)->_idx,
aoqi@0 2501 void OperandForm::ext_format(FILE *fp, FormDict &globals, uint index) {
aoqi@0 2502 Form::DataType dtype;
aoqi@0 2503 if (_matrule && (_matrule->is_base_register(globals) ||
aoqi@0 2504 strcmp(ideal_type(globalAD->globalNames()), "RegFlags") == 0)) {
aoqi@0 2505 fprintf(fp," { char reg_str[128];\n");
aoqi@0 2506 fprintf(fp," ra->dump_register(node->in(idx");
aoqi@0 2507 if ( index != 0 ) fprintf(fp, "+%d",index);
aoqi@0 2508 fprintf(fp, "),reg_str);\n");
aoqi@0 2509 fprintf(fp," st->print(\"%cs\",reg_str);\n",'%');
aoqi@0 2510 fprintf(fp," }\n");
aoqi@0 2511 } else if (_matrule && (dtype = _matrule->is_base_constant(globals)) != Form::none) {
aoqi@0 2512 format_constant( fp, index, dtype );
aoqi@0 2513 } else if (ideal_to_sReg_type(_ident) != Form::none) {
aoqi@0 2514 // Special format for Stack Slot Register
aoqi@0 2515 fprintf(fp," { char reg_str[128];\n");
aoqi@0 2516 fprintf(fp," ra->dump_register(node->in(idx");
aoqi@0 2517 if ( index != 0 ) fprintf(fp, "+%d",index);
aoqi@0 2518 fprintf(fp, "),reg_str);\n");
aoqi@0 2519 fprintf(fp," st->print(\"%cs\",reg_str);\n",'%');
aoqi@0 2520 fprintf(fp," }\n");
aoqi@0 2521 } else {
aoqi@0 2522 fprintf(fp," st->print(\"No format defined for %s\n\");\n", _ident);
aoqi@0 2523 assert( false,"Internal error:\n output_external_operand() attempting to output other than a Register or Constant");
aoqi@0 2524 }
aoqi@0 2525 }
aoqi@0 2526
aoqi@0 2527 void OperandForm::format_constant(FILE *fp, uint const_index, uint const_type) {
aoqi@0 2528 switch(const_type) {
aoqi@0 2529 case Form::idealI: fprintf(fp," st->print(\"#%%d\", _c%d);\n", const_index); break;
aoqi@0 2530 case Form::idealP: fprintf(fp," if (_c%d) _c%d->dump_on(st);\n", const_index, const_index); break;
aoqi@0 2531 case Form::idealNKlass:
aoqi@0 2532 case Form::idealN: fprintf(fp," if (_c%d) _c%d->dump_on(st);\n", const_index, const_index); break;
aoqi@0 2533 case Form::idealL: fprintf(fp," st->print(\"#\" INT64_FORMAT, (int64_t)_c%d);\n", const_index); break;
aoqi@0 2534 case Form::idealF: fprintf(fp," st->print(\"#%%f\", _c%d);\n", const_index); break;
aoqi@0 2535 case Form::idealD: fprintf(fp," st->print(\"#%%f\", _c%d);\n", const_index); break;
aoqi@0 2536 default:
aoqi@0 2537 assert( false, "ShouldNotReachHere()");
aoqi@0 2538 }
aoqi@0 2539 }
aoqi@0 2540
aoqi@0 2541 // Return the operand form corresponding to the given index, else NULL.
aoqi@0 2542 OperandForm *OperandForm::constant_operand(FormDict &globals,
aoqi@0 2543 uint index) {
aoqi@0 2544 // !!!!!
aoqi@0 2545 // Check behavior on complex operands
aoqi@0 2546 uint n_consts = num_consts(globals);
aoqi@0 2547 if( n_consts > 0 ) {
aoqi@0 2548 uint i = 0;
aoqi@0 2549 const char *type;
aoqi@0 2550 Component *comp;
aoqi@0 2551 _components.reset();
aoqi@0 2552 if ((comp = _components.iter()) == NULL) {
aoqi@0 2553 assert(n_consts == 1, "Bad component list detected.\n");
aoqi@0 2554 // Current operand is THE operand
aoqi@0 2555 if ( index == 0 ) {
aoqi@0 2556 return this;
aoqi@0 2557 }
aoqi@0 2558 } // end if NULL
aoqi@0 2559 else {
aoqi@0 2560 // Skip the first component, it can not be a DEF of a constant
aoqi@0 2561 do {
aoqi@0 2562 type = comp->base_type(globals);
aoqi@0 2563 // Check that "type" is a 'ConI', 'ConP', ...
aoqi@0 2564 if ( ideal_to_const_type(type) != Form::none ) {
aoqi@0 2565 // When at correct component, get corresponding Operand
aoqi@0 2566 if ( index == 0 ) {
aoqi@0 2567 return globals[comp->_type]->is_operand();
aoqi@0 2568 }
aoqi@0 2569 // Decrement number of constants to go
aoqi@0 2570 --index;
aoqi@0 2571 }
aoqi@0 2572 } while((comp = _components.iter()) != NULL);
aoqi@0 2573 }
aoqi@0 2574 }
aoqi@0 2575
aoqi@0 2576 // Did not find a constant for this index.
aoqi@0 2577 return NULL;
aoqi@0 2578 }
aoqi@0 2579
aoqi@0 2580 // If this operand has a single ideal type, return its type
aoqi@0 2581 Form::DataType OperandForm::simple_type(FormDict &globals) const {
aoqi@0 2582 const char *type_name = ideal_type(globals);
aoqi@0 2583 Form::DataType type = type_name ? ideal_to_const_type( type_name )
aoqi@0 2584 : Form::none;
aoqi@0 2585 return type;
aoqi@0 2586 }
aoqi@0 2587
aoqi@0 2588 Form::DataType OperandForm::is_base_constant(FormDict &globals) const {
aoqi@0 2589 if ( _matrule == NULL ) return Form::none;
aoqi@0 2590
aoqi@0 2591 return _matrule->is_base_constant(globals);
aoqi@0 2592 }
aoqi@0 2593
aoqi@0 2594 // "true" if this operand is a simple type that is swallowed
aoqi@0 2595 bool OperandForm::swallowed(FormDict &globals) const {
aoqi@0 2596 Form::DataType type = simple_type(globals);
aoqi@0 2597 if( type != Form::none ) {
aoqi@0 2598 return true;
aoqi@0 2599 }
aoqi@0 2600
aoqi@0 2601 return false;
aoqi@0 2602 }
aoqi@0 2603
aoqi@0 2604 // Output code to access the value of the index'th constant
aoqi@0 2605 void OperandForm::access_constant(FILE *fp, FormDict &globals,
aoqi@0 2606 uint const_index) {
aoqi@0 2607 OperandForm *oper = constant_operand(globals, const_index);
aoqi@0 2608 assert( oper, "Index exceeds number of constants in operand");
aoqi@0 2609 Form::DataType dtype = oper->is_base_constant(globals);
aoqi@0 2610
aoqi@0 2611 switch(dtype) {
aoqi@0 2612 case idealI: fprintf(fp,"_c%d", const_index); break;
aoqi@0 2613 case idealP: fprintf(fp,"_c%d->get_con()",const_index); break;
aoqi@0 2614 case idealL: fprintf(fp,"_c%d", const_index); break;
aoqi@0 2615 case idealF: fprintf(fp,"_c%d", const_index); break;
aoqi@0 2616 case idealD: fprintf(fp,"_c%d", const_index); break;
aoqi@0 2617 default:
aoqi@0 2618 assert( false, "ShouldNotReachHere()");
aoqi@0 2619 }
aoqi@0 2620 }
aoqi@0 2621
aoqi@0 2622
aoqi@0 2623 void OperandForm::dump() {
aoqi@0 2624 output(stderr);
aoqi@0 2625 }
aoqi@0 2626
aoqi@0 2627 void OperandForm::output(FILE *fp) {
aoqi@0 2628 fprintf(fp,"\nOperand: %s\n", (_ident?_ident:""));
aoqi@0 2629 if (_matrule) _matrule->dump();
aoqi@0 2630 if (_interface) _interface->dump();
aoqi@0 2631 if (_attribs) _attribs->dump();
aoqi@0 2632 if (_predicate) _predicate->dump();
aoqi@0 2633 if (_constraint) _constraint->dump();
aoqi@0 2634 if (_construct) _construct->dump();
aoqi@0 2635 if (_format) _format->dump();
aoqi@0 2636 }
aoqi@0 2637
aoqi@0 2638 //------------------------------Constraint-------------------------------------
aoqi@0 2639 Constraint::Constraint(const char *func, const char *arg)
aoqi@0 2640 : _func(func), _arg(arg) {
aoqi@0 2641 }
aoqi@0 2642 Constraint::~Constraint() { /* not owner of char* */
aoqi@0 2643 }
aoqi@0 2644
aoqi@0 2645 bool Constraint::stack_slots_only() const {
aoqi@0 2646 return strcmp(_func, "ALLOC_IN_RC") == 0
aoqi@0 2647 && strcmp(_arg, "stack_slots") == 0;
aoqi@0 2648 }
aoqi@0 2649
aoqi@0 2650 void Constraint::dump() {
aoqi@0 2651 output(stderr);
aoqi@0 2652 }
aoqi@0 2653
aoqi@0 2654 void Constraint::output(FILE *fp) { // Write info to output files
aoqi@0 2655 assert((_func != NULL && _arg != NULL),"missing constraint function or arg");
aoqi@0 2656 fprintf(fp,"Constraint: %s ( %s )\n", _func, _arg);
aoqi@0 2657 }
aoqi@0 2658
aoqi@0 2659 //------------------------------Predicate--------------------------------------
aoqi@0 2660 Predicate::Predicate(char *pr)
aoqi@0 2661 : _pred(pr) {
aoqi@0 2662 }
aoqi@0 2663 Predicate::~Predicate() {
aoqi@0 2664 }
aoqi@0 2665
aoqi@0 2666 void Predicate::dump() {
aoqi@0 2667 output(stderr);
aoqi@0 2668 }
aoqi@0 2669
aoqi@0 2670 void Predicate::output(FILE *fp) {
aoqi@0 2671 fprintf(fp,"Predicate"); // Write to output files
aoqi@0 2672 }
aoqi@0 2673 //------------------------------Interface--------------------------------------
aoqi@0 2674 Interface::Interface(const char *name) : _name(name) {
aoqi@0 2675 }
aoqi@0 2676 Interface::~Interface() {
aoqi@0 2677 }
aoqi@0 2678
aoqi@0 2679 Form::InterfaceType Interface::interface_type(FormDict &globals) const {
aoqi@0 2680 Interface *thsi = (Interface*)this;
aoqi@0 2681 if ( thsi->is_RegInterface() ) return Form::register_interface;
aoqi@0 2682 if ( thsi->is_MemInterface() ) return Form::memory_interface;
aoqi@0 2683 if ( thsi->is_ConstInterface() ) return Form::constant_interface;
aoqi@0 2684 if ( thsi->is_CondInterface() ) return Form::conditional_interface;
aoqi@0 2685
aoqi@0 2686 return Form::no_interface;
aoqi@0 2687 }
aoqi@0 2688
aoqi@0 2689 RegInterface *Interface::is_RegInterface() {
aoqi@0 2690 if ( strcmp(_name,"REG_INTER") != 0 )
aoqi@0 2691 return NULL;
aoqi@0 2692 return (RegInterface*)this;
aoqi@0 2693 }
aoqi@0 2694 MemInterface *Interface::is_MemInterface() {
aoqi@0 2695 if ( strcmp(_name,"MEMORY_INTER") != 0 ) return NULL;
aoqi@0 2696 return (MemInterface*)this;
aoqi@0 2697 }
aoqi@0 2698 ConstInterface *Interface::is_ConstInterface() {
aoqi@0 2699 if ( strcmp(_name,"CONST_INTER") != 0 ) return NULL;
aoqi@0 2700 return (ConstInterface*)this;
aoqi@0 2701 }
aoqi@0 2702 CondInterface *Interface::is_CondInterface() {
aoqi@0 2703 if ( strcmp(_name,"COND_INTER") != 0 ) return NULL;
aoqi@0 2704 return (CondInterface*)this;
aoqi@0 2705 }
aoqi@0 2706
aoqi@0 2707
aoqi@0 2708 void Interface::dump() {
aoqi@0 2709 output(stderr);
aoqi@0 2710 }
aoqi@0 2711
aoqi@0 2712 // Write info to output files
aoqi@0 2713 void Interface::output(FILE *fp) {
aoqi@0 2714 fprintf(fp,"Interface: %s\n", (_name ? _name : "") );
aoqi@0 2715 }
aoqi@0 2716
aoqi@0 2717 //------------------------------RegInterface-----------------------------------
aoqi@0 2718 RegInterface::RegInterface() : Interface("REG_INTER") {
aoqi@0 2719 }
aoqi@0 2720 RegInterface::~RegInterface() {
aoqi@0 2721 }
aoqi@0 2722
aoqi@0 2723 void RegInterface::dump() {
aoqi@0 2724 output(stderr);
aoqi@0 2725 }
aoqi@0 2726
aoqi@0 2727 // Write info to output files
aoqi@0 2728 void RegInterface::output(FILE *fp) {
aoqi@0 2729 Interface::output(fp);
aoqi@0 2730 }
aoqi@0 2731
aoqi@0 2732 //------------------------------ConstInterface---------------------------------
aoqi@0 2733 ConstInterface::ConstInterface() : Interface("CONST_INTER") {
aoqi@0 2734 }
aoqi@0 2735 ConstInterface::~ConstInterface() {
aoqi@0 2736 }
aoqi@0 2737
aoqi@0 2738 void ConstInterface::dump() {
aoqi@0 2739 output(stderr);
aoqi@0 2740 }
aoqi@0 2741
aoqi@0 2742 // Write info to output files
aoqi@0 2743 void ConstInterface::output(FILE *fp) {
aoqi@0 2744 Interface::output(fp);
aoqi@0 2745 }
aoqi@0 2746
aoqi@0 2747 //------------------------------MemInterface-----------------------------------
aoqi@0 2748 MemInterface::MemInterface(char *base, char *index, char *scale, char *disp)
aoqi@0 2749 : Interface("MEMORY_INTER"), _base(base), _index(index), _scale(scale), _disp(disp) {
aoqi@0 2750 }
aoqi@0 2751 MemInterface::~MemInterface() {
aoqi@0 2752 // not owner of any character arrays
aoqi@0 2753 }
aoqi@0 2754
aoqi@0 2755 void MemInterface::dump() {
aoqi@0 2756 output(stderr);
aoqi@0 2757 }
aoqi@0 2758
aoqi@0 2759 // Write info to output files
aoqi@0 2760 void MemInterface::output(FILE *fp) {
aoqi@0 2761 Interface::output(fp);
aoqi@0 2762 if ( _base != NULL ) fprintf(fp," base == %s\n", _base);
aoqi@0 2763 if ( _index != NULL ) fprintf(fp," index == %s\n", _index);
aoqi@0 2764 if ( _scale != NULL ) fprintf(fp," scale == %s\n", _scale);
aoqi@0 2765 if ( _disp != NULL ) fprintf(fp," disp == %s\n", _disp);
aoqi@0 2766 // fprintf(fp,"\n");
aoqi@0 2767 }
aoqi@0 2768
aoqi@0 2769 //------------------------------CondInterface----------------------------------
aoqi@0 2770 CondInterface::CondInterface(const char* equal, const char* equal_format,
aoqi@0 2771 const char* not_equal, const char* not_equal_format,
aoqi@0 2772 const char* less, const char* less_format,
aoqi@0 2773 const char* greater_equal, const char* greater_equal_format,
aoqi@0 2774 const char* less_equal, const char* less_equal_format,
aoqi@0 2775 const char* greater, const char* greater_format,
aoqi@0 2776 const char* overflow, const char* overflow_format,
aoqi@0 2777 const char* no_overflow, const char* no_overflow_format)
aoqi@0 2778 : Interface("COND_INTER"),
aoqi@0 2779 _equal(equal), _equal_format(equal_format),
aoqi@0 2780 _not_equal(not_equal), _not_equal_format(not_equal_format),
aoqi@0 2781 _less(less), _less_format(less_format),
aoqi@0 2782 _greater_equal(greater_equal), _greater_equal_format(greater_equal_format),
aoqi@0 2783 _less_equal(less_equal), _less_equal_format(less_equal_format),
aoqi@0 2784 _greater(greater), _greater_format(greater_format),
aoqi@0 2785 _overflow(overflow), _overflow_format(overflow_format),
aoqi@0 2786 _no_overflow(no_overflow), _no_overflow_format(no_overflow_format) {
aoqi@0 2787 }
aoqi@0 2788 CondInterface::~CondInterface() {
aoqi@0 2789 // not owner of any character arrays
aoqi@0 2790 }
aoqi@0 2791
aoqi@0 2792 void CondInterface::dump() {
aoqi@0 2793 output(stderr);
aoqi@0 2794 }
aoqi@0 2795
aoqi@0 2796 // Write info to output files
aoqi@0 2797 void CondInterface::output(FILE *fp) {
aoqi@0 2798 Interface::output(fp);
aoqi@0 2799 if ( _equal != NULL ) fprintf(fp," equal == %s\n", _equal);
aoqi@0 2800 if ( _not_equal != NULL ) fprintf(fp," not_equal == %s\n", _not_equal);
aoqi@0 2801 if ( _less != NULL ) fprintf(fp," less == %s\n", _less);
aoqi@0 2802 if ( _greater_equal != NULL ) fprintf(fp," greater_equal == %s\n", _greater_equal);
aoqi@0 2803 if ( _less_equal != NULL ) fprintf(fp," less_equal == %s\n", _less_equal);
aoqi@0 2804 if ( _greater != NULL ) fprintf(fp," greater == %s\n", _greater);
aoqi@0 2805 if ( _overflow != NULL ) fprintf(fp," overflow == %s\n", _overflow);
aoqi@0 2806 if ( _no_overflow != NULL ) fprintf(fp," no_overflow == %s\n", _no_overflow);
aoqi@0 2807 // fprintf(fp,"\n");
aoqi@0 2808 }
aoqi@0 2809
aoqi@0 2810 //------------------------------ConstructRule----------------------------------
aoqi@0 2811 ConstructRule::ConstructRule(char *cnstr)
aoqi@0 2812 : _construct(cnstr) {
aoqi@0 2813 }
aoqi@0 2814 ConstructRule::~ConstructRule() {
aoqi@0 2815 }
aoqi@0 2816
aoqi@0 2817 void ConstructRule::dump() {
aoqi@0 2818 output(stderr);
aoqi@0 2819 }
aoqi@0 2820
aoqi@0 2821 void ConstructRule::output(FILE *fp) {
aoqi@0 2822 fprintf(fp,"\nConstruct Rule\n"); // Write to output files
aoqi@0 2823 }
aoqi@0 2824
aoqi@0 2825
aoqi@0 2826 //==============================Shared Forms===================================
aoqi@0 2827 //------------------------------AttributeForm----------------------------------
aoqi@0 2828 int AttributeForm::_insId = 0; // start counter at 0
aoqi@0 2829 int AttributeForm::_opId = 0; // start counter at 0
aoqi@0 2830 const char* AttributeForm::_ins_cost = "ins_cost"; // required name
aoqi@0 2831 const char* AttributeForm::_op_cost = "op_cost"; // required name
aoqi@0 2832
aoqi@0 2833 AttributeForm::AttributeForm(char *attr, int type, char *attrdef)
aoqi@0 2834 : Form(Form::ATTR), _attrname(attr), _atype(type), _attrdef(attrdef) {
aoqi@0 2835 if (type==OP_ATTR) {
aoqi@0 2836 id = ++_opId;
aoqi@0 2837 }
aoqi@0 2838 else if (type==INS_ATTR) {
aoqi@0 2839 id = ++_insId;
aoqi@0 2840 }
aoqi@0 2841 else assert( false,"");
aoqi@0 2842 }
aoqi@0 2843 AttributeForm::~AttributeForm() {
aoqi@0 2844 }
aoqi@0 2845
aoqi@0 2846 // Dynamic type check
aoqi@0 2847 AttributeForm *AttributeForm::is_attribute() const {
aoqi@0 2848 return (AttributeForm*)this;
aoqi@0 2849 }
aoqi@0 2850
aoqi@0 2851
aoqi@0 2852 // inlined // int AttributeForm::type() { return id;}
aoqi@0 2853
aoqi@0 2854 void AttributeForm::dump() {
aoqi@0 2855 output(stderr);
aoqi@0 2856 }
aoqi@0 2857
aoqi@0 2858 void AttributeForm::output(FILE *fp) {
aoqi@0 2859 if( _attrname && _attrdef ) {
aoqi@0 2860 fprintf(fp,"\n// AttributeForm \nstatic const int %s = %s;\n",
aoqi@0 2861 _attrname, _attrdef);
aoqi@0 2862 }
aoqi@0 2863 else {
aoqi@0 2864 fprintf(fp,"\n// AttributeForm missing name %s or definition %s\n",
aoqi@0 2865 (_attrname?_attrname:""), (_attrdef?_attrdef:"") );
aoqi@0 2866 }
aoqi@0 2867 }
aoqi@0 2868
aoqi@0 2869 //------------------------------Component--------------------------------------
aoqi@0 2870 Component::Component(const char *name, const char *type, int usedef)
aoqi@0 2871 : _name(name), _type(type), _usedef(usedef) {
aoqi@0 2872 _ftype = Form::COMP;
aoqi@0 2873 }
aoqi@0 2874 Component::~Component() {
aoqi@0 2875 }
aoqi@0 2876
aoqi@0 2877 // True if this component is equal to the parameter.
aoqi@0 2878 bool Component::is(int use_def_kill_enum) const {
aoqi@0 2879 return (_usedef == use_def_kill_enum ? true : false);
aoqi@0 2880 }
aoqi@0 2881 // True if this component is used/def'd/kill'd as the parameter suggests.
aoqi@0 2882 bool Component::isa(int use_def_kill_enum) const {
aoqi@0 2883 return (_usedef & use_def_kill_enum) == use_def_kill_enum;
aoqi@0 2884 }
aoqi@0 2885
aoqi@0 2886 // Extend this component with additional use/def/kill behavior
aoqi@0 2887 int Component::promote_use_def_info(int new_use_def) {
aoqi@0 2888 _usedef |= new_use_def;
aoqi@0 2889
aoqi@0 2890 return _usedef;
aoqi@0 2891 }
aoqi@0 2892
aoqi@0 2893 // Check the base type of this component, if it has one
aoqi@0 2894 const char *Component::base_type(FormDict &globals) {
aoqi@0 2895 const Form *frm = globals[_type];
aoqi@0 2896 if (frm == NULL) return NULL;
aoqi@0 2897 OperandForm *op = frm->is_operand();
aoqi@0 2898 if (op == NULL) return NULL;
aoqi@0 2899 if (op->ideal_only()) return op->_ident;
aoqi@0 2900 return (char *)op->ideal_type(globals);
aoqi@0 2901 }
aoqi@0 2902
aoqi@0 2903 void Component::dump() {
aoqi@0 2904 output(stderr);
aoqi@0 2905 }
aoqi@0 2906
aoqi@0 2907 void Component::output(FILE *fp) {
aoqi@0 2908 fprintf(fp,"Component:"); // Write to output files
aoqi@0 2909 fprintf(fp, " name = %s", _name);
aoqi@0 2910 fprintf(fp, ", type = %s", _type);
aoqi@0 2911 assert(_usedef != 0, "unknown effect");
aoqi@0 2912 fprintf(fp, ", use/def = %s\n", getUsedefName());
aoqi@0 2913 }
aoqi@0 2914
aoqi@0 2915
aoqi@0 2916 //------------------------------ComponentList---------------------------------
aoqi@0 2917 ComponentList::ComponentList() : NameList(), _matchcnt(0) {
aoqi@0 2918 }
aoqi@0 2919 ComponentList::~ComponentList() {
aoqi@0 2920 // // This list may not own its elements if copied via assignment
aoqi@0 2921 // Component *component;
aoqi@0 2922 // for (reset(); (component = iter()) != NULL;) {
aoqi@0 2923 // delete component;
aoqi@0 2924 // }
aoqi@0 2925 }
aoqi@0 2926
aoqi@0 2927 void ComponentList::insert(Component *component, bool mflag) {
aoqi@0 2928 NameList::addName((char *)component);
aoqi@0 2929 if(mflag) _matchcnt++;
aoqi@0 2930 }
aoqi@0 2931 void ComponentList::insert(const char *name, const char *opType, int usedef,
aoqi@0 2932 bool mflag) {
aoqi@0 2933 Component * component = new Component(name, opType, usedef);
aoqi@0 2934 insert(component, mflag);
aoqi@0 2935 }
aoqi@0 2936 Component *ComponentList::current() { return (Component*)NameList::current(); }
aoqi@0 2937 Component *ComponentList::iter() { return (Component*)NameList::iter(); }
aoqi@0 2938 Component *ComponentList::match_iter() {
aoqi@0 2939 if(_iter < _matchcnt) return (Component*)NameList::iter();
aoqi@0 2940 return NULL;
aoqi@0 2941 }
aoqi@0 2942 Component *ComponentList::post_match_iter() {
aoqi@0 2943 Component *comp = iter();
aoqi@0 2944 // At end of list?
aoqi@0 2945 if ( comp == NULL ) {
aoqi@0 2946 return comp;
aoqi@0 2947 }
aoqi@0 2948 // In post-match components?
aoqi@0 2949 if (_iter > match_count()-1) {
aoqi@0 2950 return comp;
aoqi@0 2951 }
aoqi@0 2952
aoqi@0 2953 return post_match_iter();
aoqi@0 2954 }
aoqi@0 2955
aoqi@0 2956 void ComponentList::reset() { NameList::reset(); }
aoqi@0 2957 int ComponentList::count() { return NameList::count(); }
aoqi@0 2958
aoqi@0 2959 Component *ComponentList::operator[](int position) {
aoqi@0 2960 // Shortcut complete iteration if there are not enough entries
aoqi@0 2961 if (position >= count()) return NULL;
aoqi@0 2962
aoqi@0 2963 int index = 0;
aoqi@0 2964 Component *component = NULL;
aoqi@0 2965 for (reset(); (component = iter()) != NULL;) {
aoqi@0 2966 if (index == position) {
aoqi@0 2967 return component;
aoqi@0 2968 }
aoqi@0 2969 ++index;
aoqi@0 2970 }
aoqi@0 2971
aoqi@0 2972 return NULL;
aoqi@0 2973 }
aoqi@0 2974
aoqi@0 2975 const Component *ComponentList::search(const char *name) {
aoqi@0 2976 PreserveIter pi(this);
aoqi@0 2977 reset();
aoqi@0 2978 for( Component *comp = NULL; ((comp = iter()) != NULL); ) {
aoqi@0 2979 if( strcmp(comp->_name,name) == 0 ) return comp;
aoqi@0 2980 }
aoqi@0 2981
aoqi@0 2982 return NULL;
aoqi@0 2983 }
aoqi@0 2984
aoqi@0 2985 // Return number of USEs + number of DEFs
aoqi@0 2986 // When there are no components, or the first component is a USE,
aoqi@0 2987 // then we add '1' to hold a space for the 'result' operand.
aoqi@0 2988 int ComponentList::num_operands() {
aoqi@0 2989 PreserveIter pi(this);
aoqi@0 2990 uint count = 1; // result operand
aoqi@0 2991 uint position = 0;
aoqi@0 2992
aoqi@0 2993 Component *component = NULL;
aoqi@0 2994 for( reset(); (component = iter()) != NULL; ++position ) {
aoqi@0 2995 if( component->isa(Component::USE) ||
aoqi@0 2996 ( position == 0 && (! component->isa(Component::DEF))) ) {
aoqi@0 2997 ++count;
aoqi@0 2998 }
aoqi@0 2999 }
aoqi@0 3000
aoqi@0 3001 return count;
aoqi@0 3002 }
aoqi@0 3003
aoqi@0 3004 // Return zero-based position of operand 'name' in list; -1 if not in list.
aoqi@0 3005 // if parameter 'usedef' is ::USE, it will match USE, USE_DEF, ...
aoqi@0 3006 int ComponentList::operand_position(const char *name, int usedef, Form *fm) {
aoqi@0 3007 PreserveIter pi(this);
aoqi@0 3008 int position = 0;
aoqi@0 3009 int num_opnds = num_operands();
aoqi@0 3010 Component *component;
aoqi@0 3011 Component* preceding_non_use = NULL;
aoqi@0 3012 Component* first_def = NULL;
aoqi@0 3013 for (reset(); (component = iter()) != NULL; ++position) {
aoqi@0 3014 // When the first component is not a DEF,
aoqi@0 3015 // leave space for the result operand!
aoqi@0 3016 if ( position==0 && (! component->isa(Component::DEF)) ) {
aoqi@0 3017 ++position;
aoqi@0 3018 ++num_opnds;
aoqi@0 3019 }
aoqi@0 3020 if (strcmp(name, component->_name)==0 && (component->isa(usedef))) {
aoqi@0 3021 // When the first entry in the component list is a DEF and a USE
aoqi@0 3022 // Treat them as being separate, a DEF first, then a USE
aoqi@0 3023 if( position==0
aoqi@0 3024 && usedef==Component::USE && component->isa(Component::DEF) ) {
aoqi@0 3025 assert(position+1 < num_opnds, "advertised index in bounds");
aoqi@0 3026 return position+1;
aoqi@0 3027 } else {
aoqi@0 3028 if( preceding_non_use && strcmp(component->_name, preceding_non_use->_name) ) {
aoqi@0 3029 fprintf(stderr, "the name '%s(%s)' should not precede the name '%s(%s)'",
aoqi@0 3030 preceding_non_use->_name, preceding_non_use->getUsedefName(),
aoqi@0 3031 name, component->getUsedefName());
aoqi@0 3032 if (fm && fm->is_instruction()) fprintf(stderr, "in form '%s'", fm->is_instruction()->_ident);
aoqi@0 3033 if (fm && fm->is_operand()) fprintf(stderr, "in form '%s'", fm->is_operand()->_ident);
aoqi@0 3034 fprintf(stderr, "\n");
aoqi@0 3035 }
aoqi@0 3036 if( position >= num_opnds ) {
aoqi@0 3037 fprintf(stderr, "the name '%s' is too late in its name list", name);
aoqi@0 3038 if (fm && fm->is_instruction()) fprintf(stderr, "in form '%s'", fm->is_instruction()->_ident);
aoqi@0 3039 if (fm && fm->is_operand()) fprintf(stderr, "in form '%s'", fm->is_operand()->_ident);
aoqi@0 3040 fprintf(stderr, "\n");
aoqi@0 3041 }
aoqi@0 3042 assert(position < num_opnds, "advertised index in bounds");
aoqi@0 3043 return position;
aoqi@0 3044 }
aoqi@0 3045 }
aoqi@0 3046 if( component->isa(Component::DEF)
aoqi@0 3047 && component->isa(Component::USE) ) {
aoqi@0 3048 ++position;
aoqi@0 3049 if( position != 1 ) --position; // only use two slots for the 1st USE_DEF
aoqi@0 3050 }
aoqi@0 3051 if( component->isa(Component::DEF) && !first_def ) {
aoqi@0 3052 first_def = component;
aoqi@0 3053 }
aoqi@0 3054 if( !component->isa(Component::USE) && component != first_def ) {
aoqi@0 3055 preceding_non_use = component;
aoqi@0 3056 } else if( preceding_non_use && !strcmp(component->_name, preceding_non_use->_name) ) {
aoqi@0 3057 preceding_non_use = NULL;
aoqi@0 3058 }
aoqi@0 3059 }
aoqi@0 3060 return Not_in_list;
aoqi@0 3061 }
aoqi@0 3062
aoqi@0 3063 // Find position for this name, regardless of use/def information
aoqi@0 3064 int ComponentList::operand_position(const char *name) {
aoqi@0 3065 PreserveIter pi(this);
aoqi@0 3066 int position = 0;
aoqi@0 3067 Component *component;
aoqi@0 3068 for (reset(); (component = iter()) != NULL; ++position) {
aoqi@0 3069 // When the first component is not a DEF,
aoqi@0 3070 // leave space for the result operand!
aoqi@0 3071 if ( position==0 && (! component->isa(Component::DEF)) ) {
aoqi@0 3072 ++position;
aoqi@0 3073 }
aoqi@0 3074 if (strcmp(name, component->_name)==0) {
aoqi@0 3075 return position;
aoqi@0 3076 }
aoqi@0 3077 if( component->isa(Component::DEF)
aoqi@0 3078 && component->isa(Component::USE) ) {
aoqi@0 3079 ++position;
aoqi@0 3080 if( position != 1 ) --position; // only use two slots for the 1st USE_DEF
aoqi@0 3081 }
aoqi@0 3082 }
aoqi@0 3083 return Not_in_list;
aoqi@0 3084 }
aoqi@0 3085
aoqi@0 3086 int ComponentList::operand_position_format(const char *name, Form *fm) {
aoqi@0 3087 PreserveIter pi(this);
aoqi@0 3088 int first_position = operand_position(name);
aoqi@0 3089 int use_position = operand_position(name, Component::USE, fm);
aoqi@0 3090
aoqi@0 3091 return ((first_position < use_position) ? use_position : first_position);
aoqi@0 3092 }
aoqi@0 3093
aoqi@0 3094 int ComponentList::label_position() {
aoqi@0 3095 PreserveIter pi(this);
aoqi@0 3096 int position = 0;
aoqi@0 3097 reset();
aoqi@0 3098 for( Component *comp; (comp = iter()) != NULL; ++position) {
aoqi@0 3099 // When the first component is not a DEF,
aoqi@0 3100 // leave space for the result operand!
aoqi@0 3101 if ( position==0 && (! comp->isa(Component::DEF)) ) {
aoqi@0 3102 ++position;
aoqi@0 3103 }
aoqi@0 3104 if (strcmp(comp->_type, "label")==0) {
aoqi@0 3105 return position;
aoqi@0 3106 }
aoqi@0 3107 if( comp->isa(Component::DEF)
aoqi@0 3108 && comp->isa(Component::USE) ) {
aoqi@0 3109 ++position;
aoqi@0 3110 if( position != 1 ) --position; // only use two slots for the 1st USE_DEF
aoqi@0 3111 }
aoqi@0 3112 }
aoqi@0 3113
aoqi@0 3114 return -1;
aoqi@0 3115 }
aoqi@0 3116
aoqi@0 3117 int ComponentList::method_position() {
aoqi@0 3118 PreserveIter pi(this);
aoqi@0 3119 int position = 0;
aoqi@0 3120 reset();
aoqi@0 3121 for( Component *comp; (comp = iter()) != NULL; ++position) {
aoqi@0 3122 // When the first component is not a DEF,
aoqi@0 3123 // leave space for the result operand!
aoqi@0 3124 if ( position==0 && (! comp->isa(Component::DEF)) ) {
aoqi@0 3125 ++position;
aoqi@0 3126 }
aoqi@0 3127 if (strcmp(comp->_type, "method")==0) {
aoqi@0 3128 return position;
aoqi@0 3129 }
aoqi@0 3130 if( comp->isa(Component::DEF)
aoqi@0 3131 && comp->isa(Component::USE) ) {
aoqi@0 3132 ++position;
aoqi@0 3133 if( position != 1 ) --position; // only use two slots for the 1st USE_DEF
aoqi@0 3134 }
aoqi@0 3135 }
aoqi@0 3136
aoqi@0 3137 return -1;
aoqi@0 3138 }
aoqi@0 3139
aoqi@0 3140 void ComponentList::dump() { output(stderr); }
aoqi@0 3141
aoqi@0 3142 void ComponentList::output(FILE *fp) {
aoqi@0 3143 PreserveIter pi(this);
aoqi@0 3144 fprintf(fp, "\n");
aoqi@0 3145 Component *component;
aoqi@0 3146 for (reset(); (component = iter()) != NULL;) {
aoqi@0 3147 component->output(fp);
aoqi@0 3148 }
aoqi@0 3149 fprintf(fp, "\n");
aoqi@0 3150 }
aoqi@0 3151
aoqi@0 3152 //------------------------------MatchNode--------------------------------------
aoqi@0 3153 MatchNode::MatchNode(ArchDesc &ad, const char *result, const char *mexpr,
aoqi@0 3154 const char *opType, MatchNode *lChild, MatchNode *rChild)
aoqi@0 3155 : _AD(ad), _result(result), _name(mexpr), _opType(opType),
aoqi@0 3156 _lChild(lChild), _rChild(rChild), _internalop(0), _numleaves(0),
aoqi@0 3157 _commutative_id(0) {
aoqi@0 3158 _numleaves = (lChild ? lChild->_numleaves : 0)
aoqi@0 3159 + (rChild ? rChild->_numleaves : 0);
aoqi@0 3160 }
aoqi@0 3161
aoqi@0 3162 MatchNode::MatchNode(ArchDesc &ad, MatchNode& mnode)
aoqi@0 3163 : _AD(ad), _result(mnode._result), _name(mnode._name),
aoqi@0 3164 _opType(mnode._opType), _lChild(mnode._lChild), _rChild(mnode._rChild),
aoqi@0 3165 _internalop(0), _numleaves(mnode._numleaves),
aoqi@0 3166 _commutative_id(mnode._commutative_id) {
aoqi@0 3167 }
aoqi@0 3168
aoqi@0 3169 MatchNode::MatchNode(ArchDesc &ad, MatchNode& mnode, int clone)
aoqi@0 3170 : _AD(ad), _result(mnode._result), _name(mnode._name),
aoqi@0 3171 _opType(mnode._opType),
aoqi@0 3172 _internalop(0), _numleaves(mnode._numleaves),
aoqi@0 3173 _commutative_id(mnode._commutative_id) {
aoqi@0 3174 if (mnode._lChild) {
aoqi@0 3175 _lChild = new MatchNode(ad, *mnode._lChild, clone);
aoqi@0 3176 } else {
aoqi@0 3177 _lChild = NULL;
aoqi@0 3178 }
aoqi@0 3179 if (mnode._rChild) {
aoqi@0 3180 _rChild = new MatchNode(ad, *mnode._rChild, clone);
aoqi@0 3181 } else {
aoqi@0 3182 _rChild = NULL;
aoqi@0 3183 }
aoqi@0 3184 }
aoqi@0 3185
aoqi@0 3186 MatchNode::~MatchNode() {
aoqi@0 3187 // // This node may not own its children if copied via assignment
aoqi@0 3188 // if( _lChild ) delete _lChild;
aoqi@0 3189 // if( _rChild ) delete _rChild;
aoqi@0 3190 }
aoqi@0 3191
aoqi@0 3192 bool MatchNode::find_type(const char *type, int &position) const {
aoqi@0 3193 if ( (_lChild != NULL) && (_lChild->find_type(type, position)) ) return true;
aoqi@0 3194 if ( (_rChild != NULL) && (_rChild->find_type(type, position)) ) return true;
aoqi@0 3195
aoqi@0 3196 if (strcmp(type,_opType)==0) {
aoqi@0 3197 return true;
aoqi@0 3198 } else {
aoqi@0 3199 ++position;
aoqi@0 3200 }
aoqi@0 3201 return false;
aoqi@0 3202 }
aoqi@0 3203
aoqi@0 3204 // Recursive call collecting info on top-level operands, not transitive.
aoqi@0 3205 // Implementation does not modify state of internal structures.
aoqi@0 3206 void MatchNode::append_components(FormDict& locals, ComponentList& components,
aoqi@0 3207 bool def_flag) const {
aoqi@0 3208 int usedef = def_flag ? Component::DEF : Component::USE;
aoqi@0 3209 FormDict &globals = _AD.globalNames();
aoqi@0 3210
aoqi@0 3211 assert (_name != NULL, "MatchNode::build_components encountered empty node\n");
aoqi@0 3212 // Base case
aoqi@0 3213 if (_lChild==NULL && _rChild==NULL) {
aoqi@0 3214 // If _opType is not an operation, do not build a component for it #####
aoqi@0 3215 const Form *f = globals[_opType];
aoqi@0 3216 if( f != NULL ) {
aoqi@0 3217 // Add non-ideals that are operands, operand-classes,
aoqi@0 3218 if( ! f->ideal_only()
aoqi@0 3219 && (f->is_opclass() || f->is_operand()) ) {
aoqi@0 3220 components.insert(_name, _opType, usedef, true);
aoqi@0 3221 }
aoqi@0 3222 }
aoqi@0 3223 return;
aoqi@0 3224 }
aoqi@0 3225 // Promote results of "Set" to DEF
aoqi@0 3226 bool tmpdef_flag = (!strcmp(_opType, "Set")) ? true : false;
aoqi@0 3227 if (_lChild) _lChild->append_components(locals, components, tmpdef_flag);
aoqi@0 3228 tmpdef_flag = false; // only applies to component immediately following 'Set'
aoqi@0 3229 if (_rChild) _rChild->append_components(locals, components, tmpdef_flag);
aoqi@0 3230 }
aoqi@0 3231
aoqi@0 3232 // Find the n'th base-operand in the match node,
aoqi@0 3233 // recursively investigates match rules of user-defined operands.
aoqi@0 3234 //
aoqi@0 3235 // Implementation does not modify state of internal structures since they
aoqi@0 3236 // can be shared.
aoqi@0 3237 bool MatchNode::base_operand(uint &position, FormDict &globals,
aoqi@0 3238 const char * &result, const char * &name,
aoqi@0 3239 const char * &opType) const {
aoqi@0 3240 assert (_name != NULL, "MatchNode::base_operand encountered empty node\n");
aoqi@0 3241 // Base case
aoqi@0 3242 if (_lChild==NULL && _rChild==NULL) {
aoqi@0 3243 // Check for special case: "Universe", "label"
aoqi@0 3244 if (strcmp(_opType,"Universe") == 0 || strcmp(_opType,"label")==0 ) {
aoqi@0 3245 if (position == 0) {
aoqi@0 3246 result = _result;
aoqi@0 3247 name = _name;
aoqi@0 3248 opType = _opType;
aoqi@0 3249 return 1;
aoqi@0 3250 } else {
aoqi@0 3251 -- position;
aoqi@0 3252 return 0;
aoqi@0 3253 }
aoqi@0 3254 }
aoqi@0 3255
aoqi@0 3256 const Form *form = globals[_opType];
aoqi@0 3257 MatchNode *matchNode = NULL;
aoqi@0 3258 // Check for user-defined type
aoqi@0 3259 if (form) {
aoqi@0 3260 // User operand or instruction?
aoqi@0 3261 OperandForm *opForm = form->is_operand();
aoqi@0 3262 InstructForm *inForm = form->is_instruction();
aoqi@0 3263 if ( opForm ) {
aoqi@0 3264 matchNode = (MatchNode*)opForm->_matrule;
aoqi@0 3265 } else if ( inForm ) {
aoqi@0 3266 matchNode = (MatchNode*)inForm->_matrule;
aoqi@0 3267 }
aoqi@0 3268 }
aoqi@0 3269 // if this is user-defined, recurse on match rule
aoqi@0 3270 // User-defined operand and instruction forms have a match-rule.
aoqi@0 3271 if (matchNode) {
aoqi@0 3272 return (matchNode->base_operand(position,globals,result,name,opType));
aoqi@0 3273 } else {
aoqi@0 3274 // Either not a form, or a system-defined form (no match rule).
aoqi@0 3275 if (position==0) {
aoqi@0 3276 result = _result;
aoqi@0 3277 name = _name;
aoqi@0 3278 opType = _opType;
aoqi@0 3279 return 1;
aoqi@0 3280 } else {
aoqi@0 3281 --position;
aoqi@0 3282 return 0;
aoqi@0 3283 }
aoqi@0 3284 }
aoqi@0 3285
aoqi@0 3286 } else {
aoqi@0 3287 // Examine the left child and right child as well
aoqi@0 3288 if (_lChild) {
aoqi@0 3289 if (_lChild->base_operand(position, globals, result, name, opType))
aoqi@0 3290 return 1;
aoqi@0 3291 }
aoqi@0 3292
aoqi@0 3293 if (_rChild) {
aoqi@0 3294 if (_rChild->base_operand(position, globals, result, name, opType))
aoqi@0 3295 return 1;
aoqi@0 3296 }
aoqi@0 3297 }
aoqi@0 3298
aoqi@0 3299 return 0;
aoqi@0 3300 }
aoqi@0 3301
aoqi@0 3302 // Recursive call on all operands' match rules in my match rule.
aoqi@0 3303 uint MatchNode::num_consts(FormDict &globals) const {
aoqi@0 3304 uint index = 0;
aoqi@0 3305 uint num_consts = 0;
aoqi@0 3306 const char *result;
aoqi@0 3307 const char *name;
aoqi@0 3308 const char *opType;
aoqi@0 3309
aoqi@0 3310 for (uint position = index;
aoqi@0 3311 base_operand(position,globals,result,name,opType); position = index) {
aoqi@0 3312 ++index;
aoqi@0 3313 if( ideal_to_const_type(opType) ) num_consts++;
aoqi@0 3314 }
aoqi@0 3315
aoqi@0 3316 return num_consts;
aoqi@0 3317 }
aoqi@0 3318
aoqi@0 3319 // Recursive call on all operands' match rules in my match rule.
aoqi@0 3320 // Constants in match rule subtree with specified type
aoqi@0 3321 uint MatchNode::num_consts(FormDict &globals, Form::DataType type) const {
aoqi@0 3322 uint index = 0;
aoqi@0 3323 uint num_consts = 0;
aoqi@0 3324 const char *result;
aoqi@0 3325 const char *name;
aoqi@0 3326 const char *opType;
aoqi@0 3327
aoqi@0 3328 for (uint position = index;
aoqi@0 3329 base_operand(position,globals,result,name,opType); position = index) {
aoqi@0 3330 ++index;
aoqi@0 3331 if( ideal_to_const_type(opType) == type ) num_consts++;
aoqi@0 3332 }
aoqi@0 3333
aoqi@0 3334 return num_consts;
aoqi@0 3335 }
aoqi@0 3336
aoqi@0 3337 // Recursive call on all operands' match rules in my match rule.
aoqi@0 3338 uint MatchNode::num_const_ptrs(FormDict &globals) const {
aoqi@0 3339 return num_consts( globals, Form::idealP );
aoqi@0 3340 }
aoqi@0 3341
aoqi@0 3342 bool MatchNode::sets_result() const {
aoqi@0 3343 return ( (strcmp(_name,"Set") == 0) ? true : false );
aoqi@0 3344 }
aoqi@0 3345
aoqi@0 3346 const char *MatchNode::reduce_right(FormDict &globals) const {
aoqi@0 3347 // If there is no right reduction, return NULL.
aoqi@0 3348 const char *rightStr = NULL;
aoqi@0 3349
aoqi@0 3350 // If we are a "Set", start from the right child.
aoqi@0 3351 const MatchNode *const mnode = sets_result() ?
aoqi@0 3352 (const MatchNode *)this->_rChild :
aoqi@0 3353 (const MatchNode *)this;
aoqi@0 3354
aoqi@0 3355 // If our right child exists, it is the right reduction
aoqi@0 3356 if ( mnode->_rChild ) {
aoqi@0 3357 rightStr = mnode->_rChild->_internalop ? mnode->_rChild->_internalop
aoqi@0 3358 : mnode->_rChild->_opType;
aoqi@0 3359 }
aoqi@0 3360 // Else, May be simple chain rule: (Set dst operand_form), rightStr=NULL;
aoqi@0 3361 return rightStr;
aoqi@0 3362 }
aoqi@0 3363
aoqi@0 3364 const char *MatchNode::reduce_left(FormDict &globals) const {
aoqi@0 3365 // If there is no left reduction, return NULL.
aoqi@0 3366 const char *leftStr = NULL;
aoqi@0 3367
aoqi@0 3368 // If we are a "Set", start from the right child.
aoqi@0 3369 const MatchNode *const mnode = sets_result() ?
aoqi@0 3370 (const MatchNode *)this->_rChild :
aoqi@0 3371 (const MatchNode *)this;
aoqi@0 3372
aoqi@0 3373 // If our left child exists, it is the left reduction
aoqi@0 3374 if ( mnode->_lChild ) {
aoqi@0 3375 leftStr = mnode->_lChild->_internalop ? mnode->_lChild->_internalop
aoqi@0 3376 : mnode->_lChild->_opType;
aoqi@0 3377 } else {
aoqi@0 3378 // May be simple chain rule: (Set dst operand_form_source)
aoqi@0 3379 if ( sets_result() ) {
aoqi@0 3380 OperandForm *oper = globals[mnode->_opType]->is_operand();
aoqi@0 3381 if( oper ) {
aoqi@0 3382 leftStr = mnode->_opType;
aoqi@0 3383 }
aoqi@0 3384 }
aoqi@0 3385 }
aoqi@0 3386 return leftStr;
aoqi@0 3387 }
aoqi@0 3388
aoqi@0 3389 //------------------------------count_instr_names------------------------------
aoqi@0 3390 // Count occurrences of operands names in the leaves of the instruction
aoqi@0 3391 // match rule.
aoqi@0 3392 void MatchNode::count_instr_names( Dict &names ) {
aoqi@0 3393 if( !this ) return;
aoqi@0 3394 if( _lChild ) _lChild->count_instr_names(names);
aoqi@0 3395 if( _rChild ) _rChild->count_instr_names(names);
aoqi@0 3396 if( !_lChild && !_rChild ) {
aoqi@0 3397 uintptr_t cnt = (uintptr_t)names[_name];
aoqi@0 3398 cnt++; // One more name found
aoqi@0 3399 names.Insert(_name,(void*)cnt);
aoqi@0 3400 }
aoqi@0 3401 }
aoqi@0 3402
aoqi@0 3403 //------------------------------build_instr_pred-------------------------------
aoqi@0 3404 // Build a path to 'name' in buf. Actually only build if cnt is zero, so we
aoqi@0 3405 // can skip some leading instances of 'name'.
aoqi@0 3406 int MatchNode::build_instr_pred( char *buf, const char *name, int cnt ) {
aoqi@0 3407 if( _lChild ) {
aoqi@0 3408 if( !cnt ) strcpy( buf, "_kids[0]->" );
aoqi@0 3409 cnt = _lChild->build_instr_pred( buf+strlen(buf), name, cnt );
aoqi@0 3410 if( cnt < 0 ) return cnt; // Found it, all done
aoqi@0 3411 }
aoqi@0 3412 if( _rChild ) {
aoqi@0 3413 if( !cnt ) strcpy( buf, "_kids[1]->" );
aoqi@0 3414 cnt = _rChild->build_instr_pred( buf+strlen(buf), name, cnt );
aoqi@0 3415 if( cnt < 0 ) return cnt; // Found it, all done
aoqi@0 3416 }
aoqi@0 3417 if( !_lChild && !_rChild ) { // Found a leaf
aoqi@0 3418 // Wrong name? Give up...
aoqi@0 3419 if( strcmp(name,_name) ) return cnt;
aoqi@0 3420 if( !cnt ) strcpy(buf,"_leaf");
aoqi@0 3421 return cnt-1;
aoqi@0 3422 }
aoqi@0 3423 return cnt;
aoqi@0 3424 }
aoqi@0 3425
aoqi@0 3426
aoqi@0 3427 //------------------------------build_internalop-------------------------------
aoqi@0 3428 // Build string representation of subtree
aoqi@0 3429 void MatchNode::build_internalop( ) {
aoqi@0 3430 char *iop, *subtree;
aoqi@0 3431 const char *lstr, *rstr;
aoqi@0 3432 // Build string representation of subtree
aoqi@0 3433 // Operation lchildType rchildType
aoqi@0 3434 int len = (int)strlen(_opType) + 4;
aoqi@0 3435 lstr = (_lChild) ? ((_lChild->_internalop) ?
aoqi@0 3436 _lChild->_internalop : _lChild->_opType) : "";
aoqi@0 3437 rstr = (_rChild) ? ((_rChild->_internalop) ?
aoqi@0 3438 _rChild->_internalop : _rChild->_opType) : "";
aoqi@0 3439 len += (int)strlen(lstr) + (int)strlen(rstr);
aoqi@0 3440 subtree = (char *)malloc(len);
aoqi@0 3441 sprintf(subtree,"_%s_%s_%s", _opType, lstr, rstr);
aoqi@0 3442 // Hash the subtree string in _internalOps; if a name exists, use it
aoqi@0 3443 iop = (char *)_AD._internalOps[subtree];
aoqi@0 3444 // Else create a unique name, and add it to the hash table
aoqi@0 3445 if (iop == NULL) {
aoqi@0 3446 iop = subtree;
aoqi@0 3447 _AD._internalOps.Insert(subtree, iop);
aoqi@0 3448 _AD._internalOpNames.addName(iop);
aoqi@0 3449 _AD._internalMatch.Insert(iop, this);
aoqi@0 3450 }
aoqi@0 3451 // Add the internal operand name to the MatchNode
aoqi@0 3452 _internalop = iop;
aoqi@0 3453 _result = iop;
aoqi@0 3454 }
aoqi@0 3455
aoqi@0 3456
aoqi@0 3457 void MatchNode::dump() {
aoqi@0 3458 output(stderr);
aoqi@0 3459 }
aoqi@0 3460
aoqi@0 3461 void MatchNode::output(FILE *fp) {
aoqi@0 3462 if (_lChild==0 && _rChild==0) {
aoqi@0 3463 fprintf(fp," %s",_name); // operand
aoqi@0 3464 }
aoqi@0 3465 else {
aoqi@0 3466 fprintf(fp," (%s ",_name); // " (opcodeName "
aoqi@0 3467 if(_lChild) _lChild->output(fp); // left operand
aoqi@0 3468 if(_rChild) _rChild->output(fp); // right operand
aoqi@0 3469 fprintf(fp,")"); // ")"
aoqi@0 3470 }
aoqi@0 3471 }
aoqi@0 3472
aoqi@0 3473 int MatchNode::needs_ideal_memory_edge(FormDict &globals) const {
aoqi@0 3474 static const char *needs_ideal_memory_list[] = {
aoqi@0 3475 "StoreI","StoreL","StoreP","StoreN","StoreNKlass","StoreD","StoreF" ,
aoqi@0 3476 "StoreB","StoreC","Store" ,"StoreFP",
aoqi@0 3477 "LoadI", "LoadL", "LoadP" ,"LoadN", "LoadD" ,"LoadF" ,
aoqi@0 3478 "LoadB" , "LoadUB", "LoadUS" ,"LoadS" ,"Load" ,
aoqi@0 3479 "StoreVector", "LoadVector",
aoqi@0 3480 "LoadRange", "LoadKlass", "LoadNKlass", "LoadL_unaligned", "LoadD_unaligned",
aoqi@0 3481 "LoadPLocked",
aoqi@0 3482 "StorePConditional", "StoreIConditional", "StoreLConditional",
aoqi@0 3483 "CompareAndSwapI", "CompareAndSwapL", "CompareAndSwapP", "CompareAndSwapN",
aoqi@0 3484 "StoreCM",
aoqi@0 3485 "ClearArray",
aoqi@0 3486 "GetAndAddI", "GetAndSetI", "GetAndSetP",
aoqi@0 3487 "GetAndAddL", "GetAndSetL", "GetAndSetN",
aoqi@0 3488 };
aoqi@0 3489 int cnt = sizeof(needs_ideal_memory_list)/sizeof(char*);
aoqi@0 3490 if( strcmp(_opType,"PrefetchRead")==0 ||
aoqi@0 3491 strcmp(_opType,"PrefetchWrite")==0 ||
aoqi@0 3492 strcmp(_opType,"PrefetchAllocation")==0 )
aoqi@0 3493 return 1;
aoqi@0 3494 if( _lChild ) {
aoqi@0 3495 const char *opType = _lChild->_opType;
aoqi@0 3496 for( int i=0; i<cnt; i++ )
aoqi@0 3497 if( strcmp(opType,needs_ideal_memory_list[i]) == 0 )
aoqi@0 3498 return 1;
aoqi@0 3499 if( _lChild->needs_ideal_memory_edge(globals) )
aoqi@0 3500 return 1;
aoqi@0 3501 }
aoqi@0 3502 if( _rChild ) {
aoqi@0 3503 const char *opType = _rChild->_opType;
aoqi@0 3504 for( int i=0; i<cnt; i++ )
aoqi@0 3505 if( strcmp(opType,needs_ideal_memory_list[i]) == 0 )
aoqi@0 3506 return 1;
aoqi@0 3507 if( _rChild->needs_ideal_memory_edge(globals) )
aoqi@0 3508 return 1;
aoqi@0 3509 }
aoqi@0 3510
aoqi@0 3511 return 0;
aoqi@0 3512 }
aoqi@0 3513
aoqi@0 3514 // TRUE if defines a derived oop, and so needs a base oop edge present
aoqi@0 3515 // post-matching.
aoqi@0 3516 int MatchNode::needs_base_oop_edge() const {
aoqi@0 3517 if( !strcmp(_opType,"AddP") ) return 1;
aoqi@0 3518 if( strcmp(_opType,"Set") ) return 0;
aoqi@0 3519 return !strcmp(_rChild->_opType,"AddP");
aoqi@0 3520 }
aoqi@0 3521
aoqi@0 3522 int InstructForm::needs_base_oop_edge(FormDict &globals) const {
aoqi@0 3523 if( is_simple_chain_rule(globals) ) {
aoqi@0 3524 const char *src = _matrule->_rChild->_opType;
aoqi@0 3525 OperandForm *src_op = globals[src]->is_operand();
aoqi@0 3526 assert( src_op, "Not operand class of chain rule" );
aoqi@0 3527 return src_op->_matrule ? src_op->_matrule->needs_base_oop_edge() : 0;
aoqi@0 3528 } // Else check instruction
aoqi@0 3529
aoqi@0 3530 return _matrule ? _matrule->needs_base_oop_edge() : 0;
aoqi@0 3531 }
aoqi@0 3532
aoqi@0 3533
aoqi@0 3534 //-------------------------cisc spilling methods-------------------------------
aoqi@0 3535 // helper routines and methods for detecting cisc-spilling instructions
aoqi@0 3536 //-------------------------cisc_spill_merge------------------------------------
aoqi@0 3537 int MatchNode::cisc_spill_merge(int left_spillable, int right_spillable) {
aoqi@0 3538 int cisc_spillable = Maybe_cisc_spillable;
aoqi@0 3539
aoqi@0 3540 // Combine results of left and right checks
aoqi@0 3541 if( (left_spillable == Maybe_cisc_spillable) && (right_spillable == Maybe_cisc_spillable) ) {
aoqi@0 3542 // neither side is spillable, nor prevents cisc spilling
aoqi@0 3543 cisc_spillable = Maybe_cisc_spillable;
aoqi@0 3544 }
aoqi@0 3545 else if( (left_spillable == Maybe_cisc_spillable) && (right_spillable > Maybe_cisc_spillable) ) {
aoqi@0 3546 // right side is spillable
aoqi@0 3547 cisc_spillable = right_spillable;
aoqi@0 3548 }
aoqi@0 3549 else if( (right_spillable == Maybe_cisc_spillable) && (left_spillable > Maybe_cisc_spillable) ) {
aoqi@0 3550 // left side is spillable
aoqi@0 3551 cisc_spillable = left_spillable;
aoqi@0 3552 }
aoqi@0 3553 else if( (left_spillable == Not_cisc_spillable) || (right_spillable == Not_cisc_spillable) ) {
aoqi@0 3554 // left or right prevents cisc spilling this instruction
aoqi@0 3555 cisc_spillable = Not_cisc_spillable;
aoqi@0 3556 }
aoqi@0 3557 else {
aoqi@0 3558 // Only allow one to spill
aoqi@0 3559 cisc_spillable = Not_cisc_spillable;
aoqi@0 3560 }
aoqi@0 3561
aoqi@0 3562 return cisc_spillable;
aoqi@0 3563 }
aoqi@0 3564
aoqi@0 3565 //-------------------------root_ops_match--------------------------------------
aoqi@0 3566 bool static root_ops_match(FormDict &globals, const char *op1, const char *op2) {
aoqi@0 3567 // Base Case: check that the current operands/operations match
aoqi@0 3568 assert( op1, "Must have op's name");
aoqi@0 3569 assert( op2, "Must have op's name");
aoqi@0 3570 const Form *form1 = globals[op1];
aoqi@0 3571 const Form *form2 = globals[op2];
aoqi@0 3572
aoqi@0 3573 return (form1 == form2);
aoqi@0 3574 }
aoqi@0 3575
aoqi@0 3576 //-------------------------cisc_spill_match_node-------------------------------
aoqi@0 3577 // Recursively check two MatchRules for legal conversion via cisc-spilling
aoqi@0 3578 int MatchNode::cisc_spill_match(FormDict& globals, RegisterForm* registers, MatchNode* mRule2, const char* &operand, const char* &reg_type) {
aoqi@0 3579 int cisc_spillable = Maybe_cisc_spillable;
aoqi@0 3580 int left_spillable = Maybe_cisc_spillable;
aoqi@0 3581 int right_spillable = Maybe_cisc_spillable;
aoqi@0 3582
aoqi@0 3583 // Check that each has same number of operands at this level
aoqi@0 3584 if( (_lChild && !(mRule2->_lChild)) || (_rChild && !(mRule2->_rChild)) )
aoqi@0 3585 return Not_cisc_spillable;
aoqi@0 3586
aoqi@0 3587 // Base Case: check that the current operands/operations match
aoqi@0 3588 // or are CISC spillable
aoqi@0 3589 assert( _opType, "Must have _opType");
aoqi@0 3590 assert( mRule2->_opType, "Must have _opType");
aoqi@0 3591 const Form *form = globals[_opType];
aoqi@0 3592 const Form *form2 = globals[mRule2->_opType];
aoqi@0 3593 if( form == form2 ) {
aoqi@0 3594 cisc_spillable = Maybe_cisc_spillable;
aoqi@0 3595 } else {
aoqi@0 3596 const InstructForm *form2_inst = form2 ? form2->is_instruction() : NULL;
aoqi@0 3597 const char *name_left = mRule2->_lChild ? mRule2->_lChild->_opType : NULL;
aoqi@0 3598 const char *name_right = mRule2->_rChild ? mRule2->_rChild->_opType : NULL;
aoqi@0 3599 DataType data_type = Form::none;
aoqi@0 3600 if (form->is_operand()) {
aoqi@0 3601 // Make sure the loadX matches the type of the reg
aoqi@0 3602 data_type = form->ideal_to_Reg_type(form->is_operand()->ideal_type(globals));
aoqi@0 3603 }
aoqi@0 3604 // Detect reg vs (loadX memory)
aoqi@0 3605 if( form->is_cisc_reg(globals)
aoqi@0 3606 && form2_inst
aoqi@0 3607 && data_type != Form::none
aoqi@0 3608 && (is_load_from_memory(mRule2->_opType) == data_type) // reg vs. (load memory)
aoqi@0 3609 && (name_left != NULL) // NOT (load)
aoqi@0 3610 && (name_right == NULL) ) { // NOT (load memory foo)
aoqi@0 3611 const Form *form2_left = name_left ? globals[name_left] : NULL;
aoqi@0 3612 if( form2_left && form2_left->is_cisc_mem(globals) ) {
aoqi@0 3613 cisc_spillable = Is_cisc_spillable;
aoqi@0 3614 operand = _name;
aoqi@0 3615 reg_type = _result;
aoqi@0 3616 return Is_cisc_spillable;
aoqi@0 3617 } else {
aoqi@0 3618 cisc_spillable = Not_cisc_spillable;
aoqi@0 3619 }
aoqi@0 3620 }
aoqi@0 3621 // Detect reg vs memory
aoqi@0 3622 else if( form->is_cisc_reg(globals) && form2->is_cisc_mem(globals) ) {
aoqi@0 3623 cisc_spillable = Is_cisc_spillable;
aoqi@0 3624 operand = _name;
aoqi@0 3625 reg_type = _result;
aoqi@0 3626 return Is_cisc_spillable;
aoqi@0 3627 } else {
aoqi@0 3628 cisc_spillable = Not_cisc_spillable;
aoqi@0 3629 }
aoqi@0 3630 }
aoqi@0 3631
aoqi@0 3632 // If cisc is still possible, check rest of tree
aoqi@0 3633 if( cisc_spillable == Maybe_cisc_spillable ) {
aoqi@0 3634 // Check that each has same number of operands at this level
aoqi@0 3635 if( (_lChild && !(mRule2->_lChild)) || (_rChild && !(mRule2->_rChild)) ) return Not_cisc_spillable;
aoqi@0 3636
aoqi@0 3637 // Check left operands
aoqi@0 3638 if( (_lChild == NULL) && (mRule2->_lChild == NULL) ) {
aoqi@0 3639 left_spillable = Maybe_cisc_spillable;
aoqi@0 3640 } else {
aoqi@0 3641 left_spillable = _lChild->cisc_spill_match(globals, registers, mRule2->_lChild, operand, reg_type);
aoqi@0 3642 }
aoqi@0 3643
aoqi@0 3644 // Check right operands
aoqi@0 3645 if( (_rChild == NULL) && (mRule2->_rChild == NULL) ) {
aoqi@0 3646 right_spillable = Maybe_cisc_spillable;
aoqi@0 3647 } else {
aoqi@0 3648 right_spillable = _rChild->cisc_spill_match(globals, registers, mRule2->_rChild, operand, reg_type);
aoqi@0 3649 }
aoqi@0 3650
aoqi@0 3651 // Combine results of left and right checks
aoqi@0 3652 cisc_spillable = cisc_spill_merge(left_spillable, right_spillable);
aoqi@0 3653 }
aoqi@0 3654
aoqi@0 3655 return cisc_spillable;
aoqi@0 3656 }
aoqi@0 3657
aoqi@0 3658 //---------------------------cisc_spill_match_rule------------------------------
aoqi@0 3659 // Recursively check two MatchRules for legal conversion via cisc-spilling
aoqi@0 3660 // This method handles the root of Match tree,
aoqi@0 3661 // general recursive checks done in MatchNode
aoqi@0 3662 int MatchRule::matchrule_cisc_spill_match(FormDict& globals, RegisterForm* registers,
aoqi@0 3663 MatchRule* mRule2, const char* &operand,
aoqi@0 3664 const char* &reg_type) {
aoqi@0 3665 int cisc_spillable = Maybe_cisc_spillable;
aoqi@0 3666 int left_spillable = Maybe_cisc_spillable;
aoqi@0 3667 int right_spillable = Maybe_cisc_spillable;
aoqi@0 3668
aoqi@0 3669 // Check that each sets a result
aoqi@0 3670 if( !(sets_result() && mRule2->sets_result()) ) return Not_cisc_spillable;
aoqi@0 3671 // Check that each has same number of operands at this level
aoqi@0 3672 if( (_lChild && !(mRule2->_lChild)) || (_rChild && !(mRule2->_rChild)) ) return Not_cisc_spillable;
aoqi@0 3673
aoqi@0 3674 // Check left operands: at root, must be target of 'Set'
aoqi@0 3675 if( (_lChild == NULL) || (mRule2->_lChild == NULL) ) {
aoqi@0 3676 left_spillable = Not_cisc_spillable;
aoqi@0 3677 } else {
aoqi@0 3678 // Do not support cisc-spilling instruction's target location
aoqi@0 3679 if( root_ops_match(globals, _lChild->_opType, mRule2->_lChild->_opType) ) {
aoqi@0 3680 left_spillable = Maybe_cisc_spillable;
aoqi@0 3681 } else {
aoqi@0 3682 left_spillable = Not_cisc_spillable;
aoqi@0 3683 }
aoqi@0 3684 }
aoqi@0 3685
aoqi@0 3686 // Check right operands: recursive walk to identify reg->mem operand
aoqi@0 3687 if( (_rChild == NULL) && (mRule2->_rChild == NULL) ) {
aoqi@0 3688 right_spillable = Maybe_cisc_spillable;
aoqi@0 3689 } else {
aoqi@0 3690 right_spillable = _rChild->cisc_spill_match(globals, registers, mRule2->_rChild, operand, reg_type);
aoqi@0 3691 }
aoqi@0 3692
aoqi@0 3693 // Combine results of left and right checks
aoqi@0 3694 cisc_spillable = cisc_spill_merge(left_spillable, right_spillable);
aoqi@0 3695
aoqi@0 3696 return cisc_spillable;
aoqi@0 3697 }
aoqi@0 3698
aoqi@0 3699 //----------------------------- equivalent ------------------------------------
aoqi@0 3700 // Recursively check to see if two match rules are equivalent.
aoqi@0 3701 // This rule handles the root.
aoqi@0 3702 bool MatchRule::equivalent(FormDict &globals, MatchNode *mRule2) {
aoqi@0 3703 // Check that each sets a result
aoqi@0 3704 if (sets_result() != mRule2->sets_result()) {
aoqi@0 3705 return false;
aoqi@0 3706 }
aoqi@0 3707
aoqi@0 3708 // Check that the current operands/operations match
aoqi@0 3709 assert( _opType, "Must have _opType");
aoqi@0 3710 assert( mRule2->_opType, "Must have _opType");
aoqi@0 3711 const Form *form = globals[_opType];
aoqi@0 3712 const Form *form2 = globals[mRule2->_opType];
aoqi@0 3713 if( form != form2 ) {
aoqi@0 3714 return false;
aoqi@0 3715 }
aoqi@0 3716
aoqi@0 3717 if (_lChild ) {
aoqi@0 3718 if( !_lChild->equivalent(globals, mRule2->_lChild) )
aoqi@0 3719 return false;
aoqi@0 3720 } else if (mRule2->_lChild) {
aoqi@0 3721 return false; // I have NULL left child, mRule2 has non-NULL left child.
aoqi@0 3722 }
aoqi@0 3723
aoqi@0 3724 if (_rChild ) {
aoqi@0 3725 if( !_rChild->equivalent(globals, mRule2->_rChild) )
aoqi@0 3726 return false;
aoqi@0 3727 } else if (mRule2->_rChild) {
aoqi@0 3728 return false; // I have NULL right child, mRule2 has non-NULL right child.
aoqi@0 3729 }
aoqi@0 3730
aoqi@0 3731 // We've made it through the gauntlet.
aoqi@0 3732 return true;
aoqi@0 3733 }
aoqi@0 3734
aoqi@0 3735 //----------------------------- equivalent ------------------------------------
aoqi@0 3736 // Recursively check to see if two match rules are equivalent.
aoqi@0 3737 // This rule handles the operands.
aoqi@0 3738 bool MatchNode::equivalent(FormDict &globals, MatchNode *mNode2) {
aoqi@0 3739 if( !mNode2 )
aoqi@0 3740 return false;
aoqi@0 3741
aoqi@0 3742 // Check that the current operands/operations match
aoqi@0 3743 assert( _opType, "Must have _opType");
aoqi@0 3744 assert( mNode2->_opType, "Must have _opType");
aoqi@0 3745 const Form *form = globals[_opType];
aoqi@0 3746 const Form *form2 = globals[mNode2->_opType];
aoqi@0 3747 if( form != form2 ) {
aoqi@0 3748 return false;
aoqi@0 3749 }
aoqi@0 3750
aoqi@0 3751 // Check that their children also match
aoqi@0 3752 if (_lChild ) {
aoqi@0 3753 if( !_lChild->equivalent(globals, mNode2->_lChild) )
aoqi@0 3754 return false;
aoqi@0 3755 } else if (mNode2->_lChild) {
aoqi@0 3756 return false; // I have NULL left child, mNode2 has non-NULL left child.
aoqi@0 3757 }
aoqi@0 3758
aoqi@0 3759 if (_rChild ) {
aoqi@0 3760 if( !_rChild->equivalent(globals, mNode2->_rChild) )
aoqi@0 3761 return false;
aoqi@0 3762 } else if (mNode2->_rChild) {
aoqi@0 3763 return false; // I have NULL right child, mNode2 has non-NULL right child.
aoqi@0 3764 }
aoqi@0 3765
aoqi@0 3766 // We've made it through the gauntlet.
aoqi@0 3767 return true;
aoqi@0 3768 }
aoqi@0 3769
aoqi@0 3770 //-------------------------- has_commutative_op -------------------------------
aoqi@0 3771 // Recursively check for commutative operations with subtree operands
aoqi@0 3772 // which could be swapped.
aoqi@0 3773 void MatchNode::count_commutative_op(int& count) {
aoqi@0 3774 static const char *commut_op_list[] = {
aoqi@0 3775 "AddI","AddL","AddF","AddD",
aoqi@0 3776 "AndI","AndL",
aoqi@0 3777 "MaxI","MinI",
aoqi@0 3778 "MulI","MulL","MulF","MulD",
aoqi@0 3779 "OrI" ,"OrL" ,
aoqi@0 3780 "XorI","XorL"
aoqi@0 3781 };
aoqi@0 3782 int cnt = sizeof(commut_op_list)/sizeof(char*);
aoqi@0 3783
aoqi@0 3784 if( _lChild && _rChild && (_lChild->_lChild || _rChild->_lChild) ) {
aoqi@0 3785 // Don't swap if right operand is an immediate constant.
aoqi@0 3786 bool is_const = false;
aoqi@0 3787 if( _rChild->_lChild == NULL && _rChild->_rChild == NULL ) {
aoqi@0 3788 FormDict &globals = _AD.globalNames();
aoqi@0 3789 const Form *form = globals[_rChild->_opType];
aoqi@0 3790 if ( form ) {
aoqi@0 3791 OperandForm *oper = form->is_operand();
aoqi@0 3792 if( oper && oper->interface_type(globals) == Form::constant_interface )
aoqi@0 3793 is_const = true;
aoqi@0 3794 }
aoqi@0 3795 }
aoqi@0 3796 if( !is_const ) {
aoqi@0 3797 for( int i=0; i<cnt; i++ ) {
aoqi@0 3798 if( strcmp(_opType, commut_op_list[i]) == 0 ) {
aoqi@0 3799 count++;
aoqi@0 3800 _commutative_id = count; // id should be > 0
aoqi@0 3801 break;
aoqi@0 3802 }
aoqi@0 3803 }
aoqi@0 3804 }
aoqi@0 3805 }
aoqi@0 3806 if( _lChild )
aoqi@0 3807 _lChild->count_commutative_op(count);
aoqi@0 3808 if( _rChild )
aoqi@0 3809 _rChild->count_commutative_op(count);
aoqi@0 3810 }
aoqi@0 3811
aoqi@0 3812 //-------------------------- swap_commutative_op ------------------------------
aoqi@0 3813 // Recursively swap specified commutative operation with subtree operands.
aoqi@0 3814 void MatchNode::swap_commutative_op(bool atroot, int id) {
aoqi@0 3815 if( _commutative_id == id ) { // id should be > 0
aoqi@0 3816 assert(_lChild && _rChild && (_lChild->_lChild || _rChild->_lChild ),
aoqi@0 3817 "not swappable operation");
aoqi@0 3818 MatchNode* tmp = _lChild;
aoqi@0 3819 _lChild = _rChild;
aoqi@0 3820 _rChild = tmp;
aoqi@0 3821 // Don't exit here since we need to build internalop.
aoqi@0 3822 }
aoqi@0 3823
aoqi@0 3824 bool is_set = ( strcmp(_opType, "Set") == 0 );
aoqi@0 3825 if( _lChild )
aoqi@0 3826 _lChild->swap_commutative_op(is_set, id);
aoqi@0 3827 if( _rChild )
aoqi@0 3828 _rChild->swap_commutative_op(is_set, id);
aoqi@0 3829
aoqi@0 3830 // If not the root, reduce this subtree to an internal operand
aoqi@0 3831 if( !atroot && (_lChild || _rChild) ) {
aoqi@0 3832 build_internalop();
aoqi@0 3833 }
aoqi@0 3834 }
aoqi@0 3835
aoqi@0 3836 //-------------------------- swap_commutative_op ------------------------------
aoqi@0 3837 // Recursively swap specified commutative operation with subtree operands.
aoqi@0 3838 void MatchRule::matchrule_swap_commutative_op(const char* instr_ident, int count, int& match_rules_cnt) {
aoqi@0 3839 assert(match_rules_cnt < 100," too many match rule clones");
aoqi@0 3840 // Clone
aoqi@0 3841 MatchRule* clone = new MatchRule(_AD, this);
aoqi@0 3842 // Swap operands of commutative operation
aoqi@0 3843 ((MatchNode*)clone)->swap_commutative_op(true, count);
aoqi@0 3844 char* buf = (char*) malloc(strlen(instr_ident) + 4);
aoqi@0 3845 sprintf(buf, "%s_%d", instr_ident, match_rules_cnt++);
aoqi@0 3846 clone->_result = buf;
aoqi@0 3847
aoqi@0 3848 clone->_next = this->_next;
aoqi@0 3849 this-> _next = clone;
aoqi@0 3850 if( (--count) > 0 ) {
aoqi@0 3851 this-> matchrule_swap_commutative_op(instr_ident, count, match_rules_cnt);
aoqi@0 3852 clone->matchrule_swap_commutative_op(instr_ident, count, match_rules_cnt);
aoqi@0 3853 }
aoqi@0 3854 }
aoqi@0 3855
aoqi@0 3856 //------------------------------MatchRule--------------------------------------
aoqi@0 3857 MatchRule::MatchRule(ArchDesc &ad)
aoqi@0 3858 : MatchNode(ad), _depth(0), _construct(NULL), _numchilds(0) {
aoqi@0 3859 _next = NULL;
aoqi@0 3860 }
aoqi@0 3861
aoqi@0 3862 MatchRule::MatchRule(ArchDesc &ad, MatchRule* mRule)
aoqi@0 3863 : MatchNode(ad, *mRule, 0), _depth(mRule->_depth),
aoqi@0 3864 _construct(mRule->_construct), _numchilds(mRule->_numchilds) {
aoqi@0 3865 _next = NULL;
aoqi@0 3866 }
aoqi@0 3867
aoqi@0 3868 MatchRule::MatchRule(ArchDesc &ad, MatchNode* mroot, int depth, char *cnstr,
aoqi@0 3869 int numleaves)
aoqi@0 3870 : MatchNode(ad,*mroot), _depth(depth), _construct(cnstr),
aoqi@0 3871 _numchilds(0) {
aoqi@0 3872 _next = NULL;
aoqi@0 3873 mroot->_lChild = NULL;
aoqi@0 3874 mroot->_rChild = NULL;
aoqi@0 3875 delete mroot;
aoqi@0 3876 _numleaves = numleaves;
aoqi@0 3877 _numchilds = (_lChild ? 1 : 0) + (_rChild ? 1 : 0);
aoqi@0 3878 }
aoqi@0 3879 MatchRule::~MatchRule() {
aoqi@0 3880 }
aoqi@0 3881
aoqi@0 3882 // Recursive call collecting info on top-level operands, not transitive.
aoqi@0 3883 // Implementation does not modify state of internal structures.
aoqi@0 3884 void MatchRule::append_components(FormDict& locals, ComponentList& components, bool def_flag) const {
aoqi@0 3885 assert (_name != NULL, "MatchNode::build_components encountered empty node\n");
aoqi@0 3886
aoqi@0 3887 MatchNode::append_components(locals, components,
aoqi@0 3888 false /* not necessarily a def */);
aoqi@0 3889 }
aoqi@0 3890
aoqi@0 3891 // Recursive call on all operands' match rules in my match rule.
aoqi@0 3892 // Implementation does not modify state of internal structures since they
aoqi@0 3893 // can be shared.
aoqi@0 3894 // The MatchNode that is called first treats its
aoqi@0 3895 bool MatchRule::base_operand(uint &position0, FormDict &globals,
aoqi@0 3896 const char *&result, const char * &name,
aoqi@0 3897 const char * &opType)const{
aoqi@0 3898 uint position = position0;
aoqi@0 3899
aoqi@0 3900 return (MatchNode::base_operand( position, globals, result, name, opType));
aoqi@0 3901 }
aoqi@0 3902
aoqi@0 3903
aoqi@0 3904 bool MatchRule::is_base_register(FormDict &globals) const {
aoqi@0 3905 uint position = 1;
aoqi@0 3906 const char *result = NULL;
aoqi@0 3907 const char *name = NULL;
aoqi@0 3908 const char *opType = NULL;
aoqi@0 3909 if (!base_operand(position, globals, result, name, opType)) {
aoqi@0 3910 position = 0;
aoqi@0 3911 if( base_operand(position, globals, result, name, opType) &&
aoqi@0 3912 (strcmp(opType,"RegI")==0 ||
aoqi@0 3913 strcmp(opType,"RegP")==0 ||
aoqi@0 3914 strcmp(opType,"RegN")==0 ||
aoqi@0 3915 strcmp(opType,"RegL")==0 ||
aoqi@0 3916 strcmp(opType,"RegF")==0 ||
aoqi@0 3917 strcmp(opType,"RegD")==0 ||
aoqi@0 3918 strcmp(opType,"VecS")==0 ||
aoqi@0 3919 strcmp(opType,"VecD")==0 ||
aoqi@0 3920 strcmp(opType,"VecX")==0 ||
aoqi@0 3921 strcmp(opType,"VecY")==0 ||
aoqi@0 3922 strcmp(opType,"Reg" )==0) ) {
aoqi@0 3923 return 1;
aoqi@0 3924 }
aoqi@0 3925 }
aoqi@0 3926 return 0;
aoqi@0 3927 }
aoqi@0 3928
aoqi@0 3929 Form::DataType MatchRule::is_base_constant(FormDict &globals) const {
aoqi@0 3930 uint position = 1;
aoqi@0 3931 const char *result = NULL;
aoqi@0 3932 const char *name = NULL;
aoqi@0 3933 const char *opType = NULL;
aoqi@0 3934 if (!base_operand(position, globals, result, name, opType)) {
aoqi@0 3935 position = 0;
aoqi@0 3936 if (base_operand(position, globals, result, name, opType)) {
aoqi@0 3937 return ideal_to_const_type(opType);
aoqi@0 3938 }
aoqi@0 3939 }
aoqi@0 3940 return Form::none;
aoqi@0 3941 }
aoqi@0 3942
aoqi@0 3943 bool MatchRule::is_chain_rule(FormDict &globals) const {
aoqi@0 3944
aoqi@0 3945 // Check for chain rule, and do not generate a match list for it
aoqi@0 3946 if ((_lChild == NULL) && (_rChild == NULL) ) {
aoqi@0 3947 const Form *form = globals[_opType];
aoqi@0 3948 // If this is ideal, then it is a base match, not a chain rule.
aoqi@0 3949 if ( form && form->is_operand() && (!form->ideal_only())) {
aoqi@0 3950 return true;
aoqi@0 3951 }
aoqi@0 3952 }
aoqi@0 3953 // Check for "Set" form of chain rule, and do not generate a match list
aoqi@0 3954 if (_rChild) {
aoqi@0 3955 const char *rch = _rChild->_opType;
aoqi@0 3956 const Form *form = globals[rch];
aoqi@0 3957 if ((!strcmp(_opType,"Set") &&
aoqi@0 3958 ((form) && form->is_operand()))) {
aoqi@0 3959 return true;
aoqi@0 3960 }
aoqi@0 3961 }
aoqi@0 3962 return false;
aoqi@0 3963 }
aoqi@0 3964
aoqi@0 3965 int MatchRule::is_ideal_copy() const {
aoqi@0 3966 if( _rChild ) {
aoqi@0 3967 const char *opType = _rChild->_opType;
aoqi@0 3968 #if 1
aoqi@0 3969 if( strcmp(opType,"CastIP")==0 )
aoqi@0 3970 return 1;
aoqi@0 3971 #else
aoqi@0 3972 if( strcmp(opType,"CastII")==0 )
aoqi@0 3973 return 1;
aoqi@0 3974 // Do not treat *CastPP this way, because it
aoqi@0 3975 // may transfer a raw pointer to an oop.
aoqi@0 3976 // If the register allocator were to coalesce this
aoqi@0 3977 // into a single LRG, the GC maps would be incorrect.
aoqi@0 3978 //if( strcmp(opType,"CastPP")==0 )
aoqi@0 3979 // return 1;
aoqi@0 3980 //if( strcmp(opType,"CheckCastPP")==0 )
aoqi@0 3981 // return 1;
aoqi@0 3982 //
aoqi@0 3983 // Do not treat CastX2P or CastP2X this way, because
aoqi@0 3984 // raw pointers and int types are treated differently
aoqi@0 3985 // when saving local & stack info for safepoints in
aoqi@0 3986 // Output().
aoqi@0 3987 //if( strcmp(opType,"CastX2P")==0 )
aoqi@0 3988 // return 1;
aoqi@0 3989 //if( strcmp(opType,"CastP2X")==0 )
aoqi@0 3990 // return 1;
aoqi@0 3991 #endif
aoqi@0 3992 }
aoqi@0 3993 if( is_chain_rule(_AD.globalNames()) &&
aoqi@0 3994 _lChild && strncmp(_lChild->_opType,"stackSlot",9)==0 )
aoqi@0 3995 return 1;
aoqi@0 3996 return 0;
aoqi@0 3997 }
aoqi@0 3998
aoqi@0 3999
aoqi@0 4000 int MatchRule::is_expensive() const {
aoqi@0 4001 if( _rChild ) {
aoqi@0 4002 const char *opType = _rChild->_opType;
aoqi@0 4003 if( strcmp(opType,"AtanD")==0 ||
aoqi@0 4004 strcmp(opType,"CosD")==0 ||
aoqi@0 4005 strcmp(opType,"DivD")==0 ||
aoqi@0 4006 strcmp(opType,"DivF")==0 ||
aoqi@0 4007 strcmp(opType,"DivI")==0 ||
aoqi@0 4008 strcmp(opType,"ExpD")==0 ||
aoqi@0 4009 strcmp(opType,"LogD")==0 ||
aoqi@0 4010 strcmp(opType,"Log10D")==0 ||
aoqi@0 4011 strcmp(opType,"ModD")==0 ||
aoqi@0 4012 strcmp(opType,"ModF")==0 ||
aoqi@0 4013 strcmp(opType,"ModI")==0 ||
aoqi@0 4014 strcmp(opType,"PowD")==0 ||
aoqi@0 4015 strcmp(opType,"SinD")==0 ||
aoqi@0 4016 strcmp(opType,"SqrtD")==0 ||
aoqi@0 4017 strcmp(opType,"TanD")==0 ||
aoqi@0 4018 strcmp(opType,"ConvD2F")==0 ||
aoqi@0 4019 strcmp(opType,"ConvD2I")==0 ||
aoqi@0 4020 strcmp(opType,"ConvD2L")==0 ||
aoqi@0 4021 strcmp(opType,"ConvF2D")==0 ||
aoqi@0 4022 strcmp(opType,"ConvF2I")==0 ||
aoqi@0 4023 strcmp(opType,"ConvF2L")==0 ||
aoqi@0 4024 strcmp(opType,"ConvI2D")==0 ||
aoqi@0 4025 strcmp(opType,"ConvI2F")==0 ||
aoqi@0 4026 strcmp(opType,"ConvI2L")==0 ||
aoqi@0 4027 strcmp(opType,"ConvL2D")==0 ||
aoqi@0 4028 strcmp(opType,"ConvL2F")==0 ||
aoqi@0 4029 strcmp(opType,"ConvL2I")==0 ||
aoqi@0 4030 strcmp(opType,"DecodeN")==0 ||
aoqi@0 4031 strcmp(opType,"EncodeP")==0 ||
aoqi@0 4032 strcmp(opType,"EncodePKlass")==0 ||
aoqi@0 4033 strcmp(opType,"DecodeNKlass")==0 ||
aoqi@0 4034 strcmp(opType,"RoundDouble")==0 ||
aoqi@0 4035 strcmp(opType,"RoundFloat")==0 ||
aoqi@0 4036 strcmp(opType,"ReverseBytesI")==0 ||
aoqi@0 4037 strcmp(opType,"ReverseBytesL")==0 ||
aoqi@0 4038 strcmp(opType,"ReverseBytesUS")==0 ||
aoqi@0 4039 strcmp(opType,"ReverseBytesS")==0 ||
aoqi@0 4040 strcmp(opType,"ReplicateB")==0 ||
aoqi@0 4041 strcmp(opType,"ReplicateS")==0 ||
aoqi@0 4042 strcmp(opType,"ReplicateI")==0 ||
aoqi@0 4043 strcmp(opType,"ReplicateL")==0 ||
aoqi@0 4044 strcmp(opType,"ReplicateF")==0 ||
aoqi@0 4045 strcmp(opType,"ReplicateD")==0 ||
aoqi@0 4046 0 /* 0 to line up columns nicely */ )
aoqi@0 4047 return 1;
aoqi@0 4048 }
aoqi@0 4049 return 0;
aoqi@0 4050 }
aoqi@0 4051
aoqi@0 4052 bool MatchRule::is_ideal_if() const {
aoqi@0 4053 if( !_opType ) return false;
aoqi@0 4054 return
aoqi@0 4055 !strcmp(_opType,"If" ) ||
aoqi@0 4056 !strcmp(_opType,"CountedLoopEnd");
aoqi@0 4057 }
aoqi@0 4058
aoqi@0 4059 bool MatchRule::is_ideal_fastlock() const {
aoqi@0 4060 if ( _opType && (strcmp(_opType,"Set") == 0) && _rChild ) {
aoqi@0 4061 return (strcmp(_rChild->_opType,"FastLock") == 0);
aoqi@0 4062 }
aoqi@0 4063 return false;
aoqi@0 4064 }
aoqi@0 4065
aoqi@0 4066 bool MatchRule::is_ideal_membar() const {
aoqi@0 4067 if( !_opType ) return false;
aoqi@0 4068 return
aoqi@0 4069 !strcmp(_opType,"MemBarAcquire") ||
aoqi@0 4070 !strcmp(_opType,"MemBarRelease") ||
aoqi@0 4071 !strcmp(_opType,"MemBarAcquireLock") ||
aoqi@0 4072 !strcmp(_opType,"MemBarReleaseLock") ||
aoqi@0 4073 !strcmp(_opType,"LoadFence" ) ||
aoqi@0 4074 !strcmp(_opType,"StoreFence") ||
aoqi@0 4075 !strcmp(_opType,"MemBarVolatile") ||
aoqi@0 4076 !strcmp(_opType,"MemBarCPUOrder") ||
aoqi@0 4077 !strcmp(_opType,"MemBarStoreStore");
aoqi@0 4078 }
aoqi@0 4079
aoqi@0 4080 bool MatchRule::is_ideal_loadPC() const {
aoqi@0 4081 if ( _opType && (strcmp(_opType,"Set") == 0) && _rChild ) {
aoqi@0 4082 return (strcmp(_rChild->_opType,"LoadPC") == 0);
aoqi@0 4083 }
aoqi@0 4084 return false;
aoqi@0 4085 }
aoqi@0 4086
aoqi@0 4087 bool MatchRule::is_ideal_box() const {
aoqi@0 4088 if ( _opType && (strcmp(_opType,"Set") == 0) && _rChild ) {
aoqi@0 4089 return (strcmp(_rChild->_opType,"Box") == 0);
aoqi@0 4090 }
aoqi@0 4091 return false;
aoqi@0 4092 }
aoqi@0 4093
aoqi@0 4094 bool MatchRule::is_ideal_goto() const {
aoqi@0 4095 bool ideal_goto = false;
aoqi@0 4096
aoqi@0 4097 if( _opType && (strcmp(_opType,"Goto") == 0) ) {
aoqi@0 4098 ideal_goto = true;
aoqi@0 4099 }
aoqi@0 4100 return ideal_goto;
aoqi@0 4101 }
aoqi@0 4102
aoqi@0 4103 bool MatchRule::is_ideal_jump() const {
aoqi@0 4104 if( _opType ) {
aoqi@0 4105 if( !strcmp(_opType,"Jump") )
aoqi@0 4106 return true;
aoqi@0 4107 }
aoqi@0 4108 return false;
aoqi@0 4109 }
aoqi@0 4110
aoqi@0 4111 bool MatchRule::is_ideal_bool() const {
aoqi@0 4112 if( _opType ) {
aoqi@0 4113 if( !strcmp(_opType,"Bool") )
aoqi@0 4114 return true;
aoqi@0 4115 }
aoqi@0 4116 return false;
aoqi@0 4117 }
aoqi@0 4118
aoqi@0 4119
aoqi@0 4120 Form::DataType MatchRule::is_ideal_load() const {
aoqi@0 4121 Form::DataType ideal_load = Form::none;
aoqi@0 4122
aoqi@0 4123 if ( _opType && (strcmp(_opType,"Set") == 0) && _rChild ) {
aoqi@0 4124 const char *opType = _rChild->_opType;
aoqi@0 4125 ideal_load = is_load_from_memory(opType);
aoqi@0 4126 }
aoqi@0 4127
aoqi@0 4128 return ideal_load;
aoqi@0 4129 }
aoqi@0 4130
aoqi@0 4131 bool MatchRule::is_vector() const {
aoqi@0 4132 static const char *vector_list[] = {
aoqi@0 4133 "AddVB","AddVS","AddVI","AddVL","AddVF","AddVD",
aoqi@0 4134 "SubVB","SubVS","SubVI","SubVL","SubVF","SubVD",
aoqi@0 4135 "MulVS","MulVI","MulVF","MulVD",
aoqi@0 4136 "DivVF","DivVD",
aoqi@0 4137 "AndV" ,"XorV" ,"OrV",
aoqi@0 4138 "LShiftCntV","RShiftCntV",
aoqi@0 4139 "LShiftVB","LShiftVS","LShiftVI","LShiftVL",
aoqi@0 4140 "RShiftVB","RShiftVS","RShiftVI","RShiftVL",
aoqi@0 4141 "URShiftVB","URShiftVS","URShiftVI","URShiftVL",
aoqi@0 4142 "ReplicateB","ReplicateS","ReplicateI","ReplicateL","ReplicateF","ReplicateD",
aoqi@0 4143 "LoadVector","StoreVector",
aoqi@0 4144 // Next are not supported currently.
aoqi@0 4145 "PackB","PackS","PackI","PackL","PackF","PackD","Pack2L","Pack2D",
aoqi@0 4146 "ExtractB","ExtractUB","ExtractC","ExtractS","ExtractI","ExtractL","ExtractF","ExtractD"
aoqi@0 4147 };
aoqi@0 4148 int cnt = sizeof(vector_list)/sizeof(char*);
aoqi@0 4149 if (_rChild) {
aoqi@0 4150 const char *opType = _rChild->_opType;
aoqi@0 4151 for (int i=0; i<cnt; i++)
aoqi@0 4152 if (strcmp(opType,vector_list[i]) == 0)
aoqi@0 4153 return true;
aoqi@0 4154 }
aoqi@0 4155 return false;
aoqi@0 4156 }
aoqi@0 4157
aoqi@0 4158
aoqi@0 4159 bool MatchRule::skip_antidep_check() const {
aoqi@0 4160 // Some loads operate on what is effectively immutable memory so we
aoqi@0 4161 // should skip the anti dep computations. For some of these nodes
aoqi@0 4162 // the rewritable field keeps the anti dep logic from triggering but
aoqi@0 4163 // for certain kinds of LoadKlass it does not since they are
aoqi@0 4164 // actually reading memory which could be rewritten by the runtime,
aoqi@0 4165 // though never by generated code. This disables it uniformly for
aoqi@0 4166 // the nodes that behave like this: LoadKlass, LoadNKlass and
aoqi@0 4167 // LoadRange.
aoqi@0 4168 if ( _opType && (strcmp(_opType,"Set") == 0) && _rChild ) {
aoqi@0 4169 const char *opType = _rChild->_opType;
aoqi@0 4170 if (strcmp("LoadKlass", opType) == 0 ||
aoqi@0 4171 strcmp("LoadNKlass", opType) == 0 ||
aoqi@0 4172 strcmp("LoadRange", opType) == 0) {
aoqi@0 4173 return true;
aoqi@0 4174 }
aoqi@0 4175 }
aoqi@0 4176
aoqi@0 4177 return false;
aoqi@0 4178 }
aoqi@0 4179
aoqi@0 4180
aoqi@0 4181 Form::DataType MatchRule::is_ideal_store() const {
aoqi@0 4182 Form::DataType ideal_store = Form::none;
aoqi@0 4183
aoqi@0 4184 if ( _opType && (strcmp(_opType,"Set") == 0) && _rChild ) {
aoqi@0 4185 const char *opType = _rChild->_opType;
aoqi@0 4186 ideal_store = is_store_to_memory(opType);
aoqi@0 4187 }
aoqi@0 4188
aoqi@0 4189 return ideal_store;
aoqi@0 4190 }
aoqi@0 4191
aoqi@0 4192
aoqi@0 4193 void MatchRule::dump() {
aoqi@0 4194 output(stderr);
aoqi@0 4195 }
aoqi@0 4196
aoqi@0 4197 // Write just one line.
aoqi@0 4198 void MatchRule::output_short(FILE *fp) {
aoqi@0 4199 fprintf(fp,"MatchRule: ( %s",_name);
aoqi@0 4200 if (_lChild) _lChild->output(fp);
aoqi@0 4201 if (_rChild) _rChild->output(fp);
aoqi@0 4202 fprintf(fp," )");
aoqi@0 4203 }
aoqi@0 4204
aoqi@0 4205 void MatchRule::output(FILE *fp) {
aoqi@0 4206 output_short(fp);
aoqi@0 4207 fprintf(fp,"\n nesting depth = %d\n", _depth);
aoqi@0 4208 if (_result) fprintf(fp," Result Type = %s", _result);
aoqi@0 4209 fprintf(fp,"\n");
aoqi@0 4210 }
aoqi@0 4211
aoqi@0 4212 //------------------------------Attribute--------------------------------------
aoqi@0 4213 Attribute::Attribute(char *id, char* val, int type)
aoqi@0 4214 : _ident(id), _val(val), _atype(type) {
aoqi@0 4215 }
aoqi@0 4216 Attribute::~Attribute() {
aoqi@0 4217 }
aoqi@0 4218
aoqi@0 4219 int Attribute::int_val(ArchDesc &ad) {
aoqi@0 4220 // Make sure it is an integer constant:
aoqi@0 4221 int result = 0;
aoqi@0 4222 if (!_val || !ADLParser::is_int_token(_val, result)) {
aoqi@0 4223 ad.syntax_err(0, "Attribute %s must have an integer value: %s",
aoqi@0 4224 _ident, _val ? _val : "");
aoqi@0 4225 }
aoqi@0 4226 return result;
aoqi@0 4227 }
aoqi@0 4228
aoqi@0 4229 void Attribute::dump() {
aoqi@0 4230 output(stderr);
aoqi@0 4231 } // Debug printer
aoqi@0 4232
aoqi@0 4233 // Write to output files
aoqi@0 4234 void Attribute::output(FILE *fp) {
aoqi@0 4235 fprintf(fp,"Attribute: %s %s\n", (_ident?_ident:""), (_val?_val:""));
aoqi@0 4236 }
aoqi@0 4237
aoqi@0 4238 //------------------------------FormatRule----------------------------------
aoqi@0 4239 FormatRule::FormatRule(char *temp)
aoqi@0 4240 : _temp(temp) {
aoqi@0 4241 }
aoqi@0 4242 FormatRule::~FormatRule() {
aoqi@0 4243 }
aoqi@0 4244
aoqi@0 4245 void FormatRule::dump() {
aoqi@0 4246 output(stderr);
aoqi@0 4247 }
aoqi@0 4248
aoqi@0 4249 // Write to output files
aoqi@0 4250 void FormatRule::output(FILE *fp) {
aoqi@0 4251 fprintf(fp,"\nFormat Rule: \n%s", (_temp?_temp:""));
aoqi@0 4252 fprintf(fp,"\n");
aoqi@0 4253 }

mercurial