Commit Graph

12816 Commits

Author SHA1 Message Date
Eli Friedman
f1ffa870a3 A few adjustments to AST/Sema for ConstructorDecls, and starting IRGen.
Swift SVN r2160
2012-06-06 00:53:44 +00:00
Eli Friedman
75907029f1 Add parsing and semantic analysis for a basic ConstructorDecl. Still missing: no IRGen, and semantic analysis to actually call them.
Swift SVN r2159
2012-06-05 23:51:19 +00:00
Eli Friedman
cd8632c685 Compute heap layout for classes lazily, so we don't get infinite recursion. <rdar://problem/11588882>.
Swift SVN r2155
2012-06-05 20:17:23 +00:00
John McCall
53646ccfc8 Better support for mangling, emitting, and using local
functions.

Swift SVN r2152
2012-06-05 04:51:21 +00:00
John McCall
b5381edb88 Some overlooked uses of std::vector that are unnecessary
now that SmallVector is move-only-compatible.

Swift SVN r2151
2012-06-05 04:51:12 +00:00
John McCall
24a84132ca More CC-related changes.
Swift SVN r2150
2012-06-05 04:51:04 +00:00
John McCall
5064f39024 Refactor towards the goal of using different CCs when
passing this pointers or data arguments.

Swift SVN r2149
2012-06-05 04:50:58 +00:00
John McCall
6758b45136 Kill FixedPadding::Realign; it is not address-invariant, which
is a property that we'd prefer to maintain.

Swift SVN r2148
2012-06-05 04:50:49 +00:00
John McCall
3dd77943df Change the size of a prototype type to 3 pointers rather than
a fixed size of 16 bytes.  3 pointers is the magic value in
swift:  many, many things are better if we can handle three
pointers efficiently.

Swift SVN r2147
2012-06-05 04:50:42 +00:00
Chris Lattner
fe24ea3c8f delete some pointless objc_retain/objc_release pairs, which show up in String -> NSString conversions.
Finishes off rdar://11583269


Swift SVN r2127
2012-06-03 04:41:00 +00:00
Chris Lattner
5074859478 teach the optimizer about objc_retain and objc_release, allowing us to zap a objc_release(null)
from the String->NSString conversion routine (rdar://11583269)


Swift SVN r2126
2012-06-03 04:33:21 +00:00
Chris Lattner
83cee744d1 sinking retains pushed them after insertelement instructions in a return sequence,
which defeated the optimization which formed "retainThree" tail calls.  Restructure
and generalize this optimization to handle the new and old forms.  Through
the combination of the two, we now form 19 of them on the stdlib.  Before I broke
things, we only formed 14 of them.


Swift SVN r2124
2012-06-03 03:50:07 +00:00
Chris Lattner
540b7b92e6 implement trivial retain motion, pushing retains past operations that obviously cannot release an object (unless we get to a matching retain of course).
This allows us to optimize away 43 (instead of 31) retain/release pairs from the stdlib.  This resolves rdar://11571612.


Swift SVN r2123
2012-06-03 00:53:18 +00:00
Chris Lattner
32f529f1db Split arc-optimizer into two passes: arc-optimize and arc-expand.
This makes the two phases independently testable, but is also the
right thing to do: previously we'd form swift_retain early enough
that inlining would inline them from previously optimized callees
into callers, and this would block some mid-level optimizations
from doing nice things (because swift_retain isn't no-escape).

It's a small thing, but doing this allows us to eliminate a few 
more "and x, 9223372036854775807"'s from the stdlib.  We also
end up doing a lot less optimizations because we do them early
instead of only having the optimizations exposed after inlining
deeply.



Swift SVN r2114
2012-06-02 16:43:51 +00:00
Chris Lattner
fac11ffe56 Introduce a swift-specific alias analysis pass that knows that retain/release/alloc
don't mod/ref any state to swift code.  This allows the general LLVM optimizer to be
*much* more aggressive.  For example, on swift.swift, GVN deletes 15% more instructions,
jump threading folds 2.4X more terminators, SCCP removes 3.3X more instructions, and 2
more retain/release pairs are removed by the ARC optimizer.


Swift SVN r2113
2012-06-02 02:39:27 +00:00
Eli Friedman
ae86d64644 Rename Decl::getLocStart() to Decl::getStartLoc(). Add Decl::getLoc(), which is essentially the location which should be used for diagnostics.
Swift SVN r2105
2012-05-31 23:56:30 +00:00
Chris Lattner
a7f2593b51 make sure to set the tail marker on the generated calls.
Swift SVN r2103
2012-05-31 23:21:47 +00:00
Chris Lattner
91a80673b7 Enhance the swift_retainAndReturnThree optimizer to be able to handle the case
when swift_retainAndReturnThree is inlined from a previously optimized function.

The upshot of this is that we compile:

var a : String
func f() -> String {
  return a
}

into:

__T1t3fooFT_NSs6String:
	pushq	%rax
	movq	__T1t1xNSs6String+16(%rip), %rcx
	movq	__T1t1xNSs6String+8(%rip), %rdx
	movq	__T1t1xNSs6String(%rip), %rsi
	movq	%rcx, %rdi
	callq	_swift_retainAndReturnThree
	popq	%rsi
	ret

instead of:

__T1t3fooFT_NSs6String:
	pushq	%r14
	pushq	%rbx
	pushq	%rax
	movq	__T1t1aNSs6String+8(%rip), %r14
	movq	__T1t1aNSs6String(%rip), %rbx
	movq	__T1t1aNSs6String+16(%rip), %rdi
	callq	_swift_retain
	movq	%rax, %rcx
	movq	%rbx, %rax
	movq	%r14, %rdx
	addq	$8, %rsp
	popq	%rbx
	popq	%r14
	ret



Swift SVN r2102
2012-05-31 22:57:10 +00:00
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