21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "opto/addnode.hpp"
27 #include "opto/callnode.hpp"
28 #include "opto/cfgnode.hpp"
29 #include "opto/idealKit.hpp"
30 #include "opto/runtime.hpp"
31
32 // Static initialization
33
34 // This declares the position where vars are kept in the cvstate
35 // For some degree of consistency we use the TypeFunc enum to
36 // soak up spots in the inputs even though we only use early Control
37 // and Memory slots. (So far.)
38 const uint IdealKit::first_var = TypeFunc::Parms + 1;
39
40 //----------------------------IdealKit-----------------------------------------
41 IdealKit::IdealKit(PhaseGVN &gvn, Node* control, Node* mem, bool delay_all_transforms, bool has_declarations) :
42 _gvn(gvn), C(gvn.C) {
43 _initial_ctrl = control;
44 _initial_memory = mem;
45 _delay_all_transforms = delay_all_transforms;
46 _var_ct = 0;
47 _cvstate = NULL;
48 // We can go memory state free or else we need the entire memory state
49 assert(mem == NULL || mem->Opcode() == Op_MergeMem, "memory must be pre-split");
50 int init_size = 5;
51 _pending_cvstates = new (C->node_arena()) GrowableArray<Node*>(C->node_arena(), init_size, 0, 0);
52 _delay_transform = new (C->node_arena()) GrowableArray<Node*>(C->node_arena(), init_size, 0, 0);
53 DEBUG_ONLY(_state = new (C->node_arena()) GrowableArray<int>(C->node_arena(), init_size, 0, 0));
54 if (!has_declarations) {
55 declarations_done();
56 }
57 }
58
59 //-------------------------------if_then-------------------------------------
60 // Create: if(left relop right)
61 // / \
62 // iffalse iftrue
63 // Push the iffalse cvstate onto the stack. The iftrue becomes the current cvstate.
64 void IdealKit::if_then(Node* left, BoolTest::mask relop,
65 Node* right, float prob, float cnt, bool push_new_state) {
66 assert((state() & (BlockS|LoopS|IfThenS|ElseS)), "bad state for new If");
67 Node* bol;
68 if (left->bottom_type()->isa_ptr() == NULL) {
69 if (left->bottom_type()->isa_int() != NULL) {
70 bol = Bool(CmpI(left, right), relop);
71 } else {
72 assert(left->bottom_type()->isa_long() != NULL, "what else?");
73 bol = Bool(CmpL(left, right), relop);
74 }
75
76 } else {
77 bol = Bool(CmpP(left, right), relop);
78 }
139 _cvstate = _pending_cvstates->pop();
140
141 bind(lab);
142 DEBUG_ONLY(_state->pop());
143 }
144
145 //-------------------------------loop-------------------------------------
146 // Create the loop head portion (*) of:
147 // * iv = init
148 // * top: (region node)
149 // * if (iv relop limit) {
150 // loop body
151 // i = i + 1
152 // goto top
153 // * } else // exits loop
154 //
155 // Pushes the loop top cvstate first, then the else (loop exit) cvstate
156 // onto the stack.
157 void IdealKit::loop(GraphKit* gkit, int nargs, IdealVariable& iv, Node* init, BoolTest::mask relop, Node* limit, float prob, float cnt) {
158 assert((state() & (BlockS|LoopS|IfThenS|ElseS)), "bad state for new loop");
159
160 // Sync IdealKit and graphKit.
161 gkit->set_all_memory(this->merged_memory());
162 gkit->set_control(this->ctrl());
163 // Add loop predicate.
164 gkit->add_predicate(nargs);
165 // Update IdealKit memory.
166 this->set_all_memory(gkit->merged_memory());
167 this->set_ctrl(gkit->control());
168
169 set(iv, init);
170 Node* head = make_label(1);
171 bind(head);
172 _pending_cvstates->push(head); // push for use at end_loop
173 _cvstate = copy_cvstate();
174 if_then(value(iv), relop, limit, prob, cnt, false /* no new state */);
175 DEBUG_ONLY(_state->push(LoopS));
176 assert(ctrl()->is_IfTrue(), "true branch stays in loop");
177 assert(_pending_cvstates->top()->in(TypeFunc::Control)->is_IfFalse(), "false branch exits loop");
178 }
179
180 //-------------------------------end_loop-------------------------------------
181 // Creates the goto top label.
182 // Expects the else (loop exit) cvstate to be on top of the
183 // stack, and the loop top cvstate to be 2nd.
184 void IdealKit::end_loop() {
185 assert((state() == LoopS), "bad state for new end_loop");
186 Node* exit = _pending_cvstates->pop();
187 Node* head = _pending_cvstates->pop();
188 goto_(head);
263 }
264 }
265 do_memory_merge(_cvstate, lab);
266 stop();
267 }
268
269 //-----------------------------promote_to_phi-----------------------------------
270 Node* IdealKit::promote_to_phi(Node* n, Node* reg) {
271 assert(!was_promoted_to_phi(n, reg), "n already promoted to phi on this region");
272 // Get a conservative type for the phi
273 const BasicType bt = n->bottom_type()->basic_type();
274 const Type* ct = Type::get_const_basic_type(bt);
275 return delay_transform(PhiNode::make(reg, n, ct));
276 }
277
278 //-----------------------------declarations_done-------------------------------
279 void IdealKit::declarations_done() {
280 _cvstate = new_cvstate(); // initialize current cvstate
281 set_ctrl(_initial_ctrl); // initialize control in current cvstate
282 set_all_memory(_initial_memory);// initialize memory in current cvstate
283 DEBUG_ONLY(_state->push(BlockS));
284 }
285
286 //-----------------------------transform-----------------------------------
287 Node* IdealKit::transform(Node* n) {
288 if (_delay_all_transforms) {
289 return delay_transform(n);
290 } else {
291 return gvn().transform(n);
292 }
293 }
294
295 //-----------------------------delay_transform-----------------------------------
296 Node* IdealKit::delay_transform(Node* n) {
297 if (!gvn().is_IterGVN() || !gvn().is_IterGVN()->delay_transform()) {
298 gvn().set_type(n, n->bottom_type());
299 }
300 _delay_transform->push(n);
301 return n;
302 }
404 // Convert required edge to precedence edge before allocation.
405 Node* st = new (C, 5) StoreCMNode(ctl, mem, adr, adr_type, val, oop_store, oop_adr_idx);
406
407 st = transform(st);
408 set_memory(st, adr_idx);
409
410 return st;
411 }
412
413 //---------------------------- do_memory_merge --------------------------------
414 // The memory from one merging cvstate needs to be merged with the memory for another
415 // join cvstate. If the join cvstate doesn't have a merged memory yet then we
416 // can just copy the state from the merging cvstate
417
418 // Merge one slow path into the rest of memory.
419 void IdealKit::do_memory_merge(Node* merging, Node* join) {
420
421 // Get the region for the join state
422 Node* join_region = join->in(TypeFunc::Control);
423 assert(join_region != NULL, "join region must exist");
424 if (join->in(TypeFunc::Memory) == NULL ) {
425 join->set_req(TypeFunc::Memory, merging->in(TypeFunc::Memory));
426 return;
427 }
428
429 // The control flow for merging must have already been attached to the join region
430 // we need its index for the phis.
431 uint slot;
432 for (slot = 1; slot < join_region->req() ; slot ++ ) {
433 if (join_region->in(slot) == merging->in(TypeFunc::Control)) break;
434 }
435 assert(slot != join_region->req(), "edge must already exist");
436
437 MergeMemNode* join_m = join->in(TypeFunc::Memory)->as_MergeMem();
438 MergeMemNode* merging_m = merging->in(TypeFunc::Memory)->as_MergeMem();
439
440 // join_m should be an ancestor mergemem of merging
441 // Slow path memory comes from the current map (which is from a slow call)
442 // Fast path/null path memory comes from the call's input
443
450 PhiNode* phi;
451 // bool new_phi = false;
452 // Is the phi for this slice one that we created for this join region or simply
453 // one we copied? If it is ours then add
454 if (join_slice->is_Phi() && join_slice->as_Phi()->region() == join_region) {
455 phi = join_slice->as_Phi();
456 } else {
457 // create the phi with join_slice filling supplying memory for all of the
458 // control edges to the join region
459 phi = PhiNode::make(join_region, join_slice, Type::MEMORY, mms.adr_type(C));
460 phi = (PhiNode*) delay_transform(phi);
461 // gvn().set_type(phi, Type::MEMORY);
462 // new_phi = true;
463 }
464 // Now update the phi with the slice for the merging slice
465 phi->set_req(slot, merging_slice/* slow_path, slow_slice */);
466 // this updates join_m with the phi
467 mms.set_memory(phi);
468 }
469 }
470 }
471
472
473 //----------------------------- make_call ----------------------------
474 // Trivial runtime call
475 void IdealKit::make_leaf_call(const TypeFunc *slow_call_type,
476 address slow_call,
477 const char *leaf_name,
478 Node* parm0,
479 Node* parm1,
480 Node* parm2) {
481
482 // We only handle taking in RawMem and modifying RawMem
483 const TypePtr* adr_type = TypeRawPtr::BOTTOM;
484 uint adr_idx = C->get_alias_index(adr_type);
485
486 // Slow-path leaf call
487 int size = slow_call_type->domain()->cnt();
488 CallNode *call = (CallNode*)new (C, size) CallLeafNode( slow_call_type, slow_call, leaf_name, adr_type);
489
490 // Set fixed predefined input arguments
491 call->init_req( TypeFunc::Control, ctrl() );
492 call->init_req( TypeFunc::I_O , top() ) ; // does no i/o
493 // Narrow memory as only memory input
494 call->init_req( TypeFunc::Memory , memory(adr_idx));
495 call->init_req( TypeFunc::FramePtr, top() /* frameptr() */ );
496 call->init_req( TypeFunc::ReturnAdr, top() );
497
498 if (parm0 != NULL) call->init_req(TypeFunc::Parms+0, parm0);
499 if (parm1 != NULL) call->init_req(TypeFunc::Parms+1, parm1);
500 if (parm2 != NULL) call->init_req(TypeFunc::Parms+2, parm2);
501
502 // Node *c = _gvn.transform(call);
503 call = (CallNode *) _gvn.transform(call);
504 Node *c = call; // dbx gets confused with call call->dump()
505
506 // Slow leaf call has no side-effects, sets few values
507
508 set_ctrl(transform( new (C, 1) ProjNode(call,TypeFunc::Control) ));
509
510 // Make memory for the call
511 Node* mem = _gvn.transform( new (C, 1) ProjNode(call, TypeFunc::Memory) );
512
513 // Set the RawPtr memory state only.
514 set_memory(mem, adr_idx);
515
516 assert(C->alias_type(call->adr_type()) == C->alias_type(adr_type),
517 "call node must be constructed correctly");
518 }
|
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "opto/addnode.hpp"
27 #include "opto/callnode.hpp"
28 #include "opto/cfgnode.hpp"
29 #include "opto/idealKit.hpp"
30 #include "opto/runtime.hpp"
31
32 // Static initialization
33
34 // This declares the position where vars are kept in the cvstate
35 // For some degree of consistency we use the TypeFunc enum to
36 // soak up spots in the inputs even though we only use early Control
37 // and Memory slots. (So far.)
38 const uint IdealKit::first_var = TypeFunc::Parms + 1;
39
40 //----------------------------IdealKit-----------------------------------------
41 IdealKit::IdealKit(GraphKit* gkit, bool delay_all_transforms, bool has_declarations) :
42 _gvn(gkit->gvn()), C(gkit->C) {
43 _initial_ctrl = gkit->control();
44 _initial_memory = gkit->merged_memory();
45 _initial_i_o = gkit->i_o();
46 _delay_all_transforms = delay_all_transforms;
47 _var_ct = 0;
48 _cvstate = NULL;
49 // We can go memory state free or else we need the entire memory state
50 assert(_initial_memory == NULL || _initial_memory->Opcode() == Op_MergeMem, "memory must be pre-split");
51 int init_size = 5;
52 _pending_cvstates = new (C->node_arena()) GrowableArray<Node*>(C->node_arena(), init_size, 0, 0);
53 _delay_transform = new (C->node_arena()) GrowableArray<Node*>(C->node_arena(), init_size, 0, 0);
54 DEBUG_ONLY(_state = new (C->node_arena()) GrowableArray<int>(C->node_arena(), init_size, 0, 0));
55 if (!has_declarations) {
56 declarations_done();
57 }
58 }
59
60 //----------------------------sync_kit-----------------------------------------
61 void IdealKit::sync_kit(GraphKit* gkit) {
62 set_all_memory(gkit->merged_memory());
63 set_i_o(gkit->i_o());
64 set_ctrl(gkit->control());
65 }
66
67 //-------------------------------if_then-------------------------------------
68 // Create: if(left relop right)
69 // / \
70 // iffalse iftrue
71 // Push the iffalse cvstate onto the stack. The iftrue becomes the current cvstate.
72 void IdealKit::if_then(Node* left, BoolTest::mask relop,
73 Node* right, float prob, float cnt, bool push_new_state) {
74 assert((state() & (BlockS|LoopS|IfThenS|ElseS)), "bad state for new If");
75 Node* bol;
76 if (left->bottom_type()->isa_ptr() == NULL) {
77 if (left->bottom_type()->isa_int() != NULL) {
78 bol = Bool(CmpI(left, right), relop);
79 } else {
80 assert(left->bottom_type()->isa_long() != NULL, "what else?");
81 bol = Bool(CmpL(left, right), relop);
82 }
83
84 } else {
85 bol = Bool(CmpP(left, right), relop);
86 }
147 _cvstate = _pending_cvstates->pop();
148
149 bind(lab);
150 DEBUG_ONLY(_state->pop());
151 }
152
153 //-------------------------------loop-------------------------------------
154 // Create the loop head portion (*) of:
155 // * iv = init
156 // * top: (region node)
157 // * if (iv relop limit) {
158 // loop body
159 // i = i + 1
160 // goto top
161 // * } else // exits loop
162 //
163 // Pushes the loop top cvstate first, then the else (loop exit) cvstate
164 // onto the stack.
165 void IdealKit::loop(GraphKit* gkit, int nargs, IdealVariable& iv, Node* init, BoolTest::mask relop, Node* limit, float prob, float cnt) {
166 assert((state() & (BlockS|LoopS|IfThenS|ElseS)), "bad state for new loop");
167 if (UseLoopPredicate) {
168 // Sync IdealKit and graphKit.
169 gkit->sync_kit(*this, false);
170 // Add loop predicate.
171 gkit->add_predicate(nargs);
172 // Update IdealKit memory.
173 sync_kit(gkit);
174 }
175 set(iv, init);
176 Node* head = make_label(1);
177 bind(head);
178 _pending_cvstates->push(head); // push for use at end_loop
179 _cvstate = copy_cvstate();
180 if_then(value(iv), relop, limit, prob, cnt, false /* no new state */);
181 DEBUG_ONLY(_state->push(LoopS));
182 assert(ctrl()->is_IfTrue(), "true branch stays in loop");
183 assert(_pending_cvstates->top()->in(TypeFunc::Control)->is_IfFalse(), "false branch exits loop");
184 }
185
186 //-------------------------------end_loop-------------------------------------
187 // Creates the goto top label.
188 // Expects the else (loop exit) cvstate to be on top of the
189 // stack, and the loop top cvstate to be 2nd.
190 void IdealKit::end_loop() {
191 assert((state() == LoopS), "bad state for new end_loop");
192 Node* exit = _pending_cvstates->pop();
193 Node* head = _pending_cvstates->pop();
194 goto_(head);
269 }
270 }
271 do_memory_merge(_cvstate, lab);
272 stop();
273 }
274
275 //-----------------------------promote_to_phi-----------------------------------
276 Node* IdealKit::promote_to_phi(Node* n, Node* reg) {
277 assert(!was_promoted_to_phi(n, reg), "n already promoted to phi on this region");
278 // Get a conservative type for the phi
279 const BasicType bt = n->bottom_type()->basic_type();
280 const Type* ct = Type::get_const_basic_type(bt);
281 return delay_transform(PhiNode::make(reg, n, ct));
282 }
283
284 //-----------------------------declarations_done-------------------------------
285 void IdealKit::declarations_done() {
286 _cvstate = new_cvstate(); // initialize current cvstate
287 set_ctrl(_initial_ctrl); // initialize control in current cvstate
288 set_all_memory(_initial_memory);// initialize memory in current cvstate
289 set_i_o(_initial_i_o); // initialize i_o in current cvstate
290 DEBUG_ONLY(_state->push(BlockS));
291 }
292
293 //-----------------------------transform-----------------------------------
294 Node* IdealKit::transform(Node* n) {
295 if (_delay_all_transforms) {
296 return delay_transform(n);
297 } else {
298 return gvn().transform(n);
299 }
300 }
301
302 //-----------------------------delay_transform-----------------------------------
303 Node* IdealKit::delay_transform(Node* n) {
304 if (!gvn().is_IterGVN() || !gvn().is_IterGVN()->delay_transform()) {
305 gvn().set_type(n, n->bottom_type());
306 }
307 _delay_transform->push(n);
308 return n;
309 }
411 // Convert required edge to precedence edge before allocation.
412 Node* st = new (C, 5) StoreCMNode(ctl, mem, adr, adr_type, val, oop_store, oop_adr_idx);
413
414 st = transform(st);
415 set_memory(st, adr_idx);
416
417 return st;
418 }
419
420 //---------------------------- do_memory_merge --------------------------------
421 // The memory from one merging cvstate needs to be merged with the memory for another
422 // join cvstate. If the join cvstate doesn't have a merged memory yet then we
423 // can just copy the state from the merging cvstate
424
425 // Merge one slow path into the rest of memory.
426 void IdealKit::do_memory_merge(Node* merging, Node* join) {
427
428 // Get the region for the join state
429 Node* join_region = join->in(TypeFunc::Control);
430 assert(join_region != NULL, "join region must exist");
431 if (join->in(TypeFunc::I_O) == NULL ) {
432 join->set_req(TypeFunc::I_O, merging->in(TypeFunc::I_O));
433 }
434 if (join->in(TypeFunc::Memory) == NULL ) {
435 join->set_req(TypeFunc::Memory, merging->in(TypeFunc::Memory));
436 return;
437 }
438
439 // The control flow for merging must have already been attached to the join region
440 // we need its index for the phis.
441 uint slot;
442 for (slot = 1; slot < join_region->req() ; slot ++ ) {
443 if (join_region->in(slot) == merging->in(TypeFunc::Control)) break;
444 }
445 assert(slot != join_region->req(), "edge must already exist");
446
447 MergeMemNode* join_m = join->in(TypeFunc::Memory)->as_MergeMem();
448 MergeMemNode* merging_m = merging->in(TypeFunc::Memory)->as_MergeMem();
449
450 // join_m should be an ancestor mergemem of merging
451 // Slow path memory comes from the current map (which is from a slow call)
452 // Fast path/null path memory comes from the call's input
453
460 PhiNode* phi;
461 // bool new_phi = false;
462 // Is the phi for this slice one that we created for this join region or simply
463 // one we copied? If it is ours then add
464 if (join_slice->is_Phi() && join_slice->as_Phi()->region() == join_region) {
465 phi = join_slice->as_Phi();
466 } else {
467 // create the phi with join_slice filling supplying memory for all of the
468 // control edges to the join region
469 phi = PhiNode::make(join_region, join_slice, Type::MEMORY, mms.adr_type(C));
470 phi = (PhiNode*) delay_transform(phi);
471 // gvn().set_type(phi, Type::MEMORY);
472 // new_phi = true;
473 }
474 // Now update the phi with the slice for the merging slice
475 phi->set_req(slot, merging_slice/* slow_path, slow_slice */);
476 // this updates join_m with the phi
477 mms.set_memory(phi);
478 }
479 }
480
481 Node* join_io = join->in(TypeFunc::I_O);
482 Node* merging_io = merging->in(TypeFunc::I_O);
483 if (join_io != merging_io) {
484 PhiNode* phi;
485 if (join_io->is_Phi() && join_io->as_Phi()->region() == join_region) {
486 phi = join_io->as_Phi();
487 } else {
488 phi = PhiNode::make(join_region, join_io, Type::ABIO);
489 phi = (PhiNode*) delay_transform(phi);
490 join->set_req(TypeFunc::I_O, phi);
491 }
492 phi->set_req(slot, merging_io);
493 }
494 }
495
496
497 //----------------------------- make_call ----------------------------
498 // Trivial runtime call
499 void IdealKit::make_leaf_call(const TypeFunc *slow_call_type,
500 address slow_call,
501 const char *leaf_name,
502 Node* parm0,
503 Node* parm1,
504 Node* parm2,
505 Node* parm3) {
506
507 // We only handle taking in RawMem and modifying RawMem
508 const TypePtr* adr_type = TypeRawPtr::BOTTOM;
509 uint adr_idx = C->get_alias_index(adr_type);
510
511 // Slow-path leaf call
512 int size = slow_call_type->domain()->cnt();
513 CallNode *call = (CallNode*)new (C, size) CallLeafNode( slow_call_type, slow_call, leaf_name, adr_type);
514
515 // Set fixed predefined input arguments
516 call->init_req( TypeFunc::Control, ctrl() );
517 call->init_req( TypeFunc::I_O , top() ) ; // does no i/o
518 // Narrow memory as only memory input
519 call->init_req( TypeFunc::Memory , memory(adr_idx));
520 call->init_req( TypeFunc::FramePtr, top() /* frameptr() */ );
521 call->init_req( TypeFunc::ReturnAdr, top() );
522
523 if (parm0 != NULL) call->init_req(TypeFunc::Parms+0, parm0);
524 if (parm1 != NULL) call->init_req(TypeFunc::Parms+1, parm1);
525 if (parm2 != NULL) call->init_req(TypeFunc::Parms+2, parm2);
526 if (parm3 != NULL) call->init_req(TypeFunc::Parms+3, parm3);
527
528 // Node *c = _gvn.transform(call);
529 call = (CallNode *) _gvn.transform(call);
530 Node *c = call; // dbx gets confused with call call->dump()
531
532 // Slow leaf call has no side-effects, sets few values
533
534 set_ctrl(transform( new (C, 1) ProjNode(call,TypeFunc::Control) ));
535
536 // Make memory for the call
537 Node* mem = _gvn.transform( new (C, 1) ProjNode(call, TypeFunc::Memory) );
538
539 // Set the RawPtr memory state only.
540 set_memory(mem, adr_idx);
541
542 assert(C->alias_type(call->adr_type()) == C->alias_type(adr_type),
543 "call node must be constructed correctly");
544 }
545
546
547 void IdealKit::make_leaf_call_no_fp(const TypeFunc *slow_call_type,
548 address slow_call,
549 const char *leaf_name,
550 const TypePtr* adr_type,
551 Node* parm0,
552 Node* parm1,
553 Node* parm2,
554 Node* parm3) {
555
556 // We only handle taking in RawMem and modifying RawMem
557 uint adr_idx = C->get_alias_index(adr_type);
558
559 // Slow-path leaf call
560 int size = slow_call_type->domain()->cnt();
561 CallNode *call = (CallNode*)new (C, size) CallLeafNoFPNode( slow_call_type, slow_call, leaf_name, adr_type);
562
563 // Set fixed predefined input arguments
564 call->init_req( TypeFunc::Control, ctrl() );
565 call->init_req( TypeFunc::I_O , top() ) ; // does no i/o
566 // Narrow memory as only memory input
567 call->init_req( TypeFunc::Memory , memory(adr_idx));
568 call->init_req( TypeFunc::FramePtr, top() /* frameptr() */ );
569 call->init_req( TypeFunc::ReturnAdr, top() );
570
571 if (parm0 != NULL) call->init_req(TypeFunc::Parms+0, parm0);
572 if (parm1 != NULL) call->init_req(TypeFunc::Parms+1, parm1);
573 if (parm2 != NULL) call->init_req(TypeFunc::Parms+2, parm2);
574 if (parm3 != NULL) call->init_req(TypeFunc::Parms+3, parm3);
575
576 // Node *c = _gvn.transform(call);
577 call = (CallNode *) _gvn.transform(call);
578 Node *c = call; // dbx gets confused with call call->dump()
579
580 // Slow leaf call has no side-effects, sets few values
581
582 set_ctrl(transform( new (C, 1) ProjNode(call,TypeFunc::Control) ));
583
584 // Make memory for the call
585 Node* mem = _gvn.transform( new (C, 1) ProjNode(call, TypeFunc::Memory) );
586
587 // Set the RawPtr memory state only.
588 set_memory(mem, adr_idx);
589
590 assert(C->alias_type(call->adr_type()) == C->alias_type(adr_type),
591 "call node must be constructed correctly");
592 }
|