| //===-- FirBuilder.h -- FIR operation builder -------------------*- C++ -*-===// |
| // |
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| // See https://llvm.org/LICENSE.txt for license information. |
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| // |
| //===----------------------------------------------------------------------===// |
| // |
| // Builder routines for constructing the FIR dialect of MLIR. As FIR is a |
| // dialect of MLIR, it makes extensive use of MLIR interfaces and MLIR's coding |
| // style (https://mlir.llvm.org/getting_started/DeveloperGuide/) is used in this |
| // module. |
| // |
| //===----------------------------------------------------------------------===// |
| |
| #ifndef FORTRAN_OPTIMIZER_BUILDER_FIRBUILDER_H |
| #define FORTRAN_OPTIMIZER_BUILDER_FIRBUILDER_H |
| |
| #include "flang/Optimizer/Dialect/FIROps.h" |
| #include "flang/Optimizer/Dialect/FIRType.h" |
| #include "flang/Optimizer/Support/KindMapping.h" |
| #include "mlir/IR/Builders.h" |
| #include "mlir/IR/BuiltinOps.h" |
| |
| namespace fir { |
| |
| //===----------------------------------------------------------------------===// |
| // FirOpBuilder |
| //===----------------------------------------------------------------------===// |
| |
| /// Extends the MLIR OpBuilder to provide methods for building common FIR |
| /// patterns. |
| class FirOpBuilder : public mlir::OpBuilder { |
| public: |
| explicit FirOpBuilder(mlir::Operation *op, const fir::KindMapping &kindMap) |
| : OpBuilder{op}, kindMap{kindMap} {} |
| explicit FirOpBuilder(mlir::OpBuilder &builder, |
| const fir::KindMapping &kindMap) |
| : OpBuilder{builder}, kindMap{kindMap} {} |
| |
| /// Create an integer constant of type \p type and value \p i. |
| mlir::Value createIntegerConstant(mlir::Location loc, mlir::Type integerType, |
| std::int64_t i); |
| |
| /// Lazy creation of fir.convert op. |
| mlir::Value createConvert(mlir::Location loc, mlir::Type toTy, |
| mlir::Value val); |
| |
| /// Cast the input value to IndexType. |
| mlir::Value convertToIndexType(mlir::Location loc, mlir::Value val) { |
| return createConvert(loc, getIndexType(), val); |
| } |
| |
| private: |
| const KindMapping &kindMap; |
| }; |
| |
| } // namespace fir |
| |
| #endif // FORTRAN_OPTIMIZER_BUILDER_FIRBUILDER_H |