diff mbox series

[1/6] add insert_last_instruction()

Message ID 20210321161609.45905-2-luc.vanoostenryck@gmail.com (mailing list archive)
State Mainlined, archived
Headers show
Series use an helper to add an instruction to a BB | expand

Commit Message

Luc Van Oostenryck March 21, 2021, 4:16 p.m. UTC
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>
---
 linearize.h | 8 ++++++++
 1 file changed, 8 insertions(+)
diff mbox series

Patch

diff --git a/linearize.h b/linearize.h
index b6c8bf134065..493f6be1074c 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);