From b1e8b4f24927efc6ed68420e4f579fb20ab831a9 Mon Sep 17 00:00:00 2001 From: Johnny Richard Date: Sun, 30 Apr 2023 19:16:42 +0200 Subject: gas: Optimize variable reference on assembly We were moving the stack data for variable reference to another stack position ending up with two pointer to the same value. // a: i32 = 1; mov $1, -8(%rbp) // b: i32 = a; mov -8(%rbp), %rax mov %rax, -24(%rbp) mov -24(%rbp), %rax mov %rax, -16(%rbp) After this changes, we wont create a new temp space on stack if we don't need it. See bellow the example after the optimization: // a: i32 = 1; mov $1, -8(%rbp) // b: i32 = a; mov -8(%rbp), %rax mov %rax, -16(%rbp) Signed-off-by: Johnny Richard Co-authored-by: Carlos Maniero --- src/gas_assembly_generator.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/gas_assembly_generator.h') diff --git a/src/gas_assembly_generator.h b/src/gas_assembly_generator.h index 8501a67..92972f9 100644 --- a/src/gas_assembly_generator.h +++ b/src/gas_assembly_generator.h @@ -25,12 +25,14 @@ typedef enum evaluation_result_kind_t { EVALUATION_RESULT_VOID, EVALUATION_RESULT_ON_RAX, + EVALUATION_RESULT_ON_STACK, EVALUATION_RESULT_AS_LITERAL_INTEGER } evaluation_result_kind_t; typedef union evaluation_result_data_t { int64_t literal_int; + int stack_offset; } evaluation_result_data_t; typedef struct evaluation_result_t -- cgit v1.2.3