- 在HIR函数元数据中添加defined字段来标记函数是否已定义 - 在AST到IR转换过程中设置函数定义状态 - 修改LIR模块函数声明接口以支持定义状态参数 - 实现直接调用和间接调用的区别处理,通过符号查找确定调用类型 - 更新LIR调用指令结构以支持直接和间接调用的不同表示方式 - 调整x86后端指令选择以正确处理不同类型的调用 fix(x86-isel): 优化x86指令发射和操作数大小处理 - 移除move/load/store函数中的size参数,改由操作数本身携带大小信息 - 简化x86指令操作数结构,减少操作数数量限制 - 添加专门的mov系列表单选择函数,根据操作数类型和大小自动选择正确的指令形式 - 修正间接调用的指令形式为CALL_NEAR_MEMV而非GPRV - 添加向量版本的load/store/move发射函数 refactor(reg-alloc): 更新寄存器分配迭代器接口 - 为分配迭代器的替换方法添加size参数,以便正确处理不同大小的寄存器
77 lines
3.3 KiB
C
77 lines
3.3 KiB
C
#ifndef __SCC_X86_ISEL_H__
|
|
#define __SCC_X86_ISEL_H__
|
|
|
|
#include <scc_lir_module.h>
|
|
#include <scc_tree_dump.h>
|
|
|
|
#include "../core_pass/scc_abi_lowering.h"
|
|
#include "scc_x86_mir.h"
|
|
|
|
typedef struct scc_x86_64_isel {
|
|
scc_mir_x86_instr_vec_t instrs;
|
|
scc_mir_func_t *func;
|
|
scc_pos_t pos;
|
|
scc_abi_lowering_t abi_lowering;
|
|
} scc_x86_64_isel_t;
|
|
|
|
void scc_isel_x86_64(scc_mir_module_t *mir_module,
|
|
const scc_lir_module_t *lir_module,
|
|
scc_x86_64_isel_t *isel);
|
|
|
|
// Utils
|
|
void scc_x86_emit_move(scc_x86_64_isel_t *isel, scc_x86_operand_value_t dst_reg,
|
|
scc_x86_operand_value_t src);
|
|
void scc_x86_emit_load(scc_x86_64_isel_t *isel, scc_x86_operand_value_t dst,
|
|
scc_x86_operand_value_t src);
|
|
void scc_x86_emit_store(scc_x86_64_isel_t *isel, scc_x86_operand_value_t dst,
|
|
scc_x86_operand_value_t src);
|
|
scc_x86_operand_value_t scc_x86_lir_val_to_mir_op(scc_x86_64_isel_t *isel,
|
|
const scc_lir_val_t *val,
|
|
u8 size);
|
|
|
|
static inline void emit_direct_call(scc_x86_64_isel_t *isel,
|
|
const char *callee) {
|
|
scc_mir_x86_instr_t instr = {0};
|
|
scc_x86_operand_value_t op = scc_x86_op_reloc_global_relbr(callee, 0);
|
|
scc_mir_x86_instr_1(&instr, SCC_X86_IFORM_CALL_NEAR_RELBRZ, op,
|
|
scc_pos_create());
|
|
scc_vec_push(isel->instrs, instr);
|
|
}
|
|
|
|
static inline void emit_indirect_call(scc_x86_64_isel_t *isel,
|
|
scc_x86_operand_value_t mem) {
|
|
scc_mir_x86_instr_t instr = {0};
|
|
scc_mir_x86_instr_1(&instr, SCC_X86_IFORM_CALL_NEAR_MEMV, mem,
|
|
scc_pos_create());
|
|
scc_vec_push(isel->instrs, instr);
|
|
}
|
|
|
|
static inline void emit_ret(scc_x86_64_isel_t *isel) {
|
|
scc_mir_x86_instr_t instr = {0};
|
|
scc_mir_x86_instr_0(&instr, SCC_X86_IFORM_RET_NEAR, scc_pos_create());
|
|
scc_vec_push(isel->instrs, instr);
|
|
}
|
|
|
|
#define add_instr_0(isel, iform) \
|
|
do { \
|
|
scc_mir_x86_instr_t instr; \
|
|
scc_mir_x86_instr_0(&instr, (iform), (isel)->pos); \
|
|
scc_vec_push((isel)->instrs, instr); \
|
|
} while (0)
|
|
|
|
#define add_instr_1(isel, iform, arg1) \
|
|
do { \
|
|
scc_mir_x86_instr_t instr; \
|
|
scc_mir_x86_instr_1(&instr, (iform), (arg1), (isel)->pos); \
|
|
scc_vec_push((isel)->instrs, instr); \
|
|
} while (0)
|
|
|
|
#define add_instr_2(isel, iform, arg1, arg2) \
|
|
do { \
|
|
scc_mir_x86_instr_t instr; \
|
|
scc_mir_x86_instr_2(&instr, (iform), (arg1), (arg2), (isel)->pos); \
|
|
scc_vec_push((isel)->instrs, instr); \
|
|
} while (0)
|
|
|
|
#endif /* __SCC_X86_ISEL_H__ */
|