aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-03-29 18:49:54 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2021-03-19 23:56:44 +0100
commitb2dc8031654a536313fe77951ee04c74a3017e0b (patch)
treed3fd2e6316d15640af487dea1534e58178b29848
parent701775cdf99d737aeaed00419eaff65d05ef1b57 (diff)
downloadsparse-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.c16
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) {