[SILGen] Bootstrapping opaque values (#7113)

[NFC] Add -enable-sil-opaque-values frontend option.

This will be used to change the SIL-level calling convention for opaque values,
such as generics and resilient structs, to pass-by-value.  Under this flag,
opaque values have SSA lifetimes, managed by copy_value and destroy_value.

This will make it easier to optimize copies and verify ownership.

* [SILGen] type lowering support for opaque values.

Add OpaqueValueTypeLowering.
Under EnableSILOpaqueValues, lower address-only types as opaque values.

* [SIL] Fix ValueOwnershipKind to support opaque SIL values.

* Test case: SILGen opaque value support for Parameter/ResultConvention.

* [SILGen] opaque value support for function arguments.

* Future Test case: SILGen opaque value specialDest arguments.

* Future Test case: SILGen opaque values: emitOpenExistential.

* Test case: SIL parsing support for EnableSILOpaqueValues.

* SILGen opaque values: prepareArchetypeCallee.

* [SIL Verify] allow copy_value for EnableSILOpaqueValues.

* Test cast: SIL serializer support for opaque values.

* Add a static_assert for ParameterConvention layout.

* Test case: Mandatory SILOpt support for EnableSILOpaqueValues.

* Test case: SILOpt support for EnableSILOpaqueValues.

* SILGen opaque values: TypeLowering emitCopyValue.

* SILBuilder createLoad. Allow loading opaque values.

* SIL Verifier. Allow loading and storing opaque values.

* SILGen emitSemanticStore support for opaque values.

* Test case for SILGen emitSemanticStore.

* Test case for SIL mandatory support for inout assignment.

* Fix SILGen opaque values test case after rebasing.
This commit is contained in:
Andrew Trick
2017-01-27 18:56:53 -08:00
committed by GitHub
parent 51bdd6f09b
commit e9c559b718
22 changed files with 429 additions and 56 deletions

View File

@@ -730,6 +730,19 @@ static ManagedValue manageParam(SILGenFunction &gen,
SILParameterInfo info,
bool allowPlusZero) {
switch (info.getConvention()) {
case ParameterConvention::Indirect_In_Guaranteed:
if (gen.silConv.useLoweredAddresses()) {
// FIXME: Avoid a behavior change while guaranteed self is disabled by
// default.
if (allowPlusZero) {
return ManagedValue::forUnmanaged(paramValue);
} else {
auto copy = gen.emitTemporaryAllocation(loc, paramValue->getType());
gen.B.createCopyAddr(loc, paramValue, copy, IsNotTake, IsInitialization);
return gen.emitManagedBufferWithCleanup(copy);
}
}
SWIFT_FALLTHROUGH;
case ParameterConvention::Direct_Guaranteed:
if (allowPlusZero)
return ManagedValue::forUnmanaged(paramValue);
@@ -743,21 +756,14 @@ static ManagedValue manageParam(SILGenFunction &gen,
case ParameterConvention::Direct_Owned:
return gen.emitManagedRValueWithCleanup(paramValue);
case ParameterConvention::Indirect_In_Guaranteed:
// FIXME: Avoid a behavior change while guaranteed self is disabled by
// default.
if (allowPlusZero) {
return ManagedValue::forUnmanaged(paramValue);
} else {
auto copy = gen.emitTemporaryAllocation(loc, paramValue->getType());
gen.B.createCopyAddr(loc, paramValue, copy, IsNotTake, IsInitialization);
return gen.emitManagedBufferWithCleanup(copy);
}
case ParameterConvention::Indirect_In:
if (gen.silConv.useLoweredAddresses())
return gen.emitManagedBufferWithCleanup(paramValue);
return gen.emitManagedRValueWithCleanup(paramValue);
case ParameterConvention::Indirect_Inout:
case ParameterConvention::Indirect_InoutAliasable:
return ManagedValue::forLValue(paramValue);
case ParameterConvention::Indirect_In:
return gen.emitManagedBufferWithCleanup(paramValue);
}
llvm_unreachable("bad parameter convention");
}