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 C(gkit->C), _gvn(gkit->gvn()) {
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 = nullptr;
49 // We can go memory state free or else we need the entire memory state
50 assert(_initial_memory == nullptr || _initial_memory->Opcode() == Op_MergeMem, "memory must be pre-split");
51 assert(!_gvn.is_IterGVN(), "IdealKit can't be used during Optimize phase");
52 int init_size = 5;
53 _pending_cvstates = new (C->node_arena()) GrowableArray<Node*>(C->node_arena(), init_size, 0, nullptr);
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() == nullptr) {
77 if (left->bottom_type()->isa_int() != nullptr) {
78 bol = Bool(CmpI(left, right), relop);
79 } else {
80 assert(left->bottom_type()->isa_long() != nullptr, "what else?");
81 bol = Bool(CmpL(left, right), relop);
82 }
83
84 } else {
85 bol = Bool(CmpP(left, right), relop);
86 }
87 // Delay gvn.transform on if-nodes until construction is finished
88 // to prevent a constant bool input from discarding a control output.
89 IfNode* iff = delay_transform(new IfNode(ctrl(), bol, prob, cnt))->as_If();
90 Node* then = IfTrue(iff);
91 Node* elsen = IfFalse(iff);
92 Node* else_cvstate = copy_cvstate();
93 else_cvstate->set_req(TypeFunc::Control, elsen);
94 _pending_cvstates->push(else_cvstate);
95 DEBUG_ONLY(if (push_new_state) _state->push(IfThenS));
96 set_ctrl(then);
97 }
98
99 //-------------------------------else_-------------------------------------
100 // Pop the else cvstate off the stack, and push the (current) then cvstate.
101 // The else cvstate becomes the current cvstate.
102 void IdealKit::else_() {
103 assert(state() == IfThenS, "bad state for new Else");
104 Node* else_cvstate = _pending_cvstates->pop();
105 DEBUG_ONLY(_state->pop());
106 // save current (then) cvstate for later use at endif
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 n = gvn().transform(n);
299 C->record_for_igvn(n);
300 return n;
301 }
302 }
303
304 //-----------------------------delay_transform-----------------------------------
305 Node* IdealKit::delay_transform(Node* n) {
306 // Delay transform until IterativeGVN
307 gvn().set_type(n, n->bottom_type());
308 C->record_for_igvn(n);
309 return n;
310 }
311
312 //-----------------------------new_cvstate-----------------------------------
313 Node* IdealKit::new_cvstate() {
314 uint sz = _var_ct + first_var;
315 return new Node(sz);
316 }
317
318 //-----------------------------copy_cvstate-----------------------------------
319 Node* IdealKit::copy_cvstate() {
320 Node* ns = new_cvstate();
321 for (uint i = 0; i < ns->req(); i++) ns->init_req(i, _cvstate->in(i));
322 // We must clone memory since it will be updated as we do stores.
323 ns->set_req(TypeFunc::Memory, MergeMemNode::make(ns->in(TypeFunc::Memory)));
324 return ns;
325 }
326
327 //-----------------------------clear-----------------------------------
328 void IdealKit::clear(Node* m) {
488 if (parm2 != nullptr) call->init_req(TypeFunc::Parms+2, parm2);
489 if (parm3 != nullptr) call->init_req(TypeFunc::Parms+3, parm3);
490
491 // Node *c = _gvn.transform(call);
492 call = (CallNode *) _gvn.transform(call);
493 Node *c = call; // dbx gets confused with call call->dump()
494
495 // Slow leaf call has no side-effects, sets few values
496
497 set_ctrl(transform( new ProjNode(call,TypeFunc::Control) ));
498
499 // Make memory for the call
500 Node* mem = _gvn.transform( new ProjNode(call, TypeFunc::Memory) );
501
502 // Set the RawPtr memory state only.
503 set_memory(mem, adr_idx);
504
505 assert(C->alias_type(call->adr_type()) == C->alias_type(adr_type),
506 "call node must be constructed correctly");
507 Node* res = nullptr;
508 if (slow_call_type->range()->cnt() > TypeFunc::Parms) {
509 assert(slow_call_type->range()->cnt() == TypeFunc::Parms+1, "only one return value");
510 res = transform(new ProjNode(call, TypeFunc::Parms));
511 }
512 return res;
513 }
514
515 void IdealKit::make_leaf_call_no_fp(const TypeFunc *slow_call_type,
516 address slow_call,
517 const char *leaf_name,
518 const TypePtr* adr_type,
519 Node* parm0,
520 Node* parm1,
521 Node* parm2,
522 Node* parm3) {
523
524 // We only handle taking in RawMem and modifying RawMem
525 uint adr_idx = C->get_alias_index(adr_type);
526
527 // Slow-path leaf call
528 CallNode *call = (CallNode*)new CallLeafNoFPNode( slow_call_type, slow_call, leaf_name, adr_type);
529
|
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 C(gkit->C), _gvn(gkit->gvn()) {
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 = nullptr;
49 // We can go memory state free or else we need the entire memory state
50 assert(_initial_memory == nullptr || _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, 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 } else {
83 bol = Bool(CmpP(left, right), relop);
84 }
85 if_then(bol, prob, cnt, push_new_state);
86 }
87
88 void IdealKit::if_then(Node* bol, float prob, float cnt, bool push_new_state) {
89 // Delay gvn.transform on if-nodes until construction is finished
90 // to prevent a constant bool input from discarding a control output.
91 IfNode* iff = delay_transform(new IfNode(ctrl(), bol, prob, cnt))->as_If();
92 Node* then = IfTrue(iff);
93 Node* elsen = IfFalse(iff);
94 Node* else_cvstate = copy_cvstate();
95 else_cvstate->set_req(TypeFunc::Control, elsen);
96 _pending_cvstates->push(else_cvstate);
97 DEBUG_ONLY(if (push_new_state) _state->push(IfThenS));
98 set_ctrl(then);
99 }
100
101 //-------------------------------else_-------------------------------------
102 // Pop the else cvstate off the stack, and push the (current) then cvstate.
103 // The else cvstate becomes the current cvstate.
104 void IdealKit::else_() {
105 assert(state() == IfThenS, "bad state for new Else");
106 Node* else_cvstate = _pending_cvstates->pop();
107 DEBUG_ONLY(_state->pop());
108 // save current (then) cvstate for later use at endif
281 const BasicType bt = n->bottom_type()->basic_type();
282 const Type* ct = Type::get_const_basic_type(bt);
283 return delay_transform(PhiNode::make(reg, n, ct));
284 }
285
286 //-----------------------------declarations_done-------------------------------
287 void IdealKit::declarations_done() {
288 _cvstate = new_cvstate(); // initialize current cvstate
289 set_ctrl(_initial_ctrl); // initialize control in current cvstate
290 set_all_memory(_initial_memory);// initialize memory in current cvstate
291 set_i_o(_initial_i_o); // initialize i_o in current cvstate
292 DEBUG_ONLY(_state->push(BlockS));
293 }
294
295 //-----------------------------transform-----------------------------------
296 Node* IdealKit::transform(Node* n) {
297 if (_delay_all_transforms) {
298 return delay_transform(n);
299 } else {
300 n = gvn().transform(n);
301 gvn().record_for_igvn(n);
302 return n;
303 }
304 }
305
306 //-----------------------------delay_transform-----------------------------------
307 Node* IdealKit::delay_transform(Node* n) {
308 // Delay transform until IterativeGVN
309 gvn().set_type(n, n->bottom_type());
310 gvn().record_for_igvn(n);
311 return n;
312 }
313
314 //-----------------------------new_cvstate-----------------------------------
315 Node* IdealKit::new_cvstate() {
316 uint sz = _var_ct + first_var;
317 return new Node(sz);
318 }
319
320 //-----------------------------copy_cvstate-----------------------------------
321 Node* IdealKit::copy_cvstate() {
322 Node* ns = new_cvstate();
323 for (uint i = 0; i < ns->req(); i++) ns->init_req(i, _cvstate->in(i));
324 // We must clone memory since it will be updated as we do stores.
325 ns->set_req(TypeFunc::Memory, MergeMemNode::make(ns->in(TypeFunc::Memory)));
326 return ns;
327 }
328
329 //-----------------------------clear-----------------------------------
330 void IdealKit::clear(Node* m) {
490 if (parm2 != nullptr) call->init_req(TypeFunc::Parms+2, parm2);
491 if (parm3 != nullptr) call->init_req(TypeFunc::Parms+3, parm3);
492
493 // Node *c = _gvn.transform(call);
494 call = (CallNode *) _gvn.transform(call);
495 Node *c = call; // dbx gets confused with call call->dump()
496
497 // Slow leaf call has no side-effects, sets few values
498
499 set_ctrl(transform( new ProjNode(call,TypeFunc::Control) ));
500
501 // Make memory for the call
502 Node* mem = _gvn.transform( new ProjNode(call, TypeFunc::Memory) );
503
504 // Set the RawPtr memory state only.
505 set_memory(mem, adr_idx);
506
507 assert(C->alias_type(call->adr_type()) == C->alias_type(adr_type),
508 "call node must be constructed correctly");
509 Node* res = nullptr;
510 if (slow_call_type->range_sig()->cnt() > TypeFunc::Parms) {
511 assert(slow_call_type->range_sig()->cnt() == TypeFunc::Parms+1, "only one return value");
512 res = transform(new ProjNode(call, TypeFunc::Parms));
513 }
514 return res;
515 }
516
517 void IdealKit::make_leaf_call_no_fp(const TypeFunc *slow_call_type,
518 address slow_call,
519 const char *leaf_name,
520 const TypePtr* adr_type,
521 Node* parm0,
522 Node* parm1,
523 Node* parm2,
524 Node* parm3) {
525
526 // We only handle taking in RawMem and modifying RawMem
527 uint adr_idx = C->get_alias_index(adr_type);
528
529 // Slow-path leaf call
530 CallNode *call = (CallNode*)new CallLeafNoFPNode( slow_call_type, slow_call, leaf_name, adr_type);
531
|