-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[NFC][DebugInfo] Use iterator moveBefore at many call-sites #123583
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -207,12 +207,19 @@ class Instruction : public User, | |
/// Insert an unlinked instruction into a basic block immediately before | ||
/// the specified instruction. | ||
void insertBefore(Instruction *InsertPos); | ||
|
||
/// Insert an unlinked instruction into a basic block immediately before | ||
/// the specified position. | ||
void insertBefore(InstListType::iterator InsertPos); | ||
|
||
/// Insert an unlinked instruction into a basic block immediately after the | ||
/// specified instruction. | ||
void insertAfter(Instruction *InsertPos); | ||
|
||
/// Insert an unlinked instruction into a basic block immediately after the | ||
/// specified position. | ||
void insertAfter(InstListType::iterator InsertPos); | ||
|
||
/// Inserts an unlinked instruction into \p ParentBB at position \p It and | ||
/// returns the iterator of the inserted instruction. | ||
InstListType::iterator insertInto(BasicBlock *ParentBB, | ||
|
@@ -224,11 +231,15 @@ class Instruction : public User, | |
/// the basic block that MovePos lives in, right before MovePos. | ||
void moveBefore(Instruction *MovePos); | ||
|
||
/// Unlink this instruction from its current basic block and insert it into | ||
/// the basic block that MovePos lives in, right before MovePos. | ||
void moveBefore(InstListType::iterator InsertPos); | ||
|
||
/// Perform a \ref moveBefore operation, while signalling that the caller | ||
/// intends to preserve the original ordering of instructions. This implicitly | ||
/// means that any adjacent debug-info should move with this instruction. | ||
/// This method is currently a no-op placeholder, but it will become meaningful | ||
/// when the "RemoveDIs" project is enabled. | ||
/// This method is currently a no-op placeholder, but it will become | ||
/// meaningful when the "RemoveDIs" project is enabled. | ||
Comment on lines
+241
to
+242
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this comment stale? |
||
void moveBeforePreserving(Instruction *MovePos); | ||
|
||
private: | ||
|
@@ -242,13 +253,19 @@ class Instruction : public User, | |
/// \pre I is a valid iterator into BB. | ||
void moveBefore(BasicBlock &BB, InstListType::iterator I); | ||
|
||
/// (See other overload for moveBeforePreserving). | ||
void moveBeforePreserving(BasicBlock &BB, InstListType::iterator I); | ||
/// Unlink this instruction from its current basic block and insert it into | ||
/// the basic block that MovePos lives in, right before MovePos. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: mismatch param name in comment |
||
void moveBeforePreserving(InstListType::iterator I); | ||
|
||
/// Unlink this instruction from its current basic block and insert it into | ||
/// the basic block that MovePos lives in, right after MovePos. | ||
void moveAfter(Instruction *MovePos); | ||
|
||
/// Unlink this instruction from its current basic block and insert it into | ||
/// the basic block that MovePos lives in, right after MovePos. | ||
void moveAfter(InstListType::iterator MovePos); | ||
|
||
/// See \ref moveBeforePreserving . | ||
void moveAfterPreserving(Instruction *MovePos); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1264,7 +1264,7 @@ simplifyRelocatesOffABase(GCRelocateInst *RelocatedBase, | |
if (auto *RI = dyn_cast<GCRelocateInst>(R)) | ||
if (RI->getStatepoint() == RelocatedBase->getStatepoint()) | ||
if (RI->getBasePtrIndex() == RelocatedBase->getBasePtrIndex()) { | ||
RelocatedBase->moveBefore(RI); | ||
RelocatedBase->moveBefore(RI->getIterator()); | ||
MadeChange = true; | ||
break; | ||
} | ||
|
@@ -2690,7 +2690,7 @@ bool CodeGenPrepare::optimizeCallInst(CallInst *CI, ModifyDT &ModifiedDT) { | |
ExtVal->getParent() == CI->getParent()) | ||
return false; | ||
// Sink a zext feeding stlxr/stxr before it, so it can be folded into it. | ||
ExtVal->moveBefore(CI); | ||
ExtVal->moveBefore(CI->getIterator()); | ||
// Mark this instruction as "inserted by CGP", so that other | ||
// optimizations don't touch it. | ||
InsertedInsts.insert(ExtVal); | ||
|
@@ -3036,7 +3036,7 @@ bool CodeGenPrepare::dupRetToEnableTailCallOpts(BasicBlock *BB, | |
for (auto *CI : CallInsts) { | ||
for (auto const *FakeUse : FakeUses) { | ||
auto *ClonedInst = FakeUse->clone(); | ||
ClonedInst->insertBefore(CI); | ||
ClonedInst->insertBefore(CI->getIterator()); | ||
} | ||
} | ||
BB->eraseFromParent(); | ||
|
@@ -7552,9 +7552,9 @@ bool CodeGenPrepare::optimizeSelectInst(SelectInst *SI) { | |
// Sink expensive instructions into the conditional blocks to avoid executing | ||
// them speculatively. | ||
for (Instruction *I : TrueInstrs) | ||
I->moveBefore(TrueBranch); | ||
I->moveBefore(TrueBranch->getIterator()); | ||
for (Instruction *I : FalseInstrs) | ||
I->moveBefore(FalseBranch); | ||
I->moveBefore(FalseBranch->getIterator()); | ||
|
||
// If we did not create a new block for one of the 'true' or 'false' paths | ||
// of the condition, it means that side of the branch goes to the end block | ||
|
@@ -7682,7 +7682,7 @@ bool CodeGenPrepare::tryToSinkFreeOperands(Instruction *I) { | |
NewInstructions[UI] = NI; | ||
MaybeDead.insert(UI); | ||
LLVM_DEBUG(dbgs() << "Sinking " << *UI << " to user " << *I << "\n"); | ||
NI->insertBefore(InsertPoint); | ||
NI->insertBefore(InsertPoint->getIterator()); | ||
InsertPoint = NI; | ||
InsertedInsts.insert(NI); | ||
|
||
|
@@ -7744,7 +7744,7 @@ bool CodeGenPrepare::optimizeSwitchType(SwitchInst *SI) { | |
} | ||
|
||
auto *ExtInst = CastInst::Create(ExtType, Cond, NewType); | ||
ExtInst->insertBefore(SI); | ||
ExtInst->insertBefore(SI->getIterator()); | ||
ExtInst->setDebugLoc(SI->getDebugLoc()); | ||
SI->setCondition(ExtInst); | ||
for (auto Case : SI->cases()) { | ||
|
@@ -8556,7 +8556,7 @@ static bool optimizeBranch(BranchInst *Branch, const TargetLowering &TLI, | |
match(UI, m_Shr(m_Specific(X), m_SpecificInt(CmpC.logBase2())))) { | ||
IRBuilder<> Builder(Branch); | ||
if (UI->getParent() != Branch->getParent()) | ||
UI->moveBefore(Branch); | ||
UI->moveBefore(Branch->getIterator()); | ||
UI->dropPoisonGeneratingFlags(); | ||
Value *NewCmp = Builder.CreateCmp(ICmpInst::ICMP_EQ, UI, | ||
ConstantInt::get(UI->getType(), 0)); | ||
|
@@ -8570,7 +8570,7 @@ static bool optimizeBranch(BranchInst *Branch, const TargetLowering &TLI, | |
match(UI, m_Sub(m_Specific(X), m_SpecificInt(CmpC))))) { | ||
IRBuilder<> Builder(Branch); | ||
if (UI->getParent() != Branch->getParent()) | ||
UI->moveBefore(Branch); | ||
UI->moveBefore(Branch->getIterator()); | ||
UI->dropPoisonGeneratingFlags(); | ||
Value *NewCmp = Builder.CreateCmp(Cmp->getPredicate(), UI, | ||
ConstantInt::get(UI->getType(), 0)); | ||
|
@@ -8890,21 +8890,21 @@ bool CodeGenPrepare::fixupDbgVariableRecord(DbgVariableRecord &DVR) { | |
return AnyChange; | ||
} | ||
|
||
static void DbgInserterHelper(DbgValueInst *DVI, Instruction *VI) { | ||
static void DbgInserterHelper(DbgValueInst *DVI, BasicBlock::iterator VI) { | ||
DVI->removeFromParent(); | ||
if (isa<PHINode>(VI)) | ||
DVI->insertBefore(&*VI->getParent()->getFirstInsertionPt()); | ||
DVI->insertBefore(VI->getParent()->getFirstInsertionPt()); | ||
else | ||
DVI->insertAfter(VI); | ||
} | ||
|
||
static void DbgInserterHelper(DbgVariableRecord *DVR, Instruction *VI) { | ||
static void DbgInserterHelper(DbgVariableRecord *DVR, BasicBlock::iterator VI) { | ||
DVR->removeFromParent(); | ||
BasicBlock *VIBB = VI->getParent(); | ||
if (isa<PHINode>(VI)) | ||
VIBB->insertDbgRecordBefore(DVR, VIBB->getFirstInsertionPt()); | ||
else | ||
VIBB->insertDbgRecordAfter(DVR, VI); | ||
VIBB->insertDbgRecordAfter(DVR, &*VI); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a code-transition-state bug, or is there some reason we've got to use the Instruction * overload here? I suppose it doesn't matter either way for dbg records. |
||
} | ||
|
||
// A llvm.dbg.value may be using a value before its definition, due to | ||
|
@@ -8954,7 +8954,7 @@ bool CodeGenPrepare::placeDbgValues(Function &F) { | |
|
||
LLVM_DEBUG(dbgs() << "Moving Debug Value before :\n" | ||
<< *DbgItem << ' ' << *VI); | ||
DbgInserterHelper(DbgItem, VI); | ||
DbgInserterHelper(DbgItem, VI->getIterator()); | ||
MadeChange = true; | ||
++NumDbgValueMoved; | ||
} | ||
|
@@ -8997,7 +8997,7 @@ bool CodeGenPrepare::placePseudoProbes(Function &F) { | |
I++; | ||
while (I != Block.end()) { | ||
if (auto *II = dyn_cast<PseudoProbeInst>(I++)) { | ||
II->moveBefore(&*FirstInst); | ||
II->moveBefore(FirstInst); | ||
MadeChange = true; | ||
} | ||
} | ||
|
@@ -9105,7 +9105,7 @@ bool CodeGenPrepare::splitBranchCondition(Function &F, ModifyDT &ModifiedDT) { | |
auto *Br2 = IRBuilder<>(TmpBB).CreateCondBr(Cond2, TBB, FBB); | ||
if (auto *I = dyn_cast<Instruction>(Cond2)) { | ||
I->removeFromParent(); | ||
I->insertBefore(Br2); | ||
I->insertBefore(Br2->getIterator()); | ||
} | ||
|
||
// Update PHI nodes in both successors. The original BB needs to be | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -436,7 +436,7 @@ void IRPromoter::ReplaceAllUsersOfWith(Value *From, Value *To) { | |
void IRPromoter::ExtendSources() { | ||
IRBuilder<> Builder{Ctx}; | ||
|
||
auto InsertZExt = [&](Value *V, Instruction *InsertPt) { | ||
auto InsertZExt = [&](Value *V, BasicBlock::iterator InsertPt) { | ||
assert(V->getType() != ExtTy && "zext already extends to i32"); | ||
LLVM_DEBUG(dbgs() << "IR Promotion: Inserting ZExt for " << *V << "\n"); | ||
Builder.SetInsertPoint(InsertPt); | ||
|
@@ -448,7 +448,7 @@ void IRPromoter::ExtendSources() { | |
if (isa<Argument>(V)) | ||
I->moveBefore(InsertPt); | ||
else | ||
I->moveAfter(InsertPt); | ||
I->moveAfter(&*InsertPt); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as earlier - is this a code-transition-state bug, or is there some reason we've got to use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good question on this and the other item; I think the most important fact is that inserting after an instruction never introduces a problem with head-bits and debug records, because it's always "in front" of any debug records. As a result, it's not necessary to update moveAfter before stripping out intrinsic-support from LLVM (if we get there) so I haven't focused on this. We could technically update moveAfter to use iterators (which has the benefit of uniformity); I suppose it's a transition matter because I'm not planning on doing it immediately. |
||
NewInsts.insert(I); | ||
} | ||
|
||
|
@@ -460,10 +460,10 @@ void IRPromoter::ExtendSources() { | |
for (auto *V : Sources) { | ||
LLVM_DEBUG(dbgs() << " - " << *V << "\n"); | ||
if (auto *I = dyn_cast<Instruction>(V)) | ||
InsertZExt(I, I); | ||
InsertZExt(I, I->getIterator()); | ||
else if (auto *Arg = dyn_cast<Argument>(V)) { | ||
BasicBlock &BB = Arg->getParent()->front(); | ||
InsertZExt(Arg, &*BB.getFirstInsertionPt()); | ||
InsertZExt(Arg, BB.getFirstInsertionPt()); | ||
} else { | ||
llvm_unreachable("unhandled source that needs extending"); | ||
} | ||
|
@@ -552,7 +552,7 @@ void IRPromoter::TruncateSinks() { | |
Value *Arg = Call->getArgOperand(i); | ||
Type *Ty = TruncTysMap[Call][i]; | ||
if (Instruction *Trunc = InsertTrunc(Arg, Ty)) { | ||
Trunc->moveBefore(Call); | ||
Trunc->moveBefore(Call->getIterator()); | ||
Call->setArgOperand(i, Trunc); | ||
} | ||
} | ||
|
@@ -563,7 +563,7 @@ void IRPromoter::TruncateSinks() { | |
if (auto *Switch = dyn_cast<SwitchInst>(I)) { | ||
Type *Ty = TruncTysMap[Switch][0]; | ||
if (Instruction *Trunc = InsertTrunc(Switch->getCondition(), Ty)) { | ||
Trunc->moveBefore(Switch); | ||
Trunc->moveBefore(Switch->getIterator()); | ||
Switch->setCondition(Trunc); | ||
} | ||
continue; | ||
|
@@ -583,7 +583,7 @@ void IRPromoter::TruncateSinks() { | |
for (unsigned i = 0; i < I->getNumOperands(); ++i) { | ||
Type *Ty = TruncTysMap[I][i]; | ||
if (Instruction *Trunc = InsertTrunc(I->getOperand(i), Ty)) { | ||
Trunc->moveBefore(I); | ||
Trunc->moveBefore(I->getIterator()); | ||
I->setOperand(i, Trunc); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: parameter name and comment don't match up