llvm.org GIT mirror llvm / 454d26d
Remove unused variables and parameters. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@96780 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 10 years ago
4 changed file(s) with 29 addition(s) and 51 deletion(s). Raw diff Collapse all Expand all
141141 /// the loop, resulting in reg-reg copies (if we use the pre-inc value when we
142142 /// should use the post-inc value).
143143 static bool IVUseShouldUsePostIncValue(Instruction *User, Instruction *IV,
144 Loop *L, LoopInfo *LI, DominatorTree *DT,
145 Pass *P) {
144 Loop *L, DominatorTree *DT) {
146145 // If the user is in the loop, use the preinc value.
147146 if (L->contains(User)) return false;
148147
244243 // Okay, we found a user that we cannot reduce. Analyze the instruction
245244 // and decide what to do with it. If we are a use inside of the loop, use
246245 // the value before incrementation, otherwise use it after incrementation.
247 if (IVUseShouldUsePostIncValue(User, I, L, LI, DT, this)) {
246 if (IVUseShouldUsePostIncValue(User, I, L, DT)) {
248247 // The value used will be incremented by the stride more than we are
249248 // expecting, so subtract this off.
250249 const SCEV *NewStart = SE->getMinusSCEV(Start, Stride);
25632563 SmallPtrSet Visited;
25642564 Visited.insert(I);
25652565 while (!Worklist.empty()) {
2566 Instruction *I = Worklist.pop_back_val();
2566 I = Worklist.pop_back_val();
25672567 if (!Visited.insert(I)) continue;
25682568
25692569 std::map::iterator It =
29412941
29422942 if (const SCEVUnknown *U = dyn_cast(S)) {
29432943 // For a SCEVUnknown, ask ValueTracking.
2944 unsigned BitWidth = getTypeSizeInBits(U->getType());
29452944 APInt Mask = APInt::getAllOnesValue(BitWidth);
29462945 APInt Zeros(BitWidth, 0), Ones(BitWidth, 0);
29472946 ComputeMaskedBits(U->getValue(), Mask, Zeros, Ones, TD);
53665365 bool ScalarEvolution::runOnFunction(Function &F) {
53675366 this->F = &F;
53685367 LI = &getAnalysis();
5368 TD = getAnalysisIfAvailable();
53695369 DT = &getAnalysis();
5370 TD = getAnalysisIfAvailable();
53715370 return false;
53725371 }
53735372
102102 BasicBlock *ExitingBlock,
103103 BranchInst *BI,
104104 SCEVExpander &Rewriter);
105 void RewriteLoopExitValues(Loop *L, const SCEV *BackedgeTakenCount,
106 SCEVExpander &Rewriter);
107
108 void RewriteIVExpressions(Loop *L, const Type *LargestType,
109 SCEVExpander &Rewriter);
105 void RewriteLoopExitValues(Loop *L, SCEVExpander &Rewriter);
106
107 void RewriteIVExpressions(Loop *L, SCEVExpander &Rewriter);
110108
111109 void SinkUnusedInvariants(Loop *L);
112110
214212 /// able to brute-force evaluate arbitrary instructions as long as they have
215213 /// constant operands at the beginning of the loop.
216214 void IndVarSimplify::RewriteLoopExitValues(Loop *L,
217 const SCEV *BackedgeTakenCount,
218215 SCEVExpander &Rewriter) {
219216 // Verify the input to the pass in already in LCSSA form.
220217 assert(L->isLCSSAForm());
357354 // the current expressions.
358355 //
359356 if (!isa(BackedgeTakenCount))
360 RewriteLoopExitValues(L, BackedgeTakenCount, Rewriter);
357 RewriteLoopExitValues(L, Rewriter);
361358
362359 // Compute the type of the largest recurrence expression, and decide whether
363360 // a canonical induction variable should be inserted.
426423 }
427424
428425 // Rewrite IV-derived expressions. Clears the rewriter cache.
429 RewriteIVExpressions(L, LargestType, Rewriter);
426 RewriteIVExpressions(L, Rewriter);
430427
431428 // The Rewriter may not be used from this point on.
432429
446443 return Changed;
447444 }
448445
449 void IndVarSimplify::RewriteIVExpressions(Loop *L, const Type *LargestType,
450 SCEVExpander &Rewriter) {
446 void IndVarSimplify::RewriteIVExpressions(Loop *L, SCEVExpander &Rewriter) {
451447 SmallVector DeadInsts;
452448
453449 // Rewrite all induction variable expressions in terms of the canonical
911911 MaxOffset(INT64_MIN),
912912 AllFixupsOutsideLoop(true) {}
913913
914 bool InsertFormula(size_t LUIdx, const Formula &F);
914 bool InsertFormula(const Formula &F);
915915
916916 void check() const;
917917
921921
922922 /// InsertFormula - If the given formula has not yet been inserted, add it to
923923 /// the list, and return true. Return false otherwise.
924 bool LSRUse::InsertFormula(size_t LUIdx, const Formula &F) {
924 bool LSRUse::InsertFormula(const Formula &F) {
925925 SmallVector Key = F.BaseRegs;
926926 if (F.ScaledReg) Key.push_back(F.ScaledReg);
927927 // Unstable sort by host order ok, because this is only used for uniquifying.
10561056 GlobalValue *BaseGV,
10571057 bool HasBaseReg,
10581058 LSRUse::KindType Kind, const Type *AccessTy,
1059 const TargetLowering *TLI,
1060 ScalarEvolution &SE) {
1059 const TargetLowering *TLI) {
10611060 // Fast-path: zero is always foldable.
10621061 if (BaseOffs == 0 && !BaseGV) return true;
10631062
11851184 const Type *AccessTy);
11861185
11871186 public:
1188 void InsertInitialFormula(const SCEV *S, Loop *L, LSRUse &LU, size_t LUIdx);
1187 void InsertInitialFormula(const SCEV *S, LSRUse &LU, size_t LUIdx);
11891188 void InsertSupplementalFormula(const SCEV *S, LSRUse &LU, size_t LUIdx);
11901189 void CountRegisters(const Formula &F, size_t LUIdx);
11911190 bool InsertFormula(LSRUse &LU, unsigned LUIdx, const Formula &F);
12161215
12171216 Value *Expand(const LSRFixup &LF,
12181217 const Formula &F,
1219 BasicBlock::iterator IP, Loop *L, Instruction *IVIncInsertPos,
1218 BasicBlock::iterator IP,
12201219 SCEVExpander &Rewriter,
1221 SmallVectorImpl &DeadInsts,
1222 ScalarEvolution &SE, DominatorTree &DT) const;
1220 SmallVectorImpl &DeadInsts) const;
12231221 void RewriteForPHI(PHINode *PN, const LSRFixup &LF,
12241222 const Formula &F,
1225 Loop *L, Instruction *IVIncInsertPos,
12261223 SCEVExpander &Rewriter,
12271224 SmallVectorImpl &DeadInsts,
1228 ScalarEvolution &SE, DominatorTree &DT,
12291225 Pass *P) const;
12301226 void Rewrite(const LSRFixup &LF,
12311227 const Formula &F,
1232 Loop *L, Instruction *IVIncInsertPos,
12331228 SCEVExpander &Rewriter,
12341229 SmallVectorImpl &DeadInsts,
1235 ScalarEvolution &SE, DominatorTree &DT,
12361230 Pass *P) const;
12371231 void ImplementSolution(const SmallVectorImpl &Solution,
12381232 Pass *P);
16541648 // Conservatively assume HasBaseReg is true for now.
16551649 if (NewOffset < LU.MinOffset) {
16561650 if (!isAlwaysFoldable(LU.MaxOffset - NewOffset, 0, /*HasBaseReg=*/true,
1657 Kind, AccessTy, TLI, SE))
1651 Kind, AccessTy, TLI))
16581652 return false;
16591653 NewMinOffset = NewOffset;
16601654 } else if (NewOffset > LU.MaxOffset) {
16611655 if (!isAlwaysFoldable(NewOffset - LU.MinOffset, 0, /*HasBaseReg=*/true,
1662 Kind, AccessTy, TLI, SE))
1656 Kind, AccessTy, TLI))
16631657 return false;
16641658 NewMaxOffset = NewOffset;
16651659 }
16861680 int64_t Offset = ExtractImmediate(Expr, SE);
16871681
16881682 // Basic uses can't accept any offset, for example.
1689 if (!isAlwaysFoldable(Offset, 0, /*HasBaseReg=*/true,
1690 Kind, AccessTy, TLI, SE)) {
1683 if (!isAlwaysFoldable(Offset, 0, /*HasBaseReg=*/true, Kind, AccessTy, TLI)) {
16911684 Expr = Copy;
16921685 Offset = 0;
16931686 }
17601753 if (Factor->getValue()->getValue().getMinSignedBits() <= 64)
17611754 Factors.insert(Factor->getValue()->getValue().getSExtValue());
17621755 } else if (const SCEVConstant *Factor =
1763 dyn_cast_or_null(getExactSDiv(OldStride, NewStride,
1756 dyn_cast_or_null(getExactSDiv(OldStride,
1757 NewStride,
17641758 SE, true))) {
17651759 if (Factor->getValue()->getValue().getMinSignedBits() <= 64)
17661760 Factors.insert(Factor->getValue()->getValue().getSExtValue());
18331827
18341828 // If this is the first use of this LSRUse, give it a formula.
18351829 if (LU.Formulae.empty()) {
1836 InsertInitialFormula(S, L, LU, LF.LUIdx);
1830 InsertInitialFormula(S, LU, LF.LUIdx);
18371831 CountRegisters(LU.Formulae.back(), LF.LUIdx);
18381832 }
18391833 }
18421836 }
18431837
18441838 void
1845 LSRInstance::InsertInitialFormula(const SCEV *S, Loop *L,
1846 LSRUse &LU, size_t LUIdx) {
1839 LSRInstance::InsertInitialFormula(const SCEV *S, LSRUse &LU, size_t LUIdx) {
18471840 Formula F;
18481841 F.InitialMatch(S, L, SE, DT);
18491842 bool Inserted = InsertFormula(LU, LUIdx, F);
18731866 /// InsertFormula - If the given formula has not yet been inserted, add it to
18741867 /// the list, and return true. Return false otherwise.
18751868 bool LSRInstance::InsertFormula(LSRUse &LU, unsigned LUIdx, const Formula &F) {
1876 if (!LU.InsertFormula(LUIdx, F))
1869 if (!LU.InsertFormula(F))
18771870 return false;
18781871
18791872 CountRegisters(F, LUIdx);
27852778 Value *LSRInstance::Expand(const LSRFixup &LF,
27862779 const Formula &F,
27872780 BasicBlock::iterator IP,
2788 Loop *L, Instruction *IVIncInsertPos,
27892781 SCEVExpander &Rewriter,
2790 SmallVectorImpl &DeadInsts,
2791 ScalarEvolution &SE, DominatorTree &DT) const {
2782 SmallVectorImpl &DeadInsts) const {
27922783 const LSRUse &LU = Uses[LF.LUIdx];
27932784
27942785 // Then, collect some instructions which we will remain dominated by when
29782969 void LSRInstance::RewriteForPHI(PHINode *PN,
29792970 const LSRFixup &LF,
29802971 const Formula &F,
2981 Loop *L, Instruction *IVIncInsertPos,
29822972 SCEVExpander &Rewriter,
29832973 SmallVectorImpl &DeadInsts,
2984 ScalarEvolution &SE, DominatorTree &DT,
29852974 Pass *P) const {
29862975 DenseMap Inserted;
29872976 for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
30153004 if (!Pair.second)
30163005 PN->setIncomingValue(i, Pair.first->second);
30173006 else {
3018 Value *FullV = Expand(LF, F, BB->getTerminator(), L, IVIncInsertPos,
3019 Rewriter, DeadInsts, SE, DT);
3007 Value *FullV = Expand(LF, F, BB->getTerminator(), Rewriter, DeadInsts);
30203008
30213009 // If this is reuse-by-noop-cast, insert the noop cast.
30223010 const Type *OpTy = LF.OperandValToReplace->getType();
30383026 /// the newly expanded value.
30393027 void LSRInstance::Rewrite(const LSRFixup &LF,
30403028 const Formula &F,
3041 Loop *L, Instruction *IVIncInsertPos,
30423029 SCEVExpander &Rewriter,
30433030 SmallVectorImpl &DeadInsts,
3044 ScalarEvolution &SE, DominatorTree &DT,
30453031 Pass *P) const {
30463032 // First, find an insertion point that dominates UserInst. For PHI nodes,
30473033 // find the nearest block which dominates all the relevant uses.
30483034 if (PHINode *PN = dyn_cast(LF.UserInst)) {
3049 RewriteForPHI(PN, LF, F, L, IVIncInsertPos, Rewriter, DeadInsts, SE, DT, P);
3035 RewriteForPHI(PN, LF, F, Rewriter, DeadInsts, P);
30503036 } else {
3051 Value *FullV = Expand(LF, F, LF.UserInst, L, IVIncInsertPos,
3052 Rewriter, DeadInsts, SE, DT);
3037 Value *FullV = Expand(LF, F, LF.UserInst, Rewriter, DeadInsts);
30533038
30543039 // If this is reuse-by-noop-cast, insert the noop cast.
30553040 const Type *OpTy = LF.OperandValToReplace->getType();
30893074 for (size_t i = 0, e = Fixups.size(); i != e; ++i) {
30903075 size_t LUIdx = Fixups[i].LUIdx;
30913076
3092 Rewrite(Fixups[i], *Solution[LUIdx], L, IVIncInsertPos, Rewriter,
3093 DeadInsts, SE, DT, P);
3077 Rewrite(Fixups[i], *Solution[LUIdx], Rewriter, DeadInsts, P);
30943078
30953079 Changed = true;
30963080 }