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:
+9
-11
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user