1 //===-- 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 // Coding style: https://mlir.llvm.org/getting_started/DeveloperGuide/ 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef FORTRAN_OPTIMIZER_BUILDER_DOLOOPHELPER_H 14 #define FORTRAN_OPTIMIZER_BUILDER_DOLOOPHELPER_H 15 16 #include "flang/Optimizer/Builder/FIRBuilder.h" 17 18 namespace fir::factory { 19 20 /// Helper to build fir.do_loop Ops. 21 class DoLoopHelper { 22 public: DoLoopHelper(fir::FirOpBuilder & builder,mlir::Location loc)23 explicit DoLoopHelper(fir::FirOpBuilder &builder, mlir::Location loc) 24 : builder(builder), loc(loc) {} 25 DoLoopHelper(const DoLoopHelper &) = delete; 26 27 /// Type of a callback to generate the loop body. 28 using BodyGenerator = std::function<void(fir::FirOpBuilder &, mlir::Value)>; 29 30 /// Build loop [\p lb, \p ub] with step \p step. 31 /// If \p step is an empty value, 1 is used for the step. 32 fir::DoLoopOp createLoop(mlir::Value lb, mlir::Value ub, mlir::Value step, 33 const BodyGenerator &bodyGenerator); 34 35 /// Build loop [\p lb, \p ub] with step 1. 36 fir::DoLoopOp createLoop(mlir::Value lb, mlir::Value ub, 37 const BodyGenerator &bodyGenerator); 38 39 /// Build loop [0, \p count) with step 1. 40 fir::DoLoopOp createLoop(mlir::Value count, 41 const BodyGenerator &bodyGenerator); 42 43 private: 44 fir::FirOpBuilder &builder; 45 mlir::Location loc; 46 }; 47 48 } // namespace fir::factory 49 50 #endif // FORTRAN_OPTIMIZER_BUILDER_DOLOOPHELPER_H 51