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