[KT-42234] Moved optimization flags to konan.properties
Combined with KT-40670, it simplifies tuning of LLVM optimization and compilation pipeline.
This commit is contained in:
committed by
Stanislav Erokhin
parent
e2cb099d2b
commit
431a7c9ba9
+12
-49
@@ -9,7 +9,6 @@ import org.jetbrains.kotlin.backend.konan.llvm.makeVisibilityHiddenLikeLlvmInter
|
||||
import org.jetbrains.kotlin.konan.target.CompilerOutputKind
|
||||
import org.jetbrains.kotlin.konan.target.Configurables
|
||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||
import org.jetbrains.kotlin.konan.target.ZephyrConfigurables
|
||||
|
||||
private fun initializeLlvmGlobalPassRegistry() {
|
||||
val passRegistry = LLVMGetGlobalPassRegistry()
|
||||
@@ -46,53 +45,26 @@ private class LlvmPipelineConfiguration(context: Context) {
|
||||
|
||||
val targetTriple: String = context.llvm.targetTriple
|
||||
|
||||
// Some of these values are copied from corresponding runtime.bc
|
||||
// which is using "generic" target CPU for many case.
|
||||
// This approach is suboptimal because target-cpu="generic" limits
|
||||
// the set of used cpu features.
|
||||
// TODO: refactor KonanTarget so that we can explicitly specify
|
||||
// target cpu or arch+features combination in a single place.
|
||||
val cpuModel: String = when (target) {
|
||||
KonanTarget.IOS_ARM32 -> "generic"
|
||||
KonanTarget.IOS_ARM64 -> "cyclone"
|
||||
KonanTarget.IOS_X64 -> "core2"
|
||||
KonanTarget.TVOS_ARM64 -> "cyclone"
|
||||
KonanTarget.TVOS_X64 -> "core2"
|
||||
KonanTarget.WATCHOS_X86 -> "i386"
|
||||
KonanTarget.WATCHOS_X64 -> "core2"
|
||||
KonanTarget.WATCHOS_ARM64,
|
||||
KonanTarget.WATCHOS_ARM32 -> "cortex-a7"
|
||||
KonanTarget.LINUX_X64 -> "x86-64"
|
||||
KonanTarget.MINGW_X86 -> "pentium4"
|
||||
KonanTarget.MINGW_X64 -> "x86-64"
|
||||
KonanTarget.MACOS_X64 -> "core2"
|
||||
KonanTarget.LINUX_ARM32_HFP -> "arm1136jf-s"
|
||||
KonanTarget.LINUX_ARM64 -> "generic"
|
||||
KonanTarget.ANDROID_ARM32 -> "arm7tdmi"
|
||||
KonanTarget.ANDROID_ARM64 -> "cortex-a57"
|
||||
KonanTarget.ANDROID_X64 -> "x86-64"
|
||||
KonanTarget.ANDROID_X86 -> "i686"
|
||||
KonanTarget.LINUX_MIPS32 -> "mips32r2"
|
||||
KonanTarget.LINUX_MIPSEL32 -> "mips32r2"
|
||||
KonanTarget.WASM32 -> "generic"
|
||||
is KonanTarget.ZEPHYR -> (configurables as ZephyrConfigurables).targetCpu ?: run {
|
||||
context.reportCompilationWarning("targetCpu for target $target was not set. Targeting `generic` cpu.")
|
||||
"generic"
|
||||
}
|
||||
val cpuModel: String = configurables.targetCpu ?: run {
|
||||
context.reportCompilationWarning("targetCpu for target $target was not set. Targeting `generic` cpu.")
|
||||
"generic"
|
||||
}
|
||||
|
||||
val cpuFeatures: String = when (target) {
|
||||
KonanTarget.LINUX_ARM32_HFP -> "+dsp,+strict-align,+vfp2,-crypto,-d16,-fp-armv8,-fp-only-sp,-fp16,-neon,-thumb-mode,-vfp3,-vfp4"
|
||||
KonanTarget.ANDROID_ARM32 -> "+soft-float,+strict-align,-crypto,-neon,-thumb-mode"
|
||||
else -> ""
|
||||
}
|
||||
val cpuFeatures: String = configurables.targetCpuFeatures ?: ""
|
||||
|
||||
/**
|
||||
* Null value means that LLVM should use default inliner params
|
||||
* for the provided optimization and size level.
|
||||
*/
|
||||
val customInlineThreshold: Int? = when {
|
||||
context.shouldOptimize() -> INLINE_THRESHOLD_OPT
|
||||
context.shouldOptimize() -> configurables.llvmInlineThreshold?.let {
|
||||
it.toIntOrNull() ?: run {
|
||||
context.reportCompilationWarning(
|
||||
"`llvmInlineThreshold` should be an integer. Got `$it` instead. Using default value."
|
||||
)
|
||||
null
|
||||
}
|
||||
}
|
||||
context.shouldContainDebugInfo() -> null
|
||||
else -> null
|
||||
}
|
||||
@@ -122,15 +94,6 @@ private class LlvmPipelineConfiguration(context: Context) {
|
||||
|
||||
val codeModel: LLVMCodeModel = LLVMCodeModel.LLVMCodeModelDefault
|
||||
|
||||
companion object {
|
||||
// By default LLVM uses 250 for -03 builds.
|
||||
// We use a smaller value since default value leads to
|
||||
// unreasonably bloated runtime code without any measurable
|
||||
// performance benefits.
|
||||
// This value still has to be tuned for different targets, though.
|
||||
private const val INLINE_THRESHOLD_OPT = 100
|
||||
}
|
||||
|
||||
enum class LlvmOptimizationLevel(val value: Int) {
|
||||
NONE(0),
|
||||
DEFAULT(1),
|
||||
|
||||
Reference in New Issue
Block a user