diff --git a/compiler/frontend/src/org/jetbrains/kotlin/cfg/PseudocodeTraverser.kt b/compiler/frontend/src/org/jetbrains/kotlin/cfg/PseudocodeTraverser.kt index 69804c1b0c0..66be8d77789 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/cfg/PseudocodeTraverser.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/cfg/PseudocodeTraverser.kt @@ -64,14 +64,13 @@ fun > Pseudocode.collectData( val edgesMap = LinkedHashMap>() edgesMap.put(getStartInstruction(traversalOrder), Edges(initialInfo, initialInfo)) - val changed = BooleanArray(1) - changed[0] = true - while (changed[0]) { - changed[0] = false + val changed = mutableMapOf() + do { collectDataFromSubgraph( traversalOrder, edgesMap, mergeEdges, updateEdge, Collections.emptyList(), changed, false) - } + } while (changed.any { it.value }) + return edgesMap } @@ -81,7 +80,7 @@ private fun > Pseudocode.collectDataFromSubgraph( mergeEdges: (Instruction, Collection) -> Edges, updateEdge: (Instruction, Instruction, I) -> I, previousSubGraphInstructions: Collection, - changed: BooleanArray, + changed: MutableMap, isLocal: Boolean ) { val instructions = getInstructions(traversalOrder) @@ -107,7 +106,13 @@ private fun > Pseudocode.collectDataFromSubgraph( updateEdgeDataForInstruction(instruction, previousValue, updatedValue, edgesMap, changed) continue } + + val previousDataValue = edgesMap[instruction] + if (previousDataValue != null && previousInstructions.all { changed[it] == false }) { + changed[instruction] = false + continue + } val incomingEdgesData = HashSet() @@ -139,11 +144,19 @@ private fun getPreviousIncludingSubGraphInstructions( } private fun > updateEdgeDataForInstruction( - instruction: Instruction, previousValue: Edges?, newValue: Edges?, edgesMap: MutableMap>, changed: BooleanArray) { + instruction: Instruction, + previousValue: Edges?, + newValue: Edges?, + edgesMap: MutableMap>, + changed: MutableMap +) { if (previousValue != newValue && newValue != null) { - changed[0] = true + changed[instruction] = true edgesMap.put(instruction, newValue) } + else { + changed[instruction] = false + } } data class Edges(val incoming: T, val outgoing: T)