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.trace;
|
|
24 |
|
|
25 |
import static jdk.vm.ci.code.ValueUtil.asAllocatableValue;
|
|
26 |
import static jdk.vm.ci.code.ValueUtil.asRegister;
|
|
27 |
import static jdk.vm.ci.code.ValueUtil.asStackSlot;
|
|
28 |
import static jdk.vm.ci.code.ValueUtil.isIllegal;
|
|
29 |
import static jdk.vm.ci.code.ValueUtil.isRegister;
|
|
30 |
import static jdk.vm.ci.code.ValueUtil.isStackSlot;
|
46344
|
31 |
import static org.graalvm.compiler.lir.LIRValueUtil.asVirtualStackSlot;
|
|
32 |
import static org.graalvm.compiler.lir.LIRValueUtil.isStackSlotValue;
|
|
33 |
import static org.graalvm.compiler.lir.LIRValueUtil.isVirtualStackSlot;
|
|
34 |
import static org.graalvm.compiler.lir.alloc.trace.TraceUtil.asShadowedRegisterValue;
|
|
35 |
import static org.graalvm.compiler.lir.alloc.trace.TraceUtil.isShadowedRegisterValue;
|
43972
|
36 |
|
|
37 |
import java.util.ArrayList;
|
|
38 |
import java.util.Arrays;
|
|
39 |
import java.util.HashSet;
|
|
40 |
|
|
41 |
import org.graalvm.compiler.core.common.LIRKind;
|
46459
|
42 |
import org.graalvm.compiler.core.common.alloc.RegisterAllocationConfig;
|
43972
|
43 |
import org.graalvm.compiler.debug.Debug;
|
|
44 |
import org.graalvm.compiler.debug.DebugCounter;
|
|
45 |
import org.graalvm.compiler.debug.GraalError;
|
|
46 |
import org.graalvm.compiler.debug.Indent;
|
|
47 |
import org.graalvm.compiler.lir.LIRInsertionBuffer;
|
|
48 |
import org.graalvm.compiler.lir.LIRInstruction;
|
|
49 |
import org.graalvm.compiler.lir.VirtualStackSlot;
|
|
50 |
import org.graalvm.compiler.lir.framemap.FrameMap;
|
|
51 |
import org.graalvm.compiler.lir.framemap.FrameMapBuilder;
|
|
52 |
import org.graalvm.compiler.lir.framemap.FrameMapBuilderTool;
|
|
53 |
import org.graalvm.compiler.lir.gen.LIRGenerationResult;
|
|
54 |
import org.graalvm.compiler.lir.gen.LIRGeneratorTool.MoveFactory;
|
46344
|
55 |
import org.graalvm.compiler.options.OptionValues;
|
43972
|
56 |
|
|
57 |
import jdk.vm.ci.code.Architecture;
|
|
58 |
import jdk.vm.ci.code.RegisterArray;
|
|
59 |
import jdk.vm.ci.code.StackSlot;
|
|
60 |
import jdk.vm.ci.meta.AllocatableValue;
|
|
61 |
import jdk.vm.ci.meta.Value;
|
|
62 |
|
|
63 |
/**
|
|
64 |
*/
|
|
65 |
public final class TraceGlobalMoveResolver extends TraceGlobalMoveResolutionPhase.MoveResolver {
|
|
66 |
|
|
67 |
private static final DebugCounter cycleBreakingSlotsAllocated = Debug.counter("TraceRA[cycleBreakingSlotsAllocated(global)]");
|
|
68 |
private static final DebugCounter cycleBreakingSlotsReused = Debug.counter("TraceRA[cycleBreakingSlotsReused(global)]");
|
|
69 |
|
|
70 |
private int insertIdx;
|
|
71 |
private LIRInsertionBuffer insertionBuffer; // buffer where moves are inserted
|
|
72 |
|
46344
|
73 |
private final ArrayList<Value> mappingFrom;
|
|
74 |
private final ArrayList<Value> mappingFromStack;
|
|
75 |
private final ArrayList<AllocatableValue> mappingTo;
|
43972
|
76 |
private final int[] registerBlocked;
|
|
77 |
private static final int STACK_SLOT_IN_CALLER_FRAME_IDX = -1;
|
|
78 |
private int[] stackBlocked;
|
|
79 |
private final int firstVirtualStackIndex;
|
|
80 |
private final MoveFactory spillMoveFactory;
|
|
81 |
private final FrameMapBuilder frameMapBuilder;
|
46344
|
82 |
private final OptionValues options;
|
46459
|
83 |
private final RegisterAllocationConfig registerAllocationConfig;
|
43972
|
84 |
|
|
85 |
private void setValueBlocked(Value location, int direction) {
|
|
86 |
assert direction == 1 || direction == -1 : "out of bounds";
|
|
87 |
if (isStackSlotValue(location)) {
|
|
88 |
int stackIdx = getStackArrayIndex(location);
|
|
89 |
if (stackIdx == STACK_SLOT_IN_CALLER_FRAME_IDX) {
|
|
90 |
// incoming stack arguments can be ignored
|
|
91 |
return;
|
|
92 |
}
|
|
93 |
if (stackIdx >= stackBlocked.length) {
|
|
94 |
stackBlocked = Arrays.copyOf(stackBlocked, stackIdx + 1);
|
|
95 |
}
|
|
96 |
stackBlocked[stackIdx] += direction;
|
|
97 |
} else {
|
|
98 |
assert direction == 1 || direction == -1 : "out of bounds";
|
|
99 |
if (isRegister(location)) {
|
|
100 |
registerBlocked[asRegister(location).number] += direction;
|
|
101 |
} else {
|
|
102 |
throw GraalError.shouldNotReachHere("unhandled value " + location);
|
|
103 |
}
|
|
104 |
}
|
|
105 |
}
|
|
106 |
|
|
107 |
private int valueBlocked(Value location) {
|
|
108 |
if (isStackSlotValue(location)) {
|
|
109 |
int stackIdx = getStackArrayIndex(location);
|
|
110 |
if (stackIdx == STACK_SLOT_IN_CALLER_FRAME_IDX) {
|
|
111 |
// incoming stack arguments are always blocked (aka they can not be written)
|
|
112 |
return 1;
|
|
113 |
}
|
|
114 |
if (stackIdx >= stackBlocked.length) {
|
|
115 |
return 0;
|
|
116 |
}
|
|
117 |
return stackBlocked[stackIdx];
|
|
118 |
}
|
|
119 |
if (isRegister(location)) {
|
|
120 |
return registerBlocked[asRegister(location).number];
|
|
121 |
}
|
|
122 |
throw GraalError.shouldNotReachHere("unhandled value " + location);
|
|
123 |
}
|
|
124 |
|
|
125 |
private static boolean areMultipleReadsAllowed() {
|
|
126 |
return true;
|
|
127 |
}
|
|
128 |
|
|
129 |
private boolean hasMappings() {
|
|
130 |
return mappingFrom.size() > 0;
|
|
131 |
}
|
|
132 |
|
|
133 |
private MoveFactory getSpillMoveFactory() {
|
|
134 |
return spillMoveFactory;
|
|
135 |
}
|
|
136 |
|
|
137 |
private RegisterArray getRegisters() {
|
|
138 |
return frameMapBuilder.getRegisterConfig().getAllocatableRegisters();
|
|
139 |
}
|
|
140 |
|
46459
|
141 |
public TraceGlobalMoveResolver(LIRGenerationResult res, MoveFactory spillMoveFactory, RegisterAllocationConfig registerAllocationConfig, Architecture arch) {
|
43972
|
142 |
|
|
143 |
this.mappingFrom = new ArrayList<>(8);
|
|
144 |
this.mappingFromStack = new ArrayList<>(8);
|
|
145 |
this.mappingTo = new ArrayList<>(8);
|
|
146 |
this.insertIdx = -1;
|
|
147 |
this.insertionBuffer = new LIRInsertionBuffer();
|
|
148 |
|
|
149 |
this.frameMapBuilder = res.getFrameMapBuilder();
|
|
150 |
this.spillMoveFactory = spillMoveFactory;
|
|
151 |
this.registerBlocked = new int[arch.getRegisters().size()];
|
46459
|
152 |
this.registerAllocationConfig = registerAllocationConfig;
|
43972
|
153 |
|
|
154 |
FrameMapBuilderTool frameMapBuilderTool = (FrameMapBuilderTool) frameMapBuilder;
|
|
155 |
this.stackBlocked = new int[frameMapBuilderTool.getNumberOfStackSlots()];
|
|
156 |
|
|
157 |
FrameMap frameMap = frameMapBuilderTool.getFrameMap();
|
|
158 |
this.firstVirtualStackIndex = !frameMap.frameNeedsAllocating() ? 0 : frameMap.currentFrameSize() + 1;
|
46344
|
159 |
this.options = res.getLIR().getOptions();
|
43972
|
160 |
}
|
|
161 |
|
|
162 |
private boolean checkEmpty() {
|
|
163 |
for (int i = 0; i < stackBlocked.length; i++) {
|
|
164 |
assert stackBlocked[i] == 0 : "stack map must be empty before and after processing";
|
|
165 |
}
|
|
166 |
assert mappingFrom.size() == 0 && mappingTo.size() == 0 && mappingFromStack.size() == 0 : "list must be empty before and after processing";
|
|
167 |
for (int i = 0; i < getRegisters().size(); i++) {
|
|
168 |
assert registerBlocked[i] == 0 : "register map must be empty before and after processing";
|
|
169 |
}
|
|
170 |
return true;
|
|
171 |
}
|
|
172 |
|
|
173 |
private boolean verifyBeforeResolve() {
|
|
174 |
assert mappingFrom.size() == mappingTo.size() && mappingFrom.size() == mappingFromStack.size() : "length must be equal";
|
|
175 |
assert insertIdx != -1 : "insert position not set";
|
|
176 |
|
|
177 |
int i;
|
|
178 |
int j;
|
|
179 |
if (!areMultipleReadsAllowed()) {
|
|
180 |
for (i = 0; i < mappingFrom.size(); i++) {
|
|
181 |
for (j = i + 1; j < mappingFrom.size(); j++) {
|
|
182 |
assert mappingFrom.get(i) == null || mappingFrom.get(i) != mappingFrom.get(j) : "cannot read from same interval twice";
|
|
183 |
}
|
|
184 |
}
|
|
185 |
}
|
|
186 |
|
|
187 |
for (i = 0; i < mappingTo.size(); i++) {
|
|
188 |
for (j = i + 1; j < mappingTo.size(); j++) {
|
|
189 |
assert mappingTo.get(i) != mappingTo.get(j) : "cannot write to same interval twice";
|
|
190 |
}
|
|
191 |
}
|
|
192 |
|
|
193 |
for (i = 0; i < mappingTo.size(); i++) {
|
|
194 |
Value to = mappingTo.get(i);
|
|
195 |
assert !isStackSlotValue(to) || getStackArrayIndex(to) != STACK_SLOT_IN_CALLER_FRAME_IDX : "Cannot move to in argument: " + to;
|
|
196 |
}
|
|
197 |
|
|
198 |
HashSet<Value> usedRegs = new HashSet<>();
|
|
199 |
if (!areMultipleReadsAllowed()) {
|
|
200 |
for (i = 0; i < mappingFrom.size(); i++) {
|
|
201 |
Value from = mappingFrom.get(i);
|
|
202 |
if (from != null && !isIllegal(from)) {
|
|
203 |
boolean unique = usedRegs.add(from);
|
|
204 |
assert unique : "cannot read from same register twice";
|
|
205 |
}
|
|
206 |
}
|
|
207 |
}
|
|
208 |
|
|
209 |
usedRegs.clear();
|
|
210 |
for (i = 0; i < mappingTo.size(); i++) {
|
|
211 |
Value to = mappingTo.get(i);
|
|
212 |
if (isIllegal(to)) {
|
|
213 |
// After insertion the location may become illegal, so don't check it since multiple
|
|
214 |
// intervals might be illegal.
|
|
215 |
continue;
|
|
216 |
}
|
|
217 |
boolean unique = usedRegs.add(to);
|
|
218 |
assert unique : "cannot write to same register twice";
|
|
219 |
}
|
|
220 |
|
|
221 |
return true;
|
|
222 |
}
|
|
223 |
|
|
224 |
// mark assignedReg and assignedRegHi of the interval as blocked
|
|
225 |
private void block(Value location) {
|
|
226 |
if (mightBeBlocked(location)) {
|
|
227 |
assert areMultipleReadsAllowed() || valueBlocked(location) == 0 : "location already marked as used: " + location;
|
|
228 |
setValueBlocked(location, 1);
|
|
229 |
Debug.log("block %s", location);
|
|
230 |
}
|
|
231 |
}
|
|
232 |
|
|
233 |
// mark assignedReg and assignedRegHi of the interval as unblocked
|
|
234 |
private void unblock(Value location) {
|
|
235 |
if (mightBeBlocked(location)) {
|
|
236 |
assert valueBlocked(location) > 0 : "location already marked as unused: " + location;
|
|
237 |
setValueBlocked(location, -1);
|
|
238 |
Debug.log("unblock %s", location);
|
|
239 |
}
|
|
240 |
}
|
|
241 |
|
|
242 |
/**
|
|
243 |
* Checks if {@code to} is not blocked or is only blocked by {@code from}.
|
|
244 |
*/
|
|
245 |
private boolean safeToProcessMove(Value fromLocation, Value toLocation) {
|
|
246 |
if (mightBeBlocked(toLocation)) {
|
|
247 |
if ((valueBlocked(toLocation) > 1 || (valueBlocked(toLocation) == 1 && !isMoveToSelf(fromLocation, toLocation)))) {
|
|
248 |
return false;
|
|
249 |
}
|
|
250 |
}
|
|
251 |
|
|
252 |
return true;
|
|
253 |
}
|
|
254 |
|
|
255 |
public static boolean isMoveToSelf(Value from, Value to) {
|
|
256 |
assert to != null;
|
|
257 |
if (to.equals(from)) {
|
|
258 |
return true;
|
|
259 |
}
|
|
260 |
if (from == null) {
|
|
261 |
return false;
|
|
262 |
}
|
|
263 |
if (isShadowedRegisterValue(from)) {
|
|
264 |
/* From is a shadowed register. */
|
|
265 |
if (isShadowedRegisterValue(to)) {
|
|
266 |
// both shadowed but not equal
|
|
267 |
return false;
|
|
268 |
}
|
|
269 |
ShadowedRegisterValue shadowed = asShadowedRegisterValue(from);
|
|
270 |
if (isRegisterToRegisterMoveToSelf(shadowed.getRegister(), to)) {
|
|
271 |
return true;
|
|
272 |
}
|
|
273 |
if (isStackSlotValue(to)) {
|
|
274 |
return to.equals(shadowed.getStackSlot());
|
|
275 |
}
|
|
276 |
} else {
|
|
277 |
/*
|
|
278 |
* A shadowed destination value is never a self move it both values are not equal. Fall
|
|
279 |
* through.
|
|
280 |
*/
|
|
281 |
// if (isShadowedRegisterValue(to)) return false;
|
|
282 |
|
|
283 |
return isRegisterToRegisterMoveToSelf(from, to);
|
|
284 |
}
|
|
285 |
return false;
|
|
286 |
}
|
|
287 |
|
|
288 |
private static boolean isRegisterToRegisterMoveToSelf(Value from, Value to) {
|
|
289 |
if (to.equals(from)) {
|
|
290 |
return true;
|
|
291 |
}
|
|
292 |
if (isRegister(from) && isRegister(to) && asRegister(from).equals(asRegister(to))) {
|
|
293 |
// Values differ but Registers are the same
|
|
294 |
return true;
|
|
295 |
}
|
|
296 |
return false;
|
|
297 |
}
|
|
298 |
|
|
299 |
private static boolean mightBeBlocked(Value location) {
|
|
300 |
return isRegister(location) || isStackSlotValue(location);
|
|
301 |
}
|
|
302 |
|
46344
|
303 |
private void createInsertionBuffer(ArrayList<LIRInstruction> list) {
|
43972
|
304 |
assert !insertionBuffer.initialized() : "overwriting existing buffer";
|
|
305 |
insertionBuffer.init(list);
|
|
306 |
}
|
|
307 |
|
|
308 |
private void appendInsertionBuffer() {
|
|
309 |
if (insertionBuffer.initialized()) {
|
|
310 |
insertionBuffer.finish();
|
|
311 |
}
|
|
312 |
assert !insertionBuffer.initialized() : "must be uninitialized now";
|
|
313 |
|
|
314 |
insertIdx = -1;
|
|
315 |
}
|
|
316 |
|
|
317 |
private void insertMove(Value fromOperand, AllocatableValue toOperand) {
|
|
318 |
assert !fromOperand.equals(toOperand) : "from and to are equal: " + fromOperand + " vs. " + toOperand;
|
46459
|
319 |
assert LIRKind.verifyMoveKinds(fromOperand.getValueKind(), fromOperand.getValueKind(), registerAllocationConfig) : "move between different types";
|
43972
|
320 |
assert insertIdx != -1 : "must setup insert position first";
|
|
321 |
|
|
322 |
insertionBuffer.append(insertIdx, createMove(fromOperand, toOperand));
|
|
323 |
|
|
324 |
if (Debug.isLogEnabled()) {
|
|
325 |
Debug.log("insert move from %s to %s at %d", fromOperand, toOperand, insertIdx);
|
|
326 |
}
|
|
327 |
}
|
|
328 |
|
|
329 |
/**
|
|
330 |
* @param fromOpr Operand of the {@code from} interval
|
|
331 |
* @param toOpr Operand of the {@code to} interval
|
|
332 |
*/
|
|
333 |
private LIRInstruction createMove(Value fromOpr, AllocatableValue toOpr) {
|
|
334 |
if (isStackSlotValue(toOpr) && isStackSlotValue(fromOpr)) {
|
|
335 |
return getSpillMoveFactory().createStackMove(toOpr, asAllocatableValue(fromOpr));
|
|
336 |
}
|
|
337 |
return getSpillMoveFactory().createMove(toOpr, fromOpr);
|
|
338 |
}
|
|
339 |
|
|
340 |
@SuppressWarnings("try")
|
|
341 |
private void resolveMappings() {
|
|
342 |
try (Indent indent = Debug.logAndIndent("resolveMapping")) {
|
|
343 |
assert verifyBeforeResolve();
|
|
344 |
if (Debug.isLogEnabled()) {
|
|
345 |
printMapping();
|
|
346 |
}
|
|
347 |
|
|
348 |
// Block all registers that are used as input operands of a move.
|
|
349 |
// When a register is blocked, no move to this register is emitted.
|
|
350 |
// This is necessary for detecting cycles in moves.
|
|
351 |
for (int i = mappingFrom.size() - 1; i >= 0; i--) {
|
|
352 |
Value from = mappingFrom.get(i);
|
|
353 |
block(from);
|
|
354 |
}
|
|
355 |
|
|
356 |
ArrayList<AllocatableValue> busySpillSlots = null;
|
|
357 |
while (mappingFrom.size() > 0) {
|
|
358 |
boolean processedInterval = false;
|
|
359 |
|
|
360 |
int spillCandidate = -1;
|
|
361 |
for (int i = mappingFrom.size() - 1; i >= 0; i--) {
|
|
362 |
Value fromLocation = mappingFrom.get(i);
|
|
363 |
AllocatableValue toLocation = mappingTo.get(i);
|
|
364 |
if (safeToProcessMove(fromLocation, toLocation)) {
|
|
365 |
// this interval can be processed because target is free
|
|
366 |
insertMove(fromLocation, toLocation);
|
|
367 |
unblock(fromLocation);
|
|
368 |
if (isStackSlotValue(toLocation)) {
|
|
369 |
if (busySpillSlots == null) {
|
|
370 |
busySpillSlots = new ArrayList<>(2);
|
|
371 |
}
|
|
372 |
busySpillSlots.add(toLocation);
|
|
373 |
}
|
|
374 |
mappingFrom.remove(i);
|
|
375 |
mappingFromStack.remove(i);
|
|
376 |
mappingTo.remove(i);
|
|
377 |
|
|
378 |
processedInterval = true;
|
|
379 |
} else if (fromLocation != null) {
|
|
380 |
if (isRegister(fromLocation) && (busySpillSlots == null || !busySpillSlots.contains(mappingFromStack.get(i)))) {
|
|
381 |
// this interval cannot be processed now because target is not free
|
|
382 |
// it starts in a register, so it is a possible candidate for spilling
|
|
383 |
spillCandidate = i;
|
|
384 |
} else if (isStackSlotValue(fromLocation) && spillCandidate == -1) {
|
|
385 |
// fall back to spill a stack slot in case no other candidate is found
|
|
386 |
spillCandidate = i;
|
|
387 |
}
|
|
388 |
}
|
|
389 |
}
|
|
390 |
|
|
391 |
if (!processedInterval) {
|
|
392 |
breakCycle(spillCandidate);
|
|
393 |
}
|
|
394 |
}
|
|
395 |
}
|
|
396 |
|
|
397 |
// check that all intervals have been processed
|
|
398 |
assert checkEmpty();
|
|
399 |
}
|
|
400 |
|
|
401 |
@SuppressWarnings("try")
|
|
402 |
private void breakCycle(int spillCandidate) {
|
|
403 |
// no move could be processed because there is a cycle in the move list
|
|
404 |
// (e.g. r1 . r2, r2 . r1), so one interval must be spilled to memory
|
|
405 |
assert spillCandidate != -1 : "no interval in register for spilling found";
|
|
406 |
|
|
407 |
// create a new spill interval and assign a stack slot to it
|
|
408 |
Value from = mappingFrom.get(spillCandidate);
|
|
409 |
try (Indent indent = Debug.logAndIndent("BreakCycle: %s", from)) {
|
|
410 |
AllocatableValue spillSlot = null;
|
46344
|
411 |
if (TraceRegisterAllocationPhase.Options.TraceRAreuseStackSlotsForMoveResolutionCycleBreaking.getValue(options) && !isStackSlotValue(from)) {
|
43972
|
412 |
// don't use the stack slot if from is already the stack slot
|
|
413 |
Value fromStack = mappingFromStack.get(spillCandidate);
|
|
414 |
if (fromStack != null) {
|
|
415 |
spillSlot = (AllocatableValue) fromStack;
|
|
416 |
cycleBreakingSlotsReused.increment();
|
|
417 |
Debug.log("reuse slot for spilling: %s", spillSlot);
|
|
418 |
}
|
|
419 |
}
|
|
420 |
if (spillSlot == null) {
|
|
421 |
spillSlot = frameMapBuilder.allocateSpillSlot(from.getValueKind());
|
|
422 |
cycleBreakingSlotsAllocated.increment();
|
|
423 |
Debug.log("created new slot for spilling: %s", spillSlot);
|
|
424 |
// insert a move from register to stack and update the mapping
|
|
425 |
insertMove(from, spillSlot);
|
|
426 |
}
|
|
427 |
block(spillSlot);
|
|
428 |
mappingFrom.set(spillCandidate, spillSlot);
|
|
429 |
unblock(from);
|
|
430 |
}
|
|
431 |
}
|
|
432 |
|
|
433 |
@SuppressWarnings("try")
|
|
434 |
private void printMapping() {
|
|
435 |
try (Indent indent = Debug.logAndIndent("Mapping")) {
|
|
436 |
for (int i = mappingFrom.size() - 1; i >= 0; i--) {
|
|
437 |
Debug.log("move %s <- %s (%s)", mappingTo.get(i), mappingFrom.get(i), mappingFromStack.get(i));
|
|
438 |
}
|
|
439 |
}
|
|
440 |
}
|
|
441 |
|
46344
|
442 |
public void setInsertPosition(ArrayList<LIRInstruction> insertList, int insertIdx) {
|
43972
|
443 |
assert this.insertIdx == -1 : "use moveInsertPosition instead of setInsertPosition when data already set";
|
|
444 |
|
|
445 |
createInsertionBuffer(insertList);
|
|
446 |
this.insertIdx = insertIdx;
|
|
447 |
}
|
|
448 |
|
|
449 |
@Override
|
|
450 |
public void addMapping(Value from, AllocatableValue to, Value fromStack) {
|
|
451 |
if (Debug.isLogEnabled()) {
|
|
452 |
Debug.log("add move mapping from %s to %s", from, to);
|
|
453 |
}
|
|
454 |
|
|
455 |
assert !from.equals(to) : "from and to interval equal: " + from;
|
46459
|
456 |
assert LIRKind.verifyMoveKinds(to.getValueKind(), from.getValueKind(), registerAllocationConfig) : String.format("Kind mismatch: %s vs. %s, from=%s, to=%s", from.getValueKind(),
|
|
457 |
to.getValueKind(), from, to);
|
|
458 |
assert fromStack == null || LIRKind.verifyMoveKinds(to.getValueKind(), fromStack.getValueKind(), registerAllocationConfig) : String.format("Kind mismatch: %s vs. %s, fromStack=%s, to=%s",
|
|
459 |
fromStack.getValueKind(),
|
43972
|
460 |
to.getValueKind(), fromStack, to);
|
|
461 |
mappingFrom.add(from);
|
|
462 |
mappingFromStack.add(fromStack);
|
|
463 |
mappingTo.add(to);
|
|
464 |
}
|
|
465 |
|
|
466 |
public void resolveAndAppendMoves() {
|
|
467 |
if (hasMappings()) {
|
|
468 |
resolveMappings();
|
|
469 |
}
|
|
470 |
appendInsertionBuffer();
|
|
471 |
}
|
|
472 |
|
|
473 |
private int getStackArrayIndex(Value stackSlotValue) {
|
|
474 |
if (isStackSlot(stackSlotValue)) {
|
|
475 |
return getStackArrayIndex(asStackSlot(stackSlotValue));
|
|
476 |
}
|
|
477 |
if (isVirtualStackSlot(stackSlotValue)) {
|
|
478 |
return getStackArrayIndex(asVirtualStackSlot(stackSlotValue));
|
|
479 |
}
|
|
480 |
throw GraalError.shouldNotReachHere("value is not a stack slot: " + stackSlotValue);
|
|
481 |
}
|
|
482 |
|
|
483 |
private int getStackArrayIndex(StackSlot stackSlot) {
|
|
484 |
int stackIdx;
|
|
485 |
if (stackSlot.isInCallerFrame()) {
|
|
486 |
// incoming stack arguments can be ignored
|
|
487 |
stackIdx = STACK_SLOT_IN_CALLER_FRAME_IDX;
|
|
488 |
} else {
|
|
489 |
assert stackSlot.getRawAddFrameSize() : "Unexpected stack slot: " + stackSlot;
|
|
490 |
int offset = -stackSlot.getRawOffset();
|
|
491 |
assert 0 <= offset && offset < firstVirtualStackIndex : String.format("Wrong stack slot offset: %d (first virtual stack slot index: %d", offset, firstVirtualStackIndex);
|
|
492 |
stackIdx = offset;
|
|
493 |
}
|
|
494 |
return stackIdx;
|
|
495 |
}
|
|
496 |
|
|
497 |
private int getStackArrayIndex(VirtualStackSlot virtualStackSlot) {
|
|
498 |
return firstVirtualStackIndex + virtualStackSlot.getId();
|
|
499 |
}
|
|
500 |
|
|
501 |
}
|