From e397c1d73e924b03ae730b8b2283931271c4f50c Mon Sep 17 00:00:00 2001 From: Sergey Bogolepov Date: Mon, 5 Feb 2018 09:23:05 +0300 Subject: [PATCH] Added opt and llc configs for wasm32 --- .../kotlin/backend/konan/LinkStage.kt | 33 +++++++++++++------ backend.native/konan.properties | 8 +++++ .../kotlin/konan/target/Configurables.kt | 12 ++++++- 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/LinkStage.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/LinkStage.kt index 9280911b7c8..fbcbcfb1474 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/LinkStage.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/LinkStage.kt @@ -78,22 +78,35 @@ internal class LinkStage(val context: Context) { runTool(absoluteToolName, *arg) } - private fun hostLlvmTool(tool: String, args: List) { + private fun hostLlvmTool(tool: String, vararg arg: String) { val absoluteToolName = "${platform.absoluteLlvmHome}/bin/$tool" - val command = listOf(absoluteToolName) + args - runTool(command) + runTool(absoluteToolName, *arg) } // TODO: pass different options llvm toolchain private fun bitcodeToWasm(bitcodeFiles: List): String { - val combinedBc = temporary("combined", ".bc") - hostLlvmTool("llvm-link", bitcodeFiles + listOf("-o", combinedBc)) - val internalizedBc = temporary("internalized", ".bc") - hostLlvmTool("opt", listOf(combinedBc, "-o", internalizedBc, "-internalize", "-O2")) - val combinedS = temporary("combined", ".s") - targetTool("llc", internalizedBc, "-o", combinedS) + val configurables = platform.configurables as WasmConfigurables - val s2wasmFlags = (platform.configurables as WasmConfigurables).s2wasmFlags.toTypedArray() + val combinedBc = temporary("combined", ".bc") + hostLlvmTool("llvm-link", *bitcodeFiles.toTypedArray(), "-o", combinedBc) + + val optFlags = (configurables.optFlags + when { + optimize -> configurables.optOptFlags + debug -> configurables.optDebugFlags + else -> configurables.optNooptFlags + }).toTypedArray() + val optimizedBc = temporary("optimized", ".bc") + hostLlvmTool("opt", combinedBc, "-o", optimizedBc, *optFlags) + + val llcFlags = (configurables.llcFlags + when { + optimize -> configurables.llcOptFlags + debug -> configurables.llcDebugFlags + else -> configurables.llcNooptFlags + }).toTypedArray() + val combinedS = temporary("combined", ".s") + targetTool("llc", optimizedBc, "-o", combinedS, *llcFlags) + + val s2wasmFlags = configurables.s2wasmFlags.toTypedArray() val combinedWast = temporary( "combined", ".wast") targetTool("s2wasm", combinedS, "-o", combinedWast, *s2wasmFlags) diff --git a/backend.native/konan.properties b/backend.native/konan.properties index eb9e75acb0a..4fc51c6a722 100644 --- a/backend.native/konan.properties +++ b/backend.native/konan.properties @@ -321,5 +321,13 @@ dependencies.mingw-wasm32 = \ quadruple.wasm32 = wasm32 llvmLtoFlags.wasm32 = targetSysRoot.wasm32 = target-sysroot-2-wasm +optFlags.wasm32 = -internalize +optNooptFlags.wasm32 = -O1 +optOptFlags.wasm32 = -O3 +optDebugFlags.wasm32 = +llcFlags.wasm32 = +llcNooptFlags.wasm32 = -O1 +llcOptFlags.wasm32 = -O3 +llcDebugFlags.wasm32 = # The stack size is in bytes. s2wasmFlags.wasm32 = --allocate-stack 1048576 --import-memory diff --git a/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/Configurables.kt b/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/Configurables.kt index 95760855789..c4b70f6214b 100644 --- a/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/Configurables.kt +++ b/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/Configurables.kt @@ -76,5 +76,15 @@ interface RaspberryPiConfigurables : LinuxBasedConfigurables interface AndroidConfigurables : NonAppleConfigurables interface WasmConfigurables : NonAppleConfigurables { - val s2wasmFlags get() = targetList("s2wasmFlags") + val s2wasmFlags get() = targetList("s2wasmFlags") + + val llcFlags get() = targetList("llcFlags") + val llcNooptFlags get() = targetList("llcNooptFlags") + val llcOptFlags get() = targetList("llcOptFlags") + val llcDebugFlags get() = targetList("llcDebugFlags") + + val optFlags get() = targetList("optFlags") + val optNooptFlags get() = targetList("optNooptFlags") + val optOptFlags get() = targetList("optOptFlags") + val optDebugFlags get() = targetList("optDebugFlags") }