From b2dc8031654a536313fe77951ee04c74a3017e0b Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Sun, 29 Mar 2020 18:49:54 +0200 Subject: 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 --- linearize.c | 16 ++++++---------- 1 file 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) { -- cgit 1.2.3-korg