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