Skip to content

Commit eb46445

Browse files
committed
Address some of the feedback
1 parent 009d863 commit eb46445

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
@@ -1154,36 +1154,34 @@ class OMPFullClause final : public OMPNoChildClause<llvm::omp::OMPC_full> {
11541154
/// for(int k = 127; k >= 0; --k)
11551155
/// \endcode
11561156
class OMPLoopRangeClause final
1157-
: public OMPClause,
1158-
private llvm::TrailingObjects<OMPLoopRangeClause, Expr *> {
1157+
: public OMPClause {
11591158
friend class OMPClauseReader;
1160-
friend class llvm::TrailingObjects<OMPLoopRangeClause, Expr *>;
1161-
11621159
/// Location of '('
11631160
SourceLocation LParenLoc;
11641161

11651162
/// Location of first and count expressions
11661163
SourceLocation FirstLoc, CountLoc;
11671164

11681165
/// Number of looprange arguments (always 2: first, count)
1169-
unsigned NumArgs = 2;
1166+
static constexpr unsigned NumArgs = 2;
1167+
Stmt *Args[NumArgs] = {nullptr, nullptr};
11701168

1171-
/// Set the argument expressions.
1172-
void setArgs(ArrayRef<Expr *> Args) {
1173-
assert(Args.size() == NumArgs && "Expected exactly 2 looprange arguments");
1174-
std::copy(Args.begin(), Args.end(), getTrailingObjects<Expr *>());
1175-
}
1169+
/// Set looprange 'first' expression
1170+
void setFirst(Expr *E) { Args[0] = E; }
1171+
1172+
/// Set looprange 'count' expression
1173+
void setCount(Expr *E) { Args[1] = E; }
11761174

11771175
/// Build an empty clause for deserialization.
11781176
explicit OMPLoopRangeClause()
1179-
: OMPClause(llvm::omp::OMPC_looprange, {}, {}), NumArgs(2) {}
1177+
: OMPClause(llvm::omp::OMPC_looprange, {}, {}) {}
11801178

11811179
public:
11821180
/// Build a 'looprange' clause AST node.
11831181
static OMPLoopRangeClause *
11841182
Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
11851183
SourceLocation FirstLoc, SourceLocation CountLoc,
1186-
SourceLocation EndLoc, ArrayRef<Expr *> Args);
1184+
SourceLocation EndLoc, Expr* First, Expr* Count);
11871185

11881186
/// Build an empty 'looprange' clause node.
11891187
static OMPLoopRangeClause *CreateEmpty(const ASTContext &C);
@@ -1198,32 +1196,16 @@ class OMPLoopRangeClause final
11981196
void setCountLoc(SourceLocation Loc) { CountLoc = Loc; }
11991197

12001198
/// Get looprange 'first' expression
1201-
Expr *getFirst() const { return getArgs()[0]; }
1199+
Expr *getFirst() const { return cast_or_null<Expr>(Args[0]); }
12021200

12031201
/// Get looprange 'count' expression
1204-
Expr *getCount() const { return getArgs()[1]; }
1205-
1206-
/// Set looprange 'first' expression
1207-
void setFirst(Expr *E) { getArgs()[0] = E; }
1208-
1209-
/// Set looprange 'count' expression
1210-
void setCount(Expr *E) { getArgs()[1] = E; }
1211-
1212-
MutableArrayRef<Expr *> getArgs() {
1213-
return MutableArrayRef<Expr *>(getTrailingObjects<Expr *>(), NumArgs);
1214-
}
1215-
ArrayRef<Expr *> getArgs() const {
1216-
return ArrayRef<Expr *>(getTrailingObjects<Expr *>(), NumArgs);
1217-
}
1202+
Expr *getCount() const { return cast_or_null<Expr>(Args[1]); }
12181203

12191204
child_range children() {
1220-
return child_range(reinterpret_cast<Stmt **>(getArgs().begin()),
1221-
reinterpret_cast<Stmt **>(getArgs().end()));
1205+
return child_range(Args, Args + NumArgs);
12221206
}
12231207
const_child_range children() const {
1224-
auto AR = getArgs();
1225-
return const_child_range(reinterpret_cast<Stmt *const *>(AR.begin()),
1226-
reinterpret_cast<Stmt *const *>(AR.end()));
1208+
return const_child_range(Args, Args + NumArgs);
12271209
}
12281210

12291211
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
@@ -1028,23 +1028,20 @@ OMPLoopRangeClause *
10281028
OMPLoopRangeClause::Create(const ASTContext &C, SourceLocation StartLoc,
10291029
SourceLocation LParenLoc, SourceLocation FirstLoc,
10301030
SourceLocation CountLoc, SourceLocation EndLoc,
1031-
ArrayRef<Expr *> Args) {
1032-
1033-
assert(Args.size() == 2 &&
1034-
"looprange clause must have exactly two arguments");
1031+
Expr *First, Expr* Count) {
10351032
OMPLoopRangeClause *Clause = CreateEmpty(C);
10361033
Clause->setLocStart(StartLoc);
10371034
Clause->setLParenLoc(LParenLoc);
10381035
Clause->setFirstLoc(FirstLoc);
10391036
Clause->setCountLoc(CountLoc);
10401037
Clause->setLocEnd(EndLoc);
1041-
Clause->setArgs(Args);
1038+
Clause->setFirst(First);
1039+
Clause->setCount(Count);
10421040
return Clause;
10431041
}
10441042

10451043
OMPLoopRangeClause *OMPLoopRangeClause::CreateEmpty(const ASTContext &C) {
1046-
void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2));
1047-
return new (Mem) OMPLoopRangeClause();
1044+
return new (C) OMPLoopRangeClause();
10481045
}
10491046

10501047
OMPAllocateClause *OMPAllocateClause::Create(

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 44 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -14195,29 +14195,29 @@ StmtResult SemaOpenMP::ActOnOpenMPTargetTeamsDistributeSimdDirective(
1419514195
}
1419614196

1419714197
/// Overloaded base case function
14198-
template <typename T, typename F> static bool tryHandleAs(T *t, F &&) {
14198+
template <typename T, typename F> static bool tryHandleAs(T *, F &&) {
1419914199
return false;
1420014200
}
1420114201

14202-
/// Tries to recursively cast `t` to one of the given types and invokes `f` if
14203-
/// successful.
14202+
/// Tries to recursively cast `Type` to one of the given types and invokes
14203+
/// `Func` if successful.
1420414204
///
14205-
/// @tparam Class The first type to check.
14206-
/// @tparam Rest The remaining types to check.
14207-
/// @tparam T The base type of `t`.
14208-
/// @tparam F The callable type for the function to invoke upon a successful
14205+
/// \tparam Class The first type to check.
14206+
/// \tparam Rest The remaining types to check.
14207+
/// \tparam T The base type of `Type`.
14208+
/// \tparam F The callable type for the function to invoke upon a successful
1420914209
/// cast.
14210-
/// @param t The object to be checked.
14211-
/// @param f The function to invoke if `t` matches `Class`.
14212-
/// @return `true` if `t` matched any type and `f` was called, otherwise
14210+
/// \param Type The object to be checked.
14211+
/// \param Func The function to invoke if `Type` matches `Class`.
14212+
/// \return `true` if `Type` matched any type and `Func` was called, otherwise
1421314213
/// `false`.
1421414214
template <typename Class, typename... Rest, typename T, typename F>
14215-
static bool tryHandleAs(T *t, F &&f) {
14216-
if (Class *c = dyn_cast<Class>(t)) {
14217-
f(c);
14215+
static bool tryHandleAs(T *Type, F &&Func) {
14216+
if (Class *C = dyn_cast<Class>(Type)) {
14217+
Func(C);
1421814218
return true;
1421914219
}
14220-
return tryHandleAs<Rest...>(t, std::forward<F>(f));
14220+
return tryHandleAs<Rest...>(Type, std::forward<F>(Func));
1422114221
}
1422214222

1422314223
/// Updates OriginalInits by checking Transform against loop transformation
@@ -14297,7 +14297,7 @@ bool SemaOpenMP::checkTransformableLoopNest(
1429714297
/// }
1429814298
/// }
1429914299
/// Result: Loop 'i' contains 2 loops, Loop 'r' also contains 2 loops
14300-
class NestedLoopCounterVisitor : public DynamicRecursiveASTVisitor {
14300+
class NestedLoopCounterVisitor final : public DynamicRecursiveASTVisitor {
1430114301
private:
1430214302
unsigned NestedLoopCount = 0;
1430314303

@@ -14385,22 +14385,21 @@ bool SemaOpenMP::analyzeLoopSequence(
1438514385
LoopSeqSize += NumGeneratedLoopNests;
1438614386
NumLoops += NumGeneratedLoops;
1438714387
return true;
14388-
} else {
14389-
// Unroll full (0 loops produced)
14390-
Diag(Child->getBeginLoc(), diag::err_omp_not_for)
14391-
<< 0 << getOpenMPDirectiveName(Kind);
14392-
return false;
1439314388
}
14389+
// Unroll full (0 loops produced)
14390+
Diag(Child->getBeginLoc(), diag::err_omp_not_for)
14391+
<< 0 << getOpenMPDirectiveName(Kind);
14392+
return false;
1439414393
}
1439514394
// Handle loop transformations with multiple loop nests
1439614395
// Unroll full
14397-
if (NumGeneratedLoopNests <= 0) {
14396+
if (!NumGeneratedLoopNests) {
1439814397
Diag(Child->getBeginLoc(), diag::err_omp_not_for)
1439914398
<< 0 << getOpenMPDirectiveName(Kind);
1440014399
return false;
1440114400
}
1440214401
// Loop transformatons such as split or loopranged fuse
14403-
else if (NumGeneratedLoopNests > 1) {
14402+
if (NumGeneratedLoopNests > 1) {
1440414403
// Get the preinits related to this loop sequence generating
1440514404
// loop transformation (i.e loopranged fuse, split...)
1440614405
LoopSequencePreInits.emplace_back();
@@ -14413,30 +14412,29 @@ bool SemaOpenMP::analyzeLoopSequence(
1441314412
LoopHelpers, ForStmts, OriginalInits,
1441414413
TransformsPreInits, LoopSequencePreInits,
1441514414
LoopCategories, Context, Kind);
14416-
} else {
14417-
// Vast majority: (Tile, Unroll, Stripe, Reverse, Interchange, Fuse all)
14418-
// Process the transformed loop statement
14419-
OriginalInits.emplace_back();
14420-
TransformsPreInits.emplace_back();
14421-
LoopHelpers.emplace_back();
14422-
LoopCategories.push_back(OMPLoopCategory::TransformSingleLoop);
14423-
14424-
unsigned IsCanonical =
14425-
checkOpenMPLoop(Kind, nullptr, nullptr, TransformedStmt, SemaRef,
14426-
*DSAStack, TmpDSA, LoopHelpers[LoopSeqSize]);
14427-
14428-
if (!IsCanonical) {
14429-
Diag(TransformedStmt->getBeginLoc(), diag::err_omp_not_canonical_loop)
14430-
<< getOpenMPDirectiveName(Kind);
14431-
return false;
14432-
}
14433-
StoreLoopStatements(TransformedStmt);
14434-
updatePreInits(LoopTransform, TransformsPreInits);
14415+
}
14416+
// Vast majority: (Tile, Unroll, Stripe, Reverse, Interchange, Fuse all)
14417+
// Process the transformed loop statement
14418+
OriginalInits.emplace_back();
14419+
TransformsPreInits.emplace_back();
14420+
LoopHelpers.emplace_back();
14421+
LoopCategories.push_back(OMPLoopCategory::TransformSingleLoop);
1443514422

14436-
NumLoops += NumGeneratedLoops;
14437-
++LoopSeqSize;
14438-
return true;
14423+
unsigned IsCanonical =
14424+
checkOpenMPLoop(Kind, nullptr, nullptr, TransformedStmt, SemaRef,
14425+
*DSAStack, TmpDSA, LoopHelpers[LoopSeqSize]);
14426+
14427+
if (!IsCanonical) {
14428+
Diag(TransformedStmt->getBeginLoc(), diag::err_omp_not_canonical_loop)
14429+
<< getOpenMPDirectiveName(Kind);
14430+
return false;
1443914431
}
14432+
StoreLoopStatements(TransformedStmt);
14433+
updatePreInits(LoopTransform, TransformsPreInits);
14434+
14435+
NumLoops += NumGeneratedLoops;
14436+
++LoopSeqSize;
14437+
return true;
1444014438
};
1444114439

1444214440
/// Modularized code for handling regular canonical loops
@@ -16303,7 +16301,7 @@ StmtResult SemaOpenMP::ActOnOpenMPFuseDirective(ArrayRef<OMPClause *> Clauses,
1630316301
// Only TransformSingleLoop requires inserting pre-inits here
1630416302

1630516303
if (LoopCategories[I] == OMPLoopCategory::TransformSingleLoop) {
16306-
auto TransformPreInit = TransformsPreInits[TransformIndex++];
16304+
const auto &TransformPreInit = TransformsPreInits[TransformIndex++];
1630716305
if (!TransformPreInit.empty()) {
1630816306
llvm::append_range(PreInits, TransformPreInit);
1630916307
}
@@ -17456,15 +17454,13 @@ OMPClause *SemaOpenMP::ActOnOpenMPLoopRangeClause(
1745617454
if (CountVal.isInvalid())
1745717455
Count = nullptr;
1745817456

17459-
SmallVector<Expr *, 2> ArgsVec = {First, Count};
17460-
1746117457
// OpenMP [6.0, Restrictions]
1746217458
// first + count - 1 must not evaluate to a value greater than the
1746317459
// loop sequence length of the associated canonical loop sequence.
1746417460
// This check must be performed afterwards due to the delayed
1746517461
// parsing and computation of the associated loop sequence
1746617462
return OMPLoopRangeClause::Create(getASTContext(), StartLoc, LParenLoc,
17467-
FirstLoc, CountLoc, EndLoc, ArgsVec);
17463+
FirstLoc, CountLoc, EndLoc, First, Count);
1746817464
}
1746917465

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

0 commit comments

Comments
 (0)