< prev index next >

src/hotspot/share/opto/loopnode.hpp

Print this page

  61   uint _loop_flags;
  62   // Names for flag bitfields
  63   enum { Normal=0, Pre=1, Main=2, Post=3, PreMainPostFlagsMask=3,
  64          MainHasNoPreLoop    = 1<<2,
  65          HasExactTripCount   = 1<<3,
  66          InnerLoop           = 1<<4,
  67          PartialPeelLoop     = 1<<5,
  68          PartialPeelFailed   = 1<<6,
  69          HasReductions       = 1<<7,
  70          WasSlpAnalyzed      = 1<<8,
  71          PassedSlpAnalysis   = 1<<9,
  72          DoUnrollOnly        = 1<<10,
  73          VectorizedLoop      = 1<<11,
  74          HasAtomicPostLoop   = 1<<12,
  75          HasRangeChecks      = 1<<13,
  76          IsMultiversioned    = 1<<14,
  77          StripMined          = 1<<15,
  78          SubwordLoop         = 1<<16,
  79          ProfileTripFailed   = 1<<17,
  80          TransformedLongInnerLoop = 1<<18,
  81          TransformedLongOuterLoop = 1<<19};

  82   char _unswitch_count;
  83   enum { _unswitch_max=3 };
  84   char _postloop_flags;
  85   enum { LoopNotRCEChecked = 0, LoopRCEChecked = 1, RCEPostLoop = 2 };
  86 
  87   // Expected trip count from profile data
  88   float _profile_trip_cnt;
  89 
  90 public:
  91   // Names for edge indices
  92   enum { Self=0, EntryControl, LoopBackControl };
  93 
  94   bool is_inner_loop() const { return _loop_flags & InnerLoop; }
  95   void set_inner_loop() { _loop_flags |= InnerLoop; }
  96 
  97   bool range_checks_present() const { return _loop_flags & HasRangeChecks; }
  98   bool is_multiversioned() const { return _loop_flags & IsMultiversioned; }
  99   bool is_vectorized_loop() const { return _loop_flags & VectorizedLoop; }
 100   bool is_partial_peel_loop() const { return _loop_flags & PartialPeelLoop; }
 101   void set_partial_peel_loop() { _loop_flags |= PartialPeelLoop; }
 102   bool partial_peel_has_failed() const { return _loop_flags & PartialPeelFailed; }
 103   bool is_strip_mined() const { return _loop_flags & StripMined; }
 104   bool is_profile_trip_failed() const { return _loop_flags & ProfileTripFailed; }
 105   bool is_subword_loop() const { return _loop_flags & SubwordLoop; }
 106   bool is_transformed_long_inner_loop() const { return _loop_flags & TransformedLongInnerLoop; }
 107   bool is_transformed_long_outer_loop() const { return _loop_flags & TransformedLongOuterLoop; }

 108 
 109   void mark_partial_peel_failed() { _loop_flags |= PartialPeelFailed; }
 110   void mark_has_reductions() { _loop_flags |= HasReductions; }
 111   void mark_was_slp() { _loop_flags |= WasSlpAnalyzed; }
 112   void mark_passed_slp() { _loop_flags |= PassedSlpAnalysis; }
 113   void mark_do_unroll_only() { _loop_flags |= DoUnrollOnly; }
 114   void mark_loop_vectorized() { _loop_flags |= VectorizedLoop; }
 115   void mark_has_atomic_post_loop() { _loop_flags |= HasAtomicPostLoop; }
 116   void mark_has_range_checks() { _loop_flags |=  HasRangeChecks; }
 117   void mark_is_multiversioned() { _loop_flags |= IsMultiversioned; }
 118   void mark_strip_mined() { _loop_flags |= StripMined; }
 119   void clear_strip_mined() { _loop_flags &= ~StripMined; }
 120   void mark_profile_trip_failed() { _loop_flags |= ProfileTripFailed; }
 121   void mark_subword_loop() { _loop_flags |= SubwordLoop; }
 122   void mark_transformed_long_inner_loop() { _loop_flags |= TransformedLongInnerLoop; }
 123   void mark_transformed_long_outer_loop() { _loop_flags |= TransformedLongOuterLoop; }

 124 
 125   int unswitch_max() { return _unswitch_max; }
 126   int unswitch_count() { return _unswitch_count; }
 127 
 128   int has_been_range_checked() const { return _postloop_flags & LoopRCEChecked; }
 129   void set_has_been_range_checked() { _postloop_flags |= LoopRCEChecked; }
 130   int is_rce_post_loop() const { return _postloop_flags & RCEPostLoop; }
 131   void set_is_rce_post_loop() { _postloop_flags |= RCEPostLoop; }
 132 
 133   void set_unswitch_count(int val) {
 134     assert (val <= unswitch_max(), "too many unswitches");
 135     _unswitch_count = val;
 136   }
 137 
 138   void set_profile_trip_cnt(float ptc) { _profile_trip_cnt = ptc; }
 139   float profile_trip_cnt()             { return _profile_trip_cnt; }
 140 
 141   LoopNode(Node *entry, Node *backedge)
 142     : RegionNode(3), _loop_flags(0), _unswitch_count(0),
 143       _postloop_flags(0), _profile_trip_cnt(COUNT_UNKNOWN)  {

1339     return !has_node(n) || n->is_unreachable(_igvn);
1340   }
1341 
1342   // Eliminate range-checks and other trip-counter vs loop-invariant tests.
1343   int do_range_check( IdealLoopTree *loop, Node_List &old_new );
1344 
1345   // Check to see if do_range_check(...) cleaned the main loop of range-checks
1346   void has_range_checks(IdealLoopTree *loop);
1347 
1348   // Process post loops which have range checks and try to build a multi-version
1349   // guard to safely determine if we can execute the post loop which was RCE'd.
1350   bool multi_version_post_loops(IdealLoopTree *rce_loop, IdealLoopTree *legacy_loop);
1351 
1352   // Cause the rce'd post loop to optimized away, this happens if we cannot complete multiverioning
1353   void poison_rce_post_loop(IdealLoopTree *rce_loop);
1354 
1355   // Create a slow version of the loop by cloning the loop
1356   // and inserting an if to select fast-slow versions.
1357   // Return the inserted if.
1358   IfNode* create_slow_version_of_loop(IdealLoopTree *loop,
1359                                         Node_List &old_new,
1360                                         IfNode* unswitch_iff,
1361                                         CloneLoopMode mode);
1362 
1363   // Clone a loop and return the clone head (clone_loop_head).
1364   // Added nodes include int(1), int(0) - disconnected, If, IfTrue, IfFalse,
1365   // This routine was created for usage in CountedLoopReserveKit.
1366   //
1367   //    int(1) -> If -> IfTrue -> original_loop_head
1368   //              |
1369   //              V
1370   //           IfFalse -> clone_loop_head (returned by function pointer)
1371   //
1372   LoopNode* create_reserve_version_of_loop(IdealLoopTree *loop, CountedLoopReserveKit* lk);
1373   // Clone loop with an invariant test (that does not exit) and
1374   // insert a clone of the test that selects which version to
1375   // execute.
1376   void do_unswitching (IdealLoopTree *loop, Node_List &old_new);
1377 
1378   // Find candidate "if" for unswitching
1379   IfNode* find_unswitching_candidate(const IdealLoopTree *loop) const;
1380 
1381   // Range Check Elimination uses this function!
1382   // Constrain the main loop iterations so the affine function:
1383   //    low_limit <= scale_con * I + offset  <  upper_limit
1384   // always holds true.  That is, either increase the number of iterations in
1385   // the pre-loop or the post-loop until the condition holds true in the main
1386   // loop.  Scale_con, offset and limit are all loop invariant.
1387   void add_constraint(jlong stride_con, jlong scale_con, Node* offset, Node* low_limit, Node* upper_limit, Node* pre_ctrl, Node** pre_limit, Node** main_limit);
1388   // Helper function for add_constraint().
1389   Node* adjust_limit(bool reduce, Node* scale, Node* offset, Node* rc_limit, Node* old_limit, Node* pre_ctrl, bool round);
1390 
1391   // Partially peel loop up through last_peel node.
1392   bool partial_peel( IdealLoopTree *loop, Node_List &old_new );
1393 
1394   // Create a scheduled list of nodes control dependent on ctrl set.
1395   void scheduled_nodelist( IdealLoopTree *loop, VectorSet& ctrl, Node_List &sched );
1396   // Has a use in the vector set
1397   bool has_use_in_set( Node* n, VectorSet& vset );
1398   // Has use internal to the vector set (ie. not in a phi at the loop head)
1399   bool has_use_internal_to_set( Node* n, VectorSet& vset, IdealLoopTree *loop );

1480   bool intrinsify_fill(IdealLoopTree* lpt);
1481   bool match_fill_loop(IdealLoopTree* lpt, Node*& store, Node*& store_value,
1482                        Node*& shift, Node*& offset);
1483 
1484 private:
1485   // Return a type based on condition control flow
1486   const TypeInt* filtered_type( Node *n, Node* n_ctrl);
1487   const TypeInt* filtered_type( Node *n ) { return filtered_type(n, NULL); }
1488  // Helpers for filtered type
1489   const TypeInt* filtered_type_from_dominators( Node* val, Node *val_ctrl);
1490 
1491   // Helper functions
1492   Node *spinup( Node *iff, Node *new_false, Node *new_true, Node *region, Node *phi, small_cache *cache );
1493   Node *find_use_block( Node *use, Node *def, Node *old_false, Node *new_false, Node *old_true, Node *new_true );
1494   void handle_use( Node *use, Node *def, small_cache *cache, Node *region_dom, Node *new_false, Node *new_true, Node *old_false, Node *old_true );
1495   bool split_up( Node *n, Node *blk1, Node *blk2 );
1496   void sink_use( Node *use, Node *post_loop );
1497   Node* place_outside_loop(Node* useblock, IdealLoopTree* loop) const;
1498   Node* try_move_store_before_loop(Node* n, Node *n_ctrl);
1499   void try_move_store_after_loop(Node* n);

1500   bool identical_backtoback_ifs(Node *n);

1501   bool can_split_if(Node *n_ctrl);
1502 
1503   // Determine if a method is too big for a/another round of split-if, based on
1504   // a magic (approximate) ratio derived from the equally magic constant 35000,
1505   // previously used for this purpose (but without relating to the node limit).
1506   bool must_throttle_split_if() {
1507     uint threshold = C->max_node_limit() * 2 / 5;
1508     return C->live_nodes() > threshold;
1509   }
1510 
1511   // A simplistic node request tracking mechanism, where
1512   //   = UINT_MAX   Request not valid or made final.
1513   //   < UINT_MAX   Nodes currently requested (estimate).
1514   uint _nodes_required;
1515 
1516   enum { REQUIRE_MIN = 70 };
1517 
1518   uint nodes_required() const { return _nodes_required; }
1519 
1520   // Given the _currently_  available number of nodes, check  whether there is

  61   uint _loop_flags;
  62   // Names for flag bitfields
  63   enum { Normal=0, Pre=1, Main=2, Post=3, PreMainPostFlagsMask=3,
  64          MainHasNoPreLoop    = 1<<2,
  65          HasExactTripCount   = 1<<3,
  66          InnerLoop           = 1<<4,
  67          PartialPeelLoop     = 1<<5,
  68          PartialPeelFailed   = 1<<6,
  69          HasReductions       = 1<<7,
  70          WasSlpAnalyzed      = 1<<8,
  71          PassedSlpAnalysis   = 1<<9,
  72          DoUnrollOnly        = 1<<10,
  73          VectorizedLoop      = 1<<11,
  74          HasAtomicPostLoop   = 1<<12,
  75          HasRangeChecks      = 1<<13,
  76          IsMultiversioned    = 1<<14,
  77          StripMined          = 1<<15,
  78          SubwordLoop         = 1<<16,
  79          ProfileTripFailed   = 1<<17,
  80          TransformedLongInnerLoop = 1<<18,
  81          TransformedLongOuterLoop = 1<<19,
  82          FlattenedArrays     = 1<<20};
  83   char _unswitch_count;
  84   enum { _unswitch_max=3 };
  85   char _postloop_flags;
  86   enum { LoopNotRCEChecked = 0, LoopRCEChecked = 1, RCEPostLoop = 2 };
  87 
  88   // Expected trip count from profile data
  89   float _profile_trip_cnt;
  90 
  91 public:
  92   // Names for edge indices
  93   enum { Self=0, EntryControl, LoopBackControl };
  94 
  95   bool is_inner_loop() const { return _loop_flags & InnerLoop; }
  96   void set_inner_loop() { _loop_flags |= InnerLoop; }
  97 
  98   bool range_checks_present() const { return _loop_flags & HasRangeChecks; }
  99   bool is_multiversioned() const { return _loop_flags & IsMultiversioned; }
 100   bool is_vectorized_loop() const { return _loop_flags & VectorizedLoop; }
 101   bool is_partial_peel_loop() const { return _loop_flags & PartialPeelLoop; }
 102   void set_partial_peel_loop() { _loop_flags |= PartialPeelLoop; }
 103   bool partial_peel_has_failed() const { return _loop_flags & PartialPeelFailed; }
 104   bool is_strip_mined() const { return _loop_flags & StripMined; }
 105   bool is_profile_trip_failed() const { return _loop_flags & ProfileTripFailed; }
 106   bool is_subword_loop() const { return _loop_flags & SubwordLoop; }
 107   bool is_transformed_long_inner_loop() const { return _loop_flags & TransformedLongInnerLoop; }
 108   bool is_transformed_long_outer_loop() const { return _loop_flags & TransformedLongOuterLoop; }
 109   bool is_flattened_arrays() const { return _loop_flags & FlattenedArrays; }
 110 
 111   void mark_partial_peel_failed() { _loop_flags |= PartialPeelFailed; }
 112   void mark_has_reductions() { _loop_flags |= HasReductions; }
 113   void mark_was_slp() { _loop_flags |= WasSlpAnalyzed; }
 114   void mark_passed_slp() { _loop_flags |= PassedSlpAnalysis; }
 115   void mark_do_unroll_only() { _loop_flags |= DoUnrollOnly; }
 116   void mark_loop_vectorized() { _loop_flags |= VectorizedLoop; }
 117   void mark_has_atomic_post_loop() { _loop_flags |= HasAtomicPostLoop; }
 118   void mark_has_range_checks() { _loop_flags |=  HasRangeChecks; }
 119   void mark_is_multiversioned() { _loop_flags |= IsMultiversioned; }
 120   void mark_strip_mined() { _loop_flags |= StripMined; }
 121   void clear_strip_mined() { _loop_flags &= ~StripMined; }
 122   void mark_profile_trip_failed() { _loop_flags |= ProfileTripFailed; }
 123   void mark_subword_loop() { _loop_flags |= SubwordLoop; }
 124   void mark_transformed_long_inner_loop() { _loop_flags |= TransformedLongInnerLoop; }
 125   void mark_transformed_long_outer_loop() { _loop_flags |= TransformedLongOuterLoop; }
 126   void mark_flattened_arrays() { _loop_flags |= FlattenedArrays; }
 127 
 128   int unswitch_max() { return _unswitch_max; }
 129   int unswitch_count() { return _unswitch_count; }
 130 
 131   int has_been_range_checked() const { return _postloop_flags & LoopRCEChecked; }
 132   void set_has_been_range_checked() { _postloop_flags |= LoopRCEChecked; }
 133   int is_rce_post_loop() const { return _postloop_flags & RCEPostLoop; }
 134   void set_is_rce_post_loop() { _postloop_flags |= RCEPostLoop; }
 135 
 136   void set_unswitch_count(int val) {
 137     assert (val <= unswitch_max(), "too many unswitches");
 138     _unswitch_count = val;
 139   }
 140 
 141   void set_profile_trip_cnt(float ptc) { _profile_trip_cnt = ptc; }
 142   float profile_trip_cnt()             { return _profile_trip_cnt; }
 143 
 144   LoopNode(Node *entry, Node *backedge)
 145     : RegionNode(3), _loop_flags(0), _unswitch_count(0),
 146       _postloop_flags(0), _profile_trip_cnt(COUNT_UNKNOWN)  {

1342     return !has_node(n) || n->is_unreachable(_igvn);
1343   }
1344 
1345   // Eliminate range-checks and other trip-counter vs loop-invariant tests.
1346   int do_range_check( IdealLoopTree *loop, Node_List &old_new );
1347 
1348   // Check to see if do_range_check(...) cleaned the main loop of range-checks
1349   void has_range_checks(IdealLoopTree *loop);
1350 
1351   // Process post loops which have range checks and try to build a multi-version
1352   // guard to safely determine if we can execute the post loop which was RCE'd.
1353   bool multi_version_post_loops(IdealLoopTree *rce_loop, IdealLoopTree *legacy_loop);
1354 
1355   // Cause the rce'd post loop to optimized away, this happens if we cannot complete multiverioning
1356   void poison_rce_post_loop(IdealLoopTree *rce_loop);
1357 
1358   // Create a slow version of the loop by cloning the loop
1359   // and inserting an if to select fast-slow versions.
1360   // Return the inserted if.
1361   IfNode* create_slow_version_of_loop(IdealLoopTree *loop,
1362                                       Node_List &old_new,
1363                                       Node_List &unswitch_iffs,
1364                                       CloneLoopMode mode);
1365 
1366   // Clone a loop and return the clone head (clone_loop_head).
1367   // Added nodes include int(1), int(0) - disconnected, If, IfTrue, IfFalse,
1368   // This routine was created for usage in CountedLoopReserveKit.
1369   //
1370   //    int(1) -> If -> IfTrue -> original_loop_head
1371   //              |
1372   //              V
1373   //           IfFalse -> clone_loop_head (returned by function pointer)
1374   //
1375   LoopNode* create_reserve_version_of_loop(IdealLoopTree *loop, CountedLoopReserveKit* lk);
1376   // Clone loop with an invariant test (that does not exit) and
1377   // insert a clone of the test that selects which version to
1378   // execute.
1379   void do_unswitching (IdealLoopTree *loop, Node_List &old_new);
1380 
1381   // Find candidate "if" for unswitching
1382   IfNode* find_unswitching_candidate(const IdealLoopTree *loop, Node_List& unswitch_iffs) const;
1383 
1384   // Range Check Elimination uses this function!
1385   // Constrain the main loop iterations so the affine function:
1386   //    low_limit <= scale_con * I + offset  <  upper_limit
1387   // always holds true.  That is, either increase the number of iterations in
1388   // the pre-loop or the post-loop until the condition holds true in the main
1389   // loop.  Scale_con, offset and limit are all loop invariant.
1390   void add_constraint(jlong stride_con, jlong scale_con, Node* offset, Node* low_limit, Node* upper_limit, Node* pre_ctrl, Node** pre_limit, Node** main_limit);
1391   // Helper function for add_constraint().
1392   Node* adjust_limit(bool reduce, Node* scale, Node* offset, Node* rc_limit, Node* old_limit, Node* pre_ctrl, bool round);
1393 
1394   // Partially peel loop up through last_peel node.
1395   bool partial_peel( IdealLoopTree *loop, Node_List &old_new );
1396 
1397   // Create a scheduled list of nodes control dependent on ctrl set.
1398   void scheduled_nodelist( IdealLoopTree *loop, VectorSet& ctrl, Node_List &sched );
1399   // Has a use in the vector set
1400   bool has_use_in_set( Node* n, VectorSet& vset );
1401   // Has use internal to the vector set (ie. not in a phi at the loop head)
1402   bool has_use_internal_to_set( Node* n, VectorSet& vset, IdealLoopTree *loop );

1483   bool intrinsify_fill(IdealLoopTree* lpt);
1484   bool match_fill_loop(IdealLoopTree* lpt, Node*& store, Node*& store_value,
1485                        Node*& shift, Node*& offset);
1486 
1487 private:
1488   // Return a type based on condition control flow
1489   const TypeInt* filtered_type( Node *n, Node* n_ctrl);
1490   const TypeInt* filtered_type( Node *n ) { return filtered_type(n, NULL); }
1491  // Helpers for filtered type
1492   const TypeInt* filtered_type_from_dominators( Node* val, Node *val_ctrl);
1493 
1494   // Helper functions
1495   Node *spinup( Node *iff, Node *new_false, Node *new_true, Node *region, Node *phi, small_cache *cache );
1496   Node *find_use_block( Node *use, Node *def, Node *old_false, Node *new_false, Node *old_true, Node *new_true );
1497   void handle_use( Node *use, Node *def, small_cache *cache, Node *region_dom, Node *new_false, Node *new_true, Node *old_false, Node *old_true );
1498   bool split_up( Node *n, Node *blk1, Node *blk2 );
1499   void sink_use( Node *use, Node *post_loop );
1500   Node* place_outside_loop(Node* useblock, IdealLoopTree* loop) const;
1501   Node* try_move_store_before_loop(Node* n, Node *n_ctrl);
1502   void try_move_store_after_loop(Node* n);
1503   void move_flat_array_check_out_of_loop(Node* n);
1504   bool identical_backtoback_ifs(Node *n);
1505   bool flatten_array_element_type_check(Node *n);
1506   bool can_split_if(Node *n_ctrl);
1507 
1508   // Determine if a method is too big for a/another round of split-if, based on
1509   // a magic (approximate) ratio derived from the equally magic constant 35000,
1510   // previously used for this purpose (but without relating to the node limit).
1511   bool must_throttle_split_if() {
1512     uint threshold = C->max_node_limit() * 2 / 5;
1513     return C->live_nodes() > threshold;
1514   }
1515 
1516   // A simplistic node request tracking mechanism, where
1517   //   = UINT_MAX   Request not valid or made final.
1518   //   < UINT_MAX   Nodes currently requested (estimate).
1519   uint _nodes_required;
1520 
1521   enum { REQUIRE_MIN = 70 };
1522 
1523   uint nodes_required() const { return _nodes_required; }
1524 
1525   // Given the _currently_  available number of nodes, check  whether there is
< prev index next >