36
36
using namespace mlir ;
37
37
using namespace mlir ::dataflow;
38
38
39
+ namespace {
40
+
41
+ OptionalIntRanges getOptionalRange (const IntegerValueRange &range) {
42
+ if (range.isUninitialized ())
43
+ return std::nullopt;
44
+ return range.getValue ();
45
+ }
46
+
47
+ OptionalIntRanges getOptionalRangeFromLattice (const IntegerValueRangeLattice* lattice) {
48
+ return getOptionalRange (lattice->getValue ());
49
+ }
50
+
51
+ } // end namespace
52
+
39
53
IntegerValueRange IntegerValueRange::getMaxRange (Value value) {
40
54
unsigned width = ConstantIntRanges::getStorageBitwidth (value.getType ());
55
+ if (width == 0 )
56
+ return {};
57
+
41
58
APInt umin = APInt::getMinValue (width);
42
59
APInt umax = APInt::getMaxValue (width);
43
60
APInt smin = width != 0 ? APInt::getSignedMinValue (width) : umin;
@@ -71,23 +88,15 @@ void IntegerRangeAnalysis::visitOperation(
71
88
Operation *op, ArrayRef<const IntegerValueRangeLattice *> operands,
72
89
ArrayRef<IntegerValueRangeLattice *> results) {
73
90
// If the lattice on any operand is unitialized, bail out.
74
- if (llvm::any_of (operands, [](const IntegerValueRangeLattice *lattice) {
75
- return lattice->getValue ().isUninitialized ();
76
- })) {
77
- return ;
78
- }
79
-
80
91
auto inferrable = dyn_cast<InferIntRangeInterface>(op);
81
92
if (!inferrable)
82
93
return setAllToEntryStates (results);
83
94
84
95
LLVM_DEBUG (llvm::dbgs () << " Inferring ranges for " << *op << " \n " );
85
- SmallVector<ConstantIntRanges> argRanges (
86
- llvm::map_range (operands, [](const IntegerValueRangeLattice *val) {
87
- return val->getValue ().getValue ();
88
- }));
96
+ SmallVector<OptionalIntRanges> argRanges (llvm::map_range (
97
+ operands, getOptionalRangeFromLattice));
89
98
90
- auto joinCallback = [&](Value v, const ConstantIntRanges &attrs) {
99
+ auto joinCallback = [&](Value v, const OptionalIntRanges &attrs) {
91
100
auto result = dyn_cast<OpResult>(v);
92
101
if (!result)
93
102
return ;
@@ -97,7 +106,9 @@ void IntegerRangeAnalysis::visitOperation(
97
106
IntegerValueRangeLattice *lattice = results[result.getResultNumber ()];
98
107
IntegerValueRange oldRange = lattice->getValue ();
99
108
100
- ChangeResult changed = lattice->join (IntegerValueRange{attrs});
109
+ ChangeResult changed =
110
+ attrs ? lattice->join (IntegerValueRange{attrs})
111
+ : lattice->join (IntegerValueRange::getMaxRange (v));
101
112
102
113
// Catch loop results with loop variant bounds and conservatively make
103
114
// them [-inf, inf] so we don't circle around infinitely often (because
@@ -127,12 +138,12 @@ void IntegerRangeAnalysis::visitNonControlFlowArguments(
127
138
return getLatticeElementFor (op, value)->getValue ().isUninitialized ();
128
139
}))
129
140
return ;
130
- SmallVector<ConstantIntRanges > argRanges (
141
+ SmallVector<OptionalIntRanges > argRanges (
131
142
llvm::map_range (op->getOperands (), [&](Value value) {
132
- return getLatticeElementFor (op, value)-> getValue (). getValue ( );
143
+ return getOptionalRangeFromLattice ( getLatticeElementFor (op, value));
133
144
}));
134
145
135
- auto joinCallback = [&](Value v, const ConstantIntRanges &attrs) {
146
+ auto joinCallback = [&](Value v, const OptionalIntRanges &attrs) {
136
147
auto arg = dyn_cast<BlockArgument>(v);
137
148
if (!arg)
138
149
return ;
@@ -143,7 +154,9 @@ void IntegerRangeAnalysis::visitNonControlFlowArguments(
143
154
IntegerValueRangeLattice *lattice = argLattices[arg.getArgNumber ()];
144
155
IntegerValueRange oldRange = lattice->getValue ();
145
156
146
- ChangeResult changed = lattice->join (IntegerValueRange{attrs});
157
+ ChangeResult changed =
158
+ attrs ? lattice->join (IntegerValueRange{attrs})
159
+ : lattice->join (IntegerValueRange::getMaxRange (v));
147
160
148
161
// Catch loop results with loop variant bounds and conservatively make
149
162
// them [-inf, inf] so we don't circle around infinitely often (because
0 commit comments