Skip to content

Commit 7ffd140

Browse files
committed
Address some of the feedback
1 parent 473d783 commit 7ffd140

File tree

4 files changed

+63
-88
lines changed

4 files changed

+63
-88
lines changed

clang/include/clang/AST/OpenMPClause.h

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,36 +1160,34 @@ class OMPFullClause final : public OMPNoChildClause<llvm::omp::OMPC_full> {
11601160
/// for(int k = 127; k >= 0; --k)
11611161
/// \endcode
11621162
class OMPLoopRangeClause final
1163-
: public OMPClause,
1164-
private llvm::TrailingObjects<OMPLoopRangeClause, Expr *> {
1163+
: public OMPClause {
11651164
friend class OMPClauseReader;
1166-
friend class llvm::TrailingObjects<OMPLoopRangeClause, Expr *>;
1167-
11681165
/// Location of '('
11691166
SourceLocation LParenLoc;
11701167

11711168
/// Location of first and count expressions
11721169
SourceLocation FirstLoc, CountLoc;
11731170

11741171
/// Number of looprange arguments (always 2: first, count)
1175-
unsigned NumArgs = 2;
1172+
static constexpr unsigned NumArgs = 2;
1173+
Stmt *Args[NumArgs] = {nullptr, nullptr};
11761174

1177-
/// Set the argument expressions.
1178-
void setArgs(ArrayRef<Expr *> Args) {
1179-
assert(Args.size() == NumArgs && "Expected exactly 2 looprange arguments");
1180-
std::copy(Args.begin(), Args.end(), getTrailingObjects<Expr *>());
1181-
}
1175+
/// Set looprange 'first' expression
1176+
void setFirst(Expr *E) { Args[0] = E; }
1177+
1178+
/// Set looprange 'count' expression
1179+
void setCount(Expr *E) { Args[1] = E; }
11821180

11831181
/// Build an empty clause for deserialization.
11841182
explicit OMPLoopRangeClause()
1185-
: OMPClause(llvm::omp::OMPC_looprange, {}, {}), NumArgs(2) {}
1183+
: OMPClause(llvm::omp::OMPC_looprange, {}, {}) {}
11861184

11871185
public:
11881186
/// Build a 'looprange' clause AST node.
11891187
static OMPLoopRangeClause *
11901188
Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
11911189
SourceLocation FirstLoc, SourceLocation CountLoc,
1192-
SourceLocation EndLoc, ArrayRef<Expr *> Args);
1190+
SourceLocation EndLoc, Expr* First, Expr* Count);
11931191

11941192
/// Build an empty 'looprange' clause node.
11951193
static OMPLoopRangeClause *CreateEmpty(const ASTContext &C);
@@ -1204,32 +1202,16 @@ class OMPLoopRangeClause final
12041202
void setCountLoc(SourceLocation Loc) { CountLoc = Loc; }
12051203

12061204
/// Get looprange 'first' expression
1207-
Expr *getFirst() const { return getArgs()[0]; }
1205+
Expr *getFirst() const { return cast_or_null<Expr>(Args[0]); }
12081206

12091207
/// Get looprange 'count' expression
1210-
Expr *getCount() const { return getArgs()[1]; }
1211-
1212-
/// Set looprange 'first' expression
1213-
void setFirst(Expr *E) { getArgs()[0] = E; }
1214-
1215-
/// Set looprange 'count' expression
1216-
void setCount(Expr *E) { getArgs()[1] = E; }
1217-
1218-
MutableArrayRef<Expr *> getArgs() {
1219-
return MutableArrayRef<Expr *>(getTrailingObjects<Expr *>(), NumArgs);
1220-
}
1221-
ArrayRef<Expr *> getArgs() const {
1222-
return ArrayRef<Expr *>(getTrailingObjects<Expr *>(), NumArgs);
1223-
}
1208+
Expr *getCount() const { return cast_or_null<Expr>(Args[1]); }
12241209

12251210
child_range children() {
1226-
return child_range(reinterpret_cast<Stmt **>(getArgs().begin()),
1227-
reinterpret_cast<Stmt **>(getArgs().end()));
1211+
return child_range(Args, Args + NumArgs);
12281212
}
12291213
const_child_range children() const {
1230-
auto AR = getArgs();
1231-
return const_child_range(reinterpret_cast<Stmt *const *>(AR.begin()),
1232-
reinterpret_cast<Stmt *const *>(AR.end()));
1214+
return const_child_range(Args, Args + NumArgs);
12331215
}
12341216

12351217
child_range used_children() {

clang/include/clang/Sema/SemaOpenMP.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1494,7 +1494,7 @@ class SemaOpenMP : public SemaBase {
14941494
SmallVectorImpl<OMPLoopBasedDirective::HelperExprs> &LoopHelpers,
14951495
Stmt *&Body, SmallVectorImpl<SmallVector<Stmt *>> &OriginalInits);
14961496

1497-
/// @brief Categories of loops encountered during semantic OpenMP loop
1497+
/// Categories of loops encountered during semantic OpenMP loop
14981498
/// analysis
14991499
///
15001500
/// This enumeration identifies the structural category of a loop or sequence

clang/lib/AST/OpenMPClause.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,23 +1024,20 @@ OMPLoopRangeClause *
10241024
OMPLoopRangeClause::Create(const ASTContext &C, SourceLocation StartLoc,
10251025
SourceLocation LParenLoc, SourceLocation FirstLoc,
10261026
SourceLocation CountLoc, SourceLocation EndLoc,
1027-
ArrayRef<Expr *> Args) {
1028-
1029-
assert(Args.size() == 2 &&
1030-
"looprange clause must have exactly two arguments");
1027+
Expr *First, Expr* Count) {
10311028
OMPLoopRangeClause *Clause = CreateEmpty(C);
10321029
Clause->setLocStart(StartLoc);
10331030
Clause->setLParenLoc(LParenLoc);
10341031
Clause->setFirstLoc(FirstLoc);
10351032
Clause->setCountLoc(CountLoc);
10361033
Clause->setLocEnd(EndLoc);
1037-
Clause->setArgs(Args);
1034+
Clause->setFirst(First);
1035+
Clause->setCount(Count);
10381036
return Clause;
10391037
}
10401038

10411039
OMPLoopRangeClause *OMPLoopRangeClause::CreateEmpty(const ASTContext &C) {
1042-
void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2));
1043-
return new (Mem) OMPLoopRangeClause();
1040+
return new (C) OMPLoopRangeClause();
10441041
}
10451042

10461043
OMPAllocateClause *OMPAllocateClause::Create(

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 44 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -14212,29 +14212,29 @@ StmtResult SemaOpenMP::ActOnOpenMPTargetTeamsDistributeSimdDirective(
1421214212
}
1421314213

1421414214
/// Overloaded base case function
14215-
template <typename T, typename F> static bool tryHandleAs(T *t, F &&) {
14215+
template <typename T, typename F> static bool tryHandleAs(T *, F &&) {
1421614216
return false;
1421714217
}
1421814218

14219-
/// Tries to recursively cast `t` to one of the given types and invokes `f` if
14220-
/// successful.
14219+
/// Tries to recursively cast `Type` to one of the given types and invokes
14220+
/// `Func` if successful.
1422114221
///
14222-
/// @tparam Class The first type to check.
14223-
/// @tparam Rest The remaining types to check.
14224-
/// @tparam T The base type of `t`.
14225-
/// @tparam F The callable type for the function to invoke upon a successful
14222+
/// \tparam Class The first type to check.
14223+
/// \tparam Rest The remaining types to check.
14224+
/// \tparam T The base type of `Type`.
14225+
/// \tparam F The callable type for the function to invoke upon a successful
1422614226
/// cast.
14227-
/// @param t The object to be checked.
14228-
/// @param f The function to invoke if `t` matches `Class`.
14229-
/// @return `true` if `t` matched any type and `f` was called, otherwise
14227+
/// \param Type The object to be checked.
14228+
/// \param Func The function to invoke if `Type` matches `Class`.
14229+
/// \return `true` if `Type` matched any type and `Func` was called, otherwise
1423014230
/// `false`.
1423114231
template <typename Class, typename... Rest, typename T, typename F>
14232-
static bool tryHandleAs(T *t, F &&f) {
14233-
if (Class *c = dyn_cast<Class>(t)) {
14234-
f(c);
14232+
static bool tryHandleAs(T *Type, F &&Func) {
14233+
if (Class *C = dyn_cast<Class>(Type)) {
14234+
Func(C);
1423514235
return true;
1423614236
}
14237-
return tryHandleAs<Rest...>(t, std::forward<F>(f));
14237+
return tryHandleAs<Rest...>(Type, std::forward<F>(Func));
1423814238
}
1423914239

1424014240
/// Updates OriginalInits by checking Transform against loop transformation
@@ -14314,7 +14314,7 @@ bool SemaOpenMP::checkTransformableLoopNest(
1431414314
/// }
1431514315
/// }
1431614316
/// Result: Loop 'i' contains 2 loops, Loop 'r' also contains 2 loops
14317-
class NestedLoopCounterVisitor : public DynamicRecursiveASTVisitor {
14317+
class NestedLoopCounterVisitor final : public DynamicRecursiveASTVisitor {
1431814318
private:
1431914319
unsigned NestedLoopCount = 0;
1432014320

@@ -14402,22 +14402,21 @@ bool SemaOpenMP::analyzeLoopSequence(
1440214402
LoopSeqSize += NumGeneratedLoopNests;
1440314403
NumLoops += NumGeneratedLoops;
1440414404
return true;
14405-
} else {
14406-
// Unroll full (0 loops produced)
14407-
Diag(Child->getBeginLoc(), diag::err_omp_not_for)
14408-
<< 0 << getOpenMPDirectiveName(Kind);
14409-
return false;
1441014405
}
14406+
// Unroll full (0 loops produced)
14407+
Diag(Child->getBeginLoc(), diag::err_omp_not_for)
14408+
<< 0 << getOpenMPDirectiveName(Kind);
14409+
return false;
1441114410
}
1441214411
// Handle loop transformations with multiple loop nests
1441314412
// Unroll full
14414-
if (NumGeneratedLoopNests <= 0) {
14413+
if (!NumGeneratedLoopNests) {
1441514414
Diag(Child->getBeginLoc(), diag::err_omp_not_for)
1441614415
<< 0 << getOpenMPDirectiveName(Kind);
1441714416
return false;
1441814417
}
1441914418
// Loop transformatons such as split or loopranged fuse
14420-
else if (NumGeneratedLoopNests > 1) {
14419+
if (NumGeneratedLoopNests > 1) {
1442114420
// Get the preinits related to this loop sequence generating
1442214421
// loop transformation (i.e loopranged fuse, split...)
1442314422
LoopSequencePreInits.emplace_back();
@@ -14430,30 +14429,29 @@ bool SemaOpenMP::analyzeLoopSequence(
1443014429
LoopHelpers, ForStmts, OriginalInits,
1443114430
TransformsPreInits, LoopSequencePreInits,
1443214431
LoopCategories, Context, Kind);
14433-
} else {
14434-
// Vast majority: (Tile, Unroll, Stripe, Reverse, Interchange, Fuse all)
14435-
// Process the transformed loop statement
14436-
OriginalInits.emplace_back();
14437-
TransformsPreInits.emplace_back();
14438-
LoopHelpers.emplace_back();
14439-
LoopCategories.push_back(OMPLoopCategory::TransformSingleLoop);
14440-
14441-
unsigned IsCanonical =
14442-
checkOpenMPLoop(Kind, nullptr, nullptr, TransformedStmt, SemaRef,
14443-
*DSAStack, TmpDSA, LoopHelpers[LoopSeqSize]);
14444-
14445-
if (!IsCanonical) {
14446-
Diag(TransformedStmt->getBeginLoc(), diag::err_omp_not_canonical_loop)
14447-
<< getOpenMPDirectiveName(Kind);
14448-
return false;
14449-
}
14450-
StoreLoopStatements(TransformedStmt);
14451-
updatePreInits(LoopTransform, TransformsPreInits);
14432+
}
14433+
// Vast majority: (Tile, Unroll, Stripe, Reverse, Interchange, Fuse all)
14434+
// Process the transformed loop statement
14435+
OriginalInits.emplace_back();
14436+
TransformsPreInits.emplace_back();
14437+
LoopHelpers.emplace_back();
14438+
LoopCategories.push_back(OMPLoopCategory::TransformSingleLoop);
1445214439

14453-
NumLoops += NumGeneratedLoops;
14454-
++LoopSeqSize;
14455-
return true;
14440+
unsigned IsCanonical =
14441+
checkOpenMPLoop(Kind, nullptr, nullptr, TransformedStmt, SemaRef,
14442+
*DSAStack, TmpDSA, LoopHelpers[LoopSeqSize]);
14443+
14444+
if (!IsCanonical) {
14445+
Diag(TransformedStmt->getBeginLoc(), diag::err_omp_not_canonical_loop)
14446+
<< getOpenMPDirectiveName(Kind);
14447+
return false;
1445614448
}
14449+
StoreLoopStatements(TransformedStmt);
14450+
updatePreInits(LoopTransform, TransformsPreInits);
14451+
14452+
NumLoops += NumGeneratedLoops;
14453+
++LoopSeqSize;
14454+
return true;
1445714455
};
1445814456

1445914457
/// Modularized code for handling regular canonical loops
@@ -16320,7 +16318,7 @@ StmtResult SemaOpenMP::ActOnOpenMPFuseDirective(ArrayRef<OMPClause *> Clauses,
1632016318
// Only TransformSingleLoop requires inserting pre-inits here
1632116319

1632216320
if (LoopCategories[I] == OMPLoopCategory::TransformSingleLoop) {
16323-
auto TransformPreInit = TransformsPreInits[TransformIndex++];
16321+
const auto &TransformPreInit = TransformsPreInits[TransformIndex++];
1632416322
if (!TransformPreInit.empty()) {
1632516323
llvm::append_range(PreInits, TransformPreInit);
1632616324
}
@@ -17483,15 +17481,13 @@ OMPClause *SemaOpenMP::ActOnOpenMPLoopRangeClause(
1748317481
if (CountVal.isInvalid())
1748417482
Count = nullptr;
1748517483

17486-
SmallVector<Expr *, 2> ArgsVec = {First, Count};
17487-
1748817484
// OpenMP [6.0, Restrictions]
1748917485
// first + count - 1 must not evaluate to a value greater than the
1749017486
// loop sequence length of the associated canonical loop sequence.
1749117487
// This check must be performed afterwards due to the delayed
1749217488
// parsing and computation of the associated loop sequence
1749317489
return OMPLoopRangeClause::Create(getASTContext(), StartLoc, LParenLoc,
17494-
FirstLoc, CountLoc, EndLoc, ArgsVec);
17490+
FirstLoc, CountLoc, EndLoc, First, Count);
1749517491
}
1749617492

1749717493
OMPClause *SemaOpenMP::ActOnOpenMPAlignClause(Expr *A, SourceLocation StartLoc,

0 commit comments

Comments
 (0)