43972
|
1 |
/*
|
|
2 |
* Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
|
22 |
*/
|
|
23 |
package org.graalvm.compiler.lir.alloc.lsra;
|
|
24 |
|
|
25 |
import static jdk.vm.ci.code.ValueUtil.asRegister;
|
|
26 |
import static jdk.vm.ci.code.ValueUtil.isIllegal;
|
|
27 |
import static jdk.vm.ci.code.ValueUtil.isRegister;
|
|
28 |
|
|
29 |
import java.util.ArrayList;
|
|
30 |
|
48861
|
31 |
import org.graalvm.collections.EconomicSet;
|
|
32 |
import org.graalvm.collections.Equivalence;
|
43972
|
33 |
import org.graalvm.compiler.core.common.LIRKind;
|
46640
|
34 |
import org.graalvm.compiler.debug.CounterKey;
|
|
35 |
import org.graalvm.compiler.debug.DebugContext;
|
43972
|
36 |
import org.graalvm.compiler.debug.GraalError;
|
|
37 |
import org.graalvm.compiler.debug.Indent;
|
|
38 |
import org.graalvm.compiler.lir.LIRInsertionBuffer;
|
|
39 |
import org.graalvm.compiler.lir.LIRInstruction;
|
|
40 |
import org.graalvm.compiler.lir.LIRValueUtil;
|
46536
|
41 |
import org.graalvm.compiler.lir.gen.LIRGenerationResult;
|
46680
|
42 |
|
43972
|
43 |
import jdk.vm.ci.meta.AllocatableValue;
|
|
44 |
import jdk.vm.ci.meta.Constant;
|
|
45 |
import jdk.vm.ci.meta.Value;
|
|
46 |
|
|
47 |
/**
|
|
48 |
*/
|
|
49 |
public class MoveResolver {
|
|
50 |
|
46640
|
51 |
private static final CounterKey cycleBreakingSlotsAllocated = DebugContext.counter("LSRA[cycleBreakingSlotsAllocated]");
|
43972
|
52 |
|
|
53 |
private final LinearScan allocator;
|
|
54 |
|
|
55 |
private int insertIdx;
|
|
56 |
private LIRInsertionBuffer insertionBuffer; // buffer where moves are inserted
|
|
57 |
|
46344
|
58 |
private final ArrayList<Interval> mappingFrom;
|
|
59 |
private final ArrayList<Constant> mappingFromOpr;
|
|
60 |
private final ArrayList<Interval> mappingTo;
|
43972
|
61 |
private boolean multipleReadsAllowed;
|
|
62 |
private final int[] registerBlocked;
|
|
63 |
|
46536
|
64 |
private final LIRGenerationResult res;
|
|
65 |
|
43972
|
66 |
protected void setValueBlocked(Value location, int direction) {
|
|
67 |
assert direction == 1 || direction == -1 : "out of bounds";
|
|
68 |
if (isRegister(location)) {
|
|
69 |
registerBlocked[asRegister(location).number] += direction;
|
|
70 |
} else {
|
|
71 |
throw GraalError.shouldNotReachHere("unhandled value " + location);
|
|
72 |
}
|
|
73 |
}
|
|
74 |
|
|
75 |
protected Interval getMappingFrom(int i) {
|
|
76 |
return mappingFrom.get(i);
|
|
77 |
}
|
|
78 |
|
|
79 |
protected int mappingFromSize() {
|
|
80 |
return mappingFrom.size();
|
|
81 |
}
|
|
82 |
|
|
83 |
protected int valueBlocked(Value location) {
|
|
84 |
if (isRegister(location)) {
|
|
85 |
return registerBlocked[asRegister(location).number];
|
|
86 |
}
|
|
87 |
throw GraalError.shouldNotReachHere("unhandled value " + location);
|
|
88 |
}
|
|
89 |
|
|
90 |
void setMultipleReadsAllowed() {
|
|
91 |
multipleReadsAllowed = true;
|
|
92 |
}
|
|
93 |
|
|
94 |
protected boolean areMultipleReadsAllowed() {
|
|
95 |
return multipleReadsAllowed;
|
|
96 |
}
|
|
97 |
|
|
98 |
boolean hasMappings() {
|
|
99 |
return mappingFrom.size() > 0;
|
|
100 |
}
|
|
101 |
|
|
102 |
protected LinearScan getAllocator() {
|
|
103 |
return allocator;
|
|
104 |
}
|
|
105 |
|
|
106 |
protected MoveResolver(LinearScan allocator) {
|
|
107 |
this.allocator = allocator;
|
|
108 |
this.multipleReadsAllowed = false;
|
|
109 |
this.mappingFrom = new ArrayList<>(8);
|
|
110 |
this.mappingFromOpr = new ArrayList<>(8);
|
|
111 |
this.mappingTo = new ArrayList<>(8);
|
|
112 |
this.insertIdx = -1;
|
|
113 |
this.insertionBuffer = new LIRInsertionBuffer();
|
|
114 |
this.registerBlocked = new int[allocator.getRegisters().size()];
|
46536
|
115 |
this.res = allocator.getLIRGenerationResult();
|
43972
|
116 |
}
|
|
117 |
|
|
118 |
protected boolean checkEmpty() {
|
|
119 |
assert mappingFrom.size() == 0 && mappingFromOpr.size() == 0 && mappingTo.size() == 0 : "list must be empty before and after processing";
|
|
120 |
for (int i = 0; i < getAllocator().getRegisters().size(); i++) {
|
|
121 |
assert registerBlocked[i] == 0 : "register map must be empty before and after processing";
|
|
122 |
}
|
|
123 |
checkMultipleReads();
|
|
124 |
return true;
|
|
125 |
}
|
|
126 |
|
|
127 |
protected void checkMultipleReads() {
|
|
128 |
assert !areMultipleReadsAllowed() : "must have default value";
|
|
129 |
}
|
|
130 |
|
|
131 |
private boolean verifyBeforeResolve() {
|
|
132 |
assert mappingFrom.size() == mappingFromOpr.size() : "length must be equal";
|
|
133 |
assert mappingFrom.size() == mappingTo.size() : "length must be equal";
|
|
134 |
assert insertIdx != -1 : "insert position not set";
|
|
135 |
|
|
136 |
int i;
|
|
137 |
int j;
|
|
138 |
if (!areMultipleReadsAllowed()) {
|
|
139 |
for (i = 0; i < mappingFrom.size(); i++) {
|
|
140 |
for (j = i + 1; j < mappingFrom.size(); j++) {
|
|
141 |
assert mappingFrom.get(i) == null || mappingFrom.get(i) != mappingFrom.get(j) : "cannot read from same interval twice";
|
|
142 |
}
|
|
143 |
}
|
|
144 |
}
|
|
145 |
|
|
146 |
for (i = 0; i < mappingTo.size(); i++) {
|
|
147 |
for (j = i + 1; j < mappingTo.size(); j++) {
|
|
148 |
assert mappingTo.get(i) != mappingTo.get(j) : "cannot write to same interval twice";
|
|
149 |
}
|
|
150 |
}
|
|
151 |
|
46344
|
152 |
EconomicSet<Value> usedRegs = EconomicSet.create(Equivalence.DEFAULT);
|
43972
|
153 |
if (!areMultipleReadsAllowed()) {
|
|
154 |
for (i = 0; i < mappingFrom.size(); i++) {
|
|
155 |
Interval interval = mappingFrom.get(i);
|
|
156 |
if (interval != null && !isIllegal(interval.location())) {
|
|
157 |
boolean unique = usedRegs.add(interval.location());
|
|
158 |
assert unique : "cannot read from same register twice";
|
|
159 |
}
|
|
160 |
}
|
|
161 |
}
|
|
162 |
|
|
163 |
usedRegs.clear();
|
|
164 |
for (i = 0; i < mappingTo.size(); i++) {
|
|
165 |
Interval interval = mappingTo.get(i);
|
|
166 |
if (isIllegal(interval.location())) {
|
|
167 |
// After insertion the location may become illegal, so don't check it since multiple
|
|
168 |
// intervals might be illegal.
|
|
169 |
continue;
|
|
170 |
}
|
|
171 |
boolean unique = usedRegs.add(interval.location());
|
|
172 |
assert unique : "cannot write to same register twice";
|
|
173 |
}
|
|
174 |
|
|
175 |
verifyStackSlotMapping();
|
|
176 |
|
|
177 |
return true;
|
|
178 |
}
|
|
179 |
|
|
180 |
protected void verifyStackSlotMapping() {
|
46344
|
181 |
EconomicSet<Value> usedRegs = EconomicSet.create(Equivalence.DEFAULT);
|
43972
|
182 |
for (int i = 0; i < mappingFrom.size(); i++) {
|
|
183 |
Interval interval = mappingFrom.get(i);
|
|
184 |
if (interval != null && !isRegister(interval.location())) {
|
|
185 |
usedRegs.add(interval.location());
|
|
186 |
}
|
|
187 |
}
|
|
188 |
for (int i = 0; i < mappingTo.size(); i++) {
|
|
189 |
Interval interval = mappingTo.get(i);
|
|
190 |
assert !usedRegs.contains(interval.location()) ||
|
|
191 |
checkIntervalLocation(mappingFrom.get(i), interval, mappingFromOpr.get(i)) : "stack slots used in mappingFrom must be disjoint to mappingTo";
|
|
192 |
}
|
|
193 |
}
|
|
194 |
|
|
195 |
private static boolean checkIntervalLocation(Interval from, Interval to, Constant fromOpr) {
|
|
196 |
if (from == null) {
|
|
197 |
return fromOpr != null;
|
|
198 |
} else {
|
|
199 |
return to.location().equals(from.location());
|
|
200 |
}
|
|
201 |
}
|
|
202 |
|
|
203 |
// mark assignedReg and assignedRegHi of the interval as blocked
|
|
204 |
private void blockRegisters(Interval interval) {
|
|
205 |
Value location = interval.location();
|
|
206 |
if (mightBeBlocked(location)) {
|
|
207 |
assert areMultipleReadsAllowed() || valueBlocked(location) == 0 : "location already marked as used: " + location;
|
|
208 |
int direction = 1;
|
|
209 |
setValueBlocked(location, direction);
|
46640
|
210 |
allocator.getDebug().log("block %s", location);
|
43972
|
211 |
}
|
|
212 |
}
|
|
213 |
|
|
214 |
// mark assignedReg and assignedRegHi of the interval as unblocked
|
|
215 |
private void unblockRegisters(Interval interval) {
|
|
216 |
Value location = interval.location();
|
|
217 |
if (mightBeBlocked(location)) {
|
|
218 |
assert valueBlocked(location) > 0 : "location already marked as unused: " + location;
|
|
219 |
setValueBlocked(location, -1);
|
46640
|
220 |
allocator.getDebug().log("unblock %s", location);
|
43972
|
221 |
}
|
|
222 |
}
|
|
223 |
|
|
224 |
/**
|
|
225 |
* Checks if the {@linkplain Interval#location() location} of {@code to} is not blocked or is
|
|
226 |
* only blocked by {@code from}.
|
|
227 |
*/
|
|
228 |
private boolean safeToProcessMove(Interval from, Interval to) {
|
|
229 |
Value fromReg = from != null ? from.location() : null;
|
|
230 |
|
|
231 |
Value location = to.location();
|
|
232 |
if (mightBeBlocked(location)) {
|
|
233 |
if ((valueBlocked(location) > 1 || (valueBlocked(location) == 1 && !isMoveToSelf(fromReg, location)))) {
|
|
234 |
return false;
|
|
235 |
}
|
|
236 |
}
|
|
237 |
|
|
238 |
return true;
|
|
239 |
}
|
|
240 |
|
|
241 |
protected boolean isMoveToSelf(Value from, Value to) {
|
|
242 |
assert to != null;
|
|
243 |
if (to.equals(from)) {
|
|
244 |
return true;
|
|
245 |
}
|
|
246 |
if (from != null && isRegister(from) && isRegister(to) && asRegister(from).equals(asRegister(to))) {
|
46459
|
247 |
assert LIRKind.verifyMoveKinds(to.getValueKind(), from.getValueKind(), allocator.getRegisterAllocationConfig()) : String.format("Same register but Kind mismatch %s <- %s", to, from);
|
43972
|
248 |
return true;
|
|
249 |
}
|
|
250 |
return false;
|
|
251 |
}
|
|
252 |
|
|
253 |
protected boolean mightBeBlocked(Value location) {
|
|
254 |
return isRegister(location);
|
|
255 |
}
|
|
256 |
|
46344
|
257 |
private void createInsertionBuffer(ArrayList<LIRInstruction> list) {
|
43972
|
258 |
assert !insertionBuffer.initialized() : "overwriting existing buffer";
|
|
259 |
insertionBuffer.init(list);
|
|
260 |
}
|
|
261 |
|
|
262 |
private void appendInsertionBuffer() {
|
|
263 |
if (insertionBuffer.initialized()) {
|
|
264 |
insertionBuffer.finish();
|
|
265 |
}
|
|
266 |
assert !insertionBuffer.initialized() : "must be uninitialized now";
|
|
267 |
|
|
268 |
insertIdx = -1;
|
|
269 |
}
|
|
270 |
|
46536
|
271 |
private LIRInstruction insertMove(Interval fromInterval, Interval toInterval) {
|
43972
|
272 |
assert !fromInterval.operand.equals(toInterval.operand) : "from and to interval equal: " + fromInterval;
|
46459
|
273 |
assert LIRKind.verifyMoveKinds(toInterval.kind(), fromInterval.kind(), allocator.getRegisterAllocationConfig()) : "move between different types";
|
43972
|
274 |
assert insertIdx != -1 : "must setup insert position first";
|
|
275 |
|
46536
|
276 |
LIRInstruction move = createMove(fromInterval.operand, toInterval.operand, fromInterval.location(), toInterval.location());
|
|
277 |
insertionBuffer.append(insertIdx, move);
|
43972
|
278 |
|
46640
|
279 |
DebugContext debug = allocator.getDebug();
|
|
280 |
if (debug.isLogEnabled()) {
|
|
281 |
debug.log("insert move from %s to %s at %d", fromInterval, toInterval, insertIdx);
|
43972
|
282 |
}
|
46536
|
283 |
return move;
|
43972
|
284 |
}
|
|
285 |
|
|
286 |
/**
|
|
287 |
* @param fromOpr {@link Interval#operand operand} of the {@code from} interval
|
|
288 |
* @param toOpr {@link Interval#operand operand} of the {@code to} interval
|
|
289 |
* @param fromLocation {@link Interval#location() location} of the {@code to} interval
|
|
290 |
* @param toLocation {@link Interval#location() location} of the {@code to} interval
|
|
291 |
*/
|
|
292 |
protected LIRInstruction createMove(AllocatableValue fromOpr, AllocatableValue toOpr, AllocatableValue fromLocation, AllocatableValue toLocation) {
|
|
293 |
return getAllocator().getSpillMoveFactory().createMove(toOpr, fromOpr);
|
|
294 |
}
|
|
295 |
|
46536
|
296 |
private LIRInstruction insertMove(Constant fromOpr, Interval toInterval) {
|
43972
|
297 |
assert insertIdx != -1 : "must setup insert position first";
|
|
298 |
|
|
299 |
AllocatableValue toOpr = toInterval.operand;
|
46680
|
300 |
LIRInstruction move;
|
|
301 |
if (LIRValueUtil.isStackSlotValue(toInterval.location())) {
|
|
302 |
move = getAllocator().getSpillMoveFactory().createStackLoad(toOpr, fromOpr);
|
|
303 |
} else {
|
|
304 |
move = getAllocator().getSpillMoveFactory().createLoad(toOpr, fromOpr);
|
|
305 |
}
|
43972
|
306 |
insertionBuffer.append(insertIdx, move);
|
|
307 |
|
46640
|
308 |
DebugContext debug = allocator.getDebug();
|
|
309 |
if (debug.isLogEnabled()) {
|
|
310 |
debug.log("insert move from value %s to %s at %d", fromOpr, toInterval, insertIdx);
|
43972
|
311 |
}
|
46536
|
312 |
return move;
|
43972
|
313 |
}
|
|
314 |
|
|
315 |
@SuppressWarnings("try")
|
|
316 |
private void resolveMappings() {
|
46640
|
317 |
DebugContext debug = allocator.getDebug();
|
|
318 |
try (Indent indent = debug.logAndIndent("resolveMapping")) {
|
43972
|
319 |
assert verifyBeforeResolve();
|
46640
|
320 |
if (debug.isLogEnabled()) {
|
43972
|
321 |
printMapping();
|
|
322 |
}
|
|
323 |
|
|
324 |
// Block all registers that are used as input operands of a move.
|
|
325 |
// When a register is blocked, no move to this register is emitted.
|
|
326 |
// This is necessary for detecting cycles in moves.
|
|
327 |
int i;
|
|
328 |
for (i = mappingFrom.size() - 1; i >= 0; i--) {
|
|
329 |
Interval fromInterval = mappingFrom.get(i);
|
|
330 |
if (fromInterval != null) {
|
|
331 |
blockRegisters(fromInterval);
|
|
332 |
}
|
|
333 |
}
|
|
334 |
|
|
335 |
ArrayList<AllocatableValue> busySpillSlots = null;
|
|
336 |
while (mappingFrom.size() > 0) {
|
|
337 |
boolean processedInterval = false;
|
|
338 |
|
|
339 |
int spillCandidate = -1;
|
|
340 |
for (i = mappingFrom.size() - 1; i >= 0; i--) {
|
|
341 |
Interval fromInterval = mappingFrom.get(i);
|
|
342 |
Interval toInterval = mappingTo.get(i);
|
|
343 |
|
|
344 |
if (safeToProcessMove(fromInterval, toInterval)) {
|
|
345 |
// this interval can be processed because target is free
|
46536
|
346 |
final LIRInstruction move;
|
43972
|
347 |
if (fromInterval != null) {
|
46536
|
348 |
move = insertMove(fromInterval, toInterval);
|
43972
|
349 |
unblockRegisters(fromInterval);
|
|
350 |
} else {
|
46536
|
351 |
move = insertMove(mappingFromOpr.get(i), toInterval);
|
43972
|
352 |
}
|
46536
|
353 |
move.setComment(res, "MoveResolver resolve mapping");
|
43972
|
354 |
if (LIRValueUtil.isStackSlotValue(toInterval.location())) {
|
|
355 |
if (busySpillSlots == null) {
|
|
356 |
busySpillSlots = new ArrayList<>(2);
|
|
357 |
}
|
|
358 |
busySpillSlots.add(toInterval.location());
|
|
359 |
}
|
|
360 |
mappingFrom.remove(i);
|
|
361 |
mappingFromOpr.remove(i);
|
|
362 |
mappingTo.remove(i);
|
|
363 |
|
|
364 |
processedInterval = true;
|
|
365 |
} else if (fromInterval != null && isRegister(fromInterval.location()) &&
|
|
366 |
(busySpillSlots == null || !busySpillSlots.contains(fromInterval.spillSlot()))) {
|
|
367 |
// this interval cannot be processed now because target is not free
|
|
368 |
// it starts in a register, so it is a possible candidate for spilling
|
|
369 |
spillCandidate = i;
|
|
370 |
}
|
|
371 |
}
|
|
372 |
|
|
373 |
if (!processedInterval) {
|
|
374 |
breakCycle(spillCandidate);
|
|
375 |
}
|
|
376 |
}
|
|
377 |
}
|
|
378 |
|
|
379 |
// reset to default value
|
|
380 |
multipleReadsAllowed = false;
|
|
381 |
|
|
382 |
// check that all intervals have been processed
|
|
383 |
assert checkEmpty();
|
|
384 |
}
|
|
385 |
|
|
386 |
protected void breakCycle(int spillCandidate) {
|
|
387 |
// no move could be processed because there is a cycle in the move list
|
|
388 |
// (e.g. r1 . r2, r2 . r1), so one interval must be spilled to memory
|
|
389 |
assert spillCandidate != -1 : "no interval in register for spilling found";
|
|
390 |
|
|
391 |
// create a new spill interval and assign a stack slot to it
|
|
392 |
Interval fromInterval = mappingFrom.get(spillCandidate);
|
|
393 |
// do not allocate a new spill slot for temporary interval, but
|
|
394 |
// use spill slot assigned to fromInterval. Otherwise moves from
|
|
395 |
// one stack slot to another can happen (not allowed by LIRAssembler
|
|
396 |
AllocatableValue spillSlot = fromInterval.spillSlot();
|
|
397 |
if (spillSlot == null) {
|
|
398 |
spillSlot = getAllocator().getFrameMapBuilder().allocateSpillSlot(fromInterval.kind());
|
|
399 |
fromInterval.setSpillSlot(spillSlot);
|
46640
|
400 |
cycleBreakingSlotsAllocated.increment(allocator.getDebug());
|
43972
|
401 |
}
|
|
402 |
spillInterval(spillCandidate, fromInterval, spillSlot);
|
|
403 |
}
|
|
404 |
|
|
405 |
protected void spillInterval(int spillCandidate, Interval fromInterval, AllocatableValue spillSlot) {
|
|
406 |
assert mappingFrom.get(spillCandidate).equals(fromInterval);
|
|
407 |
Interval spillInterval = getAllocator().createDerivedInterval(fromInterval);
|
|
408 |
spillInterval.setKind(fromInterval.kind());
|
|
409 |
|
|
410 |
// add a dummy range because real position is difficult to calculate
|
|
411 |
// Note: this range is a special case when the integrity of the allocation is
|
|
412 |
// checked
|
|
413 |
spillInterval.addRange(1, 2);
|
|
414 |
|
|
415 |
spillInterval.assignLocation(spillSlot);
|
|
416 |
|
46640
|
417 |
DebugContext debug = allocator.getDebug();
|
|
418 |
if (debug.isLogEnabled()) {
|
|
419 |
debug.log("created new Interval for spilling: %s", spillInterval);
|
43972
|
420 |
}
|
|
421 |
blockRegisters(spillInterval);
|
|
422 |
|
|
423 |
// insert a move from register to stack and update the mapping
|
46536
|
424 |
LIRInstruction move = insertMove(fromInterval, spillInterval);
|
43972
|
425 |
mappingFrom.set(spillCandidate, spillInterval);
|
|
426 |
unblockRegisters(fromInterval);
|
46536
|
427 |
move.setComment(res, "MoveResolver break cycle");
|
43972
|
428 |
}
|
|
429 |
|
|
430 |
@SuppressWarnings("try")
|
|
431 |
private void printMapping() {
|
46640
|
432 |
DebugContext debug = allocator.getDebug();
|
|
433 |
try (Indent indent = debug.logAndIndent("Mapping")) {
|
43972
|
434 |
for (int i = mappingFrom.size() - 1; i >= 0; i--) {
|
|
435 |
Interval fromInterval = mappingFrom.get(i);
|
|
436 |
Interval toInterval = mappingTo.get(i);
|
|
437 |
String from;
|
|
438 |
Value to = toInterval.location();
|
|
439 |
if (fromInterval == null) {
|
|
440 |
from = mappingFromOpr.get(i).toString();
|
|
441 |
} else {
|
|
442 |
from = fromInterval.location().toString();
|
|
443 |
}
|
46640
|
444 |
debug.log("move %s <- %s", from, to);
|
43972
|
445 |
}
|
|
446 |
}
|
|
447 |
}
|
|
448 |
|
46344
|
449 |
void setInsertPosition(ArrayList<LIRInstruction> insertList, int insertIdx) {
|
43972
|
450 |
assert this.insertIdx == -1 : "use moveInsertPosition instead of setInsertPosition when data already set";
|
|
451 |
|
|
452 |
createInsertionBuffer(insertList);
|
|
453 |
this.insertIdx = insertIdx;
|
|
454 |
}
|
|
455 |
|
46344
|
456 |
void moveInsertPosition(ArrayList<LIRInstruction> newInsertList, int newInsertIdx) {
|
43972
|
457 |
if (insertionBuffer.lirList() != null && (insertionBuffer.lirList() != newInsertList || this.insertIdx != newInsertIdx)) {
|
|
458 |
// insert position changed . resolve current mappings
|
|
459 |
resolveMappings();
|
|
460 |
}
|
|
461 |
|
|
462 |
if (insertionBuffer.lirList() != newInsertList) {
|
|
463 |
// block changed . append insertionBuffer because it is
|
|
464 |
// bound to a specific block and create a new insertionBuffer
|
|
465 |
appendInsertionBuffer();
|
|
466 |
createInsertionBuffer(newInsertList);
|
|
467 |
}
|
|
468 |
|
|
469 |
this.insertIdx = newInsertIdx;
|
|
470 |
}
|
|
471 |
|
|
472 |
public void addMapping(Interval fromInterval, Interval toInterval) {
|
46640
|
473 |
DebugContext debug = allocator.getDebug();
|
43972
|
474 |
if (isIllegal(toInterval.location()) && toInterval.canMaterialize()) {
|
46640
|
475 |
if (debug.isLogEnabled()) {
|
|
476 |
debug.log("no store to rematerializable interval %s needed", toInterval);
|
43972
|
477 |
}
|
|
478 |
return;
|
|
479 |
}
|
|
480 |
if (isIllegal(fromInterval.location()) && fromInterval.canMaterialize()) {
|
|
481 |
// Instead of a reload, re-materialize the value
|
|
482 |
Constant rematValue = fromInterval.getMaterializedValue();
|
|
483 |
addMapping(rematValue, toInterval);
|
|
484 |
return;
|
|
485 |
}
|
46640
|
486 |
if (debug.isLogEnabled()) {
|
|
487 |
debug.log("add move mapping from %s to %s", fromInterval, toInterval);
|
43972
|
488 |
}
|
|
489 |
|
|
490 |
assert !fromInterval.operand.equals(toInterval.operand) : "from and to interval equal: " + fromInterval;
|
46680
|
491 |
assert LIRKind.verifyMoveKinds(toInterval.kind(), fromInterval.kind(), allocator.getRegisterAllocationConfig()) : String.format("Kind mismatch: %s vs. %s, from=%s, to=%s",
|
|
492 |
fromInterval.kind(),
|
46459
|
493 |
toInterval.kind(), fromInterval, toInterval);
|
43972
|
494 |
mappingFrom.add(fromInterval);
|
|
495 |
mappingFromOpr.add(null);
|
|
496 |
mappingTo.add(toInterval);
|
|
497 |
}
|
|
498 |
|
|
499 |
public void addMapping(Constant fromOpr, Interval toInterval) {
|
46640
|
500 |
DebugContext debug = allocator.getDebug();
|
|
501 |
if (debug.isLogEnabled()) {
|
|
502 |
debug.log("add move mapping from %s to %s", fromOpr, toInterval);
|
43972
|
503 |
}
|
|
504 |
|
|
505 |
mappingFrom.add(null);
|
|
506 |
mappingFromOpr.add(fromOpr);
|
|
507 |
mappingTo.add(toInterval);
|
|
508 |
}
|
|
509 |
|
|
510 |
void resolveAndAppendMoves() {
|
|
511 |
if (hasMappings()) {
|
|
512 |
resolveMappings();
|
|
513 |
}
|
|
514 |
appendInsertionBuffer();
|
|
515 |
}
|
|
516 |
}
|