@@ -284,148 +284,3 @@ void PhaseIdealLoop::verify_fast_loop(LoopNode* head, const ProjNode* proj_true)
284284}
285285#endif // ASSERT
286286
287- LoopNode* PhaseIdealLoop::create_reserve_version_of_loop (IdealLoopTree *loop, CountedLoopReserveKit* lk) {
288- Node_List old_new;
289- LoopNode* head = loop->_head ->as_Loop ();
290- Node* entry = head->skip_strip_mined ()->in (LoopNode::EntryControl);
291- _igvn.rehash_node_delayed (entry);
292- IdealLoopTree* outer_loop = head->is_strip_mined () ? loop->_parent ->_parent : loop->_parent ;
293-
294- ConINode* const_1 = _igvn.intcon (1 );
295- set_ctrl (const_1, C->root ());
296- IfNode* iff = new IfNode (entry, const_1, PROB_MAX, COUNT_UNKNOWN);
297- register_node (iff, outer_loop, entry, dom_depth (entry));
298- ProjNode* iffast = new IfTrueNode (iff);
299- register_node (iffast, outer_loop, iff, dom_depth (iff));
300- ProjNode* ifslow = new IfFalseNode (iff);
301- register_node (ifslow, outer_loop, iff, dom_depth (iff));
302-
303- // Clone the loop body. The clone becomes the slow loop. The
304- // original pre-header will (illegally) have 3 control users
305- // (old & new loops & new if).
306- clone_loop (loop, old_new, dom_depth (head), CloneIncludesStripMined, iff);
307- assert (old_new[head->_idx ]->is_Loop (), " " );
308-
309- LoopNode* slow_head = old_new[head->_idx ]->as_Loop ();
310-
311- #ifndef PRODUCT
312- if (TraceLoopOpts) {
313- tty->print_cr (" PhaseIdealLoop::create_reserve_version_of_loop:" );
314- tty->print (" \t iff = %d, " , iff->_idx ); iff->dump ();
315- tty->print (" \t iffast = %d, " , iffast->_idx ); iffast->dump ();
316- tty->print (" \t ifslow = %d, " , ifslow->_idx ); ifslow->dump ();
317- tty->print (" \t before replace_input_of: head = %d, " , head->_idx ); head->dump ();
318- tty->print (" \t before replace_input_of: slow_head = %d, " , slow_head->_idx ); slow_head->dump ();
319- }
320- #endif
321-
322- // Fast (true) control
323- _igvn.replace_input_of (head->skip_strip_mined (), LoopNode::EntryControl, iffast);
324- // Slow (false) control
325- _igvn.replace_input_of (slow_head->skip_strip_mined (), LoopNode::EntryControl, ifslow);
326-
327- recompute_dom_depth ();
328-
329- lk->set_iff (iff);
330-
331- #ifndef PRODUCT
332- if (TraceLoopOpts ) {
333- tty->print (" \t after replace_input_of: head = %d, " , head->_idx ); head->dump ();
334- tty->print (" \t after replace_input_of: slow_head = %d, " , slow_head->_idx ); slow_head->dump ();
335- }
336- #endif
337-
338- return slow_head->as_Loop ();
339- }
340-
341- CountedLoopReserveKit::CountedLoopReserveKit (PhaseIdealLoop* phase, IdealLoopTree *loop, bool active = true ) :
342- _phase(phase),
343- _lpt(loop),
344- _lp(nullptr ),
345- _iff(nullptr ),
346- _lp_reserved(nullptr ),
347- _has_reserved(false ),
348- _use_new(false ),
349- _active(active)
350- {
351- create_reserve ();
352- };
353-
354- CountedLoopReserveKit::~CountedLoopReserveKit () {
355- if (!_active) {
356- return ;
357- }
358-
359- if (_has_reserved && !_use_new) {
360- // intcon(0)->iff-node reverts CF to the reserved copy
361- ConINode* const_0 = _phase->_igvn .intcon (0 );
362- _phase->set_ctrl (const_0, _phase->C ->root ());
363- _iff->set_req (1 , const_0);
364-
365- #ifndef PRODUCT
366- if (TraceLoopOpts) {
367- tty->print_cr (" CountedLoopReserveKit::~CountedLoopReserveKit()" );
368- tty->print (" \t discard loop %d and revert to the reserved loop clone %d: " , _lp->_idx , _lp_reserved->_idx );
369- _lp_reserved->dump ();
370- }
371- #endif
372- }
373- }
374-
375- bool CountedLoopReserveKit::create_reserve () {
376- if (!_active) {
377- return false ;
378- }
379-
380- if (!_lpt->_head ->is_CountedLoop ()) {
381- if (TraceLoopOpts) {
382- tty->print_cr (" CountedLoopReserveKit::create_reserve: %d not counted loop" , _lpt->_head ->_idx );
383- }
384- return false ;
385- }
386- CountedLoopNode *cl = _lpt->_head ->as_CountedLoop ();
387- if (!cl->is_valid_counted_loop (T_INT)) {
388- if (TraceLoopOpts) {
389- tty->print_cr (" CountedLoopReserveKit::create_reserve: %d not valid counted loop" , cl->_idx );
390- }
391- return false ; // skip malformed counted loop
392- }
393- if (!cl->is_main_loop ()) {
394- bool loop_not_canonical = true ;
395- if (cl->is_post_loop () && (cl->slp_max_unroll () > 0 )) {
396- loop_not_canonical = false ;
397- }
398- // only reject some loop forms
399- if (loop_not_canonical) {
400- if (TraceLoopOpts) {
401- tty->print_cr (" CountedLoopReserveKit::create_reserve: %d not canonical loop" , cl->_idx );
402- }
403- return false ; // skip normal, pre, and post (conditionally) loops
404- }
405- }
406-
407- _lp = _lpt->_head ->as_Loop ();
408- _lp_reserved = _phase->create_reserve_version_of_loop (_lpt, this );
409-
410- if (!_lp_reserved->is_CountedLoop ()) {
411- return false ;
412- }
413-
414- Node* ifslow_pred = _lp_reserved->skip_strip_mined ()->in (LoopNode::EntryControl);
415-
416- if (!ifslow_pred->is_IfFalse ()) {
417- return false ;
418- }
419-
420- Node* iff = ifslow_pred->in (0 );
421- if (!iff->is_If () || iff != _iff) {
422- return false ;
423- }
424-
425- if (iff->in (1 )->Opcode () != Op_ConI) {
426- return false ;
427- }
428-
429- _has_reserved = true ;
430- return true ;
431- }
0 commit comments