Skip to content

Commit 8dba664

Browse files
committed
[OPENMP] parsing 'linear' clause (for directive 'omp simd')
Differential Revision: http://reviews.llvm.org/D3272 llvm-svn: 206891
1 parent 761aa37 commit 8dba664

20 files changed

+693
-20
lines changed

clang/include/clang/AST/DataRecursiveASTVisitor.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2405,6 +2405,14 @@ bool DataRecursiveASTVisitor<Derived>::VisitOMPSharedClause(OMPSharedClause *C)
24052405
return true;
24062406
}
24072407

2408+
template<typename Derived>
2409+
bool
2410+
DataRecursiveASTVisitor<Derived>::VisitOMPLinearClause(OMPLinearClause *C) {
2411+
VisitOMPClauseList(C);
2412+
TraverseStmt(C->getStep());
2413+
return true;
2414+
}
2415+
24082416
template<typename Derived>
24092417
bool DataRecursiveASTVisitor<Derived>::VisitOMPCopyinClause(OMPCopyinClause *C) {
24102418
VisitOMPClauseList(C);

clang/include/clang/AST/OpenMPClause.h

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,91 @@ class OMPSharedClause : public OMPVarListClause<OMPSharedClause> {
553553
}
554554
};
555555

556+
/// \brief This represents clause 'linear' in the '#pragma omp ...'
557+
/// directives.
558+
///
559+
/// \code
560+
/// #pragma omp simd linear(a,b : 2)
561+
/// \endcode
562+
/// In this example directive '#pragma omp simd' has clause 'linear'
563+
/// with variables 'a', 'b' and linear step '2'.
564+
///
565+
class OMPLinearClause : public OMPVarListClause<OMPLinearClause> {
566+
friend class OMPClauseReader;
567+
/// \brief Location of ':'.
568+
SourceLocation ColonLoc;
569+
570+
/// \brief Sets the linear step for clause.
571+
void setStep(Expr *Step) { *varlist_end() = Step; }
572+
573+
/// \brief Build 'linear' clause with given number of variables \a NumVars.
574+
///
575+
/// \param StartLoc Starting location of the clause.
576+
/// \param LParenLoc Location of '('.
577+
/// \param ColonLoc Location of ':'.
578+
/// \param EndLoc Ending location of the clause.
579+
/// \param NumVars Number of variables.
580+
///
581+
OMPLinearClause(SourceLocation StartLoc, SourceLocation LParenLoc,
582+
SourceLocation ColonLoc, SourceLocation EndLoc,
583+
unsigned NumVars)
584+
: OMPVarListClause<OMPLinearClause>(OMPC_linear, StartLoc, LParenLoc,
585+
EndLoc, NumVars),
586+
ColonLoc(ColonLoc) {}
587+
588+
/// \brief Build an empty clause.
589+
///
590+
/// \param NumVars Number of variables.
591+
///
592+
explicit OMPLinearClause(unsigned NumVars)
593+
: OMPVarListClause<OMPLinearClause>(OMPC_linear, SourceLocation(),
594+
SourceLocation(), SourceLocation(),
595+
NumVars),
596+
ColonLoc(SourceLocation()) {}
597+
598+
public:
599+
/// \brief Creates clause with a list of variables \a VL and a linear step
600+
/// \a Step.
601+
///
602+
/// \param C AST Context.
603+
/// \param StartLoc Starting location of the clause.
604+
/// \param LParenLoc Location of '('.
605+
/// \param ColonLoc Location of ':'.
606+
/// \param EndLoc Ending location of the clause.
607+
/// \param VL List of references to the variables.
608+
/// \param Step Linear step.
609+
static OMPLinearClause *Create(const ASTContext &C, SourceLocation StartLoc,
610+
SourceLocation LParenLoc,
611+
SourceLocation ColonLoc, SourceLocation EndLoc,
612+
ArrayRef<Expr *> VL, Expr *Step);
613+
614+
/// \brief Creates an empty clause with the place for \a NumVars variables.
615+
///
616+
/// \param C AST context.
617+
/// \param NumVars Number of variables.
618+
///
619+
static OMPLinearClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
620+
621+
/// \brief Sets the location of ':'.
622+
void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
623+
/// \brief Returns the location of '('.
624+
SourceLocation getColonLoc() const { return ColonLoc; }
625+
626+
/// \brief Returns linear step.
627+
Expr *getStep() { return *varlist_end(); }
628+
/// \brief Returns linear step.
629+
const Expr *getStep() const { return *varlist_end(); }
630+
631+
StmtRange children() {
632+
return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
633+
reinterpret_cast<Stmt **>(varlist_end() + 1));
634+
}
635+
636+
static bool classof(const OMPClause *T) {
637+
return T->getClauseKind() == OMPC_linear;
638+
}
639+
};
640+
556641
/// \brief This represents clause 'copyin' in the '#pragma omp ...' directives.
557642
///
558643
/// \code

clang/include/clang/AST/RecursiveASTVisitor.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2442,6 +2442,13 @@ bool RecursiveASTVisitor<Derived>::VisitOMPSharedClause(OMPSharedClause *C) {
24422442
return true;
24432443
}
24442444

2445+
template<typename Derived>
2446+
bool RecursiveASTVisitor<Derived>::VisitOMPLinearClause(OMPLinearClause *C) {
2447+
VisitOMPClauseList(C);
2448+
TraverseStmt(C->getStep());
2449+
return true;
2450+
}
2451+
24452452
template<typename Derived>
24462453
bool RecursiveASTVisitor<Derived>::VisitOMPCopyinClause(OMPCopyinClause *C) {
24472454
VisitOMPClauseList(C);

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,7 @@ def ASM : DiagGroup<"asm", [
671671

672672
// OpenMP warnings.
673673
def SourceUsesOpenMP : DiagGroup<"source-uses-openmp">;
674+
def OpenMPClauses : DiagGroup<"openmp-clauses">;
674675

675676
// Backend warnings.
676677
def BackendInlineAsm : DiagGroup<"inline-asm">;

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6928,6 +6928,16 @@ def err_omp_ambiguous_conversion : Error<
69286928
"enumeration type">;
69296929
def err_omp_required_access : Error<
69306930
"%0 variable must be %1">;
6931+
def err_omp_const_variable : Error<
6932+
"const-qualified variable cannot be %0">;
6933+
def err_omp_linear_incomplete_type : Error<
6934+
"a linear variable with incomplete type %0">;
6935+
def err_omp_linear_expected_int_or_ptr : Error<
6936+
"argument of a linear clause should be of integral or pointer "
6937+
"type, not %0">;
6938+
def warn_omp_linear_step_zero : Warning<
6939+
"zero linear step (%0 %select{|and other variables in clause }1should probably be const)">,
6940+
InGroup<OpenMPClauses>;
69316941
} // end of OpenMP category
69326942

69336943
let CategoryName = "Related Result Type Issue" in {

clang/include/clang/Basic/OpenMPKinds.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ OPENMP_CLAUSE(default, OMPDefaultClause)
4242
OPENMP_CLAUSE(private, OMPPrivateClause)
4343
OPENMP_CLAUSE(firstprivate, OMPFirstprivateClause)
4444
OPENMP_CLAUSE(shared, OMPSharedClause)
45+
OPENMP_CLAUSE(linear, OMPLinearClause)
4546
OPENMP_CLAUSE(copyin, OMPCopyinClause)
4647

4748
// Clauses allowed for OpenMP directive 'parallel'.
@@ -55,6 +56,7 @@ OPENMP_PARALLEL_CLAUSE(copyin)
5556

5657
// FIXME: more clauses allowed for directive 'omp simd'.
5758
OPENMP_SIMD_CLAUSE(private)
59+
OPENMP_SIMD_CLAUSE(linear)
5860
OPENMP_SIMD_CLAUSE(safelen)
5961

6062
// Static attributes for 'default' clause.

clang/include/clang/Sema/Sema.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7286,8 +7286,10 @@ class Sema {
72867286

72877287
OMPClause *ActOnOpenMPVarListClause(OpenMPClauseKind Kind,
72887288
ArrayRef<Expr *> Vars,
7289+
Expr *TailExpr,
72897290
SourceLocation StartLoc,
72907291
SourceLocation LParenLoc,
7292+
SourceLocation ColonLoc,
72917293
SourceLocation EndLoc);
72927294
/// \brief Called on well-formed 'private' clause.
72937295
OMPClause *ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList,
@@ -7304,6 +7306,13 @@ class Sema {
73047306
SourceLocation StartLoc,
73057307
SourceLocation LParenLoc,
73067308
SourceLocation EndLoc);
7309+
/// \brief Called on well-formed 'linear' clause.
7310+
OMPClause *ActOnOpenMPLinearClause(ArrayRef<Expr *> VarList,
7311+
Expr *Step,
7312+
SourceLocation StartLoc,
7313+
SourceLocation LParenLoc,
7314+
SourceLocation ColonLoc,
7315+
SourceLocation EndLoc);
73077316
/// \brief Called on well-formed 'copyin' clause.
73087317
OMPClause *ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList,
73097318
SourceLocation StartLoc,

clang/lib/AST/Stmt.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,6 +1192,30 @@ OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C,
11921192
return new (Mem) OMPSharedClause(N);
11931193
}
11941194

1195+
OMPLinearClause *OMPLinearClause::Create(const ASTContext &C,
1196+
SourceLocation StartLoc,
1197+
SourceLocation LParenLoc,
1198+
SourceLocation ColonLoc,
1199+
SourceLocation EndLoc,
1200+
ArrayRef<Expr *> VL, Expr *Step) {
1201+
void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPLinearClause),
1202+
llvm::alignOf<Expr *>()) +
1203+
sizeof(Expr *) * (VL.size() + 1));
1204+
OMPLinearClause *Clause = new (Mem)
1205+
OMPLinearClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size());
1206+
Clause->setVarRefs(VL);
1207+
Clause->setStep(Step);
1208+
return Clause;
1209+
}
1210+
1211+
OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C,
1212+
unsigned NumVars) {
1213+
void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPLinearClause),
1214+
llvm::alignOf<Expr *>()) +
1215+
sizeof(Expr *) * (NumVars + 1));
1216+
return new (Mem) OMPLinearClause(NumVars);
1217+
}
1218+
11951219
OMPCopyinClause *OMPCopyinClause::Create(const ASTContext &C,
11961220
SourceLocation StartLoc,
11971221
SourceLocation LParenLoc,

clang/lib/AST/StmtPrinter.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,18 @@ void OMPClausePrinter::VisitOMPSharedClause(OMPSharedClause *Node) {
664664
}
665665
}
666666

667+
void OMPClausePrinter::VisitOMPLinearClause(OMPLinearClause *Node) {
668+
if (!Node->varlist_empty()) {
669+
OS << "linear";
670+
VisitOMPClauseList(Node, '(');
671+
if (Node->getStep() != 0) {
672+
OS << ": ";
673+
Node->getStep()->printPretty(OS, 0, Policy, 0);
674+
}
675+
OS << ")";
676+
}
677+
}
678+
667679
void OMPClausePrinter::VisitOMPCopyinClause(OMPCopyinClause *Node) {
668680
if (!Node->varlist_empty()) {
669681
OS << "copyin";

clang/lib/AST/StmtProfile.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,10 @@ void OMPClauseProfiler::VisitOMPFirstprivateClause(
297297
void OMPClauseProfiler::VisitOMPSharedClause(const OMPSharedClause *C) {
298298
VisitOMPClauseList(C);
299299
}
300+
void OMPClauseProfiler::VisitOMPLinearClause(const OMPLinearClause *C) {
301+
VisitOMPClauseList(C);
302+
Profiler->VisitStmt(C->getStep());
303+
}
300304
void OMPClauseProfiler::VisitOMPCopyinClause(const OMPCopyinClause *C) {
301305
VisitOMPClauseList(C);
302306
}

0 commit comments

Comments
 (0)