[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 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 inner class FunctionDFGBuilder(val expressionValuesExtractor: ExpressionValuesExtractor,
|
||||
@@ -836,16 +846,9 @@ internal class ModuleDFGBuilder(val context: Context, val irModule: IrModuleFrag
|
||||
|
||||
is IrGetField -> {
|
||||
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(
|
||||
receiver,
|
||||
DataFlowIR.Field(
|
||||
receiverType,
|
||||
symbolTable.mapType(value.symbol.owner.type),
|
||||
name.localHash.value,
|
||||
takeName { name }
|
||||
),
|
||||
value.symbol.owner.toDataFlowIRField(),
|
||||
mapReturnType(value.type, value.symbol.owner.type),
|
||||
value
|
||||
)
|
||||
@@ -853,16 +856,9 @@ internal class ModuleDFGBuilder(val context: Context, val irModule: IrModuleFrag
|
||||
|
||||
is IrSetField -> {
|
||||
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(
|
||||
receiver,
|
||||
DataFlowIR.Field(
|
||||
receiverType,
|
||||
symbolTable.mapType(value.symbol.owner.type),
|
||||
name.localHash.value,
|
||||
takeName { name }
|
||||
),
|
||||
value.symbol.owner.toDataFlowIRField(),
|
||||
expressionToEdge(value.value),
|
||||
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?) {
|
||||
|
||||
|
||||
+3
-4
@@ -180,8 +180,7 @@ internal object DevirtualizationAnalysis {
|
||||
|
||||
val voidNode = addNode { Node.Ordinary(it, { "Void" }) }
|
||||
val virtualNode = addNode { Node.Source(it, VIRTUAL_TYPE_ID, { "Virtual" }) }
|
||||
val arrayItemField = DataFlowIR.Field(null,
|
||||
symbolTable.mapClassReferenceType(context.irBuiltIns.anyClass.owner), 1, "Array\$Item")
|
||||
val arrayItemField = DataFlowIR.Field(symbolTable.mapClassReferenceType(context.irBuiltIns.anyClass.owner), -1, "Array\$Item")
|
||||
val functions = mutableMapOf<DataFlowIR.FunctionSymbol, Function>()
|
||||
val externalFunctions = mutableMapOf<Pair<DataFlowIR.FunctionSymbol, DataFlowIR.Type>, Node>()
|
||||
val fields = mutableMapOf<DataFlowIR.Field, Node>() // Do not distinguish receivers.
|
||||
@@ -1221,14 +1220,14 @@ internal object DevirtualizationAnalysis {
|
||||
val type = node.field.type.resolved()
|
||||
if (entryPoint == null && type.isFinal)
|
||||
addInstantiatingClass(type)
|
||||
readField(node.field, type)
|
||||
readField(node.field, node.type.resolved())
|
||||
}
|
||||
|
||||
is DataFlowIR.Node.FieldWrite -> {
|
||||
val type = node.field.type.resolved()
|
||||
if (entryPoint == null && type.isFinal)
|
||||
addInstantiatingClass(type)
|
||||
writeField(node.field, type, edgeToConstraintNode(node.value))
|
||||
writeField(node.field, node.type.resolved(), edgeToConstraintNode(node.value))
|
||||
constraintGraph.voidNode
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -108,12 +108,12 @@ internal object EscapeAnalysis {
|
||||
|
||||
// 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.
|
||||
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.
|
||||
// Basically we substitute [return x] with [ret.v@lue = x].
|
||||
// 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.
|
||||
private enum class Role {
|
||||
@@ -303,8 +303,8 @@ internal object EscapeAnalysis {
|
||||
for (i in path.indices) {
|
||||
if (i >= other.path.size)
|
||||
return 1
|
||||
if (path[i].hash != other.path[i].hash)
|
||||
return path[i].hash.compareTo(other.path[i].hash)
|
||||
if (path[i].index != other.path[i].index)
|
||||
return path[i].index.compareTo(other.path[i].index)
|
||||
}
|
||||
if (path.size < other.path.size) return -1
|
||||
return 0
|
||||
@@ -327,7 +327,7 @@ internal object EscapeAnalysis {
|
||||
append(root ?: kind.toString())
|
||||
path.forEach {
|
||||
append('.')
|
||||
append(it.name ?: "<no_name@${it.hash}>")
|
||||
append(it.name ?: "<no_name@${it.index}>")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user