@@ -90,7 +90,7 @@ class CanonicalLoopLabeler : public MatchFinder::MatchCallback {
9090 DIMemoryClientServerInfo &DIMInfo, CanonicalLoopSet *CLI)
9191 : mRgnInfo(&DFRI), mLoopInfo(&LM), mMemoryMatcher(&MM),
9292 mAliasTree(&AT), mTLI(&TLI), mSE(&SE), mDIMInfo(&DIMInfo),
93- mDT(&DT), mCanonicalLoopInfo(CLI), mSTR(DIMInfo.DIAT) {}
93+ mDT(&DT), mCanonicalLoopInfo(CLI) {}
9494
9595 // / \brief This function is called each time LoopMatcher finds appropriate
9696 // / loop.
@@ -262,12 +262,13 @@ class CanonicalLoopLabeler : public MatchFinder::MatchCallback {
262262
263263 // / Finds a last instruction in a specified block which writes memory
264264 // / from a specified node.
265- Instruction* findLastWrite (DIMemory &DIMI, BasicBlock *BB) {
265+ Instruction* findLastWrite (DIMemory &DIMI, BasicBlock *BB,
266+ const SpanningTreeRelation<const DIAliasTree *> &STR) {
266267 auto *DINI = DIMI.getAliasNode ();
267268 for (auto I = BB->rbegin (), E = BB->rend (); I != E; ++I) {
268269 bool RequiredInstruction = false ;
269270 for_each_memory (*I, *mTLI ,
270- [this , DINI, &RequiredInstruction] (Instruction &I,
271+ [this , &STR, DINI, &RequiredInstruction] (Instruction &I,
271272 MemoryLocation &&Loc, unsigned Idx, AccessInfo, AccessInfo W) {
272273 if (W == AccessInfo::No)
273274 return ;
@@ -277,9 +278,9 @@ class CanonicalLoopLabeler : public MatchFinder::MatchCallback {
277278 auto *DIM = mDIMInfo ->findFromClient (
278279 *EM->getTopLevelParent (), DL, *mDT ).get <Clone>();
279280 RequiredInstruction |=
280- (!DIM || !mSTR .isUnreachable (DINI, DIM->getAliasNode ()));
281+ (!DIM || !STR .isUnreachable (DINI, DIM->getAliasNode ()));
281282 },
282- [this , &DINI, &RequiredInstruction] (Instruction &I, AccessInfo,
283+ [this , &STR, & DINI, &RequiredInstruction] (Instruction &I, AccessInfo,
283284 AccessInfo W) {
284285 if (W == AccessInfo::No)
285286 return ;
@@ -291,7 +292,7 @@ class CanonicalLoopLabeler : public MatchFinder::MatchCallback {
291292 auto DIM = mDIMInfo ->findFromClient (
292293 I, *mDT , DIUnknownMemory::NoFlags).get <Clone>();
293294 RequiredInstruction |=
294- (!DIM || !mSTR .isUnreachable (DINI, DIM->getAliasNode ()));
295+ (!DIM || !STR .isUnreachable (DINI, DIM->getAliasNode ()));
295296 }
296297 );
297298 if (RequiredInstruction)
@@ -330,6 +331,7 @@ class CanonicalLoopLabeler : public MatchFinder::MatchCallback {
330331 // / induction variable or `nullptr`,
331332 // / - instruction accesses this operand or `nullptr`.
332333 std::tuple<bool , unsigned , unsigned , Value *, Value *> isLoopInvariantMemory (
334+ const SpanningTreeRelation<const DIAliasTree *> &STR,
333335 const DIDependenceSet &DIDepSet, DIMemory &DIMI, User &U) {
334336 bool Result = true ;
335337 unsigned InductUseNum = 0 , InductDefNum = 0 ;
@@ -338,7 +340,7 @@ class CanonicalLoopLabeler : public MatchFinder::MatchCallback {
338340 auto &DL = Inst->getModule ()->getDataLayout ();
339341 auto *DINI = DIMI.getAliasNode ();
340342 for_each_memory (*Inst, *mTLI ,
341- [this , Inst, DL, DINI, &DIDepSet,
343+ [this , &STR, Inst, DL, DINI, &DIDepSet,
342344 &Result, &InductUseNum, &InductDefNum, &InductIdx](
343345 Instruction &, MemoryLocation &&Loc, unsigned Idx,
344346 AccessInfo R, AccessInfo W) {
@@ -351,7 +353,7 @@ class CanonicalLoopLabeler : public MatchFinder::MatchCallback {
351353 // / TODO ([email protected] ): investigate cases when DIM is nullptr. 352354 if (!(Result = DIM))
353355 return ;
354- if (!mSTR .isUnreachable (DIM->getAliasNode (), DINI)) {
356+ if (!STR .isUnreachable (DIM->getAliasNode (), DINI)) {
355357 if (R != AccessInfo::No || W != AccessInfo::No)
356358 InductIdx.insert (Idx);
357359 if (R != AccessInfo::No)
@@ -386,7 +388,7 @@ class CanonicalLoopLabeler : public MatchFinder::MatchCallback {
386388 bool OpNotAccessInduct = true ;
387389 for (auto &Op : U.operands ())
388390 if (isa<Instruction>(Op) || isa<ConstantExpr>(Op)) {
389- auto T = isLoopInvariantMemory (DIDepSet, DIMI, cast<User>(*Op));
391+ auto T = isLoopInvariantMemory (STR, DIDepSet, DIMI, cast<User>(*Op));
390392 std::get<0 >(Tuple) &= std::get<0 >(T);
391393 if (!std::get<0 >(Tuple))
392394 return Tuple;
@@ -444,7 +446,8 @@ class CanonicalLoopLabeler : public MatchFinder::MatchCallback {
444446 " for induction\n " );
445447 return ;
446448 }
447- Instruction *Init = findLastWrite (*DIMI, L->getLoopPreheader ());
449+ SpanningTreeRelation<const DIAliasTree *> STR (mDIMInfo ->DIAT );
450+ Instruction *Init = findLastWrite (*DIMI, L->getLoopPreheader (), STR);
448451 assert (Init && " Init instruction should not be nullptr!" );
449452 Instruction *Condition = findLastCmp (L->getHeader ());
450453 assert (Condition && " Condition instruction should not be nullptr!" );
@@ -462,7 +465,7 @@ class CanonicalLoopLabeler : public MatchFinder::MatchCallback {
462465 for (auto *BB: L->blocks ()) {
463466 int NumOfWrites = 0 ;
464467 for_each_memory (*BB, *mTLI ,
465- [this , &DL, DINI, &NumOfWrites, &Increment] (Instruction &I,
468+ [this , &STR, & DL, DINI, &NumOfWrites, &Increment] (Instruction &I,
466469 MemoryLocation &&Loc, unsigned Idx, AccessInfo, AccessInfo W) {
467470 if (W == AccessInfo::No)
468471 return ;
@@ -473,18 +476,18 @@ class CanonicalLoopLabeler : public MatchFinder::MatchCallback {
473476 // / TODO ([email protected] ): investigate cases when DIM is nullptr. 474477 if (!DIM) {
475478 ++NumOfWrites;
476- } else if (!mSTR .isUnreachable (DINI, DIM->getAliasNode ())) {
479+ } else if (!STR .isUnreachable (DINI, DIM->getAliasNode ())) {
477480 ++NumOfWrites;
478481 Increment = &I;
479482 }
480483 },
481- [this , DINI, &NumOfWrites] (Instruction &I, AccessInfo, AccessInfo W) {
484+ [this , &STR, DINI, &NumOfWrites] (Instruction &I, AccessInfo, AccessInfo W) {
482485 if (W == AccessInfo::No)
483486 return ;
484487 auto *DIM = mDIMInfo ->findFromClient (
485488 I, *mDT , DIUnknownMemory::NoFlags).get <Clone>();
486489 // / TODO ([email protected] ): investigate cases when DIM is nullptr. 487- if (!DIM ||!mSTR .isUnreachable (DINI, DIM->getAliasNode ()))
490+ if (!DIM ||!STR .isUnreachable (DINI, DIM->getAliasNode ()))
488491 ++NumOfWrites;
489492 }
490493 );
@@ -506,7 +509,7 @@ class CanonicalLoopLabeler : public MatchFinder::MatchCallback {
506509 Value *Expr;
507510 Value *Inst;
508511 std::tie (Result, InductUseNum, InductDefNum, Expr, Inst) =
509- isLoopInvariantMemory (*DIDepSet, *DIMI, *Init);
512+ isLoopInvariantMemory (STR, *DIDepSet, *DIMI, *Init);
510513 if (!Result || InductDefNum != 1 || InductUseNum > 0 )
511514 return ;
512515 LInfo->setStart (Expr);
@@ -516,7 +519,7 @@ class CanonicalLoopLabeler : public MatchFinder::MatchCallback {
516519 TSAR_LLVM_DUMP (Expr->dump ());
517520 });
518521 std::tie (Result, InductUseNum, InductDefNum, Expr, Inst) =
519- isLoopInvariantMemory (*DIDepSet, *DIMI, *Increment);
522+ isLoopInvariantMemory (STR, *DIDepSet, *DIMI, *Increment);
520523 if (!Result || InductDefNum != 1 || InductUseNum > 1 )
521524 return ;
522525 assert ((!Expr || Inst && isa<llvm::BinaryOperator>(Inst) &&
@@ -536,7 +539,7 @@ class CanonicalLoopLabeler : public MatchFinder::MatchCallback {
536539 TSAR_LLVM_DUMP (LInfo->getStep ()->dump ());
537540 });
538541 std::tie (Result, InductUseNum, InductDefNum, Expr, Inst) =
539- isLoopInvariantMemory (*DIDepSet, *DIMI, *Condition);
542+ isLoopInvariantMemory (STR, *DIDepSet, *DIMI, *Condition);
540543 if (!Result || InductDefNum != 0 || InductUseNum > 1 )
541544 return ;
542545 LInfo->setEnd (Expr);
@@ -564,7 +567,6 @@ class CanonicalLoopLabeler : public MatchFinder::MatchCallback {
564567 DominatorTree *mDT ;
565568 DIMemoryClientServerInfo *mDIMInfo ;
566569 CanonicalLoopSet *mCanonicalLoopInfo ;
567- SpanningTreeRelation<const DIAliasTree *> mSTR ;
568570};
569571
570572// / Returns LoopMatcher that matches loops that can be canonical.
0 commit comments