feat(compiler): 实现HIR到LIR的函数定义标记和直接/间接调用区分

- 在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参数,以便正确处理不同大小的寄存器
This commit is contained in:
zzy
2026-05-23 15:33:54 +08:00
parent d78b91894e
commit ea553718f0
21 changed files with 495 additions and 444 deletions

View File

@@ -45,33 +45,52 @@ typedef struct {
scc_x86_mem_t mem;
scc_x86_reloc_op_t reloc;
};
usize size;
u8 size;
} scc_x86_operand_value_t;
static inline scc_x86_operand_value_t scc_x86_op_preg(scc_x86_reg_t reg) {
scc_x86_operand_value_t o = {.kind = SCC_X86_OPR_REG, .reg = reg};
static inline scc_x86_operand_value_t scc_x86_op_preg(scc_x86_reg_t reg,
u8 size) {
scc_x86_operand_value_t o = {
.kind = SCC_X86_OPR_REG,
.reg = reg,
.size = size,
};
return o;
}
static inline scc_x86_reg_t scc_x86_op_vreg_reg(int vreg) {
return (int)SCC_X86_REG_COUNT + vreg;
}
static inline scc_x86_operand_value_t scc_x86_op_vreg(int vreg) {
static inline scc_x86_operand_value_t scc_x86_op_vreg(int vreg, u8 size) {
scc_x86_operand_value_t o = {
.kind = SCC_X86_OPR_REG,
.reg = scc_x86_op_vreg_reg(vreg),
.size = size,
};
return o;
}
static inline scc_x86_operand_value_t scc_x86_op_relbr(i32 rel) {
scc_x86_operand_value_t o = {.kind = SCC_X86_OPR_RELBR, .brdisp = rel};
scc_x86_operand_value_t o = {
.kind = SCC_X86_OPR_RELBR,
.brdisp = rel,
.size = 4,
};
return o;
}
static inline scc_x86_operand_value_t scc_x86_op_imm(i64 imm) {
scc_x86_operand_value_t o = {.kind = SCC_X86_OPR_IMM, .simm0 = imm};
static inline scc_x86_operand_value_t scc_x86_op_imm(i64 imm, u8 size) {
scc_x86_operand_value_t o = {
.kind = SCC_X86_OPR_IMM,
.simm0 = imm,
.size = size,
};
return o;
}
static inline scc_x86_operand_value_t scc_x86_op_mem(scc_x86_mem_t mem) {
scc_x86_operand_value_t o = {.kind = SCC_X86_OPR_MEM, .mem = mem};
static inline scc_x86_operand_value_t scc_x86_op_mem(scc_x86_mem_t mem,
u8 size) {
scc_x86_operand_value_t o = {
.kind = SCC_X86_OPR_MEM,
.mem = mem,
.size = size,
};
return o;
}
@@ -83,6 +102,7 @@ scc_x86_op_reloc_global_imm(const char *sym, i64 addend) {
op.reloc.target = SCC_X86_RELOC_TARGET_SYMBOL;
op.reloc.global_name = sym;
op.reloc.addend = addend;
op.size = 0;
return op;
}
@@ -93,6 +113,7 @@ scc_x86_op_reloc_global_relrip(const char *sym, i64 addend) {
op.reloc.target = SCC_X86_RELOC_TARGET_SYMBOL;
op.reloc.global_name = sym;
op.reloc.addend = addend;
op.size = 4;
return op;
}
@@ -104,6 +125,7 @@ scc_x86_op_reloc_global_relbr(const char *sym, i64 addend) {
op.reloc.target = SCC_X86_RELOC_TARGET_SYMBOL;
op.reloc.global_name = sym;
op.reloc.addend = addend;
op.size = 4;
return op;
}
@@ -115,6 +137,7 @@ static inline scc_x86_operand_value_t scc_x86_op_reloc_block(int bid,
op.reloc.target = SCC_X86_RELOC_TARGET_BBLOCK;
op.reloc.bblock_id = bid;
op.reloc.addend = addend;
op.size = 4;
return op;
}
@@ -128,11 +151,15 @@ scc_x86_op_reloc_global_mem(const char *sym, i64 addend) {
op.reloc.global_name = sym;
op.reloc.addend = addend;
// 编码时需生成 RIP 相对寻址的 ModRM/SIB
op.size = 0;
return op;
}
/* 按 iform 发射一条指令ops 数组长度需与 iform 定义的操作数数目一致 */
int scc_x86_encode_inst(scc_mcode_t *mcode, scc_x86_iform_t iform,
const scc_x86_operand_value_t *ops);
scc_x86_iform_t scc_x86_iclass_to_iform(scc_x86_iclass_t iclass,
const scc_x86_operand_value_t *ops,
int num_ops);
#endif /* __SCC_X86_ENCODE_H__ */