1 /* 2 * Copyright (c) 1997, 2010, 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 class BufferBlob; 26 class CodeBuffer; 27 class JVMState; 28 class MachCallDynamicJavaNode; 29 class MachCallJavaNode; 30 class MachCallLeafNode; 31 class MachCallNode; 32 class MachCallRuntimeNode; 33 class MachCallStaticJavaNode; 34 class MachEpilogNode; 35 class MachIfNode; 36 class MachNullCheckNode; 37 class MachOper; 38 class MachProjNode; 39 class MachPrologNode; 40 class MachReturnNode; 41 class MachSafePointNode; 42 class MachSpillCopyNode; 43 class Matcher; 44 class PhaseRegAlloc; 45 class RegMask; 46 class State; 47 48 //---------------------------MachOper------------------------------------------ 49 class MachOper : public ResourceObj { 50 public: 51 // Allocate right next to the MachNodes in the same arena 52 void *operator new( size_t x, Compile* C ) { return C->node_arena()->Amalloc_D(x); } 53 54 // Opcode 55 virtual uint opcode() const = 0; 56 57 // Number of input edges. 58 // Generally at least 1 59 virtual uint num_edges() const { return 1; } 60 // Array of Register masks 61 virtual const RegMask *in_RegMask(int index) const; 62 63 // Methods to output the encoding of the operand 64 65 // Negate conditional branches. Error for non-branch Nodes 66 virtual void negate(); 67 68 // Return the value requested 69 // result register lookup, corresponding to int_format 70 virtual int reg(PhaseRegAlloc *ra_, const Node *node) const; 71 // input register lookup, corresponding to ext_format 72 virtual int reg(PhaseRegAlloc *ra_, const Node *node, int idx) const; 73 74 // helpers for MacroAssembler generation from ADLC 75 Register as_Register(PhaseRegAlloc *ra_, const Node *node) const { 76 return ::as_Register(reg(ra_, node)); 77 } 78 Register as_Register(PhaseRegAlloc *ra_, const Node *node, int idx) const { 79 return ::as_Register(reg(ra_, node, idx)); 80 } 81 FloatRegister as_FloatRegister(PhaseRegAlloc *ra_, const Node *node) const { 82 return ::as_FloatRegister(reg(ra_, node)); 83 } 84 FloatRegister as_FloatRegister(PhaseRegAlloc *ra_, const Node *node, int idx) const { 85 return ::as_FloatRegister(reg(ra_, node, idx)); 86 } 87 88 #if defined(IA32) || defined(AMD64) 89 XMMRegister as_XMMRegister(PhaseRegAlloc *ra_, const Node *node) const { 90 return ::as_XMMRegister(reg(ra_, node)); 91 } 92 XMMRegister as_XMMRegister(PhaseRegAlloc *ra_, const Node *node, int idx) const { 93 return ::as_XMMRegister(reg(ra_, node, idx)); 94 } 95 #endif 96 97 virtual intptr_t constant() const; 98 virtual bool constant_is_oop() const; 99 virtual jdouble constantD() const; 100 virtual jfloat constantF() const; 101 virtual jlong constantL() const; 102 virtual TypeOopPtr *oop() const; 103 virtual int ccode() const; 104 // A zero, default, indicates this value is not needed. 105 // May need to lookup the base register, as done in int_ and ext_format 106 virtual int base (PhaseRegAlloc *ra_, const Node *node, int idx) const; 107 virtual int index(PhaseRegAlloc *ra_, const Node *node, int idx) const; 108 virtual int scale() const; 109 // Parameters needed to support MEMORY_INTERFACE access to stackSlot 110 virtual int disp (PhaseRegAlloc *ra_, const Node *node, int idx) const; 111 // Check for PC-Relative displacement 112 virtual bool disp_is_oop() const; 113 virtual int constant_disp() const; // usu. 0, may return Type::OffsetBot 114 virtual int base_position() const; // base edge position, or -1 115 virtual int index_position() const; // index edge position, or -1 116 117 // Access the TypeKlassPtr of operands with a base==RegI and disp==RegP 118 // Only returns non-null value for i486.ad's indOffset32X 119 virtual const TypePtr *disp_as_type() const { return NULL; } 120 121 // Return the label 122 virtual Label *label() const; 123 124 // Return the method's address 125 virtual intptr_t method() const; 126 127 // Hash and compare over operands are currently identical 128 virtual uint hash() const; 129 virtual uint cmp( const MachOper &oper ) const; 130 131 // Virtual clone, since I do not know how big the MachOper is. 132 virtual MachOper *clone(Compile* C) const = 0; 133 134 // Return ideal Type from simple operands. Fail for complex operands. 135 virtual const Type *type() const; 136 137 // Set an integer offset if we have one, or error otherwise 138 virtual void set_con( jint c0 ) { ShouldNotReachHere(); } 139 140 #ifndef PRODUCT 141 // Return name of operand 142 virtual const char *Name() const { return "???";} 143 144 // Methods to output the text version of the operand 145 virtual void int_format(PhaseRegAlloc *,const MachNode *node, outputStream *st) const = 0; 146 virtual void ext_format(PhaseRegAlloc *,const MachNode *node,int idx, outputStream *st) const=0; 147 148 virtual void dump_spec(outputStream *st) const; // Print per-operand info 149 #endif 150 }; 151 152 //------------------------------MachNode--------------------------------------- 153 // Base type for all machine specific nodes. All node classes generated by the 154 // ADLC inherit from this class. 155 class MachNode : public Node { 156 public: 157 MachNode() : Node((uint)0), _num_opnds(0), _opnds(NULL) { 158 init_class_id(Class_Mach); 159 } 160 // Required boilerplate 161 virtual uint size_of() const { return sizeof(MachNode); } 162 virtual int Opcode() const; // Always equal to MachNode 163 virtual uint rule() const = 0; // Machine-specific opcode 164 // Number of inputs which come before the first operand. 165 // Generally at least 1, to skip the Control input 166 virtual uint oper_input_base() const { return 1; } 167 168 // Copy inputs and operands to new node of instruction. 169 // Called from cisc_version() and short_branch_version(). 170 // !!!! The method's body is defined in ad_<arch>.cpp file. 171 void fill_new_machnode(MachNode *n, Compile* C) const; 172 173 // Return an equivalent instruction using memory for cisc_operand position 174 virtual MachNode *cisc_version(int offset, Compile* C); 175 // Modify this instruction's register mask to use stack version for cisc_operand 176 virtual void use_cisc_RegMask(); 177 178 // Support for short branches 179 virtual MachNode *short_branch_version(Compile* C) { return NULL; } 180 bool may_be_short_branch() const { return (flags() & Flag_may_be_short_branch) != 0; } 181 182 // First index in _in[] corresponding to operand, or -1 if there is none 183 int operand_index(uint operand) const; 184 185 // Register class input is expected in 186 virtual const RegMask &in_RegMask(uint) const; 187 188 // cisc-spillable instructions redefine for use by in_RegMask 189 virtual const RegMask *cisc_RegMask() const { return NULL; } 190 191 // If this instruction is a 2-address instruction, then return the 192 // index of the input which must match the output. Not nessecary 193 // for instructions which bind the input and output register to the 194 // same singleton regiser (e.g., Intel IDIV which binds AX to be 195 // both an input and an output). It is nessecary when the input and 196 // output have choices - but they must use the same choice. 197 virtual uint two_adr( ) const { return 0; } 198 199 // Array of complex operand pointers. Each corresponds to zero or 200 // more leafs. Must be set by MachNode constructor to point to an 201 // internal array of MachOpers. The MachOper array is sized by 202 // specific MachNodes described in the ADL. 203 uint _num_opnds; 204 MachOper **_opnds; 205 uint num_opnds() const { return _num_opnds; } 206 207 // Emit bytes into cbuf 208 virtual void emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const; 209 // Size of instruction in bytes 210 virtual uint size(PhaseRegAlloc *ra_) const; 211 // Helper function that computes size by emitting code 212 virtual uint emit_size(PhaseRegAlloc *ra_) const; 213 214 // Return the alignment required (in units of relocInfo::addr_unit()) 215 // for this instruction (must be a power of 2) 216 virtual int alignment_required() const { return 1; } 217 218 // Return the padding (in bytes) to be emitted before this 219 // instruction to properly align it. 220 virtual int compute_padding(int current_offset) const { return 0; } 221 222 // Return number of relocatable values contained in this instruction 223 virtual int reloc() const { return 0; } 224 225 // Hash and compare over operands. Used to do GVN on machine Nodes. 226 virtual uint hash() const; 227 virtual uint cmp( const Node &n ) const; 228 229 // Expand method for MachNode, replaces nodes representing pseudo 230 // instructions with a set of nodes which represent real machine 231 // instructions and compute the same value. 232 virtual MachNode *Expand( State *, Node_List &proj_list, Node* mem ) { return this; } 233 234 // Bottom_type call; value comes from operand0 235 virtual const class Type *bottom_type() const { return _opnds[0]->type(); } 236 virtual uint ideal_reg() const { const Type *t = _opnds[0]->type(); return t == TypeInt::CC ? Op_RegFlags : Matcher::base2reg[t->base()]; } 237 238 // If this is a memory op, return the base pointer and fixed offset. 239 // If there are no such, return NULL. If there are multiple addresses 240 // or the address is indeterminate (rare cases) then return (Node*)-1, 241 // which serves as node bottom. 242 // If the offset is not statically determined, set it to Type::OffsetBot. 243 // This method is free to ignore stack slots if that helps. 244 #define TYPE_PTR_SENTINAL ((const TypePtr*)-1) 245 // Passing TYPE_PTR_SENTINAL as adr_type asks for computation of the adr_type if possible 246 const Node* get_base_and_disp(intptr_t &offset, const TypePtr* &adr_type) const; 247 248 // Helper for get_base_and_disp: find the base and index input nodes. 249 // Returns the MachOper as determined by memory_operand(), for use, if 250 // needed by the caller. If (MachOper *)-1 is returned, base and index 251 // are set to NodeSentinel. If (MachOper *) NULL is returned, base and 252 // index are set to NULL. 253 const MachOper* memory_inputs(Node* &base, Node* &index) const; 254 255 // Helper for memory_inputs: Which operand carries the necessary info? 256 // By default, returns NULL, which means there is no such operand. 257 // If it returns (MachOper*)-1, this means there are multiple memories. 258 virtual const MachOper* memory_operand() const { return NULL; } 259 260 // Call "get_base_and_disp" to decide which category of memory is used here. 261 virtual const class TypePtr *adr_type() const; 262 263 // Negate conditional branches. Error for non-branch Nodes 264 virtual void negate(); 265 266 // Apply peephole rule(s) to this instruction 267 virtual MachNode *peephole( Block *block, int block_index, PhaseRegAlloc *ra_, int &deleted, Compile* C ); 268 269 // Check for PC-Relative addressing 270 bool is_pc_relative() const { return (flags() & Flag_is_pc_relative) != 0; } 271 272 // Top-level ideal Opcode matched 273 virtual int ideal_Opcode() const { return Op_Node; } 274 275 // Set the branch inside jump MachNodes. Error for non-branch Nodes. 276 virtual void label_set( Label& label, uint block_num ); 277 278 // Adds the label for the case 279 virtual void add_case_label( int switch_val, Label* blockLabel); 280 281 // Set the absolute address for methods 282 virtual void method_set( intptr_t addr ); 283 284 // Should we clone rather than spill this instruction? 285 bool rematerialize() const; 286 287 // Get the pipeline info 288 static const Pipeline *pipeline_class(); 289 virtual const Pipeline *pipeline() const; 290 291 #ifndef PRODUCT 292 virtual const char *Name() const = 0; // Machine-specific name 293 virtual void dump_spec(outputStream *st) const; // Print per-node info 294 void dump_format(PhaseRegAlloc *ra, outputStream *st) const; // access to virtual 295 #endif 296 }; 297 298 //------------------------------MachIdealNode---------------------------- 299 // Machine specific versions of nodes that must be defined by user. 300 // These are not converted by matcher from ideal nodes to machine nodes 301 // but are inserted into the code by the compiler. 302 class MachIdealNode : public MachNode { 303 public: 304 MachIdealNode( ) {} 305 306 // Define the following defaults for non-matched machine nodes 307 virtual uint oper_input_base() const { return 0; } 308 virtual uint rule() const { return 9999999; } 309 virtual const class Type *bottom_type() const { return _opnds == NULL ? Type::CONTROL : MachNode::bottom_type(); } 310 }; 311 312 //------------------------------MachTypeNode---------------------------- 313 // Machine Nodes that need to retain a known Type. 314 class MachTypeNode : public MachNode { 315 virtual uint size_of() const { return sizeof(*this); } // Size is bigger 316 public: 317 const Type *_bottom_type; 318 319 virtual const class Type *bottom_type() const { return _bottom_type; } 320 #ifndef PRODUCT 321 virtual void dump_spec(outputStream *st) const; 322 #endif 323 }; 324 325 //------------------------------MachBreakpointNode---------------------------- 326 // Machine breakpoint or interrupt Node 327 class MachBreakpointNode : public MachIdealNode { 328 public: 329 MachBreakpointNode( ) {} 330 virtual void emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const; 331 virtual uint size(PhaseRegAlloc *ra_) const; 332 333 #ifndef PRODUCT 334 virtual const char *Name() const { return "Breakpoint"; } 335 virtual void format( PhaseRegAlloc *, outputStream *st ) const; 336 #endif 337 }; 338 339 //------------------------------MachConstantBaseNode-------------------------- 340 // Machine node that represents the base address of the constant 341 // table. 342 class MachConstantBaseNode : public MachIdealNode { 343 public: 344 class Constant { 345 private: 346 BasicType _type; 347 jvalue _value; 348 int _offset; // offset of this constant (in bytes) relative to the constant table base. 349 bool _can_be_reused; // true (default) if the value can be shared with other users. 350 351 public: 352 Constant() : _type(T_ILLEGAL), _offset(-1), _can_be_reused(true) { _value.l = 0; } 353 Constant(BasicType type, jvalue value, bool can_be_reused = true) : 354 _type(type), 355 _value(value), 356 _offset(-1), 357 _can_be_reused(can_be_reused) 358 {} 359 360 bool operator==(const Constant& other); 361 362 BasicType type() const { return _type; } 363 364 jlong get_jlong() const { return _value.j; } 365 jfloat get_jfloat() const { return _value.f; } 366 jdouble get_jdouble() const { return _value.d; } 367 jobject get_jobject() const { return _value.l; } 368 369 int offset() const { return _offset; } 370 void set_offset(int offset) { _offset = offset; } 371 372 bool can_be_reused() const { return _can_be_reused; } 373 }; 374 375 private: 376 GrowableArray<Constant> _constants; // Constant table of this node. 377 int _table_base_offset; // Offset of the table base that gets added to the constant offsets. 378 static const RegMask& _out_RegMask; // We need the out_RegMask statically in MachConstantNode::in_RegMask(). 379 380 protected: 381 void set_table_base_offset(int x) { _table_base_offset = x; } 382 // MachConstantBaseNode::emit is const but we need to modify the object. 383 void set_table_base_offset(int x) const { ((MachConstantBaseNode*) this)->set_table_base_offset(x); } 384 385 void emit_constant_table(CodeBuffer& cb); 386 void emit_constant_table(CodeBuffer& cb) const { ((MachConstantBaseNode*) this)->emit_constant_table(cb); } 387 388 // Returns the offset of the last entry (the top) of the constant table. 389 int top_constant_offset() const { assert(_constants.top().offset() != -1, "constant not yet bound"); return _constants.top().offset(); } 390 391 public: 392 MachConstantBaseNode() : 393 MachIdealNode(), 394 _table_base_offset(-1) // We can use -1 here since the constant table is always bigger than 2 bytes (-(size / 2), see MachConstantBaseNode::emit). 395 { 396 init_class_id(Class_MachConstantBase); 397 add_req(NULL); 398 } 399 virtual const class Type* bottom_type() const { return TypeRawPtr::NOTNULL; } 400 virtual uint ideal_reg() const { return Op_RegP; } 401 virtual uint oper_input_base() const { return 1; } 402 403 virtual void emit(CodeBuffer& cbuf, PhaseRegAlloc* ra_) const; 404 virtual uint size(PhaseRegAlloc* ra_) const; 405 virtual bool pinned() const { return true; } 406 407 static const RegMask& static_out_RegMask() { return _out_RegMask; } 408 virtual const RegMask& out_RegMask() const { return static_out_RegMask(); } 409 410 #ifndef PRODUCT 411 virtual const char* Name() const { return "MachConstantBaseNode"; } 412 virtual void format(PhaseRegAlloc*, outputStream* st) const; 413 #endif 414 415 int table_base_offset() const { assert(_table_base_offset != -1, "table base offset not yet set"); return _table_base_offset; } 416 417 int add_constant(Constant& con); 418 int calculate_constant_table_size(); 419 int find_constant_offset(Constant& con) const; 420 }; 421 422 //------------------------------MachConstantNode------------------------------- 423 // Machine node that holds a constant which is stored in the constant 424 // table. 425 class MachConstantNode : public MachNode { 426 private: 427 MachConstantBaseNode::Constant _constant; 428 429 public: 430 MachConstantNode() : MachNode() { 431 init_class_id(Class_MachConstant); 432 } 433 434 virtual void eval_constant() { 435 #ifdef ASSERT 436 tty->print("missing MachConstantNode eval_constant function: "); 437 dump(); 438 #endif 439 ShouldNotCallThis(); 440 } 441 442 virtual const RegMask &in_RegMask(uint idx) const { 443 if (idx == mach_constant_base_node_input()) 444 return MachConstantBaseNode::static_out_RegMask(); 445 return MachNode::in_RegMask(idx); 446 } 447 448 // Input edge of MachConstantBaseNode. 449 uint mach_constant_base_node_input() const { return req() - 1; } 450 int constant_offset(); 451 int constant_offset() const { return ((MachConstantNode*) this)->constant_offset(); } 452 453 protected: 454 void add_to_constant_table(BasicType type, jvalue value); 455 void add_to_constant_table(MachOper* oper); 456 void add_to_constant_table(jfloat f) { 457 jvalue value; value.f = f; 458 add_to_constant_table(T_FLOAT, value); 459 } 460 void add_to_constant_table(jdouble d) { 461 jvalue value; value.d = d; 462 add_to_constant_table(T_DOUBLE, value); 463 } 464 465 // Jump table 466 void allocate_jump_table_in_constant_table(); 467 void fill_jump_table_in_constant_table(CodeBuffer& cb, GrowableArray<Label*> labels) const; 468 }; 469 470 //------------------------------MachUEPNode----------------------------------- 471 // Machine Unvalidated Entry Point Node 472 class MachUEPNode : public MachIdealNode { 473 public: 474 MachUEPNode( ) {} 475 virtual void emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const; 476 virtual uint size(PhaseRegAlloc *ra_) const; 477 478 #ifndef PRODUCT 479 virtual const char *Name() const { return "Unvalidated-Entry-Point"; } 480 virtual void format( PhaseRegAlloc *, outputStream *st ) const; 481 #endif 482 }; 483 484 //------------------------------MachPrologNode-------------------------------- 485 // Machine function Prolog Node 486 class MachPrologNode : public MachIdealNode { 487 public: 488 MachPrologNode( ) {} 489 virtual void emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const; 490 virtual uint size(PhaseRegAlloc *ra_) const; 491 virtual int reloc() const; 492 493 #ifndef PRODUCT 494 virtual const char *Name() const { return "Prolog"; } 495 virtual void format( PhaseRegAlloc *, outputStream *st ) const; 496 #endif 497 }; 498 499 //------------------------------MachEpilogNode-------------------------------- 500 // Machine function Epilog Node 501 class MachEpilogNode : public MachIdealNode { 502 public: 503 MachEpilogNode(bool do_poll = false) : _do_polling(do_poll) {} 504 virtual void emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const; 505 virtual uint size(PhaseRegAlloc *ra_) const; 506 virtual int reloc() const; 507 virtual const Pipeline *pipeline() const; 508 509 private: 510 bool _do_polling; 511 512 public: 513 bool do_polling() const { return _do_polling; } 514 515 // Offset of safepoint from the beginning of the node 516 int safepoint_offset() const; 517 518 #ifndef PRODUCT 519 virtual const char *Name() const { return "Epilog"; } 520 virtual void format( PhaseRegAlloc *, outputStream *st ) const; 521 #endif 522 }; 523 524 //------------------------------MachNopNode----------------------------------- 525 // Machine function Nop Node 526 class MachNopNode : public MachIdealNode { 527 private: 528 int _count; 529 public: 530 MachNopNode( ) : _count(1) {} 531 MachNopNode( int count ) : _count(count) {} 532 virtual void emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const; 533 virtual uint size(PhaseRegAlloc *ra_) const; 534 535 virtual const class Type *bottom_type() const { return Type::CONTROL; } 536 537 virtual int ideal_Opcode() const { return Op_Con; } // bogus; see output.cpp 538 virtual const Pipeline *pipeline() const; 539 #ifndef PRODUCT 540 virtual const char *Name() const { return "Nop"; } 541 virtual void format( PhaseRegAlloc *, outputStream *st ) const; 542 virtual void dump_spec(outputStream *st) const { } // No per-operand info 543 #endif 544 }; 545 546 //------------------------------MachSpillCopyNode------------------------------ 547 // Machine SpillCopy Node. Copies 1 or 2 words from any location to any 548 // location (stack or register). 549 class MachSpillCopyNode : public MachIdealNode { 550 const RegMask *_in; // RegMask for input 551 const RegMask *_out; // RegMask for output 552 const Type *_type; 553 public: 554 MachSpillCopyNode( Node *n, const RegMask &in, const RegMask &out ) : 555 MachIdealNode(), _in(&in), _out(&out), _type(n->bottom_type()) { 556 init_class_id(Class_MachSpillCopy); 557 init_flags(Flag_is_Copy); 558 add_req(NULL); 559 add_req(n); 560 } 561 virtual uint size_of() const { return sizeof(*this); } 562 void set_out_RegMask(const RegMask &out) { _out = &out; } 563 void set_in_RegMask(const RegMask &in) { _in = ∈ } 564 virtual const RegMask &out_RegMask() const { return *_out; } 565 virtual const RegMask &in_RegMask(uint) const { return *_in; } 566 virtual const class Type *bottom_type() const { return _type; } 567 virtual uint ideal_reg() const { return Matcher::base2reg[_type->base()]; } 568 virtual uint oper_input_base() const { return 1; } 569 uint implementation( CodeBuffer *cbuf, PhaseRegAlloc *ra_, bool do_size, outputStream* st ) const; 570 571 virtual void emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const; 572 virtual uint size(PhaseRegAlloc *ra_) const; 573 574 #ifndef PRODUCT 575 virtual const char *Name() const { return "MachSpillCopy"; } 576 virtual void format( PhaseRegAlloc *, outputStream *st ) const; 577 #endif 578 }; 579 580 //------------------------------MachNullChkNode-------------------------------- 581 // Machine-dependent null-pointer-check Node. Points a real MachNode that is 582 // also some kind of memory op. Turns the indicated MachNode into a 583 // conditional branch with good latency on the ptr-not-null path and awful 584 // latency on the pointer-is-null path. 585 586 class MachNullCheckNode : public MachIdealNode { 587 public: 588 const uint _vidx; // Index of memop being tested 589 MachNullCheckNode( Node *ctrl, Node *memop, uint vidx ) : MachIdealNode(), _vidx(vidx) { 590 init_class_id(Class_MachNullCheck); 591 init_flags(Flag_is_Branch | Flag_is_pc_relative); 592 add_req(ctrl); 593 add_req(memop); 594 } 595 596 virtual void emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const; 597 virtual bool pinned() const { return true; }; 598 virtual void negate() { } 599 virtual const class Type *bottom_type() const { return TypeTuple::IFBOTH; } 600 virtual uint ideal_reg() const { return NotAMachineReg; } 601 virtual const RegMask &in_RegMask(uint) const; 602 virtual const RegMask &out_RegMask() const { return RegMask::Empty; } 603 #ifndef PRODUCT 604 virtual const char *Name() const { return "NullCheck"; } 605 virtual void format( PhaseRegAlloc *, outputStream *st ) const; 606 #endif 607 }; 608 609 //------------------------------MachProjNode---------------------------------- 610 // Machine-dependent Ideal projections (how is that for an oxymoron). Really 611 // just MachNodes made by the Ideal world that replicate simple projections 612 // but with machine-dependent input & output register masks. Generally 613 // produced as part of calling conventions. Normally I make MachNodes as part 614 // of the Matcher process, but the Matcher is ill suited to issues involving 615 // frame handling, so frame handling is all done in the Ideal world with 616 // occasional callbacks to the machine model for important info. 617 class MachProjNode : public ProjNode { 618 public: 619 MachProjNode( Node *multi, uint con, const RegMask &out, uint ideal_reg ) : ProjNode(multi,con), _rout(out), _ideal_reg(ideal_reg) {} 620 RegMask _rout; 621 const uint _ideal_reg; 622 enum projType { 623 unmatched_proj = 0, // Projs for Control, I/O, memory not matched 624 fat_proj = 999 // Projs killing many regs, defined by _rout 625 }; 626 virtual int Opcode() const; 627 virtual const Type *bottom_type() const; 628 virtual const TypePtr *adr_type() const; 629 virtual const RegMask &in_RegMask(uint) const { return RegMask::Empty; } 630 virtual const RegMask &out_RegMask() const { return _rout; } 631 virtual uint ideal_reg() const { return _ideal_reg; } 632 // Need size_of() for virtual ProjNode::clone() 633 virtual uint size_of() const { return sizeof(MachProjNode); } 634 #ifndef PRODUCT 635 virtual void dump_spec(outputStream *st) const; 636 #endif 637 }; 638 639 //------------------------------MachIfNode------------------------------------- 640 // Machine-specific versions of IfNodes 641 class MachIfNode : public MachNode { 642 virtual uint size_of() const { return sizeof(*this); } // Size is bigger 643 public: 644 float _prob; // Probability branch goes either way 645 float _fcnt; // Frequency counter 646 MachIfNode() : MachNode() { 647 init_class_id(Class_MachIf); 648 } 649 #ifndef PRODUCT 650 virtual void dump_spec(outputStream *st) const; 651 #endif 652 }; 653 654 //------------------------------MachFastLockNode------------------------------------- 655 // Machine-specific versions of FastLockNodes 656 class MachFastLockNode : public MachNode { 657 virtual uint size_of() const { return sizeof(*this); } // Size is bigger 658 public: 659 BiasedLockingCounters* _counters; 660 661 MachFastLockNode() : MachNode() {} 662 }; 663 664 //------------------------------MachReturnNode-------------------------------- 665 // Machine-specific versions of subroutine returns 666 class MachReturnNode : public MachNode { 667 virtual uint size_of() const; // Size is bigger 668 public: 669 RegMask *_in_rms; // Input register masks, set during allocation 670 ReallocMark _nesting; // assertion check for reallocations 671 const TypePtr* _adr_type; // memory effects of call or return 672 MachReturnNode() : MachNode() { 673 init_class_id(Class_MachReturn); 674 _adr_type = TypePtr::BOTTOM; // the default: all of memory 675 } 676 677 void set_adr_type(const TypePtr* atp) { _adr_type = atp; } 678 679 virtual const RegMask &in_RegMask(uint) const; 680 virtual bool pinned() const { return true; }; 681 virtual const TypePtr *adr_type() const; 682 }; 683 684 //------------------------------MachSafePointNode----------------------------- 685 // Machine-specific versions of safepoints 686 class MachSafePointNode : public MachReturnNode { 687 public: 688 OopMap* _oop_map; // Array of OopMap info (8-bit char) for GC 689 JVMState* _jvms; // Pointer to list of JVM State Objects 690 uint _jvmadj; // Extra delta to jvms indexes (mach. args) 691 OopMap* oop_map() const { return _oop_map; } 692 void set_oop_map(OopMap* om) { _oop_map = om; } 693 694 MachSafePointNode() : MachReturnNode(), _oop_map(NULL), _jvms(NULL), _jvmadj(0) { 695 init_class_id(Class_MachSafePoint); 696 init_flags(Flag_is_safepoint_node); 697 } 698 699 virtual JVMState* jvms() const { return _jvms; } 700 void set_jvms(JVMState* s) { 701 _jvms = s; 702 } 703 bool is_safepoint_node() const { return (flags() & Flag_is_safepoint_node) != 0; } 704 virtual const Type *bottom_type() const; 705 706 virtual const RegMask &in_RegMask(uint) const; 707 708 // Functionality from old debug nodes 709 Node *returnadr() const { return in(TypeFunc::ReturnAdr); } 710 Node *frameptr () const { return in(TypeFunc::FramePtr); } 711 712 Node *local(const JVMState* jvms, uint idx) const { 713 assert(verify_jvms(jvms), "jvms must match"); 714 return in(_jvmadj + jvms->locoff() + idx); 715 } 716 Node *stack(const JVMState* jvms, uint idx) const { 717 assert(verify_jvms(jvms), "jvms must match"); 718 return in(_jvmadj + jvms->stkoff() + idx); 719 } 720 Node *monitor_obj(const JVMState* jvms, uint idx) const { 721 assert(verify_jvms(jvms), "jvms must match"); 722 return in(_jvmadj + jvms->monitor_obj_offset(idx)); 723 } 724 Node *monitor_box(const JVMState* jvms, uint idx) const { 725 assert(verify_jvms(jvms), "jvms must match"); 726 return in(_jvmadj + jvms->monitor_box_offset(idx)); 727 } 728 void set_local(const JVMState* jvms, uint idx, Node *c) { 729 assert(verify_jvms(jvms), "jvms must match"); 730 set_req(_jvmadj + jvms->locoff() + idx, c); 731 } 732 void set_stack(const JVMState* jvms, uint idx, Node *c) { 733 assert(verify_jvms(jvms), "jvms must match"); 734 set_req(_jvmadj + jvms->stkoff() + idx, c); 735 } 736 void set_monitor(const JVMState* jvms, uint idx, Node *c) { 737 assert(verify_jvms(jvms), "jvms must match"); 738 set_req(_jvmadj + jvms->monoff() + idx, c); 739 } 740 }; 741 742 //------------------------------MachCallNode---------------------------------- 743 // Machine-specific versions of subroutine calls 744 class MachCallNode : public MachSafePointNode { 745 protected: 746 virtual uint hash() const { return NO_HASH; } // CFG nodes do not hash 747 virtual uint cmp( const Node &n ) const; 748 virtual uint size_of() const = 0; // Size is bigger 749 public: 750 const TypeFunc *_tf; // Function type 751 address _entry_point; // Address of the method being called 752 float _cnt; // Estimate of number of times called 753 uint _argsize; // Size of argument block on stack 754 755 const TypeFunc* tf() const { return _tf; } 756 const address entry_point() const { return _entry_point; } 757 const float cnt() const { return _cnt; } 758 uint argsize() const { return _argsize; } 759 760 void set_tf(const TypeFunc* tf) { _tf = tf; } 761 void set_entry_point(address p) { _entry_point = p; } 762 void set_cnt(float c) { _cnt = c; } 763 void set_argsize(int s) { _argsize = s; } 764 765 MachCallNode() : MachSafePointNode() { 766 init_class_id(Class_MachCall); 767 init_flags(Flag_is_Call); 768 } 769 770 virtual const Type *bottom_type() const; 771 virtual bool pinned() const { return false; } 772 virtual const Type *Value( PhaseTransform *phase ) const; 773 virtual const RegMask &in_RegMask(uint) const; 774 virtual int ret_addr_offset() { return 0; } 775 776 bool returns_long() const { return tf()->return_type() == T_LONG; } 777 bool return_value_is_used() const; 778 #ifndef PRODUCT 779 virtual void dump_spec(outputStream *st) const; 780 #endif 781 }; 782 783 //------------------------------MachCallJavaNode------------------------------ 784 // "Base" class for machine-specific versions of subroutine calls 785 class MachCallJavaNode : public MachCallNode { 786 protected: 787 virtual uint cmp( const Node &n ) const; 788 virtual uint size_of() const; // Size is bigger 789 public: 790 ciMethod* _method; // Method being direct called 791 int _bci; // Byte Code index of call byte code 792 bool _optimized_virtual; // Tells if node is a static call or an optimized virtual 793 bool _method_handle_invoke; // Tells if the call has to preserve SP 794 MachCallJavaNode() : MachCallNode() { 795 init_class_id(Class_MachCallJava); 796 } 797 798 virtual const RegMask &in_RegMask(uint) const; 799 800 #ifndef PRODUCT 801 virtual void dump_spec(outputStream *st) const; 802 #endif 803 }; 804 805 //------------------------------MachCallStaticJavaNode------------------------ 806 // Machine-specific versions of monomorphic subroutine calls 807 class MachCallStaticJavaNode : public MachCallJavaNode { 808 virtual uint cmp( const Node &n ) const; 809 virtual uint size_of() const; // Size is bigger 810 public: 811 const char *_name; // Runtime wrapper name 812 MachCallStaticJavaNode() : MachCallJavaNode() { 813 init_class_id(Class_MachCallStaticJava); 814 } 815 816 // If this is an uncommon trap, return the request code, else zero. 817 int uncommon_trap_request() const; 818 819 virtual int ret_addr_offset(); 820 #ifndef PRODUCT 821 virtual void dump_spec(outputStream *st) const; 822 void dump_trap_args(outputStream *st) const; 823 #endif 824 }; 825 826 //------------------------------MachCallDynamicJavaNode------------------------ 827 // Machine-specific versions of possibly megamorphic subroutine calls 828 class MachCallDynamicJavaNode : public MachCallJavaNode { 829 public: 830 int _vtable_index; 831 MachCallDynamicJavaNode() : MachCallJavaNode() { 832 init_class_id(Class_MachCallDynamicJava); 833 DEBUG_ONLY(_vtable_index = -99); // throw an assert if uninitialized 834 } 835 virtual int ret_addr_offset(); 836 #ifndef PRODUCT 837 virtual void dump_spec(outputStream *st) const; 838 #endif 839 }; 840 841 //------------------------------MachCallRuntimeNode---------------------------- 842 // Machine-specific versions of subroutine calls 843 class MachCallRuntimeNode : public MachCallNode { 844 virtual uint cmp( const Node &n ) const; 845 virtual uint size_of() const; // Size is bigger 846 public: 847 const char *_name; // Printable name, if _method is NULL 848 MachCallRuntimeNode() : MachCallNode() { 849 init_class_id(Class_MachCallRuntime); 850 } 851 virtual int ret_addr_offset(); 852 #ifndef PRODUCT 853 virtual void dump_spec(outputStream *st) const; 854 #endif 855 }; 856 857 class MachCallLeafNode: public MachCallRuntimeNode { 858 public: 859 MachCallLeafNode() : MachCallRuntimeNode() { 860 init_class_id(Class_MachCallLeaf); 861 } 862 }; 863 864 //------------------------------MachHaltNode----------------------------------- 865 // Machine-specific versions of halt nodes 866 class MachHaltNode : public MachReturnNode { 867 public: 868 virtual JVMState* jvms() const; 869 }; 870 871 872 //------------------------------MachTempNode----------------------------------- 873 // Node used by the adlc to construct inputs to represent temporary registers 874 class MachTempNode : public MachNode { 875 private: 876 MachOper *_opnd_array[1]; 877 878 public: 879 virtual const RegMask &out_RegMask() const { return *_opnds[0]->in_RegMask(0); } 880 virtual uint rule() const { return 9999999; } 881 virtual void emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const {} 882 883 MachTempNode(MachOper* oper) { 884 init_class_id(Class_MachTemp); 885 _num_opnds = 1; 886 _opnds = _opnd_array; 887 add_req(NULL); 888 _opnds[0] = oper; 889 } 890 virtual uint size_of() const { return sizeof(MachTempNode); } 891 892 #ifndef PRODUCT 893 virtual void format(PhaseRegAlloc *, outputStream *st ) const {} 894 virtual const char *Name() const { return "MachTemp";} 895 #endif 896 }; 897 898 899 900 //------------------------------labelOper-------------------------------------- 901 // Machine-independent version of label operand 902 class labelOper : public MachOper { 903 private: 904 virtual uint num_edges() const { return 0; } 905 public: 906 // Supported for fixed size branches 907 Label* _label; // Label for branch(es) 908 909 uint _block_num; 910 911 labelOper() : _block_num(0), _label(0) {} 912 913 labelOper(Label* label, uint block_num) : _label(label), _block_num(block_num) {} 914 915 labelOper(labelOper* l) : _label(l->_label) , _block_num(l->_block_num) {} 916 917 virtual MachOper *clone(Compile* C) const; 918 919 virtual Label *label() const { return _label; } 920 921 virtual uint opcode() const; 922 923 virtual uint hash() const; 924 virtual uint cmp( const MachOper &oper ) const; 925 #ifndef PRODUCT 926 virtual const char *Name() const { return "Label";} 927 928 virtual void int_format(PhaseRegAlloc *ra, const MachNode *node, outputStream *st) const; 929 virtual void ext_format(PhaseRegAlloc *ra, const MachNode *node, int idx, outputStream *st) const { int_format( ra, node, st ); } 930 #endif 931 }; 932 933 934 //------------------------------methodOper-------------------------------------- 935 // Machine-independent version of method operand 936 class methodOper : public MachOper { 937 private: 938 virtual uint num_edges() const { return 0; } 939 public: 940 intptr_t _method; // Address of method 941 methodOper() : _method(0) {} 942 methodOper(intptr_t method) : _method(method) {} 943 944 virtual MachOper *clone(Compile* C) const; 945 946 virtual intptr_t method() const { return _method; } 947 948 virtual uint opcode() const; 949 950 virtual uint hash() const; 951 virtual uint cmp( const MachOper &oper ) const; 952 #ifndef PRODUCT 953 virtual const char *Name() const { return "Method";} 954 955 virtual void int_format(PhaseRegAlloc *ra, const MachNode *node, outputStream *st) const; 956 virtual void ext_format(PhaseRegAlloc *ra, const MachNode *node, int idx, outputStream *st) const { int_format( ra, node, st ); } 957 #endif 958 };