Changeset View
Changeset View
Standalone View
Standalone View
lib/Transforms/Vectorize/LoopVectorize.cpp
- This file is larger than 256 KB, so syntax highlighting is disabled by default.
Show First 20 Lines • Show All 1,533 Lines • ▼ Show 20 Lines | |||||
class LoopVectorizationLegality { | class LoopVectorizationLegality { | ||||
public: | public: | ||||
LoopVectorizationLegality( | LoopVectorizationLegality( | ||||
Loop *L, PredicatedScalarEvolution &PSE, DominatorTree *DT, | Loop *L, PredicatedScalarEvolution &PSE, DominatorTree *DT, | ||||
TargetLibraryInfo *TLI, AliasAnalysis *AA, Function *F, | TargetLibraryInfo *TLI, AliasAnalysis *AA, Function *F, | ||||
const TargetTransformInfo *TTI, | const TargetTransformInfo *TTI, | ||||
std::function<const LoopAccessInfo &(Loop &)> *GetLAA, LoopInfo *LI, | std::function<const LoopAccessInfo &(Loop &)> *GetLAA, LoopInfo *LI, | ||||
OptimizationRemarkEmitter *ORE, LoopVectorizationRequirements *R, | OptimizationRemarkEmitter *ORE, LoopVectorizationRequirements *R, | ||||
LoopVectorizeHints *H) | LoopVectorizeHints *H, DemandedBits *DB, AssumptionCache *AC) | ||||
: TheLoop(L), PSE(PSE), TLI(TLI), TTI(TTI), DT(DT), GetLAA(GetLAA), | : TheLoop(L), PSE(PSE), TLI(TLI), TTI(TTI), DT(DT), GetLAA(GetLAA), | ||||
ORE(ORE), InterleaveInfo(PSE, L, DT, LI), Requirements(R), Hints(H) {} | ORE(ORE), InterleaveInfo(PSE, L, DT, LI), Requirements(R), Hints(H), | ||||
DB(DB), AC(AC) {} | |||||
/// ReductionList contains the reduction descriptors for all | /// ReductionList contains the reduction descriptors for all | ||||
/// of the reductions that were found in the loop. | /// of the reductions that were found in the loop. | ||||
using ReductionList = DenseMap<PHINode *, RecurrenceDescriptor>; | using ReductionList = DenseMap<PHINode *, RecurrenceDescriptor>; | ||||
/// InductionList saves induction variables and maps them to the | /// InductionList saves induction variables and maps them to the | ||||
/// induction descriptor. | /// induction descriptor. | ||||
using InductionList = MapVector<PHINode *, InductionDescriptor>; | using InductionList = MapVector<PHINode *, InductionDescriptor>; | ||||
▲ Show 20 Lines • Show All 272 Lines • ▼ Show 20 Lines | private: | ||||
bool HasFunNoNaNAttr = false; | bool HasFunNoNaNAttr = false; | ||||
/// Vectorization requirements that will go through late-evaluation. | /// Vectorization requirements that will go through late-evaluation. | ||||
LoopVectorizationRequirements *Requirements; | LoopVectorizationRequirements *Requirements; | ||||
/// Used to emit an analysis of any legality issues. | /// Used to emit an analysis of any legality issues. | ||||
LoopVectorizeHints *Hints; | LoopVectorizeHints *Hints; | ||||
/// The demanded bits analsyis is used to compute the minimum type size in | |||||
/// which a reduction can be computed. | |||||
DemandedBits *DB; | |||||
/// The assumption cache analysis is used to compute the minimum type size in | |||||
/// which a reduction can be computed. | |||||
AssumptionCache *AC; | |||||
/// While vectorizing these instructions we have to generate a | /// While vectorizing these instructions we have to generate a | ||||
/// call to the appropriate masked intrinsic | /// call to the appropriate masked intrinsic | ||||
SmallPtrSet<const Instruction *, 8> MaskedOp; | SmallPtrSet<const Instruction *, 8> MaskedOp; | ||||
}; | }; | ||||
/// LoopVectorizationCostModel - estimates the expected speedups due to | /// LoopVectorizationCostModel - estimates the expected speedups due to | ||||
/// vectorization. | /// vectorization. | ||||
/// In many cases vectorization is not profitable. This can happen because of | /// In many cases vectorization is not profitable. This can happen because of | ||||
▲ Show 20 Lines • Show All 3,259 Lines • ▼ Show 20 Lines | for (Instruction &I : *BB) { | ||||
if (Phi->getNumIncomingValues() != 2) { | if (Phi->getNumIncomingValues() != 2) { | ||||
ORE->emit(createMissedAnalysis("CFGNotUnderstood", Phi) | ORE->emit(createMissedAnalysis("CFGNotUnderstood", Phi) | ||||
<< "control flow not understood by vectorizer"); | << "control flow not understood by vectorizer"); | ||||
DEBUG(dbgs() << "LV: Found an invalid PHI.\n"); | DEBUG(dbgs() << "LV: Found an invalid PHI.\n"); | ||||
return false; | return false; | ||||
} | } | ||||
RecurrenceDescriptor RedDes; | RecurrenceDescriptor RedDes; | ||||
if (RecurrenceDescriptor::isReductionPHI(Phi, TheLoop, RedDes)) { | if (RecurrenceDescriptor::isReductionPHI(Phi, TheLoop, RedDes, DB, AC, | ||||
DT)) { | |||||
if (RedDes.hasUnsafeAlgebra()) | if (RedDes.hasUnsafeAlgebra()) | ||||
Requirements->addUnsafeAlgebraInst(RedDes.getUnsafeAlgebraInst()); | Requirements->addUnsafeAlgebraInst(RedDes.getUnsafeAlgebraInst()); | ||||
AllowedExit.insert(RedDes.getLoopExitInstr()); | AllowedExit.insert(RedDes.getLoopExitInstr()); | ||||
Reductions[Phi] = RedDes; | Reductions[Phi] = RedDes; | ||||
continue; | continue; | ||||
} | } | ||||
InductionDescriptor ID; | InductionDescriptor ID; | ||||
▲ Show 20 Lines • Show All 3,201 Lines • ▼ Show 20 Lines | if (!Hints.allowVectorization(F, L, AlwaysVectorize)) { | ||||
return false; | return false; | ||||
} | } | ||||
PredicatedScalarEvolution PSE(*SE, *L); | PredicatedScalarEvolution PSE(*SE, *L); | ||||
// Check if it is legal to vectorize the loop. | // Check if it is legal to vectorize the loop. | ||||
LoopVectorizationRequirements Requirements(*ORE); | LoopVectorizationRequirements Requirements(*ORE); | ||||
LoopVectorizationLegality LVL(L, PSE, DT, TLI, AA, F, TTI, GetLAA, LI, ORE, | LoopVectorizationLegality LVL(L, PSE, DT, TLI, AA, F, TTI, GetLAA, LI, ORE, | ||||
&Requirements, &Hints); | &Requirements, &Hints, DB, AC); | ||||
if (!LVL.canVectorize()) { | if (!LVL.canVectorize()) { | ||||
DEBUG(dbgs() << "LV: Not vectorizing: Cannot prove legality.\n"); | DEBUG(dbgs() << "LV: Not vectorizing: Cannot prove legality.\n"); | ||||
emitMissedWarning(F, L, Hints, ORE); | emitMissedWarning(F, L, Hints, ORE); | ||||
return false; | return false; | ||||
} | } | ||||
// Check the function attributes to find out if this function should be | // Check the function attributes to find out if this function should be | ||||
// optimized for size. | // optimized for size. | ||||
▲ Show 20 Lines • Show All 300 Lines • Show Last 20 Lines |