[clang] [flang] [llvm] [openmp] [Clang][OpenMP][LoopTransformations] Add support for "#pragma omp fuse" loop transformation directive and "looprange" clause (PR #139293)
Alexey Bataev via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 20 11:19:10 PDT 2025
================
@@ -1143,6 +1143,101 @@ class OMPFullClause final : public OMPNoChildClause<llvm::omp::OMPC_full> {
static OMPFullClause *CreateEmpty(const ASTContext &C);
};
+/// This class represents the 'looprange' clause in the
+/// '#pragma omp fuse' directive
+///
+/// \code {c}
+/// #pragma omp fuse looprange(1,2)
+/// {
+/// for(int i = 0; i < 64; ++i)
+/// for(int j = 0; j < 256; j+=2)
+/// for(int k = 127; k >= 0; --k)
+/// \endcode
+class OMPLoopRangeClause final
+ : public OMPClause,
+ private llvm::TrailingObjects<OMPLoopRangeClause, Expr *> {
+ friend class OMPClauseReader;
+ friend class llvm::TrailingObjects<OMPLoopRangeClause, Expr *>;
+
+ /// Location of '('
+ SourceLocation LParenLoc;
+
+ /// Location of first and count expressions
+ SourceLocation FirstLoc, CountLoc;
+
+ /// Number of looprange arguments (always 2: first, count)
+ unsigned NumArgs = 2;
+
+ /// Set the argument expressions.
+ void setArgs(ArrayRef<Expr *> Args) {
+ assert(Args.size() == NumArgs && "Expected exactly 2 looprange arguments");
+ std::copy(Args.begin(), Args.end(), getTrailingObjects<Expr *>());
+ }
+
+ /// Build an empty clause for deserialization.
+ explicit OMPLoopRangeClause()
+ : OMPClause(llvm::omp::OMPC_looprange, {}, {}), NumArgs(2) {}
+
+public:
+ /// Build a 'looprange' clause AST node.
+ static OMPLoopRangeClause *
+ Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
+ SourceLocation FirstLoc, SourceLocation CountLoc,
+ SourceLocation EndLoc, ArrayRef<Expr *> Args);
+
+ /// Build an empty 'looprange' clause node.
+ static OMPLoopRangeClause *CreateEmpty(const ASTContext &C);
+
+ // Location getters/setters
+ SourceLocation getLParenLoc() const { return LParenLoc; }
+ SourceLocation getFirstLoc() const { return FirstLoc; }
+ SourceLocation getCountLoc() const { return CountLoc; }
+
+ void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
+ void setFirstLoc(SourceLocation Loc) { FirstLoc = Loc; }
+ void setCountLoc(SourceLocation Loc) { CountLoc = Loc; }
+
+ /// Get looprange 'first' expression
+ Expr *getFirst() const { return getArgs()[0]; }
+
+ /// Get looprange 'count' expression
+ Expr *getCount() const { return getArgs()[1]; }
+
+ /// Set looprange 'first' expression
+ void setFirst(Expr *E) { getArgs()[0] = E; }
+
+ /// Set looprange 'count' expression
+ void setCount(Expr *E) { getArgs()[1] = E; }
+
----------------
alexey-bataev wrote:
These functions should be private
https://github.com/llvm/llvm-project/pull/139293
More information about the llvm-commits
mailing list