Skip to content

Commit 07e7dc8

Browse files
committed
Fixed formatting and comments
1 parent 0d90fa9 commit 07e7dc8

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
@@ -14128,42 +14128,43 @@ StmtResult SemaOpenMP::ActOnOpenMPTargetTeamsDistributeSimdDirective(
1412814128
}
1412914129

1413014130
// Overloaded base case function
14131-
template <typename T, typename F>
14132-
static bool tryHandleAs(T *t, F &&) {
14133-
return false;
14131+
template <typename T, typename F> static bool tryHandleAs(T *t, F &&) {
14132+
return false;
1413414133
}
1413514134

1413614135
/**
14137-
* Tries to recursively cast `t` to one of the given types and invokes `f` if successful.
14136+
* Tries to recursively cast `t` to one of the given types and invokes `f` if
14137+
* successful.
1413814138
*
1413914139
* @tparam Class The first type to check.
1414014140
* @tparam Rest The remaining types to check.
1414114141
* @tparam T The base type of `t`.
14142-
* @tparam F The callable type for the function to invoke upon a successful cast.
14142+
* @tparam F The callable type for the function to invoke upon a successful
14143+
* cast.
1414314144
* @param t The object to be checked.
1414414145
* @param f The function to invoke if `t` matches `Class`.
1414514146
* @return `true` if `t` matched any type and `f` was called, otherwise `false`.
1414614147
*/
1414714148
template <typename Class, typename... Rest, typename T, typename F>
1414814149
static bool tryHandleAs(T *t, F &&f) {
14149-
if (Class *c = dyn_cast<Class>(t)) {
14150-
f(c);
14151-
return true;
14152-
} else {
14153-
return tryHandleAs<Rest...>(t, std::forward<F>(f));
14154-
}
14150+
if (Class *c = dyn_cast<Class>(t)) {
14151+
f(c);
14152+
return true;
14153+
} else {
14154+
return tryHandleAs<Rest...>(t, std::forward<F>(f));
14155+
}
1415514156
}
1415614157

1415714158
// Updates OriginalInits by checking Transform against loop transformation
1415814159
// directives and appending their pre-inits if a match is found.
1415914160
static void updatePreInits(OMPLoopBasedDirective *Transform,
1416014161
SmallVectorImpl<SmallVector<Stmt *, 0>> &PreInits) {
14161-
if (!tryHandleAs<OMPTileDirective, OMPUnrollDirective, OMPReverseDirective,
14162-
OMPInterchangeDirective, OMPFuseDirective>(
14163-
Transform, [&PreInits](auto *Dir) {
14164-
appendFlattenedStmtList(PreInits.back(), Dir->getPreInits());
14165-
}))
14166-
llvm_unreachable("Unhandled loop transformation");
14162+
if (!tryHandleAs<OMPTileDirective, OMPUnrollDirective, OMPReverseDirective,
14163+
OMPInterchangeDirective, OMPFuseDirective>(
14164+
Transform, [&PreInits](auto *Dir) {
14165+
appendFlattenedStmtList(PreInits.back(), Dir->getPreInits());
14166+
}))
14167+
llvm_unreachable("Unhandled loop transformation");
1416714168
}
1416814169

1416914170
bool SemaOpenMP::checkTransformableLoopNest(
@@ -14241,43 +14242,42 @@ class NestedLoopCounterVisitor : public DynamicRecursiveASTVisitor {
1424114242
unsigned getNestedLoopCount() const { return NestedLoopCount; }
1424214243

1424314244
bool VisitForStmt(ForStmt *FS) override {
14244-
++NestedLoopCount;
14245-
return true;
14245+
++NestedLoopCount;
14246+
return true;
1424614247
}
1424714248

1424814249
bool VisitCXXForRangeStmt(CXXForRangeStmt *FRS) override {
14249-
++NestedLoopCount;
14250-
return true;
14250+
++NestedLoopCount;
14251+
return true;
1425114252
}
1425214253

1425314254
bool TraverseStmt(Stmt *S) override {
14254-
if (!S)
14255+
if (!S)
1425514256
return true;
1425614257

14257-
// Skip traversal of all expressions, including special cases like
14258-
// LambdaExpr, StmtExpr, BlockExpr, and RequiresExpr. These expressions
14259-
// may contain inner statements (and even loops), but they are not part
14260-
// of the syntactic body of the surrounding loop structure.
14261-
// Therefore must not be counted
14262-
if (isa<Expr>(S))
14258+
// Skip traversal of all expressions, including special cases like
14259+
// LambdaExpr, StmtExpr, BlockExpr, and RequiresExpr. These expressions
14260+
// may contain inner statements (and even loops), but they are not part
14261+
// of the syntactic body of the surrounding loop structure.
14262+
// Therefore must not be counted
14263+
if (isa<Expr>(S))
1426314264
return true;
1426414265

14265-
// Only recurse into CompoundStmt (block {}) and loop bodies
14266-
if (isa<CompoundStmt>(S) || isa<ForStmt>(S) ||
14267-
isa<CXXForRangeStmt>(S)) {
14266+
// Only recurse into CompoundStmt (block {}) and loop bodies
14267+
if (isa<CompoundStmt>(S) || isa<ForStmt>(S) || isa<CXXForRangeStmt>(S)) {
1426814268
return DynamicRecursiveASTVisitor::TraverseStmt(S);
14269-
}
14269+
}
1427014270

14271-
// Stop traversal of the rest of statements, that break perfect
14272-
// loop nesting, such as control flow (IfStmt, SwitchStmt...)
14273-
return true;
14271+
// Stop traversal of the rest of statements, that break perfect
14272+
// loop nesting, such as control flow (IfStmt, SwitchStmt...)
14273+
return true;
1427414274
}
1427514275

1427614276
bool TraverseDecl(Decl *D) override {
14277-
// Stop in the case of finding a declaration, it is not important
14278-
// in order to find nested loops (Possible CXXRecordDecl, RecordDecl,
14279-
// FunctionDecl...)
14280-
return true;
14277+
// Stop in the case of finding a declaration, it is not important
14278+
// in order to find nested loops (Possible CXXRecordDecl, RecordDecl,
14279+
// FunctionDecl...)
14280+
return true;
1428114281
}
1428214282
};
1428314283

@@ -14435,15 +14435,14 @@ bool SemaOpenMP::analyzeLoopSequence(
1443514435
return isa<OMPLoopTransformationDirective>(Child);
1443614436
};
1443714437

14438-
1443914438
// High level grammar validation
1444014439
for (auto *Child : LoopSeqStmt->children()) {
1444114440

14442-
if (!Child)
14441+
if (!Child)
1444314442
continue;
1444414443

14445-
// Skip over non-loop-sequence statements
14446-
if (!isLoopSequenceDerivation(Child)) {
14444+
// Skip over non-loop-sequence statements
14445+
if (!isLoopSequenceDerivation(Child)) {
1444714446
Child = Child->IgnoreContainers();
1444814447

1444914448
// Ignore empty compound statement
@@ -14461,9 +14460,9 @@ bool SemaOpenMP::analyzeLoopSequence(
1446114460
// Already been treated, skip this children
1446214461
continue;
1446314462
}
14464-
}
14465-
// Regular loop sequence handling
14466-
if (isLoopSequenceDerivation(Child)) {
14463+
}
14464+
// Regular loop sequence handling
14465+
if (isLoopSequenceDerivation(Child)) {
1446714466
if (isLoopGeneratingStmt(Child)) {
1446814467
if (!analyzeLoopGeneration(Child)) {
1446914468
return false;
@@ -14477,12 +14476,12 @@ bool SemaOpenMP::analyzeLoopSequence(
1447714476
// Update the Loop Sequence size by one
1447814477
++LoopSeqSize;
1447914478
}
14480-
} else {
14479+
} else {
1448114480
// Report error for invalid statement inside canonical loop sequence
1448214481
Diag(Child->getBeginLoc(), diag::err_omp_not_for)
1448314482
<< 0 << getOpenMPDirectiveName(Kind);
1448414483
return false;
14485-
}
14484+
}
1448614485
}
1448714486
return true;
1448814487
}
@@ -14499,9 +14498,9 @@ bool SemaOpenMP::checkTransformableLoopSequence(
1449914498

1450014499
// Checks whether the given statement is a compound statement
1450114500
if (!isa<CompoundStmt>(AStmt)) {
14502-
Diag(AStmt->getBeginLoc(), diag::err_omp_not_a_loop_sequence)
14503-
<< getOpenMPDirectiveName(Kind);
14504-
return false;
14501+
Diag(AStmt->getBeginLoc(), diag::err_omp_not_a_loop_sequence)
14502+
<< getOpenMPDirectiveName(Kind);
14503+
return false;
1450514504
}
1450614505
// Number of top level canonical loop nests observed (And acts as index)
1450714506
LoopSeqSize = 0;
@@ -14532,7 +14531,7 @@ bool SemaOpenMP::checkTransformableLoopSequence(
1453214531
OriginalInits, TransformsPreInits,
1453314532
LoopSequencePreInits, LoopCategories, Context,
1453414533
Kind)) {
14535-
return false;
14534+
return false;
1453614535
}
1453714536
if (LoopSeqSize <= 0) {
1453814537
Diag(AStmt->getBeginLoc(), diag::err_omp_empty_loop_sequence)
@@ -15233,7 +15232,7 @@ StmtResult SemaOpenMP::ActOnOpenMPUnrollDirective(ArrayRef<OMPClause *> Clauses,
1523315232
Stmt *LoopStmt = nullptr;
1523415233
collectLoopStmts(AStmt, {LoopStmt});
1523515234

15236-
// Determine the PreInit declarations.e
15235+
// Determine the PreInit declarations.
1523715236
SmallVector<Stmt *, 4> PreInits;
1523815237
addLoopPreInits(Context, LoopHelper, LoopStmt, OriginalInits[0], PreInits);
1523915238

@@ -15848,13 +15847,18 @@ StmtResult SemaOpenMP::ActOnOpenMPFuseDirective(ArrayRef<OMPClause *> Clauses,
1584815847
CountVal = CountInt.getZExtValue();
1584915848
};
1585015849

15851-
// Checks if the loop range is valid
15850+
// OpenMP [6.0, Restrictions]
15851+
// first + count - 1 must not evaluate to a value greater than the
15852+
// loop sequence length of the associated canonical loop sequence.
1585215853
auto ValidLoopRange = [](uint64_t FirstVal, uint64_t CountVal,
1585315854
unsigned NumLoops) -> bool {
1585415855
return FirstVal + CountVal - 1 <= NumLoops;
1585515856
};
1585615857
uint64_t FirstVal = 1, CountVal = 0, LastVal = LoopSeqSize;
1585715858

15859+
// Validates the loop range after evaluating the semantic information
15860+
// and ensures that the range is valid for the given loop sequence size.
15861+
// Expressions are evaluated at compile time to obtain constant values.
1585815862
if (LRC) {
1585915863
EvaluateLoopRangeArguments(LRC->getFirst(), LRC->getCount(), FirstVal,
1586015864
CountVal);

0 commit comments

Comments
 (0)