Commit Graph

111 Commits

Author SHA1 Message Date
Michael Gottesman
19f0f6e686 [semantic-sil] Reify the split in SILArgument in between function and block arguments via subclasses.
For a long time, we have:

1. Created methods on SILArgument that only work on either function arguments or
block arguments.
2. Created code paths in the compiler that only allow for "function"
SILArguments or "block" SILArguments.

This commit refactors SILArgument into two subclasses, SILPHIArgument and
SILFunctionArgument, separates the function and block APIs onto the subclasses
(leaving the common APIs on SILArgument). It also goes through and changes all
places in the compiler that conditionalize on one of the forms of SILArgument to
just use the relevant subclass. This is made easier by the relevant APIs not
being on SILArgument anymore. If you take a quick look through you will see that
the API now expresses a lot more of its intention.

The reason why I am performing this refactoring now is that SILFunctionArguments
have a ValueOwnershipKind defined by the given function's signature. On the
other hand, SILBlockArguments have a stored ValueOwnershipKind. Rather than
store ValueOwnershipKind in both instances and in the function case have a dead
variable, I decided to just bite the bullet and fix this.

rdar://29671437
2016-12-18 01:11:28 -08:00
Michael Gottesman
a178ac97e0 [sil-ownership] Fix some cases in SILValue::getOwnershipKind().
I fixed a few things. Now I am finally hitting cases where we have
guaranteed/owned arguments, so I really need to do the SILGen work. But this was
a good first step.

rdar://29671437
2016-12-17 01:23:52 -08:00
Michael Gottesman
4bfaef8ae0 [semantic-sil] Add a new pass that dumps out the ownership of all SILValue in a function and performs some minor checks upon them.
rdar://29671437
2016-12-16 17:53:49 -08:00
Michael Gottesman
3df612b0d6 [semantic-sil] Implement ValueOwnershipKindBuiltinVisitor to compute ValueOwnershipKind for Builtins/llvm intrinsics.
This is just a first pass through. We know that builtins can only be used in the
standard library and trivially so only in non-generic contexts.

This means that anything that I marked trivial that isn't really will be caught
and there are very very few builtins that traffic in ownership, so I can sight
verify them.

rdar://29671437
2016-12-16 17:41:43 -08:00
Michael Gottesman
7d25db5603 [semantic-sil] Implement support for most SILNodes in ValueOwnershipKindVisitor.
The remaining nodes will be defined in subsequent commits. They are:

1. SILArgument.
2. BuiltinInst.

rdar://29671437
2016-12-16 17:12:27 -08:00
Michael Gottesman
d4fb21d50f [semantic-sil] Define ValueOwnershipKind SILValue::getOwnershipKind().
The implementation will rely on a SILVisitor to ensure that we properly handle
all relevant cases. Right now, there are only stubs and we assert in all of
them.

rdar://29671437
2016-12-16 17:00:54 -08:00
Michael Gottesman
57d3f848a6 [semantic-sil] Define ValueOwnershipKind enum.
This enum models the various froms of ownership semantics that a specific
SILValue can have.

rdar://29671437
2016-12-16 16:50:49 -08:00
Michael Gottesman
26b37f1641 [gardening] Move ValueBase::RAUW from SIL.cpp => SILValue.cpp. 2016-12-14 15:44:31 -08:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Michael Gottesman
a8c4cc60e8 [gardening] Rename ValueBase::getParentBB() => getParentBlock(). 2016-11-14 00:39:47 -08:00
Michael Gottesman
c6c99141b5 [gardening] Change ValueBase::{getParentBB,getFunction,getModule}() to be const methods so in the debugger one can use it with const ValueBase. 2016-11-14 00:39:41 -08:00
Michael Gottesman
3eaa25bcd6 [sil] Complement ValueBase::getParentBB() with ValueBase::get{Function,Module}().
These APIs work just like getParentBB does, namely they attempt to cast
self to either SILInstruction/SILArgument and if the instance is one of
those classes, using the APIs on said classes to get the relevant
Function or Module. If the dynamic casts fail, then nullptr is returned.
2016-10-23 14:47:12 -07:00
Erik Eckstein
f18c8431fd SIL: remove unneeded includes 2016-01-25 15:00:49 -08:00
Erik Eckstein
b745691a38 SIL refactoring: Move some functions out of SILValue and Operand
SILValue.h/.cpp just defines the SIL base classes. Referring to specific instructions is a (small) kind of layering violation.
Also I want to keep SILValue small so that it is really just a type alias of ValueBase*.
NFC.
2016-01-25 10:37:03 -08:00
Erik Eckstein
ec172cde5b Remove SILValue::replaceAllUsesWith.
It's not needed anymore because we can use ValueBase::replaceAllUses
2016-01-21 16:04:30 -08:00
Erik Eckstein
25e52a0ba0 treat project_box as projection in SILValue and SideEffectAnalysis 2016-01-15 12:35:29 -08:00
Michael Gottesman
2f3709443d [rc-id] Make RCIdentity strip off single-pred arguments.
In a bunch of use-cases we use stripSinglePredecessorArgs to eliminate this
case. There is no reason to assume that this is being done in the caller of
RCIdentity. Lets make sure that we handle this case here.

rdar://24156136
2016-01-14 18:19:54 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
practicalswift
8ab8847684 Fix typos. 2015-12-16 22:09:32 +01:00
practicalswift
ff03d6faff Fix typo: arugment → argument 2015-12-14 00:11:14 +01:00
Ted Kremenek
2dca3963a9 Merge pull request #7 from aschwaighofer/hoist_addr_proj_bug
Fix a bug in SILValue's hoistAddressProjections
2015-11-20 15:36:53 -08:00
Ted Kremenek
3e779dbc66 Revert "Revert "Safely implement strict TBAA rules.""
We believe the failure now may be in the setup of the test harness.
Re-applying this change, since the tests passed in our other
configurations.
2015-11-20 15:08:58 -08:00
Ted Kremenek
ddc9c52d5a Revert "Safely implement strict TBAA rules."
This reverts commit 3d5c4969a0.

This is breaking the iOS device tests.
2015-11-20 14:51:25 -08:00
Andrew Trick
3d5c4969a0 Safely implement strict TBAA rules.
This fixes type punning issues with unsafeBitCast.

The optimizer is still too aggressive with UnsafePointer. To fix that,
we first need an explicit API for circumventing type safety
(rdar://23406272).

I should be able to fix the following regressions by migrating the
stdlib away from unsafeBitCast to unsafeReferenceCast (~2 weeks).

Slowdowns:
|.Benchmark.................|..Before.|...After.|.Speedup|
|.ArrayInClass..............|...49.00.|...78.00.|.-37.2%.|
|.Sim2DArray................|..471.00.|..549.00.|.-14.2%.|
|.PrimeNum..................|.1876.00.|.1980.00.|..-5.3%.|

Speedups:
|.Benchmark.................|..Before.|...After.|.Speedup|
|.HeapSort..................|.2962.00.|.2663.00.|..11.2%.|
|.StdlibSort................|.2672.00.|.2537.00.|...5.3%.|
2015-11-20 09:59:56 -08:00
Arnold Schwaighofer
95f43bccad Fix a bug in SILValue's hoistAddressProjections
We have to insert instructions that are operands *before* the instruction using
them as an operand.

Also fix a bug in the same code when looking through single predecessor basic
block arguments.

Add a testcase for all three cases.

rdar://23159379
2015-11-20 07:47:33 -08:00
Andrew Trick
2318be324f UncheckedAddrCast does not preserve RC identity.
UncheckedRefCastAddr does.

This cleans up the white-list used by ARC
optimization to be a bit more conservative.

I wasn't able to observe a change in behavior.
2015-11-12 10:41:19 -08:00
Andrew Trick
c20370a664 Remove the last remnants of unchecked_ref_bit_cast
Swift SVN r32598
2015-10-10 05:42:57 +00:00
Michael Gottesman
74a984de6b Rename SILValue::stripAggregateProjections => SILValue::stripValueProjections.
This matches the terminology used in Projection. NFC.

Swift SVN r31418
2015-08-23 04:27:24 +00:00
Arnold Schwaighofer
0c6363a399 SILValue: Add an api to strip expect intrinsics
Swift SVN r27838
2015-04-27 23:43:41 +00:00
Michael Gottesman
52a332b2bd Specify that the static_asserts I inserted in the past couple of comments are
meant to ensure behavior does not change by mistake, but are open to be changed
if one wishes to modify them on purpose.



Swift SVN r26531
2015-03-25 06:46:53 +00:00
Michael Gottesman
3ec2d151f6 Shrink Projection to 24 bytes and Add some static assertions to make sure that SILValue and Projection stay the same size and standard layout.
Swift SVN r26526
2015-03-25 06:21:08 +00:00
Mark Lacey
fbc7b76614 Be more conservative about stripping upcasts in devirtualization.
This fixes two issues that I ran into with the devirtualizer and also
paves the path to more simplification of the devirtualizer code.

Both issues are due to having a very liberal definition of what can be
considered an upcast.

In one case, we tunnel through an unchecked_ref_cast and then fail to
devirtualize because the source type is not a class
type (rdar://problem/20115523). We would be better off sticking to the
class type we started with.

In the other case, we tunnel through an unchecked_ref_bit_cast and this
results in an attempt to insert a checked_cast_br between unrelated
types (rdar://problem/20117782).

Swift SVN r25976
2015-03-11 08:25:51 +00:00
Arnold Schwaighofer
a95eefb934 Add a utility function to Operand to hoist projections rooted in an operand to
an earlier point.

Swift SVN r25618
2015-02-27 22:07:38 +00:00
Erik Eckstein
c2702fbf8b Fix <rdar://problem/19069205> Stack overflow in SIL alias analysis
The problem was that SILValue::stripAddressProjections() was out of sync with Projection::isAddrProjection().



Swift SVN r23806
2014-12-09 11:16:16 +00:00
Roman Levenstein
ab7b1c26ca Move stripClassCasts into SILValue. NFC.
Swift SVN r23539
2014-11-21 22:21:52 +00:00
Arnold Schwaighofer
08015deced RefToBridgeObjectInst and BridgeObjectToRefInst are rc identity preserving
rdar://19006443

Swift SVN r23411
2014-11-18 21:23:07 +00:00
Arnold Schwaighofer
0b12dd19e3 These casts are not rc identity preserving we can't strip them
rdar://18668900

Swift SVN r22804
2014-10-16 23:44:13 +00:00
Roman Levenstein
ed22906964 Add helper methods to strip upcasts. This is required for upcoming devirtualizer patches.
Swift SVN r22602
2014-10-08 13:09:05 +00:00
Arnold Schwaighofer
36ad6d2faa ValueBase: Add getParentBB api
Swift SVN r21925
2014-09-12 21:05:21 +00:00
Michael Gottesman
4609513593 Remove SILValue::stripRCIdentityPreservingArgs and teach all uses of that method to use the new RCIdentityAnalysis.
Currently, the pass just calls a local version of that function. After OzU, I
will enable the full pass (which is currently disabled behind a flag).

Swift SVN r21894
2014-09-11 22:29:31 +00:00
Michael Gottesman
4647eb9601 Create RCIdentityAnalysis a cache for stripRCIdentityPreservingOps.
The cache is needed to ensure we do not run into compile time problems once we
start looking through Phi Nodes.

The analysis is currently disabled and just returns
SILValue::stripRCIdentityPreservingOps. I am going to thread it through the rest
of the passes that use that call. Then I am going to hide
stripRCIdentityPreservingArgs. Finally post OzU, I am going to enable the pass.

rdar://18300069

Swift SVN r21891
2014-09-11 21:51:29 +00:00
Michael Gottesman
875fa02f98 Hide SILValue::stripSinglePredecessor{Args,RCIdentityPreservingArgs}.
These really should never have been exposed since they are internals to
SILValue.

Swift SVN r21868
2014-09-11 05:44:58 +00:00
Michael Gottesman
2b4d7f72a2 [g-arc-opts] Look through enum literal instructions.
The enum literal instruction has the same reference identity as its payload if
it has a payload.

<rdar://problem/18195085>

Swift SVN r21644
2014-09-02 16:03:11 +00:00
Michael Gottesman
ec7cc211cb [g-arc-opts] A struct_extract of the only non-trivial stored field of a struct is always a ref count identity preserving identity.
rdar://18189325

Swift SVN r21614
2014-08-31 18:08:30 +00:00
Michael Gottesman
fb04e9082b [g-arc-opts] unchecked_enum_data is always a ref count identity preserving operation, always strip them off.
Originally I was using the notion of layout compatible to define the notion of a
ref count identity preserving operation. This is too restrictive of a definition
since layout compatible implies that the operation does not change the memory
location being pointed at. On the other hand, we just care that the ref counts
are the same.

rdar://18189329

Swift SVN r21613
2014-08-31 18:08:29 +00:00
Michael Gottesman
ae0ff91ff3 Teach the various forms of stripping to ignore single predecessor args from br and cond_br.
This is effectively looking through a no-op. So it makes sense to always look
through them if we can.

<rdar://problem/18038959>

Swift SVN r21343
2014-08-21 05:16:45 +00:00
Michael Gottesman
b30b212d04 Remove the term non-PHI and instead use SinglePredecessor.
Swift SVN r21340
2014-08-21 04:13:27 +00:00
Michael Gottesman
73434aa4fa Rename SwitchEnumInst::getBBCase => getUniqueCaseForDestination.
This matches the name for SwitchEnumInst::getCaseDestination() and includes the word
'unique' so that the name self documents.

I also removed a local function doing the same work in SimplifyCFG and changed
its user to use getUniqueCaseForDestination instead.

Swift SVN r21339
2014-08-21 04:06:19 +00:00
Michael Gottesman
6d7ace6013 Make sure that when stripping non phi rc identity preserving args from switch enums, we only strip off switch enum inst if our BB is mapped to the first payloaded case of the enum.
Swift SVN r21336
2014-08-21 03:46:26 +00:00
Michael Gottesman
96ef9814f5 Change CondBranchInst::getArgForDestBB() so that it returns SILValue() if the TrueBB and the False BB equal and so that it takes the SILArgument instead of the index.
Swift SVN r21335
2014-08-21 03:45:35 +00:00