IR: refactor performByIrFile a little

Take a list of phases instead of the CompositePhase, to make stacktraces
nicer and avoid quadratic time of phase construction.
This commit is contained in:
Alexander Udalov
2020-07-01 02:38:41 +02:00
parent 4475325ffa
commit 15a969b3ba
2 changed files with 90 additions and 92 deletions
@@ -132,27 +132,24 @@ fun <Context : CommonBackendContext> namedOpUnitPhase(
fun <Context : CommonBackendContext> performByIrFile(
name: String = "PerformByIrFile",
description: String = "Perform phases by IrFile",
prerequisite: Set<NamedCompilerPhase<Context, *>> = emptySet(),
preconditions: Set<Checker<IrModuleFragment>> = emptySet(),
postconditions: Set<Checker<IrModuleFragment>> = emptySet(),
stickyPostconditions: Set<Checker<IrModuleFragment>> = emptySet(),
actions: Set<Action<IrModuleFragment, Context>> = setOf(defaultDumper),
lower: CompilerPhase<Context, IrFile, IrFile>
lower: List<CompilerPhase<Context, IrFile, IrFile>>
): NamedCompilerPhase<Context, IrModuleFragment> =
namedIrModulePhase(
name, description, prerequisite, PerformByIrFilePhase(lower), preconditions, postconditions, stickyPostconditions, actions,
nlevels = 1,
name, description, emptySet(), PerformByIrFilePhase(lower), emptySet(), emptySet(), emptySet(),
setOf(defaultDumper), nlevels = 1,
)
private class PerformByIrFilePhase<Context : CommonBackendContext>(
private val lower: CompilerPhase<Context, IrFile, IrFile>
private val lower: List<CompilerPhase<Context, IrFile, IrFile>>
) : SameTypeCompilerPhase<Context, IrModuleFragment> {
override fun invoke(
phaseConfig: PhaseConfig, phaserState: PhaserState<IrModuleFragment>, context: Context, input: IrModuleFragment
): IrModuleFragment {
for (irFile in input.files) {
try {
lower.invoke(phaseConfig, phaserState.changeType(), context, irFile)
for (phase in lower) {
phase.invoke(phaseConfig, phaserState.changeType(), context, irFile)
}
} catch (e: Throwable) {
CodegenUtil.reportBackendException(e, "IR lowering", irFile.fileEntry.name)
}
@@ -162,7 +159,8 @@ private class PerformByIrFilePhase<Context : CommonBackendContext>(
return input
}
override fun getNamedSubphases(startDepth: Int) = lower.getNamedSubphases(startDepth)
override fun getNamedSubphases(startDepth: Int): List<Pair<Int, NamedCompilerPhase<Context, *>>> =
lower.flatMap { it.getNamedSubphases(startDepth) }
}
fun <Context : CommonBackendContext> makeIrFilePhase(