Commit Graph

797 Commits

Author SHA1 Message Date
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
Doug Gregor
12c064d501 IR generation for DynamicSelf method invocations on existentials.
When projecting an existential into an opened archetype, bind the
archetype with metadata and witness tables extracted from the
existential. Tweak SILGen so that it doesn't destroy the opened
archetype value an extra two times.

Use an executable testcase to ensure end-to-end operation, because we
still don't have a parsable form existential projection to opened
archetype instructions.



Swift SVN r13755
2014-02-10 18:47:24 +00:00
Mark Lacey
e54a454cca Handle the remaining types in Clang type generation.
With this we generate Clang types for everything we allow to be in the
signature of a C/@objc function.

Swift SVN r13734
2014-02-10 05:07:22 +00:00
Mark Lacey
660bb20909 Select correct IR types for direct arguments to C/@objc functions.
Reapply r13532 fixes for dealing with arguments that should be exploded
for C/Obj-C functions.

This gets us a bit closer to properly generating the correct types for
arguments. The remaining piece is generating all the argument types at
once rather than one at a time, which also requires being able to always
generate Clang types for the Swift types we see in the signatures of
these functions.

Swift SVN r13638
2014-02-07 18:04:45 +00:00
Mark Lacey
d335817783 Revert "Generate arguments with the correct ABI types for C/Obj-C functions."
This reverts commit r13532 which broke the build.

Swift SVN r13547
2014-02-06 02:07:17 +00:00
Mark Lacey
fd8e10fa68 Generate arguments with the correct ABI types for C/Obj-C functions.
This gets us a bit closer to properly generating the correct types for
arguments. The remaining piece is generating all the argument types at
once rather than one at a time.

That part cannot happen until we can always generate Clang types for
the Swift types we see in the signatures of these functions.

Swift SVN r13532
2014-02-06 01:06:32 +00:00
Mark Lacey
db70ec74be Minor refactoring of return type handling for C/Obj-C functions.
Swift SVN r13520
2014-02-05 23:18:50 +00:00
Mark Lacey
e9e4db4168 Use the correct type when determining whether we need to coerce.
Swift SVN r13379
2014-02-03 22:48:39 +00:00
Doug Gregor
9740ccc33e Adopt Clang's new ABITypes.arrangeFreeFunctionCall API
Swift SVN r13308
2014-02-01 22:41:17 +00:00
Mark Lacey
088d7b5f20 IRGenModule users shouldn't need to know about clang::CodeGenerator.
Swift SVN r13179
2014-01-30 22:59:00 +00:00
Mark Lacey
d69b305200 Generate IR for inline functions from Clang modules.
Currently only inline functions referenced from Swift source files, or
from the REPL, will get IR generated for them. Inline functions
referenced by other inline functions will require additional effort to
generate properly.

With this change we use the clang::CodeGenerator-created llvm::Module
for all IR generation in Swift. This is perhaps undesirable, but
unavoidable given the interface the public Clang APIs expose, which do
not allow for building a ModuleBuilder that borrows an existing
llvm::Module.

Also unfortunate is the hack to generate a UsedAttr for each imported
inline function, but the public Clang APIs do not provide a way to only
emit deferred decls without emitting other things (e.g. module flags
that conflict with what the Swift IRGen emits). Note that we do not do
IRGen for every inline function in the module - only the ones that the
importer pulls in, which appears to be only those transitively
referenced from Swift code.

Swift SVN r13134
2014-01-30 02:33:37 +00:00
Mark Lacey
c06facbdd1 Small simplification of IRGenFunction::coerceValue().
We know the type of the value we are reinterpreting so it does not need
to be a parameter.

Swift SVN r12911
2014-01-24 07:51:26 +00:00
Mark Lacey
6fa70874fa Correctly select when C/ObjC arguments are passed as byvals.
Swift SVN r12890
2014-01-24 00:21:06 +00:00
Joe Groff
2af8cf2343 IRGen: Use interface types to lower ApplyInst args and returns, and SILFunction parameters and returns.
Swift SVN r12626
2014-01-21 00:23:07 +00:00
Joe Groff
dd5dec3dd5 IRGen: Use SILFunctionType interface types in easy places.
ObjC partial_apply thunks are never generic, and neither are cast builtins, so the interface types are always equivalent.

Swift SVN r12625
2014-01-21 00:23:06 +00:00
Joe Groff
5fc62094c7 IRGen: Fix handling of u_to_s_checked_trunc with runtime checks disabled.
I forgot to update this case from an implementation that doesn't work. Factor out the common implementation with the other cases and use it in both places. This enables the libraries and tests to build and run with -DSWIFT_RUNTIME_CHECKS=OFF.

Swift SVN r12609
2014-01-20 20:16:17 +00:00
Joe Groff
c7a8b4f1a5 IRGen: Emit unchecked operations for checked builtins with -disable-all-runtime-checks.
Emit checked arithmetic and conversion instructions as unchecked LLVM IR when runtime checks are disabled.

Swift SVN r12592
2014-01-20 18:01:02 +00:00
Joe Groff
4c6ef04d02 IRGen: Expand function signatures from SILFunctionType's interface types.
Now that we unique equivalent archetypes and lower interface types from the AST, we can convert IRGen over to using the interface types of the SILFunctionType when expanding out an LLVM function signature.

Swift SVN r12566
2014-01-19 17:14:09 +00:00
Mark Lacey
0564fae0bd Assert if we attempt to coerce types of different sizes.
We shouldn't store to one size and load as another, and shouldn't need
to handle things like truncation and extension of numeric types, either.

Swift SVN r12530
2014-01-18 04:49:32 +00:00