Commit 347f3c18 authored by alokmishra.besu's avatar alokmishra.besu Committed by cchen
Browse files

OpenMP 5.0 metadirective

This patch supports OpenMP 5.0 metadirective features.
It is implemented keeping the OpenMP 5.1 features like dynamic user condition in mind.

A new function, getBestWhenMatchForContext, is defined in llvm/Frontend/OpenMP/OMPContext.h

Currently this function return the index of the when clause with the highest score from the ones applicable in the Context.
But this function is declared with an array which can be used in OpenMP 5.1 implementation to select all the valid when clauses which can be resolved in runtime. Currently this array is set to null by default and its implementation is left for future.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D91944
parent 7efb8253
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -2592,7 +2592,11 @@ enum CXCursorKind {
   */
  CXCursor_OMPUnrollDirective = 293,

  CXCursor_LastStmt = CXCursor_OMPUnrollDirective,
  /** OpenMP metadirective directive.
   */
  CXCursor_OMPMetaDirective = 294,

  CXCursor_LastStmt = CXCursor_OMPMetaDirective,

  /**
   * Cursor that represents the translation unit itself.
+3 −0
Original line number Diff line number Diff line
@@ -2842,6 +2842,9 @@ RecursiveASTVisitor<Derived>::TraverseOMPLoopDirective(OMPLoopDirective *S) {
  return TraverseOMPExecutableDirective(S);
}

DEF_TRAVERSE_STMT(OMPMetaDirective,
                  { TRY_TO(TraverseOMPExecutableDirective(S)); })

DEF_TRAVERSE_STMT(OMPParallelDirective,
                  { TRY_TO(TraverseOMPExecutableDirective(S)); })

+38 −0
Original line number Diff line number Diff line
@@ -5379,6 +5379,44 @@ public:
  }
};

/// This represents '#pragma omp metadirective' directive.
///
/// \code
/// #pragma omp metadirective when(user={condition(N>10)}: parallel for)
/// \endcode
/// In this example directive '#pragma omp metadirective' has clauses 'when'
/// with a dynamic user condition to check if a variable 'N > 10'
///
class OMPMetaDirective final : public OMPExecutableDirective {
  friend class ASTStmtReader;
  friend class OMPExecutableDirective;
  Stmt *IfStmt;

  OMPMetaDirective(SourceLocation StartLoc, SourceLocation EndLoc)
      : OMPExecutableDirective(OMPMetaDirectiveClass,
                               llvm::omp::OMPD_metadirective, StartLoc,
                               EndLoc) {}
  explicit OMPMetaDirective()
      : OMPExecutableDirective(OMPMetaDirectiveClass,
                               llvm::omp::OMPD_metadirective, SourceLocation(),
                               SourceLocation()) {}

  void setIfStmt(Stmt *S) { IfStmt = S; }

public:
  static OMPMetaDirective *Create(const ASTContext &C, SourceLocation StartLoc,
                                  SourceLocation EndLoc,
                                  ArrayRef<OMPClause *> Clauses,
                                  Stmt *AssociatedStmt, Stmt *IfStmt);
  static OMPMetaDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses,
                                       EmptyShell);
  Stmt *getIfStmt() const { return IfStmt; }

  static bool classof(const Stmt *T) {
    return T->getStmtClass() == OMPMetaDirectiveClass;
  }
};

} // end namespace clang

#endif
+3 −0
Original line number Diff line number Diff line
@@ -1436,6 +1436,9 @@ def warn_omp51_compat_attributes : Warning<
  "specifying OpenMP directives with [[]] is incompatible with OpenMP "
  "standards before OpenMP 5.1">,
  InGroup<OpenMPPre51Compat>, DefaultIgnore;
def err_omp_expected_colon : Error<"missing ':' in %0">;
def err_omp_expected_context_selector
    : Error<"expected valid context selector in %0">;

// Pragma loop support.
def err_pragma_loop_missing_argument : Error<
+2 −0
Original line number Diff line number Diff line
@@ -10794,6 +10794,8 @@ def err_omp_dispatch_statement_call
def err_omp_unroll_full_variable_trip_count : Error<
  "loop to be fully unrolled must have a constant trip count">;
def note_omp_directive_here : Note<"'%0' directive found here">;
def err_omp_instantiation_not_supported
    : Error<"instantiation of '%0' not supported yet">;
} // end of OpenMP category
let CategoryName = "Related Result Type Issue" in {
Loading