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;
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) {
418 DEBUG(
dbgs() <<
"\tintersect constraints\n");
421 assert(!Y->isPoint() &&
"Y must not be a Point");
435 if (X->isDistance() && Y->isDistance()) {
436 DEBUG(
dbgs() <<
"\t intersect 2 distances\n");
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()) {
463 DEBUG(
dbgs() <<
"\t intersect 2 lines\n");
482 DEBUG(
dbgs() <<
"\t\tdifferent slopes\n");
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();
504 DEBUG(
dbgs() <<
"\t\tXtop = " << Xtop <<
"\n");
505 DEBUG(
dbgs() <<
"\t\tXbot = " << Xbot <<
"\n");
506 DEBUG(
dbgs() <<
"\t\tYtop = " << Ytop <<
"\n");
507 DEBUG(
dbgs() <<
"\t\tYbot = " << Ybot <<
"\n");
514 if (Xr != 0 || Yr != 0) {
519 DEBUG(
dbgs() <<
"\t\tX = " << Xq <<
", Y = " << Yq <<
"\n");
520 if (Xq.
slt(0) || Yq.
slt(0)) {
526 collectConstantUpperBound(X->getAssociatedLoop(), Prod1->
getType())) {
527 const APInt &UpperBound = CUB->getAPInt();
528 DEBUG(
dbgs() <<
"\t\tupper bound = " << UpperBound <<
"\n");
529 if (Xq.
sgt(UpperBound) || Yq.
sgt(UpperBound)) {
537 X->getAssociatedLoop());
545 assert(!(X->isLine() && Y->isPoint()) &&
"This case should never occur");
547 if (X->isPoint() && Y->isLine()) {
548 DEBUG(
dbgs() <<
"\t intersect Point and Line\n");
572 bool Splitable =
false;
588 for (
unsigned II = 1; II <= Levels; ++II) {
639 if (
const LoadInst *LI = dyn_cast<LoadInst>(I))
640 return LI->isUnordered();
641 else if (
const StoreInst *
SI = dyn_cast<StoreInst>(I))
642 return SI->isUnordered();
649 if (
LoadInst *LI = dyn_cast<LoadInst>(I))
650 return LI->getPointerOperand();
652 return SI->getPointerOperand();
708 void DependenceInfo::establishNestingLevels(
const Instruction *Src,
716 SrcLevels = SrcLevel;
717 MaxLevels = SrcLevel + DstLevel;
718 while (SrcLevel > DstLevel) {
722 while (DstLevel > SrcLevel) {
726 while (SrcLoop != DstLoop) {
731 CommonLevels = SrcLevel;
732 MaxLevels -= CommonLevels;
738 unsigned DependenceInfo::mapSrcLoop(
const Loop *SrcLoop)
const {
745 unsigned DependenceInfo::mapDstLoop(
const Loop *DstLoop)
const {
747 if (D > CommonLevels)
748 return D - CommonLevels + SrcLevels;
755 bool DependenceInfo::isLoopInvariant(
const SCEV *Expression,
756 const Loop *LoopNest)
const {
767 void DependenceInfo::collectCommonLoops(
const SCEV *Expression,
768 const Loop *LoopNest,
772 if (Level <= CommonLevels && !SE->isLoopInvariant(Expression, LoopNest))
780 unsigned widestWidthSeen = 0;
785 for (Subscript *Pair : Pairs) {
786 const SCEV *Src = Pair->Src;
787 const SCEV *Dst = Pair->Dst;
790 if (SrcTy ==
nullptr || DstTy ==
nullptr) {
791 assert(SrcTy == DstTy &&
"This function only unify integer types and "
792 "expect Src and Dst share the same type "
800 if (DstTy->getBitWidth() > widestWidthSeen) {
801 widestWidthSeen = DstTy->getBitWidth();
807 assert(widestWidthSeen > 0);
810 for (Subscript *Pair : Pairs) {
811 const SCEV *Src = Pair->Src;
812 const SCEV *Dst = Pair->Dst;
815 if (SrcTy ==
nullptr || DstTy ==
nullptr) {
816 assert(SrcTy == DstTy &&
"This function only unify integer types and "
817 "expect Src and Dst share the same type "
824 if (DstTy->getBitWidth() < widestWidthSeen) {
835 void DependenceInfo::removeMatchingExtensions(Subscript *Pair) {
836 const SCEV *Src = Pair->Src;
837 const SCEV *Dst = Pair->Dst;
838 if ((isa<SCEVZeroExtendExpr>(Src) && isa<SCEVZeroExtendExpr>(Dst)) ||
839 (isa<SCEVSignExtendExpr>(Src) && isa<SCEVSignExtendExpr>(Dst))) {
843 const SCEV *DstCastOp = DstCast->getOperand();
844 if (SrcCastOp->getType() == DstCastOp->
getType()) {
845 Pair->Src = SrcCastOp;
846 Pair->Dst = DstCastOp;
854 bool DependenceInfo::checkSrcSubscript(
const SCEV *Src,
const Loop *LoopNest,
858 return isLoopInvariant(Src, LoopNest);
862 if (!isa<SCEVCouldNotCompute>(UB)) {
869 if (!isLoopInvariant(Step, LoopNest))
872 return checkSrcSubscript(Start, LoopNest, Loops);
879 bool DependenceInfo::checkDstSubscript(
const SCEV *Dst,
const Loop *LoopNest,
883 return isLoopInvariant(Dst, LoopNest);
887 if (!isa<SCEVCouldNotCompute>(UB)) {
894 if (!isLoopInvariant(Step, LoopNest))
897 return checkDstSubscript(Start, LoopNest, Loops);
904 DependenceInfo::Subscript::ClassificationKind
905 DependenceInfo::classifyPair(
const SCEV *Src,
const Loop *SrcLoopNest,
906 const SCEV *Dst,
const Loop *DstLoopNest,
910 if (!checkSrcSubscript(Src, SrcLoopNest, SrcLoops))
911 return Subscript::NonLinear;
912 if (!checkDstSubscript(Dst, DstLoopNest, DstLoops))
913 return Subscript::NonLinear;
916 unsigned N = Loops.
count();
918 return Subscript::ZIV;
920 return Subscript::SIV;
921 if (N == 2 && (SrcLoops.count() == 0 ||
922 DstLoops.count() == 0 ||
923 (SrcLoops.count() == 1 && DstLoops.count() == 1)))
924 return Subscript::RDIV;
925 return Subscript::MIV;
940 const SCEV *Y)
const {
943 if ((isa<SCEVSignExtendExpr>(X) &&
944 isa<SCEVSignExtendExpr>(Y)) ||
945 (isa<SCEVZeroExtendExpr>(X) &&
946 isa<SCEVZeroExtendExpr>(Y))) {
950 const SCEV *Yop = CY->getOperand();
951 if (Xop->getType() == Yop->
getType()) {
991 const SCEV *DependenceInfo::collectUpperBound(
const Loop *
L,
Type *
T)
const {
1002 const SCEVConstant *DependenceInfo::collectConstantUpperBound(
const Loop *L,
1004 if (
const SCEV *UB = collectUpperBound(L, T))
1020 bool DependenceInfo::testZIV(
const SCEV *Src,
const SCEV *Dst,
1022 DEBUG(
dbgs() <<
" src = " << *Src <<
"\n");
1023 DEBUG(
dbgs() <<
" dst = " << *Dst <<
"\n");
1026 DEBUG(
dbgs() <<
" provably dependent\n");
1030 DEBUG(
dbgs() <<
" provably independent\n");
1034 DEBUG(
dbgs() <<
" possibly dependent\n");
1035 Result.Consistent =
false;
1067 bool DependenceInfo::strongSIVtest(
const SCEV *Coeff,
const SCEV *SrcConst,
1068 const SCEV *DstConst,
const Loop *CurLoop,
1070 Constraint &NewConstraint)
const {
1072 DEBUG(
dbgs() <<
"\t Coeff = " << *Coeff);
1074 DEBUG(
dbgs() <<
"\t SrcConst = " << *SrcConst);
1076 DEBUG(
dbgs() <<
"\t DstConst = " << *DstConst);
1078 ++StrongSIVapplications;
1079 assert(0 < Level && Level <= CommonLevels &&
"level out of range");
1083 DEBUG(
dbgs() <<
"\t Delta = " << *Delta);
1087 if (
const SCEV *UpperBound = collectUpperBound(CurLoop, Delta->
getType())) {
1088 DEBUG(
dbgs() <<
"\t UpperBound = " << *UpperBound);
1089 DEBUG(
dbgs() <<
", " << *UpperBound->getType() <<
"\n");
1090 const SCEV *AbsDelta =
1092 const SCEV *AbsCoeff =
1097 ++StrongSIVindependence;
1098 ++StrongSIVsuccesses;
1104 if (isa<SCEVConstant>(Delta) && isa<SCEVConstant>(Coeff)) {
1105 APInt ConstDelta = cast<SCEVConstant>(Delta)->getAPInt();
1106 APInt ConstCoeff = cast<SCEVConstant>(Coeff)->getAPInt();
1107 APInt Distance = ConstDelta;
1108 APInt Remainder = ConstDelta;
1110 DEBUG(
dbgs() <<
"\t Distance = " << Distance <<
"\n");
1111 DEBUG(
dbgs() <<
"\t Remainder = " << Remainder <<
"\n");
1113 if (Remainder != 0) {
1115 ++StrongSIVindependence;
1116 ++StrongSIVsuccesses;
1120 NewConstraint.setDistance(SE->
getConstant(Distance), CurLoop);
1121 if (Distance.
sgt(0))
1123 else if (Distance.
slt(0))
1127 ++StrongSIVsuccesses;
1129 else if (Delta->
isZero()) {
1131 Result.DV[
Level].Distance = Delta;
1132 NewConstraint.setDistance(Delta, CurLoop);
1134 ++StrongSIVsuccesses;
1137 if (Coeff->
isOne()) {
1138 DEBUG(
dbgs() <<
"\t Distance = " << *Delta <<
"\n");
1139 Result.DV[
Level].Distance = Delta;
1140 NewConstraint.setDistance(Delta, CurLoop);
1143 Result.Consistent =
false;
1144 NewConstraint.setLine(Coeff,
1159 if ((DeltaMaybePositive && CoeffMaybePositive) ||
1160 (DeltaMaybeNegative && CoeffMaybeNegative))
1164 if ((DeltaMaybeNegative && CoeffMaybePositive) ||
1165 (DeltaMaybePositive && CoeffMaybeNegative))
1167 if (NewDirection < Result.DV[Level].Direction)
1168 ++StrongSIVsuccesses;
1169 Result.DV[
Level].Direction &= NewDirection;
1203 bool DependenceInfo::weakCrossingSIVtest(
1204 const SCEV *Coeff,
const SCEV *SrcConst,
const SCEV *DstConst,
1206 Constraint &NewConstraint,
const SCEV *&SplitIter)
const {
1207 DEBUG(
dbgs() <<
"\tWeak-Crossing SIV test\n");
1208 DEBUG(
dbgs() <<
"\t Coeff = " << *Coeff <<
"\n");
1209 DEBUG(
dbgs() <<
"\t SrcConst = " << *SrcConst <<
"\n");
1210 DEBUG(
dbgs() <<
"\t DstConst = " << *DstConst <<
"\n");
1211 ++WeakCrossingSIVapplications;
1212 assert(0 < Level && Level <= CommonLevels &&
"Level out of range");
1214 Result.Consistent =
false;
1216 DEBUG(
dbgs() <<
"\t Delta = " << *Delta <<
"\n");
1217 NewConstraint.setLine(Coeff, Coeff, Delta, CurLoop);
1221 ++WeakCrossingSIVsuccesses;
1222 if (!Result.DV[Level].Direction) {
1223 ++WeakCrossingSIVindependence;
1226 Result.DV[
Level].Distance = Delta;
1233 Result.DV[
Level].Splitable =
true;
1237 "dynamic cast of negative of ConstCoeff should yield constant");
1246 DEBUG(
dbgs() <<
"\t Split iter = " << *SplitIter <<
"\n");
1254 DEBUG(
dbgs() <<
"\t Delta = " << *Delta <<
"\n");
1255 DEBUG(
dbgs() <<
"\t ConstCoeff = " << *ConstCoeff <<
"\n");
1258 ++WeakCrossingSIVindependence;
1259 ++WeakCrossingSIVsuccesses;
1265 if (
const SCEV *UpperBound = collectUpperBound(CurLoop, Delta->
getType())) {
1266 DEBUG(
dbgs() <<
"\t UpperBound = " << *UpperBound <<
"\n");
1270 DEBUG(
dbgs() <<
"\t ML = " << *ML <<
"\n");
1273 ++WeakCrossingSIVindependence;
1274 ++WeakCrossingSIVsuccesses;
1281 ++WeakCrossingSIVsuccesses;
1282 if (!Result.DV[Level].Direction) {
1283 ++WeakCrossingSIVindependence;
1286 Result.DV[
Level].Splitable =
false;
1295 APInt Distance = APDelta;
1296 APInt Remainder = APDelta;
1298 DEBUG(
dbgs() <<
"\t Remainder = " << Remainder <<
"\n");
1299 if (Remainder != 0) {
1301 ++WeakCrossingSIVindependence;
1302 ++WeakCrossingSIVsuccesses;
1305 DEBUG(
dbgs() <<
"\t Distance = " << Distance <<
"\n");
1309 Remainder = Distance.
srem(Two);
1310 DEBUG(
dbgs() <<
"\t Remainder = " << Remainder <<
"\n");
1311 if (Remainder != 0) {
1314 ++WeakCrossingSIVsuccesses;
1332 APInt A0(Bits, 1,
true), A1(Bits, 0,
true);
1333 APInt B0(Bits, 0,
true), B1(Bits, 1,
true);
1340 APInt A2 = A0 - Q*A1; A0 = A1; A1 = A2;
1341 APInt B2 = B0 - Q*B1; B0 = B1; B1 = B2;
1346 DEBUG(
dbgs() <<
"\t GCD = " << G <<
"\n");
1347 X = AM.
slt(0) ? -A1 : A1;
1348 Y = BM.
slt(0) ? B1 : -B1;
1366 if ((A.
sgt(0) && B.
sgt(0)) ||
1379 if ((A.
sgt(0) && B.
sgt(0)) ||
1389 return A.
sgt(B) ? A :
B;
1395 return A.
slt(B) ? A :
B;
1414 bool DependenceInfo::exactSIVtest(
const SCEV *SrcCoeff,
const SCEV *DstCoeff,
1415 const SCEV *SrcConst,
const SCEV *DstConst,
1416 const Loop *CurLoop,
unsigned Level,
1418 Constraint &NewConstraint)
const {
1420 DEBUG(
dbgs() <<
"\t SrcCoeff = " << *SrcCoeff <<
" = AM\n");
1421 DEBUG(
dbgs() <<
"\t DstCoeff = " << *DstCoeff <<
" = BM\n");
1422 DEBUG(
dbgs() <<
"\t SrcConst = " << *SrcConst <<
"\n");
1423 DEBUG(
dbgs() <<
"\t DstConst = " << *DstConst <<
"\n");
1424 ++ExactSIVapplications;
1425 assert(0 < Level && Level <= CommonLevels &&
"Level out of range");
1427 Result.Consistent =
false;
1429 DEBUG(
dbgs() <<
"\t Delta = " << *Delta <<
"\n");
1435 if (!ConstDelta || !ConstSrcCoeff || !ConstDstCoeff)
1440 APInt AM = ConstSrcCoeff->getAPInt();
1441 APInt BM = ConstDstCoeff->getAPInt();
1445 ++ExactSIVindependence;
1446 ++ExactSIVsuccesses;
1450 DEBUG(
dbgs() <<
"\t X = " << X <<
", Y = " << Y <<
"\n");
1453 APInt UM(Bits, 1,
true);
1454 bool UMvalid =
false;
1457 collectConstantUpperBound(CurLoop, Delta->
getType())) {
1458 UM = CUB->getAPInt();
1459 DEBUG(
dbgs() <<
"\t UM = " << UM <<
"\n");
1470 DEBUG(
dbgs() <<
"\t TL = " << TL <<
"\n");
1473 DEBUG(
dbgs() <<
"\t TU = " << TU <<
"\n");
1478 DEBUG(
dbgs() <<
"\t TU = " << TU <<
"\n");
1481 DEBUG(
dbgs() <<
"\t TL = " << TL <<
"\n");
1489 DEBUG(
dbgs() <<
"\t TL = " << TL <<
"\n");
1492 DEBUG(
dbgs() <<
"\t TU = " << TU <<
"\n");
1497 DEBUG(
dbgs() <<
"\t TU = " << TU <<
"\n");
1500 DEBUG(
dbgs() <<
"\t TL = " << TL <<
"\n");
1504 ++ExactSIVindependence;
1505 ++ExactSIVsuccesses;
1515 DEBUG(
dbgs() <<
"\t exploring LT direction\n");
1519 DEBUG(
dbgs() <<
"\t\t TL = " << TL <<
"\n");
1523 DEBUG(
dbgs() <<
"\t\t TU = " << TU <<
"\n");
1527 ++ExactSIVsuccesses;
1533 DEBUG(
dbgs() <<
"\t exploring EQ direction\n");
1536 DEBUG(
dbgs() <<
"\t\t TL = " << TL <<
"\n");
1540 DEBUG(
dbgs() <<
"\t\t TU = " << TU <<
"\n");
1545 DEBUG(
dbgs() <<
"\t\t TL = " << TL <<
"\n");
1549 DEBUG(
dbgs() <<
"\t\t TU = " << TU <<
"\n");
1553 ++ExactSIVsuccesses;
1559 DEBUG(
dbgs() <<
"\t exploring GT direction\n");
1562 DEBUG(
dbgs() <<
"\t\t TL = " << TL <<
"\n");
1566 DEBUG(
dbgs() <<
"\t\t TU = " << TU <<
"\n");
1570 ++ExactSIVsuccesses;
1574 Result.DV[
Level].Direction &= NewDirection;
1576 ++ExactSIVindependence;
1588 return ConstDividend.
srem(ConstDivisor) == 0;
1623 bool DependenceInfo::weakZeroSrcSIVtest(
const SCEV *DstCoeff,
1624 const SCEV *SrcConst,
1625 const SCEV *DstConst,
1626 const Loop *CurLoop,
unsigned Level,
1628 Constraint &NewConstraint)
const {
1632 DEBUG(
dbgs() <<
"\tWeak-Zero (src) SIV test\n");
1633 DEBUG(
dbgs() <<
"\t DstCoeff = " << *DstCoeff <<
"\n");
1634 DEBUG(
dbgs() <<
"\t SrcConst = " << *SrcConst <<
"\n");
1635 DEBUG(
dbgs() <<
"\t DstConst = " << *DstConst <<
"\n");
1636 ++WeakZeroSIVapplications;
1637 assert(0 < Level && Level <= MaxLevels &&
"Level out of range");
1639 Result.Consistent =
false;
1641 NewConstraint.setLine(SE->
getZero(Delta->
getType()), DstCoeff, Delta,
1643 DEBUG(
dbgs() <<
"\t Delta = " << *Delta <<
"\n");
1645 if (Level < CommonLevels) {
1647 Result.DV[
Level].PeelFirst =
true;
1648 ++WeakZeroSIVsuccesses;
1655 const SCEV *AbsCoeff =
1658 const SCEV *NewDelta =
1663 if (
const SCEV *UpperBound = collectUpperBound(CurLoop, Delta->
getType())) {
1664 DEBUG(
dbgs() <<
"\t UpperBound = " << *UpperBound <<
"\n");
1667 ++WeakZeroSIVindependence;
1668 ++WeakZeroSIVsuccesses;
1673 if (Level < CommonLevels) {
1675 Result.DV[
Level].PeelLast =
true;
1676 ++WeakZeroSIVsuccesses;
1686 ++WeakZeroSIVindependence;
1687 ++WeakZeroSIVsuccesses;
1692 if (isa<SCEVConstant>(Delta) &&
1694 ++WeakZeroSIVindependence;
1695 ++WeakZeroSIVsuccesses;
1733 bool DependenceInfo::weakZeroDstSIVtest(
const SCEV *SrcCoeff,
1734 const SCEV *SrcConst,
1735 const SCEV *DstConst,
1736 const Loop *CurLoop,
unsigned Level,
1738 Constraint &NewConstraint)
const {
1741 DEBUG(
dbgs() <<
"\tWeak-Zero (dst) SIV test\n");
1742 DEBUG(
dbgs() <<
"\t SrcCoeff = " << *SrcCoeff <<
"\n");
1743 DEBUG(
dbgs() <<
"\t SrcConst = " << *SrcConst <<
"\n");
1744 DEBUG(
dbgs() <<
"\t DstConst = " << *DstConst <<
"\n");
1745 ++WeakZeroSIVapplications;
1746 assert(0 < Level && Level <= SrcLevels &&
"Level out of range");
1748 Result.Consistent =
false;
1750 NewConstraint.setLine(SrcCoeff, SE->
getZero(Delta->
getType()), Delta,
1752 DEBUG(
dbgs() <<
"\t Delta = " << *Delta <<
"\n");
1754 if (Level < CommonLevels) {
1756 Result.DV[
Level].PeelFirst =
true;
1757 ++WeakZeroSIVsuccesses;
1764 const SCEV *AbsCoeff =
1767 const SCEV *NewDelta =
1772 if (
const SCEV *UpperBound = collectUpperBound(CurLoop, Delta->
getType())) {
1773 DEBUG(
dbgs() <<
"\t UpperBound = " << *UpperBound <<
"\n");
1776 ++WeakZeroSIVindependence;
1777 ++WeakZeroSIVsuccesses;
1782 if (Level < CommonLevels) {
1784 Result.DV[
Level].PeelLast =
true;
1785 ++WeakZeroSIVsuccesses;
1795 ++WeakZeroSIVindependence;
1796 ++WeakZeroSIVsuccesses;
1801 if (isa<SCEVConstant>(Delta) &&
1803 ++WeakZeroSIVindependence;
1804 ++WeakZeroSIVsuccesses;
1818 bool DependenceInfo::exactRDIVtest(
const SCEV *SrcCoeff,
const SCEV *DstCoeff,
1819 const SCEV *SrcConst,
const SCEV *DstConst,
1820 const Loop *SrcLoop,
const Loop *DstLoop,
1823 DEBUG(
dbgs() <<
"\t SrcCoeff = " << *SrcCoeff <<
" = AM\n");
1824 DEBUG(
dbgs() <<
"\t DstCoeff = " << *DstCoeff <<
" = BM\n");
1825 DEBUG(
dbgs() <<
"\t SrcConst = " << *SrcConst <<
"\n");
1826 DEBUG(
dbgs() <<
"\t DstConst = " << *DstConst <<
"\n");
1827 ++ExactRDIVapplications;
1828 Result.Consistent =
false;
1830 DEBUG(
dbgs() <<
"\t Delta = " << *Delta <<
"\n");
1834 if (!ConstDelta || !ConstSrcCoeff || !ConstDstCoeff)
1839 APInt AM = ConstSrcCoeff->getAPInt();
1840 APInt BM = ConstDstCoeff->getAPInt();
1844 ++ExactRDIVindependence;
1848 DEBUG(
dbgs() <<
"\t X = " << X <<
", Y = " << Y <<
"\n");
1851 APInt SrcUM(Bits, 1,
true);
1852 bool SrcUMvalid =
false;
1855 collectConstantUpperBound(SrcLoop, Delta->
getType())) {
1856 SrcUM = UpperBound->getAPInt();
1857 DEBUG(
dbgs() <<
"\t SrcUM = " << SrcUM <<
"\n");
1861 APInt DstUM(Bits, 1,
true);
1862 bool DstUMvalid =
false;
1865 collectConstantUpperBound(DstLoop, Delta->
getType())) {
1866 DstUM = UpperBound->getAPInt();
1867 DEBUG(
dbgs() <<
"\t DstUM = " << DstUM <<
"\n");
1878 DEBUG(
dbgs() <<
"\t TL = " << TL <<
"\n");
1881 DEBUG(
dbgs() <<
"\t TU = " << TU <<
"\n");
1886 DEBUG(
dbgs() <<
"\t TU = " << TU <<
"\n");
1889 DEBUG(
dbgs() <<
"\t TL = " << TL <<
"\n");
1897 DEBUG(
dbgs() <<
"\t TL = " << TL <<
"\n");
1900 DEBUG(
dbgs() <<
"\t TU = " << TU <<
"\n");
1905 DEBUG(
dbgs() <<
"\t TU = " << TU <<
"\n");
1908 DEBUG(
dbgs() <<
"\t TL = " << TL <<
"\n");
1912 ++ExactRDIVindependence;
1959 bool DependenceInfo::symbolicRDIVtest(
const SCEV *A1,
const SCEV *A2,
1962 const Loop *Loop2)
const {
1963 ++SymbolicRDIVapplications;
1964 DEBUG(
dbgs() <<
"\ttry symbolic RDIV test\n");
1967 DEBUG(
dbgs() <<
"\t A2 = " << *A2 <<
"\n");
1968 DEBUG(
dbgs() <<
"\t C1 = " << *C1 <<
"\n");
1969 DEBUG(
dbgs() <<
"\t C2 = " << *C2 <<
"\n");
1970 const SCEV *N1 = collectUpperBound(Loop1, A1->
getType());
1971 const SCEV *N2 = collectUpperBound(Loop2, A1->
getType());
1972 DEBUG(
if (N1)
dbgs() <<
"\t N1 = " << *N1 <<
"\n");
1973 DEBUG(
if (N2)
dbgs() <<
"\t N2 = " << *N2 <<
"\n");
1976 DEBUG(
dbgs() <<
"\t C2 - C1 = " << *C2_C1 <<
"\n");
1977 DEBUG(
dbgs() <<
"\t C1 - C2 = " << *C1_C2 <<
"\n");
1984 DEBUG(
dbgs() <<
"\t A1*N1 = " << *A1N1 <<
"\n");
1986 ++SymbolicRDIVindependence;
1993 DEBUG(
dbgs() <<
"\t A2*N2 = " << *A2N2 <<
"\n");
1995 ++SymbolicRDIVindependence;
2007 DEBUG(
dbgs() <<
"\t A1*N1 - A2*N2 = " << *A1N1_A2N2 <<
"\n");
2009 ++SymbolicRDIVindependence;
2015 ++SymbolicRDIVindependence;
2028 DEBUG(
dbgs() <<
"\t A1*N1 - A2*N2 = " << *A1N1_A2N2 <<
"\n");
2030 ++SymbolicRDIVindependence;
2036 ++SymbolicRDIVindependence;
2045 DEBUG(
dbgs() <<
"\t A1*N1 = " << *A1N1 <<
"\n");
2047 ++SymbolicRDIVindependence;
2054 DEBUG(
dbgs() <<
"\t A2*N2 = " << *A2N2 <<
"\n");
2056 ++SymbolicRDIVindependence;
2074 bool DependenceInfo::testSIV(
const SCEV *Src,
const SCEV *Dst,
unsigned &Level,
2076 const SCEV *&SplitIter)
const {
2077 DEBUG(
dbgs() <<
" src = " << *Src <<
"\n");
2078 DEBUG(
dbgs() <<
" dst = " << *Dst <<
"\n");
2081 if (SrcAddRec && DstAddRec) {
2083 const SCEV *DstConst = DstAddRec->getStart();
2085 const SCEV *DstCoeff = DstAddRec->getStepRecurrence(*SE);
2087 assert(CurLoop == DstAddRec->getLoop() &&
2088 "both loops in SIV should be same");
2089 Level = mapSrcLoop(CurLoop);
2091 if (SrcCoeff == DstCoeff)
2092 disproven = strongSIVtest(SrcCoeff, SrcConst, DstConst, CurLoop,
2093 Level, Result, NewConstraint);
2095 disproven = weakCrossingSIVtest(SrcCoeff, SrcConst, DstConst, CurLoop,
2096 Level, Result, NewConstraint, SplitIter);
2098 disproven = exactSIVtest(SrcCoeff, DstCoeff, SrcConst, DstConst, CurLoop,
2099 Level, Result, NewConstraint);
2101 gcdMIVtest(Src, Dst, Result) ||
2102 symbolicRDIVtest(SrcCoeff, DstCoeff, SrcConst, DstConst, CurLoop, CurLoop);
2107 const SCEV *DstConst = Dst;
2109 Level = mapSrcLoop(CurLoop);
2110 return weakZeroDstSIVtest(SrcCoeff, SrcConst, DstConst, CurLoop,
2111 Level, Result, NewConstraint) ||
2112 gcdMIVtest(Src, Dst, Result);
2115 const SCEV *DstConst = DstAddRec->getStart();
2116 const SCEV *DstCoeff = DstAddRec->getStepRecurrence(*SE);
2117 const SCEV *SrcConst = Src;
2118 const Loop *CurLoop = DstAddRec->getLoop();
2119 Level = mapDstLoop(CurLoop);
2120 return weakZeroSrcSIVtest(DstCoeff, SrcConst, DstConst,
2121 CurLoop, Level, Result, NewConstraint) ||
2122 gcdMIVtest(Src, Dst, Result);
2142 bool DependenceInfo::testRDIV(
const SCEV *Src,
const SCEV *Dst,
2150 const SCEV *SrcConst, *DstConst;
2151 const SCEV *SrcCoeff, *DstCoeff;
2152 const Loop *SrcLoop, *DstLoop;
2154 DEBUG(
dbgs() <<
" src = " << *Src <<
"\n");
2155 DEBUG(
dbgs() <<
" dst = " << *Dst <<
"\n");
2158 if (SrcAddRec && DstAddRec) {
2161 SrcLoop = SrcAddRec->
getLoop();
2162 DstConst = DstAddRec->getStart();
2163 DstCoeff = DstAddRec->getStepRecurrence(*SE);
2164 DstLoop = DstAddRec->getLoop();
2166 else if (SrcAddRec) {
2168 dyn_cast<SCEVAddRecExpr>(SrcAddRec->
getStart())) {
2169 SrcConst = tmpAddRec->getStart();
2170 SrcCoeff = tmpAddRec->getStepRecurrence(*SE);
2171 SrcLoop = tmpAddRec->getLoop();
2174 DstLoop = SrcAddRec->
getLoop();
2179 else if (DstAddRec) {
2181 dyn_cast<SCEVAddRecExpr>(DstAddRec->getStart())) {
2182 DstConst = tmpAddRec->getStart();
2183 DstCoeff = tmpAddRec->getStepRecurrence(*SE);
2184 DstLoop = tmpAddRec->getLoop();
2187 SrcLoop = DstAddRec->getLoop();
2194 return exactRDIVtest(SrcCoeff, DstCoeff,
2198 gcdMIVtest(Src, Dst, Result) ||
2199 symbolicRDIVtest(SrcCoeff, DstCoeff,
2208 bool DependenceInfo::testMIV(
const SCEV *Src,
const SCEV *Dst,
2211 DEBUG(
dbgs() <<
" src = " << *Src <<
"\n");
2212 DEBUG(
dbgs() <<
" dst = " << *Dst <<
"\n");
2213 Result.Consistent =
false;
2214 return gcdMIVtest(Src, Dst, Result) ||
2215 banerjeeMIVtest(Src, Dst, Loops, Result);
2223 if (
const auto *
Constant = dyn_cast<SCEVConstant>(Expr))
2225 else if (
const auto *Product = dyn_cast<SCEVMulExpr>(Expr))
2226 if (
const auto *
Constant = dyn_cast<SCEVConstant>(Product->getOperand(0)))
2250 bool DependenceInfo::gcdMIVtest(
const SCEV *Src,
const SCEV *Dst,
2261 const SCEV *Coefficients = Src;
2263 dyn_cast<SCEVAddRecExpr>(Coefficients)) {
2274 const SCEV *SrcConst = Coefficients;
2282 dyn_cast<SCEVAddRecExpr>(Coefficients)) {
2293 const SCEV *DstConst = Coefficients;
2297 DEBUG(
dbgs() <<
" Delta = " << *Delta <<
"\n");
2299 if (
const SCEVAddExpr *Sum = dyn_cast<SCEVAddExpr>(Delta)) {
2301 for (
unsigned Op = 0, Ops = Sum->getNumOperands();
Op < Ops;
Op++) {
2302 const SCEV *Operand = Sum->getOperand(
Op);
2303 if (isa<SCEVConstant>(Operand)) {
2304 assert(!Constant &&
"Surprised to find multiple constants");
2305 Constant = cast<SCEVConstant>(Operand);
2307 else if (
const SCEVMulExpr *Product = dyn_cast<SCEVMulExpr>(Operand)) {
2315 ConstOpValue.
abs());
2323 APInt ConstDelta = cast<SCEVConstant>(Constant)->getAPInt();
2324 DEBUG(
dbgs() <<
" ConstDelta = " << ConstDelta <<
"\n");
2325 if (ConstDelta == 0)
2328 DEBUG(
dbgs() <<
" RunningGCD = " << RunningGCD <<
"\n");
2329 APInt Remainder = ConstDelta.
srem(RunningGCD);
2330 if (Remainder != 0) {
2347 DEBUG(
dbgs() <<
" ExtraGCD = " << ExtraGCD <<
'\n');
2349 bool Improved =
false;
2352 dyn_cast<SCEVAddRecExpr>(Coefficients)) {
2355 RunningGCD = ExtraGCD;
2358 const SCEV *Inner = Src;
2359 while (RunningGCD != 1 && isa<SCEVAddRecExpr>(Inner)) {
2360 AddRec = cast<SCEVAddRecExpr>(Inner);
2362 if (CurLoop == AddRec->
getLoop())
2376 while (RunningGCD != 1 && isa<SCEVAddRecExpr>(Inner)) {
2377 AddRec = cast<SCEVAddRecExpr>(Inner);
2379 if (CurLoop == AddRec->
getLoop())
2402 DEBUG(
dbgs() <<
"\tRunningGCD = " << RunningGCD <<
"\n");
2403 if (RunningGCD != 0) {
2404 Remainder = ConstDelta.
srem(RunningGCD);
2405 DEBUG(
dbgs() <<
"\tRemainder = " << Remainder <<
"\n");
2406 if (Remainder != 0) {
2407 unsigned Level = mapSrcLoop(CurLoop);
2453 bool DependenceInfo::banerjeeMIVtest(
const SCEV *Src,
const SCEV *Dst,
2457 ++BanerjeeApplications;
2458 DEBUG(
dbgs() <<
" Src = " << *Src <<
'\n');
2460 CoefficientInfo *
A = collectCoeffInfo(Src,
true, A0);
2461 DEBUG(
dbgs() <<
" Dst = " << *Dst <<
'\n');
2463 CoefficientInfo *
B = collectCoeffInfo(Dst,
false, B0);
2464 BoundInfo *Bound =
new BoundInfo[MaxLevels + 1];
2466 DEBUG(
dbgs() <<
"\tDelta = " << *Delta <<
'\n');
2470 for (
unsigned K = 1; K <= MaxLevels; ++K) {
2471 Bound[K].Iterations = A[K].Iterations ? A[K].Iterations : B[K].Iterations;
2474 findBoundsALL(A, B, Bound, K);
2478 DEBUG(
dbgs() << *Bound[K].
Lower[Dependence::DVEntry::ALL] <<
'\t');
2481 if (Bound[K].
Upper[Dependence::DVEntry::ALL])
2482 DEBUG(
dbgs() << *Bound[K].
Upper[Dependence::DVEntry::ALL] <<
'\n');
2489 bool Disproved =
false;
2490 if (testBounds(Dependence::DVEntry::ALL, 0, Bound, Delta)) {
2492 unsigned DepthExpanded = 0;
2493 unsigned NewDeps = exploreDirections(1, A, B, Bound,
2494 Loops, DepthExpanded, Delta);
2496 bool Improved =
false;
2497 for (
unsigned K = 1; K <= CommonLevels; ++K) {
2499 unsigned Old = Result.DV[K - 1].Direction;
2500 Result.DV[K - 1].Direction = Old & Bound[K].DirSet;
2501 Improved |= Old != Result.DV[K - 1].Direction;
2502 if (!Result.DV[K - 1].Direction) {
2510 ++BanerjeeSuccesses;
2513 ++BanerjeeIndependence;
2518 ++BanerjeeIndependence;
2533 unsigned DependenceInfo::exploreDirections(
unsigned Level, CoefficientInfo *A,
2534 CoefficientInfo *B, BoundInfo *Bound,
2536 unsigned &DepthExpanded,
2537 const SCEV *Delta)
const {
2538 if (Level > CommonLevels) {
2541 for (
unsigned K = 1; K <= CommonLevels; ++K) {
2543 Bound[K].DirSet |= Bound[K].Direction;
2545 switch (Bound[K].Direction) {
2555 case Dependence::DVEntry::ALL:
2568 if (Level > DepthExpanded) {
2569 DepthExpanded =
Level;
2571 findBoundsLT(A, B, Bound, Level);
2572 findBoundsGT(A, B, Bound, Level);
2573 findBoundsEQ(A, B, Bound, Level);
2575 DEBUG(
dbgs() <<
"\tBound for level = " << Level <<
'\n');
2578 DEBUG(
dbgs() << *Bound[Level].
Lower[Dependence::DVEntry::LT] <<
'\t');
2581 if (Bound[Level].
Upper[Dependence::DVEntry::LT])
2582 DEBUG(
dbgs() << *Bound[Level].
Upper[Dependence::DVEntry::LT] <<
'\n');
2587 DEBUG(
dbgs() << *Bound[Level].
Lower[Dependence::DVEntry::EQ] <<
'\t');
2590 if (Bound[Level].
Upper[Dependence::DVEntry::EQ])
2591 DEBUG(
dbgs() << *Bound[Level].
Upper[Dependence::DVEntry::EQ] <<
'\n');
2596 DEBUG(
dbgs() << *Bound[Level].
Lower[Dependence::DVEntry::GT] <<
'\t');
2599 if (Bound[Level].
Upper[Dependence::DVEntry::GT])
2600 DEBUG(
dbgs() << *Bound[Level].
Upper[Dependence::DVEntry::GT] <<
'\n');
2606 unsigned NewDeps = 0;
2609 if (testBounds(Dependence::DVEntry::LT, Level, Bound, Delta))
2610 NewDeps += exploreDirections(Level + 1, A, B, Bound,
2611 Loops, DepthExpanded, Delta);
2614 if (testBounds(Dependence::DVEntry::EQ, Level, Bound, Delta))
2615 NewDeps += exploreDirections(Level + 1, A, B, Bound,
2616 Loops, DepthExpanded, Delta);
2619 if (testBounds(Dependence::DVEntry::GT, Level, Bound, Delta))
2620 NewDeps += exploreDirections(Level + 1, A, B, Bound,
2621 Loops, DepthExpanded, Delta);
2627 return exploreDirections(Level + 1, A, B, Bound, Loops, DepthExpanded, Delta);
2632 bool DependenceInfo::testBounds(
unsigned char DirKind,
unsigned Level,
2633 BoundInfo *Bound,
const SCEV *Delta)
const {
2634 Bound[
Level].Direction = DirKind;
2635 if (
const SCEV *LowerBound = getLowerBound(Bound))
2638 if (
const SCEV *UpperBound = getUpperBound(Bound))
2660 void DependenceInfo::findBoundsALL(CoefficientInfo *A, CoefficientInfo *B,
2661 BoundInfo *Bound,
unsigned K)
const {
2664 if (Bound[K].Iterations) {
2667 Bound[K].Iterations);
2670 Bound[K].Iterations);
2675 Bound[K].
Lower[Dependence::DVEntry::ALL] =
2676 SE->
getZero(A[K].Coeff->getType());
2678 Bound[K].
Upper[Dependence::DVEntry::ALL] =
2679 SE->
getZero(A[K].Coeff->getType());
2699 void DependenceInfo::findBoundsEQ(CoefficientInfo *A, CoefficientInfo *B,
2700 BoundInfo *Bound,
unsigned K)
const {
2703 if (Bound[K].Iterations) {
2705 const SCEV *NegativePart = getNegativePart(Delta);
2707 SE->
getMulExpr(NegativePart, Bound[K].Iterations);
2708 const SCEV *PositivePart = getPositivePart(Delta);
2710 SE->
getMulExpr(PositivePart, Bound[K].Iterations);
2716 const SCEV *NegativePart = getNegativePart(Delta);
2717 if (NegativePart->
isZero())
2718 Bound[K].
Lower[Dependence::DVEntry::EQ] = NegativePart;
2719 const SCEV *PositivePart = getPositivePart(Delta);
2720 if (PositivePart->
isZero())
2721 Bound[K].
Upper[Dependence::DVEntry::EQ] = PositivePart;
2739 void DependenceInfo::findBoundsLT(CoefficientInfo *A, CoefficientInfo *B,
2740 BoundInfo *Bound,
unsigned K)
const {
2743 if (Bound[K].Iterations) {
2745 Bound[K].Iterations, SE->
getOne(Bound[K].Iterations->getType()));
2746 const SCEV *NegPart =
2747 getNegativePart(SE->
getMinusSCEV(A[K].NegPart, B[K].Coeff));
2750 const SCEV *PosPart =
2751 getPositivePart(SE->
getMinusSCEV(A[K].PosPart, B[K].Coeff));
2758 const SCEV *NegPart =
2759 getNegativePart(SE->
getMinusSCEV(A[K].NegPart, B[K].Coeff));
2762 const SCEV *PosPart =
2763 getPositivePart(SE->
getMinusSCEV(A[K].PosPart, B[K].Coeff));
2783 void DependenceInfo::findBoundsGT(CoefficientInfo *A, CoefficientInfo *B,
2784 BoundInfo *Bound,
unsigned K)
const {
2787 if (Bound[K].Iterations) {
2789 Bound[K].Iterations, SE->
getOne(Bound[K].Iterations->getType()));
2790 const SCEV *NegPart =
2791 getNegativePart(SE->
getMinusSCEV(A[K].Coeff, B[K].PosPart));
2794 const SCEV *PosPart =
2795 getPositivePart(SE->
getMinusSCEV(A[K].Coeff, B[K].NegPart));
2802 const SCEV *NegPart = getNegativePart(SE->
getMinusSCEV(A[K].Coeff, B[K].PosPart));
2804 Bound[K].
Lower[Dependence::DVEntry::GT] = A[K].Coeff;
2805 const SCEV *PosPart = getPositivePart(SE->
getMinusSCEV(A[K].Coeff, B[K].NegPart));
2807 Bound[K].
Upper[Dependence::DVEntry::GT] = A[K].Coeff;
2813 const SCEV *DependenceInfo::getPositivePart(
const SCEV *X)
const {
2819 const SCEV *DependenceInfo::getNegativePart(
const SCEV *X)
const {
2827 DependenceInfo::CoefficientInfo *
2828 DependenceInfo::collectCoeffInfo(
const SCEV *Subscript,
bool SrcFlag,
2829 const SCEV *&Constant)
const {
2831 CoefficientInfo *CI =
new CoefficientInfo[MaxLevels + 1];
2832 for (
unsigned K = 1; K <= MaxLevels; ++K) {
2834 CI[K].PosPart =
Zero;
2835 CI[K].NegPart =
Zero;
2836 CI[K].Iterations =
nullptr;
2838 while (
const SCEVAddRecExpr *AddRec = dyn_cast<SCEVAddRecExpr>(Subscript)) {
2840 unsigned K = SrcFlag ? mapSrcLoop(L) : mapDstLoop(L);
2842 CI[K].PosPart = getPositivePart(CI[K].Coeff);
2843 CI[K].NegPart = getNegativePart(CI[K].Coeff);
2844 CI[K].Iterations = collectUpperBound(L, Subscript->
getType());
2847 Constant = Subscript;
2849 DEBUG(
dbgs() <<
"\tCoefficient Info\n");
2850 for (
unsigned K = 1; K <= MaxLevels; ++K) {
2851 DEBUG(
dbgs() <<
"\t " << K <<
"\t" << *CI[K].Coeff);
2857 if (CI[K].Iterations)
2863 DEBUG(
dbgs() <<
"\t Constant = " << *Subscript <<
'\n');
2873 const SCEV *DependenceInfo::getLowerBound(BoundInfo *Bound)
const {
2874 const SCEV *Sum = Bound[1].Lower[Bound[1].Direction];
2875 for (
unsigned K = 2; Sum && K <= MaxLevels; ++K) {
2876 if (Bound[K].
Lower[Bound[K].Direction])
2889 const SCEV *DependenceInfo::getUpperBound(BoundInfo *Bound)
const {
2890 const SCEV *Sum = Bound[1].Upper[Bound[1].Direction];
2891 for (
unsigned K = 2; Sum && K <= MaxLevels; ++K) {
2892 if (Bound[K].
Upper[Bound[K].Direction])
2910 const SCEV *DependenceInfo::findCoefficient(
const SCEV *Expr,
2911 const Loop *TargetLoop)
const {
2915 if (AddRec->
getLoop() == TargetLoop)
2917 return findCoefficient(AddRec->
getStart(), TargetLoop);
2926 const SCEV *DependenceInfo::zeroCoefficient(
const SCEV *Expr,
2927 const Loop *TargetLoop)
const {
2931 if (AddRec->
getLoop() == TargetLoop)
2945 const SCEV *DependenceInfo::addToCoefficient(
const SCEV *Expr,
2946 const Loop *TargetLoop,
2954 if (AddRec->
getLoop() == TargetLoop) {
2966 addToCoefficient(AddRec->
getStart(), TargetLoop, Value),
2982 bool DependenceInfo::propagate(
const SCEV *&Src,
const SCEV *&Dst,
2986 bool Result =
false;
2987 for (
unsigned LI : Loops.
set_bits()) {
2988 DEBUG(
dbgs() <<
"\t Constraint[" << LI <<
"] is");
2990 if (Constraints[LI].isDistance())
2991 Result |= propagateDistance(Src, Dst, Constraints[LI], Consistent);
2992 else if (Constraints[LI].isLine())
2993 Result |= propagateLine(Src, Dst, Constraints[LI], Consistent);
2994 else if (Constraints[LI].isPoint())
2995 Result |= propagatePoint(Src, Dst, Constraints[LI]);
3006 bool DependenceInfo::propagateDistance(
const SCEV *&Src,
const SCEV *&Dst,
3007 Constraint &CurConstraint,
3009 const Loop *CurLoop = CurConstraint.getAssociatedLoop();
3010 DEBUG(
dbgs() <<
"\t\tSrc is " << *Src <<
"\n");
3011 const SCEV *A_K = findCoefficient(Src, CurLoop);
3016 Src = zeroCoefficient(Src, CurLoop);
3017 DEBUG(
dbgs() <<
"\t\tnew Src is " << *Src <<
"\n");
3018 DEBUG(
dbgs() <<
"\t\tDst is " << *Dst <<
"\n");
3020 DEBUG(
dbgs() <<
"\t\tnew Dst is " << *Dst <<
"\n");
3021 if (!findCoefficient(Dst, CurLoop)->
isZero())
3032 bool DependenceInfo::propagateLine(
const SCEV *&Src,
const SCEV *&Dst,
3033 Constraint &CurConstraint,
3035 const Loop *CurLoop = CurConstraint.getAssociatedLoop();
3036 const SCEV *A = CurConstraint.getA();
3037 const SCEV *B = CurConstraint.getB();
3038 const SCEV *
C = CurConstraint.getC();
3039 DEBUG(
dbgs() <<
"\t\tA = " << *A <<
", B = " << *B <<
", C = " << *C <<
"\n");
3040 DEBUG(
dbgs() <<
"\t\tSrc = " << *Src <<
"\n");
3041 DEBUG(
dbgs() <<
"\t\tDst = " << *Dst <<
"\n");
3045 if (!Bconst || !Cconst)
return false;
3047 APInt Charlie = Cconst->getAPInt();
3049 assert(Charlie.
srem(Beta) == 0 &&
"C should be evenly divisible by B");
3050 const SCEV *AP_K = findCoefficient(Dst, CurLoop);
3053 Dst = zeroCoefficient(Dst, CurLoop);
3054 if (!findCoefficient(Src, CurLoop)->
isZero())
3060 if (!Aconst || !Cconst)
return false;
3062 APInt Charlie = Cconst->getAPInt();
3064 assert(Charlie.
srem(Alpha) == 0 &&
"C should be evenly divisible by A");
3065 const SCEV *A_K = findCoefficient(Src, CurLoop);
3067 Src = zeroCoefficient(Src, CurLoop);
3068 if (!findCoefficient(Dst, CurLoop)->
isZero())
3074 if (!Aconst || !Cconst)
return false;
3076 APInt Charlie = Cconst->getAPInt();
3078 assert(Charlie.
srem(Alpha) == 0 &&
"C should be evenly divisible by A");
3079 const SCEV *A_K = findCoefficient(Src, CurLoop);
3081 Src = zeroCoefficient(Src, CurLoop);
3082 Dst = addToCoefficient(Dst, CurLoop, A_K);
3083 if (!findCoefficient(Dst, CurLoop)->
isZero())
3088 const SCEV *A_K = findCoefficient(Src, CurLoop);
3092 Src = zeroCoefficient(Src, CurLoop);
3093 Dst = addToCoefficient(Dst, CurLoop, SE->
getMulExpr(A_K, B));
3094 if (!findCoefficient(Dst, CurLoop)->
isZero())
3097 DEBUG(
dbgs() <<
"\t\tnew Src = " << *Src <<
"\n");
3098 DEBUG(
dbgs() <<
"\t\tnew Dst = " << *Dst <<
"\n");
3106 bool DependenceInfo::propagatePoint(
const SCEV *&Src,
const SCEV *&Dst,
3107 Constraint &CurConstraint) {
3108 const Loop *CurLoop = CurConstraint.getAssociatedLoop();
3109 const SCEV *A_K = findCoefficient(Src, CurLoop);
3110 const SCEV *AP_K = findCoefficient(Dst, CurLoop);
3113 DEBUG(
dbgs() <<
"\t\tSrc is " << *Src <<
"\n");
3115 Src = zeroCoefficient(Src, CurLoop);
3116 DEBUG(
dbgs() <<
"\t\tnew Src is " << *Src <<
"\n");
3117 DEBUG(
dbgs() <<
"\t\tDst is " << *Dst <<
"\n");
3118 Dst = zeroCoefficient(Dst, CurLoop);
3119 DEBUG(
dbgs() <<
"\t\tnew Dst is " << *Dst <<
"\n");
3126 const Constraint &CurConstraint)
const {
3127 DEBUG(
dbgs() <<
"\tUpdate direction, constraint =");
3129 if (CurConstraint.isAny())
3131 else if (CurConstraint.isDistance()) {
3134 Level.
Distance = CurConstraint.getD();
3137 NewDirection = Dependence::DVEntry::EQ;
3139 NewDirection |= Dependence::DVEntry::LT;
3141 NewDirection |= Dependence::DVEntry::GT;
3144 else if (CurConstraint.isLine()) {
3149 else if (CurConstraint.isPoint()) {
3154 CurConstraint.getY(),
3155 CurConstraint.getX()))
3159 CurConstraint.getY(),
3160 CurConstraint.getX()))
3164 CurConstraint.getY(),
3165 CurConstraint.getX()))
3187 const SCEV *SrcAccessFn =
3189 const SCEV *DstAccessFn =
3197 if (!SrcBase || !DstBase || SrcBase != DstBase)
3209 if (!SrcAR || !DstAR || !SrcAR->
isAffine() || !DstAR->isAffine())
3227 if (SrcSubscripts.
size() < 2 || DstSubscripts.
size() < 2 ||
3228 SrcSubscripts.
size() != DstSubscripts.
size())
3231 int size = SrcSubscripts.
size();
3234 dbgs() <<
"\nSrcSubscripts: ";
3235 for (
int i = 0; i < size; i++)
3236 dbgs() << *SrcSubscripts[i];
3237 dbgs() <<
"\nDstSubscripts: ";
3238 for (
int i = 0; i < size; i++)
3239 dbgs() << *DstSubscripts[i];
3247 for (
int i = 0; i < size; ++i) {
3248 Pair[i].Src = SrcSubscripts[i];
3249 Pair[i].Dst = DstSubscripts[i];
3250 unifySubscriptType(&Pair[i]);
3289 std::unique_ptr<Dependence>
3291 bool PossiblyLoopIndependent) {
3293 PossiblyLoopIndependent =
false;
3302 DEBUG(
dbgs() <<
"can only handle simple loads and stores\n");
3303 return make_unique<Dependence>(Src, Dst);
3314 DEBUG(
dbgs() <<
"can't analyze may or partial alias\n");
3315 return make_unique<Dependence>(Src, Dst);
3325 establishNestingLevels(Src, Dst);
3326 DEBUG(
dbgs() <<
" common nesting levels = " << CommonLevels <<
"\n");
3327 DEBUG(
dbgs() <<
" maximum nesting levels = " << MaxLevels <<
"\n");
3329 FullDependence Result(Src, Dst, PossiblyLoopIndependent, CommonLevels);
3333 bool UsefulGEP =
false;
3336 if (SrcGEP && DstGEP &&
3339 const SCEV *DstPtrSCEV = SE->
getSCEV(DstGEP->getPointerOperand());
3340 DEBUG(
dbgs() <<
" SrcPtrSCEV = " << *SrcPtrSCEV <<
"\n");
3341 DEBUG(
dbgs() <<
" DstPtrSCEV = " << *DstPtrSCEV <<
"\n");
3355 DstIdx = DstGEP->idx_begin();
3357 ++SrcIdx, ++DstIdx, ++
P) {
3358 Pair[
P].Src = SE->
getSCEV(*SrcIdx);
3359 Pair[
P].Dst = SE->
getSCEV(*DstIdx);
3360 unifySubscriptType(&Pair[P]);
3367 DEBUG(
dbgs() <<
" SrcSCEV = " << *SrcSCEV <<
"\n");
3368 DEBUG(
dbgs() <<
" DstSCEV = " << *DstSCEV <<
"\n");
3369 Pair[0].Src = SrcSCEV;
3370 Pair[0].Dst = DstSCEV;
3374 if (tryDelinearize(Src, Dst, Pair)) {
3376 Pairs = Pair.
size();
3380 for (
unsigned P = 0;
P < Pairs; ++
P) {
3381 Pair[
P].Loops.
resize(MaxLevels + 1);
3382 Pair[
P].GroupLoops.
resize(MaxLevels + 1);
3384 removeMatchingExtensions(&Pair[
P]);
3385 Pair[
P].Classification =
3386 classifyPair(Pair[P].Src, LI->
getLoopFor(Src->getParent()),
3387 Pair[P].Dst, LI->
getLoopFor(Dst->getParent()),
3389 Pair[
P].GroupLoops = Pair[
P].Loops;
3390 Pair[
P].Group.set(P);
3391 DEBUG(
dbgs() <<
" subscript " << P <<
"\n");
3392 DEBUG(
dbgs() <<
"\tsrc = " << *Pair[P].Src <<
"\n");
3393 DEBUG(
dbgs() <<
"\tdst = " << *Pair[P].Dst <<
"\n");
3394 DEBUG(
dbgs() <<
"\tclass = " << Pair[P].Classification <<
"\n");
3459 for (
unsigned SI = 0;
SI < Pairs; ++
SI) {
3460 if (Pair[
SI].Classification == Subscript::NonLinear) {
3462 ++NonlinearSubscriptPairs;
3463 collectCommonLoops(Pair[
SI].Src,
3466 collectCommonLoops(Pair[
SI].Dst,
3469 Result.Consistent =
false;
3470 }
else if (Pair[
SI].Classification == Subscript::ZIV) {
3477 for (
unsigned SJ =
SI + 1; SJ < Pairs; ++SJ) {
3479 Intersection &= Pair[SJ].GroupLoops;
3480 if (Intersection.
any()) {
3482 Pair[SJ].GroupLoops |= Pair[
SI].GroupLoops;
3484 Pair[SJ].Group |= Pair[
SI].Group;
3489 if (Pair[
SI].Group.count() == 1) {
3491 ++SeparableSubscriptPairs;
3495 ++CoupledSubscriptPairs;
3506 Constraint NewConstraint;
3507 NewConstraint.setAny(SE);
3512 switch (Pair[
SI].Classification) {
3513 case Subscript::ZIV:
3515 if (testZIV(Pair[
SI].Src, Pair[
SI].Dst, Result))
3518 case Subscript::SIV: {
3521 const SCEV *SplitIter =
nullptr;
3522 if (testSIV(Pair[
SI].Src, Pair[
SI].Dst, Level, Result, NewConstraint,
3527 case Subscript::RDIV:
3529 if (testRDIV(Pair[
SI].Src, Pair[
SI].Dst, Result))
3532 case Subscript::MIV:
3534 if (testMIV(Pair[
SI].Src, Pair[
SI].Dst, Pair[
SI].Loops, Result))
3542 if (Coupled.
count()) {
3544 DEBUG(
dbgs() <<
"starting on coupled subscripts\n");
3545 DEBUG(
dbgs() <<
"MaxLevels + 1 = " << MaxLevels + 1 <<
"\n");
3547 for (
unsigned II = 0; II <= MaxLevels; ++II)
3548 Constraints[II].setAny(SE);
3550 DEBUG(
dbgs() <<
"testing subscript group " <<
SI <<
" { ");
3556 for (
unsigned SJ : Group.
set_bits()) {
3558 if (Pair[SJ].Classification == Subscript::SIV)
3564 unifySubscriptType(PairsInGroup);
3566 while (Sivs.
any()) {
3567 bool Changed =
false;
3568 for (
unsigned SJ : Sivs.
set_bits()) {
3569 DEBUG(
dbgs() <<
"testing subscript " << SJ <<
", SIV\n");
3572 const SCEV *SplitIter =
nullptr;
3574 if (testSIV(Pair[SJ].Src, Pair[SJ].Dst, Level, Result, NewConstraint,
3577 ConstrainedLevels.
set(Level);
3578 if (intersectConstraints(&Constraints[Level], &NewConstraint)) {
3579 if (Constraints[Level].isEmpty()) {
3580 ++DeltaIndependence;
3592 for (
unsigned SJ : Mivs.
set_bits()) {
3594 DEBUG(
dbgs() <<
"\tSJ = " << SJ <<
"\n");
3595 if (propagate(Pair[SJ].Src, Pair[SJ].Dst, Pair[SJ].Loops,
3596 Constraints, Result.Consistent)) {
3598 ++DeltaPropagations;
3599 Pair[SJ].Classification =
3600 classifyPair(Pair[SJ].Src, LI->
getLoopFor(Src->getParent()),
3601 Pair[SJ].Dst, LI->
getLoopFor(Dst->getParent()),
3603 switch (Pair[SJ].Classification) {
3604 case Subscript::ZIV:
3606 if (testZIV(Pair[SJ].Src, Pair[SJ].Dst, Result))
3610 case Subscript::SIV:
3614 case Subscript::RDIV:
3615 case Subscript::MIV:
3626 for (
unsigned SJ : Mivs.
set_bits()) {
3627 if (Pair[SJ].Classification == Subscript::RDIV) {
3629 if (testRDIV(Pair[SJ].Src, Pair[SJ].Dst, Result))
3639 for (
unsigned SJ : Mivs.
set_bits()) {
3640 if (Pair[SJ].Classification == Subscript::MIV) {
3642 if (testMIV(Pair[SJ].Src, Pair[SJ].Dst, Pair[SJ].Loops, Result))
3651 for (
unsigned SJ : ConstrainedLevels.
set_bits()) {
3652 if (SJ > CommonLevels)
3654 updateDirection(Result.DV[SJ - 1], Constraints[SJ]);
3663 for (
unsigned SI = 0;
SI < Pairs; ++
SI)
3664 CompleteLoops |= Pair[
SI].Loops;
3665 for (
unsigned II = 1; II <= CommonLevels; ++II)
3666 if (CompleteLoops[II])
3667 Result.DV[II - 1].Scalar =
false;
3669 if (PossiblyLoopIndependent) {
3673 for (
unsigned II = 1; II <= CommonLevels; ++II) {
3675 Result.LoopIndependent =
false;
3683 bool AllEqual =
true;
3684 for (
unsigned II = 1; II <= CommonLevels; ++II) {
3694 return make_unique<FullDependence>(std::move(Result));
3747 unsigned SplitLevel) {
3749 "Dep should be splitable at SplitLevel");
3752 assert(Src->mayReadFromMemory() || Src->mayWriteToMemory());
3762 establishNestingLevels(Src, Dst);
3767 bool UsefulGEP =
false;
3770 if (SrcGEP && DstGEP &&
3773 const SCEV *DstPtrSCEV = SE->
getSCEV(DstGEP->getPointerOperand());
3774 UsefulGEP = isLoopInvariant(SrcPtrSCEV, LI->
getLoopFor(Src->getParent())) &&
3784 DstIdx = DstGEP->idx_begin();
3786 ++SrcIdx, ++DstIdx, ++
P) {
3787 Pair[
P].Src = SE->
getSCEV(*SrcIdx);
3788 Pair[
P].Dst = SE->
getSCEV(*DstIdx);
3794 Pair[0].Src = SrcSCEV;
3795 Pair[0].Dst = DstSCEV;
3799 if (tryDelinearize(Src, Dst, Pair)) {
3801 Pairs = Pair.
size();
3805 for (
unsigned P = 0;
P < Pairs; ++
P) {
3806 Pair[
P].Loops.
resize(MaxLevels + 1);
3807 Pair[
P].GroupLoops.
resize(MaxLevels + 1);
3809 removeMatchingExtensions(&Pair[
P]);
3810 Pair[
P].Classification =
3811 classifyPair(Pair[P].Src, LI->
getLoopFor(Src->getParent()),
3812 Pair[P].Dst, LI->
getLoopFor(Dst->getParent()),
3814 Pair[
P].GroupLoops = Pair[
P].Loops;
3815 Pair[
P].Group.set(P);
3822 for (
unsigned SI = 0;
SI < Pairs; ++
SI) {
3823 if (Pair[
SI].Classification == Subscript::NonLinear) {
3825 collectCommonLoops(Pair[
SI].Src,
3828 collectCommonLoops(Pair[
SI].Dst,
3831 Result.Consistent =
false;
3833 else if (Pair[
SI].Classification == Subscript::ZIV)
3838 for (
unsigned SJ =
SI + 1; SJ < Pairs; ++SJ) {
3840 Intersection &= Pair[SJ].GroupLoops;
3841 if (Intersection.
any()) {
3843 Pair[SJ].GroupLoops |= Pair[
SI].GroupLoops;
3845 Pair[SJ].Group |= Pair[
SI].Group;
3850 if (Pair[
SI].Group.count() == 1)
3858 Constraint NewConstraint;
3859 NewConstraint.setAny(SE);
3863 switch (Pair[
SI].Classification) {
3864 case Subscript::SIV: {
3866 const SCEV *SplitIter =
nullptr;
3867 (void) testSIV(Pair[
SI].Src, Pair[
SI].Dst, Level,
3868 Result, NewConstraint, SplitIter);
3869 if (Level == SplitLevel) {
3870 assert(SplitIter !=
nullptr);
3875 case Subscript::ZIV:
3876 case Subscript::RDIV:
3877 case Subscript::MIV:
3884 if (Coupled.
count()) {
3887 for (
unsigned II = 0; II <= MaxLevels; ++II)
3888 Constraints[II].setAny(SE);
3894 for (
unsigned SJ : Group.
set_bits()) {
3895 if (Pair[SJ].Classification == Subscript::SIV)
3900 while (Sivs.
any()) {
3901 bool Changed =
false;
3902 for (
unsigned SJ : Sivs.
set_bits()) {
3905 const SCEV *SplitIter =
nullptr;
3906 (void) testSIV(Pair[SJ].Src, Pair[SJ].Dst, Level,
3907 Result, NewConstraint, SplitIter);
3908 if (Level == SplitLevel && SplitIter)
3910 ConstrainedLevels.
set(Level);
3911 if (intersectConstraints(&Constraints[Level], &NewConstraint))
3917 for (
unsigned SJ : Mivs.
set_bits()) {
3919 if (propagate(Pair[SJ].Src, Pair[SJ].Dst,
3920 Pair[SJ].Loops, Constraints, Result.Consistent)) {
3921 Pair[SJ].Classification =
3922 classifyPair(Pair[SJ].Src, LI->
getLoopFor(Src->getParent()),
3923 Pair[SJ].Dst, LI->
getLoopFor(Dst->getParent()),
3925 switch (Pair[SJ].Classification) {
3926 case Subscript::ZIV:
3929 case Subscript::SIV:
3933 case Subscript::RDIV:
3934 case Subscript::MIV:
NoWrapFlags getNoWrapFlags(NoWrapFlags Mask=NoWrapMask) const
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass...
The two locations precisely alias each other.
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...
unsigned getLoopDepth(const BlockT *BB) const
Return the loop nesting level of the specified block.
size_type count() const
Returns the number of bits which are set.
bool isAnti() const
isAnti - Returns true if this is an anti dependence.
virtual bool isConfused() const
isConfused - Returns true if this dependence is confused (the compiler understands nothing and makes ...
bool isOne() const
Return true if the expression is a constant one.
This is a 'bitvector' (really, a variable-sized bit array), optimized for the case when the array is ...
const SCEV * getConstant(ConstantInt *V)
STATISTIC(NumFunctions,"Total number of functions")
const SCEV * getSplitIteration(const Dependence &Dep, unsigned Level)
getSplitIteration - Give a dependence that's splittable at some particular level, return the iteratio...
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
A Module instance is used to store all the information related to an LLVM module. ...
virtual bool isPeelFirst(unsigned Level) const
isPeelFirst - Returns true if peeling the first iteration from this loop will break this dependence...
bool isZero() const
Return true if the expression is a constant zero.
Legacy pass manager pass to access dependence information.
unsigned getNumOperands() const
The two locations alias, but only due to a partial overlap.
const SCEV * getPointerBase(const SCEV *V)
Transitively follow the chain of pointer-type operands until reaching a SCEV that does not have a sin...
The main scalar evolution driver.
bool isKnownNonNegative(const SCEV *S)
Test if the given expression is known to be non-negative.
static void sdivrem(const APInt &LHS, const APInt &RHS, APInt &Quotient, APInt &Remainder)
const SCEV * getStepRecurrence(ScalarEvolution &SE) const
Constructs and returns the recurrence indicating how much this expression steps by.
static Value * getPointerOperand(Instruction *I)
static void dumpSmallBitVector(SmallBitVector &BV)
bool isLoopInvariant(const SCEV *S, const Loop *L)
Return true if the value of the given SCEV is unchanging in the specified loop.
static void dump(StringRef Title, SpillInfo const &Spills)
LoopT * getParentLoop() const
The two locations do not alias at all.
An instruction for reading from memory.
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
LoopT * getLoopFor(const BlockT *BB) const
Return the inner most loop that BB lives in.
DependenceInfo - This class is the main dependence-analysis driver.
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.
The two locations may or may not alias. This is the least precise result.
This is the base class for unary cast operator classes.
const SCEV * getStart() const
static const SCEVConstant * getConstantPart(const SCEV *Expr)
bool isKnownNonPositive(const SCEV *S)
Test if the given expression is known to be non-positive.
const SCEV * getZero(Type *Ty)
Return a SCEV for the constant 0 of a specific type.
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB)
The main low level interface to the alias analysis implementation.
Type * getPointerOperandType() const
Method to return the pointer operand as a PointerType.
#define INITIALIZE_PASS_DEPENDENCY(depName)
void computeAccessFunctions(const SCEV *Expr, SmallVectorImpl< const SCEV * > &Subscripts, SmallVectorImpl< const SCEV * > &Sizes)
Return in Subscripts the access functions for each dimension in Sizes (third step of delinearization)...
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)
bool isPeelLast(unsigned Level) const override
isPeelLast - Returns true if peeling the last iteration from this loop will break this dependence...
A Use represents the edge between a Value definition and its users.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs...ExtraArgs)
Get the result of an analysis pass for a given IR unit.
uint64_t getTypeSizeInBits(Type *Ty) const
Return the size in bits of the specified type, for which isSCEVable must return true.
virtual bool isSplitable(unsigned Level) const
isSplitable - Returns true if splitting this loop will break the dependence.
Analysis pass that exposes the LoopInfo for a function.
This node represents multiplication of some number of SCEVs.
bool isKnownPredicate(ICmpInst::Predicate Pred, const SCEV *LHS, const SCEV *RHS)
Test if the given expression is known to satisfy the condition described by Pred, LHS...
bool mayReadFromMemory() const
Return true if this instruction may read memory.
This node represents a polynomial recurrence on the trip count of the specified loop.
bool sgt(const APInt &RHS) const
Signed greather than comparison.
const SCEV * getMulExpr(SmallVectorImpl< const SCEV * > &Ops, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap, unsigned Depth=0)
Get a canonical multiply expression, or something simpler if possible.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
static cl::opt< bool > Delinearize("da-delinearize", cl::init(false), cl::Hidden, cl::ZeroOrMore, cl::desc("Try to delinearize array references."))
static APInt ceilingOfQuotient(const APInt &A, const APInt &B)
An instruction for storing to memory.
const SCEV * getAddRecExpr(const SCEV *Start, const SCEV *Step, const Loop *L, SCEV::NoWrapFlags Flags)
Get an add recurrence expression for the specified loop.
void findArrayDimensions(SmallVectorImpl< const SCEV * > &Terms, SmallVectorImpl< const SCEV * > &Sizes, const SCEV *ElementSize)
Compute the array dimensions Sizes from the set of Terms extracted from the memory access function of...
unsigned getDirection(unsigned Level) const override
getDirection - Returns the direction associated with a particular level.
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.
bool isAffine() const
Return true if this represents an expression A + B*x where A and B are loop invariant values...
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
const SCEV * getOne(Type *Ty)
Return a SCEV for the constant 1 of a specific type.
* 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...
Type * getType() const
Return the LLVM type of this SCEV expression.
This is an important base class in LLVM.
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...
static bool isLoadOrStore(const Instruction *I)
Function * getFunction() const
A manager for alias analyses.
bool isSplitable(unsigned Level) const override
isSplitable - Returns true if splitting the loop will break the dependence.
bool isFlow() const
isFlow - Returns true if this is a flow (aka true) dependence.
const SCEV * getSMaxExpr(const SCEV *LHS, const SCEV *RHS)
const SCEV * getSCEVAtScope(const SCEV *S, const Loop *L)
Return a SCEV expression for the specified value at the specified scope in the program.
AliasResult
The possible results of an alias query.
Represent the analysis usage information of a pass.
static AliasResult underlyingObjectsAlias(AliasAnalysis *AA, const DataLayout &DL, const Value *A, const Value *B)
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE,"Assign register bank of generic virtual registers", false, false) RegBankSelect
unsigned getBitWidth() const
Return the number of bits in the APInt.
int find_next(unsigned Prev) const
Returns the index of the next set bit following the "Prev" bit.
Value * getPointerOperand()
FunctionPass class - This class is used to implement most global optimizations.
APInt sdiv(const APInt &RHS) const
Signed division function for APInt.
bool isPeelFirst(unsigned Level) const override
isPeelFirst - Returns true if peeling the first iteration from this loop will break this dependence...
Class to represent integer types.
virtual const SCEV * getDistance(unsigned Level) const
getDistance - Returns the distance (or NULL) associated with a particular level.
bool isKnownNegative(const SCEV *S)
Test if the given expression is known to be negative.
const SCEV * getMinusSCEV(const SCEV *LHS, const SCEV *RHS, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap, unsigned Depth=0)
Return LHS-RHS. Minus is represented in SCEV as A+B*-1.
Instruction * getSrc() const
getSrc - Returns the source instruction for this dependence.
static APInt minAPInt(APInt A, APInt B)
const APInt & getAPInt() const
virtual unsigned getDirection(unsigned Level) const
getDirection - Returns the direction associated with a particular level.
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...
virtual bool isConsistent() const
isConsistent - Returns true if this dependence is consistent (occurs every time the source and destin...
bool mayWriteToMemory() const
Return true if this instruction may modify memory.
APInt srem(const APInt &RHS) const
Function for signed remainder operation.
const SCEV * getSMinExpr(const SCEV *LHS, const SCEV *RHS)
static bool findGCD(unsigned Bits, const APInt &AM, const APInt &BM, const APInt &Delta, APInt &G, APInt &X, APInt &Y)
bool isKnownPositive(const SCEV *S)
Test if the given expression is known to be positive.
static void dumpExampleDependence(raw_ostream &OS, DependenceInfo *DA)
iterator_range< const_set_bits_iterator > set_bits() const
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.
Type * getType() const
All values are typed, get the type of this value.
virtual unsigned getLevels() const
getLevels - Returns the number of common loops surrounding the source and destination of the dependen...
virtual bool isPeelLast(unsigned Level) const
isPeelLast - Returns true if peeling the last iteration from this loop will break this dependence...
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.
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...
llvm_unreachable("Unknown RegBank!")
Analysis pass that exposes the ScalarEvolution for a function.
static bool isZero(Value *V, const DataLayout &DL, DominatorTree *DT, AssumptionCache *AC)
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
void collectParametricTerms(const SCEV *Expr, SmallVectorImpl< const SCEV * > &Terms)
Collect parametric terms occurring in step expressions (first step of delinearization).
INITIALIZE_PASS_BEGIN(DependenceAnalysisWrapperPass,"da","Dependence Analysis", true, true) INITIALIZE_PASS_END(DependenceAnalysisWrapperPass
This class represents an analyzed expression in the program.
Represents a single loop in the control flow graph.
virtual bool isLoopIndependent() const
isLoopIndependent - Returns true if this is a loop-independent dependence.
Instruction * getDst() const
getDst - Returns the destination instruction for this dependence.
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
void dump(raw_ostream &OS) const
dump - For debugging purposes, dumps a dependence to OS.
bool isKnownNonZero(const SCEV *S)
Test if the given expression is known to be non-zero.
DependenceInfo & getDI() const
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()
const Loop * getLoop() const
Dependence::DVEntry - Each level in the distance/direction vector has a direction (or perhaps a union...
uint64_t getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type...
static APInt maxAPInt(APInt A, APInt B)
bool isInput() const
isInput - Returns true if this is an input dependence.
const SCEV * getBackedgeTakenCount(const Loop *L)
If the specified loop has a predictable backedge-taken count, return it, otherwise return a SCEVCould...
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.
const SCEV * getNegativeSCEV(const SCEV *V, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap)
Return the SCEV object corresponding to -V.
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
bool any() const
Returns true if any bit is set.
const SCEV * getSCEV(Value *V)
Return a SCEV expression for the full generality of the specified expression.
This class implements an extremely fast bulk output stream that can only output to a stream...
const SCEV * getUDivExpr(const SCEV *LHS, const SCEV *RHS)
Get a canonical unsigned division expression, or something simpler if possible.
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.
bool isOutput() const
isOutput - Returns true if this is an output dependence.
const SCEV * getTruncateOrZeroExtend(const SCEV *V, Type *Ty)
Return a SCEV corresponding to a conversion of the input value to the specified type.
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml","ocaml 3.10-compatible collector")
const SCEV * getAddExpr(SmallVectorImpl< const SCEV * > &Ops, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap, unsigned Depth=0)
Get a canonical add expression, or something simpler if possible.
const SCEV * getElementSize(Instruction *Inst)
Return the size of an element read or written by Inst.
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...
APInt abs() const
Get the absolute value;.
Dependence - This class represents a dependence between two memory memory references in a function...
const SCEV * getOperand() const
unsigned getLoopDepth() const
Return the nesting level of this loop.
bool hasLoopInvariantBackedgeTakenCount(const Loop *L)
Return true if the specified loop has an analyzable loop-invariant backedge-taken count...
A special type used by analysis passes to provide an address that identifies that particular analysis...
const BasicBlock * getParent() const
const SCEV * getSignExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth=0)
This class represents a constant integer value.
bool slt(const APInt &RHS) const
Signed less than comparison.