feat(mir): 添加x86架构相关头文件并重构MIR指令表示

- 创建scc_x86_mir.h头文件,定义x86后端MIR指令结构和操作数构造器
- 创建scc_x86_isel.h头文件,定义x86_64指令选择器和相关工具函数
- 创建scc_x86_reg_alloc.h头文件,定义x86寄存器分配架构特定接口
- 移除旧的x86_64_isel.h和x86_64_reg_alloc.h文件
- 重构scc_mir.h中的指令表示,使用联合体存储伪指令数据
- 更新ABI lowering回调参数,使用void指针保持类型无关
- 扩展寄存器分配操作接口,添加指令信息查询和伪指令处理功能
- 更新目标文件包含路径以使用新的头文件命名
This commit is contained in:
zzy
2026-05-20 11:07:05 +08:00
parent 2c13ac54df
commit c6e3bb2e20
22 changed files with 792 additions and 788 deletions

View File

@@ -4,9 +4,12 @@
#include "../scc_mir_module.h"
#include <scc_lir_module.h>
// 所有回调通过 void* userdata / void* out_op 保持类型无关
typedef void (*scc_abi_lower_fn)(void *user_data, const scc_lir_instr_t *instr);
typedef scc_mir_operand_t (*scc_abi_lower_param_fn)(void *userdata,
const scc_lir_val_t *val);
// lower_param 将 LIR 值转化为后端操作数,写入 out_op后端知道实际类型
typedef void (*scc_abi_lower_param_fn)(void *userdata,
const scc_lir_val_t *val,
void *out_op);
typedef struct scc_abi_lowering {
scc_abi_lower_fn lower_call;

View File

@@ -7,37 +7,46 @@ typedef enum {
SCC_REG_ALLOC_OP_ACCESS_READ = 0,
SCC_REG_ALLOC_OP_ACCESS_WRITE = 1,
SCC_REG_ALLOC_OP_ACCESS_READWRITE = 2,
} scc_op_access_t;
} scc_reg_op_access_t;
// 后端回调表 —— 框架通过回调获取/修改指令,不感知具体布局
typedef struct scc_reg_alloc_op {
// preg → [slot]
void (*emit_spill)(scc_mir_instr_vec_t *ctx, int preg, int slot);
// [slot] → preg
void (*emit_reload)(scc_mir_instr_vec_t *ctx, int preg, int slot);
// preg → preg
void (*emit_copy)(scc_mir_instr_vec_t *ctx, int dst_preg, int src_preg,
int size);
// 通用寄存器申请 / 释放
int (*acquire_reg)(void *ctx); // 返回一个物理寄存器编号
void (*release_reg)(void *ctx, int preg); // 归还该寄存器
// 显式标记某个寄存器已占用 / 未占用(用于隐式寄存器、固定分配等)
// ── 寄存器池 ──
int (*acquire_reg)(void *ctx);
void (*release_reg)(void *ctx, int preg);
void (*mark_reg_used)(void *ctx, int preg);
void (*clean_mark_regs)(void *ctx);
// ---- 指令信息查询(只读) ----
scc_op_access_t (*get_operand_access)(void *ctx, int opcode, int op_idx);
// ── 指令信息 ──
int (*instr_opcode)(const void *instr);
int (*instr_num_operands)(const void *instr);
bool (*op_is_vreg)(const void *instr, int idx);
int (*op_get_vreg)(const void *instr, int idx);
void (*op_set_preg)(void *instr, int idx, int preg);
void (*op_set_slot)(void *instr, int idx, int slot);
// 读写属性与隐式寄存器
scc_reg_op_access_t (*get_operand_access)(void *ctx, int opcode,
int op_idx);
void (*get_implicit_regs)(void *ctx, int opcode, const int **out_uses,
const int **out_defs);
// ── 伪指令处理 ──
bool (*is_pseudo)(const void *instr);
void (*handle_pseudo)(scc_mir_func_t *func, void *instr, void *out);
// ── 溢出/重载(写入 out 向量) ──
void (*emit_spill)(void *out, int preg, int slot);
void (*emit_reload)(void *out, int preg, int slot);
void (*emit_copy)(void *out, int dst_preg, int src_preg, int size);
} scc_reg_alloc_op_t;
typedef struct scc_reg_alloc_ctx {
scc_reg_alloc_op_t ops;
scc_mir_module_t *module;
scc_mir_func_t *func;
scc_mir_instr_vec_t *instrs;
} scc_reg_alloc_ctx_t;
// 通用寄存器分配入口:遍历所有函数/基本块,对每条指令做 vreg → preg 分配
void scc_reg_alloc(scc_reg_alloc_ctx_t *ctx, scc_mir_module_t *module);
#endif /* __SCC_REG_ALLOC__ */
#endif /* __SCC_REG_ALLOC_H__ */