annotate src/cpu/x86/vm/c1_LinearScan_x86.cpp @ 71:3d62cb85208d

6662967: Optimize I2D conversion on new x86 Summary: Use CVTDQ2PS and CVTDQ2PD for integer values conversions to float and double values on new AMD cpu. Reviewed-by: sgoldman, never
author kvn
date Wed, 19 Mar 2008 15:33:25 -0700
parents a61af66fc99e
children ff1a29907b6c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 #include "incls/_precompiled.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
26 #include "incls/_c1_LinearScan_x86.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28
a61af66fc99e Initial load
duke
parents:
diff changeset
29 //----------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
30 // Allocation of FPU stack slots (Intel x86 only)
a61af66fc99e Initial load
duke
parents:
diff changeset
31 //----------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
32
a61af66fc99e Initial load
duke
parents:
diff changeset
33 void LinearScan::allocate_fpu_stack() {
a61af66fc99e Initial load
duke
parents:
diff changeset
34 // First compute which FPU registers are live at the start of each basic block
a61af66fc99e Initial load
duke
parents:
diff changeset
35 // (To minimize the amount of work we have to do if we have to merge FPU stacks)
a61af66fc99e Initial load
duke
parents:
diff changeset
36 if (ComputeExactFPURegisterUsage) {
a61af66fc99e Initial load
duke
parents:
diff changeset
37 Interval* intervals_in_register, *intervals_in_memory;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 create_unhandled_lists(&intervals_in_register, &intervals_in_memory, is_in_fpu_register, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
39
a61af66fc99e Initial load
duke
parents:
diff changeset
40 // ignore memory intervals by overwriting intervals_in_memory
a61af66fc99e Initial load
duke
parents:
diff changeset
41 // the dummy interval is needed to enforce the walker to walk until the given id:
a61af66fc99e Initial load
duke
parents:
diff changeset
42 // without it, the walker stops when the unhandled-list is empty -> live information
a61af66fc99e Initial load
duke
parents:
diff changeset
43 // beyond this point would be incorrect.
a61af66fc99e Initial load
duke
parents:
diff changeset
44 Interval* dummy_interval = new Interval(any_reg);
a61af66fc99e Initial load
duke
parents:
diff changeset
45 dummy_interval->add_range(max_jint - 2, max_jint - 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
46 dummy_interval->set_next(Interval::end());
a61af66fc99e Initial load
duke
parents:
diff changeset
47 intervals_in_memory = dummy_interval;
a61af66fc99e Initial load
duke
parents:
diff changeset
48
a61af66fc99e Initial load
duke
parents:
diff changeset
49 IntervalWalker iw(this, intervals_in_register, intervals_in_memory);
a61af66fc99e Initial load
duke
parents:
diff changeset
50
a61af66fc99e Initial load
duke
parents:
diff changeset
51 const int num_blocks = block_count();
a61af66fc99e Initial load
duke
parents:
diff changeset
52 for (int i = 0; i < num_blocks; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
53 BlockBegin* b = block_at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
54
a61af66fc99e Initial load
duke
parents:
diff changeset
55 // register usage is only needed for merging stacks -> compute only
a61af66fc99e Initial load
duke
parents:
diff changeset
56 // when more than one predecessor.
a61af66fc99e Initial load
duke
parents:
diff changeset
57 // the block must not have any spill moves at the beginning (checked by assertions)
a61af66fc99e Initial load
duke
parents:
diff changeset
58 // spill moves would use intervals that are marked as handled and so the usage bit
a61af66fc99e Initial load
duke
parents:
diff changeset
59 // would been set incorrectly
a61af66fc99e Initial load
duke
parents:
diff changeset
60
a61af66fc99e Initial load
duke
parents:
diff changeset
61 // NOTE: the check for number_of_preds > 1 is necessary. A block with only one
a61af66fc99e Initial load
duke
parents:
diff changeset
62 // predecessor may have spill moves at the begin of the block.
a61af66fc99e Initial load
duke
parents:
diff changeset
63 // If an interval ends at the current instruction id, it is not possible
a61af66fc99e Initial load
duke
parents:
diff changeset
64 // to decide if the register is live or not at the block begin -> the
a61af66fc99e Initial load
duke
parents:
diff changeset
65 // register information would be incorrect.
a61af66fc99e Initial load
duke
parents:
diff changeset
66 if (b->number_of_preds() > 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
67 int id = b->first_lir_instruction_id();
a61af66fc99e Initial load
duke
parents:
diff changeset
68 BitMap regs(FrameMap::nof_fpu_regs);
a61af66fc99e Initial load
duke
parents:
diff changeset
69 regs.clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
70
a61af66fc99e Initial load
duke
parents:
diff changeset
71 iw.walk_to(id); // walk after the first instruction (always a label) of the block
a61af66fc99e Initial load
duke
parents:
diff changeset
72 assert(iw.current_position() == id, "did not walk completely to id");
a61af66fc99e Initial load
duke
parents:
diff changeset
73
a61af66fc99e Initial load
duke
parents:
diff changeset
74 // Only consider FPU values in registers
a61af66fc99e Initial load
duke
parents:
diff changeset
75 Interval* interval = iw.active_first(fixedKind);
a61af66fc99e Initial load
duke
parents:
diff changeset
76 while (interval != Interval::end()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
77 int reg = interval->assigned_reg();
a61af66fc99e Initial load
duke
parents:
diff changeset
78 assert(reg >= pd_first_fpu_reg && reg <= pd_last_fpu_reg, "no fpu register");
a61af66fc99e Initial load
duke
parents:
diff changeset
79 assert(interval->assigned_regHi() == -1, "must not have hi register (doubles stored in one register)");
a61af66fc99e Initial load
duke
parents:
diff changeset
80 assert(interval->from() <= id && id < interval->to(), "interval out of range");
a61af66fc99e Initial load
duke
parents:
diff changeset
81
a61af66fc99e Initial load
duke
parents:
diff changeset
82 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
83 if (TraceFPURegisterUsage) {
a61af66fc99e Initial load
duke
parents:
diff changeset
84 tty->print("fpu reg %d is live because of ", reg - pd_first_fpu_reg); interval->print();
a61af66fc99e Initial load
duke
parents:
diff changeset
85 }
a61af66fc99e Initial load
duke
parents:
diff changeset
86 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
87
a61af66fc99e Initial load
duke
parents:
diff changeset
88 regs.set_bit(reg - pd_first_fpu_reg);
a61af66fc99e Initial load
duke
parents:
diff changeset
89 interval = interval->next();
a61af66fc99e Initial load
duke
parents:
diff changeset
90 }
a61af66fc99e Initial load
duke
parents:
diff changeset
91
a61af66fc99e Initial load
duke
parents:
diff changeset
92 b->set_fpu_register_usage(regs);
a61af66fc99e Initial load
duke
parents:
diff changeset
93
a61af66fc99e Initial load
duke
parents:
diff changeset
94 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
95 if (TraceFPURegisterUsage) {
a61af66fc99e Initial load
duke
parents:
diff changeset
96 tty->print("FPU regs for block %d, LIR instr %d): ", b->block_id(), id); regs.print_on(tty); tty->print_cr("");
a61af66fc99e Initial load
duke
parents:
diff changeset
97 }
a61af66fc99e Initial load
duke
parents:
diff changeset
98 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
99 }
a61af66fc99e Initial load
duke
parents:
diff changeset
100 }
a61af66fc99e Initial load
duke
parents:
diff changeset
101 }
a61af66fc99e Initial load
duke
parents:
diff changeset
102
a61af66fc99e Initial load
duke
parents:
diff changeset
103 FpuStackAllocator alloc(ir()->compilation(), this);
a61af66fc99e Initial load
duke
parents:
diff changeset
104 _fpu_stack_allocator = &alloc;
a61af66fc99e Initial load
duke
parents:
diff changeset
105 alloc.allocate();
a61af66fc99e Initial load
duke
parents:
diff changeset
106 _fpu_stack_allocator = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
107 }
a61af66fc99e Initial load
duke
parents:
diff changeset
108
a61af66fc99e Initial load
duke
parents:
diff changeset
109
a61af66fc99e Initial load
duke
parents:
diff changeset
110 FpuStackAllocator::FpuStackAllocator(Compilation* compilation, LinearScan* allocator)
a61af66fc99e Initial load
duke
parents:
diff changeset
111 : _compilation(compilation)
a61af66fc99e Initial load
duke
parents:
diff changeset
112 , _lir(NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
113 , _pos(-1)
a61af66fc99e Initial load
duke
parents:
diff changeset
114 , _allocator(allocator)
a61af66fc99e Initial load
duke
parents:
diff changeset
115 , _sim(compilation)
a61af66fc99e Initial load
duke
parents:
diff changeset
116 , _temp_sim(compilation)
a61af66fc99e Initial load
duke
parents:
diff changeset
117 {}
a61af66fc99e Initial load
duke
parents:
diff changeset
118
a61af66fc99e Initial load
duke
parents:
diff changeset
119 void FpuStackAllocator::allocate() {
a61af66fc99e Initial load
duke
parents:
diff changeset
120 int num_blocks = allocator()->block_count();
a61af66fc99e Initial load
duke
parents:
diff changeset
121 for (int i = 0; i < num_blocks; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
122 // Set up to process block
a61af66fc99e Initial load
duke
parents:
diff changeset
123 BlockBegin* block = allocator()->block_at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
124 intArray* fpu_stack_state = block->fpu_stack_state();
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
127 if (TraceFPUStack) {
a61af66fc99e Initial load
duke
parents:
diff changeset
128 tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
129 tty->print_cr("------- Begin of new Block %d -------", block->block_id());
a61af66fc99e Initial load
duke
parents:
diff changeset
130 }
a61af66fc99e Initial load
duke
parents:
diff changeset
131 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
132
a61af66fc99e Initial load
duke
parents:
diff changeset
133 assert(fpu_stack_state != NULL ||
a61af66fc99e Initial load
duke
parents:
diff changeset
134 block->end()->as_Base() != NULL ||
a61af66fc99e Initial load
duke
parents:
diff changeset
135 block->is_set(BlockBegin::exception_entry_flag),
a61af66fc99e Initial load
duke
parents:
diff changeset
136 "FPU stack state must be present due to linear-scan order for FPU stack allocation");
a61af66fc99e Initial load
duke
parents:
diff changeset
137 // note: exception handler entries always start with an empty fpu stack
a61af66fc99e Initial load
duke
parents:
diff changeset
138 // because stack merging would be too complicated
a61af66fc99e Initial load
duke
parents:
diff changeset
139
a61af66fc99e Initial load
duke
parents:
diff changeset
140 if (fpu_stack_state != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
141 sim()->read_state(fpu_stack_state);
a61af66fc99e Initial load
duke
parents:
diff changeset
142 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
143 sim()->clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
144 }
a61af66fc99e Initial load
duke
parents:
diff changeset
145
a61af66fc99e Initial load
duke
parents:
diff changeset
146 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
147 if (TraceFPUStack) {
a61af66fc99e Initial load
duke
parents:
diff changeset
148 tty->print("Reading FPU state for block %d:", block->block_id());
a61af66fc99e Initial load
duke
parents:
diff changeset
149 sim()->print();
a61af66fc99e Initial load
duke
parents:
diff changeset
150 tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
151 }
a61af66fc99e Initial load
duke
parents:
diff changeset
152 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
153
a61af66fc99e Initial load
duke
parents:
diff changeset
154 allocate_block(block);
a61af66fc99e Initial load
duke
parents:
diff changeset
155 CHECK_BAILOUT();
a61af66fc99e Initial load
duke
parents:
diff changeset
156 }
a61af66fc99e Initial load
duke
parents:
diff changeset
157 }
a61af66fc99e Initial load
duke
parents:
diff changeset
158
a61af66fc99e Initial load
duke
parents:
diff changeset
159 void FpuStackAllocator::allocate_block(BlockBegin* block) {
a61af66fc99e Initial load
duke
parents:
diff changeset
160 bool processed_merge = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
161 LIR_OpList* insts = block->lir()->instructions_list();
a61af66fc99e Initial load
duke
parents:
diff changeset
162 set_lir(block->lir());
a61af66fc99e Initial load
duke
parents:
diff changeset
163 set_pos(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
164
a61af66fc99e Initial load
duke
parents:
diff changeset
165
a61af66fc99e Initial load
duke
parents:
diff changeset
166 // Note: insts->length() may change during loop
a61af66fc99e Initial load
duke
parents:
diff changeset
167 while (pos() < insts->length()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
168 LIR_Op* op = insts->at(pos());
a61af66fc99e Initial load
duke
parents:
diff changeset
169 _debug_information_computed = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
170
a61af66fc99e Initial load
duke
parents:
diff changeset
171 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
172 if (TraceFPUStack) {
a61af66fc99e Initial load
duke
parents:
diff changeset
173 op->print();
a61af66fc99e Initial load
duke
parents:
diff changeset
174 }
a61af66fc99e Initial load
duke
parents:
diff changeset
175 check_invalid_lir_op(op);
a61af66fc99e Initial load
duke
parents:
diff changeset
176 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
177
a61af66fc99e Initial load
duke
parents:
diff changeset
178 LIR_OpBranch* branch = op->as_OpBranch();
a61af66fc99e Initial load
duke
parents:
diff changeset
179 LIR_Op1* op1 = op->as_Op1();
a61af66fc99e Initial load
duke
parents:
diff changeset
180 LIR_Op2* op2 = op->as_Op2();
a61af66fc99e Initial load
duke
parents:
diff changeset
181 LIR_OpCall* opCall = op->as_OpCall();
a61af66fc99e Initial load
duke
parents:
diff changeset
182
a61af66fc99e Initial load
duke
parents:
diff changeset
183 if (branch != NULL && branch->block() != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
184 if (!processed_merge) {
a61af66fc99e Initial load
duke
parents:
diff changeset
185 // propagate stack at first branch to a successor
a61af66fc99e Initial load
duke
parents:
diff changeset
186 processed_merge = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
187 bool required_merge = merge_fpu_stack_with_successors(block);
a61af66fc99e Initial load
duke
parents:
diff changeset
188
a61af66fc99e Initial load
duke
parents:
diff changeset
189 assert(!required_merge || branch->cond() == lir_cond_always, "splitting of critical edges should prevent FPU stack mismatches at cond branches");
a61af66fc99e Initial load
duke
parents:
diff changeset
190 }
a61af66fc99e Initial load
duke
parents:
diff changeset
191
a61af66fc99e Initial load
duke
parents:
diff changeset
192 } else if (op1 != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
193 handle_op1(op1);
a61af66fc99e Initial load
duke
parents:
diff changeset
194 } else if (op2 != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
195 handle_op2(op2);
a61af66fc99e Initial load
duke
parents:
diff changeset
196 } else if (opCall != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
197 handle_opCall(opCall);
a61af66fc99e Initial load
duke
parents:
diff changeset
198 }
a61af66fc99e Initial load
duke
parents:
diff changeset
199
a61af66fc99e Initial load
duke
parents:
diff changeset
200 compute_debug_information(op);
a61af66fc99e Initial load
duke
parents:
diff changeset
201
a61af66fc99e Initial load
duke
parents:
diff changeset
202 set_pos(1 + pos());
a61af66fc99e Initial load
duke
parents:
diff changeset
203 }
a61af66fc99e Initial load
duke
parents:
diff changeset
204
a61af66fc99e Initial load
duke
parents:
diff changeset
205 // Propagate stack when block does not end with branch
a61af66fc99e Initial load
duke
parents:
diff changeset
206 if (!processed_merge) {
a61af66fc99e Initial load
duke
parents:
diff changeset
207 merge_fpu_stack_with_successors(block);
a61af66fc99e Initial load
duke
parents:
diff changeset
208 }
a61af66fc99e Initial load
duke
parents:
diff changeset
209 }
a61af66fc99e Initial load
duke
parents:
diff changeset
210
a61af66fc99e Initial load
duke
parents:
diff changeset
211
a61af66fc99e Initial load
duke
parents:
diff changeset
212 void FpuStackAllocator::compute_debug_information(LIR_Op* op) {
a61af66fc99e Initial load
duke
parents:
diff changeset
213 if (!_debug_information_computed && op->id() != -1 && allocator()->has_info(op->id())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
214 visitor.visit(op);
a61af66fc99e Initial load
duke
parents:
diff changeset
215
a61af66fc99e Initial load
duke
parents:
diff changeset
216 // exception handling
a61af66fc99e Initial load
duke
parents:
diff changeset
217 if (allocator()->compilation()->has_exception_handlers()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
218 XHandlers* xhandlers = visitor.all_xhandler();
a61af66fc99e Initial load
duke
parents:
diff changeset
219 int n = xhandlers->length();
a61af66fc99e Initial load
duke
parents:
diff changeset
220 for (int k = 0; k < n; k++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
221 allocate_exception_handler(xhandlers->handler_at(k));
a61af66fc99e Initial load
duke
parents:
diff changeset
222 }
a61af66fc99e Initial load
duke
parents:
diff changeset
223 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
224 assert(visitor.all_xhandler()->length() == 0, "missed exception handler");
a61af66fc99e Initial load
duke
parents:
diff changeset
225 }
a61af66fc99e Initial load
duke
parents:
diff changeset
226
a61af66fc99e Initial load
duke
parents:
diff changeset
227 // compute debug information
a61af66fc99e Initial load
duke
parents:
diff changeset
228 int n = visitor.info_count();
a61af66fc99e Initial load
duke
parents:
diff changeset
229 assert(n > 0, "should not visit operation otherwise");
a61af66fc99e Initial load
duke
parents:
diff changeset
230
a61af66fc99e Initial load
duke
parents:
diff changeset
231 for (int j = 0; j < n; j++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
232 CodeEmitInfo* info = visitor.info_at(j);
a61af66fc99e Initial load
duke
parents:
diff changeset
233 // Compute debug information
a61af66fc99e Initial load
duke
parents:
diff changeset
234 allocator()->compute_debug_info(info, op->id());
a61af66fc99e Initial load
duke
parents:
diff changeset
235 }
a61af66fc99e Initial load
duke
parents:
diff changeset
236 }
a61af66fc99e Initial load
duke
parents:
diff changeset
237 _debug_information_computed = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
238 }
a61af66fc99e Initial load
duke
parents:
diff changeset
239
a61af66fc99e Initial load
duke
parents:
diff changeset
240 void FpuStackAllocator::allocate_exception_handler(XHandler* xhandler) {
a61af66fc99e Initial load
duke
parents:
diff changeset
241 if (!sim()->is_empty()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
242 LIR_List* old_lir = lir();
a61af66fc99e Initial load
duke
parents:
diff changeset
243 int old_pos = pos();
a61af66fc99e Initial load
duke
parents:
diff changeset
244 intArray* old_state = sim()->write_state();
a61af66fc99e Initial load
duke
parents:
diff changeset
245
a61af66fc99e Initial load
duke
parents:
diff changeset
246 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
247 if (TraceFPUStack) {
a61af66fc99e Initial load
duke
parents:
diff changeset
248 tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
249 tty->print_cr("------- begin of exception handler -------");
a61af66fc99e Initial load
duke
parents:
diff changeset
250 }
a61af66fc99e Initial load
duke
parents:
diff changeset
251 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
252
a61af66fc99e Initial load
duke
parents:
diff changeset
253 if (xhandler->entry_code() == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
254 // need entry code to clear FPU stack
a61af66fc99e Initial load
duke
parents:
diff changeset
255 LIR_List* entry_code = new LIR_List(_compilation);
a61af66fc99e Initial load
duke
parents:
diff changeset
256 entry_code->jump(xhandler->entry_block());
a61af66fc99e Initial load
duke
parents:
diff changeset
257 xhandler->set_entry_code(entry_code);
a61af66fc99e Initial load
duke
parents:
diff changeset
258 }
a61af66fc99e Initial load
duke
parents:
diff changeset
259
a61af66fc99e Initial load
duke
parents:
diff changeset
260 LIR_OpList* insts = xhandler->entry_code()->instructions_list();
a61af66fc99e Initial load
duke
parents:
diff changeset
261 set_lir(xhandler->entry_code());
a61af66fc99e Initial load
duke
parents:
diff changeset
262 set_pos(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
263
a61af66fc99e Initial load
duke
parents:
diff changeset
264 // Note: insts->length() may change during loop
a61af66fc99e Initial load
duke
parents:
diff changeset
265 while (pos() < insts->length()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
266 LIR_Op* op = insts->at(pos());
a61af66fc99e Initial load
duke
parents:
diff changeset
267
a61af66fc99e Initial load
duke
parents:
diff changeset
268 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
269 if (TraceFPUStack) {
a61af66fc99e Initial load
duke
parents:
diff changeset
270 op->print();
a61af66fc99e Initial load
duke
parents:
diff changeset
271 }
a61af66fc99e Initial load
duke
parents:
diff changeset
272 check_invalid_lir_op(op);
a61af66fc99e Initial load
duke
parents:
diff changeset
273 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
274
a61af66fc99e Initial load
duke
parents:
diff changeset
275 switch (op->code()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
276 case lir_move:
a61af66fc99e Initial load
duke
parents:
diff changeset
277 assert(op->as_Op1() != NULL, "must be LIR_Op1");
a61af66fc99e Initial load
duke
parents:
diff changeset
278 assert(pos() != insts->length() - 1, "must not be last operation");
a61af66fc99e Initial load
duke
parents:
diff changeset
279
a61af66fc99e Initial load
duke
parents:
diff changeset
280 handle_op1((LIR_Op1*)op);
a61af66fc99e Initial load
duke
parents:
diff changeset
281 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
282
a61af66fc99e Initial load
duke
parents:
diff changeset
283 case lir_branch:
a61af66fc99e Initial load
duke
parents:
diff changeset
284 assert(op->as_OpBranch()->cond() == lir_cond_always, "must be unconditional branch");
a61af66fc99e Initial load
duke
parents:
diff changeset
285 assert(pos() == insts->length() - 1, "must be last operation");
a61af66fc99e Initial load
duke
parents:
diff changeset
286
a61af66fc99e Initial load
duke
parents:
diff changeset
287 // remove all remaining dead registers from FPU stack
a61af66fc99e Initial load
duke
parents:
diff changeset
288 clear_fpu_stack(LIR_OprFact::illegalOpr);
a61af66fc99e Initial load
duke
parents:
diff changeset
289 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
290
a61af66fc99e Initial load
duke
parents:
diff changeset
291 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
292 // other operations not allowed in exception entry code
a61af66fc99e Initial load
duke
parents:
diff changeset
293 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
294 }
a61af66fc99e Initial load
duke
parents:
diff changeset
295
a61af66fc99e Initial load
duke
parents:
diff changeset
296 set_pos(pos() + 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
297 }
a61af66fc99e Initial load
duke
parents:
diff changeset
298
a61af66fc99e Initial load
duke
parents:
diff changeset
299 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
300 if (TraceFPUStack) {
a61af66fc99e Initial load
duke
parents:
diff changeset
301 tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
302 tty->print_cr("------- end of exception handler -------");
a61af66fc99e Initial load
duke
parents:
diff changeset
303 }
a61af66fc99e Initial load
duke
parents:
diff changeset
304 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
305
a61af66fc99e Initial load
duke
parents:
diff changeset
306 set_lir(old_lir);
a61af66fc99e Initial load
duke
parents:
diff changeset
307 set_pos(old_pos);
a61af66fc99e Initial load
duke
parents:
diff changeset
308 sim()->read_state(old_state);
a61af66fc99e Initial load
duke
parents:
diff changeset
309 }
a61af66fc99e Initial load
duke
parents:
diff changeset
310 }
a61af66fc99e Initial load
duke
parents:
diff changeset
311
a61af66fc99e Initial load
duke
parents:
diff changeset
312
a61af66fc99e Initial load
duke
parents:
diff changeset
313 int FpuStackAllocator::fpu_num(LIR_Opr opr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
314 assert(opr->is_fpu_register() && !opr->is_xmm_register(), "shouldn't call this otherwise");
a61af66fc99e Initial load
duke
parents:
diff changeset
315 return opr->is_single_fpu() ? opr->fpu_regnr() : opr->fpu_regnrLo();
a61af66fc99e Initial load
duke
parents:
diff changeset
316 }
a61af66fc99e Initial load
duke
parents:
diff changeset
317
a61af66fc99e Initial load
duke
parents:
diff changeset
318 int FpuStackAllocator::tos_offset(LIR_Opr opr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
319 return sim()->offset_from_tos(fpu_num(opr));
a61af66fc99e Initial load
duke
parents:
diff changeset
320 }
a61af66fc99e Initial load
duke
parents:
diff changeset
321
a61af66fc99e Initial load
duke
parents:
diff changeset
322
a61af66fc99e Initial load
duke
parents:
diff changeset
323 LIR_Opr FpuStackAllocator::to_fpu_stack(LIR_Opr opr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
324 assert(opr->is_fpu_register() && !opr->is_xmm_register(), "shouldn't call this otherwise");
a61af66fc99e Initial load
duke
parents:
diff changeset
325
a61af66fc99e Initial load
duke
parents:
diff changeset
326 int stack_offset = tos_offset(opr);
a61af66fc99e Initial load
duke
parents:
diff changeset
327 if (opr->is_single_fpu()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
328 return LIR_OprFact::single_fpu(stack_offset)->make_fpu_stack_offset();
a61af66fc99e Initial load
duke
parents:
diff changeset
329 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
330 assert(opr->is_double_fpu(), "shouldn't call this otherwise");
a61af66fc99e Initial load
duke
parents:
diff changeset
331 return LIR_OprFact::double_fpu(stack_offset)->make_fpu_stack_offset();
a61af66fc99e Initial load
duke
parents:
diff changeset
332 }
a61af66fc99e Initial load
duke
parents:
diff changeset
333 }
a61af66fc99e Initial load
duke
parents:
diff changeset
334
a61af66fc99e Initial load
duke
parents:
diff changeset
335 LIR_Opr FpuStackAllocator::to_fpu_stack_top(LIR_Opr opr, bool dont_check_offset) {
a61af66fc99e Initial load
duke
parents:
diff changeset
336 assert(opr->is_fpu_register() && !opr->is_xmm_register(), "shouldn't call this otherwise");
a61af66fc99e Initial load
duke
parents:
diff changeset
337 assert(dont_check_offset || tos_offset(opr) == 0, "operand is not on stack top");
a61af66fc99e Initial load
duke
parents:
diff changeset
338
a61af66fc99e Initial load
duke
parents:
diff changeset
339 int stack_offset = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
340 if (opr->is_single_fpu()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
341 return LIR_OprFact::single_fpu(stack_offset)->make_fpu_stack_offset();
a61af66fc99e Initial load
duke
parents:
diff changeset
342 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
343 assert(opr->is_double_fpu(), "shouldn't call this otherwise");
a61af66fc99e Initial load
duke
parents:
diff changeset
344 return LIR_OprFact::double_fpu(stack_offset)->make_fpu_stack_offset();
a61af66fc99e Initial load
duke
parents:
diff changeset
345 }
a61af66fc99e Initial load
duke
parents:
diff changeset
346 }
a61af66fc99e Initial load
duke
parents:
diff changeset
347
a61af66fc99e Initial load
duke
parents:
diff changeset
348
a61af66fc99e Initial load
duke
parents:
diff changeset
349
a61af66fc99e Initial load
duke
parents:
diff changeset
350 void FpuStackAllocator::insert_op(LIR_Op* op) {
a61af66fc99e Initial load
duke
parents:
diff changeset
351 lir()->insert_before(pos(), op);
a61af66fc99e Initial load
duke
parents:
diff changeset
352 set_pos(1 + pos());
a61af66fc99e Initial load
duke
parents:
diff changeset
353 }
a61af66fc99e Initial load
duke
parents:
diff changeset
354
a61af66fc99e Initial load
duke
parents:
diff changeset
355
a61af66fc99e Initial load
duke
parents:
diff changeset
356 void FpuStackAllocator::insert_exchange(int offset) {
a61af66fc99e Initial load
duke
parents:
diff changeset
357 if (offset > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
358 LIR_Op1* fxch_op = new LIR_Op1(lir_fxch, LIR_OprFact::intConst(offset), LIR_OprFact::illegalOpr);
a61af66fc99e Initial load
duke
parents:
diff changeset
359 insert_op(fxch_op);
a61af66fc99e Initial load
duke
parents:
diff changeset
360 sim()->swap(offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
361
a61af66fc99e Initial load
duke
parents:
diff changeset
362 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
363 if (TraceFPUStack) {
a61af66fc99e Initial load
duke
parents:
diff changeset
364 tty->print("Exchanged register: %d New state: ", sim()->get_slot(0)); sim()->print(); tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
365 }
a61af66fc99e Initial load
duke
parents:
diff changeset
366 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
367
a61af66fc99e Initial load
duke
parents:
diff changeset
368 }
a61af66fc99e Initial load
duke
parents:
diff changeset
369 }
a61af66fc99e Initial load
duke
parents:
diff changeset
370
a61af66fc99e Initial load
duke
parents:
diff changeset
371 void FpuStackAllocator::insert_exchange(LIR_Opr opr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
372 insert_exchange(tos_offset(opr));
a61af66fc99e Initial load
duke
parents:
diff changeset
373 }
a61af66fc99e Initial load
duke
parents:
diff changeset
374
a61af66fc99e Initial load
duke
parents:
diff changeset
375
a61af66fc99e Initial load
duke
parents:
diff changeset
376 void FpuStackAllocator::insert_free(int offset) {
a61af66fc99e Initial load
duke
parents:
diff changeset
377 // move stack slot to the top of stack and then pop it
a61af66fc99e Initial load
duke
parents:
diff changeset
378 insert_exchange(offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
379
a61af66fc99e Initial load
duke
parents:
diff changeset
380 LIR_Op* fpop = new LIR_Op0(lir_fpop_raw);
a61af66fc99e Initial load
duke
parents:
diff changeset
381 insert_op(fpop);
a61af66fc99e Initial load
duke
parents:
diff changeset
382 sim()->pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
383
a61af66fc99e Initial load
duke
parents:
diff changeset
384 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
385 if (TraceFPUStack) {
a61af66fc99e Initial load
duke
parents:
diff changeset
386 tty->print("Inserted pop New state: "); sim()->print(); tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
387 }
a61af66fc99e Initial load
duke
parents:
diff changeset
388 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
389 }
a61af66fc99e Initial load
duke
parents:
diff changeset
390
a61af66fc99e Initial load
duke
parents:
diff changeset
391
a61af66fc99e Initial load
duke
parents:
diff changeset
392 void FpuStackAllocator::insert_free_if_dead(LIR_Opr opr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
393 if (sim()->contains(fpu_num(opr))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
394 int res_slot = tos_offset(opr);
a61af66fc99e Initial load
duke
parents:
diff changeset
395 insert_free(res_slot);
a61af66fc99e Initial load
duke
parents:
diff changeset
396 }
a61af66fc99e Initial load
duke
parents:
diff changeset
397 }
a61af66fc99e Initial load
duke
parents:
diff changeset
398
a61af66fc99e Initial load
duke
parents:
diff changeset
399 void FpuStackAllocator::insert_free_if_dead(LIR_Opr opr, LIR_Opr ignore) {
a61af66fc99e Initial load
duke
parents:
diff changeset
400 if (fpu_num(opr) != fpu_num(ignore) && sim()->contains(fpu_num(opr))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
401 int res_slot = tos_offset(opr);
a61af66fc99e Initial load
duke
parents:
diff changeset
402 insert_free(res_slot);
a61af66fc99e Initial load
duke
parents:
diff changeset
403 }
a61af66fc99e Initial load
duke
parents:
diff changeset
404 }
a61af66fc99e Initial load
duke
parents:
diff changeset
405
a61af66fc99e Initial load
duke
parents:
diff changeset
406 void FpuStackAllocator::insert_copy(LIR_Opr from, LIR_Opr to) {
a61af66fc99e Initial load
duke
parents:
diff changeset
407 int offset = tos_offset(from);
a61af66fc99e Initial load
duke
parents:
diff changeset
408 LIR_Op1* fld = new LIR_Op1(lir_fld, LIR_OprFact::intConst(offset), LIR_OprFact::illegalOpr);
a61af66fc99e Initial load
duke
parents:
diff changeset
409 insert_op(fld);
a61af66fc99e Initial load
duke
parents:
diff changeset
410
a61af66fc99e Initial load
duke
parents:
diff changeset
411 sim()->push(fpu_num(to));
a61af66fc99e Initial load
duke
parents:
diff changeset
412
a61af66fc99e Initial load
duke
parents:
diff changeset
413 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
414 if (TraceFPUStack) {
a61af66fc99e Initial load
duke
parents:
diff changeset
415 tty->print("Inserted copy (%d -> %d) New state: ", fpu_num(from), fpu_num(to)); sim()->print(); tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
416 }
a61af66fc99e Initial load
duke
parents:
diff changeset
417 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
418 }
a61af66fc99e Initial load
duke
parents:
diff changeset
419
a61af66fc99e Initial load
duke
parents:
diff changeset
420 void FpuStackAllocator::do_rename(LIR_Opr from, LIR_Opr to) {
a61af66fc99e Initial load
duke
parents:
diff changeset
421 sim()->rename(fpu_num(from), fpu_num(to));
a61af66fc99e Initial load
duke
parents:
diff changeset
422 }
a61af66fc99e Initial load
duke
parents:
diff changeset
423
a61af66fc99e Initial load
duke
parents:
diff changeset
424 void FpuStackAllocator::do_push(LIR_Opr opr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
425 sim()->push(fpu_num(opr));
a61af66fc99e Initial load
duke
parents:
diff changeset
426 }
a61af66fc99e Initial load
duke
parents:
diff changeset
427
a61af66fc99e Initial load
duke
parents:
diff changeset
428 void FpuStackAllocator::pop_if_last_use(LIR_Op* op, LIR_Opr opr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
429 assert(op->fpu_pop_count() == 0, "fpu_pop_count alredy set");
a61af66fc99e Initial load
duke
parents:
diff changeset
430 assert(tos_offset(opr) == 0, "can only pop stack top");
a61af66fc99e Initial load
duke
parents:
diff changeset
431
a61af66fc99e Initial load
duke
parents:
diff changeset
432 if (opr->is_last_use()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
433 op->set_fpu_pop_count(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
434 sim()->pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
435 }
a61af66fc99e Initial load
duke
parents:
diff changeset
436 }
a61af66fc99e Initial load
duke
parents:
diff changeset
437
a61af66fc99e Initial load
duke
parents:
diff changeset
438 void FpuStackAllocator::pop_always(LIR_Op* op, LIR_Opr opr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
439 assert(op->fpu_pop_count() == 0, "fpu_pop_count alredy set");
a61af66fc99e Initial load
duke
parents:
diff changeset
440 assert(tos_offset(opr) == 0, "can only pop stack top");
a61af66fc99e Initial load
duke
parents:
diff changeset
441
a61af66fc99e Initial load
duke
parents:
diff changeset
442 op->set_fpu_pop_count(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
443 sim()->pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
444 }
a61af66fc99e Initial load
duke
parents:
diff changeset
445
a61af66fc99e Initial load
duke
parents:
diff changeset
446 void FpuStackAllocator::clear_fpu_stack(LIR_Opr preserve) {
a61af66fc99e Initial load
duke
parents:
diff changeset
447 int result_stack_size = (preserve->is_fpu_register() && !preserve->is_xmm_register() ? 1 : 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
448 while (sim()->stack_size() > result_stack_size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
449 assert(!sim()->slot_is_empty(0), "not allowed");
a61af66fc99e Initial load
duke
parents:
diff changeset
450
a61af66fc99e Initial load
duke
parents:
diff changeset
451 if (result_stack_size == 0 || sim()->get_slot(0) != fpu_num(preserve)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
452 insert_free(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
453 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
454 // move "preserve" to bottom of stack so that all other stack slots can be popped
a61af66fc99e Initial load
duke
parents:
diff changeset
455 insert_exchange(sim()->stack_size() - 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
456 }
a61af66fc99e Initial load
duke
parents:
diff changeset
457 }
a61af66fc99e Initial load
duke
parents:
diff changeset
458 }
a61af66fc99e Initial load
duke
parents:
diff changeset
459
a61af66fc99e Initial load
duke
parents:
diff changeset
460
a61af66fc99e Initial load
duke
parents:
diff changeset
461 void FpuStackAllocator::handle_op1(LIR_Op1* op1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
462 LIR_Opr in = op1->in_opr();
a61af66fc99e Initial load
duke
parents:
diff changeset
463 LIR_Opr res = op1->result_opr();
a61af66fc99e Initial load
duke
parents:
diff changeset
464
a61af66fc99e Initial load
duke
parents:
diff changeset
465 LIR_Opr new_in = in; // new operands relative to the actual fpu stack top
a61af66fc99e Initial load
duke
parents:
diff changeset
466 LIR_Opr new_res = res;
a61af66fc99e Initial load
duke
parents:
diff changeset
467
a61af66fc99e Initial load
duke
parents:
diff changeset
468 // Note: this switch is processed for all LIR_Op1, regardless if they have FPU-arguments,
a61af66fc99e Initial load
duke
parents:
diff changeset
469 // so checks for is_float_kind() are necessary inside the cases
a61af66fc99e Initial load
duke
parents:
diff changeset
470 switch (op1->code()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
471
a61af66fc99e Initial load
duke
parents:
diff changeset
472 case lir_return: {
a61af66fc99e Initial load
duke
parents:
diff changeset
473 // FPU-Stack must only contain the (optional) fpu return value.
a61af66fc99e Initial load
duke
parents:
diff changeset
474 // All remaining dead values are popped from the stack
a61af66fc99e Initial load
duke
parents:
diff changeset
475 // If the input operand is a fpu-register, it is exchanged to the bottom of the stack
a61af66fc99e Initial load
duke
parents:
diff changeset
476
a61af66fc99e Initial load
duke
parents:
diff changeset
477 clear_fpu_stack(in);
a61af66fc99e Initial load
duke
parents:
diff changeset
478 if (in->is_fpu_register() && !in->is_xmm_register()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
479 new_in = to_fpu_stack_top(in);
a61af66fc99e Initial load
duke
parents:
diff changeset
480 }
a61af66fc99e Initial load
duke
parents:
diff changeset
481
a61af66fc99e Initial load
duke
parents:
diff changeset
482 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
483 }
a61af66fc99e Initial load
duke
parents:
diff changeset
484
a61af66fc99e Initial load
duke
parents:
diff changeset
485 case lir_move: {
a61af66fc99e Initial load
duke
parents:
diff changeset
486 if (in->is_fpu_register() && !in->is_xmm_register()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
487 if (res->is_xmm_register()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
488 // move from fpu register to xmm register (necessary for operations that
a61af66fc99e Initial load
duke
parents:
diff changeset
489 // are not available in the SSE instruction set)
a61af66fc99e Initial load
duke
parents:
diff changeset
490 insert_exchange(in);
a61af66fc99e Initial load
duke
parents:
diff changeset
491 new_in = to_fpu_stack_top(in);
a61af66fc99e Initial load
duke
parents:
diff changeset
492 pop_always(op1, in);
a61af66fc99e Initial load
duke
parents:
diff changeset
493
a61af66fc99e Initial load
duke
parents:
diff changeset
494 } else if (res->is_fpu_register() && !res->is_xmm_register()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
495 // move from fpu-register to fpu-register:
a61af66fc99e Initial load
duke
parents:
diff changeset
496 // * input and result register equal:
a61af66fc99e Initial load
duke
parents:
diff changeset
497 // nothing to do
a61af66fc99e Initial load
duke
parents:
diff changeset
498 // * input register is last use:
a61af66fc99e Initial load
duke
parents:
diff changeset
499 // rename the input register to result register -> input register
a61af66fc99e Initial load
duke
parents:
diff changeset
500 // not present on fpu-stack afterwards
a61af66fc99e Initial load
duke
parents:
diff changeset
501 // * input register not last use:
a61af66fc99e Initial load
duke
parents:
diff changeset
502 // duplicate input register to result register to preserve input
a61af66fc99e Initial load
duke
parents:
diff changeset
503 //
a61af66fc99e Initial load
duke
parents:
diff changeset
504 // Note: The LIR-Assembler does not produce any code for fpu register moves,
a61af66fc99e Initial load
duke
parents:
diff changeset
505 // so input and result stack index must be equal
a61af66fc99e Initial load
duke
parents:
diff changeset
506
a61af66fc99e Initial load
duke
parents:
diff changeset
507 if (fpu_num(in) == fpu_num(res)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
508 // nothing to do
a61af66fc99e Initial load
duke
parents:
diff changeset
509 } else if (in->is_last_use()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
510 insert_free_if_dead(res);//, in);
a61af66fc99e Initial load
duke
parents:
diff changeset
511 do_rename(in, res);
a61af66fc99e Initial load
duke
parents:
diff changeset
512 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
513 insert_free_if_dead(res);
a61af66fc99e Initial load
duke
parents:
diff changeset
514 insert_copy(in, res);
a61af66fc99e Initial load
duke
parents:
diff changeset
515 }
a61af66fc99e Initial load
duke
parents:
diff changeset
516 new_in = to_fpu_stack(res);
a61af66fc99e Initial load
duke
parents:
diff changeset
517 new_res = new_in;
a61af66fc99e Initial load
duke
parents:
diff changeset
518
a61af66fc99e Initial load
duke
parents:
diff changeset
519 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
520 // move from fpu-register to memory
a61af66fc99e Initial load
duke
parents:
diff changeset
521 // input operand must be on top of stack
a61af66fc99e Initial load
duke
parents:
diff changeset
522
a61af66fc99e Initial load
duke
parents:
diff changeset
523 insert_exchange(in);
a61af66fc99e Initial load
duke
parents:
diff changeset
524
a61af66fc99e Initial load
duke
parents:
diff changeset
525 // create debug information here because afterwards the register may have been popped
a61af66fc99e Initial load
duke
parents:
diff changeset
526 compute_debug_information(op1);
a61af66fc99e Initial load
duke
parents:
diff changeset
527
a61af66fc99e Initial load
duke
parents:
diff changeset
528 new_in = to_fpu_stack_top(in);
a61af66fc99e Initial load
duke
parents:
diff changeset
529 pop_if_last_use(op1, in);
a61af66fc99e Initial load
duke
parents:
diff changeset
530 }
a61af66fc99e Initial load
duke
parents:
diff changeset
531
a61af66fc99e Initial load
duke
parents:
diff changeset
532 } else if (res->is_fpu_register() && !res->is_xmm_register()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
533 // move from memory/constant to fpu register
a61af66fc99e Initial load
duke
parents:
diff changeset
534 // result is pushed on the stack
a61af66fc99e Initial load
duke
parents:
diff changeset
535
a61af66fc99e Initial load
duke
parents:
diff changeset
536 insert_free_if_dead(res);
a61af66fc99e Initial load
duke
parents:
diff changeset
537
a61af66fc99e Initial load
duke
parents:
diff changeset
538 // create debug information before register is pushed
a61af66fc99e Initial load
duke
parents:
diff changeset
539 compute_debug_information(op1);
a61af66fc99e Initial load
duke
parents:
diff changeset
540
a61af66fc99e Initial load
duke
parents:
diff changeset
541 do_push(res);
a61af66fc99e Initial load
duke
parents:
diff changeset
542 new_res = to_fpu_stack_top(res);
a61af66fc99e Initial load
duke
parents:
diff changeset
543 }
a61af66fc99e Initial load
duke
parents:
diff changeset
544 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
545 }
a61af66fc99e Initial load
duke
parents:
diff changeset
546
a61af66fc99e Initial load
duke
parents:
diff changeset
547 case lir_neg: {
a61af66fc99e Initial load
duke
parents:
diff changeset
548 if (in->is_fpu_register() && !in->is_xmm_register()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
549 assert(res->is_fpu_register() && !res->is_xmm_register(), "must be");
a61af66fc99e Initial load
duke
parents:
diff changeset
550 assert(in->is_last_use(), "old value gets destroyed");
a61af66fc99e Initial load
duke
parents:
diff changeset
551
a61af66fc99e Initial load
duke
parents:
diff changeset
552 insert_free_if_dead(res, in);
a61af66fc99e Initial load
duke
parents:
diff changeset
553 insert_exchange(in);
a61af66fc99e Initial load
duke
parents:
diff changeset
554 new_in = to_fpu_stack_top(in);
a61af66fc99e Initial load
duke
parents:
diff changeset
555
a61af66fc99e Initial load
duke
parents:
diff changeset
556 do_rename(in, res);
a61af66fc99e Initial load
duke
parents:
diff changeset
557 new_res = to_fpu_stack_top(res);
a61af66fc99e Initial load
duke
parents:
diff changeset
558 }
a61af66fc99e Initial load
duke
parents:
diff changeset
559 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
560 }
a61af66fc99e Initial load
duke
parents:
diff changeset
561
a61af66fc99e Initial load
duke
parents:
diff changeset
562 case lir_convert: {
a61af66fc99e Initial load
duke
parents:
diff changeset
563 Bytecodes::Code bc = op1->as_OpConvert()->bytecode();
a61af66fc99e Initial load
duke
parents:
diff changeset
564 switch (bc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
565 case Bytecodes::_d2f:
a61af66fc99e Initial load
duke
parents:
diff changeset
566 case Bytecodes::_f2d:
a61af66fc99e Initial load
duke
parents:
diff changeset
567 assert(res->is_fpu_register(), "must be");
a61af66fc99e Initial load
duke
parents:
diff changeset
568 assert(in->is_fpu_register(), "must be");
a61af66fc99e Initial load
duke
parents:
diff changeset
569
a61af66fc99e Initial load
duke
parents:
diff changeset
570 if (!in->is_xmm_register() && !res->is_xmm_register()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
571 // this is quite the same as a move from fpu-register to fpu-register
a61af66fc99e Initial load
duke
parents:
diff changeset
572 // Note: input and result operands must have different types
a61af66fc99e Initial load
duke
parents:
diff changeset
573 if (fpu_num(in) == fpu_num(res)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
574 // nothing to do
a61af66fc99e Initial load
duke
parents:
diff changeset
575 new_in = to_fpu_stack(in);
a61af66fc99e Initial load
duke
parents:
diff changeset
576 } else if (in->is_last_use()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
577 insert_free_if_dead(res);//, in);
a61af66fc99e Initial load
duke
parents:
diff changeset
578 new_in = to_fpu_stack(in);
a61af66fc99e Initial load
duke
parents:
diff changeset
579 do_rename(in, res);
a61af66fc99e Initial load
duke
parents:
diff changeset
580 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
581 insert_free_if_dead(res);
a61af66fc99e Initial load
duke
parents:
diff changeset
582 insert_copy(in, res);
a61af66fc99e Initial load
duke
parents:
diff changeset
583 new_in = to_fpu_stack_top(in, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
584 }
a61af66fc99e Initial load
duke
parents:
diff changeset
585 new_res = to_fpu_stack(res);
a61af66fc99e Initial load
duke
parents:
diff changeset
586 }
a61af66fc99e Initial load
duke
parents:
diff changeset
587
a61af66fc99e Initial load
duke
parents:
diff changeset
588 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
589
a61af66fc99e Initial load
duke
parents:
diff changeset
590 case Bytecodes::_i2f:
a61af66fc99e Initial load
duke
parents:
diff changeset
591 case Bytecodes::_l2f:
a61af66fc99e Initial load
duke
parents:
diff changeset
592 case Bytecodes::_i2d:
a61af66fc99e Initial load
duke
parents:
diff changeset
593 case Bytecodes::_l2d:
a61af66fc99e Initial load
duke
parents:
diff changeset
594 assert(res->is_fpu_register(), "must be");
a61af66fc99e Initial load
duke
parents:
diff changeset
595 if (!res->is_xmm_register()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
596 insert_free_if_dead(res);
a61af66fc99e Initial load
duke
parents:
diff changeset
597 do_push(res);
a61af66fc99e Initial load
duke
parents:
diff changeset
598 new_res = to_fpu_stack_top(res);
a61af66fc99e Initial load
duke
parents:
diff changeset
599 }
a61af66fc99e Initial load
duke
parents:
diff changeset
600 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
601
a61af66fc99e Initial load
duke
parents:
diff changeset
602 case Bytecodes::_f2i:
a61af66fc99e Initial load
duke
parents:
diff changeset
603 case Bytecodes::_d2i:
a61af66fc99e Initial load
duke
parents:
diff changeset
604 assert(in->is_fpu_register(), "must be");
a61af66fc99e Initial load
duke
parents:
diff changeset
605 if (!in->is_xmm_register()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
606 insert_exchange(in);
a61af66fc99e Initial load
duke
parents:
diff changeset
607 new_in = to_fpu_stack_top(in);
a61af66fc99e Initial load
duke
parents:
diff changeset
608
a61af66fc99e Initial load
duke
parents:
diff changeset
609 // TODO: update registes of stub
a61af66fc99e Initial load
duke
parents:
diff changeset
610 }
a61af66fc99e Initial load
duke
parents:
diff changeset
611 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
612
a61af66fc99e Initial load
duke
parents:
diff changeset
613 case Bytecodes::_f2l:
a61af66fc99e Initial load
duke
parents:
diff changeset
614 case Bytecodes::_d2l:
a61af66fc99e Initial load
duke
parents:
diff changeset
615 assert(in->is_fpu_register(), "must be");
a61af66fc99e Initial load
duke
parents:
diff changeset
616 if (!in->is_xmm_register()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
617 insert_exchange(in);
a61af66fc99e Initial load
duke
parents:
diff changeset
618 new_in = to_fpu_stack_top(in);
a61af66fc99e Initial load
duke
parents:
diff changeset
619 pop_always(op1, in);
a61af66fc99e Initial load
duke
parents:
diff changeset
620 }
a61af66fc99e Initial load
duke
parents:
diff changeset
621 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
622
a61af66fc99e Initial load
duke
parents:
diff changeset
623 case Bytecodes::_i2l:
a61af66fc99e Initial load
duke
parents:
diff changeset
624 case Bytecodes::_l2i:
a61af66fc99e Initial load
duke
parents:
diff changeset
625 case Bytecodes::_i2b:
a61af66fc99e Initial load
duke
parents:
diff changeset
626 case Bytecodes::_i2c:
a61af66fc99e Initial load
duke
parents:
diff changeset
627 case Bytecodes::_i2s:
a61af66fc99e Initial load
duke
parents:
diff changeset
628 // no fpu operands
a61af66fc99e Initial load
duke
parents:
diff changeset
629 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
630
a61af66fc99e Initial load
duke
parents:
diff changeset
631 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
632 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
633 }
a61af66fc99e Initial load
duke
parents:
diff changeset
634 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
635 }
a61af66fc99e Initial load
duke
parents:
diff changeset
636
a61af66fc99e Initial load
duke
parents:
diff changeset
637 case lir_roundfp: {
a61af66fc99e Initial load
duke
parents:
diff changeset
638 assert(in->is_fpu_register() && !in->is_xmm_register(), "input must be in register");
a61af66fc99e Initial load
duke
parents:
diff changeset
639 assert(res->is_stack(), "result must be on stack");
a61af66fc99e Initial load
duke
parents:
diff changeset
640
a61af66fc99e Initial load
duke
parents:
diff changeset
641 insert_exchange(in);
a61af66fc99e Initial load
duke
parents:
diff changeset
642 new_in = to_fpu_stack_top(in);
a61af66fc99e Initial load
duke
parents:
diff changeset
643 pop_if_last_use(op1, in);
a61af66fc99e Initial load
duke
parents:
diff changeset
644 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
645 }
a61af66fc99e Initial load
duke
parents:
diff changeset
646
a61af66fc99e Initial load
duke
parents:
diff changeset
647 default: {
a61af66fc99e Initial load
duke
parents:
diff changeset
648 assert(!in->is_float_kind() && !res->is_float_kind(), "missed a fpu-operation");
a61af66fc99e Initial load
duke
parents:
diff changeset
649 }
a61af66fc99e Initial load
duke
parents:
diff changeset
650 }
a61af66fc99e Initial load
duke
parents:
diff changeset
651
a61af66fc99e Initial load
duke
parents:
diff changeset
652 op1->set_in_opr(new_in);
a61af66fc99e Initial load
duke
parents:
diff changeset
653 op1->set_result_opr(new_res);
a61af66fc99e Initial load
duke
parents:
diff changeset
654 }
a61af66fc99e Initial load
duke
parents:
diff changeset
655
a61af66fc99e Initial load
duke
parents:
diff changeset
656 void FpuStackAllocator::handle_op2(LIR_Op2* op2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
657 LIR_Opr left = op2->in_opr1();
a61af66fc99e Initial load
duke
parents:
diff changeset
658 if (!left->is_float_kind()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
659 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
660 }
a61af66fc99e Initial load
duke
parents:
diff changeset
661 if (left->is_xmm_register()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
662 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
663 }
a61af66fc99e Initial load
duke
parents:
diff changeset
664
a61af66fc99e Initial load
duke
parents:
diff changeset
665 LIR_Opr right = op2->in_opr2();
a61af66fc99e Initial load
duke
parents:
diff changeset
666 LIR_Opr res = op2->result_opr();
a61af66fc99e Initial load
duke
parents:
diff changeset
667 LIR_Opr new_left = left; // new operands relative to the actual fpu stack top
a61af66fc99e Initial load
duke
parents:
diff changeset
668 LIR_Opr new_right = right;
a61af66fc99e Initial load
duke
parents:
diff changeset
669 LIR_Opr new_res = res;
a61af66fc99e Initial load
duke
parents:
diff changeset
670
a61af66fc99e Initial load
duke
parents:
diff changeset
671 assert(!left->is_xmm_register() && !right->is_xmm_register() && !res->is_xmm_register(), "not for xmm registers");
a61af66fc99e Initial load
duke
parents:
diff changeset
672
a61af66fc99e Initial load
duke
parents:
diff changeset
673 switch (op2->code()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
674 case lir_cmp:
a61af66fc99e Initial load
duke
parents:
diff changeset
675 case lir_cmp_fd2i:
a61af66fc99e Initial load
duke
parents:
diff changeset
676 case lir_ucmp_fd2i: {
a61af66fc99e Initial load
duke
parents:
diff changeset
677 assert(left->is_fpu_register(), "invalid LIR");
a61af66fc99e Initial load
duke
parents:
diff changeset
678 assert(right->is_fpu_register(), "invalid LIR");
a61af66fc99e Initial load
duke
parents:
diff changeset
679
a61af66fc99e Initial load
duke
parents:
diff changeset
680 // the left-hand side must be on top of stack.
a61af66fc99e Initial load
duke
parents:
diff changeset
681 // the right-hand side is never popped, even if is_last_use is set
a61af66fc99e Initial load
duke
parents:
diff changeset
682 insert_exchange(left);
a61af66fc99e Initial load
duke
parents:
diff changeset
683 new_left = to_fpu_stack_top(left);
a61af66fc99e Initial load
duke
parents:
diff changeset
684 new_right = to_fpu_stack(right);
a61af66fc99e Initial load
duke
parents:
diff changeset
685 pop_if_last_use(op2, left);
a61af66fc99e Initial load
duke
parents:
diff changeset
686 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
687 }
a61af66fc99e Initial load
duke
parents:
diff changeset
688
a61af66fc99e Initial load
duke
parents:
diff changeset
689 case lir_mul_strictfp:
a61af66fc99e Initial load
duke
parents:
diff changeset
690 case lir_div_strictfp: {
a61af66fc99e Initial load
duke
parents:
diff changeset
691 assert(op2->tmp_opr()->is_fpu_register(), "strict operations need temporary fpu stack slot");
a61af66fc99e Initial load
duke
parents:
diff changeset
692 insert_free_if_dead(op2->tmp_opr());
a61af66fc99e Initial load
duke
parents:
diff changeset
693 assert(sim()->stack_size() <= 7, "at least one stack slot must be free");
a61af66fc99e Initial load
duke
parents:
diff changeset
694 // fall-through: continue with the normal handling of lir_mul and lir_div
a61af66fc99e Initial load
duke
parents:
diff changeset
695 }
a61af66fc99e Initial load
duke
parents:
diff changeset
696 case lir_add:
a61af66fc99e Initial load
duke
parents:
diff changeset
697 case lir_sub:
a61af66fc99e Initial load
duke
parents:
diff changeset
698 case lir_mul:
a61af66fc99e Initial load
duke
parents:
diff changeset
699 case lir_div: {
a61af66fc99e Initial load
duke
parents:
diff changeset
700 assert(left->is_fpu_register(), "must be");
a61af66fc99e Initial load
duke
parents:
diff changeset
701 assert(res->is_fpu_register(), "must be");
a61af66fc99e Initial load
duke
parents:
diff changeset
702 assert(left->is_equal(res), "must be");
a61af66fc99e Initial load
duke
parents:
diff changeset
703
a61af66fc99e Initial load
duke
parents:
diff changeset
704 // either the left-hand or the right-hand side must be on top of stack
a61af66fc99e Initial load
duke
parents:
diff changeset
705 // (if right is not a register, left must be on top)
a61af66fc99e Initial load
duke
parents:
diff changeset
706 if (!right->is_fpu_register()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
707 insert_exchange(left);
a61af66fc99e Initial load
duke
parents:
diff changeset
708 new_left = to_fpu_stack_top(left);
a61af66fc99e Initial load
duke
parents:
diff changeset
709 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
710 // no exchange necessary if right is alredy on top of stack
a61af66fc99e Initial load
duke
parents:
diff changeset
711 if (tos_offset(right) == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
712 new_left = to_fpu_stack(left);
a61af66fc99e Initial load
duke
parents:
diff changeset
713 new_right = to_fpu_stack_top(right);
a61af66fc99e Initial load
duke
parents:
diff changeset
714 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
715 insert_exchange(left);
a61af66fc99e Initial load
duke
parents:
diff changeset
716 new_left = to_fpu_stack_top(left);
a61af66fc99e Initial load
duke
parents:
diff changeset
717 new_right = to_fpu_stack(right);
a61af66fc99e Initial load
duke
parents:
diff changeset
718 }
a61af66fc99e Initial load
duke
parents:
diff changeset
719
a61af66fc99e Initial load
duke
parents:
diff changeset
720 if (right->is_last_use()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
721 op2->set_fpu_pop_count(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
722
a61af66fc99e Initial load
duke
parents:
diff changeset
723 if (tos_offset(right) == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
724 sim()->pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
725 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
726 // if left is on top of stack, the result is placed in the stack
a61af66fc99e Initial load
duke
parents:
diff changeset
727 // slot of right, so a renaming from right to res is necessary
a61af66fc99e Initial load
duke
parents:
diff changeset
728 assert(tos_offset(left) == 0, "must be");
a61af66fc99e Initial load
duke
parents:
diff changeset
729 sim()->pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
730 do_rename(right, res);
a61af66fc99e Initial load
duke
parents:
diff changeset
731 }
a61af66fc99e Initial load
duke
parents:
diff changeset
732 }
a61af66fc99e Initial load
duke
parents:
diff changeset
733 }
a61af66fc99e Initial load
duke
parents:
diff changeset
734 new_res = to_fpu_stack(res);
a61af66fc99e Initial load
duke
parents:
diff changeset
735
a61af66fc99e Initial load
duke
parents:
diff changeset
736 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
737 }
a61af66fc99e Initial load
duke
parents:
diff changeset
738
a61af66fc99e Initial load
duke
parents:
diff changeset
739 case lir_rem: {
a61af66fc99e Initial load
duke
parents:
diff changeset
740 assert(left->is_fpu_register(), "must be");
a61af66fc99e Initial load
duke
parents:
diff changeset
741 assert(right->is_fpu_register(), "must be");
a61af66fc99e Initial load
duke
parents:
diff changeset
742 assert(res->is_fpu_register(), "must be");
a61af66fc99e Initial load
duke
parents:
diff changeset
743 assert(left->is_equal(res), "must be");
a61af66fc99e Initial load
duke
parents:
diff changeset
744
a61af66fc99e Initial load
duke
parents:
diff changeset
745 // Must bring both operands to top of stack with following operand ordering:
a61af66fc99e Initial load
duke
parents:
diff changeset
746 // * fpu stack before rem: ... right left
a61af66fc99e Initial load
duke
parents:
diff changeset
747 // * fpu stack after rem: ... left
a61af66fc99e Initial load
duke
parents:
diff changeset
748 if (tos_offset(right) != 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
749 insert_exchange(right);
a61af66fc99e Initial load
duke
parents:
diff changeset
750 insert_exchange(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
751 }
a61af66fc99e Initial load
duke
parents:
diff changeset
752 insert_exchange(left);
a61af66fc99e Initial load
duke
parents:
diff changeset
753 assert(tos_offset(right) == 1, "check");
a61af66fc99e Initial load
duke
parents:
diff changeset
754 assert(tos_offset(left) == 0, "check");
a61af66fc99e Initial load
duke
parents:
diff changeset
755
a61af66fc99e Initial load
duke
parents:
diff changeset
756 new_left = to_fpu_stack_top(left);
a61af66fc99e Initial load
duke
parents:
diff changeset
757 new_right = to_fpu_stack(right);
a61af66fc99e Initial load
duke
parents:
diff changeset
758
a61af66fc99e Initial load
duke
parents:
diff changeset
759 op2->set_fpu_pop_count(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
760 sim()->pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
761 do_rename(right, res);
a61af66fc99e Initial load
duke
parents:
diff changeset
762
a61af66fc99e Initial load
duke
parents:
diff changeset
763 new_res = to_fpu_stack_top(res);
a61af66fc99e Initial load
duke
parents:
diff changeset
764 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
765 }
a61af66fc99e Initial load
duke
parents:
diff changeset
766
a61af66fc99e Initial load
duke
parents:
diff changeset
767 case lir_log:
a61af66fc99e Initial load
duke
parents:
diff changeset
768 case lir_log10:
a61af66fc99e Initial load
duke
parents:
diff changeset
769 case lir_abs:
a61af66fc99e Initial load
duke
parents:
diff changeset
770 case lir_sqrt: {
a61af66fc99e Initial load
duke
parents:
diff changeset
771 // Right argument appears to be unused
a61af66fc99e Initial load
duke
parents:
diff changeset
772 assert(right->is_illegal(), "must be");
a61af66fc99e Initial load
duke
parents:
diff changeset
773 assert(left->is_fpu_register(), "must be");
a61af66fc99e Initial load
duke
parents:
diff changeset
774 assert(res->is_fpu_register(), "must be");
a61af66fc99e Initial load
duke
parents:
diff changeset
775 assert(left->is_last_use(), "old value gets destroyed");
a61af66fc99e Initial load
duke
parents:
diff changeset
776
a61af66fc99e Initial load
duke
parents:
diff changeset
777 insert_free_if_dead(res, left);
a61af66fc99e Initial load
duke
parents:
diff changeset
778 insert_exchange(left);
a61af66fc99e Initial load
duke
parents:
diff changeset
779 do_rename(left, res);
a61af66fc99e Initial load
duke
parents:
diff changeset
780
a61af66fc99e Initial load
duke
parents:
diff changeset
781 new_left = to_fpu_stack_top(res);
a61af66fc99e Initial load
duke
parents:
diff changeset
782 new_res = new_left;
a61af66fc99e Initial load
duke
parents:
diff changeset
783
a61af66fc99e Initial load
duke
parents:
diff changeset
784 op2->set_fpu_stack_size(sim()->stack_size());
a61af66fc99e Initial load
duke
parents:
diff changeset
785 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
786 }
a61af66fc99e Initial load
duke
parents:
diff changeset
787
a61af66fc99e Initial load
duke
parents:
diff changeset
788
a61af66fc99e Initial load
duke
parents:
diff changeset
789 case lir_tan:
a61af66fc99e Initial load
duke
parents:
diff changeset
790 case lir_sin:
a61af66fc99e Initial load
duke
parents:
diff changeset
791 case lir_cos: {
a61af66fc99e Initial load
duke
parents:
diff changeset
792 // sin and cos need two temporary fpu stack slots, so there are two temporary
a61af66fc99e Initial load
duke
parents:
diff changeset
793 // registers (stored in right and temp of the operation).
a61af66fc99e Initial load
duke
parents:
diff changeset
794 // the stack allocator must guarantee that the stack slots are really free,
a61af66fc99e Initial load
duke
parents:
diff changeset
795 // otherwise there might be a stack overflow.
a61af66fc99e Initial load
duke
parents:
diff changeset
796 assert(left->is_fpu_register(), "must be");
a61af66fc99e Initial load
duke
parents:
diff changeset
797 assert(res->is_fpu_register(), "must be");
a61af66fc99e Initial load
duke
parents:
diff changeset
798 // assert(left->is_last_use(), "old value gets destroyed");
a61af66fc99e Initial load
duke
parents:
diff changeset
799 assert(right->is_fpu_register(), "right is used as the first temporary register");
a61af66fc99e Initial load
duke
parents:
diff changeset
800 assert(op2->tmp_opr()->is_fpu_register(), "temp is used as the second temporary register");
a61af66fc99e Initial load
duke
parents:
diff changeset
801 assert(fpu_num(left) != fpu_num(right) && fpu_num(right) != fpu_num(op2->tmp_opr()) && fpu_num(op2->tmp_opr()) != fpu_num(res), "need distinct temp registers");
a61af66fc99e Initial load
duke
parents:
diff changeset
802
a61af66fc99e Initial load
duke
parents:
diff changeset
803 insert_free_if_dead(right);
a61af66fc99e Initial load
duke
parents:
diff changeset
804 insert_free_if_dead(op2->tmp_opr());
a61af66fc99e Initial load
duke
parents:
diff changeset
805
a61af66fc99e Initial load
duke
parents:
diff changeset
806 insert_free_if_dead(res, left);
a61af66fc99e Initial load
duke
parents:
diff changeset
807 insert_exchange(left);
a61af66fc99e Initial load
duke
parents:
diff changeset
808 do_rename(left, res);
a61af66fc99e Initial load
duke
parents:
diff changeset
809
a61af66fc99e Initial load
duke
parents:
diff changeset
810 new_left = to_fpu_stack_top(res);
a61af66fc99e Initial load
duke
parents:
diff changeset
811 new_res = new_left;
a61af66fc99e Initial load
duke
parents:
diff changeset
812
a61af66fc99e Initial load
duke
parents:
diff changeset
813 op2->set_fpu_stack_size(sim()->stack_size());
a61af66fc99e Initial load
duke
parents:
diff changeset
814 assert(sim()->stack_size() <= 6, "at least two stack slots must be free");
a61af66fc99e Initial load
duke
parents:
diff changeset
815 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
816 }
a61af66fc99e Initial load
duke
parents:
diff changeset
817
a61af66fc99e Initial load
duke
parents:
diff changeset
818 default: {
a61af66fc99e Initial load
duke
parents:
diff changeset
819 assert(false, "missed a fpu-operation");
a61af66fc99e Initial load
duke
parents:
diff changeset
820 }
a61af66fc99e Initial load
duke
parents:
diff changeset
821 }
a61af66fc99e Initial load
duke
parents:
diff changeset
822
a61af66fc99e Initial load
duke
parents:
diff changeset
823 op2->set_in_opr1(new_left);
a61af66fc99e Initial load
duke
parents:
diff changeset
824 op2->set_in_opr2(new_right);
a61af66fc99e Initial load
duke
parents:
diff changeset
825 op2->set_result_opr(new_res);
a61af66fc99e Initial load
duke
parents:
diff changeset
826 }
a61af66fc99e Initial load
duke
parents:
diff changeset
827
a61af66fc99e Initial load
duke
parents:
diff changeset
828 void FpuStackAllocator::handle_opCall(LIR_OpCall* opCall) {
a61af66fc99e Initial load
duke
parents:
diff changeset
829 LIR_Opr res = opCall->result_opr();
a61af66fc99e Initial load
duke
parents:
diff changeset
830
a61af66fc99e Initial load
duke
parents:
diff changeset
831 // clear fpu-stack before call
a61af66fc99e Initial load
duke
parents:
diff changeset
832 // it may contain dead values that could not have been remved by previous operations
a61af66fc99e Initial load
duke
parents:
diff changeset
833 clear_fpu_stack(LIR_OprFact::illegalOpr);
a61af66fc99e Initial load
duke
parents:
diff changeset
834 assert(sim()->is_empty(), "fpu stack must be empty now");
a61af66fc99e Initial load
duke
parents:
diff changeset
835
a61af66fc99e Initial load
duke
parents:
diff changeset
836 // compute debug information before (possible) fpu result is pushed
a61af66fc99e Initial load
duke
parents:
diff changeset
837 compute_debug_information(opCall);
a61af66fc99e Initial load
duke
parents:
diff changeset
838
a61af66fc99e Initial load
duke
parents:
diff changeset
839 if (res->is_fpu_register() && !res->is_xmm_register()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
840 do_push(res);
a61af66fc99e Initial load
duke
parents:
diff changeset
841 opCall->set_result_opr(to_fpu_stack_top(res));
a61af66fc99e Initial load
duke
parents:
diff changeset
842 }
a61af66fc99e Initial load
duke
parents:
diff changeset
843 }
a61af66fc99e Initial load
duke
parents:
diff changeset
844
a61af66fc99e Initial load
duke
parents:
diff changeset
845 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
846 void FpuStackAllocator::check_invalid_lir_op(LIR_Op* op) {
a61af66fc99e Initial load
duke
parents:
diff changeset
847 switch (op->code()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
848 case lir_24bit_FPU:
a61af66fc99e Initial load
duke
parents:
diff changeset
849 case lir_reset_FPU:
a61af66fc99e Initial load
duke
parents:
diff changeset
850 case lir_ffree:
a61af66fc99e Initial load
duke
parents:
diff changeset
851 assert(false, "operations not allowed in lir. If one of these operations is needed, check if they have fpu operands");
a61af66fc99e Initial load
duke
parents:
diff changeset
852 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
853
a61af66fc99e Initial load
duke
parents:
diff changeset
854 case lir_fpop_raw:
a61af66fc99e Initial load
duke
parents:
diff changeset
855 case lir_fxch:
a61af66fc99e Initial load
duke
parents:
diff changeset
856 case lir_fld:
a61af66fc99e Initial load
duke
parents:
diff changeset
857 assert(false, "operations only inserted by FpuStackAllocator");
a61af66fc99e Initial load
duke
parents:
diff changeset
858 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
859 }
a61af66fc99e Initial load
duke
parents:
diff changeset
860 }
a61af66fc99e Initial load
duke
parents:
diff changeset
861 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
862
a61af66fc99e Initial load
duke
parents:
diff changeset
863
a61af66fc99e Initial load
duke
parents:
diff changeset
864 void FpuStackAllocator::merge_insert_add(LIR_List* instrs, FpuStackSim* cur_sim, int reg) {
a61af66fc99e Initial load
duke
parents:
diff changeset
865 LIR_Op1* move = new LIR_Op1(lir_move, LIR_OprFact::doubleConst(0), LIR_OprFact::double_fpu(reg)->make_fpu_stack_offset());
a61af66fc99e Initial load
duke
parents:
diff changeset
866
a61af66fc99e Initial load
duke
parents:
diff changeset
867 instrs->instructions_list()->push(move);
a61af66fc99e Initial load
duke
parents:
diff changeset
868
a61af66fc99e Initial load
duke
parents:
diff changeset
869 cur_sim->push(reg);
a61af66fc99e Initial load
duke
parents:
diff changeset
870 move->set_result_opr(to_fpu_stack(move->result_opr()));
a61af66fc99e Initial load
duke
parents:
diff changeset
871
a61af66fc99e Initial load
duke
parents:
diff changeset
872 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
873 if (TraceFPUStack) {
a61af66fc99e Initial load
duke
parents:
diff changeset
874 tty->print("Added new register: %d New state: ", reg); cur_sim->print(); tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
875 }
a61af66fc99e Initial load
duke
parents:
diff changeset
876 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
877 }
a61af66fc99e Initial load
duke
parents:
diff changeset
878
a61af66fc99e Initial load
duke
parents:
diff changeset
879 void FpuStackAllocator::merge_insert_xchg(LIR_List* instrs, FpuStackSim* cur_sim, int slot) {
a61af66fc99e Initial load
duke
parents:
diff changeset
880 assert(slot > 0, "no exchange necessary");
a61af66fc99e Initial load
duke
parents:
diff changeset
881
a61af66fc99e Initial load
duke
parents:
diff changeset
882 LIR_Op1* fxch = new LIR_Op1(lir_fxch, LIR_OprFact::intConst(slot));
a61af66fc99e Initial load
duke
parents:
diff changeset
883 instrs->instructions_list()->push(fxch);
a61af66fc99e Initial load
duke
parents:
diff changeset
884 cur_sim->swap(slot);
a61af66fc99e Initial load
duke
parents:
diff changeset
885
a61af66fc99e Initial load
duke
parents:
diff changeset
886 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
887 if (TraceFPUStack) {
a61af66fc99e Initial load
duke
parents:
diff changeset
888 tty->print("Exchanged register: %d New state: ", cur_sim->get_slot(slot)); cur_sim->print(); tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
889 }
a61af66fc99e Initial load
duke
parents:
diff changeset
890 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
891 }
a61af66fc99e Initial load
duke
parents:
diff changeset
892
a61af66fc99e Initial load
duke
parents:
diff changeset
893 void FpuStackAllocator::merge_insert_pop(LIR_List* instrs, FpuStackSim* cur_sim) {
a61af66fc99e Initial load
duke
parents:
diff changeset
894 int reg = cur_sim->get_slot(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
895
a61af66fc99e Initial load
duke
parents:
diff changeset
896 LIR_Op* fpop = new LIR_Op0(lir_fpop_raw);
a61af66fc99e Initial load
duke
parents:
diff changeset
897 instrs->instructions_list()->push(fpop);
a61af66fc99e Initial load
duke
parents:
diff changeset
898 cur_sim->pop(reg);
a61af66fc99e Initial load
duke
parents:
diff changeset
899
a61af66fc99e Initial load
duke
parents:
diff changeset
900 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
901 if (TraceFPUStack) {
a61af66fc99e Initial load
duke
parents:
diff changeset
902 tty->print("Removed register: %d New state: ", reg); cur_sim->print(); tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
903 }
a61af66fc99e Initial load
duke
parents:
diff changeset
904 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
905 }
a61af66fc99e Initial load
duke
parents:
diff changeset
906
a61af66fc99e Initial load
duke
parents:
diff changeset
907 bool FpuStackAllocator::merge_rename(FpuStackSim* cur_sim, FpuStackSim* sux_sim, int start_slot, int change_slot) {
a61af66fc99e Initial load
duke
parents:
diff changeset
908 int reg = cur_sim->get_slot(change_slot);
a61af66fc99e Initial load
duke
parents:
diff changeset
909
a61af66fc99e Initial load
duke
parents:
diff changeset
910 for (int slot = start_slot; slot >= 0; slot--) {
a61af66fc99e Initial load
duke
parents:
diff changeset
911 int new_reg = sux_sim->get_slot(slot);
a61af66fc99e Initial load
duke
parents:
diff changeset
912
a61af66fc99e Initial load
duke
parents:
diff changeset
913 if (!cur_sim->contains(new_reg)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
914 cur_sim->set_slot(change_slot, new_reg);
a61af66fc99e Initial load
duke
parents:
diff changeset
915
a61af66fc99e Initial load
duke
parents:
diff changeset
916 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
917 if (TraceFPUStack) {
a61af66fc99e Initial load
duke
parents:
diff changeset
918 tty->print("Renamed register %d to %d New state: ", reg, new_reg); cur_sim->print(); tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
919 }
a61af66fc99e Initial load
duke
parents:
diff changeset
920 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
921
a61af66fc99e Initial load
duke
parents:
diff changeset
922 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
923 }
a61af66fc99e Initial load
duke
parents:
diff changeset
924 }
a61af66fc99e Initial load
duke
parents:
diff changeset
925 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
926 }
a61af66fc99e Initial load
duke
parents:
diff changeset
927
a61af66fc99e Initial load
duke
parents:
diff changeset
928
a61af66fc99e Initial load
duke
parents:
diff changeset
929 void FpuStackAllocator::merge_fpu_stack(LIR_List* instrs, FpuStackSim* cur_sim, FpuStackSim* sux_sim) {
a61af66fc99e Initial load
duke
parents:
diff changeset
930 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
931 if (TraceFPUStack) {
a61af66fc99e Initial load
duke
parents:
diff changeset
932 tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
933 tty->print("before merging: pred: "); cur_sim->print(); tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
934 tty->print(" sux: "); sux_sim->print(); tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
935 }
a61af66fc99e Initial load
duke
parents:
diff changeset
936
a61af66fc99e Initial load
duke
parents:
diff changeset
937 int slot;
a61af66fc99e Initial load
duke
parents:
diff changeset
938 for (slot = 0; slot < cur_sim->stack_size(); slot++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
939 assert(!cur_sim->slot_is_empty(slot), "not handled by algorithm");
a61af66fc99e Initial load
duke
parents:
diff changeset
940 }
a61af66fc99e Initial load
duke
parents:
diff changeset
941 for (slot = 0; slot < sux_sim->stack_size(); slot++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
942 assert(!sux_sim->slot_is_empty(slot), "not handled by algorithm");
a61af66fc99e Initial load
duke
parents:
diff changeset
943 }
a61af66fc99e Initial load
duke
parents:
diff changeset
944 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
945
a61af66fc99e Initial load
duke
parents:
diff changeset
946 // size difference between cur and sux that must be resolved by adding or removing values form the stack
a61af66fc99e Initial load
duke
parents:
diff changeset
947 int size_diff = cur_sim->stack_size() - sux_sim->stack_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
948
a61af66fc99e Initial load
duke
parents:
diff changeset
949 if (!ComputeExactFPURegisterUsage) {
a61af66fc99e Initial load
duke
parents:
diff changeset
950 // add slots that are currently free, but used in successor
a61af66fc99e Initial load
duke
parents:
diff changeset
951 // When the exact FPU register usage is computed, the stack does
a61af66fc99e Initial load
duke
parents:
diff changeset
952 // not contain dead values at merging -> no values must be added
a61af66fc99e Initial load
duke
parents:
diff changeset
953
a61af66fc99e Initial load
duke
parents:
diff changeset
954 int sux_slot = sux_sim->stack_size() - 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
955 while (size_diff < 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
956 assert(sux_slot >= 0, "slot out of bounds -> error in algorithm");
a61af66fc99e Initial load
duke
parents:
diff changeset
957
a61af66fc99e Initial load
duke
parents:
diff changeset
958 int reg = sux_sim->get_slot(sux_slot);
a61af66fc99e Initial load
duke
parents:
diff changeset
959 if (!cur_sim->contains(reg)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
960 merge_insert_add(instrs, cur_sim, reg);
a61af66fc99e Initial load
duke
parents:
diff changeset
961 size_diff++;
a61af66fc99e Initial load
duke
parents:
diff changeset
962
a61af66fc99e Initial load
duke
parents:
diff changeset
963 if (sux_slot + size_diff != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
964 merge_insert_xchg(instrs, cur_sim, sux_slot + size_diff);
a61af66fc99e Initial load
duke
parents:
diff changeset
965 }
a61af66fc99e Initial load
duke
parents:
diff changeset
966 }
a61af66fc99e Initial load
duke
parents:
diff changeset
967 sux_slot--;
a61af66fc99e Initial load
duke
parents:
diff changeset
968 }
a61af66fc99e Initial load
duke
parents:
diff changeset
969 }
a61af66fc99e Initial load
duke
parents:
diff changeset
970
a61af66fc99e Initial load
duke
parents:
diff changeset
971 assert(cur_sim->stack_size() >= sux_sim->stack_size(), "stack size must be equal or greater now");
a61af66fc99e Initial load
duke
parents:
diff changeset
972 assert(size_diff == cur_sim->stack_size() - sux_sim->stack_size(), "must be");
a61af66fc99e Initial load
duke
parents:
diff changeset
973
a61af66fc99e Initial load
duke
parents:
diff changeset
974 // stack merge algorithm:
a61af66fc99e Initial load
duke
parents:
diff changeset
975 // 1) as long as the current stack top is not in the right location (that meens
a61af66fc99e Initial load
duke
parents:
diff changeset
976 // it should not be on the stack top), exchange it into the right location
a61af66fc99e Initial load
duke
parents:
diff changeset
977 // 2) if the stack top is right, but the remaining stack is not ordered correctly,
a61af66fc99e Initial load
duke
parents:
diff changeset
978 // the stack top is exchanged away to get another value on top ->
a61af66fc99e Initial load
duke
parents:
diff changeset
979 // now step 1) can be continued
a61af66fc99e Initial load
duke
parents:
diff changeset
980 // the stack can also contain unused items -> these items are removed from stack
a61af66fc99e Initial load
duke
parents:
diff changeset
981
a61af66fc99e Initial load
duke
parents:
diff changeset
982 int finished_slot = sux_sim->stack_size() - 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
983 while (finished_slot >= 0 || size_diff > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
984 while (size_diff > 0 || (cur_sim->stack_size() > 0 && cur_sim->get_slot(0) != sux_sim->get_slot(0))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
985 int reg = cur_sim->get_slot(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
986 if (sux_sim->contains(reg)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
987 int sux_slot = sux_sim->offset_from_tos(reg);
a61af66fc99e Initial load
duke
parents:
diff changeset
988 merge_insert_xchg(instrs, cur_sim, sux_slot + size_diff);
a61af66fc99e Initial load
duke
parents:
diff changeset
989
a61af66fc99e Initial load
duke
parents:
diff changeset
990 } else if (!merge_rename(cur_sim, sux_sim, finished_slot, 0)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
991 assert(size_diff > 0, "must be");
a61af66fc99e Initial load
duke
parents:
diff changeset
992
a61af66fc99e Initial load
duke
parents:
diff changeset
993 merge_insert_pop(instrs, cur_sim);
a61af66fc99e Initial load
duke
parents:
diff changeset
994 size_diff--;
a61af66fc99e Initial load
duke
parents:
diff changeset
995 }
a61af66fc99e Initial load
duke
parents:
diff changeset
996 assert(cur_sim->stack_size() == 0 || cur_sim->get_slot(0) != reg, "register must have been changed");
a61af66fc99e Initial load
duke
parents:
diff changeset
997 }
a61af66fc99e Initial load
duke
parents:
diff changeset
998
a61af66fc99e Initial load
duke
parents:
diff changeset
999 while (finished_slot >= 0 && cur_sim->get_slot(finished_slot) == sux_sim->get_slot(finished_slot)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1000 finished_slot--;
a61af66fc99e Initial load
duke
parents:
diff changeset
1001 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1002
a61af66fc99e Initial load
duke
parents:
diff changeset
1003 if (finished_slot >= 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1004 int reg = cur_sim->get_slot(finished_slot);
a61af66fc99e Initial load
duke
parents:
diff changeset
1005
a61af66fc99e Initial load
duke
parents:
diff changeset
1006 if (sux_sim->contains(reg) || !merge_rename(cur_sim, sux_sim, finished_slot, finished_slot)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1007 assert(sux_sim->contains(reg) || size_diff > 0, "must be");
a61af66fc99e Initial load
duke
parents:
diff changeset
1008 merge_insert_xchg(instrs, cur_sim, finished_slot);
a61af66fc99e Initial load
duke
parents:
diff changeset
1009 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1010 assert(cur_sim->get_slot(finished_slot) != reg, "register must have been changed");
a61af66fc99e Initial load
duke
parents:
diff changeset
1011 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1012 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1013
a61af66fc99e Initial load
duke
parents:
diff changeset
1014 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
1015 if (TraceFPUStack) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1016 tty->print("after merging: pred: "); cur_sim->print(); tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
1017 tty->print(" sux: "); sux_sim->print(); tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
1018 tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
1019 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1020 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
1021 assert(cur_sim->stack_size() == sux_sim->stack_size(), "stack size must be equal now");
a61af66fc99e Initial load
duke
parents:
diff changeset
1022 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1023
a61af66fc99e Initial load
duke
parents:
diff changeset
1024
a61af66fc99e Initial load
duke
parents:
diff changeset
1025 void FpuStackAllocator::merge_cleanup_fpu_stack(LIR_List* instrs, FpuStackSim* cur_sim, BitMap& live_fpu_regs) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1026 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
1027 if (TraceFPUStack) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1028 tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
1029 tty->print("before cleanup: state: "); cur_sim->print(); tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
1030 tty->print(" live: "); live_fpu_regs.print_on(tty); tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
1031 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1032 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
1033
a61af66fc99e Initial load
duke
parents:
diff changeset
1034 int slot = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1035 while (slot < cur_sim->stack_size()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1036 int reg = cur_sim->get_slot(slot);
a61af66fc99e Initial load
duke
parents:
diff changeset
1037 if (!live_fpu_regs.at(reg)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1038 if (slot != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1039 merge_insert_xchg(instrs, cur_sim, slot);
a61af66fc99e Initial load
duke
parents:
diff changeset
1040 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1041 merge_insert_pop(instrs, cur_sim);
a61af66fc99e Initial load
duke
parents:
diff changeset
1042 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1043 slot++;
a61af66fc99e Initial load
duke
parents:
diff changeset
1044 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1045 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1046
a61af66fc99e Initial load
duke
parents:
diff changeset
1047 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
1048 if (TraceFPUStack) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1049 tty->print("after cleanup: state: "); cur_sim->print(); tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
1050 tty->print(" live: "); live_fpu_regs.print_on(tty); tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
1051 tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
1052 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1053
a61af66fc99e Initial load
duke
parents:
diff changeset
1054 // check if fpu stack only contains live registers
a61af66fc99e Initial load
duke
parents:
diff changeset
1055 for (unsigned int i = 0; i < live_fpu_regs.size(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1056 if (live_fpu_regs.at(i) != cur_sim->contains(i)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1057 tty->print_cr("mismatch between required and actual stack content");
a61af66fc99e Initial load
duke
parents:
diff changeset
1058 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1059 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1060 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1061 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
1062 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1063
a61af66fc99e Initial load
duke
parents:
diff changeset
1064
a61af66fc99e Initial load
duke
parents:
diff changeset
1065 bool FpuStackAllocator::merge_fpu_stack_with_successors(BlockBegin* block) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1066 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
1067 if (TraceFPUStack) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1068 tty->print_cr("Propagating FPU stack state for B%d at LIR_Op position %d to successors:",
a61af66fc99e Initial load
duke
parents:
diff changeset
1069 block->block_id(), pos());
a61af66fc99e Initial load
duke
parents:
diff changeset
1070 sim()->print();
a61af66fc99e Initial load
duke
parents:
diff changeset
1071 tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
1072 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1073 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
1074
a61af66fc99e Initial load
duke
parents:
diff changeset
1075 bool changed = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1076 int number_of_sux = block->number_of_sux();
a61af66fc99e Initial load
duke
parents:
diff changeset
1077
a61af66fc99e Initial load
duke
parents:
diff changeset
1078 if (number_of_sux == 1 && block->sux_at(0)->number_of_preds() > 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1079 // The successor has at least two incoming edges, so a stack merge will be necessary
a61af66fc99e Initial load
duke
parents:
diff changeset
1080 // If this block is the first predecessor, cleanup the current stack and propagate it
a61af66fc99e Initial load
duke
parents:
diff changeset
1081 // If this block is not the first predecessor, a stack merge will be necessary
a61af66fc99e Initial load
duke
parents:
diff changeset
1082
a61af66fc99e Initial load
duke
parents:
diff changeset
1083 BlockBegin* sux = block->sux_at(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
1084 intArray* state = sux->fpu_stack_state();
a61af66fc99e Initial load
duke
parents:
diff changeset
1085 LIR_List* instrs = new LIR_List(_compilation);
a61af66fc99e Initial load
duke
parents:
diff changeset
1086
a61af66fc99e Initial load
duke
parents:
diff changeset
1087 if (state != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1088 // Merge with a successors that already has a FPU stack state
a61af66fc99e Initial load
duke
parents:
diff changeset
1089 // the block must only have one successor because critical edges must been split
a61af66fc99e Initial load
duke
parents:
diff changeset
1090 FpuStackSim* cur_sim = sim();
a61af66fc99e Initial load
duke
parents:
diff changeset
1091 FpuStackSim* sux_sim = temp_sim();
a61af66fc99e Initial load
duke
parents:
diff changeset
1092 sux_sim->read_state(state);
a61af66fc99e Initial load
duke
parents:
diff changeset
1093
a61af66fc99e Initial load
duke
parents:
diff changeset
1094 merge_fpu_stack(instrs, cur_sim, sux_sim);
a61af66fc99e Initial load
duke
parents:
diff changeset
1095
a61af66fc99e Initial load
duke
parents:
diff changeset
1096 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1097 // propagate current FPU stack state to successor without state
a61af66fc99e Initial load
duke
parents:
diff changeset
1098 // clean up stack first so that there are no dead values on the stack
a61af66fc99e Initial load
duke
parents:
diff changeset
1099 if (ComputeExactFPURegisterUsage) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1100 FpuStackSim* cur_sim = sim();
a61af66fc99e Initial load
duke
parents:
diff changeset
1101 BitMap live_fpu_regs = block->sux_at(0)->fpu_register_usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
1102 assert(live_fpu_regs.size() == FrameMap::nof_fpu_regs, "missing register usage");
a61af66fc99e Initial load
duke
parents:
diff changeset
1103
a61af66fc99e Initial load
duke
parents:
diff changeset
1104 merge_cleanup_fpu_stack(instrs, cur_sim, live_fpu_regs);
a61af66fc99e Initial load
duke
parents:
diff changeset
1105 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1106
a61af66fc99e Initial load
duke
parents:
diff changeset
1107 intArray* state = sim()->write_state();
a61af66fc99e Initial load
duke
parents:
diff changeset
1108 if (TraceFPUStack) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1109 tty->print_cr("Setting FPU stack state of B%d (merge path)", sux->block_id());
a61af66fc99e Initial load
duke
parents:
diff changeset
1110 sim()->print(); tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
1111 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1112 sux->set_fpu_stack_state(state);
a61af66fc99e Initial load
duke
parents:
diff changeset
1113 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1114
a61af66fc99e Initial load
duke
parents:
diff changeset
1115 if (instrs->instructions_list()->length() > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1116 lir()->insert_before(pos(), instrs);
a61af66fc99e Initial load
duke
parents:
diff changeset
1117 set_pos(instrs->instructions_list()->length() + pos());
a61af66fc99e Initial load
duke
parents:
diff changeset
1118 changed = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1119 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1120
a61af66fc99e Initial load
duke
parents:
diff changeset
1121 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1122 // Propagate unmodified Stack to successors where a stack merge is not necessary
a61af66fc99e Initial load
duke
parents:
diff changeset
1123 intArray* state = sim()->write_state();
a61af66fc99e Initial load
duke
parents:
diff changeset
1124 for (int i = 0; i < number_of_sux; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1125 BlockBegin* sux = block->sux_at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
1126
a61af66fc99e Initial load
duke
parents:
diff changeset
1127 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
1128 for (int j = 0; j < sux->number_of_preds(); j++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1129 assert(block == sux->pred_at(j), "all critical edges must be broken");
a61af66fc99e Initial load
duke
parents:
diff changeset
1130 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1131
a61af66fc99e Initial load
duke
parents:
diff changeset
1132 // check if new state is same
a61af66fc99e Initial load
duke
parents:
diff changeset
1133 if (sux->fpu_stack_state() != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1134 intArray* sux_state = sux->fpu_stack_state();
a61af66fc99e Initial load
duke
parents:
diff changeset
1135 assert(state->length() == sux_state->length(), "overwriting existing stack state");
a61af66fc99e Initial load
duke
parents:
diff changeset
1136 for (int j = 0; j < state->length(); j++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1137 assert(state->at(j) == sux_state->at(j), "overwriting existing stack state");
a61af66fc99e Initial load
duke
parents:
diff changeset
1138 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1139 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1140 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
1141 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
1142 if (TraceFPUStack) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1143 tty->print_cr("Setting FPU stack state of B%d", sux->block_id());
a61af66fc99e Initial load
duke
parents:
diff changeset
1144 sim()->print(); tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
1145 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1146 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
1147
a61af66fc99e Initial load
duke
parents:
diff changeset
1148 sux->set_fpu_stack_state(state);
a61af66fc99e Initial load
duke
parents:
diff changeset
1149 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1150 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1151
a61af66fc99e Initial load
duke
parents:
diff changeset
1152 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
1153 // assertions that FPU stack state conforms to all successors' states
a61af66fc99e Initial load
duke
parents:
diff changeset
1154 intArray* cur_state = sim()->write_state();
a61af66fc99e Initial load
duke
parents:
diff changeset
1155 for (int i = 0; i < number_of_sux; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1156 BlockBegin* sux = block->sux_at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
1157 intArray* sux_state = sux->fpu_stack_state();
a61af66fc99e Initial load
duke
parents:
diff changeset
1158
a61af66fc99e Initial load
duke
parents:
diff changeset
1159 assert(sux_state != NULL, "no fpu state");
a61af66fc99e Initial load
duke
parents:
diff changeset
1160 assert(cur_state->length() == sux_state->length(), "incorrect length");
a61af66fc99e Initial load
duke
parents:
diff changeset
1161 for (int i = 0; i < cur_state->length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1162 assert(cur_state->at(i) == sux_state->at(i), "element not equal");
a61af66fc99e Initial load
duke
parents:
diff changeset
1163 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1164 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1165 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
1166
a61af66fc99e Initial load
duke
parents:
diff changeset
1167 return changed;
a61af66fc99e Initial load
duke
parents:
diff changeset
1168 }