[clang] [llvm] [openmp] [CLANG][OpenMP] Restore loop variable values after transformation directives (PR #214717)
Alexey Bataev via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 27 07:12:26 PDT 2026
================
@@ -15705,6 +15726,29 @@ static Expr *makeFloorIVRef(Sema &SemaRef, ArrayRef<VarDecl *> FloorIndVars,
OrigCntVar->getExprLoc());
}
+/// Build loop variable finalization statement from HelperExprs.Finals.
+/// Returns a CompoundStmt containing all finalization statements, or nullptr
+/// if there are no finalization statements.
+/// Note: Loops with non-arithmetic loop variables (e.g., iterators) are skipped
+/// because finalization only applies to integer/floating-point counters.
+static Stmt *buildLoopFinalization(
+ ASTContext &Context,
+ ArrayRef<OMPLoopBasedDirective::HelperExprs> LoopHelpers) {
+ SmallVector<Stmt *, 8> FinalizationStmts;
+
+ for (size_t I : llvm::seq<size_t>(LoopHelpers.size())) {
+ for (auto *Final : LoopHelpers[I].Finals)
+ if (Final)
+ FinalizationStmts.push_back(Final);
----------------
alexey-bataev wrote:
```suggestion
FinalizationStmts.push_back(IfStmt::Create(
Context, SourceLocation(), IfStatementKind::Ordinary, nullptr,
nullptr, LoopHelpers[I].PreCond, SourceLocation(),
SourceLocation(), Final, SourceLocation(), nullptr));
```
https://github.com/llvm/llvm-project/pull/214717
More information about the llvm-commits
mailing list