src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/trace/TraceGlobalMoveResolver.java
Index
Unified diffs
Context diffs
Sdiffs
Patch
New
Old
Previous File
Next File
hotspot Cdiff src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/trace/TraceGlobalMoveResolver.java
src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/trace/TraceGlobalMoveResolver.java
Print this page
*** 38,51 ****
import java.util.Arrays;
import java.util.HashSet;
import org.graalvm.compiler.core.common.LIRKind;
import org.graalvm.compiler.core.common.alloc.RegisterAllocationConfig;
! import org.graalvm.compiler.debug.Debug;
! import org.graalvm.compiler.debug.DebugCounter;
import org.graalvm.compiler.debug.GraalError;
import org.graalvm.compiler.debug.Indent;
import org.graalvm.compiler.lir.LIRInsertionBuffer;
import org.graalvm.compiler.lir.LIRInstruction;
import org.graalvm.compiler.lir.VirtualStackSlot;
import org.graalvm.compiler.lir.framemap.FrameMap;
import org.graalvm.compiler.lir.framemap.FrameMapBuilder;
--- 38,52 ----
import java.util.Arrays;
import java.util.HashSet;
import org.graalvm.compiler.core.common.LIRKind;
import org.graalvm.compiler.core.common.alloc.RegisterAllocationConfig;
! import org.graalvm.compiler.debug.CounterKey;
! import org.graalvm.compiler.debug.DebugContext;
import org.graalvm.compiler.debug.GraalError;
import org.graalvm.compiler.debug.Indent;
+ import org.graalvm.compiler.lir.LIR;
import org.graalvm.compiler.lir.LIRInsertionBuffer;
import org.graalvm.compiler.lir.LIRInstruction;
import org.graalvm.compiler.lir.VirtualStackSlot;
import org.graalvm.compiler.lir.framemap.FrameMap;
import org.graalvm.compiler.lir.framemap.FrameMapBuilder;
*** 62,73 ****
/**
*/
public final class TraceGlobalMoveResolver extends TraceGlobalMoveResolutionPhase.MoveResolver {
! private static final DebugCounter cycleBreakingSlotsAllocated = Debug.counter("TraceRA[cycleBreakingSlotsAllocated(global)]");
! private static final DebugCounter cycleBreakingSlotsReused = Debug.counter("TraceRA[cycleBreakingSlotsReused(global)]");
private int insertIdx;
private LIRInsertionBuffer insertionBuffer; // buffer where moves are inserted
private final ArrayList<Value> mappingFrom;
--- 63,74 ----
/**
*/
public final class TraceGlobalMoveResolver extends TraceGlobalMoveResolutionPhase.MoveResolver {
! private static final CounterKey cycleBreakingSlotsAllocated = DebugContext.counter("TraceRA[cycleBreakingSlotsAllocated(global)]");
! private static final CounterKey cycleBreakingSlotsReused = DebugContext.counter("TraceRA[cycleBreakingSlotsReused(global)]");
private int insertIdx;
private LIRInsertionBuffer insertionBuffer; // buffer where moves are inserted
private final ArrayList<Value> mappingFrom;
*** 80,89 ****
--- 81,91 ----
private final MoveFactory spillMoveFactory;
private final FrameMapBuilder frameMapBuilder;
private final OptionValues options;
private final RegisterAllocationConfig registerAllocationConfig;
private final LIRGenerationResult res;
+ private final DebugContext debug;
private void setValueBlocked(Value location, int direction) {
assert direction == 1 || direction == -1 : "out of bounds";
if (isStackSlotValue(location)) {
int stackIdx = getStackArrayIndex(location);
*** 155,166 ****
FrameMapBuilderTool frameMapBuilderTool = (FrameMapBuilderTool) frameMapBuilder;
this.stackBlocked = new int[frameMapBuilderTool.getNumberOfStackSlots()];
FrameMap frameMap = frameMapBuilderTool.getFrameMap();
this.firstVirtualStackIndex = !frameMap.frameNeedsAllocating() ? 0 : frameMap.currentFrameSize() + 1;
- this.options = res.getLIR().getOptions();
this.res = res;
}
private boolean checkEmpty() {
for (int i = 0; i < stackBlocked.length; i++) {
assert stackBlocked[i] == 0 : "stack map must be empty before and after processing";
--- 157,170 ----
FrameMapBuilderTool frameMapBuilderTool = (FrameMapBuilderTool) frameMapBuilder;
this.stackBlocked = new int[frameMapBuilderTool.getNumberOfStackSlots()];
FrameMap frameMap = frameMapBuilderTool.getFrameMap();
this.firstVirtualStackIndex = !frameMap.frameNeedsAllocating() ? 0 : frameMap.currentFrameSize() + 1;
this.res = res;
+ LIR lir = res.getLIR();
+ this.options = lir.getOptions();
+ this.debug = lir.getDebug();
}
private boolean checkEmpty() {
for (int i = 0; i < stackBlocked.length; i++) {
assert stackBlocked[i] == 0 : "stack map must be empty before and after processing";
*** 226,245 ****
// mark assignedReg and assignedRegHi of the interval as blocked
private void block(Value location) {
if (mightBeBlocked(location)) {
assert areMultipleReadsAllowed() || valueBlocked(location) == 0 : "location already marked as used: " + location;
setValueBlocked(location, 1);
! Debug.log("block %s", location);
}
}
// mark assignedReg and assignedRegHi of the interval as unblocked
private void unblock(Value location) {
if (mightBeBlocked(location)) {
assert valueBlocked(location) > 0 : "location already marked as unused: " + location;
setValueBlocked(location, -1);
! Debug.log("unblock %s", location);
}
}
/**
* Checks if {@code to} is not blocked or is only blocked by {@code from}.
--- 230,249 ----
// mark assignedReg and assignedRegHi of the interval as blocked
private void block(Value location) {
if (mightBeBlocked(location)) {
assert areMultipleReadsAllowed() || valueBlocked(location) == 0 : "location already marked as used: " + location;
setValueBlocked(location, 1);
! debug.log("block %s", location);
}
}
// mark assignedReg and assignedRegHi of the interval as unblocked
private void unblock(Value location) {
if (mightBeBlocked(location)) {
assert valueBlocked(location) > 0 : "location already marked as unused: " + location;
setValueBlocked(location, -1);
! debug.log("unblock %s", location);
}
}
/**
* Checks if {@code to} is not blocked or is only blocked by {@code from}.
*** 322,333 ****
assert insertIdx != -1 : "must setup insert position first";
LIRInstruction move = createMove(fromOperand, toOperand);
insertionBuffer.append(insertIdx, move);
! if (Debug.isLogEnabled()) {
! Debug.log("insert move from %s to %s at %d", fromOperand, toOperand, insertIdx);
}
return move;
}
/**
--- 326,337 ----
assert insertIdx != -1 : "must setup insert position first";
LIRInstruction move = createMove(fromOperand, toOperand);
insertionBuffer.append(insertIdx, move);
! if (debug.isLogEnabled()) {
! debug.log("insert move from %s to %s at %d", fromOperand, toOperand, insertIdx);
}
return move;
}
/**
*** 341,353 ****
return getSpillMoveFactory().createMove(toOpr, fromOpr);
}
@SuppressWarnings("try")
private void resolveMappings() {
! try (Indent indent = Debug.logAndIndent("resolveMapping")) {
assert verifyBeforeResolve();
! if (Debug.isLogEnabled()) {
printMapping();
}
// Block all registers that are used as input operands of a move.
// When a register is blocked, no move to this register is emitted.
--- 345,357 ----
return getSpillMoveFactory().createMove(toOpr, fromOpr);
}
@SuppressWarnings("try")
private void resolveMappings() {
! try (Indent indent = debug.logAndIndent("resolveMapping")) {
assert verifyBeforeResolve();
! if (debug.isLogEnabled()) {
printMapping();
}
// Block all registers that are used as input operands of a move.
// When a register is blocked, no move to this register is emitted.
*** 409,433 ****
// (e.g. r1 . r2, r2 . r1), so one interval must be spilled to memory
assert spillCandidate != -1 : "no interval in register for spilling found";
// create a new spill interval and assign a stack slot to it
Value from = mappingFrom.get(spillCandidate);
! try (Indent indent = Debug.logAndIndent("BreakCycle: %s", from)) {
AllocatableValue spillSlot = null;
if (TraceRegisterAllocationPhase.Options.TraceRAreuseStackSlotsForMoveResolutionCycleBreaking.getValue(options) && !isStackSlotValue(from)) {
// don't use the stack slot if from is already the stack slot
Value fromStack = mappingFromStack.get(spillCandidate);
if (fromStack != null) {
spillSlot = (AllocatableValue) fromStack;
! cycleBreakingSlotsReused.increment();
! Debug.log("reuse slot for spilling: %s", spillSlot);
}
}
if (spillSlot == null) {
spillSlot = frameMapBuilder.allocateSpillSlot(from.getValueKind());
! cycleBreakingSlotsAllocated.increment();
! Debug.log("created new slot for spilling: %s", spillSlot);
// insert a move from register to stack and update the mapping
LIRInstruction move = insertMove(from, spillSlot);
move.setComment(res, "TraceGlobalMoveResolver: breakCycle");
}
block(spillSlot);
--- 413,437 ----
// (e.g. r1 . r2, r2 . r1), so one interval must be spilled to memory
assert spillCandidate != -1 : "no interval in register for spilling found";
// create a new spill interval and assign a stack slot to it
Value from = mappingFrom.get(spillCandidate);
! try (Indent indent = debug.logAndIndent("BreakCycle: %s", from)) {
AllocatableValue spillSlot = null;
if (TraceRegisterAllocationPhase.Options.TraceRAreuseStackSlotsForMoveResolutionCycleBreaking.getValue(options) && !isStackSlotValue(from)) {
// don't use the stack slot if from is already the stack slot
Value fromStack = mappingFromStack.get(spillCandidate);
if (fromStack != null) {
spillSlot = (AllocatableValue) fromStack;
! cycleBreakingSlotsReused.increment(debug);
! debug.log("reuse slot for spilling: %s", spillSlot);
}
}
if (spillSlot == null) {
spillSlot = frameMapBuilder.allocateSpillSlot(from.getValueKind());
! cycleBreakingSlotsAllocated.increment(debug);
! debug.log("created new slot for spilling: %s", spillSlot);
// insert a move from register to stack and update the mapping
LIRInstruction move = insertMove(from, spillSlot);
move.setComment(res, "TraceGlobalMoveResolver: breakCycle");
}
block(spillSlot);
*** 436,448 ****
}
}
@SuppressWarnings("try")
private void printMapping() {
! try (Indent indent = Debug.logAndIndent("Mapping")) {
for (int i = mappingFrom.size() - 1; i >= 0; i--) {
! Debug.log("move %s <- %s (%s)", mappingTo.get(i), mappingFrom.get(i), mappingFromStack.get(i));
}
}
}
public void setInsertPosition(ArrayList<LIRInstruction> insertList, int insertIdx) {
--- 440,452 ----
}
}
@SuppressWarnings("try")
private void printMapping() {
! try (Indent indent = debug.logAndIndent("Mapping")) {
for (int i = mappingFrom.size() - 1; i >= 0; i--) {
! debug.log("move %s <- %s (%s)", mappingTo.get(i), mappingFrom.get(i), mappingFromStack.get(i));
}
}
}
public void setInsertPosition(ArrayList<LIRInstruction> insertList, int insertIdx) {
*** 452,463 ****
this.insertIdx = insertIdx;
}
@Override
public void addMapping(Value from, AllocatableValue to, Value fromStack) {
! if (Debug.isLogEnabled()) {
! Debug.log("add move mapping from %s to %s", from, to);
}
assert !from.equals(to) : "from and to interval equal: " + from;
assert LIRKind.verifyMoveKinds(to.getValueKind(), from.getValueKind(), registerAllocationConfig) : String.format("Kind mismatch: %s vs. %s, from=%s, to=%s", from.getValueKind(),
to.getValueKind(), from, to);
--- 456,467 ----
this.insertIdx = insertIdx;
}
@Override
public void addMapping(Value from, AllocatableValue to, Value fromStack) {
! if (debug.isLogEnabled()) {
! debug.log("add move mapping from %s to %s", from, to);
}
assert !from.equals(to) : "from and to interval equal: " + from;
assert LIRKind.verifyMoveKinds(to.getValueKind(), from.getValueKind(), registerAllocationConfig) : String.format("Kind mismatch: %s vs. %s, from=%s, to=%s", from.getValueKind(),
to.getValueKind(), from, to);
src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/trace/TraceGlobalMoveResolver.java
Index
Unified diffs
Context diffs
Sdiffs
Patch
New
Old
Previous File
Next File