[clang] edd675a - [OpenMP] atomic compare fail : Parser & AST support
Author: Sunil Kuravinakop Date: 2023-11-20T03:05:31-06:00 New Revision: edd675ac283909397880f85ba68d0d5f99dc1be2 URL: https://github.com/llvm/llvm-project/commit/edd675ac283909397880f85ba68d0d5f99dc1be2 DIFF: https://github.com/llvm/llvm-project/commit/edd675ac283909397880f85ba68d0d5f99dc1be2.diff LOG: [OpenMP] atomic compare fail : Parser & AST support Diff Revision: https://reviews.llvm.org/D123235 Added: Modified: clang/include/clang/AST/OpenMPClause.h clang/include/clang/AST/RecursiveASTVisitor.h clang/include/clang/Basic/DiagnosticSemaKinds.td clang/include/clang/Basic/OpenMPKinds.def clang/include/clang/Basic/OpenMPKinds.h clang/include/clang/Sema/Sema.h clang/lib/AST/OpenMPClause.cpp clang/lib/AST/StmtProfile.cpp clang/lib/Basic/OpenMPKinds.cpp clang/lib/CodeGen/CGStmtOpenMP.cpp clang/lib/Parse/ParseOpenMP.cpp clang/lib/Sema/SemaOpenMP.cpp clang/lib/Sema/TreeTransform.h clang/lib/Serialization/ASTReader.cpp clang/lib/Serialization/ASTWriter.cpp clang/test/OpenMP/atomic_ast_print.cpp clang/test/OpenMP/atomic_messages.cpp clang/tools/libclang/CIndex.cpp flang/lib/Semantics/check-omp-structure.cpp llvm/include/llvm/Frontend/OpenMP/OMP.td Removed: diff --git a/clang/include/clang/AST/OpenMPClause.h b/clang/include/clang/AST/OpenMPClause.h index 549f12e87df597a..ccceadeabedc7ff 100644 --- a/clang/include/clang/AST/OpenMPClause.h +++ b/clang/include/clang/AST/OpenMPClause.h @@ -2513,6 +2513,89 @@ class OMPRelaxedClause final : public OMPClause { } }; +/// This represents 'fail' clause in the '#pragma omp atomic' +/// directive. +/// +/// \code +/// #pragma omp atomic compare fail +/// \endcode +/// In this example directive '#pragma omp atomic compare' has 'fail' clause. +class OMPFailClause final : public OMPClause { + + // FailParameter is a memory-order-clause. Storing the ClauseKind is + // sufficient for our purpose. + OpenMPClauseKind FailParameter = llvm::omp::Clause::OMPC_unknown; + SourceLocation FailParameterLoc; + SourceLocation LParenLoc; + + friend class OMPClauseReader; + + /// Sets the location of '(' in fail clause. + void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } + + /// Sets the location of memoryOrder clause argument in fail clause. + void setFailParameterLoc(SourceLocation Loc) { FailParameterLoc = Loc; } + + /// Sets the mem_order clause for 'atomic compare fail' directive. + void setFailParameter(OpenMPClauseKind FailParameter) { +this->FailParameter = FailParameter; +assert(checkFailClauseParameter(FailParameter) && + "Invalid fail clause parameter"); + } + +public: + /// Build 'fail' clause. + /// + /// \param StartLoc Starting location of the clause. + /// \param EndLoc Ending location of the clause. + OMPFailClause(SourceLocation StartLoc, SourceLocation EndLoc) + : OMPClause(llvm::omp::OMPC_fail, StartLoc, EndLoc) {} + + OMPFailClause(OpenMPClauseKind FailParameter, SourceLocation FailParameterLoc, +SourceLocation StartLoc, SourceLocation LParenLoc, +SourceLocation EndLoc) + : OMPClause(llvm::omp::OMPC_fail, StartLoc, EndLoc), +FailParameterLoc(FailParameterLoc), LParenLoc(LParenLoc) { + +setFailParameter(FailParameter); + } + + /// Build an empty clause. + OMPFailClause() + : OMPClause(llvm::omp::OMPC_fail, SourceLocation(), SourceLocation()) {} + + child_range children() { +return child_range(child_iterator(), child_iterator()); + } + + const_child_range children() const { +return const_child_range(const_child_iterator(), const_child_iterator()); + } + + child_range used_children() { +return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { +return const_child_range(const_child_iterator(), const_child_iterator()); + } + + static bool classof(const OMPClause *T) { +return T->getClauseKind() == llvm::omp::OMPC_fail; + } + + /// Gets the location of '(' (for the parameter) in fail clause. + SourceLocation getLParenLoc() const { +return LParenLoc; + } + + /// Gets the location of Fail Parameter (type memory-order-clause) in + /// fail clause. + SourceLocation getFailParameterLoc() const { return FailParameterLoc; } + + /// Gets the parameter (type memory-order-clause) in Fail clause. + OpenMPClauseKind getFailParameter() const { return FailParameter; } +}; + /// This represents clause 'private' in the '#pragma omp ...' directives. /// /// \code diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h b/clang/include/clang/AST/RecursiveASTVisitor.h index 53bc15e1b19f668..c501801b95bd955 100644 --- a/clang/include/clang/AST/RecursiveASTVisitor.h +++ b/clang/include/clang/AST/RecursiveASTVisitor.h @@ -3398,6 +3398,11 @@ bool RecursiveASTVisitor::VisitOMPCompareClause(OMPCompareClause *) {
[clang] d033f51 - [OpenMP] atomic compare fail : Parser & AST support
Author: Sunil Kuravinakop Date: 2023-11-26T13:34:34-06:00 New Revision: d033f51a0aafd8149f5059bc0f89ffd300093356 URL: https://github.com/llvm/llvm-project/commit/d033f51a0aafd8149f5059bc0f89ffd300093356 DIFF: https://github.com/llvm/llvm-project/commit/d033f51a0aafd8149f5059bc0f89ffd300093356.diff LOG: [OpenMP] atomic compare fail : Parser & AST support Diff Revision: https://reviews.llvm.org/D123235 Added: Modified: clang/include/clang/AST/OpenMPClause.h clang/include/clang/AST/RecursiveASTVisitor.h clang/include/clang/Basic/DiagnosticSemaKinds.td clang/include/clang/Basic/OpenMPKinds.def clang/include/clang/Basic/OpenMPKinds.h clang/include/clang/Sema/Sema.h clang/lib/AST/OpenMPClause.cpp clang/lib/AST/StmtProfile.cpp clang/lib/Basic/CMakeLists.txt clang/lib/Basic/OpenMPKinds.cpp clang/lib/CodeGen/CGStmtOpenMP.cpp clang/lib/Parse/ParseOpenMP.cpp clang/lib/Sema/SemaOpenMP.cpp clang/lib/Sema/TreeTransform.h clang/lib/Serialization/ASTReader.cpp clang/lib/Serialization/ASTWriter.cpp clang/test/OpenMP/atomic_ast_print.cpp clang/test/OpenMP/atomic_messages.cpp clang/tools/libclang/CIndex.cpp flang/lib/Semantics/check-omp-structure.cpp llvm/include/llvm/Frontend/OpenMP/OMP.td Removed: diff --git a/clang/include/clang/AST/OpenMPClause.h b/clang/include/clang/AST/OpenMPClause.h index 51155e63dcb8f7d..924ca189381ba86 100644 --- a/clang/include/clang/AST/OpenMPClause.h +++ b/clang/include/clang/AST/OpenMPClause.h @@ -2513,6 +2513,89 @@ class OMPRelaxedClause final : public OMPClause { } }; +/// This represents 'fail' clause in the '#pragma omp atomic' +/// directive. +/// +/// \code +/// #pragma omp atomic compare fail +/// \endcode +/// In this example directive '#pragma omp atomic compare' has 'fail' clause. +class OMPFailClause final : public OMPClause { + + // FailParameter is a memory-order-clause. Storing the ClauseKind is + // sufficient for our purpose. + OpenMPClauseKind FailParameter = llvm::omp::Clause::OMPC_unknown; + SourceLocation FailParameterLoc; + SourceLocation LParenLoc; + + friend class OMPClauseReader; + + /// Sets the location of '(' in fail clause. + void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } + + /// Sets the location of memoryOrder clause argument in fail clause. + void setFailParameterLoc(SourceLocation Loc) { FailParameterLoc = Loc; } + + /// Sets the mem_order clause for 'atomic compare fail' directive. + void setFailParameter(OpenMPClauseKind FailParameter) { +this->FailParameter = FailParameter; +assert(checkFailClauseParameter(FailParameter) && + "Invalid fail clause parameter"); + } + +public: + /// Build 'fail' clause. + /// + /// \param StartLoc Starting location of the clause. + /// \param EndLoc Ending location of the clause. + OMPFailClause(SourceLocation StartLoc, SourceLocation EndLoc) + : OMPClause(llvm::omp::OMPC_fail, StartLoc, EndLoc) {} + + OMPFailClause(OpenMPClauseKind FailParameter, SourceLocation FailParameterLoc, +SourceLocation StartLoc, SourceLocation LParenLoc, +SourceLocation EndLoc) + : OMPClause(llvm::omp::OMPC_fail, StartLoc, EndLoc), +FailParameterLoc(FailParameterLoc), LParenLoc(LParenLoc) { + +setFailParameter(FailParameter); + } + + /// Build an empty clause. + OMPFailClause() + : OMPClause(llvm::omp::OMPC_fail, SourceLocation(), SourceLocation()) {} + + child_range children() { +return child_range(child_iterator(), child_iterator()); + } + + const_child_range children() const { +return const_child_range(const_child_iterator(), const_child_iterator()); + } + + child_range used_children() { +return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { +return const_child_range(const_child_iterator(), const_child_iterator()); + } + + static bool classof(const OMPClause *T) { +return T->getClauseKind() == llvm::omp::OMPC_fail; + } + + /// Gets the location of '(' (for the parameter) in fail clause. + SourceLocation getLParenLoc() const { +return LParenLoc; + } + + /// Gets the location of Fail Parameter (type memory-order-clause) in + /// fail clause. + SourceLocation getFailParameterLoc() const { return FailParameterLoc; } + + /// Gets the parameter (type memory-order-clause) in Fail clause. + OpenMPClauseKind getFailParameter() const { return FailParameter; } +}; + /// This represents clause 'private' in the '#pragma omp ...' directives. /// /// \code diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h b/clang/include/clang/AST/RecursiveASTVisitor.h index 53bc15e1b19f668..c501801b95bd955 100644 --- a/clang/include/clang/AST/RecursiveASTVisitor.h +++ b/clang/include/clang/AST/RecursiveASTVisitor.h @@ -3398,6 +3398,11 @@ bool RecursiveASTVisitor::VisitOMP
[clang] [OpenMP] Support for `nothing` in `metadirective` (PR #73690)
https://github.com/sandeepkosuri created https://github.com/llvm/llvm-project/pull/73690 - Removed an unnecessary check that was preventing `nothing` to work properly inside `metadirective`. >From 0aad8e5ca5d7e9f2d2400e6c2f3db0a374d55ed8 Mon Sep 17 00:00:00 2001 From: Sandeep Kosuri Date: Tue, 28 Nov 2023 13:03:25 -0600 Subject: [PATCH] [OpenMP] Support for `nothing` in `metadirective` --- clang/lib/Parse/ParseOpenMP.cpp | 12 +++- clang/test/OpenMP/metadirective_ast_print.c | 12 clang/test/OpenMP/metadirective_empty.cpp | 20 clang/test/OpenMP/nothing_messages.cpp | 1 - 4 files changed, 39 insertions(+), 6 deletions(-) diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp index ca70bb241d6f723..fb7e7a979e49f7e 100644 --- a/clang/lib/Parse/ParseOpenMP.cpp +++ b/clang/lib/Parse/ParseOpenMP.cpp @@ -2518,12 +2518,14 @@ StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective( switch (DKind) { case OMPD_nothing: -if ((StmtCtx & ParsedStmtContext::AllowStandaloneOpenMPDirectives) == -ParsedStmtContext()) - Diag(Tok, diag::err_omp_immediate_directive) -<< getOpenMPDirectiveName(DKind) << 0; ConsumeToken(); -skipUntilPragmaOpenMPEnd(DKind); +// If we are parsing the directive within a metadirective, the directive +// ends with a ')'. +if (ReadDirectiveWithinMetadirective && Tok.is(tok::r_paren)) + while (Tok.isNot(tok::annot_pragma_openmp_end)) +ConsumeAnyToken(); +else + skipUntilPragmaOpenMPEnd(DKind); if (Tok.is(tok::annot_pragma_openmp_end)) ConsumeAnnotationToken(); break; diff --git a/clang/test/OpenMP/metadirective_ast_print.c b/clang/test/OpenMP/metadirective_ast_print.c index ddd5b8633cc5013..d9ff7e764521607 100644 --- a/clang/test/OpenMP/metadirective_ast_print.c +++ b/clang/test/OpenMP/metadirective_ast_print.c @@ -67,6 +67,16 @@ void foo(void) { default(parallel for) for (int i = 0; i < 100; i++) ; + +#pragma omp metadirective when(implementation = {extension(match_all)} \ + : nothing) default(parallel for) + for (int i = 0; i < 16; i++) +; + +#pragma omp metadirective when(implementation = {extension(match_any)} \ + : parallel) default(nothing) + for (int i = 0; i < 16; i++) +; } // CHECK: void bar(void); @@ -95,5 +105,7 @@ void foo(void) { // CHECK-NEXT: for (int j = 0; j < 16; j++) // CHECK-AMDGCN: #pragma omp teams distribute parallel for // CHECK-AMDGCN-NEXT: for (int i = 0; i < 100; i++) +// CHECK: for (int i = 0; i < 16; i++) +// CHECK: for (int i = 0; i < 16; i++) #endif diff --git a/clang/test/OpenMP/metadirective_empty.cpp b/clang/test/OpenMP/metadirective_empty.cpp index 8708aa45b156309..b93ed722cb6e904 100644 --- a/clang/test/OpenMP/metadirective_empty.cpp +++ b/clang/test/OpenMP/metadirective_empty.cpp @@ -14,11 +14,17 @@ void func() { :) default(parallel for) for (int i = 0; i < N; i++) ; + +#pragma omp metadirective when(implementation = {vendor(llvm)} \ + :nothing) default(parallel for) + for (int i = 0; i < N; i++) +; } // CHECK-LABEL: void @_Z4funcv() // CHECK: entry: // CHECK: [[I:%.+]] = alloca i32, +// CHECK: [[I1:%.+]] = alloca i32, // CHECK: store i32 0, ptr [[I]], // CHECK: br label %[[FOR_COND:.+]] // CHECK: [[FOR_COND]]: @@ -33,6 +39,20 @@ void func() { // CHECK: store i32 [[INC]], ptr [[I]], // CHECK: br label %[[FOR_COND]], // CHECK: [[FOR_END]]: +// CHECK: store i32 0, ptr [[I1]], +// CHECK: br label %[[FOR_COND1:.+]] +// CHECK: [[FOR_COND1]]: +// CHECK: [[TWO:%.+]] = load i32, ptr [[I1]], +// CHECK: [[CMP1:%.+]] = icmp slt i32 [[TWO]], 1000 +// CHECK: br i1 [[CMP1]], label %[[FOR_BODY1:.+]], label %[[FOR_END1:.+]] +// CHECK: [[FOR_BODY1]]: +// CHECK: br label %[[FOR_INC1:.+]] +// CHECK: [[FOR_INC1]]: +// CHECK: [[THREE:%.+]] = load i32, ptr [[I1]], +// CHECK: [[INC1:%.+]] = add nsw i32 [[THREE]], 1 +// CHECK: store i32 [[INC1]], ptr [[I1]], +// CHECK: br label %[[FOR_COND1]], +// CHECK: [[FOR_END1]]: // CHECK: ret void // CHECK: } diff --git a/clang/test/OpenMP/nothing_messages.cpp b/clang/test/OpenMP/nothing_messages.cpp index cd6d0defe492fb4..0e27e3c27076a7b 100644 --- a/clang/test/OpenMP/nothing_messages.cpp +++ b/clang/test/OpenMP/nothing_messages.cpp @@ -12,7 +12,6 @@ int mixed() { x=d; } -// expected-error@+2 {{#pragma omp nothing' cannot be an immediate substatement}} if(!x) #pragma omp nothing x=d; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenMP] Support for `nothing` in `metadirective` (PR #73690)
@@ -12,7 +12,6 @@ int mixed() { x=d; } -// expected-error@+2 {{#pragma omp nothing' cannot be an immediate substatement}} sandeepkosuri wrote: But I don't see such a restriction for `nothing` in spec 5.1, is it really required ? https://github.com/llvm/llvm-project/pull/73690 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenMP] Support for `nothing` in `metadirective` (PR #73690)
@@ -12,7 +12,6 @@ int mixed() { x=d; } -// expected-error@+2 {{#pragma omp nothing' cannot be an immediate substatement}} sandeepkosuri wrote: oh sorry for missing that ! So, is this supposed to produce a compilation error (provided arch is x86_64)? ``` #pragma omp target #pragma omp metadirective \ when( device={arch("x86_64")}: nothing) \ default(parallel) for (int i= 0; i< N; i++) v3[i] = v1[i] * v2[i]; ``` https://github.com/llvm/llvm-project/pull/73690 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenMP] Support for `nothing` in `metadirective` (PR #73690)
https://github.com/sandeepkosuri closed https://github.com/llvm/llvm-project/pull/73690 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [openmp] [OpenMP] return empty stmt for `nothing` (PR #74042)
https://github.com/sandeepkosuri created https://github.com/llvm/llvm-project/pull/74042 - `nothing` directive was effecting the `if` block structure which it should not. So return an empty statement instead of an error statement while parsing to avoid this. >From e60bc748d9c856d6f7be9cea42df834c94332359 Mon Sep 17 00:00:00 2001 From: Sandeep Kosuri Date: Fri, 1 Dec 2023 11:26:59 +0530 Subject: [PATCH] [OpenMP] return empty stmt for `nothing` --- clang/lib/Parse/ParseOpenMP.cpp | 3 ++- clang/test/OpenMP/nothing_ast_print.cpp | 20 +++ openmp/runtime/test/misc_bugs/omp_nothing.c | 27 + 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 clang/test/OpenMP/nothing_ast_print.cpp create mode 100644 openmp/runtime/test/misc_bugs/omp_nothing.c diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp index fb7e7a979e49f7e..da5f6605c6ffac9 100644 --- a/clang/lib/Parse/ParseOpenMP.cpp +++ b/clang/lib/Parse/ParseOpenMP.cpp @@ -2528,7 +2528,8 @@ StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective( skipUntilPragmaOpenMPEnd(DKind); if (Tok.is(tok::annot_pragma_openmp_end)) ConsumeAnnotationToken(); -break; +// return an empty statement +return StmtEmpty(); case OMPD_metadirective: { ConsumeToken(); SmallVector VMIs; diff --git a/clang/test/OpenMP/nothing_ast_print.cpp b/clang/test/OpenMP/nothing_ast_print.cpp new file mode 100644 index 000..a16f95044b60d69 --- /dev/null +++ b/clang/test/OpenMP/nothing_ast_print.cpp @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -fopenmp -ast-print %s | FileCheck %s --check-prefix=PRINT +// RUN: %clang_cc1 -ast-print %s | FileCheck %s --check-prefix=PRINT + +// Checks whether the `if` body looks same with and without OpenMP enabled + +void foo() { +return; +} + +int main() { +int x = 3; +if (x % 2 == 0) +#pragma omp nothing +foo(); + +return 0; +// PRINT: if (x % 2 == 0) +// PRINT:foo(); +// PRINT: return 0; +} \ No newline at end of file diff --git a/openmp/runtime/test/misc_bugs/omp_nothing.c b/openmp/runtime/test/misc_bugs/omp_nothing.c new file mode 100644 index 000..e50d32d147ec9bc --- /dev/null +++ b/openmp/runtime/test/misc_bugs/omp_nothing.c @@ -0,0 +1,27 @@ +// RUN: %libomp-compile +// RUN: %libomp-run | FileCheck %s --check-prefix OMP-CHECK + +#include + +void foo(int x) { + printf("foo"); + return; +} + +int main() { + int x = 4; + // should call foo() + if (x % 2 == 0) +#pragma omp nothing +foo(x); + + // should not call foo() + x = 3; + if (x % 2 == 0) +#pragma omp nothing +foo(x); + + // OMP-CHECK: foo + // OMP-CHECK-NOT: foo + return 0; +} \ No newline at end of file ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [openmp] [OpenMP] return empty stmt for `nothing` (PR #74042)
https://github.com/sandeepkosuri closed https://github.com/llvm/llvm-project/pull/74042 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [clang-tools-extra] [libc] [mlir] [lldb] [libcxx] [flang] [llvm] [openmp] [OpenMP] atomic compare fail : Codegen support (PR #75709)
https://github.com/sandeepkosuri closed https://github.com/llvm/llvm-project/pull/75709 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[polly] [lldb] [compiler-rt] [clang-tools-extra] [libcxxabi] [flang] [libc] [openmp] [llvm] [mlir] [libcxx] [clang] [OpenMP] Patch for Support to loop bind clause : Checking Parent Region (PR #76938)
https://github.com/sandeepkosuri closed https://github.com/llvm/llvm-project/pull/76938 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenMP] Parse and Sema support for declare target in local scope (PR #83223)
@@ -11326,6 +11326,8 @@ def err_omp_device_type_mismatch : Error< def err_omp_wrong_device_function_call : Error< "function with 'device_type(%0)' is not available on %select{device|host}1">; def note_omp_marked_device_type_here : Note<"marked as 'device_type(%0)' here">; +def err_omp_declare_target_has_local_vars : Error< + "local variable '%0' ignored in 'declare target' directive; ">; sandeepkosuri wrote: Yeah, will fix that https://github.com/llvm/llvm-project/pull/83223 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenMP] Parse and Sema support for declare target in local scope (PR #83223)
https://github.com/sandeepkosuri updated https://github.com/llvm/llvm-project/pull/83223 >From cbf1b4409e379309ae3d942b3dbec0964b9ee0d1 Mon Sep 17 00:00:00 2001 From: Sandeep Kosuri Date: Tue, 27 Feb 2024 23:19:41 -0600 Subject: [PATCH 1/3] [OpenMP] Parse and Sema support for declare target in local scope --- .../clang/Basic/DiagnosticSemaKinds.td| 3 +++ clang/lib/Parse/ParseOpenMP.cpp | 23 ++- clang/lib/Sema/SemaOpenMP.cpp | 9 .../test/OpenMP/declare_target_ast_print.cpp | 19 +++ clang/test/OpenMP/declare_target_messages.cpp | 9 5 files changed, 62 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index a7f2858477bee6..faa7d1872ae3f1 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -11326,6 +11326,9 @@ def err_omp_device_type_mismatch : Error< def err_omp_wrong_device_function_call : Error< "function with 'device_type(%0)' is not available on %select{device|host}1">; def note_omp_marked_device_type_here : Note<"marked as 'device_type(%0)' here">; +def warn_omp_declare_target_has_local_vars : Warning< + "local variable '%0' ignored in 'declare target' directive; ">, + InGroup; def warn_omp_declare_target_after_first_use : Warning< "declaration marked as declare target after first use, it may lead to incorrect results">, InGroup; diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp index bfc31f2653c237..814126e321d3bc 100644 --- a/clang/lib/Parse/ParseOpenMP.cpp +++ b/clang/lib/Parse/ParseOpenMP.cpp @@ -2984,8 +2984,29 @@ StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective( OMPDirectiveScope.Exit(); break; } + case OMPD_declare_target: { +SourceLocation DTLoc = ConsumeAnyToken(); +bool HasClauses = Tok.isNot(tok::annot_pragma_openmp_end); +Sema::DeclareTargetContextInfo DTCI(DKind, DTLoc); +if (HasClauses) + ParseOMPDeclareTargetClauses(DTCI); +bool HasImplicitMappings = +!HasClauses || (DTCI.ExplicitlyMapped.empty() && DTCI.Indirect); + +if (HasImplicitMappings) { + Diag(Tok, diag::err_omp_unexpected_directive) + << 1 << getOpenMPDirectiveName(DKind); + SkipUntil(tok::annot_pragma_openmp_end); + break; +} + +// Skip the last annot_pragma_openmp_end. +ConsumeAnyToken(); + +Actions.ActOnFinishedOpenMPDeclareTargetContext(DTCI); +break; + } case OMPD_declare_simd: - case OMPD_declare_target: case OMPD_begin_declare_target: case OMPD_end_declare_target: case OMPD_requires: diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index 7f75cfc5b54f35..0cd8ff065a3419 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -23352,6 +23352,15 @@ void Sema::ActOnOpenMPDeclareTargetName(NamedDecl *ND, SourceLocation Loc, isa(ND)) && "Expected variable, function or function template."); + if (auto *VD = dyn_cast(ND)) { +// Only global variables can be marked as declare target. +if (!VD->isFileVarDecl() && !VD->isStaticLocal() && +!VD->isStaticDataMember()) { + Diag(Loc, diag::warn_omp_declare_target_has_local_vars) + << VD->getNameAsString(); + return; +} + } // Diagnose marking after use as it may lead to incorrect diagnosis and // codegen. if (LangOpts.OpenMP >= 50 && diff --git a/clang/test/OpenMP/declare_target_ast_print.cpp b/clang/test/OpenMP/declare_target_ast_print.cpp index 40c5dd299abd96..43cccf763e97c3 100644 --- a/clang/test/OpenMP/declare_target_ast_print.cpp +++ b/clang/test/OpenMP/declare_target_ast_print.cpp @@ -360,6 +360,17 @@ int inner_link; // CHECK-NEXT: int inner_link; // CHECK-NEXT: #pragma omp end declare target +void foo2() { return ;} +// CHECK: #pragma omp declare target +// CHECK-NEXT: void foo2() { +// CHECK-NEXT: return; +// CHECK-NEXT: } + +int x; +// CHECK: #pragma omp declare target link +// CHECK-NEXT: int x; +// CHECK-NEXT: #pragma omp end declare target + int main (int argc, char **argv) { foo(); foo_c(); @@ -367,6 +378,14 @@ int main (int argc, char **argv) { test1(); baz(); baz(); + +#if _OPENMP == 202111 +#pragma omp declare target enter(foo2) +#else +#pragma omp declare target to (foo2) +#endif + + #pragma omp declare target link(x) return (0); } diff --git a/clang/test/OpenMP/declare_target_messages.cpp b/clang/test/OpenMP/declare_target_messages.cpp index cf034aca7c9136..39616bc47b2ccb 100644 --- a/clang/test/OpenMP/declare_target_messages.cpp +++ b/clang/test/OpenMP/declare_target_messages.cpp @@ -182,11 +182,20 @@ struct S { #pragma omp end declare target }; +void foo3() { + return; +} + +int *y; +int **w = &y; int main (int argc, char **argv) { + int a = 2; #pragma omp declare target // expected-error
[clang] [OpenMP] Parse and Sema support for declare target in local scope (PR #83223)
https://github.com/sandeepkosuri closed https://github.com/llvm/llvm-project/pull/83223 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenMP] Parse and Sema support for declare target in local scope (PR #83223)
https://github.com/sandeepkosuri created https://github.com/llvm/llvm-project/pull/83223 - adds Parse and Sema support for the `declare target` directive inside a function scope. >From cbf1b4409e379309ae3d942b3dbec0964b9ee0d1 Mon Sep 17 00:00:00 2001 From: Sandeep Kosuri Date: Tue, 27 Feb 2024 23:19:41 -0600 Subject: [PATCH] [OpenMP] Parse and Sema support for declare target in local scope --- .../clang/Basic/DiagnosticSemaKinds.td| 3 +++ clang/lib/Parse/ParseOpenMP.cpp | 23 ++- clang/lib/Sema/SemaOpenMP.cpp | 9 .../test/OpenMP/declare_target_ast_print.cpp | 19 +++ clang/test/OpenMP/declare_target_messages.cpp | 9 5 files changed, 62 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index a7f2858477bee6..faa7d1872ae3f1 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -11326,6 +11326,9 @@ def err_omp_device_type_mismatch : Error< def err_omp_wrong_device_function_call : Error< "function with 'device_type(%0)' is not available on %select{device|host}1">; def note_omp_marked_device_type_here : Note<"marked as 'device_type(%0)' here">; +def warn_omp_declare_target_has_local_vars : Warning< + "local variable '%0' ignored in 'declare target' directive; ">, + InGroup; def warn_omp_declare_target_after_first_use : Warning< "declaration marked as declare target after first use, it may lead to incorrect results">, InGroup; diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp index bfc31f2653c237..814126e321d3bc 100644 --- a/clang/lib/Parse/ParseOpenMP.cpp +++ b/clang/lib/Parse/ParseOpenMP.cpp @@ -2984,8 +2984,29 @@ StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective( OMPDirectiveScope.Exit(); break; } + case OMPD_declare_target: { +SourceLocation DTLoc = ConsumeAnyToken(); +bool HasClauses = Tok.isNot(tok::annot_pragma_openmp_end); +Sema::DeclareTargetContextInfo DTCI(DKind, DTLoc); +if (HasClauses) + ParseOMPDeclareTargetClauses(DTCI); +bool HasImplicitMappings = +!HasClauses || (DTCI.ExplicitlyMapped.empty() && DTCI.Indirect); + +if (HasImplicitMappings) { + Diag(Tok, diag::err_omp_unexpected_directive) + << 1 << getOpenMPDirectiveName(DKind); + SkipUntil(tok::annot_pragma_openmp_end); + break; +} + +// Skip the last annot_pragma_openmp_end. +ConsumeAnyToken(); + +Actions.ActOnFinishedOpenMPDeclareTargetContext(DTCI); +break; + } case OMPD_declare_simd: - case OMPD_declare_target: case OMPD_begin_declare_target: case OMPD_end_declare_target: case OMPD_requires: diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index 7f75cfc5b54f35..0cd8ff065a3419 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -23352,6 +23352,15 @@ void Sema::ActOnOpenMPDeclareTargetName(NamedDecl *ND, SourceLocation Loc, isa(ND)) && "Expected variable, function or function template."); + if (auto *VD = dyn_cast(ND)) { +// Only global variables can be marked as declare target. +if (!VD->isFileVarDecl() && !VD->isStaticLocal() && +!VD->isStaticDataMember()) { + Diag(Loc, diag::warn_omp_declare_target_has_local_vars) + << VD->getNameAsString(); + return; +} + } // Diagnose marking after use as it may lead to incorrect diagnosis and // codegen. if (LangOpts.OpenMP >= 50 && diff --git a/clang/test/OpenMP/declare_target_ast_print.cpp b/clang/test/OpenMP/declare_target_ast_print.cpp index 40c5dd299abd96..43cccf763e97c3 100644 --- a/clang/test/OpenMP/declare_target_ast_print.cpp +++ b/clang/test/OpenMP/declare_target_ast_print.cpp @@ -360,6 +360,17 @@ int inner_link; // CHECK-NEXT: int inner_link; // CHECK-NEXT: #pragma omp end declare target +void foo2() { return ;} +// CHECK: #pragma omp declare target +// CHECK-NEXT: void foo2() { +// CHECK-NEXT: return; +// CHECK-NEXT: } + +int x; +// CHECK: #pragma omp declare target link +// CHECK-NEXT: int x; +// CHECK-NEXT: #pragma omp end declare target + int main (int argc, char **argv) { foo(); foo_c(); @@ -367,6 +378,14 @@ int main (int argc, char **argv) { test1(); baz(); baz(); + +#if _OPENMP == 202111 +#pragma omp declare target enter(foo2) +#else +#pragma omp declare target to (foo2) +#endif + + #pragma omp declare target link(x) return (0); } diff --git a/clang/test/OpenMP/declare_target_messages.cpp b/clang/test/OpenMP/declare_target_messages.cpp index cf034aca7c9136..39616bc47b2ccb 100644 --- a/clang/test/OpenMP/declare_target_messages.cpp +++ b/clang/test/OpenMP/declare_target_messages.cpp @@ -182,11 +182,20 @@ struct S { #pragma omp end declare target }; +void foo3() { + return; +} + +int *y; +int **w = &y; int ma
[clang] [OpenMP] Parse and Sema support for declare target in local scope (PR #83223)
sandeepkosuri wrote: > One big question - why do we need it in function scope for clang? According to the spec, it is not explicitly mentioned that the `declare target` placement is not allowed inside a function scope. And I came across this [sollve test case](https://github.com/SOLLVE/sollve_vv/blob/master/tests/5.0/declare_target/test_declare_target_nested_functions.c) which made me realise that this should be allowed. https://github.com/llvm/llvm-project/pull/83223 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenMP] Parse and Sema support for declare target in local scope (PR #83223)
@@ -23352,6 +23352,15 @@ void Sema::ActOnOpenMPDeclareTargetName(NamedDecl *ND, SourceLocation Loc, isa(ND)) && "Expected variable, function or function template."); + if (auto *VD = dyn_cast(ND)) { sandeepkosuri wrote: previously `ActOnOpenMPDeclareTargetName` was called for variables of file scope, I guess that's why there was no check to guard against local variables at this point. `checkDeclIsAllowedInOpenMPTarget` is called after giving the `OMPDeclareTargetDeclAttr` to the variable, so it does not filter out local vars from getting that attribute. https://github.com/llvm/llvm-project/pull/83223 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenMP] Parse and Sema support for declare target in local scope (PR #83223)
@@ -11326,6 +11326,9 @@ def err_omp_device_type_mismatch : Error< def err_omp_wrong_device_function_call : Error< "function with 'device_type(%0)' is not available on %select{device|host}1">; def note_omp_marked_device_type_here : Note<"marked as 'device_type(%0)' here">; +def warn_omp_declare_target_has_local_vars : Warning< + "local variable '%0' ignored in 'declare target' directive; ">, + InGroup; sandeepkosuri wrote: sure i will make this an error. https://github.com/llvm/llvm-project/pull/83223 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenMP] Clang Codegen Interop : Accept multiple init (PR #82604)
https://github.com/sandeepkosuri closed https://github.com/llvm/llvm-project/pull/82604 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenMP] Parse and Sema support for declare target in local scope (PR #83223)
https://github.com/sandeepkosuri updated https://github.com/llvm/llvm-project/pull/83223 >From cbf1b4409e379309ae3d942b3dbec0964b9ee0d1 Mon Sep 17 00:00:00 2001 From: Sandeep Kosuri Date: Tue, 27 Feb 2024 23:19:41 -0600 Subject: [PATCH 1/2] [OpenMP] Parse and Sema support for declare target in local scope --- .../clang/Basic/DiagnosticSemaKinds.td| 3 +++ clang/lib/Parse/ParseOpenMP.cpp | 23 ++- clang/lib/Sema/SemaOpenMP.cpp | 9 .../test/OpenMP/declare_target_ast_print.cpp | 19 +++ clang/test/OpenMP/declare_target_messages.cpp | 9 5 files changed, 62 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index a7f2858477bee6..faa7d1872ae3f1 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -11326,6 +11326,9 @@ def err_omp_device_type_mismatch : Error< def err_omp_wrong_device_function_call : Error< "function with 'device_type(%0)' is not available on %select{device|host}1">; def note_omp_marked_device_type_here : Note<"marked as 'device_type(%0)' here">; +def warn_omp_declare_target_has_local_vars : Warning< + "local variable '%0' ignored in 'declare target' directive; ">, + InGroup; def warn_omp_declare_target_after_first_use : Warning< "declaration marked as declare target after first use, it may lead to incorrect results">, InGroup; diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp index bfc31f2653c237..814126e321d3bc 100644 --- a/clang/lib/Parse/ParseOpenMP.cpp +++ b/clang/lib/Parse/ParseOpenMP.cpp @@ -2984,8 +2984,29 @@ StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective( OMPDirectiveScope.Exit(); break; } + case OMPD_declare_target: { +SourceLocation DTLoc = ConsumeAnyToken(); +bool HasClauses = Tok.isNot(tok::annot_pragma_openmp_end); +Sema::DeclareTargetContextInfo DTCI(DKind, DTLoc); +if (HasClauses) + ParseOMPDeclareTargetClauses(DTCI); +bool HasImplicitMappings = +!HasClauses || (DTCI.ExplicitlyMapped.empty() && DTCI.Indirect); + +if (HasImplicitMappings) { + Diag(Tok, diag::err_omp_unexpected_directive) + << 1 << getOpenMPDirectiveName(DKind); + SkipUntil(tok::annot_pragma_openmp_end); + break; +} + +// Skip the last annot_pragma_openmp_end. +ConsumeAnyToken(); + +Actions.ActOnFinishedOpenMPDeclareTargetContext(DTCI); +break; + } case OMPD_declare_simd: - case OMPD_declare_target: case OMPD_begin_declare_target: case OMPD_end_declare_target: case OMPD_requires: diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index 7f75cfc5b54f35..0cd8ff065a3419 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -23352,6 +23352,15 @@ void Sema::ActOnOpenMPDeclareTargetName(NamedDecl *ND, SourceLocation Loc, isa(ND)) && "Expected variable, function or function template."); + if (auto *VD = dyn_cast(ND)) { +// Only global variables can be marked as declare target. +if (!VD->isFileVarDecl() && !VD->isStaticLocal() && +!VD->isStaticDataMember()) { + Diag(Loc, diag::warn_omp_declare_target_has_local_vars) + << VD->getNameAsString(); + return; +} + } // Diagnose marking after use as it may lead to incorrect diagnosis and // codegen. if (LangOpts.OpenMP >= 50 && diff --git a/clang/test/OpenMP/declare_target_ast_print.cpp b/clang/test/OpenMP/declare_target_ast_print.cpp index 40c5dd299abd96..43cccf763e97c3 100644 --- a/clang/test/OpenMP/declare_target_ast_print.cpp +++ b/clang/test/OpenMP/declare_target_ast_print.cpp @@ -360,6 +360,17 @@ int inner_link; // CHECK-NEXT: int inner_link; // CHECK-NEXT: #pragma omp end declare target +void foo2() { return ;} +// CHECK: #pragma omp declare target +// CHECK-NEXT: void foo2() { +// CHECK-NEXT: return; +// CHECK-NEXT: } + +int x; +// CHECK: #pragma omp declare target link +// CHECK-NEXT: int x; +// CHECK-NEXT: #pragma omp end declare target + int main (int argc, char **argv) { foo(); foo_c(); @@ -367,6 +378,14 @@ int main (int argc, char **argv) { test1(); baz(); baz(); + +#if _OPENMP == 202111 +#pragma omp declare target enter(foo2) +#else +#pragma omp declare target to (foo2) +#endif + + #pragma omp declare target link(x) return (0); } diff --git a/clang/test/OpenMP/declare_target_messages.cpp b/clang/test/OpenMP/declare_target_messages.cpp index cf034aca7c9136..39616bc47b2ccb 100644 --- a/clang/test/OpenMP/declare_target_messages.cpp +++ b/clang/test/OpenMP/declare_target_messages.cpp @@ -182,11 +182,20 @@ struct S { #pragma omp end declare target }; +void foo3() { + return; +} + +int *y; +int **w = &y; int main (int argc, char **argv) { + int a = 2; #pragma omp declare target // expected-error
[clang] 85f6b2f - [OpenMP] Patch for Support to loop bind clause : Checking Parent Region
Author: Sunil Kuravinakop Date: 2023-10-26T05:08:41-05:00 New Revision: 85f6b2fac9a367337e43ca288c45ea783981cc16 URL: https://github.com/llvm/llvm-project/commit/85f6b2fac9a367337e43ca288c45ea783981cc16 DIFF: https://github.com/llvm/llvm-project/commit/85f6b2fac9a367337e43ca288c45ea783981cc16.diff LOG: [OpenMP] Patch for Support to loop bind clause : Checking Parent Region Differential revision: https://reviews.llvm.org/D158266 Added: Modified: clang/include/clang/Sema/Sema.h clang/lib/Sema/SemaOpenMP.cpp clang/test/OpenMP/loop_bind_messages.cpp clang/test/PCH/pragma-loop.cpp Removed: diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 1e9752345ffd173..18ac85011aa752a 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -11307,6 +11307,7 @@ class Sema final { /// on the parameter of the bind clause. In the methods for the /// mapped directives, check the parameters of the lastprivate clause. bool checkLastPrivateForMappedDirectives(ArrayRef Clauses); + /// Depending on the bind clause of OMPD_loop map the directive to new /// directives. ///1) loop bind(parallel) --> OMPD_for @@ -11316,9 +11317,12 @@ class Sema final { /// rigorous semantic checking in the new mapped directives. bool mapLoopConstruct(llvm::SmallVector &ClausesWithoutBind, ArrayRef Clauses, -OpenMPBindClauseKind BindKind, +OpenMPBindClauseKind &BindKind, OpenMPDirectiveKind &Kind, -OpenMPDirectiveKind &PrevMappedDirective); +OpenMPDirectiveKind &PrevMappedDirective, +SourceLocation StartLoc, SourceLocation EndLoc, +const DeclarationNameInfo &DirName, +OpenMPDirectiveKind CancelRegion); public: /// The declarator \p D defines a function in the scope \p S which is nested diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index 75f9e152dca9297..f28e0f2693080c1 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -5062,6 +5062,18 @@ static bool checkNestingOfRegions(Sema &SemaRef, const DSAStackTy *Stack, CurrentRegion != OMPD_cancellation_point && CurrentRegion != OMPD_cancel && CurrentRegion != OMPD_scan) return false; +// Checks needed for mapping "loop" construct. Please check mapLoopConstruct +// for a detailed explanation +if (SemaRef.LangOpts.OpenMP >= 50 && CurrentRegion == OMPD_loop && +((BindKind == OMPC_BIND_parallel) || (BindKind == OMPC_BIND_teams)) && +(isOpenMPWorksharingDirective(ParentRegion) || + ParentRegion == OMPD_loop)) { + int ErrorMsgNumber = (BindKind == OMPC_BIND_parallel) ? 1 : 4; + SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region) + << true << getOpenMPDirectiveName(ParentRegion) << ErrorMsgNumber + << getOpenMPDirectiveName(CurrentRegion); + return true; +} if (CurrentRegion == OMPD_cancellation_point || CurrentRegion == OMPD_cancel) { // OpenMP [2.16, Nesting of Regions] @@ -6114,35 +6126,40 @@ processImplicitMapsWithDefaultMappers(Sema &S, DSAStackTy *Stack, bool Sema::mapLoopConstruct(llvm::SmallVector &ClausesWithoutBind, ArrayRef Clauses, -OpenMPBindClauseKind BindKind, +OpenMPBindClauseKind &BindKind, OpenMPDirectiveKind &Kind, -OpenMPDirectiveKind &PrevMappedDirective) { +OpenMPDirectiveKind &PrevMappedDirective, +SourceLocation StartLoc, SourceLocation EndLoc, +const DeclarationNameInfo &DirName, +OpenMPDirectiveKind CancelRegion) { bool UseClausesWithoutBind = false; // Restricting to "#pragma omp loop bind" if (getLangOpts().OpenMP >= 50 && Kind == OMPD_loop) { + +const OpenMPDirectiveKind ParentDirective = DSAStack->getParentDirective(); + if (BindKind == OMPC_BIND_unknown) { // Setting the enclosing teams or parallel construct for the loop // directive without bind clause. BindKind = OMPC_BIND_thread; // Default bind(thread) if binding is unknown - const OpenMPDirectiveKind ParentDirective = - DSAStack->getParentDirective(); if (ParentDirective == OMPD_unknown) { Diag(DSAStack->getDefaultDSALocation(), diag::err_omp_bind_required_on_loop); - } else if (ParentDirective == OMPD_parallel || - ParentDirective == OMPD_target_parallel) { + } else if (isOpenMPParallelDirective(ParentDirective) && + !isOpenMPTeamsDirect
[clang] 239ad4f - [OPENMP][NFC] Editing OpenMP support page
Author: Sandeep Kosuri Date: 2023-07-24T05:43:07-05:00 New Revision: 239ad4fde8805ad8d48babff633230313e051e36 URL: https://github.com/llvm/llvm-project/commit/239ad4fde8805ad8d48babff633230313e051e36 DIFF: https://github.com/llvm/llvm-project/commit/239ad4fde8805ad8d48babff633230313e051e36.diff LOG: [OPENMP][NFC] Editing OpenMP support page Added: Modified: clang/docs/OpenMPSupport.rst Removed: diff --git a/clang/docs/OpenMPSupport.rst b/clang/docs/OpenMPSupport.rst index 989c665db3bce2..6d31269d3abfa3 100644 --- a/clang/docs/OpenMPSupport.rst +++ b/clang/docs/OpenMPSupport.rst @@ -170,7 +170,7 @@ implementation. +--+--+--+---+ | device | infer target functions from initializers | :part:`worked on`| | +--+--+--+---+ -| device | infer target variables from initializers | :part:`worked on`| | +| device | infer target variables from initializers | :part:`done` | D146418 | +--+--+--+---+ | device | OMP_TARGET_OFFLOAD environment variable | :good:`done` | D50522 | +--+--+--+---+ ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 4097a24 - [Clang][OpenMP] Support for Code Generation of loop bind clause
Author: Sunil Kuravinakop Date: 2023-08-07T07:58:59-05:00 New Revision: 4097a24584121dba562d471fab97d3dfec1b5bff URL: https://github.com/llvm/llvm-project/commit/4097a24584121dba562d471fab97d3dfec1b5bff DIFF: https://github.com/llvm/llvm-project/commit/4097a24584121dba562d471fab97d3dfec1b5bff.diff LOG: [Clang][OpenMP] Support for Code Generation of loop bind clause Added: clang/test/OpenMP/loop_bind_codegen.cpp clang/test/OpenMP/loop_bind_enclosed.cpp clang/test/OpenMP/loop_bind_messages.cpp Modified: clang/include/clang/AST/StmtOpenMP.h clang/include/clang/Basic/DiagnosticSemaKinds.td clang/include/clang/Sema/Sema.h clang/lib/AST/StmtOpenMP.cpp clang/lib/Sema/SemaOpenMP.cpp clang/lib/Sema/TreeTransform.h clang/lib/Serialization/ASTReaderStmt.cpp clang/lib/Serialization/ASTWriterStmt.cpp clang/test/OpenMP/generic_loop_ast_print.cpp clang/test/OpenMP/generic_loop_codegen.cpp clang/test/OpenMP/nested_loop_codegen.cpp clang/test/PCH/pragma-loop.cpp Removed: diff --git a/clang/include/clang/AST/StmtOpenMP.h b/clang/include/clang/AST/StmtOpenMP.h index 2d37fdbf4ca8fb..20cd198f5f0cc5 100644 --- a/clang/include/clang/AST/StmtOpenMP.h +++ b/clang/include/clang/AST/StmtOpenMP.h @@ -281,6 +281,15 @@ class OMPExecutableDirective : public Stmt { return Data->getClauses(); } + /// Was this directive mapped from an another directive? + /// e.g. 1) omp loop bind(parallel) is mapped to OMPD_for + /// 2) omp loop bind(teams) is mapped to OMPD_distribute + /// 3) omp loop bind(thread) is mapped to OMPD_simd + /// It was necessary to note it down in the Directive because of + /// clang::TreeTransform::TransformOMPExecutableDirective() pass in + /// the frontend. + OpenMPDirectiveKind PrevMappedDirective = llvm::omp::OMPD_unknown; + protected: /// Data, associated with the directive. OMPChildren *Data = nullptr; @@ -345,6 +354,10 @@ class OMPExecutableDirective : public Stmt { return Inst; } + void setMappedDirective(OpenMPDirectiveKind MappedDirective) { +PrevMappedDirective = MappedDirective; + } + public: /// Iterates over expressions/statements used in the construct. class used_clauses_child_iterator @@ -598,6 +611,8 @@ class OMPExecutableDirective : public Stmt { "Expected directive with the associated statement."); return Data->getRawStmt(); } + + OpenMPDirectiveKind getMappedDirective() const { return PrevMappedDirective; } }; /// This represents '#pragma omp parallel' directive. @@ -1604,7 +1619,8 @@ class OMPSimdDirective : public OMPLoopDirective { SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef Clauses, Stmt *AssociatedStmt, - const HelperExprs &Exprs); + const HelperExprs &Exprs, + OpenMPDirectiveKind ParamPrevMappedDirective); /// Creates an empty directive with the place /// for \a NumClauses clauses. @@ -1682,7 +1698,8 @@ class OMPForDirective : public OMPLoopDirective { SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs, - Expr *TaskRedRef, bool HasCancel); + Expr *TaskRedRef, bool HasCancel, + OpenMPDirectiveKind ParamPrevMappedDirective); /// Creates an empty directive with the place /// for \a NumClauses clauses. @@ -4406,7 +4423,8 @@ class OMPDistributeDirective : public OMPLoopDirective { static OMPDistributeDirective * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef Clauses, - Stmt *AssociatedStmt, const HelperExprs &Exprs); + Stmt *AssociatedStmt, const HelperExprs &Exprs, + OpenMPDirectiveKind ParamPrevMappedDirective); /// Creates an empty directive with the place /// for \a NumClauses clauses. diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 4979f9f86d236d..5e0aca3c12d3d6 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -9869,6 +9869,11 @@ def err_break_not_in_loop_or_switch : Error< def warn_loop_ctrl_binds_to_inner : Warning< "'%0' is bound to current loop, GCC binds it to the enclosing loop">, InGroup; +def err_omp_bind_required_on_loop : Error< + "expected 'bind' clause for 'loop' construct without an enclosing OpenMP " + "construct">; +def err_omp_loop_reduction_clause : Error< + "'reduction' clause not allowed with '#pr
[clang] 8e7f032 - [Clang][OpenMP] Support for Code Generation of loop bind clause.
Author: Sunil Kuravinakop Date: 2023-08-08T09:23:00-05:00 New Revision: 8e7f0320ad7fb760fff598aba4b2c86528c58c2d URL: https://github.com/llvm/llvm-project/commit/8e7f0320ad7fb760fff598aba4b2c86528c58c2d DIFF: https://github.com/llvm/llvm-project/commit/8e7f0320ad7fb760fff598aba4b2c86528c58c2d.diff LOG: [Clang][OpenMP] Support for Code Generation of loop bind clause. Added: clang/test/OpenMP/loop_bind_codegen.cpp clang/test/OpenMP/loop_bind_enclosed.cpp clang/test/OpenMP/loop_bind_messages.cpp Modified: clang/include/clang/AST/StmtOpenMP.h clang/include/clang/Basic/DiagnosticSemaKinds.td clang/include/clang/Sema/Sema.h clang/lib/AST/StmtOpenMP.cpp clang/lib/Sema/SemaOpenMP.cpp clang/lib/Sema/TreeTransform.h clang/lib/Serialization/ASTReaderStmt.cpp clang/lib/Serialization/ASTWriterStmt.cpp clang/test/OpenMP/generic_loop_ast_print.cpp clang/test/OpenMP/generic_loop_codegen.cpp clang/test/OpenMP/nested_loop_codegen.cpp clang/test/PCH/pragma-loop.cpp Removed: diff --git a/clang/include/clang/AST/StmtOpenMP.h b/clang/include/clang/AST/StmtOpenMP.h index 2d37fdbf4ca8fb..20cd198f5f0cc5 100644 --- a/clang/include/clang/AST/StmtOpenMP.h +++ b/clang/include/clang/AST/StmtOpenMP.h @@ -281,6 +281,15 @@ class OMPExecutableDirective : public Stmt { return Data->getClauses(); } + /// Was this directive mapped from an another directive? + /// e.g. 1) omp loop bind(parallel) is mapped to OMPD_for + /// 2) omp loop bind(teams) is mapped to OMPD_distribute + /// 3) omp loop bind(thread) is mapped to OMPD_simd + /// It was necessary to note it down in the Directive because of + /// clang::TreeTransform::TransformOMPExecutableDirective() pass in + /// the frontend. + OpenMPDirectiveKind PrevMappedDirective = llvm::omp::OMPD_unknown; + protected: /// Data, associated with the directive. OMPChildren *Data = nullptr; @@ -345,6 +354,10 @@ class OMPExecutableDirective : public Stmt { return Inst; } + void setMappedDirective(OpenMPDirectiveKind MappedDirective) { +PrevMappedDirective = MappedDirective; + } + public: /// Iterates over expressions/statements used in the construct. class used_clauses_child_iterator @@ -598,6 +611,8 @@ class OMPExecutableDirective : public Stmt { "Expected directive with the associated statement."); return Data->getRawStmt(); } + + OpenMPDirectiveKind getMappedDirective() const { return PrevMappedDirective; } }; /// This represents '#pragma omp parallel' directive. @@ -1604,7 +1619,8 @@ class OMPSimdDirective : public OMPLoopDirective { SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef Clauses, Stmt *AssociatedStmt, - const HelperExprs &Exprs); + const HelperExprs &Exprs, + OpenMPDirectiveKind ParamPrevMappedDirective); /// Creates an empty directive with the place /// for \a NumClauses clauses. @@ -1682,7 +1698,8 @@ class OMPForDirective : public OMPLoopDirective { SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs, - Expr *TaskRedRef, bool HasCancel); + Expr *TaskRedRef, bool HasCancel, + OpenMPDirectiveKind ParamPrevMappedDirective); /// Creates an empty directive with the place /// for \a NumClauses clauses. @@ -4406,7 +4423,8 @@ class OMPDistributeDirective : public OMPLoopDirective { static OMPDistributeDirective * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef Clauses, - Stmt *AssociatedStmt, const HelperExprs &Exprs); + Stmt *AssociatedStmt, const HelperExprs &Exprs, + OpenMPDirectiveKind ParamPrevMappedDirective); /// Creates an empty directive with the place /// for \a NumClauses clauses. diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index e6b1dc948fc6bd..12909d6b7903b2 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -9875,6 +9875,11 @@ def err_break_not_in_loop_or_switch : Error< def warn_loop_ctrl_binds_to_inner : Warning< "'%0' is bound to current loop, GCC binds it to the enclosing loop">, InGroup; +def err_omp_bind_required_on_loop : Error< + "expected 'bind' clause for 'loop' construct without an enclosing OpenMP " + "construct">; +def err_omp_loop_reduction_clause : Error< + "'reduction' clause not allowed with '#p
[clang] 58eba70 - [OpenMP] supporting additional case of declare target initializer expression list
Author: Ritanya B Bharadwaj Date: 2023-08-08T10:14:59-05:00 New Revision: 58eba709a330e4c83de0a98b50fc0acf26cb4344 URL: https://github.com/llvm/llvm-project/commit/58eba709a330e4c83de0a98b50fc0acf26cb4344 DIFF: https://github.com/llvm/llvm-project/commit/58eba709a330e4c83de0a98b50fc0acf26cb4344.diff LOG: [OpenMP] supporting additional case of declare target initializer expression list Added: Modified: clang/lib/Sema/SemaOpenMP.cpp clang/test/OpenMP/declare_target_variables_ast_print.cpp Removed: diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index 3482cafbc74aa1..404b21559559f1 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -23257,6 +23257,10 @@ void Sema::ActOnOpenMPDeclareTargetName(NamedDecl *ND, SourceLocation Loc, if (ASTMutationListener *ML = Context.getASTMutationListener()) ML->DeclarationMarkedOpenMPDeclareTarget(ND, A); checkDeclIsAllowedInOpenMPTarget(nullptr, ND, Loc); + if (auto *VD = dyn_cast(ND); + LangOpts.OpenMP && VD && VD->hasAttr() && + VD->hasGlobalStorage()) +ActOnOpenMPDeclareTargetInitializer(ND); } static void checkDeclInTargetContext(SourceLocation SL, SourceRange SR, diff --git a/clang/test/OpenMP/declare_target_variables_ast_print.cpp b/clang/test/OpenMP/declare_target_variables_ast_print.cpp index 1e37efe20989c7..cd5dfea56f8f35 100644 --- a/clang/test/OpenMP/declare_target_variables_ast_print.cpp +++ b/clang/test/OpenMP/declare_target_variables_ast_print.cpp @@ -27,6 +27,10 @@ struct target{ }; static target S; +static int var3 = 100; +static int *ptr_3 = &var3; +static char c = 'a'; + #pragma omp declare target int target_var = variable; float target_var1 = variable2; @@ -36,6 +40,9 @@ int (**ptr3)[2] = &arrptr; declare **obj3 = &obj2; target *S1 = &S; #pragma omp end declare target +#pragma omp declare target(ptr_3) +#pragma omp declare target to(c) + // CHECK: #pragma omp declare target // CHECK-NEXT: static int variable = 100; // CHECK-NEXT: #pragma omp end declare target @@ -87,7 +94,15 @@ target *S1 = &S; // CHECK-NEXT: #pragma omp declare target // CHECK-NEXT: static target S; // CHECK-NEXT: #pragma omp end declare target - +// CHECK-NEXT: #pragma omp declare target +// CHECK-NEXT: static int var3 = 100; +// CHECK-NEXT: #pragma omp end declare target +// CHECK-NEXT: #pragma omp declare target +// CHECK-NEXT: static int *ptr_3 = &var3; +// CHECK-NEXT: #pragma omp end declare target +// CHECK-NEXT: #pragma omp declare target +// CHECK-NEXT: static char c = 'a'; +// CHECK-NEXT: #pragma omp end declare target // CHECK-NEXT: #pragma omp declare target // CHECK-NEXT: int target_var = variable; // CHECK-NEXT: #pragma omp end declare target ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 08bbff4 - [OpenMP] Codegen support for thread_limit on target directive for host
Author: Sandeep Kosuri Date: 2023-08-26T22:18:49-05:00 New Revision: 08bbff4aad57c70a38d5d2680a61901977e66637 URL: https://github.com/llvm/llvm-project/commit/08bbff4aad57c70a38d5d2680a61901977e66637 DIFF: https://github.com/llvm/llvm-project/commit/08bbff4aad57c70a38d5d2680a61901977e66637.diff LOG: [OpenMP] Codegen support for thread_limit on target directive for host offloading - This patch adds support for thread_limit clause on target directive according to OpenMP 51 [2.14.5] - The idea is to create an outer task for target region, when there is a thread_limit clause, and manipulate the thread_limit of task instead. This way, thread_limit will be applied to all the relevant constructs enclosed by the target region. Differential Revision: https://reviews.llvm.org/D152054 Added: clang/test/OpenMP/target_parallel_for_simd_tl_codegen.cpp clang/test/OpenMP/target_parallel_for_tl_codegen.cpp clang/test/OpenMP/target_parallel_generic_loop_tl_codegen.cpp clang/test/OpenMP/target_parallel_tl_codegen.cpp clang/test/OpenMP/target_simd_tl_codegen.cpp openmp/runtime/test/target/target_thread_limit.cpp Modified: clang/include/clang/Basic/OpenMPKinds.h clang/lib/Basic/OpenMPKinds.cpp clang/lib/CodeGen/CGOpenMPRuntime.cpp clang/lib/CodeGen/CGOpenMPRuntime.h clang/lib/CodeGen/CGStmtOpenMP.cpp clang/lib/Sema/SemaOpenMP.cpp clang/test/OpenMP/target_codegen.cpp llvm/include/llvm/Frontend/OpenMP/OMP.td llvm/include/llvm/Frontend/OpenMP/OMPKinds.def openmp/runtime/src/kmp.h openmp/runtime/src/kmp_csupport.cpp openmp/runtime/src/kmp_ftn_entry.h openmp/runtime/src/kmp_global.cpp openmp/runtime/src/kmp_runtime.cpp Removed: diff --git a/clang/include/clang/Basic/OpenMPKinds.h b/clang/include/clang/Basic/OpenMPKinds.h index f5fc7a8ce5bb3c..ac1b3cdfff145b 100644 --- a/clang/include/clang/Basic/OpenMPKinds.h +++ b/clang/include/clang/Basic/OpenMPKinds.h @@ -356,6 +356,13 @@ void getOpenMPCaptureRegions( /// \return true - if the above condition is met for this directive /// otherwise - false. bool isOpenMPCombinedParallelADirective(OpenMPDirectiveKind DKind); + +/// Checks if the specified target directive, combined or not, needs task based +/// thread_limit +/// \param DKind Specified directive. +/// \return true - if the above condition is met for this directive +/// otherwise - false. +bool needsTaskBasedThreadLimit(OpenMPDirectiveKind DKind); } #endif diff --git a/clang/lib/Basic/OpenMPKinds.cpp b/clang/lib/Basic/OpenMPKinds.cpp index a679f2ecf0e2b5..86de067da134a0 100644 --- a/clang/lib/Basic/OpenMPKinds.cpp +++ b/clang/lib/Basic/OpenMPKinds.cpp @@ -748,6 +748,13 @@ bool clang::isOpenMPCombinedParallelADirective(OpenMPDirectiveKind DKind) { DKind == OMPD_parallel_sections; } +bool clang::needsTaskBasedThreadLimit(OpenMPDirectiveKind DKind) { + return DKind == OMPD_target || DKind == OMPD_target_parallel || + DKind == OMPD_target_parallel_for || + DKind == OMPD_target_parallel_for_simd || DKind == OMPD_target_simd || + DKind == OMPD_target_parallel_loop; +} + void clang::getOpenMPCaptureRegions( SmallVectorImpl &CaptureRegions, OpenMPDirectiveKind DKind) { diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp index 5d947a2c0943a1..253ef8b75163ec 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -9681,9 +9681,13 @@ void CGOpenMPRuntime::emitTargetCall( assert((OffloadingMandatory || OutlinedFn) && "Invalid outlined function!"); - const bool RequiresOuterTask = D.hasClausesOfKind() || - D.hasClausesOfKind() || - D.hasClausesOfKind(); + const bool RequiresOuterTask = + D.hasClausesOfKind() || + D.hasClausesOfKind() || + D.hasClausesOfKind() || + (CGM.getLangOpts().OpenMP >= 51 && + needsTaskBasedThreadLimit(D.getDirectiveKind()) && + D.hasClausesOfKind()); llvm::SmallVector CapturedVars; const CapturedStmt &CS = *D.getCapturedStmt(OMPD_target); auto &&ArgsCodegen = [&CS, &CapturedVars](CodeGenFunction &CGF, @@ -10235,6 +10239,24 @@ void CGOpenMPRuntime::emitNumTeamsClause(CodeGenFunction &CGF, PushNumTeamsArgs); } +void CGOpenMPRuntime::emitThreadLimitClause(CodeGenFunction &CGF, +const Expr *ThreadLimit, +SourceLocation Loc) { + llvm::Value *RTLoc = emitUpdateLocation(CGF, Loc); + llvm::Value *ThreadLimitVal = + ThreadLimit + ? CGF.Builder.CreateIntCast(CGF.EmitScalarExpr(ThreadLimit), + CGF.CGM.Int32Ty, /* isSigned = */ true) + : CGF.Builder.getInt32(0); + + // Build call __kmpc_set_thread_limit(&loc, global_tid,
[clang] 453e02c - [OpenMP] Add support for declare target initializer expressions
Author: Ritanya B Bharadwaj Date: 2023-06-01T05:27:23-05:00 New Revision: 453e02ca0903c9f65529d21c513925ab0fdea1e1 URL: https://github.com/llvm/llvm-project/commit/453e02ca0903c9f65529d21c513925ab0fdea1e1 DIFF: https://github.com/llvm/llvm-project/commit/453e02ca0903c9f65529d21c513925ab0fdea1e1.diff LOG: [OpenMP] Add support for declare target initializer expressions Initial support for OpenMP 5.0 declare target "as if" behavior for "initializer expressions". OpenMP 5.0, 2.12.7 declare target. Reviewed By: Alexey Differential Revision: https://reviews.llvm.org/D146418 Added: clang/test/OpenMP/declare_target_variables_ast_print.cpp Modified: clang/include/clang/Sema/Sema.h clang/lib/Sema/SemaDecl.cpp clang/lib/Sema/SemaOpenMP.cpp clang/test/OpenMP/declare_target_messages.cpp clang/test/OpenMP/nvptx_target_exceptions_messages.cpp Removed: diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index afbc895cfd28..d2cb0ef261fb 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -11324,6 +11324,11 @@ class Sema final { void checkDeclIsAllowedInOpenMPTarget(Expr *E, Decl *D, SourceLocation IdLoc = SourceLocation()); + + /// Adds OMPDeclareTargetDeclAttr to referenced variables in declare target + /// directive. + void ActOnOpenMPDeclareTargetInitializer(Decl *D); + /// Finishes analysis of the deferred functions calls that may be declared as /// host/nohost during device/host compilation. void finalizeOpenMPDelayedAnalysis(const FunctionDecl *Caller, diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index d7c595b4201f..b8aba816283d 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -14476,6 +14476,12 @@ Sema::DeclGroupPtrTy Sema::FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS, for (unsigned i = 0, e = Group.size(); i != e; ++i) { if (Decl *D = Group[i]) { + // Check if the Decl has been declared in '#pragma omp declare target' + // directive and has static storage duration. + if (auto *VD = dyn_cast(D); + LangOpts.OpenMP && VD && VD->hasAttr() && + VD->hasGlobalStorage()) +ActOnOpenMPDeclareTargetInitializer(D); // For declarators, there are some additional syntactic-ish checks we need // to perform. if (auto *DD = dyn_cast(D)) { diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index 45cbfa6eeff1..6e83e20d96d5 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -23100,6 +23100,55 @@ void Sema::checkDeclIsAllowedInOpenMPTarget(Expr *E, Decl *D, checkDeclInTargetContext(E->getExprLoc(), E->getSourceRange(), *this, D); } +/// This class visits every VarDecl that the initializer references and adds +/// OMPDeclareTargetDeclAttr to each of them. +class GlobalDeclRefChecker final +: public StmtVisitor { + SmallVector DeclVector; + Attr *A; + +public: + /// A StmtVisitor class function that visits all DeclRefExpr and adds + /// OMPDeclareTargetDeclAttr to them. + void VisitDeclRefExpr(DeclRefExpr *Node) { +if (auto *VD = dyn_cast(Node->getDecl())) { + VD->addAttr(A); + DeclVector.push_back(VD); +} + } + /// A function that iterates across each of the Expr's children. + void VisitExpr(Expr *Ex) { +for (auto *Child : Ex->children()) { + Visit(Child); +} + } + /// A function that keeps a record of all the Decls that are variables, has + /// OMPDeclareTargetDeclAttr, and has global storage in the DeclVector. Pop + /// each Decl one at a time and use the inherited 'visit' functions to look + /// for DeclRefExpr. + void declareTargetInitializer(Decl *TD) { +A = TD->getAttr(); +DeclVector.push_back(cast(TD)); +while (!DeclVector.empty()) { + VarDecl *TargetVarDecl = DeclVector.pop_back_val(); + if (TargetVarDecl->hasAttr() && + TargetVarDecl->hasInit() && TargetVarDecl->hasGlobalStorage()) { +if (Expr *Ex = TargetVarDecl->getInit()) + Visit(Ex); + } +} + } +}; + +/// Adding OMPDeclareTargetDeclAttr to variables with static storage +/// duration that are referenced in the initializer expression list of +/// variables with static storage duration in declare target directive. +void Sema::ActOnOpenMPDeclareTargetInitializer(Decl *TargetDecl) { + GlobalDeclRefChecker Checker; + if (auto *TargetVarDecl = dyn_cast_or_null(TargetDecl)) +Checker.declareTargetInitializer(TargetDecl); +} + OMPClause *Sema::ActOnOpenMPToClause( ArrayRef MotionModifiers, ArrayRef MotionModifiersLoc, diff --git a/clang/test/OpenMP/declare_target_messages.cpp b/clang/test/OpenMP/declare_target_messages.cpp index ed011a8c3a59..482d3dc8cff3 100644 --- a/clang/test/OpenMP/declare_target_messages.cpp +++ b/cla
[clang] f4ef084 - [OPENMP][NFC] added loop bind to the support page
Author: Sandeep Kosuri Date: 2023-02-10T02:33:44-06:00 New Revision: f4ef08433fe78c31493688f5ab608b2f9689f478 URL: https://github.com/llvm/llvm-project/commit/f4ef08433fe78c31493688f5ab608b2f9689f478 DIFF: https://github.com/llvm/llvm-project/commit/f4ef08433fe78c31493688f5ab608b2f9689f478.diff LOG: [OPENMP][NFC] added loop bind to the support page Added: Modified: clang/docs/OpenMPSupport.rst Removed: diff --git a/clang/docs/OpenMPSupport.rst b/clang/docs/OpenMPSupport.rst index 16cb50afa1a13..f1f0f85bacde6 100644 --- a/clang/docs/OpenMPSupport.rst +++ b/clang/docs/OpenMPSupport.rst @@ -122,6 +122,8 @@ implementation. +--+--+--+---+ | loop | #pragma omp loop (directive) | :part:`worked on`| | +--+--+--+---+ +| loop | #pragma omp loop bind | :part:`worked on`| | ++--+--+--+---+ | loop | collapse imperfectly nested loop | :good:`done` | | +--+--+--+---+ | loop | collapse non-rectangular nested loop | :good:`done` | | ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Notifying assume directive as 'worked on'. (PR #90022)
https://github.com/sandeepkosuri closed https://github.com/llvm/llvm-project/pull/90022 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Emitting a warning if optimizations are enabled with sanitizers (PR #95934)
@@ -1038,3 +1038,10 @@ // RUN: not %clang --target=aarch64-none-elf -fsanitize=dataflow %s -### 2>&1 | FileCheck %s -check-prefix=UNSUPPORTED-BAREMETAL // RUN: not %clang --target=arm-arm-none-eabi -fsanitize=shadow-call-stack %s -### 2>&1 | FileCheck %s -check-prefix=UNSUPPORTED-BAREMETAL // UNSUPPORTED-BAREMETAL: unsupported option '-fsanitize={{.*}}' for target + +// RUN: %clang -O0 -O1 -fsanitize=address %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-SAN-OPT-WARN +// RUN: %clang -Ofast -fsanitize=address %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-SAN-OPT-WARN +// RUN: %clang -O3 -fsanitize=address %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-SAN-OPT-WARN +// RUN: %clang -O2 -fsanitize=thread %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-SAN-OPT-WARN +// RUN: %clang -O1 -fsanitize=thread %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-SAN-OPT-WARN +// CHECK-SAN-OPT-WARN: warning: enabling optimizations with sanitizers may potentially reduce effectiveness sandeepkosuri wrote: ```suggestion // CHECK-SAN-OPT-WARN: warning: enabling optimizations may reduce the effectiveness of sanitizers ``` https://github.com/llvm/llvm-project/pull/95934 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Emitting a warning if optimizations are enabled with sanitizers (PR #95934)
@@ -477,6 +477,8 @@ def warn_drv_disabling_vptr_no_rtti_default : Warning< def warn_drv_object_size_disabled_O0 : Warning< "the object size sanitizer has no effect at -O0, but is explicitly enabled: %0">, InGroup, DefaultWarnNoWerror; +def warn_sanitizer_with_optimization : Warning< + "enabling optimizations with sanitizers may potentially reduce effectiveness">; sandeepkosuri wrote: ```suggestion "enabling optimizations may reduce the effectiveness of sanitizers">; ``` https://github.com/llvm/llvm-project/pull/95934 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits