From 3ff704fa2b67d6c857142218c5aca3058b6239fc Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 13 Jan 2009 07:43:51 +0000 Subject: [PATCH] add a new insertAfter method, patch by Tom Jablin! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@62158 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/ADT/ilist.h | 7 +++++++ include/llvm/Instruction.h | 4 ++++ lib/VMCore/Instruction.cpp | 6 ++++++ 3 files changed, 17 insertions(+) diff --git a/include/llvm/ADT/ilist.h b/include/llvm/ADT/ilist.h index bd2fd0df871..6619f0a71eb 100644 --- a/include/llvm/ADT/ilist.h +++ b/include/llvm/ADT/ilist.h @@ -384,6 +384,13 @@ public: return New; } + iterator insertAfter(iterator where, NodeTy *New) { + if (empty()) + return insert(begin(), New); + else + return insert(++where, New); + } + NodeTy *remove(iterator &IT) { assert(IT != end() && "Cannot remove end of list!"); NodeTy *Node = &*IT; diff --git a/include/llvm/Instruction.h b/include/llvm/Instruction.h index 9a7f769a94f..a9cc000a25e 100644 --- a/include/llvm/Instruction.h +++ b/include/llvm/Instruction.h @@ -101,6 +101,10 @@ public: /// immediately before the specified instruction. void insertBefore(Instruction *InsertPos); + /// insertAfter - Insert an unlinked instructions into a basic block + /// immediately after the specified instruction. + void insertAfter(Instruction *InsertPos); + /// moveBefore - Unlink this instruction from its current basic block and /// insert it into the basic block that MovePos lives in, right before /// MovePos. diff --git a/lib/VMCore/Instruction.cpp b/lib/VMCore/Instruction.cpp index 6635e704e2a..b09ab93aa11 100644 --- a/lib/VMCore/Instruction.cpp +++ b/lib/VMCore/Instruction.cpp @@ -74,6 +74,12 @@ void Instruction::insertBefore(Instruction *InsertPos) { InsertPos->getParent()->getInstList().insert(InsertPos, 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); +} + /// moveBefore - Unlink this instruction from its current basic block and /// insert it into the basic block that MovePos lives in, right before /// MovePos.