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