diff options
| author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2015-10-08 23:49:46 +0000 |
|---|---|---|
| committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2015-10-08 23:49:46 +0000 |
| commit | 52888a673859a5047acd08d60b43f173d126c8e7 (patch) | |
| tree | 9ef0445b493863e9e6e4a7fa269e91ba8bab0f58 /llvm/lib/IR/Instruction.cpp | |
| parent | 5a9640be324cf3ede6aa6ba714266b3bddf32db4 (diff) | |
| download | bcm5719-llvm-52888a673859a5047acd08d60b43f173d126c8e7.tar.gz bcm5719-llvm-52888a673859a5047acd08d60b43f173d126c8e7.zip | |
IR: Remove implicit iterator conversions from lib/IR, NFC
Stop converting implicitly between iterators and pointers/references in
lib/IR. For convenience, I've added a `getIterator()` accessor to
`ilist_node` so that callers don't need to know how to spell the
iterator class (i.e., they can use `X.getIterator()` instead of
`Function::iterator(X)`).
I'll eventually disallow these implicit conversions entirely, but
there's a lot of code, so it doesn't make sense to do it all in one
patch. One library or so at a time.
Why? To root out cases of `getNextNode()` and `getPrevNode()` being
used in iterator logic. The design of `ilist` makes that invalid when
the current node could be at the back of the list, but it happens to
"work" right now because of a bug where those functions never return
`nullptr` if you're using a half-node sentinel. Before I can fix the
function, I have to remove uses of it that rely on it misbehaving.
(Maybe the function should just be deleted anyway? But I don't want
deleting it -- potentially a huge project -- to block fixing
ilist/iplist.)
llvm-svn: 249782
Diffstat (limited to 'llvm/lib/IR/Instruction.cpp')
| -rw-r--r-- | llvm/lib/IR/Instruction.cpp | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/llvm/lib/IR/Instruction.cpp b/llvm/lib/IR/Instruction.cpp index 91ac83c10d4..b5a30a4969b 100644 --- a/llvm/lib/IR/Instruction.cpp +++ b/llvm/lib/IR/Instruction.cpp @@ -28,7 +28,7 @@ Instruction::Instruction(Type *ty, unsigned it, Use *Ops, unsigned NumOps, if (InsertBefore) { BasicBlock *BB = InsertBefore->getParent(); assert(BB && "Instruction to insert before is not in a basic block!"); - BB->getInstList().insert(InsertBefore, this); + BB->getInstList().insert(InsertBefore->getIterator(), this); } } @@ -64,31 +64,32 @@ Module *Instruction::getModule() { void Instruction::removeFromParent() { - getParent()->getInstList().remove(this); + getParent()->getInstList().remove(getIterator()); } iplist<Instruction>::iterator Instruction::eraseFromParent() { - return getParent()->getInstList().erase(this); + return getParent()->getInstList().erase(getIterator()); } /// insertBefore - Insert an unlinked instructions into a basic block /// immediately before the specified instruction. void Instruction::insertBefore(Instruction *InsertPos) { - InsertPos->getParent()->getInstList().insert(InsertPos, this); + InsertPos->getParent()->getInstList().insert(InsertPos->getIterator(), this); } /// insertAfter - Insert an unlinked instructions into a basic block /// immediately after the specified instruction. void Instruction::insertAfter(Instruction *InsertPos) { - InsertPos->getParent()->getInstList().insertAfter(InsertPos, this); + InsertPos->getParent()->getInstList().insertAfter(InsertPos->getIterator(), + this); } /// moveBefore - Unlink this instruction from its current basic block and /// insert it into the basic block that MovePos lives in, right before /// MovePos. void Instruction::moveBefore(Instruction *MovePos) { - MovePos->getParent()->getInstList().splice(MovePos,getParent()->getInstList(), - this); + MovePos->getParent()->getInstList().splice( + MovePos->getIterator(), getParent()->getInstList(), getIterator()); } /// Set or clear the unsafe-algebra flag on this instruction, which must be an |

