L2ValueManifest

class L2ValueManifest

The L2ValueManifest maintains information about which L2SemanticValues hold equivalent values at this point, the TypeRestrictions for those semantic values, and the list of L2WriteOperands that are visible definitions of those values.

In order to avoid reevaluating primitives with the same values, a manifest also tracks L2Registers hold values representing which L2SemanticValues, specifically using L2Synonyms as the binding mechanism.

The mapping is keyed both ways (semantic value → synonym, and register → synonym), so that registers can be efficiently removed. This happens at control flow merges, where only the intersection of the semantic values available in each predecessor edge is kept, specifically via the introduction of new registers defined by phi instructions.

Author

Mark van Gulik

Todd L Smith

Constructors

Link copied to clipboard
fun L2ValueManifest()

Create a new, empty manifest.

Link copied to clipboard
fun L2ValueManifest(originalManifest: L2ValueManifest)

Copy an existing manifest.

Types

Link copied to clipboard
object Companion
Link copied to clipboard
class Constraint(theDefinitions: List<L2Register>, var restriction: TypeRestriction)

A utility type containing a mutable list of L2Registers that currently hold the same value, and a TypeRestriction.

Functions

Link copied to clipboard
fun allRegisters(): Set<L2Register>

Answer a Set of all L2Registers available in this manifest.

Link copied to clipboard
fun check()

Verify that this manifest is internally consistent.

Link copied to clipboard
fun clear()

Remove all information about registers and semantic values from this manifest.

Link copied to clipboard
fun definitionsForDescribing(synonym: L2Synonym): Iterable<L2Register>

Produce all live definitions of the synonym.

Link copied to clipboard
fun equivalentSemanticValue(semanticValue: L2SemanticValue): L2SemanticValue?

Given an L2SemanticValue, see if there's already an equivalent one in this manifest. If an L2SemanticPrimitiveInvocation is supplied, look for a recursively synonymous one.

Link copied to clipboard
fun extendSynonym(existingSynonym: L2Synonym, semanticValue: L2SemanticValue)

Merge a new L2SemanticValue into an existing L2Synonym. Update the manifest to reflect the merge.

Link copied to clipboard
fun forgetBoxedRegistersFor(synonym: L2Synonym)

Forget only the BOXED_KIND register definitions for this synonym. Keep the synonym around in all circumstances, even if there are no remaining definitions. Also, do not alter the synonym's restriction.

Link copied to clipboard
fun <R : L2Register> getDefinition(semanticValue: L2SemanticValue, registerKind: L2Register.RegisterKind): R

Retrieve the oldest definition of the given L2SemanticValue or an equivalent, but having the given RegisterKind. Only consider registers whose definitions all include that semantic value. This should work well in SSA or non-SSA, but not after register coloring.

Link copied to clipboard
fun <R : L2Register> getDefinitions(semanticValue: L2SemanticValue): List<R>

Retrieve all L2Registers known to contain the given L2SemanticValue. Narrow it to just those registers whose definitions all include that semantic value.

Link copied to clipboard
fun hasSemanticValue(semanticValue: L2SemanticValue): Boolean

Answer whether the L2SemanticValue is known to this manifest.

Link copied to clipboard
fun intersectType(semanticValue: L2SemanticValue, type: A_Type)

Replace the TypeRestriction associated with the given L2SemanticValue, which must be known by this manifest, with the intersection of its current restriction and the given restriction. Note that this also restricts any synonymous semantic values.

Link copied to clipboard
fun introduceSynonym(freshSynonym: L2Synonym, restriction: TypeRestriction)

Capture information about a new L2Synonym and its TypeRestriction. It's an error if any of the semantic values of the synonym are already bound to other synonyms in this manifest.

Link copied to clipboard
fun mergeExistingSemanticValues(semanticValue1: L2SemanticValue, semanticValue2: L2SemanticValue)

Given two L2SemanticValues, merge their L2Synonyms together, if they're not already. Update the manifest to reflect the merged synonyms.

Link copied to clipboard
fun populateFromIntersection(    manifests: List<L2ValueManifest>,     generator: L2Generator,     generatePhis: Boolean,     forcePhis: Boolean,     regenerator: L2Regenerator? = null)

Populate the empty receiver with bindings from the incoming manifests. Only keep the bindings for L2SemanticValues that occur in all incoming manifests. Generate phi functions as needed on the provided L2Generator. The phi functions' source registers correspond positionally with the list of manifests.

Link copied to clipboard
fun readBoxed(semanticValue: L2SemanticValue): L2ReadBoxedOperand

Create an L2ReadBoxedOperand for the L2SemanticValue of the earliest known boxed write for any semantic values in the same L2Synonym as the given semantic value.

Link copied to clipboard
fun readFloat(semanticValue: L2SemanticValue): L2ReadFloatOperand

Create an L2ReadFloatOperand for the L2SemanticValue of the earliest known unboxed float write for any semantic values in the same L2Synonym as the given semantic value.

Link copied to clipboard
fun readInt(semanticValue: L2SemanticValue): L2ReadIntOperand

Create an L2ReadIntOperand for the L2SemanticValue of the earliest known unboxed int write for any semantic values in the same L2Synonym as the given semantic value.

Link copied to clipboard
fun recordDefinition(writer: L2WriteOperand<*>)

Record the fact that an L2Instruction has been emitted, which writes to the given L2WriteOperand. Since this is the introduction of a new L2SemanticValue, it must not yet be in this manifest.

Link copied to clipboard
fun recordDefinitionForMakeImmutable(writer: L2WriteOperand<*>, sourceSemanticValue: L2SemanticValue)

Record the fact that an L2Instruction has been emitted, which writes to the given L2WriteOperand.

Link copied to clipboard
fun recordDefinitionForMove(writer: L2WriteOperand<*>, sourceSemanticValue: L2SemanticValue)

Record the fact that an L2Instruction has been emitted, which writes to the given L2WriteOperand. The source and destination should end up in the same synonym.

Link copied to clipboard
fun recordDefinitionNoCheck(writer: L2WriteOperand<*>)

Record the fact that an L2Instruction has been emitted, which writes to the given L2WriteOperand. Since this is the introduction of a new L2SemanticValue, it must not yet be in this manifest.

Link copied to clipboard
fun recordPostponedSourceInstruction(sourceInstruction: L2Instruction)

Record a sourceInstruction, which can be translated by an L2Regenerator whenever its output values are needed.

Link copied to clipboard
fun removePostponedSourceInstruction(semanticValue: L2SemanticValue): L2Instruction

Remove a previously recorded sourceInstruction, which can be translated by an L2Regenerator whenever its output values are needed. It will be stored under each RegisterKind and L2SemanticValue that the L2Instruction wrote in the prior L2ControlFlowGraph, so it should be removed under each such key. Answer the instruction.

Link copied to clipboard
fun replaceDefinitions(writeOperand: L2WriteOperand<*>)

Remove all definitions related to this L2WriteOperand's L2SemanticValues, then add this write operand as the sole definition in this manifest.

Link copied to clipboard
fun restrictionFor(semanticValue: L2SemanticValue): TypeRestriction

Look up the TypeRestriction that currently bounds this L2SemanticValue. Fail if there is none.

Link copied to clipboard
fun retainRegisters(registersToRetain: Set<L2Register>): Boolean

Retain as definitions only those L2Registers that are in the given Set, removing the rest.

Link copied to clipboard
fun retainSemanticValues(semanticValuesToRetain: Set<L2SemanticValue>)

Retain information only about the L2SemanticValues that are present in the given Set, removing the rest.

Link copied to clipboard
fun semanticValueToSynonym(semanticValue: L2SemanticValue): L2Synonym

Look up the given L2SemanticValue, answering the L2Synonym that's bound to it. Fail if it's not found.

Link copied to clipboard
fun setRestriction(semanticValue: L2SemanticValue, restriction: TypeRestriction)

Replace the TypeRestriction associated with the given L2SemanticValue, which must be known by this manifest. Note that this also restricts any synonymous semantic values.

Link copied to clipboard
fun subtractType(semanticValue: L2SemanticValue, type: A_Type)

Replace the TypeRestriction associated with the given L2SemanticValue, which must be known by this manifest, with the difference between its current restriction and the given restriction. Note that this also restricts any synonymous semantic values.

Link copied to clipboard
fun synonymsArray(): Array<L2Synonym>

Answer an arbitrarily ordered array of the L2Synonyms in this manifest.

Link copied to clipboard
fun synonymsForRegister(register: L2Register): List<L2Synonym>

Given an L2Register, find which L2Synonyms, if any, are mapped to it in this manifest. The CFG does not have to be in SSA form.

Link copied to clipboard
fun transform(semanticValueTransformer: (L2SemanticValue) -> L2SemanticValue): L2ValueManifest

Transform this manifest by mapping its L2SemanticValues.

Link copied to clipboard
fun updateConstraint(synonym: L2Synonym, body: L2ValueManifest.Constraint.() -> Unit)

Update the Constraint associated with the given L2Synonym.

Properties

Link copied to clipboard

A map from L2SemanticValue to source L2Instructions from a previous L2ControlFlowGraph, which can be translated as needed by an L2Regenerator, as part of the instruction postponement optimization (perfect redundancy elimination). The same source instruction is stored under each semantic value that was written by that instruction.