Skip to content

Commit

Permalink
Separate ir_next_control() fnction
Browse files Browse the repository at this point in the history
  • Loading branch information
dstogov committed Nov 15, 2024
1 parent c35ff00 commit f8ff379
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
16 changes: 3 additions & 13 deletions ir_cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ IR_ALWAYS_INLINE void _ir_add_predecessors(const ir_insn *insn, ir_worklist *wor

int ir_build_cfg(ir_ctx *ctx)
{
ir_ref n, *p, ref, start, end, next;
ir_ref n, *p, ref, start, end;
uint32_t b;
ir_insn *insn;
ir_worklist worklist;
Expand Down Expand Up @@ -145,18 +145,8 @@ int ir_build_cfg(ir_ctx *ctx)
start = ref;
/* Skip control nodes untill BB end */
while (1) {
use_list = &ctx->use_lists[ref];
n = use_list->count;
next = IR_UNUSED;
for (p = &ctx->use_edges[use_list->refs]; n > 0; p++, n--) {
next = *p;
insn = &ctx->ir_base[next];
if ((ir_op_flags[insn->op] & IR_OP_FLAG_CONTROL) && insn->op1 == ref) {
break;
}
}
IR_ASSERT(next != IR_UNUSED);
ref = next;
ref = ir_next_control(ctx, ref);
insn = &ctx->ir_base[ref];
if (IR_IS_BB_END(insn->op)) {
break;
}
Expand Down
19 changes: 19 additions & 0 deletions ir_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,25 @@ void ir_use_list_replace_all(ir_ctx *ctx, ir_ref ref, ir_ref use, ir_ref new_use
void ir_use_list_replace_one(ir_ctx *ctx, ir_ref ref, ir_ref use, ir_ref new_use);
bool ir_use_list_add(ir_ctx *ctx, ir_ref to, ir_ref new_use);

IR_ALWAYS_INLINE ir_ref ir_next_control(const ir_ctx *ctx, ir_ref ref)
{
ir_use_list *use_list = &ctx->use_lists[ref];
ir_ref n = use_list->count;
ir_ref *p;

IR_ASSERT(ir_op_flags[ctx->ir_base[ref].op] & IR_OP_FLAG_CONTROL);
for (p = &ctx->use_edges[use_list->refs]; n > 0; p++, n--) {
ir_ref next = *p;
ir_insn *insn = &ctx->ir_base[next];

if ((ir_op_flags[insn->op] & IR_OP_FLAG_CONTROL) && insn->op1 == ref) {
return next;
}
}
IR_ASSERT(0);
return IR_UNUSED;
}

/*** Modification helpers ***/
#define MAKE_NOP(_insn) do { \
ir_insn *__insn = _insn; \
Expand Down

0 comments on commit f8ff379

Please sign in to comment.