@@ -210,29 +210,25 @@ SILInstruction *SILCombiner::visitSwitchEnumAddrInst(SwitchEnumAddrInst *SEAI) {
210
210
return eraseInstFromFunction (*SEAI);
211
211
}
212
212
213
- SILInstruction *SILCombiner::visitSelectEnumAddrInst (SelectEnumAddrInst *SEAI) {
214
- if (SEAI->getFunction ()->hasOwnership ())
215
- return nullptr ;
216
-
213
+ SILInstruction *SILCombiner::visitSelectEnumAddrInst (SelectEnumAddrInst *seai) {
217
214
// Canonicalize a select_enum_addr: if the default refers to exactly one case,
218
215
// then replace the default with that case.
219
- Builder.setCurrentDebugScope (SEAI ->getDebugScope ());
220
- if (SEAI ->hasDefault ()) {
221
- NullablePtr<EnumElementDecl> elementDecl = SEAI ->getUniqueCaseForDefault ();
216
+ Builder.setCurrentDebugScope (seai ->getDebugScope ());
217
+ if (seai ->hasDefault ()) {
218
+ NullablePtr<EnumElementDecl> elementDecl = seai ->getUniqueCaseForDefault ();
222
219
if (elementDecl.isNonNull ()) {
223
220
// Construct a new instruction by copying all the case entries.
224
- SmallVector<std::pair<EnumElementDecl *, SILValue>, 4 > CaseValues ;
225
- for (int idx = 0 , numIdcs = SEAI ->getNumCases (); idx < numIdcs; ++idx) {
226
- CaseValues .push_back (SEAI ->getCase (idx));
221
+ SmallVector<std::pair<EnumElementDecl *, SILValue>, 4 > caseValues ;
222
+ for (int idx = 0 , numIdcs = seai ->getNumCases (); idx < numIdcs; ++idx) {
223
+ caseValues .push_back (seai ->getCase (idx));
227
224
}
228
225
// Add the default-entry of the original instruction as case-entry.
229
- CaseValues .push_back (
230
- std::make_pair (elementDecl.get (), SEAI ->getDefaultResult ()));
226
+ caseValues .push_back (
227
+ std::make_pair (elementDecl.get (), seai ->getDefaultResult ()));
231
228
232
- return Builder.createSelectEnumAddr (SEAI->getLoc (),
233
- SEAI->getEnumOperand (),
234
- SEAI->getType (), SILValue (),
235
- CaseValues);
229
+ return Builder.createSelectEnumAddr (
230
+ seai->getLoc (), seai->getEnumOperand (), seai->getType (), SILValue (),
231
+ caseValues);
236
232
}
237
233
}
238
234
@@ -241,20 +237,23 @@ SILInstruction *SILCombiner::visitSelectEnumAddrInst(SelectEnumAddrInst *SEAI) {
241
237
// ->
242
238
// %value = load %ptr
243
239
// = select_enum %value
244
- SILType Ty = SEAI ->getEnumOperand ()->getType ();
245
- if (!Ty .isLoadable (*SEAI ->getFunction ()))
240
+ SILType ty = seai ->getEnumOperand ()->getType ();
241
+ if (!ty .isLoadable (*seai ->getFunction ()))
246
242
return nullptr ;
247
243
248
- SmallVector<std::pair<EnumElementDecl*, SILValue>, 8 > Cases;
249
- for (int i = 0 , e = SEAI->getNumCases (); i < e; ++i)
250
- Cases.push_back (SEAI->getCase (i));
251
-
252
- SILValue Default = SEAI->hasDefault () ? SEAI->getDefaultResult () : SILValue ();
253
- LoadInst *EnumVal = Builder.createLoad (SEAI->getLoc (), SEAI->getEnumOperand (),
254
- LoadOwnershipQualifier::Unqualified);
255
- auto *I = Builder.createSelectEnum (SEAI->getLoc (), EnumVal, SEAI->getType (),
256
- Default, Cases);
257
- return I;
244
+ SmallVector<std::pair<EnumElementDecl *, SILValue>, 8 > cases;
245
+ for (int i = 0 , e = seai->getNumCases (); i < e; ++i)
246
+ cases.push_back (seai->getCase (i));
247
+
248
+ SILValue defaultCase =
249
+ seai->hasDefault () ? seai->getDefaultResult () : SILValue ();
250
+ auto enumVal =
251
+ Builder.emitLoadBorrowOperation (seai->getLoc (), seai->getEnumOperand ());
252
+ auto *result = Builder.createSelectEnum (seai->getLoc (), enumVal,
253
+ seai->getType (), defaultCase, cases);
254
+ Builder.emitEndBorrowOperation (seai->getLoc (), enumVal);
255
+ replaceInstUsesWith (*seai, result);
256
+ return eraseInstFromFunction (*seai);
258
257
}
259
258
260
259
SILInstruction *SILCombiner::visitSwitchValueInst (SwitchValueInst *SVI) {
0 commit comments