@@ -247,7 +247,7 @@ class AddUnknownAccessFunctor :
247247// / loop nest associated with region `R`, this value will be set to `false`,
248248// / `true` otherwise.
249249std::pair<MemoryLocationRange, bool > aggregate (
250- DFRegion *R, DFNode *Node, const MemoryLocationRange &Loc,
250+ DFRegion *R, const MemoryLocationRange &Loc,
251251 const ReachDFFwk *Fwk) {
252252 typedef MemoryLocationRange::Dimension Dimension;
253253 typedef MemoryLocationRange::LocKind LocKind;
@@ -344,11 +344,6 @@ std::pair<MemoryLocationRange, bool> aggregate(
344344 if (auto *DFL = dyn_cast<DFLoop>(R)) {
345345 assert (DFL->getLoop () && C->getLoop () &&
346346 " Loops for the DFLoop and AddRecExpr must be specified!" );
347- if (!DFL->getLoop ()->getExitingBlock () || !DFL->getLoop ()->getLoopLatch ()) {
348- LLVM_DEBUG (dbgs () << " [AGGREGATE] Multiple exiting and latch blocks "
349- " are prohibited.\n " );
350- break ;
351- }
352347 if (DFL->getLoop ()->contains (C->getLoop ()))
353348 ++LoopMatchCount;
354349 }
@@ -358,23 +353,23 @@ std::pair<MemoryLocationRange, bool> aggregate(
358353 break ;
359354 }
360355 auto AddRecStep = cast<SCEVConstant>(StepSCEV)->getAPInt ().getSExtValue ();
356+ if (!C->getLoop ()->getExitingBlock () || !C->getLoop ()->getLoopLatch ()) {
357+ LLVM_DEBUG (dbgs () << " [AGGREGATE] Multiple exiting and latch blocks "
358+ " are prohibited.\n " );
359+ break ;
360+ }
361361 unsigned int TripCount = 0 ;
362- if (auto *DFL = dyn_cast<DFLoop>(R)) {
363- auto Loop = DFL->getLoop ();
364- if (Loop->getLoopLatch () == Loop->getExitingBlock () &&
365- Loop->getLoopLatch () != nullptr ) {
366- LLVM_DEBUG (dbgs () << " [AGGREGATE] Node kind: Latch and Exiting.\n " );
367- TripCount = SE->getSmallConstantTripCount (C->getLoop ());
368- } else {
369- LLVM_DEBUG (dbgs () << " [AGGREGATE] Node kind: Latch or Exiting.\n " );
370- auto BTC = SE->getBackedgeTakenCount (C->getLoop ());
371- if (isa<SCEVConstant>(BTC))
372- TripCount = cast<SCEVConstant>(BTC)->getAPInt ().getZExtValue ();
373- }
374- LLVM_DEBUG (dbgs () << " [AGGREGATE] Total trip count: " << TripCount << " \n " );
362+ if (C->getLoop ()->getLoopLatch () == C->getLoop ()->getExitingBlock ()) {
363+ LLVM_DEBUG (dbgs () << " [AGGREGATE] Node kind: Latch and Exiting.\n " );
364+ TripCount = SE->getSmallConstantTripCount (C->getLoop ());
365+ } else {
366+ LLVM_DEBUG (dbgs () << " [AGGREGATE] Node kind: Latch or Exiting.\n " );
367+ auto BTC = SE->getBackedgeTakenCount (C->getLoop ());
368+ if (isa<SCEVConstant>(BTC))
369+ TripCount = cast<SCEVConstant>(BTC)->getAPInt ().getZExtValue ();
375370 }
376- if (TripCount > 1 ) {
377- LLVM_DEBUG (dbgs () << " [AGGREGATE] Aggregate constant range.\n " );
371+ if (TripCount > 0 ) {
372+ LLVM_DEBUG (dbgs () << " [AGGREGATE] Aggregate a constant range.\n " );
378373 int64_t SignedRangeMin = SE->getSignedRangeMin (SCEV).getSExtValue ();
379374 if (SignedRangeMin < 0 ) {
380375 LLVM_DEBUG (dbgs () << " [AGGREGATE] Range bounds must be "
@@ -384,7 +379,7 @@ std::pair<MemoryLocationRange, bool> aggregate(
384379 DimInfo.Start = SE->getConstant (SCEV->getType (), SignedRangeMin);
385380 DimInfo.End = SE->getConstant (SCEV->getType (),
386381 SignedRangeMin + std::abs (AddRecStep) * (TripCount - 1 ));
387- } else if (TripCount == 0 ) {
382+ } else {
388383 if (std::abs (AddRecStep) != 1 )
389384 break ;
390385 auto Bounds = C->getLoop ()->getBounds (*SE);
@@ -433,13 +428,14 @@ std::pair<MemoryLocationRange, bool> aggregate(
433428 if (Bounds->getDirection () == Loop::LoopBounds::Direction::Increasing) {
434429 if (Predicate == Predicate::ICMP_SLT ||
435430 Predicate == Predicate::ICMP_ULT) {
436- FinalSCEV = SE->getMinusSCEV (FinalSCEV, SE->getOne (FinalSCEV->getType ()));
431+ FinalSCEV = SE->getMinusSCEV (FinalSCEV,
432+ SE->getOne (FinalSCEV->getType ()));
437433 }
438434 } else {
439- // std::swap(InitSCEV, FinalSCEV);
440435 if (Predicate == Predicate::ICMP_SGT ||
441436 Predicate == Predicate::ICMP_UGT) {
442- FinalSCEV = SE->getAddExpr (SE->getOne (FinalSCEV->getType ()), FinalSCEV);
437+ FinalSCEV = SE->getAddExpr (SE->getOne (FinalSCEV->getType ()),
438+ FinalSCEV);
443439 }
444440 }
445441 auto ZeroItr = C->evaluateAtIteration (SE->getZero (C->getType ()), *SE);
@@ -468,11 +464,9 @@ std::pair<MemoryLocationRange, bool> aggregate(
468464 LLVM_DEBUG (dbgs () << " [AGGREGATE] Incorrect bounds.\n " );
469465 break ;
470466 }
471- } else {
472- LLVM_DEBUG (dbgs () << " [AGGREGATE] Invalid trip count.\n " );
473- break ;
474467 }
475- DimInfo.Step = SE->getConstant (C->getStepRecurrence (*SE)->getType (), std::abs (AddRecStep));
468+ DimInfo.Step = SE->getConstant (C->getStepRecurrence (*SE)->getType (),
469+ std::abs (AddRecStep));
476470 assert (DimInfo.Start && DimInfo.End && DimInfo.Step &&
477471 " Dimension bounds and step must be specified!" );
478472 if (isa<SCEVConstant>(DimInfo.End ) &&
@@ -582,14 +576,12 @@ class AddKnownAccessFunctor :
582576
583577private:
584578 void addMust (const MemoryLocationRange &Loc) {
585- static_cast <ImpTy *>(this )->addMust (
586- aggregate (nullptr , nullptr , Loc, DFF).first );
579+ static_cast <ImpTy *>(this )->addMust (aggregate (nullptr , Loc, DFF).first );
587580 static_cast <ImpTy *>(this )->addMust (Loc);
588581 }
589582
590583 void addMay (const MemoryLocationRange &Loc) {
591- static_cast <ImpTy *>(this )->addMay (
592- aggregate (nullptr , nullptr , Loc, DFF).first );
584+ static_cast <ImpTy *>(this )->addMay (aggregate (nullptr , Loc, DFF).first );
593585 static_cast <ImpTy *>(this )->addMay (Loc);
594586 }
595587
@@ -1035,7 +1027,6 @@ void ReachDFFwk::collapse(DFRegion *R) {
10351027 dbgs () << " (" << Loc.getKindAsString () << " )\n " ;
10361028 };
10371029 #endif
1038- // llvm::SmallVector<std::pair<MemoryLocationRange, DFNode *>, 16> ExpAccessesWithNodes;
10391030 for (DFNode *N : R->getNodes ()) {
10401031 auto DefItr = getDefInfo ().find (N);
10411032 assert (DefItr != getDefInfo ().end () &&
@@ -1059,7 +1050,7 @@ void ReachDFFwk::collapse(DFRegion *R) {
10591050 continue ;
10601051 }
10611052 LLVM_DEBUG (printLocInfo (" [COLLAPSE] Collapse Use location: " , Loc));
1062- distribute (aggregate (R, N, Loc, this ), Loc, OwnUses, OtherUses);
1053+ distribute (aggregate (R, Loc, this ), Loc, OwnUses, OtherUses);
10631054 }
10641055 OwnUses.clarify (OtherUses);
10651056 for (auto &Loc : OwnUses) {
@@ -1125,12 +1116,12 @@ void ReachDFFwk::collapse(DFRegion *R) {
11251116 for (auto &L : Locs) {
11261117 LLVM_DEBUG (printLocInfo (
11271118 " [COLLAPSE] Add location from a latch node: " , L));
1128- distribute (aggregate (R, N, L, this ), Loc, OwnDefs, OtherDefs);
1119+ distribute (aggregate (R, L, this ), Loc, OwnDefs, OtherDefs);
11291120 }
11301121 } else {
11311122 LLVM_DEBUG (printLocInfo (
11321123 " [COLLAPSE] Collapse MayDef location of a latch node: " , Loc));
1133- distribute (aggregate (R, N, Loc, this ), Loc, OwnMayDefs, OtherMayDefs);
1124+ distribute (aggregate (R, Loc, this ), Loc, OwnMayDefs, OtherMayDefs);
11341125 }
11351126 }
11361127 LLVM_DEBUG (dbgs () << " [COLLAPSE] Check ExitingDefs.\n " );
@@ -1139,11 +1130,11 @@ void ReachDFFwk::collapse(DFRegion *R) {
11391130 if (!Locs.empty ()) {
11401131 for (auto &L : Locs) {
11411132 LLVM_DEBUG (printLocInfo (" [COLLAPSE] Collapse Def location: " , L));
1142- distribute (aggregate (R, N, L, this ), Loc, OwnDefs, OtherDefs);
1133+ distribute (aggregate (R, L, this ), Loc, OwnDefs, OtherDefs);
11431134 }
11441135 } else {
11451136 LLVM_DEBUG (printLocInfo (" [COLLAPSE] Collapse MayDef location: " , Loc));
1146- distribute (aggregate (R, N, Loc, this ), Loc, OwnMayDefs, OtherMayDefs);
1137+ distribute (aggregate (R, Loc, this ), Loc, OwnMayDefs, OtherMayDefs);
11471138 }
11481139 }
11491140 OwnDefs.clarify (OtherDefs);
@@ -1152,12 +1143,10 @@ void ReachDFFwk::collapse(DFRegion *R) {
11521143 if (Loc.Kind & MemoryLocationRange::LocKind::Hint)
11531144 continue ;
11541145 LLVM_DEBUG (printLocInfo (" [COLLAPSE] Collapse MayDef location: " , Loc));
1155- distribute (aggregate (R, N, Loc, this ), Loc, OwnMayDefs, OtherMayDefs);
1146+ distribute (aggregate (R, Loc, this ), Loc, OwnMayDefs, OtherMayDefs);
11561147 }
11571148 OwnMayDefs.clarify (OtherMayDefs);
11581149 DefUse->addMayDefs (OwnMayDefs);
1159- // for (auto &ExpLoc: DU->getExplicitAccesses())
1160- // ExpAccessesWithNodes.push_back(std::make_pair(ExpLoc, N));
11611150 DefUse->addExplicitAccesses (DU->getExplicitAccesses ());
11621151 DefUse->addExplicitUnknowns (DU->getExplicitUnknowns ());
11631152 for (auto Loc : DU->getAddressAccesses ())
@@ -1170,9 +1159,7 @@ void ReachDFFwk::collapse(DFRegion *R) {
11701159 for (auto Inst : DU->getUnknownInsts ())
11711160 DefUse->addUnknownInst (Inst);
11721161 }
1173- for (auto &ExpNode : DefUse->getExplicitAccesses ()) {
1174- auto &Loc = ExpNode/* .first*/ ;
1175- // DefUse->addExplicitAccess(Loc);
1162+ for (auto &Loc : DefUse->getExplicitAccesses ()) {
11761163 auto *EM{AT.find (Loc)};
11771164 if (EM) {
11781165 if (auto *DFL{dyn_cast<DFLoop>(R)})
@@ -1187,7 +1174,7 @@ void ReachDFFwk::collapse(DFRegion *R) {
11871174 EM = EM->getTopLevelParent ();
11881175 }
11891176 LLVM_DEBUG (printLocInfo (" [COLLAPSE] Collapse Explicit Access: " , Loc));
1190- MemoryLocationRange ExpLoc = aggregate (R, /* ExpNode.second */ nullptr , Loc, this ).first ;
1177+ MemoryLocationRange ExpLoc = aggregate (R, Loc, this ).first ;
11911178 MemoryLocationRange NewLoc (Loc);
11921179 NewLoc.Kind |= MemoryLocationRange::LocKind::Hint;
11931180 // We use top-level parent (EM) if it is available to update def-use set.
0 commit comments