DFG: placed isGlobalInitializer to FunctionSymbol
This commit is contained in:
+1
-1
@@ -96,8 +96,8 @@ internal class CallGraphBuilder(val context: Context,
|
|||||||
val rootSet = if (hasMain) {
|
val rootSet = if (hasMain) {
|
||||||
listOf(symbolTable.mapFunction(findMainEntryPoint(context)!!).resolved()) +
|
listOf(symbolTable.mapFunction(findMainEntryPoint(context)!!).resolved()) +
|
||||||
moduleDFG.functions
|
moduleDFG.functions
|
||||||
.filter { it.value.isGlobalInitializer }
|
|
||||||
.map { it.key }
|
.map { it.key }
|
||||||
|
.filter { it.isGlobalInitializer }
|
||||||
} else {
|
} else {
|
||||||
moduleDFG.functions.keys.filterIsInstance<DataFlowIR.FunctionSymbol.Public>()
|
moduleDFG.functions.keys.filterIsInstance<DataFlowIR.FunctionSymbol.Public>()
|
||||||
}
|
}
|
||||||
|
|||||||
-1
@@ -454,7 +454,6 @@ internal class ModuleDFGBuilder(val context: Context, val irModule: IrModuleFrag
|
|||||||
|
|
||||||
return DataFlowIR.Function(
|
return DataFlowIR.Function(
|
||||||
symbol = symbolTable.mapFunction(descriptor),
|
symbol = symbolTable.mapFunction(descriptor),
|
||||||
isGlobalInitializer = descriptor is PropertyDescriptor,
|
|
||||||
numberOfParameters = templateParameters.size + if (descriptor.isSuspend) 1 else 0,
|
numberOfParameters = templateParameters.size + if (descriptor.isSuspend) 1 else 0,
|
||||||
body = DataFlowIR.FunctionBody(allNodes.distinct().toList(), returnsNode, throwsNode)
|
body = DataFlowIR.FunctionBody(allNodes.distinct().toList(), returnsNode, throwsNode)
|
||||||
)
|
)
|
||||||
|
|||||||
+34
-24
@@ -278,39 +278,45 @@ internal object DFGSerializer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ExternalFunctionSymbol(val hash: Long, val numberOfParameters: Int, val escapes: Int?, val pointsTo: IntArray?, val name: String?) {
|
class ExternalFunctionSymbol(val hash: Long, val numberOfParameters: Int, val isGlobalInitializer: Boolean,
|
||||||
|
val escapes: Int?, val pointsTo: IntArray?, val name: String?) {
|
||||||
|
|
||||||
constructor(data: ArraySlice) : this(data.readLong(), data.readInt(), data.readNullableInt(),
|
constructor(data: ArraySlice) : this(data.readLong(), data.readInt(), data.readBoolean(), data.readNullableInt(),
|
||||||
data.readNullable { readIntArray() }, data.readNullableString())
|
data.readNullable { readIntArray() }, data.readNullableString())
|
||||||
|
|
||||||
fun write(result: ArraySlice) {
|
fun write(result: ArraySlice) {
|
||||||
result.writeLong(hash)
|
result.writeLong(hash)
|
||||||
result.writeInt(numberOfParameters)
|
result.writeInt(numberOfParameters)
|
||||||
|
result.writeBoolean(isGlobalInitializer)
|
||||||
result.writeNullableInt(escapes)
|
result.writeNullableInt(escapes)
|
||||||
result.writeNullable(pointsTo) { writeIntArray(it) }
|
result.writeNullable(pointsTo) { writeIntArray(it) }
|
||||||
result.writeNullableString(name)
|
result.writeNullableString(name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class PublicFunctionSymbol(val hash: Long, val numberOfParameters: Int, val index: Int, val name: String?) {
|
class PublicFunctionSymbol(val hash: Long, val numberOfParameters: Int, val isGlobalInitializer: Boolean,
|
||||||
|
val index: Int, val name: String?) {
|
||||||
|
|
||||||
constructor(data: ArraySlice) : this(data.readLong(), data.readInt(), data.readInt(), data.readNullableString())
|
constructor(data: ArraySlice) : this(data.readLong(), data.readInt(), data.readBoolean(), data.readInt(),
|
||||||
|
data.readNullableString())
|
||||||
|
|
||||||
fun write(result: ArraySlice) {
|
fun write(result: ArraySlice) {
|
||||||
result.writeLong(hash)
|
result.writeLong(hash)
|
||||||
result.writeInt(numberOfParameters)
|
result.writeInt(numberOfParameters)
|
||||||
|
result.writeBoolean(isGlobalInitializer)
|
||||||
result.writeInt(index)
|
result.writeInt(index)
|
||||||
result.writeNullableString(name)
|
result.writeNullableString(name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class PrivateFunctionSymbol(val index: Int, val numberOfParameters: Int, val name: String?) {
|
class PrivateFunctionSymbol(val index: Int, val numberOfParameters: Int, val isGlobalInitializer: Boolean, val name: String?) {
|
||||||
|
|
||||||
constructor(data: ArraySlice) : this(data.readInt(), data.readInt(), data.readNullableString())
|
constructor(data: ArraySlice) : this(data.readInt(), data.readInt(), data.readBoolean(), data.readNullableString())
|
||||||
|
|
||||||
fun write(result: ArraySlice) {
|
fun write(result: ArraySlice) {
|
||||||
result.writeInt(index)
|
result.writeInt(index)
|
||||||
result.writeInt(numberOfParameters)
|
result.writeInt(numberOfParameters)
|
||||||
|
result.writeBoolean(isGlobalInitializer)
|
||||||
result.writeNullableString(name)
|
result.writeNullableString(name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -332,14 +338,14 @@ internal object DFGSerializer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun external(hash: Long, numberOfParameters: Int, escapes: Int?, pointsTo: IntArray?, name: String?) =
|
fun external(hash: Long, numberOfParameters: Int, isGlobalInitializer: Boolean, escapes: Int?, pointsTo: IntArray?, name: String?) =
|
||||||
FunctionSymbol(ExternalFunctionSymbol(hash, numberOfParameters, escapes, pointsTo, name), null, null)
|
FunctionSymbol(ExternalFunctionSymbol(hash, numberOfParameters, isGlobalInitializer, escapes, pointsTo, name), null, null)
|
||||||
|
|
||||||
fun public(hash: Long, numberOfParameters: Int, index: Int, name: String?) =
|
fun public(hash: Long, numberOfParameters: Int, isGlobalInitializer: Boolean, index: Int, name: String?) =
|
||||||
FunctionSymbol(null, PublicFunctionSymbol(hash, numberOfParameters, index, name), null)
|
FunctionSymbol(null, PublicFunctionSymbol(hash, numberOfParameters, isGlobalInitializer, index, name), null)
|
||||||
|
|
||||||
fun private(index: Int, numberOfParameters: Int, name: String?) =
|
fun private(index: Int, numberOfParameters: Int, isGlobalInitializer: Boolean, name: String?) =
|
||||||
FunctionSymbol(null, null, PrivateFunctionSymbol(index, numberOfParameters, name))
|
FunctionSymbol(null, null, PrivateFunctionSymbol(index, numberOfParameters, isGlobalInitializer, name))
|
||||||
|
|
||||||
fun read(data: ArraySlice): FunctionSymbol {
|
fun read(data: ArraySlice): FunctionSymbol {
|
||||||
val tag = data.readByte().toInt()
|
val tag = data.readByte().toInt()
|
||||||
@@ -657,14 +663,12 @@ internal object DFGSerializer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Function(val symbol: Int, val isGlobalInitializer: Boolean,
|
class Function(val symbol: Int, val numberOfParameters: Int, val body: FunctionBody) {
|
||||||
val numberOfParameters: Int, val body: FunctionBody) {
|
|
||||||
|
|
||||||
constructor(data: ArraySlice) : this(data.readInt(), data.readBoolean(), data.readInt(), FunctionBody(data))
|
constructor(data: ArraySlice) : this(data.readInt(), data.readInt(), FunctionBody(data))
|
||||||
|
|
||||||
fun write(result: ArraySlice) {
|
fun write(result: ArraySlice) {
|
||||||
result.writeInt(symbol)
|
result.writeInt(symbol)
|
||||||
result.writeBoolean(isGlobalInitializer)
|
|
||||||
result.writeInt(numberOfParameters)
|
result.writeInt(numberOfParameters)
|
||||||
body.write(result)
|
body.write(result)
|
||||||
}
|
}
|
||||||
@@ -728,16 +732,20 @@ internal object DFGSerializer {
|
|||||||
.map {
|
.map {
|
||||||
val functionSymbol = it.key
|
val functionSymbol = it.key
|
||||||
val numberOfParameters = functionSymbol.numberOfParameters
|
val numberOfParameters = functionSymbol.numberOfParameters
|
||||||
|
val isGlobalInitializer = functionSymbol.isGlobalInitializer
|
||||||
val name = functionSymbol.name
|
val name = functionSymbol.name
|
||||||
when (functionSymbol) {
|
when (functionSymbol) {
|
||||||
is DataFlowIR.FunctionSymbol.External ->
|
is DataFlowIR.FunctionSymbol.External ->
|
||||||
FunctionSymbol.external(functionSymbol.hash, numberOfParameters, functionSymbol.escapes, functionSymbol.pointsTo, name)
|
FunctionSymbol.external(functionSymbol.hash, numberOfParameters, isGlobalInitializer,
|
||||||
|
functionSymbol.escapes, functionSymbol.pointsTo, name)
|
||||||
|
|
||||||
is DataFlowIR.FunctionSymbol.Public ->
|
is DataFlowIR.FunctionSymbol.Public ->
|
||||||
FunctionSymbol.public(functionSymbol.hash, numberOfParameters, functionSymbol.symbolTableIndex, name)
|
FunctionSymbol.public(functionSymbol.hash, numberOfParameters,
|
||||||
|
isGlobalInitializer, functionSymbol.symbolTableIndex, name)
|
||||||
|
|
||||||
is DataFlowIR.FunctionSymbol.Private ->
|
is DataFlowIR.FunctionSymbol.Private ->
|
||||||
FunctionSymbol.private(functionSymbol.symbolTableIndex, numberOfParameters, name)
|
FunctionSymbol.private(functionSymbol.symbolTableIndex, numberOfParameters,
|
||||||
|
isGlobalInitializer, name)
|
||||||
|
|
||||||
else -> error("Unknown function symbol $functionSymbol")
|
else -> error("Unknown function symbol $functionSymbol")
|
||||||
}
|
}
|
||||||
@@ -808,7 +816,6 @@ internal object DFGSerializer {
|
|||||||
.toTypedArray()
|
.toTypedArray()
|
||||||
Function(
|
Function(
|
||||||
functionSymbolMap[function.symbol]!!,
|
functionSymbolMap[function.symbol]!!,
|
||||||
function.isGlobalInitializer,
|
|
||||||
function.numberOfParameters,
|
function.numberOfParameters,
|
||||||
FunctionBody(nodes, nodeMap[body.returns]!!, nodeMap[body.throws]!!)
|
FunctionBody(nodes, nodeMap[body.returns]!!, nodeMap[body.throws]!!)
|
||||||
)
|
)
|
||||||
@@ -879,13 +886,15 @@ internal object DFGSerializer {
|
|||||||
val private = it.private
|
val private = it.private
|
||||||
when {
|
when {
|
||||||
external != null ->
|
external != null ->
|
||||||
DataFlowIR.FunctionSymbol.External(external.hash, external.numberOfParameters, external.escapes, external.pointsTo, external.name)
|
DataFlowIR.FunctionSymbol.External(external.hash, external.numberOfParameters,
|
||||||
|
external.isGlobalInitializer, external.escapes, external.pointsTo, external.name)
|
||||||
|
|
||||||
public != null -> {
|
public != null -> {
|
||||||
val symbolTableIndex = public.index
|
val symbolTableIndex = public.index
|
||||||
if (symbolTableIndex >= 0)
|
if (symbolTableIndex >= 0)
|
||||||
++module.numberOfFunctions
|
++module.numberOfFunctions
|
||||||
DataFlowIR.FunctionSymbol.Public(public.hash, public.numberOfParameters, module, symbolTableIndex, public.name).also {
|
DataFlowIR.FunctionSymbol.Public(public.hash, public.numberOfParameters, module,
|
||||||
|
symbolTableIndex, public.isGlobalInitializer, public.name).also {
|
||||||
publicFunctionsMap.put(it.hash, it)
|
publicFunctionsMap.put(it.hash, it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -894,7 +903,8 @@ internal object DFGSerializer {
|
|||||||
val symbolTableIndex = private!!.index
|
val symbolTableIndex = private!!.index
|
||||||
if (symbolTableIndex >= 0)
|
if (symbolTableIndex >= 0)
|
||||||
++module.numberOfFunctions
|
++module.numberOfFunctions
|
||||||
DataFlowIR.FunctionSymbol.Private(privateFunIndex++, private.numberOfParameters, module, symbolTableIndex, private.name)
|
DataFlowIR.FunctionSymbol.Private(privateFunIndex++, private.numberOfParameters, module,
|
||||||
|
symbolTableIndex, private.isGlobalInitializer, private.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1090,7 +1100,7 @@ internal object DFGSerializer {
|
|||||||
|
|
||||||
moduleDataFlowGraph.functions.forEach {
|
moduleDataFlowGraph.functions.forEach {
|
||||||
val symbol = functionSymbols[it.symbol]
|
val symbol = functionSymbols[it.symbol]
|
||||||
functions.put(symbol, DataFlowIR.Function(symbol, it.isGlobalInitializer, it.numberOfParameters, deserializeBody(it.body)))
|
functions.put(symbol, DataFlowIR.Function(symbol, it.numberOfParameters, deserializeBody(it.body)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+22
-16
@@ -114,9 +114,11 @@ internal object DataFlowIR {
|
|||||||
var numberOfFunctions = 0
|
var numberOfFunctions = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class FunctionSymbol(val numberOfParameters: Int, val name: String?) {
|
abstract class FunctionSymbol(val numberOfParameters: Int, val isGlobalInitializer: Boolean, val name: String?) {
|
||||||
class External(val hash: Long, numberOfParameters: Int, val escapes: Int?, val pointsTo: IntArray?, name: String? = null)
|
class External(val hash: Long, numberOfParameters: Int, isGlobalInitializer: Boolean,
|
||||||
: FunctionSymbol(numberOfParameters, name) {
|
val escapes: Int?, val pointsTo: IntArray?, name: String? = null)
|
||||||
|
: FunctionSymbol(numberOfParameters, isGlobalInitializer, name) {
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
if (this === other) return true
|
if (this === other) return true
|
||||||
if (other !is External) return false
|
if (other !is External) return false
|
||||||
@@ -133,11 +135,13 @@ internal object DataFlowIR {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class Declared(numberOfParameters: Int, val module: Module, val symbolTableIndex: Int, name: String?)
|
abstract class Declared(numberOfParameters: Int, val module: Module, val symbolTableIndex: Int,
|
||||||
: FunctionSymbol(numberOfParameters, name)
|
isGlobalInitializer: Boolean, name: String?)
|
||||||
|
: FunctionSymbol(numberOfParameters, isGlobalInitializer, name)
|
||||||
|
|
||||||
class Public(val hash: Long, numberOfParameters: Int, module: Module, symbolTableIndex: Int, name: String? = null)
|
class Public(val hash: Long, numberOfParameters: Int, module: Module, symbolTableIndex: Int,
|
||||||
: Declared(numberOfParameters, module, symbolTableIndex, name) {
|
isGlobalInitializer: Boolean, name: String? = null)
|
||||||
|
: Declared(numberOfParameters, module, symbolTableIndex, isGlobalInitializer, name) {
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
if (this === other) return true
|
if (this === other) return true
|
||||||
if (other !is Public) return false
|
if (other !is Public) return false
|
||||||
@@ -154,8 +158,9 @@ internal object DataFlowIR {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Private(val index: Int, numberOfParameters: Int, module: Module, symbolTableIndex: Int, name: String? = null)
|
class Private(val index: Int, numberOfParameters: Int, module: Module, symbolTableIndex: Int,
|
||||||
: Declared(numberOfParameters, module, symbolTableIndex, name) {
|
isGlobalInitializer: Boolean, name: String? = null)
|
||||||
|
: Declared(numberOfParameters, module, symbolTableIndex, isGlobalInitializer, name) {
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
if (this === other) return true
|
if (this === other) return true
|
||||||
if (other !is Private) return false
|
if (other !is Private) return false
|
||||||
@@ -229,11 +234,9 @@ internal object DataFlowIR {
|
|||||||
class FunctionBody(val nodes: List<Node>, val returns: Node.Variable, val throws: Node.Variable)
|
class FunctionBody(val nodes: List<Node>, val returns: Node.Variable, val throws: Node.Variable)
|
||||||
|
|
||||||
class Function(val symbol: FunctionSymbol,
|
class Function(val symbol: FunctionSymbol,
|
||||||
val isGlobalInitializer: Boolean,
|
|
||||||
val numberOfParameters: Int,
|
val numberOfParameters: Int,
|
||||||
val body: FunctionBody) {
|
val body: FunctionBody) {
|
||||||
|
|
||||||
|
|
||||||
fun debugOutput() {
|
fun debugOutput() {
|
||||||
println("FUNCTION $symbol")
|
println("FUNCTION $symbol")
|
||||||
println("Params: $numberOfParameters")
|
println("Params: $numberOfParameters")
|
||||||
@@ -511,8 +514,11 @@ internal object DataFlowIR {
|
|||||||
fun mapFunction(descriptor: CallableDescriptor) = descriptor.original.let {
|
fun mapFunction(descriptor: CallableDescriptor) = descriptor.original.let {
|
||||||
functionMap.getOrPut(it) {
|
functionMap.getOrPut(it) {
|
||||||
when (it) {
|
when (it) {
|
||||||
is PropertyDescriptor ->
|
is PropertyDescriptor -> {
|
||||||
FunctionSymbol.Private(privateFunIndex++, 0, module, -1, takeName { "${it.symbolName}_init" })
|
// A global property initializer.
|
||||||
|
assert (it.dispatchReceiverParameter == null) { "All local properties initializers should've been lowered" }
|
||||||
|
FunctionSymbol.Private(privateFunIndex++, 0, module, -1, true, takeName { "${it.symbolName}_init" })
|
||||||
|
}
|
||||||
|
|
||||||
is FunctionDescriptor -> {
|
is FunctionDescriptor -> {
|
||||||
val name = if (it.isExported()) it.symbolName else it.internalName
|
val name = if (it.isExported()) it.symbolName else it.internalName
|
||||||
@@ -524,7 +530,7 @@ internal object DataFlowIR {
|
|||||||
val escapesBitMask = (escapesAnnotation?.allValueArguments?.get(escapesWhoDescriptor.name) as? ConstantValue<Int>)?.value
|
val escapesBitMask = (escapesAnnotation?.allValueArguments?.get(escapesWhoDescriptor.name) as? ConstantValue<Int>)?.value
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
val pointsToBitMask = (pointsToAnnotation?.allValueArguments?.get(pointsToOnWhomDescriptor.name) as? ConstantValue<List<IntValue>>)?.value
|
val pointsToBitMask = (pointsToAnnotation?.allValueArguments?.get(pointsToOnWhomDescriptor.name) as? ConstantValue<List<IntValue>>)?.value
|
||||||
FunctionSymbol.External(name.localHash.value, numberOfParameters, escapesBitMask,
|
FunctionSymbol.External(name.localHash.value, numberOfParameters, false, escapesBitMask,
|
||||||
pointsToBitMask?.let { it.map { it.value }.toIntArray() }, takeName { name })
|
pointsToBitMask?.let { it.map { it.value }.toIntArray() }, takeName { name })
|
||||||
} else {
|
} else {
|
||||||
val isAbstract = it.modality == Modality.ABSTRACT
|
val isAbstract = it.modality == Modality.ABSTRACT
|
||||||
@@ -536,9 +542,9 @@ internal object DataFlowIR {
|
|||||||
++module.numberOfFunctions
|
++module.numberOfFunctions
|
||||||
val symbolTableIndex = if (!placeToFunctionsTable) -1 else couldBeCalledVirtuallyIndex++
|
val symbolTableIndex = if (!placeToFunctionsTable) -1 else couldBeCalledVirtuallyIndex++
|
||||||
if (it.isExported())
|
if (it.isExported())
|
||||||
FunctionSymbol.Public(name.localHash.value, numberOfParameters, module, symbolTableIndex, takeName { name })
|
FunctionSymbol.Public(name.localHash.value, numberOfParameters, module, symbolTableIndex, false, takeName { name })
|
||||||
else
|
else
|
||||||
FunctionSymbol.Private(privateFunIndex++, numberOfParameters, module, symbolTableIndex, takeName { name })
|
FunctionSymbol.Private(privateFunIndex++, numberOfParameters, module, symbolTableIndex, false, takeName { name })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user