[codegenerator][refactor] extract method for tramboline generation

This commit is contained in:
Vasily Levchenko
2021-06-07 13:17:44 +02:00
parent 0651f7de20
commit 79600f32d2
7 changed files with 22 additions and 41 deletions
@@ -169,21 +169,12 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
null
}
})
putIfNotNull(GENERATE_INLINED_FUNCTION_BODY_MARKER, when (val it = arguments.generateInlinedFunctionMarkerString) {
putIfNotNull(GENERATE_DEBUG_TRAMPOLINE, when (val it = arguments.generateDebugTrampolineString) {
"enable" -> true
"disable" -> false
null -> null
else -> {
configuration.report(ERROR, "Unsupported -Xg-generate-inline-function-body-marker= value: $it. Possible values are 'enable'/'disable'")
null
}
})
putIfNotNull(GENERATE_WHEN_MARKER, when (val it = arguments.generateWhenMarkerString) {
"enable" -> true
"disable" -> false
null -> null
else -> {
configuration.report(ERROR, "Unsupported -Xg-generate-when-marker= value: $it. Possible values are 'enable'/'disable'")
configuration.report(ERROR, "Unsupported -Xg-generate-debug-tramboline= value: $it. Possible values are 'enable'/'disable'")
null
}
})
@@ -166,17 +166,11 @@ class K2NativeCompilerArguments : CommonCompilerArguments() {
var lightDebugDeprecated: Boolean = false
@Argument(
value = "-Xg-generate-inline-function-body-marker",
value = "-Xg-generate-debug-trampoline",
valueDescription = "{disable|enable}",
description = """generates marker of inlined function body on call site to make debugger breakpoint resolution more accurate"""
description = """generates trampolines to make debugger breakpoint resolution more accurate (inlines, when, etc.)"""
)
var generateInlinedFunctionMarkerString: String? = null
@Argument(
value = "-Xg-generate-when-marker",
valueDescription = "{disable|enable}",
description = """generates marker of when to make debugger breakpoint resolution more accurate"""
)
var generateWhenMarkerString: String? = null
var generateDebugTrampolineString: String? = null
@Argument(
@@ -43,8 +43,7 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration
val debug: Boolean get() = configuration.getBoolean(KonanConfigKeys.DEBUG)
val lightDebug: Boolean = configuration.get(KonanConfigKeys.LIGHT_DEBUG)
?: target.family.isAppleFamily // Default is true for Apple targets.
val generateInlinedBodyTrampoline = debug && configuration.get(KonanConfigKeys.GENERATE_INLINED_FUNCTION_BODY_MARKER) ?: false
val generateWhenTrampoline = debug && configuration.get(KonanConfigKeys.GENERATE_WHEN_MARKER) ?: false
val generateDebugTrampoline = debug && configuration.get(KonanConfigKeys.GENERATE_DEBUG_TRAMPOLINE) ?: false
val memoryModel: MemoryModel get() = configuration.get(KonanConfigKeys.MEMORY_MODEL)!!
val destroyRuntimeMode: DestroyRuntimeMode get() = configuration.get(KonanConfigKeys.DESTROY_RUNTIME_MODE)!!
@@ -56,10 +56,8 @@ class KonanConfigKeys {
= CompilerConfigurationKey.create("library version")
val LIGHT_DEBUG: CompilerConfigurationKey<Boolean?>
= CompilerConfigurationKey.create("add light debug information")
val GENERATE_INLINED_FUNCTION_BODY_MARKER: CompilerConfigurationKey<Boolean?>
= CompilerConfigurationKey.create("generates inlined function body marker on call site")
val GENERATE_WHEN_MARKER: CompilerConfigurationKey<Boolean?>
= CompilerConfigurationKey.create("generates when marker on call site")
val GENERATE_DEBUG_TRAMPOLINE: CompilerConfigurationKey<Boolean?>
= CompilerConfigurationKey.create("generates debug trampolines to make debugger breakpoint resolution more accurate")
val LINKER_ARGS: CompilerConfigurationKey<List<String>>
= CompilerConfigurationKey.create("additional linker arguments")
val LIST_PHASES: CompilerConfigurationKey<Boolean>
@@ -1177,12 +1177,7 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
val whenEmittingContext = WhenEmittingContext(expression)
val generationContext = (currentCodeContext.functionScope() as? FunctionScope)?.functionGenerationContext
.takeIf { context.config.generateWhenTrampoline }
generationContext?.basicBlock("when", expression.startLocation)?.let {
generationContext.br(it)
generationContext.positionAtEnd(it)
}
generateDebugTrambolineIf("when", expression)
expression.branches.forEach {
val bbNext = if (it == expression.branches.last())
null
@@ -1202,6 +1197,15 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
}
}
private fun generateDebugTrambolineIf(name: String, expression: IrExpression) {
val generationContext = (currentCodeContext.functionScope() as? FunctionScope)?.functionGenerationContext
.takeIf { context.config.generateDebugTrampoline }
generationContext?.basicBlock(name, expression.startLocation)?.let {
generationContext.br(it)
generationContext.positionAtEnd(it)
}
}
private fun generateWhenCase(whenEmittingContext: WhenEmittingContext, branch: IrBranch, bbNext: LLVMBasicBlockRef?) {
val brResult = if (isUnconditional(branch))
evaluateExpression(branch.result)
@@ -1824,12 +1828,7 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
context.log{"evaluateReturnableBlock : ${value.statements.forEach { ir2string(it) }}"}
val returnableBlockScope = ReturnableBlockScope(value)
val generationContext = (currentCodeContext.functionScope() as? FunctionScope)?.functionGenerationContext
.takeIf { context.config.generateInlinedBodyTrampoline }
generationContext?.basicBlock("inline", value.startLocation)?.let {
generationContext.br(it)
generationContext.positionAtEnd(it)
}
generateDebugTrambolineIf("inline", value)
using(returnableBlockScope) {
using(VariableScope()) {
value.statements.forEach {
@@ -2413,7 +2413,7 @@ standaloneTest("check_stacktrace_format") {
standaloneTest("stack_trace_inline") {
// TODO: Enable after the test has been fixed.
disabled = !isAppleTarget(project) || project.globalTestArgs.contains('-opt') || (project.testTarget == 'ios_arm64')
flags = ['-g', '-Xg-generate-inline-function-body-marker=enable']
flags = ['-g', '-Xg-generate-debug-trampoline=enable']
source = "runtime/exceptions/stack_trace_inline.kt"
}
@@ -164,7 +164,7 @@ class LldbTests {
|fun main(args: Array<String>) {
| println(question("Subject", args))
|}
""".trimMargin().binary("kt33055", "-g", "-Xg-generate-inline-function-body-marker=enable")
""".trimMargin().binary("kt33055", "-g", "-Xg-generate-debug-trampoline=enable")
"""
> b 2
Breakpoint 1: where = [..]`kfun:#question(kotlin.String;kotlin.Array<kotlin.String>){}kotlin.String [..] at kt33055.kt:2:12, [..]
@@ -192,7 +192,7 @@ class LldbTests {
| else -> print("C")
| }
|}
""".trimMargin().binary("kt33364", "-g", "-Xg-generate-when-marker=enable")
""".trimMargin().binary("kt33364", "-g", "-Xg-generate-debug-trampoline=enable")
"""
> b 5
Breakpoint 1: where = [..]kfun:#main(){} [..] at kt33364.kt:5:[..]