61 #include "llvm/Config/llvm-config.h" 72 #define DEBUG_TYPE "da" 77 STATISTIC(TotalArrayPairs,
"Array pairs tested");
78 STATISTIC(SeparableSubscriptPairs,
"Separable subscript pairs");
79 STATISTIC(CoupledSubscriptPairs,
"Coupled subscript pairs");
80 STATISTIC(NonlinearSubscriptPairs,
"Nonlinear subscript pairs");
81 STATISTIC(ZIVapplications,
"ZIV applications");
82 STATISTIC(ZIVindependence,
"ZIV independence");
83 STATISTIC(StrongSIVapplications,
"Strong SIV applications");
84 STATISTIC(StrongSIVsuccesses,
"Strong SIV successes");
85 STATISTIC(StrongSIVindependence,
"Strong SIV independence");
86 STATISTIC(WeakCrossingSIVapplications,
"Weak-Crossing SIV applications");
87 STATISTIC(WeakCrossingSIVsuccesses,
"Weak-Crossing SIV successes");
88 STATISTIC(WeakCrossingSIVindependence,
"Weak-Crossing SIV independence");
89 STATISTIC(ExactSIVapplications,
"Exact SIV applications");
90 STATISTIC(ExactSIVsuccesses,
"Exact SIV successes");
91 STATISTIC(ExactSIVindependence,
"Exact SIV independence");
92 STATISTIC(WeakZeroSIVapplications,
"Weak-Zero SIV applications");
93 STATISTIC(WeakZeroSIVsuccesses,
"Weak-Zero SIV successes");
94 STATISTIC(WeakZeroSIVindependence,
"Weak-Zero SIV independence");
95 STATISTIC(ExactRDIVapplications,
"Exact RDIV applications");
96 STATISTIC(ExactRDIVindependence,
"Exact RDIV independence");
97 STATISTIC(SymbolicRDIVapplications,
"Symbolic RDIV applications");
98 STATISTIC(SymbolicRDIVindependence,
"Symbolic RDIV independence");
99 STATISTIC(DeltaApplications,
"Delta applications");
100 STATISTIC(DeltaSuccesses,
"Delta successes");
101 STATISTIC(DeltaIndependence,
"Delta independence");
102 STATISTIC(DeltaPropagations,
"Delta propagations");
103 STATISTIC(GCDapplications,
"GCD applications");
104 STATISTIC(GCDsuccesses,
"GCD successes");
105 STATISTIC(GCDindependence,
"GCD independence");
106 STATISTIC(BanerjeeApplications,
"Banerjee applications");
107 STATISTIC(BanerjeeIndependence,
"Banerjee independence");
108 STATISTIC(BanerjeeSuccesses,
"Banerjee successes");
112 cl::desc(
"Try to delinearize array references."));
128 "Dependence Analysis",
true,
true)
135 char DependenceAnalysisWrapperPass::
ID = 0;
138 return new DependenceAnalysisWrapperPass();
142 auto &AA = getAnalysis<AAResultsWrapperPass>().getAAResults();
143 auto &SE = getAnalysis<ScalarEvolutionWrapperPass>().getSE();
144 auto &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
169 if (isa<StoreInst>(*SrcI) || isa<LoadInst>(*SrcI)) {
171 DstI != DstE; ++DstI) {
172 if (isa<StoreInst>(*DstI) || isa<LoadInst>(*DstI)) {
173 OS <<
"da analyze - ";
174 if (
auto D = DA->
depends(&*SrcI, &*DstI,
true)) {
177 if (
D->isSplitable(
Level)) {
178 OS <<
"da analyze - split level = " <<
Level;
202 return Src->mayReadFromMemory() && Dst->mayReadFromMemory();
208 return Src->mayWriteToMemory() && Dst->mayWriteToMemory();
214 return Src->mayWriteToMemory() && Dst->mayReadFromMemory();
220 return Src->mayReadFromMemory() && Dst->mayWriteToMemory();
237 bool PossiblyLoopIndependent,
238 unsigned CommonLevels)
239 :
Dependence(Source, Destination), Levels(CommonLevels),
240 LoopIndependent(PossiblyLoopIndependent) {
243 DV = make_unique<DVEntry[]>(CommonLevels);
250 assert(0 < Level && Level <= Levels &&
"Level out of range");
251 return DV[Level - 1].Direction;
257 assert(0 < Level && Level <= Levels &&
"Level out of range");
258 return DV[Level - 1].Distance;
266 assert(0 < Level && Level <= Levels &&
"Level out of range");
267 return DV[Level - 1].Scalar;
274 assert(0 < Level && Level <= Levels &&
"Level out of range");
275 return DV[Level - 1].PeelFirst;
282 assert(0 < Level && Level <= Levels &&
"Level out of range");
283 return DV[Level - 1].PeelLast;
289 assert(0 < Level && Level <= Levels &&
"Level out of range");
290 return DV[Level - 1].Splitable;
299 const SCEV *DependenceInfo::Constraint::getX()
const {
300 assert(
Kind == Point &&
"Kind should be Point");
307 const SCEV *DependenceInfo::Constraint::getY()
const {
308 assert(
Kind == Point &&
"Kind should be Point");
315 const SCEV *DependenceInfo::Constraint::getA()
const {
317 "Kind should be Line (or Distance)");
324 const SCEV *DependenceInfo::Constraint::getB()
const {
326 "Kind should be Line (or Distance)");
333 const SCEV *DependenceInfo::Constraint::getC()
const {
335 "Kind should be Line (or Distance)");
342 const SCEV *DependenceInfo::Constraint::getD()
const {
343 assert(
Kind == Distance &&
"Kind should be Distance");
344 return SE->getNegativeSCEV(
C);
349 const Loop *DependenceInfo::Constraint::getAssociatedLoop()
const {
351 "Kind should be Distance, Line, or Point");
352 return AssociatedLoop;
355 void DependenceInfo::Constraint::setPoint(
const SCEV *
X,
const SCEV *
Y,
356 const Loop *CurLoop) {
360 AssociatedLoop = CurLoop;
363 void DependenceInfo::Constraint::setLine(
const SCEV *AA,
const SCEV *BB,
364 const SCEV *CC,
const Loop *CurLoop) {
369 AssociatedLoop = CurLoop;
372 void DependenceInfo::Constraint::setDistance(
const SCEV *
D,
373 const Loop *CurLoop) {
376 B = SE->getNegativeSCEV(A);
377 C = SE->getNegativeSCEV(D);
378 AssociatedLoop = CurLoop;
381 void DependenceInfo::Constraint::setEmpty() {
Kind =
Empty; }
388 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 396 OS <<
" Point is <" << *getX() <<
", " << *getY() <<
">\n";
397 else if (isDistance())
398 OS <<
" Distance is " << *getD() <<
399 " (" << *getA() <<
"*X + " << *getB() <<
"*Y = " << *getC() <<
")\n";
401 OS <<
" Line is " << *getA() <<
"*X + " <<
402 *getB() <<
"*Y = " << *getC() <<
"\n";
416 bool DependenceInfo::intersectConstraints(Constraint *X,
const Constraint *Y) {
421 assert(!Y->isPoint() &&
"Y must not be a Point");
435 if (X->isDistance() && Y->isDistance()) {
446 if (isa<SCEVConstant>(Y->getD())) {
459 assert(!(X->isPoint() && Y->isPoint()) &&
460 "We shouldn't ever see X->isPoint() && Y->isPoint()");
462 if (X->isLine() && Y->isLine()) {
464 const SCEV *Prod1 = SE->getMulExpr(X->getA(), Y->getB());
465 const SCEV *Prod2 = SE->getMulExpr(X->getB(), Y->getA());
469 Prod1 = SE->getMulExpr(X->getC(), Y->getB());
470 Prod2 = SE->getMulExpr(X->getB(), Y->getC());
483 const SCEV *C1B2 = SE->getMulExpr(X->getC(), Y->getB());
484 const SCEV *C1A2 = SE->getMulExpr(X->getC(), Y->getA());
485 const SCEV *C2B1 = SE->getMulExpr(Y->getC(), X->getB());
486 const SCEV *C2A1 = SE->getMulExpr(Y->getC(), X->getA());
487 const SCEV *A1B2 = SE->getMulExpr(X->getA(), Y->getB());
488 const SCEV *A2B1 = SE->getMulExpr(Y->getA(), X->getB());
497 if (!C1B2_C2B1 || !C1A2_C2A1 ||
498 !A1B2_A2B1 || !A2B1_A1B2)
500 APInt Xtop = C1B2_C2B1->getAPInt();
501 APInt Xbot = A1B2_A2B1->getAPInt();
503 APInt Ybot = A2B1_A1B2->getAPInt();
514 if (Xr != 0 || Yr != 0) {
520 if (Xq.
slt(0) || Yq.
slt(0)) {
526 collectConstantUpperBound(X->getAssociatedLoop(), Prod1->
getType())) {
527 const APInt &UpperBound = CUB->getAPInt();
529 if (Xq.
sgt(UpperBound) || Yq.
sgt(UpperBound)) {
535 X->setPoint(SE->getConstant(Xq),
537 X->getAssociatedLoop());
545 assert(!(X->isLine() && Y->isPoint()) &&
"This case should never occur");
547 if (X->isPoint() && Y->isLine()) {
549 const SCEV *A1X1 = SE->getMulExpr(Y->getA(), X->getX());
550 const SCEV *B1Y1 = SE->getMulExpr(Y->getB(), X->getY());
551 const SCEV *Sum = SE->getAddExpr(A1X1, B1Y1);
572 bool Splitable =
false;
588 for (
unsigned II = 1; II <= Levels; ++II) {
664 if (
const LoadInst *LI = dyn_cast<LoadInst>(I))
665 return LI->isUnordered();
666 else if (
const StoreInst *
SI = dyn_cast<StoreInst>(I))
667 return SI->isUnordered();
722 void DependenceInfo::establishNestingLevels(
const Instruction *Src,
726 unsigned SrcLevel = LI->getLoopDepth(SrcBlock);
727 unsigned DstLevel = LI->getLoopDepth(DstBlock);
728 const Loop *SrcLoop = LI->getLoopFor(SrcBlock);
729 const Loop *DstLoop = LI->getLoopFor(DstBlock);
730 SrcLevels = SrcLevel;
731 MaxLevels = SrcLevel + DstLevel;
732 while (SrcLevel > DstLevel) {
736 while (DstLevel > SrcLevel) {
740 while (SrcLoop != DstLoop) {
745 CommonLevels = SrcLevel;
746 MaxLevels -= CommonLevels;
752 unsigned DependenceInfo::mapSrcLoop(
const Loop *SrcLoop)
const {
759 unsigned DependenceInfo::mapDstLoop(
const Loop *DstLoop)
const {
761 if (D > CommonLevels)
762 return D - CommonLevels + SrcLevels;
769 bool DependenceInfo::isLoopInvariant(
const SCEV *Expression,
770 const Loop *LoopNest)
const {
773 return SE->isLoopInvariant(Expression, LoopNest) &&
781 void DependenceInfo::collectCommonLoops(
const SCEV *Expression,
782 const Loop *LoopNest,
786 if (Level <= CommonLevels && !SE->
isLoopInvariant(Expression, LoopNest))
794 unsigned widestWidthSeen = 0;
799 for (Subscript *Pair : Pairs) {
800 const SCEV *Src = Pair->Src;
801 const SCEV *Dst = Pair->Dst;
804 if (SrcTy ==
nullptr || DstTy ==
nullptr) {
805 assert(SrcTy == DstTy &&
"This function only unify integer types and " 806 "expect Src and Dst share the same type " 814 if (DstTy->getBitWidth() > widestWidthSeen) {
815 widestWidthSeen = DstTy->getBitWidth();
821 assert(widestWidthSeen > 0);
824 for (Subscript *Pair : Pairs) {
825 const SCEV *Src = Pair->Src;
826 const SCEV *Dst = Pair->Dst;
829 if (SrcTy ==
nullptr || DstTy ==
nullptr) {
830 assert(SrcTy == DstTy &&
"This function only unify integer types and " 831 "expect Src and Dst share the same type " 837 Pair->Src = SE->getSignExtendExpr(Src, widestType);
838 if (DstTy->getBitWidth() < widestWidthSeen) {
840 Pair->Dst = SE->getSignExtendExpr(Dst, widestType);
849 void DependenceInfo::removeMatchingExtensions(Subscript *Pair) {
850 const SCEV *Src = Pair->Src;
851 const SCEV *Dst = Pair->Dst;
852 if ((isa<SCEVZeroExtendExpr>(Src) && isa<SCEVZeroExtendExpr>(Dst)) ||
853 (isa<SCEVSignExtendExpr>(Src) && isa<SCEVSignExtendExpr>(Dst))) {
857 const SCEV *DstCastOp = DstCast->getOperand();
858 if (SrcCastOp->getType() == DstCastOp->
getType()) {
859 Pair->Src = SrcCastOp;
860 Pair->Dst = DstCastOp;
868 bool DependenceInfo::checkSrcSubscript(
const SCEV *Src,
const Loop *LoopNest,
875 const SCEV *UB = SE->getBackedgeTakenCount(AddRec->
getLoop());
876 if (!isa<SCEVCouldNotCompute>(UB)) {
877 if (SE->getTypeSizeInBits(Start->
getType()) <
878 SE->getTypeSizeInBits(UB->
getType())) {
886 return checkSrcSubscript(Start, LoopNest, Loops);
893 bool DependenceInfo::checkDstSubscript(
const SCEV *Dst,
const Loop *LoopNest,
900 const SCEV *UB = SE->getBackedgeTakenCount(AddRec->
getLoop());
901 if (!isa<SCEVCouldNotCompute>(UB)) {
902 if (SE->getTypeSizeInBits(Start->
getType()) <
903 SE->getTypeSizeInBits(UB->
getType())) {
911 return checkDstSubscript(Start, LoopNest, Loops);
918 DependenceInfo::Subscript::ClassificationKind
919 DependenceInfo::classifyPair(
const SCEV *Src,
const Loop *SrcLoopNest,
920 const SCEV *Dst,
const Loop *DstLoopNest,
924 if (!checkSrcSubscript(Src, SrcLoopNest, SrcLoops))
925 return Subscript::NonLinear;
926 if (!checkDstSubscript(Dst, DstLoopNest, DstLoops))
927 return Subscript::NonLinear;
930 unsigned N = Loops.
count();
932 return Subscript::ZIV;
934 return Subscript::SIV;
935 if (N == 2 && (SrcLoops.
count() == 0 ||
936 DstLoops.
count() == 0 ||
937 (SrcLoops.
count() == 1 && DstLoops.
count() == 1)))
938 return Subscript::RDIV;
939 return Subscript::MIV;
954 const SCEV *Y)
const {
957 if ((isa<SCEVSignExtendExpr>(X) &&
958 isa<SCEVSignExtendExpr>(Y)) ||
959 (isa<SCEVZeroExtendExpr>(X) &&
960 isa<SCEVZeroExtendExpr>(Y))) {
964 const SCEV *Yop = CY->getOperand();
965 if (Xop->getType() == Yop->
getType()) {
971 if (SE->isKnownPredicate(Pred, X, Y))
978 const SCEV *Delta = SE->getMinusSCEV(X, Y);
983 return SE->isKnownNonZero(Delta);
985 return SE->isKnownNonNegative(Delta);
987 return SE->isKnownNonPositive(Delta);
989 return SE->isKnownPositive(Delta);
991 return SE->isKnownNegative(Delta);
1000 bool DependenceInfo::isKnownLessThan(
const SCEV *S,
const SCEV *
Size)
const {
1004 if (!SType || !SizeType)
1007 (SType->getBitWidth() >= SizeType->getBitWidth()) ? SType : SizeType;
1008 S = SE->getTruncateOrZeroExtend(S, MaxType);
1009 Size = SE->getTruncateOrZeroExtend(Size, MaxType);
1012 const SCEV *Bound = SE->getMinusSCEV(S, Size);
1013 if (
const SCEVAddRecExpr *AddRec = dyn_cast<SCEVAddRecExpr>(Bound)) {
1014 if (AddRec->isAffine()) {
1015 const SCEV *BECount = SE->getBackedgeTakenCount(AddRec->getLoop());
1016 if (!isa<SCEVCouldNotCompute>(BECount)) {
1017 const SCEV *Limit = AddRec->evaluateAtIteration(BECount, *SE);
1018 if (SE->isKnownNegative(Limit))
1025 const SCEV *LimitedBound =
1026 SE->getMinusSCEV(S, SE->getSMaxExpr(Size, SE->getOne(Size->
getType())));
1027 return SE->isKnownNegative(LimitedBound);
1030 bool DependenceInfo::isKnownNonNegative(
const SCEV *S,
const Value *
Ptr)
const {
1031 bool Inbounds =
false;
1032 if (
auto *SrcGEP = dyn_cast<GetElementPtrInst>(Ptr))
1033 Inbounds = SrcGEP->isInBounds();
1035 if (
const SCEVAddRecExpr *AddRec = dyn_cast<SCEVAddRecExpr>(S)) {
1036 if (AddRec->isAffine()) {
1039 if (SE->isKnownNonNegative(AddRec->getStart()) &&
1040 SE->isKnownNonNegative(AddRec->getOperand(1)))
1046 return SE->isKnownNonNegative(S);
1056 const SCEV *DependenceInfo::collectUpperBound(
const Loop *L,
Type *
T)
const {
1057 if (SE->hasLoopInvariantBackedgeTakenCount(L)) {
1058 const SCEV *UB = SE->getBackedgeTakenCount(L);
1059 return SE->getTruncateOrZeroExtend(UB, T);
1067 const SCEVConstant *DependenceInfo::collectConstantUpperBound(
const Loop *L,
1069 if (
const SCEV *UB = collectUpperBound(L, T))
1085 bool DependenceInfo::testZIV(
const SCEV *Src,
const SCEV *Dst,
1100 Result.Consistent =
false;
1132 bool DependenceInfo::strongSIVtest(
const SCEV *Coeff,
const SCEV *SrcConst,
1133 const SCEV *DstConst,
const Loop *CurLoop,
1135 Constraint &NewConstraint)
const {
1143 ++StrongSIVapplications;
1144 assert(0 < Level && Level <= CommonLevels &&
"level out of range");
1147 const SCEV *Delta = SE->getMinusSCEV(SrcConst, DstConst);
1152 if (
const SCEV *UpperBound = collectUpperBound(CurLoop, Delta->
getType())) {
1155 const SCEV *AbsDelta =
1156 SE->isKnownNonNegative(Delta) ? Delta : SE->getNegativeSCEV(Delta);
1157 const SCEV *AbsCoeff =
1158 SE->isKnownNonNegative(Coeff) ? Coeff : SE->getNegativeSCEV(Coeff);
1159 const SCEV *Product = SE->getMulExpr(UpperBound, AbsCoeff);
1162 ++StrongSIVindependence;
1163 ++StrongSIVsuccesses;
1169 if (isa<SCEVConstant>(Delta) && isa<SCEVConstant>(Coeff)) {
1170 APInt ConstDelta = cast<SCEVConstant>(Delta)->getAPInt();
1171 APInt ConstCoeff = cast<SCEVConstant>(Coeff)->getAPInt();
1172 APInt Distance = ConstDelta;
1173 APInt Remainder = ConstDelta;
1178 if (Remainder != 0) {
1180 ++StrongSIVindependence;
1181 ++StrongSIVsuccesses;
1184 Result.DV[
Level].Distance = SE->getConstant(Distance);
1185 NewConstraint.setDistance(SE->getConstant(Distance), CurLoop);
1186 if (Distance.
sgt(0))
1188 else if (Distance.
slt(0))
1192 ++StrongSIVsuccesses;
1194 else if (Delta->
isZero()) {
1196 Result.DV[
Level].Distance = Delta;
1197 NewConstraint.setDistance(Delta, CurLoop);
1199 ++StrongSIVsuccesses;
1202 if (Coeff->
isOne()) {
1204 Result.DV[
Level].Distance = Delta;
1205 NewConstraint.setDistance(Delta, CurLoop);
1208 Result.Consistent =
false;
1209 NewConstraint.setLine(Coeff,
1210 SE->getNegativeSCEV(Coeff),
1211 SE->getNegativeSCEV(Delta), CurLoop);
1215 bool DeltaMaybeZero = !SE->isKnownNonZero(Delta);
1216 bool DeltaMaybePositive = !SE->isKnownNonPositive(Delta);
1217 bool DeltaMaybeNegative = !SE->isKnownNonNegative(Delta);
1218 bool CoeffMaybePositive = !SE->isKnownNonPositive(Coeff);
1219 bool CoeffMaybeNegative = !SE->isKnownNonNegative(Coeff);
1224 if ((DeltaMaybePositive && CoeffMaybePositive) ||
1225 (DeltaMaybeNegative && CoeffMaybeNegative))
1229 if ((DeltaMaybeNegative && CoeffMaybePositive) ||
1230 (DeltaMaybePositive && CoeffMaybeNegative))
1232 if (NewDirection < Result.DV[Level].Direction)
1233 ++StrongSIVsuccesses;
1234 Result.DV[
Level].Direction &= NewDirection;
1268 bool DependenceInfo::weakCrossingSIVtest(
1269 const SCEV *Coeff,
const SCEV *SrcConst,
const SCEV *DstConst,
1271 Constraint &NewConstraint,
const SCEV *&SplitIter)
const {
1276 ++WeakCrossingSIVapplications;
1277 assert(0 < Level && Level <= CommonLevels &&
"Level out of range");
1279 Result.Consistent =
false;
1280 const SCEV *Delta = SE->getMinusSCEV(DstConst, SrcConst);
1282 NewConstraint.setLine(Coeff, Coeff, Delta, CurLoop);
1286 ++WeakCrossingSIVsuccesses;
1287 if (!Result.DV[Level].Direction) {
1288 ++WeakCrossingSIVindependence;
1291 Result.DV[
Level].Distance = Delta;
1298 Result.DV[
Level].Splitable =
true;
1299 if (SE->isKnownNegative(ConstCoeff)) {
1302 "dynamic cast of negative of ConstCoeff should yield constant");
1303 Delta = SE->getNegativeSCEV(Delta);
1305 assert(SE->isKnownPositive(ConstCoeff) &&
"ConstCoeff should be positive");
1308 SplitIter = SE->getUDivExpr(
1309 SE->getSMaxExpr(SE->getZero(Delta->
getType()), Delta),
1310 SE->getMulExpr(SE->getConstant(Delta->
getType(), 2), ConstCoeff));
1321 if (SE->isKnownNegative(Delta)) {
1323 ++WeakCrossingSIVindependence;
1324 ++WeakCrossingSIVsuccesses;
1330 if (
const SCEV *UpperBound = collectUpperBound(CurLoop, Delta->
getType())) {
1332 const SCEV *ConstantTwo = SE->getConstant(UpperBound->getType(), 2);
1333 const SCEV *ML = SE->getMulExpr(SE->getMulExpr(ConstCoeff, UpperBound),
1338 ++WeakCrossingSIVindependence;
1339 ++WeakCrossingSIVsuccesses;
1346 ++WeakCrossingSIVsuccesses;
1347 if (!Result.DV[Level].Direction) {
1348 ++WeakCrossingSIVindependence;
1351 Result.DV[
Level].Splitable =
false;
1352 Result.DV[
Level].Distance = SE->getZero(Delta->
getType());
1360 APInt Distance = APDelta;
1361 APInt Remainder = APDelta;
1364 if (Remainder != 0) {
1366 ++WeakCrossingSIVindependence;
1367 ++WeakCrossingSIVsuccesses;
1374 Remainder = Distance.
srem(Two);
1376 if (Remainder != 0) {
1379 ++WeakCrossingSIVsuccesses;
1397 APInt A0(Bits, 1,
true), A1(Bits, 0,
true);
1398 APInt B0(Bits, 0,
true),
B1(Bits, 1,
true);
1405 APInt A2 = A0 - Q*A1; A0 = A1; A1 = A2;
1406 APInt B2 = B0 - Q*B1; B0 = B1; B1 = B2;
1412 X = AM.
slt(0) ? -A1 : A1;
1413 Y = BM.
slt(0) ? B1 : -B1;
1431 if ((A.
sgt(0) && B.
sgt(0)) ||
1444 if ((A.
sgt(0) && B.
sgt(0)) ||
1454 return A.
sgt(B) ? A :
B;
1460 return A.
slt(B) ? A :
B;
1479 bool DependenceInfo::exactSIVtest(
const SCEV *SrcCoeff,
const SCEV *DstCoeff,
1480 const SCEV *SrcConst,
const SCEV *DstConst,
1481 const Loop *CurLoop,
unsigned Level,
1483 Constraint &NewConstraint)
const {
1485 LLVM_DEBUG(
dbgs() <<
"\t SrcCoeff = " << *SrcCoeff <<
" = AM\n");
1486 LLVM_DEBUG(
dbgs() <<
"\t DstCoeff = " << *DstCoeff <<
" = BM\n");
1489 ++ExactSIVapplications;
1490 assert(0 < Level && Level <= CommonLevels &&
"Level out of range");
1492 Result.Consistent =
false;
1493 const SCEV *Delta = SE->getMinusSCEV(DstConst, SrcConst);
1495 NewConstraint.setLine(SrcCoeff, SE->getNegativeSCEV(DstCoeff),
1500 if (!ConstDelta || !ConstSrcCoeff || !ConstDstCoeff)
1505 APInt AM = ConstSrcCoeff->getAPInt();
1506 APInt BM = ConstDstCoeff->getAPInt();
1510 ++ExactSIVindependence;
1511 ++ExactSIVsuccesses;
1518 APInt UM(Bits, 1,
true);
1519 bool UMvalid =
false;
1522 collectConstantUpperBound(CurLoop, Delta->
getType())) {
1523 UM = CUB->getAPInt();
1569 ++ExactSIVindependence;
1570 ++ExactSIVsuccesses;
1592 ++ExactSIVsuccesses;
1618 ++ExactSIVsuccesses;
1635 ++ExactSIVsuccesses;
1639 Result.DV[
Level].Direction &= NewDirection;
1641 ++ExactSIVindependence;
1653 return ConstDividend.
srem(ConstDivisor) == 0;
1688 bool DependenceInfo::weakZeroSrcSIVtest(
const SCEV *DstCoeff,
1689 const SCEV *SrcConst,
1690 const SCEV *DstConst,
1691 const Loop *CurLoop,
unsigned Level,
1693 Constraint &NewConstraint)
const {
1701 ++WeakZeroSIVapplications;
1702 assert(0 < Level && Level <= MaxLevels &&
"Level out of range");
1704 Result.Consistent =
false;
1705 const SCEV *Delta = SE->getMinusSCEV(SrcConst, DstConst);
1706 NewConstraint.setLine(SE->getZero(Delta->
getType()), DstCoeff, Delta,
1710 if (Level < CommonLevels) {
1712 Result.DV[
Level].PeelFirst =
true;
1713 ++WeakZeroSIVsuccesses;
1720 const SCEV *AbsCoeff =
1721 SE->isKnownNegative(ConstCoeff) ?
1722 SE->getNegativeSCEV(ConstCoeff) : ConstCoeff;
1723 const SCEV *NewDelta =
1724 SE->isKnownNegative(ConstCoeff) ? SE->getNegativeSCEV(Delta) : Delta;
1728 if (
const SCEV *UpperBound = collectUpperBound(CurLoop, Delta->
getType())) {
1730 const SCEV *Product = SE->getMulExpr(AbsCoeff, UpperBound);
1732 ++WeakZeroSIVindependence;
1733 ++WeakZeroSIVsuccesses;
1738 if (Level < CommonLevels) {
1740 Result.DV[
Level].PeelLast =
true;
1741 ++WeakZeroSIVsuccesses;
1749 if (SE->isKnownNegative(NewDelta)) {
1751 ++WeakZeroSIVindependence;
1752 ++WeakZeroSIVsuccesses;
1757 if (isa<SCEVConstant>(Delta) &&
1759 ++WeakZeroSIVindependence;
1760 ++WeakZeroSIVsuccesses;
1798 bool DependenceInfo::weakZeroDstSIVtest(
const SCEV *SrcCoeff,
1799 const SCEV *SrcConst,
1800 const SCEV *DstConst,
1801 const Loop *CurLoop,
unsigned Level,
1803 Constraint &NewConstraint)
const {
1810 ++WeakZeroSIVapplications;
1811 assert(0 < Level && Level <= SrcLevels &&
"Level out of range");
1813 Result.Consistent =
false;
1814 const SCEV *Delta = SE->getMinusSCEV(DstConst, SrcConst);
1815 NewConstraint.setLine(SrcCoeff, SE->getZero(Delta->
getType()), Delta,
1819 if (Level < CommonLevels) {
1821 Result.DV[
Level].PeelFirst =
true;
1822 ++WeakZeroSIVsuccesses;
1829 const SCEV *AbsCoeff =
1830 SE->isKnownNegative(ConstCoeff) ?
1831 SE->getNegativeSCEV(ConstCoeff) : ConstCoeff;
1832 const SCEV *NewDelta =
1833 SE->isKnownNegative(ConstCoeff) ? SE->getNegativeSCEV(Delta) : Delta;
1837 if (
const SCEV *UpperBound = collectUpperBound(CurLoop, Delta->
getType())) {
1839 const SCEV *Product = SE->getMulExpr(AbsCoeff, UpperBound);
1841 ++WeakZeroSIVindependence;
1842 ++WeakZeroSIVsuccesses;
1847 if (Level < CommonLevels) {
1849 Result.DV[
Level].PeelLast =
true;
1850 ++WeakZeroSIVsuccesses;
1858 if (SE->isKnownNegative(NewDelta)) {
1860 ++WeakZeroSIVindependence;
1861 ++WeakZeroSIVsuccesses;
1866 if (isa<SCEVConstant>(Delta) &&
1868 ++WeakZeroSIVindependence;
1869 ++WeakZeroSIVsuccesses;
1883 bool DependenceInfo::exactRDIVtest(
const SCEV *SrcCoeff,
const SCEV *DstCoeff,
1884 const SCEV *SrcConst,
const SCEV *DstConst,
1885 const Loop *SrcLoop,
const Loop *DstLoop,
1888 LLVM_DEBUG(
dbgs() <<
"\t SrcCoeff = " << *SrcCoeff <<
" = AM\n");
1889 LLVM_DEBUG(
dbgs() <<
"\t DstCoeff = " << *DstCoeff <<
" = BM\n");
1892 ++ExactRDIVapplications;
1893 Result.Consistent =
false;
1894 const SCEV *Delta = SE->getMinusSCEV(DstConst, SrcConst);
1899 if (!ConstDelta || !ConstSrcCoeff || !ConstDstCoeff)
1904 APInt AM = ConstSrcCoeff->getAPInt();
1905 APInt BM = ConstDstCoeff->getAPInt();
1909 ++ExactRDIVindependence;
1916 APInt SrcUM(Bits, 1,
true);
1917 bool SrcUMvalid =
false;
1920 collectConstantUpperBound(SrcLoop, Delta->
getType())) {
1921 SrcUM = UpperBound->getAPInt();
1926 APInt DstUM(Bits, 1,
true);
1927 bool DstUMvalid =
false;
1930 collectConstantUpperBound(DstLoop, Delta->
getType())) {
1931 DstUM = UpperBound->getAPInt();
1977 ++ExactRDIVindependence;
2024 bool DependenceInfo::symbolicRDIVtest(
const SCEV *A1,
const SCEV *A2,
2027 const Loop *Loop2)
const {
2028 ++SymbolicRDIVapplications;
2035 const SCEV *N1 = collectUpperBound(Loop1, A1->
getType());
2036 const SCEV *N2 = collectUpperBound(Loop2, A1->
getType());
2039 const SCEV *C2_C1 = SE->getMinusSCEV(C2, C1);
2040 const SCEV *C1_C2 = SE->getMinusSCEV(C1, C2);
2043 if (SE->isKnownNonNegative(A1)) {
2044 if (SE->isKnownNonNegative(A2)) {
2048 const SCEV *A1N1 = SE->getMulExpr(A1, N1);
2051 ++SymbolicRDIVindependence;
2057 const SCEV *A2N2 = SE->getMulExpr(A2, N2);
2060 ++SymbolicRDIVindependence;
2065 else if (SE->isKnownNonPositive(A2)) {
2069 const SCEV *A1N1 = SE->getMulExpr(A1, N1);
2070 const SCEV *A2N2 = SE->getMulExpr(A2, N2);
2071 const SCEV *A1N1_A2N2 = SE->getMinusSCEV(A1N1, A2N2);
2072 LLVM_DEBUG(
dbgs() <<
"\t A1*N1 - A2*N2 = " << *A1N1_A2N2 <<
"\n");
2074 ++SymbolicRDIVindependence;
2079 if (SE->isKnownNegative(C2_C1)) {
2080 ++SymbolicRDIVindependence;
2085 else if (SE->isKnownNonPositive(A1)) {
2086 if (SE->isKnownNonNegative(A2)) {
2090 const SCEV *A1N1 = SE->getMulExpr(A1, N1);
2091 const SCEV *A2N2 = SE->getMulExpr(A2, N2);
2092 const SCEV *A1N1_A2N2 = SE->getMinusSCEV(A1N1, A2N2);
2093 LLVM_DEBUG(
dbgs() <<
"\t A1*N1 - A2*N2 = " << *A1N1_A2N2 <<
"\n");
2095 ++SymbolicRDIVindependence;
2100 if (SE->isKnownPositive(C2_C1)) {
2101 ++SymbolicRDIVindependence;
2105 else if (SE->isKnownNonPositive(A2)) {
2109 const SCEV *A1N1 = SE->getMulExpr(A1, N1);
2112 ++SymbolicRDIVindependence;
2118 const SCEV *A2N2 = SE->getMulExpr(A2, N2);
2121 ++SymbolicRDIVindependence;
2139 bool DependenceInfo::testSIV(
const SCEV *Src,
const SCEV *Dst,
unsigned &Level,
2141 const SCEV *&SplitIter)
const {
2146 if (SrcAddRec && DstAddRec) {
2148 const SCEV *DstConst = DstAddRec->getStart();
2150 const SCEV *DstCoeff = DstAddRec->getStepRecurrence(*SE);
2152 assert(CurLoop == DstAddRec->getLoop() &&
2153 "both loops in SIV should be same");
2154 Level = mapSrcLoop(CurLoop);
2156 if (SrcCoeff == DstCoeff)
2157 disproven = strongSIVtest(SrcCoeff, SrcConst, DstConst, CurLoop,
2158 Level, Result, NewConstraint);
2159 else if (SrcCoeff == SE->getNegativeSCEV(DstCoeff))
2160 disproven = weakCrossingSIVtest(SrcCoeff, SrcConst, DstConst, CurLoop,
2161 Level, Result, NewConstraint, SplitIter);
2163 disproven = exactSIVtest(SrcCoeff, DstCoeff, SrcConst, DstConst, CurLoop,
2164 Level, Result, NewConstraint);
2166 gcdMIVtest(Src, Dst, Result) ||
2167 symbolicRDIVtest(SrcCoeff, DstCoeff, SrcConst, DstConst, CurLoop, CurLoop);
2172 const SCEV *DstConst = Dst;
2174 Level = mapSrcLoop(CurLoop);
2175 return weakZeroDstSIVtest(SrcCoeff, SrcConst, DstConst, CurLoop,
2176 Level, Result, NewConstraint) ||
2177 gcdMIVtest(Src, Dst, Result);
2180 const SCEV *DstConst = DstAddRec->getStart();
2181 const SCEV *DstCoeff = DstAddRec->getStepRecurrence(*SE);
2182 const SCEV *SrcConst = Src;
2183 const Loop *CurLoop = DstAddRec->getLoop();
2184 Level = mapDstLoop(CurLoop);
2185 return weakZeroSrcSIVtest(DstCoeff, SrcConst, DstConst,
2186 CurLoop, Level, Result, NewConstraint) ||
2187 gcdMIVtest(Src, Dst, Result);
2207 bool DependenceInfo::testRDIV(
const SCEV *Src,
const SCEV *Dst,
2215 const SCEV *SrcConst, *DstConst;
2216 const SCEV *SrcCoeff, *DstCoeff;
2217 const Loop *SrcLoop, *DstLoop;
2223 if (SrcAddRec && DstAddRec) {
2226 SrcLoop = SrcAddRec->
getLoop();
2227 DstConst = DstAddRec->getStart();
2228 DstCoeff = DstAddRec->getStepRecurrence(*SE);
2229 DstLoop = DstAddRec->getLoop();
2231 else if (SrcAddRec) {
2233 dyn_cast<SCEVAddRecExpr>(SrcAddRec->
getStart())) {
2234 SrcConst = tmpAddRec->getStart();
2235 SrcCoeff = tmpAddRec->getStepRecurrence(*SE);
2236 SrcLoop = tmpAddRec->getLoop();
2239 DstLoop = SrcAddRec->
getLoop();
2244 else if (DstAddRec) {
2246 dyn_cast<SCEVAddRecExpr>(DstAddRec->getStart())) {
2247 DstConst = tmpAddRec->getStart();
2248 DstCoeff = tmpAddRec->getStepRecurrence(*SE);
2249 DstLoop = tmpAddRec->getLoop();
2251 SrcCoeff = SE->getNegativeSCEV(DstAddRec->getStepRecurrence(*SE));
2252 SrcLoop = DstAddRec->getLoop();
2259 return exactRDIVtest(SrcCoeff, DstCoeff,
2263 gcdMIVtest(Src, Dst, Result) ||
2264 symbolicRDIVtest(SrcCoeff, DstCoeff,
2273 bool DependenceInfo::testMIV(
const SCEV *Src,
const SCEV *Dst,
2278 Result.Consistent =
false;
2279 return gcdMIVtest(Src, Dst, Result) ||
2280 banerjeeMIVtest(Src, Dst, Loops, Result);
2288 if (
const auto *
Constant = dyn_cast<SCEVConstant>(Expr))
2290 else if (
const auto *Product = dyn_cast<SCEVMulExpr>(Expr))
2291 if (
const auto *
Constant = dyn_cast<SCEVConstant>(Product->getOperand(0)))
2315 bool DependenceInfo::gcdMIVtest(
const SCEV *Src,
const SCEV *Dst,
2319 unsigned BitWidth = SE->getTypeSizeInBits(Src->
getType());
2326 const SCEV *Coefficients = Src;
2328 dyn_cast<SCEVAddRecExpr>(Coefficients)) {
2329 const SCEV *Coeff = AddRec->getStepRecurrence(*SE);
2337 Coefficients = AddRec->getStart();
2339 const SCEV *SrcConst = Coefficients;
2347 dyn_cast<SCEVAddRecExpr>(Coefficients)) {
2348 const SCEV *Coeff = AddRec->getStepRecurrence(*SE);
2356 Coefficients = AddRec->getStart();
2358 const SCEV *DstConst = Coefficients;
2361 const SCEV *Delta = SE->getMinusSCEV(DstConst, SrcConst);
2364 if (
const SCEVAddExpr *Sum = dyn_cast<SCEVAddExpr>(Delta)) {
2366 for (
unsigned Op = 0, Ops = Sum->getNumOperands();
Op < Ops;
Op++) {
2367 const SCEV *Operand = Sum->getOperand(
Op);
2368 if (isa<SCEVConstant>(Operand)) {
2369 assert(!Constant &&
"Surprised to find multiple constants");
2370 Constant = cast<SCEVConstant>(Operand);
2372 else if (
const SCEVMulExpr *Product = dyn_cast<SCEVMulExpr>(Operand)) {
2380 ConstOpValue.
abs());
2388 APInt ConstDelta = cast<SCEVConstant>(Constant)->getAPInt();
2390 if (ConstDelta == 0)
2394 APInt Remainder = ConstDelta.
srem(RunningGCD);
2395 if (Remainder != 0) {
2414 bool Improved =
false;
2417 dyn_cast<SCEVAddRecExpr>(Coefficients)) {
2418 Coefficients = AddRec->getStart();
2419 const Loop *CurLoop = AddRec->getLoop();
2420 RunningGCD = ExtraGCD;
2421 const SCEV *SrcCoeff = AddRec->getStepRecurrence(*SE);
2422 const SCEV *DstCoeff = SE->getMinusSCEV(SrcCoeff, SrcCoeff);
2423 const SCEV *Inner = Src;
2424 while (RunningGCD != 1 && isa<SCEVAddRecExpr>(Inner)) {
2425 AddRec = cast<SCEVAddRecExpr>(Inner);
2426 const SCEV *Coeff = AddRec->getStepRecurrence(*SE);
2427 if (CurLoop == AddRec->getLoop())
2438 Inner = AddRec->getStart();
2441 while (RunningGCD != 1 && isa<SCEVAddRecExpr>(Inner)) {
2442 AddRec = cast<SCEVAddRecExpr>(Inner);
2443 const SCEV *Coeff = AddRec->getStepRecurrence(*SE);
2444 if (CurLoop == AddRec->getLoop())
2455 Inner = AddRec->getStart();
2457 Delta = SE->getMinusSCEV(SrcCoeff, DstCoeff);
2468 if (RunningGCD != 0) {
2469 Remainder = ConstDelta.
srem(RunningGCD);
2471 if (Remainder != 0) {
2472 unsigned Level = mapSrcLoop(CurLoop);
2518 bool DependenceInfo::banerjeeMIVtest(
const SCEV *Src,
const SCEV *Dst,
2522 ++BanerjeeApplications;
2525 CoefficientInfo *A = collectCoeffInfo(Src,
true, A0);
2528 CoefficientInfo *
B = collectCoeffInfo(Dst,
false, B0);
2529 BoundInfo *Bound =
new BoundInfo[MaxLevels + 1];
2530 const SCEV *Delta = SE->getMinusSCEV(B0, A0);
2535 for (
unsigned K = 1; K <= MaxLevels; ++K) {
2536 Bound[K].Iterations = A[K].Iterations ? A[K].Iterations : B[K].Iterations;
2539 findBoundsALL(A, B, Bound, K);
2546 if (Bound[K].
Upper[Dependence::DVEntry::ALL])
2554 bool Disproved =
false;
2557 unsigned DepthExpanded = 0;
2558 unsigned NewDeps = exploreDirections(1, A, B, Bound,
2559 Loops, DepthExpanded, Delta);
2561 bool Improved =
false;
2562 for (
unsigned K = 1; K <= CommonLevels; ++K) {
2564 unsigned Old = Result.DV[K - 1].Direction;
2565 Result.DV[K - 1].Direction = Old & Bound[K].DirSet;
2566 Improved |= Old != Result.DV[K - 1].Direction;
2567 if (!Result.DV[K - 1].Direction) {
2575 ++BanerjeeSuccesses;
2578 ++BanerjeeIndependence;
2583 ++BanerjeeIndependence;
2598 unsigned DependenceInfo::exploreDirections(
unsigned Level, CoefficientInfo *A,
2599 CoefficientInfo *
B, BoundInfo *Bound,
2601 unsigned &DepthExpanded,
2602 const SCEV *Delta)
const {
2603 if (Level > CommonLevels) {
2606 for (
unsigned K = 1; K <= CommonLevels; ++K) {
2608 Bound[K].DirSet |= Bound[K].Direction;
2610 switch (Bound[K].Direction) {
2633 if (Level > DepthExpanded) {
2634 DepthExpanded =
Level;
2636 findBoundsLT(A, B, Bound, Level);
2637 findBoundsGT(A, B, Bound, Level);
2638 findBoundsEQ(A, B, Bound, Level);
2647 if (Bound[Level].
Upper[Dependence::DVEntry::LT])
2658 if (Bound[Level].
Upper[Dependence::DVEntry::EQ])
2669 if (Bound[Level].
Upper[Dependence::DVEntry::GT])
2677 unsigned NewDeps = 0;
2681 NewDeps += exploreDirections(Level + 1, A, B, Bound,
2682 Loops, DepthExpanded, Delta);
2686 NewDeps += exploreDirections(Level + 1, A, B, Bound,
2687 Loops, DepthExpanded, Delta);
2691 NewDeps += exploreDirections(Level + 1, A, B, Bound,
2692 Loops, DepthExpanded, Delta);
2698 return exploreDirections(Level + 1, A, B, Bound, Loops, DepthExpanded, Delta);
2703 bool DependenceInfo::testBounds(
unsigned char DirKind,
unsigned Level,
2704 BoundInfo *Bound,
const SCEV *Delta)
const {
2705 Bound[
Level].Direction = DirKind;
2706 if (
const SCEV *LowerBound = getLowerBound(Bound))
2709 if (
const SCEV *UpperBound = getUpperBound(Bound))
2731 void DependenceInfo::findBoundsALL(CoefficientInfo *A, CoefficientInfo *B,
2732 BoundInfo *Bound,
unsigned K)
const {
2735 if (Bound[K].Iterations) {
2737 SE->getMulExpr(SE->getMinusSCEV(A[K].NegPart, B[K].PosPart),
2738 Bound[K].Iterations);
2740 SE->getMulExpr(SE->getMinusSCEV(A[K].PosPart, B[K].NegPart),
2741 Bound[K].Iterations);
2747 SE->getZero(A[K].Coeff->getType());
2750 SE->getZero(A[K].Coeff->getType());
2770 void DependenceInfo::findBoundsEQ(CoefficientInfo *A, CoefficientInfo *B,
2771 BoundInfo *Bound,
unsigned K)
const {
2774 if (Bound[K].Iterations) {
2775 const SCEV *Delta = SE->getMinusSCEV(A[K].Coeff, B[K].Coeff);
2776 const SCEV *NegativePart = getNegativePart(Delta);
2778 SE->getMulExpr(NegativePart, Bound[K].Iterations);
2779 const SCEV *PositivePart = getPositivePart(Delta);
2781 SE->getMulExpr(PositivePart, Bound[K].Iterations);
2786 const SCEV *Delta = SE->getMinusSCEV(A[K].Coeff, B[K].Coeff);
2787 const SCEV *NegativePart = getNegativePart(Delta);
2788 if (NegativePart->
isZero())
2790 const SCEV *PositivePart = getPositivePart(Delta);
2791 if (PositivePart->
isZero())
2810 void DependenceInfo::findBoundsLT(CoefficientInfo *A, CoefficientInfo *B,
2811 BoundInfo *Bound,
unsigned K)
const {
2814 if (Bound[K].Iterations) {
2815 const SCEV *Iter_1 = SE->getMinusSCEV(
2816 Bound[K].Iterations, SE->getOne(Bound[K].Iterations->getType()));
2817 const SCEV *NegPart =
2818 getNegativePart(SE->getMinusSCEV(A[K].NegPart, B[K].Coeff));
2820 SE->getMinusSCEV(SE->getMulExpr(NegPart, Iter_1), B[K].Coeff);
2821 const SCEV *PosPart =
2822 getPositivePart(SE->getMinusSCEV(A[K].PosPart, B[K].Coeff));
2824 SE->getMinusSCEV(SE->getMulExpr(PosPart, Iter_1), B[K].Coeff);
2829 const SCEV *NegPart =
2830 getNegativePart(SE->getMinusSCEV(A[K].NegPart, B[K].Coeff));
2833 const SCEV *PosPart =
2834 getPositivePart(SE->getMinusSCEV(A[K].PosPart, B[K].Coeff));
2854 void DependenceInfo::findBoundsGT(CoefficientInfo *A, CoefficientInfo *B,
2855 BoundInfo *Bound,
unsigned K)
const {
2858 if (Bound[K].Iterations) {
2859 const SCEV *Iter_1 = SE->getMinusSCEV(
2860 Bound[K].Iterations, SE->getOne(Bound[K].Iterations->getType()));
2861 const SCEV *NegPart =
2862 getNegativePart(SE->getMinusSCEV(A[K].Coeff, B[K].PosPart));
2864 SE->getAddExpr(SE->getMulExpr(NegPart, Iter_1), A[K].Coeff);
2865 const SCEV *PosPart =
2866 getPositivePart(SE->getMinusSCEV(A[K].Coeff, B[K].NegPart));
2868 SE->getAddExpr(SE->getMulExpr(PosPart, Iter_1), A[K].Coeff);
2873 const SCEV *NegPart = getNegativePart(SE->getMinusSCEV(A[K].Coeff, B[K].PosPart));
2876 const SCEV *PosPart = getPositivePart(SE->getMinusSCEV(A[K].Coeff, B[K].NegPart));
2884 const SCEV *DependenceInfo::getPositivePart(
const SCEV *X)
const {
2885 return SE->getSMaxExpr(X, SE->getZero(X->
getType()));
2890 const SCEV *DependenceInfo::getNegativePart(
const SCEV *X)
const {
2891 return SE->getSMinExpr(X, SE->getZero(X->
getType()));
2898 DependenceInfo::CoefficientInfo *
2899 DependenceInfo::collectCoeffInfo(
const SCEV *Subscript,
bool SrcFlag,
2901 const SCEV *Zero = SE->getZero(Subscript->
getType());
2902 CoefficientInfo *CI =
new CoefficientInfo[MaxLevels + 1];
2903 for (
unsigned K = 1; K <= MaxLevels; ++K) {
2905 CI[K].PosPart = Zero;
2906 CI[K].NegPart = Zero;
2907 CI[K].Iterations =
nullptr;
2909 while (
const SCEVAddRecExpr *AddRec = dyn_cast<SCEVAddRecExpr>(Subscript)) {
2910 const Loop *L = AddRec->getLoop();
2911 unsigned K = SrcFlag ? mapSrcLoop(L) : mapDstLoop(L);
2912 CI[K].Coeff = AddRec->getStepRecurrence(*SE);
2913 CI[K].PosPart = getPositivePart(CI[K].Coeff);
2914 CI[K].NegPart = getNegativePart(CI[K].Coeff);
2915 CI[K].Iterations = collectUpperBound(L, Subscript->
getType());
2916 Subscript = AddRec->getStart();
2918 Constant = Subscript;
2921 for (
unsigned K = 1; K <= MaxLevels; ++K) {
2928 if (CI[K].Iterations)
2944 const SCEV *DependenceInfo::getLowerBound(BoundInfo *Bound)
const {
2945 const SCEV *Sum = Bound[1].Lower[Bound[1].Direction];
2946 for (
unsigned K = 2; Sum && K <= MaxLevels; ++K) {
2947 if (Bound[K].
Lower[Bound[K].Direction])
2948 Sum = SE->getAddExpr(Sum, Bound[K].
Lower[Bound[K].Direction]);
2960 const SCEV *DependenceInfo::getUpperBound(BoundInfo *Bound)
const {
2961 const SCEV *Sum = Bound[1].Upper[Bound[1].Direction];
2962 for (
unsigned K = 2; Sum && K <= MaxLevels; ++K) {
2963 if (Bound[K].
Upper[Bound[K].Direction])
2964 Sum = SE->getAddExpr(Sum, Bound[K].
Upper[Bound[K].Direction]);
2981 const SCEV *DependenceInfo::findCoefficient(
const SCEV *Expr,
2982 const Loop *TargetLoop)
const {
2985 return SE->getZero(Expr->
getType());
2986 if (AddRec->
getLoop() == TargetLoop)
2988 return findCoefficient(AddRec->
getStart(), TargetLoop);
2997 const SCEV *DependenceInfo::zeroCoefficient(
const SCEV *Expr,
2998 const Loop *TargetLoop)
const {
3002 if (AddRec->
getLoop() == TargetLoop)
3004 return SE->getAddRecExpr(zeroCoefficient(AddRec->
getStart(), TargetLoop),
3016 const SCEV *DependenceInfo::addToCoefficient(
const SCEV *Expr,
3017 const Loop *TargetLoop,
3021 return SE->getAddRecExpr(Expr,
3025 if (AddRec->
getLoop() == TargetLoop) {
3029 return SE->getAddRecExpr(AddRec->
getStart(),
3034 if (SE->isLoopInvariant(AddRec, TargetLoop))
3036 return SE->getAddRecExpr(
3037 addToCoefficient(AddRec->
getStart(), TargetLoop, Value),
3053 bool DependenceInfo::propagate(
const SCEV *&Src,
const SCEV *&Dst,
3057 bool Result =
false;
3058 for (
unsigned LI : Loops.
set_bits()) {
3061 if (Constraints[LI].isDistance())
3062 Result |= propagateDistance(Src, Dst, Constraints[LI], Consistent);
3063 else if (Constraints[LI].isLine())
3064 Result |= propagateLine(Src, Dst, Constraints[LI], Consistent);
3065 else if (Constraints[LI].isPoint())
3066 Result |= propagatePoint(Src, Dst, Constraints[LI]);
3077 bool DependenceInfo::propagateDistance(
const SCEV *&Src,
const SCEV *&Dst,
3078 Constraint &CurConstraint,
3080 const Loop *CurLoop = CurConstraint.getAssociatedLoop();
3082 const SCEV *A_K = findCoefficient(Src, CurLoop);
3085 const SCEV *DA_K = SE->getMulExpr(A_K, CurConstraint.getD());
3086 Src = SE->getMinusSCEV(Src, DA_K);
3087 Src = zeroCoefficient(Src, CurLoop);
3090 Dst = addToCoefficient(Dst, CurLoop, SE->getNegativeSCEV(A_K));
3092 if (!findCoefficient(Dst, CurLoop)->
isZero())
3103 bool DependenceInfo::propagateLine(
const SCEV *&Src,
const SCEV *&Dst,
3104 Constraint &CurConstraint,
3106 const Loop *CurLoop = CurConstraint.getAssociatedLoop();
3107 const SCEV *A = CurConstraint.getA();
3108 const SCEV *B = CurConstraint.getB();
3109 const SCEV *
C = CurConstraint.getC();
3110 LLVM_DEBUG(
dbgs() <<
"\t\tA = " << *A <<
", B = " << *B <<
", C = " << *C
3117 if (!Bconst || !Cconst)
return false;
3119 APInt Charlie = Cconst->getAPInt();
3121 assert(Charlie.
srem(Beta) == 0 &&
"C should be evenly divisible by B");
3122 const SCEV *AP_K = findCoefficient(Dst, CurLoop);
3124 Src = SE->getMinusSCEV(Src, SE->getMulExpr(AP_K, SE->getConstant(CdivB)));
3125 Dst = zeroCoefficient(Dst, CurLoop);
3126 if (!findCoefficient(Src, CurLoop)->
isZero())
3132 if (!Aconst || !Cconst)
return false;
3134 APInt Charlie = Cconst->getAPInt();
3136 assert(Charlie.
srem(Alpha) == 0 &&
"C should be evenly divisible by A");
3137 const SCEV *A_K = findCoefficient(Src, CurLoop);
3138 Src = SE->getAddExpr(Src, SE->getMulExpr(A_K, SE->getConstant(CdivA)));
3139 Src = zeroCoefficient(Src, CurLoop);
3140 if (!findCoefficient(Dst, CurLoop)->
isZero())
3146 if (!Aconst || !Cconst)
return false;
3148 APInt Charlie = Cconst->getAPInt();
3150 assert(Charlie.
srem(Alpha) == 0 &&
"C should be evenly divisible by A");
3151 const SCEV *A_K = findCoefficient(Src, CurLoop);
3152 Src = SE->getAddExpr(Src, SE->getMulExpr(A_K, SE->getConstant(CdivA)));
3153 Src = zeroCoefficient(Src, CurLoop);
3154 Dst = addToCoefficient(Dst, CurLoop, A_K);
3155 if (!findCoefficient(Dst, CurLoop)->
isZero())
3160 const SCEV *A_K = findCoefficient(Src, CurLoop);
3161 Src = SE->getMulExpr(Src, A);
3162 Dst = SE->getMulExpr(Dst, A);
3163 Src = SE->getAddExpr(Src, SE->getMulExpr(A_K, C));
3164 Src = zeroCoefficient(Src, CurLoop);
3165 Dst = addToCoefficient(Dst, CurLoop, SE->getMulExpr(A_K, B));
3166 if (!findCoefficient(Dst, CurLoop)->isZero())
3178 bool DependenceInfo::propagatePoint(
const SCEV *&Src,
const SCEV *&Dst,
3179 Constraint &CurConstraint) {
3180 const Loop *CurLoop = CurConstraint.getAssociatedLoop();
3181 const SCEV *A_K = findCoefficient(Src, CurLoop);
3182 const SCEV *AP_K = findCoefficient(Dst, CurLoop);
3183 const SCEV *XA_K = SE->getMulExpr(A_K, CurConstraint.getX());
3184 const SCEV *YAP_K = SE->getMulExpr(AP_K, CurConstraint.getY());
3186 Src = SE->getAddExpr(Src, SE->getMinusSCEV(XA_K, YAP_K));
3187 Src = zeroCoefficient(Src, CurLoop);
3190 Dst = zeroCoefficient(Dst, CurLoop);
3198 const Constraint &CurConstraint)
const {
3201 if (CurConstraint.isAny())
3203 else if (CurConstraint.isDistance()) {
3206 Level.
Distance = CurConstraint.getD();
3208 if (!SE->isKnownNonZero(Level.
Distance))
3210 if (!SE->isKnownNonPositive(Level.
Distance))
3212 if (!SE->isKnownNonNegative(Level.
Distance))
3216 else if (CurConstraint.isLine()) {
3221 else if (CurConstraint.isPoint()) {
3226 CurConstraint.getY(),
3227 CurConstraint.getX()))
3231 CurConstraint.getY(),
3232 CurConstraint.getX()))
3236 CurConstraint.getY(),
3237 CurConstraint.getX()))
3261 const SCEV *SrcAccessFn =
3262 SE->getSCEVAtScope(SrcPtr, SrcLoop);
3263 const SCEV *DstAccessFn =
3264 SE->getSCEVAtScope(DstPtr, DstLoop);
3271 if (!SrcBase || !DstBase || SrcBase != DstBase)
3274 const SCEV *ElementSize = SE->getElementSize(Src);
3275 if (ElementSize != SE->getElementSize(Dst))
3278 const SCEV *SrcSCEV = SE->getMinusSCEV(SrcAccessFn, SrcBase);
3279 const SCEV *DstSCEV = SE->getMinusSCEV(DstAccessFn, DstBase);
3283 if (!SrcAR || !DstAR || !SrcAR->
isAffine() || !DstAR->isAffine())
3288 SE->collectParametricTerms(SrcAR, Terms);
3289 SE->collectParametricTerms(DstAR, Terms);
3293 SE->findArrayDimensions(Terms, Sizes, ElementSize);
3297 SE->computeAccessFunctions(SrcAR, SrcSubscripts, Sizes);
3298 SE->computeAccessFunctions(DstAR, DstSubscripts, Sizes);
3301 if (SrcSubscripts.
size() < 2 || DstSubscripts.
size() < 2 ||
3302 SrcSubscripts.
size() != DstSubscripts.
size())
3313 for (
int i = 1; i <
size; ++i) {
3317 if (!isKnownLessThan(SrcSubscripts[i], Sizes[i - 1]))
3323 if (!isKnownLessThan(DstSubscripts[i], Sizes[i - 1]))
3328 dbgs() <<
"\nSrcSubscripts: ";
3329 for (
int i = 0; i <
size; i++)
3330 dbgs() << *SrcSubscripts[i];
3331 dbgs() <<
"\nDstSubscripts: ";
3332 for (
int i = 0; i <
size; i++)
3333 dbgs() << *DstSubscripts[i];
3341 for (
int i = 0; i <
size; ++i) {
3342 Pair[i].Src = SrcSubscripts[i];
3343 Pair[i].Dst = DstSubscripts[i];
3344 unifySubscriptType(&Pair[i]);
3376 std::unique_ptr<Dependence>
3378 bool PossiblyLoopIndependent) {
3380 PossiblyLoopIndependent =
false;
3389 LLVM_DEBUG(
dbgs() <<
"can only handle simple loads and stores\n");
3390 return make_unique<Dependence>(Src, Dst);
3405 return make_unique<Dependence>(Src, Dst);
3415 establishNestingLevels(Src, Dst);
3416 LLVM_DEBUG(
dbgs() <<
" common nesting levels = " << CommonLevels <<
"\n");
3417 LLVM_DEBUG(
dbgs() <<
" maximum nesting levels = " << MaxLevels <<
"\n");
3419 FullDependence Result(Src, Dst, PossiblyLoopIndependent, CommonLevels);
3424 const SCEV *SrcSCEV = SE->getSCEV(SrcPtr);
3425 const SCEV *DstSCEV = SE->getSCEV(DstPtr);
3428 Pair[0].Src = SrcSCEV;
3429 Pair[0].Dst = DstSCEV;
3432 if (tryDelinearize(Src, Dst, Pair)) {
3434 Pairs = Pair.
size();
3438 for (
unsigned P = 0;
P < Pairs; ++
P) {
3439 Pair[
P].Loops.
resize(MaxLevels + 1);
3440 Pair[
P].GroupLoops.
resize(MaxLevels + 1);
3442 removeMatchingExtensions(&Pair[
P]);
3443 Pair[
P].Classification =
3444 classifyPair(Pair[P].Src, LI->getLoopFor(Src->getParent()),
3445 Pair[P].Dst, LI->getLoopFor(Dst->getParent()),
3447 Pair[
P].GroupLoops = Pair[
P].Loops;
3448 Pair[
P].Group.set(P);
3452 LLVM_DEBUG(
dbgs() <<
"\tclass = " << Pair[P].Classification <<
"\n");
3517 for (
unsigned SI = 0;
SI < Pairs; ++
SI) {
3518 if (Pair[
SI].Classification == Subscript::NonLinear) {
3520 ++NonlinearSubscriptPairs;
3521 collectCommonLoops(Pair[
SI].Src,
3522 LI->getLoopFor(Src->getParent()),
3524 collectCommonLoops(Pair[
SI].Dst,
3525 LI->getLoopFor(Dst->getParent()),
3527 Result.Consistent =
false;
3528 }
else if (Pair[
SI].Classification == Subscript::ZIV) {
3535 for (
unsigned SJ =
SI + 1; SJ < Pairs; ++SJ) {
3537 Intersection &= Pair[SJ].GroupLoops;
3538 if (Intersection.
any()) {
3540 Pair[SJ].GroupLoops |= Pair[
SI].GroupLoops;
3542 Pair[SJ].Group |= Pair[
SI].Group;
3547 if (Pair[
SI].Group.count() == 1) {
3549 ++SeparableSubscriptPairs;
3553 ++CoupledSubscriptPairs;
3564 Constraint NewConstraint;
3565 NewConstraint.setAny(SE);
3570 switch (Pair[
SI].Classification) {
3571 case Subscript::ZIV:
3573 if (testZIV(Pair[
SI].Src, Pair[
SI].Dst, Result))
3576 case Subscript::SIV: {
3579 const SCEV *SplitIter =
nullptr;
3580 if (testSIV(Pair[
SI].Src, Pair[
SI].Dst, Level, Result, NewConstraint,
3585 case Subscript::RDIV:
3587 if (testRDIV(Pair[
SI].Src, Pair[
SI].Dst, Result))
3590 case Subscript::MIV:
3592 if (testMIV(Pair[
SI].Src, Pair[
SI].Dst, Pair[
SI].Loops, Result))
3600 if (Coupled.
count()) {
3603 LLVM_DEBUG(
dbgs() <<
"MaxLevels + 1 = " << MaxLevels + 1 <<
"\n");
3605 for (
unsigned II = 0; II <= MaxLevels; ++II)
3606 Constraints[II].setAny(SE);
3614 for (
unsigned SJ : Group.
set_bits()) {
3616 if (Pair[SJ].Classification == Subscript::SIV)
3622 unifySubscriptType(PairsInGroup);
3624 while (Sivs.
any()) {
3625 bool Changed =
false;
3626 for (
unsigned SJ : Sivs.
set_bits()) {
3630 const SCEV *SplitIter =
nullptr;
3632 if (testSIV(Pair[SJ].Src, Pair[SJ].Dst, Level, Result, NewConstraint,
3635 ConstrainedLevels.
set(Level);
3636 if (intersectConstraints(&Constraints[Level], &NewConstraint)) {
3637 if (Constraints[Level].isEmpty()) {
3638 ++DeltaIndependence;
3650 for (
unsigned SJ : Mivs.
set_bits()) {
3653 if (
propagate(Pair[SJ].Src, Pair[SJ].Dst, Pair[SJ].Loops,
3654 Constraints, Result.Consistent)) {
3656 ++DeltaPropagations;
3657 Pair[SJ].Classification =
3658 classifyPair(Pair[SJ].Src, LI->getLoopFor(Src->getParent()),
3659 Pair[SJ].Dst, LI->getLoopFor(Dst->getParent()),
3661 switch (Pair[SJ].Classification) {
3662 case Subscript::ZIV:
3664 if (testZIV(Pair[SJ].Src, Pair[SJ].Dst, Result))
3668 case Subscript::SIV:
3672 case Subscript::RDIV:
3673 case Subscript::MIV:
3684 for (
unsigned SJ : Mivs.
set_bits()) {
3685 if (Pair[SJ].Classification == Subscript::RDIV) {
3687 if (testRDIV(Pair[SJ].Src, Pair[SJ].Dst, Result))
3697 for (
unsigned SJ : Mivs.
set_bits()) {
3698 if (Pair[SJ].Classification == Subscript::MIV) {
3700 if (testMIV(Pair[SJ].Src, Pair[SJ].Dst, Pair[SJ].Loops, Result))
3709 for (
unsigned SJ : ConstrainedLevels.
set_bits()) {
3710 if (SJ > CommonLevels)
3712 updateDirection(Result.DV[SJ - 1], Constraints[SJ]);
3721 for (
unsigned SI = 0;
SI < Pairs; ++
SI)
3722 CompleteLoops |= Pair[
SI].Loops;
3723 for (
unsigned II = 1; II <= CommonLevels; ++II)
3724 if (CompleteLoops[II])
3725 Result.DV[II - 1].Scalar =
false;
3727 if (PossiblyLoopIndependent) {
3731 for (
unsigned II = 1; II <= CommonLevels; ++II) {
3733 Result.LoopIndependent =
false;
3741 bool AllEqual =
true;
3742 for (
unsigned II = 1; II <= CommonLevels; ++II) {
3752 return make_unique<FullDependence>(std::move(Result));
3805 unsigned SplitLevel) {
3807 "Dep should be splitable at SplitLevel");
3810 assert(Src->mayReadFromMemory() || Src->mayWriteToMemory());
3821 establishNestingLevels(Src, Dst);
3827 const SCEV *SrcSCEV = SE->getSCEV(SrcPtr);
3828 const SCEV *DstSCEV = SE->getSCEV(DstPtr);
3829 Pair[0].Src = SrcSCEV;
3830 Pair[0].Dst = DstSCEV;
3833 if (tryDelinearize(Src, Dst, Pair)) {
3835 Pairs = Pair.
size();
3839 for (
unsigned P = 0;
P < Pairs; ++
P) {
3840 Pair[
P].Loops.
resize(MaxLevels + 1);
3841 Pair[
P].GroupLoops.
resize(MaxLevels + 1);
3843 removeMatchingExtensions(&Pair[
P]);
3844 Pair[
P].Classification =
3845 classifyPair(Pair[P].Src, LI->getLoopFor(Src->getParent()),
3846 Pair[P].Dst, LI->getLoopFor(Dst->getParent()),
3848 Pair[
P].GroupLoops = Pair[
P].Loops;
3849 Pair[
P].Group.set(P);
3856 for (
unsigned SI = 0;
SI < Pairs; ++
SI) {
3857 if (Pair[
SI].Classification == Subscript::NonLinear) {
3859 collectCommonLoops(Pair[
SI].Src,
3860 LI->getLoopFor(Src->getParent()),
3862 collectCommonLoops(Pair[
SI].Dst,
3863 LI->getLoopFor(Dst->getParent()),
3865 Result.Consistent =
false;
3867 else if (Pair[
SI].Classification == Subscript::ZIV)
3872 for (
unsigned SJ =
SI + 1; SJ < Pairs; ++SJ) {
3874 Intersection &= Pair[SJ].GroupLoops;
3875 if (Intersection.
any()) {
3877 Pair[SJ].GroupLoops |= Pair[
SI].GroupLoops;
3879 Pair[SJ].Group |= Pair[
SI].Group;
3884 if (Pair[
SI].Group.count() == 1)
3892 Constraint NewConstraint;
3893 NewConstraint.setAny(SE);
3897 switch (Pair[
SI].Classification) {
3898 case Subscript::SIV: {
3900 const SCEV *SplitIter =
nullptr;
3901 (void) testSIV(Pair[
SI].Src, Pair[
SI].Dst, Level,
3902 Result, NewConstraint, SplitIter);
3903 if (Level == SplitLevel) {
3904 assert(SplitIter !=
nullptr);
3909 case Subscript::ZIV:
3910 case Subscript::RDIV:
3911 case Subscript::MIV:
3918 if (Coupled.
count()) {
3921 for (
unsigned II = 0; II <= MaxLevels; ++II)
3922 Constraints[II].setAny(SE);
3928 for (
unsigned SJ : Group.
set_bits()) {
3929 if (Pair[SJ].Classification == Subscript::SIV)
3934 while (Sivs.
any()) {
3935 bool Changed =
false;
3936 for (
unsigned SJ : Sivs.
set_bits()) {
3939 const SCEV *SplitIter =
nullptr;
3940 (void) testSIV(Pair[SJ].Src, Pair[SJ].Dst, Level,
3941 Result, NewConstraint, SplitIter);
3942 if (Level == SplitLevel && SplitIter)
3944 ConstrainedLevels.
set(Level);
3945 if (intersectConstraints(&Constraints[Level], &NewConstraint))
3951 for (
unsigned SJ : Mivs.
set_bits()) {
3953 if (
propagate(Pair[SJ].Src, Pair[SJ].Dst,
3954 Pair[SJ].Loops, Constraints, Result.Consistent)) {
3955 Pair[SJ].Classification =
3956 classifyPair(Pair[SJ].Src, LI->getLoopFor(Src->getParent()),
3957 Pair[SJ].Dst, LI->getLoopFor(Dst->getParent()),
3959 switch (Pair[SJ].Classification) {
3960 case Subscript::ZIV:
3963 case Subscript::SIV:
3967 case Subscript::RDIV:
3968 case Subscript::MIV:
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass...
APInt abs() const
Get the absolute value;.
void push_back(const T &Elt)
const SCEV * getDistance(unsigned Level) const override
getDistance - Returns the distance (or NULL) associated with a particular level.
A parsed version of the target data layout string in and methods for querying it. ...
FunctionPass * createDependenceAnalysisWrapperPass()
createDependenceAnalysisPass - This creates an instance of the DependenceAnalysis wrapper pass...
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
static bool isLoopInvariant(Value *V, const Loop *L, const DominatorTree *DT)
Perform a quick domtree based check for loop invariance assuming that V is used within the loop...
This is a 'bitvector' (really, a variable-sized bit array), optimized for the case when the array is ...
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Compute iterated dominance frontiers using a linear time algorithm.
const SCEV * getSplitIteration(const Dependence &Dep, unsigned Level)
getSplitIteration - Give a dependence that's splittable at some particular level, return the iteratio...
A Module instance is used to store all the information related to an LLVM module. ...
APInt sdiv(const APInt &RHS) const
Signed division function for APInt.
static cl::opt< bool > Delinearize("da-delinearize", cl::init(true), cl::Hidden, cl::ZeroOrMore, cl::desc("Try to delinearize array references."))
Legacy pass manager pass to access dependence information.
unsigned getLoopDepth() const
Return the nesting level of this loop.
The main scalar evolution driver.
bool slt(const APInt &RHS) const
Signed less than comparison.
bool isZero() const
Return true if the expression is a constant zero.
bool mayWriteToMemory() const
Return true if this instruction may modify memory.
The two locations do not alias at all.
static void sdivrem(const APInt &LHS, const APInt &RHS, APInt &Quotient, APInt &Remainder)
static void dumpSmallBitVector(SmallBitVector &BV)
bool sgt(const APInt &RHS) const
Signed greather than comparison.
static void dump(StringRef Title, SpillInfo const &Spills)
STATISTIC(NumFunctions, "Total number of functions")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
An instruction for reading from memory.
const SCEV * getOperand() const
static AliasResult underlyingObjectsAlias(AliasAnalysis *AA, const DataLayout &DL, const MemoryLocation &LocA, const MemoryLocation &LocB)
DependenceInfo - This class is the main dependence-analysis driver.
bool sle(const APInt &RHS) const
Signed less or equal comparison.
void dump(raw_ostream &OS) const
dump - For debugging purposes, dumps a dependence to OS.
APInt GreatestCommonDivisor(APInt A, APInt B)
Compute GCD of two unsigned APInt values.
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
This is the base class for unary cast operator classes.
unsigned getBitWidth() const
Return the number of bits in the APInt.
bool isConsistent() const override
isConsistent - Returns true if this dependence is consistent (occurs every time the source and destin...
static const SCEVConstant * getConstantPart(const SCEV *Expr)
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB)
The main low level interface to the alias analysis implementation.
#define INITIALIZE_PASS_DEPENDENCY(depName)
void getAnalysisUsage(AnalysisUsage &) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
inst_iterator inst_begin(Function *F)
const Loop * getLoop() const
bool isPeelLast(unsigned Level) const override
isPeelLast - Returns true if peeling the last iteration from this loop will break this dependence...
static AnalysisKey * ID()
Returns an opaque, unique ID for this analysis type.
virtual bool isScalar(unsigned Level) const
isScalar - Returns true if a particular level is scalar; that is, if no subscript in the source or de...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Analysis pass that exposes the LoopInfo for a function.
bool isFlow() const
isFlow - Returns true if this is a flow (aka true) dependence.
This node represents multiplication of some number of SCEVs.
const APInt & getAPInt() const
bool isIdentifiedObject(const Value *V)
Return true if this pointer refers to a distinct and identifiable object.
INITIALIZE_PASS_BEGIN(DependenceAnalysisWrapperPass, "da", "Dependence Analysis", true, true) INITIALIZE_PASS_END(DependenceAnalysisWrapperPass
This node represents a polynomial recurrence on the trip count of the specified loop.
iterator_range< const_set_bits_iterator > set_bits() const
Instruction * getSrc() const
getSrc - Returns the source instruction for this dependence.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
static APInt ceilingOfQuotient(const APInt &A, const APInt &B)
Value * getLoadStorePointerOperand(Value *V)
A helper function that returns the pointer operand of a load or store instruction.
An instruction for storing to memory.
unsigned getLevels() const override
getLevels - Returns the number of common loops surrounding the source and destination of the dependen...
bool isLoopIndependent() const override
isLoopIndependent - Returns true if this is a loop-independent dependence.
const SCEV * getStepRecurrence(ScalarEvolution &SE) const
Constructs and returns the recurrence indicating how much this expression steps by.
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
bool isOutput() const
isOutput - Returns true if this is an output dependence.
AliasResult
The possible results of an alias query.
unsigned getDirection(unsigned Level) const override
getDirection - Returns the direction associated with a particular level.
static MemoryLocation get(const LoadInst *LI)
Return a location with information about the memory reference by the given instruction.
This means that we are dealing with an entirely unknown SCEV value, and only represent it as its LLVM...
initializer< Ty > init(const Ty &Val)
std::unique_ptr< Dependence > depends(Instruction *Src, Instruction *Dst, bool PossiblyLoopIndependent)
depends - Tests for a dependence between the Src and Dst instructions.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
bool isKnownNonNegative(const Value *V, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Returns true if the give value is known to be non-negative.
This is an important base class in LLVM.
static bool isLoadOrStore(const Instruction *I)
A manager for alias analyses.
bool isConfused() const override
isConfused - Returns true if this dependence is confused (the compiler understands nothing and makes ...
bool isSplitable(unsigned Level) const override
isSplitable - Returns true if splitting the loop will break the dependence.
Represent the analysis usage information of a pass.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
FunctionPass class - This class is used to implement most global optimizations.
bool isAffine() const
Return true if this represents an expression A + B*x where A and B are loop invariant values...
bool isPeelFirst(unsigned Level) const override
isPeelFirst - Returns true if peeling the first iteration from this loop will break this dependence...
const SCEV * getStart() const
Class to represent integer types.
static APInt minAPInt(APInt A, APInt B)
Value * GetUnderlyingObject(Value *V, const DataLayout &DL, unsigned MaxLookup=6)
This method strips off any GEP address adjustments and pointer casts from the specified value...
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
The two locations may or may not alias. This is the least precise result.
const Value * Ptr
The address of the start of the location.
Representation for a specific memory location.
The two locations precisely alias each other.
static bool findGCD(unsigned Bits, const APInt &AM, const APInt &BM, const APInt &Delta, APInt &G, APInt &X, APInt &Y)
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
Type * getType() const
Return the LLVM type of this SCEV expression.
static void dumpExampleDependence(raw_ostream &OS, DependenceInfo *DA)
static APInt floorOfQuotient(const APInt &A, const APInt &B)
void print(raw_ostream &, const Module *=nullptr) const override
print - Print out the internal state of the pass.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
int find_next(unsigned Prev) const
Returns the index of the next set bit following the "Prev" bit.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Class for arbitrary precision integers.
This node represents an addition of some number of SCEVs.
FullDependence(Instruction *Src, Instruction *Dst, bool LoopIndependent, unsigned Levels)
void setPreservesAll()
Set by analyses that do not transform their input at all.
static void propagate(InstantiatedValue From, InstantiatedValue To, MatchState State, ReachabilitySet &ReachSet, std::vector< WorkListItem > &WorkList)
bool isScalar(unsigned Level) const override
isScalar - Returns true if a particular level is scalar; that is, if no subscript in the source or de...
Analysis pass that exposes the ScalarEvolution for a function.
Function * getFunction() const
bool isAnti() const
isAnti - Returns true if this is an anti dependence.
LoopT * getParentLoop() const
static bool isZero(Value *V, const DataLayout &DL, DominatorTree *DT, AssumptionCache *AC)
AAMDNodes AATags
The metadata nodes which describes the aliasing of the location (each member is null if that kind of ...
This class represents an analyzed expression in the program.
Represents a single loop in the control flow graph.
virtual bool isSplitable(unsigned Level) const
isSplitable - Returns true if splitting this loop will break the dependence.
APInt srem(const APInt &RHS) const
Function for signed remainder operation.
bool mayReadFromMemory() const
Return true if this instruction may read memory.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
FullDependence - This class represents a dependence between two memory references in a function...
static bool isRemainderZero(const SCEVConstant *Dividend, const SCEVConstant *Divisor)
AnalysisUsage & addRequiredTransitive()
Dependence::DVEntry - Each level in the distance/direction vector has a direction (or perhaps a union...
Instruction * getDst() const
getDst - Returns the destination instruction for this dependence.
static APInt maxAPInt(APInt A, APInt B)
bool isInput() const
isInput - Returns true if this is an input dependence.
Result run(Function &F, FunctionAnalysisManager &FAM)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static APInt getSignedMinValue(unsigned numBits)
Gets minimum signed value of APInt for a specific bit width.
bool isOne() const
Return true if the expression is a constant one.
LLVM Value Representation.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
bool any() const
Returns true if any bit is set.
This class implements an extremely fast bulk output stream that can only output to a stream...
The legacy pass manager's analysis pass to compute loop information.
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
inst_iterator inst_end(Function *F)
A container for analyses that lazily runs them and caches their results.
static APInt getNullValue(unsigned numBits)
Get the '0' value.
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object...
DependenceInfo & getDI() const
The two locations alias, but only due to a partial overlap.
Dependence - This class represents a dependence between two memory memory references in a function...
NoWrapFlags getNoWrapFlags(NoWrapFlags Mask=NoWrapMask) const
A special type used by analysis passes to provide an address that identifies that particular analysis...
size_type count() const
Returns the number of bits which are set.
const BasicBlock * getParent() const
This class represents a constant integer value.