1 //===-- Optimizer/Support/Utils.h -------------------------------*- 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_SUPPORT_UTILS_H
14 #define FORTRAN_OPTIMIZER_SUPPORT_UTILS_H
15 
16 #include "mlir/Dialect/StandardOps/IR/Ops.h"
17 #include "mlir/IR/BuiltinAttributes.h"
18 
19 namespace fir {
20 /// Return the integer value of a ConstantOp.
toInt(mlir::ConstantOp cop)21 inline std::int64_t toInt(mlir::ConstantOp cop) {
22   return cop.getValue().cast<mlir::IntegerAttr>().getValue().getSExtValue();
23 }
24 } // namespace fir
25 
26 #endif // FORTRAN_OPTIMIZER_SUPPORT_UTILS_H
27