Commits

Adrian Prantl committed 8ab1e2dd502
Unify debug scope and location handling in SILInstruction and SILBuilder. The drivers for this change are providing a simpler API to SIL pass authors, having a more efficient of the in-memory representation, and ruling out an entire class of common bugs that usually result in hard-to-debug backend crashes. Summary ------- SILInstruction Old New +---------------+ +------------------+ +-----------------+ |SILInstruction | |SILInstruction | |SILDebugLocation | +---------------+ +------------------+ +-----------------+ | ... | | ... | | ... | |SILLocation | |SILDebugLocation *| -> |SILLocation | |SILDebugScope *| +------------------+ |SILDebugScope * | +---------------+ +-----------------+ We’re introducing a new class SILDebugLocation which represents the combination of a SILLocation and a SILDebugScope. Instead of storing an inline SILLocation and a SILDebugScope pointer, SILInstruction now only has one SILDebugLocation pointer. The APIs of SILBuilder and SILDebugLocation guarantees that every SILInstruction has a nonempty SILDebugScope. Developer-visible changes include: SILBuilder ---------- In the old design SILBuilder populated the InsertedInstrs list to allow setting the debug scopes of all built instructions in bulk at the very end (as the responsibility of the user). In the new design, SILBuilder now carries a "current debug scope" state and immediately sets the debug scope when an instruction is inserted. This fixes a use-after-free issue with with SIL passes that delete instructions before destroying the SILBuilder that created them. Because of this, SILBuilderWithScopes no longer needs to be a template, which simplifies its call sites. SILInstruction -------------- It is neither possible or necessary to manually call setDebugScope() on a SILInstruction any more. The function still exists as a private method, but is only used when splicing instructions from one function to another. Efficiency ---------- In addition to dropping 20 bytes from each SILInstruction, SILDebugLocations are now allocated in the SILModule's bump pointer allocator and are uniqued by SILBuilder. Unfortunately repeat compiles of the standard library already vary by about 5% so I couldn’t yet produce reliable numbers for how much this saves overall. rdar://problem/22017421