Commit Graph

1541 Commits

Author SHA1 Message Date
Slava Pestov
fafd0b83ee Attempt to properly handle static global variables
This is based on Jordan Rose's patch from rdar://problem/17597453.

Swift SVN r27821
2015-04-27 22:16:37 +00:00
Slava Pestov
892b5af3f7 IRGen: Simplify LinkInfo::createVariable()
llvm::Module::getNamedGlobal() already returns an llvm::GlobalVariable;
no need to cast. NFC

Swift SVN r27808
2015-04-27 18:55:47 +00:00
Joe Groff
0b339b9a46 IRGen: Populate nominal type descriptor metadata for enums.
Store the number of payload and no-payload cases, the case names, and a lazy case type accessor function for enums, like we do for stored properties of structs and classes. This will be useful for multi-payload runtime support, and should also be enough info to hack together a reflection implementation for enums.

For dynamic multi-payload enums to not be ridiculously inefficient, we'll need to track the size of the payload area in the enum, like we do the field offsets of generic structs and classes, so hack off a byte in the payload case count to track the offset of that field in metadata records. 16 million payloads ought to be enough for anyone, right? (and 256 words between the enum metadata's address point and the payload size offset)

Swift SVN r27789
2015-04-27 00:35:04 +00:00
Erik Eckstein
f362570fb9 Change IRGenModuleDispatcher to a reference in IRGenModule.
According to Sean's feedback.



Swift SVN r27692
2015-04-24 09:17:29 +00:00
Joe Groff
ad0d20c07a Fold "AbstractCC" into SILFunctionType::Representation.
These aren't really orthogonal concerns--you'll never have a @thick @cc(objc_method), or an @objc_block @cc(witness_method)--and we have gross decision trees all over the codebase that try to hopscotch between the subset of combinations that make sense. Stop the madness by eliminating AbstractCC and folding its states into SILFunctionTypeRepresentation. This cleans up a ton of code across the compiler.

I couldn't quite eliminate AbstractCC's information from AST function types, since SIL type lowering transiently created AnyFunctionTypes with AbstractCCs set, even though these never occur at the source level. To accommodate type lowering, allow AnyFunctionType::ExtInfo to carry a SILFunctionTypeRepresentation, and arrange for the overlapping representations to share raw values.

In order to avoid disturbing test output, AST and SILFunctionTypes are still printed and parsed using the existing @thin/@thick/@objc_block and @cc() attributes, which is kind of gross, but lets me stage in the real source-breaking change separately.

Swift SVN r27095
2015-04-07 21:59:39 +00:00
Doug Gregor
38cc1fe5c6 Remove LazyResolver arguments from API entry points to the conformance lookup table.
Swift SVN r26838
2015-04-02 00:06:01 +00:00
John McCall
dc5a03a7bc Add IRGen support for error results from functions.
As part of this, re-arrange the argument order so that
generic arguments come before the context, which comes
before the error result.  Be more consistent about always
adding a context parameter on thick functions, even
when it's unused.  Pull out the witness-method Self
argument so that it appears last after the error
argument.

Swift SVN r26667
2015-03-28 02:00:17 +00:00
John McCall
080b7dfabf Remove the default handle-all Decl and DeclAttribute
cases from ASTVisitor and privatize SILGen's statement
emitter.  NFC.

Swift SVN r26402
2015-03-22 03:22:45 +00:00
Doug Gregor
7502d400c5 Replace an unnecessarily complicated traversal of protocols/conformances with DeclContext::getLocalConformances(). NFC
Swift SVN r26329
2015-03-19 22:10:11 +00:00
Erik Eckstein
22991b1088 Multi-threaded llvm code generation (experimental).
It can be enabled with the -num-threads <n> option.
Without this option there should be NFC.

When enabled, the LLVM IR is split into multiple modules: one module for each input file.
And for each module an output file is generated. All output files must be specified with -o options:
for each input file in the command line there must be an -o <outputfile> option.

LLVM compilation is performed on each module separately.
This means that the generated code is different than with regular -wmo.
But performance and code size should be approximately the same because important inter-file
optimizations are already done at SIL level (e.g. inlining, specialization).

There is still no support in the driver for this feature.



Swift SVN r25930
2015-03-10 16:52:14 +00:00
Michael Gottesman
34f686161e Change shared and shared_external to always be linkonce_odr hidden.
rdar://19936108

Swift SVN r25722
2015-03-03 23:01:51 +00:00
Michael Gottesman
697fb10bdb Make this switch a covered switch. NFC.
Swift SVN r25651
2015-03-01 04:45:27 +00:00
Michael Gottesman
01ca48a145 Lower fragile shared_external and fragile shared functions the same.
SharedExternal is a hack that just signals that the shared function comes from a
different module. Besides that information, SharedExternal should always be
treated exactly the same as Shared.

<rdar://problem/19936108>

Swift SVN r25650
2015-03-01 04:18:30 +00:00
Joe Groff
c0722c21d1 IRGen: Defer emitting field type generators for nominal types.
The field type generator may end up producing recursive static references to metadata while we're generating metadata. Fixes rdar://problem/19838839.

Swift SVN r25534
2015-02-25 21:20:50 +00:00
Justin Bogner
59bb06b0fb InstrProf: SIL-level coverage mapping and lowering to LLVM
The adds the sil_coveragemap construct to SIL and the needed IRGen to
turn these into LLVM's coverage maps.

Swift SVN r25210
2015-02-12 00:28:39 +00:00
Joe Groff
fb43b048a2 IRGen: Consider decl linkage instead of type linkage for lazy metadata emission.
It doesn't really make sense to ask a type whether symbols related to it have unique linkage or not; that's a property of the type's declaration. Fixes rdar://problem/19792174 better.

Swift SVN r25199
2015-02-11 22:31:02 +00:00
Joe Groff
a4c777320e IRGen: Change type layout verifier to take a type by name to verify.
Swift SVN r25088
2015-02-09 02:51:41 +00:00
Joe Groff
8e1e6665a7 IRGen: Start a type verifier to fuzz static type info against runtime type info.
We've had a rash of bugs due to inconsistencies between how IRGen and the runtime think types are laid out. Add a '-verify-type-layout' mode to the frontend that causes IRGen to emit a bunch of code that compares its static assumptions against what the runtime value witness does.

Swift SVN r24918
2015-02-03 16:47:25 +00:00
Joe Groff
acfb0c3d15 IRGen: Properly register the selector name for @objc protocol property setters in JIT mode.
Fixes rdar://problem/19671719.

Swift SVN r24871
2015-01-31 00:50:14 +00:00
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