Commit Graph

2295 Commits

Author SHA1 Message Date
Chris Lattner
37f5452d15 require -> guard.
Swift SVN r28223
2015-05-06 22:53:38 +00:00
Chris Lattner
ba4186befb remove parser support for let/else. I left in a cheesy fixit to help
migrate code, but it isn't great.  It needs to be removed before wwdc
(tracked by 20794825)


Swift SVN r28099
2015-05-03 21:46:05 +00:00
Chris Lattner
0011b3ae21 rename "unless" to "require" and give it an 'else' keyword.
Swift SVN r28059
2015-05-02 00:16:44 +00:00
Mark Lacey
15dbf5e0b8 Properly invalidate non-local stores in global load/store opts.
In global load/store optimization, ensure that we remove non-local
stores from the store map when we hit instructions that can potentially
overwrite all or part of the stored value.

In the test case from this particular radar, the address being stored to
is also passed as an inout to a mutating method, and then loaded after
the mutation.

rdar://problem/20603219

Swift SVN r28053
2015-05-01 22:50:12 +00:00
Chris Lattner
e1e83eb8ce Reject 'unless' blocks that fall through.
Unless is now done, we just need to decide what color to paint it.


Swift SVN r27996
2015-04-30 21:12:39 +00:00
Erik Eckstein
30c34894e0 Don't speculate initialization of globals with limited availability.
Fixes rdar://problem/20708979



Swift SVN r27965
2015-04-30 11:08:49 +00:00
Erik Eckstein
ebbecf5e5a Do not inline "availability.osversion" functions in mid-level inliner.
Because GlobalOpt must see this functions (rdar://problem/20708979)



Swift SVN r27964
2015-04-30 11:07:42 +00:00
Arnold Schwaighofer
8d14a3d9c4 LoopRotate: Don't rotate single basic block loops with split backedges
rdar://20746203

Swift SVN r27938
2015-04-29 22:49:05 +00:00
Roman Levenstein
dcd3055360 [load-store-opts] Avoid re-loading values of "let"-variables
Teach LoadStoreOpts to handle "let" variables properly. Such variables should be loaded only once and their loaded values can be reused. This is safe, because once assigned these variables cannot change their value.

Swift SVN r27915
2015-04-29 18:02:12 +00:00
Erik Eckstein
64d48c8883 GlobalLoadStoreOpts: correctly update the data structures in case instructions are deleted.
This fixes: rdar://problem/20617907



Swift SVN r27913
2015-04-29 17:13:49 +00:00
Erik Eckstein
c9075401d3 Improve debug logging in GlobalLoadStoreOpts. NFC.
Swift SVN r27911
2015-04-29 17:05:09 +00:00
Doug Gregor
4ed45ec830 Revert "Generic specializer: don't allow specialization if it uses an incomplete conformance."
This reverts r27886; a better solution is coming.

Swift SVN r27895
2015-04-29 00:08:26 +00:00
Andrew Trick
61d2c0166b Make SILPasses (ARC & Pin removal) aware of IsUniqueInst.
Swift SVN r27888
2015-04-28 22:54:25 +00:00
Andrew Trick
a174aa4dfe Add AST and SILGen support for Builtin.isUnique.
Preparation to fix <rdar://problem/18151694> Add Builtin.checkUnique
to avoid lost Array copies.

This adds the following new builtins:

    isUnique : <T> (inout T[?]) -> Int1
    isUniqueOrPinned : <T> (inout T[?]) -> Int1

These builtins take an inout object reference and return a
boolean. Passing the reference inout forces the optimizer to preserve
a retain distinct from what’s required to maintain lifetime for any of
the reference's source-level copies, because the called function is
allowed to replace the reference, thereby releasing the referent.

Before this change, the API entry points for uniqueness checking
already took an inout reference. However, after full inlining, it was
possible for two source-level variables that reference the same object
to appear to be the same variable from the optimizer's perspective
because an address to the variable was longer taken at the point of
checking uniqueness. Consequently the optimizer could remove
"redundant" copies which were actually needed to implement
copy-on-write semantics. With a builtin, the variable whose reference
is being checked for uniqueness appears mutable at the level of an
individual SIL instruction.

The kind of reference count checking that Builtin.isUnique performs
depends on the argument type:

    - Native object types are directly checked by reading the
      strong reference count:
      (Builtin.NativeObject, known native class reference)

    - Objective-C object types require an additional check that the
      dynamic object type uses native swift reference counting:
      (Builtin.UnknownObject, unknown class reference, class existential)

    - Bridged object types allow the dymanic object type check to be
      bypassed based on the pointer encoding:
      (Builtin.BridgeObject)

Any of the above types may also be wrapped in an optional.  If the
static argument type is optional, then a null check is also performed.

Thus, isUnique only returns true for non-null, native swift object
references with a strong reference count of one.

isUniqueOrPinned has the same semantics as isUnique except that it
also returns true if the object is marked pinned regardless of the
reference count. This allows for simultaneous non-structural
modification of multiple subobjects.

In some cases, the standard library can dynamically determine that it
has a native reference even though the static type is a bridge or
unknown object. Unsafe variants of the builtin are available to allow
the additional pointer bit mask and dynamic class lookup to be
bypassed in these cases:

    isUnique_native : <T> (inout T[?]) -> Int1
    isUniqueOrPinned_native : <T> (inout T[?]) -> Int1

These builtins perform an implicit cast to NativeObject before
checking uniqueness. There’s no way at SIL level to cast the address
of a reference, so we need to encapsulate this operation as part of
the builtin.

Swift SVN r27887
2015-04-28 22:54:24 +00:00
Doug Gregor
152de6bb34 Generic specializer: don't allow specialization if it uses an incomplete conformance.
Semantic analysis should be guaranteeing that all conformances that
show up in the AST are complete. Until that day, work around the crash
in rdar://problem/20700616 by not specializing.

Swift SVN r27886
2015-04-28 22:34:40 +00:00
Arnold Schwaighofer
82baf4eca1 Delete now unused variable
Swift SVN r27848
2015-04-28 00:04:17 +00:00
Arnold Schwaighofer
8016bc0fa0 Canonicalize cmp_eq %X, -1 -> xor (cmp_eq %X, 0), -1
Swift SVN r27846
2015-04-27 23:46:48 +00:00
Arnold Schwaighofer
e5a038fafb Nuke dead code
Swift SVN r27845
2015-04-27 23:46:48 +00:00
Arnold Schwaighofer
0bdcbd2612 Nuke old dominator based simplification code that is subsumed by the dominator
based jumpthreading commit.

Swift SVN r27844
2015-04-27 23:46:47 +00:00
Arnold Schwaighofer
3812583031 DominatorBasedJumpThreading: Resurrected
Teach dominator based simplifications to also thread dominated edges.

The code now handles cond_br and switch_enum terminators for both value based
simplifications (where the use is dominated) and jump threading edges (the edge
is dominated).

Update simplify_cfg.sil test cases for split edges.

This also handles the test case from rdar://20390647.

Swift SVN r27843
2015-04-27 23:44:57 +00:00
Arnold Schwaighofer
598eb60f2d ABCOpts: Let's handle loops with split backedges
Swift SVN r27842
2015-04-27 23:44:56 +00:00
Arnold Schwaighofer
bfcc1fface Make splitBasicBlock public.
Swift SVN r27841
2015-04-27 23:44:55 +00:00
Arnold Schwaighofer
5272408e62 SimplifyCFG: Canonicalize cond_br (not %cond) bb1, bb2 to cond_br %cond bb2,
bb1.

Swift SVN r27839
2015-04-27 23:43:42 +00:00
Arnold Schwaighofer
ea6e5e71de InlineCost: expect intrinsics should be free
Swift SVN r27837
2015-04-27 23:43:40 +00:00
Arnold Schwaighofer
bde2409316 SimplifyCFG: Fix a bug in tryToReplaceArgWithIncomingValue
Replace all uses of the *argument value* with the incoming *value*.Triggered by my upcoming changes

Swift SVN r27836
2015-04-27 23:43:40 +00:00
Arnold Schwaighofer
8ed5229a58 SimplifyCFG: Appease SILLocation verification
We can't always adopt the location of the user for the integer_literal because
the user's location might be a (Implicit)ReturnLocation which is disallowed on
most instructions.

Swift SVN r27835
2015-04-27 23:43:39 +00:00
Nadav Rotem
fbfbc2afbf Fix a bug in a code that assumes that builtins must have two operands.
This commits moves the code that accesses the operands after the point where
we identify the builtins and know they have two operands.

rdar://20711757

Swift SVN r27810
2015-04-27 19:20:26 +00:00
Michael Gottesman
9006fca42b Rename SILBuilder::emitDestroyAddr => SILBuilder::emitDestroyAddrAndFold.
Now it matches SILBuilder::emit{StrongRelease,ReleaseValue}AndFold which perform
the same operation but on object types.

Swift SVN r27806
2015-04-27 17:29:50 +00:00
Erik Eckstein
3549d46d3b Remove -enable-static-init option from GlobalOpts.
It is now done by default.



Swift SVN r27805
2015-04-27 17:07:45 +00:00
Michael Gottesman
a3aa89d4c4 Remove Callback from SILBuilder and instead rename
emit{StrongRelease,ReleaseValue} => emit{StrongRelease,ReleaseValue}AndFold.
Then introduce a new method emit{StrongRelease,ReleaseValue} that returns a
PointerUnion containing the increment to be deleted if it exists. This obviates
the need for the callback.

Swift SVN r27804
2015-04-27 07:29:13 +00:00
Michael Gottesman
583d7aa30a Add a delete callback to SILBuilder so that if we delete retains and releases in emitStrongRelease, emitReleaseValue, passes (like SILCombine) can update their state. Also teach the closure deletion code how to detect such a case and not send a notification message if no new instruction is created.
Swift SVN r27803
2015-04-27 05:37:09 +00:00
Michael Gottesman
d494735329 Teach capture promotion how to handle all types of partial apply arguments. We technically don't need it now but it would be technical debt to leave it unfixed.
rdar://19552593

Swift SVN r27798
2015-04-27 01:59:46 +00:00
Chris Lattner
16522c3758 fix <rdar://problem/19623566> Obscure diagnostic for assigning negative numbers to unsigned
We now produce:
t.swift:1:15: error: negative integer '-9223372036854775808' overflows when stored into unsigned type 'UInt'
var x: UInt = -0x8000_0000_0000_0000
              ^



Swift SVN r27797
2015-04-27 01:18:47 +00:00
Chris Lattner
43c7334abc fix two QoI issues:
- <rdar://problem/16306600> QoI: passing a 'let' value as an inout results in an unfriendly diagnostic
 - <rdar://problem/16927246> provide a fixit to change "let" to "var" if needing to mutate a variable

We now refer to an inout argument as such, e.g.:

t.swift:7:9: error: cannot pass 'let' value 'a' as inout argument
  swap(&a, &b)
        ^

we also produce a note with a fixit to rewrite let->var in trivial cases where mutation is
being assed for, e.g.:

t.swift:3:3: note: change 'let' to 'var' to make it mutable
  let a = 42
  ^~~
  var

The note is produced by both Sema and DI.



Swift SVN r27774
2015-04-26 21:51:50 +00:00
Michael Gottesman
da0f1b972f Delete dead code.
Swift SVN r27773
2015-04-26 21:19:06 +00:00
Chris Lattner
fa4f1d86ee Recommit r27756 with an update to diagnostic_constant_propagation_int.swift, which is iOS only.
Swift SVN r27761
2015-04-26 15:56:41 +00:00
Chris Lattner
79b976dfc3 '#if 0' a big function that is never called to silence a warning. Someone should
look at this and nuke the function if it really is dead.


Swift SVN r27758
2015-04-26 15:13:04 +00:00
Ted Kremenek
4a227f2661 Speculatively revert "fix <rdar://problem/18213320> enum with raw values that are too big are not diagnosed"
This looks like it caused test 'SILPasses/diagnostic_constant_propagation_int.swift' to fail.

Swift SVN r27757
2015-04-26 15:12:58 +00:00
Chris Lattner
d5ae69b276 fix <rdar://problem/18213320> enum with raw values that are too big are not diagnosed
On that testcase, we now generate:

t.swift:8:22: error: integer literal '123456' overflows when stored into 'UInt8'
  case tooFarByFar = 123456
                     ^
t.swift:7:8: error: integer literal '256' overflows when stored into 'UInt8'
  case twoHundredFiftySix
       ^

instead of spitting out some warnings with no source loc (which Xcode eats).


This patch:
 - Propagates source locations for literals when synthesizing code in various places,
   so we get the right diagnostic at the right spot.
 - Improves the constant folding SIL Pass to print the value overflowing, which is
   necessary for cases with an implicit value (like 256 above), and is general goodness
   for the QoI of the diagnostic anyway.



Swift SVN r27756
2015-04-26 06:21:23 +00:00
Chris Lattner
61afbe993f Fix <rdar://problem/20193929> Can't "return nil" in a convenience initializer
This falls out of the rework I did of 'self' in initializers.  We now correctly
dealloc_ref the allocated object on the failure path of a convenience init.



Swift SVN r27752
2015-04-26 05:13:48 +00:00
Michael Gottesman
abb34fa1b0 Teach mandatory inlining how to use closure deletion infrastructure.
rdar://19552593

Swift SVN r27751
2015-04-26 05:11:57 +00:00
Michael Gottesman
af1be5004d Change SILCombine to use tryDeleteDeadClosure.
rdar://19552593

Swift SVN r27750
2015-04-26 05:11:56 +00:00
Michael Gottesman
eed6317da2 Add a callback struct to tryDeleteDeadClosure() that clients can use to be notified of instruction insertion and deletion.
rdar://19552593

Swift SVN r27749
2015-04-26 05:11:54 +00:00
Michael Gottesman
6891258151 Teach tryDeleteDeadClosure how to properly delete all types of captured arguments.
Previously, we relied on certain types not being passed in by the users of the
given function. Since I had a lot on my plate on the time and I knew it was safe
I left it in. Now I am going to be using this function in more places so it
needs to handle everything correctly.

rdar://19552593

Swift SVN r27748
2015-04-26 05:11:52 +00:00
Arnold Schwaighofer
e4e1254383 Reapply "SimplifyCFG: Fix a bug in the jump threading code"
This reverts commit r27739 reapplying r27722.

The test (validation/stdlib/Hashing.swift) that failed is expected to sometimes
fails.

Original message

"SimplifyCFG: Fix a bug in the jump threading code

When jump threading a block we used to propagate phi values directly into the
threaded block - instead of leaving in a copy. Because of this the SSA updater
would propagate the value feeding the copy from the next iteration.
Now when jump threading the destination block into the edge we leave in the phi
(copy) such that the SSA updater picks up value of the right iteration.

rdar://20617338"

Swift SVN r27741
2015-04-26 01:28:10 +00:00
Arnold Schwaighofer
50355e99dc Revert "SimplifyCFG: Fix a bug in the jump threading code"
This reverts commit r27722.

Broken bot.

Swift SVN r27738
2015-04-26 00:24:34 +00:00
Arnold Schwaighofer
9921573073 SimplifyCFG: Fix a bug in the jump threading code
When jump threading a block we used to propagate phi values directly into the
threaded block - instead of leaving in a copy. Because of this the SSA updater
would propagate the value feeding the copy from the next iteration.
Now when jump threading the destination block into the edge we leave in the phi
(copy) such that the SSA updater picks up value of the right iteration.

rdar://20617338

Swift SVN r27722
2015-04-25 22:42:29 +00:00
Chris Lattner
0e8f0d6bfc fix <rdar://problem/20679379> DI crashes on initializers on protocol extensions
DI makes the assumption that the type of self in an initializer is always
derived from a nominal type.  Now that you can put an initializer body on a
protocol, this isn't true anymore, so teach it about this.



Swift SVN r27714
2015-04-24 23:51:40 +00:00
Chris Lattner
3973d376ab when emitting the epilog 'return 0' for top level code, mark it as autogenerated,
fixing <rdar://problem/19664185> Pointless "always evaluates to true" warning in while true loops at the top level

Also, merge test/SILPasses/diagnose_unreachable_two_while_loops.swift into SILPasses/unreachable_code.swift.


Swift SVN r27696
2015-04-24 18:22:57 +00:00
Erik Eckstein
3149910bc9 Improve the removal of redundant global-init calls in GlobalOpt.
Due to a small bug, redundant init-calls were only removed if the first call was inside a loop.
Now it should also work in cases without loops.
Related radar: rdar://problem/20433505



Swift SVN r27693
2015-04-24 13:59:06 +00:00