diff options
author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2021-03-20 18:18:23 +0100 |
---|---|---|
committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2021-03-21 15:58:14 +0100 |
commit | 9794908e1ad570920c470a8c817abbc3b195b876 (patch) | |
tree | 2a7ed48868340c9ba845eada6c194749e0dc78b9 | |
parent | 7b5cc7b6135733cbbce121cc94fdc4a5400f46b5 (diff) | |
download | sparse-9794908e1ad570920c470a8c817abbc3b195b876.tar.gz |
add insert_last_instruction()
It's relatively common to have to add an instruction at the end of a BB.
More exactly, at the end but just before the terminator instruction.
What is done for this is:
1) remove the terminator
2) add the new instruction
3) add the terminator back
This is a bit tedious, need to declare a temporary variable for the
terminator and, more generally, it's low-level details.
So, add an helper for doing this: insert_last_instruction().
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r-- | linearize.h | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/linearize.h b/linearize.h index b6c8bf13..493f6be1 100644 --- a/linearize.h +++ b/linearize.h @@ -195,6 +195,14 @@ static inline void add_instruction(struct instruction_list **list, struct instru add_ptr_list(list, insn); } +static inline void insert_last_instruction(struct basic_block *bb, struct instruction *insn) +{ + struct instruction *last = delete_last_instruction(&bb->insns); + add_instruction(&bb->insns, insn); + add_instruction(&bb->insns, last); + insn->bb = bb; +} + static inline void add_multijmp(struct multijmp_list **list, struct multijmp *multijmp) { add_ptr_list(list, multijmp); |