Commit Graph

55 Commits

Author SHA1 Message Date
Mark Lacey
bdc5667d1a Assert that we aren't erasing a block argument that has uses.
This fires in a bug I am investigating.
2016-03-07 15:49:50 -08:00
Adrian Prantl
310b0433a9 Reapply "Serialize debug scope and location info in the SIL assembler language.""
This ireapplies commit 255c52de9f.

Original commit message:

Serialize debug scope and location info in the SIL assembler language.
At the moment it is only possible to test the effects that SIL
optimization passes have on debug information by observing the
effects of a full .swift -> LLVM IR compilation. This change enable us
to write targeted testcases for single SIL optimization passes.

The new syntax is as follows:

 sil-scope-ref ::= 'scope' [0-9]+
 sil-scope ::= 'sil_scope' [0-9]+ '{'
                 sil-loc
                 'parent' scope-parent
                 ('inlined_at' sil-scope-ref )?
               '}'
 scope-parent ::= sil-function-name ':' sil-type
 scope-parent ::= sil-scope-ref
 sil-loc ::= 'loc' string-literal ':' [0-9]+ ':' [0-9]+

Each instruction may have a debug location and a SIL scope reference
at the end.  Debug locations consist of a filename, a line number, and
a column number.  If the debug location is omitted, it defaults to the
location in the SIL source file.  SIL scopes describe the position
inside the lexical scope structure that the Swift expression a SIL
instruction was generated from had originally. SIL scopes also hold
inlining information.

<rdar://problem/22706994>
2016-02-26 13:28:57 -08:00
Adrian Prantl
255c52de9f Revert "Serialize debug scope and location info in the SIL assembler language."
Temporarily reverting while updating the validation test suite.

This reverts commit c9927f66f0.
2016-02-26 11:51:57 -08:00
Adrian Prantl
c9927f66f0 Serialize debug scope and location info in the SIL assembler language.
At the moment it is only possible to test the effects that SIL
optimization passes have on debug information by observing the
effects of a full .swift -> LLVM IR compilation. This change enable us
to write targeted testcases for single SIL optimization passes.

The new syntax is as follows:

 sil-scope-ref ::= 'scope' [0-9]+
 sil-scope ::= 'sil_scope' [0-9]+ '{'
                 sil-loc
                 'parent' scope-parent
                 ('inlined_at' sil-scope-ref )?
               '}'
 scope-parent ::= sil-function-name ':' sil-type
 scope-parent ::= sil-scope-ref
 sil-loc ::= 'loc' string-literal ':' [0-9]+ ':' [0-9]+

Each instruction may have a debug location and a SIL scope reference
at the end.  Debug locations consist of a filename, a line number, and
a column number.  If the debug location is omitted, it defaults to the
location in the SIL source file.  SIL scopes describe the position
inside the lexical scope structure that the Swift expression a SIL
instruction was generated from had originally. SIL scopes also hold
inlining information.

<rdar://problem/22706994>
2016-02-26 10:46:29 -08:00
Adrian Prantl
75fc840126 Merge the parent scope and function fields of SILDebugScope into a
PointerUnion.

This saves 8 bytes per SILDebugScope.

rdar://problem/22706994
2016-01-29 17:21:26 -08:00
practicalswift
50baf2e53b Use consistent formatting in top of file headers. 2016-01-04 02:17:48 +01:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Roman Levenstein
46b58ac699 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 issues reported by build bots are fixed now.

rdar://23303031
2015-12-10 08:36:59 -08:00
Nadav Rotem
9233217ded [ValueHandle] Allow invalidation of BB arguments.
This commit changes the invalidation handler from SILInstruction to ValueBase,
and also invalidates SILArguments.
2015-12-04 17:32:16 -08:00
Roman Levenstein
4d02520424 Send delete notifications when basic block arguments are being erased. 2015-12-04 16:00:02 -08:00
Roman Levenstein
64161c34bc Trigger delete notifications only when instructions are erased
We don't want to be notified when instructions are removed and later inserted at a different place, e.g. as part of SILInstruction::moveBefore.
2015-12-04 14:27:32 -08:00
Nadav Rotem
37991af1cf [SIL] Add support for delete notification handlers.
This commit adds the basic support for delete notification handlers. The SIL
Module is notified every time an instruction is deleted. The module will forward
notification messages to users who ask to be notified.  The motivation for this
work is described in the upcoming commit to OptimizerDesign.md.
2015-12-04 07:37:12 -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
Michael Gottesman
9fb54bf4bf Fix for upstream ilist changes. 2015-11-11 16:07:41 -08:00
Mark Lacey
263cbdce03 Revert "Hook instruction insertion & removal."
This reverts commit r32359.

I'll look into doing fine-grained rebuilds of portions of the call graph
after some other changes go in that will make that more reasonable to
do.

Swift SVN r32379
2015-10-01 20:31:19 +00:00
Mark Lacey
48b0e18e23 Hook instruction insertion & removal.
Call back to the SILModule to notify of instructions being inserted or
removed from basic blocks.

The intent is to use this to notify the call graph (if one exists and
the module knows about it). We can then use these notifications to
automatically update the call graph.

Swift SVN r32359
2015-10-01 02:43:33 +00:00
Mark Lacey
a3fd30276e Remove SILBasicBlock::getInstList().
There's no longer a need to directly access the instruction list.

Swift SVN r32349
2015-09-30 21:36:46 +00:00
Mark Lacey
0c9fb63d60 Add push_front()/push_back() to SILBasicBlock.
Use these in place of getInstList().push_front()/push_back().

Swift SVN r32319
2015-09-29 23:22:18 +00:00
Mark Lacey
46b2de075e Add instruction list manipulation functions to SILBasicBlock.
Begin using these functions to encapsulate the instruction list rather
than directly accessing it via getInstList().

Swift SVN r32298
2015-09-29 06:35:49 +00:00
Mark Lacey
9bfc4c431a More conversion to using SILBuilder for instruction creation.
Move the implementation of SILBasicBlock::splitBasicBlockAndBranch into
CFG's util function swift::splitBasicBlockAndBranch since it's the only
user, and update the latter to take a SILBuilder and use it to create
the branch to the split-off block.

Swift SVN r32128
2015-09-21 21:47:05 +00:00
Adrian Prantl
1daaf310fb Revert "Reverting commits 29181-29187 to investigate buildbot breakage."
This reverts commit 29189.

Swift SVN r29191
2015-05-31 17:38:32 +00:00
Adrian Prantl
b994bde5b5 Reverting commits 29181-29187 to investigate buildbot breakage.
Swift SVN r29190
2015-05-31 06:13:03 +00:00
Adrian Prantl
6ad0679106 Make a deep copy of SILDebugScopes when doing a SILBasicBlock::splice()>
The cloned abstract variables may end up having different types
so they need to be distinct from the originals.

This fixes an crash/assertion in the LLVM backend.
rdar://problem/21109015

Swift SVN r29184
2015-05-31 05:39:30 +00:00
Michael Gottesman
3c217614b0 [g-arc-opts] Use RCStateTransitions when processing arguments as well.
Swift SVN r26914
2015-04-02 23:24:13 +00:00
Erik Eckstein
c2776c455b Rename SILBasicBlock::getID() -> getDebugID()
Swift SVN r24321
2015-01-09 19:37:03 +00:00
Erik Eckstein
a2f78d768f Add SILBasicBlock::getID() for dumping the block index in debug output.
Swift SVN r24308
2015-01-09 17:04:29 +00:00
Chris Lattner
f460716430 add a SILBasicBlock::removeWithParent method with the obvious semantics
(following LLVM IR), NFC.


Swift SVN r24298
2015-01-09 05:33:32 +00:00
John McCall
b6eb086af8 Add a rather hacky builtin function for constructing
a materializeForSet callback from a closure.

Swift SVN r23993
2014-12-17 22:23:26 +00:00
Michael Gottesman
1afc987739 Refactor the SILArgument API on SILBasicBlock so we can insert bb arguments anywhere in the argument list. Also clean up the API names so that they all match.
Swift SVN r23543
2014-11-22 00:24:40 +00:00
Michael Gottesman
c97ab1f11f [func-sig-opts] When splicing BB from one function to another, change
the debug scope of each instruction to be the debug scope of the new
function.

This will be tested by the functionality in function signature opts.

Swift SVN r22553
2014-10-06 23:16:52 +00:00
Michael Gottesman
ed124f6651 [func-sig-opts] Expose the ValueDecl argument of SILArgument's
constructor in SILBasicBlock::createArgument.

By default the argument is nullptr so any place that currently does not
need to pass in the ValueDecl will not need to be updated given the new
behavior.

Swift SVN r22379
2014-09-30 03:08:50 +00:00
Michael Gottesman
d3b9679795 Add the method SILArgument::getIncomingValues and refactor SILArgument implementation from SILBasicBlock.cpp => SILArgument.cpp.
SILArgument::getIncomingValues() takes in an out array parameter and attempts to
gather up all values from the SILArguments parents predecessors whose value the
SILArgument could take on.

This will let me refactor the single predecessor handling code to also handle
multiple predecessors in a simple way.

Swift SVN r21864
2014-09-11 01:53:29 +00:00
Michael Gottesman
225a5ca87b [func-sig-opts] Add the call SILFunction::spliceBody() to splice a function's body onto another function.
I also added code to ilist_traits so we can set the parent function on BB to be the new function.

Swift SVN r21729
2014-09-04 23:34:34 +00:00
Michael Gottesman
0f7053bd01 Remove SILBasicBlock::getBBArgIndex(SILArgument *) in favor of SILArgument::getIndex().
The index is a property of the argument. There is no reason from a modeling
perspective to go through the BB to get it.

Swift SVN r21338
2014-08-21 04:06:19 +00:00
Arnold Schwaighofer
2e83bdf01b Add a convenience function on SILBasicBlock to move it after another Block
Swift SVN r19633
2014-07-07 21:05:22 +00:00
John McCall
cd6fc21900 Allow SILBasicBlocks to be constructed after a specific
block, and do so when splitting a block.

Swift SVN r19076
2014-06-22 05:01:06 +00:00
Nadav Rotem
1b650dcdf6 Add helper functions to SILBlock and SILFunction.
Swift SVN r18858
2014-06-13 06:10:07 +00:00
Mark Lacey
8156008cd8 Add a dead code elimination optimization pass.
In a loop like this:
  var j = 2
  for var i = 0; i < 100; ++i {
    j += 3
  }
it will completely eliminate j.

It does not yet support rewriting conditional branches as unconditional
branches in the cases where only empty blocks are control dependent on
an edge. Once this support is added, it will also completely eliminate
the loop itself.

Swift SVN r18615
2014-05-24 07:02:18 +00:00
Mark Lacey
924e30ea61 Rewrite BB args whose only use is in struct/tuple extract.
If we have BB args that are only used in a struct/tuple extract, and
that are generated in each predecessor with a struct/tuple instruction,
retype the BB arg and replace the argument with what would have been the
extracted value.

This provides more opportunties for jump threading to kick in.

Swift SVN r16509
2014-04-18 07:19:33 +00:00
Dmitri Hrybenko
be7759b149 Track uptstream LLVM API change: llvm::next() was removed, use std::next() instead
Swift SVN r14572
2014-03-02 13:32:30 +00:00
Adrian Prantl
c610ac94ef Add an IsBare attribute to SILFunction for functions that do not have an
AST.

Swift SVN r11236
2013-12-13 04:48:37 +00:00
Adrian Prantl
2acb71831e SILArgument: Make Decls mandatory for function arguments.
Swift SVN r11099
2013-12-10 23:30:23 +00:00
Stephen Lin
3f5c0dbf0e Update SILArgument::getModule(), SILBasicBlock::getModule() and SILInstruction::getModule() signatures to match SILFunction::getModule(), for consistency; standardize usage of SILFunction::getParent() to SILFunction::getModule().
Swift SVN r8932
2013-10-04 21:12:20 +00:00
Adrian Prantl
8808d48578 Debug info: emit captured variables in closures. rdar://problem/15035486
Swift SVN r8859
2013-10-02 22:46:03 +00:00
Anna Zaks
4d7de376bb [SIL] Refactor splitBasicBlock() into splitBasicBlock and splitBasicBlockAndBranch
This API is more explicit and avoids relying on passing around empty SILLocation.
(No functional change.)

Swift SVN r7988
2013-09-06 17:46:12 +00:00
Michael Gottesman
c86a54a438 Renamed SILBasicBlock::getInsts() => SILBasicBlock::getInstList() as discussed on the list.
Swift SVN r7776
2013-08-30 03:40:37 +00:00
Ted Kremenek
8f5b8ccb02 Rename "This" to "Self" and "this" to "self".
This was not likely an error-free change.  Where you see problems
please correct them.  This went through a fairly tedious audit
before committing, but comments might have been changed incorrectly,
not changed at all, etc.

Swift SVN r7631
2013-08-27 21:58:27 +00:00
Stephen Lin
4ae68cd72f Completion of MandatoryInlining pass: recursive inlining, multiple basic blocks, and diagnosis of circular inlining.
Swift SVN r7242
2013-08-14 22:30:21 +00:00
Anna Zaks
e5c3a7ea80 [SIL] Make sure SILBasicBlock destructor gets called.
This also ensures that the instructions indie the basic block
get destructed.

Swift SVN r6667
2013-07-27 00:25:03 +00:00