Commit Graph

115 Commits

Author SHA1 Message Date
Nadav Rotem
d78b376d07 [passes] Replace the old invalidation lattice with a new invalidation scheme.
The old invalidation lattice was incorrect because changes to control flow could cause changes to the
call graph, so we've decided to change the way passes invalidate analysis.  In the new scheme, the lattice
is replaced with a list of traits that passes preserve or invalidate. The current traits are Calls and Branches.
Now, passes report which traits they preserve, which is the opposite of the previous implementation where
passes needed to report what they invalidate.

Node: I tried to limit the changes in this commit to mechanical changes to ease the review. I will cleanup some
of the code in a following commit.

Swift SVN r26449
2015-03-23 21:18:58 +00:00
Chris Lattner
4f708c049b fix const correctness and standardize on names for the successor list of
TerminatorInsts.  Now you can walk over the successor list of a terminator
and actually modify the SILSuccessor directly, allowing better CFG
transformations.  NFC.




Swift SVN r26140
2015-03-14 17:52:27 +00:00
Dmitri Hrybenko
61286f0260 Fix warnings produced by a newer version of Clang
Swift SVN r25257
2015-02-12 23:50:47 +00:00
Mark Lacey
ebdf975fdc Use the lifetime endpoints that we have already queried for.
Swift SVN r25180
2015-02-11 10:30:42 +00:00
Mark Lacey
2709a6626e Fix issue with where we release boxes in AllocBoxToStack.
When we specialize a partial_apply to remove boxes that were arguments
to the partial_apply, we release the box explicitly (since it will no
longer get released as part of releasing the partial_apply).

We were putting these releases before the partial_apply, only worked
properly in cases where those releases were not the final release of the
box.

With this commit we now release the box at each point where the
partial_apply goes dead.

Fixes rdar://problem/17892969.

Swift SVN r25177
2015-02-11 10:17:05 +00:00
Erik Eckstein
9dfd349faf Add a new Thunk-flag in SILFunction which specifies that a function is a thunk.
This will have an effect on inlining into thunks.
Currently this flag is set for witness thunks and thunks from function signature optimization.
No change in code generation, yet.



Swift SVN r24998
2015-02-05 16:45:05 +00:00
Michael Gottesman
897325b096 Codebase Gardening. NFC.
1. Eliminate unused variable warnings.
2. Change field names to match capitalization of the rest of the field names in the file.
3. Change method names to match rest of the file.
4. Change get,set method for a field to match the field type.

Swift SVN r24501
2015-01-19 00:34:07 +00:00
Mark Lacey
465db2121a Fix AllocBoxToStack cloning problem described in rdar://problem/19287131.
Recent name mangling changes resulted in AllocBoxToStack cloning the
referenced function of a partial apply once for every reference (i.e. we
would end up with N copies within the cloned function if there were N
references).

Fix this by checking for an already existing function *outside* of the
cloner rather than inside of it.

Swift SVN r24005
2014-12-18 10:25:47 +00:00
Michael Gottesman
b992933948 [mangle] Add mangling for alloc box to stack. This is the last one for real = ).
<rdar://problem/19216289>

Swift SVN r23925
2014-12-14 10:29:13 +00:00
Erik Eckstein
14af3a57e8 Enable elimination of dead methods which are in classes of higher visibility.
The underlying problem is that e.g. even if a method is private but its class is public, the method can be referenced from another module - from the vtable of a derived class.
So far we handled this by setting the SILLinkage of such methods according to the visibility of the class. But this prevented dead method elimination.
Now I set the SILLinkage according to the visibility of the method. This enables dead method elimination, but it requires the following:
1) Still set the linkage in llvm so that it can be referenced from outside.
2) If the method is dead and eliminated, create a stub for it (which calls swift_reportMissingMethod).



Swift SVN r23889
2014-12-12 17:35:40 +00:00
Mark Lacey
eaaf7aa5d4 Fix leak caused by allocbox-to-stack.
In allocbox-to-stack we were cloning closures to remove box parameters
but in the process we were also removing the release on the box. We
still need to release it so that if it is the last reference anything it
owns gets released.

This change inserts the release before the partial_apply.

Fixes rdar://problem/17872402.

Swift SVN r23876
2014-12-12 02:59:41 +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
Ben Langmuir
e9e1666ab0 Update for upstream LLVM changes
* removal of StringMap's GetOrCreateValue
* SmallSet::insert now returns a pair like std::set

Swift SVN r23435
2014-11-19 16:49:30 +00:00
Adrian Prantl
c41b30299f Audit all SILPasses to ensure that new instructions are never created
without a valid SILDebugScope. An assertion in IRGenSIL prevents future
optimizations from regressing in this regard.
Introducing SILBuilderWithScope and SILBuilderwithPostprocess to ease the
transition.

This patch is large, but mostly mechanical.
<rdar://problem/18494573> Swift: Debugger is not stopping at the set breakpoint

Swift SVN r22978
2014-10-28 01:49:11 +00:00
Mark Lacey
9180f07c8d Some clean-up of box-to-stack promotion.
There were some simplifications a while ago that makes some of the code
unnecessary at this point. NFC.

Swift SVN r22530
2014-10-05 22:15:40 +00:00
Joe Groff
782833f054 SIL: Remove the project_existential* instructions.
Swift SVN r22457
2014-10-02 04:06:10 +00:00
Joe Groff
3a606b9eb8 SIL: Drop the protocol_method instruction.
Swift SVN r22446
2014-10-01 23:35:41 +00:00
Erik Eckstein
c16c510167 Set SILLinkage according to visibility.
Now the SILLinkage for functions and global variables is according to the swift visibility (private, internal or public).

In addition, the fact whether a function or global variable is considered as fragile, is kept in a separate flag at SIL level.
Previously the linkage was used for this (e.g. no inlining of less visible functions to more visible functions). But it had no effect,
because everything was public anyway.

For now this isFragile-flag is set for public transparent functions and for everything if a module is compiled with -sil-serialize-all,
i.e. for the stdlib.

For details see <rdar://problem/18201785> Set SILLinkage correctly and better handling of fragile functions.

The benefits of this change are:
*) Enable to eliminate unused private and internal functions
*) It should be possible now to use private in the stdlib
*) The symbol linkage is as one would expect (previously almost all symbols were public).

More details:

Specializations from fragile functions (e.g. from the stdlib) now get linkonce_odr,default
linkage instead of linkonce_odr,hidden, i.e. they have public visibility.
The reason is: if such a function is called from another fragile function (in the same module),
then it has to be visible from a third module, in case the fragile caller is inlined but not
the specialized function.

I had to update lots of test files, because many CHECK-LABEL lines include the linkage, which has changed.

The -sil-serialize-all option is now handled at SILGen and not at the Serializer.
This means that test files in sil format which are compiled with -sil-serialize-all
must have the [fragile] attribute set for all functions and globals.

The -disable-access-control option doesn't help anymore if the accessed module is not compiled
with -sil-serialize-all, because the linker will complain about unresolved symbols.

A final note: I tried to consider all the implications of this change, but it's not a low-risk change.
If you have any comments, please let me know.



Swift SVN r22215
2014-09-23 12:33:18 +00:00
Erik Eckstein
99cc7603be Add an @inline(__always) function attribute.
This will let the performance inliner inline a function even if the costs are too high.
This attribute is only a hint to the inliner.
If the inliner has other good reasons not to inline a function,
it will ignore this attribute. For example if it is a recursive function (which is
currently not supported by the inliner).

Note that setting the inline threshold to 0 does disable performance inlining at all and in
this case also the @inline(__always) has no effect.



Swift SVN r21452
2014-08-26 00:56:34 +00:00
Nadav Rotem
8dd52d63cd Add the @effects(readonly/readnone/readwrite) attribute.
Swift SVN r21070
2014-08-06 18:48:20 +00:00
Mark Lacey
28731b0a69 Fix crash in box-to-stack promotion.
Don't crash in the case where we cannot find the final release of a box
along every return path. Instead, just bail out on promoting that box.

<rdar://problem/17455386>

Swift SVN r20874
2014-08-01 01:26:20 +00:00
Manman Ren
8f0ba461b3 NFC: comment typo.
Swift SVN r20195
2014-07-19 00:43:24 +00:00
Michael Gottesman
e8d4ec401b Fix some unused variable warnings during -DNDEBUG build due to variables only being used in asserts.
Swift SVN r19988
2014-07-15 22:12:51 +00:00
Joe Groff
45eec9a2e9 Remove 'interface' from the method names of SILFunctionType.
SILFunctionTypes are always interface types now. NFC.

Swift SVN r19952
2014-07-14 22:03:46 +00:00
Manman Ren
ae9f2e25ae [@semantics] add SemanticsAttr to SILFunction.
Enable SIL parsing and SIL serialization of semantics.

We add one more field to SILFunctionLayout for semantics. We should refactor
handling of attributes at SIL level, right now they are in SILFunction as bool
or std::string and in SIL serializer as a 1-bit field or an ID field.

rdar://17525564


Swift SVN r19434
2014-07-01 22:49:46 +00:00
Manman Ren
7667b829bb [noinline attribute] add noinline attribute.
Propagate it to SILFunction and use it in PerformanceInliner. We also serialize
and parse the attribute.

rdar://15882816


Swift SVN r19150
2014-06-24 23:07:45 +00:00
Adrian Prantl
17e3604b43 Make sure all non-inlining uses of SILCloner also clone the SILDebugScope
hierarchy. I still need to figure out a reliable way to write testcases
for this. For now it's ensured via an assertion in SILCloner::postprocess.

Swift SVN r18917
2014-06-15 20:50:49 +00:00
Mark Lacey
aaed5a7822 Promote boxes that are passed to generic partial_apply.
Swift SVN r16858
2014-04-26 00:07:33 +00:00
Mark Lacey
009c7a7242 Fix placement of alloc_stack/dealloc_stack
Update the box-to-stack promotion pass to place the newly promoted
allocations at the function entry, and deallocations before each return.

Ideally we would scope these lifetimes down, but it's a bit challenging
because:
  - The capture promotion pass can insert releases, and these releases
    are not in any particular order with respect to the box creation.
  - The box-to-stack promotion pass has for a while now been promoting
    boxes that are arguments to partial_apply when we know the
    partial_apply doesn't escape the current function. To correctly
    place the deallocs, we would need to determine the potential
    lifetimes of the allocated data, e.g. the last use of the
    partial_apply along any given path.

I have opened <rdar://problem/16723128> so that we can try to improve
this in the future.

Fixes <rdar://problem/16242937>.

Swift SVN r16852
2014-04-25 23:41:28 +00:00
Andrew Trick
f58ebbc251 Add a global_init attribute to SILFunction.
The implied semantics are:
- side-effects can occur any time before the first invocation.
- all calls to the same global_init function have the same side-effects.
- any operation that may observe the initializer's side-effects must be
  preceded by a call to the initializer.

This is currently true if the function is an addressor that was lazily
generated from a global variable access. Note that the initialization
function itself does not need this attribute. It is private and only
called within the addressor.

Swift SVN r16683
2014-04-23 01:09:47 +00:00
John McCall
8681963bcb A couple of long-overdue renames.
Builtin.ObjectPointer -> Builtin.NativeObject
Builtin.ObjCPointer -> Builtin.UnknownObject

Swift SVN r16634
2014-04-22 00:17:08 +00:00
Mark Lacey
ccc4b05245 When cloning closures, use the same linkage as the original.
Swift SVN r16080
2014-04-08 23:02:01 +00:00
Mark Lacey
f21ff843ab Only examine box container pointer when determining whether to promote.
Implement JoeG's suggestion to limit the examination of uses to the
container pointer since there is no legal way for the address pointer to
outlive the box container.

Deletes 16 of the 45 alloc_box in the stdlib in my build
configuration.

canValueEscape() can be simplified now since it is only being used
examine how partial_apply get used, but I'll leave that for a separate
commit.

Swift SVN r16047
2014-04-08 05:46:26 +00:00
Mark Lacey
627534144d Small clean-up in box-to-stack prmomotion.
Swift SVN r15959
2014-04-04 21:51:58 +00:00
Adrian Prantl
47bf136af5 More assertion cleanups. Thanks, Joe!
Swift SVN r15842
2014-04-02 23:06:13 +00:00
Adrian Prantl
5385d4e7a7 Clean up a slightly wrong assertion.
<rdar://problem/16499612> assert building Foundation with SWIFT_ASSERTS=NO

Swift SVN r15840
2014-04-02 22:54:35 +00:00
Chris Lattner
afea47b621 rename "destroy_value" to "release_value", part of rdar://15889208.
Swift SVN r15777
2014-04-02 05:33:52 +00:00
Mark Lacey
ad36b4f449 Make helper functions static.
Swift SVN r15749
2014-04-01 21:46:19 +00:00
Mark Lacey
c4faf8c413 Clone partially applied functions in an effort to eliminate more boxes.
Attempt to promote boxes to stack allocations by examining partial_apply
instructions that the boxes appear as arguments in, and then if things
look good examining the apply that the partial_apply is passed to in
order to ensure the partial_apply is not captured. If it looks like we
can legally promote the box, clone the partially applied function to
remove the box container pointer, and rewrite the partial_apply.

Fixes <rdar://problem/16373639>.

Swift SVN r15727
2014-04-01 09:18:32 +00:00
Mark Lacey
723e0a0783 Disable examining partial_apply bodies until the cloning part is done.
It turns out this was firing in the SWIFT_ASSERTS=NO build and resulting
in an assert.

Swift SVN r15723
2014-04-01 06:32:45 +00:00
Mark Lacey
c1ee79ed01 Collect the box pointer operands of partial_apply that are unneeded.
For the partial_apply instructions we'll rewrite to use stack operands,
we need to remove the box pointer operands when specializing the applied
functions and rewriting the partial_apply.

This is another commit with no current effect - we do not specialize
yet, and do not promote any additional boxes to stack locations.

Swift SVN r15719
2014-04-01 00:44:46 +00:00
Mark Lacey
e0a03dab19 Retain, release, and dealloc_box do not cause their operand to escape.
We see no benefit from this until we start to examine the bodies
functions that are (partially) applied.

Swift SVN r15718
2014-04-01 00:44:46 +00:00
Mark Lacey
5d2115de27 Factor out mapping an operand to a parameter index. NFC.
Swift SVN r15717
2014-04-01 00:44:46 +00:00
Mark Lacey
1bf3ca4985 Improve variable name in helper function.
Swift SVN r15621
2014-03-29 17:05:20 +00:00
Mark Lacey
622b888a0b Minor cleanup in debug statistic.
Swift SVN r15620
2014-03-29 17:05:19 +00:00
Mark Lacey
dda599f11e Refactor to separate collection of promotable boxes from promoting them.
Swift SVN r15619
2014-03-29 17:05:18 +00:00
Mark Lacey
8e698b993a Factor out common code for getting a parameter.
Given an operand to an apply/partial_apply, we want to get the BB
argument in the body of the called function that represents the operand.

Swift SVN r15609
2014-03-29 05:53:53 +00:00
Mark Lacey
a18b979da0 Fix another logic inversion bug.
Swift SVN r15608
2014-03-29 05:53:52 +00:00
Mark Lacey
5cc6a44994 Correct inverted logic.
Swift SVN r15607
2014-03-29 05:53:51 +00:00
Mark Lacey
66d779966b Move escape helper functions back to AllocBoxToStack.cpp.
These are only being used by that transform at this time, so it makes
sense to have them together.

Swift SVN r15606
2014-03-29 05:53:51 +00:00