Commit Graph

680 Commits

Author SHA1 Message Date
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
Mark Lacey
85edc079b7 Coerce scalar types in function returns.
Previously we coerced only struct return types, but we actually need to
be able to coerce scalar types as well, e.g. differing pointer types
when the ABI type differs from the type used in the body of the
function.

Swift SVN r12527
2014-01-18 02:08:04 +00:00
Mark Lacey
d9c88e94db Small clean-up in Clang type generation.
Factor our code to get to Clang ASTContext.

Swift SVN r12462
2014-01-17 04:25:10 +00:00
John McCall
32d4ef7001 Remove IR-gen's specialized ASTVisitor.
Swift SVN r12427
2014-01-16 22:32:35 +00:00
Joe Groff
0c20833d5f IRGen: Optimize copy/destroy of ObjC tagged or nullable enums too.
Rename TypeInfo::isSingleRetainablePointer to TypeInfo::isSingleSwiftRetainablePointer, and add an isSingleUnknownRetainablePointer entry point to ask whether a type has any single-refcounted representation, native or not. Use that to provide the same nullable-pointer and pointer-with-tag optimizations for copying and destroying enums with ObjC payloads as we do for Swift class payloads.

Swift SVN r12410
2014-01-16 19:08:01 +00:00
Joe Groff
197a1653fd SIL: Start on a StripRuntimeChecks pass.
In the long term we want more detailed configurability of runtime checks, but for our short-term performance work we just want a blanket on/off switch. Add a StripRuntimeChecks SIL pass that, as a start, converts invocations of checked overflow builtins to the equivalent unchecked builtins and kills cond_fails. Expose it through the compiler with a -disable-all-runtime-checks switch.

NB: I haven't tested building the stdlib or running the tests with the switch thrown yet.

Swift SVN r12379
2014-01-16 02:35:16 +00:00
John McCall
a1b469ed2f ExplosionKind -> ResilienceExpansion. NFC.
Swift SVN r12364
2014-01-16 00:25:29 +00:00
Joe Groff
1001745ac0 IRGen: Forward indirectly-returned SIL return value in partial application forwarder.
A type may be treated as a by-value return in SIL but still be lowered to an indirect return in IR if it's big enough, so handle this case in the partial application forwarder. Fixes <rdar://problem/15826328>.

Swift SVN r12351
2014-01-15 22:05:50 +00:00
Joe Groff
0bc54babdb IRGen: Don't assume the ABI return type of a function is a struct.
For some structs on arm64 this doesn't hold, and the assumption isn't important to the code.

Swift SVN r12333
2014-01-15 18:17:28 +00:00
Mark Lacey
673a65c2a5 Move Clang type generation into its own file.
We want to be able to share this both for signature type generation and
Objective-C type encoding.

A separate implementation file will follow when I expand the
functionality for more than just imported struct types.

Swift SVN r12137
2014-01-10 22:05:12 +00:00
Joe Groff
5e5f31d5e3 IRGen: Share TypeInfo among equivalent generic instantiations, take 2.
IRGen type conversion is invariant with respect to archetypes with the same set of constraints, so instead of redundantly generating a TypeInfo object and IR type for Optional<T> for every T everywhere, key TypeInfo objects using an "exemplar type" that we form using a folding set to collapse together archetypes with the same class-ness, superclass constraint, and protocol constraints.

This is a nice memory and IR size optimization, but will be essential for correctness when lowering interface types, because there is no unique context to ground a dependent type, and we need to lower the same generic parameter with the same context requirements to the same type whenever we instantiate it in order for the IR to type-check.

In this revision, we profile the nested archetypes of each recursively, which I neglected to take into account originally in r12112, causing failures when archetypes that differed by associated type constraints were incorrectly collapsed.

Swift SVN r12116
2014-01-10 05:25:45 +00:00
Doug Gregor
03edef185a Emit a -dealloc method for Swift classes whose root class is defined in Objective-C.
Teach SILGen to emit a -dealloc method that runs user code, destroys
instance variables, and then calls up to the superclass dealloc. Teach
IRGen to deal with Objective-C destructor methods and add -dealloc to
the instance method table.

There are a few things still wrong here: we're emitting both a Swift
destructor and -dealloc, even though only one of them should ever
actually be used. Additionally, instance variables shouldn't be
destroyed in -dealloc, but in .cxx_destruct, so they persist until the
last of the -dealloc methods is invoked.

Swift SVN r12115
2014-01-10 05:07:33 +00:00
Joe Groff
97ff9e47a8 Revert "IRGen: Share TypeInfo among equivalent generic instantiations."
This reverts commit r12112. It gives the buildbot indigestion.

Swift SVN r12113
2014-01-10 03:22:53 +00:00
Joe Groff
57cacbfe38 IRGen: Share TypeInfo among equivalent generic instantiations.
IRGen type conversion is invariant with respect to archetypes with the same set of constraints, so instead of redundantly generating a TypeInfo object and IR type for Optional<T> for every T everywhere, key TypeInfo objects using an "exemplar type" that we form using a folding set to collapse together archetypes with the same class-ness, superclass constraint, and protocol constraints.

This is a nice memory and IR size optimization, but will be essential for correctness when lowering interface types, because there is no unique context to ground a dependent type, and we need to lower the same generic parameter with the same context requirements to the same type whenever we instantiate it in order for the IR to type-check.

Swift SVN r12112
2014-01-10 02:02:58 +00:00
Mark Lacey
15a26af8ac Replace getClangABIType() with a CanTypeVisitor<>.
No functionality change. This is in preparation for generating Clang
types for more than just imported structs.

Swift SVN r12108
2014-01-10 00:27:25 +00:00
John McCall
5da6defa1f Clean up the linkage model and the computation of linkage.
In general, this forces SILGen and IRGen code that's grabbing
a declaration to state whether it's doing so to define it.

Change SIL serialization to serialize the linkage of functions
and global variables, which means also serializing declarations.

Change the deserializer to use this stored linkage, even when
only deserializing a declaration, and to call a callback to
inform the client that it has deserialized a new entity.

Take advantage of that callback in the linking pass to alter
the deserialized linkage as appropriate for the fact that we
imported the declaration.  This computation should really take
advantage of the relationship between modules, but currently
it does not.

Swift SVN r12090
2014-01-09 08:58:07 +00:00
Joe Groff
e672eef600 IRGen: Remove long comment about uncurrying.
All uncurrying happens in SILGen now.

Swift SVN r11994
2014-01-07 17:56:33 +00:00
Chris Lattner
8d854f3e0b straighten out IRGen's @lvalue vs @inout handling. Since SILGen lowers all
@lvalue types, IRGen only needs to handle @inout.


Swift SVN r11799
2014-01-01 20:35:02 +00:00