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
48
+ getOptionalRangeFromLattice (const IntegerValueRangeLattice *lattice) {
49
+ return getOptionalRange (lattice->getValue ());
50
+ }
51
+
52
+ } // end namespace
53
+
39
54
IntegerValueRange IntegerValueRange::getMaxRange (Value value) {
40
55
unsigned width = ConstantIntRanges::getStorageBitwidth (value.getType ());
56
+ if (width == 0 )
57
+ return {};
58
+
41
59
APInt umin = APInt::getMinValue (width);
42
60
APInt umax = APInt::getMaxValue (width);
43
61
APInt smin = width != 0 ? APInt::getSignedMinValue (width) : umin;
@@ -71,23 +89,14 @@ void IntegerRangeAnalysis::visitOperation(
71
89
Operation *op, ArrayRef<const IntegerValueRangeLattice *> operands,
72
90
ArrayRef<IntegerValueRangeLattice *> results) {
73
91
// 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
92
auto inferrable = dyn_cast<InferIntRangeInterface>(op);
81
93
if (!inferrable)
82
94
return setAllToEntryStates (results);
83
95
84
96
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
- }));
97
+ auto argRanges = llvm::map_to_vector (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