[K/N] Don't land parameters on stack in release mode

This commit is contained in:
Elena Lepilkina
2021-12-08 15:19:31 +00:00
committed by Space
parent b9a56f4888
commit f4830716bc
2 changed files with 14 additions and 6 deletions
@@ -687,11 +687,16 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
init {
if (function != null) {
parameters.forEach{
parameters.forEach {
val parameter = it.key
val local = functionGenerationContext.vars.createParameter(
parameter, debugInfoIfNeeded(function, parameter))
functionGenerationContext.mapParameterForDebug(local, it.value)
if (context.shouldContainDebugInfo()) {
val local = functionGenerationContext.vars.createParameterOnStack(
parameter, debugInfoIfNeeded(function, parameter))
functionGenerationContext.mapParameterForDebug(local, it.value)
} else {
functionGenerationContext.vars.createParameter(parameter, it.value)
}
}
}
}
@@ -33,7 +33,7 @@ internal class VariableManager(val functionGenerationContext: FunctionGeneration
}
inner class ParameterRecord(val address: LLVMValueRef, val refSlot: Boolean) : Record {
override fun load() : LLVMValueRef = functionGenerationContext.loadSlot(address, false)
override fun load(): LLVMValueRef = functionGenerationContext.loadSlot(address, false)
override fun store(value: LLVMValueRef) = functionGenerationContext.store(value, address)
override fun address() : LLVMValueRef = this.address
override fun toString() = (if (refSlot) "refslot" else "slot") + " for ${address}"
@@ -85,7 +85,7 @@ internal class VariableManager(val functionGenerationContext: FunctionGeneration
}
internal var skipSlots = 0
internal fun createParameter(valueDeclaration: IrValueDeclaration, variableLocation: VariableDebugLocation?) : Int {
internal fun createParameterOnStack(valueDeclaration: IrValueDeclaration, variableLocation: VariableDebugLocation?): Int {
assert(!contextVariablesToIndex.contains(valueDeclaration))
val index = variables.size
val type = functionGenerationContext.getLLVMType(valueDeclaration.type)
@@ -99,6 +99,9 @@ internal class VariableManager(val functionGenerationContext: FunctionGeneration
return index
}
internal fun createParameter(valueDeclaration: IrValueDeclaration, value: LLVMValueRef) =
createImmutable(valueDeclaration, value)
// Creates anonymous mutable variable.
// Think of slot reuse.
fun createAnonymousSlot(value: LLVMValueRef? = null) : LLVMValueRef {