Skip to content
This repository has been archived by the owner on Aug 10, 2021. It is now read-only.

Commit

Permalink
[codegen][debug info] use single compile unit for compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
vvlevchenko committed Feb 11, 2020
1 parent 8f7ebe7 commit 9905d40
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.ir.visitors.*
import org.jetbrains.kotlin.util.OperatorNameConventions
import kotlin.random.Random

internal val contextLLVMSetupPhase = makeKonanModuleOpPhase(
name = "ContextLLVMSetup",
Expand All @@ -34,6 +35,16 @@ internal val contextLLVMSetupPhase = makeKonanModuleOpPhase(
val llvmModule = LLVMModuleCreateWithNameInContext("out", llvmContext)!!
context.llvmModule = llvmModule
context.debugInfo.builder = LLVMCreateDIBuilder(llvmModule)
context.debugInfo.compilationUnit = if (context.shouldContainLocationDebugInfo()) DICreateCompilationUnit(
builder = context.debugInfo.builder,
lang = DWARF.language(context.config),
File = "kotlin-file-${Random.nextLong()}",
dir = "-",
producer = DWARF.producer,
isOptimized = 0,
flags = "",
rv = DWARF.runtimeVersion(context.config)) as DIScopeOpaqueRef?
else null
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ internal class DebugInfo internal constructor(override val context: Context):Con
val inlinedSubprograms = mutableMapOf<IrFunction, DISubprogramRef>()
var builder: DIBuilderRef? = null
var module: DIModuleRef? = null
var compilationUnit: DIScopeOpaqueRef? = null
var objHeaderPointerType: DITypeOpaqueRef? = null
var types = mutableMapOf<IrType, DITypeOpaqueRef>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import org.jetbrains.kotlin.konan.target.CompilerOutputKind
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.resolve.descriptorUtil.classId
import org.jetbrains.kotlin.resolve.descriptorUtil.module
import kotlin.random.Random

internal enum class FieldStorageKind {
MAIN_THREAD,
Expand Down Expand Up @@ -504,20 +505,8 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
context.llvm.objects.clear()
context.llvm.sharedObjects.clear()

val compilationUnit = if (context.shouldContainLocationDebugInfo()) {
val path = declaration.fileEntry.name.toFileAndFolder()
DICreateCompilationUnit(
builder = context.debugInfo.builder,
lang = DWARF.language(context.config),
File = path.file,
dir = path.folder,
producer = DWARF.producer,
isOptimized = 0,
flags = "",
rv = DWARF.runtimeVersion(context.config))
} else null
@Suppress("UNCHECKED_CAST")
using(FileScope(declaration, compilationUnit as DIScopeOpaqueRef?)) {
using(FileScope(declaration)) {
declaration.acceptChildrenVoid(this)

if (context.llvm.fileInitializers.isEmpty() && context.llvm.objects.isEmpty() && context.llvm.sharedObjects.isEmpty())
Expand Down Expand Up @@ -1768,7 +1757,7 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE

//-------------------------------------------------------------------------//

private open inner class FileScope(val file: IrFile, private val compilationUnit: DIScopeOpaqueRef? = null) : InnerScopeImpl() {
private open inner class FileScope(val file: IrFile) : InnerScopeImpl() {
override fun fileScope(): CodeContext? = this

override fun location(line: Int, column: Int) = scope()?.let { LocationInfo(it, line, column) }
Expand All @@ -1781,10 +1770,6 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
}

override fun scope() = scope
fun diCompilationUnit(): DIScopeOpaqueRef? = compilationUnit ?:
(this.outerContext.fileScope() as? FileScope)?.diCompilationUnit() ?:
error("no compilation unit found")

}

//-------------------------------------------------------------------------//
Expand Down Expand Up @@ -1992,7 +1977,7 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
@Suppress("UNCHECKED_CAST")
private fun diFunctionScope(name: String, linkageName: String, startLine: Int, subroutineType: DISubroutineTypeRef) = DICreateFunction(
builder = context.debugInfo.builder,
scope = (currentCodeContext.fileScope() as FileScope).diCompilationUnit(),
scope = context.debugInfo.compilationUnit,
name = name,
linkageName = linkageName,
file = file().file(),
Expand Down

0 comments on commit 9905d40

Please sign in to comment.