Previously, mayRequirePackMetadata only considered whether a type
involved a pack. That failed to account for the case of outlined value
functions that require pack metadata when the type involves a pack in
its layout. Here, mayRequirePackMetadata now considers also whether the
layout corresponding to a type involves a pack.
rdar://119829826
Instead of assuming that the list of instructions known to allocate pack
metadata is exhaustive and returning false from mayRequirePackMetadata
for all others, consider the types of the results and operands of other
instructions and look for packs.
Deallocate dynamic allocas done for metadata/wtable packs. These
stackrestore calls are inserted on the dominance frontier and then stack
nesting is fixed up. That was achieved as follows:
Added a new IRGen pass PackMetadataMarkerInserter; it
- determines if there are any instructions which might allocate on-stack
pack metadata
- if there aren't, no changes are made
- if there are, alloc_pack_metadata just before instructions that could
allocate pack metadata on the stack and dealloc_pack_metadata on the
dominance frontier of those instructions
- fixup stack nesting
During IRGen, the allocations done for metadata/wtable packs are
recorded and IRGenSILFunction associates them with the instruction that
lowered. It must be the instruction after some alloc_pack_metadata
instruction. Then, when visiting the dealloc_pack_metadata instructions
corresponding to that alloc_pack_metadata, deallocate those packs.