L2Instruction

class L2Instruction(    basicBlock: L2BasicBlock?,     val operation: L2Operation,     theOperands: L2Operand) : L2AbstractInstruction

L2Instruction is the foundation for all instructions understood by the level two Avail interpreter. These instructions are model objects generated and manipulated by the L2Generator.

It used to be the case that the instructions were flattened into a stream of integers, operation followed by operands. That is no longer the case, as of 2013-05-01 MvG. Instead, the L2Instructions themselves are kept around for reoptimization and JVM code generation.

Author

Mark van Gulik

Todd L Smith

Parameters

basicBlock

The L2BasicBlock which will contain this instruction or null if none.

operation

The L2Operation that this instruction performs.

theOperands

The array of L2Operands on which this instruction operates. These must agree with the operation's array of L2NamedOperandTypes.

Constructors

Link copied to clipboard
fun L2Instruction(    generator: L2Generator,     operation: L2Operation,     vararg theOperands: L2Operand)

Construct a new L2Instruction. The instruction will be added somewhere within the given L2Generator's current L2BasicBlock.

Link copied to clipboard
fun L2Instruction(    basicBlock: L2BasicBlock?,     operation: L2Operation,     vararg theOperands: L2Operand)

Construct a new L2Instruction.

Functions

Link copied to clipboard
fun appendToWithWarnings(    builder: StringBuilder,     operandTypes: Set<L2OperandType>,     warningStyleChange: (Boolean) -> Unit)

Output this instruction to the given builder, invoking the given lambda with a boolean to turn warning style on or off, if tracked by the caller.

Link copied to clipboard
fun assertHasBeenEmitted()

Check that this instruction's basicBlock has been set, and that each operand's instruction field has also been set.

Link copied to clipboard
fun basicBlock(): L2BasicBlock

Answer the L2BasicBlock to which this instruction belongs.

Link copied to clipboard
fun edgesAndPurposesDo(consumer: (L2PcOperand, L2NamedOperandType.Purpose?) -> Unit)

Evaluate the given function with each edge and its corresponding L2NamedOperandType.Purpose. An L2WriteOperand is only considered to take place if its L2NamedOperandType.Purpose is null, or if it is the same as the edge that is taken by this L2Instruction.

Link copied to clipboard
fun justAdded(manifest: L2ValueManifest)

This instruction was just added to its L2BasicBlock.

Link copied to clipboard
fun justInserted()

This instruction was just added to its L2BasicBlock as part of an optimization pass.

Link copied to clipboard
fun justRemoved()

This instruction was just removed from its L2BasicBlock's list of instructions, and needs to finish its removal by breaking back-pointers, plus whatever else specific operands need to do when they're no longer considered part of the code.

Link copied to clipboard
fun <O : L2Operand> operand(index: Int): O

Answer the Nth L2Operand to supply to the operation.

Link copied to clipboard
fun operandsWithNamedTypesDo(consumer: (L2Operand, L2NamedOperandType) -> Unit)

Evaluate the given function with each L2Operand and the L2NamedOperandType that it occupies.

Link copied to clipboard
fun postOptimizationCleanup()

Now that chunk optimization has completed, remove information from this instruction that will no longer be needed in the finished chunk. Note that during subsequent inlining of this chunk at a call site, the type and synonym information will be reconstructed without too much cost.

Link copied to clipboard
fun replaceRegisters(registerRemap: Map<L2Register, L2Register>)

Replace all registers in this instruction using the registerRemap. If a register is not present as a key of that map, leave it alone. Do not assume SSA form.

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
fun transformAndEmitOn(regenerator: L2Regenerator)

Write the equivalent of this instruction through the given L2Regenerator. Certain types of L2Operations are transformed in ways specific to the kind of regenerator being used.

Link copied to clipboard
fun translateToJVM(translator: JVMTranslator, method: MethodVisitor)

Translate the L2Instruction into corresponding JVM instructions.

Link copied to clipboard
fun writesForPurposeDo(purpose: L2NamedOperandType.Purpose, consumer: (L2WriteOperand<*>) -> Unit)

Evaluate the given function with each L2WriteOperand having the given L2NamedOperandType.Purpose, which correlates with the Purpose along each outbound edge to indicate which writes have effect along which outbound edges.

Properties

Link copied to clipboard
val altersControlFlow: Boolean

Answer whether this instruction can alter control flow. That's true for any kind of instruction that has more than one successor (e.g., a branch) or no successors at all (e.g., a return).

Link copied to clipboard
val destinationRegisters: MutableList<L2Register>

The destination L2Registers.

Link copied to clipboard
val hasSideEffect: Boolean

Answer whether this instruction has any observable effect besides writing to its destination registers.

Link copied to clipboard
val isEntryPoint: Boolean

Answer whether this instruction is an entry point, which uses the operation L2_ENTER_L2_CHUNK.

Link copied to clipboard
val isPlaceholder: Boolean

Determine if this instruction is a place-holding instruction that will be re-emitted as an arbitrary graph of instructions at some point, via L2Operation.generateReplacement.

Link copied to clipboard
var offset: Int

The position of this instruction within its array of instructions. Only valid near the end of translation.

Link copied to clipboard
val operands: Array<L2Operand>

The L2Operands to supply to the operation.

Link copied to clipboard
val operation: L2Operation

The L2Operation whose execution this instruction represents.

Link copied to clipboard
val readOperands: List<L2ReadOperand<*>>

Answer a List of this instruction's L2ReadOperands.

Link copied to clipboard
val shouldEmit: Boolean

Answer whether this instruction should be emitted during final code generation (from the non-SSA L2ControlFlowGraph into a flat sequence of L2Instructions. Allow the operation to decide.

Link copied to clipboard
val sourceRegisters: MutableList<L2Register>

The source L2Registers.

Link copied to clipboard
val targetEdges: List<L2PcOperand>

Answer all possible L2PcOperands within this instruction. These edges lead to other L2BasicBlocks, and carry a L2ValueManifest.

Link copied to clipboard
val writeOperands: List<L2WriteOperand<*>>

Answer a List of this instruction's L2WriteOperands.