annotate src/cpu/x86/vm/c1_LinearScan_x86.cpp @ 17524:89152779163c

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