[LLVM][Optimizations] Replace magic numbers with constants.
This commit is contained in:
committed by
Sergey Bogolepov
parent
767515cdcc
commit
02e53f95f8
+38
-12
@@ -85,24 +85,29 @@ private class LlvmPipelineConfiguration(context: Context) {
|
||||
else -> ""
|
||||
}
|
||||
|
||||
/**
|
||||
* Null value means that LLVM should use default inliner params
|
||||
* for the provided optimization and size level.
|
||||
*/
|
||||
val customInlineThreshold: Int? = when {
|
||||
context.shouldOptimize() -> 100
|
||||
context.shouldOptimize() -> INLINE_THRESHOLD_OPT
|
||||
context.shouldContainDebugInfo() -> null
|
||||
else -> null
|
||||
}
|
||||
|
||||
val optimizationLevel: Int = when {
|
||||
context.shouldOptimize() -> 3
|
||||
context.shouldContainDebugInfo() -> 0
|
||||
else -> 1
|
||||
val optimizationLevel: LlvmOptimizationLevel = when {
|
||||
context.shouldOptimize() -> LlvmOptimizationLevel.AGGRESSIVE
|
||||
context.shouldContainDebugInfo() -> LlvmOptimizationLevel.NONE
|
||||
else -> LlvmOptimizationLevel.DEFAULT
|
||||
}
|
||||
|
||||
val sizeLevel: Int = when {
|
||||
val sizeLevel: LlvmSizeLevel = when {
|
||||
// We try to optimize code as much as possible on embedded targets.
|
||||
target is KonanTarget.ZEPHYR ||
|
||||
target == KonanTarget.WASM32 -> 3
|
||||
context.shouldOptimize() -> 0
|
||||
context.shouldContainDebugInfo() -> 0
|
||||
else -> 0
|
||||
target == KonanTarget.WASM32 -> LlvmSizeLevel.AGGRESSIVE
|
||||
context.shouldOptimize() -> LlvmSizeLevel.NONE
|
||||
context.shouldContainDebugInfo() -> LlvmSizeLevel.NONE
|
||||
else -> LlvmSizeLevel.NONE
|
||||
}
|
||||
|
||||
val codegenOptimizationLevel: LLVMCodeGenOptLevel = when {
|
||||
@@ -114,6 +119,27 @@ private class LlvmPipelineConfiguration(context: Context) {
|
||||
val relocMode: LLVMRelocMode = LLVMRelocMode.LLVMRelocDefault
|
||||
|
||||
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),
|
||||
AGGRESSIVE(3)
|
||||
}
|
||||
|
||||
enum class LlvmSizeLevel(val value: Int) {
|
||||
NONE(0),
|
||||
DEFAULT(1),
|
||||
AGGRESSIVE(2)
|
||||
}
|
||||
}
|
||||
|
||||
internal fun runLlvmOptimizationPipeline(context: Context) {
|
||||
@@ -126,8 +152,8 @@ internal fun runLlvmOptimizationPipeline(context: Context) {
|
||||
initializeLlvmGlobalPassRegistry()
|
||||
val passBuilder = LLVMPassManagerBuilderCreate()
|
||||
val modulePasses = LLVMCreatePassManager()
|
||||
LLVMPassManagerBuilderSetOptLevel(passBuilder, config.optimizationLevel)
|
||||
LLVMPassManagerBuilderSetSizeLevel(passBuilder, config.sizeLevel)
|
||||
LLVMPassManagerBuilderSetOptLevel(passBuilder, config.optimizationLevel.value)
|
||||
LLVMPassManagerBuilderSetSizeLevel(passBuilder, config.sizeLevel.value)
|
||||
// TODO: use LLVMGetTargetFromName instead.
|
||||
val target = alloc<LLVMTargetRefVar>()
|
||||
val foundLlvmTarget = LLVMGetTargetFromTriple(config.targetTriple, target.ptr, null) == 0
|
||||
|
||||
Reference in New Issue
Block a user