Commit Graph

942 Commits

Author SHA1 Message Date
Erik Eckstein
90c21be191 Unify the implementation of optimization mode in various option classes.
This commit is mostly refactoring.

*) Introduce a new OptimizationMode enum and use that in SILOptions and IRGenOptions
*) Allow the optimization mode also be specified for specific SILFunctions. This is not used in this commit yet and thus still a NFC.

Also, fixes a minor bug: we didn’t run mandatory IRGen passes for functions with @_semantics("optimize.sil.never")
2017-11-14 11:25:02 -08:00
John McCall
7743be30f6 Add a "token" type to SIL to allow dependencies to be expressed without
allowing abstraction.
2017-11-13 04:03:21 -05:00
Pavel Yaskevich
be3d1af525 [ABI/Runtime] NFC: Rename function metadata arguments to parameters 2017-11-07 12:45:32 -08:00
Pavel Yaskevich
622cc1c64a [ABI/IRGen] Add custom function parameter flags representation for metadata use 2017-11-07 12:45:32 -08:00
Pavel Yaskevich
e9d4a5304e [IRGen] Fix function metadata endpoints to use separate parameter/flags arguments
Switch most general endpoint to be `flags, parameters, parameterFlags, result`,
instead of opaque `void **`, more specialized ones to use follow argument scheme:
`flags, param0, [flags0], ..., paramN, [flagsN], result` and store parameter/flags
information separately in `FunctionCacheEntry::{Key, Data}` as well.
2017-11-07 12:45:32 -08:00
Pavel Yaskevich
f5ed1a8759 [IRGen] Switch function metdata to use Metdata * for parameter references 2017-11-07 12:45:32 -08:00
Pavel Yaskevich
9b3739b91d [IRGen] Add parameter flags to function type metadata
Currently only single 'inout' flag has been encoded into function
metadata, these changes extend function metadata to support up to
32 flags per parameter.
2017-11-07 12:45:32 -08:00
Pavel Yaskevich
659c1bc2e0 Revert "[IRGen] Add parameter flags to function type metadata"
This reverts commit b33a6c7cdf.
2017-11-07 00:24:24 -08:00
Pavel Yaskevich
37185390f8 Revert "[IRGen] Switch function metdata to use Metdata * for parameter references"
This reverts commit 99f188e311.
2017-11-07 00:24:23 -08:00
Pavel Yaskevich
72bf180d0f Revert "[IRGen] Fix function metadata endpoints to use separate parameter/flags arguments"
This reverts commit 728d2a4c2f.
2017-11-07 00:24:22 -08:00
Pavel Yaskevich
aa89c4f4a8 Revert "[ABI/IRGen] Add custom function parameter flags representation for metadata use"
This reverts commit f6b0d2d2cf.
2017-11-07 00:24:21 -08:00
Pavel Yaskevich
4f354a7f09 Revert "[ABI/Runtime] NFC: Rename function metadata arguments to parameters"
This reverts commit 801b35e28c.
2017-11-07 00:24:20 -08:00
Pavel Yaskevich
e23a6f1359 Merge pull request #12500 from xedin/fn-metadata-changes
[IRGen] Improvements to function type metadata
2017-11-06 19:50:19 -08:00
Joe Groff
f8aef0a7e3 Merge pull request #12732 from jckarter/objc-class-metadata-unwrapping
[WIP] Runtime: Put ObjC class wrapper unwrapping behind a runtime call.
2017-11-06 11:32:15 -08:00
Pavel Yaskevich
801b35e28c [ABI/Runtime] NFC: Rename function metadata arguments to parameters 2017-11-06 11:16:46 -08:00
Pavel Yaskevich
f6b0d2d2cf [ABI/IRGen] Add custom function parameter flags representation for metadata use 2017-11-06 11:16:46 -08:00
Pavel Yaskevich
728d2a4c2f [IRGen] Fix function metadata endpoints to use separate parameter/flags arguments
Switch most general endpoint to be `flags, parameters, parameterFlags, result`,
instead of opaque `void **`, more specialized ones to use follow argument scheme:
`flags, param0, [flags0], ..., paramN, [flagsN], result` and store parameter/flags
information separately in `FunctionCacheEntry::{Key, Data}` as well.
2017-11-06 11:16:46 -08:00
Pavel Yaskevich
99f188e311 [IRGen] Switch function metdata to use Metdata * for parameter references 2017-11-06 11:16:46 -08:00
Pavel Yaskevich
b33a6c7cdf [IRGen] Add parameter flags to function type metadata
Currently only single 'inout' flag has been encoded into function
metadata, these changes extend function metadata to support up to
32 flags per parameter.
2017-11-06 11:16:46 -08:00
Joe Groff
95d251051b Runtime: Put ObjC class wrapper unwrapping behind a runtime call.
This is a small code size win, and also gives us some abstraction so that future cooperative ObjC compilers/runtimes might be able to interoperate ObjC class objects with Swift type metadata efficiently than they currently are in the fragile Swift runtime.

While I'm here, I also noticed that swift_getObjCClassMetadata was unnecessarily getting exposed in non-ObjC-interop runtime builds, so I fixed that as well.
2017-11-03 10:18:38 -07:00
Slava Pestov
dc3fbba9dc IRGen: Nested value types don't require dynamic metadata instantiation 2017-11-01 15:23:41 -07:00
Slava Pestov
6d6e284c4b IRGen: Simplify some code now that the parent pointer is gone 2017-11-01 14:21:29 -07:00
Pavel Yaskevich
c5cff769c7 [IRGen] Update Function Metadata to use AnyFunctionType::Param
This changes layout of the parameter metadata from single tuple record
(in case of materializable type) to N records each corresponding to
invididual function parameter, where functions with no parameters
`() -> Void` get 0 records allocated.
2017-10-12 15:58:19 -07:00
Joe Groff
6a955a95a8 IRGen: Never populate the generic metadata pattern reference in nominal type descriptors. 2017-10-04 16:14:25 -07:00
Saleem Abdulrasool
086c12114d IRGen: switch to absolute pointers for nominal type descriptors
Alter the value metadata layout to use an absolute pointer for the
nominal type descriptor rather than a relative offset relative to the
complete type metadata.  Although this is slightly less efficient in
terms of load times, this is more portable across different
environments.  For example, PE/COFF does not provide a cross-section
relative offset relocation.  Other platform ports are unable to provide
a 64-bit relative offset encoding.

Given that the value witness table reference in the value metadata is
currently an absolute pointer, this page is most likely going to be
dirtied by the loader.
2017-10-03 14:45:45 -07:00
Slava Pestov
8b73de60a9 IRGen: Remove GenericTypeRequirements::ParentType
Finally, remove the parent type metadata argument from type
constructors.

Now that type constructors don't take a parent metadata pointer,
we can hit some asserts concerning type constructors that do not
have any parameters. This happens when you define a concrete type
in a fully-constrained extension of a generic type.

A more efficient ABI would use concrete type metadata for these
cases, but that would be a bigger change that we can do later, so
for now just relax these assertions.

This resolves a runtime crasher since a circular metadata case is
no longer circular. I renamed the crasher to reference the more
specific radar since the more general issue of circular metadata
is still unresolved.
2017-09-25 15:45:17 -07:00
Slava Pestov
3ab5b6fa19 IRGen/Runtime: Remove parent field from type metadata
We no longer need this for anything, so remove it from metadata
altogether. This simplifies logic for emitting type metadata and
makes type metadata smaller.

We still pass the parent metadata pointer to type constructors;
removing that is a separate change.
2017-09-25 15:45:17 -07:00
Slava Pestov
704b8566a9 IRGen: Stop fulfilling generic parameters from the parent type
This change makes it so that type metadata stores arguments
from each nesting depth. This means that parent metadata is
no longer needed to fulfill generic arguments, but we still
store a parent pointer in metadata and pass it to type
constructor functions at this point.
2017-09-25 15:45:16 -07:00
Slava Pestov
5c0c660727 IRGen: Emit nested generic context information in the nominal type descriptor
Once generic type metadata includes arguments from all outer contexts,
we need to know how many arguments there are at each nesting depth in
order to properly reconstruct the type name from metadata.
2017-09-25 15:45:16 -07:00
John McCall
6d9294f565 Random improvements for ArrayRefView. 2017-09-25 02:05:23 -04:00
Slava Pestov
0dcfd320ae IRGen: Remove usages of getDeclaredTypeOfContext() 2017-09-19 22:12:29 -07:00
Slava Pestov
9c6cd08a9b IRGen: Fix lowering of alloc_ref for resilient classes
We were inlining the size and alignment, which was not correct.
This was the cause of a long-standing ASAN failure in some
library evolution tests.

Fixes <rdar://problem/24540778>.
2017-09-15 00:24:52 -07:00
John McCall
9ecf4e7833 Record whether a class method or protocol requirement is static in a more
comprehensive fashion.
2017-08-31 18:14:47 -04:00
John McCall
10689a0e3f Add per-method flags to the v-table in class nominal type descriptors.
For now, just store a kind and whether the method was dynamic.
2017-08-26 01:44:10 -04:00
John McCall
9a228e96e1 Change the structure of emitted protocol and generic-wtable metadata:
- Always include an array of requirement descriptors in the protocol
  descriptor.  For now, this doesn't contain anything except a general
  requirement kind and an optional default implementation, but eventually
  this can be augmented with type / name metadata.  This array is always
  emitted as constant.

- Guarantee the value of the extent fields in a protocol descriptor and
  slightly tweak their meaning.

- Move the private-data field out of line in a generic witness table
  descriptor so that the main descriptor can be emitted as constant.

- Rely on IRGen's notion of the witness-table layout instead of assuming
  that SILWitnessTable and SILDefaultWitnessTable match the actual
  physical layout.

This version of the patch uses a hack in which we assign internal rather
than private linkage to certain symbols in order to work around a Darwin
linker bug.
2017-08-25 01:42:44 -04:00
Slava Pestov
d73712d79b IRGen/Runtime: Initialize generic and resilient class vtables from nominal type descriptor
Previous patches changed the runtime to copy the vtable from the
superclass rather than IRGen emitting it statically for generic
and resilient classes.

However for generic classes we would still copy the vtable entries
for methods defined in the immediate class from the template.

Instead, store them in the nominal type descriptor, where they use
less space since we can use relative pointers, and copy them out of
there.

This will allow us to 'slim down' generic class templates eventually.
2017-08-24 15:42:08 -07:00
Slava Pestov
ed8ced5665 IRGen/Runtime: Use relative pointers in default witness table entries
This to shrink the size of the protocol descriptor, removes a 32-bit
padding field, and reduces the number of relocations.
2017-08-24 04:31:24 -07:00
Arnold Schwaighofer
c05381f96e Add LLVM's noinline to metadata/witness accessor functions at Osize 2017-08-17 14:57:22 -07:00
Slava Pestov
6f3160084f IRGen/Runtime: Dynamic vtable initialization for generic and resilient classes
Instead of emitting the vtable statically, copy it from the
superclass, and fill in method overrides, if any.

For now this is only done for classes initialized by
swift_initClassMetadata_UniversalStrategy(); I need to
add a new entry point for classes with static field
layout but a dynamic vtable.
2017-08-16 16:30:11 -04:00
Slava Pestov
7bbc2043f4 IRGen: Record address point when emitting non-generic class metadata 2017-08-16 15:36:59 -04:00
Slava Pestov
35004ce96a IRGen: Emit vtable offset and size in NominalTypeDescriptor 2017-08-16 15:36:59 -04:00
Slava Pestov
293f50251a IRGen: Another MetadataScanner => MetadataLayout refactoring 2017-08-15 01:32:12 -04:00
Slava Pestov
3685436911 IRGen: Remove obsolete TODO 2017-08-14 23:56:18 -04:00
Slava Pestov
a7ff2d2ddc SIL: Refactor SILVTable::getImplementation() into getEntry()
This will allow IRGen to recover the entry kind when emitting
class metadata.
2017-08-14 22:45:59 -04:00
Slava Pestov
aa20f404e9 IRGen: Remove MetadataSizer 2017-08-10 22:14:21 -07:00
Slava Pestov
54e171608f IRGen: Remove MetadataSearcher 2017-08-10 21:53:29 -07:00
Slava Pestov
9f6507cee8 IRGen: Use MetadataLayout in more places 2017-08-10 19:42:24 -07:00
Slava Pestov
e12c29ded9 IRGen: Refactor NonFixedStructTypeInfo::initializeMetadata()
The emitInitializeFieldOffsetVector() function used for
class metadata is now almost identical to the logic used
for structs. Refactor the code used for classes and also
use it to layout structs.
2017-08-09 01:07:09 -07:00
Slava Pestov
9555a593ec IRGen: Refactor swift_initClassMetadata_UniversalStrategy() to use TypeLayout
Both swift_init{Struct,Class}Metadata_UniversalStrategy() wish to
avoid instantiating type metadata for field types if possible.

The struct version took an array of the more general TypeLayout objects,
whereas the class version was implemented earlier and took an array
of size/alignment pairs.

Since we can emit static TypeLayouts for all fixed-size types,
the class version can use the more general TypeLayout type also.
2017-08-09 01:07:09 -07:00
Slava Pestov
cf91e309a1 IRGen: Fix emitTypeLayoutRef() for single-field structs with alignment
A single-field struct with an @_alignment attribute does not
have the same layout as its field.

This caused the runtime to compute incorrect layouts for
generic structs containing SIMD types.

Fixes <rdar://problem/33794343>.
2017-08-09 01:07:08 -07:00