[Openmp-commits] [clang] [flang] [llvm] [openmp] [Clang][OpenMP][LoopTransformations] Add support for "#pragma omp fuse" loop transformation directive and "looprange" clause (PR #139293)
Alexey Bataev via Openmp-commits
openmp-commits at lists.llvm.org
Mon Aug 11 06:56:30 PDT 2025
Roger Ferrer =?utf-8?q?Ibáñez?= <rofirrim at gmail.com>,Roger Ferrer
Ibanez <roger.ferrer at bsc.es>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/139293 at github.com>
================
@@ -14206,10 +14211,48 @@ StmtResult SemaOpenMP::ActOnOpenMPTargetTeamsDistributeSimdDirective(
getASTContext(), StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B);
}
+/// Overloaded base case function
+template <typename T, typename F> static bool tryHandleAs(T *, F &&) {
+ return false;
+}
+
+/// Tries to recursively cast `Type` to one of the given types and invokes
+/// `Func` if successful.
+///
+/// \tparam Class The first type to check.
+/// \tparam Rest The remaining types to check.
+/// \tparam T The base type of `Type`.
+/// \tparam F The callable type for the function to invoke upon a successful
+/// cast.
+/// \param Type The object to be checked.
+/// \param Func The function to invoke if `Type` matches `Class`.
+/// \return `true` if `Type` matched any type and `Func` was called, otherwise
+/// `false`.
+template <typename Class, typename... Rest, typename T, typename F>
+static bool tryHandleAs(T *Type, F &&Func) {
+ if (Class *C = dyn_cast<Class>(Type)) {
+ Func(C);
+ return true;
+ }
+ return tryHandleAs<Rest...>(Type, std::forward<F>(Func));
+}
+
+/// Updates OriginalInits by checking Transform against loop transformation
+/// directives and appending their pre-inits if a match is found.
+static void updatePreInits(OMPLoopBasedDirective *Transform,
+ SmallVectorImpl<Stmt *> &PreInits) {
+ if (!tryHandleAs<OMPTileDirective, OMPUnrollDirective, OMPReverseDirective,
+ OMPInterchangeDirective, OMPFuseDirective>(
+ Transform, [&PreInits](auto *Dir) {
+ appendFlattenedStmtList(PreInits, Dir->getPreInits());
+ }))
+ llvm_unreachable("Unhandled loop transformation");
+}
+
----------------
alexey-bataev wrote:
Better to add and start using in a separate patch
https://github.com/llvm/llvm-project/pull/139293
More information about the Openmp-commits
mailing list