[sil] Teach constant folding how to handle destructures and multiple value instructions.

I also ported the constant_propagation.sil tests over for ownership and updated
a few parts of the cast optimizer so that those tests pass with and without
ownership. I purposely only updated the parts of the cast optimizer that crashed
with ownership in the relevant test so that I can add new sil code coverage for
those uncovered code paths.
This commit is contained in:
Michael Gottesman
2019-02-09 16:55:25 -08:00
parent 3fb93cd05d
commit 0cdc2d6a35
6 changed files with 1338 additions and 118 deletions

View File

@@ -1429,12 +1429,12 @@ static bool optimizeStaticallyKnownProtocolConformance(
}
case ExistentialRepresentation::Class: {
auto Value =
B.createLoad(Loc, Src, swift::LoadOwnershipQualifier::Unqualified);
B.emitLoadValueOperation(Loc, Src, LoadOwnershipQualifier::Take);
auto Existential =
B.createInitExistentialRef(Loc, Dest->getType().getObjectType(),
SourceType, Value, Conformances);
B.createStore(Loc, Existential, Dest,
swift::StoreOwnershipQualifier::Unqualified);
B.emitStoreValueOperation(Loc, Existential, Dest,
StoreOwnershipQualifier::Init);
break;
}
case ExistentialRepresentation::Boxed: {
@@ -1445,8 +1445,8 @@ static bool optimizeStaticallyKnownProtocolConformance(
// This needs to be a copy_addr (for now) because we must handle
// address-only types.
B.createCopyAddr(Loc, Src, Projection, IsTake, IsInitialization);
B.createStore(Loc, AllocBox, Dest,
swift::StoreOwnershipQualifier::Unqualified);
B.emitStoreValueOperation(Loc, AllocBox, Dest,
StoreOwnershipQualifier::Init);
break;
}
};
@@ -1489,12 +1489,12 @@ SILInstruction *CastOptimizer::optimizeUnconditionalCheckedCastAddrInst(
if (!resultTL.isAddressOnly()) {
auto undef = SILValue(
SILUndef::get(DestType.getObjectType(), Builder.getModule()));
Builder.createStore(Loc, undef, Dest,
StoreOwnershipQualifier::Unqualified);
Builder.emitStoreValueOperation(Loc, undef, Dest,
StoreOwnershipQualifier::Init);
}
auto *TrapI = Builder.createBuiltinTrap(Loc);
EraseInstAction(Inst);
Builder.setInsertionPoint(std::next(SILBasicBlock::iterator(TrapI)));
Builder.setInsertionPoint(std::next(TrapI->getIterator()));
auto *UnreachableInst =
Builder.createUnreachable(ArtificialUnreachableLocation());