|
22 | 22 | #include "flang/Lower/IntrinsicCall.h"
|
23 | 23 | #include "flang/Lower/Runtime.h"
|
24 | 24 | #include "flang/Lower/Todo.h"
|
| 25 | +#include "flang/Optimizer/Dialect/FIRAttr.h" |
25 | 26 | #include "flang/Optimizer/Dialect/FIRDialect.h"
|
26 | 27 | #include "flang/Semantics/expression.h"
|
27 | 28 | #include "flang/Semantics/symbol.h"
|
@@ -152,16 +153,21 @@ class ExprLowering {
|
152 | 153 | mlir::Value genBoolConstant(mlir::MLIRContext *context, bool value) {
|
153 | 154 | auto i1Type = builder.getI1Type();
|
154 | 155 | auto attr = builder.getIntegerAttr(i1Type, value ? 1 : 0);
|
155 |
| - return builder.create<mlir::ConstantOp>(getLoc(), i1Type, attr).getResult(); |
| 156 | + return builder.create<mlir::ConstantOp>(getLoc(), i1Type, attr); |
156 | 157 | }
|
157 | 158 |
|
| 159 | + /// Generate a real constant with of `value`. |
158 | 160 | template <int KIND>
|
159 | 161 | mlir::Value genRealConstant(mlir::MLIRContext *context,
|
160 | 162 | const llvm::APFloat &value) {
|
161 | 163 | auto fltTy = Fortran::lower::convertReal(context, KIND);
|
162 |
| - auto attr = builder.getFloatAttr(fltTy, value); |
163 |
| - auto res = builder.create<mlir::ConstantOp>(getLoc(), fltTy, attr); |
164 |
| - return res.getResult(); |
| 164 | + if (fltTy.isa<mlir::FloatType>()) { |
| 165 | + auto attr = builder.getFloatAttr(fltTy, value); |
| 166 | + return builder.create<mlir::ConstantOp>(getLoc(), fltTy, attr); |
| 167 | + } |
| 168 | + // MLIR standard dialect doesn't support floating point larger than double. |
| 169 | + auto attr = fir::RealAttr::get(context, {KIND, value}); |
| 170 | + return builder.create<fir::ConstfOp>(getLoc(), fltTy, attr); |
165 | 171 | }
|
166 | 172 |
|
167 | 173 | mlir::Type getSomeKindInteger() { return builder.getIndexType(); }
|
|
0 commit comments