diff options
author | Johnny Richard <johnny@johnnyrichard.com> | 2023-04-30 19:16:42 +0200 |
---|---|---|
committer | Johnny Richard <johnny@johnnyrichard.com> | 2023-04-30 19:26:30 +0200 |
commit | b1e8b4f24927efc6ed68420e4f579fb20ab831a9 (patch) | |
tree | 119496bacb2758cee773138f0bd3a452c8b6ec60 /src/gas_assembly_generator.h | |
parent | efe28f579b8720ea506a4e5d24ec0290223b8745 (diff) |
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 <johnny@johnnyrichard.com>
Co-authored-by: Carlos Maniero <carlosmaniero@gmail.com>
Diffstat (limited to 'src/gas_assembly_generator.h')
-rw-r--r-- | src/gas_assembly_generator.h | 2 |
1 files changed, 2 insertions, 0 deletions
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 |