IR: make copying optional in performByIrFile
For codegen phases, input files are readonly data. There is no need to copy them.
This commit is contained in:
+17
-9
@@ -30,15 +30,17 @@ import java.util.concurrent.atomic.AtomicReference
|
|||||||
fun <Context : CommonBackendContext> performByIrFile(
|
fun <Context : CommonBackendContext> performByIrFile(
|
||||||
name: String = "PerformByIrFile",
|
name: String = "PerformByIrFile",
|
||||||
description: String = "Perform phases by IrFile",
|
description: String = "Perform phases by IrFile",
|
||||||
lower: List<CompilerPhase<Context, IrFile, IrFile>>
|
copyBeforeLowering: Boolean = true,
|
||||||
|
lower: List<CompilerPhase<Context, IrFile, IrFile>>,
|
||||||
): NamedCompilerPhase<Context, IrModuleFragment> =
|
): NamedCompilerPhase<Context, IrModuleFragment> =
|
||||||
NamedCompilerPhase(
|
NamedCompilerPhase(
|
||||||
name, description, emptySet(), PerformByIrFilePhase(lower), emptySet(), emptySet(), emptySet(),
|
name, description, emptySet(), PerformByIrFilePhase(lower, copyBeforeLowering), emptySet(), emptySet(), emptySet(),
|
||||||
setOf(defaultDumper), nlevels = 1,
|
setOf(defaultDumper), nlevels = 1,
|
||||||
)
|
)
|
||||||
|
|
||||||
private class PerformByIrFilePhase<Context : CommonBackendContext>(
|
private class PerformByIrFilePhase<Context : CommonBackendContext>(
|
||||||
private val lower: List<CompilerPhase<Context, IrFile, IrFile>>
|
private val lower: List<CompilerPhase<Context, IrFile, IrFile>>,
|
||||||
|
private val copyBeforeLowering: Boolean,
|
||||||
) : SameTypeCompilerPhase<Context, IrModuleFragment> {
|
) : SameTypeCompilerPhase<Context, IrModuleFragment> {
|
||||||
override fun invoke(
|
override fun invoke(
|
||||||
phaseConfig: PhaseConfig,
|
phaseConfig: PhaseConfig,
|
||||||
@@ -85,7 +87,10 @@ private class PerformByIrFilePhase<Context : CommonBackendContext>(
|
|||||||
|
|
||||||
// Each thread needs its own copy of phaserState.alreadyDone
|
// Each thread needs its own copy of phaserState.alreadyDone
|
||||||
val filesAndStates = input.files.map {
|
val filesAndStates = input.files.map {
|
||||||
it.copySavingMappings(remappedFiles, remappedFunctions, remappedClasses) to phaserState.copyOf()
|
if (copyBeforeLowering)
|
||||||
|
it.copySavingMappings(remappedFiles, remappedFunctions, remappedClasses) to phaserState.copyOf()
|
||||||
|
else
|
||||||
|
it to phaserState.copyOf()
|
||||||
}
|
}
|
||||||
|
|
||||||
val executor = Executors.newFixedThreadPool(nThreads)
|
val executor = Executors.newFixedThreadPool(nThreads)
|
||||||
@@ -111,12 +116,15 @@ private class PerformByIrFilePhase<Context : CommonBackendContext>(
|
|||||||
// Presumably each thread has run through the same list of phases.
|
// Presumably each thread has run through the same list of phases.
|
||||||
phaserState.alreadyDone.addAll(filesAndStates[0].second.alreadyDone)
|
phaserState.alreadyDone.addAll(filesAndStates[0].second.alreadyDone)
|
||||||
|
|
||||||
input.files.clear()
|
// Repair after working on copied files.
|
||||||
input.files.addAll(filesAndStates.map { (irFile, _) -> irFile }.toMutableList())
|
if (copyBeforeLowering) {
|
||||||
|
input.files.clear()
|
||||||
|
input.files.addAll(filesAndStates.map { (irFile, _) -> irFile }.toMutableList())
|
||||||
|
|
||||||
adjustDefaultArgumentStubs(context, remappedFunctions)
|
adjustDefaultArgumentStubs(context, remappedFunctions)
|
||||||
context.handleDeepCopy(remappedFiles, remappedClasses, remappedFunctions)
|
context.handleDeepCopy(remappedFiles, remappedClasses, remappedFunctions)
|
||||||
input.transformChildrenVoid(CrossFileCallAdjuster(remappedFunctions))
|
input.transformChildrenVoid(CrossFileCallAdjuster(remappedFunctions))
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: no guarantee that module identity is preserved by `lower`
|
// TODO: no guarantee that module identity is preserved by `lower`
|
||||||
return input
|
return input
|
||||||
|
|||||||
@@ -287,6 +287,7 @@ private fun codegenPhase(generateMultifileFacade: Boolean): NamedCompilerPhase<J
|
|||||||
return performByIrFile(
|
return performByIrFile(
|
||||||
name = "CodegenByIrFile$suffix",
|
name = "CodegenByIrFile$suffix",
|
||||||
description = "Code generation by IrFile$descriptionSuffix",
|
description = "Code generation by IrFile$descriptionSuffix",
|
||||||
|
copyBeforeLowering = false,
|
||||||
lower = listOf(
|
lower = listOf(
|
||||||
makeIrFilePhase(
|
makeIrFilePhase(
|
||||||
{ context ->
|
{ context ->
|
||||||
|
|||||||
Reference in New Issue
Block a user