use of org.graalvm.compiler.lir.LIRInstruction in project graal by oracle.
the class HotSpotBackend method gatherDestroyedCallerRegisters.
/**
* Finds all the registers that are defined by some given LIR.
*
* @param lir the LIR to examine
* @return the registers that are defined by or used as temps for any instruction in {@code lir}
*/
protected final EconomicSet<Register> gatherDestroyedCallerRegisters(LIR lir) {
final EconomicSet<Register> destroyedRegisters = EconomicSet.create(Equivalence.IDENTITY);
ValueConsumer defConsumer = new ValueConsumer() {
@Override
public void visitValue(Value value, OperandMode mode, EnumSet<OperandFlag> flags) {
if (ValueUtil.isRegister(value)) {
final Register reg = ValueUtil.asRegister(value);
destroyedRegisters.add(reg);
}
}
};
for (AbstractBlockBase<?> block : lir.codeEmittingOrder()) {
if (block == null) {
continue;
}
for (LIRInstruction op : lir.getLIRforBlock(block)) {
if (op instanceof LabelOp) {
// Don't consider this as a definition
} else {
op.visitEachTemp(defConsumer);
op.visitEachOutput(defConsumer);
}
}
}
return translateToCallerRegisters(destroyedRegisters);
}
use of org.graalvm.compiler.lir.LIRInstruction in project graal by oracle.
the class HotSpotInstructionProfiling method countInstructions.
/**
* After assembly the {@link HotSpotBackend#profileInstructions(LIR, CompilationResultBuilder)}
* calls this method for patching the instruction counts into the counter increment code.
*/
public static void countInstructions(LIR lir, Assembler asm) {
InstructionCounterOp lastOp = null;
InstructionCounter counter = asm.getInstructionCounter();
for (AbstractBlockBase<?> block : lir.codeEmittingOrder()) {
if (block == null) {
continue;
}
for (LIRInstruction inst : lir.getLIRforBlock(block)) {
if (inst instanceof InstructionCounterOp) {
InstructionCounterOp currentOp = (InstructionCounterOp) inst;
if (lastOp != null) {
int beginPc = lastOp.countOffsetEnd;
int endPc = currentOp.countOffsetBegin;
int[] instructionCounts = counter.countInstructions(lastOp.instructionsToProfile, beginPc, endPc);
lastOp.delegate.patchCounterIncrement(asm, instructionCounts);
}
lastOp = ((InstructionCounterOp) inst);
}
}
}
if (lastOp != null) {
assert lastOp.countOffsetBegin < asm.position();
int beginPc = lastOp.countOffsetBegin;
int endPc = asm.position();
int[] instructionCounts = counter.countInstructions(lastOp.instructionsToProfile, beginPc, endPc);
lastOp.delegate.patchCounterIncrement(asm, instructionCounts);
}
}
use of org.graalvm.compiler.lir.LIRInstruction in project graal by oracle.
the class HotSpotZapRegistersPhase method processBlock.
@SuppressWarnings("try")
private static void processBlock(DiagnosticLIRGeneratorTool diagnosticLirGenTool, HotSpotLIRGenerationResult res, LIR lir, LIRInsertionBuffer buffer, AbstractBlockBase<?> block, boolean zapRegisters, boolean zapStack) {
DebugContext debug = lir.getDebug();
try (Indent indent = debug.logAndIndent("Process block %s", block)) {
ArrayList<LIRInstruction> instructions = lir.getLIRforBlock(block);
buffer.init(instructions);
for (int index = 0; index < instructions.size(); index++) {
LIRInstruction inst = instructions.get(index);
if (zapStack && inst instanceof ZapStackArgumentSpaceBeforeInstruction) {
LIRInstruction zap = diagnosticLirGenTool.zapArgumentSpace();
if (zap != null) {
buffer.append(index, zap);
}
}
if (zapRegisters && inst instanceof ZapRegistersAfterInstruction) {
LIRFrameState state = getLIRState(inst);
if (state != null) {
SaveRegistersOp zap = diagnosticLirGenTool.createZapRegisters();
SaveRegistersOp old = res.getCalleeSaveInfo().put(state, zap);
assert old == null : "Already another SaveRegisterOp registered! " + old;
buffer.append(index + 1, (LIRInstruction) zap);
debug.log("Insert ZapRegister after %s", inst);
}
}
}
buffer.finish();
}
}
use of org.graalvm.compiler.lir.LIRInstruction in project graal by oracle.
the class CompositeValueReplacementTest1 method replaceCompValueTest0.
@Test
public void replaceCompValueTest0() {
DummyValue dummyValue1 = new DummyValue();
DummyValue dummyValue2 = new DummyValue();
DummyValue dummyValue3 = new DummyValue();
TestCompositeValue compValue1 = new TestCompositeValue(dummyValue1);
LIRInstruction op1 = new TestOp(compValue1);
LIRInstruction op2 = new TestOp(compValue1);
op1.forEachInput((instruction, value, mode, flags) -> {
assertEquals(dummyValue1, value);
return dummyValue2;
});
op2.forEachInput((instruction, value, mode, flags) -> {
assertEquals(dummyValue1, value);
return dummyValue3;
});
op1.visitEachInput((instruction, value, mode, flags) -> assertEquals(dummyValue2, value));
op2.visitEachInput((instruction, value, mode, flags) -> assertEquals(dummyValue3, value));
}
use of org.graalvm.compiler.lir.LIRInstruction in project graal by oracle.
the class MoveResolver method insertMove.
private LIRInstruction insertMove(Interval fromInterval, Interval toInterval) {
assert !fromInterval.operand.equals(toInterval.operand) : "from and to interval equal: " + fromInterval;
assert LIRKind.verifyMoveKinds(toInterval.kind(), fromInterval.kind(), allocator.getRegisterAllocationConfig()) : "move between different types";
assert insertIdx != -1 : "must setup insert position first";
LIRInstruction move = createMove(fromInterval.operand, toInterval.operand, fromInterval.location(), toInterval.location());
insertionBuffer.append(insertIdx, move);
DebugContext debug = allocator.getDebug();
if (debug.isLogEnabled()) {
debug.log("insert move from %s to %s at %d", fromInterval, toInterval, insertIdx);
}
return move;
}
Aggregations