Extract SameTypeNamedCompilerPhase from NamedCompilerPhase

Currently, compiler pipelines are heavily couples with
NamedCompilerPhase. Unfortunately, NamedCompilerPhase uses the same
type for Input and Output, thus it is not applicable to phases that
try to transform some data purely.
Thus, we separate this class into two, allowing to have a new
inheritor of NamedCompilerPhase with different Input and Output types.
This commit is contained in:
Sergey Bogolepov
2022-10-03 14:07:50 +03:00
committed by Space Team
parent 3a500e536a
commit 6a4722188f
9 changed files with 142 additions and 101 deletions
@@ -40,22 +40,22 @@ private fun makeKonanFileLoweringPhase(
lowering: (Context) -> FileLoweringPass,
name: String,
description: String,
prerequisite: Set<NamedCompilerPhase<Context, *>> = emptySet()
prerequisite: Set<AbstractNamedCompilerPhase<Context, *, *>> = emptySet()
) = makeIrFilePhase(lowering, name, description, prerequisite, actions = filePhaseActions)
private fun makeKonanModuleLoweringPhase(
lowering: (Context) -> FileLoweringPass,
name: String,
description: String,
prerequisite: Set<NamedCompilerPhase<Context, *>> = emptySet()
prerequisite: Set<AbstractNamedCompilerPhase<Context, *, *>> = emptySet()
) = makeIrModulePhase(lowering, name, description, prerequisite, actions = modulePhaseActions)
internal fun makeKonanFileOpPhase(
op: (Context, IrFile) -> Unit,
name: String,
description: String,
prerequisite: Set<NamedCompilerPhase<Context, *>> = emptySet()
) = NamedCompilerPhase(
prerequisite: Set<AbstractNamedCompilerPhase<Context, *, *>> = emptySet()
) = SameTypeNamedCompilerPhase(
name, description, prerequisite, nlevels = 0,
lower = object : SameTypeCompilerPhase<Context, IrFile> {
override fun invoke(phaseConfig: PhaseConfigurationService, phaserState: PhaserState<IrFile>, context: Context, input: IrFile): IrFile {
@@ -70,8 +70,8 @@ internal fun makeKonanModuleOpPhase(
op: (Context, IrModuleFragment) -> Unit,
name: String,
description: String,
prerequisite: Set<NamedCompilerPhase<Context, *>> = emptySet()
) = NamedCompilerPhase(
prerequisite: Set<AbstractNamedCompilerPhase<Context, *, *>> = emptySet()
) = SameTypeNamedCompilerPhase(
name, description, prerequisite, nlevels = 0,
lower = object : SameTypeCompilerPhase<Context, IrModuleFragment> {
override fun invoke(phaseConfig: PhaseConfigurationService, phaserState: PhaserState<IrModuleFragment>, context: Context, input: IrModuleFragment): IrModuleFragment {
@@ -5,9 +5,9 @@
package org.jetbrains.kotlin.backend.konan
import org.jetbrains.kotlin.backend.common.checkDeclarationParents
import org.jetbrains.kotlin.backend.common.IrValidator
import org.jetbrains.kotlin.backend.common.IrValidatorConfig
import org.jetbrains.kotlin.backend.common.checkDeclarationParents
import org.jetbrains.kotlin.backend.common.phaser.*
import org.jetbrains.kotlin.backend.common.serialization.CompatibilityMode
import org.jetbrains.kotlin.backend.common.serialization.metadata.KlibMetadataMonolithicSerializer
@@ -19,11 +19,15 @@ import org.jetbrains.kotlin.backend.konan.lower.SamSuperTypesChecker
import org.jetbrains.kotlin.backend.konan.objcexport.ObjCExport
import org.jetbrains.kotlin.backend.konan.objcexport.createCodeSpec
import org.jetbrains.kotlin.backend.konan.objcexport.produceObjCExportInterface
import org.jetbrains.kotlin.backend.konan.serialization.*
import org.jetbrains.kotlin.backend.konan.serialization.KonanIdSignaturer
import org.jetbrains.kotlin.backend.konan.serialization.KonanIrModuleSerializer
import org.jetbrains.kotlin.backend.konan.serialization.KonanManglerDesc
import org.jetbrains.kotlin.config.CommonConfigurationKeys
import org.jetbrains.kotlin.config.languageVersionSettings
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.declarations.IrFile
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl
import org.jetbrains.kotlin.ir.declarations.path
import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.konan.target.CompilerOutputKind
import org.jetbrains.kotlin.name.FqName
@@ -69,7 +73,7 @@ internal fun fileValidationCallback(state: ActionState, irFile: IrFile, context:
internal fun konanUnitPhase(
name: String,
description: String,
prerequisite: Set<NamedCompilerPhase<Context, *>> = emptySet(),
prerequisite: Set<AbstractNamedCompilerPhase<Context, *, *>> = emptySet(),
op: Context.() -> Unit
) = namedOpUnitPhase(name, description, prerequisite, op)
@@ -235,7 +239,7 @@ internal val finalizeCachePhase = konanUnitPhase(
description = "Finalize cache (rename temp to the final dist)"
)
internal val allLoweringsPhase = NamedCompilerPhase(
internal val allLoweringsPhase = SameTypeNamedCompilerPhase(
name = "IrLowering",
description = "IR Lowering",
// TODO: The lowerings before inlinePhase should be aligned with [NativeInlineFunctionResolver.kt]
@@ -298,7 +302,7 @@ internal val allLoweringsPhase = NamedCompilerPhase(
actions = setOf(defaultDumper, ::moduleValidationCallback)
)
internal val dependenciesLowerPhase = NamedCompilerPhase(
internal val dependenciesLowerPhase = SameTypeNamedCompilerPhase(
name = "LowerLibIR",
description = "Lower library's IR",
prerequisite = emptySet(),
@@ -336,7 +340,7 @@ internal val dependenciesLowerPhase = NamedCompilerPhase(
}
})
internal val umbrellaCompilation = NamedCompilerPhase(
internal val umbrellaCompilation = SameTypeNamedCompilerPhase(
name = "UmbrellaCompilation",
description = "A batched compilation with shared FE and ME phases",
prerequisite = emptySet(),
@@ -389,7 +393,7 @@ internal val entryPointPhase = makeCustomPhase<Context, IrModuleFragment>(
}
)
internal val bitcodePhase = NamedCompilerPhase(
internal val bitcodePhase = SameTypeNamedCompilerPhase(
name = "Bitcode",
description = "LLVM Bitcode generation",
lower = returnsInsertionPhase then
@@ -411,7 +415,7 @@ internal val bitcodePhase = NamedCompilerPhase(
cStubsPhase
)
private val bitcodePostprocessingPhase = NamedCompilerPhase(
private val bitcodePostprocessingPhase = SameTypeNamedCompilerPhase(
name = "BitcodePostprocessing",
description = "Optimize and rewrite bitcode",
lower = checkExternalCallsPhase then
@@ -422,7 +426,7 @@ private val bitcodePostprocessingPhase = NamedCompilerPhase(
rewriteExternalCallsCheckerGlobals
)
private val backendCodegen = NamedCompilerPhase(
private val backendCodegen = SameTypeNamedCompilerPhase(
name = "Backend codegen",
description = "Backend code generation",
lower = entryPointPhase then
@@ -456,7 +460,7 @@ internal val disposeGenerationStatePhase = namedUnitPhase(
}
)
private val phasesOverMainModule = NamedCompilerPhase(
private val phasesOverMainModule = SameTypeNamedCompilerPhase(
name = "PhasesOverMainModule",
description = "Phases over main module",
lower = takeFromContext<Context, Unit, IrModuleFragment> { it.irModule!! } then
@@ -466,7 +470,7 @@ private val phasesOverMainModule = NamedCompilerPhase(
prerequisite = setOf(psiToIrPhase)
)
private val entireBackend = NamedCompilerPhase(
private val entireBackend = SameTypeNamedCompilerPhase(
name = "EntireBackend",
description = "Entire backend",
lower = createGenerationStatePhase then
@@ -480,7 +484,7 @@ private val entireBackend = NamedCompilerPhase(
disposeGenerationStatePhase
)
private val middleEnd = NamedCompilerPhase(
private val middleEnd = SameTypeNamedCompilerPhase(
name = "MiddleEnd",
description = "Build and prepare IR for back end",
lower = createSymbolTablePhase then
@@ -494,7 +498,7 @@ private val middleEnd = NamedCompilerPhase(
functionsWithoutBoundCheck
)
private val singleCompilation = NamedCompilerPhase(
private val singleCompilation = SameTypeNamedCompilerPhase(
name = "SingleCompilation",
description = "Single compilation",
lower = entireBackend