Added opt and llc configs for wasm32
This commit is contained in:
committed by
Sergey Bogolepov
parent
bb5dcc9111
commit
e397c1d73e
+23
-10
@@ -78,22 +78,35 @@ internal class LinkStage(val context: Context) {
|
||||
runTool(absoluteToolName, *arg)
|
||||
}
|
||||
|
||||
private fun hostLlvmTool(tool: String, args: List<String>) {
|
||||
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<BitcodeFile>): 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)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user