[flang-commits] [flang] [Flang] Add FIR and LLVM lowering support for prefetch directive (PR #167272)

via flang-commits flang-commits at lists.llvm.org
Wed Dec 17 01:56:04 PST 2025


================
@@ -3276,7 +3276,28 @@ class FirConverter : public Fortran::lower::AbstractConverter {
               attachInliningDirectiveToStmt(dir, &eval);
             },
             [&](const Fortran::parser::CompilerDirective::Prefetch &prefetch) {
-              TODO(getCurrentLocation(), "!$dir prefetch");
+              for (const auto &p : prefetch.v) {
+                Fortran::evaluate::ExpressionAnalyzer ea{
+                    bridge.getSemanticsContext()};
+                Fortran::lower::SomeExpr expr{*ea.Analyze(
+                    std::get<Fortran::parser::DataRef>(p.value().u))};
+                Fortran::lower::StatementContext stmtCtx;
+                mlir::Location loc = genLocation(dir.source);
+                mlir::Value memRef{Fortran::lower::convertExprToHLFIR(
+                                       loc, *this, expr, localSymbols, stmtCtx)
+                                       .getBase()};
+                if (mlir::isa<fir::BaseBoxType>(
+                        fir::unwrapRefType(memRef.getType()))) {
+                  memRef = fir::BoxAddrOp::create(
+                      *builder, loc, builder->loadIfRef(loc, memRef));
+                }
----------------
jeanPerier wrote:

```suggestion
hlfir::Entity var = Fortran::lower::convertExprToHLFIR(
                                       loc, *this, expr, localSymbols, stmtCtx);
mlir::Value memRef = hlfir::genVariableRawAddress(loc, *builder, var);
```

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


More information about the flang-commits mailing list