@@ -146,6 +146,8 @@ bool swift::canOpcodeForwardOwnedValues(Operand *use) {
146
146
147
147
void BorrowingOperandKind::print (llvm::raw_ostream &os) const {
148
148
switch (value) {
149
+ case Kind::Invalid:
150
+ llvm_unreachable (" Using an unreachable?!" );
149
151
case Kind::BeginBorrow:
150
152
os << " BeginBorrow" ;
151
153
return ;
@@ -190,6 +192,8 @@ llvm::raw_ostream &swift::operator<<(llvm::raw_ostream &os,
190
192
bool BorrowingOperand::visitLocalEndScopeUses (
191
193
function_ref<bool (Operand *)> func) const {
192
194
switch (kind) {
195
+ case BorrowingOperandKind::Invalid:
196
+ llvm_unreachable (" Using invalid case" );
193
197
case BorrowingOperandKind::BeginBorrow:
194
198
for (auto *use : cast<BeginBorrowInst>(op->getUser ())->getUses ()) {
195
199
if (use->isLifetimeEnding ()) {
@@ -228,20 +232,24 @@ bool BorrowingOperand::visitLocalEndScopeUses(
228
232
void BorrowingOperand::visitBorrowIntroducingUserResults (
229
233
function_ref<void (BorrowedValue)> visitor) const {
230
234
switch (kind) {
235
+ case BorrowingOperandKind::Invalid:
236
+ llvm_unreachable (" Using invalid case" );
231
237
case BorrowingOperandKind::Apply:
232
238
case BorrowingOperandKind::TryApply:
233
239
case BorrowingOperandKind::BeginApply:
234
240
case BorrowingOperandKind::Yield:
235
241
llvm_unreachable (" Never has borrow introducer results!" );
236
242
case BorrowingOperandKind::BeginBorrow: {
237
- auto value = *BorrowedValue::get (cast<BeginBorrowInst>(op->getUser ()));
243
+ auto value = BorrowedValue::get (cast<BeginBorrowInst>(op->getUser ()));
244
+ assert (value);
238
245
return visitor (value);
239
246
}
240
247
case BorrowingOperandKind::Branch: {
241
248
auto *bi = cast<BranchInst>(op->getUser ());
242
249
for (auto *succBlock : bi->getSuccessorBlocks ()) {
243
250
auto value =
244
- *BorrowedValue::get (succBlock->getArgument (op->getOperandNumber ()));
251
+ BorrowedValue::get (succBlock->getArgument (op->getOperandNumber ()));
252
+ assert (value);
245
253
visitor (value);
246
254
}
247
255
return ;
@@ -263,8 +271,8 @@ void BorrowingOperand::visitConsumingUsesOfBorrowIntroducingUserResults(
263
271
// single guaranteed scope.
264
272
value.visitLocalScopeEndingUses ([&](Operand *valueUser) {
265
273
if (auto subBorrowScopeOp = BorrowingOperand::get (valueUser)) {
266
- if (subBorrowScopeOp-> isReborrow ()) {
267
- subBorrowScopeOp-> visitUserResultConsumingUses (func);
274
+ if (subBorrowScopeOp. isReborrow ()) {
275
+ subBorrowScopeOp. visitUserResultConsumingUses (func);
268
276
return ;
269
277
}
270
278
}
@@ -315,6 +323,8 @@ void BorrowingOperand::getImplicitUses(
315
323
316
324
void BorrowedValueKind::print (llvm::raw_ostream &os) const {
317
325
switch (value) {
326
+ case BorrowedValueKind::Invalid:
327
+ llvm_unreachable (" Using invalid case?!" );
318
328
case BorrowedValueKind::SILFunctionArgument:
319
329
os << " SILFunctionArgument" ;
320
330
return ;
@@ -342,6 +352,8 @@ void BorrowedValue::getLocalScopeEndingInstructions(
342
352
assert (isLocalScope () && " Should only call this given a local scope" );
343
353
344
354
switch (kind) {
355
+ case BorrowedValueKind::Invalid:
356
+ llvm_unreachable (" Using invalid case?!" );
345
357
case BorrowedValueKind::SILFunctionArgument:
346
358
llvm_unreachable (" Should only call this with a local scope" );
347
359
case BorrowedValueKind::BeginBorrow:
@@ -361,6 +373,8 @@ void BorrowedValue::visitLocalScopeEndingUses(
361
373
function_ref<void (Operand *)> visitor) const {
362
374
assert (isLocalScope () && " Should only call this given a local scope" );
363
375
switch (kind) {
376
+ case BorrowedValueKind::Invalid:
377
+ llvm_unreachable (" Using invalid case?!" );
364
378
case BorrowedValueKind::SILFunctionArgument:
365
379
llvm_unreachable (" Should only call this with a local scope" );
366
380
case BorrowedValueKind::LoadBorrow:
@@ -441,7 +455,7 @@ bool BorrowedValue::visitLocalScopeTransitiveEndingUses(
441
455
continue ;
442
456
}
443
457
444
- scopeOperand-> visitConsumingUsesOfBorrowIntroducingUserResults (
458
+ scopeOperand. visitConsumingUsesOfBorrowIntroducingUserResults (
445
459
[&](Operand *op) {
446
460
assert (op->isLifetimeEnding () && " Expected only consuming uses" );
447
461
// Make sure we haven't visited this consuming operand yet. If we
@@ -464,7 +478,7 @@ bool BorrowedValue::visitInteriorPointerOperands(
464
478
auto *op = worklist.pop_back_val ();
465
479
466
480
if (auto interiorPointer = InteriorPointerOperand::get (op)) {
467
- func (* interiorPointer);
481
+ func (interiorPointer);
468
482
continue ;
469
483
}
470
484
@@ -617,6 +631,8 @@ bool InteriorPointerOperand::getImplicitUses(
617
631
618
632
void OwnedValueIntroducerKind::print (llvm::raw_ostream &os) const {
619
633
switch (value) {
634
+ case OwnedValueIntroducerKind::Invalid:
635
+ llvm_unreachable (" Using invalid case?!" );
620
636
case OwnedValueIntroducerKind::Apply:
621
637
os << " Apply" ;
622
638
return ;
@@ -677,7 +693,7 @@ bool swift::getAllBorrowIntroducingValues(SILValue inputValue,
677
693
678
694
// First check if v is an introducer. If so, stash it and continue.
679
695
if (auto scopeIntroducer = BorrowedValue::get (value)) {
680
- out.push_back (* scopeIntroducer);
696
+ out.push_back (scopeIntroducer);
681
697
continue ;
682
698
}
683
699
@@ -716,10 +732,9 @@ bool swift::getAllBorrowIntroducingValues(SILValue inputValue,
716
732
return true ;
717
733
}
718
734
719
- Optional<BorrowedValue>
720
- swift::getSingleBorrowIntroducingValue (SILValue inputValue) {
735
+ BorrowedValue swift::getSingleBorrowIntroducingValue (SILValue inputValue) {
721
736
if (inputValue.getOwnershipKind () != OwnershipKind::Guaranteed)
722
- return None ;
737
+ return {} ;
723
738
724
739
SILValue currentValue = inputValue;
725
740
while (true ) {
@@ -738,7 +753,7 @@ swift::getSingleBorrowIntroducingValue(SILValue inputValue) {
738
753
// this.
739
754
auto begin = instOps.begin ();
740
755
if (std::next (begin) != instOps.end ()) {
741
- return None ;
756
+ return {} ;
742
757
}
743
758
// Otherwise, set currentOp to the single operand and continue.
744
759
currentValue = *begin;
@@ -758,7 +773,7 @@ swift::getSingleBorrowIntroducingValue(SILValue inputValue) {
758
773
759
774
// Otherwise, this is an introducer we do not understand. Bail and return
760
775
// None.
761
- return None ;
776
+ return {} ;
762
777
}
763
778
764
779
llvm_unreachable (" Should never hit this" );
@@ -777,7 +792,7 @@ bool swift::getAllOwnedValueIntroducers(
777
792
778
793
// First check if v is an introducer. If so, stash it and continue.
779
794
if (auto introducer = OwnedValueIntroducer::get (value)) {
780
- out.push_back (* introducer);
795
+ out.push_back (introducer);
781
796
continue ;
782
797
}
783
798
@@ -816,10 +831,9 @@ bool swift::getAllOwnedValueIntroducers(
816
831
return true ;
817
832
}
818
833
819
- Optional<OwnedValueIntroducer>
820
- swift::getSingleOwnedValueIntroducer (SILValue inputValue) {
834
+ OwnedValueIntroducer swift::getSingleOwnedValueIntroducer (SILValue inputValue) {
821
835
if (inputValue.getOwnershipKind () != OwnershipKind::Owned)
822
- return None ;
836
+ return {} ;
823
837
824
838
SILValue currentValue = inputValue;
825
839
while (true ) {
@@ -838,7 +852,7 @@ swift::getSingleOwnedValueIntroducer(SILValue inputValue) {
838
852
// this.
839
853
auto begin = instOps.begin ();
840
854
if (std::next (begin) != instOps.end ()) {
841
- return None ;
855
+ return {} ;
842
856
}
843
857
// Otherwise, set currentOp to the single operand and continue.
844
858
currentValue = *begin;
@@ -859,7 +873,7 @@ swift::getSingleOwnedValueIntroducer(SILValue inputValue) {
859
873
860
874
// Otherwise, this is an introducer we do not understand. Bail and return
861
875
// None.
862
- return None ;
876
+ return {} ;
863
877
}
864
878
865
879
llvm_unreachable (" Should never hit this" );
@@ -869,12 +883,12 @@ swift::getSingleOwnedValueIntroducer(SILValue inputValue) {
869
883
// Forwarding Operand
870
884
// ===----------------------------------------------------------------------===//
871
885
872
- Optional< ForwardingOperand> ForwardingOperand::get (Operand *use) {
886
+ ForwardingOperand ForwardingOperand::get (Operand *use) {
873
887
if (use->isTypeDependent ())
874
- return None ;
888
+ return nullptr ;
875
889
876
890
if (!OwnershipForwardingMixin::isa (use->getUser ())) {
877
- return None ;
891
+ return nullptr ;
878
892
}
879
893
#ifndef NDEBUG
880
894
switch (use->getOperandOwnership ()) {
0 commit comments