1235 IfNode* le = outer_loop_end();
1236 if (le == NULL) {
1237 return NULL;
1238 }
1239 Node* c = le->in(0);
1240 if (c == NULL || c->is_top()) {
1241 return NULL;
1242 }
1243 assert(c->Opcode() == Op_SafePoint, "broken outer loop");
1244 return c->as_SafePoint();
1245 }
1246
1247 SafePointNode* CountedLoopNode::outer_safepoint() const {
1248 LoopNode* l = outer_loop();
1249 if (l == NULL) {
1250 return NULL;
1251 }
1252 return l->outer_safepoint();
1253 }
1254
1255 Node* CountedLoopNode::skip_predicates() {
1256 if (is_main_loop()) {
1257 Node* ctrl = skip_strip_mined()->in(LoopNode::EntryControl);
1258 while (ctrl != NULL && ctrl->is_Proj() && ctrl->in(0)->is_If() &&
1259 ctrl->in(0)->as_If()->proj_out(1-ctrl->as_Proj()->_con)->outcnt() == 1 &&
1260 ctrl->in(0)->as_If()->proj_out(1-ctrl->as_Proj()->_con)->unique_out()->Opcode() == Op_Halt) {
1261 ctrl = ctrl->in(0)->in(0);
1262 }
1263
1264 return ctrl;
1265 }
1266 return in(LoopNode::EntryControl);
1267 }
1268
1269 void OuterStripMinedLoopNode::adjust_strip_mined_loop(PhaseIterGVN* igvn) {
1270 // Look for the outer & inner strip mined loop, reduce number of
1271 // iterations of the inner loop, set exit condition of outer loop,
1272 // construct required phi nodes for outer loop.
1273 CountedLoopNode* inner_cl = unique_ctrl_out()->as_CountedLoop();
1274 assert(inner_cl->is_strip_mined(), "inner loop should be strip mined");
1275 Node* inner_iv_phi = inner_cl->phi();
1276 if (inner_iv_phi == NULL) {
1277 IfNode* outer_le = outer_loop_end();
1278 Node* iff = igvn->transform(new IfNode(outer_le->in(0), outer_le->in(1), outer_le->_prob, outer_le->_fcnt));
1279 igvn->replace_node(outer_le, iff);
1280 inner_cl->clear_strip_mined();
1281 return;
1282 }
1283 CountedLoopEndNode* inner_cle = inner_cl->loopexit();
1284
1285 int stride = inner_cl->stride_con();
2354 }
2355
2356 #ifndef PRODUCT
2357 //------------------------------dump_head--------------------------------------
2358 // Dump 1 liner for loop header info
2359 void IdealLoopTree::dump_head( ) const {
2360 for (uint i=0; i<_nest; i++)
2361 tty->print(" ");
2362 tty->print("Loop: N%d/N%d ",_head->_idx,_tail->_idx);
2363 if (_irreducible) tty->print(" IRREDUCIBLE");
2364 Node* entry = _head->is_Loop() ? _head->as_Loop()->skip_strip_mined(-1)->in(LoopNode::EntryControl) : _head->in(LoopNode::EntryControl);
2365 Node* predicate = PhaseIdealLoop::find_predicate_insertion_point(entry, Deoptimization::Reason_loop_limit_check);
2366 if (predicate != NULL ) {
2367 tty->print(" limit_check");
2368 entry = entry->in(0)->in(0);
2369 }
2370 if (UseLoopPredicate) {
2371 entry = PhaseIdealLoop::find_predicate_insertion_point(entry, Deoptimization::Reason_predicate);
2372 if (entry != NULL) {
2373 tty->print(" predicated");
2374 }
2375 }
2376 if (_head->is_CountedLoop()) {
2377 CountedLoopNode *cl = _head->as_CountedLoop();
2378 tty->print(" counted");
2379
2380 Node* init_n = cl->init_trip();
2381 if (init_n != NULL && init_n->is_Con())
2382 tty->print(" [%d,", cl->init_trip()->get_int());
2383 else
2384 tty->print(" [int,");
2385 Node* limit_n = cl->limit();
2386 if (limit_n != NULL && limit_n->is_Con())
2387 tty->print("%d),", cl->limit()->get_int());
2388 else
2389 tty->print("int),");
2390 int stride_con = cl->stride_con();
2391 if (stride_con > 0) tty->print("+");
2392 tty->print("%d", stride_con);
2393
2461
2462 //---------------------collect_potentially_useful_predicates-----------------------
2463 // Helper function to collect potentially useful predicates to prevent them from
2464 // being eliminated by PhaseIdealLoop::eliminate_useless_predicates
2465 void PhaseIdealLoop::collect_potentially_useful_predicates(
2466 IdealLoopTree * loop, Unique_Node_List &useful_predicates) {
2467 if (loop->_child) { // child
2468 collect_potentially_useful_predicates(loop->_child, useful_predicates);
2469 }
2470
2471 // self (only loops that we can apply loop predication may use their predicates)
2472 if (loop->_head->is_Loop() &&
2473 !loop->_irreducible &&
2474 !loop->tail()->is_top()) {
2475 LoopNode* lpn = loop->_head->as_Loop();
2476 Node* entry = lpn->in(LoopNode::EntryControl);
2477 Node* predicate_proj = find_predicate(entry); // loop_limit_check first
2478 if (predicate_proj != NULL ) { // right pattern that can be used by loop predication
2479 assert(entry->in(0)->in(1)->in(1)->Opcode() == Op_Opaque1, "must be");
2480 useful_predicates.push(entry->in(0)->in(1)->in(1)); // good one
2481 entry = entry->in(0)->in(0);
2482 }
2483 predicate_proj = find_predicate(entry); // Predicate
2484 if (predicate_proj != NULL ) {
2485 useful_predicates.push(entry->in(0)->in(1)->in(1)); // good one
2486 }
2487 }
2488
2489 if (loop->_next) { // sibling
2490 collect_potentially_useful_predicates(loop->_next, useful_predicates);
2491 }
2492 }
2493
2494 //------------------------eliminate_useless_predicates-----------------------------
2495 // Eliminate all inserted predicates if they could not be used by loop predication.
2496 // Note: it will also eliminates loop limits check predicate since it also uses
2497 // Opaque1 node (see Parse::add_predicate()).
2498 void PhaseIdealLoop::eliminate_useless_predicates() {
2499 if (C->predicate_count() == 0)
2500 return; // no predicate left
2501
2502 Unique_Node_List useful_predicates; // to store useful predicates
2503 if (C->has_loops()) {
2504 collect_potentially_useful_predicates(_ltree_root->_child, useful_predicates);
2505 }
4148 while( early != legal ) { // While not at earliest legal
4149 #ifdef ASSERT
4150 if (legal->is_Start() && !early->is_Root()) {
4151 // Bad graph. Print idom path and fail.
4152 dump_bad_graph("Bad graph detected in build_loop_late", n, early, LCA);
4153 assert(false, "Bad graph detected in build_loop_late");
4154 }
4155 #endif
4156 // Find least loop nesting depth
4157 legal = idom(legal); // Bump up the IDOM tree
4158 // Check for lower nesting depth
4159 if( get_loop(legal)->_nest < get_loop(least)->_nest )
4160 least = legal;
4161 }
4162 assert(early == legal || legal != C->root(), "bad dominance of inputs");
4163
4164 // Try not to place code on a loop entry projection
4165 // which can inhibit range check elimination.
4166 if (least != early) {
4167 Node* ctrl_out = least->unique_ctrl_out();
4168 if (ctrl_out && ctrl_out->is_Loop() &&
4169 least == ctrl_out->in(LoopNode::EntryControl) &&
4170 (ctrl_out->is_CountedLoop() || ctrl_out->is_OuterStripMinedLoop())) {
4171 Node* least_dom = idom(least);
4172 if (get_loop(least_dom)->is_member(get_loop(least))) {
4173 least = least_dom;
4174 }
4175 }
4176 }
4177
4178 #ifdef ASSERT
4179 // If verifying, verify that 'verify_me' has a legal location
4180 // and choose it as our location.
4181 if( _verify_me ) {
4182 Node *v_ctrl = _verify_me->get_ctrl_no_update(n);
4183 Node *legal = LCA;
4184 while( early != legal ) { // While not at earliest legal
4185 if( legal == v_ctrl ) break; // Check for prior good location
4186 legal = idom(legal) ;// Bump up the IDOM tree
4187 }
4188 // Check for prior good location
4189 if( legal == v_ctrl ) least = legal; // Keep prior if found
4190 }
4191 #endif
4192
4193 // Assign discovered "here or above" point
|
1235 IfNode* le = outer_loop_end();
1236 if (le == NULL) {
1237 return NULL;
1238 }
1239 Node* c = le->in(0);
1240 if (c == NULL || c->is_top()) {
1241 return NULL;
1242 }
1243 assert(c->Opcode() == Op_SafePoint, "broken outer loop");
1244 return c->as_SafePoint();
1245 }
1246
1247 SafePointNode* CountedLoopNode::outer_safepoint() const {
1248 LoopNode* l = outer_loop();
1249 if (l == NULL) {
1250 return NULL;
1251 }
1252 return l->outer_safepoint();
1253 }
1254
1255 Node* CountedLoopNode::skip_predicates_from_entry(Node* ctrl) {
1256 while (ctrl != NULL && ctrl->is_Proj() && ctrl->in(0)->is_If() &&
1257 ctrl->in(0)->as_If()->proj_out(1-ctrl->as_Proj()->_con)->outcnt() == 1 &&
1258 ctrl->in(0)->as_If()->proj_out(1-ctrl->as_Proj()->_con)->unique_out()->Opcode() == Op_Halt) {
1259 ctrl = ctrl->in(0)->in(0);
1260 }
1261
1262 return ctrl;
1263 }
1264
1265 Node* CountedLoopNode::skip_predicates() {
1266 if (is_main_loop()) {
1267 Node* ctrl = skip_strip_mined()->in(LoopNode::EntryControl);
1268
1269 return skip_predicates_from_entry(ctrl);
1270 }
1271 return in(LoopNode::EntryControl);
1272 }
1273
1274 void OuterStripMinedLoopNode::adjust_strip_mined_loop(PhaseIterGVN* igvn) {
1275 // Look for the outer & inner strip mined loop, reduce number of
1276 // iterations of the inner loop, set exit condition of outer loop,
1277 // construct required phi nodes for outer loop.
1278 CountedLoopNode* inner_cl = unique_ctrl_out()->as_CountedLoop();
1279 assert(inner_cl->is_strip_mined(), "inner loop should be strip mined");
1280 Node* inner_iv_phi = inner_cl->phi();
1281 if (inner_iv_phi == NULL) {
1282 IfNode* outer_le = outer_loop_end();
1283 Node* iff = igvn->transform(new IfNode(outer_le->in(0), outer_le->in(1), outer_le->_prob, outer_le->_fcnt));
1284 igvn->replace_node(outer_le, iff);
1285 inner_cl->clear_strip_mined();
1286 return;
1287 }
1288 CountedLoopEndNode* inner_cle = inner_cl->loopexit();
1289
1290 int stride = inner_cl->stride_con();
2359 }
2360
2361 #ifndef PRODUCT
2362 //------------------------------dump_head--------------------------------------
2363 // Dump 1 liner for loop header info
2364 void IdealLoopTree::dump_head( ) const {
2365 for (uint i=0; i<_nest; i++)
2366 tty->print(" ");
2367 tty->print("Loop: N%d/N%d ",_head->_idx,_tail->_idx);
2368 if (_irreducible) tty->print(" IRREDUCIBLE");
2369 Node* entry = _head->is_Loop() ? _head->as_Loop()->skip_strip_mined(-1)->in(LoopNode::EntryControl) : _head->in(LoopNode::EntryControl);
2370 Node* predicate = PhaseIdealLoop::find_predicate_insertion_point(entry, Deoptimization::Reason_loop_limit_check);
2371 if (predicate != NULL ) {
2372 tty->print(" limit_check");
2373 entry = entry->in(0)->in(0);
2374 }
2375 if (UseLoopPredicate) {
2376 entry = PhaseIdealLoop::find_predicate_insertion_point(entry, Deoptimization::Reason_predicate);
2377 if (entry != NULL) {
2378 tty->print(" predicated");
2379 entry = PhaseIdealLoop::skip_loop_predicates(entry);
2380 }
2381 }
2382 if (UseProfiledLoopPredicate) {
2383 entry = PhaseIdealLoop::find_predicate_insertion_point(entry, Deoptimization::Reason_profile_predicate);
2384 if (entry != NULL) {
2385 tty->print(" profile_predicated");
2386 }
2387 }
2388 if (_head->is_CountedLoop()) {
2389 CountedLoopNode *cl = _head->as_CountedLoop();
2390 tty->print(" counted");
2391
2392 Node* init_n = cl->init_trip();
2393 if (init_n != NULL && init_n->is_Con())
2394 tty->print(" [%d,", cl->init_trip()->get_int());
2395 else
2396 tty->print(" [int,");
2397 Node* limit_n = cl->limit();
2398 if (limit_n != NULL && limit_n->is_Con())
2399 tty->print("%d),", cl->limit()->get_int());
2400 else
2401 tty->print("int),");
2402 int stride_con = cl->stride_con();
2403 if (stride_con > 0) tty->print("+");
2404 tty->print("%d", stride_con);
2405
2473
2474 //---------------------collect_potentially_useful_predicates-----------------------
2475 // Helper function to collect potentially useful predicates to prevent them from
2476 // being eliminated by PhaseIdealLoop::eliminate_useless_predicates
2477 void PhaseIdealLoop::collect_potentially_useful_predicates(
2478 IdealLoopTree * loop, Unique_Node_List &useful_predicates) {
2479 if (loop->_child) { // child
2480 collect_potentially_useful_predicates(loop->_child, useful_predicates);
2481 }
2482
2483 // self (only loops that we can apply loop predication may use their predicates)
2484 if (loop->_head->is_Loop() &&
2485 !loop->_irreducible &&
2486 !loop->tail()->is_top()) {
2487 LoopNode* lpn = loop->_head->as_Loop();
2488 Node* entry = lpn->in(LoopNode::EntryControl);
2489 Node* predicate_proj = find_predicate(entry); // loop_limit_check first
2490 if (predicate_proj != NULL ) { // right pattern that can be used by loop predication
2491 assert(entry->in(0)->in(1)->in(1)->Opcode() == Op_Opaque1, "must be");
2492 useful_predicates.push(entry->in(0)->in(1)->in(1)); // good one
2493 entry = skip_loop_predicates(entry);
2494 }
2495 predicate_proj = find_predicate(entry); // Predicate
2496 if (predicate_proj != NULL ) {
2497 useful_predicates.push(entry->in(0)->in(1)->in(1)); // good one
2498 entry = skip_loop_predicates(entry);
2499 }
2500 if (UseProfiledLoopPredicate) {
2501 predicate_proj = find_predicate(entry); // Predicate
2502 if (predicate_proj != NULL ) {
2503 useful_predicates.push(entry->in(0)->in(1)->in(1)); // good one
2504 }
2505 }
2506 }
2507
2508 if (loop->_next) { // sibling
2509 collect_potentially_useful_predicates(loop->_next, useful_predicates);
2510 }
2511 }
2512
2513 //------------------------eliminate_useless_predicates-----------------------------
2514 // Eliminate all inserted predicates if they could not be used by loop predication.
2515 // Note: it will also eliminates loop limits check predicate since it also uses
2516 // Opaque1 node (see Parse::add_predicate()).
2517 void PhaseIdealLoop::eliminate_useless_predicates() {
2518 if (C->predicate_count() == 0)
2519 return; // no predicate left
2520
2521 Unique_Node_List useful_predicates; // to store useful predicates
2522 if (C->has_loops()) {
2523 collect_potentially_useful_predicates(_ltree_root->_child, useful_predicates);
2524 }
4167 while( early != legal ) { // While not at earliest legal
4168 #ifdef ASSERT
4169 if (legal->is_Start() && !early->is_Root()) {
4170 // Bad graph. Print idom path and fail.
4171 dump_bad_graph("Bad graph detected in build_loop_late", n, early, LCA);
4172 assert(false, "Bad graph detected in build_loop_late");
4173 }
4174 #endif
4175 // Find least loop nesting depth
4176 legal = idom(legal); // Bump up the IDOM tree
4177 // Check for lower nesting depth
4178 if( get_loop(legal)->_nest < get_loop(least)->_nest )
4179 least = legal;
4180 }
4181 assert(early == legal || legal != C->root(), "bad dominance of inputs");
4182
4183 // Try not to place code on a loop entry projection
4184 // which can inhibit range check elimination.
4185 if (least != early) {
4186 Node* ctrl_out = least->unique_ctrl_out();
4187 if (ctrl_out && ctrl_out->is_CountedLoop() &&
4188 least == ctrl_out->in(LoopNode::EntryControl)) {
4189 Node* new_ctrl = least;
4190 // Move the node above predicates so a following pass of loop
4191 // predication doesn't hoist a predicate that depends on it
4192 // above that node.
4193 if (find_predicate_insertion_point(new_ctrl, Deoptimization::Reason_loop_limit_check) != NULL) {
4194 new_ctrl = new_ctrl->in(0)->in(0);
4195 assert(is_dominator(early, new_ctrl), "least != early so we can move up the dominator tree");
4196 }
4197 if (find_predicate_insertion_point(new_ctrl, Deoptimization::Reason_profile_predicate) != NULL) {
4198 Node* c = new_ctrl->in(0)->in(0);
4199 assert(is_dominator(early, c), "least != early so we can move up the dominator tree");
4200 new_ctrl = c;
4201 }
4202 if (find_predicate_insertion_point(new_ctrl, Deoptimization::Reason_predicate) != NULL) {
4203 Node* c = new_ctrl->in(0)->in(0);
4204 assert(is_dominator(early, c), "least != early so we can move up the dominator tree");
4205 new_ctrl = c;
4206 }
4207 if (new_ctrl != ctrl_out) {
4208 least = new_ctrl;
4209 } else if (ctrl_out->is_CountedLoop() || ctrl_out->is_OuterStripMinedLoop()) {
4210 Node* least_dom = idom(least);
4211 if (get_loop(least_dom)->is_member(get_loop(least))) {
4212 least = least_dom;
4213 }
4214 }
4215 }
4216 }
4217
4218 #ifdef ASSERT
4219 // If verifying, verify that 'verify_me' has a legal location
4220 // and choose it as our location.
4221 if( _verify_me ) {
4222 Node *v_ctrl = _verify_me->get_ctrl_no_update(n);
4223 Node *legal = LCA;
4224 while( early != legal ) { // While not at earliest legal
4225 if( legal == v_ctrl ) break; // Check for prior good location
4226 legal = idom(legal) ;// Bump up the IDOM tree
4227 }
4228 // Check for prior good location
4229 if( legal == v_ctrl ) least = legal; // Keep prior if found
4230 }
4231 #endif
4232
4233 // Assign discovered "here or above" point
|