Optimizer: improve simplification of alloc_stack

* Reimplement most of the logic in Swift as an Instruction simplification and remove the old code from SILCombine
* support more cases of existential archetype replacements:

For example:
```
  %0 = alloc_stack $any P
  %1 = init_existential_addr %0, $T
  use %1
```
is transformed to
```
  %0 = alloc_stack $T
  use %0
```

Also, if the alloc_stack is already an opened existential and the concrete type is known,
replace it as well:
```
  %0 = metatype $@thick T.Type
  %1 = init_existential_metatype %0, $@thick any P.Type
  %2 = open_existential_metatype %1 : $@thick any P.Type to $@thick (@opened("X", P) Self).Type
  ...
  %3 = alloc_stack $@opened("X", any P) Self
  use %3
```
is transformed to
```
  ...
  %3 = alloc_stack $T
  use %3
```
This commit is contained in:
Erik Eckstein
2025-02-27 20:43:31 +01:00
parent 5572c832e1
commit 46035305aa
18 changed files with 702 additions and 286 deletions

View File

@@ -540,6 +540,7 @@ SWIFT_SILCOMBINE_PASS(PointerToAddressInst)
SWIFT_SILCOMBINE_PASS(TypeValueInst)
SWIFT_SILCOMBINE_PASS(UncheckedEnumDataInst)
SWIFT_SILCOMBINE_PASS(WitnessMethodInst)
SWIFT_SILCOMBINE_PASS_WITH_LEGACY(AllocStackInst)
SWIFT_SILCOMBINE_PASS_WITH_LEGACY(UnconditionalCheckedCastInst)
SWIFT_SILCOMBINE_PASS_WITH_LEGACY(ApplyInst)
SWIFT_SILCOMBINE_PASS_WITH_LEGACY(TryApplyInst)