[Openmp-commits] [clang] [llvm] [openmp] [Clang][OpenMP] Add `#pragma omp flatten` loop directive + `depth` clause (PR #206977)
Alexey Bataev via Openmp-commits
openmp-commits at lists.llvm.org
Sun Aug 9 15:40:52 PDT 2026
================
@@ -1380,6 +1380,74 @@ class OMPPartialClause final : public OMPClause {
}
};
+/// This represents the 'depth' clause on the '#pragma omp flatten' (and
+/// '#pragma omp fuse') loop-transformation directives.
+///
+/// \code
+/// #pragma omp flatten depth(3)
+/// \endcode
+/// In this example the 'flatten' directive has a 'depth' clause whose argument
+/// '3' specifies how many perfectly nested loops are combined into one.
+/// The argument must be a positive integer constant expression that evaluates
+/// to at most the loop nest depth of the associated loop nest.
+class OMPDepthClause final : public OMPClause {
+ friend class OMPClauseReader;
+
+ /// Location of '('.
+ SourceLocation LParenLoc;
+
+ /// The depth expression (number of loops to flatten).
+ Stmt *Depth = nullptr;
+
+ /// Build an empty clause.
+ explicit OMPDepthClause() : OMPClause(llvm::omp::OMPC_depth, {}, {}) {}
+
+ /// Set the depth expression.
+ void setDepth(Expr *E) { Depth = E; }
+
+ /// Sets the location of '('.
+ void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
+
+public:
+ /// Build an AST node for a 'depth' clause.
+ ///
+ /// \param C Context of the AST.
+ /// \param StartLoc Location of the 'depth' identifier.
+ /// \param LParenLoc Location of '('.
+ /// \param EndLoc Location of ')'.
+ /// \param Depth The depth expression.
+ static OMPDepthClause *Create(const ASTContext &C, SourceLocation StartLoc,
+ SourceLocation LParenLoc, SourceLocation EndLoc,
+ Expr *Depth);
+
+ /// Build an empty 'depth' AST node for deserialization.
+ ///
+ /// \param C Context of the AST.
+ static OMPDepthClause *CreateEmpty(const ASTContext &C);
----------------
alexey-bataev wrote:
Usually, we declare this pseudo-constructors, if the default constructor does not work =, like if we have tail allocated elements. Otherwise, just regular constructors should be good enough
https://github.com/llvm/llvm-project/pull/206977
More information about the Openmp-commits
mailing list