Skip to content

Commit

Permalink
extract x86 conditional opt to llir pass (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-s168 authored Dec 2, 2024
1 parent 53a9873 commit 4c48f39
Show file tree
Hide file tree
Showing 19 changed files with 248 additions and 245 deletions.
2 changes: 1 addition & 1 deletion build.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ struct CompileData ir_opt_files[] = {
SP(CT_C, "ir/opt/ll_jumps.c"),
SP(CT_C, "ir/opt/ll_binary.c"),
SP(CT_C, "ir/opt/simple_patterns.c"),
SP(CT_C, "ir/opt/ll_sched.c"),
SP(CT_C, "ir/opt/if_opts.c"),
SP(CT_C, "ir/opt/swap_if_cases.c"),
};
Expand Down Expand Up @@ -111,6 +110,7 @@ struct CompileData cg_files[] = {
DIR("build/targets/x86"),
SP(CT_C, "targets/x86/x86.c"),
SP(CT_C, "targets/x86/cg.c"),
SP(CT_C, "targets/x86/llir_conditionals.c"),
// add target
};

Expand Down
2 changes: 0 additions & 2 deletions ir/analysis.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ bool VX_IR_OPFILTER_CONDITIONAL__impl(vx_IrOp* op, void* ign1) {

switch (op->id)
{
case VX_IR_OP_CONDTAILCALL:
case VX_IR_OP_COND:
case VX_IR_OP_CMOV:
return true;
Expand Down Expand Up @@ -562,7 +561,6 @@ bool vx_IrBlock_llIsLeaf(vx_IrBlock* block) {
for (vx_IrOp* op = block->first; op; op = op->next) {
switch (op->id) {
case VX_IR_OP_CALL:
case VX_IR_OP_CONDTAILCALL:
case VX_IR_OP_TAILCALL:
return false;

Expand Down
8 changes: 5 additions & 3 deletions ir/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ const char *vx_IrName_str[VX_IR_NAME__LAST] = {
[VX_IR_NAME_LOOP_ENDEX] = "endex",
[VX_IR_NAME_LOOP_STRIDE] = "stride",

[VX_IR_NAME_ALTERNATIVE_A] = "a",
[VX_IR_NAME_ALTERNATIVE_B] = "b",

[VX_IR_NAME_IDX] = "idx",
[VX_IR_NAME_ELSIZE] = "elsize",
[VX_IR_NAME_OFF] = "off",
Expand Down Expand Up @@ -70,6 +67,11 @@ void vx_IrValue_dump(vx_IrValue value, FILE *out, const size_t indent) {
}
break;

case VX_IR_VAL_X86_CC: {
fprintf(out, "%s", value.x86_cc);
}
break;

case VX_IR_VAL_BLOCK: {
const vx_IrBlock *block = value.block;

Expand Down
6 changes: 5 additions & 1 deletion ir/ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ bool vx_IrValue_eq(vx_IrValue a, vx_IrValue b)

case VX_IR_VAL_ID:
return a.id == b.id;

case VX_IR_VAL_X86_CC:
return !strcmp(a.x86_cc, b.x86_cc);
}
}

Expand Down Expand Up @@ -147,9 +150,10 @@ vx_IrType* vx_IrValue_type(vx_CU* cu, vx_IrBlock* root, vx_IrValue value) {

case VX_IR_VAL_VAR:
return vx_IrBlock_typeofVar(root, value.var);

default:
assert(false);
return NULL;
}
}

Expand Down
7 changes: 4 additions & 3 deletions ir/ir.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ struct vx_IrValue {
VX_IR_VAL_BLOCK,
VX_IR_VAL_TYPE,
VX_IR_VAL_ID,
VX_IR_VAL_X86_CC,
} type;

vx_IrType* no_read_rt_type;
Expand All @@ -328,6 +329,8 @@ struct vx_IrValue {
vx_IrBlock *block;
vx_IrType *ty;
size_t id;

const char *x86_cc;
};
};

Expand All @@ -341,6 +344,7 @@ bool vx_IrValue_eq(vx_IrValue a, vx_IrValue b);
#define VX_IR_VALUE_TYPE(idin) ((vx_IrValue) { .type = VX_IR_VAL_TYPE, .ty = idin })
#define VX_IR_VALUE_BLK(blk) ((vx_IrValue) { .type = VX_IR_VAL_BLOCK, .block = blk })
#define VX_IR_VALUE_ID(idin) ((vx_IrValue) { .type = VX_IR_VAL_ID, .id = idin })
#define VX_IR_VALUE_X86_CC(cc) ((vx_IrValue) { .type = VX_IR_VAL_X86_CC, .x86_cc = cc })

void vx_IrValue_dump(vx_IrValue value, FILE *out, size_t indent);

Expand Down Expand Up @@ -429,9 +433,6 @@ typedef enum {
VX_IR_NAME_LOOP_ENDEX,
VX_IR_NAME_LOOP_STRIDE,

VX_IR_NAME_ALTERNATIVE_A,
VX_IR_NAME_ALTERNATIVE_B,

VX_IR_NAME_IDX,
VX_IR_NAME_STRUCT,
VX_IR_NAME_TYPE,
Expand Down
Loading

0 comments on commit 4c48f39

Please sign in to comment.