/* * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. *
*/
class BufferBlob; class CodeBuffer; class JVMState; class MachCallDynamicJavaNode; class MachCallJavaNode; class MachCallLeafNode; class MachCallNode; class MachCallRuntimeNode; class MachCallStaticJavaNode; class MachEpilogNode; class MachIfNode; class MachNullCheckNode; class MachOper; class MachProjNode; class MachPrologNode; class MachReturnNode; class MachSafePointNode; class MachSpillCopyNode; class Matcher; class PhaseRegAlloc; class RegMask; class RTMLockingCounters; class State;
//---------------------------MachOper------------------------------------------ class MachOper : public ResourceObj { public: // Allocate right next to the MachNodes in the same arena void *operatornew(size_t x) throw() {
Compile* C = Compile::current(); return C->node_arena()->AmallocWords(x);
}
// Opcode virtual uint opcode() const = 0;
// Number of input edges. // Generally at least 1 virtual uint num_edges() const { return 1; } // Array of Register masks virtualconst RegMask *in_RegMask(int index) const;
// Methods to output the encoding of the operand
// Negate conditional branches. Error for non-branch Nodes virtualvoid negate();
// Return the value requested // result register lookup, corresponding to int_format virtualint reg(PhaseRegAlloc *ra_, const Node *node) const; // input register lookup, corresponding to ext_format virtualint reg(PhaseRegAlloc *ra_, const Node *node, int idx) const;
virtual intptr_t constant() const; virtual relocInfo::relocType constant_reloc() const; virtual jdouble constantD() const; virtual jfloat constantF() const; virtual jlong constantL() const; virtual TypeOopPtr *oop() const; virtualint ccode() const; // A zero, default, indicates this value is not needed. // May need to lookup the base register, as done in int_ and ext_format virtualint base (PhaseRegAlloc *ra_, const Node *node, int idx) const; virtualint index(PhaseRegAlloc *ra_, const Node *node, int idx) const; virtualint scale() const; // Parameters needed to support MEMORY_INTERFACE access to stackSlot virtualint disp (PhaseRegAlloc *ra_, const Node *node, int idx) const; // Check for PC-Relative displacement virtual relocInfo::relocType disp_reloc() const; virtualint constant_disp() const; // usu. 0, may return Type::OffsetBot virtualint base_position() const; // base edge position, or -1 virtualint index_position() const; // index edge position, or -1
// Access the TypeKlassPtr of operands with a base==RegI and disp==RegP // Only returns non-null value for x86_32.ad's indOffset32X virtualconst TypePtr *disp_as_type() const { return NULL; }
// Return the label virtual Label *label() const;
// Return the method's address virtual intptr_t method() const;
// Hash and compare over operands are currently identical virtual uint hash() const; virtualbool cmp( const MachOper &oper ) const;
// Virtual clone, since I do not know how big the MachOper is. virtual MachOper *clone() const = 0;
// Return ideal Type from simple operands. Fail for complex operands. virtualconst Type *type() const;
// Set an integer offset if we have one, or error otherwise virtualvoid set_con( jint c0 ) { ShouldNotReachHere(); }
#ifndef PRODUCT // Return name of operand virtualconstchar *Name() const { return"???";}
// Methods to output the text version of the operand virtualvoid int_format(PhaseRegAlloc *,const MachNode *node, outputStream *st) const = 0; virtualvoid ext_format(PhaseRegAlloc *,const MachNode *node,int idx, outputStream *st) const=0;
virtualvoid dump_spec(outputStream *st) const; // Print per-operand info
// Check whether o is a valid oper. staticbool notAnOper(const MachOper *o) { if (o == NULL) returntrue; if (((intptr_t)o & 1) != 0) returntrue; if (*(address*)o == badAddress) returntrue; // kill by Node::destruct returnfalse;
} #endif// !PRODUCT
};
//------------------------------MachNode--------------------------------------- // Base type for all machine specific nodes. All node classes generated by the // ADLC inherit from this class. class MachNode : public Node { public:
MachNode() : Node((uint)0), _barrier(0), _num_opnds(0), _opnds(NULL) {
init_class_id(Class_Mach);
} // Required boilerplate virtual uint size_of() const { returnsizeof(MachNode); } virtualint Opcode() const; // Always equal to MachNode virtual uint rule() const = 0; // Machine-specific opcode // Number of inputs which come before the first operand. // Generally at least 1, to skip the Control input virtual uint oper_input_base() const { return 1; } // Position of constant base node in node's inputs. -1 if // no constant base node input. virtual uint mach_constant_base_node_input() const { return (uint)-1; }
// Copy inputs and operands to new node of instruction. // Called from cisc_version() and short_branch_version(). // !!!! The method's body is defined in ad_<arch>.cpp file. void fill_new_machnode(MachNode *n) const;
// Return an equivalent instruction using memory for cisc_operand position virtual MachNode *cisc_version(int offset); // Modify this instruction's register mask to use stack version for cisc_operand virtualvoid use_cisc_RegMask();
// Support for short branches bool may_be_short_branch() const { return (flags() & Flag_may_be_short_branch) != 0; }
// Avoid back to back some instructions on some CPUs. enum AvoidBackToBackFlag { AVOID_NONE = 0,
AVOID_BEFORE = Flag_avoid_back_to_back_before,
AVOID_AFTER = Flag_avoid_back_to_back_after,
AVOID_BEFORE_AND_AFTER = AVOID_BEFORE | AVOID_AFTER };
// instruction implemented with a call bool has_call() const { return (flags() & Flag_has_call) != 0; }
// First index in _in[] corresponding to operand, or -1 if there is none int operand_index(uint operand) const; int operand_index(const MachOper *oper) const; int operand_index(Node* m) const;
// Register class input is expected in virtualconst RegMask &in_RegMask(uint) const;
// cisc-spillable instructions redefine for use by in_RegMask virtualconst RegMask *cisc_RegMask() const { return NULL; }
// If this instruction is a 2-address instruction, then return the // index of the input which must match the output. Not necessary // for instructions which bind the input and output register to the // same singleton register (e.g., Intel IDIV which binds AX to be // both an input and an output). It is necessary when the input and // output have choices - but they must use the same choice. virtual uint two_adr( ) const { return 0; }
// The GC might require some barrier metadata for machine code emission.
uint8_t _barrier;
// Array of complex operand pointers. Each corresponds to zero or // more leafs. Must be set by MachNode constructor to point to an // internal array of MachOpers. The MachOper array is sized by // specific MachNodes described in the ADL.
uint16_t _num_opnds;
MachOper **_opnds;
uint16_t num_opnds() const { return _num_opnds; }
// Emit bytes into cbuf virtualvoid emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const; // Expand node after register allocation. // Node is replaced by several nodes in the postalloc expand phase. // Corresponding methods are generated for nodes if they specify // postalloc_expand. See block.cpp for more documentation. virtualbool requires_postalloc_expand() const { returnfalse; } virtualvoid postalloc_expand(GrowableArray <Node *> *nodes, PhaseRegAlloc *ra_); // Size of instruction in bytes virtual uint size(PhaseRegAlloc *ra_) const; // Helper function that computes size by emitting code virtual uint emit_size(PhaseRegAlloc *ra_) const;
// Return the alignment required (in units of relocInfo::addr_unit()) // for this instruction (must be a power of 2) int pd_alignment_required() const; virtualint alignment_required() const { return pd_alignment_required(); }
// Return the padding (in bytes) to be emitted before this // instruction to properly align it. virtualint compute_padding(int current_offset) const;
// Return number of relocatable values contained in this instruction virtualint reloc() const { return 0; }
// Return number of words used for double constants in this instruction virtualint ins_num_consts() const { return 0; }
// Hash and compare over operands. Used to do GVN on machine Nodes. virtual uint hash() const; virtualbool cmp( const Node &n ) const;
// Expand method for MachNode, replaces nodes representing pseudo // instructions with a set of nodes which represent real machine // instructions and compute the same value. virtual MachNode *Expand( State *, Node_List &proj_list, Node* mem ) { returnthis; }
// Bottom_type call; value comes from operand0 virtualconstclass Type *bottom_type() const { return _opnds[0]->type(); } virtual uint ideal_reg() const { const Type *t = _opnds[0]->type(); if (t == TypeInt::CC) { return Op_RegFlags;
} else { return t->ideal_reg();
}
}
// If this is a memory op, return the base pointer and fixed offset. // If there are no such, return NULL. If there are multiple addresses // or the address is indeterminate (rare cases) then return (Node*)-1, // which serves as node bottom. // If the offset is not statically determined, set it to Type::OffsetBot. // This method is free to ignore stack slots if that helps. #define TYPE_PTR_SENTINAL ((const TypePtr*)-1) // Passing TYPE_PTR_SENTINAL as adr_type asks for computation of the adr_type if possible const Node* get_base_and_disp(intptr_t &offset, const TypePtr* &adr_type) const;
// Helper for get_base_and_disp: find the base and index input nodes. // Returns the MachOper as determined by memory_operand(), for use, if // needed by the caller. If (MachOper *)-1 is returned, base and index // are set to NodeSentinel. If (MachOper *) NULL is returned, base and // index are set to NULL. const MachOper* memory_inputs(Node* &base, Node* &index) const;
// Helper for memory_inputs: Which operand carries the necessary info? // By default, returns NULL, which means there is no such operand. // If it returns (MachOper*)-1, this means there are multiple memories. virtualconst MachOper* memory_operand() const { return NULL; }
// Call "get_base_and_disp" to decide which category of memory is used here. virtualconstclass TypePtr *adr_type() const;
// Apply peephole rule(s) to this instruction virtualint peephole(Block *block, int block_index, PhaseCFG* cfg_, PhaseRegAlloc *ra_);
// Adds the label for the case virtualvoid add_case_label( int switch_val, Label* blockLabel);
// Set the absolute address for methods virtualvoid method_set( intptr_t addr );
// Should we clone rather than spill this instruction? bool rematerialize() const;
// Get the pipeline info staticconst Pipeline *pipeline_class(); virtualconst Pipeline *pipeline() const;
// Returns true if this node is a check that can be implemented with a trap. virtualbool is_TrapBasedCheckNode() const { returnfalse; } void set_removed() { add_flag(Flag_is_removed_by_peephole); } bool get_removed() { return (flags() & Flag_is_removed_by_peephole) != 0; }
#ifndef PRODUCT virtualconstchar *Name() const = 0; // Machine-specific name virtualvoid dump_spec(outputStream *st) const; // Print per-node info void dump_format(PhaseRegAlloc *ra, outputStream *st) const; // access to virtual #endif
};
//------------------------------MachIdealNode---------------------------- // Machine specific versions of nodes that must be defined by user. // These are not converted by matcher from ideal nodes to machine nodes // but are inserted into the code by the compiler. class MachIdealNode : public MachNode { public:
MachIdealNode( ) {}
// Define the following defaults for non-matched machine nodes virtual uint oper_input_base() const { return 0; } virtual uint rule() const { return 9999999; } virtualconstclass Type *bottom_type() const { return _opnds == NULL ? Type::CONTROL : MachNode::bottom_type(); }
};
//------------------------------MachTypeNode---------------------------- // Machine Nodes that need to retain a known Type. class MachTypeNode : public MachNode { virtual uint size_of() const { returnsizeof(*this); } // Size is bigger public:
MachTypeNode( ) {} const Type *_bottom_type;
//------------------------------MachConstantBaseNode-------------------------- // Machine node that represents the base address of the constant table. class MachConstantBaseNode : public MachIdealNode { public: staticconst RegMask& _out_RegMask; // We need the out_RegMask statically in MachConstantNode::in_RegMask().
//------------------------------MachConstantNode------------------------------- // Machine node that holds a constant which is stored in the constant table. class MachConstantNode : public MachTypeNode { protected:
ConstantTable::Constant _constant; // This node's constant.
int constant_offset(); int constant_offset() const { return ((MachConstantNode*) this)->constant_offset(); } // Unchecked version to avoid assertions in debug output. int constant_offset_unchecked() const;
};
//------------------------------MachUEPNode----------------------------------- // Machine Unvalidated Entry Point Node class MachUEPNode : public MachIdealNode { public:
MachUEPNode( ) {} virtualvoid emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const; virtual uint size(PhaseRegAlloc *ra_) const;
//------------------------------MachSpillCopyNode------------------------------ // Machine SpillCopy Node. Copies 1 or 2 words from any location to any // location (stack or register). class MachSpillCopyNode : public MachIdealNode { public: enum SpillType {
TwoAddress, // Inserted when coalescing of a two-address-instruction node and its input fails
PhiInput, // Inserted when coalescing of a phi node and its input fails
DebugUse, // Inserted as debug info spills to safepoints in non-frequent blocks
LoopPhiInput, // Pre-split compares of loop-phis
Definition, // An lrg marked as spilled will be spilled to memory right after its definition, // if in high pressure region or the lrg is bound
RegToReg, // A register to register move
RegToMem, // A register to memory move
MemToReg, // A memory to register move
PhiLocationDifferToInputLocation, // When coalescing phi nodes in PhaseChaitin::Split(), a move spill is inserted if // the phi and its input resides at different locations (i.e. reg or mem)
BasePointerToMem, // Spill base pointer to memory at safepoint
InputToRematerialization, // When rematerializing a node we stretch the inputs live ranges, and they might be // stretched beyond a new definition point, therefore we split out new copies instead
CallUse, // Spill use at a call
Bound // An lrg marked as spill that is bound and needs to be spilled at a use
}; private: const RegMask *_in; // RegMask for input const RegMask *_out; // RegMask for output const Type *_type; const SpillType _spill_type; public:
MachSpillCopyNode(SpillType spill_type, Node *n, const RegMask &in, const RegMask &out ) :
MachIdealNode(), _in(&in), _out(&out), _type(n->bottom_type()), _spill_type(spill_type) {
init_class_id(Class_MachSpillCopy);
init_flags(Flag_is_Copy);
add_req(NULL);
add_req(n);
} virtual uint size_of() const { returnsizeof(*this); } void set_out_RegMask(const RegMask &out) { _out = &out; } void set_in_RegMask(const RegMask &in) { _in = ∈ } virtualconst RegMask &out_RegMask() const { return *_out; } virtualconst RegMask &in_RegMask(uint) const { return *_in; } virtualconstclass Type *bottom_type() const { return _type; } virtual uint ideal_reg() const { return _type->ideal_reg(); } virtual uint oper_input_base() const { return 1; }
uint implementation( CodeBuffer *cbuf, PhaseRegAlloc *ra_, bool do_size, outputStream* st ) const;
#ifndef PRODUCT staticconstchar *spill_type(SpillType st) { switch (st) { case TwoAddress: return"TwoAddressSpillCopy"; case PhiInput: return"PhiInputSpillCopy"; case DebugUse: return"DebugUseSpillCopy"; case LoopPhiInput: return"LoopPhiInputSpillCopy"; case Definition: return"DefinitionSpillCopy"; case RegToReg: return"RegToRegSpillCopy"; case RegToMem: return"RegToMemSpillCopy"; case MemToReg: return"MemToRegSpillCopy"; case PhiLocationDifferToInputLocation: return"PhiLocationDifferToInputLocationSpillCopy"; case BasePointerToMem: return"BasePointerToMemSpillCopy"; case InputToRematerialization: return"InputToRematerializationSpillCopy"; case CallUse: return"CallUseSpillCopy"; case Bound: return"BoundSpillCopy"; default:
assert(false, "Must have valid spill type"); return"MachSpillCopy";
}
}
// MachMergeNode is similar to a PhiNode in a sense it merges multiple values, // however it doesn't have a control input and is more like a MergeMem. // It is inserted after the register allocation is done to ensure that nodes use single // definition of a multidef lrg in a block. class MachMergeNode : public MachIdealNode { public:
MachMergeNode(Node *n1) {
init_class_id(Class_MachMerge);
add_req(NULL);
add_req(n1);
} virtualconst RegMask &out_RegMask() const { return in(1)->out_RegMask(); } virtualconst RegMask &in_RegMask(uint idx) const { return in(1)->in_RegMask(idx); } virtualconstclass Type *bottom_type() const { return in(1)->bottom_type(); } virtual uint ideal_reg() const { return bottom_type()->ideal_reg(); } virtual uint oper_input_base() const { return 1; } virtualvoid emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const { } virtual uint size(PhaseRegAlloc *ra_) const { return 0; } #ifndef PRODUCT virtualconstchar *Name() const { return"MachMerge"; } #endif
};
// Support for short branches virtual MachNode *short_branch_version() { return NULL; }
virtualbool pinned() const { returntrue; };
};
//------------------------------MachNullChkNode-------------------------------- // Machine-dependent null-pointer-check Node. Points a real MachNode that is // also some kind of memory op. Turns the indicated MachNode into a // conditional branch with good latency on the ptr-not-null path and awful // latency on the pointer-is-null path.
class MachNullCheckNode : public MachBranchNode { public: const uint _vidx; // Index of memop being tested
MachNullCheckNode( Node *ctrl, Node *memop, uint vidx ) : MachBranchNode(), _vidx(vidx) {
init_class_id(Class_MachNullCheck);
add_req(ctrl);
add_req(memop);
} virtualint Opcode() const; virtual uint size_of() const { returnsizeof(*this); }
//------------------------------MachProjNode---------------------------------- // Machine-dependent Ideal projections (how is that for an oxymoron). Really // just MachNodes made by the Ideal world that replicate simple projections // but with machine-dependent input & output register masks. Generally // produced as part of calling conventions. Normally I make MachNodes as part // of the Matcher process, but the Matcher is ill suited to issues involving // frame handling, so frame handling is all done in the Ideal world with // occasional callbacks to the machine model for important info. class MachProjNode : public ProjNode { public:
MachProjNode( Node *multi, uint con, const RegMask &out, uint ideal_reg ) : ProjNode(multi,con), _rout(out), _ideal_reg(ideal_reg) {
init_class_id(Class_MachProj);
}
RegMask _rout; const uint _ideal_reg; enum projType {
unmatched_proj = 0, // Projs for Control, I/O, memory not matched
fat_proj = 999 // Projs killing many regs, defined by _rout
}; virtualint Opcode() const; virtualconst Type *bottom_type() const; virtualconst TypePtr *adr_type() const; virtualconst RegMask &in_RegMask(uint) const { return RegMask::Empty; } virtualconst RegMask &out_RegMask() const { return _rout; } virtual uint ideal_reg() const { return _ideal_reg; } // Need size_of() for virtual ProjNode::clone() virtual uint size_of() const { returnsizeof(MachProjNode); } #ifndef PRODUCT virtualvoid dump_spec(outputStream *st) const; #endif
};
//------------------------------MachIfNode------------------------------------- // Machine-specific versions of IfNodes class MachIfNode : public MachBranchNode { virtual uint size_of() const { returnsizeof(*this); } // Size is bigger public: float _prob; // Probability branch goes either way float _fcnt; // Frequency counter
MachIfNode() : MachBranchNode() {
init_class_id(Class_MachIf);
} // Negate conditional branches. virtualvoid negate() = 0; #ifndef PRODUCT virtualvoid dump_spec(outputStream *st) const; #endif
};
//------------------------------MachJumpNode----------------------------------- // Machine-specific versions of JumpNodes class MachJumpNode : public MachConstantNode { public: float* _probs;
MachJumpNode() : MachConstantNode() {
init_class_id(Class_MachJump);
}
};
//------------------------------MachGotoNode----------------------------------- // Machine-specific versions of GotoNodes class MachGotoNode : public MachBranchNode { public:
MachGotoNode() : MachBranchNode() {
init_class_id(Class_MachGoto);
}
};
//------------------------------MachFastLockNode------------------------------------- // Machine-specific versions of FastLockNodes class MachFastLockNode : public MachNode { virtual uint size_of() const { returnsizeof(*this); } // Size is bigger public:
RTMLockingCounters* _rtm_counters; // RTM lock counters for inflated locks
RTMLockingCounters* _stack_rtm_counters; // RTM lock counters for stack locks
MachFastLockNode() : MachNode() {}
};
//------------------------------MachReturnNode-------------------------------- // Machine-specific versions of subroutine returns class MachReturnNode : public MachNode { virtual uint size_of() const; // Size is bigger public:
RegMask *_in_rms; // Input register masks, set during allocation
ReallocMark _nesting; // assertion check for reallocations const TypePtr* _adr_type; // memory effects of call or return
MachReturnNode() : MachNode() {
init_class_id(Class_MachReturn);
_adr_type = TypePtr::BOTTOM; // the default: all of memory
}
//------------------------------MachSafePointNode----------------------------- // Machine-specific versions of safepoints class MachSafePointNode : public MachReturnNode { public:
OopMap* _oop_map; // Array of OopMap info (8-bit char) for GC
JVMState* _jvms; // Pointer to list of JVM State Objects
uint _jvmadj; // Extra delta to jvms indexes (mach. args) bool _has_ea_local_in_scope; // NoEscape or ArgEscape objects in JVM States
OopMap* oop_map() const { return _oop_map; } void set_oop_map(OopMap* om) { _oop_map = om; }
//------------------------------MachCallNode---------------------------------- // Machine-specific versions of subroutine calls class MachCallNode : public MachSafePointNode { protected: virtual uint hash() const { return NO_HASH; } // CFG nodes do not hash virtualbool cmp( const Node &n ) const; virtual uint size_of() const = 0; // Size is bigger public: const TypeFunc *_tf; // Function type
address _entry_point; // Address of the method being called float _cnt; // Estimate of number of times called bool _guaranteed_safepoint; // Do we need to observe safepoint?
//------------------------------MachCallJavaNode------------------------------ // "Base" class for machine-specific versions of subroutine calls class MachCallJavaNode : public MachCallNode { protected: virtualbool cmp( const Node &n ) const; virtual uint size_of() const; // Size is bigger public:
ciMethod* _method; // Method being direct called bool _override_symbolic_info; // Override symbolic call site info from bytecode bool _optimized_virtual; // Tells if node is a static call or an optimized virtual bool _method_handle_invoke; // Tells if the call has to preserve SP bool _arg_escape; // ArgEscape in parameter list
MachCallJavaNode() : MachCallNode(), _override_symbolic_info(false) {
init_class_id(Class_MachCallJava);
}
virtualconst RegMask &in_RegMask(uint) const;
int resolved_method_index(CodeBuffer &cbuf) const { if (_override_symbolic_info) { // Attach corresponding Method* to the call site, so VM can use it during resolution // instead of querying symbolic info from bytecode.
assert(_method != NULL, "method should be set");
assert(_method->constant_encoding()->is_method(), "should point to a Method"); return cbuf.oop_recorder()->find_index(_method->constant_encoding());
} return 0; // Use symbolic info from bytecode (resolved_method == NULL).
}
//------------------------------MachTempNode----------------------------------- // Node used by the adlc to construct inputs to represent temporary registers class MachTempNode : public MachNode { private:
MachOper *_opnd_array[1];
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.