diff options
author | Michael Wong <fraggamuffin@gmail.com> | 2015-08-07 16:16:36 +0000 |
---|---|---|
committer | Michael Wong <fraggamuffin@gmail.com> | 2015-08-07 16:16:36 +0000 |
commit | e710d5459ee7fc4ffac35e89651611b1498bb1d3 (patch) | |
tree | f588d60e0fc73c26fa8b9b65e74042d976236b45 /clang/lib | |
parent | 827a40b94420680063477bef5dadf9e69c2140b2 (diff) | |
download | bcm5719-llvm-e710d5459ee7fc4ffac35e89651611b1498bb1d3.tar.gz bcm5719-llvm-e710d5459ee7fc4ffac35e89651611b1498bb1d3.zip |
This patch commits OpenMP 4 target device clauses
This is committed on behalf of Kelvin Li
http://reviews.llvm.org/D11469?id=31227
llvm-svn: 244325
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/AST/StmtPrinter.cpp | 6 | ||||
-rw-r--r-- | clang/lib/AST/StmtProfile.cpp | 3 | ||||
-rw-r--r-- | clang/lib/Basic/OpenMPKinds.cpp | 2 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGStmtOpenMP.cpp | 1 | ||||
-rw-r--r-- | clang/lib/Parse/ParseOpenMP.cpp | 5 | ||||
-rw-r--r-- | clang/lib/Sema/SemaOpenMP.cpp | 32 | ||||
-rw-r--r-- | clang/lib/Sema/TreeTransform.h | 21 | ||||
-rw-r--r-- | clang/lib/Serialization/ASTReaderStmt.cpp | 8 | ||||
-rw-r--r-- | clang/lib/Serialization/ASTWriterStmt.cpp | 5 |
9 files changed, 82 insertions, 1 deletions
diff --git a/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp index 57187ca8620..64f90ba951d 100644 --- a/clang/lib/AST/StmtPrinter.cpp +++ b/clang/lib/AST/StmtPrinter.cpp @@ -688,6 +688,12 @@ void OMPClausePrinter::VisitOMPSeqCstClause(OMPSeqCstClause *) { OS << "seq_cst"; } +void OMPClausePrinter::VisitOMPDeviceClause(OMPDeviceClause *Node) { + OS << "device("; + Node->getDevice()->printPretty(OS, nullptr, Policy, 0); + OS << ")"; +} + template<typename T> void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) { for (typename T::varlist_iterator I = Node->varlist_begin(), diff --git a/clang/lib/AST/StmtProfile.cpp b/clang/lib/AST/StmtProfile.cpp index 091682ad7ff..fa1be8644b9 100644 --- a/clang/lib/AST/StmtProfile.cpp +++ b/clang/lib/AST/StmtProfile.cpp @@ -431,6 +431,9 @@ void OMPClauseProfiler::VisitOMPFlushClause(const OMPFlushClause *C) { void OMPClauseProfiler::VisitOMPDependClause(const OMPDependClause *C) { VisitOMPClauseList(C); } +void OMPClauseProfiler::VisitOMPDeviceClause(const OMPDeviceClause *C) { + Profiler->VisitStmt(C->getDevice()); +} } void diff --git a/clang/lib/Basic/OpenMPKinds.cpp b/clang/lib/Basic/OpenMPKinds.cpp index 7db0381665f..b431598191a 100644 --- a/clang/lib/Basic/OpenMPKinds.cpp +++ b/clang/lib/Basic/OpenMPKinds.cpp @@ -122,6 +122,7 @@ unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind Kind, case OMPC_update: case OMPC_capture: case OMPC_seq_cst: + case OMPC_device: break; } llvm_unreachable("Invalid OpenMP simple clause kind"); @@ -195,6 +196,7 @@ const char *clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind, case OMPC_update: case OMPC_capture: case OMPC_seq_cst: + case OMPC_device: break; } llvm_unreachable("Invalid OpenMP simple clause kind"); diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp index fa915755268..d69040d16b7 100644 --- a/clang/lib/CodeGen/CGStmtOpenMP.cpp +++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp @@ -2077,6 +2077,7 @@ static void EmitOMPAtomicExpr(CodeGenFunction &CGF, OpenMPClauseKind Kind, case OMPC_threadprivate: case OMPC_depend: case OMPC_mergeable: + case OMPC_device: llvm_unreachable("Clause is not allowed in 'omp atomic'."); } } diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp index 1266e447fca..fb348ef55d8 100644 --- a/clang/lib/Parse/ParseOpenMP.cpp +++ b/clang/lib/Parse/ParseOpenMP.cpp @@ -396,7 +396,7 @@ bool Parser::ParseOpenMPSimpleVarList(OpenMPDirectiveKind Kind, /// lastprivate-clause | reduction-clause | proc_bind-clause | /// schedule-clause | copyin-clause | copyprivate-clause | untied-clause | /// mergeable-clause | flush-clause | read-clause | write-clause | -/// update-clause | capture-clause | seq_cst-clause +/// update-clause | capture-clause | seq_cst-clause | device-clause /// OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind, OpenMPClauseKind CKind, bool FirstClause) { @@ -416,12 +416,15 @@ OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind, case OMPC_safelen: case OMPC_collapse: case OMPC_ordered: + case OMPC_device: // OpenMP [2.5, Restrictions] // At most one if clause can appear on the directive. // At most one num_threads clause can appear on the directive. // OpenMP [2.8.1, simd construct, Restrictions] // Only one safelen clause can appear on a simd directive. // Only one collapse clause can appear on a simd directive. + // OpenMP [2.9.1, target data construct, Restrictions] + // At most one device clause can appear on the directive. // OpenMP [2.11.1, task Construct, Restrictions] // At most one if clause can appear on the directive. // At most one final clause can appear on the directive. diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index 57ebb38a70c..03e7d237188 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -4511,6 +4511,9 @@ OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, case OMPC_ordered: Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Expr); break; + case OMPC_device: + Res = ActOnOpenMPDeviceClause(Expr, StartLoc, LParenLoc, EndLoc); + break; case OMPC_default: case OMPC_proc_bind: case OMPC_schedule: @@ -4774,6 +4777,7 @@ OMPClause *Sema::ActOnOpenMPSimpleClause( case OMPC_capture: case OMPC_seq_cst: case OMPC_depend: + case OMPC_device: case OMPC_unknown: llvm_unreachable("Clause is not allowed."); } @@ -4895,6 +4899,7 @@ OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause( case OMPC_capture: case OMPC_seq_cst: case OMPC_depend: + case OMPC_device: case OMPC_unknown: llvm_unreachable("Clause is not allowed."); } @@ -5018,6 +5023,7 @@ OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind, case OMPC_threadprivate: case OMPC_flush: case OMPC_depend: + case OMPC_device: case OMPC_unknown: llvm_unreachable("Clause is not allowed."); } @@ -5128,6 +5134,7 @@ OMPClause *Sema::ActOnOpenMPVarListClause( case OMPC_update: case OMPC_capture: case OMPC_seq_cst: + case OMPC_device: case OMPC_unknown: llvm_unreachable("Clause is not allowed."); } @@ -6722,3 +6729,28 @@ Sema::ActOnOpenMPDependClause(OpenMPDependClauseKind DepKind, return OMPDependClause::Create(Context, StartLoc, LParenLoc, EndLoc, DepKind, DepLoc, ColonLoc, Vars); } + +OMPClause *Sema::ActOnOpenMPDeviceClause(Expr *Device, SourceLocation StartLoc, + SourceLocation LParenLoc, + SourceLocation EndLoc) { + 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] + // The device expression must evaluate to a non-negative integer value. + llvm::APSInt Result; + if (Value.get()->isIntegerConstantExpr(Result, Context) && + 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); +} diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index 885dba778f1..6b19bd2ad76 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -1596,6 +1596,17 @@ public: StartLoc, LParenLoc, EndLoc); } + /// \brief Build a new OpenMP 'device' clause. + /// + /// By default, performs semantic analysis to build the new statement. + /// Subclasses may override this routine to provide different behavior. + OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc, + SourceLocation LParenLoc, + SourceLocation EndLoc) { + return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc, + EndLoc); + } + /// \brief Rebuild the operand to an Objective-C \@synchronized statement. /// /// By default, performs semantic analysis to build the new statement. @@ -7494,6 +7505,16 @@ TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) { C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); } +template <typename Derived> +OMPClause * +TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) { + ExprResult E = getDerived().TransformExpr(C->getDevice()); + if (E.isInvalid()) + return nullptr; + return getDerived().RebuildOMPDeviceClause( + E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); +} + //===----------------------------------------------------------------------===// // Expression transformation //===----------------------------------------------------------------------===// diff --git a/clang/lib/Serialization/ASTReaderStmt.cpp b/clang/lib/Serialization/ASTReaderStmt.cpp index f95e66fc071..1de92d3b752 100644 --- a/clang/lib/Serialization/ASTReaderStmt.cpp +++ b/clang/lib/Serialization/ASTReaderStmt.cpp @@ -1788,6 +1788,9 @@ OMPClause *OMPClauseReader::readClause() { case OMPC_depend: C = OMPDependClause::CreateEmpty(Context, Record[Idx++]); break; + case OMPC_device: + C = new (Context) OMPDeviceClause(); + break; } Visit(C); C->setLocStart(Reader->ReadSourceLocation(Record, Idx)); @@ -2068,6 +2071,11 @@ void OMPClauseReader::VisitOMPDependClause(OMPDependClause *C) { C->setVarRefs(Vars); } +void OMPClauseReader::VisitOMPDeviceClause(OMPDeviceClause *C) { + C->setDevice(Reader->Reader.ReadSubExpr()); + C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx)); +} + //===----------------------------------------------------------------------===// // OpenMP Directives. //===----------------------------------------------------------------------===// diff --git a/clang/lib/Serialization/ASTWriterStmt.cpp b/clang/lib/Serialization/ASTWriterStmt.cpp index b9c14e548c4..1284720a240 100644 --- a/clang/lib/Serialization/ASTWriterStmt.cpp +++ b/clang/lib/Serialization/ASTWriterStmt.cpp @@ -1919,6 +1919,11 @@ void OMPClauseWriter::VisitOMPDependClause(OMPDependClause *C) { Writer->Writer.AddStmt(VE); } +void OMPClauseWriter::VisitOMPDeviceClause(OMPDeviceClause *C) { + Writer->Writer.AddStmt(C->getDevice()); + Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record); +} + //===----------------------------------------------------------------------===// // OpenMP Directives. //===----------------------------------------------------------------------===// |