< prev index next >

src/hotspot/share/opto/idealKit.cpp

Print this page

 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

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     C->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   C->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()->cnt() > TypeFunc::Parms) {
508     assert(slow_call_type->range()->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 

 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

280   const BasicType bt = n->bottom_type()->basic_type();
281   const Type* ct = Type::get_const_basic_type(bt);
282   return delay_transform(PhiNode::make(reg, n, ct));
283 }
284 
285 //-----------------------------declarations_done-------------------------------
286 void IdealKit::declarations_done() {
287   _cvstate = new_cvstate();   // initialize current cvstate
288   set_ctrl(_initial_ctrl);    // initialize control in current cvstate
289   set_all_memory(_initial_memory);// initialize memory in current cvstate
290   set_i_o(_initial_i_o);      // initialize i_o in current cvstate
291   DEBUG_ONLY(_state->push(BlockS));
292 }
293 
294 //-----------------------------transform-----------------------------------
295 Node* IdealKit::transform(Node* n) {
296   if (_delay_all_transforms) {
297     return delay_transform(n);
298   } else {
299     n = gvn().transform(n);
300     gvn().record_for_igvn(n);
301     return n;
302   }
303 }
304 
305 //-----------------------------delay_transform-----------------------------------
306 Node* IdealKit::delay_transform(Node* n) {
307   // Delay transform until IterativeGVN
308   gvn().set_type(n, n->bottom_type());
309   gvn().record_for_igvn(n);
310   return n;
311 }
312 
313 //-----------------------------new_cvstate-----------------------------------
314 Node* IdealKit::new_cvstate() {
315   uint sz = _var_ct + first_var;
316   return new Node(sz);
317 }
318 
319 //-----------------------------copy_cvstate-----------------------------------
320 Node* IdealKit::copy_cvstate() {
321   Node* ns = new_cvstate();
322   for (uint i = 0; i < ns->req(); i++) ns->init_req(i, _cvstate->in(i));
323   // We must clone memory since it will be updated as we do stores.
324   ns->set_req(TypeFunc::Memory, MergeMemNode::make(ns->in(TypeFunc::Memory)));
325   return ns;
326 }
327 
328 //-----------------------------clear-----------------------------------
329 void IdealKit::clear(Node* m) {

489   if (parm2 != nullptr)  call->init_req(TypeFunc::Parms+2, parm2);
490   if (parm3 != nullptr)  call->init_req(TypeFunc::Parms+3, parm3);
491 
492   // Node *c = _gvn.transform(call);
493   call = (CallNode *) _gvn.transform(call);
494   Node *c = call; // dbx gets confused with call call->dump()
495 
496   // Slow leaf call has no side-effects, sets few values
497 
498   set_ctrl(transform( new ProjNode(call,TypeFunc::Control) ));
499 
500   // Make memory for the call
501   Node* mem = _gvn.transform( new ProjNode(call, TypeFunc::Memory) );
502 
503   // Set the RawPtr memory state only.
504   set_memory(mem, adr_idx);
505 
506   assert(C->alias_type(call->adr_type()) == C->alias_type(adr_type),
507          "call node must be constructed correctly");
508   Node* res = nullptr;
509   if (slow_call_type->range_sig()->cnt() > TypeFunc::Parms) {
510     assert(slow_call_type->range_sig()->cnt() == TypeFunc::Parms+1, "only one return value");
511     res = transform(new ProjNode(call, TypeFunc::Parms));
512   }
513   return res;
514 }
515 
516 void IdealKit::make_leaf_call_no_fp(const TypeFunc *slow_call_type,
517                               address slow_call,
518                               const char *leaf_name,
519                               const TypePtr* adr_type,
520                               Node* parm0,
521                               Node* parm1,
522                               Node* parm2,
523                               Node* parm3) {
524 
525   // We only handle taking in RawMem and modifying RawMem
526   uint adr_idx = C->get_alias_index(adr_type);
527 
528   // Slow-path leaf call
529   CallNode *call =  (CallNode*)new CallLeafNoFPNode( slow_call_type, slow_call, leaf_name, adr_type);
530 
< prev index next >