From 1b49ea846550181538bc1965ff6b06c0ed3d041f Mon Sep 17 00:00:00 2001 From: Ilya Matveev Date: Mon, 8 Jul 2019 19:58:52 +0700 Subject: [PATCH] Debug: Get rid of descriptors in DebugUtils --- .../kotlin/backend/konan/llvm/DebugUtils.kt | 63 +++++++++---------- .../kotlin/backend/konan/llvm/IrToBitcode.kt | 23 +++---- 2 files changed, 39 insertions(+), 47 deletions(-) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/DebugUtils.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/DebugUtils.kt index d820d8fcfc2..038466898df 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/DebugUtils.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/DebugUtils.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license * that can be found in the LICENSE file. */ @@ -9,18 +9,18 @@ import kotlinx.cinterop.allocArrayOf import kotlinx.cinterop.memScoped import llvm.* import org.jetbrains.kotlin.backend.konan.* -import org.jetbrains.kotlin.builtins.UnsignedTypes import org.jetbrains.kotlin.ir.SourceManager.FileEntry import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET import org.jetbrains.kotlin.ir.declarations.IrFunction +import org.jetbrains.kotlin.ir.types.IrType +import org.jetbrains.kotlin.ir.types.classOrNull import org.jetbrains.kotlin.ir.util.SYNTHETIC_OFFSET -import org.jetbrains.kotlin.js.descriptorUtils.getJetTypeFqName +import org.jetbrains.kotlin.ir.util.isTypeParameter +import org.jetbrains.kotlin.ir.util.isUnsigned +import org.jetbrains.kotlin.ir.util.render import org.jetbrains.kotlin.konan.CURRENT import org.jetbrains.kotlin.konan.KonanVersion import org.jetbrains.kotlin.konan.file.File -import org.jetbrains.kotlin.types.KotlinType -import org.jetbrains.kotlin.types.TypeUtils - internal object DWARF { val producer = "konanc ${KonanVersion.CURRENT} / kotlin-compiler: ${KotlinVersion.CURRENT}" @@ -65,19 +65,17 @@ internal class DebugInfo internal constructor(override val context: Context):Con val inlinedSubprograms = mutableMapOf() var builder: DIBuilderRef? = null var module: DIModuleRef? = null - var types = mutableMapOf() + var types = mutableMapOf() - val llvmTypes = mapOf( - context.builtIns.booleanType to context.llvm.llvmInt8, - context.builtIns.byteType to context.llvm.llvmInt8, - context.builtIns.charType to context.llvm.llvmInt8, - context.builtIns.shortType to context.llvm.llvmInt16, - context.builtIns.intType to context.llvm.llvmInt32, - context.builtIns.longType to context.llvm.llvmInt64, - context.builtIns.floatType to context.llvm.llvmFloat, - context.builtIns.doubleType to context.llvm.llvmDouble) - val intTypes = listOf(context.builtIns.byteType, context.builtIns.shortType, context.builtIns.intType, context.builtIns.longType) - val realTypes = listOf(context.builtIns.floatType, context.builtIns.doubleType) + val llvmTypes = mapOf( + context.irBuiltIns.booleanType to context.llvm.llvmInt8, + context.irBuiltIns.byteType to context.llvm.llvmInt8, + context.irBuiltIns.charType to context.llvm.llvmInt8, + context.irBuiltIns.shortType to context.llvm.llvmInt16, + context.irBuiltIns.intType to context.llvm.llvmInt32, + context.irBuiltIns.longType to context.llvm.llvmInt64, + context.irBuiltIns.floatType to context.llvm.llvmFloat, + context.irBuiltIns.doubleType to context.llvm.llvmDouble) val llvmTypeSizes = llvmTypes.map { it.key to LLVMSizeOfTypeInBits(llvmTargetData, it.value) }.toMap() val llvmTypeAlignments = llvmTypes.map {it.key to LLVMPreferredAlignmentOfType(llvmTargetData, it.value)}.toMap() val otherLlvmType = LLVMPointerType(LLVMInt64Type(), 0)!! @@ -159,13 +157,12 @@ internal fun generateDebugInfoHeader(context: Context) { } @Suppress("UNCHECKED_CAST") -internal fun KotlinType.dwarfType(context: Context, targetData: LLVMTargetDataRef): DITypeOpaqueRef { +internal fun IrType.dwarfType(context: Context, targetData: LLVMTargetDataRef): DITypeOpaqueRef { when { - this.computePrimitiveBinaryTypeOrNull() != null -> return debugInfoBaseType(context, targetData, this.getJetTypeFqName(false), llvmType(context), encoding(context).value.toInt()) + this.computePrimitiveBinaryTypeOrNull() != null -> return debugInfoBaseType(context, targetData, this.render(), llvmType(context), encoding(context).value.toInt()) else -> { - val classDescriptor = TypeUtils.getClassDescriptor(this) return when { - classDescriptor != null -> { + classOrNull != null -> { val type = DICreateStructType( refBuilder = context.debugInfo.builder, // TODO: here should be DIFile as scope. @@ -182,7 +179,7 @@ internal fun KotlinType.dwarfType(context: Context, targetData: LLVMTargetDataRe refPlace = null)!! as DITypeOpaqueRef dwarfPointerType(context, type) } - TypeUtils.isTypeParameter(this) -> //TODO: Type parameter, how to deal with if? + this.isTypeParameter() -> //TODO: Type parameter, how to deal with if? debugInfoBaseType(context, targetData, this.toString(), llvmType(context), encoding(context).value.toInt()) else -> TODO("$this: Does this case really exist?") } @@ -190,7 +187,7 @@ internal fun KotlinType.dwarfType(context: Context, targetData: LLVMTargetDataRe } } -internal fun KotlinType.diType(context: Context, llvmTargetData: LLVMTargetDataRef): DITypeOpaqueRef = +internal fun IrType.diType(context: Context, llvmTargetData: LLVMTargetDataRef): DITypeOpaqueRef = context.debugInfo.types.getOrPut(this) { dwarfType(context, llvmTargetData) } @@ -201,17 +198,17 @@ private fun debugInfoBaseType(context:Context, targetData:LLVMTargetDataRef, typ LLVMSizeOfTypeInBits(targetData, type), LLVMPreferredAlignmentOfType(targetData, type).toLong(), encoding) as DITypeOpaqueRef -internal val IrFunction.types:List +internal val IrFunction.types:List get() { - val parameters = descriptor.valueParameters.map{it.type} - return listOf(descriptor.returnType!!, *parameters.toTypedArray()) + val parameters = valueParameters.map { it.type } + return listOf(returnType, *parameters.toTypedArray()) } -internal fun KotlinType.size(context:Context) = context.debugInfo.llvmTypeSizes.getOrDefault(this, context.debugInfo.otherTypeSize) +internal fun IrType.size(context:Context) = context.debugInfo.llvmTypeSizes.getOrDefault(this, context.debugInfo.otherTypeSize) -internal fun KotlinType.alignment(context:Context) = context.debugInfo.llvmTypeAlignments.getOrDefault(this, context.debugInfo.otherTypeAlignment).toLong() +internal fun IrType.alignment(context:Context) = context.debugInfo.llvmTypeAlignments.getOrDefault(this, context.debugInfo.otherTypeAlignment).toLong() -internal fun KotlinType.llvmType(context:Context): LLVMTypeRef = context.debugInfo.llvmTypes.getOrElse(this) { +internal fun IrType.llvmType(context:Context): LLVMTypeRef = context.debugInfo.llvmTypes.getOrElse(this) { when(computePrimitiveBinaryTypeOrNull()) { PrimitiveBinaryType.BYTE -> context.llvm.llvmInt8 PrimitiveBinaryType.SHORT -> context.llvm.llvmInt16 @@ -223,14 +220,14 @@ internal fun KotlinType.llvmType(context:Context): LLVMTypeRef = context.debugIn } } -internal fun KotlinType.encoding(context: Context): DwarfTypeKind = when(computePrimitiveBinaryTypeOrNull()) { +internal fun IrType.encoding(context: Context): DwarfTypeKind = when(computePrimitiveBinaryTypeOrNull()) { PrimitiveBinaryType.FLOAT -> DwarfTypeKind.DW_ATE_float PrimitiveBinaryType.DOUBLE -> DwarfTypeKind.DW_ATE_float PrimitiveBinaryType.BOOLEAN -> DwarfTypeKind.DW_ATE_boolean PrimitiveBinaryType.POINTER -> DwarfTypeKind.DW_ATE_address else -> { //TODO: not recursive. - if (UnsignedTypes.isUnsignedType(this)) DwarfTypeKind.DW_ATE_unsigned + if (this.isUnsigned()) DwarfTypeKind.DW_ATE_unsigned else DwarfTypeKind.DW_ATE_signed } } @@ -242,7 +239,7 @@ internal fun IrFunction.subroutineType(context: Context, llvmTargetData: LLVMTar return subroutineType(context, llvmTargetData, types) } -internal fun subroutineType(context: Context, llvmTargetData: LLVMTargetDataRef, types: List): DISubroutineTypeRef { +internal fun subroutineType(context: Context, llvmTargetData: LLVMTargetDataRef, types: List): DISubroutineTypeRef { return memScoped { DICreateSubroutineType(context.debugInfo.builder, allocArrayOf( types.map { it.diType(context, llvmTargetData) }), diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt index 2accbb6ac9f..8b23b391b5d 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license * that can be found in the LICENSE file. */ @@ -11,21 +11,16 @@ import org.jetbrains.kotlin.backend.common.descriptors.allParameters import org.jetbrains.kotlin.backend.common.ir.ir2string import org.jetbrains.kotlin.backend.konan.* import org.jetbrains.kotlin.backend.konan.descriptors.* -import org.jetbrains.kotlin.backend.konan.descriptors.isArray import org.jetbrains.kotlin.backend.konan.ir.* -import org.jetbrains.kotlin.backend.konan.ir.NaiveSourceBasedFileEntryImpl -import org.jetbrains.kotlin.backend.konan.ir.containsNull -import org.jetbrains.kotlin.backend.konan.llvm.coverage.* -import org.jetbrains.kotlin.backend.konan.optimizations.* +import org.jetbrains.kotlin.backend.konan.llvm.coverage.LLVMCoverageInstrumentation +import org.jetbrains.kotlin.backend.konan.optimizations.DataFlowIR import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.builtins.UnsignedType import org.jetbrains.kotlin.descriptors.Modality -import org.jetbrains.kotlin.descriptors.PropertyDescriptor import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.IrStatement import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET import org.jetbrains.kotlin.ir.declarations.* -import org.jetbrains.kotlin.ir.descriptors.IrPropertyDelegateDescriptor import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.types.* import org.jetbrains.kotlin.ir.util.* @@ -615,7 +610,7 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map if (shouldGenerateDebugInfo(element)) debugInfoLocalVariableLocation( builder = context.debugInfo.builder, functionScope = locationInfo.scope, - diType = element.descriptor.type.diType(context, codegen.llvmTargetData), + diType = element.type.diType(context, codegen.llvmTargetData), name = element.descriptor.name, file = file, line = locationInfo.line, @@ -1183,7 +1178,7 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map debugInfoParameterLocation( builder = context.debugInfo.builder, functionScope = locationInfo.scope, - diType = element.descriptor.type.diType(context, codegen.llvmTargetData), + diType = element.type.diType(context, codegen.llvmTargetData), name = element.descriptor.name, argNo = function.allParameters.indexOf(element) + 1, file = file, @@ -1768,9 +1763,9 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map