package org.graalvm.compiler.lir.alloc.lsra;
import static jdk.vm.ci.code.ValueUtil.asRegister;
import static jdk.vm.ci.code.ValueUtil.asStackSlot;
import static jdk.vm.ci.code.ValueUtil.isRegister;
import static jdk.vm.ci.code.ValueUtil.isStackSlot;
import static org.graalvm.compiler.lir.LIRValueUtil.asVariable;
import static org.graalvm.compiler.lir.LIRValueUtil.isVariable;
import static org.graalvm.compiler.lir.debug.LIRGenerationDebugContext.getSourceForOperandFromDebugContext;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.EnumSet;
import org.graalvm.compiler.core.common.LIRKind;
import org.graalvm.compiler.core.common.PermanentBailoutException;
import org.graalvm.compiler.core.common.alloc.ComputeBlockOrder;
import org.graalvm.compiler.core.common.cfg.AbstractBlockBase;
import org.graalvm.compiler.core.common.util.BitMap2D;
import org.graalvm.compiler.debug.Assertions;
import org.graalvm.compiler.debug.DebugContext;
import org.graalvm.compiler.debug.GraalError;
import org.graalvm.compiler.debug.Indent;
import org.graalvm.compiler.lir.InstructionValueConsumer;
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.LoadConstantOp;
import org.graalvm.compiler.lir.StandardOp.ValueMoveOp;
import org.graalvm.compiler.lir.ValueConsumer;
import org.graalvm.compiler.lir.alloc.lsra.Interval.RegisterPriority;
import org.graalvm.compiler.lir.alloc.lsra.Interval.SpillState;
import org.graalvm.compiler.lir.alloc.lsra.LinearScan.BlockData;
import org.graalvm.compiler.lir.gen.LIRGenerationResult;
import org.graalvm.compiler.lir.phases.AllocationPhase.AllocationContext;
import org.graalvm.util.EconomicSet;
import org.graalvm.util.Equivalence;
import jdk.vm.ci.code.Register;
import jdk.vm.ci.code.RegisterArray;
import jdk.vm.ci.code.StackSlot;
import jdk.vm.ci.code.TargetDescription;
import jdk.vm.ci.meta.AllocatableValue;
import jdk.vm.ci.meta.Constant;
import jdk.vm.ci.meta.JavaConstant;
import jdk.vm.ci.meta.Value;
import jdk.vm.ci.meta.ValueKind;
public class LinearScanLifetimeAnalysisPhase extends LinearScanAllocationPhase {
protected final LinearScan allocator;
protected final DebugContext debug;
protected LinearScanLifetimeAnalysisPhase(LinearScan linearScan) {
allocator = linearScan;
debug = allocator.getDebug();
}
@Override
protected void run(TargetDescription target, LIRGenerationResult lirGenRes, AllocationContext context) {
numberInstructions();
debug.dump(DebugContext.VERBOSE_LEVEL, lirGenRes.getLIR(), "Before register allocation");
computeLocalLiveSets();
computeGlobalLiveSets();
buildIntervals(Assertions.detailedAssertionsEnabled(allocator.getOptions()));
}
private BitMap2D intervalInLoop;
boolean isIntervalInLoop(int interval, int loop) {
return intervalInLoop.at(interval, loop);
}
protected void numberInstructions() {
allocator.initIntervals();
ValueConsumer setVariableConsumer = (value, mode, flags) -> {
if (isVariable(value)) {
allocator.getOrCreateInterval(asVariable(value));
}
};
int numInstructions = 0;
for (AbstractBlockBase<?> block : allocator.sortedBlocks()) {
numInstructions += allocator.getLIR().getLIRforBlock(block).size();
}
allocator.initOpIdMaps(numInstructions);
int opId = 0;
int index = 0;
for (AbstractBlockBase<?> block : allocator.sortedBlocks()) {
allocator.initBlockData(block);
ArrayList<LIRInstruction> instructions = allocator.getLIR().getLIRforBlock(block);
int numInst = instructions.size();
for (int j = 0; j < numInst; j++) {
LIRInstruction op = instructions.get(j);
op.setId(opId);
allocator.putOpIdMaps(index, op, block);
assert allocator.instructionForId(opId) == op : "must match";
op.visitEachTemp(setVariableConsumer);
op.visitEachOutput(setVariableConsumer);
index++;
opId += 2;
}
}
assert index == numInstructions : "must match";
assert (index << 1) == opId : "must match: " + (index << 1);
}
@SuppressWarnings("try")
void computeLocalLiveSets() {
int liveSize = allocator.liveSetSize();
intervalInLoop = new BitMap2D(allocator.operandSize(), allocator.numLoops());
try {
for (final AbstractBlockBase<?> block : allocator.sortedBlocks()) {
try (Indent indent = debug.logAndIndent("compute local live sets for block %s", block)) {
final BitSet liveGen = new BitSet(liveSize);
final BitSet liveKill = new BitSet(liveSize);
ArrayList<LIRInstruction> instructions = allocator.getLIR().getLIRforBlock(block);
int numInst = instructions.size();
ValueConsumer useConsumer = (operand, mode, flags) -> {
if (isVariable(operand)) {
int operandNum = allocator.operandNumber(operand);
if (!liveKill.get(operandNum)) {
liveGen.set(operandNum);
if (debug.isLogEnabled()) {
debug.log("liveGen for operand %d(%s)", operandNum, operand);
}
}
if (block.getLoop() != null) {
intervalInLoop.setBit(operandNum, block.getLoop().getIndex());
}
}
if (allocator.detailedAsserts) {
verifyInput(block, liveKill, operand);
}
};
ValueConsumer stateConsumer = (operand, mode, flags) -> {
if (LinearScan.isVariableOrRegister(operand)) {
int operandNum = allocator.operandNumber(operand);
if (!liveKill.get(operandNum)) {
liveGen.set(operandNum);
if (debug.isLogEnabled()) {
debug.log("liveGen in state for operand %d(%s)", operandNum, operand);
}
}
}
};
ValueConsumer defConsumer = (operand, mode, flags) -> {
if (isVariable(operand)) {
int varNum = allocator.operandNumber(operand);
liveKill.set(varNum);
if (debug.isLogEnabled()) {
debug.log("liveKill for operand %d(%s)", varNum, operand);
}
if (block.getLoop() != null) {
intervalInLoop.setBit(varNum, block.getLoop().getIndex());
}
}
if (allocator.detailedAsserts) {
verifyTemp(liveKill, operand);
}
};
for (int j = 0; j < numInst; j++) {
final LIRInstruction op = instructions.get(j);
try (Indent indent2 = debug.logAndIndent("handle op %d: %s", op.id(), op)) {
op.visitEachInput(useConsumer);
op.visitEachAlive(useConsumer);
op.visitEachState(stateConsumer);
op.visitEachTemp(defConsumer);
op.visitEachOutput(defConsumer);
}
}
BlockData blockSets = allocator.getBlockData(block);
blockSets.liveGen = liveGen;
blockSets.liveKill = liveKill;
blockSets.liveIn = new BitSet(liveSize);
blockSets.liveOut = new BitSet(liveSize);
if (debug.isLogEnabled()) {
debug.log("liveGen B%d %s", block.getId(), blockSets.liveGen);
debug.log("liveKill B%d %s", block.getId(), blockSets.liveKill);
}
}
}
} catch (OutOfMemoryError oom) {
throw new PermanentBailoutException(oom, "Out-of-memory during live set allocation of size %d", liveSize);
}
}
private void verifyTemp(BitSet liveKill, Value operand) {
if (isRegister(operand)) {
if (allocator.isProcessed(operand)) {
liveKill.set(allocator.operandNumber(operand));
}
}
}
private void verifyInput(AbstractBlockBase<?> block, BitSet liveKill, Value operand) {
if (isRegister(operand) && block != allocator.getLIR().getControlFlowGraph().getStartBlock()) {
if (allocator.isProcessed(operand)) {
assert liveKill.get(allocator.operandNumber(operand)) : "using fixed register " + asRegister(operand) + " that is not defined in this block " + block;
}
}
}
@SuppressWarnings("try")
protected void computeGlobalLiveSets() {
try (Indent indent = debug.logAndIndent("compute global live sets")) {
int numBlocks = allocator.blockCount();
boolean changeOccurred;
boolean changeOccurredInBlock;
int iterationCount = 0;
BitSet liveOut = new BitSet(allocator.liveSetSize());
do {
changeOccurred = false;
try (Indent indent2 = debug.logAndIndent("new iteration %d", iterationCount)) {
for (int i = numBlocks - 1; i >= 0; i--) {
AbstractBlockBase<?> block = allocator.blockAt(i);
BlockData blockSets = allocator.getBlockData(block);
changeOccurredInBlock = false;
int n = block.getSuccessorCount();
if (n > 0) {
liveOut.clear();
if (n > 0) {
for (AbstractBlockBase<?> successor : block.getSuccessors()) {
liveOut.or(allocator.getBlockData(successor).liveIn);
}
}
if (!blockSets.liveOut.equals(liveOut)) {
BitSet temp = blockSets.liveOut;
blockSets.liveOut = liveOut;
liveOut = temp;
changeOccurred = true;
changeOccurredInBlock = true;
}
}
if (iterationCount == 0 || changeOccurredInBlock) {
BitSet liveIn = blockSets.liveIn;
liveIn.clear();
liveIn.or(blockSets.liveOut);
liveIn.andNot(blockSets.liveKill);
liveIn.or(blockSets.liveGen);
if (debug.isLogEnabled()) {
debug.log("block %d: livein = %s, liveout = %s", block.getId(), liveIn, blockSets.liveOut);
}
}
}
iterationCount++;
if (changeOccurred && iterationCount > 50) {
throw new PermanentBailoutException("too many iterations in computeGlobalLiveSets");
}
}
} while (changeOccurred);
if (Assertions.detailedAssertionsEnabled(allocator.getOptions())) {
verifyLiveness();
}
AbstractBlockBase<?> startBlock = allocator.getLIR().getControlFlowGraph().getStartBlock();
if (allocator.getBlockData(startBlock).liveIn.cardinality() != 0) {
if (Assertions.detailedAssertionsEnabled(allocator.getOptions())) {
reportFailure(numBlocks);
}
throw new GraalError("liveIn set of first block must be empty: " + allocator.getBlockData(startBlock).liveIn);
}
}
}
@SuppressWarnings("try")
protected void reportFailure(int numBlocks) {
try (DebugContext.Scope s = debug.forceLog()) {
try (Indent indent = debug.logAndIndent("report failure")) {
BitSet startBlockLiveIn = allocator.getBlockData(allocator.getLIR().getControlFlowGraph().getStartBlock()).liveIn;
try (Indent indent2 = debug.logAndIndent("Error: liveIn set of first block must be empty (when this fails, variables are used before they are defined):")) {
for (int operandNum = startBlockLiveIn.nextSetBit(0); operandNum >= 0; operandNum = startBlockLiveIn.nextSetBit(operandNum + 1)) {
Interval interval = allocator.intervalFor(operandNum);
if (interval != null) {
Value operand = interval.operand;
debug.log("var %d; operand=%s; node=%s", operandNum, operand, getSourceForOperandFromDebugContext(debug, operand));
} else {
debug.log("var %d; missing operand", operandNum);
}
}
}
for (int operandNum = startBlockLiveIn.nextSetBit(0); operandNum >= 0; operandNum = startBlockLiveIn.nextSetBit(operandNum + 1)) {
Interval interval = allocator.intervalFor(operandNum);
Value operand = null;
Object valueForOperandFromDebugContext = null;
if (interval != null) {
operand = interval.operand;
valueForOperandFromDebugContext = getSourceForOperandFromDebugContext(debug, operand);
}
try (Indent indent2 = debug.logAndIndent("---- Detailed information for var %d; operand=%s; node=%s ----", operandNum, operand, valueForOperandFromDebugContext)) {
ArrayDeque<AbstractBlockBase<?>> definedIn = new ArrayDeque<>();
EconomicSet<AbstractBlockBase<?>> usedIn = EconomicSet.create(Equivalence.IDENTITY);
for (AbstractBlockBase<?> block : allocator.sortedBlocks()) {
if (allocator.getBlockData(block).liveGen.get(operandNum)) {
usedIn.add(block);
try (Indent indent3 = debug.logAndIndent("used in block B%d", block.getId())) {
for (LIRInstruction ins : allocator.getLIR().getLIRforBlock(block)) {
try (Indent indent4 = debug.logAndIndent("%d: %s", ins.id(), ins)) {
ins.forEachState((liveStateOperand, mode, flags) -> {
debug.log("operand=%s", liveStateOperand);
return liveStateOperand;
});
}
}
}
}
if (allocator.getBlockData(block).liveKill.get(operandNum)) {
definedIn.add(block);
try (Indent indent3 = debug.logAndIndent("defined in block B%d", block.getId())) {
for (LIRInstruction ins : allocator.getLIR().getLIRforBlock(block)) {
debug.log("%d: %s", ins.id(), ins);
}
}
}
}
int[] hitCount = new int[numBlocks];
while (!definedIn.isEmpty()) {
AbstractBlockBase<?> block = definedIn.removeFirst();
usedIn.remove(block);
for (AbstractBlockBase<?> successor : block.getSuccessors()) {
if (successor.isLoopHeader()) {
if (!block.isLoopEnd()) {
definedIn.add(successor);
}
} else {
if (++hitCount[successor.getId()] == successor.getPredecessorCount()) {
definedIn.add(successor);
}
}
}
}
try (Indent indent3 = debug.logAndIndent("**** offending usages are in: ")) {
for (AbstractBlockBase<?> block : usedIn) {
debug.log("B%d", block.getId());
}
}
}
}
}
} catch (Throwable e) {
throw debug.handle(e);
}
}
protected void verifyLiveness() {
for (AbstractBlockBase<?> block : allocator.sortedBlocks()) {
for (int j = 0; j <= allocator.maxRegisterNumber(); j++) {
assert !allocator.getBlockData(block).liveIn.get(j) : "liveIn set of fixed register must be empty";
assert !allocator.getBlockData(block).liveOut.get(j) : "liveOut set of fixed register must be empty";
assert !allocator.getBlockData(block).liveGen.get(j) : "liveGen set of fixed register must be empty";
}
}
}
protected void addUse(AllocatableValue operand, int from, int to, RegisterPriority registerPriority, ValueKind<?> kind, boolean detailedAsserts) {
if (!allocator.isProcessed(operand)) {
return;
}
Interval interval = allocator.getOrCreateInterval(operand);
if (!kind.equals(LIRKind.Illegal)) {
interval.setKind(kind);
}
interval.addRange(from, to);
interval.addUsePos(to & ~1, registerPriority, detailedAsserts);
if (debug.isLogEnabled()) {
debug.log("add use: %s, from %d to %d (%s)", interval, from, to, registerPriority.name());
}
}
protected void addTemp(AllocatableValue operand, int tempPos, RegisterPriority registerPriority, ValueKind<?> kind, boolean detailedAsserts) {
if (!allocator.isProcessed(operand)) {
return;
}
Interval interval = allocator.getOrCreateInterval(operand);
if (!kind.equals(LIRKind.Illegal)) {
interval.setKind(kind);
}
interval.addRange(tempPos, tempPos + 1);
interval.addUsePos(tempPos, registerPriority, detailedAsserts);
interval.addMaterializationValue(null);
if (debug.isLogEnabled()) {
debug.log("add temp: %s tempPos %d (%s)", interval, tempPos, RegisterPriority.MustHaveRegister.name());
}
}
protected void addDef(AllocatableValue operand, LIRInstruction op, RegisterPriority registerPriority, ValueKind<?> kind, boolean detailedAsserts) {
if (!allocator.isProcessed(operand)) {
return;
}
int defPos = op.id();
Interval interval = allocator.getOrCreateInterval(operand);
if (!kind.equals(LIRKind.Illegal)) {
interval.setKind(kind);
}
Range r = interval.first();
if (r.from <= defPos) {
r.from = defPos;
interval.addUsePos(defPos, registerPriority, detailedAsserts);
} else {
interval.addRange(defPos, defPos + 1);
interval.addUsePos(defPos, registerPriority, detailedAsserts);
if (debug.isLogEnabled()) {
debug.log("Warning: def of operand %s at %d occurs without use", operand, defPos);
}
}
changeSpillDefinitionPos(op, operand, interval, defPos);
if (registerPriority == RegisterPriority.None && interval.spillState().ordinal() <= SpillState.StartInMemory.ordinal() && isStackSlot(operand)) {
interval.setSpillState(SpillState.StartInMemory);
}
interval.addMaterializationValue(getMaterializedValue(op, operand, interval));
if (debug.isLogEnabled()) {
debug.log("add def: %s defPos %d (%s)", interval, defPos, registerPriority.name());
}
}
protected void handleMethodArguments(LIRInstruction op) {
if (ValueMoveOp.isValueMoveOp(op)) {
ValueMoveOp move = ValueMoveOp.asValueMoveOp(op);
if (optimizeMethodArgument(move.getInput())) {
StackSlot slot = asStackSlot(move.getInput());
if (Assertions.detailedAssertionsEnabled(allocator.getOptions())) {
assert op.id() > 0 : "invalid id";
assert allocator.blockForId(op.id()).getPredecessorCount() == 0 : "move from stack must be in first block";
assert isVariable(move.getResult()) : "result of move must be a variable";
if (debug.isLogEnabled()) {
debug.log("found move from stack slot %s to %s", slot, move.getResult());
}
}
Interval interval = allocator.intervalFor(move.getResult());
interval.setSpillSlot(slot);
interval.assignLocation(slot);
}
}
}
protected void addRegisterHint(final LIRInstruction op, final Value targetValue, OperandMode mode, EnumSet<OperandFlag> flags, final boolean hintAtDef) {
if (flags.contains(OperandFlag.HINT) && LinearScan.isVariableOrRegister(targetValue)) {
op.forEachRegisterHint(targetValue, mode, (registerHint, valueMode, valueFlags) -> {
if (LinearScan.isVariableOrRegister(registerHint)) {
Interval from = allocator.getOrCreateInterval((AllocatableValue) registerHint);
Interval to = allocator.getOrCreateInterval((AllocatableValue) targetValue);
if (hintAtDef) {
to.setLocationHint(from);
} else {
from.setLocationHint(to);
}
if (debug.isLogEnabled()) {
debug.log("operation at opId %d: added hint from interval %d to %d", op.id(), from.operandNumber, to.operandNumber);
}
return registerHint;
}
return null;
});
}
}
protected void changeSpillDefinitionPos(LIRInstruction op, AllocatableValue operand, Interval interval, int defPos) {
assert interval.isSplitParent() : "can only be called for split parents";
switch (interval.spillState()) {
case NoDefinitionFound:
assert interval.spillDefinitionPos() == -1 : "must no be set before";
interval.setSpillDefinitionPos(defPos);
interval.setSpillState(SpillState.NoSpillStore);
break;
case NoSpillStore:
assert defPos <= interval.spillDefinitionPos() : "positions are processed in reverse order when intervals are created";
if (defPos < interval.spillDefinitionPos() - 2) {
interval.setSpillState(SpillState.NoOptimization);
} else {
assert allocator.blockForId(defPos) == allocator.blockForId(interval.spillDefinitionPos()) : "block must be equal";
}
break;
case NoOptimization:
break;
default:
throw GraalError.shouldNotReachHere("other states not allowed at this time");
}
}
private static boolean optimizeMethodArgument(Value value) {
return isStackSlot(value) && asStackSlot(value).isInCallerFrame() && LIRKind.isValue(value);
}
protected RegisterPriority registerPriorityOfOutputOperand(LIRInstruction op) {
if (ValueMoveOp.isValueMoveOp(op)) {
ValueMoveOp move = ValueMoveOp.asValueMoveOp(op);
if (optimizeMethodArgument(move.getInput())) {
return RegisterPriority.None;
}
}
return RegisterPriority.MustHaveRegister;
}
protected static RegisterPriority registerPriorityOfInputOperand(EnumSet<OperandFlag> flags) {
if (flags.contains(OperandFlag.STACK)) {
return RegisterPriority.ShouldHaveRegister;
}
return RegisterPriority.MustHaveRegister;
}
@SuppressWarnings("try")
protected void buildIntervals(boolean detailedAsserts) {
try (Indent indent = debug.logAndIndent("build intervals")) {
InstructionValueConsumer outputConsumer = (op, operand, mode, flags) -> {
if (LinearScan.isVariableOrRegister(operand)) {
addDef((AllocatableValue) operand, op, registerPriorityOfOutputOperand(op), operand.getValueKind(), detailedAsserts);
addRegisterHint(op, operand, mode, flags, true);
}
};
InstructionValueConsumer tempConsumer = (op, operand, mode, flags) -> {
if (LinearScan.isVariableOrRegister(operand)) {
addTemp((AllocatableValue) operand, op.id(), RegisterPriority.MustHaveRegister, operand.getValueKind(), detailedAsserts);
addRegisterHint(op, operand, mode, flags, false);
}
};
InstructionValueConsumer aliveConsumer = (op, operand, mode, flags) -> {
if (LinearScan.isVariableOrRegister(operand)) {
RegisterPriority p = registerPriorityOfInputOperand(flags);
int opId = op.id();
int blockFrom = allocator.getFirstLirInstructionId((allocator.blockForId(opId)));
addUse((AllocatableValue) operand, blockFrom, opId + 1, p, operand.getValueKind(), detailedAsserts);
addRegisterHint(op, operand, mode, flags, false);
}
};
InstructionValueConsumer inputConsumer = (op, operand, mode, flags) -> {
if (LinearScan.isVariableOrRegister(operand)) {
int opId = op.id();
int blockFrom = allocator.getFirstLirInstructionId((allocator.blockForId(opId)));
RegisterPriority p = registerPriorityOfInputOperand(flags);
addUse((AllocatableValue) operand, blockFrom, opId, p, operand.getValueKind(), detailedAsserts);
addRegisterHint(op, operand, mode, flags, false);
}
};
InstructionValueConsumer stateProc = (op, operand, mode, flags) -> {
if (LinearScan.isVariableOrRegister(operand)) {
int opId = op.id();
int blockFrom = allocator.getFirstLirInstructionId((allocator.blockForId(opId)));
addUse((AllocatableValue) operand, blockFrom, opId + 1, RegisterPriority.None, operand.getValueKind(), detailedAsserts);
}
};
RegisterArray callerSaveRegs = allocator.getRegisterAllocationConfig().getRegisterConfig().getCallerSaveRegisters();
for (int i = allocator.blockCount() - 1; i >= 0; i--) {
AbstractBlockBase<?> block = allocator.blockAt(i);
try (Indent indent2 = debug.logAndIndent("handle block %d", block.getId())) {
ArrayList<LIRInstruction> instructions = allocator.getLIR().getLIRforBlock(block);
final int blockFrom = allocator.getFirstLirInstructionId(block);
int blockTo = allocator.getLastLirInstructionId(block);
assert blockFrom == instructions.get(0).id();
assert blockTo == instructions.get(instructions.size() - 1).id();
BitSet live = allocator.getBlockData(block).liveOut;
for (int operandNum = live.nextSetBit(0); operandNum >= 0; operandNum = live.nextSetBit(operandNum + 1)) {
assert live.get(operandNum) : "should not stop here otherwise";
AllocatableValue operand = allocator.intervalFor(operandNum).operand;
if (debug.isLogEnabled()) {
debug.log("live in %d: %s", operandNum, operand);
}
addUse(operand, blockFrom, blockTo + 2, RegisterPriority.None, LIRKind.Illegal, detailedAsserts);
if (block.isLoopEnd() && block.getLoop() != null && isIntervalInLoop(operandNum, block.getLoop().getIndex())) {
allocator.intervalFor(operandNum).addUsePos(blockTo + 1, RegisterPriority.LiveAtLoopEnd, detailedAsserts);
}
}
for (int j = instructions.size() - 1; j >= 0; j--) {
final LIRInstruction op = instructions.get(j);
final int opId = op.id();
try (Indent indent3 = debug.logAndIndent("handle inst %d: %s", opId, op)) {
if (op.destroysCallerSavedRegisters()) {
for (Register r : callerSaveRegs) {
if (allocator.attributes(r).isAllocatable()) {
addTemp(r.asValue(), opId, RegisterPriority.None, LIRKind.Illegal, detailedAsserts);
}
}
if (debug.isLogEnabled()) {
debug.log("operation destroys all caller-save registers");
}
}
op.visitEachOutput(outputConsumer);
op.visitEachTemp(tempConsumer);
op.visitEachAlive(aliveConsumer);
op.visitEachInput(inputConsumer);
op.visitEachState(stateProc);
handleMethodArguments(op);
}
}
}
}
for (Interval interval : allocator.intervals()) {
if (interval != null && isRegister(interval.operand)) {
interval.addRange(0, 1);
}
}
}
}
protected Constant getMaterializedValue(LIRInstruction op, Value operand, Interval interval) {
if (LoadConstantOp.isLoadConstantOp(op)) {
LoadConstantOp move = LoadConstantOp.asLoadConstantOp(op);
if (!allocator.neverSpillConstants()) {
Interval.UsePosList usePosList = interval.usePosList();
int numUsePos = usePosList.size();
for (int useIdx = 0; useIdx < numUsePos; useIdx++) {
Interval.RegisterPriority priority = usePosList.registerPriority(useIdx);
if (priority == Interval.RegisterPriority.ShouldHaveRegister) {
return null;
}
}
}
return move.getConstant();
}
return null;
}
}