backend: build ModuleIndex for codegen after lowering
This commit is contained in:
committed by
SvyatoslavScherbina
parent
97b5c60455
commit
40eea333ce
+2
@@ -4,6 +4,7 @@ import org.jetbrains.kotlin.analyzer.AnalysisResult
|
|||||||
import org.jetbrains.kotlin.backend.konan.llvm.emitLLVM
|
import org.jetbrains.kotlin.backend.konan.llvm.emitLLVM
|
||||||
import org.jetbrains.kotlin.backend.konan.util.profile
|
import org.jetbrains.kotlin.backend.konan.util.profile
|
||||||
import org.jetbrains.kotlin.backend.konan.Context
|
import org.jetbrains.kotlin.backend.konan.Context
|
||||||
|
import org.jetbrains.kotlin.backend.konan.ir.ModuleIndex
|
||||||
import org.jetbrains.kotlin.cli.common.CLICompiler
|
import org.jetbrains.kotlin.cli.common.CLICompiler
|
||||||
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
||||||
import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport
|
import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport
|
||||||
@@ -67,6 +68,7 @@ public fun runTopLevelPhases(konanConfig: KonanConfig, environment: KotlinCoreEn
|
|||||||
phaser.phase(KonanPhase.BACKEND) {
|
phaser.phase(KonanPhase.BACKEND) {
|
||||||
phaser.phase(KonanPhase.LOWER) {
|
phaser.phase(KonanPhase.LOWER) {
|
||||||
KonanLower(context).lower()
|
KonanLower(context).lower()
|
||||||
|
context.ir.moduleIndexForCodegen = ModuleIndex(context.ir.irModule)
|
||||||
}
|
}
|
||||||
phaser.phase(KonanPhase.BITCODE) {
|
phaser.phase(KonanPhase.BITCODE) {
|
||||||
emitLLVM(context)
|
emitLLVM(context)
|
||||||
|
|||||||
+3
-1
@@ -8,5 +8,7 @@ import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
|||||||
internal class Ir(val context: Context, val irModule: IrModuleFragment) {
|
internal class Ir(val context: Context, val irModule: IrModuleFragment) {
|
||||||
val propertiesWithBackingFields = mutableSetOf<PropertyDescriptor>()
|
val propertiesWithBackingFields = mutableSetOf<PropertyDescriptor>()
|
||||||
|
|
||||||
val moduleIndex = ModuleIndex(irModule)
|
val originalModuleIndex = ModuleIndex(irModule)
|
||||||
|
|
||||||
|
lateinit var moduleIndexForCodegen: ModuleIndex
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -75,7 +75,7 @@ internal interface ContextUtils {
|
|||||||
// In this function we check the presence of the backing filed
|
// In this function we check the presence of the backing filed
|
||||||
// two ways: first we check IR, then we check the annotation.
|
// two ways: first we check IR, then we check the annotation.
|
||||||
|
|
||||||
val irClass = context.ir.moduleIndex.classes[this.classId]
|
val irClass = context.ir.moduleIndexForCodegen.classes[this.classId]
|
||||||
if (irClass != null) {
|
if (irClass != null) {
|
||||||
val declarations = irClass.declarations
|
val declarations = irClass.declarations
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -388,7 +388,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
|||||||
LLVMSetInitializer(objectPtr, codegen.kNullObjHeaderPtr)
|
LLVMSetInitializer(objectPtr, codegen.kNullObjHeaderPtr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val irOfCurrentClass = context.ir.moduleIndex.classes[classDescriptor.classId]
|
val irOfCurrentClass = context.ir.moduleIndexForCodegen.classes[classDescriptor.classId]
|
||||||
irOfCurrentClass!!.acceptChildrenVoid(object : IrElementVisitorVoid {
|
irOfCurrentClass!!.acceptChildrenVoid(object : IrElementVisitorVoid {
|
||||||
override fun visitElement(element: IrElement) {
|
override fun visitElement(element: IrElement) {
|
||||||
element.acceptChildrenVoid(this)
|
element.acceptChildrenVoid(this)
|
||||||
|
|||||||
+2
-1
@@ -24,7 +24,8 @@ internal class FunctionInlining(val context: Context): IrElementTransformerVoid(
|
|||||||
val functionDescriptor = expression.descriptor as FunctionDescriptor
|
val functionDescriptor = expression.descriptor as FunctionDescriptor
|
||||||
if (!functionDescriptor.isInline) return super.visitCall(expression) // Function is not to be inlined - do nothing.
|
if (!functionDescriptor.isInline) return super.visitCall(expression) // Function is not to be inlined - do nothing.
|
||||||
|
|
||||||
val functionDeclaration = context.ir.moduleIndex.functions[functionDescriptor] // Get FunctionDeclaration by FunctionDescriptor.
|
val functionDeclaration = context.ir.originalModuleIndex
|
||||||
|
.functions[functionDescriptor] // Get FunctionDeclaration by FunctionDescriptor.
|
||||||
if (functionDeclaration == null) return super.visitCall(expression) // Function is declared in another module.
|
if (functionDeclaration == null) return super.visitCall(expression) // Function is declared in another module.
|
||||||
val copyFuncDeclaration = functionDeclaration.accept(DeepCopyIrTree(), null) as IrFunction // Create copy of the function.
|
val copyFuncDeclaration = functionDeclaration.accept(DeepCopyIrTree(), null) as IrFunction // Create copy of the function.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user