Skip to content

Commit fe1f150

Browse files
committed
[SILOptimizer] Implement lowering of type wrapper assignment instructions
Type wrapper originated assignment instructions are lowered similar to property wrapper ones except they don't require initializer call because assignments are done to tuple fields.
1 parent 71eb2a7 commit fe1f150

File tree

1 file changed

+39
-21
lines changed

1 file changed

+39
-21
lines changed

lib/SILOptimizer/Mandatory/RawSILInstLowering.cpp

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,10 @@ static void getAssignByWrapperArgs(SmallVectorImpl<SILValue> &args,
165165
"initializer or setter has too many arguments");
166166
}
167167

168-
static void lowerAssignByWrapperInstruction(SILBuilderWithScope &b,
169-
AssignByWrapperInst *inst,
170-
SmallSetVector<SILValue, 8> &toDelete) {
168+
static void
169+
lowerAssignByWrapperInstruction(SILBuilderWithScope &b,
170+
AssignByWrapperInst *inst,
171+
SmallSetVector<SILValue, 8> &toDelete) {
171172
LLVM_DEBUG(llvm::dbgs() << " *** Lowering " << *inst << "\n");
172173

173174
++numAssignRewritten;
@@ -186,29 +187,46 @@ static void lowerAssignByWrapperInstruction(SILBuilderWithScope &b,
186187
LLVM_FALLTHROUGH;
187188
case AssignByWrapperInst::Initialization:
188189
case AssignByWrapperInst::Assign: {
189-
SILValue initFn = inst->getInitializer();
190-
CanSILFunctionType fTy = initFn->getType().castTo<SILFunctionType>();
191-
SILFunctionConventions convention(fTy, inst->getModule());
192-
SmallVector<SILValue, 4> args;
193-
if (convention.hasIndirectSILResults()) {
194-
if (inst->getMode() == AssignByWrapperInst::Assign)
195-
b.createDestroyAddr(loc, dest);
196-
197-
args.push_back(dest);
198-
getAssignByWrapperArgs(args, src, convention, b, forCleanup);
199-
b.createApply(loc, initFn, SubstitutionMap(), args);
200-
} else {
201-
getAssignByWrapperArgs(args, src, convention, b, forCleanup);
202-
SILValue wrappedSrc = b.createApply(loc, initFn, SubstitutionMap(),
203-
args);
190+
switch (inst->getOriginator()) {
191+
case AssignByWrapperInst::Originator::TypeWrapper: {
204192
if (inst->getMode() == AssignByWrapperInst::Initialization ||
205193
inst->getDest()->getType().isTrivial(*inst->getFunction())) {
206-
b.createTrivialStoreOr(loc, wrappedSrc, dest,
207-
StoreOwnershipQualifier::Init);
194+
b.createTrivialStoreOr(loc, src, dest, StoreOwnershipQualifier::Init);
195+
} else {
196+
b.createStore(loc, src, dest, StoreOwnershipQualifier::Assign);
197+
}
198+
break;
199+
}
200+
201+
case AssignByWrapperInst::Originator::PropertyWrapper: {
202+
SILValue initFn = inst->getInitializer();
203+
CanSILFunctionType fTy = initFn->getType().castTo<SILFunctionType>();
204+
SILFunctionConventions convention(fTy, inst->getModule());
205+
SmallVector<SILValue, 4> args;
206+
if (convention.hasIndirectSILResults()) {
207+
if (inst->getMode() == AssignByWrapperInst::Assign)
208+
b.createDestroyAddr(loc, dest);
209+
210+
args.push_back(dest);
211+
getAssignByWrapperArgs(args, src, convention, b, forCleanup);
212+
b.createApply(loc, initFn, SubstitutionMap(), args);
208213
} else {
209-
b.createStore(loc, wrappedSrc, dest, StoreOwnershipQualifier::Assign);
214+
getAssignByWrapperArgs(args, src, convention, b, forCleanup);
215+
SILValue wrappedSrc =
216+
b.createApply(loc, initFn, SubstitutionMap(), args);
217+
if (inst->getMode() == AssignByWrapperInst::Initialization ||
218+
inst->getDest()->getType().isTrivial(*inst->getFunction())) {
219+
b.createTrivialStoreOr(loc, wrappedSrc, dest,
220+
StoreOwnershipQualifier::Init);
221+
} else {
222+
b.createStore(loc, wrappedSrc, dest,
223+
StoreOwnershipQualifier::Assign);
224+
}
210225
}
226+
break;
211227
}
228+
}
229+
212230
// The unused partial_apply violates memory lifetime rules in case "self"
213231
// is an inout. Therefore we cannot keep it as a dead closure to be
214232
// cleaned up later. We have to delete it in this pass.

0 commit comments

Comments
 (0)