1 /*
2  * Copyright (c) 1997, 2019, 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 #ifndef SHARE_OPTO_CFGNODE_HPP
26 #define SHARE_OPTO_CFGNODE_HPP
27 
28 #include "opto/multnode.hpp"
29 #include "opto/node.hpp"
30 #include "opto/opcodes.hpp"
31 #include "opto/type.hpp"
32 
33 // Portions of code courtesy of Clifford Click
34 
35 // Optimization - Graph Style
36 
37 class Matcher;
38 class Node;
39 class   RegionNode;
40 class   TypeNode;
41 class     PhiNode;
42 class   GotoNode;
43 class   MultiNode;
44 class     MultiBranchNode;
45 class       IfNode;
46 class       PCTableNode;
47 class         JumpNode;
48 class         CatchNode;
49 class       NeverBranchNode;
50 class   ProjNode;
51 class     CProjNode;
52 class       IfTrueNode;
53 class       IfFalseNode;
54 class       CatchProjNode;
55 class     JProjNode;
56 class       JumpProjNode;
57 class     SCMemProjNode;
58 class PhaseIdealLoop;
59 
60 //------------------------------RegionNode-------------------------------------
61 // The class of RegionNodes, which can be mapped to basic blocks in the
62 // program.  Their inputs point to Control sources.  PhiNodes (described
63 // below) have an input point to a RegionNode.  Merged data inputs to PhiNodes
64 // correspond 1-to-1 with RegionNode inputs.  The zero input of a PhiNode is
65 // the RegionNode, and the zero input of the RegionNode is itself.
66 class RegionNode : public Node {
67 public:
68   // Node layout (parallels PhiNode):
69   enum { Region,                // Generally points to self.
70          Control                // Control arcs are [1..len)
71   };
72 
RegionNode(uint required)73   RegionNode( uint required ) : Node(required) {
74     init_class_id(Class_Region);
75     init_req(0,this);
76   }
77 
is_copy() const78   Node* is_copy() const {
79     const Node* r = _in[Region];
80     if (r == NULL)
81       return nonnull_req();
82     return NULL;  // not a copy!
83   }
84   PhiNode* has_phi() const;        // returns an arbitrary phi user, or NULL
85   PhiNode* has_unique_phi() const; // returns the unique phi user, or NULL
86   // Is this region node unreachable from root?
87   bool is_unreachable_region(PhaseGVN *phase) const;
88   virtual int Opcode() const;
pinned() const89   virtual bool pinned() const { return (const Node *)in(0) == this; }
is_CFG() const90   virtual bool  is_CFG   () const { return true; }
hash() const91   virtual uint hash() const { return NO_HASH; }  // CFG nodes do not hash
depends_only_on_test() const92   virtual bool depends_only_on_test() const { return false; }
bottom_type() const93   virtual const Type *bottom_type() const { return Type::CONTROL; }
94   virtual const Type* Value(PhaseGVN* phase) const;
95   virtual Node* Identity(PhaseGVN* phase);
96   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
97   virtual const RegMask &out_RegMask() const;
98   bool try_clean_mem_phi(PhaseGVN *phase);
99   bool optimize_trichotomy(PhaseIterGVN* igvn);
100 };
101 
102 //------------------------------JProjNode--------------------------------------
103 // jump projection for node that produces multiple control-flow paths
104 class JProjNode : public ProjNode {
105  public:
JProjNode(Node * ctrl,uint idx)106   JProjNode( Node* ctrl, uint idx ) : ProjNode(ctrl,idx) {}
107   virtual int Opcode() const;
is_CFG() const108   virtual bool  is_CFG() const { return true; }
hash() const109   virtual uint  hash() const { return NO_HASH; }  // CFG nodes do not hash
is_block_proj() const110   virtual const Node* is_block_proj() const { return in(0); }
111   virtual const RegMask& out_RegMask() const;
ideal_reg() const112   virtual uint  ideal_reg() const { return 0; }
113 };
114 
115 //------------------------------PhiNode----------------------------------------
116 // PhiNodes merge values from different Control paths.  Slot 0 points to the
117 // controlling RegionNode.  Other slots map 1-for-1 with incoming control flow
118 // paths to the RegionNode.  For speed reasons (to avoid another pass) we
119 // can turn PhiNodes into copys in-place by NULL'ing out their RegionNode
120 // input in slot 0.
121 class PhiNode : public TypeNode {
122   friend class PhaseRenumberLive;
123 
124   const TypePtr* const _adr_type; // non-null only for Type::MEMORY nodes.
125   // The following fields are only used for data PhiNodes to indicate
126   // that the PhiNode represents the value of a known instance field.
127         int _inst_mem_id; // Instance memory id (node index of the memory Phi)
128         int _inst_id;     // Instance id of the memory slice.
129   const int _inst_index;  // Alias index of the instance memory slice.
130   // Array elements references have the same alias_idx but different offset.
131   const int _inst_offset; // Offset of the instance memory slice.
132   // Size is bigger to hold the _adr_type field.
133   virtual uint hash() const;    // Check the type
134   virtual bool cmp( const Node &n ) const;
size_of() const135   virtual uint size_of() const { return sizeof(*this); }
136 
137   // Determine if CMoveNode::is_cmove_id can be used at this join point.
138   Node* is_cmove_id(PhaseTransform* phase, int true_path);
139   bool wait_for_region_igvn(PhaseGVN* phase);
140 
141 public:
142   // Node layout (parallels RegionNode):
143   enum { Region,                // Control input is the Phi's region.
144          Input                  // Input values are [1..len)
145   };
146 
PhiNode(Node * r,const Type * t,const TypePtr * at=NULL,const int imid=-1,const int iid=TypeOopPtr::InstanceTop,const int iidx=Compile::AliasIdxTop,const int ioffs=Type::OffsetTop)147   PhiNode( Node *r, const Type *t, const TypePtr* at = NULL,
148            const int imid = -1,
149            const int iid = TypeOopPtr::InstanceTop,
150            const int iidx = Compile::AliasIdxTop,
151            const int ioffs = Type::OffsetTop )
152     : TypeNode(t,r->req()),
153       _adr_type(at),
154       _inst_mem_id(imid),
155       _inst_id(iid),
156       _inst_index(iidx),
157       _inst_offset(ioffs)
158   {
159     init_class_id(Class_Phi);
160     init_req(0, r);
161     verify_adr_type();
162   }
163   // create a new phi with in edges matching r and set (initially) to x
164   static PhiNode* make( Node* r, Node* x );
165   // extra type arguments override the new phi's bottom_type and adr_type
166   static PhiNode* make( Node* r, Node* x, const Type *t, const TypePtr* at = NULL );
167   // create a new phi with narrowed memory type
168   PhiNode* slice_memory(const TypePtr* adr_type) const;
169   PhiNode* split_out_instance(const TypePtr* at, PhaseIterGVN *igvn) const;
170   // like make(r, x), but does not initialize the in edges to x
171   static PhiNode* make_blank( Node* r, Node* x );
172 
173   // Accessors
region() const174   RegionNode* region() const { Node* r = in(Region); assert(!r || r->is_Region(), ""); return (RegionNode*)r; }
175 
is_copy() const176   Node* is_copy() const {
177     // The node is a real phi if _in[0] is a Region node.
178     DEBUG_ONLY(const Node* r = _in[Region];)
179     assert(r != NULL && r->is_Region(), "Not valid control");
180     return NULL;  // not a copy!
181   }
182 
183   bool is_tripcount() const;
184 
185   // Determine a unique non-trivial input, if any.
186   // Ignore casts if it helps.  Return NULL on failure.
187   Node* unique_input(PhaseTransform *phase, bool uncast);
unique_input(PhaseTransform * phase)188   Node* unique_input(PhaseTransform *phase) {
189     Node* uin = unique_input(phase, false);
190     if (uin == NULL) {
191       uin = unique_input(phase, true);
192     }
193     return uin;
194   }
195 
196   // Check for a simple dead loop.
197   enum LoopSafety { Safe = 0, Unsafe, UnsafeLoop };
198   LoopSafety simple_data_loop_check(Node *in) const;
199   // Is it unsafe data loop? It becomes a dead loop if this phi node removed.
200   bool is_unsafe_data_reference(Node *in) const;
201   int  is_diamond_phi(bool check_control_only = false) const;
202   virtual int Opcode() const;
pinned() const203   virtual bool pinned() const { return in(0) != 0; }
adr_type() const204   virtual const TypePtr *adr_type() const { verify_adr_type(true); return _adr_type; }
205 
set_inst_mem_id(int inst_mem_id)206   void  set_inst_mem_id(int inst_mem_id) { _inst_mem_id = inst_mem_id; }
inst_mem_id() const207   const int inst_mem_id() const { return _inst_mem_id; }
inst_id() const208   const int inst_id()     const { return _inst_id; }
inst_index() const209   const int inst_index()  const { return _inst_index; }
inst_offset() const210   const int inst_offset() const { return _inst_offset; }
is_same_inst_field(const Type * tp,int mem_id,int id,int index,int offset)211   bool is_same_inst_field(const Type* tp, int mem_id, int id, int index, int offset) {
212     return type()->basic_type() == tp->basic_type() &&
213            inst_mem_id() == mem_id &&
214            inst_id()     == id     &&
215            inst_index()  == index  &&
216            inst_offset() == offset &&
217            type()->higher_equal(tp);
218   }
219 
220   virtual const Type* Value(PhaseGVN* phase) const;
221   virtual Node* Identity(PhaseGVN* phase);
222   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
223   virtual const RegMask &out_RegMask() const;
224   virtual const RegMask &in_RegMask(uint) const;
225 #ifndef PRODUCT
226   virtual void related(GrowableArray<Node*> *in_rel, GrowableArray<Node*> *out_rel, bool compact) const;
227   virtual void dump_spec(outputStream *st) const;
228 #endif
229 #ifdef ASSERT
230   void verify_adr_type(VectorSet& visited, const TypePtr* at) const;
231   void verify_adr_type(bool recursive = false) const;
232 #else //ASSERT
verify_adr_type(bool recursive=false) const233   void verify_adr_type(bool recursive = false) const {}
234 #endif //ASSERT
235 };
236 
237 //------------------------------GotoNode---------------------------------------
238 // GotoNodes perform direct branches.
239 class GotoNode : public Node {
240 public:
GotoNode(Node * control)241   GotoNode( Node *control ) : Node(control) {}
242   virtual int Opcode() const;
pinned() const243   virtual bool pinned() const { return true; }
is_CFG() const244   virtual bool  is_CFG() const { return true; }
hash() const245   virtual uint hash() const { return NO_HASH; }  // CFG nodes do not hash
is_block_proj() const246   virtual const Node *is_block_proj() const { return this; }
depends_only_on_test() const247   virtual bool depends_only_on_test() const { return false; }
bottom_type() const248   virtual const Type *bottom_type() const { return Type::CONTROL; }
249   virtual const Type* Value(PhaseGVN* phase) const;
250   virtual Node* Identity(PhaseGVN* phase);
251   virtual const RegMask &out_RegMask() const;
252 
253 #ifndef PRODUCT
254   virtual void related(GrowableArray<Node*> *in_rel, GrowableArray<Node*> *out_rel, bool compact) const;
255 #endif
256 };
257 
258 //------------------------------CProjNode--------------------------------------
259 // control projection for node that produces multiple control-flow paths
260 class CProjNode : public ProjNode {
261 public:
CProjNode(Node * ctrl,uint idx)262   CProjNode( Node *ctrl, uint idx ) : ProjNode(ctrl,idx) {}
263   virtual int Opcode() const;
is_CFG() const264   virtual bool  is_CFG() const { return true; }
hash() const265   virtual uint hash() const { return NO_HASH; }  // CFG nodes do not hash
is_block_proj() const266   virtual const Node *is_block_proj() const { return in(0); }
267   virtual const RegMask &out_RegMask() const;
ideal_reg() const268   virtual uint ideal_reg() const { return 0; }
269 };
270 
271 //---------------------------MultiBranchNode-----------------------------------
272 // This class defines a MultiBranchNode, a MultiNode which yields multiple
273 // control values. These are distinguished from other types of MultiNodes
274 // which yield multiple values, but control is always and only projection #0.
275 class MultiBranchNode : public MultiNode {
276 public:
MultiBranchNode(uint required)277   MultiBranchNode( uint required ) : MultiNode(required) {
278     init_class_id(Class_MultiBranch);
279   }
280   // returns required number of users to be well formed.
281   virtual int required_outcnt() const = 0;
282 };
283 
284 //------------------------------IfNode-----------------------------------------
285 // Output selected Control, based on a boolean test
286 class IfNode : public MultiBranchNode {
287   // Size is bigger to hold the probability field.  However, _prob does not
288   // change the semantics so it does not appear in the hash & cmp functions.
size_of() const289   virtual uint size_of() const { return sizeof(*this); }
290 
291 private:
292   // Helper methods for fold_compares
293   bool cmpi_folds(PhaseIterGVN* igvn, bool fold_ne = false);
294   bool is_ctrl_folds(Node* ctrl, PhaseIterGVN* igvn);
295   bool has_shared_region(ProjNode* proj, ProjNode*& success, ProjNode*& fail);
296   bool has_only_uncommon_traps(ProjNode* proj, ProjNode*& success, ProjNode*& fail, PhaseIterGVN* igvn);
297   Node* merge_uncommon_traps(ProjNode* proj, ProjNode* success, ProjNode* fail, PhaseIterGVN* igvn);
298   static void improve_address_types(Node* l, Node* r, ProjNode* fail, PhaseIterGVN* igvn);
299   bool is_cmp_with_loadrange(ProjNode* proj);
300   bool is_null_check(ProjNode* proj, PhaseIterGVN* igvn);
301   bool is_side_effect_free_test(ProjNode* proj, PhaseIterGVN* igvn);
302   void reroute_side_effect_free_unc(ProjNode* proj, ProjNode* dom_proj, PhaseIterGVN* igvn);
303   ProjNode* uncommon_trap_proj(CallStaticJavaNode*& call) const;
304   bool fold_compares_helper(ProjNode* proj, ProjNode* success, ProjNode* fail, PhaseIterGVN* igvn);
305   static bool is_dominator_unc(CallStaticJavaNode* dom_unc, CallStaticJavaNode* unc);
306 
307 protected:
308   ProjNode* range_check_trap_proj(int& flip, Node*& l, Node*& r);
309   Node* Ideal_common(PhaseGVN *phase, bool can_reshape);
310   Node* search_identical(int dist);
311 
312   Node* simple_subsuming(PhaseIterGVN* igvn);
313 
314 public:
315 
316   // Degrees of branch prediction probability by order of magnitude:
317   // PROB_UNLIKELY_1e(N) is a 1 in 1eN chance.
318   // PROB_LIKELY_1e(N) is a 1 - PROB_UNLIKELY_1e(N)
319 #define PROB_UNLIKELY_MAG(N)    (1e- ## N ## f)
320 #define PROB_LIKELY_MAG(N)      (1.0f-PROB_UNLIKELY_MAG(N))
321 
322   // Maximum and minimum branch prediction probabilties
323   // 1 in 1,000,000 (magnitude 6)
324   //
325   // Although PROB_NEVER == PROB_MIN and PROB_ALWAYS == PROB_MAX
326   // they are used to distinguish different situations:
327   //
328   // The name PROB_MAX (PROB_MIN) is for probabilities which correspond to
329   // very likely (unlikely) but with a concrete possibility of a rare
330   // contrary case.  These constants would be used for pinning
331   // measurements, and as measures for assertions that have high
332   // confidence, but some evidence of occasional failure.
333   //
334   // The name PROB_ALWAYS (PROB_NEVER) is to stand for situations for which
335   // there is no evidence at all that the contrary case has ever occurred.
336 
337 #define PROB_NEVER              PROB_UNLIKELY_MAG(6)
338 #define PROB_ALWAYS             PROB_LIKELY_MAG(6)
339 
340 #define PROB_MIN                PROB_UNLIKELY_MAG(6)
341 #define PROB_MAX                PROB_LIKELY_MAG(6)
342 
343   // Static branch prediction probabilities
344   // 1 in 10 (magnitude 1)
345 #define PROB_STATIC_INFREQUENT  PROB_UNLIKELY_MAG(1)
346 #define PROB_STATIC_FREQUENT    PROB_LIKELY_MAG(1)
347 
348   // Fair probability 50/50
349 #define PROB_FAIR               (0.5f)
350 
351   // Unknown probability sentinel
352 #define PROB_UNKNOWN            (-1.0f)
353 
354   // Probability "constructors", to distinguish as a probability any manifest
355   // constant without a names
356 #define PROB_LIKELY(x)          ((float) (x))
357 #define PROB_UNLIKELY(x)        (1.0f - (float)(x))
358 
359   // Other probabilities in use, but without a unique name, are documented
360   // here for lack of a better place:
361   //
362   // 1 in 1000 probabilities (magnitude 3):
363   //     threshold for converting to conditional move
364   //     likelihood of null check failure if a null HAS been seen before
365   //     likelihood of slow path taken in library calls
366   //
367   // 1 in 10,000 probabilities (magnitude 4):
368   //     threshold for making an uncommon trap probability more extreme
369   //     threshold for for making a null check implicit
370   //     likelihood of needing a gc if eden top moves during an allocation
371   //     likelihood of a predicted call failure
372   //
373   // 1 in 100,000 probabilities (magnitude 5):
374   //     threshold for ignoring counts when estimating path frequency
375   //     likelihood of FP clipping failure
376   //     likelihood of catching an exception from a try block
377   //     likelihood of null check failure if a null has NOT been seen before
378   //
379   // Magic manifest probabilities such as 0.83, 0.7, ... can be found in
380   // gen_subtype_check() and catch_inline_exceptions().
381 
382   float _prob;                  // Probability of true path being taken.
383   float _fcnt;                  // Frequency counter
IfNode(Node * control,Node * b,float p,float fcnt)384   IfNode( Node *control, Node *b, float p, float fcnt )
385     : MultiBranchNode(2), _prob(p), _fcnt(fcnt) {
386     init_class_id(Class_If);
387     init_req(0,control);
388     init_req(1,b);
389   }
390   virtual int Opcode() const;
pinned() const391   virtual bool pinned() const { return true; }
bottom_type() const392   virtual const Type *bottom_type() const { return TypeTuple::IFBOTH; }
393   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
394   virtual const Type* Value(PhaseGVN* phase) const;
required_outcnt() const395   virtual int required_outcnt() const { return 2; }
396   virtual const RegMask &out_RegMask() const;
397   Node* fold_compares(PhaseIterGVN* phase);
398   static Node* up_one_dom(Node* curr, bool linear_only = false);
399   Node* dominated_by(Node* prev_dom, PhaseIterGVN* igvn);
400 
401   // Takes the type of val and filters it through the test represented
402   // by if_proj and returns a more refined type if one is produced.
403   // Returns NULL is it couldn't improve the type.
404   static const TypeInt* filtered_int_type(PhaseGVN* phase, Node* val, Node* if_proj);
405 
406 #ifndef PRODUCT
407   virtual void dump_spec(outputStream *st) const;
408   virtual void related(GrowableArray <Node *> *in_rel, GrowableArray <Node *> *out_rel, bool compact) const;
409 #endif
410 };
411 
412 class RangeCheckNode : public IfNode {
413 private:
414   int is_range_check(Node* &range, Node* &index, jint &offset);
415 
416 public:
RangeCheckNode(Node * control,Node * b,float p,float fcnt)417   RangeCheckNode(Node* control, Node *b, float p, float fcnt)
418     : IfNode(control, b, p, fcnt) {
419     init_class_id(Class_RangeCheck);
420   }
421 
422   virtual int Opcode() const;
423   virtual Node* Ideal(PhaseGVN *phase, bool can_reshape);
424 };
425 
426 class IfProjNode : public CProjNode {
427 public:
IfProjNode(IfNode * ifnode,uint idx)428   IfProjNode(IfNode *ifnode, uint idx) : CProjNode(ifnode,idx) {}
429   virtual Node* Identity(PhaseGVN* phase);
430 
431 protected:
432   // Type of If input when this branch is always taken
433   virtual bool always_taken(const TypeTuple* t) const = 0;
434 
435 #ifndef PRODUCT
436 public:
437   virtual void related(GrowableArray<Node*> *in_rel, GrowableArray<Node*> *out_rel, bool compact) const;
438 #endif
439 };
440 
441 class IfTrueNode : public IfProjNode {
442 public:
IfTrueNode(IfNode * ifnode)443   IfTrueNode( IfNode *ifnode ) : IfProjNode(ifnode,1) {
444     init_class_id(Class_IfTrue);
445   }
446   virtual int Opcode() const;
447 
448 protected:
always_taken(const TypeTuple * t) const449   virtual bool always_taken(const TypeTuple* t) const { return t == TypeTuple::IFTRUE; }
450 };
451 
452 class IfFalseNode : public IfProjNode {
453 public:
IfFalseNode(IfNode * ifnode)454   IfFalseNode( IfNode *ifnode ) : IfProjNode(ifnode,0) {
455     init_class_id(Class_IfFalse);
456   }
457   virtual int Opcode() const;
458 
459 protected:
always_taken(const TypeTuple * t) const460   virtual bool always_taken(const TypeTuple* t) const { return t == TypeTuple::IFFALSE; }
461 };
462 
463 
464 //------------------------------PCTableNode------------------------------------
465 // Build an indirect branch table.  Given a control and a table index,
466 // control is passed to the Projection matching the table index.  Used to
467 // implement switch statements and exception-handling capabilities.
468 // Undefined behavior if passed-in index is not inside the table.
469 class PCTableNode : public MultiBranchNode {
470   virtual uint hash() const;    // Target count; table size
471   virtual bool cmp( const Node &n ) const;
size_of() const472   virtual uint size_of() const { return sizeof(*this); }
473 
474 public:
475   const uint _size;             // Number of targets
476 
PCTableNode(Node * ctrl,Node * idx,uint size)477   PCTableNode( Node *ctrl, Node *idx, uint size ) : MultiBranchNode(2), _size(size) {
478     init_class_id(Class_PCTable);
479     init_req(0, ctrl);
480     init_req(1, idx);
481   }
482   virtual int Opcode() const;
483   virtual const Type* Value(PhaseGVN* phase) const;
484   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
485   virtual const Type *bottom_type() const;
pinned() const486   virtual bool pinned() const { return true; }
required_outcnt() const487   virtual int required_outcnt() const { return _size; }
488 };
489 
490 //------------------------------JumpNode---------------------------------------
491 // Indirect branch.  Uses PCTable above to implement a switch statement.
492 // It emits as a table load and local branch.
493 class JumpNode : public PCTableNode {
size_of() const494   virtual uint size_of() const { return sizeof(*this); }
495 public:
496   float* _probs; // probability of each projection
497   float _fcnt;   // total number of times this Jump was executed
JumpNode(Node * control,Node * switch_val,uint size,float * probs,float cnt)498   JumpNode( Node* control, Node* switch_val, uint size, float* probs, float cnt)
499     : PCTableNode(control, switch_val, size),
500       _probs(probs), _fcnt(cnt) {
501     init_class_id(Class_Jump);
502   }
503   virtual int   Opcode() const;
504   virtual const RegMask& out_RegMask() const;
is_block_proj() const505   virtual const Node* is_block_proj() const { return this; }
506 #ifndef PRODUCT
507   virtual void related(GrowableArray<Node*> *in_rel, GrowableArray<Node*> *out_rel, bool compact) const;
508 #endif
509 };
510 
511 class JumpProjNode : public JProjNode {
512   virtual uint hash() const;
513   virtual bool cmp( const Node &n ) const;
size_of() const514   virtual uint size_of() const { return sizeof(*this); }
515 
516  private:
517   const int  _dest_bci;
518   const uint _proj_no;
519   const int  _switch_val;
520  public:
JumpProjNode(Node * jumpnode,uint proj_no,int dest_bci,int switch_val)521   JumpProjNode(Node* jumpnode, uint proj_no, int dest_bci, int switch_val)
522     : JProjNode(jumpnode, proj_no), _dest_bci(dest_bci), _proj_no(proj_no), _switch_val(switch_val) {
523     init_class_id(Class_JumpProj);
524   }
525 
526   virtual int Opcode() const;
bottom_type() const527   virtual const Type* bottom_type() const { return Type::CONTROL; }
dest_bci() const528   int  dest_bci()    const { return _dest_bci; }
switch_val() const529   int  switch_val()  const { return _switch_val; }
proj_no() const530   uint proj_no()     const { return _proj_no; }
531 #ifndef PRODUCT
532   virtual void dump_spec(outputStream *st) const;
533   virtual void dump_compact_spec(outputStream *st) const;
534   virtual void related(GrowableArray<Node*> *in_rel, GrowableArray<Node*> *out_rel, bool compact) const;
535 #endif
536 };
537 
538 //------------------------------CatchNode--------------------------------------
539 // Helper node to fork exceptions.  "Catch" catches any exceptions thrown by
540 // a just-prior call.  Looks like a PCTableNode but emits no code - just the
541 // table.  The table lookup and branch is implemented by RethrowNode.
542 class CatchNode : public PCTableNode {
543 public:
CatchNode(Node * ctrl,Node * idx,uint size)544   CatchNode( Node *ctrl, Node *idx, uint size ) : PCTableNode(ctrl,idx,size){
545     init_class_id(Class_Catch);
546   }
547   virtual int Opcode() const;
548   virtual const Type* Value(PhaseGVN* phase) const;
549 };
550 
551 // CatchProjNode controls which exception handler is targetted after a call.
552 // It is passed in the bci of the target handler, or no_handler_bci in case
553 // the projection doesn't lead to an exception handler.
554 class CatchProjNode : public CProjNode {
555   virtual uint hash() const;
556   virtual bool cmp( const Node &n ) const;
size_of() const557   virtual uint size_of() const { return sizeof(*this); }
558 
559 private:
560   const int _handler_bci;
561 
562 public:
563   enum {
564     fall_through_index =  0,      // the fall through projection index
565     catch_all_index    =  1,      // the projection index for catch-alls
566     no_handler_bci     = -1       // the bci for fall through or catch-all projs
567   };
568 
CatchProjNode(Node * catchnode,uint proj_no,int handler_bci)569   CatchProjNode(Node* catchnode, uint proj_no, int handler_bci)
570     : CProjNode(catchnode, proj_no), _handler_bci(handler_bci) {
571     init_class_id(Class_CatchProj);
572     assert(proj_no != fall_through_index || handler_bci < 0, "fall through case must have bci < 0");
573   }
574 
575   virtual int Opcode() const;
576   virtual Node* Identity(PhaseGVN* phase);
bottom_type() const577   virtual const Type *bottom_type() const { return Type::CONTROL; }
handler_bci() const578   int  handler_bci() const        { return _handler_bci; }
is_handler_proj() const579   bool is_handler_proj() const    { return _handler_bci >= 0; }
580 #ifndef PRODUCT
581   virtual void dump_spec(outputStream *st) const;
582 #endif
583 };
584 
585 
586 //---------------------------------CreateExNode--------------------------------
587 // Helper node to create the exception coming back from a call
588 class CreateExNode : public TypeNode {
589 public:
CreateExNode(const Type * t,Node * control,Node * i_o)590   CreateExNode(const Type* t, Node* control, Node* i_o) : TypeNode(t, 2) {
591     init_req(0, control);
592     init_req(1, i_o);
593   }
594   virtual int Opcode() const;
595   virtual Node* Identity(PhaseGVN* phase);
pinned() const596   virtual bool pinned() const { return true; }
match_edge(uint idx) const597   uint match_edge(uint idx) const { return 0; }
ideal_reg() const598   virtual uint ideal_reg() const { return Op_RegP; }
599 };
600 
601 //------------------------------NeverBranchNode-------------------------------
602 // The never-taken branch.  Used to give the appearance of exiting infinite
603 // loops to those algorithms that like all paths to be reachable.  Encodes
604 // empty.
605 class NeverBranchNode : public MultiBranchNode {
606 public:
NeverBranchNode(Node * ctrl)607   NeverBranchNode( Node *ctrl ) : MultiBranchNode(1) { init_req(0,ctrl); }
608   virtual int Opcode() const;
pinned() const609   virtual bool pinned() const { return true; };
bottom_type() const610   virtual const Type *bottom_type() const { return TypeTuple::IFBOTH; }
611   virtual const Type* Value(PhaseGVN* phase) const;
612   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
required_outcnt() const613   virtual int required_outcnt() const { return 2; }
emit(CodeBuffer & cbuf,PhaseRegAlloc * ra_) const614   virtual void emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const { }
size(PhaseRegAlloc * ra_) const615   virtual uint size(PhaseRegAlloc *ra_) const { return 0; }
616 #ifndef PRODUCT
617   virtual void format( PhaseRegAlloc *, outputStream *st ) const;
618 #endif
619 };
620 
621 #endif // SHARE_OPTO_CFGNODE_HPP
622