diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/CompilerOutput.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/CompilerOutput.kt index 9ff37a999fa..cdee94ed6a9 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/CompilerOutput.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/CompilerOutput.kt @@ -4,6 +4,10 @@ */ package org.jetbrains.kotlin.backend.konan +import kotlinx.cinterop.alloc +import kotlinx.cinterop.memScoped +import kotlinx.cinterop.ptr +import kotlinx.cinterop.toKStringFromUtf8 import llvm.* import org.jetbrains.kotlin.backend.common.serialization.KlibIrVersion import org.jetbrains.kotlin.backend.common.serialization.metadata.KlibMetadataVersion @@ -52,6 +56,17 @@ internal fun produceCStubs(context: Context) { ).forEach { parseAndLinkBitcodeFile(context, llvmModule, it.absolutePath) } + // TODO: Consider adding LLVM_IR compiler output kind. + if (context.configuration.getBoolean(KonanConfigKeys.SAVE_LLVM_IR)) { + val moduleName: String = memScoped { + val sizeVar = alloc() + LLVMGetModuleIdentifier(context.llvmModule, sizeVar.ptr)!!.toKStringFromUtf8() + } + val output = context.config.tempFiles.create(moduleName,".ll") + if (LLVMPrintModuleToFile(context.llvmModule, output.absolutePath, null) != 0) { + error("Can't dump LLVM IR to ${output.absolutePath}") + } + } } private fun linkAllDependencies(context: Context, generatedBitcodeFiles: List) { diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/BitcodePhases.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/BitcodePhases.kt index 1b2518af1e6..bdbfdf49b46 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/BitcodePhases.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/BitcodePhases.kt @@ -5,10 +5,6 @@ package org.jetbrains.kotlin.backend.konan.llvm -import kotlinx.cinterop.alloc -import kotlinx.cinterop.memScoped -import kotlinx.cinterop.ptr -import kotlinx.cinterop.toKStringFromUtf8 import llvm.* import org.jetbrains.kotlin.backend.common.phaser.CompilerPhase import org.jetbrains.kotlin.backend.common.phaser.PhaseConfig @@ -327,17 +323,6 @@ internal val codegenPhase = makeKonanModuleOpPhase( description = "Code generation", op = { context, irModule -> irModule.acceptVoid(context.codegenVisitor) - // TODO: Consider adding LLVM_IR compiler output kind. - if (context.configuration.getBoolean(KonanConfigKeys.SAVE_LLVM_IR)) { - val moduleName: String = memScoped { - val sizeVar = alloc() - LLVMGetModuleIdentifier(context.llvmModule, sizeVar.ptr)!!.toKStringFromUtf8() - } - val output = context.config.tempFiles.create(moduleName,".ll") - if (LLVMPrintModuleToFile(context.llvmModule, output.absolutePath, null) != 0) { - error("Can't dump LLVM IR to ${output.absolutePath}") - } - } } )