@@ -294,7 +294,68 @@ raw_ostream &operator<<(raw_ostream &OS, const LVILatticeVal &Val) {
294
294
}
295
295
}
296
296
297
- static LVILatticeVal intersect (LVILatticeVal A, LVILatticeVal B);
297
+ // / Returns true if this lattice value represents at most one possible value.
298
+ // / This is as precise as any lattice value can get while still representing
299
+ // / reachable code.
300
+ static bool hasSingleValue (LVILatticeVal Val) {
301
+ if (Val.isConstantRange () &&
302
+ Val.getConstantRange ().isSingleElement ())
303
+ // Integer constants are single element ranges
304
+ return true ;
305
+ if (Val.isConstant ())
306
+ // Non integer constants
307
+ return true ;
308
+ return false ;
309
+ }
310
+
311
+ // / Combine two sets of facts about the same value into a single set of
312
+ // / facts. Note that this method is not suitable for merging facts along
313
+ // / different paths in a CFG; that's what the mergeIn function is for. This
314
+ // / is for merging facts gathered about the same value at the same location
315
+ // / through two independent means.
316
+ // / Notes:
317
+ // / * This method does not promise to return the most precise possible lattice
318
+ // / value implied by A and B. It is allowed to return any lattice element
319
+ // / which is at least as strong as *either* A or B (unless our facts
320
+ // / conflict, see below).
321
+ // / * Due to unreachable code, the intersection of two lattice values could be
322
+ // / contradictory. If this happens, we return some valid lattice value so as
323
+ // / not confuse the rest of LVI. Ideally, we'd always return Undefined, but
324
+ // / we do not make this guarantee. TODO: This would be a useful enhancement.
325
+ static LVILatticeVal intersect (LVILatticeVal A, LVILatticeVal B) {
326
+ // Undefined is the strongest state. It means the value is known to be along
327
+ // an unreachable path.
328
+ if (A.isUndefined ())
329
+ return A;
330
+ if (B.isUndefined ())
331
+ return B;
332
+
333
+ // If we gave up for one, but got a useable fact from the other, use it.
334
+ if (A.isOverdefined ())
335
+ return B;
336
+ if (B.isOverdefined ())
337
+ return A;
338
+
339
+ // Can't get any more precise than constants.
340
+ if (hasSingleValue (A))
341
+ return A;
342
+ if (hasSingleValue (B))
343
+ return B;
344
+
345
+ // Could be either constant range or not constant here.
346
+ if (!A.isConstantRange () || !B.isConstantRange ()) {
347
+ // TODO: Arbitrary choice, could be improved
348
+ return A;
349
+ }
350
+
351
+ // Intersect two constant ranges
352
+ ConstantRange Range =
353
+ A.getConstantRange ().intersectWith (B.getConstantRange ());
354
+ // Note: An empty range is implicitly converted to overdefined internally.
355
+ // TODO: We could instead use Undefined here since we've proven a conflict
356
+ // and thus know this path must be unreachable.
357
+ return LVILatticeVal::getRange (Range);
358
+ }
298
359
299
360
// ===----------------------------------------------------------------------===//
300
361
// LazyValueInfoCache Decl
@@ -1040,69 +1101,6 @@ static bool getEdgeValueLocal(Value *Val, BasicBlock *BBFrom,
1040
1101
return false ;
1041
1102
}
1042
1103
1043
- // / Returns true if this lattice value represents at most one possible value.
1044
- // / This is as precise as any lattice value can get while still representing
1045
- // / reachable code.
1046
- static bool hasSingleValue (LVILatticeVal Val) {
1047
- if (Val.isConstantRange () &&
1048
- Val.getConstantRange ().isSingleElement ())
1049
- // Integer constants are single element ranges
1050
- return true ;
1051
- if (Val.isConstant ())
1052
- // Non integer constants
1053
- return true ;
1054
- return false ;
1055
- }
1056
-
1057
- // / Combine two sets of facts about the same value into a single set of
1058
- // / facts. Note that this method is not suitable for merging facts along
1059
- // / different paths in a CFG; that's what the mergeIn function is for. This
1060
- // / is for merging facts gathered about the same value at the same location
1061
- // / through two independent means.
1062
- // / Notes:
1063
- // / * This method does not promise to return the most precise possible lattice
1064
- // / value implied by A and B. It is allowed to return any lattice element
1065
- // / which is at least as strong as *either* A or B (unless our facts
1066
- // / conflict, see below).
1067
- // / * Due to unreachable code, the intersection of two lattice values could be
1068
- // / contradictory. If this happens, we return some valid lattice value so as
1069
- // / not confuse the rest of LVI. Ideally, we'd always return Undefined, but
1070
- // / we do not make this guarantee. TODO: This would be a useful enhancement.
1071
- static LVILatticeVal intersect (LVILatticeVal A, LVILatticeVal B) {
1072
- // Undefined is the strongest state. It means the value is known to be along
1073
- // an unreachable path.
1074
- if (A.isUndefined ())
1075
- return A;
1076
- if (B.isUndefined ())
1077
- return B;
1078
-
1079
- // If we gave up for one, but got a useable fact from the other, use it.
1080
- if (A.isOverdefined ())
1081
- return B;
1082
- if (B.isOverdefined ())
1083
- return A;
1084
-
1085
- // Can't get any more precise than constants.
1086
- if (hasSingleValue (A))
1087
- return A;
1088
- if (hasSingleValue (B))
1089
- return B;
1090
-
1091
- // Could be either constant range or not constant here.
1092
- if (!A.isConstantRange () || !B.isConstantRange ()) {
1093
- // TODO: Arbitrary choice, could be improved
1094
- return A;
1095
- }
1096
-
1097
- // Intersect two constant ranges
1098
- ConstantRange Range =
1099
- A.getConstantRange ().intersectWith (B.getConstantRange ());
1100
- // Note: An empty range is implicitly converted to overdefined internally.
1101
- // TODO: We could instead use Undefined here since we've proven a conflict
1102
- // and thus know this path must be unreachable.
1103
- return LVILatticeVal::getRange (Range);
1104
- }
1105
-
1106
1104
// / \brief Compute the value of Val on the edge BBFrom -> BBTo or the value at
1107
1105
// / the basic block if the edge does not constrain Val.
1108
1106
bool LazyValueInfoCache::getEdgeValue (Value *Val, BasicBlock *BBFrom,
0 commit comments