Commit Graph

1572 Commits

Author SHA1 Message Date
Jordan Rose
4fae1f664f [IRGen] Remove the AST walk that looks for local type decls.
Per the previous commit we are no longer using this. Minor save in
simplicity and maybe a bit of compilation time as well.

In the long run IRGen probably shouldn't be pulling information from the
AST at all; the SILModule should be able to tell it what types it needs
to emit information for. But this is still an improvement for now.

No functionality change (that was the previous commit).

Swift SVN r24840
2015-01-30 03:54:08 +00:00
Jordan Rose
2969aab1c1 Stop giving local types private linkage; the debugger may still access them.
Instead, just fall through to the normal public/internal/private switch
added in the previous commit. Local declarations are always private.

Make sure we emit all local declarations by using the list in the SourceFile,
rather than walking the AST (which missed a few cases and was less efficient
anyway).

As an exception, declarations without accessibility at all still get private
linkage. These are things like local variables that don't get accessed by
symbol, even when using the debugger.

rdar://problem/19623016

Swift SVN r24839
2015-01-30 03:54:07 +00:00
Erik Eckstein
14af3a57e8 Enable elimination of dead methods which are in classes of higher visibility.
The underlying problem is that e.g. even if a method is private but its class is public, the method can be referenced from another module - from the vtable of a derived class.
So far we handled this by setting the SILLinkage of such methods according to the visibility of the class. But this prevented dead method elimination.
Now I set the SILLinkage according to the visibility of the method. This enables dead method elimination, but it requires the following:
1) Still set the linkage in llvm so that it can be referenced from outside.
2) If the method is dead and eliminated, create a stub for it (which calls swift_reportMissingMethod).



Swift SVN r23889
2014-12-12 17:35:40 +00:00
Adrian Prantl
3202823f3e Debug info: Emit the actual types for specialized variables instead of
their generic type.

NFC for unoptimized code, testcase for optimized code will come with
rdar://problem/18709125.

Swift SVN r23676
2014-12-04 02:13:46 +00:00
Graham Batty
06c75f5f76 Revert "Appropriately disable some more objective-c codegen on non-objc."
This reverts commit f62a356cd3689a1325c921315cedfd56eda7cb00.

Swift SVN r23578
2014-11-24 17:42:18 +00:00
Graham Batty
b0d7b07e05 Appropriately disable some more objective-c codegen on non-objc.
Swift SVN r23574
2014-11-24 17:40:42 +00:00
Graham Batty
17b1721f8f Implement ELF protocol conformance loading.
This works by loading the protocols from a specially named symbol,
which is generated by the linker through the help of a linker script
that merges all of the protocol conformance blocks into one section
with its size at the start of it and points a global symbol at
the section.

We do all this because unlike MachO, section information does not
survive to be loaded into memory with ELF binaries. Instead,
the mappings that survive are 'segments', which contain one or
more sections. Information about how these relate to their original
sections is difficult, if not impossible, to obtain at runtime.

Swift SVN r23518
2014-11-21 17:09:48 +00:00
Graham Batty
c61e40bbb8 Revert "Implement ELF protocol conformance loading."
This reverts commit r23475 at dgribenko's request.

Swift SVN r23487
2014-11-20 21:31:46 +00:00
Graham Batty
738a1b4ba0 Implement ELF protocol conformance loading.
This works by loading the protocols from a specially named symbol,
which is generated by the linker through the help of a linker script
that merges all of the protocol conformance blocks into one section
with its size at the start of it and points a global symbol at
the section.

We do all this because unlike MachO, section information does not
survive to be loaded into memory with ELF binaries. Instead,
the mappings that survive are 'segments', which contain one or
more sections. Information about how these relate to their original
sections is difficult, if not impossible, to obtain at runtime.

Swift SVN r23475
2014-11-20 17:40:05 +00:00
Ben Langmuir
e9e1666ab0 Update for upstream LLVM changes
* removal of StringMap's GetOrCreateValue
* SmallSet::insert now returns a pair like std::set

Swift SVN r23435
2014-11-19 16:49:30 +00:00
Joe Groff
b5b860ad39 IRGen: Properly create ObjC protocols using the runtime in JIT mode.
Just injecting a new protocol descriptor into an already-running ObjC runtime isn't a good idea, since the runtime might have already canonized the protocol somewhere else, and it won't recognize that classes conform to protocols it doesn't know about.

Swift SVN r23313
2014-11-14 01:01:02 +00:00
Joe Groff
af0121f8e6 IRGen: Don't nonlazily realize classes (unless they ask).
We lazily realize classes when we access their metadata now, so there's no need to force the ObjC runtime to do this greedily anymore, except for classes that the runtime statically references. For those cases, add an @objc_non_lazy_realization class attribute that will put that class reference in the nlclslist section.

Swift SVN r23105
2014-11-05 00:19:37 +00:00
Joe Groff
e773d9a1aa IRGen: Unique the metadata for imported structs and enums at runtime.
Move the uniquing information for ForeignTypeMetadata behind the address point so we can share the layout between foreign classes and the existing layout for struct and enum metadata. Emit metadata records for imported structs and enums as foreign metadata candidates, and dynamically unique references to the metadata by calling swift_getForeignTypeMetadata.

Swift SVN r23081
2014-11-03 06:12:13 +00:00
Joe Groff
efa166c443 IRGen: Don't lazily emit witness tables.
With runtime conformance lookup, it isn't possible without more complex analysis to determine whether a witness table is needed at runtime. In particular, in whole-module mode, it looked like no protocol conformances in the test/Interpreter/protocol_lookup.swift test were used, causing all of the tests to fail in -i mode. Erik's been working on SIL-level dead witness elimination which will hopefully offset the compile time hit here.

Swift SVN r23067
2014-11-02 19:18:38 +00:00
Joe Groff
3b0b2e8032 IRGen: Remove redundant runtime registration in JIT code.
We do this already in emitRuntimeRegistration, no need to duplicate it (badly) in emitSourceFile.

Swift SVN r23066
2014-11-02 16:56:38 +00:00
Joe Groff
01554448fc Runtime: Walk up superclass chains to find class conformances.
Swift SVN r23065
2014-11-02 15:41:00 +00:00
Joe Groff
f205082b6d IRGen: Register JITed conformances with the runtime.
dyld won't help us with JIT code, so we need to inject a runtime call to add the conformances ourselves in JIT mode.

Swift SVN r23058
2014-11-01 22:20:10 +00:00
Joe Groff
c98ce540d4 IRGen: Emit protocol conformance records.
When we emit a witness table, build a protocol conformance record for it, and emit the list of all conformance records into a "__swift1_proto" section of the data segment.

Swift SVN r22939
2014-10-25 01:50:49 +00:00
Erik Eckstein
3eea8e3052 Set SILLinkage of witness tables according to the protocol visibility.
This is the same change as already done for functions and globals
(for details see <rdar://problem/18201785>).




Swift SVN r22907
2014-10-24 09:02:05 +00:00
Erik Eckstein
1a26fc23bf Remove workaround for closed <rdar://problem/16094902>
Swift SVN r22796
2014-10-16 14:08:36 +00:00
Dmitri Hrybenko
4833f311cd Allow private_external to be parsed and processed correctly
Also add tests for translating SIL linkage into LLVM linkage.

Swift SVN r22705
2014-10-13 18:19:12 +00:00
Dmitri Hrybenko
1d02589fc7 Make LLVM-level linkage of fragile Xyz and XyzExternal symbols match
We used to make fragile PrivateExternal and HiddenExternal symbols
'hidden' in LLVM.  While this seems to work on Mach-O, ELF linkers can
not satisfy a hidden not defined symbol with a default symbol from a
shared library.

Swift SVN r22696
2014-10-13 11:37:46 +00:00
Joe Groff
bb46f4bbd9 SIL: Remove the global_addr instruction.
It's no longer needed now that we always lower to SIL globals.

Swift SVN r22693
2014-10-12 17:19:06 +00:00
Adrian Prantl
f477b2685c Fix two IR correctness bugs related to not using the LLVM datatype in
DebugTypeInfo.

Swift SVN r22567
2014-10-07 17:33:39 +00:00
Joe Groff
d3a54b0ec3 Remove stray dump.
Swift SVN r22532
2014-10-06 01:31:57 +00:00
Joe Groff
cac5807ae2 SILGen: Emit "main" as a SIL function.
Eliminate the intermediate top_level_code function. Now that SIL is expressive enough to express a "main" function, there's no reason for it, and this eliminates a bunch of mystery code in IRGen to thunk from main to top_level_code by reaching for hardcoded symbol names. Demystify the special code for setting up C_ARGC and C_ARGV by having SILGen look for a transparent "_didEnterMain" hook in the stdlib and emit a call to it.

Swift SVN r22525
2014-10-05 04:13:24 +00:00
Erik Eckstein
43f68b6974 Enable dead function removal for internal function in whole-module compilation.
This is controlled by a new isWholeModule() attribute in SILModule.

It gives about 9% code size reduction on the benchmark executables.
For test-suite reasons it is currently not done for the stdlib.



Swift SVN r22491
2014-10-03 14:14:23 +00:00
Jordan Rose
042569a3be Optional: Replace uses of Nothing with None.
llvm::Optional (like Swift.Optional!) uses None as its placeholder value,
not Nothing.

Swift SVN r22476
2014-10-02 18:51:42 +00:00
Jordan Rose
4adeb66b9f Drop uses of Optional's variadic forwarding constructor.
In preparation for the switch to llvm::Optional, which doesn't have this.
I suggested it, but got some pushback from David Blaikie, which is
understandable because implicit conversions are dangerous.
std::experimental::optional also doesn't have this, and we don't use it
too much. The only cost is being slightly more explicit when relying on
conversions to give us a T to then wrap in an Optional.

Swift SVN r22472
2014-10-02 18:51:37 +00:00
Erik Eckstein
3b517cb41d Add a clarifying comment.
Swift SVN r22262
2014-09-24 11:37:35 +00:00
Erik Eckstein
c16c510167 Set SILLinkage according to visibility.
Now the SILLinkage for functions and global variables is according to the swift visibility (private, internal or public).

In addition, the fact whether a function or global variable is considered as fragile, is kept in a separate flag at SIL level.
Previously the linkage was used for this (e.g. no inlining of less visible functions to more visible functions). But it had no effect,
because everything was public anyway.

For now this isFragile-flag is set for public transparent functions and for everything if a module is compiled with -sil-serialize-all,
i.e. for the stdlib.

For details see <rdar://problem/18201785> Set SILLinkage correctly and better handling of fragile functions.

The benefits of this change are:
*) Enable to eliminate unused private and internal functions
*) It should be possible now to use private in the stdlib
*) The symbol linkage is as one would expect (previously almost all symbols were public).

More details:

Specializations from fragile functions (e.g. from the stdlib) now get linkonce_odr,default
linkage instead of linkonce_odr,hidden, i.e. they have public visibility.
The reason is: if such a function is called from another fragile function (in the same module),
then it has to be visible from a third module, in case the fragile caller is inlined but not
the specialized function.

I had to update lots of test files, because many CHECK-LABEL lines include the linkage, which has changed.

The -sil-serialize-all option is now handled at SILGen and not at the Serializer.
This means that test files in sil format which are compiled with -sil-serialize-all
must have the [fragile] attribute set for all functions and globals.

The -disable-access-control option doesn't help anymore if the accessed module is not compiled
with -sil-serialize-all, because the linker will complain about unresolved symbols.

A final note: I tried to consider all the implications of this change, but it's not a low-risk change.
If you have any comments, please let me know.



Swift SVN r22215
2014-09-23 12:33:18 +00:00
Manman Ren
18042db194 [Global Opt] update SILGlobalOpt to use static initializer if possible.
This is off by default and is a modified version of r21996 (reverted in r22001).

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 and it calls globalinit_func.
2> the globalinit_func is called by "once" from a single location.
   When we inline the addressor, the globalinit_func will be called by "once"
   from multiple locations. After we remove the "once" from the addressor, the
   inlined version will mistakely initialize the global variable again.
3> the globalinit_func is trivial as defined by
   SILGlobalVariable::canBeStaticInitializer().

Update IRGen to generate constant initializers for global variables with static
initializers (i.e non-null InitializerF).

Joe's suggestion on having the static initializer to return the result instead
of storing it is not implemented in this commit. But we do verify that a static
initializer has a single store to the global variable. The suggestion is tracked
in rdar://18382039.

Implement rdar://16621368, rdar://18169093.


Swift SVN r22083
2014-09-18 17:40:24 +00:00
Jordan Rose
673b95a538 Remove the use of the 'Playground' language option for non-playground things.
LLDB has been setting 'Playground' for their REPL mode too to get some of
these behaviors, but that's not something we want to do long-term, and it's
already been subtly wrong in a few cases. Now 'Playground' really does mean
playgrounds, and 'DebuggerSupport' means REPL /or/ LLDB expression parser
mode.

rdar://problem/18338200

Swift SVN r22030
2014-09-17 18:49:44 +00:00
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