Skip to content

Commit cbe3835

Browse files
committed
[NFC] OwnershipUtils: Add a UsePoint type.
The type is a union of an Operand (a real use) and a SILInstruction (an implicit use). Such a type is needed to reflect the fact that with incomplete lifetimes, values can be implicitly destroyed at the terminators of blocks in dead end regions (along the vaule's availability boundary).
1 parent 99091c9 commit cbe3835

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

include/swift/SIL/OwnershipUtils.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,6 +1441,43 @@ bool isRedundantMoveValue(MoveValueInst *mvi);
14411441
/// `forEndBorrowValue`, which is the operand value of an `end_borrow`.
14421442
void updateReborrowFlags(SILValue forEndBorrowValue);
14431443

1444+
/// A location at which a value is used. Abstracts over explicit uses
1445+
/// (operands) and implicit uses (instructions).
1446+
struct UsePoint {
1447+
using Value = llvm::PointerUnion<SILInstruction *, Operand *>;
1448+
Value value;
1449+
1450+
UsePoint(Operand *op) : value(op) {}
1451+
UsePoint(SILInstruction *inst) : value(inst) {}
1452+
UsePoint(Value value) : value(value) {}
1453+
1454+
SILInstruction *getInstruction() const {
1455+
if (auto *op = dyn_cast<Operand *>(value)) {
1456+
return op->getUser();
1457+
}
1458+
return cast<SILInstruction *>(value);
1459+
}
1460+
1461+
Operand *getOperandOrNull() const { return dyn_cast<Operand *>(value); }
1462+
1463+
Operand *getOperand() const { return cast<Operand *>(value); }
1464+
};
1465+
1466+
struct UsePointToInstruction {
1467+
SILInstruction *operator()(const UsePoint point) const {
1468+
return point.getInstruction();
1469+
}
1470+
};
1471+
1472+
using UsePointInstructionRange =
1473+
TransformRange<ArrayRef<UsePoint>, UsePointToInstruction>;
1474+
1475+
struct PointToOperand {
1476+
Operand *operator()(const UsePoint point) const { return point.getOperand(); }
1477+
};
1478+
1479+
using PointOperandRange = TransformRange<ArrayRef<UsePoint>, PointToOperand>;
1480+
14441481
} // namespace swift
14451482

14461483
#endif

lib/SIL/Utils/OwnershipUtils.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,9 @@ bool BorrowedValue::areWithinExtendedScope(Instructions insts,
992992
return liveness.areWithinBoundary(insts, deadEndBlocks);
993993
}
994994

995+
template bool BorrowedValue::areWithinExtendedScope<UsePointInstructionRange>(
996+
UsePointInstructionRange insts, DeadEndBlocks *deadEndBlocks) const;
997+
995998
template bool
996999
BorrowedValue::areWithinExtendedScope<SILInstruction::OperandUserRange>(
9971000
SILInstruction::OperandUserRange insts, DeadEndBlocks *deadEndBlocks) const;

0 commit comments

Comments
 (0)