< 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 = 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   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() == 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   }




 87   // Delay gvn.tranform 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) {

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

 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 = 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   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() == NULL) {
 76     if (left->bottom_type()->isa_int() != NULL) {
 77       bol = Bool(CmpI(left, right), relop);
 78     } else {
 79       assert(left->bottom_type()->isa_long() != NULL, "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.tranform 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) {

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