< prev index next >

src/hotspot/share/opto/idealKit.cpp

Print this page

 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, 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() == 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) {

508   if (parm2 != nullptr)  call->init_req(TypeFunc::Parms+2, parm2);
509   if (parm3 != nullptr)  call->init_req(TypeFunc::Parms+3, parm3);
510 
511   // Node *c = _gvn.transform(call);
512   call = (CallNode *) _gvn.transform(call);
513   Node *c = call; // dbx gets confused with call call->dump()
514 
515   // Slow leaf call has no side-effects, sets few values
516 
517   set_ctrl(transform( new ProjNode(call,TypeFunc::Control) ));
518 
519   // Make memory for the call
520   Node* mem = _gvn.transform( new ProjNode(call, TypeFunc::Memory) );
521 
522   // Set the RawPtr memory state only.
523   set_memory(mem, adr_idx);
524 
525   assert(C->alias_type(call->adr_type()) == C->alias_type(adr_type),
526          "call node must be constructed correctly");
527   Node* res = nullptr;
528   if (slow_call_type->range()->cnt() > TypeFunc::Parms) {
529     assert(slow_call_type->range()->cnt() == TypeFunc::Parms+1, "only one return value");
530     res = transform(new ProjNode(call, TypeFunc::Parms));
531   }
532   return res;
533 }
534 
535 void IdealKit::make_leaf_call_no_fp(const TypeFunc *slow_call_type,
536                               address slow_call,
537                               const char *leaf_name,
538                               const TypePtr* adr_type,
539                               Node* parm0,
540                               Node* parm1,
541                               Node* parm2,
542                               Node* parm3) {
543 
544   // We only handle taking in RawMem and modifying RawMem
545   uint adr_idx = C->get_alias_index(adr_type);
546 
547   // Slow-path leaf call
548   CallNode *call =  (CallNode*)new CallLeafNoFPNode( slow_call_type, slow_call, leaf_name, adr_type);
549 

 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, 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 //----------------------------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) {

510   if (parm2 != nullptr)  call->init_req(TypeFunc::Parms+2, parm2);
511   if (parm3 != nullptr)  call->init_req(TypeFunc::Parms+3, parm3);
512 
513   // Node *c = _gvn.transform(call);
514   call = (CallNode *) _gvn.transform(call);
515   Node *c = call; // dbx gets confused with call call->dump()
516 
517   // Slow leaf call has no side-effects, sets few values
518 
519   set_ctrl(transform( new ProjNode(call,TypeFunc::Control) ));
520 
521   // Make memory for the call
522   Node* mem = _gvn.transform( new ProjNode(call, TypeFunc::Memory) );
523 
524   // Set the RawPtr memory state only.
525   set_memory(mem, adr_idx);
526 
527   assert(C->alias_type(call->adr_type()) == C->alias_type(adr_type),
528          "call node must be constructed correctly");
529   Node* res = nullptr;
530   if (slow_call_type->range_sig()->cnt() > TypeFunc::Parms) {
531     assert(slow_call_type->range_sig()->cnt() == TypeFunc::Parms+1, "only one return value");
532     res = transform(new ProjNode(call, TypeFunc::Parms));
533   }
534   return res;
535 }
536 
537 void IdealKit::make_leaf_call_no_fp(const TypeFunc *slow_call_type,
538                               address slow_call,
539                               const char *leaf_name,
540                               const TypePtr* adr_type,
541                               Node* parm0,
542                               Node* parm1,
543                               Node* parm2,
544                               Node* parm3) {
545 
546   // We only handle taking in RawMem and modifying RawMem
547   uint adr_idx = C->get_alias_index(adr_type);
548 
549   // Slow-path leaf call
550   CallNode *call =  (CallNode*)new CallLeafNoFPNode( slow_call_type, slow_call, leaf_name, adr_type);
551 
< prev index next >