diff options
author | Jeremy Morse <jeremy.morse@sony.com> | 2024-03-04 14:51:56 +0000 |
---|---|---|
committer | Jeremy Morse <jeremy.morse@sony.com> | 2024-03-05 15:12:22 +0000 |
commit | 2fe81edef6f0b35abffbbc59b649b30ea9c15a62 (patch) | |
tree | 34690d759ee0440c77187ffcedd986cbd96acb11 /llvm/lib/Transforms/Scalar/JumpThreading.cpp | |
parent | a691f65a845d6d5e639a83e8240a2543663c103a (diff) | |
download | llvm-2fe81edef6f0b35abffbbc59b649b30ea9c15a62.zip llvm-2fe81edef6f0b35abffbbc59b649b30ea9c15a62.tar.gz llvm-2fe81edef6f0b35abffbbc59b649b30ea9c15a62.tar.bz2 |
[NFC][RemoveDIs] Insert instruction using iterators in Transforms/
As part of the RemoveDIs project we need LLVM to insert instructions using
iterators wherever possible, so that the iterators can carry a bit of
debug-info. This commit implements some of that by updating the contents of
llvm/lib/Transforms/Utils to always use iterator-versions of instruction
constructors.
There are two general flavours of update:
* Almost all call-sites just call getIterator on an instruction
* Several make use of an existing iterator (scenarios where the code is
actually significant for debug-info)
The underlying logic is that any call to getFirstInsertionPt or similar
APIs that identify the start of a block need to have that iterator passed
directly to the insertion function, without being converted to a bare
Instruction pointer along the way.
Noteworthy changes:
* FindInsertedValue now takes an optional iterator rather than an
instruction pointer, as we need to always insert with iterators,
* I've added a few iterator-taking versions of some value-tracking and
DomTree methods -- they just unwrap the iterator. These are purely
convenience methods to avoid extra syntax in some passes.
* A few calls to getNextNode become std::next instead (to keep in the
theme of using iterators for positions),
* SeparateConstOffsetFromGEP has it's insertion-position field changed.
Noteworthy because it's not a purely localised spelling change.
All this should be NFC.
Diffstat (limited to 'llvm/lib/Transforms/Scalar/JumpThreading.cpp')
-rw-r--r-- | llvm/lib/Transforms/Scalar/JumpThreading.cpp | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp index 5816bf2..a04987c 100644 --- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp +++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp @@ -1037,7 +1037,7 @@ bool JumpThreadingPass::processBlock(BasicBlock *BB) { LLVM_DEBUG(dbgs() << " In block '" << BB->getName() << "' folding undef terminator: " << *BBTerm << '\n'); - BranchInst::Create(BBTerm->getSuccessor(BestSucc), BBTerm); + BranchInst::Create(BBTerm->getSuccessor(BestSucc), BBTerm->getIterator()); ++NumFolds; BBTerm->eraseFromParent(); DTU->applyUpdatesPermissive(Updates); @@ -1202,7 +1202,7 @@ bool JumpThreadingPass::processImpliedCondition(BasicBlock *BB) { BasicBlock *KeepSucc = BI->getSuccessor(*Implication ? 0 : 1); BasicBlock *RemoveSucc = BI->getSuccessor(*Implication ? 1 : 0); RemoveSucc->removePredecessor(BB); - BranchInst *UncondBI = BranchInst::Create(KeepSucc, BI); + BranchInst *UncondBI = BranchInst::Create(KeepSucc, BI->getIterator()); UncondBI->setDebugLoc(BI->getDebugLoc()); ++NumFolds; BI->eraseFromParent(); @@ -1280,7 +1280,7 @@ bool JumpThreadingPass::simplifyPartiallyRedundantLoad(LoadInst *LoadI) { AvailableVal = PoisonValue::get(LoadI->getType()); if (AvailableVal->getType() != LoadI->getType()) AvailableVal = CastInst::CreateBitOrPointerCast( - AvailableVal, LoadI->getType(), "", LoadI); + AvailableVal, LoadI->getType(), "", LoadI->getIterator()); LoadI->replaceAllUsesWith(AvailableVal); LoadI->eraseFromParent(); return true; @@ -1421,7 +1421,7 @@ bool JumpThreadingPass::simplifyPartiallyRedundantLoad(LoadInst *LoadI) { LoadI->getType(), LoadedPtr->DoPHITranslation(LoadBB, UnavailablePred), LoadI->getName() + ".pr", false, LoadI->getAlign(), LoadI->getOrdering(), LoadI->getSyncScopeID(), - UnavailablePred->getTerminator()); + UnavailablePred->getTerminator()->getIterator()); NewVal->setDebugLoc(LoadI->getDebugLoc()); if (AATags) NewVal->setAAMetadata(AATags); @@ -1454,8 +1454,8 @@ bool JumpThreadingPass::simplifyPartiallyRedundantLoad(LoadInst *LoadI) { // predecessor use the same bitcast. Value *&PredV = I->second; if (PredV->getType() != LoadI->getType()) - PredV = CastInst::CreateBitOrPointerCast(PredV, LoadI->getType(), "", - P->getTerminator()); + PredV = CastInst::CreateBitOrPointerCast( + PredV, LoadI->getType(), "", P->getTerminator()->getIterator()); PN->addIncoming(PredV, I->first); } @@ -1653,7 +1653,7 @@ bool JumpThreadingPass::processThreadableEdges(Value *Cond, BasicBlock *BB, // Finally update the terminator. Instruction *Term = BB->getTerminator(); - BranchInst::Create(OnlyDest, Term); + BranchInst::Create(OnlyDest, Term->getIterator()); ++NumFolds; Term->eraseFromParent(); DTU->applyUpdatesPermissive(Updates); @@ -2971,13 +2971,13 @@ bool JumpThreadingPass::tryToUnfoldSelectInCurrBB(BasicBlock *BB) { // Expand the select. Value *Cond = SI->getCondition(); if (!isGuaranteedNotToBeUndefOrPoison(Cond, nullptr, SI)) - Cond = new FreezeInst(Cond, "cond.fr", SI); + Cond = new FreezeInst(Cond, "cond.fr", SI->getIterator()); MDNode *BranchWeights = getBranchWeightMDNode(*SI); Instruction *Term = SplitBlockAndInsertIfThen(Cond, SI, false, BranchWeights); BasicBlock *SplitBB = SI->getParent(); BasicBlock *NewBB = Term->getParent(); - PHINode *NewPN = PHINode::Create(SI->getType(), 2, "", SI); + PHINode *NewPN = PHINode::Create(SI->getType(), 2, "", SI->getIterator()); NewPN->addIncoming(SI->getTrueValue(), Term->getParent()); NewPN->addIncoming(SI->getFalseValue(), BB); SI->replaceAllUsesWith(NewPN); |