Native: don't use frame pointer in leaf functions on ARM64 targets
Clang 8 and Clang 11 both have this optimization, but it was moved from LLVM to Clang: https://github.com/llvm/llvm-project/compare/c5b890e922432bd80a5e3c6d82994ef4cdc41900...a0aa58dad53f2e5e90a9b7079ec31bf7c3144fc7 So Kotlin/Native compiler now has to enable this optimization explicitly.
This commit is contained in:
committed by
Space
parent
2b6d8ab975
commit
a4b9e2502c
+20
-3
@@ -11,7 +11,9 @@ import org.jetbrains.kotlin.ir.declarations.IrConstructor
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||
import org.jetbrains.kotlin.ir.types.isNothing
|
||||
import org.jetbrains.kotlin.ir.util.isThrowable
|
||||
import org.jetbrains.kotlin.konan.target.Architecture
|
||||
import org.jetbrains.kotlin.konan.target.Family
|
||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||
|
||||
internal fun addLlvmFunctionWithDefaultAttributes(
|
||||
context: Context,
|
||||
@@ -29,7 +31,7 @@ internal fun addLlvmFunctionWithDefaultAttributes(
|
||||
private fun addDefaultLlvmFunctionAttributes(context: Context, llvmFunction: LLVMValueRef) {
|
||||
if (shouldEnforceFramePointer(context)) {
|
||||
// Note: this is default for clang on at least on iOS and macOS.
|
||||
enforceFramePointer(llvmFunction)
|
||||
enforceFramePointer(llvmFunction, context)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,6 +68,21 @@ private fun shouldEnforceFramePointer(context: Context): Boolean {
|
||||
}
|
||||
}
|
||||
|
||||
private fun enforceFramePointer(llvmFunction: LLVMValueRef) {
|
||||
LLVMAddTargetDependentFunctionAttr(llvmFunction, "frame-pointer", "all")
|
||||
private fun enforceFramePointer(llvmFunction: LLVMValueRef, context: Context) {
|
||||
val target = context.config.target
|
||||
|
||||
// Matches Clang behaviour.
|
||||
val omitLeafFp = when {
|
||||
target == KonanTarget.WATCHOS_ARM64 -> false
|
||||
target.architecture == Architecture.ARM64 -> true
|
||||
else -> false
|
||||
}
|
||||
|
||||
val fpKind = if (omitLeafFp) {
|
||||
"non-leaf"
|
||||
} else {
|
||||
"all"
|
||||
}
|
||||
|
||||
LLVMAddTargetDependentFunctionAttr(llvmFunction, "frame-pointer", fpKind)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user