Skip to content

Commit 87abaaa

Browse files
committed
[FSPrunedLiveness] Returned bitfield from isDef.
Whether a node is a def on a collection of bits (whether a range or a bit vector) isn't exhaustively characterized by the values {true, false}. A node may be a def on some but not others of the bits in the collection. Changed the range-taking isDef to write back the bits in the range at which the node is a def. The caller can then decide how to react with full information.
1 parent 667a78a commit 87abaaa

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed

include/swift/SIL/FieldSensitivePrunedLiveness.h

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,42 +1379,52 @@ class FieldSensitiveMultiDefPrunedLiveRange
13791379
return isDef(cast<SILNode>(value), bit);
13801380
}
13811381

1382-
bool isDef(SILNode *node, SmallBitVector const &bits) const {
1382+
void isDef(SILNode *node, SmallBitVector const &bits,
1383+
SmallBitVector &bitsOut) const {
13831384
assert(isInitialized());
1385+
assert(bitsOut.none());
13841386
auto iter = defs.find(node);
13851387
if (!iter)
1386-
return false;
1387-
SmallBitVector allBits(bits.size());
1388+
return;
13881389
for (auto range : *iter) {
1389-
range.setBits(allBits);
1390+
range.setBits(bitsOut);
13901391
}
1391-
return (bits & allBits) == bits;
1392+
bitsOut &= bits;
13921393
}
13931394

1394-
bool isDef(SILValue value, SmallBitVector const &bits) const {
1395-
return isDef(cast<SILNode>(value), bits);
1395+
void isDef(SILValue value, SmallBitVector const &bits,
1396+
SmallBitVector &bitsOut) const {
1397+
isDef(cast<SILNode>(value), bits, bitsOut);
13961398
}
13971399

1398-
bool isDef(SILInstruction *inst, SmallBitVector const &bits) const {
1399-
return isDef(cast<SILNode>(inst), bits);
1400+
void isDef(SILInstruction *inst, SmallBitVector const &bits,
1401+
SmallBitVector &bitsOut) const {
1402+
isDef(cast<SILNode>(inst), bits, bitsOut);
14001403
}
14011404

1402-
bool isDef(SILNode *node, TypeTreeLeafTypeRange span) const {
1405+
void isDef(SILNode *node, TypeTreeLeafTypeRange span,
1406+
SmallBitVector &bitsOut) const {
14031407
assert(isInitialized());
1408+
assert(bitsOut.none());
14041409
auto iter = defs.find(node);
14051410
if (!iter)
1406-
return false;
1407-
return llvm::any_of(*iter, [&](TypeTreeLeafTypeRange storedSpan) {
1408-
return span.setIntersection(storedSpan).has_value();
1409-
});
1411+
return;
1412+
for (auto defSpan : *iter) {
1413+
auto intersection = span.setIntersection(defSpan);
1414+
if (!intersection.has_value())
1415+
continue;
1416+
span.setBits(bitsOut);
1417+
}
14101418
}
14111419

1412-
bool isDef(SILInstruction *inst, TypeTreeLeafTypeRange span) const {
1413-
return isDef(cast<SILNode>(inst), span);
1420+
void isDef(SILInstruction *inst, TypeTreeLeafTypeRange span,
1421+
SmallBitVector &bitsOut) const {
1422+
return isDef(cast<SILNode>(inst), span, bitsOut);
14141423
}
14151424

1416-
bool isDef(SILValue value, TypeTreeLeafTypeRange span) const {
1417-
return isDef(cast<SILNode>(value), span);
1425+
void isDef(SILValue value, TypeTreeLeafTypeRange span,
1426+
SmallBitVector &bitsOut) const {
1427+
return isDef(cast<SILNode>(value), span, bitsOut);
14181428
}
14191429

14201430
void

0 commit comments

Comments
 (0)