@@ -152,9 +152,6 @@ void ClangLoopSwap::getAnalysisUsage(AnalysisUsage &AU) const {
152152}
153153
154154namespace {
155- // inline void dbgPrintln(const char *Msg) {
156- // LLVM_DEBUG(dbgs() << DEBUG_PREFIX << Msg << "\n");
157- // }
158155class SwapClauseVisitor : public clang ::RecursiveASTVisitor<SwapClauseVisitor> {
159156public:
160157 bool VisitStringLiteral (clang::StringLiteral *SL) {
@@ -175,19 +172,21 @@ class ClangLoopSwapVisitor
175172 ClangLoopSwapVisitor (TransformationContext *TfmCtx,
176173 ClangGlobalInfoPass::RawInfo &RawInfo,
177174 MemoryMatchInfo::MemoryMatcher *Matcher,
178- const GlobalOptions *GO, AnalysisSocketInfo *SocketInfo ,
175+ const GlobalOptions *GO, AnalysisSocket &Socket ,
179176 ClangLoopSwap &Pass, llvm::Module &M)
180177 : mTfmCtx (TfmCtx), mRewriter (TfmCtx->getRewriter ()),
181178 mContext(TfmCtx->getContext ()), mSrcMgr(mRewriter .getSourceMgr()),
182- mLangOpts(mRewriter .getLangOpts()), mRawInfo(RawInfo),
183- mSocketInfo(SocketInfo), mPass(Pass), mModule(M),
184- mStatus(SEARCH_PRAGMA), mGO(GO), mDIAT(NULL ), mDIDepInfo(NULL ),
185- mMemMatcher(Matcher), mPerfectLoopInfo(NULL ), mCurrentLoops(NULL ),
186- mIsStrict(false ) {}
179+ mLangOpts(mRewriter .getLangOpts()), mRawInfo(RawInfo), mSocket(Socket),
180+ mPass(Pass), mModule(M), mMemMatcher(Matcher), mGO(GO),
181+ mClientToServer(
182+ **mSocket .getAnalysis<AnalysisClientServerMatcherWrapper>()
183+ ->value<AnalysisClientServerMatcherWrapper *>()),
184+ mStatus(SEARCH_PRAGMA), mIsStrict(false ), mDIAT(NULL ), mDIDepInfo(NULL ),
185+ mPerfectLoopInfo(NULL ), mCanonicalLoopInfo(NULL ) {}
187186 const CanonicalLoopInfo *getLoopInfo (clang::ForStmt *FS) {
188187 if (!FS)
189188 return NULL ;
190- for (auto Info : *mCurrentLoops ) {
189+ for (auto Info : *mCanonicalLoopInfo ) {
191190 if (Info->getASTLoop () == FS) {
192191 return Info;
193192 }
@@ -233,7 +232,8 @@ class ClangLoopSwapVisitor
233232 bool Dependency = false ;
234233 auto *Loop = LI->getLoop ()->getLoop ();
235234 auto *LoopID = Loop->getLoopID ();
236- auto DepItr = mDIDepInfo ->find (LoopID);
235+ auto ServerLoopID = cast<MDNode>(*mClientToServer .getMappedMD (LoopID));
236+ auto DepItr = mDIDepInfo ->find (ServerLoopID);
237237 if (DepItr == mDIDepInfo ->end ()) {
238238 mLoopsKinds [mLoopsKinds .size () - 1 ] = NO_ANALYSIS;
239239 } else {
@@ -280,7 +280,7 @@ class ClangLoopSwapVisitor
280280 Pragma P (*S);
281281 llvm::SmallVector<clang::Stmt *, 1 > Clauses;
282282 if (findClause (P, ClauseId::LoopSwap, Clauses)) {
283- LLVM_DEBUG (dbgs () << DEBUG_PREFIX << " Start pass \n " );
283+ LLVM_DEBUG (dbgs () << DEBUG_PREFIX << " Found swap clause \n " );
284284 // collect info from clauses
285285 SwapClauseVisitor SCV;
286286 for (auto C : Clauses)
@@ -295,7 +295,7 @@ class ClangLoopSwapVisitor
295295 findClause (P, ClauseId::NoStrict, Clauses);
296296 if (Csize != Clauses.size ()) {
297297 mIsStrict = false ;
298- LLVM_DEBUG (dbgs () << DEBUG_PREFIX << " Pragma found \n " );
298+ LLVM_DEBUG (dbgs () << DEBUG_PREFIX << " Found nostrict clause \n " );
299299 }
300300 // remove clauses
301301 llvm::SmallVector<clang::CharSourceRange, 8 > ToRemove;
@@ -351,24 +351,19 @@ class ClangLoopSwapVisitor
351351 if (mNewAnalisysRequired ) {
352352 Function *F = mModule .getFunction (mCurrentFD ->getNameAsString ());
353353 mProvider = &mPass .getAnalysis <ClangLoopSwapProvider>(*F);
354- mCurrentLoops =
354+ mCanonicalLoopInfo =
355355 &mProvider ->get <CanonicalLoopPass>().getCanonicalLoopInfo ();
356356 mPerfectLoopInfo =
357357 &mProvider ->get <ClangPerfectLoopPass>().getPerfectLoopInfo ();
358- // mDIAT = &mProvider->get<DIEstimateMemoryPass>().getAliasTree();
359- // mDIDepInfo =
360- // &mProvider->get<DIDependencyAnalysisPass>().getDependencies();
361- auto &Socket = mSocketInfo ->getActive ()->second ;
362358 auto RF =
363- Socket .getAnalysis <DIEstimateMemoryPass, DIDependencyAnalysisPass>(
359+ mSocket .getAnalysis <DIEstimateMemoryPass, DIDependencyAnalysisPass>(
364360 *F);
365361 assert (RF &&
366362 " Dependence analysis must be available for a parallel loop!" );
367363 mDIAT = &RF->value <DIEstimateMemoryPass *>()->getAliasTree ();
368364 mDIDepInfo =
369365 &RF->value <DIDependencyAnalysisPass *>()->getDependencies ();
370366 mNewAnalisysRequired = false ;
371- errs () << " GOT INFO\n " ;
372367 }
373368 // collect inductions
374369 mStatus = GET_REFERENCES;
@@ -511,16 +506,18 @@ class ClangLoopSwapVisitor
511506 // get analysis from provider only if it is required
512507 bool mNewAnalisysRequired ;
513508 clang::FunctionDecl *mCurrentFD ;
514- const CanonicalLoopSet *mCurrentLoops ;
515509 ClangLoopSwap &mPass ;
516510 llvm::Module &mModule ;
517- ClangLoopSwapProvider *mProvider ;
518- tsar::DIDependencInfo *mDIDepInfo ;
519- tsar::DIAliasTree *mDIAT ;
520511 const tsar::GlobalOptions *mGO ;
512+ ClangLoopSwapProvider *mProvider ;
521513 tsar::MemoryMatchInfo::MemoryMatcher *mMemMatcher ;
514+ const CanonicalLoopSet *mCanonicalLoopInfo ;
522515 tsar::PerfectLoopInfo *mPerfectLoopInfo ;
523- AnalysisSocketInfo *mSocketInfo ;
516+ tsar::DIDependencInfo *mDIDepInfo ;
517+ tsar::DIAliasTree *mDIAT ;
518+ AnalysisSocket &mSocket ;
519+ llvm::ValueToValueMapTy &mClientToServer ;
520+
524521 bool mIsStrict ;
525522 enum LoopKind {
526523 CANONICAL_AND_PERFECT,
@@ -540,7 +537,7 @@ class ClangLoopSwapVisitor
540537} // namespace
541538
542539bool ClangLoopSwap::runOnModule (Module &M) {
543- errs ( ) << " Start Loop Swap Pass \n " ;
540+ LLVM_DEBUG ( dbgs ( ) << DEBUG_PREFIX << " Start \n " ) ;
544541 auto *TfmCtx = getAnalysis<TransformationEnginePass>().getContext (M);
545542 if (!TfmCtx || !TfmCtx->hasInstance ()) {
546543 M.getContext ().emitError (" can not transform sources"
@@ -613,9 +610,10 @@ bool ClangLoopSwap::runOnModule(Module &M) {
613610 auto &CG = getAnalysis<CallGraphWrapperPass>().getCallGraph ();
614611 auto &RawInfo = getAnalysis<ClangGlobalInfoPass>().getRawInfo ();
615612 ClangLoopSwapVisitor CLSV (TfmCtx, RawInfo, &MemoryMatcher->Matcher ,
616- GlobalOpts, SocketInfo, *this , M);
613+ GlobalOpts, SocketInfo->getActive ()->second , *this ,
614+ M);
617615 CLSV.TraverseDecl (TfmCtx->getContext ().getTranslationUnitDecl ());
618- errs ( ) << " Finish Loop Swap Pass \n " ;
616+ LLVM_DEBUG ( dbgs ( ) << DEBUG_PREFIX << " Finish \n " ) ;
619617 return false ;
620618}
621619
0 commit comments