From cc73788981b3ca81fcdf185f0d276ac41e316b4c Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 8 Nov 2022 18:17:29 +0300 Subject: [PATCH] Fix compilation warnings --- ir.c | 27 ++++----------------------- ir.h | 31 +++++++++++++++++++++++++++---- ir_aarch64.dasc | 12 ++++++------ ir_emit_c.c | 8 ++------ ir_gcm.c | 2 +- ir_ra.c | 22 +++++++++------------- ir_sccp.c | 42 +++++++++++++++++++----------------------- ir_x86.dasc | 12 ++++++------ 8 files changed, 74 insertions(+), 82 deletions(-) diff --git a/ir.c b/ir.c index e7acb98..1e97adf 100644 --- a/ir.c +++ b/ir.c @@ -29,10 +29,6 @@ # include #endif -#if defined(__GNUC__) -# pragma GCC diagnostic ignored "-Warray-bounds" -#endif - #define IR_TYPE_FLAGS(name, type, field, flags) ((flags)|sizeof(type)), #define IR_TYPE_NAME(name, type, field, flags) #name, #define IR_TYPE_CNAME(name, type, field, flags) #type, @@ -622,21 +618,6 @@ ir_ref ir_emit3(ir_ctx *ctx, uint32_t opt, ir_ref op1, ir_ref op2, ir_ref op3) return ir_emit(ctx, opt, op1, op2, op3); } -void ir_set_op1(ir_ctx *ctx, ir_ref ref, ir_ref val) -{ - ctx->ir_base[ref].op1 = val; -} - -void ir_set_op2(ir_ctx *ctx, ir_ref ref, ir_ref val) -{ - ctx->ir_base[ref].op2 = val; -} - -void ir_set_op3(ir_ctx *ctx, ir_ref ref, ir_ref val) -{ - ctx->ir_base[ref].op3 = val; -} - static ir_ref _ir_fold_cse(ir_ctx *ctx, uint32_t opt, ir_ref op1, ir_ref op2, ir_ref op3) { ir_ref ref = ctx->prev_insn_chain[opt & IR_OPT_OP_MASK]; @@ -859,7 +840,7 @@ ir_ref ir_fold3(ir_ctx *ctx, uint32_t opt, ir_ref op1, ir_ref op2, ir_ref op3) ir_ref ir_emit_N(ir_ctx *ctx, uint32_t opt, uint32_t count) { int i; - ir_ref ref = ctx->insns_count; + ir_ref *p, ref = ctx->insns_count; ir_insn *insn; while (UNEXPECTED(ref + count/4 >= ctx->insns_limit)) { @@ -872,8 +853,8 @@ ir_ref ir_emit_N(ir_ctx *ctx, uint32_t opt, uint32_t count) if ((opt & IR_OPT_OP_MASK) != IR_PHI) { insn->inputs_count = count; } - for (i = 1; i <= (count|3); i++) { - insn->ops[i] = IR_UNUSED; + for (i = 1, p = insn->ops + i; i <= (count|3); i++, p++) { + *p = IR_UNUSED; } return ref; @@ -906,7 +887,7 @@ void ir_set_op(ir_ctx *ctx, ir_ref ref, uint32_t n, ir_ref val) } IR_ASSERT(n <= count); } - insn->ops[n] = val; + ir_insn_set_op(insn, n, val); } ir_ref ir_param(ir_ctx *ctx, ir_type type, ir_ref region, const char *name, int pos) diff --git a/ir.h b/ir.h index 414c4cb..06ca6f5 100644 --- a/ir.h +++ b/ir.h @@ -523,13 +523,36 @@ ir_ref ir_emit1(ir_ctx *ctx, uint32_t opt, ir_ref op1); ir_ref ir_emit2(ir_ctx *ctx, uint32_t opt, ir_ref op1, ir_ref op2); ir_ref ir_emit3(ir_ctx *ctx, uint32_t opt, ir_ref op1, ir_ref op2, ir_ref op3); -void ir_set_op1(ir_ctx *ctx, ir_ref ref, ir_ref val); -void ir_set_op2(ir_ctx *ctx, ir_ref ref, ir_ref val); -void ir_set_op3(ir_ctx *ctx, ir_ref ref, ir_ref val); - ir_ref ir_emit_N(ir_ctx *ctx, uint32_t opt, uint32_t count); void ir_set_op(ir_ctx *ctx, ir_ref ref, uint32_t n, ir_ref val); +static inline void ir_set_op1(ir_ctx *ctx, ir_ref ref, ir_ref val) +{ + ctx->ir_base[ref].op1 = val; +} + +static inline void ir_set_op2(ir_ctx *ctx, ir_ref ref, ir_ref val) +{ + ctx->ir_base[ref].op2 = val; +} + +static inline void ir_set_op3(ir_ctx *ctx, ir_ref ref, ir_ref val) +{ + ctx->ir_base[ref].op3 = val; +} + +static inline ir_ref ir_insn_op(ir_insn *insn, uint32_t n) +{ + ir_ref *p = insn->ops + n; + return *p; +} + +static inline void ir_insn_set_op(ir_insn *insn, uint32_t n, ir_ref val) +{ + ir_ref *p = insn->ops + n; + *p = val; +} + ir_ref ir_fold(ir_ctx *ctx, uint32_t opt, ir_ref op1, ir_ref op2, ir_ref op3); ir_ref ir_fold0(ir_ctx *ctx, uint32_t opt); diff --git a/ir_aarch64.dasc b/ir_aarch64.dasc index d78f18a..95963b1 100644 --- a/ir_aarch64.dasc +++ b/ir_aarch64.dasc @@ -328,7 +328,7 @@ static ir_reg ir_get_arg_reg(ir_ctx *ctx, ir_insn *insn, int op_num) n = ir_input_edges_count(ctx, insn); for (j = 3; j <= n; j++) { - type = ctx->ir_base[insn->ops[j]].type; + type = ctx->ir_base[ir_insn_op(insn, j)].type; if (IR_IS_TYPE_INT(type)) { if (j == op_num) { if (int_param < int_reg_params_count) { @@ -366,7 +366,7 @@ static bool ir_call_needs_tmp_int_reg(ir_ctx *ctx, ir_ref ref) n = ir_input_edges_count(ctx, insn); for (j = 3; j <= n; j++) { - arg = insn->ops[j]; + arg = ir_insn_op(insn, j); arg_insn = &ctx->ir_base[arg]; type = arg_insn->type; if (IR_IS_TYPE_INT(type)) { @@ -3598,7 +3598,7 @@ static int32_t ir_call_used_stack(ir_ctx *ctx, ir_insn *insn) n = ir_input_edges_count(ctx, insn); for (j = 3; j <= n; j++) { - type = ctx->ir_base[insn->ops[j]].type; + type = ctx->ir_base[ir_insn_op(insn, j)].type; if (IR_IS_TYPE_INT(type)) { if (int_param >= int_reg_params_count) { used_stack += IR_MAX(sizeof(void*), ir_type_size[type]); @@ -3660,7 +3660,7 @@ static int32_t ir_emit_arguments(ir_ctx *ctx, ir_ref def, ir_insn *insn, ir_reg * and collect arguments that should be passed through registers */ copies = ir_mem_malloc((n - 2) * sizeof(ir_copy)); for (j = 3; j <= n; j++) { - arg = insn->ops[j]; + arg = ir_insn_op(insn, j); src_reg = ctx->regs[def][j]; arg_insn = &ctx->ir_base[arg]; type = arg_insn->type; @@ -3759,7 +3759,7 @@ static int32_t ir_emit_arguments(ir_ctx *ctx, ir_ref def, ir_insn *insn, ir_reg int_param = 0; fp_param = 0; for (j = 3; j <= n; j++) { - arg = insn->ops[j]; + arg = ir_insn_op(insn, j); src_reg = ctx->regs[def][j]; arg_insn = &ctx->ir_base[arg]; type = arg_insn->type; @@ -4323,7 +4323,7 @@ static int ir_emit_dessa_move(ir_ctx *ctx, uint8_t type, ir_ref from, ir_ref to) for (j = 0; j < use_list->count; j++) { ir_ref use = ctx->use_edges[use_list->refs + j]; ir_insn *insn = &ctx->ir_base[use]; - if (insn->op == IR_PHI && insn->ops[k] == from && insn->op1 == to_bb->start) { + if (insn->op == IR_PHI && ir_insn_op(insn, k) == from && insn->op1 == to_bb->start) { phi = use; break; } diff --git a/ir_emit_c.c b/ir_emit_c.c index e90a469..4a15197 100644 --- a/ir_emit_c.c +++ b/ir_emit_c.c @@ -8,10 +8,6 @@ #include "ir.h" #include "ir_private.h" -#if defined(__GNUC__) -# pragma GCC diagnostic ignored "-Warray-bounds" -#endif - static int ir_emit_dessa_move(ir_ctx *ctx, uint8_t type, ir_ref from, ir_ref to) { FILE *f = ctx->data; @@ -539,7 +535,7 @@ static void ir_emit_call(ir_ctx *ctx, FILE *f, ir_ref def, ir_insn *insn) if (j != 3) { fprintf(f, ", "); } - ir_emit_ref(ctx, f, insn->ops[j]); + ir_emit_ref(ctx, f, ir_insn_op(insn, j)); } fprintf(f, ");\n"); } @@ -562,7 +558,7 @@ static void ir_emit_tailcall(ir_ctx *ctx, FILE *f, ir_insn *insn) if (j != 3) { fprintf(f, ", "); } - ir_emit_ref(ctx, f, insn->ops[j]); + ir_emit_ref(ctx, f, ir_insn_op(insn, j)); } fprintf(f, ");\n"); if (insn->type == IR_VOID) { diff --git a/ir_gcm.c b/ir_gcm.c index fb29657..ee8ff31 100644 --- a/ir_gcm.c +++ b/ir_gcm.c @@ -90,7 +90,7 @@ static void ir_gcm_schedule_late(ir_ctx *ctx, uint32_t *_blocks, ir_bitset visit n = ir_input_edges_count(ctx, insn); for (j = 3, p = insn->ops + 4; j < n; j++, p++) { if (*p == ref) { - b = _blocks[ctx->ir_base[insn->op1].ops[j]]; + b = _blocks[ir_insn_op(&ctx->ir_base[insn->op1], j)]; break; } } diff --git a/ir_ra.c b/ir_ra.c index d649523..2497130 100644 --- a/ir_ra.c +++ b/ir_ra.c @@ -27,10 +27,6 @@ #include "ir_private.h" -#if defined(__GNUC__) -# pragma GCC diagnostic ignored "-Warray-bounds" -#endif - #define IR_SKIP IR_LAST_OP #define IR_SKIP_REG (IR_LAST_OP+1) #define IR_SKIP_MEM (IR_LAST_OP+2) @@ -401,16 +397,16 @@ int ir_compute_live_ranges(ir_ctx *ctx) ir_ref use = ctx->use_edges[use_list->refs + j]; insn = &ctx->ir_base[use]; if (insn->op == IR_PHI) { - if (insn->ops[k] > 0) { + if (ir_insn_op(insn, k) > 0) { /* live.add(phi.inputOf(b)) */ - IR_ASSERT(ctx->vregs[insn->ops[k]]); - ir_bitset_incl(live, ctx->vregs[insn->ops[k]]); + IR_ASSERT(ctx->vregs[ir_insn_op(insn, k)]); + ir_bitset_incl(live, ctx->vregs[ir_insn_op(insn, k)]); // TODO: ir_add_live_range() is used just to set ival->type /* intervals[phi.inputOf(b)].addRange(b.from, b.to) */ - ir_add_live_range(ctx, &unused, ctx->vregs[insn->ops[k]], insn->type, + ir_add_live_range(ctx, &unused, ctx->vregs[ir_insn_op(insn, k)], insn->type, IR_START_LIVE_POS_FROM_REF(bb->start), IR_END_LIVE_POS_FROM_REF(bb->end)); - ir_add_phi_use(ctx, ctx->vregs[insn->ops[k]], k, IR_DEF_LIVE_POS_FROM_REF(bb->end), use); + ir_add_phi_use(ctx, ctx->vregs[ir_insn_op(insn, k)], k, IR_DEF_LIVE_POS_FROM_REF(bb->end), use); } } } @@ -507,7 +503,7 @@ int ir_compute_live_ranges(ir_ctx *ctx) n = ir_input_edges_count(ctx, insn); for (j = 1; j <= n; j++) { if (IR_OPND_KIND(flags, j) == IR_OPND_DATA) { - ir_ref input = insn->ops[j]; + ir_ref input = ir_insn_op(insn, j); uint8_t use_flags; if (ctx->rules) { @@ -1028,7 +1024,7 @@ int ir_coalesce(ir_ctx *ctx) use = *p; insn = &ctx->ir_base[use]; if (insn->op == IR_PHI) { - input = insn->ops[k]; + input = ir_insn_op(insn, k); if (input > 0) { if (!ir_try_coalesce(ctx, &unused, input, use)) { ir_add_phi_move(ctx, b, input, use); @@ -1133,7 +1129,7 @@ int ir_compute_dessa_moves(ir_ctx *ctx) if (insn->op == IR_PHI) { k = ir_input_edges_count(ctx, insn); for (j = 2; j <= k; j++) { - if (IR_IS_CONST_REF(insn->ops[j]) || ctx->vregs[insn->ops[j]] != ctx->vregs[use]) { + if (IR_IS_CONST_REF(ir_insn_op(insn, j)) || ctx->vregs[ir_insn_op(insn, j)] != ctx->vregs[use]) { int pred = ctx->cfg_edges[bb->predecessors + (j-2)]; ctx->cfg_blocks[pred].flags |= IR_BB_DESSA_MOVES; } @@ -1182,7 +1178,7 @@ int ir_gen_dessa_moves(ir_ctx *ctx, int b, emit_copy_t emit_copy) ir_ref ref = ctx->use_edges[use_list->refs + j]; ir_insn *insn = &ctx->ir_base[ref]; if (insn->op == IR_PHI) { - ir_ref input = insn->ops[k]; + ir_ref input = ir_insn_op(insn, k); if (IR_IS_CONST_REF(input)) { emit_copy(ctx, insn->type, input, ref); } else if (ctx->vregs[input] != ctx->vregs[ref]) { diff --git a/ir_sccp.c b/ir_sccp.c index aefaea5..035cc38 100644 --- a/ir_sccp.c +++ b/ir_sccp.c @@ -12,10 +12,6 @@ #include "ir.h" #include "ir_private.h" -#if defined(__GNUC__) -# pragma GCC diagnostic ignored "-Warray-bounds" -#endif - #define IR_TOP IR_UNUSED #define IR_BOTTOM IR_LAST_OP @@ -262,8 +258,8 @@ static void ir_sccp_replace_insn(ir_ctx *ctx, ir_insn *_values, ir_ref ref, ir_r insn = &ctx->ir_base[use]; l = ir_input_edges_count(ctx, insn); for (k = 1; k <= l; k++) { - if (insn->ops[k] == ref) { - insn->ops[k] = new_ref; + if (ir_insn_op(insn, k) == ref) { + ir_insn_set_op(insn, k, new_ref); } } #if IR_COMBO_COPY_PROPAGATION @@ -405,8 +401,8 @@ static void ir_sccp_remove_unreachable_merge_inputs(ir_ctx *ctx, ir_insn *_value if (n - unreachable_inputs == 1) { /* remove MERGE completely */ for (j = 1; j <= n; j++) { - if (insn->ops[j] && IR_IS_REACHABLE(insn->ops[j])) { - ir_ref prev, next = IR_UNUSED, input = insn->ops[j]; + if (ir_insn_op(insn, j) && IR_IS_REACHABLE(ir_insn_op(insn, j))) { + ir_ref prev, next = IR_UNUSED, input = ir_insn_op(insn, j); ir_insn *next_insn = NULL, *input_insn = &ctx->ir_base[input]; IR_ASSERT(input_insn->op == IR_END || input_insn->op == IR_IJMP || input_insn->op == IR_UNREACHABLE); @@ -440,9 +436,9 @@ static void ir_sccp_remove_unreachable_merge_inputs(ir_ctx *ctx, ir_insn *_value i = 1; life_inputs = ir_bitset_malloc(n + 1); for (j = 1; j <= n; j++) { - if (insn->ops[j]) { + if (ir_insn_op(insn, j)) { if (i != j) { - insn->ops[i] = insn->ops[j]; + ir_insn_set_op(insn, i, ir_insn_op(insn, j)); } ir_bitset_incl(life_inputs, j); i++; @@ -463,13 +459,13 @@ static void ir_sccp_remove_unreachable_merge_inputs(ir_ctx *ctx, ir_insn *_value i = 2; for (j = 2; j <= n; j++) { if (ir_bitset_in(life_inputs, j - 1)) { - IR_ASSERT(use_insn->ops[j]); + IR_ASSERT(ir_insn_op(use_insn, j)); if (i != j) { - use_insn->ops[i] = use_insn->ops[j]; + ir_insn_set_op(use_insn, i, ir_insn_op(use_insn, j)); } i++; } else { - IR_ASSERT(use_insn->ops[j] <= 0); + IR_ASSERT(ir_insn_op(use_insn, j) <= 0); } } } @@ -486,7 +482,7 @@ static void ir_sccp_mark_reachable_data(ir_ctx *ctx, ir_bitqueue *worklist, ir_i n = ir_input_edges_count(ctx, insn); for (j = 1; j <= n; j++) { if (IR_OPND_KIND(flags, j) == IR_OPND_DATA || IR_OPND_KIND(flags, j) == IR_OPND_VAR) { - use = insn->ops[j]; + use = ir_insn_op(insn, j); if (use > 0 && IR_IS_TOP(use) && !ir_bitqueue_in(worklist, use)) { ir_bitqueue_add(worklist, use); ir_sccp_mark_reachable_data(ctx, worklist, _values, &ctx->ir_base[use]); @@ -530,10 +526,10 @@ int ir_sccp(ir_ctx *ctx) } } for (j = 1; j < n; j++) { - if (merge_insn->ops[j] && IR_IS_REACHABLE(merge_insn->ops[j])) { - if (IR_IS_TOP(insn->ops[j + 1])) { - ir_bitqueue_add(&worklist, insn->ops[j +1]); - } else if (ir_sccp_join_values(ctx, _values, i, insn->ops[j + 1])) { + if (ir_insn_op(merge_insn, j) && IR_IS_REACHABLE(ir_insn_op(merge_insn, j))) { + if (IR_IS_TOP(ir_insn_op(insn, j + 1))) { + ir_bitqueue_add(&worklist, ir_insn_op(insn, j +1)); + } else if (ir_sccp_join_values(ctx, _values, i, ir_insn_op(insn, j + 1))) { changed = 1; } } @@ -546,11 +542,11 @@ int ir_sccp(ir_ctx *ctx) bool has_top = 0; n = ir_input_edges_count(ctx, insn); for (j = 1; j <= n; j++) { - ir_ref input = insn->ops[j]; + ir_ref input = ir_insn_op(insn, j); if (!IR_IS_CONST_REF(input)) { if (_values[input].optx == IR_TOP) { has_top = 1; - ir_bitqueue_add(&worklist, insn->ops[j]); + ir_bitqueue_add(&worklist, ir_insn_op(insn, j)); } else if (_values[input].optx != IR_BOTTOM) { /* Perform folding only if some of direct inputs * is going to be replaced by a constant or copy. @@ -663,8 +659,8 @@ int ir_sccp(ir_ctx *ctx) } } for (j = 1; j <= n; j++) { - if (insn->ops[j]) { - if (!IR_IS_REACHABLE(insn->ops[j])) { + if (ir_insn_op(insn, j)) { + if (!IR_IS_REACHABLE(ir_insn_op(insn, j))) { unreachable_inputs++; } } @@ -697,7 +693,7 @@ int ir_sccp(ir_ctx *ctx) IR_ASSERT(n == 0 || IR_OPND_KIND(flags, 1) == IR_OPND_CONTROL); for (j = 2; j <= n; j++) { if (IR_OPND_KIND(flags, j) == IR_OPND_DATA || IR_OPND_KIND(flags, j) == IR_OPND_VAR) { - use = insn->ops[j]; + use = ir_insn_op(insn, j); if (use > 0 && IR_IS_TOP(use) && !ir_bitqueue_in(&worklist, use)) { ir_bitqueue_add(&worklist, use); ir_sccp_mark_reachable_data(ctx, &worklist, _values, &ctx->ir_base[use]); diff --git a/ir_x86.dasc b/ir_x86.dasc index c463b80..a6c935b 100644 --- a/ir_x86.dasc +++ b/ir_x86.dasc @@ -647,7 +647,7 @@ static ir_reg ir_get_arg_reg(ir_ctx *ctx, ir_insn *insn, int op_num) n = ir_input_edges_count(ctx, insn); for (j = 3; j <= n; j++) { - type = ctx->ir_base[insn->ops[j]].type; + type = ctx->ir_base[ir_insn_op(insn, j)].type; if (IR_IS_TYPE_INT(type)) { if (j == op_num) { if (int_param < int_reg_params_count) { @@ -691,7 +691,7 @@ static bool ir_call_needs_tmp_int_reg(ir_ctx *ctx, ir_ref ref) n = ir_input_edges_count(ctx, insn); for (j = 3; j <= n; j++) { - arg = insn->ops[j]; + arg = ir_insn_op(insn, j); arg_insn = &ctx->ir_base[arg]; type = arg_insn->type; if (IR_IS_TYPE_INT(type)) { @@ -5765,7 +5765,7 @@ static int32_t ir_call_used_stack(ir_ctx *ctx, ir_insn *insn) n = ir_input_edges_count(ctx, insn); for (j = 3; j <= n; j++) { - type = ctx->ir_base[insn->ops[j]].type; + type = ctx->ir_base[ir_insn_op(insn, j)].type; if (IR_IS_TYPE_INT(type)) { if (int_param >= int_reg_params_count) { used_stack += IR_MAX(sizeof(void*), ir_type_size[type]); @@ -5836,7 +5836,7 @@ static int32_t ir_emit_arguments(ir_ctx *ctx, ir_ref def, ir_insn *insn, ir_reg * and collect arguments that should be passed through registers */ copies = ir_mem_malloc((n - 2) * sizeof(ir_copy)); for (j = 3; j <= n; j++) { - arg = insn->ops[j]; + arg = ir_insn_op(insn, j); src_reg = ctx->regs[def][j]; arg_insn = &ctx->ir_base[arg]; type = arg_insn->type; @@ -5962,7 +5962,7 @@ static int32_t ir_emit_arguments(ir_ctx *ctx, ir_ref def, ir_insn *insn, ir_reg int_param = 0; fp_param = 0; for (j = 3; j <= n; j++) { - arg = insn->ops[j]; + arg = ir_insn_op(insn, j); src_reg = ctx->regs[def][j]; arg_insn = &ctx->ir_base[arg]; type = arg_insn->type; @@ -6790,7 +6790,7 @@ static int ir_emit_dessa_move(ir_ctx *ctx, uint8_t type, ir_ref from, ir_ref to) for (j = 0; j < use_list->count; j++) { ir_ref use = ctx->use_edges[use_list->refs + j]; ir_insn *insn = &ctx->ir_base[use]; - if (insn->op == IR_PHI && insn->ops[k] == from && insn->op1 == to_bb->start) { + if (insn->op == IR_PHI && ir_insn_op(insn, k) == from && insn->op1 == to_bb->start) { phi = use; break; }