Skip to content

Commit 667a78a

Browse files
committed
[NFC] FSPrunedLiveness: Deduplicated isDef impls.
The version for Value and Instruction are identical except for the type of the source of the cast to SILNode. Add an overload for SILNode through which the other two call.
1 parent e8364d6 commit 667a78a

File tree

1 file changed

+21
-28
lines changed

1 file changed

+21
-28
lines changed

include/swift/SIL/FieldSensitivePrunedLiveness.h

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,27 +1362,26 @@ class FieldSensitiveMultiDefPrunedLiveRange
13621362
}
13631363
}
13641364

1365-
bool isDef(SILInstruction *inst, unsigned bit) const {
1365+
bool isDef(SILNode *node, unsigned bit) const {
13661366
assert(isInitialized());
1367-
auto iter = defs.find(cast<SILNode>(inst));
1367+
auto iter = defs.find(node);
13681368
if (!iter)
13691369
return false;
13701370
return llvm::any_of(
13711371
*iter, [&](TypeTreeLeafTypeRange span) { return span.contains(bit); });
13721372
}
13731373

1374+
bool isDef(SILInstruction *inst, unsigned bit) const {
1375+
return isDef(cast<SILNode>(inst), bit);
1376+
}
1377+
13741378
bool isDef(SILValue value, unsigned bit) const {
1375-
assert(isInitialized());
1376-
auto iter = defs.find(cast<SILNode>(value));
1377-
if (!iter)
1378-
return false;
1379-
return llvm::any_of(
1380-
*iter, [&](TypeTreeLeafTypeRange span) { return span.contains(bit); });
1379+
return isDef(cast<SILNode>(value), bit);
13811380
}
13821381

1383-
bool isDef(SILValue value, SmallBitVector const &bits) const {
1382+
bool isDef(SILNode *node, SmallBitVector const &bits) const {
13841383
assert(isInitialized());
1385-
auto iter = defs.find(cast<SILNode>(value));
1384+
auto iter = defs.find(node);
13861385
if (!iter)
13871386
return false;
13881387
SmallBitVector allBits(bits.size());
@@ -1392,36 +1391,30 @@ class FieldSensitiveMultiDefPrunedLiveRange
13921391
return (bits & allBits) == bits;
13931392
}
13941393

1394+
bool isDef(SILValue value, SmallBitVector const &bits) const {
1395+
return isDef(cast<SILNode>(value), bits);
1396+
}
1397+
13951398
bool isDef(SILInstruction *inst, SmallBitVector const &bits) const {
1396-
assert(isInitialized());
1397-
auto iter = defs.find(cast<SILNode>(inst));
1398-
if (!iter)
1399-
return false;
1400-
SmallBitVector allBits(bits.size());
1401-
for (auto range : *iter) {
1402-
range.setBits(allBits);
1403-
}
1404-
return (bits & allBits) == bits;
1399+
return isDef(cast<SILNode>(inst), bits);
14051400
}
14061401

1407-
bool isDef(SILInstruction *inst, TypeTreeLeafTypeRange span) const {
1402+
bool isDef(SILNode *node, TypeTreeLeafTypeRange span) const {
14081403
assert(isInitialized());
1409-
auto iter = defs.find(cast<SILNode>(inst));
1404+
auto iter = defs.find(node);
14101405
if (!iter)
14111406
return false;
14121407
return llvm::any_of(*iter, [&](TypeTreeLeafTypeRange storedSpan) {
14131408
return span.setIntersection(storedSpan).has_value();
14141409
});
14151410
}
14161411

1412+
bool isDef(SILInstruction *inst, TypeTreeLeafTypeRange span) const {
1413+
return isDef(cast<SILNode>(inst), span);
1414+
}
1415+
14171416
bool isDef(SILValue value, TypeTreeLeafTypeRange span) const {
1418-
assert(isInitialized());
1419-
auto iter = defs.find(cast<SILNode>(value));
1420-
if (!iter)
1421-
return false;
1422-
return llvm::any_of(*iter, [&](TypeTreeLeafTypeRange storedSpan) {
1423-
return span.setIntersection(storedSpan).has_value();
1424-
});
1417+
return isDef(cast<SILNode>(value), span);
14251418
}
14261419

14271420
void

0 commit comments

Comments
 (0)