Skip to content

Commit b072cab

Browse files
committed
Undo moving spltBB
1 parent 70c65b3 commit b072cab

File tree

5 files changed

+186
-124
lines changed

5 files changed

+186
-124
lines changed

llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,54 @@ struct TargetRegionEntryInfo;
3333
class OffloadEntriesInfoManager;
3434
class OpenMPIRBuilder;
3535

36+
/// Move the instruction after an InsertPoint to the beginning of another
37+
/// BasicBlock.
38+
///
39+
/// The instructions after \p IP are moved to the beginning of \p New which must
40+
/// not have any PHINodes. If \p CreateBranch is true, a branch instruction to
41+
/// \p New will be added such that there is no semantic change. Otherwise, the
42+
/// \p IP insert block remains degenerate and it is up to the caller to insert a
43+
/// terminator. \p DL is used as the debug location for the branch instruction
44+
/// if one is created.
45+
void spliceBB(IRBuilderBase::InsertPoint IP, BasicBlock *New, bool CreateBranch,
46+
DebugLoc DL);
47+
48+
/// Splice a BasicBlock at an IRBuilder's current insertion point. Its new
49+
/// insert location will stick to after the instruction before the insertion
50+
/// point (instead of moving with the instruction the InsertPoint stores
51+
/// internally).
52+
void spliceBB(IRBuilder<> &Builder, BasicBlock *New, bool CreateBranch);
53+
54+
/// Split a BasicBlock at an InsertPoint, even if the block is degenerate
55+
/// (missing the terminator).
56+
///
57+
/// llvm::SplitBasicBlock and BasicBlock::splitBasicBlock require a well-formed
58+
/// BasicBlock. \p Name is used for the new successor block. If \p CreateBranch
59+
/// is true, a branch to the new successor will new created such that
60+
/// semantically there is no change; otherwise the block of the insertion point
61+
/// remains degenerate and it is the caller's responsibility to insert a
62+
/// terminator. \p DL is used as the debug location for the branch instruction
63+
/// if one is created. Returns the new successor block.
64+
BasicBlock *splitBB(IRBuilderBase::InsertPoint IP, bool CreateBranch,
65+
DebugLoc DL, llvm::Twine Name = {});
66+
67+
/// Split a BasicBlock at \p Builder's insertion point, even if the block is
68+
/// degenerate (missing the terminator). Its new insert location will stick to
69+
/// after the instruction before the insertion point (instead of moving with the
70+
/// instruction the InsertPoint stores internally).
71+
BasicBlock *splitBB(IRBuilderBase &Builder, bool CreateBranch,
72+
llvm::Twine Name = {});
73+
74+
/// Split a BasicBlock at \p Builder's insertion point, even if the block is
75+
/// degenerate (missing the terminator). Its new insert location will stick to
76+
/// after the instruction before the insertion point (instead of moving with the
77+
/// instruction the InsertPoint stores internally).
78+
BasicBlock *splitBB(IRBuilder<> &Builder, bool CreateBranch, llvm::Twine Name);
79+
80+
/// Like splitBB, but reuses the current block's name for the new name.
81+
BasicBlock *splitBBWithSuffix(IRBuilderBase &Builder, bool CreateBranch,
82+
llvm::Twine Suffix = ".split");
83+
3684
/// Captures attributes that affect generating LLVM-IR using the
3785
/// OpenMPIRBuilder and related classes. Note that not all attributes are
3886
/// required for all classes or functions. In some use cases the configuration

llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "llvm/ADT/SetVector.h"
2121
#include "llvm/IR/BasicBlock.h"
2222
#include "llvm/IR/Dominators.h"
23-
#include "llvm/IR/IRBuilder.h"
2423
#include <cassert>
2524

2625
namespace llvm {
@@ -385,54 +384,6 @@ void SplitLandingPadPredecessors(
385384
DomTreeUpdater *DTU = nullptr, LoopInfo *LI = nullptr,
386385
MemorySSAUpdater *MSSAU = nullptr, bool PreserveLCSSA = false);
387386

388-
/// Move the instruction after an InsertPoint to the beginning of another
389-
/// BasicBlock.
390-
///
391-
/// The instructions after \p IP are moved to the beginning of \p New which must
392-
/// not have any PHINodes. If \p CreateBranch is true, a branch instruction to
393-
/// \p New will be added such that there is no semantic change. Otherwise, the
394-
/// \p IP insert block remains degenerate and it is up to the caller to insert a
395-
/// terminator. \p DL is used as the debug location for the branch instruction
396-
/// if one is created.
397-
void spliceBB(IRBuilderBase::InsertPoint IP, BasicBlock *New, bool CreateBranch,
398-
DebugLoc DL);
399-
400-
/// Splice a BasicBlock at an IRBuilder's current insertion point. Its new
401-
/// insert location will stick to after the instruction before the insertion
402-
/// point (instead of moving with the instruction the InsertPoint stores
403-
/// internally).
404-
void spliceBB(IRBuilder<> &Builder, BasicBlock *New, bool CreateBranch);
405-
406-
/// Split a BasicBlock at an InsertPoint, even if the block is degenerate
407-
/// (missing the terminator).
408-
///
409-
/// llvm::SplitBasicBlock and BasicBlock::splitBasicBlock require a well-formed
410-
/// BasicBlock. \p Name is used for the new successor block. If \p CreateBranch
411-
/// is true, a branch to the new successor will new created such that
412-
/// semantically there is no change; otherwise the block of the insertion point
413-
/// remains degenerate and it is the caller's responsibility to insert a
414-
/// terminator. \p DL is used as the debug location for the branch instruction
415-
/// if one is created. Returns the new successor block.
416-
BasicBlock *splitBB(IRBuilderBase::InsertPoint IP, bool CreateBranch,
417-
DebugLoc DL, llvm::Twine Name = {});
418-
419-
/// Split a BasicBlock at \p Builder's insertion point, even if the block is
420-
/// degenerate (missing the terminator). Its new insert location will stick to
421-
/// after the instruction before the insertion point (instead of moving with the
422-
/// instruction the InsertPoint stores internally).
423-
BasicBlock *splitBB(IRBuilderBase &Builder, bool CreateBranch,
424-
llvm::Twine Name = {});
425-
426-
/// Split a BasicBlock at \p Builder's insertion point, even if the block is
427-
/// degenerate (missing the terminator). Its new insert location will stick to
428-
/// after the instruction before the insertion point (instead of moving with the
429-
/// instruction the InsertPoint stores internally).
430-
BasicBlock *splitBB(IRBuilder<> &Builder, bool CreateBranch, llvm::Twine Name);
431-
432-
/// Like splitBB, but reuses the current block's name for the new name.
433-
BasicBlock *splitBBWithSuffix(IRBuilderBase &Builder, bool CreateBranch,
434-
llvm::Twine Suffix = ".split");
435-
436387
/// This method duplicates the specified return instruction into a predecessor
437388
/// which ends in an unconditional branch. If the return instruction returns a
438389
/// value defined by a PHI, propagate the right value into the return. It

llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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.

llvm/lib/Transforms/Utils/BasicBlockUtils.cpp

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,81 +1548,6 @@ void llvm::SplitLandingPadPredecessors(BasicBlock *OrigBB,
15481548
PreserveLCSSA);
15491549
}
15501550

1551-
void llvm::spliceBB(IRBuilderBase::InsertPoint IP, BasicBlock *New,
1552-
bool CreateBranch, DebugLoc DL) {
1553-
assert(New->getFirstInsertionPt() == New->begin() &&
1554-
"Target BB must not have PHI nodes");
1555-
1556-
// Move instructions to new block.
1557-
BasicBlock *Old = IP.getBlock();
1558-
New->splice(New->begin(), Old, IP.getPoint(), Old->end());
1559-
1560-
if (CreateBranch) {
1561-
auto *NewBr = BranchInst::Create(New, Old);
1562-
NewBr->setDebugLoc(DL);
1563-
}
1564-
}
1565-
1566-
void llvm::spliceBB(IRBuilder<> &Builder, BasicBlock *New, bool CreateBranch) {
1567-
DebugLoc DebugLoc = Builder.getCurrentDebugLocation();
1568-
BasicBlock *Old = Builder.GetInsertBlock();
1569-
1570-
spliceBB(Builder.saveIP(), New, CreateBranch, DebugLoc);
1571-
if (CreateBranch)
1572-
Builder.SetInsertPoint(Old->getTerminator());
1573-
else
1574-
Builder.SetInsertPoint(Old);
1575-
1576-
// SetInsertPoint also updates the Builder's debug location, but we want to
1577-
// keep the one the Builder was configured to use.
1578-
Builder.SetCurrentDebugLocation(DebugLoc);
1579-
}
1580-
1581-
BasicBlock *llvm::splitBB(IRBuilderBase::InsertPoint IP, bool CreateBranch,
1582-
DebugLoc DL, llvm::Twine Name) {
1583-
BasicBlock *Old = IP.getBlock();
1584-
BasicBlock *New = BasicBlock::Create(
1585-
Old->getContext(), Name.isTriviallyEmpty() ? Old->getName() : Name,
1586-
Old->getParent(), Old->getNextNode());
1587-
spliceBB(IP, New, CreateBranch, DL);
1588-
New->replaceSuccessorsPhiUsesWith(Old, New);
1589-
return New;
1590-
}
1591-
1592-
BasicBlock *llvm::splitBB(IRBuilderBase &Builder, bool CreateBranch,
1593-
llvm::Twine Name) {
1594-
DebugLoc DebugLoc = Builder.getCurrentDebugLocation();
1595-
BasicBlock *New = splitBB(Builder.saveIP(), CreateBranch, DebugLoc, Name);
1596-
if (CreateBranch)
1597-
Builder.SetInsertPoint(Builder.GetInsertBlock()->getTerminator());
1598-
else
1599-
Builder.SetInsertPoint(Builder.GetInsertBlock());
1600-
// SetInsertPoint also updates the Builder's debug location, but we want to
1601-
// keep the one the Builder was configured to use.
1602-
Builder.SetCurrentDebugLocation(DebugLoc);
1603-
return New;
1604-
}
1605-
1606-
BasicBlock *llvm::splitBB(IRBuilder<> &Builder, bool CreateBranch,
1607-
llvm::Twine Name) {
1608-
DebugLoc DebugLoc = Builder.getCurrentDebugLocation();
1609-
BasicBlock *New = splitBB(Builder.saveIP(), CreateBranch, DebugLoc, Name);
1610-
if (CreateBranch)
1611-
Builder.SetInsertPoint(Builder.GetInsertBlock()->getTerminator());
1612-
else
1613-
Builder.SetInsertPoint(Builder.GetInsertBlock());
1614-
// SetInsertPoint also updates the Builder's debug location, but we want to
1615-
// keep the one the Builder was configured to use.
1616-
Builder.SetCurrentDebugLocation(DebugLoc);
1617-
return New;
1618-
}
1619-
1620-
BasicBlock *llvm::splitBBWithSuffix(IRBuilderBase &Builder, bool CreateBranch,
1621-
llvm::Twine Suffix) {
1622-
BasicBlock *Old = Builder.GetInsertBlock();
1623-
return splitBB(Builder, CreateBranch, Old->getName() + Suffix);
1624-
}
1625-
16261551
ReturnInst *llvm::FoldReturnIntoUncondBranch(ReturnInst *RI, BasicBlock *BB,
16271552
BasicBlock *Pred,
16281553
DomTreeUpdater *DTU) {

llvm/lib/Transforms/Utils/BuildBuiltins.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,69 @@ static bool canUseSizedAtomicCall(unsigned Size, Align Alignment,
4646
Size <= LargestSize;
4747
}
4848

49+
/// Move the instruction after an InsertPoint to the beginning of another
50+
/// BasicBlock.
51+
///
52+
/// The instructions after \p IP are moved to the beginning of \p New which must
53+
/// not have any PHINodes. If \p CreateBranch is true, a branch instruction to
54+
/// \p New will be added such that there is no semantic change. Otherwise, the
55+
/// \p IP insert block remains degenerate and it is up to the caller to insert a
56+
/// terminator. \p DL is used as the debug location for the branch instruction
57+
/// if one is created.
58+
static void spliceBB(IRBuilderBase::InsertPoint IP, BasicBlock *New,
59+
bool CreateBranch, DebugLoc DL) {
60+
assert(New->getFirstInsertionPt() == New->begin() &&
61+
"Target BB must not have PHI nodes");
62+
63+
// Move instructions to new block.
64+
BasicBlock *Old = IP.getBlock();
65+
New->splice(New->begin(), Old, IP.getPoint(), Old->end());
66+
67+
if (CreateBranch) {
68+
auto *NewBr = BranchInst::Create(New, Old);
69+
NewBr->setDebugLoc(DL);
70+
}
71+
}
72+
73+
/// Split a BasicBlock at an InsertPoint, even if the block is degenerate
74+
/// (missing the terminator).
75+
///
76+
/// llvm::SplitBasicBlock and BasicBlock::splitBasicBlock require a well-formed
77+
/// BasicBlock. \p Name is used for the new successor block. If \p CreateBranch
78+
/// is true, a branch to the new successor will new created such that
79+
/// semantically there is no change; otherwise the block of the insertion point
80+
/// remains degenerate and it is the caller's responsibility to insert a
81+
/// terminator. \p DL is used as the debug location for the branch instruction
82+
/// if one is created. Returns the new successor block.
83+
static BasicBlock *splitBB(IRBuilderBase::InsertPoint IP, bool CreateBranch,
84+
DebugLoc DL, llvm::Twine Name) {
85+
BasicBlock *Old = IP.getBlock();
86+
BasicBlock *New = BasicBlock::Create(
87+
Old->getContext(), Name.isTriviallyEmpty() ? Old->getName() : Name,
88+
Old->getParent(), Old->getNextNode());
89+
spliceBB(IP, New, CreateBranch, DL);
90+
New->replaceSuccessorsPhiUsesWith(Old, New);
91+
return New;
92+
}
93+
94+
/// Split a BasicBlock at \p Builder's insertion point, even if the block is
95+
/// degenerate (missing the terminator). Its new insert location will stick to
96+
/// after the instruction before the insertion point (instead of moving with the
97+
/// instruction the InsertPoint stores internally).
98+
static BasicBlock *splitBB(IRBuilderBase &Builder, bool CreateBranch,
99+
llvm::Twine Name) {
100+
DebugLoc DebugLoc = Builder.getCurrentDebugLocation();
101+
BasicBlock *New = splitBB(Builder.saveIP(), CreateBranch, DebugLoc, Name);
102+
if (CreateBranch)
103+
Builder.SetInsertPoint(Builder.GetInsertBlock()->getTerminator());
104+
else
105+
Builder.SetInsertPoint(Builder.GetInsertBlock());
106+
// SetInsertPoint also updates the Builder's debug location, but we want to
107+
// keep the one the Builder was configured to use.
108+
Builder.SetCurrentDebugLocation(DebugLoc);
109+
return New;
110+
}
111+
49112
// Helper to check if a type is in a variant
50113
template <typename T, typename Variant> struct is_in_variant;
51114

0 commit comments

Comments
 (0)