Skip to content

Commit 09ae2ef

Browse files
committedDec 2, 2020
[ownership] Centralize all info about SILInstruction forwarding in the SILInstruction class hierarchy itself.
This commit is doing a few things: 1. It is centralizing all decisions about whether an operand's owner instruction or a value's parent instruction is forwarding in each SILInstruction itself. This will prevent this information from getting out of sync. 2. This allowed me to hide the low level queries in OwnershipUtils.h that determined if a SILNodeKind was "forwarding". I tried to minimize the amount of churn in this PR and thus didn't remove the is{Owned,Ownership,Guaranteed}Forwarding{Use,Value} checks. Instead I left them alone but added in asserts to make sure that if the old impl ever returns true, the neew impl does as well. In a subsequent commit, I am going to remove the old impl in favor of isa queries. 3. I also in the process discovered that there were some instructions that were being inconsistently marked as forwarding. All of the asserts in the PR caught these and I fixed these inconsistencies.
1 parent 33aec98 commit 09ae2ef

File tree

7 files changed

+315
-128
lines changed

7 files changed

+315
-128
lines changed
 

‎include/swift/SIL/OwnershipUtils.h

+14-20
Original file line numberDiff line numberDiff line change
@@ -32,33 +32,22 @@ class DeadEndBlocks;
3232
/// Returns true if v is an address or trivial.
3333
bool isValueAddressOrTrivial(SILValue v);
3434

35-
/// These operations forward both owned and guaranteed ownership.
36-
bool isOwnershipForwardingValueKind(SILNodeKind kind);
37-
38-
/// Is this an operand that can forward both owned and guaranteed ownership
39-
/// kinds.
35+
/// Is this an operand that can forward both owned and guaranteed ownership into
36+
/// one of the operand's owner instruction's result.
4037
bool isOwnershipForwardingUse(Operand *op);
4138

42-
/// Is this an operand that forwards guaranteed ownership from its value to a
43-
/// result of the using instruction.
39+
/// Is this an operand that can forward guaranteed ownership into one of the
40+
/// operand's owner instruction's result.
4441
bool isGuaranteedForwardingUse(Operand *op);
4542

46-
/// These operations forward guaranteed ownership, but don't necessarily forward
47-
/// owned values.
48-
bool isGuaranteedForwardingValueKind(SILNodeKind kind);
43+
/// Is this an operand that can forward owned ownership into one of the
44+
/// operand's owner instruction's result.
45+
bool isOwnedForwardingUse(Operand *use);
4946

50-
/// Is this a value that is the result of an operation that forwards owned
51-
/// ownership.
47+
/// Is this a value that is the result of an instruction that forwards
48+
/// guaranteed ownership from one of its operands.
5249
bool isGuaranteedForwardingValue(SILValue value);
5350

54-
/// Is this a node kind that can forward owned ownership, but may not be able to
55-
/// forward guaranteed ownership.
56-
bool isOwnedForwardingValueKind(SILNodeKind kind);
57-
58-
/// Does this operand 'forward' owned ownership, but may not be able to forward
59-
/// guaranteed ownership.
60-
bool isOwnedForwardingUse(Operand *use);
61-
6251
/// Is this value the result of an instruction that 'forward's owned ownership,
6352
/// but may not be able to forward guaranteed ownership.
6453
///
@@ -76,6 +65,11 @@ class ForwardingOperand {
7665
static Optional<ForwardingOperand> get(Operand *use);
7766

7867
Operand *getUse() const { return use; }
68+
OwnershipConstraint getOwnershipConstraint() const {
69+
// We use a force unwrap since a ForwardingOperand should always have an
70+
// ownership constraint.
71+
return *use->getOwnershipConstraint();
72+
}
7973
ValueOwnershipKind getOwnershipKind() const;
8074
void setOwnershipKind(ValueOwnershipKind newKind) const;
8175
void replaceOwnershipKind(ValueOwnershipKind oldKind,

0 commit comments

Comments
 (0)