33
33
#include " mlir/Conversion/OpenMPToLLVM/ConvertOpenMPToLLVM.h"
34
34
#include " mlir/Conversion/ReconcileUnrealizedCasts/ReconcileUnrealizedCasts.h"
35
35
#include " mlir/Conversion/VectorToLLVM/ConvertVectorToLLVM.h"
36
+ #include " mlir/Dialect/Arith/IR/Arith.h"
36
37
#include " mlir/Dialect/LLVMIR/LLVMDialect.h"
37
38
#include " mlir/Dialect/LLVMIR/Transforms/AddComdats.h"
38
39
#include " mlir/Dialect/OpenACC/OpenACC.h"
44
45
#include " mlir/Target/LLVMIR/ModuleTranslation.h"
45
46
#include " llvm/ADT/ArrayRef.h"
46
47
#include " llvm/ADT/TypeSwitch.h"
48
+ #include < mlir/Dialect/LLVMIR/LLVMAttrs.h>
47
49
48
50
namespace fir {
49
51
#define GEN_PASS_DEF_FIRTOLLVMLOWERING
@@ -3496,12 +3498,20 @@ struct AbsentOpConversion : public FIROpConversion<fir::AbsentOp> {
3496
3498
// Primitive operations on Complex types
3497
3499
//
3498
3500
3501
+ template <typename OPTY>
3502
+ static inline mlir::LLVM::FastmathFlagsAttr getLLVMFMFAttr (OPTY op) {
3503
+ return mlir::LLVM::FastmathFlagsAttr::get (
3504
+ op.getContext (),
3505
+ mlir::arith::convertArithFastMathFlagsToLLVM (op.getFastmath ()));
3506
+ }
3507
+
3499
3508
// / Generate inline code for complex addition/subtraction
3500
3509
template <typename LLVMOP, typename OPTY>
3501
3510
static mlir::LLVM::InsertValueOp
3502
3511
complexSum (OPTY sumop, mlir::ValueRange opnds,
3503
3512
mlir::ConversionPatternRewriter &rewriter,
3504
3513
const fir::LLVMTypeConverter &lowering) {
3514
+ mlir::LLVM::FastmathFlagsAttr fmf = getLLVMFMFAttr (sumop);
3505
3515
mlir::Value a = opnds[0 ];
3506
3516
mlir::Value b = opnds[1 ];
3507
3517
auto loc = sumop.getLoc ();
@@ -3511,8 +3521,8 @@ complexSum(OPTY sumop, mlir::ValueRange opnds,
3511
3521
auto y0 = rewriter.create <mlir::LLVM::ExtractValueOp>(loc, a, 1 );
3512
3522
auto x1 = rewriter.create <mlir::LLVM::ExtractValueOp>(loc, b, 0 );
3513
3523
auto y1 = rewriter.create <mlir::LLVM::ExtractValueOp>(loc, b, 1 );
3514
- auto rx = rewriter.create <LLVMOP>(loc, eleTy, x0, x1);
3515
- auto ry = rewriter.create <LLVMOP>(loc, eleTy, y0, y1);
3524
+ auto rx = rewriter.create <LLVMOP>(loc, eleTy, x0, x1, fmf );
3525
+ auto ry = rewriter.create <LLVMOP>(loc, eleTy, y0, y1, fmf );
3516
3526
auto r0 = rewriter.create <mlir::LLVM::UndefOp>(loc, ty);
3517
3527
auto r1 = rewriter.create <mlir::LLVM::InsertValueOp>(loc, r0, rx, 0 );
3518
3528
return rewriter.create <mlir::LLVM::InsertValueOp>(loc, r1, ry, 1 );
@@ -3560,6 +3570,7 @@ struct MulcOpConversion : public FIROpConversion<fir::MulcOp> {
3560
3570
// TODO: Can we use a call to __muldc3 ?
3561
3571
// given: (x + iy) * (x' + iy')
3562
3572
// result: (xx'-yy')+i(xy'+yx')
3573
+ mlir::LLVM::FastmathFlagsAttr fmf = getLLVMFMFAttr (mulc);
3563
3574
mlir::Value a = adaptor.getOperands ()[0 ];
3564
3575
mlir::Value b = adaptor.getOperands ()[1 ];
3565
3576
auto loc = mulc.getLoc ();
@@ -3569,12 +3580,12 @@ struct MulcOpConversion : public FIROpConversion<fir::MulcOp> {
3569
3580
auto y0 = rewriter.create <mlir::LLVM::ExtractValueOp>(loc, a, 1 );
3570
3581
auto x1 = rewriter.create <mlir::LLVM::ExtractValueOp>(loc, b, 0 );
3571
3582
auto y1 = rewriter.create <mlir::LLVM::ExtractValueOp>(loc, b, 1 );
3572
- auto xx = rewriter.create <mlir::LLVM::FMulOp>(loc, eleTy, x0, x1);
3573
- auto yx = rewriter.create <mlir::LLVM::FMulOp>(loc, eleTy, y0, x1);
3574
- auto xy = rewriter.create <mlir::LLVM::FMulOp>(loc, eleTy, x0, y1);
3575
- auto ri = rewriter.create <mlir::LLVM::FAddOp>(loc, eleTy, xy, yx);
3576
- auto yy = rewriter.create <mlir::LLVM::FMulOp>(loc, eleTy, y0, y1);
3577
- auto rr = rewriter.create <mlir::LLVM::FSubOp>(loc, eleTy, xx, yy);
3583
+ auto xx = rewriter.create <mlir::LLVM::FMulOp>(loc, eleTy, x0, x1, fmf );
3584
+ auto yx = rewriter.create <mlir::LLVM::FMulOp>(loc, eleTy, y0, x1, fmf );
3585
+ auto xy = rewriter.create <mlir::LLVM::FMulOp>(loc, eleTy, x0, y1, fmf );
3586
+ auto ri = rewriter.create <mlir::LLVM::FAddOp>(loc, eleTy, xy, yx, fmf );
3587
+ auto yy = rewriter.create <mlir::LLVM::FMulOp>(loc, eleTy, y0, y1, fmf );
3588
+ auto rr = rewriter.create <mlir::LLVM::FSubOp>(loc, eleTy, xx, yy, fmf );
3578
3589
auto ra = rewriter.create <mlir::LLVM::UndefOp>(loc, ty);
3579
3590
auto r1 = rewriter.create <mlir::LLVM::InsertValueOp>(loc, ra, rr, 0 );
3580
3591
auto r0 = rewriter.create <mlir::LLVM::InsertValueOp>(loc, r1, ri, 1 );
@@ -3594,6 +3605,7 @@ struct DivcOpConversion : public FIROpConversion<fir::DivcOp> {
3594
3605
// Just generate inline code for now.
3595
3606
// given: (x + iy) / (x' + iy')
3596
3607
// result: ((xx'+yy')/d) + i((yx'-xy')/d) where d = x'x' + y'y'
3608
+ mlir::LLVM::FastmathFlagsAttr fmf = getLLVMFMFAttr (divc);
3597
3609
mlir::Value a = adaptor.getOperands ()[0 ];
3598
3610
mlir::Value b = adaptor.getOperands ()[1 ];
3599
3611
auto loc = divc.getLoc ();
@@ -3603,17 +3615,17 @@ struct DivcOpConversion : public FIROpConversion<fir::DivcOp> {
3603
3615
auto y0 = rewriter.create <mlir::LLVM::ExtractValueOp>(loc, a, 1 );
3604
3616
auto x1 = rewriter.create <mlir::LLVM::ExtractValueOp>(loc, b, 0 );
3605
3617
auto y1 = rewriter.create <mlir::LLVM::ExtractValueOp>(loc, b, 1 );
3606
- auto xx = rewriter.create <mlir::LLVM::FMulOp>(loc, eleTy, x0, x1);
3607
- auto x1x1 = rewriter.create <mlir::LLVM::FMulOp>(loc, eleTy, x1, x1);
3608
- auto yx = rewriter.create <mlir::LLVM::FMulOp>(loc, eleTy, y0, x1);
3609
- auto xy = rewriter.create <mlir::LLVM::FMulOp>(loc, eleTy, x0, y1);
3610
- auto yy = rewriter.create <mlir::LLVM::FMulOp>(loc, eleTy, y0, y1);
3611
- auto y1y1 = rewriter.create <mlir::LLVM::FMulOp>(loc, eleTy, y1, y1);
3612
- auto d = rewriter.create <mlir::LLVM::FAddOp>(loc, eleTy, x1x1, y1y1);
3613
- auto rrn = rewriter.create <mlir::LLVM::FAddOp>(loc, eleTy, xx, yy);
3614
- auto rin = rewriter.create <mlir::LLVM::FSubOp>(loc, eleTy, yx, xy);
3615
- auto rr = rewriter.create <mlir::LLVM::FDivOp>(loc, eleTy, rrn, d);
3616
- auto ri = rewriter.create <mlir::LLVM::FDivOp>(loc, eleTy, rin, d);
3618
+ auto xx = rewriter.create <mlir::LLVM::FMulOp>(loc, eleTy, x0, x1, fmf );
3619
+ auto x1x1 = rewriter.create <mlir::LLVM::FMulOp>(loc, eleTy, x1, x1, fmf );
3620
+ auto yx = rewriter.create <mlir::LLVM::FMulOp>(loc, eleTy, y0, x1, fmf );
3621
+ auto xy = rewriter.create <mlir::LLVM::FMulOp>(loc, eleTy, x0, y1, fmf );
3622
+ auto yy = rewriter.create <mlir::LLVM::FMulOp>(loc, eleTy, y0, y1, fmf );
3623
+ auto y1y1 = rewriter.create <mlir::LLVM::FMulOp>(loc, eleTy, y1, y1, fmf );
3624
+ auto d = rewriter.create <mlir::LLVM::FAddOp>(loc, eleTy, x1x1, y1y1, fmf );
3625
+ auto rrn = rewriter.create <mlir::LLVM::FAddOp>(loc, eleTy, xx, yy, fmf );
3626
+ auto rin = rewriter.create <mlir::LLVM::FSubOp>(loc, eleTy, yx, xy, fmf );
3627
+ auto rr = rewriter.create <mlir::LLVM::FDivOp>(loc, eleTy, rrn, d, fmf );
3628
+ auto ri = rewriter.create <mlir::LLVM::FDivOp>(loc, eleTy, rin, d, fmf );
3617
3629
auto ra = rewriter.create <mlir::LLVM::UndefOp>(loc, ty);
3618
3630
auto r1 = rewriter.create <mlir::LLVM::InsertValueOp>(loc, ra, rr, 0 );
3619
3631
auto r0 = rewriter.create <mlir::LLVM::InsertValueOp>(loc, r1, ri, 1 );
0 commit comments