1 //===-- Lower/DoLoopHelper.h -- gen fir.do_loop ops -------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef FORTRAN_LOWER_DOLOOPHELPER_H 10 #define FORTRAN_LOWER_DOLOOPHELPER_H 11 12 #include "flang/Lower/FIRBuilder.h" 13 14 namespace Fortran::lower { 15 16 /// Helper to build fir.do_loop Ops. 17 class DoLoopHelper { 18 public: DoLoopHelper(FirOpBuilder & builder,mlir::Location loc)19 explicit DoLoopHelper(FirOpBuilder &builder, mlir::Location loc) 20 : builder(builder), loc(loc) {} 21 DoLoopHelper(const DoLoopHelper &) = delete; 22 23 /// Type of a callback to generate the loop body. 24 using BodyGenerator = std::function<void(FirOpBuilder &, mlir::Value)>; 25 26 /// Build loop [\p lb, \p ub] with step \p step. 27 /// If \p step is an empty value, 1 is used for the step. 28 void createLoop(mlir::Value lb, mlir::Value ub, mlir::Value step, 29 const BodyGenerator &bodyGenerator); 30 31 /// Build loop [\p lb, \p ub] with step 1. 32 void createLoop(mlir::Value lb, mlir::Value ub, 33 const BodyGenerator &bodyGenerator); 34 35 /// Build loop [0, \p count) with step 1. 36 void createLoop(mlir::Value count, const BodyGenerator &bodyGenerator); 37 38 private: 39 FirOpBuilder &builder; 40 mlir::Location loc; 41 }; 42 43 } // namespace Fortran::lower 44 45 #endif // FORTRAN_LOWER_DOLOOPHELPER_H 46