30
31 // Static initialization
32
33 // This declares the position where vars are kept in the cvstate
34 // For some degree of consistency we use the TypeFunc enum to
35 // soak up spots in the inputs even though we only use early Control
36 // and Memory slots. (So far.)
37 const uint IdealKit::first_var = TypeFunc::Parms + 1;
38
39 //----------------------------IdealKit-----------------------------------------
40 IdealKit::IdealKit(GraphKit* gkit, bool delay_all_transforms, bool has_declarations) :
41 C(gkit->C), _gvn(gkit->gvn()) {
42 _initial_ctrl = gkit->control();
43 _initial_memory = gkit->merged_memory();
44 _initial_i_o = gkit->i_o();
45 _delay_all_transforms = delay_all_transforms;
46 _var_ct = 0;
47 _cvstate = nullptr;
48 // We can go memory state free or else we need the entire memory state
49 assert(_initial_memory == nullptr || _initial_memory->Opcode() == Op_MergeMem, "memory must be pre-split");
50 assert(!_gvn.is_IterGVN(), "IdealKit can't be used during Optimize phase");
51 int init_size = 5;
52 _pending_cvstates = new (C->node_arena()) GrowableArray<Node*>(C->node_arena(), init_size, 0, nullptr);
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 //----------------------------sync_kit-----------------------------------------
60 void IdealKit::sync_kit(GraphKit* gkit) {
61 set_all_memory(gkit->merged_memory());
62 set_i_o(gkit->i_o());
63 set_ctrl(gkit->control());
64 }
65
66 //-------------------------------if_then-------------------------------------
67 // Create: if(left relop right)
68 // / \
69 // iffalse iftrue
70 // Push the iffalse cvstate onto the stack. The iftrue becomes the current cvstate.
71 void IdealKit::if_then(Node* left, BoolTest::mask relop,
72 Node* right, float prob, float cnt, bool push_new_state) {
73 assert((state() & (BlockS|LoopS|IfThenS|ElseS)), "bad state for new If");
74 Node* bol;
75 if (left->bottom_type()->isa_ptr() == nullptr) {
76 if (left->bottom_type()->isa_int() != nullptr) {
77 bol = Bool(CmpI(left, right), relop);
78 } else {
79 assert(left->bottom_type()->isa_long() != nullptr, "what else?");
80 bol = Bool(CmpL(left, right), relop);
81 }
82
83 } else {
84 bol = Bool(CmpP(left, right), relop);
85 }
86 // Delay gvn.transform on if-nodes until construction is finished
87 // to prevent a constant bool input from discarding a control output.
88 IfNode* iff = delay_transform(new IfNode(ctrl(), bol, prob, cnt))->as_If();
89 Node* then = IfTrue(iff);
90 Node* elsen = IfFalse(iff);
91 Node* else_cvstate = copy_cvstate();
92 else_cvstate->set_req(TypeFunc::Control, elsen);
93 _pending_cvstates->push(else_cvstate);
94 DEBUG_ONLY(if (push_new_state) _state->push(IfThenS));
95 set_ctrl(then);
96 }
97
98 //-------------------------------else_-------------------------------------
99 // Pop the else cvstate off the stack, and push the (current) then cvstate.
100 // The else cvstate becomes the current cvstate.
101 void IdealKit::else_() {
102 assert(state() == IfThenS, "bad state for new Else");
103 Node* else_cvstate = _pending_cvstates->pop();
104 DEBUG_ONLY(_state->pop());
105 // save current (then) cvstate for later use at endif
276 const BasicType bt = n->bottom_type()->basic_type();
277 const Type* ct = Type::get_const_basic_type(bt);
278 return delay_transform(PhiNode::make(reg, n, ct));
279 }
280
281 //-----------------------------declarations_done-------------------------------
282 void IdealKit::declarations_done() {
283 _cvstate = new_cvstate(); // initialize current cvstate
284 set_ctrl(_initial_ctrl); // initialize control in current cvstate
285 set_all_memory(_initial_memory);// initialize memory in current cvstate
286 set_i_o(_initial_i_o); // initialize i_o in current cvstate
287 DEBUG_ONLY(_state->push(BlockS));
288 }
289
290 //-----------------------------transform-----------------------------------
291 Node* IdealKit::transform(Node* n) {
292 if (_delay_all_transforms) {
293 return delay_transform(n);
294 } else {
295 n = gvn().transform(n);
296 C->record_for_igvn(n);
297 return n;
298 }
299 }
300
301 //-----------------------------delay_transform-----------------------------------
302 Node* IdealKit::delay_transform(Node* n) {
303 // Delay transform until IterativeGVN
304 gvn().set_type(n, n->bottom_type());
305 C->record_for_igvn(n);
306 return n;
307 }
308
309 //-----------------------------new_cvstate-----------------------------------
310 Node* IdealKit::new_cvstate() {
311 uint sz = _var_ct + first_var;
312 return new Node(sz);
313 }
314
315 //-----------------------------copy_cvstate-----------------------------------
316 Node* IdealKit::copy_cvstate() {
317 Node* ns = new_cvstate();
318 for (uint i = 0; i < ns->req(); i++) ns->init_req(i, _cvstate->in(i));
319 // We must clone memory since it will be updated as we do stores.
320 ns->set_req(TypeFunc::Memory, MergeMemNode::make(ns->in(TypeFunc::Memory)));
321 return ns;
322 }
323
324 //-----------------------------clear-----------------------------------
325 void IdealKit::clear(Node* m) {
485 if (parm2 != nullptr) call->init_req(TypeFunc::Parms+2, parm2);
486 if (parm3 != nullptr) call->init_req(TypeFunc::Parms+3, parm3);
487
488 // Node *c = _gvn.transform(call);
489 call = (CallNode *) _gvn.transform(call);
490 Node *c = call; // dbx gets confused with call call->dump()
491
492 // Slow leaf call has no side-effects, sets few values
493
494 set_ctrl(transform( new ProjNode(call,TypeFunc::Control) ));
495
496 // Make memory for the call
497 Node* mem = _gvn.transform( new ProjNode(call, TypeFunc::Memory) );
498
499 // Set the RawPtr memory state only.
500 set_memory(mem, adr_idx);
501
502 assert(C->alias_type(call->adr_type()) == C->alias_type(adr_type),
503 "call node must be constructed correctly");
504 Node* res = nullptr;
505 if (slow_call_type->range()->cnt() > TypeFunc::Parms) {
506 assert(slow_call_type->range()->cnt() == TypeFunc::Parms+1, "only one return value");
507 res = transform(new ProjNode(call, TypeFunc::Parms));
508 }
509 return res;
510 }
511
512 void IdealKit::make_leaf_call_no_fp(const TypeFunc *slow_call_type,
513 address slow_call,
514 const char *leaf_name,
515 const TypePtr* adr_type,
516 Node* parm0,
517 Node* parm1,
518 Node* parm2,
519 Node* parm3) {
520
521 // We only handle taking in RawMem and modifying RawMem
522 uint adr_idx = C->get_alias_index(adr_type);
523
524 // Slow-path leaf call
525 CallNode *call = (CallNode*)new CallLeafNoFPNode( slow_call_type, slow_call, leaf_name, adr_type);
526
|
30
31 // Static initialization
32
33 // This declares the position where vars are kept in the cvstate
34 // For some degree of consistency we use the TypeFunc enum to
35 // soak up spots in the inputs even though we only use early Control
36 // and Memory slots. (So far.)
37 const uint IdealKit::first_var = TypeFunc::Parms + 1;
38
39 //----------------------------IdealKit-----------------------------------------
40 IdealKit::IdealKit(GraphKit* gkit, bool delay_all_transforms, bool has_declarations) :
41 C(gkit->C), _gvn(gkit->gvn()) {
42 _initial_ctrl = gkit->control();
43 _initial_memory = gkit->merged_memory();
44 _initial_i_o = gkit->i_o();
45 _delay_all_transforms = delay_all_transforms;
46 _var_ct = 0;
47 _cvstate = nullptr;
48 // We can go memory state free or else we need the entire memory state
49 assert(_initial_memory == nullptr || _initial_memory->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, nullptr);
52 DEBUG_ONLY(_state = new (C->node_arena()) GrowableArray<int>(C->node_arena(), init_size, 0, 0));
53 if (!has_declarations) {
54 declarations_done();
55 }
56 }
57
58 //----------------------------sync_kit-----------------------------------------
59 void IdealKit::sync_kit(GraphKit* gkit) {
60 set_all_memory(gkit->merged_memory());
61 set_i_o(gkit->i_o());
62 set_ctrl(gkit->control());
63 }
64
65 //-------------------------------if_then-------------------------------------
66 // Create: if(left relop right)
67 // / \
68 // iffalse iftrue
69 // Push the iffalse cvstate onto the stack. The iftrue becomes the current cvstate.
70 void IdealKit::if_then(Node* left, BoolTest::mask relop,
71 Node* right, float prob, float cnt, bool push_new_state) {
72 assert((state() & (BlockS|LoopS|IfThenS|ElseS)), "bad state for new If");
73 Node* bol;
74 if (left->bottom_type()->isa_ptr() == nullptr) {
75 if (left->bottom_type()->isa_int() != nullptr) {
76 bol = Bool(CmpI(left, right), relop);
77 } else {
78 assert(left->bottom_type()->isa_long() != nullptr, "what else?");
79 bol = Bool(CmpL(left, right), relop);
80 }
81 } else {
82 bol = Bool(CmpP(left, right), relop);
83 }
84 if_then(bol, prob, cnt, push_new_state);
85 }
86
87 void IdealKit::if_then(Node* bol, float prob, float cnt, bool push_new_state) {
88 // Delay gvn.transform on if-nodes until construction is finished
89 // to prevent a constant bool input from discarding a control output.
90 IfNode* iff = delay_transform(new IfNode(ctrl(), bol, prob, cnt))->as_If();
91 Node* then = IfTrue(iff);
92 Node* elsen = IfFalse(iff);
93 Node* else_cvstate = copy_cvstate();
94 else_cvstate->set_req(TypeFunc::Control, elsen);
95 _pending_cvstates->push(else_cvstate);
96 DEBUG_ONLY(if (push_new_state) _state->push(IfThenS));
97 set_ctrl(then);
98 }
99
100 //-------------------------------else_-------------------------------------
101 // Pop the else cvstate off the stack, and push the (current) then cvstate.
102 // The else cvstate becomes the current cvstate.
103 void IdealKit::else_() {
104 assert(state() == IfThenS, "bad state for new Else");
105 Node* else_cvstate = _pending_cvstates->pop();
106 DEBUG_ONLY(_state->pop());
107 // save current (then) cvstate for later use at endif
278 const BasicType bt = n->bottom_type()->basic_type();
279 const Type* ct = Type::get_const_basic_type(bt);
280 return delay_transform(PhiNode::make(reg, n, ct));
281 }
282
283 //-----------------------------declarations_done-------------------------------
284 void IdealKit::declarations_done() {
285 _cvstate = new_cvstate(); // initialize current cvstate
286 set_ctrl(_initial_ctrl); // initialize control in current cvstate
287 set_all_memory(_initial_memory);// initialize memory in current cvstate
288 set_i_o(_initial_i_o); // initialize i_o in current cvstate
289 DEBUG_ONLY(_state->push(BlockS));
290 }
291
292 //-----------------------------transform-----------------------------------
293 Node* IdealKit::transform(Node* n) {
294 if (_delay_all_transforms) {
295 return delay_transform(n);
296 } else {
297 n = gvn().transform(n);
298 gvn().record_for_igvn(n);
299 return n;
300 }
301 }
302
303 //-----------------------------delay_transform-----------------------------------
304 Node* IdealKit::delay_transform(Node* n) {
305 // Delay transform until IterativeGVN
306 gvn().set_type(n, n->bottom_type());
307 gvn().record_for_igvn(n);
308 return n;
309 }
310
311 //-----------------------------new_cvstate-----------------------------------
312 Node* IdealKit::new_cvstate() {
313 uint sz = _var_ct + first_var;
314 return new Node(sz);
315 }
316
317 //-----------------------------copy_cvstate-----------------------------------
318 Node* IdealKit::copy_cvstate() {
319 Node* ns = new_cvstate();
320 for (uint i = 0; i < ns->req(); i++) ns->init_req(i, _cvstate->in(i));
321 // We must clone memory since it will be updated as we do stores.
322 ns->set_req(TypeFunc::Memory, MergeMemNode::make(ns->in(TypeFunc::Memory)));
323 return ns;
324 }
325
326 //-----------------------------clear-----------------------------------
327 void IdealKit::clear(Node* m) {
487 if (parm2 != nullptr) call->init_req(TypeFunc::Parms+2, parm2);
488 if (parm3 != nullptr) call->init_req(TypeFunc::Parms+3, parm3);
489
490 // Node *c = _gvn.transform(call);
491 call = (CallNode *) _gvn.transform(call);
492 Node *c = call; // dbx gets confused with call call->dump()
493
494 // Slow leaf call has no side-effects, sets few values
495
496 set_ctrl(transform( new ProjNode(call,TypeFunc::Control) ));
497
498 // Make memory for the call
499 Node* mem = _gvn.transform( new ProjNode(call, TypeFunc::Memory) );
500
501 // Set the RawPtr memory state only.
502 set_memory(mem, adr_idx);
503
504 assert(C->alias_type(call->adr_type()) == C->alias_type(adr_type),
505 "call node must be constructed correctly");
506 Node* res = nullptr;
507 if (slow_call_type->range_sig()->cnt() > TypeFunc::Parms) {
508 assert(slow_call_type->range_sig()->cnt() == TypeFunc::Parms+1, "only one return value");
509 res = transform(new ProjNode(call, TypeFunc::Parms));
510 }
511 return res;
512 }
513
514 void IdealKit::make_leaf_call_no_fp(const TypeFunc *slow_call_type,
515 address slow_call,
516 const char *leaf_name,
517 const TypePtr* adr_type,
518 Node* parm0,
519 Node* parm1,
520 Node* parm2,
521 Node* parm3) {
522
523 // We only handle taking in RawMem and modifying RawMem
524 uint adr_idx = C->get_alias_index(adr_type);
525
526 // Slow-path leaf call
527 CallNode *call = (CallNode*)new CallLeafNoFPNode( slow_call_type, slow_call, leaf_name, adr_type);
528
|