151 Unique_Node_List worklist;
152 VectorSet visited(Thread::current()->resource_area());
153 worklist.push(xroot);
154 while (worklist.size() > 0) {
155 Node* n = worklist.pop();
156 visited <<= n->_idx;
157 assert(C->node_arena()->contains(n), "dead node");
158 for (uint j = 0; j < n->req(); j++) {
159 Node* in = n->in(j);
160 if (in != NULL) {
161 assert(C->node_arena()->contains(in), "dead node");
162 if (!visited.test(in->_idx)) {
163 worklist.push(in);
164 }
165 }
166 }
167 }
168 }
169 #endif
170
171
172 //---------------------------match---------------------------------------------
173 void Matcher::match( ) {
174 if( MaxLabelRootDepth < 100 ) { // Too small?
175 assert(false, "invalid MaxLabelRootDepth, increase it to 100 minimum");
176 MaxLabelRootDepth = 100;
177 }
178 // One-time initialization of some register masks.
179 init_spill_mask( C->root()->in(1) );
180 _return_addr_mask = return_addr();
181 #ifdef _LP64
182 // Pointers take 2 slots in 64-bit land
183 _return_addr_mask.Insert(OptoReg::add(return_addr(),1));
184 #endif
185
186 // Map a Java-signature return type into return register-value
187 // machine registers for 0, 1 and 2 returned values.
188 const TypeTuple *range = C->tf()->range();
189 if( range->cnt() > TypeFunc::Parms ) { // If not a void function
190 // Get ideal-register return type
191 uint ireg = range->field_at(TypeFunc::Parms)->ideal_reg();
192 // Get machine return register
193 uint sop = C->start()->Opcode();
194 OptoRegPair regs = return_value(ireg, false);
195
196 // And mask for same
197 _return_value_mask = RegMask(regs.first());
198 if( OptoReg::is_valid(regs.second()) )
199 _return_value_mask.Insert(regs.second());
200 }
201
202 // ---------------
203 // Frame Layout
204
205 // Need the method signature to determine the incoming argument types,
206 // because the types determine which registers the incoming arguments are
207 // in, and this affects the matched code.
208 const TypeTuple *domain = C->tf()->domain_cc();
209 uint argcnt = domain->cnt() - TypeFunc::Parms;
210 BasicType *sig_bt = NEW_RESOURCE_ARRAY( BasicType, argcnt );
211 VMRegPair *vm_parm_regs = NEW_RESOURCE_ARRAY( VMRegPair, argcnt );
212 _parm_regs = NEW_RESOURCE_ARRAY( OptoRegPair, argcnt );
213 _calling_convention_mask = NEW_RESOURCE_ARRAY( RegMask, argcnt );
214 uint i;
215 for( i = 0; i<argcnt; i++ ) {
216 sig_bt[i] = domain->field_at(i+TypeFunc::Parms)->basic_type();
217 }
218
219 // Pass array of ideal registers and length to USER code (from the AD file)
220 // that will convert this to an array of register numbers.
634 init_first_stack_mask();
635
636 Node *root = C->root(); // Short name for root
637 // Count number of save-on-entry registers.
638 uint soe_cnt = number_of_saved_registers();
639 uint i;
640
641 // Find the procedure Start Node
642 StartNode *start = C->start();
643 assert( start, "Expect a start node" );
644
645 // Save argument registers in the trampolining stubs
646 if( C->save_argument_registers() )
647 for( i = 0; i < _last_Mach_Reg; i++ )
648 if( is_spillable_arg(i) )
649 soe_cnt++;
650
651 // Input RegMask array shared by all Returns.
652 // The type for doubles and longs has a count of 2, but
653 // there is only 1 returned value
654 uint ret_edge_cnt = TypeFunc::Parms + ((C->tf()->range()->cnt() == TypeFunc::Parms) ? 0 : 1);
655 RegMask *ret_rms = init_input_masks( ret_edge_cnt + soe_cnt, _return_addr_mask, c_frame_ptr_mask );
656 // Returns have 0 or 1 returned values depending on call signature.
657 // Return register is specified by return_value in the AD file.
658 if (ret_edge_cnt > TypeFunc::Parms)
659 ret_rms[TypeFunc::Parms+0] = _return_value_mask;
660
661 // Input RegMask array shared by all Rethrows.
662 uint reth_edge_cnt = TypeFunc::Parms+1;
663 RegMask *reth_rms = init_input_masks( reth_edge_cnt + soe_cnt, _return_addr_mask, c_frame_ptr_mask );
664 // Rethrow takes exception oop only, but in the argument 0 slot.
665 OptoReg::Name reg = find_receiver(false);
666 if (reg >= 0) {
667 reth_rms[TypeFunc::Parms] = mreg2regmask[reg];
668 #ifdef _LP64
669 // Need two slots for ptrs in 64-bit land
670 reth_rms[TypeFunc::Parms].Insert(OptoReg::add(OptoReg::Name(reg), 1));
671 #endif
672 }
673
674 // Input RegMask array shared by all TailCalls
675 uint tail_call_edge_cnt = TypeFunc::Parms+2;
676 RegMask *tail_call_rms = init_input_masks( tail_call_edge_cnt + soe_cnt, _return_addr_mask, c_frame_ptr_mask );
677
678 // Input RegMask array shared by all TailJumps
679 uint tail_jump_edge_cnt = TypeFunc::Parms+2;
985 Node_State nstate = mstack.state();
986 if (nstate == Visit) {
987 mstack.set_state(Post_Visit);
988 Node *oldn = n;
989 // Old-space or new-space check
990 if (!C->node_arena()->contains(n)) {
991 // Old space!
992 Node* m;
993 if (has_new_node(n)) { // Not yet Label/Reduced
994 m = new_node(n);
995 } else {
996 if (!is_dontcare(n)) { // Matcher can match this guy
997 // Calls match special. They match alone with no children.
998 // Their children, the incoming arguments, match normally.
999 m = n->is_SafePoint() ? match_sfpt(n->as_SafePoint()):match_tree(n);
1000 if (C->failing()) return NULL;
1001 if (m == NULL) { Matcher::soft_match_failure(); return NULL; }
1002 } else { // Nothing the matcher cares about
1003 if( n->is_Proj() && n->in(0)->is_Multi()) { // Projections?
1004 // Convert to machine-dependent projection
1005 m = n->in(0)->as_Multi()->match( n->as_Proj(), this );
1006 #ifdef ASSERT
1007 _new2old_map.map(m->_idx, n);
1008 #endif
1009 if (m->in(0) != NULL) // m might be top
1010 collect_null_checks(m, n);
1011 } else { // Else just a regular 'ol guy
1012 m = n->clone(); // So just clone into new-space
1013 #ifdef ASSERT
1014 _new2old_map.map(m->_idx, n);
1015 #endif
1016 // Def-Use edges will be added incrementally as Uses
1017 // of this node are matched.
1018 assert(m->outcnt() == 0, "no Uses of this clone yet");
1019 }
1020 }
1021
1022 set_new_node(n, m); // Map old to new
1023 if (_old_node_note_array != NULL) {
1024 Node_Notes* nn = C->locate_node_notes(_old_node_note_array,
1025 n->_idx);
1285 }
1286 } // End of for all arguments
1287
1288 // Compute number of stack slots needed to restore stack in case of
1289 // Pascal-style argument popping.
1290 mcall->_argsize = out_arg_limit_per_call - begin_out_arg_area;
1291 }
1292
1293 // Compute the max stack slot killed by any call. These will not be
1294 // available for debug info, and will be used to adjust FIRST_STACK_mask
1295 // after all call sites have been visited.
1296 if( _out_arg_limit < out_arg_limit_per_call)
1297 _out_arg_limit = out_arg_limit_per_call;
1298
1299 if (mcall) {
1300 // Kill the outgoing argument area, including any non-argument holes and
1301 // any legacy C-killed slots. Use Fat-Projections to do the killing.
1302 // Since the max-per-method covers the max-per-call-site and debug info
1303 // is excluded on the max-per-method basis, debug info cannot land in
1304 // this killed area.
1305 uint r_cnt = mcall->tf()->range()->cnt();
1306 MachProjNode *proj = new MachProjNode( mcall, r_cnt+10000, RegMask::Empty, MachProjNode::fat_proj );
1307 if (!RegMask::can_represent_arg(OptoReg::Name(out_arg_limit_per_call-1))) {
1308 C->record_method_not_compilable("unsupported outgoing calling sequence");
1309 } else {
1310 for (int i = begin_out_arg_area; i < out_arg_limit_per_call; i++)
1311 proj->_rout.Insert(OptoReg::Name(i));
1312 }
1313 if (proj->_rout.is_NotEmpty()) {
1314 push_projection(proj);
1315 }
1316 }
1317 // Transfer the safepoint information from the call to the mcall
1318 // Move the JVMState list
1319 msfpt->set_jvms(sfpt->jvms());
1320 for (JVMState* jvms = msfpt->jvms(); jvms; jvms = jvms->caller()) {
1321 jvms->set_map(sfpt);
1322 }
1323
1324 // Debug inputs begin just after the last incoming parameter
1325 assert((mcall == NULL) || (mcall->jvms() == NULL) ||
|
151 Unique_Node_List worklist;
152 VectorSet visited(Thread::current()->resource_area());
153 worklist.push(xroot);
154 while (worklist.size() > 0) {
155 Node* n = worklist.pop();
156 visited <<= n->_idx;
157 assert(C->node_arena()->contains(n), "dead node");
158 for (uint j = 0; j < n->req(); j++) {
159 Node* in = n->in(j);
160 if (in != NULL) {
161 assert(C->node_arena()->contains(in), "dead node");
162 if (!visited.test(in->_idx)) {
163 worklist.push(in);
164 }
165 }
166 }
167 }
168 }
169 #endif
170
171 // Array of RegMask, one per returned values (value type instances can
172 // be returned as multiple return values, one per field)
173 RegMask* Matcher::return_values_mask(const TypeTuple *range) {
174 uint cnt = range->cnt() - TypeFunc::Parms;
175 if (cnt == 0) {
176 return NULL;
177 }
178 RegMask* mask = NEW_RESOURCE_ARRAY(RegMask, cnt);
179
180 if (!ValueTypeReturnedAsFields) {
181 // Get ideal-register return type
182 uint ireg = range->field_at(TypeFunc::Parms)->ideal_reg();
183 // Get machine return register
184 OptoRegPair regs = return_value(ireg, false);
185
186 // And mask for same
187 mask[0].Clear();
188 mask[0].Insert(regs.first());
189 if (OptoReg::is_valid(regs.second())) {
190 mask[0].Insert(regs.second());
191 }
192 } else {
193 BasicType *sig_bt = NEW_RESOURCE_ARRAY(BasicType, cnt);
194 VMRegPair *vm_parm_regs = NEW_RESOURCE_ARRAY(VMRegPair, cnt);
195
196 for (uint i = 0; i < cnt; i++) {
197 sig_bt[i] = range->field_at(i+TypeFunc::Parms)->basic_type();
198 }
199
200 int regs = SharedRuntime::java_return_convention(sig_bt, vm_parm_regs, cnt);
201 assert(regs > 0, "should have been tested during graph construction");
202 for (uint i = 0; i < cnt; i++) {
203 mask[i].Clear();
204
205 OptoReg::Name reg1 = OptoReg::as_OptoReg(vm_parm_regs[i].first());
206 if (OptoReg::is_valid(reg1)) {
207 mask[i].Insert(reg1);
208 }
209 OptoReg::Name reg2 = OptoReg::as_OptoReg(vm_parm_regs[i].second());
210 if (OptoReg::is_valid(reg2)) {
211 mask[i].Insert(reg2);
212 }
213 }
214 }
215 return mask;
216 }
217
218 //---------------------------match---------------------------------------------
219 void Matcher::match( ) {
220 if( MaxLabelRootDepth < 100 ) { // Too small?
221 assert(false, "invalid MaxLabelRootDepth, increase it to 100 minimum");
222 MaxLabelRootDepth = 100;
223 }
224 // One-time initialization of some register masks.
225 init_spill_mask( C->root()->in(1) );
226 _return_addr_mask = return_addr();
227 #ifdef _LP64
228 // Pointers take 2 slots in 64-bit land
229 _return_addr_mask.Insert(OptoReg::add(return_addr(),1));
230 #endif
231
232 // Map Java-signature return types into return register-value
233 // machine registers.
234 const TypeTuple *range = C->tf()->range_cc();
235 _return_values_mask = return_values_mask(range);
236
237 // ---------------
238 // Frame Layout
239
240 // Need the method signature to determine the incoming argument types,
241 // because the types determine which registers the incoming arguments are
242 // in, and this affects the matched code.
243 const TypeTuple *domain = C->tf()->domain_cc();
244 uint argcnt = domain->cnt() - TypeFunc::Parms;
245 BasicType *sig_bt = NEW_RESOURCE_ARRAY( BasicType, argcnt );
246 VMRegPair *vm_parm_regs = NEW_RESOURCE_ARRAY( VMRegPair, argcnt );
247 _parm_regs = NEW_RESOURCE_ARRAY( OptoRegPair, argcnt );
248 _calling_convention_mask = NEW_RESOURCE_ARRAY( RegMask, argcnt );
249 uint i;
250 for( i = 0; i<argcnt; i++ ) {
251 sig_bt[i] = domain->field_at(i+TypeFunc::Parms)->basic_type();
252 }
253
254 // Pass array of ideal registers and length to USER code (from the AD file)
255 // that will convert this to an array of register numbers.
669 init_first_stack_mask();
670
671 Node *root = C->root(); // Short name for root
672 // Count number of save-on-entry registers.
673 uint soe_cnt = number_of_saved_registers();
674 uint i;
675
676 // Find the procedure Start Node
677 StartNode *start = C->start();
678 assert( start, "Expect a start node" );
679
680 // Save argument registers in the trampolining stubs
681 if( C->save_argument_registers() )
682 for( i = 0; i < _last_Mach_Reg; i++ )
683 if( is_spillable_arg(i) )
684 soe_cnt++;
685
686 // Input RegMask array shared by all Returns.
687 // The type for doubles and longs has a count of 2, but
688 // there is only 1 returned value
689 uint ret_edge_cnt = C->tf()->range_cc()->cnt();
690 RegMask *ret_rms = init_input_masks( ret_edge_cnt + soe_cnt, _return_addr_mask, c_frame_ptr_mask );
691 for (i = TypeFunc::Parms; i < ret_edge_cnt; i++) {
692 ret_rms[i] = _return_values_mask[i-TypeFunc::Parms];
693 }
694
695 // Input RegMask array shared by all Rethrows.
696 uint reth_edge_cnt = TypeFunc::Parms+1;
697 RegMask *reth_rms = init_input_masks( reth_edge_cnt + soe_cnt, _return_addr_mask, c_frame_ptr_mask );
698 // Rethrow takes exception oop only, but in the argument 0 slot.
699 OptoReg::Name reg = find_receiver(false);
700 if (reg >= 0) {
701 reth_rms[TypeFunc::Parms] = mreg2regmask[reg];
702 #ifdef _LP64
703 // Need two slots for ptrs in 64-bit land
704 reth_rms[TypeFunc::Parms].Insert(OptoReg::add(OptoReg::Name(reg), 1));
705 #endif
706 }
707
708 // Input RegMask array shared by all TailCalls
709 uint tail_call_edge_cnt = TypeFunc::Parms+2;
710 RegMask *tail_call_rms = init_input_masks( tail_call_edge_cnt + soe_cnt, _return_addr_mask, c_frame_ptr_mask );
711
712 // Input RegMask array shared by all TailJumps
713 uint tail_jump_edge_cnt = TypeFunc::Parms+2;
1019 Node_State nstate = mstack.state();
1020 if (nstate == Visit) {
1021 mstack.set_state(Post_Visit);
1022 Node *oldn = n;
1023 // Old-space or new-space check
1024 if (!C->node_arena()->contains(n)) {
1025 // Old space!
1026 Node* m;
1027 if (has_new_node(n)) { // Not yet Label/Reduced
1028 m = new_node(n);
1029 } else {
1030 if (!is_dontcare(n)) { // Matcher can match this guy
1031 // Calls match special. They match alone with no children.
1032 // Their children, the incoming arguments, match normally.
1033 m = n->is_SafePoint() ? match_sfpt(n->as_SafePoint()):match_tree(n);
1034 if (C->failing()) return NULL;
1035 if (m == NULL) { Matcher::soft_match_failure(); return NULL; }
1036 } else { // Nothing the matcher cares about
1037 if( n->is_Proj() && n->in(0)->is_Multi()) { // Projections?
1038 // Convert to machine-dependent projection
1039 RegMask* mask = NULL;
1040 if (n->in(0)->is_Call()) {
1041 mask = return_values_mask(n->in(0)->as_Call()->tf()->range_cc());
1042 }
1043 m = n->in(0)->as_Multi()->match(n->as_Proj(), this, mask);
1044 #ifdef ASSERT
1045 _new2old_map.map(m->_idx, n);
1046 #endif
1047 if (m->in(0) != NULL) // m might be top
1048 collect_null_checks(m, n);
1049 } else { // Else just a regular 'ol guy
1050 m = n->clone(); // So just clone into new-space
1051 #ifdef ASSERT
1052 _new2old_map.map(m->_idx, n);
1053 #endif
1054 // Def-Use edges will be added incrementally as Uses
1055 // of this node are matched.
1056 assert(m->outcnt() == 0, "no Uses of this clone yet");
1057 }
1058 }
1059
1060 set_new_node(n, m); // Map old to new
1061 if (_old_node_note_array != NULL) {
1062 Node_Notes* nn = C->locate_node_notes(_old_node_note_array,
1063 n->_idx);
1323 }
1324 } // End of for all arguments
1325
1326 // Compute number of stack slots needed to restore stack in case of
1327 // Pascal-style argument popping.
1328 mcall->_argsize = out_arg_limit_per_call - begin_out_arg_area;
1329 }
1330
1331 // Compute the max stack slot killed by any call. These will not be
1332 // available for debug info, and will be used to adjust FIRST_STACK_mask
1333 // after all call sites have been visited.
1334 if( _out_arg_limit < out_arg_limit_per_call)
1335 _out_arg_limit = out_arg_limit_per_call;
1336
1337 if (mcall) {
1338 // Kill the outgoing argument area, including any non-argument holes and
1339 // any legacy C-killed slots. Use Fat-Projections to do the killing.
1340 // Since the max-per-method covers the max-per-call-site and debug info
1341 // is excluded on the max-per-method basis, debug info cannot land in
1342 // this killed area.
1343 uint r_cnt = mcall->tf()->range_sig()->cnt();
1344 MachProjNode *proj = new MachProjNode( mcall, r_cnt+10000, RegMask::Empty, MachProjNode::fat_proj );
1345 if (!RegMask::can_represent_arg(OptoReg::Name(out_arg_limit_per_call-1))) {
1346 C->record_method_not_compilable("unsupported outgoing calling sequence");
1347 } else {
1348 for (int i = begin_out_arg_area; i < out_arg_limit_per_call; i++)
1349 proj->_rout.Insert(OptoReg::Name(i));
1350 }
1351 if (proj->_rout.is_NotEmpty()) {
1352 push_projection(proj);
1353 }
1354 }
1355 // Transfer the safepoint information from the call to the mcall
1356 // Move the JVMState list
1357 msfpt->set_jvms(sfpt->jvms());
1358 for (JVMState* jvms = msfpt->jvms(); jvms; jvms = jvms->caller()) {
1359 jvms->set_map(sfpt);
1360 }
1361
1362 // Debug inputs begin just after the last incoming parameter
1363 assert((mcall == NULL) || (mcall->jvms() == NULL) ||
|