Use ir_ctx.fixed_regset to limit available registers

This commit is contained in:
Dmitry Stogov 2022-06-21 16:13:14 +03:00
parent fc2266d61a
commit 082bcf89c9
8 changed files with 10 additions and 29 deletions

View File

@ -1,5 +1,5 @@
CC = gcc
#CFLAGS = -O2 -g -Wall -DIR_TARGET_X64 -DIR_DEBUG_REGSET
#CFLAGS = -O2 -g -Wall -DIR_TARGET_X64
CFLAGS = -O0 -g -Wall -DIR_DEBUG -DIR_TARGET_X64
LDFLAGS = -lm
PHP = php

1
ir.c
View File

@ -287,6 +287,7 @@ void ir_init(ir_ctx *ctx, ir_ref consts_limit, ir_ref insns_limit)
ctx->rules = NULL;
ctx->vregs_count = 0;
ctx->vregs = NULL;
ctx->fixed_regset = 0;
ctx->live_intervals = NULL;
ctx->regs = NULL;
ctx->prev_insn_len = NULL;

12
ir.h
View File

@ -434,6 +434,7 @@ typedef struct _ir_ctx {
uint32_t *rules;
uint32_t vregs_count;
uint32_t *vregs;
uint64_t fixed_regset;
ir_live_interval **live_intervals;
ir_regs *regs;
uint32_t *prev_insn_len;
@ -591,15 +592,4 @@ int ir_mem_protect(void *ptr, size_t size);
int ir_mem_unprotect(void *ptr, size_t size);
int ir_mem_flush(void *ptr, size_t size);
/* IR Debug API */
#ifdef IR_DEBUG
# ifndef IR_DEBUG_REGSET
# define IR_DEBUG_REGSET
# endif
#endif
#ifdef IR_DEBUG_REGSET
extern uint64_t debug_regset;
#endif
#endif /* IR_H */

View File

@ -474,6 +474,7 @@ restart:
/* Linearization */
ir_init(&new_ctx, ctx->consts_count, ctx->insns_count);
new_ctx.flags = ctx->flags;
new_ctx.fixed_regset = ctx->fixed_regset;
/* TODO: linearize without reallocation and reconstruction ??? */
if (!ir_copy(&new_ctx, ctx, _next, 1)) {
ir_free(&new_ctx);

View File

@ -210,6 +210,7 @@ int main(int argc, char **argv)
uint32_t dump = 0;
int opt_level = 2;
uint32_t mflags = 0;
uint64_t debug_regset = 0xffffffffffffffff;
ir_consistency_check();
@ -302,7 +303,6 @@ int main(int argc, char **argv)
} else if (strcmp(argv[i], "--debug-ra") == 0) {
mflags |= IR_DEBUG_RA;
#endif
#ifdef IR_DEBUG_REGSET
} else if (strcmp(argv[i], "--debug-regset") == 0) {
if (i + 1 == argc || argv[i + 1][0] == '-') {
fprintf(stderr, "ERROR: Invalid usage' (use --help)\n");
@ -310,7 +310,6 @@ int main(int argc, char **argv)
}
debug_regset = strtoull(argv[i + 1], NULL, 0);
i++;
#endif
} else if (argv[i][0] == '-') {
fprintf(stderr, "ERROR: Unknown option '%s' (use --help)\n", argv[i]);
return 1;
@ -355,6 +354,7 @@ int main(int argc, char **argv)
if (dump_asm || run) {
ctx.flags |= IR_GEN_NATIVE;
}
ctx.fixed_regset = ~debug_regset;
if (!ir_load(&ctx, f)) {
fprintf(stderr, "ERROR: Cannot load input file '%s'\n", input);

View File

@ -6,9 +6,6 @@
#ifdef IR_DEBUG
# include <assert.h>
# define IR_ASSERT(x) assert(x)
# ifndef IR_DEBUG_REGSET
# define IR_DEBUG_REGSET
# endif
#else
# define IR_ASSERT(x)
#endif

12
ir_ra.c
View File

@ -17,10 +17,6 @@
# pragma GCC diagnostic ignored "-Warray-bounds"
#endif
#ifdef IR_DEBUG_REGSET
uint64_t debug_regset = 0xffffffffffffffff;
#endif
int ir_regs_number(void)
{
return IR_REG_NUM;
@ -1599,9 +1595,7 @@ static ir_reg ir_try_allocate_free_reg(ir_ctx *ctx, ir_live_interval *ival, ir_l
}
}
#ifdef IR_DEBUG_REGSET
available &= debug_regset;
#endif
available = IR_REGSET_DIFFERENCE(available, (ir_regset)ctx->fixed_regset);
/* for each interval it in active */
other = *active;
@ -1741,9 +1735,7 @@ static ir_reg ir_allocate_blocked_reg(ir_ctx *ctx, ir_live_interval *ival, ir_li
}
}
#ifdef IR_DEBUG_REGSET
available &= debug_regset;
#endif
available = IR_REGSET_DIFFERENCE(available, (ir_regset)ctx->fixed_regset);
if (IR_REGSET_IS_EMPTY(available)) {
fprintf(stderr, "LSRA Internal Error: No registers available. Allocation is not possible\n");

View File

@ -124,6 +124,7 @@ int main(int argc, char **argv)
int i;
int opt_level = 2;
uint32_t mflags = 0;
uint64_t debug_regset = 0xffffffffffffffff;
ir_consistency_check();
@ -152,7 +153,6 @@ int main(int argc, char **argv)
} else if (strcmp(argv[i], "--debug-ra") == 0) {
mflags |= IR_DEBUG_RA;
#endif
#ifdef IR_DEBUG_REGSET
} else if (strcmp(argv[i], "--debug-regset") == 0) {
if (i + 1 == argc || argv[i + 1][0] == '-') {
fprintf(stderr, "ERROR: Invalid usage' (use --help)\n");
@ -160,7 +160,6 @@ int main(int argc, char **argv)
}
debug_regset = strtoull(argv[i + 1], NULL, 0);
i++;
#endif
} else {
/* pass*/
}
@ -172,6 +171,7 @@ int main(int argc, char **argv)
if (opt_level > 0) {
ctx.flags |= IR_OPT_FOLDING | IR_OPT_CODEGEN;
}
ctx.fixed_regset = ~debug_regset;
gen_mandelbrot(&ctx);
ir_build_def_use_lists(&ctx);