Commit Graph

2933 Commits

Author SHA1 Message Date
Adrian Prantl
f18d802c19 Debug Info: Emit the error result argument.
If a function has an error result slot, emit debug info for an artificial
function argument "$error" with indirect storage that holds a pointer
to the error object address.

<rdar://problem/20736999> lldb needs to be able to locate the error return location when stepping out of a function

Swift SVN r28229
2015-05-07 00:29:40 +00:00
Joe Groff
ab09922966 Runtime/IRGen: Replace the _SwiftNativeNS*Base +load hack with a compiler hack.
Rather than swizzle the superclass of these bridging classes at +load time, have the compiler set their ObjC runtime base classes, using a "@_swift_native_objc_runtime_base" attribute that tells the compiler to use a different implicit base class from SwiftObject. This lets the runtime shed its last lingering +loads, and should overall be more robust, since it doesn't rely on static initialization order or deprecated ObjC runtime calls.

Swift SVN r28219
2015-05-06 22:00:59 +00:00
Joe Groff
c52a019f49 Quiet warnings about new KnownProtocolKind.
Swift SVN r28210
2015-05-06 17:17:31 +00:00
Joe Groff
bbf2e6dd4b Revert "IRGen: Use acquire semantics to load the inline "once" predicate."
This reverts commit r28178. We should do what dispatch_once does in C.

Swift SVN r28192
2015-05-06 01:29:18 +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
Joe Groff
8e4c83fcac IRGen: Use acquire semantics to load the inline "once" predicate.
This is free on x86_64, and saves us from relying on unspoken architectural assumptions on ARM.

Swift SVN r28178
2015-05-05 19:51:39 +00:00
Joe Groff
220dc2c722 IRGen: Make the target OnceDone predicate value 32-bit-safe.
Thanks John.

Swift SVN r28168
2015-05-05 16:44:13 +00:00
Joe Groff
7b2a6e5e8d IRGen: Emit the "done" check for Builtin.once inline.
This matches how dispatch_once works in C, dramatically cutting the cost of a global accessor by avoiding the runtime call in the hot path and giving the global a unique branch for the CPU to predict away. For now, only do this for Darwin; non-ObjC platforms don't necessarily expose their "done" value as ABI like ours do.

While we're here, change "once" to take a thin function pointer. We don't ever emit global initializers with context dependencies, and this simplifies the runtime glue between swift_once and dispatch_once/std::call_once a bit.

Swift SVN r28166
2015-05-05 15:35:57 +00:00
Adrian Prantl
2aff7e78d7 Debug Info: Mangle the AST type instead of the SIL type for local variables
and function arguments.

<rdar://problem/20565180> Debug info should not expose ImplFunctionType

Swift SVN r28148
2015-05-05 03:50:28 +00:00
Slava Pestov
6a31cb242f IRGen: use concrete inherited conformances for archetypes
Refactor emitWitnessTableRefs(), EmitPolymorphicArguments::emit() and
getProtocolWitnessTable() to share code, and make them work for the case
where we have a concrete conformance for an archetype.

Fixes <rdar://problem/20628295>

Swift SVN r28138
2015-05-04 23:50:27 +00:00
John McCall
b186be429b Catch errors in top-level code.
Swift SVN r28133
2015-05-04 22:15:28 +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
Erik Eckstein
94b3f8c545 IRGen: improve debug logging for multi-threaded compilation
Swift SVN r28115
2015-05-04 15:10:49 +00:00
Chris Lattner
7733b060c5 Enhance IRGen to know a simple heuristic in emitValueBitCast to avoid
going to the stack when two explosions will end up with the same elements.
This helps with optional to optional conversions.  We now compile:

public func opt_to_opt_trivial(x: Int?) -> Int! { return x }
public func opt_to_opt_reference(x : C!) -> C? { return x }

into:

define { i64, i1 } @_TF1x18opt_to_opt_trivialFGSqSi_GSQSi_(i64, i1) {
entry:
  %2 = insertvalue { i64, i1 } undef, i64 %0, 0
  %3 = insertvalue { i64, i1 } %2, i1 %1, 1
  ret { i64, i1 } %3
}

define i64 @_TF1x20opt_to_opt_referenceFGSQCS_1C_GSqS0__(i64) {
entry:
  ret i64 %0
}

instead of:

define { i64, i1 } @_TF1x18opt_to_opt_trivialFGSqSi_GSQSi_(i64, i1) {
entry:
  %bitcast = alloca %Sq, align 8
  %2 = bitcast %Sq* %bitcast to i64*
  store i64 %0, i64* %2, align 8
  %3 = getelementptr inbounds %Sq, %Sq* %bitcast, i32 0, i32 1
  %4 = bitcast [1 x i8]* %3 to i1*
  store i1 %1, i1* %4, align 8
  %5 = bitcast %Sq* %bitcast to %SQ*
  %6 = bitcast %SQ* %5 to i64*
  %7 = load i64, i64* %6, align 8
  %8 = getelementptr inbounds %SQ, %SQ* %5, i32 0, i32 1
  %9 = bitcast [1 x i8]* %8 to i1*
  %10 = load i1, i1* %9, align 8
  %11 = insertvalue { i64, i1 } undef, i64 %7, 0
  %12 = insertvalue { i64, i1 } %11, i1 %10, 1
  ret { i64, i1 } %12
}

define i64 @_TF1x20opt_to_opt_referenceFGSQCS_1C_GSqS0__(i64) {
entry:
  %bitcast = alloca %SQ.17, align 8
  %1 = bitcast %SQ.17* %bitcast to i64*
  store i64 %0, i64* %1, align 8
  %2 = bitcast %SQ.17* %bitcast to %Sq.16*
  %3 = bitcast %Sq.16* %2 to i64*
  %4 = load i64, i64* %3, align 8
  ret i64 %4
}




Swift SVN r28107
2015-05-04 03:50:48 +00:00
Joe Groff
2d3eba9e0d IRGen: Reuse value witness table projections.
Don't project every value witness from the metadata every time we need one; this wastes code size in a way LLVM can't really optimize since it doesn't know the metadata is immutable. The code size wins on the standard library are disappointingly small (stdlib only shrinks by 4KB), but this makes generic IR a lot more compact and easier to read.

Swift SVN r28095
2015-05-03 05:00:40 +00:00
Joe Groff
d0473756ec ClangImporter etc.: Remap C vector types to nested BaseType.VectorN types.
The design we landed on for SIMD is to define the vector types as nested types of their element, e.g. Float.Vector4, Int32.Vector2, etc. Update the Clang importer and other mapping facilities to match.

Swift SVN r28087
2015-05-02 15:04:43 +00:00
John McCall
5c171fd448 Parsing, type-checking, SILGen, and IRGen for try!.
Swift SVN r28085
2015-05-02 08:03:15 +00:00
Andrew Trick
5bc23acf75 Add wrappers around Builtin.isUnique.
Currently they do nothing but allow stdlib code to use regular (Bool)
types.  However, soon the wrappers for the _native variants will
provide point-of-use sanity checking.

These need to be fully generic to support class protocols and
single-payload enums (not just for optional). It also avoids a massive
amount of overloading for all the reference type variations
(AnyObject, Native, Unknown, Bridge) x 2 for optional versions of
each.

Because the wrapper is generic, type checking had to be deferred until
IRGen. Generating code for the wrapper itself will result in an
IRGen-time type error. They need to be transparent anyway for proper
diagnostics, but also must be internal.

Note that the similar external API type checks ok because it
forces conformance to AnyObject.

The sanity checks are disabled because our current facilities for
unsafe type casting are incomplete and unsound. SILCombine can
remove UnsafeMutablePointer and RawPointer casts by assuming layout
compatibility. IRGen will later discover layout incompatibility and
generate a trap.

I'll send out a proposal for improving the casting situation so we can
get the sanity checks back.

Swift SVN r28057
2015-05-01 23:45:44 +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
Adrian Prantl
acba19a494 Debug Info: Remove an early exit that prevented the swift frontend from
emitting indirect pieces — LLVM (ToT, 700) now supports this.

Since this only happens in optimized code it is currently not feasible
to write a non-flaky testcase for this. I'll revisit this once our
SIL serialization efforts progressed further.

<rdar://problem/19427586> Support indirect pieces

Swift SVN r28051
2015-05-01 22:13:01 +00:00
Joe Groff
fbd76737a4 Clang Importer: Rename the special vector type module to "simd".
We want this to act as an overlay/replacement for the C "simd" module.

Swift SVN r28047
2015-05-01 20:11:01 +00:00
Joe Groff
0bd45029b8 IRGen: Cache the result of local metadata accessor calls.
Swift SVN r28046
2015-05-01 20:10:58 +00:00
Slava Pestov
9d2d52b7ff SILWitnessVisitor: canonicalize protocols for associated types
Fixes <rdar://problem/20714534>.

Swift SVN r27990
2015-04-30 18:41:11 +00:00
Slava Pestov
18f0915432 Factor out SILWitnessVisitor from SILGenConformance and IRGen's WitnessVisitor
Bad things could happen if these ever got out of sync, and there's
no reason to repeat the logic twice. NFC

Swift SVN r27989
2015-04-30 18:41:10 +00:00
Slava Pestov
9f6dc433dc IRGen: Refactor WitnessVisitor to use ASTVisitor instead of hand-rolled dispatch
Some related cleanups here also:
- visitor no longer needs an IRGenModule
- fold code paths for static and instance methods

NFC

Swift SVN r27987
2015-04-30 18:41:08 +00:00
Slava Pestov
6b67758372 IRGen: remove requiresProtocolWitnessTable()
We can call TypeConverter::protocolRequiresWitnessTable() instead. NFC

Swift SVN r27986
2015-04-30 18:41:06 +00:00
Adrian Prantl
fa402df22d Debug Info: Anonymous functions should only have a linkage name.
<rdar://problem/20008393> MDSubprogram has name

Swift SVN r27981
2015-04-30 16:30:15 +00:00
Doug Gregor
009b38d4a0 Stop using getProtocols() in IRGen. NFC
Swift SVN r27973
2015-04-30 16:13:41 +00:00
Andrew Trick
ec31f6dbc9 Revert "Add wrappers around Builtin.isUnique."
This reverts commit 64e9f11211a19fa603f5bc2d2bea171a9b07d3fa.

I think this is breaking ExistentialCollection test in the
Release + stdlib asserts build.

Swift SVN r27947
2015-04-29 23:23:13 +00:00
Andrew Trick
4063e4ffd1 Remove workaround for rdar://19537198 (all bots are on Xcode 7).
Swift SVN r27941
2015-04-29 23:06:23 +00:00
Andrew Trick
09db0dda92 Add wrappers around Builtin.isUnique.
The wrappers for the _native variants provide point-of-use sanity checking.
They also allows stdlib code to use regular (Bool) types.

These need to be fully generic to support class protocols. It also
avoids a massive amount of overloading for all the reference type
variations (AnyObject, Native, Unknown, Bridge) x 2 for optional
versions of each.

Because the wrapper is generic, type checking had to be deferred until
IRGen. Generating code for the wrapper itself will result in an
IRGen-time type error. They need to be transparent anyway for proper
diagnostics, but also must be internal.

The external API passes type checks because it forces conformance to AnyObject.

Swift SVN r27930
2015-04-29 21:59:19 +00:00
Duncan Exon Smith
c6d42db070 Adapt to MD* => DI* renaming of debug info types
Applied the upgrade script from r236120 (LLVM) and r236121 (CFE).  This is the
final step of rdar://problem/20434113.



Swift SVN r27925
2015-04-29 21:40:21 +00:00
Andrew Trick
a174aa4dfe Add AST and SILGen support for Builtin.isUnique.
Preparation to fix <rdar://problem/18151694> Add Builtin.checkUnique
to avoid lost Array copies.

This adds the following new builtins:

    isUnique : <T> (inout T[?]) -> Int1
    isUniqueOrPinned : <T> (inout T[?]) -> Int1

These builtins take an inout object reference and return a
boolean. Passing the reference inout forces the optimizer to preserve
a retain distinct from what’s required to maintain lifetime for any of
the reference's source-level copies, because the called function is
allowed to replace the reference, thereby releasing the referent.

Before this change, the API entry points for uniqueness checking
already took an inout reference. However, after full inlining, it was
possible for two source-level variables that reference the same object
to appear to be the same variable from the optimizer's perspective
because an address to the variable was longer taken at the point of
checking uniqueness. Consequently the optimizer could remove
"redundant" copies which were actually needed to implement
copy-on-write semantics. With a builtin, the variable whose reference
is being checked for uniqueness appears mutable at the level of an
individual SIL instruction.

The kind of reference count checking that Builtin.isUnique performs
depends on the argument type:

    - Native object types are directly checked by reading the
      strong reference count:
      (Builtin.NativeObject, known native class reference)

    - Objective-C object types require an additional check that the
      dynamic object type uses native swift reference counting:
      (Builtin.UnknownObject, unknown class reference, class existential)

    - Bridged object types allow the dymanic object type check to be
      bypassed based on the pointer encoding:
      (Builtin.BridgeObject)

Any of the above types may also be wrapped in an optional.  If the
static argument type is optional, then a null check is also performed.

Thus, isUnique only returns true for non-null, native swift object
references with a strong reference count of one.

isUniqueOrPinned has the same semantics as isUnique except that it
also returns true if the object is marked pinned regardless of the
reference count. This allows for simultaneous non-structural
modification of multiple subobjects.

In some cases, the standard library can dynamically determine that it
has a native reference even though the static type is a bridge or
unknown object. Unsafe variants of the builtin are available to allow
the additional pointer bit mask and dynamic class lookup to be
bypassed in these cases:

    isUnique_native : <T> (inout T[?]) -> Int1
    isUniqueOrPinned_native : <T> (inout T[?]) -> Int1

These builtins perform an implicit cast to NativeObject before
checking uniqueness. There’s no way at SIL level to cast the address
of a reference, so we need to encapsulate this operation as part of
the builtin.

Swift SVN r27887
2015-04-28 22:54:24 +00:00
Nadav Rotem
3e8c871c6a Emit calls to swift_willThrow as part of SILGen using a builtin.
Calls to willThrow are marked as read-none so that the optimizer can remove
them. The willThrow builtin is still generated for all throw/rethrow sites,
but I plan to look at this next.

rdar://20356658

Swift SVN r27877
2015-04-28 18:36:22 +00:00
Erik Eckstein
1708e0480f Reapply "IRGen: Use a larger bit size for integer literal to float conversion."
This time with 64-bit instead of 128-bit which works for armv7.



Swift SVN r27868
2015-04-28 13:24:32 +00:00
Erik Eckstein
81160c46b9 Revert "IRGen: Use a larger bit size for integer literal to float conversion."
It gives linker errors on armv7.



Swift SVN r27867
2015-04-28 11:31:17 +00:00
Erik Eckstein
83e412387c IRGen: Use a larger bit size for integer literal to float conversion.
rdar://problem/19447843



Swift SVN r27866
2015-04-28 10:31:22 +00:00
Erik Eckstein
2a366df113 Remove SILType::isExistentialMetatypeType().
Suggested by John.



Swift SVN r27864
2015-04-28 08:43:15 +00:00
Erik Eckstein
519dfca347 IRGen: fix crash on x.dynamicType.dynamicType.
rdar://problem/19545563



Swift SVN r27862
2015-04-28 07:36:13 +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
Joe Groff
bdac5fe1c8 IRGen: Implement emitIndirectCaseTest for dynamic multi-payload enums.
The last little bit of unimplemented code for dynamic enums.

Swift SVN r27814
2015-04-27 19:37:18 +00:00
Joe Groff
889b8d3826 IRGen: Fix implementation of emitValueCaseTest for multi-payload enums.
Empty cases are packed into the payload under a minimal number of tags, instead of having once case per tag, as for payload cases.

Swift SVN r27813
2015-04-27 19:37:18 +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
0126311e23 Enable dynamic multi-payload enums.
Fixes rdar://problem/15666173.

Swift SVN r27792
2015-04-27 00:35:13 +00:00
Joe Groff
3dafb24b5d IRGen: Call the runtime to initialize dynamic multi-payload enum metadata.
Emit a call to a third and final to-be-implemented runtime function to help instantiate the metadata of a dynamic multi-payload enum.

Swift SVN r27790
2015-04-27 00:35:07 +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
Joe Groff
6349fd7726 IRGen: Bitwise-take peepholes for multi-payload enums.
Do initializeWithTake by bitwise-copy on multi-payload enums when possible.

Swift SVN r27788
2015-04-27 00:34:59 +00:00
Joe Groff
fbf7c9c3c8 IRGen: Value semantics for dynamic multi-payload enums.
Refactor some things so that the copy_addr implementation for multi-payload enums works with dynamic as well as fixed cases.

Swift SVN r27787
2015-04-27 00:34:56 +00:00
Joe Groff
ff2d1df7af IRGen: Switching for dynamic multi-payload enums.
Use a different yet-to-be-implemented runtime call to extract the tag from a dynamic-layout enum so we can switch it.

Swift SVN r27786
2015-04-27 00:34:54 +00:00
Joe Groff
27266ff08a IRGen: Codegen for dynamic multi-payload tag injections.
Emit a call to an as-yet-unwritten runtime function that will perform the injection.

Swift SVN r27784
2015-04-27 00:34:49 +00:00