Commit Graph

1572 Commits

Author SHA1 Message Date
Nadav Rotem
7c1e5236a7 Refactor the code that checks for owned parameters. NFC.
Swift SVN r32478
2015-10-06 23:53:55 +00:00
Nadav Rotem
bb9aa3aedd Teach IRGen to emit the 'readonly' function attribute.
Teach IRGen to emit the llvm function attribute 'readonly' for functions that
are annotated with the @effects(readonly) attribute.

Swift SVN r32477
2015-10-06 23:53:53 +00:00
Joe Groff
dd9f28e1df IRGen: Emit protocol conformances on the parallel IRGen path too.
The new implementation needs to happen after all source files have been built and before lazy definitions are emitted, but I neglected to insert it in the parallel IRGen path. Fixes rdar://problem/22825770.

Swift SVN r32189
2015-09-23 22:37:37 +00:00
Chris Lattner
5c5ed635a4 add a use of an unused variable, it seems that an unused 'foreignCandidate'
might be a bug?


Swift SVN r31937
2015-09-14 21:49:29 +00:00
Joe Groff
f78fc20271 IRGen: Remove workarounds for rdar://problem/22467267.
Lang fixed MCJIT to support subtractor relocations in LLVM, so we can use direct relative references in JITed metadata now.

Swift SVN r31904
2015-09-11 19:30:57 +00:00
Joe Groff
9eea4d3838 IRGen: Rename TypeMetadataAccessStrategy -> MetadataAccessStrategy.
NFC, but this set of access modes applies more generally to other kinds of metadata that may need to be guarded by accessors, such as witness tables.

Swift SVN r31838
2015-09-10 00:51:05 +00:00
Joe Groff
e4ae6a4e16 IRGen: Avoid using the GOT for public symbols in the same TU.
This time, with yet another workaround for rdar://problem/22450593 to avoid an MC bug for 32-bit Mach-O.

Swift SVN r31559
2015-08-28 19:44:42 +00:00
Joe Groff
79364849ac Revert "IRGen: Avoid using the GOT for public symbols in the same TU."
This reverts commit r31557. It breaks on i386.

Swift SVN r31558
2015-08-28 19:16:51 +00:00
Joe Groff
a8fb6aebb5 IRGen: Avoid using the GOT for public symbols in the same TU.
Swift SVN r31557
2015-08-28 19:07:47 +00:00
Joe Groff
7e15a0dde7 Add rdar references to FIXMEs for rdar://problem/22467267 workarounds.
Swift SVN r31556
2015-08-28 18:13:50 +00:00
Joe Groff
773eadb9f2 IRGen/Runtime: Populate the runtime protocol conformance table with relative references.
By using relative references, either directly to symbols internal to the current TU, or to the GOT entry for external symbols, we avoid unnecessary runtime relocations, and we save space on 64-bit platforms, since a single image is still <2GB in size. For the 64-bit standard library, this trades 26KB of fake-const data in __DATA,__swift1_proto for 13KB of true-const data in __TEXT,__swift2_proto. Implements rdar://problem/22334380.

Swift SVN r31555
2015-08-28 18:07:22 +00:00
Joe Groff
43d620c7e0 IRGen: Export direct metadata symbols at the address point of the metadata object.
This is more resilient, since we want to be able to add more information behind the address point of type objects. The start of the metadata object is now an internal "full metadata" symbol.

Note that we can't do this for known opaque metadata from the C++ runtime, since clang doesn't have a good way to emit offset symbol aliases, so for non-nominal metadata objects we still emit an adjustment inline. We also aren't able to generate references to aliases within the same module due to an MC bug with alias refs on i386 and armv7 (rdar://problem/22450593).

Swift SVN r31523
2015-08-27 05:18:38 +00:00
Joe Groff
f705c561e3 Revert "IRGen: Export direct metadata symbols at the address point of the metadata object."
This reverts commit r31515. It causes an LLVM error on the release bots.

Swift SVN r31516
2015-08-27 01:44:56 +00:00
Joe Groff
8e2ce60f5b IRGen: Export direct metadata symbols at the address point of the metadata object.
This is more resilient, since we want to be able to add more information behind the address point of type objects, and also makes IR a lot less cluttered. The start of the metadata object is now an internal "full metadata" symbol.

Note that we can't do this for known opaque metadata from the C++ runtime, since clang doesn't have a good way to emit offset symbol aliases, so for non-nominal metadata objects we still emit an adjustment inline.

Swift SVN r31515
2015-08-27 01:34:22 +00:00
Jordan Rose
0733ba42c9 Allow @NSManaged to be applied to methods.
Core Data synthesizes Key-Value-Coding-compliant accessors for @NSManaged
properties, but Swift won't allow them to be called without predeclaring
them.

In practice, '@NSManaged' on a method is the same as 'dynamic', except
you /can't/ provide a body and overriding it won't work. This is not the
long-term model we want (see rdar://problem/20829214), but it fixes a
short-term issue with an unfortunate workaround (go through
mutableOrderedSetValueForKey(_:) and similar methods).

rdar://problem/17583057

Swift SVN r30523
2015-07-23 02:08:55 +00:00
Slava Pestov
871d71a555 Sema: Differentiate between 'class is @objc' and 'class has implicitly @objc members'
Generic subclasses of @objc classes are thus no longer @objc, but still
have implicitly @objc members.

Explicit @objc on generic classes or classes that inherit from @objc
classes is now forbidden with a diagnostic. Users need to know that
while they can override Objective-C methods and properties in such
a class, they cannot refer to the class by name from Objective-C code,
since it will not appear in the bridging header.

Fixes <rdar://problem/21342574>.

Swift SVN r30494
2015-07-22 06:34:20 +00:00
Joe Groff
9c5cdaaceb IRGen: Register class property accessors with the metaclass, not the class object, in JIT mode.
Fixes rdar://problem/19069918.

Swift SVN r30453
2015-07-21 18:03:15 +00:00
Slava Pestov
dd2b4a9299 IRGen: Fix emission of categories with @NSManaged properties
The FIXME comment no longer applied and the if statement didn't make
sense. Perhaps the 'break' was at one point meant to be a 'continue',
however now we seem to correctly handle emission of a property
descriptor for a property without accessors.

Fixes <rdar://problem/21474718>.

Swift SVN r30132
2015-07-13 00:20:38 +00:00
Doug Gregor
3023a710fc Split TypeBase::isDependentType() into isTypeParameter() and hasTypeParameter().
The isDependentType() query is woefully misunderstood. Some places
seem to want it to mean "a generic type parameter of dependent member
type", which corresponds to what is effectively a type parameter in
the language, while others want it to mean "contains a type parameter
anywhere in the type". Tease out these two meanings in
isTypeParameter() and hasTypeParameter(), respectively, and sort out
the callers.

Swift SVN r29945
2015-07-07 21:20:54 +00:00
Dmitri Hrybenko
2fc1cbe8c1 Adjust to the new IRBuilder APIs
Swift SVN r29692
2015-06-25 22:01:24 +00:00
Jordan Rose
49e1a746e0 [IRGen] Bitcast SIL globals that don't have the right LLVM type.
This comes up when the SIL global actually refers to a static global defined
in C. In these cases Clang may have already emitted the global with a
different type---one appropriate for Clang, but not for Swift. By the time
we get to this part of the code, we should have already rejected anything not
layout-compatible, so just do the bitcast and be done with it.

Reviewed by John.

rdar://problem/21361469

Swift SVN r29471
2015-06-17 23:26:13 +00:00
Jordan Rose
f335128e40 [IRGen] Don't wait until we find libswiftCore to autolink libobjc.
No intended functionality change.

Swift SVN r29443
2015-06-17 04:48:10 +00:00
Jordan Rose
c516ef9223 [IRGen] Remove unnecessary IRGenOptions flag HasUnderlyingModule.
The test that it's guarding is cheap enough to do all the time, and we
don't have any interesting configurations where it's not set any more.

Swift SVN r29442
2015-06-17 04:48:09 +00:00
Joe Groff
a321938d34 IRGen: Peephole (copy_addr to [initialization] (alloc_stack)) operations to use initializeBuffer value witnesses.
This saves a value witness call in the common case where a generic local variable or temporary is initialized from another value.

Swift SVN r29366
2015-06-12 16:59:14 +00:00
Arnold Schwaighofer
15ff698409 IRGen: Give ClangCodeGen a chance to emit its translation unit's global state
We need this because that global state includes tables like llvm[.compiler].used
which would otherwise be sorely missed.

This fixes an issue of the clang importer that would cause us to fail whenever
we imported a function (say it is marked as static inline) that performs an
objective-c method call and we optimize the code. The optimizer would not see
the objective-c selector global variable (which is marked private) as being
"used by unkown i.e the objc runtime" and would rightly assume it could
propagate the value of the global variable's initializer value as a constant to
loads of the global variable.

Now we call the ClangCodeGenerators translation unit finalization code which
will emit these tables and other module flags. We need to take care that we
merge those datastrutures with datastructures that we emit from swift's IRGen.

rdar://21115194

Swift SVN r29176
2015-05-31 00:01:29 +00:00
Doug Gregor
b8995b0aa3 Transform the Module class into ModuleDecl.
Modules occupy a weird space in the AST now: they can be treated like
types (Swift.Int), which is captured by ModuleType. They can be
treated like values for disambiguation (Swift.print), which is
captured by ModuleExpr. And we jump through hoops in various places to
store "either a module or a decl".

Start cleaning this up by transforming Module into ModuleDecl, a
TypeDecl that's implicitly created to describe a module. Subsequent
changes will start folding away the special cases (ModuleExpr ->
DeclRefExpr, name lookup results stop having a separate Module case,
etc.).

Note that the Module -> ModuleDecl typedef is there to limit the
changes needed. Much of this patch is actually dealing with the fact
that Module used to have Ctx and Name public members that now need to
be accessed via getASTContext() and getName(), respectively.

Swift SVN r28284
2015-05-07 21:10:50 +00:00
Adrian Prantl
de7de7db9c Debug info: Don't emit externally defined global variables.
rdar://problem/20507438

Swift SVN r28276
2015-05-07 18:14:55 +00:00
Manman Ren
e94aae06da [Function Attribute] add target-cpu and target-features sets if they're non-null.
All llvm::Functions created during IRGen will have target-cpu and target-features
attributes if they are non-null.

Update testing cases to expect the attribute in function definition.
Add testing case function-target-features.swift to verify target-cpu and
target-features.

rdar://20772331


Swift SVN r28186
2015-05-05 23:19:48 +00:00
Erik Eckstein
3940797583 IRGen: Do a better distribution of functions to multi-threaded compiled modules.
Instead of putting a function without an associated source-file into the primary module,
it is now put into the module which first references the function.



Swift SVN r28116
2015-05-04 15:30:41 +00:00
David Farler
91c64fdbb1 Stop re-exporting the Objective-C library
and link it properly. This is needed to embed LLVM bitcode sections
in the standard library and overlays. The linker doesn't support
embedded bitcode and reexport flags (among others).

rdar://problem/20750099

Swift SVN r28052
2015-05-01 22:24:14 +00:00
Doug Gregor
009b38d4a0 Stop using getProtocols() in IRGen. NFC
Swift SVN r27973
2015-04-30 16:13:41 +00:00
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