aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/lib/IR/BasicBlock.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/llvm/lib/IR/BasicBlock.cpp')
-rw-r--r--contrib/llvm-project/llvm/lib/IR/BasicBlock.cpp70
1 files changed, 57 insertions, 13 deletions
diff --git a/contrib/llvm-project/llvm/lib/IR/BasicBlock.cpp b/contrib/llvm-project/llvm/lib/IR/BasicBlock.cpp
index f064ff503eba..63d363e2d082 100644
--- a/contrib/llvm-project/llvm/lib/IR/BasicBlock.cpp
+++ b/contrib/llvm-project/llvm/lib/IR/BasicBlock.cpp
@@ -62,9 +62,9 @@ void BasicBlock::insertInto(Function *NewParent, BasicBlock *InsertBefore) {
assert(!Parent && "Already has a parent");
if (InsertBefore)
- NewParent->getBasicBlockList().insert(InsertBefore->getIterator(), this);
+ NewParent->insert(InsertBefore->getIterator(), this);
else
- NewParent->getBasicBlockList().push_back(this);
+ NewParent->insert(NewParent->end(), this);
}
BasicBlock::~BasicBlock() {
@@ -134,14 +134,13 @@ iplist<BasicBlock>::iterator BasicBlock::eraseFromParent() {
}
void BasicBlock::moveBefore(BasicBlock *MovePos) {
- MovePos->getParent()->getBasicBlockList().splice(
- MovePos->getIterator(), getParent()->getBasicBlockList(), getIterator());
+ MovePos->getParent()->splice(MovePos->getIterator(), getParent(),
+ getIterator());
}
void BasicBlock::moveAfter(BasicBlock *MovePos) {
- MovePos->getParent()->getBasicBlockList().splice(
- ++MovePos->getIterator(), getParent()->getBasicBlockList(),
- getIterator());
+ MovePos->getParent()->splice(++MovePos->getIterator(), getParent(),
+ getIterator());
}
const Module *BasicBlock::getModule() const {
@@ -253,6 +252,30 @@ BasicBlock::const_iterator BasicBlock::getFirstInsertionPt() const {
return InsertPt;
}
+BasicBlock::const_iterator BasicBlock::getFirstNonPHIOrDbgOrAlloca() const {
+ const Instruction *FirstNonPHI = getFirstNonPHI();
+ if (!FirstNonPHI)
+ return end();
+
+ const_iterator InsertPt = FirstNonPHI->getIterator();
+ if (InsertPt->isEHPad())
+ ++InsertPt;
+
+ if (isEntryBlock()) {
+ const_iterator End = end();
+ while (InsertPt != End &&
+ (isa<AllocaInst>(*InsertPt) || isa<DbgInfoIntrinsic>(*InsertPt) ||
+ isa<PseudoProbeInst>(*InsertPt))) {
+ if (const AllocaInst *AI = dyn_cast<AllocaInst>(&*InsertPt)) {
+ if (!AI->isStaticAlloca())
+ break;
+ }
+ ++InsertPt;
+ }
+ }
+ return InsertPt;
+}
+
void BasicBlock::dropAllReferences() {
for (Instruction &I : *this)
I.dropAllReferences();
@@ -391,7 +414,7 @@ BasicBlock *BasicBlock::splitBasicBlock(iterator I, const Twine &BBName,
DebugLoc Loc = I->getDebugLoc();
// Move all of the specified instructions from the original basic block into
// the new basic block.
- New->getInstList().splice(New->end(), this->getInstList(), I, end());
+ New->splice(New->end(), this, I, end());
// Add a branch instruction to the newly formed basic block.
BranchInst *BI = BranchInst::Create(New, this);
@@ -420,7 +443,7 @@ BasicBlock *BasicBlock::splitBasicBlockBefore(iterator I, const Twine &BBName) {
DebugLoc Loc = I->getDebugLoc();
// Move all of the specified instructions from the original basic block into
// the new basic block.
- New->getInstList().splice(New->end(), this->getInstList(), begin(), I);
+ New->splice(New->end(), this, begin(), I);
// Loop through all of the predecessors of the 'this' block (which will be the
// predecessors of the New block), replace the specified successor 'this'
@@ -428,7 +451,11 @@ BasicBlock *BasicBlock::splitBasicBlockBefore(iterator I, const Twine &BBName) {
// If there were PHI nodes in 'this' block, the PHI nodes are updated
// to reflect that the incoming branches will be from the New block and not
// from predecessors of the 'this' block.
- for (BasicBlock *Pred : predecessors(this)) {
+ // Save predecessors to separate vector before modifying them.
+ SmallVector<BasicBlock *, 4> Predecessors;
+ for (BasicBlock *Pred : predecessors(this))
+ Predecessors.push_back(Pred);
+ for (BasicBlock *Pred : Predecessors) {
Instruction *TI = Pred->getTerminator();
TI->replaceSuccessorWith(this, New);
this->replacePhiUsesWith(Pred, New);
@@ -440,6 +467,23 @@ BasicBlock *BasicBlock::splitBasicBlockBefore(iterator I, const Twine &BBName) {
return New;
}
+void BasicBlock::splice(BasicBlock::iterator ToIt, BasicBlock *FromBB,
+ BasicBlock::iterator FromBeginIt,
+ BasicBlock::iterator FromEndIt) {
+#ifdef EXPENSIVE_CHECKS
+ // Check that FromBeginIt is befor FromEndIt.
+ auto FromBBEnd = FromBB->end();
+ for (auto It = FromBeginIt; It != FromEndIt; ++It)
+ assert(It != FromBBEnd && "FromBeginIt not before FromEndIt!");
+#endif // EXPENSIVE_CHECKS
+ getInstList().splice(ToIt, FromBB->getInstList(), FromBeginIt, FromEndIt);
+}
+
+BasicBlock::iterator BasicBlock::erase(BasicBlock::iterator FromIt,
+ BasicBlock::iterator ToIt) {
+ return InstList.erase(FromIt, ToIt);
+}
+
void BasicBlock::replacePhiUsesWith(BasicBlock *Old, BasicBlock *New) {
// N.B. This might not be a complete BasicBlock, so don't assume
// that it ends with a non-phi instruction.
@@ -474,17 +518,17 @@ const LandingPadInst *BasicBlock::getLandingPadInst() const {
return dyn_cast<LandingPadInst>(getFirstNonPHI());
}
-Optional<uint64_t> BasicBlock::getIrrLoopHeaderWeight() const {
+std::optional<uint64_t> BasicBlock::getIrrLoopHeaderWeight() const {
const Instruction *TI = getTerminator();
if (MDNode *MDIrrLoopHeader =
TI->getMetadata(LLVMContext::MD_irr_loop)) {
MDString *MDName = cast<MDString>(MDIrrLoopHeader->getOperand(0));
if (MDName->getString().equals("loop_header_weight")) {
auto *CI = mdconst::extract<ConstantInt>(MDIrrLoopHeader->getOperand(1));
- return Optional<uint64_t>(CI->getValue().getZExtValue());
+ return std::optional<uint64_t>(CI->getValue().getZExtValue());
}
}
- return Optional<uint64_t>();
+ return std::nullopt;
}
BasicBlock::iterator llvm::skipDebugIntrinsics(BasicBlock::iterator It) {