@@ -110,21 +110,43 @@ void addVarList(const ClangDependenceAnalyzer::ReductionVarListT &VarInfoList,
110110 }
111111}
112112
113- unsigned getPerfectNestSize (const DFLoop &DFL,
114- const PerfectLoopInfo &PerfectInfo,
115- const CanonicalLoopSet &CanonicalLoops) {
113+ void addOnClause (const DFLoop &DFL, const PerfectLoopInfo &PerfectInfo,
114+ const CanonicalLoopSet &CanonicalLoops,
115+ const MemoryMatchInfo &MemoryMatcher,
116+ SmallVectorImpl<char > &Out) {
117+ Out.append ({' ' , ' o' , ' n' , ' (' });
116118 auto *CurrDFL = &DFL;
117- unsigned PerfectSize = 1 ;
118- for (; PerfectInfo.count (CurrDFL) && CurrDFL->getNumRegions () > 0 ;
119- ++PerfectSize) {
119+ auto CanonicalItr = CanonicalLoops.find_as (const_cast <DFLoop *>(CurrDFL));
120+ assert (CanonicalItr != CanonicalLoops.end () &&
121+ (**CanonicalItr).isCanonical () &&
122+ " Parallel loop must have canonical loop form!" );
123+ auto *Induction = (**CanonicalItr).getInduction ();
124+ assert (Induction && " Induction variable must not be null in canonical loop!" );
125+ auto MatchItr = MemoryMatcher.Matcher .find <IR>(Induction);
126+ assert (MatchItr != MemoryMatcher.Matcher .end () &&
127+ " AST-level variable representation must be available!" );
128+ Out.append ({' [' });
129+ Out.append (MatchItr->get <AST>()->getName ().begin (),
130+ MatchItr->get <AST>()->getName ().end ());
131+ Out.append ({' ]' });
132+ for (; PerfectInfo.count (CurrDFL) && CurrDFL->getNumRegions () > 0 ;) {
120133 CurrDFL = dyn_cast<DFLoop>(*CurrDFL->region_begin ());
121134 if (!CurrDFL)
122- return PerfectSize ;
135+ break ;
123136 auto CanonicalItr = CanonicalLoops.find_as (const_cast <DFLoop *>(CurrDFL));
124137 if (CanonicalItr == CanonicalLoops.end () || !(**CanonicalItr).isCanonical ())
125- return PerfectSize;
138+ break ;
139+ auto *Induction = (**CanonicalItr).getInduction ();
140+ assert (Induction && " Induction variable must not be null in canonical loop!" );
141+ auto MatchItr = MemoryMatcher.Matcher .find <IR>(Induction);
142+ assert (MatchItr != MemoryMatcher.Matcher .end () &&
143+ " AST-level variable representation must be available!" );
144+ Out.append ({' [' });
145+ Out.append (MatchItr->get <AST>()->getName ().begin (),
146+ MatchItr->get <AST>()->getName ().end ());
147+ Out.append ({' ]' });
126148 }
127- return PerfectSize ;
149+ Out. append ({ ' ) ' }) ;
128150}
129151} // namespace
130152
@@ -166,13 +188,13 @@ bool ClangDVMHSMParallelization::exploitParallelism(
166188 }
167189 auto &PerfectInfo = Provider.get <ClangPerfectLoopPass>().getPerfectLoopInfo ();
168190 auto &CanonicalInfo = Provider.get <CanonicalLoopPass>().getCanonicalLoopInfo ();
169- SmallString<128 > ParallelFor (" #pragma dvm parallel (" );
191+ auto &MemoryMatcher = Provider.get <MemoryMatcherImmutableWrapper>().get ();
192+
193+ SmallString<128 > ParallelFor (" #pragma dvm parallel" );
170194 if (HostOnly)
171- ParallelFor += " 1 " ;
195+ ParallelFor += " (1) " ;
172196 else
173- Twine (getPerfectNestSize (IR, PerfectInfo, CanonicalInfo))
174- .toStringRef (ParallelFor);
175- ParallelFor += " )" ;
197+ addOnClause (IR, PerfectInfo, CanonicalInfo, MemoryMatcher, ParallelFor);
176198 if (!ASTDepInfo.get <trait::Private>().empty ()) {
177199 ParallelFor += " private" ;
178200 addVarList (ASTDepInfo.get <trait::Private>(), ParallelFor);
@@ -182,16 +204,16 @@ bool ClangDVMHSMParallelization::exploitParallelism(
182204 DVMHRegion += " \n {\n " ;
183205 // Add directives to the source code.
184206 auto &Rewriter = TfmCtx.getRewriter ();
185- Rewriter.InsertTextBefore (AST.getBeginLoc (), ParallelFor);
186- Rewriter.InsertTextBefore (AST.getBeginLoc (), DVMHRegion);
207+ Rewriter.InsertTextBefore (AST.getBeginLoc (), ParallelFor);
208+ Rewriter.InsertTextBefore (AST.getBeginLoc (), DVMHRegion);
187209 if (!DVMHActual.empty ())
188- Rewriter.InsertTextBefore (AST.getBeginLoc (), DVMHActual);
210+ Rewriter.InsertTextBefore (AST.getBeginLoc (), DVMHActual);
189211 auto &ASTCtx = TfmCtx.getContext ();
190212 Token SemiTok;
191- auto InsertLoc = (!getRawTokenAfter (AST.getEndLoc (),
213+ auto InsertLoc = (!getRawTokenAfter (AST.getEndLoc (),
192214 ASTCtx.getSourceManager (), ASTCtx.getLangOpts (), SemiTok)
193215 && SemiTok.is (tok::semi))
194- ? SemiTok.getLocation () : AST.getEndLoc ();
216+ ? SemiTok.getLocation () : AST.getEndLoc ();
195217 Rewriter.InsertTextAfterToken (InsertLoc, " }" );
196218 if (!DVMHGetActual.empty ()) {
197219 Rewriter.InsertTextAfterToken (InsertLoc, " \n " );
0 commit comments