[IR] Add Instruction::getInsertionPointAfterDef()
authorNikita Popov <npopov@redhat.com>
Wed, 13 Jul 2022 14:53:11 +0000 (16:53 +0200)
committerNikita Popov <npopov@redhat.com>
Wed, 31 Aug 2022 08:50:10 +0000 (10:50 +0200)
commit972840aa3b3d83a3a49cb5cfa3f4e1582ee63a3b
tree0442f600ba86addae5a584bc30aec11300d589a0
parentba2b2b595fc3419425e274c18f96c0f60ef539e8
[IR] Add Instruction::getInsertionPointAfterDef()

Transforms occasionally want to insert an instruction directly
after the definition point of a value. This involves quite a few
different edge cases, e.g. for phi nodes the next insertion point
is not the next instruction, and for invokes and callbrs its not
even in the same block. Additionally, the insertion point may not
exist at all if catchswitch is involved.

This adds a general Instruction::getInsertionPointAfterDef() API to
implement the necessary logic. For now it is used in two places
where this should be mostly NFC. I will follow up with additional
uses where this fixes specific bugs in the existing implementations.

Differential Revision: https://reviews.llvm.org/D129660
llvm/include/llvm/IR/Instruction.h
llvm/lib/IR/Instruction.cpp
llvm/lib/Transforms/Coroutines/CoroFrame.cpp
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp