kill_instruction() may need to be forced or not
There is essentially three cases where kill_instruction() is
called:
1) when implicitely removing an instruction via
kill_use()/remove_usage() once all users of (the target of)
this instruction have been removed and so this instruction
become unneeded.
2) when explicitely removing a specific instruction.
3) when explicitely removing all instructions in a basic block
because it became unreachable.
For 'pure' instructions, like the arithmetic operators, these
three cases can be handled exactly the same but for instructions
having side-effects, special care is needed.
For them case 1) should do nothing while cases 2) & 3) should
remove the instruction and adjust the usage of its operands like
for normal instructions.
To handle this gracefully:
- rename kill_instruction() into kill_insn()
- add a new argument ('force') to kill_insn()
- create kill_instruction() & kill_instruction_force() as inline
functions calling kill_insn() with 'force' set respectively to 0 & 1.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Signed-off-by: Christopher Li <sparse@chrisli.org>
3 files changed