Skip to content

Commit

Permalink
Use union to pack constant value
Browse files Browse the repository at this point in the history
  • Loading branch information
tyfkda committed Oct 13, 2023
1 parent 054fda0 commit a44d396
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
17 changes: 12 additions & 5 deletions src/cc/backend/ir.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,19 @@ enum VRegSize {

typedef struct VReg {
enum VRegSize vsize;
int virt; // Virtual reg no.
int phys; // Physical reg no.
int flag;
int reg_param_index; // Index of function parameter through register: -1=not a register param.
int64_t fixnum; // Constant value.
FrameInfo frame; // FrameInfo for spilled register.
union {
// Non-const:
struct {
int virt; // Virtual reg no.
int phys; // Physical reg no.
int reg_param_index; // Index of function parameter through register: -1=non reg param.
FrameInfo frame; // FrameInfo for spilled register.
};

// Const:
int64_t fixnum; // Constant value.
};
} VReg;

void spill_vreg(VReg *vreg);
Expand Down
3 changes: 1 addition & 2 deletions src/cc/backend/regalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ static VReg *alloc_vreg(enum VRegSize vsize, int vflag) {
VReg *vreg = malloc_or_die(sizeof(*vreg));
vreg->virt = -1;
vreg->phys = -1;
vreg->fixnum = 0;
vreg->vsize = vsize;
vreg->flag = vflag;
vreg->reg_param_index = -1;
Expand Down Expand Up @@ -169,7 +168,7 @@ static void check_live_interval(BBContainer *bbcon, int vreg_count, LiveInterval
VReg *vregs[] = {ir->dst, ir->opr1, ir->opr2};
for (int k = 0; k < 3; ++k) {
VReg *vreg = vregs[k];
if (vreg == NULL)
if (vreg == NULL || (vreg->flag & VRF_CONST))
continue;
LiveInterval *li = &intervals[vreg->virt];
if (li->start < 0 && !(vreg->flag & VRF_PARAM))
Expand Down

0 comments on commit a44d396

Please sign in to comment.