src/share/vm/opto/machnode.cpp

Thu, 24 May 2018 19:26:50 +0800

author
aoqi
date
Thu, 24 May 2018 19:26:50 +0800
changeset 8862
fd13a567f179
parent 7535
7ae4e26cb1e0
child 9572
624a0741915c
permissions
-rw-r--r--

#7046 C2 supports long branch
Contributed-by: fujie

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

mercurial