< prev index next >

src/hotspot/share/opto/loopPredicate.cpp

Print this page




 284     igvn->register_new_node_with_optimizer(opq);
 285     igvn->register_new_node_with_optimizer(bol);
 286   }
 287   igvn->hash_delete(iff);
 288   iff->set_req(1, bol);
 289   return new_predicate_proj;
 290 }
 291 
 292 
 293 //--------------------------clone_loop_predicates-----------------------
 294 // Interface from IGVN
 295 Node* PhaseIterGVN::clone_loop_predicates(Node* old_entry, Node* new_entry, bool clone_limit_check) {
 296   return PhaseIdealLoop::clone_loop_predicates(old_entry, new_entry, clone_limit_check, NULL, this);
 297 }
 298 
 299 // Interface from PhaseIdealLoop
 300 Node* PhaseIdealLoop::clone_loop_predicates(Node* old_entry, Node* new_entry, bool clone_limit_check) {
 301   return clone_loop_predicates(old_entry, new_entry, clone_limit_check, this, &this->_igvn);
 302 }
 303 






































































 304 // Clone loop predicates to cloned loops (peeled, unswitched, split_if).
 305 Node* PhaseIdealLoop::clone_loop_predicates(Node* old_entry, Node* new_entry,
 306                                             bool clone_limit_check,
 307                                             PhaseIdealLoop* loop_phase,
 308                                             PhaseIterGVN* igvn) {
 309 #ifdef ASSERT
 310   if (new_entry == NULL || !(new_entry->is_Proj() || new_entry->is_Region() || new_entry->is_SafePoint())) {
 311     if (new_entry != NULL)
 312       new_entry->dump();
 313     assert(false, "not IfTrue, IfFalse, Region or SafePoint");
 314   }
 315 #endif
 316   // Search original predicates
 317   Node* entry = old_entry;
 318   ProjNode* limit_check_proj = NULL;
 319   limit_check_proj = find_predicate_insertion_point(entry, Deoptimization::Reason_loop_limit_check);
 320   if (limit_check_proj != NULL) {
 321     entry = skip_loop_predicates(entry);
 322   }
 323   ProjNode* profile_predicate_proj = NULL;
 324   ProjNode* predicate_proj = NULL;
 325   if (UseProfiledLoopPredicate) {
 326     profile_predicate_proj = find_predicate_insertion_point(entry, Deoptimization::Reason_profile_predicate);
 327     if (profile_predicate_proj != NULL) {
 328       entry = skip_loop_predicates(entry);
 329     }
 330   }
 331   if (UseLoopPredicate) {
 332     predicate_proj = find_predicate_insertion_point(entry, Deoptimization::Reason_predicate);
 333   }
 334   if (predicate_proj != NULL) { // right pattern that can be used by loop predication
 335     // clone predicate
 336     new_entry = clone_predicate(predicate_proj, new_entry,
 337                                 Deoptimization::Reason_predicate,
 338                                 loop_phase, igvn);
 339     assert(new_entry != NULL && new_entry->is_Proj(), "IfTrue or IfFalse after clone predicate");

 340     if (TraceLoopPredicate) {
 341       tty->print("Loop Predicate cloned: ");
 342       debug_only( new_entry->in(0)->dump(); );









 343     }
 344   }
 345   if (profile_predicate_proj != NULL) { // right pattern that can be used by loop predication
 346     // clone predicate
 347     new_entry = clone_predicate(profile_predicate_proj, new_entry,
 348                                 Deoptimization::Reason_profile_predicate,
 349                                 loop_phase, igvn);
 350     assert(new_entry != NULL && new_entry->is_Proj(), "IfTrue or IfFalse after clone predicate");
 351     if (TraceLoopPredicate) {
 352       tty->print("Loop Predicate cloned: ");
 353       debug_only( new_entry->in(0)->dump(); );
 354     }
 355   }
 356   if (limit_check_proj != NULL && clone_limit_check) {
 357     // Clone loop limit check last to insert it before loop.
 358     // Don't clone a limit check which was already finalized
 359     // for this counted loop (only one limit check is needed).
 360     new_entry = clone_predicate(limit_check_proj, new_entry,
 361                                 Deoptimization::Reason_loop_limit_check,
 362                                 loop_phase, igvn);




 284     igvn->register_new_node_with_optimizer(opq);
 285     igvn->register_new_node_with_optimizer(bol);
 286   }
 287   igvn->hash_delete(iff);
 288   iff->set_req(1, bol);
 289   return new_predicate_proj;
 290 }
 291 
 292 
 293 //--------------------------clone_loop_predicates-----------------------
 294 // Interface from IGVN
 295 Node* PhaseIterGVN::clone_loop_predicates(Node* old_entry, Node* new_entry, bool clone_limit_check) {
 296   return PhaseIdealLoop::clone_loop_predicates(old_entry, new_entry, clone_limit_check, NULL, this);
 297 }
 298 
 299 // Interface from PhaseIdealLoop
 300 Node* PhaseIdealLoop::clone_loop_predicates(Node* old_entry, Node* new_entry, bool clone_limit_check) {
 301   return clone_loop_predicates(old_entry, new_entry, clone_limit_check, this, &this->_igvn);
 302 }
 303 
 304 void PhaseIdealLoop::clone_loop_predicates_fix_mem(ProjNode* dom_proj , ProjNode* proj,
 305                                                    PhaseIdealLoop* loop_phase,
 306                                                    PhaseIterGVN* igvn) {
 307   if (!UseShenandoahGC) {
 308     return;
 309   }
 310   Compile* C = NULL;
 311   if (loop_phase != NULL) {
 312     igvn = &loop_phase->igvn();
 313   }
 314   C = igvn->C;
 315   ProjNode* other_dom_proj = dom_proj->in(0)->as_Multi()->proj_out(1-dom_proj->_con);
 316   Node* dom_r = other_dom_proj->unique_ctrl_out();
 317   if (dom_r->is_Region()) {
 318     assert(dom_r->unique_ctrl_out()->is_Call(), "unc expected");
 319     ProjNode* other_proj = proj->in(0)->as_Multi()->proj_out(1-proj->_con);
 320     Node* r = other_proj->unique_ctrl_out();
 321     assert(r->is_Region() && r->unique_ctrl_out()->is_Call(), "cloned predicate should have caused region to be added");
 322     for (DUIterator_Fast imax, i = dom_r->fast_outs(imax); i < imax; i++) {
 323       Node* dom_use = dom_r->fast_out(i);
 324       if (dom_use->is_Phi() && dom_use->bottom_type() == Type::MEMORY) {
 325         assert(dom_use->in(0) == dom_r, "");
 326         Node* phi = NULL;
 327         for (DUIterator_Fast jmax, j = r->fast_outs(jmax); j < jmax; j++) {
 328           Node* use = r->fast_out(j);
 329           if (use->is_Phi() && use->bottom_type() == Type::MEMORY &&
 330               use->adr_type() == dom_use->adr_type()) {
 331             assert(use->in(0) == r, "");
 332             assert(phi == NULL, "only one phi");
 333             phi = use;
 334           }
 335         }
 336         if (phi == NULL) {
 337           const TypePtr* adr_type = dom_use->adr_type();
 338           int alias = C->get_alias_index(adr_type);
 339           Node* call = r->unique_ctrl_out();
 340           Node* mem = call->in(TypeFunc::Memory);
 341           MergeMemNode* mm = NULL;
 342           if (mem->is_MergeMem()) {
 343             mm = mem->clone()->as_MergeMem();
 344             if (adr_type == TypePtr::BOTTOM) {
 345               mem = mem->as_MergeMem()->base_memory();
 346             } else {
 347               mem = mem->as_MergeMem()->memory_at(alias);
 348             }
 349           } else {
 350             mm = MergeMemNode::make(mem);
 351           }
 352           phi = PhiNode::make(r, mem, Type::MEMORY, adr_type);
 353           if (adr_type == TypePtr::BOTTOM) {
 354             mm->set_base_memory(phi);
 355           } else {
 356             mm->set_memory_at(alias, phi);
 357           }
 358           if (loop_phase != NULL) {
 359             loop_phase->register_new_node(mm, r);
 360             loop_phase->register_new_node(phi, r);
 361           } else {
 362             igvn->register_new_node_with_optimizer(mm);
 363             igvn->register_new_node_with_optimizer(phi);
 364           }
 365           igvn->replace_input_of(call, TypeFunc::Memory, mm);
 366         }
 367         igvn->replace_input_of(phi, r->req()-1, dom_use->in(dom_r->find_edge(other_dom_proj)));
 368       }
 369     }
 370   }
 371 }
 372 
 373 
 374 // Clone loop predicates to cloned loops (peeled, unswitched, split_if).
 375 Node* PhaseIdealLoop::clone_loop_predicates(Node* old_entry, Node* new_entry,
 376                                             bool clone_limit_check,
 377                                             PhaseIdealLoop* loop_phase,
 378                                             PhaseIterGVN* igvn) {
 379 #ifdef ASSERT
 380   if (new_entry == NULL || !(new_entry->is_Proj() || new_entry->is_Region() || new_entry->is_SafePoint())) {
 381     if (new_entry != NULL)
 382       new_entry->dump();
 383     assert(false, "not IfTrue, IfFalse, Region or SafePoint");
 384   }
 385 #endif
 386   // Search original predicates
 387   Node* entry = old_entry;
 388   ProjNode* limit_check_proj = NULL;
 389   limit_check_proj = find_predicate_insertion_point(entry, Deoptimization::Reason_loop_limit_check);
 390   if (limit_check_proj != NULL) {
 391     entry = skip_loop_predicates(entry);
 392   }
 393   ProjNode* profile_predicate_proj = NULL;
 394   ProjNode* predicate_proj = NULL;
 395   if (UseProfiledLoopPredicate) {
 396     profile_predicate_proj = find_predicate_insertion_point(entry, Deoptimization::Reason_profile_predicate);
 397     if (profile_predicate_proj != NULL) {
 398       entry = skip_loop_predicates(entry);
 399     }
 400   }
 401   if (UseLoopPredicate) {
 402     predicate_proj = find_predicate_insertion_point(entry, Deoptimization::Reason_predicate);
 403   }
 404   if (predicate_proj != NULL) { // right pattern that can be used by loop predication
 405     // clone predicate
 406     ProjNode* proj = clone_predicate(predicate_proj, new_entry,
 407                                      Deoptimization::Reason_predicate,
 408                                      loop_phase, igvn);
 409     assert(proj != NULL, "IfTrue or IfFalse after clone predicate");
 410     new_entry = proj;
 411     if (TraceLoopPredicate) {
 412       tty->print("Loop Predicate cloned: ");
 413       debug_only( new_entry->in(0)->dump(); );
 414     }
 415     if (profile_predicate_proj != NULL) {
 416       // A node that produces memory may be out of loop and depend on
 417       // a profiled predicates. In that case the memory state at the
 418       // end of profiled predicates and at the end of predicates are
 419       // not the same. The cloned predicates are dominated by the
 420       // profiled predicates but may have the wrong memory
 421       // state. Update it.
 422       clone_loop_predicates_fix_mem(profile_predicate_proj, proj, loop_phase, igvn);
 423     }
 424   }
 425   if (profile_predicate_proj != NULL) { // right pattern that can be used by loop predication
 426     // clone predicate
 427     new_entry = clone_predicate(profile_predicate_proj, new_entry,
 428                                 Deoptimization::Reason_profile_predicate,
 429                                 loop_phase, igvn);
 430     assert(new_entry != NULL && new_entry->is_Proj(), "IfTrue or IfFalse after clone predicate");
 431     if (TraceLoopPredicate) {
 432       tty->print("Loop Predicate cloned: ");
 433       debug_only( new_entry->in(0)->dump(); );
 434     }
 435   }
 436   if (limit_check_proj != NULL && clone_limit_check) {
 437     // Clone loop limit check last to insert it before loop.
 438     // Don't clone a limit check which was already finalized
 439     // for this counted loop (only one limit check is needed).
 440     new_entry = clone_predicate(limit_check_proj, new_entry,
 441                                 Deoptimization::Reason_loop_limit_check,
 442                                 loop_phase, igvn);


< prev index next >