@@ -82,15 +82,19 @@ namespace {
8282// / This class visits and analyzes all matched for-loops in a source code.
8383class CanonicalLoopLabeler : public MatchFinder ::MatchCallback {
8484public:
85- // / Creates visitor.
86- explicit CanonicalLoopLabeler (DFRegionInfo &DFRI,
87- const LoopMatcherPass::LoopMatcher &LM,
88- const MemoryMatchInfo::MemoryMatcher &MM, AliasTree &AT,
89- TargetLibraryInfo &TLI, ScalarEvolution &SE, DominatorTree &DT,
90- DIMemoryClientServerInfo &DIMInfo, CanonicalLoopSet *CLI)
91- : mRgnInfo(&DFRI), mLoopInfo(&LM), mMemoryMatcher(&MM),
92- mAliasTree(&AT), mTLI(&TLI), mSE(&SE), mDIMInfo(&DIMInfo),
93- mDT(&DT), mCanonicalLoopInfo(CLI) {}
85+ CanonicalLoopLabeler (FunctionPass &P, Function &F, CanonicalLoopSet &CLI)
86+ : mCanonicalLoopInfo (&CLI) {
87+ mRgnInfo = &P.getAnalysis <DFRegionInfoPass>().getRegionInfo ();
88+ mLoopInfo = &P.getAnalysis <LoopMatcherPass>().getMatcher ();
89+ mMemoryMatcher = &P.getAnalysis <MemoryMatcherImmutableWrapper>()->Matcher ;
90+ mAliasTree = &P.getAnalysis <EstimateMemoryPass>().getAliasTree ();
91+ mTLI = &P.getAnalysis <TargetLibraryInfoWrapperPass>().getTLI ();
92+ mSE = &P.getAnalysis <ScalarEvolutionWrapperPass>().getSE ();
93+ mDT = &P.getAnalysis <DominatorTreeWrapperPass>().getDomTree ();
94+ auto &DIEMPass = P.getAnalysis <DIEstimateMemoryPass>();
95+ if (DIEMPass.isConstructed ())
96+ mDIMInfo = DIMemoryClientServerInfo (DIEMPass.getAliasTree (), P, F);
97+ }
9498
9599 // / \brief This function is called each time LoopMatcher finds appropriate
96100 // / loop.
@@ -264,6 +268,8 @@ class CanonicalLoopLabeler : public MatchFinder::MatchCallback {
264268 // / from a specified node.
265269 Instruction* findLastWrite (DIMemory &DIMI, BasicBlock *BB,
266270 const SpanningTreeRelation<const DIAliasTree *> &STR) {
271+ assert (mDIMInfo && mDIMInfo ->isValid () &&
272+ " Client-to-server mapping must be available!" );
267273 auto *DINI = DIMI.getAliasNode ();
268274 for (auto I = BB->rbegin (), E = BB->rend (); I != E; ++I) {
269275 bool RequiredInstruction = false ;
@@ -280,8 +286,8 @@ class CanonicalLoopLabeler : public MatchFinder::MatchCallback {
280286 RequiredInstruction |=
281287 (!DIM || !STR.isUnreachable (DINI, DIM->getAliasNode ()));
282288 },
283- [this , &STR, &DINI, &RequiredInstruction] (Instruction &I, AccessInfo,
284- AccessInfo W) {
289+ [this , &STR, &DINI, &RequiredInstruction] (Instruction &I,
290+ AccessInfo, AccessInfo W) {
285291 if (W == AccessInfo::No)
286292 return ;
287293 // / TODO ([email protected] ): use results from server to check @@ -333,6 +339,8 @@ class CanonicalLoopLabeler : public MatchFinder::MatchCallback {
333339 std::tuple<bool , unsigned , unsigned , Value *, Value *> isLoopInvariantMemory (
334340 const SpanningTreeRelation<const DIAliasTree *> &STR,
335341 const DIDependenceSet &DIDepSet, DIMemory &DIMI, User &U) {
342+ assert (mDIMInfo && mDIMInfo ->isValid () &&
343+ " Client-to-server mapping must be available!" );
336344 bool Result = true ;
337345 unsigned InductUseNum = 0 , InductDefNum = 0 ;
338346 SmallSet<unsigned , 2 > InductIdx;
@@ -421,7 +429,7 @@ class CanonicalLoopLabeler : public MatchFinder::MatchCallback {
421429 // / \post The`LInfo` parameter will be updated. Start, end, step will be set
422430 // / is possible, and loop will be marked as canonical on success.
423431 void checkLoop (tsar::DFLoop* Region, VarDecl *Var, CanonicalLoopInfo *LInfo) {
424- if (!mDIMInfo ->isValid ())
432+ if (!mDIMInfo || ! mDIMInfo ->isValid ())
425433 return ;
426434 auto MemMatch = mMemoryMatcher ->find <AST>(Var);
427435 if (MemMatch == mMemoryMatcher ->end ())
@@ -558,15 +566,15 @@ class CanonicalLoopLabeler : public MatchFinder::MatchCallback {
558566 LInfo->markAsCanonical ();
559567 }
560568
561- DFRegionInfo * mRgnInfo ;
562- const LoopMatcherPass::LoopMatcher * mLoopInfo ;
563- const MemoryMatchInfo::MemoryMatcher * mMemoryMatcher ;
564- tsar::AliasTree * mAliasTree ;
565- TargetLibraryInfo * mTLI ;
566- ScalarEvolution * mSE ;
567- DominatorTree * mDT ;
568- DIMemoryClientServerInfo * mDIMInfo ;
569- CanonicalLoopSet * mCanonicalLoopInfo ;
569+ CanonicalLoopSet * mCanonicalLoopInfo = nullptr ;
570+ DFRegionInfo * mRgnInfo = nullptr ; ;
571+ const LoopMatcherPass::LoopMatcher * mLoopInfo = nullptr ;
572+ const MemoryMatchInfo::MemoryMatcher * mMemoryMatcher = nullptr ;
573+ AliasTree * mAliasTree = nullptr ;
574+ TargetLibraryInfo * mTLI = nullptr ;
575+ ScalarEvolution * mSE = nullptr ;
576+ DominatorTree * mDT = nullptr ;
577+ Optional<DIMemoryClientServerInfo> mDIMInfo ;
570578};
571579
572580// / Returns LoopMatcher that matches loops that can be canonical.
@@ -685,19 +693,8 @@ bool CanonicalLoopPass::runOnFunction(Function &F) {
685693 auto FuncDecl = TfmCtx->getDeclForMangledName (F.getName ());
686694 if (!FuncDecl)
687695 return false ;
688- auto &RgnInfo = getAnalysis<DFRegionInfoPass>().getRegionInfo ();
689- auto &LoopInfo = getAnalysis<LoopMatcherPass>().getMatcher ();
690- auto &MemInfo =
691- getAnalysis<MemoryMatcherImmutableWrapper>()->Matcher ;
692- auto &ATree = getAnalysis<EstimateMemoryPass>().getAliasTree ();
693- auto &TLI = getAnalysis<TargetLibraryInfoWrapperPass>().getTLI ();
694- auto &SE = getAnalysis<ScalarEvolutionWrapperPass>().getSE ();
695- auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree ();
696696 DeclarationMatcher LoopMatcher = makeLoopMatcher ();
697- DIMemoryClientServerInfo DIMInfo (
698- getAnalysis<DIEstimateMemoryPass>().getAliasTree (), *this , F);
699- CanonicalLoopLabeler Labeler (RgnInfo, LoopInfo, MemInfo, ATree,
700- TLI, SE, DT, DIMInfo, &mCanonicalLoopInfo );
697+ CanonicalLoopLabeler Labeler (*this , F, mCanonicalLoopInfo );
701698 auto &Context = FuncDecl->getASTContext ();
702699 auto Nodes = match<DeclarationMatcher, Decl>(LoopMatcher, *FuncDecl, Context);
703700 while (!Nodes.empty ()) {
0 commit comments