Commit Graph

103 Commits

Author SHA1 Message Date
Slava Pestov
d460d5def6 IRGen: Remove ASTTy field from StructLayout 2018-08-07 04:26:43 -07:00
Slava Pestov
bdb5eb3289 IRGen: [ClassLayout] Don't build a separate StructLayout for classes
The type info for a class described its layout using a combination of a
StructLayout and ClassLayout, with different information stored in both.

Since we never use a class as a struct, it's simpler to add the relevant
bits to ClassLayout, and not build a StructLayout at all.

Also, drop inherited properties from the ClassLayout -- they're no
longer needed.
2018-08-07 00:37:03 -07:00
David Zarzycki
a8fbe3a18e [AST] NFC: Repack misc DeclAttribute bits into inline bitfield 2018-04-18 11:25:11 -04:00
Slava Pestov
d5868e5492 IRGen: ElementLayout now stores two TypeInfos
This allows us to perform fragile layout of resilient fields without
completely disabling value type resilience.
2018-04-09 21:53:45 -07:00
Arnold Schwaighofer
4cd16ae489 IRGen: Empty fields do have an entry in the field offset vector
This is an error introduced as the result of a refactoring a while ago
and means that we will store dependently typed stored properties at the
wrong offset in a generic struct if it has stored properties of empty
types before said property.

rdar://36384871
2018-01-12 13:00:13 -08:00
Greg Parker
9a38e609af [IRGen][runtime] Reduce object header to 8 bytes on 32-bit platforms. (#12790)
SR-4353, rdar://29765800
2017-11-08 02:50:11 -08:00
Erik Eckstein
315aa14049 IRGen: extend ClassLayoutBuilder to create layouts for classes with tail allocated elements 2017-08-23 09:15:01 -07:00
Joe Groff
3663c36284 IRGen: Begin NSObject subclass layout with an NSObject 'isa' header only.
We would lay out all classes starting with a Swift-style two-word header, even classes that inherit NSObject and therefore don't have Swift refcounting. The ObjC runtime would slide our ivars down for us at realization time, but it's nice to avoid unnecessarily dirtying memory in the not-uncommon case of direct NSObject subclasses.
2017-06-16 14:42:27 -07:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Slava Pestov
54ac82b784 IRGen: Remove an unused function 2016-10-17 18:10:37 -07:00
Joe Groff
c877900624 IRGen: Set instanceStart correctly in ObjC rodata when first stored property is empty.
Give empty fields a notional byte offset so we can still use the offset of the first field as an approximation of the instanceStart of a class.

Fixes SR-1055.
2016-03-29 08:48:39 -07:00
Slava Pestov
33ed1e0ab6 IRGen: Add ResilienceExpansion parameter to TypeInfo::isKnownEmpty(), NFC
In a few places, we have to be careful about the distinction between
"empty in this resilience domain" versus "empty in all resilience
domains". Make callers think about this by adding a parameter instead
of relying on them to check isFixedSize() as necessary first.

While making this change I noticed that the code for checking if
types are empty when computing extra inhabitants of structs and enums
might be slightly wrong in the face of resilience; I will revisit
this later.
2016-01-08 19:56:01 -08:00
Slava Pestov
7faf90a787 IRGen: Replace ResilienceScope enum with AST's ResilienceExpansion, NFC 2016-01-07 08:29:23 -08:00
practicalswift
50baf2e53b Use consistent formatting in top of file headers. 2016-01-04 02:17:48 +01:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Slava Pestov
5fa9a7dc6d IRGen: Multi-payload enums only use spare bits if payloads are universally fixed-size
For example, if a @_fixed_layout struct A contains a resilient struct B
from the same module M, then inside M, A can have a fixed size, but
outside, A has a dynamic size because B is opaque. In this case, A is
not "universally fixed-size". This impacts multi-payload enums, because
if A is placed inside a multi-payload enum E which is lowered inside X,
we would get a fixed layout with spare bits, but lowering E outside of
X would yield a dynamic layout. This is incorrect.

Fix this by plumbing through a new predicate IsAlwaysFixedSize, which
is similar to IsPOD and IsBitwiseTakable, where a compound type inherits
the property if all leaf types exhibit it, and only use spare bits if
the original and substituted types have this property.
2015-11-16 16:34:56 -08:00
Slava Pestov
1adf7534d7 IRGen: Collapse down ResilienceScope enum
John and I discussed this and agreed that we only need two cases here,
not four. In the future this may be merged with ResilienceExpansion,
and become a struct with additional availability information, but
we're definitely sure we don't need four levels here.
2015-11-13 17:56:17 -08:00
Joe Groff
e89ff69ac7 IRGen: Handle the case when the compound type isn't nominal when looking for layout attributes.
This doesn't appear to come up in the compiler, but LLDB was hitting this case.

Swift SVN r27337
2015-04-15 23:07:54 +00:00
Joe Groff
e4e0f35aed IRGen: Implement an @_alignment attribute.
This is an internal-only affordance for the numerics team to be able to work on SIMD-compatible types. For now, it can only increase alignment of fixed-layout structs and enums; dynamic layout, classes, and other obvious extensions are left to another day when we can design a proper layout control design.

Swift SVN r27323
2015-04-15 17:23:30 +00:00
John McCall
275ef489d4 Switch IRGen to use ClusteredBitVector.
IRGen uses a typedef, SpareBitVector, for its principal
purpose of tracking spare bits.  Other uses should not
use this typedef, and I've tried to follow that, but I
did this rewrite mostly with sed and may have missed
some fixups.

This should be almost completely NFC.  There may be
some subtle changes in spare bits for witness tables
and other off-beat pointer types.  I also fixed a bug
where IRGen thought that thin functions were two
pointers wide, but this wouldn't have affected anything
because we never store thin functions anyway, since
they're not a valid AST type.

This commit repplies r24305 with two fixes:

  - It fixes the computation of spare bits for unusual
    integer types to use the already-agreed-upon type
    size instead of recomputing it.  This fixes the
    i386 stdlib build.  Joe and I agreed that we should
    also change the size to use the LLVM alloc size
    instead of the next power of 2, but this patch
    does not do that yet.

  - It changes the spare bits in function types back
    to the empty set.  I'll be changing this in a
    follow-up, but it needs to be tied to runtime
    changes.  This fixes the regression test failures.

Swift SVN r24324
2015-01-09 21:06:37 +00:00
Dmitri Hrybenko
4caca5d098 Revert "Switch IRGen to use ClusteredBitVector."
This reverts commit r24305.  It broke the standard library build.

Swift SVN r24318
2015-01-09 18:25:21 +00:00
John McCall
6e41b3c742 Switch IRGen to use ClusteredBitVector.
IRGen uses a typedef, SpareBitVector, for its principal
purpose of tracking spare bits.  Other uses should not
use this typedef, and I've tried to follow that, but I
did this rewrite mostly with sed and may have missed
some fixups.

This should be almost completely NFC.  There may be
some subtle changes in spare bits for witness tables
and other off-beat pointer types.  I also fixed a bug
where IRGen thought that thin functions were two
pointers wide, but this wouldn't have affected anything
because we never store thin functions anyway, since
they're not a valid AST type.

Swift SVN r24305
2015-01-09 10:05:51 +00:00
Joe Groff
c0202d4fc2 IRGen: Push an 'isBitwiseTakable' bit through type infos.
In value witness table generation, and probably other places, we're inappropriately assuming that 'initializeWithTake' is equivalent to a memcpy in all cases, which isn't true for types that carry weak references or for potentially other types in the future. Add an 'isBitwiseTakable' property to TypeInfos that can be checked to see whether a type is bitwise-takable.

Swift SVN r16799
2014-04-25 03:06:46 +00:00
Joe Groff
9b38c4b5db IRGen: Forward spare bits through aggregates.
When doing struct layout for fixed-layout structs or tuples, combine the spare bit masks of their elements to form the spare bit mask of the aggregate, treating padding between elements as spare bits as well.

For now, disable using these spare bits to form extra inhabitants for structs and tuples; we would need additional runtime work to expose these extra inhabitants for correct generic runtime behavior. This puts us in a weird situation where 'enum { case A(Struct), B, C }' spills a bit but 'enum { case A(Struct), B(Struct), C }' doesn't, but the work to make the former happen isn't immediately critical for String optimization.

Swift SVN r12165
2014-01-10 23:15:34 +00:00
Joe Groff
4ff3c62ef6 IRGen: Include instance size and alignment mask in class metadata.
We need these for dependent-layout generic classes so we know the allocation/deallocation size and alignment. When I figure out ObjC interop with generic subclasses these should move to the rodata so they get handled resiliently by the ObjC runtime, but for generic class bringup this is convenient.

Swift SVN r9249
2013-10-12 01:51:18 +00:00
Joe Groff
edb520c97e IRGen: Assert that fixed-size aggregates are laid out as LLVM types of matching size.
A sanity check we probably should have had all along.

Swift SVN r9057
2013-10-09 04:12:50 +00:00
Joe Groff
2ac198d16b IRGen: Use packed structs to accurately lay out aggregate types.
LLVM's normal data layout doesn't jive with our own StructLayout's more aggressive use of padding space, and causes problems such as <rdar://problem/14336903>. Because we do our own alignment and stride management, we can safely use LLVM packed struct types with manual padding to get the level of control we need to accurately reflect our desired struct layout.

Swift SVN r9056
2013-10-09 04:12:46 +00:00
John McCall
65342ac19a Change %swift.refcounted to correctly model HeapObject as of r5873.
Swift SVN r5958
2013-07-01 23:29:15 +00:00
John McCall
d8cdb0160f Switch IR-generation to generally traffic in alignment
masks rather than raw alignments.

Swift SVN r5136
2013-05-10 06:16:28 +00:00
Joe Groff
86cb75c24c IRGen: Don't put opaque types inside struct layouts.
{ %swift.opaque } freaks out InstCombine and other optimization passes. Just leave opaque types out of the struct type, even if they appear first in the layout.

Swift SVN r5066
2013-05-06 22:48:24 +00:00
John McCall
7bf40e2f08 Project a non-fixed-size initial element using a bitcast instead
of a GEP.

LLVM does not permit GEPs over unsized types, even if the index
is a constant zero.

This makes simple code involving generic tuples work.

Swift SVN r4969
2013-04-29 00:18:30 +00:00
John McCall
1fec73a8d2 Untested support for tuples with generically-sized elements.
Swift SVN r4926
2013-04-26 21:33:24 +00:00
John McCall
65fc2b74f8 Basics of dynamic struct layout.
Swift SVN r4902
2013-04-25 01:39:58 +00:00
John McCall
03c04d04df Prepare StructLayout and StructLayoutBuilder for non-fixed layouts.
Swift SVN r4900
2013-04-25 01:39:45 +00:00
John McCall
80a82b6849 Abstract ElementLayout to work with non-fixed layouts.
Swift SVN r4899
2013-04-25 01:39:40 +00:00
John McCall
38b34b7307 Pass #1 at localizing assumptions about fixed layout and
handling non-fixed layouts.

This uncovered a bug where we weren't rounding up the header
size to the element alignment when allocating an array of archetypes.

Writing up a detailed test case for *that* revealed that we were
never initializing the length field of heap arrays.  Fixing that
caused a bunch of tests to crash trying to release stuff.  So...
I've left this in a workaround state right now because I have to
catch a plane.

Swift SVN r4804
2013-04-18 07:58:21 +00:00
John McCall
8fe4246833 Hide StorageSize/Alignment behind accessors in preparation for moving
them to a subclass.

Swift SVN r4779
2013-04-17 21:55:41 +00:00
John McCall
45ed2ef355 Emit correct ivar bounds and offsets.
I had thought that we could get away with letting the
runtime figure out that these offsets were invalid (and
thus recompute them), but it turns out that the runtime
has some basic consistency requirements:  basically, it
expects the ivars to have been correctly laid out, and
it merely slides them around according to the layout of
the superclass.

Swift SVN r3747
2013-01-11 08:09:08 +00:00
John McCall
d4f80a3993 Introduce a ClassLayoutBuilder and use it to build layouts.
The test changes are that we're setting a class body on
some types that we weren't before.  For some of these,
this is okay;  for others, it's more questionable, but
ultimately not *harmful*.

Swift SVN r3746
2013-01-11 08:09:06 +00:00
John McCall
288210e5df Refactor StructLayout into a builder pattern.
Swift SVN r3745
2013-01-11 08:09:03 +00:00
Chris Lattner
47dbc4051c update for mainline LLVM header file moves.
Swift SVN r3634
2013-01-02 14:38:42 +00:00
John McCall
ce7ddef710 Change value witnesses to take the metatype as 'self'.
The motivations here are that (1) the parametric types
that actually need the 'self' argument don't necessarily
all want to do what tuples do and put the VWT relative
to the metatype at some definable offset and (2)
recovering type parameters from the metatype is much
better defined than also hopping some relationship back.
Plus this allows VWTs to be shared across instances of
generic types.  Also, I'm going to need to add a VW
that takes a metatype, and consistency seems right here.

If keeping two values live is actually punishing, I
might have to reconsider this.  But the VWT is at least
always recoverable from the metatype, so....

I ended up abstracting the thing that GenHeap was doing
in order to save archetypes for arrays, because I
needed it to save metatypes instead of VWTs and because
it really needed abstractin'.

Swift SVN r3096
2012-10-31 08:09:33 +00:00
Eli Friedman
dd299a35af Fix for LLVM TargetData -> DataLayout rename.
Swift SVN r2959
2012-10-09 23:18:24 +00:00
John McCall
e53aed65d7 Initial support for IR-genning generic function bodies.
Mangling is still a hack, pending a better type AST.  Fixed
a bug where arguments passed indirectly were not being destroyed
by the callee (when passed by value).  Changed some of the protocol
signatures to use the generic opaque pointer type, making the
types a bit more self-documenting in the IR.

Swift SVN r2274
2012-06-28 08:50:06 +00:00
John McCall
e2440ff94c Split TypeInfo into its own header.
Swift SVN r2240
2012-06-25 20:44:51 +00:00
John McCall
48cd78cfef Allow an opaque struct type to be specified as the struct
to perform struct-layout into.

Swift SVN r1823
2012-05-12 07:19:43 +00:00
John McCall
875d914c77 Extract the layout logic out of GenTuple.cpp into a template header.
It does seem silly for this to all be templated, but I couldn't
really see a very elegant solution given how I wanted things to
be genericized.

...interestingly, a ?t.t[] type would have done nicely for some
of this.

Swift SVN r1807
2012-05-11 01:34:56 +00:00
John McCall
980f94817c Abstract out adding the heap header to things.
Swift SVN r1650
2012-04-26 07:34:00 +00:00
John McCall
f3e27d90ff Change IR-generation so that it emits metadata objects for the
heap allocations it makes, and switch swift_alloc over to pass
that pointer in as well as the alignment.  Also, compute
whether a type is POD during its generation and cache that in
the object, and introduce a method on TypeInfo to destroy an
object in memory.

Swift SVN r1356
2012-04-10 06:28:22 +00:00