[sil] Add a new CastConsumptionKind called BorrowAlways.

This means that:

1. SILGenPattern always borrows the object before it emits a case.
2. Any cast with this cast has a +0 result.

NOTE: That one can not use this with address types (so we assert if you
pass this checked_cast_addr_br).
NOTE: Once we have opaque values, checked_cast_br of a guaranteed value will
lower to a copy + checked_cast_addr_br (assuming the operation is a consuming
cast). To make sure this does not become a problem in terms of performance, we
will need a pass that can transform SILGenPattern +0 cases to +1 cases. This is
something that we have talked about in the past and I think it is reasonable to
implement.

This is an incremental commit towards fixing SILGenPattern for ownership.

rdar://29791263
This commit is contained in:
Michael Gottesman
2018-10-08 13:05:03 -07:00
parent 2a18ea7b79
commit 62b5110357
12 changed files with 93 additions and 19 deletions

View File

@@ -85,6 +85,8 @@ static unsigned toStableCastConsumptionKind(CastConsumptionKind kind) {
return SIL_CAST_CONSUMPTION_TAKE_ON_SUCCESS;
case CastConsumptionKind::CopyOnSuccess:
return SIL_CAST_CONSUMPTION_COPY_ON_SUCCESS;
case CastConsumptionKind::BorrowAlways:
return SIL_CAST_CONSUMPTION_BORROW_ALWAYS;
}
llvm_unreachable("bad cast consumption kind");
}