Skip to content

Commit c4adc64

Browse files
committed
[ownership] Remove ownership merging from computing Operand constraints for Forwarding Insts.
Another step towards allowing us to use an invalid result to mean an instruction can accept any value.
1 parent 6c3af65 commit c4adc64

File tree

2 files changed

+11
-56
lines changed

2 files changed

+11
-56
lines changed

lib/SIL/IR/OperandOwnership.cpp

Lines changed: 8 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,6 @@ class OperandOwnershipKindClassifier
7373
return getOwnershipKind() == ValueOwnershipKind::None;
7474
}
7575

76-
OperandOwnershipKindMap visitForwardingInst(SILInstruction *i,
77-
ArrayRef<Operand> ops);
78-
OperandOwnershipKindMap visitForwardingInst(SILInstruction *i) {
79-
return visitForwardingInst(i, i->getAllOperands());
80-
}
81-
8276
OperandOwnershipKindMap
8377
visitApplyParameter(ValueOwnershipKind requiredConvention,
8478
UseLifetimeConstraint requirement);
@@ -299,38 +293,12 @@ ACCEPTS_ANY_OWNERSHIP_INST(ConvertEscapeToNoEscape)
299293
#include "swift/AST/ReferenceStorage.def"
300294
#undef ACCEPTS_ANY_OWNERSHIP_INST
301295

302-
OperandOwnershipKindMap
303-
OperandOwnershipKindClassifier::visitForwardingInst(SILInstruction *i,
304-
ArrayRef<Operand> ops) {
305-
assert(i->getNumOperands() && "Expected to have non-zero operands");
306-
assert(isOwnershipForwardingInst(i) &&
307-
"Expected to have an ownership forwarding inst");
308-
309-
// Merge all of the ownership of our operands. If we get back a .none from the
310-
// merge, then we return an empty compatibility map. This ensures that we will
311-
// not be compatible with /any/ input triggering a special error in the
312-
// ownership verifier.
313-
Optional<ValueOwnershipKind> optionalKind =
314-
ValueOwnershipKind::merge(makeOptionalTransformRange(
315-
ops, [&i](const Operand &op) -> Optional<ValueOwnershipKind> {
316-
if (i->isTypeDependentOperand(op))
317-
return None;
318-
return op.get().getOwnershipKind();
319-
}));
320-
if (!optionalKind)
321-
return Map();
322-
323-
auto kind = optionalKind.getValue();
324-
if (kind == ValueOwnershipKind::None)
325-
return Map::allLive();
326-
auto lifetimeConstraint = kind.getForwardingLifetimeConstraint();
327-
return Map::compatibilityMap(kind, lifetimeConstraint);
328-
}
329-
330296
#define FORWARD_ANY_OWNERSHIP_INST(INST) \
331297
OperandOwnershipKindMap OperandOwnershipKindClassifier::visit##INST##Inst( \
332298
INST##Inst *i) { \
333-
return visitForwardingInst(i); \
299+
auto kind = i->getOwnershipKind(); \
300+
auto lifetimeConstraint = kind.getForwardingLifetimeConstraint(); \
301+
return Map::compatibilityMap(kind, lifetimeConstraint); \
334302
}
335303
FORWARD_ANY_OWNERSHIP_INST(Tuple)
336304
FORWARD_ANY_OWNERSHIP_INST(Struct)
@@ -348,25 +316,10 @@ FORWARD_ANY_OWNERSHIP_INST(InitExistentialRef)
348316
FORWARD_ANY_OWNERSHIP_INST(DifferentiableFunction)
349317
FORWARD_ANY_OWNERSHIP_INST(LinearFunction)
350318
FORWARD_ANY_OWNERSHIP_INST(UncheckedValueCast)
319+
FORWARD_ANY_OWNERSHIP_INST(DestructureStruct)
320+
FORWARD_ANY_OWNERSHIP_INST(DestructureTuple)
351321
#undef FORWARD_ANY_OWNERSHIP_INST
352322

353-
// Temporary implementation for staging purposes.
354-
OperandOwnershipKindMap
355-
OperandOwnershipKindClassifier::visitDestructureStructInst(
356-
DestructureStructInst *dsi) {
357-
auto kind = dsi->getOwnershipKind();
358-
auto constraint = kind.getForwardingLifetimeConstraint();
359-
return {kind, constraint};
360-
}
361-
362-
OperandOwnershipKindMap
363-
OperandOwnershipKindClassifier::visitDestructureTupleInst(
364-
DestructureTupleInst *dsi) {
365-
auto kind = dsi->getOwnershipKind();
366-
auto constraint = kind.getForwardingLifetimeConstraint();
367-
return {kind, constraint};
368-
}
369-
370323
// An instruction that forwards a constant ownership or trivial ownership.
371324
#define FORWARD_CONSTANT_OR_NONE_OWNERSHIP_INST(OWNERSHIP, \
372325
USE_LIFETIME_CONSTRAINT, INST) \
@@ -410,7 +363,9 @@ OperandOwnershipKindClassifier::visitSelectEnumInst(SelectEnumInst *i) {
410363
return Map::allLive();
411364
}
412365

413-
return visitForwardingInst(i, i->getAllOperands().drop_front());
366+
auto kind = i->getOwnershipKind();
367+
auto lifetimeConstraint = kind.getForwardingLifetimeConstraint();
368+
return Map::compatibilityMap(kind, lifetimeConstraint);
414369
}
415370

416371
OperandOwnershipKindMap

test/SIL/ownership-verifier/undef.sil

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ struct MyInt {
4444
// CHECK-NEXT: Operand Ownership Map:
4545
// CHECK-NEXT: Op #: 0
4646
// CHECK-NEXT: Ownership Map: -- OperandOwnershipKindMap --
47-
// CHECK-NEXT: unowned: Yes. Liveness: NonLifetimeEnding
48-
// CHECK-NEXT: owned: Yes. Liveness: NonLifetimeEnding
49-
// CHECK-NEXT: guaranteed: Yes. Liveness: NonLifetimeEnding
47+
// CHECK-NEXT: unowned: No.
48+
// CHECK-NEXT: owned: No.
49+
// CHECK-NEXT: guaranteed: No.
5050
// CHECK-NEXT: any: Yes. Liveness: NonLifetimeEnding
5151
sil [ossa] @undef_addresses_have_any_ownership : $@convention(thin) () -> () {
5252
bb0:

0 commit comments

Comments
 (0)