diff options
author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-03-29 18:49:54 +0200 |
---|---|---|
committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2021-03-19 23:56:44 +0100 |
commit | b2dc8031654a536313fe77951ee04c74a3017e0b (patch) | |
tree | d3fd2e6316d15640af487dea1534e58178b29848 | |
parent | 701775cdf99d737aeaed00419eaff65d05ef1b57 (diff) | |
download | sparse-b2dc8031654a536313fe77951ee04c74a3017e0b.tar.gz |
let insert_branch() reuse the terminating instruction
insert_branch() changes a switch or a conditional branch into a jump.
This is implemented by deleting the old instruction and allocating
the new one. This is not needed here since no reference to the
old instruction is kept.
So, simply reuse the terminating instruction and change it.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r-- | linearize.c | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/linearize.c b/linearize.c index 2268b095..1d85cf2b 100644 --- a/linearize.c +++ b/linearize.c @@ -696,18 +696,14 @@ static void set_activeblock(struct entrypoint *ep, struct basic_block *bb) void insert_branch(struct instruction *jmp, struct basic_block *target) { struct basic_block *bb = jmp->bb; - struct instruction *br, *old; struct basic_block *child; - /* Remove the switch */ - old = delete_last_instruction(&bb->insns); - assert(old == jmp); - kill_instruction(old); - - br = alloc_instruction(OP_BR, 0); - br->bb = bb; - br->bb_true = target; - add_instruction(&bb->insns, br); + kill_use(&jmp->cond); + jmp->bb_true = target; + jmp->bb_false = NULL; + jmp->cond = NULL; + jmp->size = 0; + jmp->opcode = OP_BR; FOR_EACH_PTR(bb->children, child) { if (child == target) { |