llvm.org GIT mirror llvm / a04a4a7
revert r166264 because the LTO build is still failing git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@166340 91177308-0d34-0410-b5e6-96231b3b80d8 Nadav Rotem 8 years ago
6 changed file(s) with 95 addition(s) and 104 deletion(s). Raw diff Collapse all Expand all
2121 #include
2222
2323 namespace llvm {
24 class ScalarTargetTransformInfo;
24 class TargetLowering;
2525
2626 /// Return true if the given expression is safe to expand in the sense that
2727 /// all materialized values are safe to speculate.
128128 /// representative. Return the number of phis eliminated.
129129 unsigned replaceCongruentIVs(Loop *L, const DominatorTree *DT,
130130 SmallVectorImpl &DeadInsts,
131 const ScalarTargetTransformInfo *STTI = NULL);
131 const TargetLowering *TLI = NULL);
132132
133133 /// expandCodeFor - Insert code to directly compute the specified SCEV
134134 /// expression into the program. The inserted code is inserted into the
118118 // optional parameter used to consult the target machine whether certain
119119 // transformations are profitable.
120120 //
121 Pass *createLoopStrengthReducePass();
121 Pass *createLoopStrengthReducePass(const TargetLowering *TLI = 0);
122122
123123 Pass *createGlobalMergePass(const TargetLowering *TLI = 0);
124124
248248 // purpose "my LLVM-to-LLVM pass doesn't support the invoke instruction yet"
249249 // lowering pass.
250250 //
251 FunctionPass *createLowerInvokePass();
252 FunctionPass *createLowerInvokePass(bool useExpensiveEHSupport);
251 FunctionPass *createLowerInvokePass(const TargetLowering *TLI = 0);
252 FunctionPass *createLowerInvokePass(const TargetLowering *TLI,
253 bool useExpensiveEHSupport);
253254 extern char &LowerInvokePassID;
254255
255256 //===----------------------------------------------------------------------===//
1818 #include "llvm/LLVMContext.h"
1919 #include "llvm/Support/Debug.h"
2020 #include "llvm/DataLayout.h"
21 #include "llvm/Target/TargetLowering.h"
2122 #include "llvm/ADT/STLExtras.h"
22 #include "llvm/TargetTransformInfo.h"
2323
2424 using namespace llvm;
2525
15981598 /// This does not depend on any SCEVExpander state but should be used in
15991599 /// the same context that SCEVExpander is used.
16001600 unsigned SCEVExpander::replaceCongruentIVs(Loop *L, const DominatorTree *DT,
1601 SmallVectorImpl &DeadInsts,
1602 const ScalarTargetTransformInfo *STTI) {
1601 SmallVectorImpl &DeadInsts,
1602 const TargetLowering *TLI) {
16031603 // Find integer phis in order of increasing width.
16041604 SmallVector Phis;
16051605 for (BasicBlock::iterator I = L->getHeader()->begin();
16061606 PHINode *Phi = dyn_cast(I); ++I) {
16071607 Phis.push_back(Phi);
16081608 }
1609 if (STTI)
1609 if (TLI)
16101610 std::sort(Phis.begin(), Phis.end(), width_descending);
16111611
16121612 unsigned NumElim = 0;
16341634 PHINode *&OrigPhiRef = ExprToIVMap[SE.getSCEV(Phi)];
16351635 if (!OrigPhiRef) {
16361636 OrigPhiRef = Phi;
1637 if (Phi->getType()->isIntegerTy() && STTI &&
1638 STTI->isTruncateFree(Phi->getType(), Phis.back()->getType())) {
1637 if (Phi->getType()->isIntegerTy() && TLI
1638 && TLI->isTruncateFree(Phi->getType(), Phis.back()->getType())) {
16391639 // This phi can be freely truncated to the narrowest phi type. Map the
16401640 // truncated expression to it so it will be reused for narrow types.
16411641 const SCEV *TruncExpr =
358358
359359 // Run loop strength reduction before anything else.
360360 if (getOptLevel() != CodeGenOpt::None && !DisableLSR) {
361 addPass(createLoopStrengthReducePass());
361 addPass(createLoopStrengthReducePass(getTargetLowering()));
362362 if (PrintLSR)
363363 addPass(createPrintFunctionPass("\n\n*** Code after LSR ***\n", &dbgs()));
364364 }
388388 addPass(createDwarfEHPass(TM));
389389 break;
390390 case ExceptionHandling::None:
391 addPass(createLowerInvokePass());
391 addPass(createLowerInvokePass(TM->getTargetLowering()));
392392
393393 // The lower invoke pass may create unreachable code. Remove it.
394394 addPass(createUnreachableBlockEliminationPass());
3636 //
3737 // TODO: Handle multiple loops at a time.
3838 //
39 // TODO: Should AddrMode::BaseGV be changed to a ConstantExpr
39 // TODO: Should TargetLowering::AddrMode::BaseGV be changed to a ConstantExpr
4040 // instead of a GlobalValue?
4141 //
4242 // TODO: When truncation is free, truncate ICmp users' operands to make it a
6666 #include "llvm/Transforms/Scalar.h"
6767 #include "llvm/Transforms/Utils/BasicBlockUtils.h"
6868 #include "llvm/Transforms/Utils/Local.h"
69 #include "llvm/TargetTransformInfo.h"
7069 #include "llvm/ADT/SmallBitVector.h"
7170 #include "llvm/ADT/SetVector.h"
7271 #include "llvm/ADT/DenseSet.h"
7473 #include "llvm/Support/CommandLine.h"
7574 #include "llvm/Support/ValueHandle.h"
7675 #include "llvm/Support/raw_ostream.h"
76 #include "llvm/Target/TargetLowering.h"
7777 #include
7878 using namespace llvm;
7979
11171117 enum KindType {
11181118 Basic, ///< A normal use, with no folding.
11191119 Special, ///< A special case of basic, allowing -1 scales.
1120 Address, ///< An address use; folding according to ScalarTargetTransformInfo.
1120 Address, ///< An address use; folding according to TargetLowering
11211121 ICmpZero ///< An equality icmp with both operands folded into one.
11221122 // TODO: Add a generic icmp too?
11231123 };
12711271 /// address-mode folding and special icmp tricks.
12721272 static bool isLegalUse(const AddrMode &AM,
12731273 LSRUse::KindType Kind, Type *AccessTy,
1274 const ScalarTargetTransformInfo *STTI) {
1274 const TargetLowering *TLI) {
12751275 switch (Kind) {
12761276 case LSRUse::Address:
12771277 // If we have low-level target information, ask the target if it can
12781278 // completely fold this address.
1279 if (STTI) return STTI->isLegalAddressingMode(AM, AccessTy);
1279 if (TLI) return TLI->isLegalAddressingMode(AM, AccessTy);
12801280
12811281 // Otherwise, just guess that reg+reg addressing is legal.
12821282 return !AM.BaseGV && AM.BaseOffs == 0 && AM.Scale <= 1;
12991299 // If we have low-level target information, ask the target if it can fold an
13001300 // integer immediate on an icmp.
13011301 if (AM.BaseOffs != 0) {
1302 if (!STTI)
1302 if (!TLI)
13031303 return false;
13041304 // We have one of:
13051305 // ICmpZero BaseReg + Offset => ICmp BaseReg, -Offset
13081308 int64_t Offs = AM.BaseOffs;
13091309 if (AM.Scale == 0)
13101310 Offs = -(uint64_t)Offs; // The cast does the right thing with INT64_MIN.
1311 return STTI->isLegalICmpImmediate(Offs);
1311 return TLI->isLegalICmpImmediate(Offs);
13121312 }
13131313
13141314 // ICmpZero BaseReg + -1*ScaleReg => ICmp BaseReg, ScaleReg
13291329 static bool isLegalUse(AddrMode AM,
13301330 int64_t MinOffset, int64_t MaxOffset,
13311331 LSRUse::KindType Kind, Type *AccessTy,
1332 const ScalarTargetTransformInfo *LTTI) {
1332 const TargetLowering *TLI) {
13331333 // Check for overflow.
13341334 if (((int64_t)((uint64_t)AM.BaseOffs + MinOffset) > AM.BaseOffs) !=
13351335 (MinOffset > 0))
13361336 return false;
13371337 AM.BaseOffs = (uint64_t)AM.BaseOffs + MinOffset;
1338 if (isLegalUse(AM, Kind, AccessTy, LTTI)) {
1338 if (isLegalUse(AM, Kind, AccessTy, TLI)) {
13391339 AM.BaseOffs = (uint64_t)AM.BaseOffs - MinOffset;
13401340 // Check for overflow.
13411341 if (((int64_t)((uint64_t)AM.BaseOffs + MaxOffset) > AM.BaseOffs) !=
13421342 (MaxOffset > 0))
13431343 return false;
13441344 AM.BaseOffs = (uint64_t)AM.BaseOffs + MaxOffset;
1345 return isLegalUse(AM, Kind, AccessTy, LTTI);
1345 return isLegalUse(AM, Kind, AccessTy, TLI);
13461346 }
13471347 return false;
13481348 }
13511351 GlobalValue *BaseGV,
13521352 bool HasBaseReg,
13531353 LSRUse::KindType Kind, Type *AccessTy,
1354 const ScalarTargetTransformInfo *LTTI) {
1354 const TargetLowering *TLI) {
13551355 // Fast-path: zero is always foldable.
13561356 if (BaseOffs == 0 && !BaseGV) return true;
13571357
13701370 AM.HasBaseReg = true;
13711371 }
13721372
1373 return isLegalUse(AM, Kind, AccessTy, LTTI);
1373 return isLegalUse(AM, Kind, AccessTy, TLI);
13741374 }
13751375
13761376 static bool isAlwaysFoldable(const SCEV *S,
13771377 int64_t MinOffset, int64_t MaxOffset,
13781378 bool HasBaseReg,
13791379 LSRUse::KindType Kind, Type *AccessTy,
1380 const ScalarTargetTransformInfo *LTTI,
1380 const TargetLowering *TLI,
13811381 ScalarEvolution &SE) {
13821382 // Fast-path: zero is always foldable.
13831383 if (S->isZero()) return true;
14011401 AM.HasBaseReg = HasBaseReg;
14021402 AM.Scale = Kind == LSRUse::ICmpZero ? -1 : 1;
14031403
1404 return isLegalUse(AM, MinOffset, MaxOffset, Kind, AccessTy, LTTI);
1404 return isLegalUse(AM, MinOffset, MaxOffset, Kind, AccessTy, TLI);
14051405 }
14061406
14071407 namespace {
15011501 ScalarEvolution &SE;
15021502 DominatorTree &DT;
15031503 LoopInfo &LI;
1504 const ScalarTargetTransformInfo *const STTI;
1504 const TargetLowering *const TLI;
15051505 Loop *const L;
15061506 bool Changed;
15071507
16371637 Pass *P);
16381638
16391639 public:
1640 LSRInstance(const ScalarTargetTransformInfo *ltti, Loop *l, Pass *P);
1640 LSRInstance(const TargetLowering *tli, Loop *l, Pass *P);
16411641
16421642 bool getChanged() const { return Changed; }
16431643
16871687 }
16881688 if (!DestTy) continue;
16891689
1690 if (STTI) {
1690 if (TLI) {
16911691 // If target does not support DestTy natively then do not apply
16921692 // this transformation.
1693 if (!STTI->isTypeLegal(DestTy)) continue;
1693 EVT DVT = TLI->getValueType(DestTy);
1694 if (!TLI->isTypeLegal(DVT)) continue;
16941695 }
16951696
16961697 PHINode *PH = dyn_cast(ShadowUse->getOperand(0));
20132014 if (C->getValue().getMinSignedBits() >= 64 ||
20142015 C->getValue().isMinSignedValue())
20152016 goto decline_post_inc;
2016 // Without STTI, assume that any stride might be valid, and so any
2017 // Without TLI, assume that any stride might be valid, and so any
20172018 // use might be shared.
2018 if (!STTI)
2019 if (!TLI)
20192020 goto decline_post_inc;
20202021 // Check for possible scaled-address reuse.
20212022 Type *AccessTy = getAccessType(UI->getUser());
20222023 AddrMode AM;
20232024 AM.Scale = C->getSExtValue();
2024 if (STTI->isLegalAddressingMode(AM, AccessTy))
2025 if (TLI->isLegalAddressingMode(AM, AccessTy))
20252026 goto decline_post_inc;
20262027 AM.Scale = -AM.Scale;
2027 if (STTI->isLegalAddressingMode(AM, AccessTy))
2028 if (TLI->isLegalAddressingMode(AM, AccessTy))
20282029 goto decline_post_inc;
20292030 }
20302031 }
20952096 // Conservatively assume HasBaseReg is true for now.
20962097 if (NewOffset < LU.MinOffset) {
20972098 if (!isAlwaysFoldable(LU.MaxOffset - NewOffset, 0, HasBaseReg,
2098 Kind, AccessTy, STTI))
2099 Kind, AccessTy, TLI))
20992100 return false;
21002101 NewMinOffset = NewOffset;
21012102 } else if (NewOffset > LU.MaxOffset) {
21022103 if (!isAlwaysFoldable(NewOffset - LU.MinOffset, 0, HasBaseReg,
2103 Kind, AccessTy, STTI))
2104 Kind, AccessTy, TLI))
21042105 return false;
21052106 NewMaxOffset = NewOffset;
21062107 }
21292130 int64_t Offset = ExtractImmediate(Expr, SE);
21302131
21312132 // Basic uses can't accept any offset, for example.
2132 if (!isAlwaysFoldable(Offset, 0, /*HasBaseReg=*/true, Kind, AccessTy, STTI)) {
2133 if (!isAlwaysFoldable(Offset, 0, /*HasBaseReg=*/true, Kind, AccessTy, TLI)) {
21332134 Expr = Copy;
21342135 Offset = 0;
21352136 }
23942395 /// TODO: Consider IVInc free if it's already used in another chains.
23952396 static bool
23962397 isProfitableChain(IVChain &Chain, SmallPtrSet &Users,
2397 ScalarEvolution &SE, const ScalarTargetTransformInfo *STTI) {
2398 ScalarEvolution &SE, const TargetLowering *TLI) {
23982399 if (StressIVChain)
23992400 return true;
24002401
26522653 for (unsigned UsersIdx = 0, NChains = IVChainVec.size();
26532654 UsersIdx < NChains; ++UsersIdx) {
26542655 if (!isProfitableChain(IVChainVec[UsersIdx],
2655 ChainUsersVec[UsersIdx].FarUsers, SE, STTI))
2656 ChainUsersVec[UsersIdx].FarUsers, SE, TLI))
26562657 continue;
26572658 // Preserve the chain at UsesIdx.
26582659 if (ChainIdx != UsersIdx)
26792680
26802681 /// Return true if the IVInc can be folded into an addressing mode.
26812682 static bool canFoldIVIncExpr(const SCEV *IncExpr, Instruction *UserInst,
2682 Value *Operand,
2683 const ScalarTargetTransformInfo *STTI) {
2683 Value *Operand, const TargetLowering *TLI) {
26842684 const SCEVConstant *IncConst = dyn_cast(IncExpr);
26852685 if (!IncConst || !isAddressUse(UserInst, Operand))
26862686 return false;
26902690
26912691 int64_t IncOffset = IncConst->getValue()->getSExtValue();
26922692 if (!isAlwaysFoldable(IncOffset, /*BaseGV=*/0, /*HaseBaseReg=*/false,
2693 LSRUse::Address, getAccessType(UserInst), STTI))
2693 LSRUse::Address, getAccessType(UserInst), TLI))
26942694 return false;
26952695
26962696 return true;
27612761
27622762 // If an IV increment can't be folded, use it as the next IV value.
27632763 if (!canFoldIVIncExpr(LeftOverExpr, IncI->UserInst, IncI->IVOperand,
2764 STTI)) {
2764 TLI)) {
27652765 assert(IVTy == IVOper->getType() && "inconsistent IV increment type");
27662766 IVSrc = IVOper;
27672767 LeftOverExpr = 0;
31073107 // into an immediate field.
31083108 if (isAlwaysFoldable(*J, LU.MinOffset, LU.MaxOffset,
31093109 Base.getNumRegs() > 1,
3110 LU.Kind, LU.AccessTy, STTI, SE))
3110 LU.Kind, LU.AccessTy, TLI, SE))
31113111 continue;
31123112
31133113 // Collect all operands except *J.
31213121 if (InnerAddOps.size() == 1 &&
31223122 isAlwaysFoldable(InnerAddOps[0], LU.MinOffset, LU.MaxOffset,
31233123 Base.getNumRegs() > 1,
3124 LU.Kind, LU.AccessTy, STTI, SE))
3124 LU.Kind, LU.AccessTy, TLI, SE))
31253125 continue;
31263126
31273127 const SCEV *InnerSum = SE.getAddExpr(InnerAddOps);
31313131
31323132 // Add the remaining pieces of the add back into the new formula.
31333133 const SCEVConstant *InnerSumSC = dyn_cast(InnerSum);
3134 if (STTI && InnerSumSC &&
3134 if (TLI && InnerSumSC &&
31353135 SE.getTypeSizeInBits(InnerSumSC->getType()) <= 64 &&
3136 STTI->isLegalAddImmediate((uint64_t)F.UnfoldedOffset +
3136 TLI->isLegalAddImmediate((uint64_t)F.UnfoldedOffset +
31373137 InnerSumSC->getValue()->getZExtValue())) {
31383138 F.UnfoldedOffset = (uint64_t)F.UnfoldedOffset +
31393139 InnerSumSC->getValue()->getZExtValue();
31433143
31443144 // Add J as its own register, or an unfolded immediate.
31453145 const SCEVConstant *SC = dyn_cast(*J);
3146 if (STTI && SC && SE.getTypeSizeInBits(SC->getType()) <= 64 &&
3147 STTI->isLegalAddImmediate((uint64_t)F.UnfoldedOffset +
3146 if (TLI && SC && SE.getTypeSizeInBits(SC->getType()) <= 64 &&
3147 TLI->isLegalAddImmediate((uint64_t)F.UnfoldedOffset +
31483148 SC->getValue()->getZExtValue()))
31493149 F.UnfoldedOffset = (uint64_t)F.UnfoldedOffset +
31503150 SC->getValue()->getZExtValue();
32043204 Formula F = Base;
32053205 F.AM.BaseGV = GV;
32063206 if (!isLegalUse(F.AM, LU.MinOffset, LU.MaxOffset,
3207 LU.Kind, LU.AccessTy, STTI))
3207 LU.Kind, LU.AccessTy, TLI))
32083208 continue;
32093209 F.BaseRegs[i] = G;
32103210 (void)InsertFormula(LU, LUIdx, F);
32293229 Formula F = Base;
32303230 F.AM.BaseOffs = (uint64_t)Base.AM.BaseOffs - *I;
32313231 if (isLegalUse(F.AM, LU.MinOffset - *I, LU.MaxOffset - *I,
3232 LU.Kind, LU.AccessTy, STTI)) {
3232 LU.Kind, LU.AccessTy, TLI)) {
32333233 // Add the offset to the base register.
32343234 const SCEV *NewG = SE.getAddExpr(SE.getConstant(G->getType(), *I), G);
32353235 // If it cancelled out, drop the base register, otherwise update it.
32493249 Formula F = Base;
32503250 F.AM.BaseOffs = (uint64_t)F.AM.BaseOffs + Imm;
32513251 if (!isLegalUse(F.AM, LU.MinOffset, LU.MaxOffset,
3252 LU.Kind, LU.AccessTy, STTI))
3252 LU.Kind, LU.AccessTy, TLI))
32533253 continue;
32543254 F.BaseRegs[i] = G;
32553255 (void)InsertFormula(LU, LUIdx, F);
32963296 F.AM.BaseOffs = NewBaseOffs;
32973297
32983298 // Check that this scale is legal.
3299 if (!isLegalUse(F.AM, Offset, Offset, LU.Kind, LU.AccessTy, STTI))
3299 if (!isLegalUse(F.AM, Offset, Offset, LU.Kind, LU.AccessTy, TLI))
33003300 continue;
33013301
33023302 // Compensate for the use having MinOffset built into it.
33523352 Base.AM.HasBaseReg = Base.BaseRegs.size() > 1;
33533353 // Check whether this scale is going to be legal.
33543354 if (!isLegalUse(Base.AM, LU.MinOffset, LU.MaxOffset,
3355 LU.Kind, LU.AccessTy, STTI)) {
3355 LU.Kind, LU.AccessTy, TLI)) {
33563356 // As a special-case, handle special out-of-loop Basic users specially.
33573357 // TODO: Reconsider this special case.
33583358 if (LU.Kind == LSRUse::Basic &&
33593359 isLegalUse(Base.AM, LU.MinOffset, LU.MaxOffset,
3360 LSRUse::Special, LU.AccessTy, STTI) &&
3360 LSRUse::Special, LU.AccessTy, TLI) &&
33613361 LU.AllFixupsOutsideLoop)
33623362 LU.Kind = LSRUse::Special;
33633363 else
33903390
33913391 /// GenerateTruncates - Generate reuse formulae from different IV types.
33923392 void LSRInstance::GenerateTruncates(LSRUse &LU, unsigned LUIdx, Formula Base) {
3393 // This requires ScalarTargetTransformInfo to tell us which truncates are free.
3394 if (!STTI) return;
3393 // This requires TargetLowering to tell us which truncates are free.
3394 if (!TLI) return;
33953395
33963396 // Don't bother truncating symbolic values.
33973397 if (Base.AM.BaseGV) return;
34043404 for (SmallSetVector::const_iterator
34053405 I = Types.begin(), E = Types.end(); I != E; ++I) {
34063406 Type *SrcTy = *I;
3407 if (SrcTy != DstTy && STTI->isTruncateFree(SrcTy, DstTy)) {
3407 if (SrcTy != DstTy && TLI->isTruncateFree(SrcTy, DstTy)) {
34083408 Formula F = Base;
34093409
34103410 if (F.ScaledReg) F.ScaledReg = SE.getAnyExtendExpr(F.ScaledReg, *I);
35603560 Formula NewF = F;
35613561 NewF.AM.BaseOffs = Offs;
35623562 if (!isLegalUse(NewF.AM, LU.MinOffset, LU.MaxOffset,
3563 LU.Kind, LU.AccessTy, STTI))
3563 LU.Kind, LU.AccessTy, TLI))
35643564 continue;
35653565 NewF.ScaledReg = SE.getAddExpr(NegImmS, NewF.ScaledReg);
35663566
35853585 Formula NewF = F;
35863586 NewF.AM.BaseOffs = (uint64_t)NewF.AM.BaseOffs + Imm;
35873587 if (!isLegalUse(NewF.AM, LU.MinOffset, LU.MaxOffset,
3588 LU.Kind, LU.AccessTy, STTI)) {
3589 if (!STTI ||
3590 !STTI->isLegalAddImmediate((uint64_t)NewF.UnfoldedOffset + Imm))
3588 LU.Kind, LU.AccessTy, TLI)) {
3589 if (!TLI ||
3590 !TLI->isLegalAddImmediate((uint64_t)NewF.UnfoldedOffset + Imm))
35913591 continue;
35923592 NewF = F;
35933593 NewF.UnfoldedOffset = (uint64_t)NewF.UnfoldedOffset + Imm;
38993899 Formula &F = LUThatHas->Formulae[i];
39003900 if (!isLegalUse(F.AM,
39013901 LUThatHas->MinOffset, LUThatHas->MaxOffset,
3902 LUThatHas->Kind, LUThatHas->AccessTy, STTI)) {
3902 LUThatHas->Kind, LUThatHas->AccessTy, TLI)) {
39033903 DEBUG(dbgs() << " Deleting "; F.print(dbgs());
39043904 dbgs() << '\n');
39053905 LUThatHas->DeleteFormula(F);
45884588 Changed |= DeleteTriviallyDeadInstructions(DeadInsts);
45894589 }
45904590
4591 LSRInstance::LSRInstance(const ScalarTargetTransformInfo *stti, Loop *l, Pass *P)
4591 LSRInstance::LSRInstance(const TargetLowering *tli, Loop *l, Pass *P)
45924592 : IU(P->getAnalysis()),
45934593 SE(P->getAnalysis()),
45944594 DT(P->getAnalysis()),
45954595 LI(P->getAnalysis()),
4596 STTI(stti), L(l), Changed(false), IVIncInsertPos(0) {
4596 TLI(tli), L(l), Changed(false), IVIncInsertPos(0) {
45974597
45984598 // If LoopSimplify form is not available, stay out of trouble.
45994599 if (!L->isLoopSimplifyForm())
46834683 for (SmallVectorImpl::const_iterator J = LU.Formulae.begin(),
46844684 JE = LU.Formulae.end(); J != JE; ++J)
46854685 assert(isLegalUse(J->AM, LU.MinOffset, LU.MaxOffset,
4686 LU.Kind, LU.AccessTy, STTI) &&
4686 LU.Kind, LU.AccessTy, TLI) &&
46874687 "Illegal formula generated!");
46884688 };
46894689 #endif
47564756 namespace {
47574757
47584758 class LoopStrengthReduce : public LoopPass {
4759 /// ScalarTargetTransformInfo provides target information that is needed
4760 /// for strength reducing loops.
4761 const ScalarTargetTransformInfo *STTI;
4759 /// TLI - Keep a pointer of a TargetLowering to consult for determining
4760 /// transformation profitability.
4761 const TargetLowering *const TLI;
47624762
47634763 public:
47644764 static char ID; // Pass ID, replacement for typeid
4765 LoopStrengthReduce();
4765 explicit LoopStrengthReduce(const TargetLowering *tli = 0);
47664766
47674767 private:
47684768 bool runOnLoop(Loop *L, LPPassManager &LPM);
47824782 INITIALIZE_PASS_END(LoopStrengthReduce, "loop-reduce",
47834783 "Loop Strength Reduction", false, false)
47844784
4785 Pass *llvm::createLoopStrengthReducePass() {
4786 return new LoopStrengthReduce();
4787 }
4788
4789 LoopStrengthReduce::LoopStrengthReduce()
4790 : LoopPass(ID), STTI(0) {
4785
4786 Pass *llvm::createLoopStrengthReducePass(const TargetLowering *TLI) {
4787 return new LoopStrengthReduce(TLI);
4788 }
4789
4790 LoopStrengthReduce::LoopStrengthReduce(const TargetLowering *tli)
4791 : LoopPass(ID), TLI(tli) {
47914792 initializeLoopStrengthReducePass(*PassRegistry::getPassRegistry());
47924793 }
47934794
48134814 bool LoopStrengthReduce::runOnLoop(Loop *L, LPPassManager & /*LPM*/) {
48144815 bool Changed = false;
48154816
4816 TargetTransformInfo *TTI = getAnalysisIfAvailable();
4817
4818 if (TTI)
4819 STTI = TTI->getScalarTargetTransformInfo();
4820
48214817 // Run the main LSR transformation.
4822 Changed |= LSRInstance(STTI, L, this).getChanged();
4818 Changed |= LSRInstance(TLI, L, this).getChanged();
48234819
48244820 // Remove any extra phis created by processing inner loops.
48254821 Changed |= DeleteDeadPHIs(L->getHeader());
48304826 Rewriter.setDebugType(DEBUG_TYPE);
48314827 #endif
48324828 unsigned numFolded = Rewriter.
4833 replaceCongruentIVs(L, &getAnalysis(), DeadInsts, STTI);
4829 replaceCongruentIVs(L, &getAnalysis(), DeadInsts, TLI);
48344830 if (numFolded) {
48354831 Changed = true;
48364832 DeleteTriviallyDeadInstructions(DeadInsts);
4444 #include "llvm/Pass.h"
4545 #include "llvm/Transforms/Utils/BasicBlockUtils.h"
4646 #include "llvm/Transforms/Utils/Local.h"
47 #include "llvm/TargetTransformInfo.h"
4847 #include "llvm/ADT/SmallVector.h"
4948 #include "llvm/ADT/Statistic.h"
5049 #include "llvm/Support/CommandLine.h"
50 #include "llvm/Target/TargetLowering.h"
5151 #include
5252 #include
5353 using namespace llvm;
6969 Constant *SetJmpFn, *LongJmpFn, *StackSaveFn, *StackRestoreFn;
7070 bool useExpensiveEHSupport;
7171
72 // We peek in STTI to grab the target's jmp_buf size and alignment
73 const ScalarTargetTransformInfo *STTI;
72 // We peek in TLI to grab the target's jmp_buf size and alignment
73 const TargetLowering *TLI;
7474
7575 public:
7676 static char ID; // Pass identification, replacement for typeid
77 explicit LowerInvoke(bool useExpensiveEHSupport = ExpensiveEHSupport)
77 explicit LowerInvoke(const TargetLowering *tli = NULL,
78 bool useExpensiveEHSupport = ExpensiveEHSupport)
7879 : FunctionPass(ID), useExpensiveEHSupport(useExpensiveEHSupport),
79 STTI(0) {
80 TLI(tli) {
8081 initializeLowerInvokePass(*PassRegistry::getPassRegistry());
8182 }
8283 bool doInitialization(Module &M);
106107 char &llvm::LowerInvokePassID = LowerInvoke::ID;
107108
108109 // Public Interface To the LowerInvoke pass.
109 FunctionPass *llvm::createLowerInvokePass() {
110 return new LowerInvoke(ExpensiveEHSupport);
111 }
112 FunctionPass *llvm::createLowerInvokePass(bool useExpensiveEHSupport) {
113 return new LowerInvoke(useExpensiveEHSupport);
110 FunctionPass *llvm::createLowerInvokePass(const TargetLowering *TLI) {
111 return new LowerInvoke(TLI, ExpensiveEHSupport);
112 }
113 FunctionPass *llvm::createLowerInvokePass(const TargetLowering *TLI,
114 bool useExpensiveEHSupport) {
115 return new LowerInvoke(TLI, useExpensiveEHSupport);
114116 }
115117
116118 // doInitialization - Make sure that there is a prototype for abort in the
117119 // current module.
118120 bool LowerInvoke::doInitialization(Module &M) {
119 TargetTransformInfo *TTI = getAnalysisIfAvailable();
120 if (TTI)
121 STTI = TTI->getScalarTargetTransformInfo();
122
123121 Type *VoidPtrTy = Type::getInt8PtrTy(M.getContext());
124122 if (useExpensiveEHSupport) {
125123 // Insert a type for the linked list of jump buffers.
126 unsigned JBSize = STTI ? STTI->getJumpBufSize() : 0;
124 unsigned JBSize = TLI ? TLI->getJumpBufSize() : 0;
127125 JBSize = JBSize ? JBSize : 200;
128126 Type *JmpBufTy = ArrayType::get(VoidPtrTy, JBSize);
129127
431429 // Create an alloca for the incoming jump buffer ptr and the new jump buffer
432430 // that needs to be restored on all exits from the function. This is an
433431 // alloca because the value needs to be live across invokes.
434 unsigned Align = STTI ? STTI->getJumpBufAlignment() : 0;
432 unsigned Align = TLI ? TLI->getJumpBufAlignment() : 0;
435433 AllocaInst *JmpBuf =
436434 new AllocaInst(JBLinkTy, 0, Align,
437435 "jblink", F.begin()->begin());
576574 }
577575
578576 bool LowerInvoke::runOnFunction(Function &F) {
579 TargetTransformInfo *TTI = getAnalysisIfAvailable();
580 if (TTI)
581 STTI = TTI->getScalarTargetTransformInfo();
582
583577 if (useExpensiveEHSupport)
584578 return insertExpensiveEHSupport(F);
585579 else