Commit Graph

887 Commits

Author SHA1 Message Date
Erik Eckstein
db00c5e924 SIL: allow alloc_ref_dynamic to allocate tail elements.
It's the same thing as for alloc_ref: the optional [tail_elems ...] attribute specify the tail elements to allocate.
For details see docs/SIL.rst

This feature is needed so that we can allocate a MangedBuffer with alloc_ref_dynamic.
The ManagedBuffer.create() function uses the dynamic self type to create the buffer instance.
2016-10-06 08:46:23 -07:00
Huon Wilson
25b41906a2 [IRGen] Handle padding in global structs.
Previously there was a mismatch between SIL's concept of a
struct (padding is implicit) and LLVM's (padding is explicit) in IRGen's
constant evaluator. The explicit padding fields need to be given a value
in the IR.

This patch also moves the (currently small) list of constant evaluation
functions into their own file.

Fixes SR-716.
2016-09-29 05:21:49 -07:00
Adrian Prantl
7c763e6f72 Fix a compile time performance regression caused by redundant debug info.
Even at -Onone one SILValue can back up more than one local source variable.
This commit changes the list of variable values into a set.

<rdar://problem/28467349>
2016-09-26 17:33:20 -07:00
Adrian Prantl
c70d101ab0 Debug info: When skipping over cleanup locations in the middle of a
basic block, revert to line number 0 instead of reusing the last location.
This avoids emitting illegal IR if there was no previous location and the
instruction being emitted is a function call.

rdar://problem/28237133
2016-09-24 17:48:04 -07:00
Erik Eckstein
34a4e6df0a SIL: add new instructions to support tail-allocated arrays in SIL.
The new instructions are: ref_tail_addr, tail_addr and a new attribute [ tail_elems ] for alloc_ref.
For details see docs/SIL.rst

As these new instructions are not generated so far, this is a NFC.
2016-09-16 11:02:19 -07:00
practicalswift
b19481f887 [gardening] Fix 67 recently introduced typos 2016-09-16 11:16:07 +02:00
Dmitri Gribenko
fbb3cf35a5 Revert "New SIL instructions to support tail-allocated arrays in SIL." 2016-09-15 00:25:25 -07:00
Doug Gregor
ab70291b82 [IRGen] Handle 'super' method sends in ObjC partial application forwarders.
The Objective-C partial application forwarder that one gets when
using, e.g., "super.foo" as a function value was doing a normal
objc_msgSend. Fix the miscompile by threading all of the information
about the Objective-C message send through the forwarder.

Fixes rdar://problem/28140758.
2016-09-14 21:12:45 -07:00
Erik Eckstein
b11b60e658 SIL: add new instructions to support tail-allocated arrays in SIL.
The new instructions are: ref_tail_addr, tail_addr and a new attribute [ tail_elems ] for alloc_ref.
For details see docs/SIL.rst

As these new instructions are not generated so far, this is a NFC.
2016-09-14 14:54:18 -07:00
Adrian Prantl
56b7b08415 Debug Info: Handle vector types when extending variable live ranges.
rdar://problem/27891980
2016-08-17 18:53:18 -07:00
Joe Groff
42527ed18b IRGen: Don't attempt to emit debug info for type-erased generic params.
Fixes a crash when emitting debug info for ObjC generic extensions. Part of rdar://problem/26867815.
2016-08-11 14:38:16 -07:00
swift-ci
1f5301f0ec Merge pull request #3869 from adrian-prantl/25427596 2016-08-01 14:32:25 -07:00
Adrian Prantl
4136f07072 Debug Info: Use artificial locations for emitting aggregate shadow copies.
<rdar://problem/25427596>
2016-07-29 15:10:27 -07:00
Adrian Prantl
6e61b33584 Debug Info: Propagate dbg.value intrinsics into basic blocks that
contain a variable live range extension intrinsic.

This is working around a shortcoming of LLVM.
LiveDebugValues should be doing this but can't in general because it
currently only tracks register locations.

rdar://problem/27348117
2016-07-29 14:12:57 -07:00
Mark Lacey
122827ea00 Only emit empty inline asm instructions for cond_fail when optimizing.
These inline asm instructions are used to block branch folding when
optimizing, to ensure that we have unique trap locations (and associated
debug info) for each cond_fail.

We only need these when we're optimizing, and emitting them can block
fast isel, so only emit them when optimizing.
2016-07-26 15:38:47 -07:00
Adrian Prantl
3b3e308ed3 IRGenDebugInfo: Pass in the VarDecl separatly when emitting variables. (NFC) 2016-07-21 16:03:49 -07:00
Luke Larson
74e0498015 Revert "Update master to build with Xcode 8 beta 3, OS X 10.12, iOS 10, tvOS 10, and watchOS 3 SDKs."
This reverts commit 62d1fa760c.
2016-07-19 15:18:17 -07:00
Mishal Shah
62d1fa760c Update master to build with Xcode 8 beta 3, OS X 10.12, iOS 10, tvOS 10, and watchOS 3 SDKs. 2016-07-19 22:31:34 +02:00
Andrew Trick
2b732d0af5 Introduce Builtin.bindMemory and SIL bind_memory. (#3573)
Required for SE-0107: UnsafeRawPointer.
2016-07-18 13:18:03 -07:00
Andrew Trick
c47687da2c Add an isStrict flag to SIL pointer_to_address. (#3529)
Strict aliasing only applies to memory operations that use strict
addresses. The optimizer needs to be aware of this flag. Uses of raw
addresses should not have their address substituted with a strict
address.

Also add Builtin.LoadRaw which will be used by raw pointer loads.
2016-07-15 15:04:02 -05:00
Adrian Prantl
0e370359b9 Refactor and clean up IRGenSIL::emitShadowCopy. (NFC) 2016-07-08 12:09:10 -07:00
Adrian Prantl
ebc47e40be Shadow copies: Use the function's debug scope for the artificial location
instead of the variable's potentially incorrectly not inlined scope.

rdar://problem/27206870
2016-07-06 18:50:30 -07:00
Adrian Prantl
d3f8c1ea96 Fix a logic error that would cause shadow copies to be emitted at -O.
<rdar://problem/27206870>
2016-07-06 15:46:27 -07:00
Adrian Prantl
674d2e79ec Switch to an artificial debug location before emitting a shadow copy store.
This prevents (among other things) an unexpected step to the end of the
scope while initializing a guard variable.

<rdar://problem/25427596>
2016-07-05 11:47:56 -07:00
practicalswift
b37d0dff17 [gardening] Remove unused variable DebugScratchpads 2016-06-28 20:20:36 +02:00
Adrian Prantl
935b702a07 Add an assertion to IRBuilder to prevent function calls with no debug location
It is not valid LLVM IR to have a function call without a location to an
inlinable function inside a function with debug info — this makes it impossible
to construct inline information.

This patch adds an assertion and fixes up several places across IRGen where
such a situation could happen.

rdar://problem/26955467
2016-06-27 19:04:51 -07:00
Adrian Prantl
bffda8a78d Debugging: Extend the live ranges of local values at -Onone.
For many local values we can avoid a shadow alloca by directly
describing them with a dbg.value. This also enables precise liveness
so variables don't show up in the debugger before they are
initialized. Unfortunately this also means that values will disappear
when they are no longer needed.

This patch inserts an empty inline assembler expression depending on
the llvm::Value that is being described in the blocks dominated by it.
This uses less stack space than full shadow copies *and* allows us to
track the liveness of the variable completely. It may cause values to
be spilled onto the stack, though.

<rdar://problem/26627376>
2016-06-24 10:35:45 -07:00
Erik Eckstein
7fcfa7829e IRGen: code refactoring. NFC. 2016-06-17 15:53:20 +02:00
Slava Pestov
803a6b095b Reflection: Emit metadata for fixed-layout SIL boxes
We were recovering metadata from generic boxes by reading
the instantiated payload metadata from the box's metadata,
but this approach doesn't work for fixed-size boxes, whose
metadata does not store the payload metadata at all.

Instead, emit a capture descriptor with no metadata sources
and a single capture, using the lowered AST type appearing
in the alloc_box instruction that emitted the box.

Since box metadata is shared by all POD types of the same
size, and all single-retainable pointer payloads, the
AST type might not accurately reflect what is actually in
the box.

However, this type is *layout compatible* with the box
payload, at least enough to know where the retainable
pointers are, because after all IRGen uses this type to
synthesize the destructor.

Fixes <rdar://problem/26314060>.
2016-05-26 19:32:57 -07:00
John McCall
6c92c324f6 Rename IRGenModuleDispatcher to just IRGenerator and transfer
ownership of some of the basic structures to it.
2016-04-27 09:42:03 -07:00
David Farler
09d0cfee8d Hang closure capture descriptors from their heap metadata
Now we can discern the types of values in heap boxes at runtime!
Closure reference captures are a common way of creating reference
cycles, so this provides some basic infrastructure for detecting those
someday.

A closure capture descriptor has the following:

- The number of captures.
- The number of sources of metadata reachable from the closure.
  This is important for substituting generics at runtime since we
  can't know precisely what will get captured until we observe a
  closure.
- The number of types in the NecessaryBindings structure.
  This is a holding tank in a closure for sources of metadata that
  can't be gotten from the captured values themselves.
- The metadata source map, a list of pairs, for each
  source of metadata for every generic argument needed to perform
  substitution at runtime.
  Key: The typeref for the generic parameter visible from the closure
  in the Swift source.
  Value: The metadata source, which describes how to crawl the heap from
  the closure to get to the metadata for that generic argument.
- A list of typerefs for the captured values themselves.

Follow-up: IRGen tests for various capture scenarios, which will include
MetadataSource encoding tests.

rdar://problem/24989531
2016-04-22 19:09:06 -07:00
swiftix
baf8e7d7cb Merge pull request #2067 from swiftix/SR-249
Add [nonatomic] attribute to all SIL reference counting instructions.

Support this attribute at SIL level,  IRGen and LLVM-based ARC passes.
2016-04-06 23:56:43 -07:00
Roman Levenstein
d8e28bb690 Handle the [nonatomic] attribute in IRGen and LLVM passes.
Properly lower reference counting SIL instructions with nonatomic attribute as invocations of corresponding non-atomic reference counting runtime functions.
2016-04-06 22:30:23 -07:00
John McCall
44f71b1f11 Handle all the cases of scalar dynamic casts allowed by SIL in IRGen.
In particular, reliably look through a single level of optional
types and handle metatype-to-class casts.

Fixes rdar://24924966.
2016-04-06 19:10:02 -07:00
John McCall
4f669fe563 Move some cast-emission code to GenCast.cpp. NFC. 2016-04-06 13:31:18 -07:00
John McCall
52cd8718de Split GenFunc.cpp in three: GenFunc for function types and blocks,
GenCall for function signatures, calls, and prologue/epilogue, and
GenBuiltin for builtin operations.

NFC.
2016-04-04 23:52:14 -07:00
Slava Pestov
01b8067585 IRGen: Invalid emitIsUnique traps at runtime instead of crashing at compile time
While we always inline isUnique() into callers, we shouldn't crash
if we try to emit its body.
2016-03-28 13:24:21 -07:00
Jordan Rose
b6f7ed64b1 [IRGen] Functions with the ObjCMethod convention are not polymorphic.
...even if the 'self' type is generic. Additionally, Objective-C generic
types cannot be used as a source of type metadata, because Objective-C
generics are erased at runtime by default. (This may need to change.)

With these two changes, we now pass type metadata explicitly when we need
to, and /don't/ try to pass it to Objective-C methods that would have
needed it if they were Swift methods.
2016-03-28 09:50:30 -07:00
Mark Lacey
b21a9e7fd0 Try to ensure we generate unique trap locations.
In 2e3c0b6, code was added to emit unique trap blocks for each
cond_fail, in order to make post-mortem debugging simpler (e.g. stack
traces have correct line/column information for the trapping location,
and it's easy to trace back to the specific jump that reaches the trap).

We didn't, however, do anything to ensure that LLVM wouldn't merge these
back together again. This is an attempt to do exactly that, after seeing
BranchFolding in the code generator merging traps into a single block.

The idea here is to emit empty inline asm strings marked as
side-effecting, and taking a unique integer argument. These come before
the trap call, so they should block any valid attempt at merging the
blocks back together.

Ideally trap would take an argument which uniquely identifies it, but
that isn't possible today.

This solution is potentially brittle in that in theory LLVM could still
merge the trap/unreachable and then branch to those after the unique asm
calls. We cannot fix that by putting another asm call after the trap,
because LLVM's CFG simplification will delete code after a trap.

rdar://problem/25216969
2016-03-17 15:52:41 -07:00
Erik Eckstein
bf87de3bc3 Fix a memory leak caused by the ReleaseDevirtualizer.
This occured if a stack-promoted object with a devirtualized final release is not actually allocated on the stack.
Now the ReleaseDevirtualizer models the procedure of a final release more accurately.
It inserts a set_deallocating instruction and calles the deallocator (instead of just the deinit).

This changes also includes two peephole optimizations in IRGen and LLVMStackPromotion which get rid of
unused runtime calls in case the stack promoted object is really allocated on the stack.

This fixes rdar://problem/25068118
2016-03-15 12:56:54 -07:00
Erik Eckstein
c1bcb0b69d SIL: add new instruction set_deallocating
It will be used by the ReleaseDevirtualizer before calling the deallocator.
So far, this is NFC.
2016-03-15 12:56:54 -07:00
Mark Lacey
4cd82bff93 Minor cleanup of static initializer emission. 2016-03-15 10:06:44 -07:00
Adrian Prantl
053d7cf277 Debug Info: Don't emit shadow stack copies for local variables.
The effect of this tiny change is that local variables will be described
by llvm.dbg.values, which will get lowered into an accurate location list
instead of a stack slot that is valid for the entire scope of the variable.
This means the debugger can now accurately track the liveness of variables
knowing exactly when they are initialized and when there values go away.
Function arguments are still kept in stack slots because (1) they are
already initialized at the function entry and (2) LLDB really needs self
to be available at all times for the expression evaluator.

This was made possible by recent advancements in LLVM such as the live
debug variables pass and various related bugfixes.

<rdar://problem/15746520>
2016-03-08 11:10:02 -08:00
Adrian Prantl
c451db4403 Debug Info: Only bind the archetypes referenced by variable types early
at -Onone.

Thanks to rjmccall for the feedback!
2016-03-04 16:54:15 -08:00
Joe Groff
be71ab28e2 SIL: Add an MarkUninitializedBehavior instruction for behavior DI.
This instruction creates a "virtual" address to represent a property with a behavior that supports definite initialization. The instruction holds references to functions that perform the initialization and 'set' logic for the property. It will be DI's job to rewrite assignments into this virtual address into calls to the initializer or setter based on the initialization state of the property at the time of assignment.
2016-03-03 15:04:38 -08:00
Adrian Prantl
7d0b345772 Emit type metadata for values referenced by debug info eagerly at -Onone.
This is a hotfix for recent regressions in the LLDB testsuite caused
by lazy loading of metadata.

Long-term we will explore emitting DWARF expressions for accessing the
type metadata.

rdar://problem/24781494, SR-797
2016-03-02 12:03:10 -08:00
Xin Tong
6d006adbcc Revert "Debug Info: Don't emit shadow stack copies for local variables."
This reverts commit 1cb9c24b2f.

Broke OSX incremental build and others.
2016-03-02 07:55:33 -08:00
Adrian Prantl
1cb9c24b2f Debug Info: Don't emit shadow stack copies for local variables.
The effect of this tiny change is that local variables will be described
by llvm.dbg.values, which will get lowered into an accurate location list
instead of a stack slot that is valid for the entire scope of the variable.
This means the debugger can now accurately track the liveness of variables
knowing exactly when they are initialized and when there values go away.
Function arguments are still kept in stack slots because (1) they are
already initialized at the function entry and (2) LLDB really needs self
to be available at all times for the expression evaluator.

This was made possible by recent advancements in LLVM such as the live
debug variables pass and various related bugfixes.

<rdar://problem/15746520>
2016-03-01 18:47:34 -08:00
Chris Lattner
fe8d814ec2 add some newlines to silence warnings. 2016-02-26 11:30:47 -08:00
Adrian Prantl
13203bf749 Fix a crash when building the swift stdlib caused by the debug info
for a alloc_stack, debug_value, and debug_value_addr disagreeing on the
type of the same variable.

For -Onone, this commit is NFC.

A testcase for generic specialization will follow as soon as SIL debug
info serialization efforts are complete.
<rdar://problem/24785336>
2016-02-25 12:36:06 -08:00