[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

@@ -2710,6 +2710,9 @@ enum class ParameterConvention {
/// guarantees its validity for the entirety of the call.
Direct_Guaranteed,
};
// Check that the enum values fit inside SILFunctionTypeBits.
static_assert(unsigned(ParameterConvention::Direct_Guaranteed) < (1<<3),
"fits in SILFunctionTypeBits");
// Does this parameter convention require indirect storage? This reflects a
// SILFunctionType's formal (immutable) conventions, as opposed to the transient

View File

@@ -163,6 +163,11 @@ namespace swift {
/// and methods.
bool InferImportAsMember = false;
/// If set to true, compile with the SIL Opaque Values enabled.
/// This is for bootstrapping. It can't be in SILOptions because the
/// TypeChecker uses it to set resolve the ParameterConvention.
bool EnableSILOpaqueValues = false;
/// Sets the target we are building for and updates platform conditions
/// to match.
///

View File

@@ -248,6 +248,9 @@ def enable_sil_ownership : Flag<["-"], "enable-sil-ownership">,
def assume_parsing_unqualified_ownership_sil : Flag<["-"], "assume-parsing-unqualified-ownership-sil">,
HelpText<"Assume unqualified SIL ownership when parsing SIL">;
def enable_sil_opaque_values : Flag<["-"], "enable-sil-opaque-values">,
HelpText<"Enable SIL Opaque Values">;
def enable_experimental_property_behaviors :
Flag<["-"], "enable-experimental-property-behaviors">,
HelpText<"Enable experimental property behaviors">;

View File

@@ -469,7 +469,8 @@ public:
assert((Qualifier == LoadOwnershipQualifier::Unqualified) ||
F.hasQualifiedOwnership() &&
"Qualified inst in unqualified function");
assert(LV->getType().isLoadable(F.getModule()));
assert(!SILModuleConventions(F.getModule()).useLoweredAddresses()
|| LV->getType().isLoadable(F.getModule()));
return insert(new (F.getModule())
LoadInst(getSILDebugLocation(Loc), LV, Qualifier));
}

View File

@@ -576,6 +576,8 @@ public:
SILFunctionConventions getFunctionConventions(CanSILFunctionType funcTy);
bool useLoweredAddresses() const { return loweredAddresses; }
bool isSILIndirect(SILParameterInfo param) const {
return isIndirectSILParam(param, loweredAddresses);
}
@@ -612,6 +614,8 @@ public:
// SILModuleConventions API for convenience.
//===--------------------------------------------------------------------===//
bool useLoweredAddresses() const { return silConv.useLoweredAddresses(); }
bool isSILIndirect(SILParameterInfo param) const {
return silConv.isSILIndirect(param);
}

View File

@@ -170,6 +170,11 @@ public:
return LoweredType;
}
/// Returns true if the SIL type is an address.
bool isAddress() const {
return LoweredType.isAddress();
}
/// Return the semantic type.
///
/// The semantic type is what a type pretends to be during