Skip to content

Commit f812a2a

Browse files
committed
OwnershipUtils: check for SILInstructionKind instead of SILNodeKind
This resolves a FIXME. Also, use `getDefiningInstruction()` instead of `getRepresentativeSILNodeInObject()` NFC
1 parent ea72895 commit f812a2a

File tree

1 file changed

+49
-47
lines changed

1 file changed

+49
-47
lines changed

lib/SIL/Utils/OwnershipUtils.cpp

Lines changed: 49 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,29 @@ bool swift::isValueAddressOrTrivial(SILValue v) {
2626
}
2727

2828
// These operations forward both owned and guaranteed ownership.
29-
//
30-
// FIXME: Should be implemented as a SILInstruction type check-cast.
31-
static bool isOwnershipForwardingValueKind(SILNodeKind kind) {
29+
static bool isOwnershipForwardingInstructionKind(SILInstructionKind kind) {
3230
switch (kind) {
33-
case SILNodeKind::TupleInst:
34-
case SILNodeKind::StructInst:
35-
case SILNodeKind::EnumInst:
36-
case SILNodeKind::DifferentiableFunctionInst:
37-
case SILNodeKind::LinearFunctionInst:
38-
case SILNodeKind::OpenExistentialRefInst:
39-
case SILNodeKind::UpcastInst:
40-
case SILNodeKind::UncheckedValueCastInst:
41-
case SILNodeKind::UncheckedRefCastInst:
42-
case SILNodeKind::ConvertFunctionInst:
43-
case SILNodeKind::RefToBridgeObjectInst:
44-
case SILNodeKind::BridgeObjectToRefInst:
45-
case SILNodeKind::UnconditionalCheckedCastInst:
46-
case SILNodeKind::UncheckedEnumDataInst:
47-
case SILNodeKind::SelectEnumInst:
48-
case SILNodeKind::SwitchEnumInst:
49-
case SILNodeKind::CheckedCastBranchInst:
50-
case SILNodeKind::DestructureStructInst:
51-
case SILNodeKind::DestructureTupleInst:
52-
case SILNodeKind::MarkDependenceInst:
53-
case SILNodeKind::InitExistentialRefInst:
31+
case SILInstructionKind::TupleInst:
32+
case SILInstructionKind::StructInst:
33+
case SILInstructionKind::EnumInst:
34+
case SILInstructionKind::DifferentiableFunctionInst:
35+
case SILInstructionKind::LinearFunctionInst:
36+
case SILInstructionKind::OpenExistentialRefInst:
37+
case SILInstructionKind::UpcastInst:
38+
case SILInstructionKind::UncheckedValueCastInst:
39+
case SILInstructionKind::UncheckedRefCastInst:
40+
case SILInstructionKind::ConvertFunctionInst:
41+
case SILInstructionKind::RefToBridgeObjectInst:
42+
case SILInstructionKind::BridgeObjectToRefInst:
43+
case SILInstructionKind::UnconditionalCheckedCastInst:
44+
case SILInstructionKind::UncheckedEnumDataInst:
45+
case SILInstructionKind::SelectEnumInst:
46+
case SILInstructionKind::SwitchEnumInst:
47+
case SILInstructionKind::CheckedCastBranchInst:
48+
case SILInstructionKind::DestructureStructInst:
49+
case SILInstructionKind::DestructureTupleInst:
50+
case SILInstructionKind::MarkDependenceInst:
51+
case SILInstructionKind::InitExistentialRefInst:
5452
return true;
5553
default:
5654
return false;
@@ -59,17 +57,17 @@ static bool isOwnershipForwardingValueKind(SILNodeKind kind) {
5957

6058
// These operations forward guaranteed ownership, but don't necessarily forward
6159
// owned values.
62-
static bool isGuaranteedForwardingValueKind(SILNodeKind kind) {
60+
static bool isGuaranteedForwardingInstructionKind(SILInstructionKind kind) {
6361
switch (kind) {
64-
case SILNodeKind::TupleExtractInst:
65-
case SILNodeKind::StructExtractInst:
66-
case SILNodeKind::DifferentiableFunctionExtractInst:
67-
case SILNodeKind::LinearFunctionExtractInst:
68-
case SILNodeKind::OpenExistentialValueInst:
69-
case SILNodeKind::OpenExistentialBoxValueInst:
62+
case SILInstructionKind::TupleExtractInst:
63+
case SILInstructionKind::StructExtractInst:
64+
case SILInstructionKind::DifferentiableFunctionExtractInst:
65+
case SILInstructionKind::LinearFunctionExtractInst:
66+
case SILInstructionKind::OpenExistentialValueInst:
67+
case SILInstructionKind::OpenExistentialBoxValueInst:
7068
return true;
7169
default:
72-
return isOwnershipForwardingValueKind(kind);
70+
return isOwnershipForwardingInstructionKind(kind);
7371
}
7472
}
7573

@@ -83,32 +81,34 @@ bool swift::canOpcodeForwardGuaranteedValues(SILValue value) {
8381
return true;
8482
}
8583

86-
auto *node = value->getRepresentativeSILNodeInObject();
87-
bool result = isGuaranteedForwardingValueKind(node->getKind());
84+
auto *inst = value->getDefiningInstruction();
85+
if (!inst)
86+
return false;
87+
88+
bool result = isGuaranteedForwardingInstructionKind(inst->getKind());
8889
if (result) {
89-
assert(!isa<OwnedFirstArgForwardingSingleValueInst>(node));
90-
assert(OwnershipForwardingMixin::isa(node));
90+
assert(!isa<OwnedFirstArgForwardingSingleValueInst>(inst));
91+
assert(OwnershipForwardingMixin::isa(inst));
9192
}
9293
return result;
9394
}
9495

9596
bool swift::canOpcodeForwardGuaranteedValues(Operand *use) {
9697
auto *user = use->getUser();
97-
auto kind = user->getKind();
98-
bool result = isOwnershipForwardingValueKind(SILNodeKind(kind));
98+
bool result = isOwnershipForwardingInstructionKind(user->getKind());
9999
if (result) {
100100
assert(!isa<GuaranteedFirstArgForwardingSingleValueInst>(user));
101101
assert(OwnershipForwardingMixin::isa(user));
102102
}
103103
return result;
104104
}
105105

106-
static bool isOwnedForwardingValueKind(SILNodeKind kind) {
106+
static bool isOwnedForwardingValueKind(SILInstructionKind kind) {
107107
switch (kind) {
108-
case SILNodeKind::MarkUninitializedInst:
108+
case SILInstructionKind::MarkUninitializedInst:
109109
return true;
110110
default:
111-
return isOwnershipForwardingValueKind(kind);
111+
return isOwnershipForwardingInstructionKind(kind);
112112
}
113113
}
114114

@@ -121,19 +121,21 @@ bool swift::canOpcodeForwardOwnedValues(SILValue value) {
121121
assert(OwnershipForwardingMixin::isa(predTerm));
122122
return true;
123123
}
124-
auto *node = value->getRepresentativeSILNodeInObject();
125-
bool result = isOwnedForwardingValueKind(node->getKind());
124+
auto *inst = value->getDefiningInstruction();
125+
if (!inst)
126+
return false;
127+
128+
bool result = isOwnedForwardingValueKind(inst->getKind());
126129
if (result) {
127-
assert(!isa<GuaranteedFirstArgForwardingSingleValueInst>(node));
128-
assert(OwnershipForwardingMixin::isa(node));
130+
assert(!isa<GuaranteedFirstArgForwardingSingleValueInst>(inst));
131+
assert(OwnershipForwardingMixin::isa(inst));
129132
}
130133
return result;
131134
}
132135

133136
bool swift::canOpcodeForwardOwnedValues(Operand *use) {
134137
auto *user = use->getUser();
135-
auto kind = SILNodeKind(user->getKind());
136-
bool result = isOwnershipForwardingValueKind(kind);
138+
bool result = isOwnershipForwardingInstructionKind(user->getKind());
137139
if (result) {
138140
assert(OwnershipForwardingMixin::isa(user));
139141
}

0 commit comments

Comments
 (0)