Commit Graph

745 Commits

Author SHA1 Message Date
Slava Pestov
090d723763 SIL: Remove null_class instruction
Swift SVN r32605
2015-10-11 02:11:22 +00:00
Andrew Trick
c20370a664 Remove the last remnants of unchecked_ref_bit_cast
Swift SVN r32598
2015-10-10 05:42:57 +00:00
Andrew Trick
57a450b28f Generate unchecked_ref_cast, not unchecked_ref_bit_cast.
This improves support for promoting to and generating
unchecked_ref_cast so we no longer need unchecked_ref_bit_cast, which
will just go away in the next commit.

Swift SVN r32597
2015-10-10 05:42:53 +00:00
Andrew Trick
665e5169d5 Add unchecked_ref_cast_addr SIL instruction.
Swift SVN r32587
2015-10-10 03:39:32 +00:00
John McCall
a945bacc6b Split GenProto.cpp into three files; NFC.
- GenProto.cpp for protocols and protocol conformances
  - GenExistential.cpp for existential type layout and operations
  - GenArchetype.cpp for archetype type layout and operations

Swift SVN r32493
2015-10-07 18:41:12 +00:00
Adrian Prantl
5e14a906b4 Re-enable the SIL Verifier for debug scopes of debug instrinsics.
Swift SVN r32064
2015-09-18 03:05:07 +00:00
Adrian Prantl
2f6f4a2a4a Add a workaround to not produce local variables for
capture list arguments like "[weak self]". The better solution
would be to require all variables to be described with a
SILDebugValue(Addr) and then not describe capture list
arguments (tracked in rdar://21185379).

rdar://problem/22702122

Swift SVN r31963
2015-09-15 18:36:42 +00:00
Nadav Rotem
16bd644825 [IRGen] Remove an extra null comparison in 'exact' checked_cast_br.
rdar://22666588

This change removes a comparison and a branch on every virtual call. Before this
change we were generating code for comparing the metadata to figure out if the
incoming instance is an 'exact' cast, and then we checked if the result of the
cast was zero. This is unnecessary because we can simply reuse the result of the
exact metadata comparison. Moreover, we know that the metadata instance can't be
zero because we've emitted a load to that address that did not trap.

  %1 = getelementptr inbounds %C4main1X, %C4main1X* %0 ...
  %.metadata = load %swift.type*, %swift.type** %1  // Loading %0
  %2 = icmp eq %swift.type* %.metadata, bitcast (...)
  %3 = icmp ne %C4main1X* %0, null   ; <-----------  %0 can't be null.
  %4 = and i1 %3, %2
  br i1 %4, label %5, label %7

Swift SVN r31920
2015-09-12 05:10:53 +00:00
Slava Pestov
1628bfc3e2 SIL: Split dealloc_ref into [constructor] and [destructor] kinds
dealloc_ref [destructor] is the existing behavior. It expects the
reference count to have reached zero and the isDeallocating bit to
be set.

The new [constructor] variant first drops the initial strong
reference.

This allows DI to properly free uninitialized instances in
constructors. Previously this would fail with an assertion if the
runtime was built with debugging enabled.

Progress on <rdar://problem/21991742>.

Swift SVN r31142
2015-08-11 18:38:00 +00:00
Erik Eckstein
d9a5ee364c IRGen: clear error slot only in errorblock
In the non-error case it is null anyway.
This increases the chances that the store can be removed by dead-store-elimination in llvm.



Swift SVN r31127
2015-08-10 21:41:10 +00:00
Roman Levenstein
92246b30d1 [irgen] Support static initializers for tuples.
Nothing very spectacular here. Almost the same logic, as we do for structs.

Swift SVN r30238
2015-07-15 23:40:10 +00:00
Andrew Trick
5a16f5de4d Allow Builtin.isUnique to take implicitly unwrapped optional for completeness.
Swift SVN r30171
2015-07-13 22:46:15 +00:00
Adrian Prantl
82295e6bf8 Revert "Debug Info: Shadow-copied debug_value_addr instructions need an extra"
This reverts commit r30041. Contrary to previous radars lldb is happier
without it.

Swift SVN r30094
2015-07-10 22:09:19 +00:00
Adrian Prantl
a6341c08ed Debug Info: Shadow-copied debug_value_addr instructions need an extra
indirection.

rdar://problem/21749451

Swift SVN r30041
2015-07-09 21:40:41 +00:00
Adrian Prantl
85c8f4f181 Emit -Onone shadow copies for debug_value_addr instructions.
<rdar://problem/21710192> Not emitting shadow copies for debug_value_addr

Swift SVN r29986
2015-07-08 19:49:26 +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
Joe Groff
9bdac157d2 SIL: Remove EnableTypedBoxes staging option.
Swift SVN r29762
2015-06-27 18:10:12 +00:00
Joe Groff
8a04d67408 IRGen: Strip out dead code for untyped boxes.
Swift SVN r29761
2015-06-27 17:50:13 +00:00
Slava Pestov
c033da92a4 IRGen: Implement emission of ExistentialMetatypeInst for boxed existentials
This is based on code from emitMetatypeOfOpaqueExistential() and
emitBoxedExistentialProjection().

Fixes <rdar://problem/21498036>.

Swift SVN r29735
2015-06-26 07:29:52 +00:00
Dmitri Hrybenko
2fc1cbe8c1 Adjust to the new IRBuilder APIs
Swift SVN r29692
2015-06-25 22:01:24 +00:00
Andrew Trick
a32a0af02b Allow unchecked_trivial_bit_cast to cast to smaller types.
I'm sure this is totally safe, why wouldn't it be?

Fixes <rdar://problem/21095584> Swift: UnsafePointer on tuple works in
debug but compiles crashing binary in release

Swift SVN r29614
2015-06-24 20:25:15 +00:00
Joe Groff
3c2ee54d43 IRGen: Implementation of typed box operations.
When producing TypeInfo for a box, try to reuse instantiations for common type structures:

- any POD type with the same stride and alignment can share a fixed HeapLayout;
- any single-refcounted-pointer type can share a fixed HeapLayout with types that have the same ReferenceCounting;
- dynamically-sized types can share a runtime-based box implementation.

For the runtime implementation, use new to-be-implemented variants of allocBox/deallocBox that will produce polymorphically-projectable boxes using instantiated metadata.

Swift SVN r29612
2015-06-24 19:43:24 +00:00
Adrian Prantl
c34d71ac85 Debug Info: Ensure that shadow copies for arguments also described by
debug_value intrinsics are only emitted once.

rdar://problem/21450456

Swift SVN r29532
2015-06-20 01:08:12 +00:00
Andrew Trick
7565a65235 Introduce unchecked_bitwise_cast SIL instruction.
We need a SIL level unsafe cast that supports arbitrary usage of
UnsafePointer, generalizes Builtin.reinterpretCast, and has the same
semantics on generic vs. nongeneric code. In other words, we need to
be able to promote the cast of an address type to the cast of an
object type without changing semantics, and that cast needs to support
types that are not layout identical.

This patch introduces an unchecked_bitwise_cast instruction for that
purpose. It is different from unsafe_addr_cast, which has been our
fall-back "unknown" cast in the past. With unchecked_bitwise_cast we
cannot assume layout or RC identity. The cast implies a store and
reload of the value to obtain the low order bytes. I know that
bit_cast is just an abbreviation for bitwise_cast, but we use
"bitcast" throught to imply copying a same sized value. No one could
come up with a better name for copying an objects low bytes via:

  @addr = alloca $wideTy
    store @addr, $wideTy
      load  @addr, $narrowTy

Followup patches will optimize unchecked_bitwise_cast into more
semantically useful unchecked casts when enough type information is
present. This way, the optimizer will rarely need to be taught about
the bitwise case.

Swift SVN r29510
2015-06-19 16:29:35 +00:00
Joe Groff
821b0f488e SIL: Add a project_box insn to project the address of the value from a box.
Still no implementation yet; we'll need to renovate how boxes work a bit to make them projectable (and renovate SILGen to generate typed boxes for the insn to be useful).

Swift SVN r29490
2015-06-18 15:47:22 +00:00
Mark Lacey
f56ca1ed68 Revert "SIL: Add a project_box insn to project the address of the value from a box."
This reverts commit r29475 because it conflicts with reverting r29474,
and it looks like that commit is breaking the build of the SpriteKit
overlay.

Swift SVN r29481
2015-06-18 06:27:52 +00:00
Joe Groff
15c29e5d1f SIL: Add a project_box insn to project the address of the value from a box.
Still no implementation yet; we'll need to renovate how boxes work a bit to make them projectable (and renovate SILGen to generate typed boxes for the insn to be useful).

Swift SVN r29475
2015-06-18 04:07:23 +00:00
John McCall
1f80de3d71 Restore the original intent of our IRBuilder to not provide
functions to create load/store instructions without alignment.

Fix a couple of places that were unnecessarily using this.
This includes patching up some very suspicious code for generating
"shadow copies" of explosions for debug info that's not using
the existing TypeInfo-based load/store facilities for some
reason; I left the existing pattern in place for now, but it's
probably bogus.

Swift SVN r29459
2015-06-17 21:34:03 +00:00
Joe Groff
c354a7cf63 IRGen: Relax assertion that C parameter ABI types match size of Swift struct representation types.
Share the code that does elementwise coercions, which already behaved correctly, with the code that does struct-to-struct coercions, which still had the overly-conservative constraint. Fixes rdar://problem/21294916.

Swift SVN r29399
2015-06-16 17:23:52 +00:00
Joe Groff
e22908f569 IRGen: Peephole (copy_addr to [initialization] (init_existential_addr)) as well.
We can simultaneously allocate and initialize an opaque existential container's fixed-size buffer the same way, which benefits conversions from generic types to protocol types.

Swift SVN r29371
2015-06-13 00:35:04 +00:00
Nadav Rotem
f345ca33fd Fix unused variable warnings in Release builds.
Swift SVN r29367
2015-06-12 18:27:26 +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
Adrian Prantl
35dac3b7c8 Debug info: Ensure that function arguments are only declared once.
Caught by an assertion in LLVM.

rdar://problem/21232690

Swift SVN r29304
2015-06-04 19:33:47 +00:00
Slava Pestov
3330b5ed85 IRGen: Support polymorphic @objc_method functions
The type of the self parameter of an @objc_method might be a
BoundGenericClassType or a GenericTypeParamType. In these cases
we have to bind metadata.

For an @objc protocol P, the calling convention for an existential P
would try to pass type metadata in an extra argument, just like it
would for a <T : P> T. However, it is only necessary in the latter
case, because only there we can reflect on T to observe the statically
bound generic type. Fix this with a small hack so that ObjC protocol
methods don't get an extra argument for Self.

This patch alone doesn't enable any new functionality by itself,
because we hit the 'unimplemented dynamic layout' error instead of
crashing.

Swift SVN r29258
2015-06-03 00:01:22 +00:00
Adrian Prantl
1f7eac97ab Debug Info: Do not attempt to reconstruct function arguments for
functions without a DeclContext. Currently this cannot happen,
but future SILPasses may rewrite functions in a way that it is meaningless
to preserve the function's DeclContext.

Swift SVN r29201
2015-06-01 18:16:37 +00:00
Adrian Prantl
b6e002cc70 Revert "Revert "Don't emit debug info for SILUndef values.""
This reapplies r29189.

Swift SVN r29193
2015-05-31 17:38:34 +00:00
Adrian Prantl
1daaf310fb Revert "Reverting commits 29181-29187 to investigate buildbot breakage."
This reverts commit 29189.

Swift SVN r29191
2015-05-31 17:38:32 +00:00
Adrian Prantl
b994bde5b5 Reverting commits 29181-29187 to investigate buildbot breakage.
Swift SVN r29190
2015-05-31 06:13:03 +00:00
Adrian Prantl
f2530aca51 Revert "Don't emit debug info for SILUndef values."
This reverts commit 18bb6cbf0a98b9ca082b26a470e3fba6e2d7d672.

Swift SVN r29189
2015-05-31 06:13:00 +00:00
Adrian Prantl
abeaf2b1a6 Don't emit debug info for SILUndef values.
rdar://problem/21103107

Swift SVN r29188
2015-05-31 05:39:33 +00:00
Adrian Prantl
6830021b4e Debug Info: Use the AST instead of SIL to determine the argument ordering.
The old SIL-based approach failed to recognize function arguments of
SIL-inlined functions as arguments.

Post-Xcode 7 it would be better to lower this information during SILGen
and emit a debug_value for every function argument so we don't need
to reconstruct them after all the SIL optimizations.

rdar://problem/21109015

Swift SVN r29180
2015-05-31 05:39:26 +00:00
Ted Kremenek
a154ae25f8 Revert "Revert "Revert "IRGen: Support polymorphic @objc_method functions"""
I didn't revert in the right order.

Swift SVN r29152
2015-05-29 19:16:32 +00:00
Ted Kremenek
7c24079ead Revert "Revert "IRGen: Support polymorphic @objc_method functions""
Start reverting 'reverts' incrementally to see if they trigger issues
on the iOS builder.

Swift SVN r29151
2015-05-29 18:38:12 +00:00
Ted Kremenek
ac40accfc1 Revert "IRGen: Support polymorphic @objc_method functions"
Speculatively reverting because the iOS bots are broken.

Swift SVN r29147
2015-05-29 14:11:29 +00:00
Slava Pestov
70db2c18d1 IRGen: Support polymorphic @objc_method functions
The type of the self parameter of an @objc_method might be a
BoundGenericClassType or a GenericTypeParamType. In these cases
we have to bind metadata.

For an @objc protocol P, the calling convention for an existential P
would try to pass type metadata in an extra argument, just like it
would for a <T : P> T. However, it is only necessary in the latter
case, because only there we can reflect on T to observe the statically
bound generic type. Fix this with a small hack so that ObjC protocol
methods don't get an extra argument for Self.

This patch alone doesn't enable any new functionality by itself,
because we hit the 'unimplemented dynamic layout' error instead of
crashing.

Swift SVN r29136
2015-05-29 06:19:00 +00:00
Joe Groff
aad6bc87fd IRGen: Pass large explosions as indirect arguments.
It's not worth burning more than three registers on a parameter, and doing so causes code size issues for large structs and enums. Make it so that values with more than three explosion members get passed indirectly, just like they get returned indirectly.

This time, modify emitPartialApplyForwarder not to attempt to 'tail' call the original function when indirect arguments get alloca'ed on the stack, which is UB, and don't use "byval", as suggested by John.

Swift SVN r29032
2015-05-26 17:38:22 +00:00
Joe Groff
7a5b199a34 Revert "IRGen: Pass large explosions as indirect byval arguments."
This reverts commit r29016, because of a test failure on the bots.

Swift SVN r29018
2015-05-26 02:13:16 +00:00
Joe Groff
abba73c77f IRGen: Pass large explosions as indirect byval arguments.
It's not worth burning more than three registers on a parameter, and doing so causes code size issues for large structs and enums. Make it so that values with more than three explosion members get passed indirectly, just like they get returned indirectly.

Swift SVN r29016
2015-05-26 01:49:45 +00:00
Slava Pestov
888132ec3f IRGen: get unchecked_ref_cast working with class existential operand
There was some duplicated code and we weren't doing a claimAll() on the
input explosion in one of the duplicates.

This partially reverts r28686, but keeping the test and updating it.

Second version of this patch makes the SIL verifier and combiner passes
use the same predicate, fixing assertion failures when casting
metatypes.

Fixes <rdar://problem/21005110>.

Swift SVN r28873
2015-05-21 16:01:45 +00:00
Dmitri Hrybenko
a795e87c65 Revert "IRGen: get unchecked_ref_cast working with class existential operand"
This reverts commit r28840.  It broke check-swift-optimize-unchecked.

Swift SVN r28847
2015-05-20 20:41:18 +00:00