@@ -316,6 +316,81 @@ static void redirectTo(BasicBlock *Source, BasicBlock *Target, DebugLoc DL) {
316316 NewBr->setDebugLoc (DL);
317317}
318318
319+ void llvm::spliceBB (IRBuilderBase::InsertPoint IP, BasicBlock *New,
320+ bool CreateBranch, DebugLoc DL) {
321+ assert (New->getFirstInsertionPt () == New->begin () &&
322+ " Target BB must not have PHI nodes" );
323+
324+ // Move instructions to new block.
325+ BasicBlock *Old = IP.getBlock ();
326+ New->splice (New->begin (), Old, IP.getPoint (), Old->end ());
327+
328+ if (CreateBranch) {
329+ auto *NewBr = BranchInst::Create (New, Old);
330+ NewBr->setDebugLoc (DL);
331+ }
332+ }
333+
334+ void llvm::spliceBB (IRBuilder<> &Builder, BasicBlock *New, bool CreateBranch) {
335+ DebugLoc DebugLoc = Builder.getCurrentDebugLocation ();
336+ BasicBlock *Old = Builder.GetInsertBlock ();
337+
338+ spliceBB (Builder.saveIP (), New, CreateBranch, DebugLoc);
339+ if (CreateBranch)
340+ Builder.SetInsertPoint (Old->getTerminator ());
341+ else
342+ Builder.SetInsertPoint (Old);
343+
344+ // SetInsertPoint also updates the Builder's debug location, but we want to
345+ // keep the one the Builder was configured to use.
346+ Builder.SetCurrentDebugLocation (DebugLoc);
347+ }
348+
349+ BasicBlock *llvm::splitBB (IRBuilderBase::InsertPoint IP, bool CreateBranch,
350+ DebugLoc DL, llvm::Twine Name) {
351+ BasicBlock *Old = IP.getBlock ();
352+ BasicBlock *New = BasicBlock::Create (
353+ Old->getContext (), Name.isTriviallyEmpty () ? Old->getName () : Name,
354+ Old->getParent (), Old->getNextNode ());
355+ spliceBB (IP, New, CreateBranch, DL);
356+ New->replaceSuccessorsPhiUsesWith (Old, New);
357+ return New;
358+ }
359+
360+ BasicBlock *llvm::splitBB (IRBuilderBase &Builder, bool CreateBranch,
361+ llvm::Twine Name) {
362+ DebugLoc DebugLoc = Builder.getCurrentDebugLocation ();
363+ BasicBlock *New = splitBB (Builder.saveIP (), CreateBranch, DebugLoc, Name);
364+ if (CreateBranch)
365+ Builder.SetInsertPoint (Builder.GetInsertBlock ()->getTerminator ());
366+ else
367+ Builder.SetInsertPoint (Builder.GetInsertBlock ());
368+ // SetInsertPoint also updates the Builder's debug location, but we want to
369+ // keep the one the Builder was configured to use.
370+ Builder.SetCurrentDebugLocation (DebugLoc);
371+ return New;
372+ }
373+
374+ BasicBlock *llvm::splitBB (IRBuilder<> &Builder, bool CreateBranch,
375+ llvm::Twine Name) {
376+ DebugLoc DebugLoc = Builder.getCurrentDebugLocation ();
377+ BasicBlock *New = splitBB (Builder.saveIP (), CreateBranch, DebugLoc, Name);
378+ if (CreateBranch)
379+ Builder.SetInsertPoint (Builder.GetInsertBlock ()->getTerminator ());
380+ else
381+ Builder.SetInsertPoint (Builder.GetInsertBlock ());
382+ // SetInsertPoint also updates the Builder's debug location, but we want to
383+ // keep the one the Builder was configured to use.
384+ Builder.SetCurrentDebugLocation (DebugLoc);
385+ return New;
386+ }
387+
388+ BasicBlock *llvm::splitBBWithSuffix (IRBuilderBase &Builder, bool CreateBranch,
389+ llvm::Twine Suffix) {
390+ BasicBlock *Old = Builder.GetInsertBlock ();
391+ return splitBB (Builder, CreateBranch, Old->getName () + Suffix);
392+ }
393+
319394// This function creates a fake integer value and a fake use for the integer
320395// value. It returns the fake value created. This is useful in modeling the
321396// extra arguments to the outlined functions.
0 commit comments