Commit Graph

489 Commits

Author SHA1 Message Date
Manman Ren
5311e7a98f [Global Opt] revert r21996.
r21996 tries to take advantage of LLVM global opt that eliminates global
initializers by using llvm.global_ctors. Revert it because we can't guarantee
that they will be optimized to constant initializers.

A modifed version will follow that uses constant initializers directly in IRGen.


Swift SVN r22001
2014-09-17 03:30:06 +00:00
Manman Ren
0351a2aa85 [Global Opt] update SILGlobalOpt to use static initializer if possible.
Update SILGlobalOpt to remove "once" call from addressor and set the
InitializerF for SILGlboalVariable if legal.

For calls to addressor in non-cold block, we check the addressor to find out
the globalinit_func and the associated SILGlobalVariable. If legal, we set
InitializerF of SILGlobalVariable and remove "once" call from addressor.

The current rules for legality:
1> the addressor contains a single "once" call
2> it calls globalinit_func
3> the globalinit_func is called by "once" from a single location
4> the globalinit_func is trivial

Update IRGen to emit llvm.global_ctors for global variables with static
initializers (i.e non-null InitializerF).

Performance --------
After:
Totals,54,67202,67202,67202,0,0 Onone
Totals,54,88948,88948,88948,0,0 O
Totals,54,71222,71222,71222,0,0 Ounchecked
Totals,54,66405,66405,66405,0,0 Onone
Totals,54,88759,88759,88759,0,0 O
Totals,54,71761,71761,71761,0,0 Ounchecked
Before:
Totals,55,68133,68133,68133,0,0 Onone
Totals,55,92458,92458,92458,0,0 O
Totals,55,72262,72262,72262,0,0 Ounchecked
Totals,55,69022,69022,69022,0,0 Onone
Totals,55,92178,92178,92178,0,0 O
Totals,55,72593,72593,72593,0,0 Ounchecked


Swift SVN r21996
2014-09-16 23:20:37 +00:00
Manman Ren
a952c556c9 [Global Opt] replace GlobalAddrInst with SILGlobalAddrInst.
Update SILGen to create SILGlobalVariable and SILGlobalAddrInst instead of
GlobalAddrInst. When we see a definition for a global variable, we create
the corrsponding SILGlobalVariable definition.

When creating SILGlobalVariable from a global VarDecl, we mangle the global
VarDecl in the same way as we mangle it at IRGen. The SILLinkage is also
set in the same way as we set it at IRGen.

At IRGen, we use the associated VarDecl for SILGlobalVariable if it exists,
to have better debugging information.

We set the initializer for SILGlobalVariable definition only.

We also handle SILGlobalAddrInst in various SILPasses, in the similar way
as we handle GlobalAddrInst.

rdar://15493694


Swift SVN r21887
2014-09-11 20:00:39 +00:00
Manman Ren
47272fd25f [Linkage] move getSILLinkage from GenDec.cpp to FormalLinkage.h.
So SILGen can call getSILLinkage in follow-on patches to replace GlobalAddrInst
with SILGLobalAddrInst.

No functionaility change.


Swift SVN r21881
2014-09-11 17:49:39 +00:00
Jordan Rose
dcc3b9961b [IRGen] Mark all visible external entities as 'used'.
...so that they don't get dead-stripped out of an executable...
...so that they can be accessed by unit tests (or in-process plug-ins).

In Swift, marking something 'public' is a deliberate action (unlike in C),
so anything marked 'public' should be left in the final binary...even when
we're building an executable.

We currently /also/ mark the symbols for internal and private decls as
external as well, so they also won't be stripped. Hopefully that will
change soon.

rdar://problem/18173029

Swift SVN r21815
2014-09-09 23:45:43 +00:00
John McCall
0ddc7ee5b6 Resilience expansion is not an IR-generation concept.
If a type has to be passed or returned resiliently, it
will necessarily be passed indirectly, which is already
represented in SILFunctionType.  There is no need to
represent this as a separate channel of information.

NFC. Also fixes a problem where the signature cache
for ExtraData::Block was writing past the end of an
array (but into the storage for an adjacent array
which was fortunately never used).

ExtraData should also disappear as a concept, but we're
still relying on that for existential protocol witnesses.

Swift SVN r21548
2014-08-28 23:07:50 +00:00
Erik Eckstein
99cc7603be Add an @inline(__always) function attribute.
This will let the performance inliner inline a function even if the costs are too high.
This attribute is only a hint to the inliner.
If the inliner has other good reasons not to inline a function,
it will ignore this attribute. For example if it is a recursive function (which is
currently not supported by the inliner).

Note that setting the inline threshold to 0 does disable performance inlining at all and in
this case also the @inline(__always) has no effect.



Swift SVN r21452
2014-08-26 00:56:34 +00:00
Jordan Rose
64d8f31d26 [IRGen] Register Objective-C classes explicitly in immediate mode as well.
Otherwise we can't use KVO with script files.

Swift SVN r21390
2014-08-21 23:50:14 +00:00
Jordan Rose
9b0d643029 Move 'Playground' into LangOptions and out of FrontendOptions and IRGenOptions.
Also, use 'Playground' to control the behavior of ignored expressions
(which are not an error because they are displayed in the playground log).

This is preparation for LLDB no longer passing 'DebuggerSupport' for a
playground <rdar://problem/18090611>. 'DebuggerSupport' now only applies
to REPL-like contexts and enables identifiers beginning with $, special
rules for parsing top-level code, ignored expressions (like playgrounds),
and the @LLDBDebuggerSupport attribute.

Besides ignored expressions, 'Playground' enables the playground transformation
and provides an entry point for debugger initialization.

Note that this is a bit insincere---many of the options controlled by both
'Playground' and 'DebuggerSupport' really only apply to the main source file
or main module. If/when we add back support for source file imports, we'll
need to revisit all of LangOptions and see which of them should /really/
apply to /everything/ in the ASTContext.

Swift SVN r21384
2014-08-21 22:36:24 +00:00
Arnold Schwaighofer
cd799f8e46 Revert "Add an inline(late) attribute"
This reverts commit r21286.

Discussions ongoing.

Swift SVN r21289
2014-08-19 18:15:25 +00:00
Arnold Schwaighofer
7aa62ce835 Add an inline(late) attribute
This disables inlining at the SIL level. LLVM inlining is still enabled. We can
use this to expose one function at the SIL level - which can participate in
dominance based optimizations but which is implemented in terms of a cheap check
and an expensive check (function call) that benefits from LLVM's inlining.

Example:

The inline(late) in the example below prevents inlining of the two checks. We
can now perform dominance based optimizations on isClassOrObjExistential.
Without blocking inlining the optimizations would apply to the sizeof check
only and we would have multiple expensive function calls.

@inline(late)
func isClassOrObjExistential(t: Type) -> Bool{
  return sizeof(t) == sizeof(AnyObject) &&
    swift_isClassOrObjExistential(t)
}

We do want inlining of this function to happen at the LLVM level because the
first check is constant folded away - IRGen replaces sizeof by constants.

rdar://17961249

Swift SVN r21286
2014-08-19 18:05:44 +00:00
Doug Gregor
29108b932a Weak-link to Objective-C classes that Clang considers to be weak-imported.
This is a simple, trivialy, not-even-half-way-there solution to weak
leaking of Objective-C classes introduced after the deployment
target. It only works for Objective-C classes and C global variables
that Clang consideres to be "weak imported". However, this bare
minimum should be enough to develop an app (by jumping through various
hoops) that uses new functionality when its
available. <rdar://problem/17296490>, which I've restricted in scope
to capture this.

Swift SVN r20956
2014-08-02 19:33:36 +00:00
Sean Callanan
9bc668b119 Fixes to the playground transform to make it work
with the test case I'm working on.

Who knew that test cases find bugs?


Swift SVN r20451
2014-07-24 00:42:18 +00:00
Erik Eckstein
7a3e406ed3 Propagate @inline(never) attribute to llvma
This fixes <rdar://problem/17619020>



Swift SVN r20410
2014-07-23 16:26:15 +00:00
John McCall
1ae1f750d0 Move most type metadata lookups into their own readnone
functions, and make those functions memoize the result.

This memoization can be both threadsafe and extremely
fast because of the memory ordering rules of the platforms
we're targeting: x86 is very permissive, and ARM has a
very convenient address-dependence rule which happens to
exactly match the semantics we need.

Swift SVN r20381
2014-07-23 07:38:26 +00:00
Michael Gottesman
4ec0a81e5f Add linkage SILLinkage::SharedExternal for deserialized functions with shared linkage.
*NOTE* This linkage is different from {Public,Hidden}External in that it has no
extra semantic meaning beyond shared.

The use of this linkage is to ensure that we do not serialize deserialized
shared functions. Those shared functions can always be re-deserialized from the
original module. This prevents a whole class of bugs related to the
creation of module cross references since all references to the shared
item go straight to the original module.

<rdar://problem/17772847>

Swift SVN r20375
2014-07-23 05:04:48 +00:00
Dave Abrahams
21669b3aee [stdlib] Add "Mutable" to [Autoreleasing]UnsafePointer
UnsafePointer becomes UnsafeMutablePointer
AutoreleasingUnsafePointer becomes AutoreleasingUnsafeMutablePointer

Swift SVN r20316
2014-07-22 16:56:23 +00:00
Joe Groff
6cf0cf64b4 IRGen: Assert that categories are never emitted for foreign classes.
And add a test that an extension to a CF type doesn't emit a bogus class object reference. <rdar://problem/17569520>

Swift SVN r19590
2014-07-07 00:03:50 +00:00
Joe Groff
10fae3e228 Remove -enable-string-pointer-conversion staging flag.
Swift SVN r19524
2014-07-03 18:43:20 +00:00
Joe Groff
0fc7e3c442 Mangle C_ARGV appropriately when typed UnsafePointer<CChar> in the string-pointer-conversions regime.
This hack sucks

Swift SVN r19390
2014-07-01 04:48:48 +00:00
Bob Wilson
2df66cf8c4 Implement inline scopes for the performance inliner.
Mandatory-inlined (aka transparent functions) are still treated as if they
had the location and scope of the call site. <rdar://problem/14845844>
Support inline scopes once we have an optimizing SIL-based inliner

Patch by Adrian Prantl.

Swift SVN r18835
2014-06-12 19:48:43 +00:00
Jordan Rose
2d004856cf Don't try to autolink the underlying module in a mixed-source framework.
Doing so causes the linker to list the framework itself as one of its
dependencies, which confuses tools that depend on the linker's dependency
output.

<rdar://problem/17006845>

Swift SVN r18578
2014-05-22 23:50:38 +00:00
Joe Groff
6c280e27e2 IRGen: Emit runtime initialization into top_level_code for playgrounds.
To help with the playground's transition to top level code, hand the -playground frontend flag down to IRGenOptions, so that IRGen knows to emit runtime initializer code for classes and categories into top_level_code rather than an attributed function.

Swift SVN r18479
2014-05-21 02:11:09 +00:00
John McCall
f896f703bc Don't emit a category for an empty extension just because
we're extending an ObjC class.

Swift SVN r18384
2014-05-19 04:00:37 +00:00
Greg Clayton
2a74838159 Extensions to Objective-C objects fail in REPL if the class is not already initialized and LLDB now gets Objective C categories and extensions initialized properly.
Prior to this fix this would fail:
(swift) import Foundation
(swift) extension NSDate { func foo() { println("foo") }}   

As the Class for NSDate was not initialized.

<rdar://problem/16934080>



Swift SVN r18206
2014-05-16 19:49:41 +00:00
Doug Gregor
d8cca3a6a6 Make IRGen actually work in builds without assertions enabled.
Swift SVN r18099
2014-05-15 06:21:25 +00:00
Joe Groff
793fe06a34 SILGen: Emit an artificial toplevel for files with @UIApplicationMain classes.
If a source file contains the main class for its module, then implicitly emit a top_level_code that invokes UIApplicationMain with the name of the marked class.

Swift SVN r18088
2014-05-15 00:53:38 +00:00
Greg Clayton
709e5773ad Fix REPL test failures:
Failing Tests (9):
    Swift :: DebugInfo/variables-interpreter.swift
    Swift :: DebugInfo/variables-repl.swift
    Swift :: Interpreter/SDK/Cocoa_repl.swift
    Swift :: Interpreter/fractal.swift
    Swift :: Interpreter/import.swift
    Swift :: Interpreter/mandelbrot.swift
    Swift :: Interpreter/repl.swift
    Swift :: Serialization/operator.swift
    Swift :: stdlib/VarArgs.swift



Swift SVN r18041
2014-05-14 00:06:19 +00:00
Greg Clayton
5977f42f86 Add code to initialize anything we need in the special debugger function for LLDB expressions, REPL and playground.
This current fix will initialize all objective C classes with the objective C runtime when any ObjC classes are defined in expressions

<rdar://problem/16029117>



Swift SVN r18037
2014-05-13 23:10:44 +00:00
Joe Groff
43cc4a28f2 IRGen: Instantiate ObjC metaclasses and rodata with generic classes.
If we officially register our classes with the ObjC runtime, we can't get away with generic class instances sharing a runtime name or a metaclass anymore, so pack the metaclass and rodata templates into the generic metadata template and add codegen to the fill function to wire up the references at instantiation time. Since we don't have a runtime mangler yet, create a stupid unique name for classes by tacking on the pointer value.

Swift SVN r17882
2014-05-11 19:42:38 +00:00
John McCall
bafeb84a56 Generate unique type metadata for foreign classes.
Swift SVN r17430
2014-05-05 06:45:42 +00:00
Doug Gregor
93bd2a8374 Don't emit Objective-C metadata for @NSManaged property getters/setters
... but we still need the property metadata.

Swift SVN r17200
2014-05-01 22:59:02 +00:00
John McCall
0865837327 Emit non-unique type metadata lazily in IRGen.
We no longer emit any unnecessary objects just because
you import Foundation/Cocoa/whatever, at least from
IRGen; SILGen still does a ton of useless extra work.

Swift SVN r16920
2014-04-27 05:56:29 +00:00
John McCall
7c742b4d32 Emit SILWitnessTables lazily if their linkage allows it.
Swift SVN r16911
2014-04-27 04:29:56 +00:00
Doug Gregor
09797f7f99 Introduce a new declaration node, ParamDecl, for function parameters.
Use this node to capture the argument name and its source location in
the AST. We're only building these in one place at the moment; the
rest will be updated soon.


Swift SVN r16581
2014-04-20 05:23:35 +00:00
Joe Groff
85ab7ed9e1 Remove mangling and demangling for block shims.
Swift SVN r16488
2014-04-18 02:36:54 +00:00
Joe Groff
eaa6088102 SIL: Remove the now-obsolete bridge_to_block instruction.
Swift SVN r16487
2014-04-18 02:26:10 +00:00
Joe Groff
f7a375e443 IRGen: Correct the declared return type of block shims to match lowering of block types.
Fixes a crash when a block-bridged function was stored.

Swift SVN r16330
2014-04-14 21:09:06 +00:00
Dmitri Hrybenko
110f85bc16 Move @exported to use new attribute infrastructure
Swift SVN r16158
2014-04-10 13:35:35 +00:00
Joe Groff
8adaab0233 Fold ExtInfo::isThin and ::isBlock into a "Representation" enum.
These bits are orthogonal to each other, so combine them into one, and diagnose attempts to produce a type that's both. Spot-fix a bunch of places this revealed by inspection that we would have crashed in SILGen or IRGen if blocks were be handled.

Swift SVN r16088
2014-04-09 00:37:26 +00:00
John McCall
62844f58b6 Emit storage and (lazy) global initialization for static
variables in extensions of non-generic structs and enums.

rdar://16520242

Swift SVN r15957
2014-04-04 21:42:17 +00:00
Joe Groff
f5816103e4 IRGen: Emit an OBJC_CLASS symbol for @objc classes.
Create a global alias into the metadata of @objc-visible classes at their address point, which should make these classes visible for linking from ObjC, fixing <rdar://problem/14449644>.

Swift SVN r15921
2014-04-04 04:05:05 +00:00
Joe Groff
9f7dab725c Make the ASTContext parameter to MetatypeType::get optional for type-checked types.
We can just get it from the instance type, if the instance type has been fully initialized, which is the case except during parsing of type decls when the decls' own types are being formed.

Swift SVN r15598
2014-03-29 02:50:30 +00:00
Michael Gottesman
f807249aa8 [deserialization] Store the mangled name of a SILWitnessTable on the instance itself.
The importance of this is that we will be able to use this name during
SIL serialization/deserialization to lookup partially deserialized
witness tables.

I left IRGen's original code alone until I can discuss with Joe/John
combining the logic together.

Swift SVN r15400
2014-03-24 05:07:20 +00:00
Joe Groff
365c2eac8e Revert "IRGen: Emit an OBJC_CLASS symbol for @objc classes."
This reverts commit r14927. The LLVM language design for this feature will
obviate the need for the inline asm approach.

Swift SVN r15171
2014-03-17 23:24:54 +00:00
John McCall
446a9bd4a7 Introduce CanType versions of the various "getXOrBoundGenericX"
accessors.

Optimize these accessors by making them check for
BoundGenericXType instead of BoundGenericType and dyn_cast'ing
the Decl.  (The latter used to be necessary before we split
BoundGenericType.)

Swift SVN r15037
2014-03-14 05:59:44 +00:00
Ted Kremenek
e9976fb890 Remove dead 'return'.
Swift SVN r14930
2014-03-11 21:51:51 +00:00
Joe Groff
ac64ab7c60 IRGen: Emit an OBJC_CLASS symbol for @objc classes.
LLVM doesn't have interior symbols as a first-class concept, so generate module inline asm that defines the OBJC_CLASS symbol relative to the Swift metadata symbol. To prevent our system linkers from considering this symbol as the start of a new object and breaking apart class metadata objects, put the class metadata object into a no_dead_strip section.

This isn't quite enough to get the OBJC_CLASS symbol to be available--the symbol appears to show up in the .o as an undefined symbol and stripped out of the .dylib. John is investigating with the backend and linker teams as to why this is the case.

Swift SVN r14927
2014-03-11 21:44:31 +00:00
Joe Groff
c5feea4697 SILGen: Emit conformances for external definitions.
Teach IRGen to honor the linkage of SILWitnessTables, and teach SILGen to emit witness tables and protocol witness thunks for external definitions with shared linkage. Fixes <rdar://problem/16264703>.

Swift SVN r14908
2014-03-11 05:08:58 +00:00
Adrian Prantl
85436b0ee2 Update a comment and make arguments more explicit.
rdar://problem/15493512.

Swift SVN r14788
2014-03-07 19:35:23 +00:00