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

[codegen][debug info] use single compile unit for compilation #3853

Merged
merged 4 commits into from
Mar 4, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import org.jetbrains.kotlin.ir.IrStatement
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.ir.visitors.*
import org.jetbrains.kotlin.konan.file.File
import org.jetbrains.kotlin.util.OperatorNameConventions

internal val contextLLVMSetupPhase = makeKonanModuleOpPhase(
Expand All @@ -33,6 +34,17 @@ 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 = File(context.config.outputFile).absolutePath,
vvlevchenko marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -504,20 +504,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 +1756,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 +1769,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 @@ -1988,7 +1972,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