@@ -260,17 +260,15 @@ void *SILModule::allocateInst(unsigned Size, unsigned Align) const {
260
260
261
261
void SILModule::willDeleteInstruction (SILInstruction *I) {
262
262
// Update RootOpenedArchetypeDefs.
263
- if (auto *svi = dyn_cast<SingleValueInstruction>(I)) {
264
- if (const CanOpenedArchetypeType archeTy =
265
- svi->getDefinedOpenedArchetype ()) {
266
- OpenedArchetypeKey key = {archeTy, svi->getFunction ()};
267
- // In case `willDeleteInstruction` is called twice for the same instruction,
268
- // we need to check if the archetype is really still in the map for this
269
- // instruction.
270
- if (RootOpenedArchetypeDefs.lookup (key) == svi)
271
- RootOpenedArchetypeDefs.erase (key);
272
- }
273
- }
263
+ I->forEachDefinedOpenedArchetype ([&](CanOpenedArchetypeType archeTy,
264
+ SILValue dependency) {
265
+ OpenedArchetypeKey key = {archeTy, I->getFunction ()};
266
+ // In case `willDeleteInstruction` is called twice for the
267
+ // same instruction, we need to check if the archetype is really
268
+ // still in the map for this instruction.
269
+ if (RootOpenedArchetypeDefs.lookup (key) == dependency)
270
+ RootOpenedArchetypeDefs.erase (key);
271
+ });
274
272
}
275
273
276
274
void SILModule::scheduleForDeletion (SILInstruction *I) {
@@ -766,45 +764,41 @@ unsigned SILModule::getCaseIndex(EnumElementDecl *enumElement) {
766
764
}
767
765
768
766
void SILModule::notifyAddedInstruction (SILInstruction *inst) {
769
- if (auto *svi = dyn_cast<SingleValueInstruction>(inst)) {
770
- if (const CanOpenedArchetypeType archeTy =
771
- svi->getDefinedOpenedArchetype ()) {
772
- SILValue &val = RootOpenedArchetypeDefs[{archeTy, inst->getFunction ()}];
773
- if (val) {
774
- if (!isa<PlaceholderValue>(val)) {
775
- // Print a useful error message (and not just abort with an assert).
776
- llvm::errs () << " re-definition of root opened archetype in function "
777
- << svi->getFunction ()->getName () << " :\n " ;
778
- svi->print (llvm::errs ());
779
- llvm::errs () << " previously defined in function "
780
- << val->getFunction ()->getName () << " :\n " ;
781
- val->print (llvm::errs ());
782
- abort ();
783
- }
784
- // The opened archetype was unresolved so far. Replace the placeholder
785
- // by inst.
786
- auto *placeholder = cast<PlaceholderValue>(val);
787
- placeholder->replaceAllUsesWith (svi);
788
- ::delete placeholder;
789
- numUnresolvedOpenedArchetypes--;
767
+ inst->forEachDefinedOpenedArchetype ([&](CanOpenedArchetypeType archeTy,
768
+ SILValue dependency) {
769
+ SILValue &val = RootOpenedArchetypeDefs[{archeTy, inst->getFunction ()}];
770
+ if (val) {
771
+ if (!isa<PlaceholderValue>(val)) {
772
+ // Print a useful error message (and not just abort with an assert).
773
+ llvm::errs () << " re-definition of root opened archetype in function "
774
+ << inst->getFunction ()->getName () << " :\n " ;
775
+ inst->print (llvm::errs ());
776
+ llvm::errs () << " previously defined in function "
777
+ << val->getFunction ()->getName () << " :\n " ;
778
+ val->print (llvm::errs ());
779
+ abort ();
790
780
}
791
- val = svi;
781
+ // The opened archetype was unresolved so far. Replace the placeholder
782
+ // by inst.
783
+ auto *placeholder = cast<PlaceholderValue>(val);
784
+ placeholder->replaceAllUsesWith (dependency);
785
+ ::delete placeholder;
786
+ numUnresolvedOpenedArchetypes--;
792
787
}
793
- }
788
+ val = dependency;
789
+ });
794
790
}
795
791
796
792
void SILModule::notifyMovedInstruction (SILInstruction *inst,
797
793
SILFunction *fromFunction) {
798
- if (auto *svi = dyn_cast<SingleValueInstruction>(inst)) {
799
- if (const CanOpenedArchetypeType archeTy =
800
- svi->getDefinedOpenedArchetype ()) {
801
- OpenedArchetypeKey key = {archeTy, fromFunction};
802
- assert (RootOpenedArchetypeDefs.lookup (key) == svi &&
803
- " archetype def was not registered" );
804
- RootOpenedArchetypeDefs.erase (key);
805
- RootOpenedArchetypeDefs[{archeTy, svi->getFunction ()}] = svi;
806
- }
807
- }
794
+ inst->forEachDefinedOpenedArchetype ([&](CanOpenedArchetypeType archeTy,
795
+ SILValue dependency) {
796
+ OpenedArchetypeKey key = {archeTy, fromFunction};
797
+ assert (RootOpenedArchetypeDefs.lookup (key) == dependency &&
798
+ " archetype def was not registered" );
799
+ RootOpenedArchetypeDefs.erase (key);
800
+ RootOpenedArchetypeDefs[{archeTy, inst->getFunction ()}] = dependency;
801
+ });
808
802
}
809
803
810
804
// TODO: We should have an "isNoReturn" bit on Swift's BuiltinInfo, but for
0 commit comments