@@ -35,6 +35,8 @@ using namespace mlir;
35
35
// / constants and returns std::nullopt on overflow.
36
36
using ConstArithFn =
37
37
function_ref<std::optional<APInt>(const APInt &, const APInt &)>;
38
+ using ConstArithStdFn =
39
+ std::function<std::optional<APInt>(const APInt &, const APInt &)>;
38
40
39
41
// / Compute op(minLeft, minRight) and op(maxLeft, maxRight) if possible,
40
42
// / If either computation overflows, make the result unbounded.
@@ -182,16 +184,16 @@ mlir::intrange::inferAdd(ArrayRef<ConstantIntRanges> argRanges,
182
184
OverflowFlags ovfFlags) {
183
185
const ConstantIntRanges &lhs = argRanges[0 ], &rhs = argRanges[1 ];
184
186
185
- std::function uadd = [=](const APInt &a,
186
- const APInt &b) -> std::optional<APInt> {
187
+ ConstArithStdFn uadd = [=](const APInt &a,
188
+ const APInt &b) -> std::optional<APInt> {
187
189
bool overflowed = false ;
188
190
APInt result = any (ovfFlags & OverflowFlags::Nuw)
189
191
? a.uadd_sat (b)
190
192
: a.uadd_ov (b, overflowed);
191
193
return overflowed ? std::optional<APInt>() : result;
192
194
};
193
- std::function sadd = [=](const APInt &a,
194
- const APInt &b) -> std::optional<APInt> {
195
+ ConstArithStdFn sadd = [=](const APInt &a,
196
+ const APInt &b) -> std::optional<APInt> {
195
197
bool overflowed = false ;
196
198
APInt result = any (ovfFlags & OverflowFlags::Nsw)
197
199
? a.sadd_sat (b)
@@ -215,16 +217,16 @@ mlir::intrange::inferSub(ArrayRef<ConstantIntRanges> argRanges,
215
217
OverflowFlags ovfFlags) {
216
218
const ConstantIntRanges &lhs = argRanges[0 ], &rhs = argRanges[1 ];
217
219
218
- std::function usub = [=](const APInt &a,
219
- const APInt &b) -> std::optional<APInt> {
220
+ ConstArithStdFn usub = [=](const APInt &a,
221
+ const APInt &b) -> std::optional<APInt> {
220
222
bool overflowed = false ;
221
223
APInt result = any (ovfFlags & OverflowFlags::Nuw)
222
224
? a.usub_sat (b)
223
225
: a.usub_ov (b, overflowed);
224
226
return overflowed ? std::optional<APInt>() : result;
225
227
};
226
- std::function ssub = [=](const APInt &a,
227
- const APInt &b) -> std::optional<APInt> {
228
+ ConstArithStdFn ssub = [=](const APInt &a,
229
+ const APInt &b) -> std::optional<APInt> {
228
230
bool overflowed = false ;
229
231
APInt result = any (ovfFlags & OverflowFlags::Nsw)
230
232
? a.ssub_sat (b)
@@ -247,16 +249,16 @@ mlir::intrange::inferMul(ArrayRef<ConstantIntRanges> argRanges,
247
249
OverflowFlags ovfFlags) {
248
250
const ConstantIntRanges &lhs = argRanges[0 ], &rhs = argRanges[1 ];
249
251
250
- std::function umul = [=](const APInt &a,
251
- const APInt &b) -> std::optional<APInt> {
252
+ ConstArithStdFn umul = [=](const APInt &a,
253
+ const APInt &b) -> std::optional<APInt> {
252
254
bool overflowed = false ;
253
255
APInt result = any (ovfFlags & OverflowFlags::Nuw)
254
256
? a.umul_sat (b)
255
257
: a.umul_ov (b, overflowed);
256
258
return overflowed ? std::optional<APInt>() : result;
257
259
};
258
- std::function smul = [=](const APInt &a,
259
- const APInt &b) -> std::optional<APInt> {
260
+ ConstArithStdFn smul = [=](const APInt &a,
261
+ const APInt &b) -> std::optional<APInt> {
260
262
bool overflowed = false ;
261
263
APInt result = any (ovfFlags & OverflowFlags::Nsw)
262
264
? a.smul_sat (b)
@@ -565,16 +567,16 @@ mlir::intrange::inferShl(ArrayRef<ConstantIntRanges> argRanges,
565
567
566
568
// The signed/unsigned overflow behavior of shl by `rhs` matches a mul with
567
569
// 2^rhs.
568
- std::function ushl = [=](const APInt &l,
569
- const APInt &r) -> std::optional<APInt> {
570
+ ConstArithStdFn ushl = [=](const APInt &l,
571
+ const APInt &r) -> std::optional<APInt> {
570
572
bool overflowed = false ;
571
573
APInt result = any (ovfFlags & OverflowFlags::Nuw)
572
574
? l.ushl_sat (r)
573
575
: l.ushl_ov (r, overflowed);
574
576
return overflowed ? std::optional<APInt>() : result;
575
577
};
576
- std::function sshl = [=](const APInt &l,
577
- const APInt &r) -> std::optional<APInt> {
578
+ ConstArithStdFn sshl = [=](const APInt &l,
579
+ const APInt &r) -> std::optional<APInt> {
578
580
bool overflowed = false ;
579
581
APInt result = any (ovfFlags & OverflowFlags::Nsw)
580
582
? l.sshl_sat (r)
0 commit comments