Skip to content

Commit

Permalink
Add ir_get_op() function
Browse files Browse the repository at this point in the history
  • Loading branch information
dstogov committed Nov 19, 2024
1 parent c0a6994 commit f51b8a8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
16 changes: 16 additions & 0 deletions ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,22 @@ void ir_set_op(ir_ctx *ctx, ir_ref ref, int32_t n, ir_ref val)
ir_insn_set_op(insn, n, val);
}

ir_ref ir_get_op(ir_ctx *ctx, ir_ref ref, int32_t n)
{
ir_insn *insn = &ctx->ir_base[ref];

#ifdef IR_DEBUG
if (n > 3) {
int32_t count;

IR_ASSERT(IR_OP_HAS_VAR_INPUTS(ir_op_flags[insn->op]));
count = insn->inputs_count;
IR_ASSERT(n <= count);
}
#endif
return ir_insn_op(insn, n);
}

ir_ref ir_param(ir_ctx *ctx, ir_type type, ir_ref region, const char *name, int pos)
{
return ir_emit(ctx, IR_OPT(IR_PARAM, type), region, ir_str(ctx, name), pos);
Expand Down
2 changes: 2 additions & 0 deletions ir.h
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,8 @@ IR_ALWAYS_INLINE void ir_set_op3(ir_ctx *ctx, ir_ref ref, ir_ref val)
ctx->ir_base[ref].op3 = val;
}

ir_ref ir_get_op(ir_ctx *ctx, ir_ref ref, int32_t n);

IR_ALWAYS_INLINE ir_ref ir_insn_op(const ir_insn *insn, int32_t n)
{
const ir_ref *p = insn->ops + n;
Expand Down

0 comments on commit f51b8a8

Please sign in to comment.