[OpenMP] Parsing and sema support for thread_limit clause.

http://reviews.llvm.org/D15029

llvm-svn: 254207
This commit is contained in:
Kelvin Li 2015-11-27 18:47:36 +00:00
parent d08cb6c528
commit a15fb1a110
16 changed files with 300 additions and 58 deletions

View File

@ -2783,6 +2783,61 @@ public:
child_range children() { return child_range(&NumTeams, &NumTeams + 1); } child_range children() { return child_range(&NumTeams, &NumTeams + 1); }
}; };
/// \brief This represents 'thread_limit' clause in the '#pragma omp ...'
/// directive.
///
/// \code
/// #pragma omp teams thread_limit(n)
/// \endcode
/// In this example directive '#pragma omp teams' has clause 'thread_limit'
/// with single expression 'n'.
///
class OMPThreadLimitClause : public OMPClause {
friend class OMPClauseReader;
/// \brief Location of '('.
SourceLocation LParenLoc;
/// \brief ThreadLimit number.
Stmt *ThreadLimit;
/// \brief Set the ThreadLimit number.
///
/// \param E ThreadLimit number.
///
void setThreadLimit(Expr *E) { ThreadLimit = E; }
public:
/// \brief Build 'thread_limit' clause.
///
/// \param E Expression associated with this clause.
/// \param StartLoc Starting location of the clause.
/// \param LParenLoc Location of '('.
/// \param EndLoc Ending location of the clause.
///
OMPThreadLimitClause(Expr *E, SourceLocation StartLoc,
SourceLocation LParenLoc, SourceLocation EndLoc)
: OMPClause(OMPC_thread_limit, StartLoc, EndLoc), LParenLoc(LParenLoc),
ThreadLimit(E) {}
/// \brief Build an empty clause.
///
OMPThreadLimitClause()
: OMPClause(OMPC_thread_limit, SourceLocation(), SourceLocation()),
LParenLoc(SourceLocation()), ThreadLimit(nullptr) {}
/// \brief Sets the location of '('.
void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
/// \brief Returns the location of '('.
SourceLocation getLParenLoc() const { return LParenLoc; }
/// \brief Return ThreadLimit number.
Expr *getThreadLimit() { return cast<Expr>(ThreadLimit); }
/// \brief Return ThreadLimit number.
Expr *getThreadLimit() const { return cast<Expr>(ThreadLimit); }
static bool classof(const OMPClause *T) {
return T->getClauseKind() == OMPC_thread_limit;
}
child_range children() { return child_range(&ThreadLimit, &ThreadLimit + 1); }
};
} // end namespace clang } // end namespace clang
#endif // LLVM_CLANG_AST_OPENMPCLAUSE_H #endif // LLVM_CLANG_AST_OPENMPCLAUSE_H

View File

@ -2728,6 +2728,13 @@ bool RecursiveASTVisitor<Derived>::VisitOMPNumTeamsClause(
return true; return true;
} }
template <typename Derived>
bool RecursiveASTVisitor<Derived>::VisitOMPThreadLimitClause(
OMPThreadLimitClause *C) {
TRY_TO(TraverseStmt(C->getThreadLimit()));
return true;
}
// FIXME: look at the following tricky-seeming exprs to see if we // FIXME: look at the following tricky-seeming exprs to see if we
// need to recurse on anything. These are ones that have methods // need to recurse on anything. These are ones that have methods
// returning decls or qualtypes or nestednamespecifier -- though I'm // returning decls or qualtypes or nestednamespecifier -- though I'm

View File

@ -151,6 +151,7 @@ OPENMP_CLAUSE(threads, OMPThreadsClause)
OPENMP_CLAUSE(simd, OMPSIMDClause) OPENMP_CLAUSE(simd, OMPSIMDClause)
OPENMP_CLAUSE(map, OMPMapClause) OPENMP_CLAUSE(map, OMPMapClause)
OPENMP_CLAUSE(num_teams, OMPNumTeamsClause) OPENMP_CLAUSE(num_teams, OMPNumTeamsClause)
OPENMP_CLAUSE(thread_limit, OMPThreadLimitClause)
// Clauses allowed for OpenMP directive 'parallel'. // Clauses allowed for OpenMP directive 'parallel'.
OPENMP_PARALLEL_CLAUSE(if) OPENMP_PARALLEL_CLAUSE(if)
@ -323,6 +324,7 @@ OPENMP_TEAMS_CLAUSE(firstprivate)
OPENMP_TEAMS_CLAUSE(shared) OPENMP_TEAMS_CLAUSE(shared)
OPENMP_TEAMS_CLAUSE(reduction) OPENMP_TEAMS_CLAUSE(reduction)
OPENMP_TEAMS_CLAUSE(num_teams) OPENMP_TEAMS_CLAUSE(num_teams)
OPENMP_TEAMS_CLAUSE(thread_limit)
// Clauses allowed for OpenMP directive 'ordered'. // Clauses allowed for OpenMP directive 'ordered'.
// TODO More clauses for 'ordered' directive. // TODO More clauses for 'ordered' directive.

View File

@ -8125,6 +8125,11 @@ public:
OMPClause *ActOnOpenMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc, OMPClause *ActOnOpenMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc,
SourceLocation LParenLoc, SourceLocation LParenLoc,
SourceLocation EndLoc); SourceLocation EndLoc);
/// \brief Called on well-formed 'thread_limit' clause.
OMPClause *ActOnOpenMPThreadLimitClause(Expr *ThreadLimit,
SourceLocation StartLoc,
SourceLocation LParenLoc,
SourceLocation EndLoc);
/// \brief The kind of conversion being performed. /// \brief The kind of conversion being performed.
enum CheckedConversionKind { enum CheckedConversionKind {

View File

@ -715,6 +715,12 @@ void OMPClausePrinter::VisitOMPNumTeamsClause(OMPNumTeamsClause *Node) {
OS << ")"; OS << ")";
} }
void OMPClausePrinter::VisitOMPThreadLimitClause(OMPThreadLimitClause *Node) {
OS << "thread_limit(";
Node->getThreadLimit()->printPretty(OS, nullptr, Policy, 0);
OS << ")";
}
template<typename T> template<typename T>
void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) { void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
for (typename T::varlist_iterator I = Node->varlist_begin(), for (typename T::varlist_iterator I = Node->varlist_begin(),

View File

@ -456,6 +456,10 @@ void OMPClauseProfiler::VisitOMPMapClause(const OMPMapClause *C) {
void OMPClauseProfiler::VisitOMPNumTeamsClause(const OMPNumTeamsClause *C) { void OMPClauseProfiler::VisitOMPNumTeamsClause(const OMPNumTeamsClause *C) {
Profiler->VisitStmt(C->getNumTeams()); Profiler->VisitStmt(C->getNumTeams());
} }
void OMPClauseProfiler::VisitOMPThreadLimitClause(
const OMPThreadLimitClause *C) {
Profiler->VisitStmt(C->getThreadLimit());
}
} }
void void

View File

@ -136,6 +136,7 @@ unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind Kind,
case OMPC_threads: case OMPC_threads:
case OMPC_simd: case OMPC_simd:
case OMPC_num_teams: case OMPC_num_teams:
case OMPC_thread_limit:
break; break;
} }
llvm_unreachable("Invalid OpenMP simple clause kind"); llvm_unreachable("Invalid OpenMP simple clause kind");
@ -235,6 +236,7 @@ const char *clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
case OMPC_threads: case OMPC_threads:
case OMPC_simd: case OMPC_simd:
case OMPC_num_teams: case OMPC_num_teams:
case OMPC_thread_limit:
break; break;
} }
llvm_unreachable("Invalid OpenMP simple clause kind"); llvm_unreachable("Invalid OpenMP simple clause kind");

View File

@ -2435,6 +2435,7 @@ static void EmitOMPAtomicExpr(CodeGenFunction &CGF, OpenMPClauseKind Kind,
case OMPC_simd: case OMPC_simd:
case OMPC_map: case OMPC_map:
case OMPC_num_teams: case OMPC_num_teams:
case OMPC_thread_limit:
llvm_unreachable("Clause is not allowed in 'omp atomic'."); llvm_unreachable("Clause is not allowed in 'omp atomic'.");
} }
} }

View File

@ -394,7 +394,8 @@ bool Parser::ParseOpenMPSimpleVarList(OpenMPDirectiveKind Kind,
/// schedule-clause | copyin-clause | copyprivate-clause | untied-clause | /// schedule-clause | copyin-clause | copyprivate-clause | untied-clause |
/// mergeable-clause | flush-clause | read-clause | write-clause | /// mergeable-clause | flush-clause | read-clause | write-clause |
/// update-clause | capture-clause | seq_cst-clause | device-clause | /// update-clause | capture-clause | seq_cst-clause | device-clause |
/// simdlen-clause | threads-clause | simd-clause | num_teams-clause /// simdlen-clause | threads-clause | simd-clause | num_teams-clause |
/// thread_limit-clause
/// ///
OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind, OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
OpenMPClauseKind CKind, bool FirstClause) { OpenMPClauseKind CKind, bool FirstClause) {
@ -416,6 +417,7 @@ OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
case OMPC_ordered: case OMPC_ordered:
case OMPC_device: case OMPC_device:
case OMPC_num_teams: case OMPC_num_teams:
case OMPC_thread_limit:
// OpenMP [2.5, Restrictions] // OpenMP [2.5, Restrictions]
// At most one num_threads clause can appear on the directive. // At most one num_threads clause can appear on the directive.
// OpenMP [2.8.1, simd construct, Restrictions] // OpenMP [2.8.1, simd construct, Restrictions]
@ -429,6 +431,7 @@ OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
// At most one final clause can appear on the directive. // At most one final clause can appear on the directive.
// OpenMP [teams Construct, Restrictions] // OpenMP [teams Construct, Restrictions]
// At most one num_teams clause can appear on the directive. // At most one num_teams clause can appear on the directive.
// At most one thread_limit clause can appear on the directive.
if (!FirstClause) { if (!FirstClause) {
Diag(Tok, diag::err_omp_more_one_clause) Diag(Tok, diag::err_omp_more_one_clause)
<< getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0; << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0;

View File

@ -5097,6 +5097,9 @@ OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr,
case OMPC_num_teams: case OMPC_num_teams:
Res = ActOnOpenMPNumTeamsClause(Expr, StartLoc, LParenLoc, EndLoc); Res = ActOnOpenMPNumTeamsClause(Expr, StartLoc, LParenLoc, EndLoc);
break; break;
case OMPC_thread_limit:
Res = ActOnOpenMPThreadLimitClause(Expr, StartLoc, LParenLoc, EndLoc);
break;
case OMPC_if: case OMPC_if:
case OMPC_default: case OMPC_default:
case OMPC_proc_bind: case OMPC_proc_bind:
@ -5214,31 +5217,39 @@ ExprResult Sema::PerformOpenMPImplicitIntegerConversion(SourceLocation Loc,
return PerformContextualImplicitConversion(Loc, Op, ConvertDiagnoser); return PerformContextualImplicitConversion(Loc, Op, ConvertDiagnoser);
} }
static bool IsNonNegativeIntegerValue(Expr *&ValExpr, Sema &SemaRef,
OpenMPClauseKind CKind) {
if (!ValExpr->isTypeDependent() && !ValExpr->isValueDependent() &&
!ValExpr->isInstantiationDependent()) {
SourceLocation Loc = ValExpr->getExprLoc();
ExprResult Value =
SemaRef.PerformOpenMPImplicitIntegerConversion(Loc, ValExpr);
if (Value.isInvalid())
return false;
ValExpr = Value.get();
// The expression must evaluate to a non-negative integer value.
llvm::APSInt Result;
if (ValExpr->isIntegerConstantExpr(Result, SemaRef.Context) &&
Result.isSigned() && !Result.isStrictlyPositive()) {
SemaRef.Diag(Loc, diag::err_omp_negative_expression_in_clause)
<< getOpenMPClauseName(CKind) << ValExpr->getSourceRange();
return false;
}
}
return true;
}
OMPClause *Sema::ActOnOpenMPNumThreadsClause(Expr *NumThreads, OMPClause *Sema::ActOnOpenMPNumThreadsClause(Expr *NumThreads,
SourceLocation StartLoc, SourceLocation StartLoc,
SourceLocation LParenLoc, SourceLocation LParenLoc,
SourceLocation EndLoc) { SourceLocation EndLoc) {
Expr *ValExpr = NumThreads; Expr *ValExpr = NumThreads;
if (!NumThreads->isValueDependent() && !NumThreads->isTypeDependent() &&
!NumThreads->containsUnexpandedParameterPack()) {
SourceLocation NumThreadsLoc = NumThreads->getLocStart();
ExprResult Val =
PerformOpenMPImplicitIntegerConversion(NumThreadsLoc, NumThreads);
if (Val.isInvalid())
return nullptr;
ValExpr = Val.get(); // OpenMP [2.5, Restrictions]
// The num_threads expression must evaluate to a positive integer value.
// OpenMP [2.5, Restrictions] if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_threads))
// The num_threads expression must evaluate to a positive integer value. return nullptr;
llvm::APSInt Result;
if (ValExpr->isIntegerConstantExpr(Result, Context) && Result.isSigned() &&
!Result.isStrictlyPositive()) {
Diag(NumThreadsLoc, diag::err_omp_negative_expression_in_clause)
<< "num_threads" << NumThreads->getSourceRange();
return nullptr;
}
}
return new (Context) return new (Context)
OMPNumThreadsClause(ValExpr, StartLoc, LParenLoc, EndLoc); OMPNumThreadsClause(ValExpr, StartLoc, LParenLoc, EndLoc);
@ -5385,6 +5396,7 @@ OMPClause *Sema::ActOnOpenMPSimpleClause(
case OMPC_simd: case OMPC_simd:
case OMPC_map: case OMPC_map:
case OMPC_num_teams: case OMPC_num_teams:
case OMPC_thread_limit:
case OMPC_unknown: case OMPC_unknown:
llvm_unreachable("Clause is not allowed."); llvm_unreachable("Clause is not allowed.");
} }
@ -5516,6 +5528,7 @@ OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause(
case OMPC_simd: case OMPC_simd:
case OMPC_map: case OMPC_map:
case OMPC_num_teams: case OMPC_num_teams:
case OMPC_thread_limit:
case OMPC_unknown: case OMPC_unknown:
llvm_unreachable("Clause is not allowed."); llvm_unreachable("Clause is not allowed.");
} }
@ -5649,6 +5662,7 @@ OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind,
case OMPC_device: case OMPC_device:
case OMPC_map: case OMPC_map:
case OMPC_num_teams: case OMPC_num_teams:
case OMPC_thread_limit:
case OMPC_unknown: case OMPC_unknown:
llvm_unreachable("Clause is not allowed."); llvm_unreachable("Clause is not allowed.");
} }
@ -5779,6 +5793,7 @@ OMPClause *Sema::ActOnOpenMPVarListClause(
case OMPC_threads: case OMPC_threads:
case OMPC_simd: case OMPC_simd:
case OMPC_num_teams: case OMPC_num_teams:
case OMPC_thread_limit:
case OMPC_unknown: case OMPC_unknown:
llvm_unreachable("Clause is not allowed."); llvm_unreachable("Clause is not allowed.");
} }
@ -7458,23 +7473,12 @@ OMPClause *Sema::ActOnOpenMPDeviceClause(Expr *Device, SourceLocation StartLoc,
SourceLocation LParenLoc, SourceLocation LParenLoc,
SourceLocation EndLoc) { SourceLocation EndLoc) {
Expr *ValExpr = Device; Expr *ValExpr = Device;
if (!ValExpr->isTypeDependent() && !ValExpr->isValueDependent() &&
!ValExpr->isInstantiationDependent()) {
SourceLocation Loc = ValExpr->getExprLoc();
ExprResult Value = PerformOpenMPImplicitIntegerConversion(Loc, ValExpr);
if (Value.isInvalid())
return nullptr;
// OpenMP [2.9.1, Restrictions] // OpenMP [2.9.1, Restrictions]
// The device expression must evaluate to a non-negative integer value. // The device expression must evaluate to a non-negative integer value.
llvm::APSInt Result; if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_device))
if (Value.get()->isIntegerConstantExpr(Result, Context) && return nullptr;
Result.isSigned() && !Result.isStrictlyPositive()) {
Diag(Loc, diag::err_omp_negative_expression_in_clause)
<< "device" << ValExpr->getSourceRange();
return nullptr;
}
}
return new (Context) OMPDeviceClause(ValExpr, StartLoc, LParenLoc, EndLoc); return new (Context) OMPDeviceClause(ValExpr, StartLoc, LParenLoc, EndLoc);
} }
@ -7659,23 +7663,26 @@ OMPClause *Sema::ActOnOpenMPNumTeamsClause(Expr *NumTeams,
SourceLocation LParenLoc, SourceLocation LParenLoc,
SourceLocation EndLoc) { SourceLocation EndLoc) {
Expr *ValExpr = NumTeams; Expr *ValExpr = NumTeams;
if (!ValExpr->isTypeDependent() && !ValExpr->isValueDependent() &&
!ValExpr->isInstantiationDependent()) {
SourceLocation Loc = ValExpr->getExprLoc();
ExprResult Value = PerformOpenMPImplicitIntegerConversion(Loc, ValExpr);
if (Value.isInvalid())
return nullptr;
// OpenMP [teams Constrcut, Restrictions] // OpenMP [teams Constrcut, Restrictions]
// The num_teams expression must evaluate to a positive integer value. // The num_teams expression must evaluate to a positive integer value.
llvm::APSInt Result; if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_teams))
if (Value.get()->isIntegerConstantExpr(Result, Context) && return nullptr;
Result.isSigned() && !Result.isStrictlyPositive()) {
Diag(Loc, diag::err_omp_negative_expression_in_clause)
<< "num_teams" << ValExpr->getSourceRange();
return nullptr;
}
}
return new (Context) OMPNumTeamsClause(ValExpr, StartLoc, LParenLoc, EndLoc); return new (Context) OMPNumTeamsClause(ValExpr, StartLoc, LParenLoc, EndLoc);
} }
OMPClause *Sema::ActOnOpenMPThreadLimitClause(Expr *ThreadLimit,
SourceLocation StartLoc,
SourceLocation LParenLoc,
SourceLocation EndLoc) {
Expr *ValExpr = ThreadLimit;
// OpenMP [teams Constrcut, Restrictions]
// The thread_limit expression must evaluate to a positive integer value.
if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_thread_limit))
return nullptr;
return new (Context) OMPThreadLimitClause(ValExpr, StartLoc, LParenLoc,
EndLoc);
}

View File

@ -1677,6 +1677,18 @@ public:
EndLoc); EndLoc);
} }
/// \brief Build a new OpenMP 'thread_limit' clause.
///
/// By default, performs semantic analysis to build the new statement.
/// Subclasses may override this routine to provide different behavior.
OMPClause *RebuildOMPThreadLimitClause(Expr *ThreadLimit,
SourceLocation StartLoc,
SourceLocation LParenLoc,
SourceLocation EndLoc) {
return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc,
LParenLoc, EndLoc);
}
/// \brief Rebuild the operand to an Objective-C \@synchronized statement. /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
/// ///
/// By default, performs semantic analysis to build the new statement. /// By default, performs semantic analysis to build the new statement.
@ -7718,6 +7730,16 @@ TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
} }
template <typename Derived>
OMPClause *
TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
if (E.isInvalid())
return nullptr;
return getDerived().RebuildOMPThreadLimitClause(
E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
}
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// Expression transformation // Expression transformation
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//

View File

@ -1853,6 +1853,9 @@ OMPClause *OMPClauseReader::readClause() {
case OMPC_num_teams: case OMPC_num_teams:
C = new (Context) OMPNumTeamsClause(); C = new (Context) OMPNumTeamsClause();
break; break;
case OMPC_thread_limit:
C = new (Context) OMPThreadLimitClause();
break;
} }
Visit(C); Visit(C);
C->setLocStart(Reader->ReadSourceLocation(Record, Idx)); C->setLocStart(Reader->ReadSourceLocation(Record, Idx));
@ -2182,6 +2185,11 @@ void OMPClauseReader::VisitOMPNumTeamsClause(OMPNumTeamsClause *C) {
C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx)); C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
} }
void OMPClauseReader::VisitOMPThreadLimitClause(OMPThreadLimitClause *C) {
C->setThreadLimit(Reader->Reader.ReadSubExpr());
C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
}
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// OpenMP Directives. // OpenMP Directives.
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//

View File

@ -2006,6 +2006,11 @@ void OMPClauseWriter::VisitOMPNumTeamsClause(OMPNumTeamsClause *C) {
Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record); Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record);
} }
void OMPClauseWriter::VisitOMPThreadLimitClause(OMPThreadLimitClause *C) {
Writer->Writer.AddStmt(C->getThreadLimit());
Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record);
}
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// OpenMP Directives. // OpenMP Directives.
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//

View File

@ -37,7 +37,7 @@ T tmain(T argc, T *argv) {
#pragma omp teams #pragma omp teams
a=2; a=2;
#pragma omp target #pragma omp target
#pragma omp teams default(none), private(argc,b) firstprivate(argv) shared (d) reduction(+:c) reduction(max:e) num_teams(C) #pragma omp teams default(none), private(argc,b) firstprivate(argv) shared (d) reduction(+:c) reduction(max:e) num_teams(C) thread_limit(d*C)
foo(); foo();
#pragma omp target #pragma omp target
#pragma omp teams reduction(^:e, f) reduction(&& : g) #pragma omp teams reduction(^:e, f) reduction(&& : g)
@ -53,7 +53,7 @@ T tmain(T argc, T *argv) {
// CHECK-NEXT: #pragma omp teams // CHECK-NEXT: #pragma omp teams
// CHECK-NEXT: a = 2; // CHECK-NEXT: a = 2;
// CHECK-NEXT: #pragma omp target // CHECK-NEXT: #pragma omp target
// CHECK-NEXT: #pragma omp teams default(none) private(argc,b) firstprivate(argv) shared(d) reduction(+: c) reduction(max: e) num_teams(5) // CHECK-NEXT: #pragma omp teams default(none) private(argc,b) firstprivate(argv) shared(d) reduction(+: c) reduction(max: e) num_teams(5) thread_limit(d * 5)
// CHECK-NEXT: foo() // CHECK-NEXT: foo()
// CHECK-NEXT: #pragma omp target // CHECK-NEXT: #pragma omp target
// CHECK-NEXT: #pragma omp teams reduction(^: e,f) reduction(&&: g) // CHECK-NEXT: #pragma omp teams reduction(^: e,f) reduction(&&: g)
@ -66,7 +66,7 @@ T tmain(T argc, T *argv) {
// CHECK-NEXT: #pragma omp teams // CHECK-NEXT: #pragma omp teams
// CHECK-NEXT: a = 2; // CHECK-NEXT: a = 2;
// CHECK-NEXT: #pragma omp target // CHECK-NEXT: #pragma omp target
// CHECK-NEXT: #pragma omp teams default(none) private(argc,b) firstprivate(argv) shared(d) reduction(+: c) reduction(max: e) num_teams(1) // CHECK-NEXT: #pragma omp teams default(none) private(argc,b) firstprivate(argv) shared(d) reduction(+: c) reduction(max: e) num_teams(1) thread_limit(d * 1)
// CHECK-NEXT: foo() // CHECK-NEXT: foo()
// CHECK-NEXT: #pragma omp target // CHECK-NEXT: #pragma omp target
// CHECK-NEXT: #pragma omp teams reduction(^: e,f) reduction(&&: g) // CHECK-NEXT: #pragma omp teams reduction(^: e,f) reduction(&&: g)
@ -79,7 +79,7 @@ T tmain(T argc, T *argv) {
// CHECK-NEXT: #pragma omp teams // CHECK-NEXT: #pragma omp teams
// CHECK-NEXT: a = 2; // CHECK-NEXT: a = 2;
// CHECK-NEXT: #pragma omp target // CHECK-NEXT: #pragma omp target
// CHECK-NEXT: #pragma omp teams default(none) private(argc,b) firstprivate(argv) shared(d) reduction(+: c) reduction(max: e) num_teams(C) // CHECK-NEXT: #pragma omp teams default(none) private(argc,b) firstprivate(argv) shared(d) reduction(+: c) reduction(max: e) num_teams(C) thread_limit(d * C)
// CHECK-NEXT: foo() // CHECK-NEXT: foo()
// CHECK-NEXT: #pragma omp target // CHECK-NEXT: #pragma omp target
// CHECK-NEXT: #pragma omp teams reduction(^: e,f) reduction(&&: g) // CHECK-NEXT: #pragma omp teams reduction(^: e,f) reduction(&&: g)
@ -101,9 +101,9 @@ int main (int argc, char **argv) {
a=2; a=2;
// CHECK-NEXT: a = 2; // CHECK-NEXT: a = 2;
#pragma omp target #pragma omp target
#pragma omp teams default(none), private(argc,b) num_teams(f) firstprivate(argv) reduction(| : c, d) reduction(* : e) #pragma omp teams default(none), private(argc,b) num_teams(f) firstprivate(argv) reduction(| : c, d) reduction(* : e) thread_limit(f+g)
// CHECK-NEXT: #pragma omp target // CHECK-NEXT: #pragma omp target
// CHECK-NEXT: #pragma omp teams default(none) private(argc,b) num_teams(f) firstprivate(argv) reduction(|: c,d) reduction(*: e) // CHECK-NEXT: #pragma omp teams default(none) private(argc,b) num_teams(f) firstprivate(argv) reduction(|: c,d) reduction(*: e) thread_limit(f + g)
foo(); foo();
// CHECK-NEXT: foo(); // CHECK-NEXT: foo();
return tmain<int, 5>(b, &b) + tmain<long, 1>(x, &x); return tmain<int, 5>(b, &b) + tmain<long, 1>(x, &x);

View File

@ -0,0 +1,111 @@
// RUN: %clang_cc1 -verify -fopenmp -std=c++11 -ferror-limit 100 -o - %s
void foo() {
}
bool foobool(int argc) {
return argc;
}
struct S1; // expected-note 2 {{declared here}}
template <typename T, int C> // expected-note {{declared here}}
T tmain(T argc) {
char **a;
#pragma omp target
#pragma omp teams thread_limit(C)
foo();
#pragma omp target
#pragma omp teams thread_limit(T) // expected-error {{'T' does not refer to a value}}
foo();
#pragma omp target
#pragma omp teams thread_limit // expected-error {{expected '(' after 'thread_limit'}}
foo();
#pragma omp target
#pragma omp teams thread_limit( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
foo();
#pragma omp target
#pragma omp teams thread_limit() // expected-error {{expected expression}}
foo();
#pragma omp target
#pragma omp teams thread_limit(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
foo();
#pragma omp target
#pragma omp teams thread_limit(argc)) // expected-warning {{extra tokens at the end of '#pragma omp teams' are ignored}}
foo();
#pragma omp target
#pragma omp teams thread_limit(argc > 0 ? a[1] : a[2]) // expected-error {{expression must have integral or unscoped enumeration type, not 'char *'}}
foo();
#pragma omp target
#pragma omp teams thread_limit(argc + argc)
foo();
#pragma omp target
#pragma omp teams thread_limit(argc), thread_limit (argc+1) // expected-error {{directive '#pragma omp teams' cannot contain more than one 'thread_limit' clause}}
foo();
#pragma omp target
#pragma omp teams thread_limit(S1) // expected-error {{'S1' does not refer to a value}}
foo();
#pragma omp target
#pragma omp teams thread_limit(-2) // expected-error {{argument to 'thread_limit' clause must be a positive integer value}}
foo();
#pragma omp target
#pragma omp teams thread_limit(-10u)
foo();
#pragma omp target
#pragma omp teams thread_limit(3.14) // expected-error 2 {{expression must have integral or unscoped enumeration type, not 'double'}}
foo();
return 0;
}
int main(int argc, char **argv) {
#pragma omp target
#pragma omp teams thread_limit // expected-error {{expected '(' after 'thread_limit'}}
foo();
#pragma omp target
#pragma omp teams thread_limit ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
foo();
#pragma omp target
#pragma omp teams thread_limit () // expected-error {{expected expression}}
foo();
#pragma omp target
#pragma omp teams thread_limit (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
foo();
#pragma omp target
#pragma omp teams thread_limit (argc)) // expected-warning {{extra tokens at the end of '#pragma omp teams' are ignored}}
foo();
#pragma omp target
#pragma omp teams thread_limit (argc > 0 ? argv[1] : argv[2]) // expected-error {{expression must have integral or unscoped enumeration type, not 'char *'}}
foo();
#pragma omp target
#pragma omp teams thread_limit (argc + argc)
foo();
#pragma omp target
#pragma omp teams thread_limit (argc), thread_limit (argc+1) // expected-error {{directive '#pragma omp teams' cannot contain more than one 'thread_limit' clause}}
foo();
#pragma omp target
#pragma omp teams thread_limit (S1) // expected-error {{'S1' does not refer to a value}}
foo();
#pragma omp target
#pragma omp teams thread_limit (-2) // expected-error {{argument to 'thread_limit' clause must be a positive integer value}}
foo();
#pragma omp target
#pragma omp teams thread_limit (-10u)
foo();
#pragma omp target
#pragma omp teams thread_limit (3.14) // expected-error {{expression must have integral or unscoped enumeration type, not 'double'}}
foo();
return tmain<int, 10>(argc); // expected-note {{in instantiation of function template specialization 'tmain<int, 10>' requested here}}
}

View File

@ -2079,6 +2079,10 @@ void OMPClauseEnqueue::VisitOMPNumTeamsClause(const OMPNumTeamsClause *C) {
Visitor->AddStmt(C->getNumTeams()); Visitor->AddStmt(C->getNumTeams());
} }
void OMPClauseEnqueue::VisitOMPThreadLimitClause(const OMPThreadLimitClause *C) {
Visitor->AddStmt(C->getThreadLimit());
}
template<typename T> template<typename T>
void OMPClauseEnqueue::VisitOMPClauseList(T *Node) { void OMPClauseEnqueue::VisitOMPClauseList(T *Node) {
for (const auto *I : Node->varlists()) { for (const auto *I : Node->varlists()) {