Commit Graph

2202 Commits

Author SHA1 Message Date
Adrian Prantl
7821341542 Add an argument-number field to DebugValueInst and friends.
This commit adds a DebugVariable field that is shared by
- AllocBoxInst
- AllocStackInst
- DebugValueInst
- DebugValueAddrInst
Currently DebugVariable only holds the Swift argument number.

This allows us to retire several expensive heuristics in IRGen that
attempted to identify which local variables actually where arguments
and recover their relative order.

Memory footprint notes:
This commit adds a 4-byte field to 4 SILInstructin subclasses.
This was offset by 8ab1e2dd50
which removed 20 bytes from *every* SILInstruction.

Caveats:
This commit surfaces a known bug in FunctionSigantureOpts, tracked in
rdar://problem/23727705 — debug info for exploded function arguments
cannot be expressed until this is fixed.

This reapplies ed2b16dc5a with a bugfix for
generic function arrguments and an additional testcase.

<rdar://problem/21185379&22705926>
2015-12-03 13:40:35 -08:00
Adrian Prantl
717b017ebe Remove redundant code used for debugging. (NFC) 2015-12-03 08:30:30 -08:00
Adrian Prantl
2740ad6976 Temporarily Revert "Add an argument-number field to DebugValueInst and friends."
while investigating buildbot breakage.

This reverts commit ed2b16dc5a.
2015-12-02 19:10:05 -08:00
Adrian Prantl
ed2b16dc5a Add an argument-number field to DebugValueInst and friends.
This commit adds a DebugVariable field that is shared by
- AllocBoxInst
- AllocStackInst
- DebugValueInst
- DebugValueAddrInst
Currently DebugVariable only holds the Swift argument number.

This allows us to retire several expensive heuristics in IRGen that
attempted to identify which local variables actually where arguments
and recover their relative order.

Memory footprint notes:
This commit adds a 4-byte field to 4 SILInstructin subclasses.
This was offset by 8ab1e2dd50
which removed 20 bytes from *every* SILInstruction.

Caveats:
This commit surfaces a known bug in FunctionSigantureOpts, tracked in
rdar://problem/23727705 — debug info for exploded function arguments
cannot be expressed until this is fixed.

<rdar://problem/21185379&22705926>
2015-12-02 18:33:07 -08:00
Roman Levenstein
5cc14abb82 [sil-devirtualizer] Improve devirtualization of witness_method instructions.
Handle such cases like partial applications of witness methods and applications of witness methods with substitutions.

Some of these uses-cases occur when there is a protocol defining an operator, a generic struct conforming to this protocol, and the operator conformance of this struct is expressed as a global function.
2015-12-01 14:49:47 -08:00
Erik Eckstein
bd70851769 SIL: Fix mayRelease() for BuiltinInst 2015-11-30 13:11:00 -08:00
Nadav Rotem
5542bc3792 [Serialization] Fix a bug in the serialization of resilient functions
The SIL serializer can decide not to serialize the body of functions in the SIL
module, and only emit a declaration.  If we keep the original linkage kind
(public, private, etc) then the deserialized module won't pass verification
because we do not allow internal functions to have external declarations. This
commit changes the linkage kind for the functions that the serializer decides to
emit as a declaration (without a body).

rdar://21989088
2015-11-28 03:04:56 -08:00
Adrian Prantl
de8faa0094 Update comments. 2015-11-19 13:59:11 -08:00
Adrian Prantl
83b44be215 Out-line the definition of ScopeCloner::getOrCreateClonedScope(). NFC 2015-11-19 13:59:11 -08:00
Adrian Prantl
8ab1e2dd50 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
2015-11-19 09:31:26 -08:00
Roman Levenstein
5a4888236d Revert "Re-apply "Reduce memory footprint of the Swift compiler""
This reverts commit bf2fdb6764.

One of the build bots reported a malloc/free error, while other bots had successful builds. It could indicate a non-deterministic failure.
Preventively revert this patch as it is the most likely cause of these issues.

rdar://23611346
2015-11-19 07:56:57 -08:00
Roman Levenstein
bf2fdb6764 Re-apply "Reduce memory footprint of the Swift compiler"
Use malloc/free for allocating/freeing SIL instructions instead of using the BumpPtrAllocator. This allows for memory reuse and significantly reduces the memory footprint of the compiler.

For example, a peak memory usage during a compilation of the standard library and StdlibUnitTest is reduced by 25%-30%. The performance of the compiler seems to be not affected by this change, i.e. no slowdown is measured.

The use-after-free issue reported by build bots is fixed now.

rdar://23303031
2015-11-18 18:14:29 -08:00
Ted Kremenek
8b6d9e9edb Revert "Reduce memory footprint of the Swift compiler"
This reverts commit d58f9486b1.
2015-11-17 21:22:40 -08:00
Roman Levenstein
d58f9486b1 Reduce memory footprint of the Swift compiler
Use malloc/free for allocating/freeing SIL instructions instead of using the BumpPtrAllocator. This allows for memory reuse and significantly reduces the memory footprint of the compiler.

For example, a peak memory usage during a compilation of the standard library and StdlibUnitTest is reduced by 25%-30%. The performance of the compiler seems to be not affected by this change, i.e. no slowdown is measured.

rdar://23303031
2015-11-17 17:26:35 -08:00
Erik Eckstein
7f2522b92e Use getCalleeFunction in some places to simplify code. NFC 2015-11-15 18:29:54 -08:00
Erik Eckstein
ea5c51ae04 SIL: add getCalleeFunction utility also in ApplySite 2015-11-15 18:29:54 -08:00
Erik Eckstein
3e894f3831 SIL: rename getCalledFunction to getCalleeFunction in ApplyInstBase 2015-11-15 18:29:53 -08:00
Slava Pestov
57dd686742 Strawman @fixed_layout attribute and -{enable,disable}-resilience flags
A fixed layout type is one about which the compiler is allowed to
make certain assumptions across resilience domains. The assumptions
will be documented elsewhere, but for the purposes of this patch
series, they will include:

- the size of the type
- offsets of stored properties
- whether accessed properties are stored or computed

When -enable-resilience is passed to the frontend, all types become
resilient unless annotated with the @fixed_layout attribute.

So far, the @fixed_layout attribute only comes into play in SIL type
lowering of structs and enums, which now become address-only unless
they are @fixed_layout. For now, @fixed_layout is also allowed on
classes, but has no effect. In the future, support for less resilient
type lowering within a single resilience domain will be added, with
appropriate loads and stores in function prologs and epilogs.

Resilience is not enabled by default, which gives all types fixed
layout and matches the behavior of the compiler today. Since
we do not want the -enable-resilience flag to change the behavior
of existing compiled modules, only the currently-compiling module,
Sema adds the @fixed_layout flag to all declarations when the flag
is off. To reduce the size of .swiftmodule files, this could become
a flag on the module itself in the future.

The reasoning behind this is that the usual case is building
applications and private frameworks, where there is no need to make
anything resilient.

For the standard library, we can start out with resilience disabled,
while perfoming an audit adding @fixed_layout annotations in the
right places. Once the implementation is robust enough we can then
build the standard library with resilience enabled.
2015-11-13 13:20:49 -08:00
Erik Eckstein
329df40380 SIL: add a helper function to get the called function of an apply instruction. 2015-11-13 09:41:09 -08:00
Michael Gottesman
7820961891 Revert commits to fix the build.
Revert "Fix complete_decl_attribute test for @fixed_layout"
Revert "Sema: non-@objc private stored properties do not need accessors"
Revert "Sema: Access stored properties of resilient structs through accessors"
Revert "Strawman @fixed_layout attribute and -{enable,disable}-resilience flags"

This reverts commit c91c6a789e.
This reverts commit 693d3d339f.
This reverts commit 085f88f616.
This reverts commit 5d99dc9bb8.
2015-11-12 10:40:54 -08:00
Slava Pestov
5d99dc9bb8 Strawman @fixed_layout attribute and -{enable,disable}-resilience flags
A fixed layout type is one about which the compiler is allowed to
make certain assumptions across resilience domains. The assumptions
will be documented elsewhere, but for the purposes of this patch
series, they will include:

- the size of the type
- offsets of stored properties
- whether accessed properties are stored or computed

When -enable-resilience is passed to the frontend, all types become
resilient unless annotated with the @fixed_layout attribute.

So far, the @fixed_layout attribute only comes into play in SIL type
lowering of structs and enums, which now become address-only unless
they are @fixed_layout. For now, @fixed_layout is also allowed on
classes, but has no effect. In the future, support for less resilient
type lowering within a single resilience domain will be added, with
appropriate loads and stores in function prologs and epilogs.

Resilience is not enabled by default, which gives all types fixed
layout and matches the behavior of the compiler today. Since
we do not want the -enable-resilience flag to change the behavior
of existing compiled modules, only the currently-compiling module,
Sema adds the @fixed_layout flag to all declarations when the flag
is off. To reduce the size of .swiftmodule files, this could become
a flag on the module itself in the future.

The reasoning behind this is that the usual case is building
applications and private frameworks, where there is no need to make
anything resilient.

For the standard library, we can start out with resilience disabled,
while perfoming an audit adding @fixed_layout annotations in the
right places. Once the implementation is robust enough we can then
build the standard library with resilience enabled.
2015-11-12 02:30:07 -08:00
Nadav Rotem
7192b28f49 Fix another iterator invalidation bug. 💥 2015-11-11 22:38:00 -08:00
Michael Gottesman
9fb54bf4bf Fix for upstream ilist changes. 2015-11-11 16:07:41 -08:00
Xin Tong
70284daff4 [RLE-DSE] Refactor SILValueProjection. NFC 2015-11-10 14:04:25 -08:00
Xin Tong
50feb1e25d [RLE-DSE] Refactor MemLocation. NFC 2015-11-10 13:59:57 -08:00
Xin Tong
f1d4ef7fc2 [RLE-DSE] Create a superclass for MemLocation and LoadStoreValue. These two share a lot
of identical fields, e.g. Base, ProjectionPath and Kind.

This is a refactoring change. Existing tests ensures correctness
2015-11-10 13:46:33 -08:00
Xin Tong
d90054f481 [RLE-DSE] Remove local stores that are not read before function exits.
This is currently disabled. we are going to have a fix in the swift UnsafeBitCast
and TBAA that this commit depends on.

rdar://23337393
2015-11-09 16:01:51 -08:00
Xin Tong
3c93dbbc58 [RLE-DSE] Implement the actual redundant load elimination (RLE)
data flow. This should handle some simple RLE. but not phi-node, i.e.
SILArguments.

Also, the new RLE implemented in this patch is disabled by default (behind
a flag). we are working on post-commit review.
2015-11-09 15:44:39 -08:00
Erik Eckstein
6fcb9ebb26 Fix cloning of (de)alloc_stack [stack]
And remove the default value for the canAllocOnStack parameter in SILBuilder (which was a bad idea to add it).
2015-11-08 13:59:43 -08:00
Xin Tong
fd8b9339a2 This reverts commit 794df2d91f
A bug is exposed by replacing the old RLE. Revert back the old RLE.
The bug itself is unlikely to be in neither the old nor the new RLE though.
2015-11-08 10:34:25 -08:00
Xin Tong
4ff7c73b60 Revert "[RLE-DSE] Remove local stores that are not read before function exits."
This reverts commit d11b6d69ee.
2015-11-08 10:21:58 -08:00
Xin Tong
bbda1d3610 Revert "[RLE-DSE] Refactor for RLE. NFC"
This reverts commit 321b0f6b2f.
2015-11-08 10:20:49 -08:00
Xin Tong
c7360948de Revert "[RLE-DSE] Remove an obsolete file for RLE and DSE"
This reverts commit 7999b70a5d.
2015-11-08 10:20:17 -08:00
Xin Tong
2789e48676 Revert "[RLE-DSE] Create a superclass for MemLocation and LoadStoreValue. These two share a lot"
This reverts commit 389b723226.
2015-11-08 10:19:52 -08:00
Xin Tong
389b723226 [RLE-DSE] Create a superclass for MemLocation and LoadStoreValue. These two share a lot
of identical fields, e.g. Base, ProjectionPath and Kind.

This is a refactoring change. Existing tests ensures correctness
2015-11-06 15:43:35 -08:00
Xin Tong
7999b70a5d [RLE-DSE] Remove an obsolete file for RLE and DSE 2015-11-06 14:16:57 -08:00
Xin Tong
321b0f6b2f [RLE-DSE] Refactor for RLE. NFC 2015-11-06 13:52:19 -08:00
Slava Pestov
91cf4c11da SIL: Move description of abstraction patterns to AbstractionPattern.h and write new comment in SILGenPoly describing function thunks, NFC
Probably SILGenPoly.cpp should be named SILGenThunk.cpp, but I'm saving
that for if I ever extract the duplication between bridging thunks and
re-abstraction thunks.
2015-11-05 21:49:23 -08:00
Slava Pestov
736beddf1b SILGen: Cleanup, NFC 2015-11-05 21:46:04 -08:00
Mark Lacey
dae482e173 Add SILInstruction::mayRelease().
Refines the results of getReleasingBehavior() by checking the
consumption kind of UnconditionalCheckedCastAddrInst and
CheckedCastAddrBranchInst, as well as whether a CopyAddrInst is an
initialization.
2015-11-05 20:23:49 -08:00
Mark Lacey
1b0f133b34 Mark TryApplyInst as an instruction that MayRelease. 2015-11-05 16:36:28 -08:00
Xin Tong
d11b6d69ee [RLE-DSE] Remove local stores that are not read before function exits.
This is currently disabled. we are going to have a fix in the swift UnsafeBitCast
and TBAA that this commit depends on.

rdar://23337393
2015-11-05 15:24:36 -08:00
Mark Lacey
d3751d8dab Mark ApplyInst as an instruction that may release. 2015-11-05 15:16:40 -08:00
Xin Tong
794df2d91f [RLE-DSE] Implement the actual redundant load elimination (RLE)
data flow. This should handle some simple RLE. but not phi-node, i.e.
SILArguments.

Also, the new RLE implemented in this patch is disabled by default (behind
a flag). we are working on post-commit review.
2015-11-05 11:17:02 -08:00
Xin Tong
9cb86737fd [RLE-DSE] Implement LoadStoreValue in MemLocation.cpp. LoadStoreValue represents
the value residing in a given MemLocation. In RLE, we create a map between
MemLocation and its corresponding LoadStoreValue.
2015-11-05 10:03:31 -08:00
Mark Lacey
5eb64493e4 Add the notion of releasing instructions to SILNodes.def.
This will be used in call graph construction so that we can model calls
to deinits that are potentially called as a result of executing
instructions that can end up releasing memory.
2015-11-04 14:05:09 -08:00
Adrian Prantl
33f71c95a9 Simplify/Unify the constructors of SILLocation. (NFC) 2015-11-04 10:37:50 -08:00
Adrian Prantl
6baf5c629a Cleanup the comments in SILLocation. 2015-11-03 13:45:02 -08:00
Michael Gottesman
a2a6a32983 Fix leak in function signature opts.
rdar://23346077
2015-11-02 11:07:56 -08:00
Slava Pestov
406d448db2 SIL: Rename Module to ModuleDecl due to FIXME, NFC
Swift SVN r32943
2015-10-28 18:28:59 +00:00