1 /*
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "memory/allocation.inline.hpp"
27 #include "opto/addnode.hpp"
28 #include "opto/callnode.hpp"
29 #include "opto/connode.hpp"
30 #include "opto/idealGraphPrinter.hpp"
31 #include "opto/matcher.hpp"
32 #include "opto/memnode.hpp"
33 #include "opto/opcodes.hpp"
34 #include "opto/regmask.hpp"
35 #include "opto/rootnode.hpp"
36 #include "opto/runtime.hpp"
37 #include "opto/type.hpp"
38 #include "runtime/atomic.hpp"
39 #include "runtime/os.hpp"
40 #ifdef TARGET_ARCH_MODEL_x86_32
41 # include "adfiles/ad_x86_32.hpp"
42 #endif
43 #ifdef TARGET_ARCH_MODEL_x86_64
44 # include "adfiles/ad_x86_64.hpp"
45 #endif
46 #ifdef TARGET_ARCH_MODEL_sparc
47 # include "adfiles/ad_sparc.hpp"
48 #endif
49 #ifdef TARGET_ARCH_MODEL_zero
50 # include "adfiles/ad_zero.hpp"
51 #endif
52 #ifdef TARGET_ARCH_MODEL_arm
53 # include "adfiles/ad_arm.hpp"
54 #endif
55 #ifdef TARGET_ARCH_MODEL_ppc
56 # include "adfiles/ad_ppc.hpp"
57 #endif
58
59 OptoReg::Name OptoReg::c_frame_pointer;
60
61
62
63 const int Matcher::base2reg[Type::lastype] = {
64 Node::NotAMachineReg,0,0, Op_RegI, Op_RegL, 0, Op_RegN,
65 Node::NotAMachineReg, Node::NotAMachineReg, /* tuple, array */
66 Op_RegP, Op_RegP, Op_RegP, Op_RegP, Op_RegP, Op_RegP, /* the pointers */
67 0, 0/*abio*/,
68 Op_RegP /* Return address */, 0, /* the memories */
69 Op_RegF, Op_RegF, Op_RegF, Op_RegD, Op_RegD, Op_RegD,
70 0 /*bottom*/
71 };
72
73 const RegMask *Matcher::idealreg2regmask[_last_machine_leaf];
74 RegMask Matcher::mreg2regmask[_last_Mach_Reg];
75 RegMask Matcher::STACK_ONLY_mask;
76 RegMask Matcher::c_frame_ptr_mask;
77 const uint Matcher::_begin_rematerialize = _BEGIN_REMATERIALIZE;
78 const uint Matcher::_end_rematerialize = _END_REMATERIALIZE;
79
80 //---------------------------Matcher-------------------------------------------
81 Matcher::Matcher( Node_List &proj_list ) :
82 PhaseTransform( Phase::Ins_Select ),
83 #ifdef ASSERT
84 _old2new_map(C->comp_arena()),
85 _new2old_map(C->comp_arena()),
86 #endif
87 _shared_nodes(C->comp_arena()),
88 _reduceOp(reduceOp), _leftOp(leftOp), _rightOp(rightOp),
89 _swallowed(swallowed),
90 _begin_inst_chain_rule(_BEGIN_INST_CHAIN_RULE),
91 _end_inst_chain_rule(_END_INST_CHAIN_RULE),
92 _must_clone(must_clone), _proj_list(proj_list),
93 _register_save_policy(register_save_policy),
94 _c_reg_save_policy(c_reg_save_policy),
95 _register_save_type(register_save_type),
96 _ruleName(ruleName),
97 _allocation_started(false),
98 _states_arena(Chunk::medium_size),
99 _visited(&_states_arena),
100 _shared(&_states_arena),
101 _dontcare(&_states_arena) {
102 C->set_matcher(this);
103
104 idealreg2spillmask [Op_RegI] = NULL;
105 idealreg2spillmask [Op_RegN] = NULL;
106 idealreg2spillmask [Op_RegL] = NULL;
107 idealreg2spillmask [Op_RegF] = NULL;
108 idealreg2spillmask [Op_RegD] = NULL;
109 idealreg2spillmask [Op_RegP] = NULL;
110
111 idealreg2debugmask [Op_RegI] = NULL;
112 idealreg2debugmask [Op_RegN] = NULL;
113 idealreg2debugmask [Op_RegL] = NULL;
114 idealreg2debugmask [Op_RegF] = NULL;
115 idealreg2debugmask [Op_RegD] = NULL;
116 idealreg2debugmask [Op_RegP] = NULL;
117
118 idealreg2mhdebugmask[Op_RegI] = NULL;
119 idealreg2mhdebugmask[Op_RegN] = NULL;
120 idealreg2mhdebugmask[Op_RegL] = NULL;
121 idealreg2mhdebugmask[Op_RegF] = NULL;
122 idealreg2mhdebugmask[Op_RegD] = NULL;
123 idealreg2mhdebugmask[Op_RegP] = NULL;
124
125 debug_only(_mem_node = NULL;) // Ideal memory node consumed by mach node
126 }
127
128 //------------------------------warp_incoming_stk_arg------------------------
129 // This warps a VMReg into an OptoReg::Name
130 OptoReg::Name Matcher::warp_incoming_stk_arg( VMReg reg ) {
131 OptoReg::Name warped;
132 if( reg->is_stack() ) { // Stack slot argument?
133 warped = OptoReg::add(_old_SP, reg->reg2stack() );
134 warped = OptoReg::add(warped, C->out_preserve_stack_slots());
135 if( warped >= _in_arg_limit )
136 _in_arg_limit = OptoReg::add(warped, 1); // Bump max stack slot seen
137 if (!RegMask::can_represent(warped)) {
138 // the compiler cannot represent this method's calling sequence
139 C->record_method_not_compilable_all_tiers("unsupported incoming calling sequence");
140 return OptoReg::Bad;
141 }
142 return warped;
143 }
144 return OptoReg::as_OptoReg(reg);
145 }
146
147 //---------------------------compute_old_SP------------------------------------
148 OptoReg::Name Compile::compute_old_SP() {
149 int fixed = fixed_slots();
150 int preserve = in_preserve_stack_slots();
151 return OptoReg::stack2reg(round_to(fixed + preserve, Matcher::stack_alignment_in_slots()));
152 }
153
154
155
156 #ifdef ASSERT
157 void Matcher::verify_new_nodes_only(Node* xroot) {
285 if( OptoReg::is_valid(reg2))
286 _calling_convention_mask[i].Insert(reg2);
287
288 // Saved biased stack-slot register number
289 _parm_regs[i].set_pair(reg2, reg1);
290 }
291
292 // Finally, make sure the incoming arguments take up an even number of
293 // words, in case the arguments or locals need to contain doubleword stack
294 // slots. The rest of the system assumes that stack slot pairs (in
295 // particular, in the spill area) which look aligned will in fact be
296 // aligned relative to the stack pointer in the target machine. Double
297 // stack slots will always be allocated aligned.
298 _new_SP = OptoReg::Name(round_to(_in_arg_limit, RegMask::SlotsPerLong));
299
300 // Compute highest outgoing stack argument as
301 // _new_SP + out_preserve_stack_slots + max(outgoing argument size).
302 _out_arg_limit = OptoReg::add(_new_SP, C->out_preserve_stack_slots());
303 assert( is_even(_out_arg_limit), "out_preserve must be even" );
304
305 if (!RegMask::can_represent(OptoReg::add(_out_arg_limit,-1))) {
306 // the compiler cannot represent this method's calling sequence
307 C->record_method_not_compilable("must be able to represent all call arguments in reg mask");
308 }
309
310 if (C->failing()) return; // bailed out on incoming arg failure
311
312 // ---------------
313 // Collect roots of matcher trees. Every node for which
314 // _shared[_idx] is cleared is guaranteed to not be shared, and thus
315 // can be a valid interior of some tree.
316 find_shared( C->root() );
317 find_shared( C->top() );
318
319 C->print_method("Before Matching");
320
321 // Create new ideal node ConP #NULL even if it does exist in old space
322 // to avoid false sharing if the corresponding mach node is not used.
323 // The corresponding mach node is only used in rare cases for derived
324 // pointers.
325 Node* new_ideal_null = ConNode::make(C, TypePtr::NULL_PTR);
411 // course gives them a mask).
412
413 static RegMask *init_input_masks( uint size, RegMask &ret_adr, RegMask &fp ) {
414 RegMask *rms = NEW_RESOURCE_ARRAY( RegMask, size );
415 // Do all the pre-defined register masks
416 rms[TypeFunc::Control ] = RegMask::Empty;
417 rms[TypeFunc::I_O ] = RegMask::Empty;
418 rms[TypeFunc::Memory ] = RegMask::Empty;
419 rms[TypeFunc::ReturnAdr] = ret_adr;
420 rms[TypeFunc::FramePtr ] = fp;
421 return rms;
422 }
423
424 //---------------------------init_first_stack_mask-----------------------------
425 // Create the initial stack mask used by values spilling to the stack.
426 // Disallow any debug info in outgoing argument areas by setting the
427 // initial mask accordingly.
428 void Matcher::init_first_stack_mask() {
429
430 // Allocate storage for spill masks as masks for the appropriate load type.
431 RegMask *rms = (RegMask*)C->comp_arena()->Amalloc_D(sizeof(RegMask) * 3*6);
432
433 idealreg2spillmask [Op_RegN] = &rms[0];
434 idealreg2spillmask [Op_RegI] = &rms[1];
435 idealreg2spillmask [Op_RegL] = &rms[2];
436 idealreg2spillmask [Op_RegF] = &rms[3];
437 idealreg2spillmask [Op_RegD] = &rms[4];
438 idealreg2spillmask [Op_RegP] = &rms[5];
439
440 idealreg2debugmask [Op_RegN] = &rms[6];
441 idealreg2debugmask [Op_RegI] = &rms[7];
442 idealreg2debugmask [Op_RegL] = &rms[8];
443 idealreg2debugmask [Op_RegF] = &rms[9];
444 idealreg2debugmask [Op_RegD] = &rms[10];
445 idealreg2debugmask [Op_RegP] = &rms[11];
446
447 idealreg2mhdebugmask[Op_RegN] = &rms[12];
448 idealreg2mhdebugmask[Op_RegI] = &rms[13];
449 idealreg2mhdebugmask[Op_RegL] = &rms[14];
450 idealreg2mhdebugmask[Op_RegF] = &rms[15];
451 idealreg2mhdebugmask[Op_RegD] = &rms[16];
452 idealreg2mhdebugmask[Op_RegP] = &rms[17];
453
454 OptoReg::Name i;
455
456 // At first, start with the empty mask
457 C->FIRST_STACK_mask().Clear();
458
459 // Add in the incoming argument area
460 OptoReg::Name init = OptoReg::add(_old_SP, C->out_preserve_stack_slots());
461 for (i = init; i < _in_arg_limit; i = OptoReg::add(i,1))
462 C->FIRST_STACK_mask().Insert(i);
463
464 // Add in all bits past the outgoing argument area
465 guarantee(RegMask::can_represent(OptoReg::add(_out_arg_limit,-1)),
466 "must be able to represent all call arguments in reg mask");
467 init = _out_arg_limit;
468 for (i = init; RegMask::can_represent(i); i = OptoReg::add(i,1))
469 C->FIRST_STACK_mask().Insert(i);
470
471 // Finally, set the "infinite stack" bit.
472 C->FIRST_STACK_mask().set_AllStack();
473
474 // Make spill masks. Registers for their class, plus FIRST_STACK_mask.
475 #ifdef _LP64
476 *idealreg2spillmask[Op_RegN] = *idealreg2regmask[Op_RegN];
477 idealreg2spillmask[Op_RegN]->OR(C->FIRST_STACK_mask());
478 #endif
479 *idealreg2spillmask[Op_RegI] = *idealreg2regmask[Op_RegI];
480 idealreg2spillmask[Op_RegI]->OR(C->FIRST_STACK_mask());
481 *idealreg2spillmask[Op_RegL] = *idealreg2regmask[Op_RegL];
482 idealreg2spillmask[Op_RegL]->OR(C->FIRST_STACK_mask());
483 *idealreg2spillmask[Op_RegF] = *idealreg2regmask[Op_RegF];
484 idealreg2spillmask[Op_RegF]->OR(C->FIRST_STACK_mask());
485 *idealreg2spillmask[Op_RegD] = *idealreg2regmask[Op_RegD];
486 idealreg2spillmask[Op_RegD]->OR(C->FIRST_STACK_mask());
487 *idealreg2spillmask[Op_RegP] = *idealreg2regmask[Op_RegP];
488 idealreg2spillmask[Op_RegP]->OR(C->FIRST_STACK_mask());
489
490 if (UseFPUForSpilling) {
491 // This mask logic assumes that the spill operations are
492 // symmetric and that the registers involved are the same size.
493 // On sparc for instance we may have to use 64 bit moves will
494 // kill 2 registers when used with F0-F31.
495 idealreg2spillmask[Op_RegI]->OR(*idealreg2regmask[Op_RegF]);
496 idealreg2spillmask[Op_RegF]->OR(*idealreg2regmask[Op_RegI]);
497 #ifdef _LP64
498 idealreg2spillmask[Op_RegN]->OR(*idealreg2regmask[Op_RegF]);
499 idealreg2spillmask[Op_RegL]->OR(*idealreg2regmask[Op_RegD]);
500 idealreg2spillmask[Op_RegD]->OR(*idealreg2regmask[Op_RegL]);
501 idealreg2spillmask[Op_RegP]->OR(*idealreg2regmask[Op_RegD]);
502 #else
503 idealreg2spillmask[Op_RegP]->OR(*idealreg2regmask[Op_RegF]);
504 #ifdef ARM
505 // ARM has support for moving 64bit values between a pair of
506 // integer registers and a double register
507 idealreg2spillmask[Op_RegL]->OR(*idealreg2regmask[Op_RegD]);
508 idealreg2spillmask[Op_RegD]->OR(*idealreg2regmask[Op_RegL]);
509 #endif
790 #ifdef _LP64
791 MachNode *spillCP = match_tree(new (C, 3) LoadNNode(NULL,mem,fp,atp,TypeInstPtr::BOTTOM));
792 #endif
793 MachNode *spillI = match_tree(new (C, 3) LoadINode(NULL,mem,fp,atp));
794 MachNode *spillL = match_tree(new (C, 3) LoadLNode(NULL,mem,fp,atp));
795 MachNode *spillF = match_tree(new (C, 3) LoadFNode(NULL,mem,fp,atp));
796 MachNode *spillD = match_tree(new (C, 3) LoadDNode(NULL,mem,fp,atp));
797 MachNode *spillP = match_tree(new (C, 3) LoadPNode(NULL,mem,fp,atp,TypeInstPtr::BOTTOM));
798 assert(spillI != NULL && spillL != NULL && spillF != NULL &&
799 spillD != NULL && spillP != NULL, "");
800
801 // Get the ADLC notion of the right regmask, for each basic type.
802 #ifdef _LP64
803 idealreg2regmask[Op_RegN] = &spillCP->out_RegMask();
804 #endif
805 idealreg2regmask[Op_RegI] = &spillI->out_RegMask();
806 idealreg2regmask[Op_RegL] = &spillL->out_RegMask();
807 idealreg2regmask[Op_RegF] = &spillF->out_RegMask();
808 idealreg2regmask[Op_RegD] = &spillD->out_RegMask();
809 idealreg2regmask[Op_RegP] = &spillP->out_RegMask();
810 }
811
812 #ifdef ASSERT
813 static void match_alias_type(Compile* C, Node* n, Node* m) {
814 if (!VerifyAliases) return; // do not go looking for trouble by default
815 const TypePtr* nat = n->adr_type();
816 const TypePtr* mat = m->adr_type();
817 int nidx = C->get_alias_index(nat);
818 int midx = C->get_alias_index(mat);
819 // Detune the assert for cases like (AndI 0xFF (LoadB p)).
820 if (nidx == Compile::AliasIdxTop && midx >= Compile::AliasIdxRaw) {
821 for (uint i = 1; i < n->req(); i++) {
822 Node* n1 = n->in(i);
823 const TypePtr* n1at = n1->adr_type();
824 if (n1at != NULL) {
825 nat = n1at;
826 nidx = C->get_alias_index(n1at);
827 }
828 }
829 }
1046 else {
1047 ShouldNotReachHere();
1048 }
1049 } // while (mstack.is_nonempty())
1050 return n; // Return new-space Node
1051 }
1052
1053 //------------------------------warp_outgoing_stk_arg------------------------
1054 OptoReg::Name Matcher::warp_outgoing_stk_arg( VMReg reg, OptoReg::Name begin_out_arg_area, OptoReg::Name &out_arg_limit_per_call ) {
1055 // Convert outgoing argument location to a pre-biased stack offset
1056 if (reg->is_stack()) {
1057 OptoReg::Name warped = reg->reg2stack();
1058 // Adjust the stack slot offset to be the register number used
1059 // by the allocator.
1060 warped = OptoReg::add(begin_out_arg_area, warped);
1061 // Keep track of the largest numbered stack slot used for an arg.
1062 // Largest used slot per call-site indicates the amount of stack
1063 // that is killed by the call.
1064 if( warped >= out_arg_limit_per_call )
1065 out_arg_limit_per_call = OptoReg::add(warped,1);
1066 if (!RegMask::can_represent(warped)) {
1067 C->record_method_not_compilable_all_tiers("unsupported calling sequence");
1068 return OptoReg::Bad;
1069 }
1070 return warped;
1071 }
1072 return OptoReg::as_OptoReg(reg);
1073 }
1074
1075
1076 //------------------------------match_sfpt-------------------------------------
1077 // Helper function to match call instructions. Calls match special.
1078 // They match alone with no children. Their children, the incoming
1079 // arguments, match normally.
1080 MachNode *Matcher::match_sfpt( SafePointNode *sfpt ) {
1081 MachSafePointNode *msfpt = NULL;
1082 MachCallNode *mcall = NULL;
1083 uint cnt;
1084 // Split out case for SafePoint vs Call
1085 CallNode *call;
1086 const TypeTuple *domain;
1234 int regs_per_word = NOT_LP64(1) LP64_ONLY(2); // %%% make a global const!
1235 out_arg_limit_per_call += MethodHandlePushLimit * regs_per_word;
1236 // Do not update mcall->_argsize because (a) the extra space is not
1237 // pushed as arguments and (b) _argsize is dead (not used anywhere).
1238 }
1239
1240 // Compute the max stack slot killed by any call. These will not be
1241 // available for debug info, and will be used to adjust FIRST_STACK_mask
1242 // after all call sites have been visited.
1243 if( _out_arg_limit < out_arg_limit_per_call)
1244 _out_arg_limit = out_arg_limit_per_call;
1245
1246 if (mcall) {
1247 // Kill the outgoing argument area, including any non-argument holes and
1248 // any legacy C-killed slots. Use Fat-Projections to do the killing.
1249 // Since the max-per-method covers the max-per-call-site and debug info
1250 // is excluded on the max-per-method basis, debug info cannot land in
1251 // this killed area.
1252 uint r_cnt = mcall->tf()->range()->cnt();
1253 MachProjNode *proj = new (C, 1) MachProjNode( mcall, r_cnt+10000, RegMask::Empty, MachProjNode::fat_proj );
1254 if (!RegMask::can_represent(OptoReg::Name(out_arg_limit_per_call-1))) {
1255 C->record_method_not_compilable_all_tiers("unsupported outgoing calling sequence");
1256 } else {
1257 for (int i = begin_out_arg_area; i < out_arg_limit_per_call; i++)
1258 proj->_rout.Insert(OptoReg::Name(i));
1259 }
1260 if( proj->_rout.is_NotEmpty() )
1261 _proj_list.push(proj);
1262 }
1263 // Transfer the safepoint information from the call to the mcall
1264 // Move the JVMState list
1265 msfpt->set_jvms(sfpt->jvms());
1266 for (JVMState* jvms = msfpt->jvms(); jvms; jvms = jvms->caller()) {
1267 jvms->set_map(sfpt);
1268 }
1269
1270 // Debug inputs begin just after the last incoming parameter
1271 assert( (mcall == NULL) || (mcall->jvms() == NULL) ||
1272 (mcall->jvms()->debug_start() + mcall->_jvmadj == mcall->tf()->domain()->cnt()), "" );
1273
1274 // Move the OopMap
|
1 /*
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "memory/allocation.inline.hpp"
27 #include "opto/addnode.hpp"
28 #include "opto/callnode.hpp"
29 #include "opto/connode.hpp"
30 #include "opto/idealGraphPrinter.hpp"
31 #include "opto/matcher.hpp"
32 #include "opto/memnode.hpp"
33 #include "opto/opcodes.hpp"
34 #include "opto/regmask.hpp"
35 #include "opto/rootnode.hpp"
36 #include "opto/runtime.hpp"
37 #include "opto/type.hpp"
38 #include "opto/vectornode.hpp"
39 #include "runtime/atomic.hpp"
40 #include "runtime/os.hpp"
41 #ifdef TARGET_ARCH_MODEL_x86_32
42 # include "adfiles/ad_x86_32.hpp"
43 #endif
44 #ifdef TARGET_ARCH_MODEL_x86_64
45 # include "adfiles/ad_x86_64.hpp"
46 #endif
47 #ifdef TARGET_ARCH_MODEL_sparc
48 # include "adfiles/ad_sparc.hpp"
49 #endif
50 #ifdef TARGET_ARCH_MODEL_zero
51 # include "adfiles/ad_zero.hpp"
52 #endif
53 #ifdef TARGET_ARCH_MODEL_arm
54 # include "adfiles/ad_arm.hpp"
55 #endif
56 #ifdef TARGET_ARCH_MODEL_ppc
57 # include "adfiles/ad_ppc.hpp"
58 #endif
59
60 OptoReg::Name OptoReg::c_frame_pointer;
61
62 const RegMask *Matcher::idealreg2regmask[_last_machine_leaf];
63 RegMask Matcher::mreg2regmask[_last_Mach_Reg];
64 RegMask Matcher::STACK_ONLY_mask;
65 RegMask Matcher::c_frame_ptr_mask;
66 const uint Matcher::_begin_rematerialize = _BEGIN_REMATERIALIZE;
67 const uint Matcher::_end_rematerialize = _END_REMATERIALIZE;
68
69 //---------------------------Matcher-------------------------------------------
70 Matcher::Matcher( Node_List &proj_list ) :
71 PhaseTransform( Phase::Ins_Select ),
72 #ifdef ASSERT
73 _old2new_map(C->comp_arena()),
74 _new2old_map(C->comp_arena()),
75 #endif
76 _shared_nodes(C->comp_arena()),
77 _reduceOp(reduceOp), _leftOp(leftOp), _rightOp(rightOp),
78 _swallowed(swallowed),
79 _begin_inst_chain_rule(_BEGIN_INST_CHAIN_RULE),
80 _end_inst_chain_rule(_END_INST_CHAIN_RULE),
81 _must_clone(must_clone), _proj_list(proj_list),
82 _register_save_policy(register_save_policy),
83 _c_reg_save_policy(c_reg_save_policy),
84 _register_save_type(register_save_type),
85 _ruleName(ruleName),
86 _allocation_started(false),
87 _states_arena(Chunk::medium_size),
88 _visited(&_states_arena),
89 _shared(&_states_arena),
90 _dontcare(&_states_arena) {
91 C->set_matcher(this);
92
93 idealreg2spillmask [Op_RegI] = NULL;
94 idealreg2spillmask [Op_RegN] = NULL;
95 idealreg2spillmask [Op_RegL] = NULL;
96 idealreg2spillmask [Op_RegF] = NULL;
97 idealreg2spillmask [Op_RegD] = NULL;
98 idealreg2spillmask [Op_RegP] = NULL;
99 idealreg2spillmask [Op_VecS] = NULL;
100 idealreg2spillmask [Op_VecD] = NULL;
101 idealreg2spillmask [Op_VecX] = NULL;
102 idealreg2spillmask [Op_VecY] = NULL;
103
104 idealreg2debugmask [Op_RegI] = NULL;
105 idealreg2debugmask [Op_RegN] = NULL;
106 idealreg2debugmask [Op_RegL] = NULL;
107 idealreg2debugmask [Op_RegF] = NULL;
108 idealreg2debugmask [Op_RegD] = NULL;
109 idealreg2debugmask [Op_RegP] = NULL;
110 idealreg2debugmask [Op_VecS] = NULL;
111 idealreg2debugmask [Op_VecD] = NULL;
112 idealreg2debugmask [Op_VecX] = NULL;
113 idealreg2debugmask [Op_VecY] = NULL;
114
115 idealreg2mhdebugmask[Op_RegI] = NULL;
116 idealreg2mhdebugmask[Op_RegN] = NULL;
117 idealreg2mhdebugmask[Op_RegL] = NULL;
118 idealreg2mhdebugmask[Op_RegF] = NULL;
119 idealreg2mhdebugmask[Op_RegD] = NULL;
120 idealreg2mhdebugmask[Op_RegP] = NULL;
121 idealreg2mhdebugmask[Op_VecS] = NULL;
122 idealreg2mhdebugmask[Op_VecD] = NULL;
123 idealreg2mhdebugmask[Op_VecX] = NULL;
124 idealreg2mhdebugmask[Op_VecY] = NULL;
125
126 debug_only(_mem_node = NULL;) // Ideal memory node consumed by mach node
127 }
128
129 //------------------------------warp_incoming_stk_arg------------------------
130 // This warps a VMReg into an OptoReg::Name
131 OptoReg::Name Matcher::warp_incoming_stk_arg( VMReg reg ) {
132 OptoReg::Name warped;
133 if( reg->is_stack() ) { // Stack slot argument?
134 warped = OptoReg::add(_old_SP, reg->reg2stack() );
135 warped = OptoReg::add(warped, C->out_preserve_stack_slots());
136 if( warped >= _in_arg_limit )
137 _in_arg_limit = OptoReg::add(warped, 1); // Bump max stack slot seen
138 if (!RegMask::can_represent_arg(warped)) {
139 // the compiler cannot represent this method's calling sequence
140 C->record_method_not_compilable_all_tiers("unsupported incoming calling sequence");
141 return OptoReg::Bad;
142 }
143 return warped;
144 }
145 return OptoReg::as_OptoReg(reg);
146 }
147
148 //---------------------------compute_old_SP------------------------------------
149 OptoReg::Name Compile::compute_old_SP() {
150 int fixed = fixed_slots();
151 int preserve = in_preserve_stack_slots();
152 return OptoReg::stack2reg(round_to(fixed + preserve, Matcher::stack_alignment_in_slots()));
153 }
154
155
156
157 #ifdef ASSERT
158 void Matcher::verify_new_nodes_only(Node* xroot) {
286 if( OptoReg::is_valid(reg2))
287 _calling_convention_mask[i].Insert(reg2);
288
289 // Saved biased stack-slot register number
290 _parm_regs[i].set_pair(reg2, reg1);
291 }
292
293 // Finally, make sure the incoming arguments take up an even number of
294 // words, in case the arguments or locals need to contain doubleword stack
295 // slots. The rest of the system assumes that stack slot pairs (in
296 // particular, in the spill area) which look aligned will in fact be
297 // aligned relative to the stack pointer in the target machine. Double
298 // stack slots will always be allocated aligned.
299 _new_SP = OptoReg::Name(round_to(_in_arg_limit, RegMask::SlotsPerLong));
300
301 // Compute highest outgoing stack argument as
302 // _new_SP + out_preserve_stack_slots + max(outgoing argument size).
303 _out_arg_limit = OptoReg::add(_new_SP, C->out_preserve_stack_slots());
304 assert( is_even(_out_arg_limit), "out_preserve must be even" );
305
306 if (!RegMask::can_represent_arg(OptoReg::add(_out_arg_limit,-1))) {
307 // the compiler cannot represent this method's calling sequence
308 C->record_method_not_compilable("must be able to represent all call arguments in reg mask");
309 }
310
311 if (C->failing()) return; // bailed out on incoming arg failure
312
313 // ---------------
314 // Collect roots of matcher trees. Every node for which
315 // _shared[_idx] is cleared is guaranteed to not be shared, and thus
316 // can be a valid interior of some tree.
317 find_shared( C->root() );
318 find_shared( C->top() );
319
320 C->print_method("Before Matching");
321
322 // Create new ideal node ConP #NULL even if it does exist in old space
323 // to avoid false sharing if the corresponding mach node is not used.
324 // The corresponding mach node is only used in rare cases for derived
325 // pointers.
326 Node* new_ideal_null = ConNode::make(C, TypePtr::NULL_PTR);
412 // course gives them a mask).
413
414 static RegMask *init_input_masks( uint size, RegMask &ret_adr, RegMask &fp ) {
415 RegMask *rms = NEW_RESOURCE_ARRAY( RegMask, size );
416 // Do all the pre-defined register masks
417 rms[TypeFunc::Control ] = RegMask::Empty;
418 rms[TypeFunc::I_O ] = RegMask::Empty;
419 rms[TypeFunc::Memory ] = RegMask::Empty;
420 rms[TypeFunc::ReturnAdr] = ret_adr;
421 rms[TypeFunc::FramePtr ] = fp;
422 return rms;
423 }
424
425 //---------------------------init_first_stack_mask-----------------------------
426 // Create the initial stack mask used by values spilling to the stack.
427 // Disallow any debug info in outgoing argument areas by setting the
428 // initial mask accordingly.
429 void Matcher::init_first_stack_mask() {
430
431 // Allocate storage for spill masks as masks for the appropriate load type.
432 RegMask *rms = (RegMask*)C->comp_arena()->Amalloc_D(sizeof(RegMask) * (3*6+4));
433
434 idealreg2spillmask [Op_RegN] = &rms[0];
435 idealreg2spillmask [Op_RegI] = &rms[1];
436 idealreg2spillmask [Op_RegL] = &rms[2];
437 idealreg2spillmask [Op_RegF] = &rms[3];
438 idealreg2spillmask [Op_RegD] = &rms[4];
439 idealreg2spillmask [Op_RegP] = &rms[5];
440
441 idealreg2debugmask [Op_RegN] = &rms[6];
442 idealreg2debugmask [Op_RegI] = &rms[7];
443 idealreg2debugmask [Op_RegL] = &rms[8];
444 idealreg2debugmask [Op_RegF] = &rms[9];
445 idealreg2debugmask [Op_RegD] = &rms[10];
446 idealreg2debugmask [Op_RegP] = &rms[11];
447
448 idealreg2mhdebugmask[Op_RegN] = &rms[12];
449 idealreg2mhdebugmask[Op_RegI] = &rms[13];
450 idealreg2mhdebugmask[Op_RegL] = &rms[14];
451 idealreg2mhdebugmask[Op_RegF] = &rms[15];
452 idealreg2mhdebugmask[Op_RegD] = &rms[16];
453 idealreg2mhdebugmask[Op_RegP] = &rms[17];
454
455 idealreg2spillmask [Op_VecS] = &rms[18];
456 idealreg2spillmask [Op_VecD] = &rms[19];
457 idealreg2spillmask [Op_VecX] = &rms[20];
458 idealreg2spillmask [Op_VecY] = &rms[21];
459
460 OptoReg::Name i;
461
462 // At first, start with the empty mask
463 C->FIRST_STACK_mask().Clear();
464
465 // Add in the incoming argument area
466 OptoReg::Name init = OptoReg::add(_old_SP, C->out_preserve_stack_slots());
467 for (i = init; i < _in_arg_limit; i = OptoReg::add(i,1))
468 C->FIRST_STACK_mask().Insert(i);
469
470 // Add in all bits past the outgoing argument area
471 guarantee(RegMask::can_represent_arg(OptoReg::add(_out_arg_limit,-1)),
472 "must be able to represent all call arguments in reg mask");
473 init = _out_arg_limit;
474 for (i = init; RegMask::can_represent(i); i = OptoReg::add(i,1))
475 C->FIRST_STACK_mask().Insert(i);
476
477 // Finally, set the "infinite stack" bit.
478 C->FIRST_STACK_mask().set_AllStack();
479
480 // Make spill masks. Registers for their class, plus FIRST_STACK_mask.
481 RegMask aligned_stack_mask = C->FIRST_STACK_mask();
482 // Keep spill masks aligned.
483 aligned_stack_mask.clear_to_pairs();
484 assert(aligned_stack_mask.is_AllStack(), "should be infinite stack");
485
486 *idealreg2spillmask[Op_RegP] = *idealreg2regmask[Op_RegP];
487 #ifdef _LP64
488 *idealreg2spillmask[Op_RegN] = *idealreg2regmask[Op_RegN];
489 idealreg2spillmask[Op_RegN]->OR(C->FIRST_STACK_mask());
490 idealreg2spillmask[Op_RegP]->OR(aligned_stack_mask);
491 #else
492 idealreg2spillmask[Op_RegP]->OR(C->FIRST_STACK_mask());
493 #endif
494 *idealreg2spillmask[Op_RegI] = *idealreg2regmask[Op_RegI];
495 idealreg2spillmask[Op_RegI]->OR(C->FIRST_STACK_mask());
496 *idealreg2spillmask[Op_RegL] = *idealreg2regmask[Op_RegL];
497 idealreg2spillmask[Op_RegL]->OR(aligned_stack_mask);
498 *idealreg2spillmask[Op_RegF] = *idealreg2regmask[Op_RegF];
499 idealreg2spillmask[Op_RegF]->OR(C->FIRST_STACK_mask());
500 *idealreg2spillmask[Op_RegD] = *idealreg2regmask[Op_RegD];
501 idealreg2spillmask[Op_RegD]->OR(aligned_stack_mask);
502
503 if (Matcher::vector_size_supported(T_BYTE,4)) {
504 *idealreg2spillmask[Op_VecS] = *idealreg2regmask[Op_VecS];
505 idealreg2spillmask[Op_VecS]->OR(C->FIRST_STACK_mask());
506 }
507 if (Matcher::vector_size_supported(T_FLOAT,2)) {
508 *idealreg2spillmask[Op_VecD] = *idealreg2regmask[Op_VecD];
509 idealreg2spillmask[Op_VecD]->OR(aligned_stack_mask);
510 }
511 if (Matcher::vector_size_supported(T_FLOAT,4)) {
512 aligned_stack_mask.clear_to_sets(RegMask::SlotsPerVecX);
513 assert(aligned_stack_mask.is_AllStack(), "should be infinite stack");
514 *idealreg2spillmask[Op_VecX] = *idealreg2regmask[Op_VecX];
515 idealreg2spillmask[Op_VecX]->OR(aligned_stack_mask);
516 }
517 if (Matcher::vector_size_supported(T_FLOAT,8)) {
518 aligned_stack_mask.clear_to_sets(RegMask::SlotsPerVecY);
519 assert(aligned_stack_mask.is_AllStack(), "should be infinite stack");
520 *idealreg2spillmask[Op_VecY] = *idealreg2regmask[Op_VecY];
521 idealreg2spillmask[Op_VecY]->OR(aligned_stack_mask);
522 }
523 if (UseFPUForSpilling) {
524 // This mask logic assumes that the spill operations are
525 // symmetric and that the registers involved are the same size.
526 // On sparc for instance we may have to use 64 bit moves will
527 // kill 2 registers when used with F0-F31.
528 idealreg2spillmask[Op_RegI]->OR(*idealreg2regmask[Op_RegF]);
529 idealreg2spillmask[Op_RegF]->OR(*idealreg2regmask[Op_RegI]);
530 #ifdef _LP64
531 idealreg2spillmask[Op_RegN]->OR(*idealreg2regmask[Op_RegF]);
532 idealreg2spillmask[Op_RegL]->OR(*idealreg2regmask[Op_RegD]);
533 idealreg2spillmask[Op_RegD]->OR(*idealreg2regmask[Op_RegL]);
534 idealreg2spillmask[Op_RegP]->OR(*idealreg2regmask[Op_RegD]);
535 #else
536 idealreg2spillmask[Op_RegP]->OR(*idealreg2regmask[Op_RegF]);
537 #ifdef ARM
538 // ARM has support for moving 64bit values between a pair of
539 // integer registers and a double register
540 idealreg2spillmask[Op_RegL]->OR(*idealreg2regmask[Op_RegD]);
541 idealreg2spillmask[Op_RegD]->OR(*idealreg2regmask[Op_RegL]);
542 #endif
823 #ifdef _LP64
824 MachNode *spillCP = match_tree(new (C, 3) LoadNNode(NULL,mem,fp,atp,TypeInstPtr::BOTTOM));
825 #endif
826 MachNode *spillI = match_tree(new (C, 3) LoadINode(NULL,mem,fp,atp));
827 MachNode *spillL = match_tree(new (C, 3) LoadLNode(NULL,mem,fp,atp));
828 MachNode *spillF = match_tree(new (C, 3) LoadFNode(NULL,mem,fp,atp));
829 MachNode *spillD = match_tree(new (C, 3) LoadDNode(NULL,mem,fp,atp));
830 MachNode *spillP = match_tree(new (C, 3) LoadPNode(NULL,mem,fp,atp,TypeInstPtr::BOTTOM));
831 assert(spillI != NULL && spillL != NULL && spillF != NULL &&
832 spillD != NULL && spillP != NULL, "");
833
834 // Get the ADLC notion of the right regmask, for each basic type.
835 #ifdef _LP64
836 idealreg2regmask[Op_RegN] = &spillCP->out_RegMask();
837 #endif
838 idealreg2regmask[Op_RegI] = &spillI->out_RegMask();
839 idealreg2regmask[Op_RegL] = &spillL->out_RegMask();
840 idealreg2regmask[Op_RegF] = &spillF->out_RegMask();
841 idealreg2regmask[Op_RegD] = &spillD->out_RegMask();
842 idealreg2regmask[Op_RegP] = &spillP->out_RegMask();
843
844 // Vector regmasks.
845 if (Matcher::vector_size_supported(T_BYTE,4)) {
846 TypeVect::VECTS = TypeVect::make(T_BYTE, 4);
847 MachNode *spillVectS = match_tree(new (C, 3) LoadVectorNode(NULL,mem,fp,atp,TypeVect::VECTS));
848 idealreg2regmask[Op_VecS] = &spillVectS->out_RegMask();
849 }
850 if (Matcher::vector_size_supported(T_FLOAT,2)) {
851 MachNode *spillVectD = match_tree(new (C, 3) LoadVectorNode(NULL,mem,fp,atp,TypeVect::VECTD));
852 idealreg2regmask[Op_VecD] = &spillVectD->out_RegMask();
853 }
854 if (Matcher::vector_size_supported(T_FLOAT,4)) {
855 MachNode *spillVectX = match_tree(new (C, 3) LoadVectorNode(NULL,mem,fp,atp,TypeVect::VECTX));
856 idealreg2regmask[Op_VecX] = &spillVectX->out_RegMask();
857 }
858 if (Matcher::vector_size_supported(T_FLOAT,8)) {
859 MachNode *spillVectY = match_tree(new (C, 3) LoadVectorNode(NULL,mem,fp,atp,TypeVect::VECTY));
860 idealreg2regmask[Op_VecY] = &spillVectY->out_RegMask();
861 }
862 }
863
864 #ifdef ASSERT
865 static void match_alias_type(Compile* C, Node* n, Node* m) {
866 if (!VerifyAliases) return; // do not go looking for trouble by default
867 const TypePtr* nat = n->adr_type();
868 const TypePtr* mat = m->adr_type();
869 int nidx = C->get_alias_index(nat);
870 int midx = C->get_alias_index(mat);
871 // Detune the assert for cases like (AndI 0xFF (LoadB p)).
872 if (nidx == Compile::AliasIdxTop && midx >= Compile::AliasIdxRaw) {
873 for (uint i = 1; i < n->req(); i++) {
874 Node* n1 = n->in(i);
875 const TypePtr* n1at = n1->adr_type();
876 if (n1at != NULL) {
877 nat = n1at;
878 nidx = C->get_alias_index(n1at);
879 }
880 }
881 }
1098 else {
1099 ShouldNotReachHere();
1100 }
1101 } // while (mstack.is_nonempty())
1102 return n; // Return new-space Node
1103 }
1104
1105 //------------------------------warp_outgoing_stk_arg------------------------
1106 OptoReg::Name Matcher::warp_outgoing_stk_arg( VMReg reg, OptoReg::Name begin_out_arg_area, OptoReg::Name &out_arg_limit_per_call ) {
1107 // Convert outgoing argument location to a pre-biased stack offset
1108 if (reg->is_stack()) {
1109 OptoReg::Name warped = reg->reg2stack();
1110 // Adjust the stack slot offset to be the register number used
1111 // by the allocator.
1112 warped = OptoReg::add(begin_out_arg_area, warped);
1113 // Keep track of the largest numbered stack slot used for an arg.
1114 // Largest used slot per call-site indicates the amount of stack
1115 // that is killed by the call.
1116 if( warped >= out_arg_limit_per_call )
1117 out_arg_limit_per_call = OptoReg::add(warped,1);
1118 if (!RegMask::can_represent_arg(warped)) {
1119 C->record_method_not_compilable_all_tiers("unsupported calling sequence");
1120 return OptoReg::Bad;
1121 }
1122 return warped;
1123 }
1124 return OptoReg::as_OptoReg(reg);
1125 }
1126
1127
1128 //------------------------------match_sfpt-------------------------------------
1129 // Helper function to match call instructions. Calls match special.
1130 // They match alone with no children. Their children, the incoming
1131 // arguments, match normally.
1132 MachNode *Matcher::match_sfpt( SafePointNode *sfpt ) {
1133 MachSafePointNode *msfpt = NULL;
1134 MachCallNode *mcall = NULL;
1135 uint cnt;
1136 // Split out case for SafePoint vs Call
1137 CallNode *call;
1138 const TypeTuple *domain;
1286 int regs_per_word = NOT_LP64(1) LP64_ONLY(2); // %%% make a global const!
1287 out_arg_limit_per_call += MethodHandlePushLimit * regs_per_word;
1288 // Do not update mcall->_argsize because (a) the extra space is not
1289 // pushed as arguments and (b) _argsize is dead (not used anywhere).
1290 }
1291
1292 // Compute the max stack slot killed by any call. These will not be
1293 // available for debug info, and will be used to adjust FIRST_STACK_mask
1294 // after all call sites have been visited.
1295 if( _out_arg_limit < out_arg_limit_per_call)
1296 _out_arg_limit = out_arg_limit_per_call;
1297
1298 if (mcall) {
1299 // Kill the outgoing argument area, including any non-argument holes and
1300 // any legacy C-killed slots. Use Fat-Projections to do the killing.
1301 // Since the max-per-method covers the max-per-call-site and debug info
1302 // is excluded on the max-per-method basis, debug info cannot land in
1303 // this killed area.
1304 uint r_cnt = mcall->tf()->range()->cnt();
1305 MachProjNode *proj = new (C, 1) MachProjNode( mcall, r_cnt+10000, RegMask::Empty, MachProjNode::fat_proj );
1306 if (!RegMask::can_represent_arg(OptoReg::Name(out_arg_limit_per_call-1))) {
1307 C->record_method_not_compilable_all_tiers("unsupported outgoing calling sequence");
1308 } else {
1309 for (int i = begin_out_arg_area; i < out_arg_limit_per_call; i++)
1310 proj->_rout.Insert(OptoReg::Name(i));
1311 }
1312 if( proj->_rout.is_NotEmpty() )
1313 _proj_list.push(proj);
1314 }
1315 // Transfer the safepoint information from the call to the mcall
1316 // Move the JVMState list
1317 msfpt->set_jvms(sfpt->jvms());
1318 for (JVMState* jvms = msfpt->jvms(); jvms; jvms = jvms->caller()) {
1319 jvms->set_map(sfpt);
1320 }
1321
1322 // Debug inputs begin just after the last incoming parameter
1323 assert( (mcall == NULL) || (mcall->jvms() == NULL) ||
1324 (mcall->jvms()->debug_start() + mcall->_jvmadj == mcall->tf()->domain()->cnt()), "" );
1325
1326 // Move the OopMap
|