-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[Clang][OpenMP][LoopTransformations] Add support for "#pragma omp fuse" loop transformation directive and "looprange" clause #139293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-clang-modules @llvm/pr-subscribers-clang Author: Walter J.T.V (eZWALT) ChangesThis pull request introduces full support for the #pragma omp fuse directive, as specified in the OpenMP 6.0 specification, along with initial support for the looprange clause in Clang. To enable this functionality, infrastructure for the Loop Sequence construct, also new in OpenMP 6.0, has been implemented. Additionally, a minimal code skeleton has been added to Flang to ensure compatibility and avoid integration issues, although a full implementation in Flang is still pending. https://www.openmp.org/wp-content/uploads/OpenMP-API-Specification-6-0.pdf P.S. As a follow-up to this loop transformation work, I'm currently preparing a patch that implements the "#pragma omp split" directive, also introduced in OpenMP 6.0. Patch is 277.11 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/139293.diff 47 Files Affected:
diff --git a/clang/docs/OpenMPSupport.rst b/clang/docs/OpenMPSupport.rst
index d6507071d4693..b39f9d3634a63 100644
--- a/clang/docs/OpenMPSupport.rst
+++ b/clang/docs/OpenMPSupport.rst
@@ -376,6 +376,8 @@ implementation.
+-------------------------------------------------------------+---------------------------+---------------------------+--------------------------------------------------------------------------+
| loop stripe transformation | :good:`done` | https://github.com/llvm/llvm-project/pull/119891 |
+-------------------------------------------------------------+---------------------------+---------------------------+--------------------------------------------------------------------------+
+| loop fuse transformation | :good:`prototyped` | :none:`unclaimed` | |
++-------------------------------------------------------------+---------------------------+---------------------------+--------------------------------------------------------------------------+
| work distribute construct | :none:`unclaimed` | :none:`unclaimed` | |
+-------------------------------------------------------------+---------------------------+---------------------------+--------------------------------------------------------------------------+
| task_iteration | :none:`unclaimed` | :none:`unclaimed` | |
diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index d30d15e53802a..00046de62a742 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -2162,6 +2162,10 @@ enum CXCursorKind {
*/
CXCursor_OMPStripeDirective = 310,
+ /** OpenMP fuse directive
+ */
+ CXCursor_OMPFuseDirective = 318,
+
/** OpenACC Compute Construct.
*/
CXCursor_OpenACCComputeConstruct = 320,
diff --git a/clang/include/clang/AST/OpenMPClause.h b/clang/include/clang/AST/OpenMPClause.h
index 757873fd6d414..9adf41aee6f1c 100644
--- a/clang/include/clang/AST/OpenMPClause.h
+++ b/clang/include/clang/AST/OpenMPClause.h
@@ -1151,6 +1151,106 @@ 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 {
+ friend class OMPClauseReader;
+
+ explicit OMPLoopRangeClause()
+ : OMPClause(llvm::omp::OMPC_looprange, {}, {}) {}
+
+ /// Location of '('
+ SourceLocation LParenLoc;
+
+ /// Location of 'first'
+ SourceLocation FirstLoc;
+
+ /// Location of 'count'
+ SourceLocation CountLoc;
+
+ /// Expr associated with 'first' argument
+ Expr *First = nullptr;
+
+ /// Expr associated with 'count' argument
+ Expr *Count = nullptr;
+
+ /// Set 'first'
+ void setFirst(Expr *First) { this->First = First; }
+
+ /// Set 'count'
+ void setCount(Expr *Count) { this->Count = Count; }
+
+ /// Set location of '('.
+ void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
+
+ /// Set location of 'first' argument
+ void setFirstLoc(SourceLocation Loc) { FirstLoc = Loc; }
+
+ /// Set location of 'count' argument
+ void setCountLoc(SourceLocation Loc) { CountLoc = Loc; }
+
+public:
+ /// Build an AST node for a 'looprange' clause
+ ///
+ /// \param StartLoc Starting location of the clause.
+ /// \param LParenLoc Location of '('.
+ /// \param ModifierLoc Modifier location.
+ /// \param
+ static OMPLoopRangeClause *
+ Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
+ SourceLocation FirstLoc, SourceLocation CountLoc,
+ SourceLocation EndLoc, Expr *First, Expr *Count);
+
+ /// Build an empty 'looprange' node for deserialization
+ ///
+ /// \param C Context of the AST.
+ static OMPLoopRangeClause *CreateEmpty(const ASTContext &C);
+
+ /// Returns the location of '('
+ SourceLocation getLParenLoc() const { return LParenLoc; }
+
+ /// Returns the location of 'first'
+ SourceLocation getFirstLoc() const { return FirstLoc; }
+
+ /// Returns the location of 'count'
+ SourceLocation getCountLoc() const { return CountLoc; }
+
+ /// Returns the argument 'first' or nullptr if not set
+ Expr *getFirst() const { return cast_or_null<Expr>(First); }
+
+ /// Returns the argument 'count' or nullptr if not set
+ Expr *getCount() const { return cast_or_null<Expr>(Count); }
+
+ child_range children() {
+ return child_range(reinterpret_cast<Stmt **>(&First),
+ reinterpret_cast<Stmt **>(&Count) + 1);
+ }
+
+ const_child_range children() const {
+ auto Children = const_cast<OMPLoopRangeClause *>(this)->children();
+ return const_child_range(Children.begin(), Children.end());
+ }
+
+ 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_looprange;
+ }
+};
+
/// Representation of the 'partial' clause of the '#pragma omp unroll'
/// directive.
///
diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h b/clang/include/clang/AST/RecursiveASTVisitor.h
index 3edc8684d0a19..fbc93796ab46a 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -3078,6 +3078,9 @@ DEF_TRAVERSE_STMT(OMPUnrollDirective,
DEF_TRAVERSE_STMT(OMPReverseDirective,
{ TRY_TO(TraverseOMPExecutableDirective(S)); })
+DEF_TRAVERSE_STMT(OMPFuseDirective,
+ { TRY_TO(TraverseOMPExecutableDirective(S)); })
+
DEF_TRAVERSE_STMT(OMPInterchangeDirective,
{ TRY_TO(TraverseOMPExecutableDirective(S)); })
@@ -3395,6 +3398,14 @@ bool RecursiveASTVisitor<Derived>::VisitOMPFullClause(OMPFullClause *C) {
return true;
}
+template <typename Derived>
+bool RecursiveASTVisitor<Derived>::VisitOMPLoopRangeClause(
+ OMPLoopRangeClause *C) {
+ TRY_TO(TraverseStmt(C->getFirst()));
+ TRY_TO(TraverseStmt(C->getCount()));
+ return true;
+}
+
template <typename Derived>
bool RecursiveASTVisitor<Derived>::VisitOMPPartialClause(OMPPartialClause *C) {
TRY_TO(TraverseStmt(C->getFactor()));
diff --git a/clang/include/clang/AST/StmtOpenMP.h b/clang/include/clang/AST/StmtOpenMP.h
index 736bcabbad1f7..b6a948a8c6020 100644
--- a/clang/include/clang/AST/StmtOpenMP.h
+++ b/clang/include/clang/AST/StmtOpenMP.h
@@ -962,6 +962,9 @@ class OMPLoopTransformationDirective : public OMPLoopBasedDirective {
/// Number of loops generated by this loop transformation.
unsigned NumGeneratedLoops = 0;
+ /// Number of top level canonical loop nests generated by this loop
+ /// transformation
+ unsigned NumGeneratedLoopNests = 0;
protected:
explicit OMPLoopTransformationDirective(StmtClass SC,
@@ -973,6 +976,9 @@ class OMPLoopTransformationDirective : public OMPLoopBasedDirective {
/// Set the number of loops generated by this loop transformation.
void setNumGeneratedLoops(unsigned Num) { NumGeneratedLoops = Num; }
+ /// Set the number of top level canonical loop nests generated by this loop
+ /// transformation
+ void setNumGeneratedLoopNests(unsigned Num) { NumGeneratedLoopNests = Num; }
public:
/// Return the number of associated (consumed) loops.
@@ -981,6 +987,10 @@ class OMPLoopTransformationDirective : public OMPLoopBasedDirective {
/// Return the number of loops generated by this loop transformation.
unsigned getNumGeneratedLoops() const { return NumGeneratedLoops; }
+ /// Return the number of top level canonical loop nests generated by this loop
+ /// transformation
+ unsigned getNumGeneratedLoopNests() const { return NumGeneratedLoopNests; }
+
/// Get the de-sugared statements after the loop transformation.
///
/// Might be nullptr if either the directive generates no loops and is handled
@@ -995,7 +1005,7 @@ class OMPLoopTransformationDirective : public OMPLoopBasedDirective {
Stmt::StmtClass C = T->getStmtClass();
return C == OMPTileDirectiveClass || C == OMPUnrollDirectiveClass ||
C == OMPReverseDirectiveClass || C == OMPInterchangeDirectiveClass ||
- C == OMPStripeDirectiveClass;
+ C == OMPStripeDirectiveClass || C == OMPFuseDirectiveClass;
}
};
@@ -5561,7 +5571,10 @@ class OMPTileDirective final : public OMPLoopTransformationDirective {
: OMPLoopTransformationDirective(OMPTileDirectiveClass,
llvm::omp::OMPD_tile, StartLoc, EndLoc,
NumLoops) {
+ // Tiling doubles the original number of loops
setNumGeneratedLoops(2 * NumLoops);
+ // Produces a single top-level canonical loop nest
+ setNumGeneratedLoopNests(1);
}
void setPreInits(Stmt *PreInits) {
@@ -5639,6 +5652,8 @@ class OMPStripeDirective final : public OMPLoopTransformationDirective {
llvm::omp::OMPD_stripe, StartLoc, EndLoc,
NumLoops) {
setNumGeneratedLoops(2 * NumLoops);
+ // Similar to Tile, it only generates a single top level loop nest
+ setNumGeneratedLoopNests(1);
}
void setPreInits(Stmt *PreInits) {
@@ -5790,7 +5805,11 @@ class OMPReverseDirective final : public OMPLoopTransformationDirective {
explicit OMPReverseDirective(SourceLocation StartLoc, SourceLocation EndLoc)
: OMPLoopTransformationDirective(OMPReverseDirectiveClass,
llvm::omp::OMPD_reverse, StartLoc,
- EndLoc, 1) {}
+ EndLoc, 1) {
+ // Reverse produces a single top-level canonical loop nest
+ setNumGeneratedLoops(1);
+ setNumGeneratedLoopNests(1);
+ }
void setPreInits(Stmt *PreInits) {
Data->getChildren()[PreInitsOffset] = PreInits;
@@ -5857,7 +5876,10 @@ class OMPInterchangeDirective final : public OMPLoopTransformationDirective {
: OMPLoopTransformationDirective(OMPInterchangeDirectiveClass,
llvm::omp::OMPD_interchange, StartLoc,
EndLoc, NumLoops) {
- setNumGeneratedLoops(3 * NumLoops);
+ // Interchange produces a single top-level canonical loop
+ // nest, with the exact same amount of total loops
+ setNumGeneratedLoops(NumLoops);
+ setNumGeneratedLoopNests(1);
}
void setPreInits(Stmt *PreInits) {
@@ -5908,6 +5930,86 @@ class OMPInterchangeDirective final : public OMPLoopTransformationDirective {
}
};
+/// Represents the '#pragma omp fuse' loop transformation directive
+///
+/// \code{c}
+/// #pragma omp fuse
+/// {
+/// for(int i = 0; i < m1; ++i) {...}
+/// for(int j = 0; j < m2; ++j) {...}
+/// ...
+/// }
+/// \endcode
+
+class OMPFuseDirective final : public OMPLoopTransformationDirective {
+ friend class ASTStmtReader;
+ friend class OMPExecutableDirective;
+
+ // Offsets of child members.
+ enum {
+ PreInitsOffset = 0,
+ TransformedStmtOffset,
+ };
+
+ explicit OMPFuseDirective(SourceLocation StartLoc, SourceLocation EndLoc,
+ unsigned NumLoops)
+ : OMPLoopTransformationDirective(OMPFuseDirectiveClass,
+ llvm::omp::OMPD_fuse, StartLoc, EndLoc,
+ NumLoops) {}
+
+ void setPreInits(Stmt *PreInits) {
+ Data->getChildren()[PreInitsOffset] = PreInits;
+ }
+
+ void setTransformedStmt(Stmt *S) {
+ Data->getChildren()[TransformedStmtOffset] = S;
+ }
+
+public:
+ /// Create a new AST node representation for #pragma omp fuse'
+ ///
+ /// \param C Context of the AST
+ /// \param StartLoc Location of the introducer (e.g the 'omp' token)
+ /// \param EndLoc Location of the directive's end (e.g the tok::eod)
+ /// \param Clauses The directive's clauses
+ /// \param NumLoops Number of total affected loops
+ /// \param NumLoopNests Number of affected top level canonical loops
+ /// (number of items in the 'looprange' clause if present)
+ /// \param AssociatedStmt The outermost associated loop
+ /// \param TransformedStmt The loop nest after fusion, or nullptr in
+ /// dependent
+ /// \param PreInits Helper preinits statements for the loop nest
+ static OMPFuseDirective *Create(const ASTContext &C, SourceLocation StartLoc,
+ SourceLocation EndLoc,
+ ArrayRef<OMPClause *> Clauses,
+ unsigned NumLoops, unsigned NumLoopNests,
+ Stmt *AssociatedStmt, Stmt *TransformedStmt,
+ Stmt *PreInits);
+
+ /// Build an empty '#pragma omp fuse' AST node for deserialization
+ ///
+ /// \param C Context of the AST
+ /// \param NumClauses Number of clauses to allocate
+ /// \param NumLoops Number of associated loops to allocate
+ /// \param NumLoopNests Number of top level loops to allocate
+ static OMPFuseDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses,
+ unsigned NumLoops,
+ unsigned NumLoopNests);
+
+ /// Gets the associated loops after the transformation. This is the de-sugared
+ /// replacement or nulltpr in dependent contexts.
+ Stmt *getTransformedStmt() const {
+ return Data->getChildren()[TransformedStmtOffset];
+ }
+
+ /// Return preinits statement.
+ Stmt *getPreInits() const { return Data->getChildren()[PreInitsOffset]; }
+
+ static bool classof(const Stmt *T) {
+ return T->getStmtClass() == OMPFuseDirectiveClass;
+ }
+};
+
/// This represents '#pragma omp scan' directive.
///
/// \code
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index e1b9ed0647bb9..94d1f3c3e6349 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11516,6 +11516,21 @@ def note_omp_implicit_dsa : Note<
"implicitly determined as %0">;
def err_omp_loop_var_dsa : Error<
"loop iteration variable in the associated loop of 'omp %1' directive may not be %0, predetermined as %2">;
+def warn_omp_different_loop_ind_var_types : Warning <
+ "loop sequence following '#pragma omp %0' contains induction variables of differing types: %1 and %2">,
+ InGroup<OpenMPLoopForm>;
+def err_omp_not_canonical_loop : Error <
+ "loop after '#pragma omp %0' is not in canonical form">;
+def err_omp_not_a_loop_sequence : Error <
+ "statement after '#pragma omp %0' must be a loop sequence containing canonical loops or loop-generating constructs">;
+def err_omp_empty_loop_sequence : Error <
+ "loop sequence after '#pragma omp %0' must contain at least 1 canonical loop or loop-generating construct">;
+def err_omp_invalid_looprange : Error <
+ "loop range in '#pragma omp %0' exceeds the number of available loops: "
+ "range end '%1' is greater than the total number of loops '%2'">;
+def warn_omp_redundant_fusion : Warning <
+ "loop range in '#pragma omp %0' contains only a single loop, resulting in redundant fusion">,
+ InGroup<OpenMPClauses>;
def err_omp_not_for : Error<
"%select{statement after '#pragma omp %1' must be a for loop|"
"expected %2 for loops after '#pragma omp %1'%select{|, but found only %4}3}0">;
diff --git a/clang/include/clang/Basic/StmtNodes.td b/clang/include/clang/Basic/StmtNodes.td
index 9526fa5808aa5..739160342062c 100644
--- a/clang/include/clang/Basic/StmtNodes.td
+++ b/clang/include/clang/Basic/StmtNodes.td
@@ -234,6 +234,7 @@ def OMPStripeDirective : StmtNode<OMPLoopTransformationDirective>;
def OMPUnrollDirective : StmtNode<OMPLoopTransformationDirective>;
def OMPReverseDirective : StmtNode<OMPLoopTransformationDirective>;
def OMPInterchangeDirective : StmtNode<OMPLoopTransformationDirective>;
+def OMPFuseDirective : StmtNode<OMPLoopTransformationDirective>;
def OMPForDirective : StmtNode<OMPLoopDirective>;
def OMPForSimdDirective : StmtNode<OMPLoopDirective>;
def OMPSectionsDirective : StmtNode<OMPExecutableDirective>;
diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h
index e0b8850493b49..0c4c4fc4ba417 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -3622,6 +3622,9 @@ class Parser : public CodeCompletionHandler {
OpenMPClauseKind Kind,
bool ParseOnly);
+ /// Parses the 'looprange' clause of a '#pragma omp fuse' directive.
+ OMPClause *ParseOpenMPLoopRangeClause();
+
/// Parses the 'sizes' clause of a '#pragma omp tile' directive.
OMPClause *ParseOpenMPSizesClause();
diff --git a/clang/include/clang/Sema/SemaOpenMP.h b/clang/include/clang/Sema/SemaOpenMP.h
index 6498390fe96f7..ac4cbe3709a0d 100644
--- a/clang/include/clang/Sema/SemaOpenMP.h
+++ b/clang/include/clang/Sema/SemaOpenMP.h
@@ -457,6 +457,13 @@ class SemaOpenMP : public SemaBase {
Stmt *AStmt,
SourceLocation StartLoc,
SourceLocation EndLoc);
+
+ /// Called on well-formed '#pragma omp fuse' after parsing of its
+ /// clauses and the associated statement.
+ StmtResult ActOnOpenMPFuseDirective(ArrayRef<OMPClause *> Clauses,
+ Stmt *AStmt, SourceLocation StartLoc,
+ SourceLocation EndLoc);
+
/// Called on well-formed '\#pragma omp for' after parsing
/// of the associated statement.
StmtResult
@@ -914,6 +921,12 @@ class SemaOpenMP : public SemaBase {
SourceLocation StartLoc,
SourceLocation LParenLoc,
SourceLocation EndLoc);
+
+ /// Called on well-form 'looprange' clause after parsing its arguments.
+ OMPClause *
+ ActOnOpenMPLoopRangeClause(Expr *First, Expr *Count, SourceLocation StartLoc,
+ SourceLocation LParenLoc, SourceLocation FirstLoc,
+ SourceLocation CountLoc, SourceLocation EndLoc);
/// Called on well-formed 'ordered' clause.
OMPClause *
ActOnOpenMPOrderedClause(SourceLocation StartLoc, SourceLocation EndLoc,
@@ -1480,6 +1493,108 @@ class SemaOpenMP : public SemaBase {
SmallVectorImpl<OMPLoopBasedDirective::HelperExprs> &LoopHelpers,
Stmt *&Body, SmallVectorImpl<SmallVector<Stmt *, 0>> &OriginalInits);
+ /// @brief Categories of loops encountered during semantic OpenMP loop
+ /// analysis
+ ///
+ /// This enumeration identifies the structural category of a loop or sequence
+ /// of loops analyzed in the context of OpenMP transformations and directives.
+ /// This categorization helps differentiate between original source loops
+ /// and the structures resulting from applying OpenMP loop transformations.
+ enum class OMPLoopCategory {
+
+ /// @var OMPLoopCategory::RegularLoop
+ /// Represents a standard canonical loop nest found in the
+ /// original source code or an intact loop after transformations
+ /// (i.e Post/Pre loops of a loopranged fusion)
+ RegularLoop,
+
+ /// @var OMPLoopCategory::TransformSingleLoop
+ /// Represents the resulting loop structure when an OpenMP loop
+ // transformation, generates a single, top-level loop
+ TransformSingleLoop,
+
+ /// @var OMPLoopCategory::TransformLoopSequence
+ /// Represents the resulting loop structure when an OpenMP loop
+ /// transformation
+ /// generates a ...
[truncated]
|
return child_range(reinterpret_cast<Stmt **>(&First), | ||
reinterpret_cast<Stmt **>(&Count) + 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not work safely, to do this safely you need to store both associated expressions in a single array
EndLoc, 1) {} | ||
EndLoc, 1) { | ||
// Reverse produces a single top-level canonical loop nest | ||
setNumGeneratedLoops(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be in a separate patch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okey do i make another pull request just for the loop corrections though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
@@ -962,6 +962,9 @@ class OMPLoopTransformationDirective : public OMPLoopBasedDirective { | |||
|
|||
/// Number of loops generated by this loop transformation. | |||
unsigned NumGeneratedLoops = 0; | |||
/// Number of top level canonical loop nests generated by this loop | |||
/// transformation | |||
unsigned NumGeneratedLoopNests = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need this new field?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the name is a bit unfortunate and could be improved, but they are 2 completely different fields conceptually. This top level loops are the ones actually managed by loop Sequence constructs like fuse and the upcoming split. A loop sequence contains loops which may contain several inner nestes loops, but these should not be taken into account for performing fusion or splitting. This was not taken into account originally due to all transformations having a fixed number of generated top level nests (1). However fuse or split may generate several loop nests with inner nested loops.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that unroll is an exception, it could have 0 or 1 but it coincides perfectly with the original number of loops .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The question is how it is used. I did not see it is being read anywhere
setNumGeneratedLoops(3 * NumLoops); | ||
// Interchange produces a single top-level canonical loop | ||
// nest, with the exact same amount of total loops | ||
setNumGeneratedLoops(NumLoops); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Separate patch
@@ -11516,6 +11516,21 @@ def note_omp_implicit_dsa : Note< | |||
"implicitly determined as %0">; | |||
def err_omp_loop_var_dsa : Error< | |||
"loop iteration variable in the associated loop of 'omp %1' directive may not be %0, predetermined as %2">; | |||
def warn_omp_different_loop_ind_var_types : Warning < | |||
"loop sequence following '#pragma omp %0' contains induction variables of differing types: %1 and %2">, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought that the number of iterations should be the limitation here, not the type of indices
if (!AStmt) { | ||
return StmtError(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!AStmt) { | |
return StmtError(); | |
} | |
if (!AStmt) | |
return StmtError(); |
LoopCategories, Context)) { | ||
return StmtError(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LoopCategories, Context)) { | |
return StmtError(); | |
} | |
LoopCategories, Context)) | |
return StmtError(); |
[&SemaRef = this->SemaRef, &Context, &CopyTransformer, | ||
&IVType](Expr *ExprToCopy, const std::string &BaseName, unsigned I, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[&SemaRef = this->SemaRef, &Context, &CopyTransformer, | |
&IVType](Expr *ExprToCopy, const std::string &BaseName, unsigned I, | |
[&, &SemaRef = SemaRef](Expr *ExprToCopy, const std::string &BaseName, unsigned I, |
if (!LTPreInits.empty()) { | ||
llvm::append_range(PreInits, LTPreInits); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!LTPreInits.empty()) { | |
llvm::append_range(PreInits, LTPreInits); | |
} | |
if (!LTPreInits.empty()) | |
llvm::append_range(PreInits, LTPreInits); |
if (!TransformPreInit.empty()) { | ||
llvm::append_range(PreInits, TransformPreInit); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!TransformPreInit.empty()) { | |
llvm::append_range(PreInits, TransformPreInit); | |
} | |
if (!TransformPreInit.empty()) | |
llvm::append_range(PreInits, TransformPreInit); |
I want to notify that the following week I won't be available due to some circumstances, so expect this patch to be updated on the 20th of May. Thanks for the feedback @alexey-bataev |
This pull request introduces full support for the #pragma omp fuse directive, as specified in the OpenMP 6.0 specification, along with initial support for the looprange clause in Clang.
To enable this functionality, infrastructure for the Loop Sequence construct, also new in OpenMP 6.0, has been implemented. Additionally, a minimal code skeleton has been added to Flang to ensure compatibility and avoid integration issues, although a full implementation in Flang is still pending.
https://www.openmp.org/wp-content/uploads/OpenMP-API-Specification-6-0.pdf
@alexey-bataev @Meinersbur
P.S. As a follow-up to this loop transformation work, I'm currently preparing a patch that implements the "#pragma omp split" directive, also introduced in OpenMP 6.0.