diff options
| author | Roman Lebedev <lebedev.ri@gmail.com> | 2019-05-05 18:59:30 +0000 |
|---|---|---|
| committer | Roman Lebedev <lebedev.ri@gmail.com> | 2019-05-05 18:59:30 +0000 |
| commit | e3b1d82b5302102c17ea465ca609cde2a49da314 (patch) | |
| tree | 3bdbf877cf939a560ed3b6891f3826bd38f0d159 /llvm/include | |
| parent | 7ad5d14f3a2c916277e25737de9ff3f605131d1a (diff) | |
| download | bcm5719-llvm-e3b1d82b5302102c17ea465ca609cde2a49da314.tar.gz bcm5719-llvm-e3b1d82b5302102c17ea465ca609cde2a49da314.zip | |
[NFC] PHINode: introduce replaceIncomingBlockWith() function, use it
Summary:
There is `PHINode::getBasicBlockIndex()`, `PHINode::setIncomingBlock()`
and `PHINode::getNumOperands()`, but no function to replace every
specified `BasicBlock*` predecessor with some other specified `BasicBlock*`.
Clearly, there are a lot of places that could use that functionality.
Reviewers: chandlerc, craig.topper, spatel, danielcdh
Reviewed By: craig.topper
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D61011
llvm-svn: 359995
Diffstat (limited to 'llvm/include')
| -rw-r--r-- | llvm/include/llvm/IR/Instructions.h | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/llvm/include/llvm/IR/Instructions.h b/llvm/include/llvm/IR/Instructions.h index 095c82f5c42..b49a91bdc45 100644 --- a/llvm/include/llvm/IR/Instructions.h +++ b/llvm/include/llvm/IR/Instructions.h @@ -2738,6 +2738,14 @@ public: block_begin()[i] = BB; } + /// Replace every incoming basic block \p Old to basic block \p New. + void replaceIncomingBlockWith(BasicBlock *Old, BasicBlock *New) { + assert(New && Old && "PHI node got a null basic block!"); + for (unsigned Op = 0, NumOps = getNumOperands(); Op != NumOps; ++Op) + if (getIncomingBlock(Op) == Old) + setIncomingBlock(Op, New); + } + /// Add an incoming value to the end of the PHI list /// void addIncoming(Value *V, BasicBlock *BB) { |

