use of org.graalvm.compiler.asm.Assembler.InstructionCounter 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);
}
}
Aggregations