@@ -58,63 +58,57 @@ void ConvertComplexPowPass::runOnOperation() {
58
58
ModuleOp mod = getOperation ();
59
59
fir::FirOpBuilder builder (mod, fir::getKindMapping (mod));
60
60
61
- mod.walk ([&](complex ::PowOp op) {
61
+ mod.walk ([&](complex ::PowiOp op) {
62
62
builder.setInsertionPoint (op);
63
63
Location loc = op.getLoc ();
64
64
auto complexTy = cast<ComplexType>(op.getType ());
65
65
auto elemTy = complexTy.getElementType ();
66
-
67
66
Value base = op.getLhs ();
68
- Value rhs = op.getRhs ();
69
-
70
- Value intExp;
71
- if (auto create = rhs.getDefiningOp <complex ::CreateOp>()) {
72
- if (isZero (create.getImaginary ())) {
73
- if (auto conv = create.getReal ().getDefiningOp <fir::ConvertOp>()) {
74
- if (auto intTy = dyn_cast<IntegerType>(conv.getValue ().getType ()))
75
- intExp = conv.getValue ();
76
- }
77
- }
78
- }
79
-
67
+ Value intExp = op.getRhs ();
80
68
func::FuncOp callee;
81
- SmallVector<Value> args;
82
- if (intExp) {
83
- unsigned realBits = cast<FloatType>(elemTy).getWidth ();
84
- unsigned intBits = cast<IntegerType>(intExp.getType ()).getWidth ();
85
- auto funcTy = builder.getFunctionType (
86
- {complexTy, builder.getIntegerType (intBits)}, {complexTy});
87
- if (realBits == 32 && intBits == 32 )
88
- callee = getOrDeclare (builder, loc, RTNAME_STRING (cpowi), funcTy);
89
- else if (realBits == 32 && intBits == 64 )
90
- callee = getOrDeclare (builder, loc, RTNAME_STRING (cpowk), funcTy);
91
- else if (realBits == 64 && intBits == 32 )
92
- callee = getOrDeclare (builder, loc, RTNAME_STRING (zpowi), funcTy);
93
- else if (realBits == 64 && intBits == 64 )
94
- callee = getOrDeclare (builder, loc, RTNAME_STRING (zpowk), funcTy);
95
- else if (realBits == 128 && intBits == 32 )
96
- callee = getOrDeclare (builder, loc, RTNAME_STRING (cqpowi), funcTy);
97
- else if (realBits == 128 && intBits == 64 )
98
- callee = getOrDeclare (builder, loc, RTNAME_STRING (cqpowk), funcTy);
99
- else
100
- return ;
101
- args = {base, intExp};
102
- } else {
103
- unsigned realBits = cast<FloatType>(elemTy).getWidth ();
104
- auto funcTy =
105
- builder.getFunctionType ({complexTy, complexTy}, {complexTy});
106
- if (realBits == 32 )
107
- callee = getOrDeclare (builder, loc, " cpowf" , funcTy);
108
- else if (realBits == 64 )
109
- callee = getOrDeclare (builder, loc, " cpow" , funcTy);
110
- else if (realBits == 128 )
111
- callee = getOrDeclare (builder, loc, RTNAME_STRING (CPowF128), funcTy);
112
- else
113
- return ;
114
- args = {base, rhs};
115
- }
69
+ unsigned realBits = cast<FloatType>(elemTy).getWidth ();
70
+ unsigned intBits = cast<IntegerType>(intExp.getType ()).getWidth ();
71
+ auto funcTy = builder.getFunctionType (
72
+ {complexTy, builder.getIntegerType (intBits)}, {complexTy});
73
+ if (realBits == 32 && intBits == 32 )
74
+ callee = getOrDeclare (builder, loc, RTNAME_STRING (cpowi), funcTy);
75
+ else if (realBits == 32 && intBits == 64 )
76
+ callee = getOrDeclare (builder, loc, RTNAME_STRING (cpowk), funcTy);
77
+ else if (realBits == 64 && intBits == 32 )
78
+ callee = getOrDeclare (builder, loc, RTNAME_STRING (zpowi), funcTy);
79
+ else if (realBits == 64 && intBits == 64 )
80
+ callee = getOrDeclare (builder, loc, RTNAME_STRING (zpowk), funcTy);
81
+ else if (realBits == 128 && intBits == 32 )
82
+ callee = getOrDeclare (builder, loc, RTNAME_STRING (cqpowi), funcTy);
83
+ else if (realBits == 128 && intBits == 64 )
84
+ callee = getOrDeclare (builder, loc, RTNAME_STRING (cqpowk), funcTy);
85
+ else
86
+ return ;
87
+ auto call = fir::CallOp::create (builder, loc, callee, {base, intExp});
88
+ if (auto fmf = op.getFastmathAttr ())
89
+ call.setFastmathAttr (fmf);
90
+ op.replaceAllUsesWith (call.getResult (0 ));
91
+ op.erase ();
92
+ });
116
93
117
- auto call = fir::CallOp::create (builder, loc, callee, args);
94
+ mod.walk ([&](complex ::PowOp op) {
95
+ builder.setInsertionPoint (op);
96
+ Location loc = op.getLoc ();
97
+ auto complexTy = cast<ComplexType>(op.getType ());
98
+ auto elemTy = complexTy.getElementType ();
99
+ unsigned realBits = cast<FloatType>(elemTy).getWidth ();
100
+ func::FuncOp callee;
101
+ auto funcTy = builder.getFunctionType ({complexTy, complexTy}, {complexTy});
102
+ if (realBits == 32 )
103
+ callee = getOrDeclare (builder, loc, " cpowf" , funcTy);
104
+ else if (realBits == 64 )
105
+ callee = getOrDeclare (builder, loc, " cpow" , funcTy);
106
+ else if (realBits == 128 )
107
+ callee = getOrDeclare (builder, loc, RTNAME_STRING (CPowF128), funcTy);
108
+ else
109
+ return ;
110
+ auto call =
111
+ fir::CallOp::create (builder, loc, callee, {op.getLhs (), op.getRhs ()});
118
112
if (auto fmf = op.getFastmathAttr ())
119
113
call.setFastmathAttr (fmf);
120
114
op.replaceAllUsesWith (call.getResult (0 ));
0 commit comments