Skip to content

Commit 6c39757

Browse files
committed
Address reviewers comments
1 parent d89fd2e commit 6c39757

File tree

3 files changed

+25
-30
lines changed

3 files changed

+25
-30
lines changed

clang/include/clang/Sema/SemaOpenMP.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,12 +1503,12 @@ class SemaOpenMP : public SemaBase {
15031503
/// Holds the result of the analysis of a (possibly canonical) loop.
15041504
struct LoopAnalysis {
15051505
/// The analyzed loop or loop transformation.
1506-
Stmt *AStmt;
1506+
Stmt *AStmt = nullptr;
15071507
/// Loop analyses results.
15081508
OMPLoopBasedDirective::HelperExprs HelperExprs;
1509-
/// The for-statement of the loop. ForStmt equals AStmt only when the latter
1510-
/// is a canonical loop (i.e. not a loop transformation).
1511-
Stmt *ForStmt;
1509+
/// The for-statement of the loop. TheForStmt equals AStmt only when the
1510+
/// latter is a canonical loop (i.e. not a loop transformation).
1511+
Stmt *TheForStmt = nullptr;
15121512
/// Initialization statements before transformations.
15131513
SmallVector<Stmt *> OriginalInits;
15141514
/// Initialization statements required after transformation of this loop.
@@ -1521,7 +1521,7 @@ class SemaOpenMP : public SemaBase {
15211521

15221522
// Convenience functions used when building LoopSequenceAnalysis.
15231523
static bool isRegularLoop(Stmt *S) {
1524-
return isa<clang::ForStmt, CXXForRangeStmt>(S);
1524+
return isa<ForStmt, CXXForRangeStmt>(S);
15251525
}
15261526
static bool isLoopTransformation(Stmt *S) {
15271527
return isa<OMPLoopTransformationDirective>(S);

clang/lib/AST/StmtOpenMP.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -371,22 +371,18 @@ OMPForDirective *OMPForDirective::Create(
371371
}
372372

373373
Stmt *OMPLoopTransformationDirective::getTransformedStmt() const {
374-
if (auto *D = dyn_cast<OMPCanonicalLoopNestTransformationDirective>(S)) {
374+
if (auto *D = dyn_cast<OMPCanonicalLoopNestTransformationDirective>(S))
375375
return D->getTransformedStmt();
376-
}
377-
if (auto *D = dyn_cast<OMPCanonicalLoopSequenceTransformationDirective>(S)) {
376+
if (auto *D = dyn_cast<OMPCanonicalLoopSequenceTransformationDirective>(S))
378377
return D->getTransformedStmt();
379-
}
380378
llvm_unreachable("unexpected object type");
381379
}
382380

383381
Stmt *OMPLoopTransformationDirective::getPreInits() const {
384-
if (auto *D = dyn_cast<OMPCanonicalLoopNestTransformationDirective>(S)) {
382+
if (auto *D = dyn_cast<OMPCanonicalLoopNestTransformationDirective>(S))
385383
return D->getPreInits();
386-
}
387-
if (auto *D = dyn_cast<OMPCanonicalLoopSequenceTransformationDirective>(S)) {
384+
if (auto *D = dyn_cast<OMPCanonicalLoopSequenceTransformationDirective>(S))
388385
return D->getPreInits();
389-
}
390386
llvm_unreachable("unexpected object type");
391387
}
392388

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14564,11 +14564,11 @@ bool SemaOpenMP::analyzeLoopSequence(Stmt *LoopSeqStmt,
1456414564
auto StoreLoopStatements = [](LoopAnalysis &Analysis, Stmt *LoopStmt) {
1456514565
if (auto *For = dyn_cast<ForStmt>(LoopStmt)) {
1456614566
Analysis.OriginalInits.push_back(For->getInit());
14567-
Analysis.ForStmt = For;
14567+
Analysis.TheForStmt = For;
1456814568
} else {
1456914569
auto *CXXFor = cast<CXXForRangeStmt>(LoopStmt);
1457014570
Analysis.OriginalInits.push_back(CXXFor->getBeginStmt());
14571-
Analysis.ForStmt = CXXFor;
14571+
Analysis.TheForStmt = CXXFor;
1457214572
}
1457314573
};
1457414574

@@ -16019,7 +16019,9 @@ StmtResult SemaOpenMP::ActOnOpenMPFuseDirective(ArrayRef<OMPClause *> Clauses,
1601916019

1602016020
// SeqAnalysis.LoopSeqSize exists mostly to handle dependent contexts,
1602116021
// otherwise it must be the same as SeqAnalysis.Loops.size().
16022-
assert(SeqAnalysis.LoopSeqSize == SeqAnalysis.Loops.size());
16022+
assert(SeqAnalysis.LoopSeqSize == SeqAnalysis.Loops.size() &&
16023+
"Inconsistent size of the loop sequence and the number of loops "
16024+
"found in the sequence");
1602316025

1602416026
// Handle clauses, which can be any of the following: [looprange, apply]
1602516027
const OMPLoopRangeClause *LRC =
@@ -16084,7 +16086,7 @@ StmtResult SemaOpenMP::ActOnOpenMPFuseDirective(ArrayRef<OMPClause *> Clauses,
1608416086
// Select the type with the largest bit width among all induction variables
1608516087
QualType IVType =
1608616088
SeqAnalysis.Loops[FirstVal - 1].HelperExprs.IterationVarRef->getType();
16087-
for (unsigned I = FirstVal; I < LastVal; ++I) {
16089+
for (unsigned I : llvm::seq<unsigned>(FirstVal, LastVal)) {
1608816090
QualType CurrentIVType =
1608916091
SeqAnalysis.Loops[I].HelperExprs.IterationVarRef->getType();
1609016092
if (Context.getTypeSize(CurrentIVType) > Context.getTypeSize(IVType)) {
@@ -16146,9 +16148,7 @@ StmtResult SemaOpenMP::ActOnOpenMPFuseDirective(ArrayRef<OMPClause *> Clauses,
1614616148
// original loop. The preinit structure must ensure that hidden variables
1614716149
// like '.omp.fuse.max' are still properly handled.
1614816150
// Transformations that apply this concept: Loopranged Fuse, Split
16149-
if (!SeqAnalysis.LoopSequencePreInits.empty()) {
16150-
llvm::append_range(PreInits, SeqAnalysis.LoopSequencePreInits);
16151-
}
16151+
llvm::append_range(PreInits, SeqAnalysis.LoopSequencePreInits);
1615216152

1615316153
// Process each single loop to generate and collect declarations
1615416154
// and statements for all helper expressions related to
@@ -16170,19 +16170,18 @@ StmtResult SemaOpenMP::ActOnOpenMPFuseDirective(ArrayRef<OMPClause *> Clauses,
1617016170
for (unsigned int I = FirstVal - 1, J = 0; I < LastVal; ++I, ++J) {
1617116171
if (SeqAnalysis.Loops[I].isRegularLoop()) {
1617216172
addLoopPreInits(Context, SeqAnalysis.Loops[I].HelperExprs,
16173-
SeqAnalysis.Loops[I].ForStmt,
16173+
SeqAnalysis.Loops[I].TheForStmt,
1617416174
SeqAnalysis.Loops[I].OriginalInits, PreInits);
1617516175
} else if (SeqAnalysis.Loops[I].isLoopTransformation()) {
1617616176
// For transformed loops, insert both pre-inits and original inits.
1617716177
// Order matters: pre-inits may define variables used in the original
1617816178
// inits such as upper bounds...
1617916179
SmallVector<Stmt *> &TransformPreInit =
1618016180
SeqAnalysis.Loops[TransformIndex++].TransformsPreInits;
16181-
if (!TransformPreInit.empty())
16182-
llvm::append_range(PreInits, TransformPreInit);
16181+
llvm::append_range(PreInits, TransformPreInit);
1618316182

1618416183
addLoopPreInits(Context, SeqAnalysis.Loops[I].HelperExprs,
16185-
SeqAnalysis.Loops[I].ForStmt,
16184+
SeqAnalysis.Loops[I].TheForStmt,
1618616185
SeqAnalysis.Loops[I].OriginalInits, PreInits);
1618716186
}
1618816187
auto [UBVD, UBDStmt] =
@@ -16270,7 +16269,7 @@ StmtResult SemaOpenMP::ActOnOpenMPFuseDirective(ArrayRef<OMPClause *> Clauses,
1627016269
// omp.fuse.max = max(omp.temp1, omp.temp0)
1627116270

1627216271
ExprResult MaxExpr;
16273-
// I is the true
16272+
// I is the range of loops in the sequence that we fuse.
1627416273
for (unsigned I = FirstVal - 1, J = 0; I < LastVal; ++I, ++J) {
1627516274
DeclRefExpr *NIRef = MakeVarDeclRef(NIVarDecls[J]);
1627616275
QualType NITy = NIRef->getType();
@@ -16382,13 +16381,13 @@ StmtResult SemaOpenMP::ActOnOpenMPFuseDirective(ArrayRef<OMPClause *> Clauses,
1638216381

1638316382
// If the loop is a CXXForRangeStmt then the iterator variable is needed
1638416383
if (auto *SourceCXXFor =
16385-
dyn_cast<CXXForRangeStmt>(SeqAnalysis.Loops[I].ForStmt))
16384+
dyn_cast<CXXForRangeStmt>(SeqAnalysis.Loops[I].TheForStmt))
1638616385
BodyStmts.push_back(SourceCXXFor->getLoopVarStmt());
1638716386

1638816387
Stmt *Body =
16389-
(isa<ForStmt>(SeqAnalysis.Loops[I].ForStmt))
16390-
? cast<ForStmt>(SeqAnalysis.Loops[I].ForStmt)->getBody()
16391-
: cast<CXXForRangeStmt>(SeqAnalysis.Loops[I].ForStmt)->getBody();
16388+
(isa<ForStmt>(SeqAnalysis.Loops[I].TheForStmt))
16389+
? cast<ForStmt>(SeqAnalysis.Loops[I].TheForStmt)->getBody()
16390+
: cast<CXXForRangeStmt>(SeqAnalysis.Loops[I].TheForStmt)->getBody();
1639216391
BodyStmts.push_back(Body);
1639316392

1639416393
CompoundStmt *CombinedBody =
@@ -16457,7 +16456,7 @@ StmtResult SemaOpenMP::ActOnOpenMPFuseDirective(ArrayRef<OMPClause *> Clauses,
1645716456
llvm::append_range(PreInits, TransformPreInit);
1645816457
}
1645916458

16460-
FinalLoops.push_back(SeqAnalysis.Loops[I].ForStmt);
16459+
FinalLoops.push_back(SeqAnalysis.Loops[I].TheForStmt);
1646116460
}
1646216461

1646316462
FinalLoops.insert(FinalLoops.begin() + (FirstVal - 1), FusedForStmt);

0 commit comments

Comments
 (0)