Commit Graph

815 Commits

Author SHA1 Message Date
Jordan Rose
3fcdfd40e9 Remove the "swift/Basic/Optional.h" header.
llvm::Optional lives in "llvm/ADT/Optional.h". Like Clang, we can get
Optional in the 'swift' namespace by including "swift/Basic/LLVM.h".

We're now fully switched over to llvm::Optional!

Swift SVN r22477
2014-10-02 18:51:45 +00:00
Jordan Rose
042569a3be Optional: Replace uses of Nothing with None.
llvm::Optional (like Swift.Optional!) uses None as its placeholder value,
not Nothing.

Swift SVN r22476
2014-10-02 18:51:42 +00:00
Joe Groff
00fd417bd2 IRGen: Remove support for existential methods.
Eliminate support code for lowering protocol_method instructions, and eliminate ExtraDataKind::Metadata, which is no longer needed now that SIL provides all the necessary type information at the call site.

Swift SVN r22451
2014-10-02 00:11:54 +00:00
Joe Groff
1c4e08a9c8 Fix up a tangle of issues related to reabstraction.
- A spot fix in SILGen for reabstracting the result of a downcast, which fixes checked casts to function types.
- Associate the layout information in type metadata records with the most abstract representation of the type. This is the correct thing to do in cases where we need the metadata as a tag for an opaque value--if we store a value in an Any, or pass it as an unconstrained generic parameter, we must maximally reabstract it. This fixes the value semantics of existentials containing trivial metatypes.
- To ensure that we get runtime layout of structs and enums correct when they contain reabstractable types, introduce a "metadata for layout" concept, which doesn't need to describe the canonical metadata for the type, but only needs to describe a type with equivalent layout and value semantics. This is a correctness fix that allows us to correctly lay out generic types containing dependent tuples and functions, and although we don't really take advantage of it here, it's also a potential runtime performance win down the road, because we could potentially produce direct metadata for a primitive type that's layout-equivalent with a runtime-instantiated type. To aid in type safety here, push SILType deeper into IRGen in places where we potentially care about specific representations of types.
- Finally, fix an inconsistency between the runtime and IRGen's concept of what spare bits unmanaged references and thick metatypes have.

Together, these fixes address rdar://problem/16406907, rdar://problem/17822208, rdar://problem/18189508, and likely many other related issues, and also fixes crash suite cases 012 and 024.

Swift SVN r21963
2014-09-16 01:44:34 +00:00
Michael Gottesman
9514ba5a7d [irgen] Lower fix_lifetime => swift_keepAlive().
I introduced a function swift_keepAlive2() which has a different signature from
swift_keepAlive() until I can verify that the stdlib is using the new
infrastructure.

The difference in signature is that swift_keepAlive2 takes just a pointer while
swift_keepAlive also takes a metadata value that is not necessary for our
purposes anymore.

Swift SVN r21718
2014-09-04 21:53:18 +00:00
John McCall
0ddc7ee5b6 Resilience expansion is not an IR-generation concept.
If a type has to be passed or returned resiliently, it
will necessarily be passed indirectly, which is already
represented in SILFunctionType.  There is no need to
represent this as a separate channel of information.

NFC. Also fixes a problem where the signature cache
for ExtraData::Block was writing past the end of an
array (but into the storage for an adjacent array
which was fortunately never used).

ExtraData should also disappear as a concept, but we're
still relying on that for existential protocol witnesses.

Swift SVN r21548
2014-08-28 23:07:50 +00:00
John McCall
dc6f63cebe When Clang says to coerce an argument to a struct type,
it means that the argument should be passed as that
expanded sequence of types.

It turns out that LLVM makes an effort to automatically
break apart such arguments during CC lowering, but (1) it's
friendlier to break them apart ourselves and (2) it's
necessary to break them apart if we want to call inline
functions from the header.

Fixes rdar://17631440

Swift SVN r21420
2014-08-22 20:53:21 +00:00
John McCall
52ef29618c Use different TypeInfo instances for generic types whenever
anything major about IRGen for that type would change,
including the IR type of the value's components.

This generally makes the IR types we use for generic types
more precise, which means we also finally need to properly
remap loadable dependent types when they appear as the
result of a generic function call.  This basically only
comes up with class-bounded archetypes, which is why we
haven't run into it a whole lot before.

This all makes a whole lot of things in IRGen involving
generic structs a lot happier and, in particular, fixes
rdar://17986446, the "Unmanaged is horribly busted" bug.

I needed to carve out a big ol' exception for enums, which
apparently cannot be reliably specialized with substituted
types in all cases because of problems with multi-payload
strategies.  The exception reinstates the current, incorrect
rule of using a shared implementation whenever the
pattern has a fixed size.  This is rooted in a bunch of
deep, known, and tracked problems that I don't have time
to solve.

Swift SVN r21348
2014-08-21 08:01:46 +00:00
Arnold Schwaighofer
16e41ada77 Make Builtin.canBeClass return a tri-state
Replace the true/maybe state that Builtin.canBeClass was returning by a
tri-state (yes, no, maybe) allowing the optimizer to use the definite no
answer.  This removes the need of the sizeof check that we had in
isClassOrObjCExistential. It also removes the need to CSE this function since
in most cases we will be able to instantiate canBeClass to yes or no (vs maybe)
at compile time.

benchmark``````````````,``baserun0``,``optrun2``,``delta,``speedup
ClassArrayGetter```````,``988.00````,``337.00```,``644.00``,````````191.7%
DeltaBlue``````````````,``2429.00```,``1927.00``,``460.00``,````````23.9%
Dictionary`````````````,``1374.00```,``1231.00``,``129.00``,````````10.9%
Havlak`````````````````,``1079.00```,``911.00```,``124.00``,````````13.7%
Rectangles`````````````,``924.00````,``541.00```,``379.00``,````````70.1%

radar://16823238

Swift SVN r21331
2014-08-21 00:55:40 +00:00
Jordan Rose
ee22004b84 [IRGen] Walk inlineable Clang functions and emit their dependencies.
This handles things like NSSwapHostLongLongToBig and MKMapRectMake that
are static inline functions that themselves call other static inline
functions.

<rdar://problem/17227237>

Swift SVN r21080
2014-08-06 23:21:17 +00:00
Joe Groff
e3ed526a0a Remove dead function.
Swift SVN r20585
2014-07-26 00:58:12 +00:00
Joe Groff
cbdbe2cc01 IRGen: Handle call substitutions T: AnyObject = AnyObject (or other @objc existentials).
Fixes <rdar://problem/17806403>.

Swift SVN r20581
2014-07-25 23:59:37 +00:00
Ben Langmuir
085fa05ffe Shorten an init for an llvm::ConstantInt
Swift SVN r20532
2014-07-25 03:14:21 +00:00
Pete Cooper
ce68523178 Add strideof_nonzero to the compiler.
This builtin function generates max(strideof, 1) in IRGen.

Swift SVN r20508
2014-07-24 18:44:42 +00:00
Joe Groff
ec2b7172ef Update some direct Substitution accesses I missed.
Swift SVN r20422
2014-07-23 18:08:08 +00:00
Joe Groff
45eec9a2e9 Remove 'interface' from the method names of SILFunctionType.
SILFunctionTypes are always interface types now. NFC.

Swift SVN r19952
2014-07-14 22:03:46 +00:00
Dmitri Hrybenko
6f814ded6b Remove the '-disable-all-runtime-checks' option that predates current SIL-level
optimization/inlining scheme.

It was actually used while building a release version of stdlib, and
effectively disabled safety checks in debug builds.


Swift SVN r19461
2014-07-02 14:47:29 +00:00
John McCall
af92489d00 Cache the transformation of Swift types to Clang types.
Should fix <rdar://16830685>.

Swift SVN r18247
2014-05-17 08:52:34 +00:00
John McCall
059ed4cd10 Propagate alignment arguments around through the
slow allocation/deallocation APIs.

Swift SVN r18160
2014-05-16 01:40:36 +00:00
Joe Groff
3b4a9d2ba5 Add a 'conditionallyUnreachable' builtin.
This builtin only becomes unreachable when assert_configuration calls have been folded, allowing library-level checks to become unreachable based on the assert level.

Swift SVN r17322
2014-05-03 19:41:40 +00:00
Joe Groff
caff7b62d9 IRGen: Expose the array value witnesses as builtins.
Add Builtin.destroyArray, .copyArray, .takeArrayFrontToBack, and .takeArrayBackToFront, which perform bulk destroy/copy/take operations using memcpy/memmove, a loop, or a generic value witness.

Swift SVN r17009
2014-04-29 03:46:58 +00:00
Joe Groff
fa69999894 Remove some debugger noise.
Swift SVN r16870
2014-04-26 03:11:08 +00:00
Joe Groff
70272b08f7 IRGen: Substitute the types of partial_apply captures in the forwarder thunk.
Fixes a crash when a partial_apply argument is dependent on a generic parameter, which will be exposed by Michael's generic devirt work.

Swift SVN r16869
2014-04-26 03:09:35 +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
John McCall
9728a90780 Stop trying to analyze every possible type in
reemitAsUnsubstituted and just bitcast between the
explosion kinds.

Swift SVN r16791
2014-04-25 01:31:15 +00:00
John McCall
b38a63950d Implement @unowned(unsafe).
This was part of the original weak design that
there was never any particular reason to rush the
implementation for.  It's convenient to do this now
so that we can use it to implement Unmanaged<T> for
importing CF types.

Swift SVN r16693
2014-04-23 08:51:23 +00:00
John McCall
8681963bcb A couple of long-overdue renames.
Builtin.ObjectPointer -> Builtin.NativeObject
Builtin.ObjCPointer -> Builtin.UnknownObject

Swift SVN r16634
2014-04-22 00:17:08 +00:00
Doug Gregor
09797f7f99 Introduce a new declaration node, ParamDecl, for function parameters.
Use this node to capture the argument name and its source location in
the AST. We're only building these in one place at the moment; the
rest will be updated soon.


Swift SVN r16581
2014-04-20 05:23:35 +00:00
Joe Groff
eaa6088102 SIL: Remove the now-obsolete bridge_to_block instruction.
Swift SVN r16487
2014-04-18 02:26:10 +00:00
Joe Groff
318aba81ef IRGen: Implement block header generation.
Implement the init_block_storage_header SIL instruction by teaching IRGen how to produce block descriptors, including copy/dispose helpers and block signatures.

Swift SVN r16478
2014-04-17 22:40:23 +00:00
Arnold Schwaighofer
989d554a45 Add support for an assert_configuration builtin function
This patch adds support for a builtin function assert_configuration that is
replaced by constant progpagation by an appropriate value dependent on a compile
time setting. This replacement can also be disabled when serializing sil for a
library.

Using this mechanism we implement assertions that can  be disabled (or whose
behavior changes) depending on compile time build settings (Debug, Release,
DisableReplacement).

In the standard library we can now write one assert function that uses this
builtin function to provide different compile time selectable runtime behavior.

Example

Assert.swift:

@transparent
func assert<T : LogicValue>(
  condition: @auto_closure () -> T, message: StaticString = StaticString(),

  // Do not supply these parameters explicitly; they will be filled in
  // by the compiler and aren't even present when asserts are disabled
  file: StaticString = __FILE__, line: UWord = __LINE__
) {
  // Only in debug mode.
  if _isDebug() {
    assert(condition().getLogicValue(), message, file, line)
  }
}

AssertCommon.swift:

@transparent
func _isDebug() -> Bool {
  return Int32(Builtin.assert_configuration()) == 0;
}

rdar://16458612

Swift SVN r16472
2014-04-17 22:05:42 +00:00
Joe Groff
4201f6714a IRGen: Implement type info for SILBlockStorageType.
Swift SVN r16428
2014-04-17 00:43:23 +00:00
Joe Groff
8adaab0233 Fold ExtInfo::isThin and ::isBlock into a "Representation" enum.
These bits are orthogonal to each other, so combine them into one, and diagnose attempts to produce a type that's both. Spot-fix a bunch of places this revealed by inspection that we would have crashed in SILGen or IRGen if blocks were be handled.

Swift SVN r16088
2014-04-09 00:37:26 +00:00
Joe Groff
def2f97944 IRGen: Generalize 'hasSwiftRefcount' into an enum of reference counting mechanisms.
Replace HeapTypeInfo::hasSwiftRefcount with a "getSwiftRefcounting" method, returning an enum indicating whether a heap object has native/ObjC/block/unknown refcounting semantics. Use _Block_copy and _Block_release for block refcounting.

Swift SVN r16041
2014-04-08 02:43:16 +00:00
John McCall
6d213c1097 Use LLVM's inttoptr and ptrtoint instructions to coerce
those instead of going through memory.

This actually is important for making the ARC autorelease
reclaim optimization happen at -O0.

Swift SVN r15780
2014-04-02 07:42:36 +00:00
John McCall
446a9bd4a7 Introduce CanType versions of the various "getXOrBoundGenericX"
accessors.

Optimize these accessors by making them check for
BoundGenericXType instead of BoundGenericType and dyn_cast'ing
the Decl.  (The latter used to be necessary before we split
BoundGenericType.)

Swift SVN r15037
2014-03-14 05:59:44 +00:00
Chris Lattner
4efcd935f1 silence a fallthrough warning I missed.
Swift SVN r15035
2014-03-14 05:54:49 +00:00
Adrian Prantl
d1fed3b520 silence warnings
Swift SVN r14921
2014-03-11 16:55:15 +00:00
Greg Parker
0c44aa4c5e Add a failure ordering to cmpxchg builtin (following llvm r203559).
Swift SVN r14918
2014-03-11 14:44:26 +00:00
Mark Lacey
2a2b0a068e Support (non-byval) indirect parameters.
Also add some ABI test output for ARM64.

Resolves the core issue with <rdar://problem/16135769>.

Swift SVN r14658
2014-03-04 22:41:16 +00:00
Dmitri Hrybenko
a39d5b4f42 Track LLVM ToT header file name changes
This should unbreak the buildbot.


Swift SVN r14642
2014-03-04 13:11:01 +00:00
Joe Pamer
f83f94d9d8 Support build and target configurations
These changes add support for build and target configurations in the compiler.
Build and target configurations, combined with the use of #if/#else/#endif allow
for conditional compilation within declaration and statement contexts.

Build configurations can be passed into the compiler via the new '-D' flag, or
set within the LangOptions class. Target configurations are implicit, and
currently only "os" and "arch" are supported.

Swift SVN r14305
2014-02-24 18:16:48 +00:00
John McCall
79fad0cc87 Remove FunctionRef and CodeRef from IRGen in favor of SILDeclRef.
Swift SVN r14248
2014-02-22 01:45:44 +00:00
Doug Gregor
c54f98fbc9 Convert thick/thin metatype bool to an enumeration. NFC
Swift SVN r14075
2014-02-19 06:05:48 +00:00
Joe Groff
a0874ad8d0 Add a Builtin.canBeObjCClass "type trait" builtin.
This builtin returns true for types that might be ObjC class types. We want to use this builtin to optimize away NSArray handling for non-object Array types, so it needs to persist in SIL long enough for specialization to do its thing, but we never actually want to pay a runtime cost for this check, so always lower it to a constant value at IRGen time. Handle this by having canBeObjCClass return a tri-state "yes/maybe/no" result. In SILGen, we only fold away obviously "yes" or "no" cases, and in IRGen, we fold away "maybe" cases as "yes".

The optimizer will need to learn about this builtin too, but that part isn't done yet.

Swift SVN r13980
2014-02-17 07:25:52 +00:00
Joe Groff
bca066498f IRGen: Emit calls into blocks.
Add a 'Block' ExtraData kind, and teach IRGen how to pull the invocation pointer out of a block structure and pass the block object in the right place.

Swift SVN r13940
2014-02-15 08:17:09 +00:00
Mark Lacey
112e5c1dc2 Remove obsolete comments.
Swift SVN r13865
2014-02-13 09:27:10 +00:00
Mark Lacey
df975185ac Handle padding arguments in C/ObjC entrypoints and calls.
Swift SVN r13864
2014-02-13 08:49:31 +00:00
Mark Lacey
f22fc15b37 Emit extension attributes when lowering C/ObjC entrypoints.
Adds generation of signext/zeroext for return value and arguments when
generating C/ObjC entrypoints.

<rdar://problem/16056735> tracks doing this more generally for call
sites as well as for native entrypoints.

Swift SVN r13862
2014-02-13 07:43:23 +00:00
Mark Lacey
70fa0dead0 Select ABI types for all arguments of a C/ObjC function together.
Updates to signature expansion, entrypoint lowering, and callsite
lowering so that each selects the ABI types for all arguments at once
rather than an argument at a time (as well as considering whether the
return value is returned indirectly). This is required to get the
correct behavior in cases where we run out of argument registers and
need to pass arguments as indirect byvals.

This is mostly just refactoring existing code to move loops inside inner
functions as well as dealing with return values at the same time as
arguments.

Swift SVN r13781
2014-02-11 06:45:53 +00:00