Commit Graph

12848 Commits

Author SHA1 Message Date
Eli Friedman
ba4a76038b Make oneofs never implicitly generate an ExtensionDecl. This matters for local oneofs.
Swift SVN r2098
2012-05-31 21:20:56 +00:00
Chris Lattner
eef9e914fc tidy up.
Swift SVN r2097
2012-05-31 18:46:26 +00:00
Chris Lattner
44e11311f3 form calls to swift_retainAndReturnThree to improve epilog code when returning
string/array slices.  There is more to be done here, but this is enough to get 
the basic example in rdar://11563395.


Swift SVN r2095
2012-05-31 18:01:19 +00:00
Chris Lattner
41d02db9ca teach the canonicalize pass to decompose swift_retainAndReturnThree into is
relevant pieces (a swift_retain_noreturn + some copies).  This pessimizes
test2 in rdar://11563395 to generate the same code as test1 in that radar.


Swift SVN r2092
2012-05-31 05:19:21 +00:00
Eli Friedman
26bebcfd61 IRGen for break/continue.
Swift SVN r2089
2012-05-31 02:45:18 +00:00
Eli Friedman
c404598fcb Parsing and semantic analysis for 'break' and 'continue'.
Swift SVN r2087
2012-05-31 00:55:33 +00:00
Doug Gregor
3c2fb97bdf Introduce TypeBase::isExistentialType(), to determine whether a given
type is either a protocol type or a protocol composition type. The
long form of this query returns the minimal set of protocol
declarations required by that existential type.

Use the new isExistentialType() everywhere that we previously checked
just for ProtocolType, implementing the appropriate rules. Among other
things, this includes:
  - Type coercion
  - Subtyping relationship
  - Checking of explicit protocol conformance
  - Member name lookup

Note the FIXME for IR generation; we need to decide how we want to
encode the witnesses for the different protocols.

This is most of <rdar://problem/11548207>.


Swift SVN r2086
2012-05-31 00:26:13 +00:00
Eli Friedman
8eeeb361ad IRGen support for member functions on local types.
Swift SVN r2085
2012-05-31 00:16:46 +00:00
Eli Friedman
6abcbcde33 Allow using LinkEntity for members of/witnesses for local types. As a simple test to start using them, get rid of getAddrOfLocalInjectionFunction.
Swift SVN r2084
2012-05-30 23:53:58 +00:00
Chris Lattner
6291e4c2c8 zap an include
Swift SVN r2079
2012-05-30 20:57:42 +00:00
Chris Lattner
712c8c68de fix rdar://11558546 - Don't push a release past the instruction
that defines the pointer being released.


Swift SVN r2078
2012-05-30 20:42:16 +00:00
Chris Lattner
bb92b747f9 make "swift -arc-optimize" actually run the arc optimizer.
Swift SVN r2075
2012-05-30 20:26:34 +00:00
Eli Friedman
e2bfb30772 Add a verifier pass at the end of the optimization pipeline, to catch bugs in the ARC optimizer etc.
Swift SVN r2073
2012-05-30 18:47:41 +00:00
Eli Friedman
10f94cabc3 Fix missing "continue" in StructDecl IRGen.
Swift SVN r2067
2012-05-30 01:26:53 +00:00
Doug Gregor
c079874625 Implement parsing, AST, type canonicalization, and type validation for
protocol conformance types, e.g., 'protocol<P, Q>'. A few things
people *might* want to scream about, or at least scrutinize:

  - The parsing of the '<' and '>' is odd, because '<' and '>' aren't
    tokens, but are part of the operator grammar. Neither are '>>',
    '>>>', '<>', etc., which also come up and need to be parsed
    here. Rather than turning anything starting with '<' or '>' into a
    different kind of token, I instead parse the initial '<' or '>'
    from an operator token and leave the rest of the token as the
    remaining operator.
  - The canonical form of a protocol-composition type is minimized by
    removing any protocols in the list that were inherited by other
    protocols in the list, then sorting it. If a singleton list is
    left, then the canonical type is simply that protocol type.
  - It's a little unfortunate that we now have two existential types
    in the system (ProtocolType and ProtocolCompositionType), because
    many places will have to check both. Once ProtocolCompositionTypes
    are working, we should consider whether it makes sense to remove
    ProtocolType.

Still to come: name lookup, coercions.



Swift SVN r2066
2012-05-30 00:39:08 +00:00
Eli Friedman
e63eb3003a Some minor cleanups to decl IRGen.
Swift SVN r2065
2012-05-30 00:33:18 +00:00
Eli Friedman
9895a11be8 Get rid of some unnecessary handling for ExtensionDecls.
Swift SVN r2063
2012-05-30 00:27:32 +00:00
Chris Lattner
13b89db2e2 implement a new optimization to completely eliminate objects when they
don't escape and are only stored to.  This is common because other general
LLVM optimizations often forward propagate all the loads out of an object,
making it pointless.  This implements rdar://11542745, compiling that example
to:

define void @_T1t1PFT_T_() nounwind {
entry:
  tail call void @putchar(i32 32) nounwind
  ret void
}

and rdar://11542766 (eliminating the temporary forced onto the stack by &&), compiling
it into:

define i32 @_T1t4testFT1aNSs4Char_NSs6UInt32(i32 %a) nounwind {
entry:
  %a.off = add i32 %a, -33
  %0 = icmp ult i32 %a.off, 95
  %return_value.0.0 = select i1 %0, i32 4, i32 7
  ret i32 %return_value.0.0
}

This also deletes 19 objects in the stdlib, though it wildly changes inlining
behavior, so it is hard to exactly measure the impact.



Swift SVN r2052
2012-05-29 05:56:31 +00:00
Chris Lattner
16cf77644f switch the frontend to generate swift_retain_noresult calls instead of
swift_retain calls.  The pertinent difference is that the former can be
marked nocapture, allowing general LLVM optimizations more flexibility.

With this change, early-cse is able to zap 9 more instructions, and 3
more functions are able to be marked nocapture by functionattrs in the
stdlib.


Swift SVN r2043
2012-05-28 20:20:07 +00:00
Chris Lattner
fd3b5d287f swift_retain and swift_retain_noresult don't throw.
Swift SVN r2040
2012-05-28 19:19:13 +00:00
Chris Lattner
dd43739e7a rework the optimization pass to canonicalize incoming swift_retain calls to
swift_retain_noresult calls for the duration of optimization.  When we're done
hacking on the function, we rewrite all the retain_noresult calls *back* into
swift_retain calls.  No functionality change here.


Swift SVN r2039
2012-05-28 19:15:51 +00:00
Chris Lattner
a5a1a17994 add some commented out debugging stuff.
Swift SVN r2038
2012-05-28 18:04:15 +00:00
Chris Lattner
7191601569 enhance the optimizer to delete release(allocate()) pairs. This is enough to zap 2 of
them from the stdlib: ine from Format.printString.String, and one from Char.printFormatted.

This is also enough to resolve rdar://11542743, allowing us to optimize:

func maxtest(x : Int) -> Int {
  return max(x, 0)
}

into:

define i64 @_T1t7maxtestFT1xNSs5Int64_S0_(i64 %x) nounwind {
entry:
  %0 = icmp sgt i64 %x, 0
  %x.y.i = select i1 %0, i64 %x, i64 0
  ret i64 %x.y.i
}

Instead of the mess of retains and releases shown in 11542743.



Swift SVN r2037
2012-05-28 17:05:42 +00:00
Chris Lattner
2445a27406 When optimizing release(o1), allow scanning past a release(o2) since it
cannot affect the lifetime of o1 in a way we care about.  This allows
eliminating 5 more retain/release pairs from the stdlib, including
from String(Int128, radix)->String,  String(Double)->String,
and the slice reduce methods.


Swift SVN r2036
2012-05-28 16:53:57 +00:00
Chris Lattner
59b81036d1 implement the most trivial form of release optimization: scan backwards from a release
until we find a retain of the same object.  If we find one, zap both.  This is good
enough to delete 22 retain/release pairs out of the stdlib, including the one at the
end of String.subscript(rng : IntRange) -> String, which motivated rdar://11537101.


Swift SVN r2035
2012-05-28 16:47:58 +00:00
Chris Lattner
8975c0dbce teach the ARC optimizer to zap retain/release(null), which occurs 3 times in the standard library.
rdar://11542761


Swift SVN r2032
2012-05-28 02:02:44 +00:00
Chris Lattner
4f4636db31 adjust to mainline API change, and implement rdar://11542870 - @swift_release should be marked nocapture
Swift SVN r2031
2012-05-28 01:52:47 +00:00
Chris Lattner
e32922c3b3 Implement two simple passes in the ARC optimizer:
1. First thing, canonicalize the input IR so that nothing uses the result of 
   swift_retain, making it easier to reason about pointers.

<nothing in between yet>

2. Last thing, optimize register pressure by making use of the return value 
   of swift_retain where possible.

#1 is a pessimization, but is fixed (optimally!) by #2.  Our implementation
of #2 is more powerful than the ObjC ARC optimizers corresponding stuff, because
we insert PHI nodes etc in cases where there isn't a strictly dominating retain
of a use.  Ours is also much simpler :)



Swift SVN r2030
2012-05-28 01:26:26 +00:00
Dave Zarzycki
899eb001ac Remove unbalanced ')'
Swift SVN r2029
2012-05-28 01:20:25 +00:00
Chris Lattner
d1487a3ede Scaffolding for ARC optimizer pass.
Swift SVN r2027
2012-05-28 00:04:29 +00:00
John McCall
fe968974e3 We were accidentally giving value witnesses default visibility,
which doesn't play well with others.

Swift SVN r1996
2012-05-25 18:31:02 +00:00
John McCall
c9fdb3b224 Back this out, it's not really doing anything.
Revert "Hack the linkage and visibility of witnesses so that the REPL"

This reverts commit 3beb1278dfb6c306826eddd6c01fe79f4e94239e.

Swift SVN r1995
2012-05-25 18:31:00 +00:00
John McCall
28c7ba900b Hack the linkage and visibility of witnesses so that the REPL
doesn't die if the same witness is required on multiple lines.
The right solution here is to find some way to re-use the
previous functions.

Swift SVN r1994
2012-05-25 17:58:00 +00:00
John McCall
40d1591f89 Some minor tweaks to make our use of the allocation entrypoints
match the actual entrypoints vended by the runtime:
1) there is no swift_slowRawAlloc
2) swift_deallocObject takes two arguments
Also, make all calls to swift_allocObject go through a common
function so that we can easily use optimized entrypoints if the
runtime provides them.

Swift SVN r1993
2012-05-25 17:34:59 +00:00
John McCall
4b562e6b62 Use the actual raw-allocation APIs, including the optimized
allocation entrypoints.

Swift SVN r1976
2012-05-24 19:16:09 +00:00
John McCall
f3c30b7386 'noalias' needs to go on the return value, not on the function
operand.  While I'm at it, test all the side-allocation value witnesses.

Swift SVN r1974
2012-05-24 17:55:03 +00:00
John McCall
3bab069ed1 Fix a think-o where I was adding the callee-determined arguments
after the normal arguments instead of before.

Swift SVN r1970
2012-05-24 16:43:19 +00:00
John McCall
30244a2f0d Do all the dancing necessary to get method calls through
protocols working.

Swift SVN r1969
2012-05-24 12:16:51 +00:00
John McCall
6a16a5aae4 Prepare some abstractions for calling through an existential type.
Swift SVN r1968
2012-05-24 12:16:47 +00:00
John McCall
872cd45dae Stub out the less-important implementations of ExistentialMemberRefExpr.
Swift SVN r1967
2012-05-24 12:16:44 +00:00
John McCall
95a8c35a36 Implement IR-generation for instance method witnesses.
Swift SVN r1966
2012-05-24 12:16:40 +00:00
Doug Gregor
0062c84351 Introduce ExistentialMemberRefExpr for references to the members of
values of existential type, e.g.,

  var x : Printable
  x.print()

Existential member references reify the type of the implicit object
argument (implicitly, because we have no way of expressing this in the
type system), and replace the types of any other archetypes
with existential types that (don't, but will eventually) conform to
the protocols to which the archetypes conform.



Swift SVN r1963
2012-05-23 23:06:34 +00:00
Doug Gregor
9096497f0f Rename "dependent type" to "unresolved type" universally. We've been
using the term "unresolved" in expressions for a while, and it fits
for types better than "dependent type."

The term "dependent type" will likely come back at some point to mean
"involves an archetype".



Swift SVN r1962
2012-05-23 19:03:14 +00:00
Doug Gregor
74436a3120 Introduce the implicit 'This' type into protocols, which refers to the
type T that conforms to the given protocol. 'This' is modeled simply
as an associated type.



Swift SVN r1953
2012-05-23 14:45:55 +00:00
Doug Gregor
d37602629e Implement parsing, AST, and conformance checking for associated types
in protocols, e.g.,

  protocol Range {
    typealias Element
    func getAndAdvance() -> Element
  }



Swift SVN r1941
2012-05-22 21:45:58 +00:00
Doug Gregor
5f92d4a44d Make OpaqueValueExpr an unchecked expression; it does not persist in the AST.
Swift SVN r1933
2012-05-22 14:18:58 +00:00
Doug Gregor
a9906ad38f Introduce support for implicit user-defined conversions.
A user-defined conversion function is an instance method that accepts
an empty tuple and returns a value of the type we're converting to,
has the [conversion] attribute, and is named __conversion. The last of
these restrictions is a temporary hack to work around our inability to
perform a lookup across all extensions for "every function with the
conversion attribute", and shouldn't last too long.

As in C++, we only get one user-defined conversion function. Unlike in
C++, a constructor is not (and cannot) be a conversion function.

Introduce NSString <-> String conversion functions, but leave the
runtime implementations as stubs for Dave to fill in.



Swift SVN r1921
2012-05-21 23:36:16 +00:00
John McCall
3d5380045a Allocate space for function witnesses.
Swift SVN r1917
2012-05-21 20:01:39 +00:00
John McCall
a8e511d429 Expound a bit about the decisions we need to come to about protocol
resilience.

Swift SVN r1916
2012-05-21 20:01:38 +00:00
John McCall
d1ce608f17 Implement conversion to super-protocols.
Swift SVN r1915
2012-05-21 20:01:37 +00:00