Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/opto/cfgnode.hpp
32285 views
/*1* Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_VM_OPTO_CFGNODE_HPP25#define SHARE_VM_OPTO_CFGNODE_HPP2627#include "opto/multnode.hpp"28#include "opto/node.hpp"29#include "opto/opcodes.hpp"30#include "opto/type.hpp"3132// Portions of code courtesy of Clifford Click3334// Optimization - Graph Style3536class Matcher;37class Node;38class RegionNode;39class TypeNode;40class PhiNode;41class GotoNode;42class MultiNode;43class MultiBranchNode;44class IfNode;45class PCTableNode;46class JumpNode;47class CatchNode;48class NeverBranchNode;49class ProjNode;50class CProjNode;51class IfTrueNode;52class IfFalseNode;53class CatchProjNode;54class JProjNode;55class JumpProjNode;56class SCMemProjNode;57class PhaseIdealLoop;5859//------------------------------RegionNode-------------------------------------60// The class of RegionNodes, which can be mapped to basic blocks in the61// program. Their inputs point to Control sources. PhiNodes (described62// below) have an input point to a RegionNode. Merged data inputs to PhiNodes63// correspond 1-to-1 with RegionNode inputs. The zero input of a PhiNode is64// the RegionNode, and the zero input of the RegionNode is itself.65class RegionNode : public Node {66public:67// Node layout (parallels PhiNode):68enum { Region, // Generally points to self.69Control // Control arcs are [1..len)70};7172RegionNode( uint required ) : Node(required) {73init_class_id(Class_Region);74init_req(0,this);75}7677Node* is_copy() const {78const Node* r = _in[Region];79if (r == NULL)80return nonnull_req();81return NULL; // not a copy!82}83PhiNode* has_phi() const; // returns an arbitrary phi user, or NULL84PhiNode* has_unique_phi() const; // returns the unique phi user, or NULL85// Is this region node unreachable from root?86bool is_unreachable_region(PhaseGVN *phase) const;87virtual int Opcode() const;88virtual bool pinned() const { return (const Node *)in(0) == this; }89virtual bool is_CFG () const { return true; }90virtual uint hash() const { return NO_HASH; } // CFG nodes do not hash91virtual bool depends_only_on_test() const { return false; }92virtual const Type *bottom_type() const { return Type::CONTROL; }93virtual const Type *Value( PhaseTransform *phase ) const;94virtual Node *Identity( PhaseTransform *phase );95virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);96virtual const RegMask &out_RegMask() const;97bool try_clean_mem_phi(PhaseGVN *phase);98};99100//------------------------------JProjNode--------------------------------------101// jump projection for node that produces multiple control-flow paths102class JProjNode : public ProjNode {103public:104JProjNode( Node* ctrl, uint idx ) : ProjNode(ctrl,idx) {}105virtual int Opcode() const;106virtual bool is_CFG() const { return true; }107virtual uint hash() const { return NO_HASH; } // CFG nodes do not hash108virtual const Node* is_block_proj() const { return in(0); }109virtual const RegMask& out_RegMask() const;110virtual uint ideal_reg() const { return 0; }111};112113//------------------------------PhiNode----------------------------------------114// PhiNodes merge values from different Control paths. Slot 0 points to the115// controlling RegionNode. Other slots map 1-for-1 with incoming control flow116// paths to the RegionNode. For speed reasons (to avoid another pass) we117// can turn PhiNodes into copys in-place by NULL'ing out their RegionNode118// input in slot 0.119class PhiNode : public TypeNode {120const TypePtr* const _adr_type; // non-null only for Type::MEMORY nodes.121// The following fields are only used for data PhiNodes to indicate122// that the PhiNode represents the value of a known instance field.123int _inst_mem_id; // Instance memory id (node index of the memory Phi)124const int _inst_id; // Instance id of the memory slice.125const int _inst_index; // Alias index of the instance memory slice.126// Array elements references have the same alias_idx but different offset.127const int _inst_offset; // Offset of the instance memory slice.128// Size is bigger to hold the _adr_type field.129virtual uint hash() const; // Check the type130virtual uint cmp( const Node &n ) const;131virtual uint size_of() const { return sizeof(*this); }132133// Determine if CMoveNode::is_cmove_id can be used at this join point.134Node* is_cmove_id(PhaseTransform* phase, int true_path);135136public:137// Node layout (parallels RegionNode):138enum { Region, // Control input is the Phi's region.139Input // Input values are [1..len)140};141142PhiNode( Node *r, const Type *t, const TypePtr* at = NULL,143const int imid = -1,144const int iid = TypeOopPtr::InstanceTop,145const int iidx = Compile::AliasIdxTop,146const int ioffs = Type::OffsetTop )147: TypeNode(t,r->req()),148_adr_type(at),149_inst_mem_id(imid),150_inst_id(iid),151_inst_index(iidx),152_inst_offset(ioffs)153{154init_class_id(Class_Phi);155init_req(0, r);156verify_adr_type();157}158// create a new phi with in edges matching r and set (initially) to x159static PhiNode* make( Node* r, Node* x );160// extra type arguments override the new phi's bottom_type and adr_type161static PhiNode* make( Node* r, Node* x, const Type *t, const TypePtr* at = NULL );162// create a new phi with narrowed memory type163PhiNode* slice_memory(const TypePtr* adr_type) const;164PhiNode* split_out_instance(const TypePtr* at, PhaseIterGVN *igvn) const;165// like make(r, x), but does not initialize the in edges to x166static PhiNode* make_blank( Node* r, Node* x );167168// Accessors169RegionNode* region() const { Node* r = in(Region); assert(!r || r->is_Region(), ""); return (RegionNode*)r; }170171Node* is_copy() const {172// The node is a real phi if _in[0] is a Region node.173DEBUG_ONLY(const Node* r = _in[Region];)174assert(r != NULL && r->is_Region(), "Not valid control");175return NULL; // not a copy!176}177178bool is_tripcount() const;179180// Determine a unique non-trivial input, if any.181// Ignore casts if it helps. Return NULL on failure.182Node* unique_input(PhaseTransform *phase);183184// Check for a simple dead loop.185enum LoopSafety { Safe = 0, Unsafe, UnsafeLoop };186LoopSafety simple_data_loop_check(Node *in) const;187// Is it unsafe data loop? It becomes a dead loop if this phi node removed.188bool is_unsafe_data_reference(Node *in) const;189int is_diamond_phi(bool check_control_only = false) const;190virtual int Opcode() const;191virtual bool pinned() const { return in(0) != 0; }192virtual const TypePtr *adr_type() const { verify_adr_type(true); return _adr_type; }193194void set_inst_mem_id(int inst_mem_id) { _inst_mem_id = inst_mem_id; }195const int inst_mem_id() const { return _inst_mem_id; }196const int inst_id() const { return _inst_id; }197const int inst_index() const { return _inst_index; }198const int inst_offset() const { return _inst_offset; }199bool is_same_inst_field(const Type* tp, int mem_id, int id, int index, int offset) {200return type()->basic_type() == tp->basic_type() &&201inst_mem_id() == mem_id &&202inst_id() == id &&203inst_index() == index &&204inst_offset() == offset &&205type()->higher_equal(tp);206}207208virtual const Type *Value( PhaseTransform *phase ) const;209virtual Node *Identity( PhaseTransform *phase );210virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);211virtual const RegMask &out_RegMask() const;212virtual const RegMask &in_RegMask(uint) const;213#ifndef PRODUCT214virtual void dump_spec(outputStream *st) const;215#endif216#ifdef ASSERT217void verify_adr_type(VectorSet& visited, const TypePtr* at) const;218void verify_adr_type(bool recursive = false) const;219#else //ASSERT220void verify_adr_type(bool recursive = false) const {}221#endif //ASSERT222};223224//------------------------------GotoNode---------------------------------------225// GotoNodes perform direct branches.226class GotoNode : public Node {227public:228GotoNode( Node *control ) : Node(control) {}229virtual int Opcode() const;230virtual bool pinned() const { return true; }231virtual bool is_CFG() const { return true; }232virtual uint hash() const { return NO_HASH; } // CFG nodes do not hash233virtual const Node *is_block_proj() const { return this; }234virtual bool depends_only_on_test() const { return false; }235virtual const Type *bottom_type() const { return Type::CONTROL; }236virtual const Type *Value( PhaseTransform *phase ) const;237virtual Node *Identity( PhaseTransform *phase );238virtual const RegMask &out_RegMask() const;239};240241//------------------------------CProjNode--------------------------------------242// control projection for node that produces multiple control-flow paths243class CProjNode : public ProjNode {244public:245CProjNode( Node *ctrl, uint idx ) : ProjNode(ctrl,idx) {}246virtual int Opcode() const;247virtual bool is_CFG() const { return true; }248virtual uint hash() const { return NO_HASH; } // CFG nodes do not hash249virtual const Node *is_block_proj() const { return in(0); }250virtual const RegMask &out_RegMask() const;251virtual uint ideal_reg() const { return 0; }252};253254//---------------------------MultiBranchNode-----------------------------------255// This class defines a MultiBranchNode, a MultiNode which yields multiple256// control values. These are distinguished from other types of MultiNodes257// which yield multiple values, but control is always and only projection #0.258class MultiBranchNode : public MultiNode {259public:260MultiBranchNode( uint required ) : MultiNode(required) {261init_class_id(Class_MultiBranch);262}263// returns required number of users to be well formed.264virtual int required_outcnt() const = 0;265};266267//------------------------------IfNode-----------------------------------------268// Output selected Control, based on a boolean test269class IfNode : public MultiBranchNode {270// Size is bigger to hold the probability field. However, _prob does not271// change the semantics so it does not appear in the hash & cmp functions.272virtual uint size_of() const { return sizeof(*this); }273public:274275// Degrees of branch prediction probability by order of magnitude:276// PROB_UNLIKELY_1e(N) is a 1 in 1eN chance.277// PROB_LIKELY_1e(N) is a 1 - PROB_UNLIKELY_1e(N)278#define PROB_UNLIKELY_MAG(N) (1e- ## N ## f)279#define PROB_LIKELY_MAG(N) (1.0f-PROB_UNLIKELY_MAG(N))280281// Maximum and minimum branch prediction probabilties282// 1 in 1,000,000 (magnitude 6)283//284// Although PROB_NEVER == PROB_MIN and PROB_ALWAYS == PROB_MAX285// they are used to distinguish different situations:286//287// The name PROB_MAX (PROB_MIN) is for probabilities which correspond to288// very likely (unlikely) but with a concrete possibility of a rare289// contrary case. These constants would be used for pinning290// measurements, and as measures for assertions that have high291// confidence, but some evidence of occasional failure.292//293// The name PROB_ALWAYS (PROB_NEVER) is to stand for situations for which294// there is no evidence at all that the contrary case has ever occurred.295296#define PROB_NEVER PROB_UNLIKELY_MAG(6)297#define PROB_ALWAYS PROB_LIKELY_MAG(6)298299#define PROB_MIN PROB_UNLIKELY_MAG(6)300#define PROB_MAX PROB_LIKELY_MAG(6)301302// Static branch prediction probabilities303// 1 in 10 (magnitude 1)304#define PROB_STATIC_INFREQUENT PROB_UNLIKELY_MAG(1)305#define PROB_STATIC_FREQUENT PROB_LIKELY_MAG(1)306307// Fair probability 50/50308#define PROB_FAIR (0.5f)309310// Unknown probability sentinel311#define PROB_UNKNOWN (-1.0f)312313// Probability "constructors", to distinguish as a probability any manifest314// constant without a names315#define PROB_LIKELY(x) ((float) (x))316#define PROB_UNLIKELY(x) (1.0f - (float)(x))317318// Other probabilities in use, but without a unique name, are documented319// here for lack of a better place:320//321// 1 in 1000 probabilities (magnitude 3):322// threshold for converting to conditional move323// likelihood of null check failure if a null HAS been seen before324// likelihood of slow path taken in library calls325//326// 1 in 10,000 probabilities (magnitude 4):327// threshold for making an uncommon trap probability more extreme328// threshold for for making a null check implicit329// likelihood of needing a gc if eden top moves during an allocation330// likelihood of a predicted call failure331//332// 1 in 100,000 probabilities (magnitude 5):333// threshold for ignoring counts when estimating path frequency334// likelihood of FP clipping failure335// likelihood of catching an exception from a try block336// likelihood of null check failure if a null has NOT been seen before337//338// Magic manifest probabilities such as 0.83, 0.7, ... can be found in339// gen_subtype_check() and catch_inline_exceptions().340341float _prob; // Probability of true path being taken.342float _fcnt; // Frequency counter343IfNode( Node *control, Node *b, float p, float fcnt )344: MultiBranchNode(2), _prob(p), _fcnt(fcnt) {345init_class_id(Class_If);346init_req(0,control);347init_req(1,b);348}349virtual int Opcode() const;350virtual bool pinned() const { return true; }351virtual const Type *bottom_type() const { return TypeTuple::IFBOTH; }352virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);353virtual const Type *Value( PhaseTransform *phase ) const;354virtual int required_outcnt() const { return 2; }355virtual const RegMask &out_RegMask() const;356void dominated_by(Node* prev_dom, PhaseIterGVN* igvn);357int is_range_check(Node* &range, Node* &index, jint &offset);358Node* fold_compares(PhaseGVN* phase);359static Node* up_one_dom(Node* curr, bool linear_only = false);360361// Takes the type of val and filters it through the test represented362// by if_proj and returns a more refined type if one is produced.363// Returns NULL is it couldn't improve the type.364static const TypeInt* filtered_int_type(PhaseGVN* phase, Node* val, Node* if_proj);365366bool is_shenandoah_marking_if(PhaseTransform *phase) const;367368#ifndef PRODUCT369virtual void dump_spec(outputStream *st) const;370#endif371};372373class IfTrueNode : public CProjNode {374public:375IfTrueNode( IfNode *ifnode ) : CProjNode(ifnode,1) {376init_class_id(Class_IfTrue);377}378virtual int Opcode() const;379virtual Node *Identity( PhaseTransform *phase );380};381382class IfFalseNode : public CProjNode {383public:384IfFalseNode( IfNode *ifnode ) : CProjNode(ifnode,0) {385init_class_id(Class_IfFalse);386}387virtual int Opcode() const;388virtual Node *Identity( PhaseTransform *phase );389};390391392//------------------------------PCTableNode------------------------------------393// Build an indirect branch table. Given a control and a table index,394// control is passed to the Projection matching the table index. Used to395// implement switch statements and exception-handling capabilities.396// Undefined behavior if passed-in index is not inside the table.397class PCTableNode : public MultiBranchNode {398virtual uint hash() const; // Target count; table size399virtual uint cmp( const Node &n ) const;400virtual uint size_of() const { return sizeof(*this); }401402public:403const uint _size; // Number of targets404405PCTableNode( Node *ctrl, Node *idx, uint size ) : MultiBranchNode(2), _size(size) {406init_class_id(Class_PCTable);407init_req(0, ctrl);408init_req(1, idx);409}410virtual int Opcode() const;411virtual const Type *Value( PhaseTransform *phase ) const;412virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);413virtual const Type *bottom_type() const;414virtual bool pinned() const { return true; }415virtual int required_outcnt() const { return _size; }416};417418//------------------------------JumpNode---------------------------------------419// Indirect branch. Uses PCTable above to implement a switch statement.420// It emits as a table load and local branch.421class JumpNode : public PCTableNode {422public:423JumpNode( Node* control, Node* switch_val, uint size) : PCTableNode(control, switch_val, size) {424init_class_id(Class_Jump);425}426virtual int Opcode() const;427virtual const RegMask& out_RegMask() const;428virtual const Node* is_block_proj() const { return this; }429};430431class JumpProjNode : public JProjNode {432virtual uint hash() const;433virtual uint cmp( const Node &n ) const;434virtual uint size_of() const { return sizeof(*this); }435436private:437const int _dest_bci;438const uint _proj_no;439const int _switch_val;440public:441JumpProjNode(Node* jumpnode, uint proj_no, int dest_bci, int switch_val)442: JProjNode(jumpnode, proj_no), _dest_bci(dest_bci), _proj_no(proj_no), _switch_val(switch_val) {443init_class_id(Class_JumpProj);444}445446virtual int Opcode() const;447virtual const Type* bottom_type() const { return Type::CONTROL; }448int dest_bci() const { return _dest_bci; }449int switch_val() const { return _switch_val; }450uint proj_no() const { return _proj_no; }451#ifndef PRODUCT452virtual void dump_spec(outputStream *st) const;453#endif454};455456//------------------------------CatchNode--------------------------------------457// Helper node to fork exceptions. "Catch" catches any exceptions thrown by458// a just-prior call. Looks like a PCTableNode but emits no code - just the459// table. The table lookup and branch is implemented by RethrowNode.460class CatchNode : public PCTableNode {461public:462CatchNode( Node *ctrl, Node *idx, uint size ) : PCTableNode(ctrl,idx,size){463init_class_id(Class_Catch);464}465virtual int Opcode() const;466virtual const Type *Value( PhaseTransform *phase ) const;467};468469// CatchProjNode controls which exception handler is targetted after a call.470// It is passed in the bci of the target handler, or no_handler_bci in case471// the projection doesn't lead to an exception handler.472class CatchProjNode : public CProjNode {473virtual uint hash() const;474virtual uint cmp( const Node &n ) const;475virtual uint size_of() const { return sizeof(*this); }476477private:478const int _handler_bci;479480public:481enum {482fall_through_index = 0, // the fall through projection index483catch_all_index = 1, // the projection index for catch-alls484no_handler_bci = -1 // the bci for fall through or catch-all projs485};486487CatchProjNode(Node* catchnode, uint proj_no, int handler_bci)488: CProjNode(catchnode, proj_no), _handler_bci(handler_bci) {489init_class_id(Class_CatchProj);490assert(proj_no != fall_through_index || handler_bci < 0, "fall through case must have bci < 0");491}492493virtual int Opcode() const;494virtual Node *Identity( PhaseTransform *phase );495virtual const Type *bottom_type() const { return Type::CONTROL; }496int handler_bci() const { return _handler_bci; }497bool is_handler_proj() const { return _handler_bci >= 0; }498#ifndef PRODUCT499virtual void dump_spec(outputStream *st) const;500#endif501};502503504//---------------------------------CreateExNode--------------------------------505// Helper node to create the exception coming back from a call506class CreateExNode : public TypeNode {507public:508CreateExNode(const Type* t, Node* control, Node* i_o) : TypeNode(t, 2) {509init_req(0, control);510init_req(1, i_o);511}512virtual int Opcode() const;513virtual Node *Identity( PhaseTransform *phase );514virtual bool pinned() const { return true; }515uint match_edge(uint idx) const { return 0; }516virtual uint ideal_reg() const { return Op_RegP; }517};518519//------------------------------NeverBranchNode-------------------------------520// The never-taken branch. Used to give the appearance of exiting infinite521// loops to those algorithms that like all paths to be reachable. Encodes522// empty.523class NeverBranchNode : public MultiBranchNode {524public:525NeverBranchNode( Node *ctrl ) : MultiBranchNode(1) { init_req(0,ctrl); }526virtual int Opcode() const;527virtual bool pinned() const { return true; };528virtual const Type *bottom_type() const { return TypeTuple::IFBOTH; }529virtual const Type *Value( PhaseTransform *phase ) const;530virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);531virtual int required_outcnt() const { return 2; }532virtual void emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const { }533virtual uint size(PhaseRegAlloc *ra_) const { return 0; }534#ifndef PRODUCT535virtual void format( PhaseRegAlloc *, outputStream *st ) const;536#endif537};538539#endif // SHARE_VM_OPTO_CFGNODE_HPP540541542