src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/trace/lsra/TraceLinearScanAssignLocationsPhase.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/lsra/TraceLinearScanAssignLocationsPhase.java
src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/trace/lsra/TraceLinearScanAssignLocationsPhase.java
Print this page
*** 20,40 ****
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package org.graalvm.compiler.lir.alloc.trace.lsra;
import static org.graalvm.compiler.lir.LIRValueUtil.isConstantValue;
import static org.graalvm.compiler.lir.LIRValueUtil.isStackSlotValue;
import static org.graalvm.compiler.lir.LIRValueUtil.isVariable;
import static org.graalvm.compiler.lir.LIRValueUtil.isVirtualStackSlot;
- import static org.graalvm.compiler.lir.alloc.trace.TraceRegisterAllocationPhase.Options.TraceRAshareSpillInformation;
- import static jdk.vm.ci.code.ValueUtil.isIllegal;
- import static jdk.vm.ci.code.ValueUtil.isRegister;
import java.util.Collections;
import java.util.EnumSet;
- import java.util.List;
import org.graalvm.compiler.core.common.alloc.Trace;
import org.graalvm.compiler.core.common.cfg.AbstractBlockBase;
import org.graalvm.compiler.debug.Debug;
import org.graalvm.compiler.debug.GraalError;
--- 20,39 ----
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package org.graalvm.compiler.lir.alloc.trace.lsra;
+ import static jdk.vm.ci.code.ValueUtil.isIllegal;
+ import static jdk.vm.ci.code.ValueUtil.isRegister;
import static org.graalvm.compiler.lir.LIRValueUtil.isConstantValue;
import static org.graalvm.compiler.lir.LIRValueUtil.isStackSlotValue;
import static org.graalvm.compiler.lir.LIRValueUtil.isVariable;
import static org.graalvm.compiler.lir.LIRValueUtil.isVirtualStackSlot;
+ import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumSet;
import org.graalvm.compiler.core.common.alloc.Trace;
import org.graalvm.compiler.core.common.cfg.AbstractBlockBase;
import org.graalvm.compiler.debug.Debug;
import org.graalvm.compiler.debug.GraalError;
*** 44,58 ****
import org.graalvm.compiler.lir.LIRFrameState;
import org.graalvm.compiler.lir.LIRInstruction;
import org.graalvm.compiler.lir.LIRInstruction.OperandFlag;
import org.graalvm.compiler.lir.LIRInstruction.OperandMode;
import org.graalvm.compiler.lir.StandardOp;
- import org.graalvm.compiler.lir.StandardOp.BlockEndOp;
import org.graalvm.compiler.lir.StandardOp.LabelOp;
import org.graalvm.compiler.lir.StandardOp.MoveOp;
import org.graalvm.compiler.lir.StandardOp.ValueMoveOp;
import org.graalvm.compiler.lir.Variable;
import org.graalvm.compiler.lir.alloc.trace.ShadowedRegisterValue;
import org.graalvm.compiler.lir.alloc.trace.lsra.TraceLinearScanPhase.TraceLinearScan;
import org.graalvm.compiler.lir.gen.LIRGenerationResult;
import org.graalvm.compiler.lir.gen.LIRGeneratorTool.MoveFactory;
--- 43,57 ----
import org.graalvm.compiler.lir.LIRFrameState;
import org.graalvm.compiler.lir.LIRInstruction;
import org.graalvm.compiler.lir.LIRInstruction.OperandFlag;
import org.graalvm.compiler.lir.LIRInstruction.OperandMode;
import org.graalvm.compiler.lir.StandardOp;
import org.graalvm.compiler.lir.StandardOp.LabelOp;
import org.graalvm.compiler.lir.StandardOp.MoveOp;
import org.graalvm.compiler.lir.StandardOp.ValueMoveOp;
import org.graalvm.compiler.lir.Variable;
+ import org.graalvm.compiler.lir.alloc.trace.GlobalLivenessInfo;
import org.graalvm.compiler.lir.alloc.trace.ShadowedRegisterValue;
import org.graalvm.compiler.lir.alloc.trace.lsra.TraceLinearScanPhase.TraceLinearScan;
import org.graalvm.compiler.lir.gen.LIRGenerationResult;
import org.graalvm.compiler.lir.gen.LIRGeneratorTool.MoveFactory;
*** 71,81 ****
@Override
protected void run(TargetDescription target, LIRGenerationResult lirGenRes, Trace trace, TraceLinearScanAllocationContext context) {
TraceLinearScan allocator = context.allocator;
MoveFactory spillMoveFactory = context.spillMoveFactory;
! new Assigner(allocator, spillMoveFactory).assignLocations();
}
private static final class Assigner {
private final TraceLinearScan allocator;
private final MoveFactory spillMoveFactory;
--- 70,80 ----
@Override
protected void run(TargetDescription target, LIRGenerationResult lirGenRes, Trace trace, TraceLinearScanAllocationContext context) {
TraceLinearScan allocator = context.allocator;
MoveFactory spillMoveFactory = context.spillMoveFactory;
! new Assigner(allocator, spillMoveFactory).assign();
}
private static final class Assigner {
private final TraceLinearScan allocator;
private final MoveFactory spillMoveFactory;
*** 104,113 ****
--- 103,116 ----
* the right interval here.
*/
interval = allocator.splitChildAtOpId(interval, opId, mode);
}
+ return getLocation(op, interval, mode);
+ }
+
+ private static Value getLocation(LIRInstruction op, TraceInterval interval, OperandMode mode) {
if (isIllegal(interval.location()) && interval.canMaterialize()) {
if (op instanceof LabelOp) {
/*
* Spilled materialized value in a LabelOp (i.e. incoming): no need for move
* resolution so we can ignore it.
*** 161,171 ****
private void computeDebugInfo(final LIRInstruction op, LIRFrameState info) {
info.forEachState(op, this::debugInfoProcedure);
}
! private void assignLocations(List<LIRInstruction> instructions) {
int numInst = instructions.size();
boolean hasDead = false;
for (int j = 0; j < numInst; j++) {
final LIRInstruction op = instructions.get(j);
--- 164,178 ----
private void computeDebugInfo(final LIRInstruction op, LIRFrameState info) {
info.forEachState(op, this::debugInfoProcedure);
}
! @SuppressWarnings("try")
! private void assignBlock(AbstractBlockBase<?> block) {
! try (Indent indent2 = Debug.logAndIndent("assign locations in block B%d", block.getId())) {
! ArrayList<LIRInstruction> instructions = allocator.getLIR().getLIRforBlock(block);
! handleBlockBegin(block, instructions);
int numInst = instructions.size();
boolean hasDead = false;
for (int j = 0; j < numInst; j++) {
final LIRInstruction op = instructions.get(j);
*** 176,191 ****
--- 183,255 ----
hasDead = true;
} else if (assignLocations(op, instructions, j)) {
hasDead = true;
}
}
+ handleBlockEnd(block, instructions);
if (hasDead) {
// Remove null values from the list.
instructions.removeAll(Collections.singleton(null));
}
}
+ }
+
+ private void handleBlockBegin(AbstractBlockBase<?> block, ArrayList<LIRInstruction> instructions) {
+ if (allocator.hasInterTracePredecessor(block)) {
+ /* Only materialize the locations array if there is an incoming inter-trace edge. */
+ assert instructions.equals(allocator.getLIR().getLIRforBlock(block));
+ GlobalLivenessInfo li = allocator.getGlobalLivenessInfo();
+ LIRInstruction instruction = instructions.get(0);
+ OperandMode mode = OperandMode.DEF;
+ int[] live = li.getBlockIn(block);
+ Value[] values = calculateBlockBoundaryValues(instruction, live, mode);
+ li.setInLocations(block, values);
+ }
+ }
+
+ private void handleBlockEnd(AbstractBlockBase<?> block, ArrayList<LIRInstruction> instructions) {
+ if (allocator.hasInterTraceSuccessor(block)) {
+ /* Only materialize the locations array if there is an outgoing inter-trace edge. */
+ assert instructions.equals(allocator.getLIR().getLIRforBlock(block));
+ GlobalLivenessInfo li = allocator.getGlobalLivenessInfo();
+ LIRInstruction instruction = instructions.get(instructions.size() - 1);
+ OperandMode mode = OperandMode.USE;
+ int[] live = li.getBlockOut(block);
+ Value[] values = calculateBlockBoundaryValues(instruction, live, mode);
+ li.setOutLocations(block, values);
+ }
+ }
+
+ private Value[] calculateBlockBoundaryValues(LIRInstruction instruction, int[] live, OperandMode mode) {
+ Value[] values = new Value[live.length];
+ for (int i = 0; i < live.length; i++) {
+ TraceInterval interval = allocator.intervalFor(live[i]);
+ Value val = valueAtBlockBoundary(instruction, interval, mode);
+ values[i] = val;
+ }
+ return values;
+ }
+
+ private static Value valueAtBlockBoundary(LIRInstruction instruction, TraceInterval interval, OperandMode mode) {
+ if (mode == OperandMode.DEF && interval == null) {
+ // not needed in this trace
+ return Value.ILLEGAL;
+ }
+ assert interval != null : "interval must exist";
+ TraceInterval splitInterval = interval.getSplitChildAtOpIdOrNull(instruction.id(), mode);
+ if (splitInterval == null) {
+ assert mode == OperandMode.DEF : String.format("Not split child at %d for interval %s", instruction.id(), interval);
+ // not needed in this branch
+ return Value.ILLEGAL;
+ }
+
+ if (splitInterval.inMemoryAt(instruction.id()) && isRegister(splitInterval.location())) {
+ return new ShadowedRegisterValue((RegisterValue) splitInterval.location(), splitInterval.spillSlot());
+ }
+ return getLocation(instruction, splitInterval, mode);
+ }
private final InstructionValueProcedure assignProc = new InstructionValueProcedure() {
@Override
public Value doValue(LIRInstruction instruction, Value value, OperandMode mode, EnumSet<OperandFlag> flags) {
if (isVariable(value)) {
*** 201,219 ****
* @param op The {@link LIRInstruction} that should be colored.
* @param j The index of {@code op} in the {@code instructions} list.
* @param instructions The instructions of the current block.
* @return {@code true} if the instruction was deleted.
*/
! private boolean assignLocations(LIRInstruction op, List<LIRInstruction> instructions, int j) {
assert op != null && instructions.get(j) == op;
- if (TraceRAshareSpillInformation.getValue()) {
- if (op instanceof BlockEndOp) {
- ((BlockEndOp) op).forEachOutgoingValue(colorOutgoingIncomingValues);
- } else if (op instanceof LabelOp) {
- ((LabelOp) op).forEachIncomingValue(colorOutgoingIncomingValues);
- }
- }
// remove useless moves
if (op instanceof MoveOp) {
AllocatableValue result = ((MoveOp) op).getResult();
if (isVariable(result) && allocator.isMaterialized(result, op.id(), OperandMode.DEF)) {
--- 265,276 ----
* @param op The {@link LIRInstruction} that should be colored.
* @param j The index of {@code op} in the {@code instructions} list.
* @param instructions The instructions of the current block.
* @return {@code true} if the instruction was deleted.
*/
! private boolean assignLocations(LIRInstruction op, ArrayList<LIRInstruction> instructions, int j) {
assert op != null && instructions.get(j) == op;
// remove useless moves
if (op instanceof MoveOp) {
AllocatableValue result = ((MoveOp) op).getResult();
if (isVariable(result) && allocator.isMaterialized(result, op.id(), OperandMode.DEF)) {
*** 243,282 ****
return true;
}
if (isStackSlotValue(move.getInput()) && isStackSlotValue(move.getResult())) {
// rewrite stack to stack moves
instructions.set(j, spillMoveFactory.createStackMove(move.getResult(), move.getInput()));
- return true;
}
}
return false;
}
@SuppressWarnings("try")
! private void assignLocations() {
try (Indent indent = Debug.logAndIndent("assign locations")) {
for (AbstractBlockBase<?> block : allocator.sortedBlocks()) {
! try (Indent indent2 = Debug.logAndIndent("assign locations in block B%d", block.getId())) {
! assignLocations(allocator.getLIR().getLIRforBlock(block));
! }
! }
}
}
-
- private final InstructionValueProcedure colorOutgoingIncomingValues = new InstructionValueProcedure() {
-
- @Override
- public Value doValue(LIRInstruction instruction, Value value, OperandMode mode, EnumSet<OperandFlag> flags) {
- if (isVariable(value)) {
- TraceInterval interval = allocator.intervalFor(value);
- assert interval != null : "interval must exist";
- interval = allocator.splitChildAtOpId(interval, instruction.id(), mode);
-
- if (interval.inMemoryAt(instruction.id()) && isRegister(interval.location())) {
- return new ShadowedRegisterValue((RegisterValue) interval.location(), interval.spillSlot());
- }
}
- return value;
- }
- };
}
}
--- 300,319 ----
return true;
}
if (isStackSlotValue(move.getInput()) && isStackSlotValue(move.getResult())) {
// rewrite stack to stack moves
instructions.set(j, spillMoveFactory.createStackMove(move.getResult(), move.getInput()));
}
}
return false;
}
@SuppressWarnings("try")
! private void assign() {
try (Indent indent = Debug.logAndIndent("assign locations")) {
for (AbstractBlockBase<?> block : allocator.sortedBlocks()) {
! assignBlock(block);
}
}
}
}
}
src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/trace/lsra/TraceLinearScanAssignLocationsPhase.java
Index
Unified diffs
Context diffs
Sdiffs
Patch
New
Old
Previous File
Next File