LoopVectorizationLegality(Loop *L, ScalarEvolution *SE, const DataLayout *DL,
DominatorTree *DT, TargetLibraryInfo *TLI,
AliasAnalysis *AA, Function *F,
- const TargetTransformInfo *TTI)
+ const TargetTransformInfo *TTI,
+ LoopAccessAnalysis *LAA)
: NumPredStores(0), TheLoop(L), SE(SE), DL(DL),
- TLI(TLI), TheFunction(F), TTI(TTI), DT(DT), Induction(nullptr),
- WidestIndTy(nullptr),
- LAI(F, L, SE, DL, TLI, AA, DT),
- HasFunNoNaNAttr(false) {}
+ TLI(TLI), TheFunction(F), TTI(TTI), DT(DT), LAA(LAA), LAI(nullptr),
+ Induction(nullptr), WidestIndTy(nullptr), HasFunNoNaNAttr(false) {}
/// This enum represents the kinds of reductions that we support.
enum ReductionKind {
/// Returns the information that we collected about runtime memory check.
LoopAccessInfo::RuntimePointerCheck *getRuntimePointerCheck() {
- return LAI.getRuntimePointerCheck();
+ return LAI->getRuntimePointerCheck();
}
LoopAccessInfo *getLAI() {
- return &LAI;
+ return LAI;
}
/// This function returns the identity element (or neutral element) for
/// the operation K.
static Constant *getReductionIdentity(ReductionKind K, Type *Tp);
- unsigned getMaxSafeDepDistBytes() { return LAI.getMaxSafeDepDistBytes(); }
+ unsigned getMaxSafeDepDistBytes() { return LAI->getMaxSafeDepDistBytes(); }
bool hasStride(Value *V) { return StrideSet.count(V); }
bool mustCheckStrides() { return !StrideSet.empty(); }
return (MaskedOp.count(I) != 0);
}
unsigned getNumStores() const {
- return LAI.getNumStores();
+ return LAI->getNumStores();
}
unsigned getNumLoads() const {
- return LAI.getNumLoads();
+ return LAI->getNumLoads();
}
unsigned getNumPredStores() const {
return NumPredStores;
const TargetTransformInfo *TTI;
/// Dominator Tree.
DominatorTree *DT;
+ // LoopAccess analysis.
+ LoopAccessAnalysis *LAA;
+ // And the loop-accesses info corresponding to this loop. This pointer is
+ // null until canVectorizeMemory sets it up.
+ LoopAccessInfo *LAI;
// --- vectorization state --- //
/// This set holds the variables which are known to be uniform after
/// vectorization.
SmallPtrSet<Instruction*, 4> Uniforms;
- LoopAccessInfo LAI;
+
/// Can we assume the absence of NaNs.
bool HasFunNoNaNAttr;
TargetLibraryInfo *TLI;
AliasAnalysis *AA;
AssumptionCache *AC;
+ LoopAccessAnalysis *LAA;
bool DisableUnrolling;
bool AlwaysVectorize;
TLI = TLIP ? &TLIP->getTLI() : nullptr;
AA = &getAnalysis<AliasAnalysis>();
AC = &getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F);
+ LAA = &getAnalysis<LoopAccessAnalysis>();
// Compute some weights outside of the loop over the loops. Compute this
// using a BranchProbability to re-use its scaling math.
}
// Check if it is legal to vectorize the loop.
- LoopVectorizationLegality LVL(L, SE, DL, DT, TLI, AA, F, TTI);
+ LoopVectorizationLegality LVL(L, SE, DL, DT, TLI, AA, F, TTI, LAA);
if (!LVL.canVectorize()) {
DEBUG(dbgs() << "LV: Not vectorizing: Cannot prove legality.\n");
emitMissedWarning(F, L, Hints);
AU.addRequired<ScalarEvolution>();
AU.addRequired<TargetTransformInfoWrapperPass>();
AU.addRequired<AliasAnalysis>();
+ AU.addRequired<LoopAccessAnalysis>();
AU.addPreserved<LoopInfoWrapperPass>();
AU.addPreserved<DominatorTreeWrapperPass>();
AU.addPreserved<AliasAnalysis>();
}
bool LoopVectorizationLegality::isUniform(Value *V) {
- return LAI.isUniform(V);
+ return LAI->isUniform(V);
}
InnerLoopVectorizer::VectorParts&
collectLoopUniforms();
DEBUG(dbgs() << "LV: We can vectorize this loop" <<
- (LAI.getRuntimePointerCheck()->Need ? " (with a runtime bound check)" :
+ (LAI->getRuntimePointerCheck()->Need ? " (with a runtime bound check)" :
"")
<<"!\n");
}
bool LoopVectorizationLegality::canVectorizeMemory() {
- return LAI.canVectorizeMemory(Strides);
+ LAI = &LAA->getInfo(TheLoop, Strides);
+ auto &OptionalReport = LAI->getReport();
+ if (OptionalReport)
+ emitAnalysis(*OptionalReport);
+ return LAI->canVectorizeMemory();
}
static bool hasMultipleUsesOf(Instruction *I,
INITIALIZE_PASS_DEPENDENCY(LCSSA)
INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
INITIALIZE_PASS_DEPENDENCY(LoopSimplify)
+INITIALIZE_PASS_DEPENDENCY(LoopAccessAnalysis)
INITIALIZE_PASS_END(LoopVectorize, LV_NAME, lv_name, false, false)
namespace llvm {