1 /*
   2  * Copyright (c) 1997, 2014, 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 #include "precompiled.hpp"
  26 #include "gc_interface/collectedHeap.hpp"
  27 #include "opto/machnode.hpp"
  28 #include "opto/regalloc.hpp"
  29 #include "opto/shenandoahSupport.hpp"
  30 
  31 //=============================================================================
  32 // Return the value requested
  33 // result register lookup, corresponding to int_format
  34 int MachOper::reg(PhaseRegAlloc *ra_, const Node *node) const {
  35   return (int)ra_->get_encode(node);
  36 }
  37 // input register lookup, corresponding to ext_format
  38 int MachOper::reg(PhaseRegAlloc *ra_, const Node *node, int idx) const {
  39   return (int)(ra_->get_encode(node->in(idx)));
  40 }
  41 intptr_t  MachOper::constant() const { return 0x00; }
  42 relocInfo::relocType MachOper::constant_reloc() const { return relocInfo::none; }
  43 jdouble MachOper::constantD() const { ShouldNotReachHere(); return 0.0; }
  44 jfloat  MachOper::constantF() const { ShouldNotReachHere(); return 0.0; }
  45 jlong   MachOper::constantL() const { ShouldNotReachHere(); return CONST64(0) ; }
  46 TypeOopPtr *MachOper::oop() const { return NULL; }
  47 int MachOper::ccode() const { return 0x00; }
  48 // A zero, default, indicates this value is not needed.
  49 // May need to lookup the base register, as done in int_ and ext_format
  50 int MachOper::base (PhaseRegAlloc *ra_, const Node *node, int idx)  const { return 0x00; }
  51 int MachOper::index(PhaseRegAlloc *ra_, const Node *node, int idx)  const { return 0x00; }
  52 int MachOper::scale()  const { return 0x00; }
  53 int MachOper::disp (PhaseRegAlloc *ra_, const Node *node, int idx)  const { return 0x00; }
  54 int MachOper::constant_disp()  const { return 0; }
  55 int MachOper::base_position()  const { return -1; }  // no base input
  56 int MachOper::index_position() const { return -1; }  // no index input
  57 // Check for PC-Relative displacement
  58 relocInfo::relocType MachOper::disp_reloc() const { return relocInfo::none; }
  59 // Return the label
  60 Label*   MachOper::label()  const { ShouldNotReachHere(); return 0; }
  61 intptr_t MachOper::method() const { ShouldNotReachHere(); return 0; }
  62 
  63 
  64 //------------------------------negate-----------------------------------------
  65 // Negate conditional branches.  Error for non-branch operands
  66 void MachOper::negate() {
  67   ShouldNotCallThis();
  68 }
  69 
  70 //-----------------------------type--------------------------------------------
  71 const Type *MachOper::type() const {
  72   return Type::BOTTOM;
  73 }
  74 
  75 //------------------------------in_RegMask-------------------------------------
  76 const RegMask *MachOper::in_RegMask(int index) const {
  77   ShouldNotReachHere();
  78   return NULL;
  79 }
  80 
  81 //------------------------------dump_spec--------------------------------------
  82 // Print any per-operand special info
  83 #ifndef PRODUCT
  84 void MachOper::dump_spec(outputStream *st) const { }
  85 #endif
  86 
  87 //------------------------------hash-------------------------------------------
  88 // Print any per-operand special info
  89 uint MachOper::hash() const {
  90   ShouldNotCallThis();
  91   return 5;
  92 }
  93 
  94 //------------------------------cmp--------------------------------------------
  95 // Print any per-operand special info
  96 uint MachOper::cmp( const MachOper &oper ) const {
  97   ShouldNotCallThis();
  98   return opcode() == oper.opcode();
  99 }
 100 
 101 //------------------------------hash-------------------------------------------
 102 // Print any per-operand special info
 103 uint labelOper::hash() const {
 104   return _block_num;
 105 }
 106 
 107 //------------------------------cmp--------------------------------------------
 108 // Print any per-operand special info
 109 uint labelOper::cmp( const MachOper &oper ) const {
 110   return (opcode() == oper.opcode()) && (_label == oper.label());
 111 }
 112 
 113 //------------------------------hash-------------------------------------------
 114 // Print any per-operand special info
 115 uint methodOper::hash() const {
 116   return (uint)_method;
 117 }
 118 
 119 //------------------------------cmp--------------------------------------------
 120 // Print any per-operand special info
 121 uint methodOper::cmp( const MachOper &oper ) const {
 122   return (opcode() == oper.opcode()) && (_method == oper.method());
 123 }
 124 
 125 
 126 //=============================================================================
 127 //------------------------------MachNode---------------------------------------
 128 
 129 //------------------------------emit-------------------------------------------
 130 void MachNode::emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const {
 131   #ifdef ASSERT
 132   tty->print("missing MachNode emit function: ");
 133   dump();
 134   #endif
 135   ShouldNotCallThis();
 136 }
 137 
 138 //---------------------------postalloc_expand----------------------------------
 139 // Expand node after register allocation.
 140 void MachNode::postalloc_expand(GrowableArray <Node *> *nodes, PhaseRegAlloc *ra_) {}
 141 
 142 //------------------------------size-------------------------------------------
 143 // Size of instruction in bytes
 144 uint MachNode::size(PhaseRegAlloc *ra_) const {
 145   // If a virtual was not defined for this specific instruction,
 146   // Call the helper which finds the size by emitting the bits.
 147   return MachNode::emit_size(ra_);
 148 }
 149 
 150 //------------------------------size-------------------------------------------
 151 // Helper function that computes size by emitting code
 152 uint MachNode::emit_size(PhaseRegAlloc *ra_) const {
 153   // Emit into a trash buffer and count bytes emitted.
 154   assert(ra_ == ra_->C->regalloc(), "sanity");
 155   return ra_->C->scratch_emit_size(this);
 156 }
 157 
 158 
 159 
 160 //------------------------------hash-------------------------------------------
 161 uint MachNode::hash() const {
 162   uint no = num_opnds();
 163   uint sum = rule();
 164   for( uint i=0; i<no; i++ )
 165     sum += _opnds[i]->hash();
 166   return sum+Node::hash();
 167 }
 168 
 169 //-----------------------------cmp---------------------------------------------
 170 uint MachNode::cmp( const Node &node ) const {
 171   MachNode& n = *((Node&)node).as_Mach();
 172   uint no = num_opnds();
 173   if( no != n.num_opnds() ) return 0;
 174   if( rule() != n.rule() ) return 0;
 175   for( uint i=0; i<no; i++ )    // All operands must match
 176     if( !_opnds[i]->cmp( *n._opnds[i] ) )
 177       return 0;                 // mis-matched operands
 178   return 1;                     // match
 179 }
 180 
 181 // Return an equivalent instruction using memory for cisc_operand position
 182 MachNode *MachNode::cisc_version(int offset, Compile* C) {
 183   ShouldNotCallThis();
 184   return NULL;
 185 }
 186 
 187 void MachNode::use_cisc_RegMask() {
 188   ShouldNotReachHere();
 189 }
 190 
 191 
 192 //-----------------------------in_RegMask--------------------------------------
 193 const RegMask &MachNode::in_RegMask( uint idx ) const {
 194   uint numopnds = num_opnds();        // Virtual call for number of operands
 195   uint skipped   = oper_input_base(); // Sum of leaves skipped so far
 196   if( idx < skipped ) {
 197     assert( ideal_Opcode() == Op_AddP, "expected base ptr here" );
 198     assert( idx == 1, "expected base ptr here" );
 199     // debug info can be anywhere
 200     return *Compile::current()->matcher()->idealreg2spillmask[Op_RegP];
 201   }
 202   uint opcnt     = 1;                 // First operand
 203   uint num_edges = _opnds[1]->num_edges(); // leaves for first operand
 204   while( idx >= skipped+num_edges ) {
 205     skipped += num_edges;
 206     opcnt++;                          // Bump operand count
 207     assert( opcnt < numopnds, "Accessing non-existent operand" );
 208     num_edges = _opnds[opcnt]->num_edges(); // leaves for next operand
 209   }
 210 
 211   const RegMask *rm = cisc_RegMask();
 212   if( rm == NULL || (int)opcnt != cisc_operand() ) {
 213     rm = _opnds[opcnt]->in_RegMask(idx-skipped);
 214   }
 215   return *rm;
 216 }
 217 
 218 //-----------------------------memory_inputs--------------------------------
 219 const MachOper*  MachNode::memory_inputs(Node* &base, Node* &index) const {
 220   const MachOper* oper = memory_operand();
 221 
 222   if (oper == (MachOper*)-1) {
 223     base = NodeSentinel;
 224     index = NodeSentinel;
 225   } else {
 226     base = NULL;
 227     index = NULL;
 228     if (oper != NULL) {
 229       // It has a unique memory operand.  Find its index.
 230       int oper_idx = num_opnds();
 231       while (--oper_idx >= 0) {
 232         if (_opnds[oper_idx] == oper)  break;
 233       }
 234       int oper_pos = operand_index(oper_idx);
 235       int base_pos = oper->base_position();
 236       if (base_pos >= 0) {
 237         base = _in[oper_pos+base_pos];
 238       }
 239       int index_pos = oper->index_position();
 240       if (index_pos >= 0) {
 241         index = _in[oper_pos+index_pos];
 242       }
 243     }
 244   }
 245 
 246   return oper;
 247 }
 248 
 249 //-----------------------------get_base_and_disp----------------------------
 250 Node* MachNode::get_base_and_disp(intptr_t &offset, const TypePtr* &adr_type) const {
 251 
 252   // Find the memory inputs using our helper function
 253   Node* base;
 254   Node* index;
 255   const MachOper* oper = memory_inputs(base, index);
 256 
 257   if (oper == NULL) {
 258     // Base has been set to NULL
 259     offset = 0;
 260   } else if (oper == (MachOper*)-1) {
 261     // Base has been set to NodeSentinel
 262     // There is not a unique memory use here.  We will fall to AliasIdxBot.
 263     offset = Type::OffsetBot;
 264   } else {
 265     // Base may be NULL, even if offset turns out to be != 0
 266 
 267     intptr_t disp = oper->constant_disp();
 268     int scale = oper->scale();
 269     // Now we have collected every part of the ADLC MEMORY_INTER.
 270     // See if it adds up to a base + offset.
 271     if (index != NULL) {
 272       const Type* t_index = index->bottom_type();
 273       if (t_index->isa_narrowoop() || t_index->isa_narrowklass()) { // EncodeN, LoadN, LoadConN, LoadNKlass,
 274                                                                     // EncodeNKlass, LoadConNklass.
 275         // Memory references through narrow oops have a
 276         // funny base so grab the type from the index:
 277         // [R12 + narrow_oop_reg<<3 + offset]
 278         assert(base == NULL, "Memory references through narrow oops have no base");
 279         offset = disp;
 280         adr_type = t_index->make_ptr()->add_offset(offset);
 281         return NULL;
 282       } else if (!index->is_Con()) {
 283         disp = Type::OffsetBot;
 284       } else if (disp != Type::OffsetBot) {
 285         const TypeX* ti = t_index->isa_intptr_t();
 286         if (ti == NULL) {
 287           disp = Type::OffsetBot;  // a random constant??
 288         } else {
 289           disp += ti->get_con() << scale;
 290         }
 291       }
 292     }
 293     offset = disp;
 294 
 295     // In i486.ad, indOffset32X uses base==RegI and disp==RegP,
 296     // this will prevent alias analysis without the following support:
 297     // Lookup the TypePtr used by indOffset32X, a compile-time constant oop,
 298     // Add the offset determined by the "base", or use Type::OffsetBot.
 299     if( adr_type == TYPE_PTR_SENTINAL ) {
 300       const TypePtr *t_disp = oper->disp_as_type();  // only !NULL for indOffset32X
 301       if (t_disp != NULL) {
 302         offset = Type::OffsetBot;
 303         const Type* t_base = base->bottom_type();
 304         if (t_base->isa_intptr_t()) {
 305           const TypeX *t_offset = t_base->is_intptr_t();
 306           if( t_offset->is_con() ) {
 307             offset = t_offset->get_con();
 308           }
 309         }
 310         adr_type = t_disp->add_offset(offset);
 311       } else if( base == NULL && offset != 0 && offset != Type::OffsetBot ) {
 312         // Use ideal type if it is oop ptr.
 313         const TypePtr *tp = oper->type()->isa_ptr();
 314         if( tp != NULL) {
 315           adr_type = tp;
 316         }
 317       }
 318     }
 319 
 320   }
 321   return base;
 322 }
 323 
 324 
 325 //---------------------------------adr_type---------------------------------
 326 const class TypePtr *MachNode::adr_type() const {
 327   intptr_t offset = 0;
 328   const TypePtr *adr_type = TYPE_PTR_SENTINAL;  // attempt computing adr_type
 329   Node *base = get_base_and_disp(offset, adr_type);
 330 
 331   if( adr_type != TYPE_PTR_SENTINAL ) {
 332     return ShenandoahBarrierNode::fix_addp_type(adr_type, base);      // get_base_and_disp has the answer
 333   }
 334 
 335   // Direct addressing modes have no base node, simply an indirect
 336   // offset, which is always to raw memory.
 337   // %%%%% Someday we'd like to allow constant oop offsets which
 338   // would let Intel load from static globals in 1 instruction.
 339   // Currently Intel requires 2 instructions and a register temp.
 340   if (base == NULL) {
 341     // NULL base, zero offset means no memory at all (a null pointer!)
 342     if (offset == 0) {
 343       return NULL;
 344     }
 345     // NULL base, any offset means any pointer whatever
 346     if (offset == Type::OffsetBot) {
 347       return TypePtr::BOTTOM;
 348     }
 349     // %%% make offset be intptr_t
 350     assert(!Universe::heap()->is_in_reserved(cast_to_oop(offset)), "must be a raw ptr");
 351     return TypeRawPtr::BOTTOM;
 352   }
 353 
 354   // base of -1 with no particular offset means all of memory
 355   if (base == NodeSentinel)  return TypePtr::BOTTOM;
 356 
 357   const Type* t = base->bottom_type();
 358   if (t->isa_narrowoop() && Universe::narrow_oop_shift() == 0) {
 359     // 32-bit unscaled narrow oop can be the base of any address expression
 360     t = t->make_ptr();
 361   }
 362   if (t->isa_narrowklass() && Universe::narrow_klass_shift() == 0) {
 363     // 32-bit unscaled narrow oop can be the base of any address expression
 364     t = t->make_ptr();
 365   }
 366   if (t->isa_intptr_t() && offset != 0 && offset != Type::OffsetBot) {
 367     // We cannot assert that the offset does not look oop-ish here.
 368     // Depending on the heap layout the cardmark base could land
 369     // inside some oopish region.  It definitely does for Win2K.
 370     // The sum of cardmark-base plus shift-by-9-oop lands outside
 371     // the oop-ish area but we can't assert for that statically.
 372     return TypeRawPtr::BOTTOM;
 373   }
 374 
 375   const TypePtr *tp = t->isa_ptr();
 376 
 377   // be conservative if we do not recognize the type
 378   if (tp == NULL) {
 379     assert(false, "this path may produce not optimal code");
 380     return TypePtr::BOTTOM;
 381   }
 382   assert(tp->base() != Type::AnyPtr, "not a bare pointer");
 383 
 384   return ShenandoahBarrierNode::fix_addp_type(tp->add_offset(offset), base);
 385 }
 386 
 387 
 388 //-----------------------------operand_index---------------------------------
 389 int MachNode::operand_index( uint operand ) const {
 390   if( operand < 1 )  return -1;
 391   assert(operand < num_opnds(), "oob");
 392   if( _opnds[operand]->num_edges() == 0 )  return -1;
 393 
 394   uint skipped   = oper_input_base(); // Sum of leaves skipped so far
 395   for (uint opcnt = 1; opcnt < operand; opcnt++) {
 396     uint num_edges = _opnds[opcnt]->num_edges(); // leaves for operand
 397     skipped += num_edges;
 398   }
 399   return skipped;
 400 }
 401 
 402 int MachNode::operand_index(const MachOper *oper) const {
 403   uint skipped = oper_input_base(); // Sum of leaves skipped so far
 404   uint opcnt;
 405   for (opcnt = 1; opcnt < num_opnds(); opcnt++) {
 406     if (_opnds[opcnt] == oper) break;
 407     uint num_edges = _opnds[opcnt]->num_edges(); // leaves for operand
 408     skipped += num_edges;
 409   }
 410   if (_opnds[opcnt] != oper) return -1;
 411   return skipped;
 412 }
 413 
 414 //------------------------------peephole---------------------------------------
 415 // Apply peephole rule(s) to this instruction
 416 MachNode *MachNode::peephole( Block *block, int block_index, PhaseRegAlloc *ra_, int &deleted, Compile* C ) {
 417   return NULL;
 418 }
 419 
 420 //------------------------------add_case_label---------------------------------
 421 // Adds the label for the case
 422 void MachNode::add_case_label( int index_num, Label* blockLabel) {
 423   ShouldNotCallThis();
 424 }
 425 
 426 //------------------------------method_set-------------------------------------
 427 // Set the absolute address of a method
 428 void MachNode::method_set( intptr_t addr ) {
 429   ShouldNotCallThis();
 430 }
 431 
 432 //------------------------------rematerialize----------------------------------
 433 bool MachNode::rematerialize() const {
 434   // Temps are always rematerializable
 435   if (is_MachTemp()) return true;
 436 
 437   uint r = rule();              // Match rule
 438   if( r <  Matcher::_begin_rematerialize ||
 439       r >= Matcher::_end_rematerialize )
 440     return false;
 441 
 442   // For 2-address instructions, the input live range is also the output
 443   // live range.  Remateralizing does not make progress on the that live range.
 444   if( two_adr() )  return false;
 445 
 446   // Check for rematerializing float constants, or not
 447   if( !Matcher::rematerialize_float_constants ) {
 448     int op = ideal_Opcode();
 449     if( op == Op_ConF || op == Op_ConD )
 450       return false;
 451   }
 452 
 453   // Defining flags - can't spill these!  Must remateralize.
 454   if( ideal_reg() == Op_RegFlags )
 455     return true;
 456 
 457   // Stretching lots of inputs - don't do it.
 458   if( req() > 2 )
 459     return false;
 460 
 461   // Don't remateralize somebody with bound inputs - it stretches a
 462   // fixed register lifetime.
 463   uint idx = oper_input_base();
 464   if (req() > idx) {
 465     const RegMask &rm = in_RegMask(idx);
 466     if (rm.is_bound(ideal_reg()))
 467       return false;
 468   }
 469 
 470   return true;
 471 }
 472 
 473 #ifndef PRODUCT
 474 //------------------------------dump_spec--------------------------------------
 475 // Print any per-operand special info
 476 void MachNode::dump_spec(outputStream *st) const {
 477   uint cnt = num_opnds();
 478   for( uint i=0; i<cnt; i++ )
 479     _opnds[i]->dump_spec(st);
 480   const TypePtr *t = adr_type();
 481   if( t ) {
 482     Compile* C = Compile::current();
 483     if( C->alias_type(t)->is_volatile() )
 484       st->print(" Volatile!");
 485   }
 486 }
 487 
 488 //------------------------------dump_format------------------------------------
 489 // access to virtual
 490 void MachNode::dump_format(PhaseRegAlloc *ra, outputStream *st) const {
 491   format(ra, st); // access to virtual
 492 }
 493 #endif
 494 
 495 //=============================================================================
 496 #ifndef PRODUCT
 497 void MachTypeNode::dump_spec(outputStream *st) const {
 498   _bottom_type->dump_on(st);
 499 }
 500 #endif
 501 
 502 
 503 //=============================================================================
 504 int MachConstantNode::constant_offset() {
 505   // Bind the offset lazily.
 506   if (_constant.offset() == -1) {
 507     Compile::ConstantTable& constant_table = Compile::current()->constant_table();
 508     int offset = constant_table.find_offset(_constant);
 509     // If called from Compile::scratch_emit_size return the
 510     // pre-calculated offset.
 511     // NOTE: If the AD file does some table base offset optimizations
 512     // later the AD file needs to take care of this fact.
 513     if (Compile::current()->in_scratch_emit_size()) {
 514       return constant_table.calculate_table_base_offset() + offset;
 515     }
 516     _constant.set_offset(constant_table.table_base_offset() + offset);
 517   }
 518   return _constant.offset();
 519 }
 520 
 521 int MachConstantNode::constant_offset_unchecked() const {
 522   return _constant.offset();
 523 }
 524 
 525 //=============================================================================
 526 #ifndef PRODUCT
 527 void MachNullCheckNode::format( PhaseRegAlloc *ra_, outputStream *st ) const {
 528   int reg = ra_->get_reg_first(in(1)->in(_vidx));
 529   st->print("%s %s", Name(), Matcher::regName[reg]);
 530 }
 531 #endif
 532 
 533 void MachNullCheckNode::emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const {
 534   // only emits entries in the null-pointer exception handler table
 535 }
 536 void MachNullCheckNode::label_set(Label* label, uint block_num) {
 537   // Nothing to emit
 538 }
 539 void MachNullCheckNode::save_label( Label** label, uint* block_num ) {
 540   // Nothing to emit
 541 }
 542 
 543 const RegMask &MachNullCheckNode::in_RegMask( uint idx ) const {
 544   if( idx == 0 ) return RegMask::Empty;
 545   else return in(1)->as_Mach()->out_RegMask();
 546 }
 547 
 548 //=============================================================================
 549 const Type *MachProjNode::bottom_type() const {
 550   if( _ideal_reg == fat_proj ) return Type::BOTTOM;
 551   // Try the normal mechanism first
 552   const Type *t = in(0)->bottom_type();
 553   if( t->base() == Type::Tuple ) {
 554     const TypeTuple *tt = t->is_tuple();
 555     if (_con < tt->cnt())
 556       return tt->field_at(_con);
 557   }
 558   // Else use generic type from ideal register set
 559   assert((uint)_ideal_reg < (uint)_last_machine_leaf && Type::mreg2type[_ideal_reg], "in bounds");
 560   return Type::mreg2type[_ideal_reg];
 561 }
 562 
 563 const TypePtr *MachProjNode::adr_type() const {
 564   if (bottom_type() == Type::MEMORY) {
 565     // in(0) might be a narrow MemBar; otherwise we will report TypePtr::BOTTOM
 566     const TypePtr* adr_type = in(0)->adr_type();
 567     #ifdef ASSERT
 568     if (!is_error_reported() && !Node::in_dump())
 569       assert(adr_type != NULL, "source must have adr_type");
 570     #endif
 571     return adr_type;
 572   }
 573   assert(bottom_type()->base() != Type::Memory, "no other memories?");
 574   return NULL;
 575 }
 576 
 577 #ifndef PRODUCT
 578 void MachProjNode::dump_spec(outputStream *st) const {
 579   ProjNode::dump_spec(st);
 580   switch (_ideal_reg) {
 581   case unmatched_proj:  st->print("/unmatched");                         break;
 582   case fat_proj:        st->print("/fat"); if (WizardMode) _rout.dump(); break;
 583   }
 584 }
 585 #endif
 586 
 587 //=============================================================================
 588 #ifndef PRODUCT
 589 void MachIfNode::dump_spec(outputStream *st) const {
 590   st->print("P=%f, C=%f",_prob, _fcnt);
 591 }
 592 #endif
 593 
 594 //=============================================================================
 595 uint MachReturnNode::size_of() const { return sizeof(*this); }
 596 
 597 //------------------------------Registers--------------------------------------
 598 const RegMask &MachReturnNode::in_RegMask( uint idx ) const {
 599   return _in_rms[idx];
 600 }
 601 
 602 const TypePtr *MachReturnNode::adr_type() const {
 603   // most returns and calls are assumed to consume & modify all of memory
 604   // the matcher will copy non-wide adr_types from ideal originals
 605   return _adr_type;
 606 }
 607 
 608 //=============================================================================
 609 const Type *MachSafePointNode::bottom_type() const {  return TypeTuple::MEMBAR; }
 610 
 611 //------------------------------Registers--------------------------------------
 612 const RegMask &MachSafePointNode::in_RegMask( uint idx ) const {
 613   // Values in the domain use the users calling convention, embodied in the
 614   // _in_rms array of RegMasks.
 615   if( idx < TypeFunc::Parms ) return _in_rms[idx];
 616 
 617   if (SafePointNode::needs_polling_address_input() &&
 618       idx == TypeFunc::Parms &&
 619       ideal_Opcode() == Op_SafePoint) {
 620     return MachNode::in_RegMask(idx);
 621   }
 622 
 623   // Values outside the domain represent debug info
 624   return *Compile::current()->matcher()->idealreg2spillmask[in(idx)->ideal_reg()];
 625 }
 626 
 627 
 628 //=============================================================================
 629 
 630 uint MachCallNode::cmp( const Node &n ) const
 631 { return _tf == ((MachCallNode&)n)._tf; }
 632 const Type *MachCallNode::bottom_type() const { return tf()->range(); }
 633 const Type *MachCallNode::Value(PhaseTransform *phase) const { return tf()->range(); }
 634 
 635 #ifndef PRODUCT
 636 void MachCallNode::dump_spec(outputStream *st) const {
 637   st->print("# ");
 638   tf()->dump_on(st);
 639   if (_cnt != COUNT_UNKNOWN)  st->print(" C=%f",_cnt);
 640   if (jvms() != NULL)  jvms()->dump_spec(st);
 641 }
 642 #endif
 643 
 644 bool MachCallNode::return_value_is_used() const {
 645   if (tf()->range()->cnt() == TypeFunc::Parms) {
 646     // void return
 647     return false;
 648   }
 649 
 650   // find the projection corresponding to the return value
 651   for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {
 652     Node *use = fast_out(i);
 653     if (!use->is_Proj()) continue;
 654     if (use->as_Proj()->_con == TypeFunc::Parms) {
 655       return true;
 656     }
 657   }
 658   return false;
 659 }
 660 
 661 // Similar to cousin class CallNode::returns_pointer
 662 // Because this is used in deoptimization, we want the type info, not the data
 663 // flow info; the interpreter will "use" things that are dead to the optimizer.
 664 bool MachCallNode::returns_pointer() const {
 665   const TypeTuple *r = tf()->range();
 666   return (r->cnt() > TypeFunc::Parms &&
 667           r->field_at(TypeFunc::Parms)->isa_ptr());
 668 }
 669 
 670 //------------------------------Registers--------------------------------------
 671 const RegMask &MachCallNode::in_RegMask(uint idx) const {
 672   // Values in the domain use the users calling convention, embodied in the
 673   // _in_rms array of RegMasks.
 674   if (idx < tf()->domain()->cnt()) {
 675     return _in_rms[idx];
 676   }
 677   if (idx == mach_constant_base_node_input()) {
 678     return MachConstantBaseNode::static_out_RegMask();
 679   }
 680   // Values outside the domain represent debug info
 681   return *Compile::current()->matcher()->idealreg2debugmask[in(idx)->ideal_reg()];
 682 }
 683 
 684 //=============================================================================
 685 uint MachCallJavaNode::size_of() const { return sizeof(*this); }
 686 uint MachCallJavaNode::cmp( const Node &n ) const {
 687   MachCallJavaNode &call = (MachCallJavaNode&)n;
 688   return MachCallNode::cmp(call) && _method->equals(call._method);
 689 }
 690 #ifndef PRODUCT
 691 void MachCallJavaNode::dump_spec(outputStream *st) const {
 692   if (_method_handle_invoke)
 693     st->print("MethodHandle ");
 694   if (_method) {
 695     _method->print_short_name(st);
 696     st->print(" ");
 697   }
 698   MachCallNode::dump_spec(st);
 699 }
 700 #endif
 701 
 702 //------------------------------Registers--------------------------------------
 703 const RegMask &MachCallJavaNode::in_RegMask(uint idx) const {
 704   // Values in the domain use the users calling convention, embodied in the
 705   // _in_rms array of RegMasks.
 706   if (idx < tf()->domain()->cnt()) {
 707     return _in_rms[idx];
 708   }
 709   if (idx == mach_constant_base_node_input()) {
 710     return MachConstantBaseNode::static_out_RegMask();
 711   }
 712   // Values outside the domain represent debug info
 713   Matcher* m = Compile::current()->matcher();
 714   // If this call is a MethodHandle invoke we have to use a different
 715   // debugmask which does not include the register we use to save the
 716   // SP over MH invokes.
 717   RegMask** debugmask = _method_handle_invoke ? m->idealreg2mhdebugmask : m->idealreg2debugmask;
 718   return *debugmask[in(idx)->ideal_reg()];
 719 }
 720 
 721 //=============================================================================
 722 uint MachCallStaticJavaNode::size_of() const { return sizeof(*this); }
 723 uint MachCallStaticJavaNode::cmp( const Node &n ) const {
 724   MachCallStaticJavaNode &call = (MachCallStaticJavaNode&)n;
 725   return MachCallJavaNode::cmp(call) && _name == call._name;
 726 }
 727 
 728 //----------------------------uncommon_trap_request----------------------------
 729 // If this is an uncommon trap, return the request code, else zero.
 730 int MachCallStaticJavaNode::uncommon_trap_request() const {
 731   if (_name != NULL && !strcmp(_name, "uncommon_trap")) {
 732     return CallStaticJavaNode::extract_uncommon_trap_request(this);
 733   }
 734   return 0;
 735 }
 736 
 737 #ifndef PRODUCT
 738 // Helper for summarizing uncommon_trap arguments.
 739 void MachCallStaticJavaNode::dump_trap_args(outputStream *st) const {
 740   int trap_req = uncommon_trap_request();
 741   if (trap_req != 0) {
 742     char buf[100];
 743     st->print("(%s)",
 744                Deoptimization::format_trap_request(buf, sizeof(buf),
 745                                                    trap_req));
 746   }
 747 }
 748 
 749 void MachCallStaticJavaNode::dump_spec(outputStream *st) const {
 750   st->print("Static ");
 751   if (_name != NULL) {
 752     st->print("wrapper for: %s", _name );
 753     dump_trap_args(st);
 754     st->print(" ");
 755   }
 756   MachCallJavaNode::dump_spec(st);
 757 }
 758 #endif
 759 
 760 //=============================================================================
 761 #ifndef PRODUCT
 762 void MachCallDynamicJavaNode::dump_spec(outputStream *st) const {
 763   st->print("Dynamic ");
 764   MachCallJavaNode::dump_spec(st);
 765 }
 766 #endif
 767 //=============================================================================
 768 uint MachCallRuntimeNode::size_of() const { return sizeof(*this); }
 769 uint MachCallRuntimeNode::cmp( const Node &n ) const {
 770   MachCallRuntimeNode &call = (MachCallRuntimeNode&)n;
 771   return MachCallNode::cmp(call) && !strcmp(_name,call._name);
 772 }
 773 #ifndef PRODUCT
 774 void MachCallRuntimeNode::dump_spec(outputStream *st) const {
 775   st->print("%s ",_name);
 776   MachCallNode::dump_spec(st);
 777 }
 778 #endif
 779 //=============================================================================
 780 // A shared JVMState for all HaltNodes.  Indicates the start of debug info
 781 // is at TypeFunc::Parms.  Only required for SOE register spill handling -
 782 // to indicate where the stack-slot-only debug info inputs begin.
 783 // There is no other JVM state needed here.
 784 JVMState jvms_for_throw(0);
 785 JVMState *MachHaltNode::jvms() const {
 786   return &jvms_for_throw;
 787 }
 788 
 789 uint MachMemBarNode::size_of() const { return sizeof(*this); }
 790 
 791 const TypePtr *MachMemBarNode::adr_type() const {
 792   return _adr_type;
 793 }
 794 
 795 
 796 //=============================================================================
 797 #ifndef PRODUCT
 798 void labelOper::int_format(PhaseRegAlloc *ra, const MachNode *node, outputStream *st) const {
 799   st->print("B%d", _block_num);
 800 }
 801 #endif // PRODUCT
 802 
 803 //=============================================================================
 804 #ifndef PRODUCT
 805 void methodOper::int_format(PhaseRegAlloc *ra, const MachNode *node, outputStream *st) const {
 806   st->print(INTPTR_FORMAT, _method);
 807 }
 808 #endif // PRODUCT