llvm.org GIT mirror llvm / 3f46a3a
Spelling fixes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@97453 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 10 years ago
7 changed file(s) with 45 addition(s) and 45 deletion(s). Raw diff Collapse all Expand all
6060 Stride = Val;
6161 }
6262
63 /// getOffset - Return the offset to add to a theoeretical induction
63 /// getOffset - Return the offset to add to a theoretical induction
6464 /// variable that starts at zero and counts up by the stride to compute
6565 /// the value for the use. This always has the same type as the stride.
6666 const SCEV *getOffset() const { return Offset; }
115115 bool IsUseOfPostIncrementedValue;
116116
117117 /// Deleted - Implementation of CallbackVH virtual function to
118 /// recieve notification when the User is deleted.
118 /// receive notification when the User is deleted.
119119 virtual void deleted();
120120 };
121121
77 //===----------------------------------------------------------------------===//
88 //
99 // The ScalarEvolution class is an LLVM pass which can be used to analyze and
10 // catagorize scalar expressions in loops. It specializes in recognizing
10 // categorize scalar expressions in loops. It specializes in recognizing
1111 // general induction variables, representing them with the abstract and opaque
1212 // SCEV class. Given this analysis, trip counts of loops and other important
1313 // properties can be obtained.
5454
5555 protected:
5656 /// SubclassData - This field is initialized to zero and may be used in
57 /// subclasses to store miscelaneous information.
57 /// subclasses to store miscellaneous information.
5858 unsigned short SubclassData;
5959
6060 private:
176176 ///
177177 LoopInfo *LI;
178178
179 /// TD - The target data information for the target we are targetting.
179 /// TD - The target data information for the target we are targeting.
180180 ///
181181 TargetData *TD;
182182
193193 std::map Scalars;
194194
195195 /// BackedgeTakenInfo - Information about the backedge-taken count
196 /// of a loop. This currently inclues an exact count and a maximum count.
196 /// of a loop. This currently includes an exact count and a maximum count.
197197 ///
198198 struct BackedgeTakenInfo {
199199 /// Exact - An expression indicating the exact backedge-taken count of
352352 bool Inverse);
353353
354354 /// isImpliedCondOperands - Test whether the condition described by Pred,
355 /// LHS, and RHS is true whenever the condition desribed by Pred, FoundLHS,
355 /// LHS, and RHS is true whenever the condition described by Pred, FoundLHS,
356356 /// and FoundRHS is true.
357357 bool isImpliedCondOperands(ICmpInst::Predicate Pred,
358358 const SCEV *LHS, const SCEV *RHS,
359359 const SCEV *FoundLHS, const SCEV *FoundRHS);
360360
361361 /// isImpliedCondOperandsHelper - Test whether the condition described by
362 /// Pred, LHS, and RHS is true whenever the condition desribed by Pred,
362 /// Pred, LHS, and RHS is true whenever the condition described by Pred,
363363 /// FoundLHS, and FoundRHS is true.
364364 bool isImpliedCondOperandsHelper(ICmpInst::Predicate Pred,
365365 const SCEV *LHS, const SCEV *RHS,
221221 // Descend recursively, but not into PHI nodes outside the current loop.
222222 // It's important to see the entire expression outside the loop to get
223223 // choices that depend on addressing mode use right, although we won't
224 // consider references ouside the loop in all cases.
224 // consider references outside the loop in all cases.
225225 // If User is already in Processed, we don't want to recurse into it again,
226226 // but do want to record a second reference in the same instruction.
227227 bool AddUserToIVUsers = false;
329329 }
330330 OS << ":\n";
331331
332 // Use a defualt AssemblyAnnotationWriter to suppress the default info
332 // Use a default AssemblyAnnotationWriter to suppress the default info
333333 // comments, which aren't relevant here.
334334 AssemblyAnnotationWriter Annotator;
335335 for (ilist::const_iterator UI = IVUses.begin(),
615615 /// When this routine is finished, we know that any duplicates in the vector are
616616 /// consecutive and that complexity is monotonically increasing.
617617 ///
618 /// Note that we go take special precautions to ensure that we get determinstic
618 /// Note that we go take special precautions to ensure that we get deterministic
619619 /// results from this routine. In other words, we don't want the results of
620620 /// this to depend on where the addresses of various SCEV objects happened to
621621 /// land in memory.
743743 // We need at least W + T bits for the multiplication step
744744 unsigned CalculationBits = W + T;
745745
746 // Calcuate 2^T, at width T+W.
746 // Calculate 2^T, at width T+W.
747747 APInt DivFactor = APInt(CalculationBits, 1).shl(T);
748748
749749 // Calculate the multiplicative inverse of K! / 2^T;
14091409
14101410 // If we deleted at least one add, we added operands to the end of the list,
14111411 // and they are not necessarily sorted. Recurse to resort and resimplify
1412 // any operands we just aquired.
1412 // any operands we just acquired.
14131413 if (DeletedAdd)
14141414 return getAddExpr(Ops);
14151415 }
17161716
17171717 // If we deleted at least one mul, we added operands to the end of the list,
17181718 // and they are not necessarily sorted. Recurse to resort and resimplify
1719 // any operands we just aquired.
1719 // any operands we just acquired.
17201720 if (DeletedMul)
17211721 return getMulExpr(Ops);
17221722 }
27452745 } else {
27462746 // For an array, add the element offset, explicitly scaled.
27472747 const SCEV *LocalOffset = getSCEV(Index);
2748 // Getelementptr indicies are signed.
2748 // Getelementptr indices are signed.
27492749 LocalOffset = getTruncateOrSignExtend(LocalOffset, IntPtrTy);
27502750 // Lower "inbounds" GEPs to NSW arithmetic.
27512751 LocalOffset = getMulExpr(LocalOffset, getSizeOfExpr(*GTI),
32193219 const Type *Z0Ty = Z0->getType();
32203220 unsigned Z0TySize = getTypeSizeInBits(Z0Ty);
32213221
3222 // If C is a low-bits mask, the zero extend is zerving to
3222 // If C is a low-bits mask, the zero extend is serving to
32233223 // mask off the high bits. Complement the operand and
32243224 // re-apply the zext.
32253225 if (APIntOps::isMask(Z0TySize, CI->getValue()))
34043404 const ScalarEvolution::BackedgeTakenInfo &
34053405 ScalarEvolution::getBackedgeTakenInfo(const Loop *L) {
34063406 // Initially insert a CouldNotCompute for this loop. If the insertion
3407 // succeeds, procede to actually compute a backedge-taken count and
3407 // succeeds, proceed to actually compute a backedge-taken count and
34083408 // update the value. The temporary CouldNotCompute value tells SCEV
34093409 // code elsewhere that it shouldn't attempt to request a new
34103410 // backedge-taken count, which could result in infinite recursion.
36213621 return getCouldNotCompute();
36223622 }
36233623
3624 // Procede to the next level to examine the exit condition expression.
3624 // Proceed to the next level to examine the exit condition expression.
36253625 return ComputeBackedgeTakenCountFromExitCond(L, ExitBr->getCondition(),
36263626 ExitBr->getSuccessor(0),
36273627 ExitBr->getSuccessor(1));
37103710 }
37113711
37123712 // With an icmp, it may be feasible to compute an exact backedge-taken count.
3713 // Procede to the next level to examine the icmp.
3713 // Proceed to the next level to examine the icmp.
37143714 if (ICmpInst *ExitCondICmp = dyn_cast(ExitCond))
37153715 return ComputeBackedgeTakenCountFromExitCondICmp(L, ExitCondICmp, TBB, FBB);
37163716
47794779 ICmpInst::Predicate Pred,
47804780 const SCEV *LHS, const SCEV *RHS,
47814781 bool Inverse) {
4782 // Recursivly handle And and Or conditions.
4782 // Recursively handle And and Or conditions.
47834783 if (BinaryOperator *BO = dyn_cast(CondValue)) {
47844784 if (BO->getOpcode() == Instruction::And) {
47854785 if (!Inverse)
49824982 }
49834983
49844984 /// isImpliedCondOperands - Test whether the condition described by Pred,
4985 /// LHS, and RHS is true whenever the condition desribed by Pred, FoundLHS,
4985 /// LHS, and RHS is true whenever the condition described by Pred, FoundLHS,
49864986 /// and FoundRHS is true.
49874987 bool ScalarEvolution::isImpliedCondOperands(ICmpInst::Predicate Pred,
49884988 const SCEV *LHS, const SCEV *RHS,
49974997 }
49984998
49994999 /// isImpliedCondOperandsHelper - Test whether the condition described by
5000 /// Pred, LHS, and RHS is true whenever the condition desribed by Pred,
5000 /// Pred, LHS, and RHS is true whenever the condition described by Pred,
50015001 /// FoundLHS, and FoundRHS is true.
50025002 bool
50035003 ScalarEvolution::isImpliedCondOperandsHelper(ICmpInst::Predicate Pred,
51555155
51565156 // If MaxEnd is within a step of the maximum integer value in its type,
51575157 // adjust it down to the minimum value which would produce the same effect.
5158 // This allows the subsequent ceiling divison of (N+(step-1))/step to
5158 // This allows the subsequent ceiling division of (N+(step-1))/step to
51595159 // compute the correct value.
51605160 const SCEV *StepMinusOne = getMinusSCEV(Step,
51615161 getIntegerSCEV(1, Step->getType()));
54325432 }
54335433
54345434 void ScalarEvolution::print(raw_ostream &OS, const Module *) const {
5435 // ScalarEvolution's implementaiton of the print method is to print
5435 // ScalarEvolution's implementation of the print method is to print
54365436 // out SCEV values of all instructions that are interesting. Doing
54375437 // this potentially causes it to create new SCEV objects though,
54385438 // which technically conflicts with the const qualifier. This isn't
151151
152152 /// FactorOutConstant - Test if S is divisible by Factor, using signed
153153 /// division. If so, update S with Factor divided out and return true.
154 /// S need not be evenly divisble if a reasonable remainder can be
154 /// S need not be evenly divisible if a reasonable remainder can be
155155 /// computed.
156156 /// TODO: When ScalarEvolution gets a SCEVSDivExpr, this can be made
157157 /// unnecessary; in its place, just signed-divide Ops[i] by the scale and
461461 break;
462462 }
463463
464 // If none of the operands were convertable to proper GEP indices, cast
464 // If none of the operands were convertible to proper GEP indices, cast
465465 // the base to i8* and do an ugly getelementptr with that. It's still
466466 // better than ptrtoint+arithmetic+inttoptr at least.
467467 if (!AnyNonZeroIndices) {
819819 const Type *ExpandTy = PostLoopScale ? IntTy : STy;
820820 PHINode *PN = getAddRecExprPHILiterally(Normalized, L, ExpandTy, IntTy);
821821
822 // Accomodate post-inc mode, if necessary.
822 // Accommodate post-inc mode, if necessary.
823823 Value *Result;
824824 if (L != PostIncLoop)
825825 Result = PN;
11301130 }
11311131
11321132 void SCEVExpander::restoreInsertPoint(BasicBlock *BB, BasicBlock::iterator I) {
1133 // If we aquired more instructions since the old insert point was saved,
1133 // If we acquired more instructions since the old insert point was saved,
11341134 // advance past them.
11351135 while (isInsertedInstruction(I)) ++I;
11361136
593593 }
594594 }
595595
596 /// Return true if it is OK to use SIToFPInst for an inducation variable
597 /// with given inital and exit values.
596 /// Return true if it is OK to use SIToFPInst for an induction variable
597 /// with given initial and exit values.
598598 static bool useSIToFPInst(ConstantFP &InitV, ConstantFP &ExitV,
599599 uint64_t intIV, uint64_t intEV) {
600600
647647 if (!convertToInt(InitValue->getValueAPF(), &newInitValue))
648648 return;
649649
650 // Check IV increment. Reject this PH if increement operation is not
650 // Check IV increment. Reject this PH if increment operation is not
651651 // an add or increment value can not be represented by an integer.
652652 BinaryOperator *Incr =
653653 dyn_cast(PH->getIncomingValue(BackEdge));
683683 if (BI->getCondition() != EC) return;
684684 }
685685
686 // Find exit value. If exit value can not be represented as an interger then
686 // Find exit value. If exit value can not be represented as an integer then
687687 // do not handle this floating point PH.
688688 ConstantFP *EV = NULL;
689689 unsigned EVIndex = 1;
745745 ICmpInst *NewEC = new ICmpInst(EC->getParent()->getTerminator(),
746746 NewPred, LHS, RHS, EC->getName());
747747
748 // In the following deltions, PH may become dead and may be deleted.
748 // In the following deletions, PH may become dead and may be deleted.
749749 // Use a WeakVH to observe whether this happens.
750750 WeakVH WeakPH = PH;
751751
752 // Delete old, floating point, exit comparision instruction.
752 // Delete old, floating point, exit comparison instruction.
753753 NewEC->takeName(EC);
754754 EC->replaceAllUsesWith(NewEC);
755755 RecursivelyDeleteTriviallyDeadInstructions(EC);
197197
198198 }
199199
200 /// DoInitialMatch - Recurrsion helper for InitialMatch.
200 /// DoInitialMatch - Recursion helper for InitialMatch.
201201 static void DoInitialMatch(const SCEV *S, Loop *L,
202202 SmallVectorImpl &Good,
203203 SmallVectorImpl &Bad,
12451245 }
12461246
12471247 /// OptimizeShadowIV - If IV is used in a int-to-float cast
1248 /// inside the loop then try to eliminate the cast opeation.
1248 /// inside the loop then try to eliminate the cast operation.
12491249 void LSRInstance::OptimizeShadowIV() {
12501250 const SCEV *BackedgeTakenCount = SE.getBackedgeTakenCount(L);
12511251 if (isa(BackedgeTakenCount))
16721672
16731673 /// getUse - Return an LSRUse index and an offset value for a fixup which
16741674 /// needs the given expression, with the given kind and optional access type.
1675 /// Either reuse an exisitng use or create a new one, as needed.
1675 /// Either reuse an existing use or create a new one, as needed.
16761676 std::pair
16771677 LSRInstance::getUse(const SCEV *&Expr,
16781678 LSRUse::KindType Kind, const Type *AccessTy) {
20342034 /// loop-dominating registers added into a single register.
20352035 void LSRInstance::GenerateCombinations(LSRUse &LU, unsigned LUIdx,
20362036 Formula Base) {
2037 // This method is only intersting on a plurality of registers.
2037 // This method is only interesting on a plurality of registers.
20382038 if (Base.BaseRegs.size() <= 1) return;
20392039
20402040 Formula F = Base;
20532053 const SCEV *Sum = SE.getAddExpr(Ops);
20542054 // TODO: If Sum is zero, it probably means ScalarEvolution missed an
20552055 // opportunity to fold something. For now, just ignore such cases
2056 // rather than procede with zero in a register.
2056 // rather than proceed with zero in a register.
20572057 if (!Sum->isZero()) {
20582058 F.BaseRegs.push_back(Sum);
20592059 (void)InsertFormula(LU, LUIdx, F);
24002400 const SCEV *NegImmS = SE.getSCEV(ConstantInt::get(IntTy, -(uint64_t)Imm));
24012401 unsigned BitWidth = SE.getTypeSizeInBits(IntTy);
24022402
2403 // TODO: Use a more targetted data structure.
2403 // TODO: Use a more targeted data structure.
24042404 for (size_t L = 0, LE = LU.Formulae.size(); L != LE; ++L) {
24052405 Formula F = LU.Formulae[L];
24062406 // Use the immediate in the scaled register.
25682568 });
25692569 }
25702570
2571 /// NarrowSearchSpaceUsingHeuristics - If there are an extrordinary number of
2571 /// NarrowSearchSpaceUsingHeuristics - If there are an extraordinary number of
25722572 /// formulae to choose from, use some rough heuristics to prune down the number
2573 /// of formulae. This keeps the main solver from taking an extrordinary amount
2573 /// of formulae. This keeps the main solver from taking an extraordinary amount
25742574 /// of time in some worst-case scenarios.
25752575 void LSRInstance::NarrowSearchSpaceUsingHeuristics() {
25762576 // This is a rough guess that seems to work fairly well.
26202620 }
26212621
26222622 DEBUG(dbgs() << "Narrowing the search space by assuming " << *Best
2623 << " will yeild profitable reuse.\n");
2623 << " will yield profitable reuse.\n");
26242624 Taken.insert(Best);
26252625
26262626 // In any use with formulae which references this register, delete formulae
26672667 // - sort the formula so that the most profitable solutions are found first
26682668 // - sort the uses too
26692669 // - search faster:
2670 // - dont compute a cost, and then compare. compare while computing a cost
2670 // - don't compute a cost, and then compare. compare while computing a cost
26712671 // and bail early.
26722672 // - track register sets with SmallBitVector
26732673
31033103 dbgs() << ":\n");
31043104
31053105 /// OptimizeShadowIV - If IV is used in a int-to-float cast
3106 /// inside the loop then try to eliminate the cast opeation.
3106 /// inside the loop then try to eliminate the cast operation.
31073107 OptimizeShadowIV();
31083108
31093109 // Change loop terminating condition to use the postinc iv when possible.