@@ -54,19 +54,11 @@ using namespace tsar;
54
54
55
55
namespace {
56
56
57
- struct LoopRangeInfo {
58
- Loop *LoopPtr;
59
- SourceRange Range;
60
- CompoundStmt *CompStmtPtr;
61
- LoopRangeInfo () : LoopPtr(nullptr ), CompStmtPtr(nullptr ) {}
62
- LoopRangeInfo (llvm::Loop *L, const SourceRange &R, CompoundStmt *S):
63
- LoopPtr (L), Range(R), CompStmtPtr(S) {}
64
- };
65
-
66
57
// / This provides access to function-level analysis results on server.
67
58
using ClangLoopSwappingProvider =
68
59
FunctionPassAAProvider<DIEstimateMemoryPass, DIDependencyAnalysisPass>;
69
60
using DIAliasTraitVector = std::vector<const DIAliasTrait *>;
61
+ using LoopRangeInfo = std::pair<Loop *, SourceRange>;
70
62
using LoopRangeList = SmallVector<LoopRangeInfo, 2 >;
71
63
using PragmaInfoList = SmallVector<std::pair<Stmt *, LoopRangeList>, 2 >;
72
64
@@ -123,19 +115,22 @@ class LoopVisitor : public RecursiveASTVisitor<LoopVisitor> {
123
115
diag::error_loop_swapping_expect_compound);
124
116
return false ;
125
117
}
118
+ if (mState == TraverseState::OUTERFOR && !dyn_cast<ForStmt>(S)) {
119
+ toDiag (mSrcMgr .getDiagnostics (), S->getBeginLoc (),
120
+ diag::error_loop_swapping_redundant_stmt);
121
+ return false ;
122
+ }
126
123
return RecursiveASTVisitor::TraverseStmt (S);
127
124
}
128
125
129
126
bool TraverseCompoundStmt (CompoundStmt *S) {
130
- mCompStmtStack .push (S);
131
127
if (mState == TraverseState::PRAGMA) {
132
128
mState = TraverseState::OUTERFOR;
133
129
auto Res = RecursiveASTVisitor::TraverseCompoundStmt (S);
134
130
mState = TraverseState::NONE;
135
131
return Res;
136
132
}
137
133
auto Res = RecursiveASTVisitor::TraverseCompoundStmt (S);
138
- mCompStmtStack .pop ();
139
134
return Res;
140
135
}
141
136
@@ -144,13 +139,7 @@ class LoopVisitor : public RecursiveASTVisitor<LoopVisitor> {
144
139
auto Match = mLoopInfo .find <AST>(S);
145
140
if (Match != mLoopInfo .end ()) {
146
141
auto &LRL = mPragmaLoopsInfo .back ().second ;
147
- if (!LRL.empty () && LRL.back ().CompStmtPtr != mCompStmtStack .top ()) {
148
- toDiag (mSrcMgr .getDiagnostics (), S->getBeginLoc (),
149
- diag::error_loop_swapping_diff_scope);
150
- return false ;
151
- }
152
- LRL.push_back (LoopRangeInfo (Match->get <IR>(), S->getSourceRange (),
153
- mCompStmtStack .top ()));
142
+ LRL.push_back (std::make_pair (Match->get <IR>(), S->getSourceRange ()));
154
143
} else {
155
144
toDiag (mSrcMgr .getDiagnostics (), S->getBeginLoc (),
156
145
diag::error_loop_swapping_lost_loop);
@@ -178,8 +167,8 @@ class LoopVisitor : public RecursiveASTVisitor<LoopVisitor> {
178
167
++It, ++N) {
179
168
dbgs () << " \t Pragma " << N << " (" << It->first <<" ):\n " ;
180
169
for (const auto &Info : It->second ) {
181
- const auto LoopPtr = Info.LoopPtr ;
182
- const auto &Range = Info.Range ;
170
+ const auto LoopPtr = Info.first ;
171
+ const auto &Range = Info.second ;
183
172
dbgs () << " \t\t [Range]\n " ;
184
173
dbgs () << " \t\t Begin:" << Range.getBegin ().printToString (mSrcMgr )
185
174
<< " \n " ;
@@ -200,7 +189,6 @@ class LoopVisitor : public RecursiveASTVisitor<LoopVisitor> {
200
189
const LoopMatcherPass::LoopMatcher &mLoopInfo ;
201
190
TraverseState mState ;
202
191
SmallVector<Stmt *, 1 > mClauses ;
203
- std::stack<CompoundStmt *> mCompStmtStack ;
204
192
PragmaInfoList mPragmaLoopsInfo ;
205
193
};
206
194
@@ -327,15 +315,15 @@ bool ClangLoopSwapping::hasTrueOrAntiDependence(
327
315
328
316
bool ClangLoopSwapping::isSwappingAvailable (
329
317
const LoopRangeList &LRL, const Stmt *Pragma) const {
330
- auto *LoopID0 = mGetLoopID (LRL[0 ].LoopPtr ->getLoopID ());
331
- auto *LoopID1 = mGetLoopID (LRL[1 ].LoopPtr ->getLoopID ());
318
+ auto *LoopID0 = mGetLoopID (LRL[0 ].first ->getLoopID ());
319
+ auto *LoopID1 = mGetLoopID (LRL[1 ].first ->getLoopID ());
332
320
if (!LoopID0) {
333
- toDiag (mSrcMgr ->getDiagnostics (), LRL[0 ].Range .getBegin (),
321
+ toDiag (mSrcMgr ->getDiagnostics (), LRL[0 ].second .getBegin (),
334
322
diag::warn_loop_swapping_no_loop_id);
335
323
return false ;
336
324
}
337
325
if (!LoopID1) {
338
- toDiag (mSrcMgr ->getDiagnostics (), LRL[1 ].Range .getBegin (),
326
+ toDiag (mSrcMgr ->getDiagnostics (), LRL[1 ].second .getBegin (),
339
327
diag::warn_loop_swapping_no_loop_id);
340
328
return false ;
341
329
}
@@ -376,8 +364,8 @@ void ClangLoopSwapping::swapLoops(const LoopVisitor &Visitor) {
376
364
diag::warn_loop_swapping_redundant_loop);
377
365
}
378
366
if (isSwappingAvailable (Loops, Pragma)) {
379
- auto Range0 = Loops[0 ].Range ;
380
- auto Range1 = Loops[1 ].Range ;
367
+ auto Range0 = Loops[0 ].second ;
368
+ auto Range1 = Loops[1 ].second ;
381
369
Range0.setEnd (GetLoopEnd (Range0));
382
370
Range1.setEnd (GetLoopEnd (Range1));
383
371
auto Range0End = Range0.getEnd ();
0 commit comments