Commit Graph

209 Commits

Author SHA1 Message Date
Roman Levenstein
696da80ca0 [sil-devirtualizer] Support devirtualization of try_apply instructions.
rdar://21909405

Swift SVN r30710
2015-07-28 00:11:38 +00:00
Nadav Rotem
c2c6306c5a cleanups. Update docs and method names.
Swift SVN r29853
2015-07-01 20:19:08 +00:00
Nadav Rotem
93fff21037 Rename the InlineCaches pass to Speculative Devirtualization
Swift SVN r29851
2015-07-01 20:19:00 +00:00
Michael Gottesman
a39102caff Fix incorrect invalidation in inlinecaches.
In a corner case we would not invalidate the CFG when we inserted an inline
cache. This would then cause the post order analysis to get out of sync and thus
ARC would crash.

<rdar://problem/21421339>

Swift SVN r29596
2015-06-24 02:59:20 +00:00
Roman Levenstein
38922204fb [sil-devirtualizer] Fix a segmentation fault when a class_method cannot be devirtualized for a subclass.
Swift SVN r29404
2015-06-16 22:22:45 +00:00
Roman Levenstein
3ddfb2fb4b [sil-devirtualizer] Fix a bug related to devirtualization of bound generic classes.
ClassHierarchyAnalysis reports relationships between classes as they are all unbound. Therefore, when we try to devirtualize a method of a bound generic class, we need to exclude non-subclasses from the list of subclasses reported by ClassHierarchyAnalysis.

This fixes a compiler crash on generic_class.swift test when it is built with -O.

rdar://21188939.

Swift SVN r29215
2015-06-02 00:32:11 +00:00
Nadav Rotem
680c565af5 Refactor the code that checks if a function is marked with noopt semantics. NFC.
Swift SVN r27485
2015-04-20 17:27:31 +00:00
Nadav Rotem
926042ff81 Add @semantics("optimize.never") to disable optimizations of a specific function.
This commit adds a flag to disable optimizations on a specific functions. The
primary motivation of this patch is to allow the optimizer developers to reduce
testcasese by disabling optimizations of parts of the code without having to
recompile the compiler or inspect SIL. The annotations  "inline(never)"
and "optimize.none" can go a long way.

The second motivation for this patch is to allow our internal adopters to work
around compiler bugs.

rar://19745484

Usage:

@semantics("optimize.never")
public func miscompile() { ... }

Swift SVN r27475
2015-04-20 05:06:55 +00:00
Mark Lacey
730ef41385 Make devirtualizer clients remove old applies.
This makes it feasible for clients to maintain the call graph.

Swift SVN r26997
2015-04-05 02:27:57 +00:00
Michael Gottesman
faabb7ea8a [spec-devirt] Hoist releases right after the apply on self into the diamond.
rdar://20335275

Swift SVN r26985
2015-04-04 20:14:47 +00:00
Mark Lacey
315a645e05 Remove AIList from Generics.h.
There was only one remaining user since it was removed from any function
interfaces, and that should really just use SmallVector directly.

Swift SVN r26790
2015-04-01 02:10:55 +00:00
Mark Lacey
07a5ebed66 Rename devirtualizeApply to tryDevirtualizeApply.
This is more consistent with the other naming in the devirtualization
code for things that might fail.

Swift SVN r26788
2015-04-01 02:10:52 +00:00
John McCall
6d8fff9c06 Parsing and basic structure of try_apply. Not yet properly
threaded into IRGen; tests to follow when that's done.

I made a preliminary effort to make the inliner do the
right thing with try_apply, but otherwise tried to avoid
touching the optimizer any more than was required by the
removal of ApplyInstBase.

Swift SVN r26747
2015-03-31 02:41:03 +00:00
Nadav Rotem
4afd4305e5 Disable generic specialization in the devirtualzier.
The current approach does not improve the compile time. Mark has a better plan
for making the inliner/devirtualizer/specializer work together.

Swift SVN r26613
2015-03-26 23:38:18 +00:00
Mark Lacey
1f23ff27bb Remove the transparent bit from apply instructions.
We no longer need or use it since we can always refer to the same bit on
the applied function when deciding whether to inline during mandatory
inlining.

Resolves rdar://problem/19478366.

Swift SVN r26534
2015-03-25 08:36:34 +00:00
Jordan Rose
f74bc7122c Split getAccessibility() into getFormalAccess() and getEffectiveAccess().
Currently a no-op, but effective access for entities within the current
module will soon need to take testability into account. This declaration:

  internal func foo() {}

has a formal access of 'internal', but an effective access of 'public' if
we're in a testable mode.

Part of rdar://problem/17732115 (testability)

Swift SVN r26472
2015-03-24 02:16:58 +00:00
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
Nadav Rotem
a50a924e85 Teach the devirtualizer to only invalidate analysis for functions that were modified.
Swift SVN r26372
2015-03-20 22:53:05 +00:00
Mark Lacey
5547dd6047 Enable speculative devirtualization of 'class func' methods.
Swift SVN r26191
2015-03-16 21:13:12 +00:00
Mark Lacey
a30d13b0ce Simplify handling of metatypes in devirtualization.
Make the devirtualization functions take the actual type we're
devirtualizing (or speculatively devirutalizing) to, in order to
simplify the handling of metatypes. Remove the ClassDecl parameter from
these functions since it can always be derived from this type.

These changes set things up for more forthcoming improvements to
metatype handling.

As part of this I've simplified the function that determines if a member
is known to be 'final'. My expectation is that this can be further
simplified by removing the type parameter as part of other improvements
to metatype handling.

Swift SVN r26165
2015-03-15 22:04:46 +00:00
Mark Lacey
ffaa74bfbb Remove DevirtClassMethodInfo.
It turns out we're already at a point where we can easily pass the same
data along to the devirtualization functions, and were already passing
some of it.

Swift SVN r26040
2015-03-12 07:46:10 +00:00
Mark Lacey
f174ad1a2c Replace a dyn_cast with a cast.
We don't test the result, and we immediately dereference it.

Swift SVN r26033
2015-03-12 05:09:46 +00:00
Erik Eckstein
7c5ea453ba Revert "Simplify some of the logic around metatypes in the devirtualizer."
It crashes when compiling the benchmarks.



Swift SVN r25978
2015-03-11 11:44:34 +00:00
Mark Lacey
a9f29281f7 Simplify some of the logic around metatypes in the devirtualizer.
NFC.

Swift SVN r25977
2015-03-11 08:43:40 +00:00
Mark Lacey
b54c45b201 Revert "Revert "Remove subtyping checks that can never actually fail.""
This reverts commit r25946, reinstating r25944.

This had been preemptively reverted fearing it might have broken
test/SILPasses/devirt_value_metatypes.swift, but that turned out to not
have been the case.

Swift SVN r25959
2015-03-10 21:45:16 +00:00
Mark Lacey
cb7df94fc2 Revert "Revert "Hoist more early returns as early as possible.""
This reverts commit r25947, reinstating r25943 with fixes.

This had been preemptively reverted fearing it might have broken
test/SILPasses/devirt_value_metatypes.swift, which it did. One of the
early exits that was hoisted should not have been moved.

I plan on another clean-up for that particular early exit in a
forthcoming commit.

Swift SVN r25958
2015-03-10 21:45:15 +00:00
Mark Lacey
2946d377b6 Revert "Revert "Another small clean-up. Manually copy-forward a value.""
This reverts commit r25948, reinstating r25942.

This had been preemptively reverted fearing it might have broken
test/SILPasses/devirt_value_metatypes.swift, but that turned out to not
have been the case.

Swift SVN r25957
2015-03-10 21:45:13 +00:00
Mark Lacey
d9c40a7f79 Revert "Revert "Simplify some code and make it easier to understand.""
This reverts commit r25949, reinstating r25941.

This had been preemptively reverted fearing it might have broken
test/SILPasses/devirt_value_metatypes.swift, but that turned out to not
have been the case.

Swift SVN r25956
2015-03-10 21:45:12 +00:00
Mark Lacey
3221fdb2a2 Revert "Simplify some code and make it easier to understand."
This reverts commit r25941.

It may have broken a test that was missing a FileCheck.

Swift SVN r25949
2015-03-10 19:59:26 +00:00
Mark Lacey
6a58924730 Revert "Another small clean-up. Manually copy-forward a value."
This reverts commit r25942.

It may have broken a test that was missing a FileCheck.

Swift SVN r25948
2015-03-10 19:59:25 +00:00
Mark Lacey
e3adbc654b Revert "Hoist more early returns as early as possible."
This reverts commit r25943.

It may have broken a test that was missing a FileCheck.

Swift SVN r25947
2015-03-10 19:59:24 +00:00
Mark Lacey
1b4dbf717a Revert "Remove subtyping checks that can never actually fail."
This reverts commit r25944.

It may have broken a test that was missing a FileCheck.

Swift SVN r25946
2015-03-10 19:59:21 +00:00
Mark Lacey
71d17b1a47 Remove subtyping checks that can never actually fail.
It's clear from the surrounding code and our type system that these
checks can never fail. To ensure I wasn't overlooking something I added
asserts to this effect and ran the test suite. I remove the asserts
because they feel like clutter, but if anyone feels strongly I can add
them back.

Swift SVN r25944
2015-03-10 19:27:42 +00:00
Mark Lacey
cf903cc900 Hoist more early returns as early as possible.
Swift SVN r25943
2015-03-10 19:27:41 +00:00
Mark Lacey
a3ddfe4c30 Another small clean-up. Manually copy-forward a value.
We know one value can be substituted for another after a given point, so
instead of conditional assignment, just substitute it.

Swift SVN r25942
2015-03-10 19:27:40 +00:00
Mark Lacey
dd055c3496 Simplify some code and make it easier to understand.
CSE some stripUpCasts() calls and do a little renaming to aid in
understandability. NFC.

Swift SVN r25941
2015-03-10 19:27:38 +00:00
Roman Levenstein
9c0eb2985b Yet another improvement of devirtualization based on metatypes.
Swift SVN r25928
2015-03-10 16:19:43 +00:00
Roman Levenstein
1b6cf90da8 Improvement of devirtualization based on metatypes.
Swift SVN r25927
2015-03-10 16:19:42 +00:00
Mark Lacey
fa7b1f5dcc Move early exit earlier in the function.
Exit as soon as we know we can, simplifying the later exit condition.

Swift SVN r25916
2015-03-10 06:19:26 +00:00
Mark Lacey
5fc5ca4fb8 Remove assert that can never fire.
We would assert in the preceeding cast<> if it were to fail.

Swift SVN r25915
2015-03-10 06:19:25 +00:00
Roman Levenstein
30b68e5d83 [sil-devirtualizer] Fix dispatching on value_metatype
Dispatching on value_metatype, which happens in cases like obj.dynamicType.method(), was broken.
Fix it and add a corresponding test-case.

Swift SVN r25892
2015-03-09 19:35:47 +00:00
Mark Lacey
c26c15cc9f Don't pass arguments that can be easily derived from other arguments.
Swift SVN r25799
2015-03-06 06:56:56 +00:00
Mark Lacey
0b8c14e9bb Remove check which is subsumed by the call to canDevirtualizeClassMethod.
Shortly after this code we call canDevirtualizeClassMethod, which does
the same test.

Swift SVN r25796
2015-03-06 01:28:15 +00:00
Mark Lacey
99890e4b1d Remove unneeded local variable.
It's only use is to decide whether to assert later, so instead, let's
assert immediately.

Swift SVN r25795
2015-03-06 01:28:13 +00:00
Mark Lacey
757ae5796e First step in splitting out a utility for devirtualizing from the pass.
No functional change here, and this is not in its final form. This is
just cut/paste/tweak to split the code apart in a first reasonable form.

Swift SVN r25769
2015-03-04 22:21:38 +00:00
Mark Lacey
844c2df46f Rename a couple statistics.
Swift SVN r25768
2015-03-04 22:21:37 +00:00
Mark Lacey
a61e85cd51 Fix 80-column violations.
Swift SVN r25752
2015-03-04 08:39:14 +00:00
Roman Levenstein
a5b75b6f06 Oops. Forgot to commit these two lines in my previous commit.
Swift SVN r25718
2015-03-03 20:56:36 +00:00
Roman Levenstein
fcf7053c46 [sil-devirtualizer] Re-factoring of the class_method devirtualization method.
Decouple devirtualizeClassMethod into an analysis part and a part that performs a real transformation.
This allows for early bail outs when trying to devirtualize a class_method call and thus avoids creating a duplicate class_method call invocation, which happened before in certain rare cases.

Swift SVN r25717
2015-03-03 20:32:47 +00:00
Mark Lacey
a9181b08ce Make witness/vtable look-up helper naming more consistent.
Swift SVN r25713
2015-03-03 09:14:18 +00:00