Skip to content

Commit 65cbfeb

Browse files
committed
Fixed formatting and comments
1 parent 860fcd9 commit 65cbfeb

File tree

1 file changed

+58
-54
lines changed

1 file changed

+58
-54
lines changed

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 58 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -14197,42 +14197,43 @@ StmtResult SemaOpenMP::ActOnOpenMPTargetTeamsDistributeSimdDirective(
1419714197
}
1419814198

1419914199
// Overloaded base case function
14200-
template <typename T, typename F>
14201-
static bool tryHandleAs(T *t, F &&) {
14202-
return false;
14200+
template <typename T, typename F> static bool tryHandleAs(T *t, F &&) {
14201+
return false;
1420314202
}
1420414203

1420514204
/**
14206-
* Tries to recursively cast `t` to one of the given types and invokes `f` if successful.
14205+
* Tries to recursively cast `t` to one of the given types and invokes `f` if
14206+
* successful.
1420714207
*
1420814208
* @tparam Class The first type to check.
1420914209
* @tparam Rest The remaining types to check.
1421014210
* @tparam T The base type of `t`.
14211-
* @tparam F The callable type for the function to invoke upon a successful cast.
14211+
* @tparam F The callable type for the function to invoke upon a successful
14212+
* cast.
1421214213
* @param t The object to be checked.
1421314214
* @param f The function to invoke if `t` matches `Class`.
1421414215
* @return `true` if `t` matched any type and `f` was called, otherwise `false`.
1421514216
*/
1421614217
template <typename Class, typename... Rest, typename T, typename F>
1421714218
static bool tryHandleAs(T *t, F &&f) {
14218-
if (Class *c = dyn_cast<Class>(t)) {
14219-
f(c);
14220-
return true;
14221-
} else {
14222-
return tryHandleAs<Rest...>(t, std::forward<F>(f));
14223-
}
14219+
if (Class *c = dyn_cast<Class>(t)) {
14220+
f(c);
14221+
return true;
14222+
} else {
14223+
return tryHandleAs<Rest...>(t, std::forward<F>(f));
14224+
}
1422414225
}
1422514226

1422614227
// Updates OriginalInits by checking Transform against loop transformation
1422714228
// directives and appending their pre-inits if a match is found.
1422814229
static void updatePreInits(OMPLoopBasedDirective *Transform,
1422914230
SmallVectorImpl<SmallVector<Stmt *, 0>> &PreInits) {
14230-
if (!tryHandleAs<OMPTileDirective, OMPUnrollDirective, OMPReverseDirective,
14231-
OMPInterchangeDirective, OMPFuseDirective>(
14232-
Transform, [&PreInits](auto *Dir) {
14233-
appendFlattenedStmtList(PreInits.back(), Dir->getPreInits());
14234-
}))
14235-
llvm_unreachable("Unhandled loop transformation");
14231+
if (!tryHandleAs<OMPTileDirective, OMPUnrollDirective, OMPReverseDirective,
14232+
OMPInterchangeDirective, OMPFuseDirective>(
14233+
Transform, [&PreInits](auto *Dir) {
14234+
appendFlattenedStmtList(PreInits.back(), Dir->getPreInits());
14235+
}))
14236+
llvm_unreachable("Unhandled loop transformation");
1423614237
}
1423714238

1423814239
bool SemaOpenMP::checkTransformableLoopNest(
@@ -14310,43 +14311,42 @@ class NestedLoopCounterVisitor : public DynamicRecursiveASTVisitor {
1431014311
unsigned getNestedLoopCount() const { return NestedLoopCount; }
1431114312

1431214313
bool VisitForStmt(ForStmt *FS) override {
14313-
++NestedLoopCount;
14314-
return true;
14314+
++NestedLoopCount;
14315+
return true;
1431514316
}
1431614317

1431714318
bool VisitCXXForRangeStmt(CXXForRangeStmt *FRS) override {
14318-
++NestedLoopCount;
14319-
return true;
14319+
++NestedLoopCount;
14320+
return true;
1432014321
}
1432114322

1432214323
bool TraverseStmt(Stmt *S) override {
14323-
if (!S)
14324+
if (!S)
1432414325
return true;
1432514326

14326-
// Skip traversal of all expressions, including special cases like
14327-
// LambdaExpr, StmtExpr, BlockExpr, and RequiresExpr. These expressions
14328-
// may contain inner statements (and even loops), but they are not part
14329-
// of the syntactic body of the surrounding loop structure.
14330-
// Therefore must not be counted
14331-
if (isa<Expr>(S))
14327+
// Skip traversal of all expressions, including special cases like
14328+
// LambdaExpr, StmtExpr, BlockExpr, and RequiresExpr. These expressions
14329+
// may contain inner statements (and even loops), but they are not part
14330+
// of the syntactic body of the surrounding loop structure.
14331+
// Therefore must not be counted
14332+
if (isa<Expr>(S))
1433214333
return true;
1433314334

14334-
// Only recurse into CompoundStmt (block {}) and loop bodies
14335-
if (isa<CompoundStmt>(S) || isa<ForStmt>(S) ||
14336-
isa<CXXForRangeStmt>(S)) {
14335+
// Only recurse into CompoundStmt (block {}) and loop bodies
14336+
if (isa<CompoundStmt>(S) || isa<ForStmt>(S) || isa<CXXForRangeStmt>(S)) {
1433714337
return DynamicRecursiveASTVisitor::TraverseStmt(S);
14338-
}
14338+
}
1433914339

14340-
// Stop traversal of the rest of statements, that break perfect
14341-
// loop nesting, such as control flow (IfStmt, SwitchStmt...)
14342-
return true;
14340+
// Stop traversal of the rest of statements, that break perfect
14341+
// loop nesting, such as control flow (IfStmt, SwitchStmt...)
14342+
return true;
1434314343
}
1434414344

1434514345
bool TraverseDecl(Decl *D) override {
14346-
// Stop in the case of finding a declaration, it is not important
14347-
// in order to find nested loops (Possible CXXRecordDecl, RecordDecl,
14348-
// FunctionDecl...)
14349-
return true;
14346+
// Stop in the case of finding a declaration, it is not important
14347+
// in order to find nested loops (Possible CXXRecordDecl, RecordDecl,
14348+
// FunctionDecl...)
14349+
return true;
1435014350
}
1435114351
};
1435214352

@@ -14504,15 +14504,14 @@ bool SemaOpenMP::analyzeLoopSequence(
1450414504
return isa<OMPLoopTransformationDirective>(Child);
1450514505
};
1450614506

14507-
1450814507
// High level grammar validation
1450914508
for (auto *Child : LoopSeqStmt->children()) {
1451014509

14511-
if (!Child)
14510+
if (!Child)
1451214511
continue;
1451314512

14514-
// Skip over non-loop-sequence statements
14515-
if (!isLoopSequenceDerivation(Child)) {
14513+
// Skip over non-loop-sequence statements
14514+
if (!isLoopSequenceDerivation(Child)) {
1451614515
Child = Child->IgnoreContainers();
1451714516

1451814517
// Ignore empty compound statement
@@ -14530,9 +14529,9 @@ bool SemaOpenMP::analyzeLoopSequence(
1453014529
// Already been treated, skip this children
1453114530
continue;
1453214531
}
14533-
}
14534-
// Regular loop sequence handling
14535-
if (isLoopSequenceDerivation(Child)) {
14532+
}
14533+
// Regular loop sequence handling
14534+
if (isLoopSequenceDerivation(Child)) {
1453614535
if (isLoopGeneratingStmt(Child)) {
1453714536
if (!analyzeLoopGeneration(Child)) {
1453814537
return false;
@@ -14546,12 +14545,12 @@ bool SemaOpenMP::analyzeLoopSequence(
1454614545
// Update the Loop Sequence size by one
1454714546
++LoopSeqSize;
1454814547
}
14549-
} else {
14548+
} else {
1455014549
// Report error for invalid statement inside canonical loop sequence
1455114550
Diag(Child->getBeginLoc(), diag::err_omp_not_for)
1455214551
<< 0 << getOpenMPDirectiveName(Kind);
1455314552
return false;
14554-
}
14553+
}
1455514554
}
1455614555
return true;
1455714556
}
@@ -14568,9 +14567,9 @@ bool SemaOpenMP::checkTransformableLoopSequence(
1456814567

1456914568
// Checks whether the given statement is a compound statement
1457014569
if (!isa<CompoundStmt>(AStmt)) {
14571-
Diag(AStmt->getBeginLoc(), diag::err_omp_not_a_loop_sequence)
14572-
<< getOpenMPDirectiveName(Kind);
14573-
return false;
14570+
Diag(AStmt->getBeginLoc(), diag::err_omp_not_a_loop_sequence)
14571+
<< getOpenMPDirectiveName(Kind);
14572+
return false;
1457414573
}
1457514574
// Number of top level canonical loop nests observed (And acts as index)
1457614575
LoopSeqSize = 0;
@@ -14601,7 +14600,7 @@ bool SemaOpenMP::checkTransformableLoopSequence(
1460114600
OriginalInits, TransformsPreInits,
1460214601
LoopSequencePreInits, LoopCategories, Context,
1460314602
Kind)) {
14604-
return false;
14603+
return false;
1460514604
}
1460614605
if (LoopSeqSize <= 0) {
1460714606
Diag(AStmt->getBeginLoc(), diag::err_omp_empty_loop_sequence)
@@ -15315,7 +15314,7 @@ StmtResult SemaOpenMP::ActOnOpenMPUnrollDirective(ArrayRef<OMPClause *> Clauses,
1531515314
Stmt *LoopStmt = nullptr;
1531615315
collectLoopStmts(AStmt, {LoopStmt});
1531715316

15318-
// Determine the PreInit declarations.e
15317+
// Determine the PreInit declarations.
1531915318
SmallVector<Stmt *, 4> PreInits;
1532015319
addLoopPreInits(Context, LoopHelper, LoopStmt, OriginalInits[0], PreInits);
1532115320

@@ -15931,13 +15930,18 @@ StmtResult SemaOpenMP::ActOnOpenMPFuseDirective(ArrayRef<OMPClause *> Clauses,
1593115930
CountVal = CountInt.getZExtValue();
1593215931
};
1593315932

15934-
// Checks if the loop range is valid
15933+
// OpenMP [6.0, Restrictions]
15934+
// first + count - 1 must not evaluate to a value greater than the
15935+
// loop sequence length of the associated canonical loop sequence.
1593515936
auto ValidLoopRange = [](uint64_t FirstVal, uint64_t CountVal,
1593615937
unsigned NumLoops) -> bool {
1593715938
return FirstVal + CountVal - 1 <= NumLoops;
1593815939
};
1593915940
uint64_t FirstVal = 1, CountVal = 0, LastVal = LoopSeqSize;
1594015941

15942+
// Validates the loop range after evaluating the semantic information
15943+
// and ensures that the range is valid for the given loop sequence size.
15944+
// Expressions are evaluated at compile time to obtain constant values.
1594115945
if (LRC) {
1594215946
EvaluateLoopRangeArguments(LRC->getFirst(), LRC->getCount(), FirstVal,
1594315947
CountVal);

0 commit comments

Comments
 (0)