[llvm-branch-commits] [flang] [mlir] [Flang][mlir][OpenMP] Support affinity clause codegen in Flang (PR #182222)

Tom Eccles via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Feb 23 03:52:04 PST 2026


================
@@ -202,6 +202,92 @@ getIfClauseOperand(lower::AbstractConverter &converter,
                                     ifVal);
 }
 
+template <typename IteratorSpecT>
+static IteratorRange lowerIteratorRange(
+    Fortran::lower::AbstractConverter &converter, const IteratorSpecT &itSpec,
+    Fortran::lower::StatementContext &stmtCtx, mlir::Location loc) {
+  auto &builder = converter.getFirOpBuilder();
+
+  const auto &ivObj = std::get<1>(itSpec.t);
+  const auto &range = std::get<2>(itSpec.t);
+
+  IteratorRange r;
+  r.ivSym = ivObj.sym();
+  assert(r.ivSym && "expected iterator induction symbol");
+
+  const auto &lbExpr = std::get<0>(range.t);
+  const auto &ubExpr = std::get<1>(range.t);
+  const auto &stExprOpt = std::get<2>(range.t);
+
+  mlir::Value lbVal =
+      fir::getBase(converter.genExprValue(toEvExpr(lbExpr), stmtCtx));
+  mlir::Value ubVal =
+      fir::getBase(converter.genExprValue(toEvExpr(ubExpr), stmtCtx));
+
+  auto toIndex = [](fir::FirOpBuilder &builder, mlir::Location loc,
+                    mlir::Value v) -> mlir::Value {
+    if (v.getType().isIndex())
+      return v;
+    return mlir::arith::IndexCastOp::create(builder, loc,
+                                            builder.getIndexType(), v);
----------------
tblah wrote:

In flang we usually use `fir.convert`. Sticking to the same conversion operation means that common utilities within flang all understand what the operation does. In this case that probably doesn't matter but I think it is more maintainable going into the future if everything follows the canonical pattern.

https://github.com/llvm/llvm-project/pull/182222


More information about the llvm-branch-commits mailing list