Added IRBuilder::SetInsertPoint(Use) to find a valid insertion point
authorAndrew Trick <atrick@apple.com>
Wed, 29 Jun 2011 23:01:52 +0000 (23:01 +0000)
committerAndrew Trick <atrick@apple.com>
Wed, 29 Jun 2011 23:01:52 +0000 (23:01 +0000)
that dominates the given Use.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@134111 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/IRBuilder.h

index 9058e3e25354a92736a31223d0e9ece6674d29db..94592800fe4a2cad5f3fc77d9d27595338d96020 100644 (file)
@@ -90,6 +90,19 @@ public:
     InsertPt = IP;
   }
 
+  /// SetInsertPoint(Use) - Find the nearest point that dominates this use, and
+  /// specify that created instructions should be inserted at this point.
+  void SetInsertPoint(Use &U) {
+    Instruction *UseInst = cast<Instruction>(U.getUser());
+    if (PHINode *Phi = dyn_cast<PHINode>(UseInst)) {
+      BasicBlock *PredBB = Phi->getIncomingBlock(U);
+      assert(U != PredBB->getTerminator() && "critical edge not split");
+      SetInsertPoint(PredBB, PredBB->getTerminator());
+      return;
+    }
+    SetInsertPoint(UseInst);
+  }
+
   /// SetCurrentDebugLocation - Set location information used by debugging
   /// information.
   void SetCurrentDebugLocation(const DebugLoc &L) {
@@ -342,6 +355,12 @@ public:
     SetCurrentDebugLocation(IP->getDebugLoc());
   }
 
+  explicit IRBuilder(Use &U)
+    : IRBuilderBase(U->getContext()), Folder() {
+    SetInsertPoint(U);
+    SetCurrentDebugLocation(cast<Instruction>(U.getUser())->getDebugLoc());
+  }
+
   IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, const T& F)
     : IRBuilderBase(TheBB->getContext()), Folder(F) {
     SetInsertPoint(TheBB, IP);