60 #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."));
117 "Disable checks that try to statically verify validity of " 118 "delinearized subscripts. Enabling this option may result in incorrect " 119 "dependence vectors for languages that allow the subscript of one " 120 "dimension to underflow or overflow into another dimension."));
136 "Dependence Analysis",
true,
true)
143 char DependenceAnalysisWrapperPass::
ID = 0;
145 DependenceAnalysisWrapperPass::DependenceAnalysisWrapperPass()
155 auto &AA = getAnalysis<AAResultsWrapperPass>().getAAResults();
156 auto &SE = getAnalysis<ScalarEvolutionWrapperPass>().getSE();
157 auto &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
181 if (SrcI->mayReadOrWriteMemory()) {
183 DstI != DstE; ++DstI) {
184 if (DstI->mayReadOrWriteMemory()) {
185 OS <<
"Src:" << *SrcI <<
" --> Dst:" << *DstI <<
"\n";
186 OS <<
" da analyze - ";
187 if (
auto D = DA->
depends(&*SrcI, &*DstI,
true)) {
190 if (
D->isSplitable(
Level)) {
191 OS <<
" da analyze - split level = " <<
Level;
212 OS <<
"'Dependence Analysis' for function '" << F.
getName() <<
"':\n";
222 return Src->mayReadFromMemory() && Dst->mayReadFromMemory();
228 return Src->mayWriteToMemory() && Dst->mayWriteToMemory();
234 return Src->mayWriteToMemory() && Dst->mayReadFromMemory();
240 return Src->mayReadFromMemory() && Dst->mayWriteToMemory();
257 bool PossiblyLoopIndependent,
258 unsigned CommonLevels)
259 :
Dependence(Source, Destination), Levels(CommonLevels),
260 LoopIndependent(PossiblyLoopIndependent) {
263 DV = std::make_unique<DVEntry[]>(CommonLevels);
270 assert(0 < Level && Level <= Levels &&
"Level out of range");
271 return DV[Level - 1].Direction;
277 assert(0 < Level && Level <= Levels &&
"Level out of range");
278 return DV[Level - 1].Distance;
286 assert(0 < Level && Level <= Levels &&
"Level out of range");
287 return DV[Level - 1].Scalar;
294 assert(0 < Level && Level <= Levels &&
"Level out of range");
295 return DV[Level - 1].PeelFirst;
302 assert(0 < Level && Level <= Levels &&
"Level out of range");
303 return DV[Level - 1].PeelLast;
309 assert(0 < Level && Level <= Levels &&
"Level out of range");
310 return DV[Level - 1].Splitable;
319 const SCEV *DependenceInfo::Constraint::getX()
const {
320 assert(
Kind == Point &&
"Kind should be Point");
327 const SCEV *DependenceInfo::Constraint::getY()
const {
328 assert(
Kind == Point &&
"Kind should be Point");
335 const SCEV *DependenceInfo::Constraint::getA()
const {
337 "Kind should be Line (or Distance)");
344 const SCEV *DependenceInfo::Constraint::getB()
const {
346 "Kind should be Line (or Distance)");
353 const SCEV *DependenceInfo::Constraint::getC()
const {
355 "Kind should be Line (or Distance)");
362 const SCEV *DependenceInfo::Constraint::getD()
const {
363 assert(
Kind == Distance &&
"Kind should be Distance");
364 return SE->getNegativeSCEV(
C);
369 const Loop *DependenceInfo::Constraint::getAssociatedLoop()
const {
371 "Kind should be Distance, Line, or Point");
372 return AssociatedLoop;
375 void DependenceInfo::Constraint::setPoint(
const SCEV *
X,
const SCEV *
Y,
376 const Loop *CurLoop) {
380 AssociatedLoop = CurLoop;
383 void DependenceInfo::Constraint::setLine(
const SCEV *AA,
const SCEV *BB,
384 const SCEV *CC,
const Loop *CurLoop) {
389 AssociatedLoop = CurLoop;
392 void DependenceInfo::Constraint::setDistance(
const SCEV *
D,
393 const Loop *CurLoop) {
396 B = SE->getNegativeSCEV(A);
397 C = SE->getNegativeSCEV(D);
398 AssociatedLoop = CurLoop;
401 void DependenceInfo::Constraint::setEmpty() {
Kind =
Empty; }
408 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 416 OS <<
" Point is <" << *getX() <<
", " << *getY() <<
">\n";
417 else if (isDistance())
418 OS <<
" Distance is " << *getD() <<
419 " (" << *getA() <<
"*X + " << *getB() <<
"*Y = " << *getC() <<
")\n";
421 OS <<
" Line is " << *getA() <<
"*X + " <<
422 *getB() <<
"*Y = " << *getC() <<
"\n";
436 bool DependenceInfo::intersectConstraints(Constraint *X,
const Constraint *Y) {
441 assert(!Y->isPoint() &&
"Y must not be a Point");
455 if (X->isDistance() && Y->isDistance()) {
466 if (isa<SCEVConstant>(Y->getD())) {
479 assert(!(X->isPoint() && Y->isPoint()) &&
480 "We shouldn't ever see X->isPoint() && Y->isPoint()");
482 if (X->isLine() && Y->isLine()) {
484 const SCEV *Prod1 = SE->getMulExpr(X->getA(), Y->getB());
485 const SCEV *Prod2 = SE->getMulExpr(X->getB(), Y->getA());
489 Prod1 = SE->getMulExpr(X->getC(), Y->getB());
490 Prod2 = SE->getMulExpr(X->getB(), Y->getC());
503 const SCEV *C1B2 = SE->getMulExpr(X->getC(), Y->getB());
504 const SCEV *C1A2 = SE->getMulExpr(X->getC(), Y->getA());
505 const SCEV *C2B1 = SE->getMulExpr(Y->getC(), X->getB());
506 const SCEV *C2A1 = SE->getMulExpr(Y->getC(), X->getA());
507 const SCEV *A1B2 = SE->getMulExpr(X->getA(), Y->getB());
508 const SCEV *A2B1 = SE->getMulExpr(Y->getA(), X->getB());
517 if (!C1B2_C2B1 || !C1A2_C2A1 ||
518 !A1B2_A2B1 || !A2B1_A1B2)
520 APInt Xtop = C1B2_C2B1->getAPInt();
521 APInt Xbot = A1B2_A2B1->getAPInt();
523 APInt Ybot = A2B1_A1B2->getAPInt();
534 if (Xr != 0 || Yr != 0) {
540 if (Xq.
slt(0) || Yq.
slt(0)) {
546 collectConstantUpperBound(X->getAssociatedLoop(), Prod1->
getType())) {
547 const APInt &UpperBound = CUB->getAPInt();
549 if (Xq.
sgt(UpperBound) || Yq.
sgt(UpperBound)) {
555 X->setPoint(SE->getConstant(Xq),
557 X->getAssociatedLoop());
565 assert(!(X->isLine() && Y->isPoint()) &&
"This case should never occur");
567 if (X->isPoint() && Y->isLine()) {
569 const SCEV *A1X1 = SE->getMulExpr(Y->getA(), X->getX());
570 const SCEV *B1Y1 = SE->getMulExpr(Y->getB(), X->getY());
571 const SCEV *Sum = SE->getAddExpr(A1X1, B1Y1);
592 bool Splitable =
false;
608 for (
unsigned II = 1; II <= Levels; ++II) {
684 if (
const LoadInst *LI = dyn_cast<LoadInst>(I))
685 return LI->isUnordered();
686 else if (
const StoreInst *
SI = dyn_cast<StoreInst>(I))
687 return SI->isUnordered();
742 void DependenceInfo::establishNestingLevels(
const Instruction *Src,
746 unsigned SrcLevel = LI->getLoopDepth(SrcBlock);
747 unsigned DstLevel = LI->getLoopDepth(DstBlock);
748 const Loop *SrcLoop = LI->getLoopFor(SrcBlock);
749 const Loop *DstLoop = LI->getLoopFor(DstBlock);
750 SrcLevels = SrcLevel;
751 MaxLevels = SrcLevel + DstLevel;
752 while (SrcLevel > DstLevel) {
756 while (DstLevel > SrcLevel) {
760 while (SrcLoop != DstLoop) {
765 CommonLevels = SrcLevel;
766 MaxLevels -= CommonLevels;
772 unsigned DependenceInfo::mapSrcLoop(
const Loop *SrcLoop)
const {
779 unsigned DependenceInfo::mapDstLoop(
const Loop *DstLoop)
const {
781 if (D > CommonLevels)
782 return D - CommonLevels + SrcLevels;
789 bool DependenceInfo::isLoopInvariant(
const SCEV *Expression,
790 const Loop *LoopNest)
const {
793 return SE->isLoopInvariant(Expression, LoopNest) &&
801 void DependenceInfo::collectCommonLoops(
const SCEV *Expression,
802 const Loop *LoopNest,
806 if (Level <= CommonLevels && !SE->isLoopInvariant(Expression, LoopNest))
814 unsigned widestWidthSeen = 0;
819 for (Subscript *Pair : Pairs) {
820 const SCEV *Src = Pair->Src;
821 const SCEV *Dst = Pair->Dst;
824 if (SrcTy ==
nullptr || DstTy ==
nullptr) {
825 assert(SrcTy == DstTy &&
"This function only unify integer types and " 826 "expect Src and Dst share the same type " 834 if (DstTy->getBitWidth() > widestWidthSeen) {
835 widestWidthSeen = DstTy->getBitWidth();
841 assert(widestWidthSeen > 0);
844 for (Subscript *Pair : Pairs) {
845 const SCEV *Src = Pair->Src;
846 const SCEV *Dst = Pair->Dst;
849 if (SrcTy ==
nullptr || DstTy ==
nullptr) {
850 assert(SrcTy == DstTy &&
"This function only unify integer types and " 851 "expect Src and Dst share the same type " 857 Pair->Src = SE->getSignExtendExpr(Src, widestType);
858 if (DstTy->getBitWidth() < widestWidthSeen) {
860 Pair->Dst = SE->getSignExtendExpr(Dst, widestType);
869 void DependenceInfo::removeMatchingExtensions(Subscript *Pair) {
870 const SCEV *Src = Pair->Src;
871 const SCEV *Dst = Pair->Dst;
872 if ((isa<SCEVZeroExtendExpr>(Src) && isa<SCEVZeroExtendExpr>(Dst)) ||
873 (isa<SCEVSignExtendExpr>(Src) && isa<SCEVSignExtendExpr>(Dst))) {
877 const SCEV *DstCastOp = DstCast->getOperand();
878 if (SrcCastOp->getType() == DstCastOp->
getType()) {
879 Pair->Src = SrcCastOp;
880 Pair->Dst = DstCastOp;
887 bool DependenceInfo::checkSubscript(
const SCEV *Expr,
const Loop *LoopNest,
891 return isLoopInvariant(Expr, LoopNest);
894 const SCEV *UB = SE->getBackedgeTakenCount(AddRec->
getLoop());
895 if (!isa<SCEVCouldNotCompute>(UB)) {
896 if (SE->getTypeSizeInBits(Start->
getType()) <
897 SE->getTypeSizeInBits(UB->
getType())) {
902 if (!isLoopInvariant(Step, LoopNest))
908 return checkSubscript(Start, LoopNest, Loops, IsSrc);
913 bool DependenceInfo::checkSrcSubscript(
const SCEV *Src,
const Loop *LoopNest,
915 return checkSubscript(Src, LoopNest, Loops,
true);
920 bool DependenceInfo::checkDstSubscript(
const SCEV *Dst,
const Loop *LoopNest,
922 return checkSubscript(Dst, LoopNest, Loops,
false);
929 DependenceInfo::Subscript::ClassificationKind
930 DependenceInfo::classifyPair(
const SCEV *Src,
const Loop *SrcLoopNest,
931 const SCEV *Dst,
const Loop *DstLoopNest,
935 if (!checkSrcSubscript(Src, SrcLoopNest, SrcLoops))
936 return Subscript::NonLinear;
937 if (!checkDstSubscript(Dst, DstLoopNest, DstLoops))
938 return Subscript::NonLinear;
941 unsigned N = Loops.
count();
943 return Subscript::ZIV;
945 return Subscript::SIV;
946 if (N == 2 && (SrcLoops.
count() == 0 ||
947 DstLoops.
count() == 0 ||
948 (SrcLoops.
count() == 1 && DstLoops.
count() == 1)))
949 return Subscript::RDIV;
950 return Subscript::MIV;
965 const SCEV *Y)
const {
968 if ((isa<SCEVSignExtendExpr>(X) &&
969 isa<SCEVSignExtendExpr>(Y)) ||
970 (isa<SCEVZeroExtendExpr>(X) &&
971 isa<SCEVZeroExtendExpr>(Y))) {
975 const SCEV *Yop = CY->getOperand();
976 if (Xop->getType() == Yop->
getType()) {
982 if (SE->isKnownPredicate(Pred, X, Y))
989 const SCEV *Delta = SE->getMinusSCEV(X, Y);
994 return SE->isKnownNonZero(Delta);
996 return SE->isKnownNonNegative(Delta);
998 return SE->isKnownNonPositive(Delta);
1000 return SE->isKnownPositive(Delta);
1002 return SE->isKnownNegative(Delta);
1011 bool DependenceInfo::isKnownLessThan(
const SCEV *S,
const SCEV *
Size)
const {
1015 if (!SType || !SizeType)
1018 (SType->getBitWidth() >= SizeType->getBitWidth()) ? SType : SizeType;
1019 S = SE->getTruncateOrZeroExtend(S, MaxType);
1020 Size = SE->getTruncateOrZeroExtend(Size, MaxType);
1023 const SCEV *Bound = SE->getMinusSCEV(S, Size);
1024 if (
const SCEVAddRecExpr *AddRec = dyn_cast<SCEVAddRecExpr>(Bound)) {
1025 if (AddRec->isAffine()) {
1026 const SCEV *BECount = SE->getBackedgeTakenCount(AddRec->getLoop());
1027 if (!isa<SCEVCouldNotCompute>(BECount)) {
1028 const SCEV *Limit = AddRec->evaluateAtIteration(BECount, *SE);
1029 if (SE->isKnownNegative(Limit))
1036 const SCEV *LimitedBound =
1037 SE->getMinusSCEV(S, SE->getSMaxExpr(Size, SE->getOne(Size->
getType())));
1038 return SE->isKnownNegative(LimitedBound);
1041 bool DependenceInfo::isKnownNonNegative(
const SCEV *S,
const Value *Ptr)
const {
1042 bool Inbounds =
false;
1043 if (
auto *SrcGEP = dyn_cast<GetElementPtrInst>(Ptr))
1044 Inbounds = SrcGEP->isInBounds();
1046 if (
const SCEVAddRecExpr *AddRec = dyn_cast<SCEVAddRecExpr>(S)) {
1047 if (AddRec->isAffine()) {
1050 if (SE->isKnownNonNegative(AddRec->getStart()) &&
1051 SE->isKnownNonNegative(AddRec->getOperand(1)))
1057 return SE->isKnownNonNegative(S);
1067 const SCEV *DependenceInfo::collectUpperBound(
const Loop *L,
Type *
T)
const {
1068 if (SE->hasLoopInvariantBackedgeTakenCount(L)) {
1069 const SCEV *UB = SE->getBackedgeTakenCount(L);
1070 return SE->getTruncateOrZeroExtend(UB, T);
1078 const SCEVConstant *DependenceInfo::collectConstantUpperBound(
const Loop *L,
1080 if (
const SCEV *UB = collectUpperBound(L, T))
1096 bool DependenceInfo::testZIV(
const SCEV *Src,
const SCEV *Dst,
1111 Result.Consistent =
false;
1143 bool DependenceInfo::strongSIVtest(
const SCEV *Coeff,
const SCEV *SrcConst,
1144 const SCEV *DstConst,
const Loop *CurLoop,
1146 Constraint &NewConstraint)
const {
1154 ++StrongSIVapplications;
1155 assert(0 < Level && Level <= CommonLevels &&
"level out of range");
1158 const SCEV *Delta = SE->getMinusSCEV(SrcConst, DstConst);
1163 if (
const SCEV *UpperBound = collectUpperBound(CurLoop, Delta->
getType())) {
1166 const SCEV *AbsDelta =
1167 SE->isKnownNonNegative(Delta) ? Delta : SE->getNegativeSCEV(Delta);
1168 const SCEV *AbsCoeff =
1169 SE->isKnownNonNegative(Coeff) ? Coeff : SE->getNegativeSCEV(Coeff);
1170 const SCEV *Product = SE->getMulExpr(UpperBound, AbsCoeff);
1173 ++StrongSIVindependence;
1174 ++StrongSIVsuccesses;
1180 if (isa<SCEVConstant>(Delta) && isa<SCEVConstant>(Coeff)) {
1181 APInt ConstDelta = cast<SCEVConstant>(Delta)->getAPInt();
1182 APInt ConstCoeff = cast<SCEVConstant>(Coeff)->getAPInt();
1183 APInt Distance = ConstDelta;
1184 APInt Remainder = ConstDelta;
1189 if (Remainder != 0) {
1191 ++StrongSIVindependence;
1192 ++StrongSIVsuccesses;
1195 Result.DV[
Level].Distance = SE->getConstant(Distance);
1196 NewConstraint.setDistance(SE->getConstant(Distance), CurLoop);
1197 if (Distance.
sgt(0))
1199 else if (Distance.
slt(0))
1203 ++StrongSIVsuccesses;
1205 else if (Delta->
isZero()) {
1207 Result.DV[
Level].Distance = Delta;
1208 NewConstraint.setDistance(Delta, CurLoop);
1210 ++StrongSIVsuccesses;
1213 if (Coeff->
isOne()) {
1215 Result.DV[
Level].Distance = Delta;
1216 NewConstraint.setDistance(Delta, CurLoop);
1219 Result.Consistent =
false;
1220 NewConstraint.setLine(Coeff,
1221 SE->getNegativeSCEV(Coeff),
1222 SE->getNegativeSCEV(Delta), CurLoop);
1226 bool DeltaMaybeZero = !SE->isKnownNonZero(Delta);
1227 bool DeltaMaybePositive = !SE->isKnownNonPositive(Delta);
1228 bool DeltaMaybeNegative = !SE->isKnownNonNegative(Delta);
1229 bool CoeffMaybePositive = !SE->isKnownNonPositive(Coeff);
1230 bool CoeffMaybeNegative = !SE->isKnownNonNegative(Coeff);
1235 if ((DeltaMaybePositive && CoeffMaybePositive) ||
1236 (DeltaMaybeNegative && CoeffMaybeNegative))
1240 if ((DeltaMaybeNegative && CoeffMaybePositive) ||
1241 (DeltaMaybePositive && CoeffMaybeNegative))
1243 if (NewDirection < Result.DV[Level].Direction)
1244 ++StrongSIVsuccesses;
1245 Result.DV[
Level].Direction &= NewDirection;
1279 bool DependenceInfo::weakCrossingSIVtest(
1280 const SCEV *Coeff,
const SCEV *SrcConst,
const SCEV *DstConst,
1282 Constraint &NewConstraint,
const SCEV *&SplitIter)
const {
1287 ++WeakCrossingSIVapplications;
1288 assert(0 < Level && Level <= CommonLevels &&
"Level out of range");
1290 Result.Consistent =
false;
1291 const SCEV *Delta = SE->getMinusSCEV(DstConst, SrcConst);
1293 NewConstraint.setLine(Coeff, Coeff, Delta, CurLoop);
1297 ++WeakCrossingSIVsuccesses;
1298 if (!Result.DV[Level].Direction) {
1299 ++WeakCrossingSIVindependence;
1302 Result.DV[
Level].Distance = Delta;
1309 Result.DV[
Level].Splitable =
true;
1310 if (SE->isKnownNegative(ConstCoeff)) {
1313 "dynamic cast of negative of ConstCoeff should yield constant");
1314 Delta = SE->getNegativeSCEV(Delta);
1316 assert(SE->isKnownPositive(ConstCoeff) &&
"ConstCoeff should be positive");
1319 SplitIter = SE->getUDivExpr(
1320 SE->getSMaxExpr(SE->getZero(Delta->
getType()), Delta),
1321 SE->getMulExpr(SE->getConstant(Delta->
getType(), 2), ConstCoeff));
1332 if (SE->isKnownNegative(Delta)) {
1334 ++WeakCrossingSIVindependence;
1335 ++WeakCrossingSIVsuccesses;
1341 if (
const SCEV *UpperBound = collectUpperBound(CurLoop, Delta->
getType())) {
1343 const SCEV *ConstantTwo = SE->getConstant(UpperBound->getType(), 2);
1344 const SCEV *ML = SE->getMulExpr(SE->getMulExpr(ConstCoeff, UpperBound),
1349 ++WeakCrossingSIVindependence;
1350 ++WeakCrossingSIVsuccesses;
1357 ++WeakCrossingSIVsuccesses;
1358 if (!Result.DV[Level].Direction) {
1359 ++WeakCrossingSIVindependence;
1362 Result.DV[
Level].Splitable =
false;
1363 Result.DV[
Level].Distance = SE->getZero(Delta->
getType());
1371 APInt Distance = APDelta;
1372 APInt Remainder = APDelta;
1375 if (Remainder != 0) {
1377 ++WeakCrossingSIVindependence;
1378 ++WeakCrossingSIVsuccesses;
1385 Remainder = Distance.
srem(Two);
1387 if (Remainder != 0) {
1390 ++WeakCrossingSIVsuccesses;
1408 APInt A0(Bits, 1,
true), A1(Bits, 0,
true);
1409 APInt B0(Bits, 0,
true),
B1(Bits, 1,
true);
1416 APInt A2 = A0 - Q*A1; A0 = A1; A1 = A2;
1417 APInt B2 = B0 - Q*B1; B0 = B1; B1 = B2;
1423 X = AM.
slt(0) ? -A1 : A1;
1424 Y = BM.
slt(0) ? B1 : -B1;
1442 if ((A.
sgt(0) && B.
sgt(0)) ||
1455 if ((A.
sgt(0) && B.
sgt(0)) ||
1465 return A.
sgt(B) ? A :
B;
1471 return A.
slt(B) ? A :
B;
1490 bool DependenceInfo::exactSIVtest(
const SCEV *SrcCoeff,
const SCEV *DstCoeff,
1491 const SCEV *SrcConst,
const SCEV *DstConst,
1492 const Loop *CurLoop,
unsigned Level,
1494 Constraint &NewConstraint)
const {
1496 LLVM_DEBUG(
dbgs() <<
"\t SrcCoeff = " << *SrcCoeff <<
" = AM\n");
1497 LLVM_DEBUG(
dbgs() <<
"\t DstCoeff = " << *DstCoeff <<
" = BM\n");
1500 ++ExactSIVapplications;
1501 assert(0 < Level && Level <= CommonLevels &&
"Level out of range");
1503 Result.Consistent =
false;
1504 const SCEV *Delta = SE->getMinusSCEV(DstConst, SrcConst);
1506 NewConstraint.setLine(SrcCoeff, SE->getNegativeSCEV(DstCoeff),
1511 if (!ConstDelta || !ConstSrcCoeff || !ConstDstCoeff)
1516 APInt AM = ConstSrcCoeff->getAPInt();
1517 APInt BM = ConstDstCoeff->getAPInt();
1521 ++ExactSIVindependence;
1522 ++ExactSIVsuccesses;
1529 APInt UM(Bits, 1,
true);
1530 bool UMvalid =
false;
1533 collectConstantUpperBound(CurLoop, Delta->
getType())) {
1534 UM = CUB->getAPInt();
1580 ++ExactSIVindependence;
1581 ++ExactSIVsuccesses;
1603 ++ExactSIVsuccesses;
1629 ++ExactSIVsuccesses;
1646 ++ExactSIVsuccesses;
1650 Result.DV[
Level].Direction &= NewDirection;
1652 ++ExactSIVindependence;
1664 return ConstDividend.
srem(ConstDivisor) == 0;
1699 bool DependenceInfo::weakZeroSrcSIVtest(
const SCEV *DstCoeff,
1700 const SCEV *SrcConst,
1701 const SCEV *DstConst,
1702 const Loop *CurLoop,
unsigned Level,
1704 Constraint &NewConstraint)
const {
1712 ++WeakZeroSIVapplications;
1713 assert(0 < Level && Level <= MaxLevels &&
"Level out of range");
1715 Result.Consistent =
false;
1716 const SCEV *Delta = SE->getMinusSCEV(SrcConst, DstConst);
1717 NewConstraint.setLine(SE->getZero(Delta->
getType()), DstCoeff, Delta,
1721 if (Level < CommonLevels) {
1723 Result.DV[
Level].PeelFirst =
true;
1724 ++WeakZeroSIVsuccesses;
1731 const SCEV *AbsCoeff =
1732 SE->isKnownNegative(ConstCoeff) ?
1733 SE->getNegativeSCEV(ConstCoeff) : ConstCoeff;
1734 const SCEV *NewDelta =
1735 SE->isKnownNegative(ConstCoeff) ? SE->getNegativeSCEV(Delta) : Delta;
1739 if (
const SCEV *UpperBound = collectUpperBound(CurLoop, Delta->
getType())) {
1741 const SCEV *Product = SE->getMulExpr(AbsCoeff, UpperBound);
1743 ++WeakZeroSIVindependence;
1744 ++WeakZeroSIVsuccesses;
1749 if (Level < CommonLevels) {
1751 Result.DV[
Level].PeelLast =
true;
1752 ++WeakZeroSIVsuccesses;
1760 if (SE->isKnownNegative(NewDelta)) {
1762 ++WeakZeroSIVindependence;
1763 ++WeakZeroSIVsuccesses;
1768 if (isa<SCEVConstant>(Delta) &&
1770 ++WeakZeroSIVindependence;
1771 ++WeakZeroSIVsuccesses;
1809 bool DependenceInfo::weakZeroDstSIVtest(
const SCEV *SrcCoeff,
1810 const SCEV *SrcConst,
1811 const SCEV *DstConst,
1812 const Loop *CurLoop,
unsigned Level,
1814 Constraint &NewConstraint)
const {
1821 ++WeakZeroSIVapplications;
1822 assert(0 < Level && Level <= SrcLevels &&
"Level out of range");
1824 Result.Consistent =
false;
1825 const SCEV *Delta = SE->getMinusSCEV(DstConst, SrcConst);
1826 NewConstraint.setLine(SrcCoeff, SE->getZero(Delta->
getType()), Delta,
1830 if (Level < CommonLevels) {
1832 Result.DV[
Level].PeelFirst =
true;
1833 ++WeakZeroSIVsuccesses;
1840 const SCEV *AbsCoeff =
1841 SE->isKnownNegative(ConstCoeff) ?
1842 SE->getNegativeSCEV(ConstCoeff) : ConstCoeff;
1843 const SCEV *NewDelta =
1844 SE->isKnownNegative(ConstCoeff) ? SE->getNegativeSCEV(Delta) : Delta;
1848 if (
const SCEV *UpperBound = collectUpperBound(CurLoop, Delta->
getType())) {
1850 const SCEV *Product = SE->getMulExpr(AbsCoeff, UpperBound);
1852 ++WeakZeroSIVindependence;
1853 ++WeakZeroSIVsuccesses;
1858 if (Level < CommonLevels) {
1860 Result.DV[
Level].PeelLast =
true;
1861 ++WeakZeroSIVsuccesses;
1869 if (SE->isKnownNegative(NewDelta)) {
1871 ++WeakZeroSIVindependence;
1872 ++WeakZeroSIVsuccesses;
1877 if (isa<SCEVConstant>(Delta) &&
1879 ++WeakZeroSIVindependence;
1880 ++WeakZeroSIVsuccesses;
1894 bool DependenceInfo::exactRDIVtest(
const SCEV *SrcCoeff,
const SCEV *DstCoeff,
1895 const SCEV *SrcConst,
const SCEV *DstConst,
1896 const Loop *SrcLoop,
const Loop *DstLoop,
1899 LLVM_DEBUG(
dbgs() <<
"\t SrcCoeff = " << *SrcCoeff <<
" = AM\n");
1900 LLVM_DEBUG(
dbgs() <<
"\t DstCoeff = " << *DstCoeff <<
" = BM\n");
1903 ++ExactRDIVapplications;
1904 Result.Consistent =
false;
1905 const SCEV *Delta = SE->getMinusSCEV(DstConst, SrcConst);
1910 if (!ConstDelta || !ConstSrcCoeff || !ConstDstCoeff)
1915 APInt AM = ConstSrcCoeff->getAPInt();
1916 APInt BM = ConstDstCoeff->getAPInt();
1920 ++ExactRDIVindependence;
1927 APInt SrcUM(Bits, 1,
true);
1928 bool SrcUMvalid =
false;
1931 collectConstantUpperBound(SrcLoop, Delta->
getType())) {
1932 SrcUM = UpperBound->getAPInt();
1937 APInt DstUM(Bits, 1,
true);
1938 bool DstUMvalid =
false;
1941 collectConstantUpperBound(DstLoop, Delta->
getType())) {
1942 DstUM = UpperBound->getAPInt();
1988 ++ExactRDIVindependence;
2035 bool DependenceInfo::symbolicRDIVtest(
const SCEV *A1,
const SCEV *A2,
2038 const Loop *Loop2)
const {
2039 ++SymbolicRDIVapplications;
2046 const SCEV *N1 = collectUpperBound(Loop1, A1->
getType());
2047 const SCEV *N2 = collectUpperBound(Loop2, A1->
getType());
2050 const SCEV *C2_C1 = SE->getMinusSCEV(C2, C1);
2051 const SCEV *C1_C2 = SE->getMinusSCEV(C1, C2);
2054 if (SE->isKnownNonNegative(A1)) {
2055 if (SE->isKnownNonNegative(A2)) {
2059 const SCEV *A1N1 = SE->getMulExpr(A1, N1);
2062 ++SymbolicRDIVindependence;
2068 const SCEV *A2N2 = SE->getMulExpr(A2, N2);
2071 ++SymbolicRDIVindependence;
2076 else if (SE->isKnownNonPositive(A2)) {
2080 const SCEV *A1N1 = SE->getMulExpr(A1, N1);
2081 const SCEV *A2N2 = SE->getMulExpr(A2, N2);
2082 const SCEV *A1N1_A2N2 = SE->getMinusSCEV(A1N1, A2N2);
2083 LLVM_DEBUG(
dbgs() <<
"\t A1*N1 - A2*N2 = " << *A1N1_A2N2 <<
"\n");
2085 ++SymbolicRDIVindependence;
2090 if (SE->isKnownNegative(C2_C1)) {
2091 ++SymbolicRDIVindependence;
2096 else if (SE->isKnownNonPositive(A1)) {
2097 if (SE->isKnownNonNegative(A2)) {
2101 const SCEV *A1N1 = SE->getMulExpr(A1, N1);
2102 const SCEV *A2N2 = SE->getMulExpr(A2, N2);
2103 const SCEV *A1N1_A2N2 = SE->getMinusSCEV(A1N1, A2N2);
2104 LLVM_DEBUG(
dbgs() <<
"\t A1*N1 - A2*N2 = " << *A1N1_A2N2 <<
"\n");
2106 ++SymbolicRDIVindependence;
2111 if (SE->isKnownPositive(C2_C1)) {
2112 ++SymbolicRDIVindependence;
2116 else if (SE->isKnownNonPositive(A2)) {
2120 const SCEV *A1N1 = SE->getMulExpr(A1, N1);
2123 ++SymbolicRDIVindependence;
2129 const SCEV *A2N2 = SE->getMulExpr(A2, N2);
2132 ++SymbolicRDIVindependence;
2150 bool DependenceInfo::testSIV(
const SCEV *Src,
const SCEV *Dst,
unsigned &Level,
2152 const SCEV *&SplitIter)
const {
2157 if (SrcAddRec && DstAddRec) {
2159 const SCEV *DstConst = DstAddRec->getStart();
2161 const SCEV *DstCoeff = DstAddRec->getStepRecurrence(*SE);
2163 assert(CurLoop == DstAddRec->getLoop() &&
2164 "both loops in SIV should be same");
2165 Level = mapSrcLoop(CurLoop);
2167 if (SrcCoeff == DstCoeff)
2168 disproven = strongSIVtest(SrcCoeff, SrcConst, DstConst, CurLoop,
2169 Level, Result, NewConstraint);
2170 else if (SrcCoeff == SE->getNegativeSCEV(DstCoeff))
2171 disproven = weakCrossingSIVtest(SrcCoeff, SrcConst, DstConst, CurLoop,
2172 Level, Result, NewConstraint, SplitIter);
2174 disproven = exactSIVtest(SrcCoeff, DstCoeff, SrcConst, DstConst, CurLoop,
2175 Level, Result, NewConstraint);
2177 gcdMIVtest(Src, Dst, Result) ||
2178 symbolicRDIVtest(SrcCoeff, DstCoeff, SrcConst, DstConst, CurLoop, CurLoop);
2183 const SCEV *DstConst = Dst;
2185 Level = mapSrcLoop(CurLoop);
2186 return weakZeroDstSIVtest(SrcCoeff, SrcConst, DstConst, CurLoop,
2187 Level, Result, NewConstraint) ||
2188 gcdMIVtest(Src, Dst, Result);
2191 const SCEV *DstConst = DstAddRec->getStart();
2192 const SCEV *DstCoeff = DstAddRec->getStepRecurrence(*SE);
2193 const SCEV *SrcConst = Src;
2194 const Loop *CurLoop = DstAddRec->getLoop();
2195 Level = mapDstLoop(CurLoop);
2196 return weakZeroSrcSIVtest(DstCoeff, SrcConst, DstConst,
2197 CurLoop, Level, Result, NewConstraint) ||
2198 gcdMIVtest(Src, Dst, Result);
2218 bool DependenceInfo::testRDIV(
const SCEV *Src,
const SCEV *Dst,
2226 const SCEV *SrcConst, *DstConst;
2227 const SCEV *SrcCoeff, *DstCoeff;
2228 const Loop *SrcLoop, *DstLoop;
2234 if (SrcAddRec && DstAddRec) {
2237 SrcLoop = SrcAddRec->
getLoop();
2238 DstConst = DstAddRec->getStart();
2239 DstCoeff = DstAddRec->getStepRecurrence(*SE);
2240 DstLoop = DstAddRec->getLoop();
2242 else if (SrcAddRec) {
2244 dyn_cast<SCEVAddRecExpr>(SrcAddRec->
getStart())) {
2245 SrcConst = tmpAddRec->getStart();
2246 SrcCoeff = tmpAddRec->getStepRecurrence(*SE);
2247 SrcLoop = tmpAddRec->getLoop();
2250 DstLoop = SrcAddRec->
getLoop();
2255 else if (DstAddRec) {
2257 dyn_cast<SCEVAddRecExpr>(DstAddRec->getStart())) {
2258 DstConst = tmpAddRec->getStart();
2259 DstCoeff = tmpAddRec->getStepRecurrence(*SE);
2260 DstLoop = tmpAddRec->getLoop();
2262 SrcCoeff = SE->getNegativeSCEV(DstAddRec->getStepRecurrence(*SE));
2263 SrcLoop = DstAddRec->getLoop();
2270 return exactRDIVtest(SrcCoeff, DstCoeff,
2274 gcdMIVtest(Src, Dst, Result) ||
2275 symbolicRDIVtest(SrcCoeff, DstCoeff,
2284 bool DependenceInfo::testMIV(
const SCEV *Src,
const SCEV *Dst,
2289 Result.Consistent =
false;
2290 return gcdMIVtest(Src, Dst, Result) ||
2291 banerjeeMIVtest(Src, Dst, Loops, Result);
2299 if (
const auto *
Constant = dyn_cast<SCEVConstant>(Expr))
2301 else if (
const auto *Product = dyn_cast<SCEVMulExpr>(Expr))
2302 if (
const auto *
Constant = dyn_cast<SCEVConstant>(Product->getOperand(0)))
2326 bool DependenceInfo::gcdMIVtest(
const SCEV *Src,
const SCEV *Dst,
2330 unsigned BitWidth = SE->getTypeSizeInBits(Src->
getType());
2337 const SCEV *Coefficients = Src;
2339 dyn_cast<SCEVAddRecExpr>(Coefficients)) {
2340 const SCEV *Coeff = AddRec->getStepRecurrence(*SE);
2348 Coefficients = AddRec->getStart();
2350 const SCEV *SrcConst = Coefficients;
2358 dyn_cast<SCEVAddRecExpr>(Coefficients)) {
2359 const SCEV *Coeff = AddRec->getStepRecurrence(*SE);
2367 Coefficients = AddRec->getStart();
2369 const SCEV *DstConst = Coefficients;
2372 const SCEV *Delta = SE->getMinusSCEV(DstConst, SrcConst);
2375 if (
const SCEVAddExpr *Sum = dyn_cast<SCEVAddExpr>(Delta)) {
2377 for (
unsigned Op = 0, Ops = Sum->getNumOperands();
Op < Ops;
Op++) {
2378 const SCEV *Operand = Sum->getOperand(
Op);
2379 if (isa<SCEVConstant>(Operand)) {
2380 assert(!Constant &&
"Surprised to find multiple constants");
2381 Constant = cast<SCEVConstant>(Operand);
2383 else if (
const SCEVMulExpr *Product = dyn_cast<SCEVMulExpr>(Operand)) {
2391 ConstOpValue.
abs());
2399 APInt ConstDelta = cast<SCEVConstant>(Constant)->getAPInt();
2401 if (ConstDelta == 0)
2405 APInt Remainder = ConstDelta.
srem(RunningGCD);
2406 if (Remainder != 0) {
2425 bool Improved =
false;
2428 dyn_cast<SCEVAddRecExpr>(Coefficients)) {
2429 Coefficients = AddRec->getStart();
2430 const Loop *CurLoop = AddRec->getLoop();
2431 RunningGCD = ExtraGCD;
2432 const SCEV *SrcCoeff = AddRec->getStepRecurrence(*SE);
2433 const SCEV *DstCoeff = SE->getMinusSCEV(SrcCoeff, SrcCoeff);
2434 const SCEV *Inner = Src;
2435 while (RunningGCD != 1 && isa<SCEVAddRecExpr>(Inner)) {
2436 AddRec = cast<SCEVAddRecExpr>(Inner);
2437 const SCEV *Coeff = AddRec->getStepRecurrence(*SE);
2438 if (CurLoop == AddRec->getLoop())
2449 Inner = AddRec->getStart();
2452 while (RunningGCD != 1 && isa<SCEVAddRecExpr>(Inner)) {
2453 AddRec = cast<SCEVAddRecExpr>(Inner);
2454 const SCEV *Coeff = AddRec->getStepRecurrence(*SE);
2455 if (CurLoop == AddRec->getLoop())
2466 Inner = AddRec->getStart();
2468 Delta = SE->getMinusSCEV(SrcCoeff, DstCoeff);
2479 if (RunningGCD != 0) {
2480 Remainder = ConstDelta.
srem(RunningGCD);
2482 if (Remainder != 0) {
2483 unsigned Level = mapSrcLoop(CurLoop);
2529 bool DependenceInfo::banerjeeMIVtest(
const SCEV *Src,
const SCEV *Dst,
2533 ++BanerjeeApplications;
2536 CoefficientInfo *A = collectCoeffInfo(Src,
true, A0);
2539 CoefficientInfo *
B = collectCoeffInfo(Dst,
false, B0);
2540 BoundInfo *Bound =
new BoundInfo[MaxLevels + 1];
2541 const SCEV *Delta = SE->getMinusSCEV(B0, A0);
2546 for (
unsigned K = 1; K <= MaxLevels; ++K) {
2547 Bound[K].Iterations = A[K].Iterations ? A[K].Iterations : B[K].Iterations;
2550 findBoundsALL(A, B, Bound, K);
2557 if (Bound[K].
Upper[Dependence::DVEntry::ALL])
2565 bool Disproved =
false;
2568 unsigned DepthExpanded = 0;
2569 unsigned NewDeps = exploreDirections(1, A, B, Bound,
2570 Loops, DepthExpanded, Delta);
2572 bool Improved =
false;
2573 for (
unsigned K = 1; K <= CommonLevels; ++K) {
2575 unsigned Old = Result.DV[K - 1].Direction;
2576 Result.DV[K - 1].Direction = Old & Bound[K].DirSet;
2577 Improved |= Old != Result.DV[K - 1].Direction;
2578 if (!Result.DV[K - 1].Direction) {
2586 ++BanerjeeSuccesses;
2589 ++BanerjeeIndependence;
2594 ++BanerjeeIndependence;
2609 unsigned DependenceInfo::exploreDirections(
unsigned Level, CoefficientInfo *A,
2610 CoefficientInfo *
B, BoundInfo *Bound,
2612 unsigned &DepthExpanded,
2613 const SCEV *Delta)
const {
2614 if (Level > CommonLevels) {
2617 for (
unsigned K = 1; K <= CommonLevels; ++K) {
2619 Bound[K].DirSet |= Bound[K].Direction;
2644 if (Level > DepthExpanded) {
2645 DepthExpanded =
Level;
2647 findBoundsLT(A, B, Bound, Level);
2648 findBoundsGT(A, B, Bound, Level);
2649 findBoundsEQ(A, B, Bound, Level);
2658 if (Bound[Level].
Upper[Dependence::DVEntry::LT])
2669 if (Bound[Level].
Upper[Dependence::DVEntry::EQ])
2680 if (Bound[Level].
Upper[Dependence::DVEntry::GT])
2688 unsigned NewDeps = 0;
2692 NewDeps += exploreDirections(Level + 1, A, B, Bound,
2693 Loops, DepthExpanded, Delta);
2697 NewDeps += exploreDirections(Level + 1, A, B, Bound,
2698 Loops, DepthExpanded, Delta);
2702 NewDeps += exploreDirections(Level + 1, A, B, Bound,
2703 Loops, DepthExpanded, Delta);
2709 return exploreDirections(Level + 1, A, B, Bound, Loops, DepthExpanded, Delta);
2714 bool DependenceInfo::testBounds(
unsigned char DirKind,
unsigned Level,
2715 BoundInfo *Bound,
const SCEV *Delta)
const {
2716 Bound[
Level].Direction = DirKind;
2717 if (
const SCEV *LowerBound = getLowerBound(Bound))
2720 if (
const SCEV *UpperBound = getUpperBound(Bound))
2742 void DependenceInfo::findBoundsALL(CoefficientInfo *A, CoefficientInfo *B,
2743 BoundInfo *Bound,
unsigned K)
const {
2746 if (Bound[K].Iterations) {
2748 SE->getMulExpr(SE->getMinusSCEV(A[K].NegPart, B[K].PosPart),
2749 Bound[K].Iterations);
2751 SE->getMulExpr(SE->getMinusSCEV(A[K].PosPart, B[K].NegPart),
2752 Bound[K].Iterations);
2758 SE->getZero(A[K].Coeff->getType());
2761 SE->getZero(A[K].Coeff->getType());
2781 void DependenceInfo::findBoundsEQ(CoefficientInfo *A, CoefficientInfo *B,
2782 BoundInfo *Bound,
unsigned K)
const {
2785 if (Bound[K].Iterations) {
2786 const SCEV *Delta = SE->getMinusSCEV(A[K].Coeff, B[K].Coeff);
2787 const SCEV *NegativePart = getNegativePart(Delta);
2789 SE->getMulExpr(NegativePart, Bound[K].Iterations);
2790 const SCEV *PositivePart = getPositivePart(Delta);
2792 SE->getMulExpr(PositivePart, Bound[K].Iterations);
2797 const SCEV *Delta = SE->getMinusSCEV(A[K].Coeff, B[K].Coeff);
2798 const SCEV *NegativePart = getNegativePart(Delta);
2799 if (NegativePart->
isZero())
2801 const SCEV *PositivePart = getPositivePart(Delta);
2802 if (PositivePart->
isZero())
2821 void DependenceInfo::findBoundsLT(CoefficientInfo *A, CoefficientInfo *B,
2822 BoundInfo *Bound,
unsigned K)
const {
2825 if (Bound[K].Iterations) {
2826 const SCEV *Iter_1 = SE->getMinusSCEV(
2827 Bound[K].Iterations, SE->getOne(Bound[K].Iterations->getType()));
2828 const SCEV *NegPart =
2829 getNegativePart(SE->getMinusSCEV(A[K].NegPart, B[K].Coeff));
2831 SE->getMinusSCEV(SE->getMulExpr(NegPart, Iter_1), B[K].Coeff);
2832 const SCEV *PosPart =
2833 getPositivePart(SE->getMinusSCEV(A[K].PosPart, B[K].Coeff));
2835 SE->getMinusSCEV(SE->getMulExpr(PosPart, Iter_1), B[K].Coeff);
2840 const SCEV *NegPart =
2841 getNegativePart(SE->getMinusSCEV(A[K].NegPart, B[K].Coeff));
2844 const SCEV *PosPart =
2845 getPositivePart(SE->getMinusSCEV(A[K].PosPart, B[K].Coeff));
2865 void DependenceInfo::findBoundsGT(CoefficientInfo *A, CoefficientInfo *B,
2866 BoundInfo *Bound,
unsigned K)
const {
2869 if (Bound[K].Iterations) {
2870 const SCEV *Iter_1 = SE->getMinusSCEV(
2871 Bound[K].Iterations, SE->getOne(Bound[K].Iterations->getType()));
2872 const SCEV *NegPart =
2873 getNegativePart(SE->getMinusSCEV(A[K].Coeff, B[K].PosPart));
2875 SE->getAddExpr(SE->getMulExpr(NegPart, Iter_1), A[K].Coeff);
2876 const SCEV *PosPart =
2877 getPositivePart(SE->getMinusSCEV(A[K].Coeff, B[K].NegPart));
2879 SE->getAddExpr(SE->getMulExpr(PosPart, Iter_1), A[K].Coeff);
2884 const SCEV *NegPart = getNegativePart(SE->getMinusSCEV(A[K].Coeff, B[K].PosPart));
2887 const SCEV *PosPart = getPositivePart(SE->getMinusSCEV(A[K].Coeff, B[K].NegPart));
2895 const SCEV *DependenceInfo::getPositivePart(
const SCEV *X)
const {
2896 return SE->getSMaxExpr(X, SE->getZero(X->
getType()));
2901 const SCEV *DependenceInfo::getNegativePart(
const SCEV *X)
const {
2902 return SE->getSMinExpr(X, SE->getZero(X->
getType()));
2909 DependenceInfo::CoefficientInfo *
2910 DependenceInfo::collectCoeffInfo(
const SCEV *Subscript,
bool SrcFlag,
2912 const SCEV *Zero = SE->getZero(Subscript->
getType());
2913 CoefficientInfo *CI =
new CoefficientInfo[MaxLevels + 1];
2914 for (
unsigned K = 1; K <= MaxLevels; ++K) {
2916 CI[K].PosPart = Zero;
2917 CI[K].NegPart = Zero;
2918 CI[K].Iterations =
nullptr;
2920 while (
const SCEVAddRecExpr *AddRec = dyn_cast<SCEVAddRecExpr>(Subscript)) {
2921 const Loop *L = AddRec->getLoop();
2922 unsigned K = SrcFlag ? mapSrcLoop(L) : mapDstLoop(L);
2923 CI[K].Coeff = AddRec->getStepRecurrence(*SE);
2924 CI[K].PosPart = getPositivePart(CI[K].Coeff);
2925 CI[K].NegPart = getNegativePart(CI[K].Coeff);
2926 CI[K].Iterations = collectUpperBound(L, Subscript->
getType());
2927 Subscript = AddRec->getStart();
2929 Constant = Subscript;
2932 for (
unsigned K = 1; K <= MaxLevels; ++K) {
2939 if (CI[K].Iterations)
2955 const SCEV *DependenceInfo::getLowerBound(BoundInfo *Bound)
const {
2956 const SCEV *Sum = Bound[1].Lower[Bound[1].Direction];
2957 for (
unsigned K = 2; Sum && K <= MaxLevels; ++K) {
2959 Sum = SE->getAddExpr(Sum, Bound[K].
Lower[Bound[K].Direction]);
2971 const SCEV *DependenceInfo::getUpperBound(BoundInfo *Bound)
const {
2972 const SCEV *Sum = Bound[1].Upper[Bound[1].Direction];
2973 for (
unsigned K = 2; Sum && K <= MaxLevels; ++K) {
2975 Sum = SE->getAddExpr(Sum, Bound[K].
Upper[Bound[K].Direction]);
2992 const SCEV *DependenceInfo::findCoefficient(
const SCEV *Expr,
2993 const Loop *TargetLoop)
const {
2996 return SE->getZero(Expr->
getType());
2997 if (AddRec->
getLoop() == TargetLoop)
2999 return findCoefficient(AddRec->
getStart(), TargetLoop);
3008 const SCEV *DependenceInfo::zeroCoefficient(
const SCEV *Expr,
3009 const Loop *TargetLoop)
const {
3013 if (AddRec->
getLoop() == TargetLoop)
3015 return SE->getAddRecExpr(zeroCoefficient(AddRec->
getStart(), TargetLoop),
3027 const SCEV *DependenceInfo::addToCoefficient(
const SCEV *Expr,
3028 const Loop *TargetLoop,
3032 return SE->getAddRecExpr(Expr,
3036 if (AddRec->
getLoop() == TargetLoop) {
3040 return SE->getAddRecExpr(AddRec->
getStart(),
3045 if (SE->isLoopInvariant(AddRec, TargetLoop))
3047 return SE->getAddRecExpr(
3064 bool DependenceInfo::propagate(
const SCEV *&Src,
const SCEV *&Dst,
3068 bool Result =
false;
3069 for (
unsigned LI : Loops.
set_bits()) {
3072 if (Constraints[LI].isDistance())
3073 Result |= propagateDistance(Src, Dst, Constraints[LI], Consistent);
3074 else if (Constraints[LI].isLine())
3075 Result |= propagateLine(Src, Dst, Constraints[LI], Consistent);
3076 else if (Constraints[LI].isPoint())
3077 Result |= propagatePoint(Src, Dst, Constraints[LI]);
3088 bool DependenceInfo::propagateDistance(
const SCEV *&Src,
const SCEV *&Dst,
3089 Constraint &CurConstraint,
3091 const Loop *CurLoop = CurConstraint.getAssociatedLoop();
3093 const SCEV *A_K = findCoefficient(Src, CurLoop);
3096 const SCEV *DA_K = SE->getMulExpr(A_K, CurConstraint.getD());
3097 Src = SE->getMinusSCEV(Src, DA_K);
3098 Src = zeroCoefficient(Src, CurLoop);
3101 Dst = addToCoefficient(Dst, CurLoop, SE->getNegativeSCEV(A_K));
3103 if (!findCoefficient(Dst, CurLoop)->
isZero())
3114 bool DependenceInfo::propagateLine(
const SCEV *&Src,
const SCEV *&Dst,
3115 Constraint &CurConstraint,
3117 const Loop *CurLoop = CurConstraint.getAssociatedLoop();
3118 const SCEV *A = CurConstraint.getA();
3119 const SCEV *B = CurConstraint.getB();
3120 const SCEV *
C = CurConstraint.getC();
3121 LLVM_DEBUG(
dbgs() <<
"\t\tA = " << *A <<
", B = " << *B <<
", C = " << *C
3128 if (!Bconst || !Cconst)
return false;
3130 APInt Charlie = Cconst->getAPInt();
3132 assert(Charlie.
srem(Beta) == 0 &&
"C should be evenly divisible by B");
3133 const SCEV *AP_K = findCoefficient(Dst, CurLoop);
3135 Src = SE->getMinusSCEV(Src, SE->getMulExpr(AP_K, SE->getConstant(CdivB)));
3136 Dst = zeroCoefficient(Dst, CurLoop);
3137 if (!findCoefficient(Src, CurLoop)->
isZero())
3143 if (!Aconst || !Cconst)
return false;
3145 APInt Charlie = Cconst->getAPInt();
3147 assert(Charlie.
srem(Alpha) == 0 &&
"C should be evenly divisible by A");
3148 const SCEV *A_K = findCoefficient(Src, CurLoop);
3149 Src = SE->getAddExpr(Src, SE->getMulExpr(A_K, SE->getConstant(CdivA)));
3150 Src = zeroCoefficient(Src, CurLoop);
3151 if (!findCoefficient(Dst, CurLoop)->
isZero())
3157 if (!Aconst || !Cconst)
return false;
3159 APInt Charlie = Cconst->getAPInt();
3161 assert(Charlie.
srem(Alpha) == 0 &&
"C should be evenly divisible by A");
3162 const SCEV *A_K = findCoefficient(Src, CurLoop);
3163 Src = SE->getAddExpr(Src, SE->getMulExpr(A_K, SE->getConstant(CdivA)));
3164 Src = zeroCoefficient(Src, CurLoop);
3165 Dst = addToCoefficient(Dst, CurLoop, A_K);
3166 if (!findCoefficient(Dst, CurLoop)->
isZero())
3171 const SCEV *A_K = findCoefficient(Src, CurLoop);
3172 Src = SE->getMulExpr(Src, A);
3173 Dst = SE->getMulExpr(Dst, A);
3174 Src = SE->getAddExpr(Src, SE->getMulExpr(A_K, C));
3175 Src = zeroCoefficient(Src, CurLoop);
3176 Dst = addToCoefficient(Dst, CurLoop, SE->getMulExpr(A_K, B));
3177 if (!findCoefficient(Dst, CurLoop)->isZero())
3189 bool DependenceInfo::propagatePoint(
const SCEV *&Src,
const SCEV *&Dst,
3190 Constraint &CurConstraint) {
3191 const Loop *CurLoop = CurConstraint.getAssociatedLoop();
3192 const SCEV *A_K = findCoefficient(Src, CurLoop);
3193 const SCEV *AP_K = findCoefficient(Dst, CurLoop);
3194 const SCEV *XA_K = SE->getMulExpr(A_K, CurConstraint.getX());
3195 const SCEV *YAP_K = SE->getMulExpr(AP_K, CurConstraint.getY());
3197 Src = SE->getAddExpr(Src, SE->getMinusSCEV(XA_K, YAP_K));
3198 Src = zeroCoefficient(Src, CurLoop);
3201 Dst = zeroCoefficient(Dst, CurLoop);
3209 const Constraint &CurConstraint)
const {
3212 if (CurConstraint.isAny())
3214 else if (CurConstraint.isDistance()) {
3217 Level.
Distance = CurConstraint.getD();
3219 if (!SE->isKnownNonZero(Level.
Distance))
3221 if (!SE->isKnownNonPositive(Level.
Distance))
3223 if (!SE->isKnownNonNegative(Level.
Distance))
3227 else if (CurConstraint.isLine()) {
3232 else if (CurConstraint.isPoint()) {
3237 CurConstraint.getY(),
3238 CurConstraint.getX()))
3242 CurConstraint.getY(),
3243 CurConstraint.getX()))
3247 CurConstraint.getY(),
3248 CurConstraint.getX()))
3272 const SCEV *SrcAccessFn =
3273 SE->getSCEVAtScope(SrcPtr, SrcLoop);
3274 const SCEV *DstAccessFn =
3275 SE->getSCEVAtScope(DstPtr, DstLoop);
3282 if (!SrcBase || !DstBase || SrcBase != DstBase)
3285 const SCEV *ElementSize = SE->getElementSize(Src);
3286 if (ElementSize != SE->getElementSize(Dst))
3289 const SCEV *SrcSCEV = SE->getMinusSCEV(SrcAccessFn, SrcBase);
3290 const SCEV *DstSCEV = SE->getMinusSCEV(DstAccessFn, DstBase);
3294 if (!SrcAR || !DstAR || !SrcAR->
isAffine() || !DstAR->isAffine())
3299 SE->collectParametricTerms(SrcAR, Terms);
3300 SE->collectParametricTerms(DstAR, Terms);
3304 SE->findArrayDimensions(Terms, Sizes, ElementSize);
3308 SE->computeAccessFunctions(SrcAR, SrcSubscripts, Sizes);
3309 SE->computeAccessFunctions(DstAR, DstSubscripts, Sizes);
3312 if (SrcSubscripts.
size() < 2 || DstSubscripts.
size() < 2 ||
3313 SrcSubscripts.
size() != DstSubscripts.
size())
3325 for (
int i = 1; i <
size; ++i) {
3329 if (!isKnownLessThan(SrcSubscripts[i], Sizes[i - 1]))
3335 if (!isKnownLessThan(DstSubscripts[i], Sizes[i - 1]))
3340 dbgs() <<
"\nSrcSubscripts: ";
3341 for (
int i = 0; i <
size; i++)
3342 dbgs() << *SrcSubscripts[i];
3343 dbgs() <<
"\nDstSubscripts: ";
3344 for (
int i = 0; i <
size; i++)
3345 dbgs() << *DstSubscripts[i];
3353 for (
int i = 0; i <
size; ++i) {
3354 Pair[i].Src = SrcSubscripts[i];
3355 Pair[i].Dst = DstSubscripts[i];
3356 unifySubscriptType(&Pair[i]);
3401 std::unique_ptr<Dependence>
3403 bool PossiblyLoopIndependent) {
3405 PossiblyLoopIndependent =
false;
3413 LLVM_DEBUG(
dbgs() <<
"can only handle simple loads and stores\n");
3414 return std::make_unique<Dependence>(Src, Dst);
3429 return std::make_unique<Dependence>(Src, Dst);
3439 establishNestingLevels(Src, Dst);
3440 LLVM_DEBUG(
dbgs() <<
" common nesting levels = " << CommonLevels <<
"\n");
3441 LLVM_DEBUG(
dbgs() <<
" maximum nesting levels = " << MaxLevels <<
"\n");
3443 FullDependence Result(Src, Dst, PossiblyLoopIndependent, CommonLevels);
3448 const SCEV *SrcSCEV = SE->getSCEV(SrcPtr);
3449 const SCEV *DstSCEV = SE->getSCEV(DstPtr);
3452 Pair[0].Src = SrcSCEV;
3453 Pair[0].Dst = DstSCEV;
3456 if (tryDelinearize(Src, Dst, Pair)) {
3458 Pairs = Pair.
size();
3462 for (
unsigned P = 0;
P < Pairs; ++
P) {
3463 Pair[
P].Loops.
resize(MaxLevels + 1);
3464 Pair[
P].GroupLoops.
resize(MaxLevels + 1);
3466 removeMatchingExtensions(&Pair[
P]);
3467 Pair[
P].Classification =
3468 classifyPair(Pair[P].Src, LI->getLoopFor(Src->getParent()),
3469 Pair[P].Dst, LI->getLoopFor(Dst->getParent()),
3471 Pair[
P].GroupLoops = Pair[
P].Loops;
3472 Pair[
P].Group.set(P);
3476 LLVM_DEBUG(
dbgs() <<
"\tclass = " << Pair[P].Classification <<
"\n");
3541 for (
unsigned SI = 0;
SI < Pairs; ++
SI) {
3542 if (Pair[
SI].Classification == Subscript::NonLinear) {
3544 ++NonlinearSubscriptPairs;
3545 collectCommonLoops(Pair[
SI].Src,
3546 LI->getLoopFor(Src->getParent()),
3548 collectCommonLoops(Pair[
SI].Dst,
3549 LI->getLoopFor(Dst->getParent()),
3551 Result.Consistent =
false;
3552 }
else if (Pair[
SI].Classification == Subscript::ZIV) {
3559 for (
unsigned SJ =
SI + 1; SJ < Pairs; ++SJ) {
3561 Intersection &= Pair[SJ].GroupLoops;
3562 if (Intersection.
any()) {
3564 Pair[SJ].GroupLoops |= Pair[
SI].GroupLoops;
3566 Pair[SJ].Group |= Pair[
SI].Group;
3571 if (Pair[
SI].Group.count() == 1) {
3573 ++SeparableSubscriptPairs;
3577 ++CoupledSubscriptPairs;
3588 Constraint NewConstraint;
3589 NewConstraint.setAny(SE);
3594 switch (Pair[
SI].Classification) {
3595 case Subscript::ZIV:
3597 if (testZIV(Pair[
SI].Src, Pair[
SI].Dst, Result))
3600 case Subscript::SIV: {
3603 const SCEV *SplitIter =
nullptr;
3604 if (testSIV(Pair[
SI].Src, Pair[
SI].Dst, Level, Result, NewConstraint,
3609 case Subscript::RDIV:
3611 if (testRDIV(Pair[
SI].Src, Pair[
SI].Dst, Result))
3614 case Subscript::MIV:
3616 if (testMIV(Pair[
SI].Src, Pair[
SI].Dst, Pair[
SI].Loops, Result))
3624 if (Coupled.
count()) {
3627 LLVM_DEBUG(
dbgs() <<
"MaxLevels + 1 = " << MaxLevels + 1 <<
"\n");
3629 for (
unsigned II = 0; II <= MaxLevels; ++II)
3630 Constraints[II].setAny(SE);
3638 for (
unsigned SJ : Group.
set_bits()) {
3640 if (Pair[SJ].Classification == Subscript::SIV)
3646 unifySubscriptType(PairsInGroup);
3648 while (Sivs.
any()) {
3649 bool Changed =
false;
3650 for (
unsigned SJ : Sivs.
set_bits()) {
3654 const SCEV *SplitIter =
nullptr;
3656 if (testSIV(Pair[SJ].Src, Pair[SJ].Dst, Level, Result, NewConstraint,
3659 ConstrainedLevels.
set(Level);
3660 if (intersectConstraints(&Constraints[Level], &NewConstraint)) {
3661 if (Constraints[Level].isEmpty()) {
3662 ++DeltaIndependence;
3674 for (
unsigned SJ : Mivs.
set_bits()) {
3677 if (
propagate(Pair[SJ].Src, Pair[SJ].Dst, Pair[SJ].Loops,
3678 Constraints, Result.Consistent)) {
3680 ++DeltaPropagations;
3681 Pair[SJ].Classification =
3682 classifyPair(Pair[SJ].Src, LI->getLoopFor(Src->getParent()),
3683 Pair[SJ].Dst, LI->getLoopFor(Dst->getParent()),
3685 switch (Pair[SJ].Classification) {
3686 case Subscript::ZIV:
3688 if (testZIV(Pair[SJ].Src, Pair[SJ].Dst, Result))
3692 case Subscript::SIV:
3696 case Subscript::RDIV:
3697 case Subscript::MIV:
3708 for (
unsigned SJ : Mivs.
set_bits()) {
3709 if (Pair[SJ].Classification == Subscript::RDIV) {
3711 if (testRDIV(Pair[SJ].Src, Pair[SJ].Dst, Result))
3721 for (
unsigned SJ : Mivs.
set_bits()) {
3722 if (Pair[SJ].Classification == Subscript::MIV) {
3724 if (testMIV(Pair[SJ].Src, Pair[SJ].Dst, Pair[SJ].Loops, Result))
3733 for (
unsigned SJ : ConstrainedLevels.
set_bits()) {
3734 if (SJ > CommonLevels)
3736 updateDirection(Result.DV[SJ - 1], Constraints[SJ]);
3745 for (
unsigned SI = 0;
SI < Pairs; ++
SI)
3746 CompleteLoops |= Pair[
SI].Loops;
3747 for (
unsigned II = 1; II <= CommonLevels; ++II)
3748 if (CompleteLoops[II])
3749 Result.DV[II - 1].Scalar =
false;
3751 if (PossiblyLoopIndependent) {
3755 for (
unsigned II = 1; II <= CommonLevels; ++II) {
3757 Result.LoopIndependent =
false;
3765 bool AllEqual =
true;
3766 for (
unsigned II = 1; II <= CommonLevels; ++II) {
3776 return std::make_unique<FullDependence>(std::move(Result));
3827 unsigned SplitLevel) {
3829 "Dep should be splitable at SplitLevel");
3832 assert(Src->mayReadFromMemory() || Src->mayWriteToMemory());
3843 establishNestingLevels(Src, Dst);
3849 const SCEV *SrcSCEV = SE->getSCEV(SrcPtr);
3850 const SCEV *DstSCEV = SE->getSCEV(DstPtr);
3851 Pair[0].Src = SrcSCEV;
3852 Pair[0].Dst = DstSCEV;
3855 if (tryDelinearize(Src, Dst, Pair)) {
3857 Pairs = Pair.
size();
3861 for (
unsigned P = 0;
P < Pairs; ++
P) {
3862 Pair[
P].Loops.
resize(MaxLevels + 1);
3863 Pair[
P].GroupLoops.
resize(MaxLevels + 1);
3865 removeMatchingExtensions(&Pair[
P]);
3866 Pair[
P].Classification =
3867 classifyPair(Pair[P].Src, LI->getLoopFor(Src->getParent()),
3868 Pair[P].Dst, LI->getLoopFor(Dst->getParent()),
3870 Pair[
P].GroupLoops = Pair[
P].Loops;
3871 Pair[
P].Group.set(P);
3878 for (
unsigned SI = 0;
SI < Pairs; ++
SI) {
3879 if (Pair[
SI].Classification == Subscript::NonLinear) {
3881 collectCommonLoops(Pair[
SI].Src,
3882 LI->getLoopFor(Src->getParent()),
3884 collectCommonLoops(Pair[
SI].Dst,
3885 LI->getLoopFor(Dst->getParent()),
3887 Result.Consistent =
false;
3889 else if (Pair[
SI].Classification == Subscript::ZIV)
3894 for (
unsigned SJ =
SI + 1; SJ < Pairs; ++SJ) {
3896 Intersection &= Pair[SJ].GroupLoops;
3897 if (Intersection.
any()) {
3899 Pair[SJ].GroupLoops |= Pair[
SI].GroupLoops;
3901 Pair[SJ].Group |= Pair[
SI].Group;
3906 if (Pair[
SI].Group.count() == 1)
3914 Constraint NewConstraint;
3915 NewConstraint.setAny(SE);
3919 switch (Pair[
SI].Classification) {
3920 case Subscript::SIV: {
3922 const SCEV *SplitIter =
nullptr;
3923 (void) testSIV(Pair[
SI].Src, Pair[
SI].Dst, Level,
3924 Result, NewConstraint, SplitIter);
3925 if (Level == SplitLevel) {
3926 assert(SplitIter !=
nullptr);
3931 case Subscript::ZIV:
3932 case Subscript::RDIV:
3933 case Subscript::MIV:
3940 if (Coupled.
count()) {
3943 for (
unsigned II = 0; II <= MaxLevels; ++II)
3944 Constraints[II].setAny(SE);
3950 for (
unsigned SJ : Group.
set_bits()) {
3951 if (Pair[SJ].Classification == Subscript::SIV)
3956 while (Sivs.
any()) {
3957 bool Changed =
false;
3958 for (
unsigned SJ : Sivs.
set_bits()) {
3961 const SCEV *SplitIter =
nullptr;
3962 (void) testSIV(Pair[SJ].Src, Pair[SJ].Dst, Level,
3963 Result, NewConstraint, SplitIter);
3964 if (Level == SplitLevel && SplitIter)
3966 ConstrainedLevels.
set(Level);
3967 if (intersectConstraints(&Constraints[Level], &NewConstraint))
3973 for (
unsigned SJ : Mivs.
set_bits()) {
3975 if (
propagate(Pair[SJ].Src, Pair[SJ].Dst,
3976 Pair[SJ].Loops, Constraints, Result.Consistent)) {
3977 Pair[SJ].Classification =
3978 classifyPair(Pair[SJ].Src, LI->getLoopFor(Src->getParent()),
3979 Pair[SJ].Dst, LI->getLoopFor(Dst->getParent()),
3981 switch (Pair[SJ].Classification) {
3982 case Subscript::ZIV:
3985 case Subscript::SIV:
3989 case Subscript::RDIV:
3990 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;.
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...
bool invalidate(IRUnitT &IR, const PreservedAnalyses &PA)
Trigger the invalidation of some other analysis pass if not already handled and return whether it was...
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
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.
AnalysisPass to compute dependence information in a function.
This class represents lattice values for constants.
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. ...
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."))
static constexpr LocationSize unknown()
Legacy pass manager pass to access dependence information.
unsigned getLoopDepth() const
Return the nesting level of this loop.
void push_back(const T &Elt)
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 greater than comparison.
static void dump(StringRef Title, SpillInfo const &Spills)
STATISTIC(NumFunctions, "Total number of functions")
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)
PreservedAnalysisChecker getChecker() const
Build a checker for this PreservedAnalyses and the specified analysis type.
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.
const Value * getLoadStorePointerOperand(const Value *V)
A helper function that returns the pointer operand of a load or store instruction.
#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...
Direction
An enum for the direction of the loop.
void initializeDependenceAnalysisWrapperPassPass(PassRegistry &)
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)
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 isKnownNonNegative(const Value *V, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true)
Returns true if the give value is known to be non-negative.
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")
A set of analyses that are preserved following a run of a transformation pass.
* 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...
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)
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
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.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM)
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.
StringRef getName() const
Return a constant reference to the value's name.
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)
API to communicate dependencies between analyses during invalidation.
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())
This templated class represents "all analyses that operate over <a particular IR unit>" (e...
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.
bool invalidate(Function &F, const PreservedAnalyses &PA, FunctionAnalysisManager::Invalidator &Inv)
Handle transitive invalidation when the cached analysis results go away.
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...
static cl::opt< bool > DisableDelinearizationChecks("da-disable-delinearization-checks", cl::init(false), cl::Hidden, cl::ZeroOrMore, cl::desc("Disable checks that try to statically verify validity of " "delinearized subscripts. Enabling this option may result in incorrect " "dependence vectors for languages that allow the subscript of one " "dimension to underflow or overflow into another dimension."))
size_type count() const
Returns the number of bits which are set.
const BasicBlock * getParent() const
This class represents a constant integer value.
bool mayReadOrWriteMemory() const
Return true if this instruction may read or write memory.