mirror of
https://github.com/RPCS3/llvm.git
synced 2024-12-22 12:08:33 +00:00
Convert manual insert point restores to the new RAII object.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191675 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
6dc5c6b879
commit
d427882166
@ -252,8 +252,6 @@ namespace llvm {
|
||||
|
||||
void rememberInstruction(Value *I);
|
||||
|
||||
void restoreInsertPoint(BasicBlock *BB, BasicBlock::iterator I);
|
||||
|
||||
bool isNormalAddRecExprPHI(PHINode *PN, Instruction *IncV, const Loop *L);
|
||||
|
||||
bool isExpandedAddRecExprPHI(PHINode *PN, Instruction *IncV, const Loop *L);
|
||||
|
@ -177,8 +177,8 @@ Value *SCEVExpander::InsertBinop(Instruction::BinaryOps Opcode,
|
||||
}
|
||||
|
||||
// Save the original insertion point so we can restore it when we're done.
|
||||
BasicBlock *SaveInsertBB = Builder.GetInsertBlock();
|
||||
BasicBlock::iterator SaveInsertPt = Builder.GetInsertPoint();
|
||||
DebugLoc Loc = Builder.GetInsertPoint()->getDebugLoc();
|
||||
BuilderType::InsertPointGuard Guard(Builder);
|
||||
|
||||
// Move the insertion point out of as many loops as we can.
|
||||
while (const Loop *L = SE.LI->getLoopFor(Builder.GetInsertBlock())) {
|
||||
@ -192,13 +192,9 @@ Value *SCEVExpander::InsertBinop(Instruction::BinaryOps Opcode,
|
||||
|
||||
// If we haven't found this binop, insert it.
|
||||
Instruction *BO = cast<Instruction>(Builder.CreateBinOp(Opcode, LHS, RHS));
|
||||
BO->setDebugLoc(SaveInsertPt->getDebugLoc());
|
||||
BO->setDebugLoc(Loc);
|
||||
rememberInstruction(BO);
|
||||
|
||||
// Restore the original insert point.
|
||||
if (SaveInsertBB)
|
||||
restoreInsertPoint(SaveInsertBB, SaveInsertPt);
|
||||
|
||||
return BO;
|
||||
}
|
||||
|
||||
@ -553,8 +549,7 @@ Value *SCEVExpander::expandAddToGEP(const SCEV *const *op_begin,
|
||||
}
|
||||
|
||||
// Save the original insertion point so we can restore it when we're done.
|
||||
BasicBlock *SaveInsertBB = Builder.GetInsertBlock();
|
||||
BasicBlock::iterator SaveInsertPt = Builder.GetInsertPoint();
|
||||
BuilderType::InsertPointGuard Guard(Builder);
|
||||
|
||||
// Move the insertion point out of as many loops as we can.
|
||||
while (const Loop *L = SE.LI->getLoopFor(Builder.GetInsertBlock())) {
|
||||
@ -570,16 +565,11 @@ Value *SCEVExpander::expandAddToGEP(const SCEV *const *op_begin,
|
||||
Value *GEP = Builder.CreateGEP(V, Idx, "uglygep");
|
||||
rememberInstruction(GEP);
|
||||
|
||||
// Restore the original insert point.
|
||||
if (SaveInsertBB)
|
||||
restoreInsertPoint(SaveInsertBB, SaveInsertPt);
|
||||
|
||||
return GEP;
|
||||
}
|
||||
|
||||
// Save the original insertion point so we can restore it when we're done.
|
||||
BasicBlock *SaveInsertBB = Builder.GetInsertBlock();
|
||||
BasicBlock::iterator SaveInsertPt = Builder.GetInsertPoint();
|
||||
BuilderType::InsertPointGuard Guard(Builder);
|
||||
|
||||
// Move the insertion point out of as many loops as we can.
|
||||
while (const Loop *L = SE.LI->getLoopFor(Builder.GetInsertBlock())) {
|
||||
@ -614,10 +604,6 @@ Value *SCEVExpander::expandAddToGEP(const SCEV *const *op_begin,
|
||||
Ops.push_back(SE.getUnknown(GEP));
|
||||
rememberInstruction(GEP);
|
||||
|
||||
// Restore the original insert point.
|
||||
if (SaveInsertBB)
|
||||
restoreInsertPoint(SaveInsertBB, SaveInsertPt);
|
||||
|
||||
return expand(SE.getAddExpr(Ops));
|
||||
}
|
||||
|
||||
@ -1081,8 +1067,7 @@ SCEVExpander::getAddRecExprPHILiterally(const SCEVAddRecExpr *Normalized,
|
||||
}
|
||||
|
||||
// Save the original insertion point so we can restore it when we're done.
|
||||
BasicBlock *SaveInsertBB = Builder.GetInsertBlock();
|
||||
BasicBlock::iterator SaveInsertPt = Builder.GetInsertPoint();
|
||||
BuilderType::InsertPointGuard Guard(Builder);
|
||||
|
||||
// Another AddRec may need to be recursively expanded below. For example, if
|
||||
// this AddRec is quadratic, the StepV may itself be an AddRec in this
|
||||
@ -1149,10 +1134,6 @@ SCEVExpander::getAddRecExprPHILiterally(const SCEVAddRecExpr *Normalized,
|
||||
PN->addIncoming(IncV, Pred);
|
||||
}
|
||||
|
||||
// Restore the original insert point.
|
||||
if (SaveInsertBB)
|
||||
restoreInsertPoint(SaveInsertBB, SaveInsertPt);
|
||||
|
||||
// After expanding subexpressions, restore the PostIncLoops set so the caller
|
||||
// can ensure that IVIncrement dominates the current uses.
|
||||
PostIncLoops = SavedPostIncLoops;
|
||||
@ -1237,13 +1218,12 @@ Value *SCEVExpander::expandAddRecExprLiterally(const SCEVAddRecExpr *S) {
|
||||
!ExpandTy->isPointerTy() && Step->isNonConstantNegative();
|
||||
if (useSubtract)
|
||||
Step = SE.getNegativeSCEV(Step);
|
||||
// Expand the step somewhere that dominates the loop header.
|
||||
BasicBlock *SaveInsertBB = Builder.GetInsertBlock();
|
||||
BasicBlock::iterator SaveInsertPt = Builder.GetInsertPoint();
|
||||
Value *StepV = expandCodeFor(Step, IntTy, L->getHeader()->begin());
|
||||
// Restore the insertion point to the place where the caller has
|
||||
// determined dominates all uses.
|
||||
restoreInsertPoint(SaveInsertBB, SaveInsertPt);
|
||||
Value *StepV;
|
||||
{
|
||||
// Expand the step somewhere that dominates the loop header.
|
||||
BuilderType::InsertPointGuard Guard(Builder);
|
||||
StepV = expandCodeFor(Step, IntTy, L->getHeader()->begin());
|
||||
}
|
||||
Result = expandIVInc(PN, StepV, L, ExpandTy, IntTy, useSubtract);
|
||||
}
|
||||
}
|
||||
@ -1294,16 +1274,14 @@ Value *SCEVExpander::visitAddRecExpr(const SCEVAddRecExpr *S) {
|
||||
NewOps[i] = SE.getAnyExtendExpr(S->op_begin()[i], CanonicalIV->getType());
|
||||
Value *V = expand(SE.getAddRecExpr(NewOps, S->getLoop(),
|
||||
S->getNoWrapFlags(SCEV::FlagNW)));
|
||||
BasicBlock *SaveInsertBB = Builder.GetInsertBlock();
|
||||
BasicBlock::iterator SaveInsertPt = Builder.GetInsertPoint();
|
||||
BasicBlock::iterator NewInsertPt =
|
||||
llvm::next(BasicBlock::iterator(cast<Instruction>(V)));
|
||||
BuilderType::InsertPointGuard Guard(Builder);
|
||||
while (isa<PHINode>(NewInsertPt) || isa<DbgInfoIntrinsic>(NewInsertPt) ||
|
||||
isa<LandingPadInst>(NewInsertPt))
|
||||
++NewInsertPt;
|
||||
V = expandCodeFor(SE.getTruncateExpr(SE.getUnknown(V), Ty), 0,
|
||||
NewInsertPt);
|
||||
restoreInsertPoint(SaveInsertBB, SaveInsertPt);
|
||||
return V;
|
||||
}
|
||||
|
||||
@ -1536,8 +1514,7 @@ Value *SCEVExpander::expand(const SCEV *S) {
|
||||
if (I != InsertedExpressions.end())
|
||||
return I->second;
|
||||
|
||||
BasicBlock *SaveInsertBB = Builder.GetInsertBlock();
|
||||
BasicBlock::iterator SaveInsertPt = Builder.GetInsertPoint();
|
||||
BuilderType::InsertPointGuard Guard(Builder);
|
||||
Builder.SetInsertPoint(InsertPt->getParent(), InsertPt);
|
||||
|
||||
// Expand the expression into instructions.
|
||||
@ -1550,8 +1527,6 @@ Value *SCEVExpander::expand(const SCEV *S) {
|
||||
// a postinc expansion, it could be reused by a non postinc user, but only if
|
||||
// its insertion point was already at the head of the loop.
|
||||
InsertedExpressions[std::make_pair(S, InsertPt)] = V;
|
||||
|
||||
restoreInsertPoint(SaveInsertBB, SaveInsertPt);
|
||||
return V;
|
||||
}
|
||||
|
||||
@ -1562,10 +1537,6 @@ void SCEVExpander::rememberInstruction(Value *I) {
|
||||
InsertedValues.insert(I);
|
||||
}
|
||||
|
||||
void SCEVExpander::restoreInsertPoint(BasicBlock *BB, BasicBlock::iterator I) {
|
||||
Builder.SetInsertPoint(BB, I);
|
||||
}
|
||||
|
||||
/// getOrInsertCanonicalInductionVariable - This method returns the
|
||||
/// canonical induction variable of the specified type for the specified
|
||||
/// loop (inserting one if there is none). A canonical induction variable
|
||||
@ -1581,11 +1552,8 @@ SCEVExpander::getOrInsertCanonicalInductionVariable(const Loop *L,
|
||||
SE.getConstant(Ty, 1), L, SCEV::FlagAnyWrap);
|
||||
|
||||
// Emit code for it.
|
||||
BasicBlock *SaveInsertBB = Builder.GetInsertBlock();
|
||||
BasicBlock::iterator SaveInsertPt = Builder.GetInsertPoint();
|
||||
BuilderType::InsertPointGuard Guard(Builder);
|
||||
PHINode *V = cast<PHINode>(expandCodeFor(H, 0, L->getHeader()->begin()));
|
||||
if (SaveInsertBB)
|
||||
restoreInsertPoint(SaveInsertBB, SaveInsertPt);
|
||||
|
||||
return V;
|
||||
}
|
||||
|
@ -80,9 +80,8 @@ BasicBlock *BoundsChecking::getTrapBB() {
|
||||
return TrapBB;
|
||||
|
||||
Function *Fn = Inst->getParent()->getParent();
|
||||
BasicBlock::iterator PrevInsertPoint = Builder->GetInsertPoint();
|
||||
IRBuilder<>::InsertPointGuard Guard(*Builder);
|
||||
TrapBB = BasicBlock::Create(Fn->getContext(), "trap", Fn);
|
||||
Builder->SetInsertPoint(TrapBB);
|
||||
|
||||
llvm::Value *F = Intrinsic::getDeclaration(Fn->getParent(), Intrinsic::trap);
|
||||
CallInst *TrapCall = Builder->CreateCall(F);
|
||||
@ -91,7 +90,6 @@ BasicBlock *BoundsChecking::getTrapBB() {
|
||||
TrapCall->setDebugLoc(Inst->getDebugLoc());
|
||||
Builder->CreateUnreachable();
|
||||
|
||||
Builder->SetInsertPoint(PrevInsertPoint);
|
||||
return TrapBB;
|
||||
}
|
||||
|
||||
|
@ -266,8 +266,7 @@ bool FlattenCFGOpt::FlattenParallelAndOr(BasicBlock *BB, IRBuilder<> &Builder,
|
||||
BasicBlock *CB;
|
||||
BranchInst *PBI = dyn_cast<BranchInst>(FirstCondBlock->getTerminator());
|
||||
bool Iteration = true;
|
||||
BasicBlock *SaveInsertBB = Builder.GetInsertBlock();
|
||||
BasicBlock::iterator SaveInsertPt = Builder.GetInsertPoint();
|
||||
IRBuilder<>::InsertPointGuard Guard(Builder);
|
||||
Value *PC = PBI->getCondition();
|
||||
|
||||
do {
|
||||
@ -298,7 +297,6 @@ bool FlattenCFGOpt::FlattenParallelAndOr(BasicBlock *BB, IRBuilder<> &Builder,
|
||||
new UnreachableInst(CB->getContext(), CB);
|
||||
} while (Iteration);
|
||||
|
||||
Builder.SetInsertPoint(SaveInsertBB, SaveInsertPt);
|
||||
DEBUG(dbgs() << "Use parallel and/or in:\n" << *FirstCondBlock);
|
||||
return true;
|
||||
}
|
||||
|
@ -1027,25 +1027,19 @@ LoopVectorizationLegality::RuntimePointerCheck::insert(ScalarEvolution *SE,
|
||||
}
|
||||
|
||||
Value *InnerLoopVectorizer::getBroadcastInstrs(Value *V) {
|
||||
// Save the current insertion location.
|
||||
Instruction *Loc = Builder.GetInsertPoint();
|
||||
|
||||
// We need to place the broadcast of invariant variables outside the loop.
|
||||
Instruction *Instr = dyn_cast<Instruction>(V);
|
||||
bool NewInstr = (Instr && Instr->getParent() == LoopVectorBody);
|
||||
bool Invariant = OrigLoop->isLoopInvariant(V) && !NewInstr;
|
||||
|
||||
// Place the code for broadcasting invariant variables in the new preheader.
|
||||
IRBuilder<>::InsertPointGuard Guard(Builder);
|
||||
if (Invariant)
|
||||
Builder.SetInsertPoint(LoopVectorPreHeader->getTerminator());
|
||||
|
||||
// Broadcast the scalar into all locations in the vector.
|
||||
Value *Shuf = Builder.CreateVectorSplat(VF, V, "broadcast");
|
||||
|
||||
// Restore the builder insertion point.
|
||||
if (Invariant)
|
||||
Builder.SetInsertPoint(Loc);
|
||||
|
||||
return Shuf;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user