[K/N][optmz] Reworked a bit work with fields
This commit is contained in:
+12
-16
@@ -448,6 +448,16 @@ internal class ModuleDFGBuilder(val context: Context, val irModule: IrModuleFrag
|
|||||||
private val reinterpret = symbols.reinterpret
|
private val reinterpret = symbols.reinterpret
|
||||||
private val objCObjectRawValueGetter = symbols.interopObjCObjectRawValueGetter
|
private val objCObjectRawValueGetter = symbols.interopObjCObjectRawValueGetter
|
||||||
|
|
||||||
|
private val fields = mutableMapOf<IrField, DataFlowIR.Field>()
|
||||||
|
private fun IrField.toDataFlowIRField() = fields.getOrPut(this) {
|
||||||
|
val name = name.asString()
|
||||||
|
DataFlowIR.Field(
|
||||||
|
symbolTable.mapType(type),
|
||||||
|
1 + fields.size,
|
||||||
|
takeName { name }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
private class Scoped<out T : Any>(val value: T, val scope: DataFlowIR.Node.Scope)
|
private class Scoped<out T : Any>(val value: T, val scope: DataFlowIR.Node.Scope)
|
||||||
|
|
||||||
private inner class FunctionDFGBuilder(val expressionValuesExtractor: ExpressionValuesExtractor,
|
private inner class FunctionDFGBuilder(val expressionValuesExtractor: ExpressionValuesExtractor,
|
||||||
@@ -836,16 +846,9 @@ internal class ModuleDFGBuilder(val context: Context, val irModule: IrModuleFrag
|
|||||||
|
|
||||||
is IrGetField -> {
|
is IrGetField -> {
|
||||||
val receiver = value.receiver?.let { expressionToEdge(it) }
|
val receiver = value.receiver?.let { expressionToEdge(it) }
|
||||||
val receiverType = value.receiver?.let { symbolTable.mapType(it.type) }
|
|
||||||
val name = value.symbol.owner.name.asString()
|
|
||||||
DataFlowIR.Node.FieldRead(
|
DataFlowIR.Node.FieldRead(
|
||||||
receiver,
|
receiver,
|
||||||
DataFlowIR.Field(
|
value.symbol.owner.toDataFlowIRField(),
|
||||||
receiverType,
|
|
||||||
symbolTable.mapType(value.symbol.owner.type),
|
|
||||||
name.localHash.value,
|
|
||||||
takeName { name }
|
|
||||||
),
|
|
||||||
mapReturnType(value.type, value.symbol.owner.type),
|
mapReturnType(value.type, value.symbol.owner.type),
|
||||||
value
|
value
|
||||||
)
|
)
|
||||||
@@ -853,16 +856,9 @@ internal class ModuleDFGBuilder(val context: Context, val irModule: IrModuleFrag
|
|||||||
|
|
||||||
is IrSetField -> {
|
is IrSetField -> {
|
||||||
val receiver = value.receiver?.let { expressionToEdge(it) }
|
val receiver = value.receiver?.let { expressionToEdge(it) }
|
||||||
val receiverType = value.receiver?.let { symbolTable.mapType(it.type) }
|
|
||||||
val name = value.symbol.owner.name.asString()
|
|
||||||
DataFlowIR.Node.FieldWrite(
|
DataFlowIR.Node.FieldWrite(
|
||||||
receiver,
|
receiver,
|
||||||
DataFlowIR.Field(
|
value.symbol.owner.toDataFlowIRField(),
|
||||||
receiverType,
|
|
||||||
symbolTable.mapType(value.symbol.owner.type),
|
|
||||||
name.localHash.value,
|
|
||||||
takeName { name }
|
|
||||||
),
|
|
||||||
expressionToEdge(value.value),
|
expressionToEdge(value.value),
|
||||||
mapReturnType(value.value.type, value.symbol.owner.type)
|
mapReturnType(value.value.type, value.symbol.owner.type)
|
||||||
)
|
)
|
||||||
|
|||||||
+3
-1
@@ -206,7 +206,9 @@ internal object DataFlowIR {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data class Field(val receiverType: Type?, val type: Type, val hash: Long, val name: String? = null)
|
class Field(val type: Type, val index: Int, val name: String? = null) {
|
||||||
|
override fun toString() = "Field(type=$type, index=$index, name=$name)"
|
||||||
|
}
|
||||||
|
|
||||||
class Edge(val castToType: Type?) {
|
class Edge(val castToType: Type?) {
|
||||||
|
|
||||||
|
|||||||
+3
-4
@@ -180,8 +180,7 @@ internal object DevirtualizationAnalysis {
|
|||||||
|
|
||||||
val voidNode = addNode { Node.Ordinary(it, { "Void" }) }
|
val voidNode = addNode { Node.Ordinary(it, { "Void" }) }
|
||||||
val virtualNode = addNode { Node.Source(it, VIRTUAL_TYPE_ID, { "Virtual" }) }
|
val virtualNode = addNode { Node.Source(it, VIRTUAL_TYPE_ID, { "Virtual" }) }
|
||||||
val arrayItemField = DataFlowIR.Field(null,
|
val arrayItemField = DataFlowIR.Field(symbolTable.mapClassReferenceType(context.irBuiltIns.anyClass.owner), -1, "Array\$Item")
|
||||||
symbolTable.mapClassReferenceType(context.irBuiltIns.anyClass.owner), 1, "Array\$Item")
|
|
||||||
val functions = mutableMapOf<DataFlowIR.FunctionSymbol, Function>()
|
val functions = mutableMapOf<DataFlowIR.FunctionSymbol, Function>()
|
||||||
val externalFunctions = mutableMapOf<Pair<DataFlowIR.FunctionSymbol, DataFlowIR.Type>, Node>()
|
val externalFunctions = mutableMapOf<Pair<DataFlowIR.FunctionSymbol, DataFlowIR.Type>, Node>()
|
||||||
val fields = mutableMapOf<DataFlowIR.Field, Node>() // Do not distinguish receivers.
|
val fields = mutableMapOf<DataFlowIR.Field, Node>() // Do not distinguish receivers.
|
||||||
@@ -1221,14 +1220,14 @@ internal object DevirtualizationAnalysis {
|
|||||||
val type = node.field.type.resolved()
|
val type = node.field.type.resolved()
|
||||||
if (entryPoint == null && type.isFinal)
|
if (entryPoint == null && type.isFinal)
|
||||||
addInstantiatingClass(type)
|
addInstantiatingClass(type)
|
||||||
readField(node.field, type)
|
readField(node.field, node.type.resolved())
|
||||||
}
|
}
|
||||||
|
|
||||||
is DataFlowIR.Node.FieldWrite -> {
|
is DataFlowIR.Node.FieldWrite -> {
|
||||||
val type = node.field.type.resolved()
|
val type = node.field.type.resolved()
|
||||||
if (entryPoint == null && type.isFinal)
|
if (entryPoint == null && type.isFinal)
|
||||||
addInstantiatingClass(type)
|
addInstantiatingClass(type)
|
||||||
writeField(node.field, type, edgeToConstraintNode(node.value))
|
writeField(node.field, node.type.resolved(), edgeToConstraintNode(node.value))
|
||||||
constraintGraph.voidNode
|
constraintGraph.voidNode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-5
@@ -108,12 +108,12 @@ internal object EscapeAnalysis {
|
|||||||
|
|
||||||
// A special marker field for external types implemented in the runtime (mainly, arrays).
|
// A special marker field for external types implemented in the runtime (mainly, arrays).
|
||||||
// The types being passed to the constructor are not used in the analysis - just put there anything.
|
// The types being passed to the constructor are not used in the analysis - just put there anything.
|
||||||
private val intestinesField = DataFlowIR.Field(null, DataFlowIR.Type.Virtual, 1L, "inte\$tines")
|
private val intestinesField = DataFlowIR.Field(DataFlowIR.Type.Virtual, -1, "inte\$tines")
|
||||||
|
|
||||||
// A special marker field for return values.
|
// A special marker field for return values.
|
||||||
// Basically we substitute [return x] with [ret.v@lue = x].
|
// Basically we substitute [return x] with [ret.v@lue = x].
|
||||||
// This is done in order to not handle return parameter somewhat specially.
|
// This is done in order to not handle return parameter somewhat specially.
|
||||||
private val returnsValueField = DataFlowIR.Field(null, DataFlowIR.Type.Virtual, 2L, "v@lue")
|
private val returnsValueField = DataFlowIR.Field(DataFlowIR.Type.Virtual, -2, "v@lue")
|
||||||
|
|
||||||
// Roles in which particular object reference is being used.
|
// Roles in which particular object reference is being used.
|
||||||
private enum class Role {
|
private enum class Role {
|
||||||
@@ -303,8 +303,8 @@ internal object EscapeAnalysis {
|
|||||||
for (i in path.indices) {
|
for (i in path.indices) {
|
||||||
if (i >= other.path.size)
|
if (i >= other.path.size)
|
||||||
return 1
|
return 1
|
||||||
if (path[i].hash != other.path[i].hash)
|
if (path[i].index != other.path[i].index)
|
||||||
return path[i].hash.compareTo(other.path[i].hash)
|
return path[i].index.compareTo(other.path[i].index)
|
||||||
}
|
}
|
||||||
if (path.size < other.path.size) return -1
|
if (path.size < other.path.size) return -1
|
||||||
return 0
|
return 0
|
||||||
@@ -327,7 +327,7 @@ internal object EscapeAnalysis {
|
|||||||
append(root ?: kind.toString())
|
append(root ?: kind.toString())
|
||||||
path.forEach {
|
path.forEach {
|
||||||
append('.')
|
append('.')
|
||||||
append(it.name ?: "<no_name@${it.hash}>")
|
append(it.name ?: "<no_name@${it.index}>")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user