[PATCH] D140154: [IR][NFC] Cleanup: Removed non-const block iterators to force all updates go through an interface function
Vasileios Porpodas via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 15 12:39:07 PST 2022
vporpo created this revision.
vporpo added reviewers: aeubanks, asbirlea.
Herald added a subscriber: hiraditya.
Herald added a project: All.
vporpo requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D140154
Files:
llvm/include/llvm/IR/Instructions.h
llvm/lib/IR/Instructions.cpp
Index: llvm/lib/IR/Instructions.cpp
===================================================================
--- llvm/lib/IR/Instructions.cpp
+++ llvm/lib/IR/Instructions.cpp
@@ -106,7 +106,7 @@
ReservedSpace(PN.getNumOperands()) {
allocHungoffUses(PN.getNumOperands());
std::copy(PN.op_begin(), PN.op_end(), op_begin());
- std::copy(PN.block_begin(), PN.block_end(), block_begin());
+ copyIncomingBlocks(make_range(PN.block_begin(), PN.block_end()));
SubclassOptionalData = PN.SubclassOptionalData;
}
@@ -121,7 +121,7 @@
// clients might not expect this to happen. The code as it is thrashes the
// use/def lists, which is kinda lame.
std::copy(op_begin() + Idx + 1, op_end(), op_begin() + Idx);
- std::copy(block_begin() + Idx + 1, block_end(), block_begin() + Idx);
+ copyIncomingBlocks(make_range(block_begin() + Idx + 1, block_end()), Idx);
// Nuke the last value.
Op<-1>().set(nullptr);
Index: llvm/include/llvm/IR/Instructions.h
===================================================================
--- llvm/include/llvm/IR/Instructions.h
+++ llvm/include/llvm/IR/Instructions.h
@@ -2751,30 +2751,20 @@
// Block iterator interface. This provides access to the list of incoming
// basic blocks, which parallels the list of incoming values.
+ // Please note that we are not providing non-const iterators for blocks to
+ // force all updates go through an interface function.
using block_iterator = BasicBlock **;
using const_block_iterator = BasicBlock * const *;
- block_iterator block_begin() {
- return reinterpret_cast<block_iterator>(op_begin() + ReservedSpace);
- }
-
const_block_iterator block_begin() const {
return reinterpret_cast<const_block_iterator>(op_begin() + ReservedSpace);
}
- block_iterator block_end() {
- return block_begin() + getNumOperands();
- }
-
const_block_iterator block_end() const {
return block_begin() + getNumOperands();
}
- iterator_range<block_iterator> blocks() {
- return make_range(block_begin(), block_end());
- }
-
iterator_range<const_block_iterator> blocks() const {
return make_range(block_begin(), block_end());
}
@@ -2829,8 +2819,14 @@
}
void setIncomingBlock(unsigned i, BasicBlock *BB) {
- assert(BB && "PHI node got a null basic block!");
- block_begin()[i] = BB;
+ const_cast<block_iterator>(block_begin())[i] = BB;
+ }
+
+ /// Copies the basic blocks from \p BBRange to the incoming basic block list
+ /// of this PHINode, starting at \p ToIdx.
+ void copyIncomingBlocks(iterator_range<const_block_iterator> BBRange,
+ uint32_t ToIdx = 0) {
+ copy(BBRange, const_cast<block_iterator>(block_begin()) + ToIdx);
}
/// Replace every incoming basic block \p Old to basic block \p New.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D140154.483301.patch
Type: text/x-patch
Size: 2800 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221215/c1468fbc/attachment.bin>
More information about the llvm-commits
mailing list