Skip to content

Commit 38db289

Browse files
eZWALTrofirrim
authored andcommitted
Address basic PR feedback
1 parent 7e0a409 commit 38db289

File tree

8 files changed

+166
-196
lines changed

8 files changed

+166
-196
lines changed

clang/include/clang/AST/OpenMPClause.h

Lines changed: 42 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,82 +1159,73 @@ class OMPFullClause final : public OMPNoChildClause<llvm::omp::OMPC_full> {
11591159
/// for(int j = 0; j < 256; j+=2)
11601160
/// for(int k = 127; k >= 0; --k)
11611161
/// \endcode
1162-
class OMPLoopRangeClause final : public OMPClause {
1162+
class OMPLoopRangeClause final
1163+
: public OMPClause,
1164+
private llvm::TrailingObjects<OMPLoopRangeClause, Expr *> {
11631165
friend class OMPClauseReader;
1164-
1165-
explicit OMPLoopRangeClause()
1166-
: OMPClause(llvm::omp::OMPC_looprange, {}, {}) {}
1166+
friend class llvm::TrailingObjects<OMPLoopRangeClause, Expr *>;
11671167

11681168
/// Location of '('
11691169
SourceLocation LParenLoc;
11701170

1171-
/// Location of 'first'
1172-
SourceLocation FirstLoc;
1173-
1174-
/// Location of 'count'
1175-
SourceLocation CountLoc;
1176-
1177-
/// Expr associated with 'first' argument
1178-
Expr *First = nullptr;
1179-
1180-
/// Expr associated with 'count' argument
1181-
Expr *Count = nullptr;
1182-
1183-
/// Set 'first'
1184-
void setFirst(Expr *First) { this->First = First; }
1171+
/// Location of first and count expressions
1172+
SourceLocation FirstLoc, CountLoc;
11851173

1186-
/// Set 'count'
1187-
void setCount(Expr *Count) { this->Count = Count; }
1174+
/// Number of looprange arguments (always 2: first, count)
1175+
unsigned NumArgs = 2;
11881176

1189-
/// Set location of '('.
1190-
void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1191-
1192-
/// Set location of 'first' argument
1193-
void setFirstLoc(SourceLocation Loc) { FirstLoc = Loc; }
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+
}
11941182

1195-
/// Set location of 'count' argument
1196-
void setCountLoc(SourceLocation Loc) { CountLoc = Loc; }
1183+
/// Build an empty clause for deserialization.
1184+
explicit OMPLoopRangeClause()
1185+
: OMPClause(llvm::omp::OMPC_looprange, {}, {}), NumArgs(2) {}
11971186

11981187
public:
1199-
/// Build an AST node for a 'looprange' clause
1200-
///
1201-
/// \param StartLoc Starting location of the clause.
1202-
/// \param LParenLoc Location of '('.
1203-
/// \param ModifierLoc Modifier location.
1204-
/// \param
1188+
/// Build a 'looprange' clause AST node.
12051189
static OMPLoopRangeClause *
12061190
Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
12071191
SourceLocation FirstLoc, SourceLocation CountLoc,
1208-
SourceLocation EndLoc, Expr *First, Expr *Count);
1192+
SourceLocation EndLoc, ArrayRef<Expr *> Args);
12091193

1210-
/// Build an empty 'looprange' node for deserialization
1211-
///
1212-
/// \param C Context of the AST.
1194+
/// Build an empty 'looprange' clause node.
12131195
static OMPLoopRangeClause *CreateEmpty(const ASTContext &C);
12141196

1215-
/// Returns the location of '('
1197+
// Location getters/setters
12161198
SourceLocation getLParenLoc() const { return LParenLoc; }
1217-
1218-
/// Returns the location of 'first'
12191199
SourceLocation getFirstLoc() const { return FirstLoc; }
1220-
1221-
/// Returns the location of 'count'
12221200
SourceLocation getCountLoc() const { return CountLoc; }
12231201

1224-
/// Returns the argument 'first' or nullptr if not set
1225-
Expr *getFirst() const { return cast_or_null<Expr>(First); }
1202+
void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1203+
void setFirstLoc(SourceLocation Loc) { FirstLoc = Loc; }
1204+
void setCountLoc(SourceLocation Loc) { CountLoc = Loc; }
12261205

1227-
/// Returns the argument 'count' or nullptr if not set
1228-
Expr *getCount() const { return cast_or_null<Expr>(Count); }
1206+
/// Get looprange arguments: first and count
1207+
Expr *getFirst() const { return getArgs()[0]; }
1208+
Expr *getCount() const { return getArgs()[1]; }
12291209

1230-
child_range children() {
1231-
return child_range(reinterpret_cast<Stmt **>(&First),
1232-
reinterpret_cast<Stmt **>(&Count) + 1);
1210+
/// Set looprange arguments: first and count
1211+
void setFirst(Expr *E) { getArgs()[0] = E; }
1212+
void setCount(Expr *E) { getArgs()[1] = E; }
1213+
1214+
MutableArrayRef<Expr *> getArgs() {
1215+
return MutableArrayRef<Expr *>(getTrailingObjects<Expr *>(), NumArgs);
1216+
}
1217+
ArrayRef<Expr *> getArgs() const {
1218+
return ArrayRef<Expr *>(getTrailingObjects<Expr *>(), NumArgs);
12331219
}
12341220

1221+
child_range children() {
1222+
return child_range(reinterpret_cast<Stmt **>(getArgs().begin()),
1223+
reinterpret_cast<Stmt **>(getArgs().end()));
1224+
}
12351225
const_child_range children() const {
1236-
auto Children = const_cast<OMPLoopRangeClause *>(this)->children();
1237-
return const_child_range(Children.begin(), Children.end());
1226+
auto AR = getArgs();
1227+
return const_child_range(reinterpret_cast<Stmt *const *>(AR.begin()),
1228+
reinterpret_cast<Stmt *const *>(AR.end()));
12381229
}
12391230

12401231
child_range used_children() {

clang/include/clang/AST/StmtOpenMP.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5882,7 +5882,7 @@ class OMPInterchangeDirective final : public OMPLoopTransformationDirective {
58825882
EndLoc, NumLoops) {
58835883
// Interchange produces a single top-level canonical loop
58845884
// nest, with the exact same amount of total loops
5885-
setNumGeneratedLoops(NumLoops);
5885+
setNumGeneratedLoops(3 * NumLoops);
58865886
setNumGeneratedLoopNests(1);
58875887
}
58885888

clang/include/clang/Sema/SemaOpenMP.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,7 +1492,7 @@ class SemaOpenMP : public SemaBase {
14921492
bool checkTransformableLoopNest(
14931493
OpenMPDirectiveKind Kind, Stmt *AStmt, int NumLoops,
14941494
SmallVectorImpl<OMPLoopBasedDirective::HelperExprs> &LoopHelpers,
1495-
Stmt *&Body, SmallVectorImpl<SmallVector<Stmt *, 0>> &OriginalInits);
1495+
Stmt *&Body, SmallVectorImpl<SmallVector<Stmt *>> &OriginalInits);
14961496

14971497
/// @brief Categories of loops encountered during semantic OpenMP loop
14981498
/// analysis
@@ -1555,9 +1555,9 @@ class SemaOpenMP : public SemaBase {
15551555
Stmt *LoopSeqStmt, unsigned &LoopSeqSize, unsigned &NumLoops,
15561556
SmallVectorImpl<OMPLoopBasedDirective::HelperExprs> &LoopHelpers,
15571557
SmallVectorImpl<Stmt *> &ForStmts,
1558-
SmallVectorImpl<SmallVector<Stmt *, 0>> &OriginalInits,
1559-
SmallVectorImpl<SmallVector<Stmt *, 0>> &TransformsPreInits,
1560-
SmallVectorImpl<SmallVector<Stmt *, 0>> &LoopSequencePreInits,
1558+
SmallVectorImpl<SmallVector<Stmt *>> &OriginalInits,
1559+
SmallVectorImpl<SmallVector<Stmt *>> &TransformsPreInits,
1560+
SmallVectorImpl<SmallVector<Stmt *>> &LoopSequencePreInits,
15611561
SmallVectorImpl<OMPLoopCategory> &LoopCategories, ASTContext &Context,
15621562
OpenMPDirectiveKind Kind);
15631563

@@ -1591,9 +1591,9 @@ class SemaOpenMP : public SemaBase {
15911591
unsigned &NumLoops,
15921592
SmallVectorImpl<OMPLoopBasedDirective::HelperExprs> &LoopHelpers,
15931593
SmallVectorImpl<Stmt *> &ForStmts,
1594-
SmallVectorImpl<SmallVector<Stmt *, 0>> &OriginalInits,
1595-
SmallVectorImpl<SmallVector<Stmt *, 0>> &TransformsPreInits,
1596-
SmallVectorImpl<SmallVector<Stmt *, 0>> &LoopSequencePreInits,
1594+
SmallVectorImpl<SmallVector<Stmt *>> &OriginalInits,
1595+
SmallVectorImpl<SmallVector<Stmt *>> &TransformsPreInits,
1596+
SmallVectorImpl<SmallVector<Stmt *>> &LoopSequencePreInits,
15971597
SmallVectorImpl<OMPLoopCategory> &LoopCategories, ASTContext &Context);
15981598

15991599
/// Helper to keep information about the current `omp begin/end declare

clang/lib/AST/OpenMPClause.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,22 +1022,25 @@ OMPPartialClause *OMPPartialClause::CreateEmpty(const ASTContext &C) {
10221022

10231023
OMPLoopRangeClause *
10241024
OMPLoopRangeClause::Create(const ASTContext &C, SourceLocation StartLoc,
1025-
SourceLocation LParenLoc, SourceLocation EndLoc,
1026-
SourceLocation FirstLoc, SourceLocation CountLoc,
1027-
Expr *First, Expr *Count) {
1025+
SourceLocation LParenLoc, SourceLocation FirstLoc,
1026+
SourceLocation CountLoc, SourceLocation EndLoc,
1027+
ArrayRef<Expr *> Args) {
1028+
1029+
assert(Args.size() == 2 &&
1030+
"looprange clause must have exactly two arguments");
10281031
OMPLoopRangeClause *Clause = CreateEmpty(C);
10291032
Clause->setLocStart(StartLoc);
10301033
Clause->setLParenLoc(LParenLoc);
1031-
Clause->setLocEnd(EndLoc);
10321034
Clause->setFirstLoc(FirstLoc);
10331035
Clause->setCountLoc(CountLoc);
1034-
Clause->setFirst(First);
1035-
Clause->setCount(Count);
1036+
Clause->setLocEnd(EndLoc);
1037+
Clause->setArgs(Args);
10361038
return Clause;
10371039
}
10381040

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

10431046
OMPAllocateClause *OMPAllocateClause::Create(

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3256,11 +3256,8 @@ LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) {
32563256
var, ConvertTypeForMem(VD->getType()), getContext().getDeclAlign(VD));
32573257

32583258
// No other cases for now.
3259-
} else {
3260-
llvm::dbgs() << "THE DAMN DECLREFEXPR HASN'T BEEN ENTERED IN LOCALDECLMAP\n";
3261-
VD->dumpColor();
3259+
} else
32623260
llvm_unreachable("DeclRefExpr for Decl not entered in LocalDeclMap?");
3263-
}
32643261

32653262
// Handle threadlocal function locals.
32663263
if (VD->getTLSKind() != VarDecl::TLS_None)

clang/lib/CodeGen/CodeGenFunction.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5372,10 +5372,6 @@ class CodeGenFunction : public CodeGenTypeCache {
53725372

53735373
/// Set the address of a local variable.
53745374
void setAddrOfLocalVar(const VarDecl *VD, Address Addr) {
5375-
if (LocalDeclMap.count(VD)) {
5376-
llvm::errs() << "Warning: VarDecl already exists in map: ";
5377-
VD->dumpColor();
5378-
}
53795375
assert(!LocalDeclMap.count(VD) && "Decl already exists in LocalDeclMap!");
53805376
LocalDeclMap.insert({VD, Addr});
53815377
}

0 commit comments

Comments
 (0)