Path: blob/jdk8u272-b10-aarch32-20201026/hotspot/src/share/vm/opto/cfgnode.hpp
83404 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);365366#ifndef PRODUCT367virtual void dump_spec(outputStream *st) const;368#endif369};370371class IfTrueNode : public CProjNode {372public:373IfTrueNode( IfNode *ifnode ) : CProjNode(ifnode,1) {374init_class_id(Class_IfTrue);375}376virtual int Opcode() const;377virtual Node *Identity( PhaseTransform *phase );378};379380class IfFalseNode : public CProjNode {381public:382IfFalseNode( IfNode *ifnode ) : CProjNode(ifnode,0) {383init_class_id(Class_IfFalse);384}385virtual int Opcode() const;386virtual Node *Identity( PhaseTransform *phase );387};388389390//------------------------------PCTableNode------------------------------------391// Build an indirect branch table. Given a control and a table index,392// control is passed to the Projection matching the table index. Used to393// implement switch statements and exception-handling capabilities.394// Undefined behavior if passed-in index is not inside the table.395class PCTableNode : public MultiBranchNode {396virtual uint hash() const; // Target count; table size397virtual uint cmp( const Node &n ) const;398virtual uint size_of() const { return sizeof(*this); }399400public:401const uint _size; // Number of targets402403PCTableNode( Node *ctrl, Node *idx, uint size ) : MultiBranchNode(2), _size(size) {404init_class_id(Class_PCTable);405init_req(0, ctrl);406init_req(1, idx);407}408virtual int Opcode() const;409virtual const Type *Value( PhaseTransform *phase ) const;410virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);411virtual const Type *bottom_type() const;412virtual bool pinned() const { return true; }413virtual int required_outcnt() const { return _size; }414};415416//------------------------------JumpNode---------------------------------------417// Indirect branch. Uses PCTable above to implement a switch statement.418// It emits as a table load and local branch.419class JumpNode : public PCTableNode {420public:421JumpNode( Node* control, Node* switch_val, uint size) : PCTableNode(control, switch_val, size) {422init_class_id(Class_Jump);423}424virtual int Opcode() const;425virtual const RegMask& out_RegMask() const;426virtual const Node* is_block_proj() const { return this; }427};428429class JumpProjNode : public JProjNode {430virtual uint hash() const;431virtual uint cmp( const Node &n ) const;432virtual uint size_of() const { return sizeof(*this); }433434private:435const int _dest_bci;436const uint _proj_no;437const int _switch_val;438public:439JumpProjNode(Node* jumpnode, uint proj_no, int dest_bci, int switch_val)440: JProjNode(jumpnode, proj_no), _dest_bci(dest_bci), _proj_no(proj_no), _switch_val(switch_val) {441init_class_id(Class_JumpProj);442}443444virtual int Opcode() const;445virtual const Type* bottom_type() const { return Type::CONTROL; }446int dest_bci() const { return _dest_bci; }447int switch_val() const { return _switch_val; }448uint proj_no() const { return _proj_no; }449#ifndef PRODUCT450virtual void dump_spec(outputStream *st) const;451#endif452};453454//------------------------------CatchNode--------------------------------------455// Helper node to fork exceptions. "Catch" catches any exceptions thrown by456// a just-prior call. Looks like a PCTableNode but emits no code - just the457// table. The table lookup and branch is implemented by RethrowNode.458class CatchNode : public PCTableNode {459public:460CatchNode( Node *ctrl, Node *idx, uint size ) : PCTableNode(ctrl,idx,size){461init_class_id(Class_Catch);462}463virtual int Opcode() const;464virtual const Type *Value( PhaseTransform *phase ) const;465};466467// CatchProjNode controls which exception handler is targetted after a call.468// It is passed in the bci of the target handler, or no_handler_bci in case469// the projection doesn't lead to an exception handler.470class CatchProjNode : public CProjNode {471virtual uint hash() const;472virtual uint cmp( const Node &n ) const;473virtual uint size_of() const { return sizeof(*this); }474475private:476const int _handler_bci;477478public:479enum {480fall_through_index = 0, // the fall through projection index481catch_all_index = 1, // the projection index for catch-alls482no_handler_bci = -1 // the bci for fall through or catch-all projs483};484485CatchProjNode(Node* catchnode, uint proj_no, int handler_bci)486: CProjNode(catchnode, proj_no), _handler_bci(handler_bci) {487init_class_id(Class_CatchProj);488assert(proj_no != fall_through_index || handler_bci < 0, "fall through case must have bci < 0");489}490491virtual int Opcode() const;492virtual Node *Identity( PhaseTransform *phase );493virtual const Type *bottom_type() const { return Type::CONTROL; }494int handler_bci() const { return _handler_bci; }495bool is_handler_proj() const { return _handler_bci >= 0; }496#ifndef PRODUCT497virtual void dump_spec(outputStream *st) const;498#endif499};500501502//---------------------------------CreateExNode--------------------------------503// Helper node to create the exception coming back from a call504class CreateExNode : public TypeNode {505public:506CreateExNode(const Type* t, Node* control, Node* i_o) : TypeNode(t, 2) {507init_req(0, control);508init_req(1, i_o);509}510virtual int Opcode() const;511virtual Node *Identity( PhaseTransform *phase );512virtual bool pinned() const { return true; }513uint match_edge(uint idx) const { return 0; }514virtual uint ideal_reg() const { return Op_RegP; }515};516517//------------------------------NeverBranchNode-------------------------------518// The never-taken branch. Used to give the appearance of exiting infinite519// loops to those algorithms that like all paths to be reachable. Encodes520// empty.521class NeverBranchNode : public MultiBranchNode {522public:523NeverBranchNode( Node *ctrl ) : MultiBranchNode(1) { init_req(0,ctrl); }524virtual int Opcode() const;525virtual bool pinned() const { return true; };526virtual const Type *bottom_type() const { return TypeTuple::IFBOTH; }527virtual const Type *Value( PhaseTransform *phase ) const;528virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);529virtual int required_outcnt() const { return 2; }530virtual void emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const { }531virtual uint size(PhaseRegAlloc *ra_) const { return 0; }532#ifndef PRODUCT533virtual void format( PhaseRegAlloc *, outputStream *st ) const;534#endif535};536537#endif // SHARE_VM_OPTO_CFGNODE_HPP538539540