Skip to content

Commit

Permalink
tcg: Introduce tcg_remove_ops_after
Browse files Browse the repository at this point in the history
Introduce a function to remove everything emitted
since a given point.

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
  • Loading branch information
rth7680 committed Jun 14, 2021
1 parent 42eb6df commit a80cdd3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
10 changes: 10 additions & 0 deletions include/tcg/tcg.h
Expand Up @@ -1071,6 +1071,16 @@ void tcg_op_remove(TCGContext *s, TCGOp *op);
TCGOp *tcg_op_insert_before(TCGContext *s, TCGOp *op, TCGOpcode opc);
TCGOp *tcg_op_insert_after(TCGContext *s, TCGOp *op, TCGOpcode opc);

/**
* tcg_remove_ops_after:
* @op: target operation
*
* Discard any opcodes emitted since @op. Expected usage is to save
* a starting point with tcg_last_op(), speculatively emit opcodes,
* then decide whether or not to keep those opcodes after the fact.
*/
void tcg_remove_ops_after(TCGOp *op);

void tcg_optimize(TCGContext *s);

/* Allocate a new temporary and initialize it with a constant. */
Expand Down
13 changes: 13 additions & 0 deletions tcg/tcg.c
Expand Up @@ -2083,6 +2083,19 @@ void tcg_op_remove(TCGContext *s, TCGOp *op)
#endif
}

void tcg_remove_ops_after(TCGOp *op)
{
TCGContext *s = tcg_ctx;

while (true) {
TCGOp *last = tcg_last_op();
if (last == op) {
return;
}
tcg_op_remove(s, last);
}
}

static TCGOp *tcg_op_alloc(TCGOpcode opc)
{
TCGContext *s = tcg_ctx;
Expand Down

0 comments on commit a80cdd3

Please sign in to comment.