Store copies of instruction only once
removed reference to 'original' instruction
This commit is contained in:
+2
-2
@@ -23,7 +23,7 @@ import org.jetbrains.jet.lang.cfg.pseudocode.PseudoValue
|
|||||||
public trait Instruction {
|
public trait Instruction {
|
||||||
public var owner: Pseudocode
|
public var owner: Pseudocode
|
||||||
|
|
||||||
public val previousInstructions: MutableCollection<Instruction>
|
public val previousInstructions: Collection<Instruction>
|
||||||
public val nextInstructions: Collection<Instruction>
|
public val nextInstructions: Collection<Instruction>
|
||||||
|
|
||||||
public val dead: Boolean
|
public val dead: Boolean
|
||||||
@@ -32,7 +32,7 @@ public trait Instruction {
|
|||||||
|
|
||||||
public val inputValues: List<PseudoValue>
|
public val inputValues: List<PseudoValue>
|
||||||
|
|
||||||
public fun getCopies(): Collection<Instruction>
|
public val copies: Collection<Instruction>
|
||||||
|
|
||||||
public fun accept(visitor: InstructionVisitor)
|
public fun accept(visitor: InstructionVisitor)
|
||||||
public fun <R> accept(visitor: InstructionVisitorWithResult<R>): R
|
public fun <R> accept(visitor: InstructionVisitorWithResult<R>): R
|
||||||
|
|||||||
+11
-25
@@ -33,46 +33,32 @@ public abstract class InstructionImpl(public override val lexicalScope: LexicalS
|
|||||||
_owner = value
|
_owner = value
|
||||||
}
|
}
|
||||||
|
|
||||||
private val _copies = HashSet<Instruction>()
|
private var allCopies: MutableSet<InstructionImpl>? = null
|
||||||
|
|
||||||
override fun getCopies(): Collection<Instruction> {
|
override val copies: Collection<Instruction>
|
||||||
return original?.let { original ->
|
get() = allCopies?.filter { it != this } ?: Collections.emptyList()
|
||||||
val originalCopies = Sets.newHashSet(original.getCopies())
|
|
||||||
originalCopies.remove(this)
|
|
||||||
originalCopies.add(original)
|
|
||||||
originalCopies
|
|
||||||
} ?: _copies
|
|
||||||
}
|
|
||||||
|
|
||||||
private var original: Instruction? = null
|
fun copy(): Instruction = updateCopyInfo(createCopy())
|
||||||
|
|
||||||
private fun setOriginalInstruction(value: Instruction?) {
|
|
||||||
assert(original == null) { "Instruction can't have two originals: this.original = ${original}; new original = $this" }
|
|
||||||
original = value
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun copy(): Instruction {
|
|
||||||
return updateCopyInfo(createCopy())
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract fun createCopy(): InstructionImpl
|
protected abstract fun createCopy(): InstructionImpl
|
||||||
|
|
||||||
protected fun updateCopyInfo(instruction: InstructionImpl): Instruction {
|
protected fun updateCopyInfo(instruction: InstructionImpl): Instruction {
|
||||||
_copies.add(instruction)
|
if (allCopies == null) {
|
||||||
instruction.setOriginalInstruction(this)
|
allCopies = hashSetOf(this)
|
||||||
|
}
|
||||||
|
instruction.allCopies = allCopies
|
||||||
|
allCopies!!.add(instruction)
|
||||||
return instruction
|
return instruction
|
||||||
}
|
}
|
||||||
|
|
||||||
public var markedAsDead: Boolean = false
|
public var markedAsDead: Boolean = false
|
||||||
|
|
||||||
override val dead: Boolean get() = markedAsDead && getCopies().all { (it as InstructionImpl).markedAsDead }
|
override val dead: Boolean get() = allCopies?.all { it.markedAsDead } ?: markedAsDead
|
||||||
|
|
||||||
override val previousInstructions: MutableCollection<Instruction> = LinkedHashSet()
|
override val previousInstructions: MutableCollection<Instruction> = LinkedHashSet()
|
||||||
|
|
||||||
protected fun outgoingEdgeTo(target: Instruction?): Instruction? {
|
protected fun outgoingEdgeTo(target: Instruction?): Instruction? {
|
||||||
if (target != null) {
|
(target as InstructionImpl?)?.previousInstructions?.add(this)
|
||||||
target.previousInstructions.add(this)
|
|
||||||
}
|
|
||||||
return target
|
return target
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user