Don't save stack frame if function does no calls

This commit is contained in:
Bananymous 2024-04-29 22:21:09 +03:00
parent e70b078b35
commit 8bd65f4c05
1 changed files with 11 additions and 3 deletions

View File

@ -586,9 +586,16 @@ class CompileData:
break
saved_registers = list(saved_registers)
does_call = False
for instruction in code:
if instruction.opcode == 'call':
does_call = True
break
code_str += name + ':\n'
code_str += ' pushq %rbp\n'
code_str += ' movq %rsp, %rbp\n'
if does_call:
code_str += ' pushq %rbp\n'
code_str += ' movq %rsp, %rbp\n'
for reg in saved_registers:
code_str += f' pushq {reg}\n'
if len(saved_registers) % 2 != 0:
@ -602,7 +609,8 @@ class CompileData:
code_str += ' addq $8, %rsp\n'
for reg in reversed(saved_registers):
code_str += f' popq {reg}\n'
code_str += ' leave\n'
if does_call:
code_str += ' leave\n'
code_str += ' ret\n'
code_str += '\n'