Limit stack allocation only for array read operations with connection between return value and array (#3728)

This commit is contained in:
LepilkinaElena
2019-12-26 16:15:21 +03:00
committed by GitHub
parent 857e6948b2
commit 721ee18a64
3 changed files with 26 additions and 2 deletions
@@ -134,8 +134,10 @@ internal object LocalEscapeAnalysis {
}
}
is DataFlowIR.Node.ArrayRead -> {
// If element of array escapes then array also should escape.
connectObjects(node, node.array.node)
// If element of array(return value) points to array(this value) and escapes then array also should escape.
if (((node.callee.pointsTo?.elementAtOrNull(node.callee.parameters.size) ?: 0) and (1 shl 0)) != 0) {
connectObjects(node, node.array.node)
}
}
}
}
+5
View File
@@ -1789,6 +1789,11 @@ task BitSet(type: KonanLocalTest) {
source = "runtime/collections/BitSet.kt"
}
task stack_array(type: KonanLocalTest) {
goldValue = "true\n3\n"
source = "runtime/collections/stack_array.kt"
}
task array0(type: KonanLocalTest) {
goldValue = "5\n6\n7\n8\n9\n10\n11\n12\n13\n"
source = "runtime/collections/array0.kt"
@@ -0,0 +1,17 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package runtime.collections.stack_array
import kotlin.test.*
@Test fun runTest() {
val array = IntArray(2)
array[0] = 1
array[1] = 2
val check = array is IntArray
println(check)
println(array[0] + array[1])
}