Commit Graph

57 Commits

Author SHA1 Message Date
John McCall
e249fd680e Destructure result types in SIL function types.
Similarly to how we've always handled parameter types, we
now recursively expand tuples in result types and separately
determine a result convention for each result.

The most important code-generation change here is that
indirect results are now returned separately from each
other and from any direct results.  It is generally far
better, when receiving an indirect result, to receive it
as an independent result; the caller is much more likely
to be able to directly receive the result in the address
they want to initialize, rather than having to receive it
in temporary memory and then copy parts of it into the
target.

The most important conceptual change here that clients and
producers of SIL must be aware of is the new distinction
between a SILFunctionType's *parameters* and its *argument
list*.  The former is just the formal parameters, derived
purely from the parameter types of the original function;
indirect results are no longer in this list.  The latter
includes the indirect result arguments; as always, all
the indirect results strictly precede the parameters.
Apply instructions and entry block arguments follow the
argument list, not the parameter list.

A relatively minor change is that there can now be multiple
direct results, each with its own result convention.
This is a minor change because I've chosen to leave
return instructions as taking a single operand and
apply instructions as producing a single result; when
the type describes multiple results, they are implicitly
bound up in a tuple.  It might make sense to split these
up and allow e.g. return instructions to take a list
of operands; however, it's not clear what to do on the
caller side, and this would be a major change that can
be separated out from this already over-large patch.

Unsurprisingly, the most invasive changes here are in
SILGen; this requires substantial reworking of both call
emission and reabstraction.  It also proved important
to switch several SILGen operations over to work with
RValue instead of ManagedValue, since otherwise they
would be forced to spuriously "implode" buffers.
2016-02-18 01:26:28 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Joe Groff
25e43e3d48 IRGen: Mark more allocas with lifetime markers.
This should cover most temporary buffers, except for those used by indirected value arguments, which need some cooperation with CallEmission to properly mark lifetime end after the call's completed.
2015-12-26 15:19:07 -08:00
Joe Groff
c354a7cf63 IRGen: Relax assertion that C parameter ABI types match size of Swift struct representation types.
Share the code that does elementwise coercions, which already behaved correctly, with the code that does struct-to-struct coercions, which still had the overly-conservative constraint. Fixes rdar://problem/21294916.

Swift SVN r29399
2015-06-16 17:23:52 +00:00
Joe Groff
e98d9621fc IRGen: Remove dead functions.
Swift SVN r29014
2015-05-26 01:49:06 +00:00
John McCall
dc5a03a7bc Add IRGen support for error results from functions.
As part of this, re-arrange the argument order so that
generic arguments come before the context, which comes
before the error result.  Be more consistent about always
adding a context parameter on thick functions, even
when it's unused.  Pull out the witness-method Self
argument so that it appears last after the error
argument.

Swift SVN r26667
2015-03-28 02:00:17 +00:00
John McCall
5f8a81ad8f Reapply r24949. My search for uses of ABIArgInfo::Expand
was incomplete; we do use it on i386 for arbitrary small
aggregates, and unfortunately this means we have to learn
how to expand quite a lot of types.

Tested by the i386-simulator build.  I still think
we can completely remove this code relatively soon.

Swift SVN r24981
2015-02-05 00:00:31 +00:00
Dmitri Hrybenko
a979680e1d Revert "Implement clang::ABIArgInfo::Expand correctly when matching"
This reverts commit r24949.  It broke the standard library build for the
32-bit iphonesimulator.

Swift SVN r24966
2015-02-04 19:29:16 +00:00
John McCall
319b5f24fc Implement clang::ABIArgInfo::Expand correctly when matching
the C calling convention.

You might notice the absence of tests.  Older versions of Clang
used Expand for ARM64 homogeneous aggregates.  Trunk Clang no
longer does this, and indeed, on Apple platforms we no longer
use Expand to pass any kind of argument at all.  The only target
in trunk that uses it is the Windows target's vectorcall
alternative CC, which I have no way to convince Swift to
generate a call against.  Therefore this code is completely
dead in trunk, and thus untestable.

Removing Expand completely from Clang would be the ideal solution,
but that's politically tricky because this is a part of Clang
that's frequently edited by people supporting out-of-tree backends.
I've started the process, but until then, if we're going to have
dead code, it ought to at least be correct dead code.

This commit fixes rdar://19199427, or at least it will
when it's merged to branches that actually use Expand.

Swift SVN r24949
2015-02-04 08:08:39 +00:00
Joe Groff
1a845bfbd2 IRGen: Make partial application forwarders honor the convention of the applied parameters.
Until now, we treated all value parameters as +1, and all indirect parameters as +0 by reference, which is totally bogus. Now that we'll be partially applying guaranteed parameters, for instance to implement SomeType.foo curried method references, we need to get this right.

This breaks curries that capture dependent-layout parameters by value, but they were already broken due to us treating them as 'inout' captures. I'll fix this by adding NecessaryBindings and NonFixedOffsets to HeapLayout next.

Swift SVN r24475
2015-01-16 16:01:59 +00:00
Joe Groff
a60a52d72e SIL: Add a "builtin" instruction to represent builtin invocations.
Modeling builtins as first-class function values doesn't really make sense because there's no real function value to emit, and modeling them this way complicates passes that work with builtins because they have to invent function types for builtin invocations. It's much more straightforward to have a single instruction that references the builtin by ID, along with the type information for the necessary values, type parameters, and results, so add a new "builtin" instruction that directly represents a builtin invocation. NFC yet.

Swift SVN r22690
2014-10-11 20:34:24 +00:00
Jordan Rose
9891c7f2f2 Replace swift::Optional with llvm::Optional.
There are some compatibility aliases here that will go away after the switch.

Swift SVN r22474
2014-10-02 18:51:38 +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
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
Joe Groff
4201f6714a IRGen: Implement type info for SILBlockStorageType.
Swift SVN r16428
2014-04-17 00:43:23 +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
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
John McCall
93d7bc4f0d Remove unnecessary Expr uses from IR-gen.
Swift SVN r12428
2014-01-16 22:32:35 +00:00
John McCall
a1b469ed2f ExplosionKind -> ResilienceExpansion. NFC.
Swift SVN r12364
2014-01-16 00:25:29 +00:00
Chris Lattner
a5cf0fa60a Hoist the FuncDecl out of builtin function IRGen, working in terms
of the simpler Identifier instead.


Swift SVN r10693
2013-11-30 01:04:38 +00:00
John McCall
20e58dcf93 Change the type of function values in SIL to SILFunctionType.
Perform major abstraction remappings in SILGen.  Introduce
thunking functions as necessary to map between abstraction
patterns.

Swift SVN r10562
2013-11-19 22:55:09 +00:00
Joe Groff
82a18333ed SIL: Purge SpecializeInst.
Make ApplyInst and PartialApplyInst directly take substitutions for generic functions instead of trying to stage out substitutions separately. The legacy reasons for doing this are gone.

Swift SVN r8747
2013-09-28 00:15:45 +00:00
Joe Groff
b86203f021 IRGen: Emit partial applications of indirect function calls.
Add support to partial_apply lowering to handle partial applications of indirect functions, including ones that already have context.

Swift SVN r8074
2013-09-10 18:59:08 +00:00
Dmitri Hrybenko
d0455ca1c6 Remove unneeded llvm:: qualifier for llvm::ArrayRef
Swift SVN r7093
2013-08-09 20:05:02 +00:00
Joe Groff
3e3e5710ec Set proper DeclContext for ImplicitClosureExprs.
Now that SILGen and IRGen can both handle capturing archetypes from generic scopes, we can set the DeclContext of ImplicitClosureExprs correctly, so that SILGen captures their context archetypes. &&, and ||, and assert now work in generic contexts, at least in simple test cases.

Swift SVN r5476
2013-06-05 05:09:59 +00:00
Joe Groff
ae56951d08 IRGen: Emit specialized partial_apply thunks.
If a specialization is partially applied, emit a single thunk bundling the bound polymorphic arguments and the partially-applied argument values into a single context object. This should almost get closures in generic contexts (at least, ones that never cross abstraction boundaries) working.

Swift SVN r5475
2013-06-05 04:51:51 +00:00
Joe Groff
0cb8adb46f SIL: Force all SILInstruction allocations through SILModule.
Delete the non-placement operator new/delete in the SILAllocated CRTP base so that the compiler saves us from accidentally allocating and leaking SILInstructions on the main heap instead of the owning SILModule's BPA.

Swift SVN r5468
2013-06-04 15:32:11 +00:00
Joe Groff
6abe889cae IRGen: Push SILType through a couple layers of partial application.
Swift SVN r5193
2013-05-16 23:33:48 +00:00
Joe Groff
285031cc8c IRGen: Use SILTypes for utility functions used by conversion insns.
Push SILTypes down into the helper functions used to emit SuperToArchetype, Downcast, and BridgeToBlock instructions.

Swift SVN r5189
2013-05-16 22:31:46 +00:00
Joe Groff
a8a7e16cf9 IRGen: requiresExternal{ByvalArgument,IndirectResult} can use SILType now.
These functions are now used in places where we're emitting ObjC calls and have a SILType.

Swift SVN r5187
2013-05-16 21:44:43 +00:00
Joe Groff
c0a44f71c9 IRGen: Reify SpecializeInst thunks.
Teach IRGen how to emit thunks for SpecializeInsts that aren't immediately called and actually get used as values. This allows generic function instance to get passed around as values (again), and is a step along the way to making closures in generic contexts work (so we can specialize the local function, then partially apply its specialized context).

This doesn't work yet if we specialize to local archetypes--SIL needs to learn that we need a [thick]-typed thunk for local archetype specializations, in order to pack the metadata and wtables for the local type variables.

Swift SVN r5083
2013-05-07 23:39:06 +00:00
Joe Groff
0566088bf2 Move name mangling into SIL.
Sever the last load-bearing link between SILFunction and SILConstant by naming SILFunctions with their mangled symbol names. Move the core of the mangler up to SIL, and teach SILGen how to use it to mangle a SILConstant.

Swift SVN r4964
2013-04-28 03:32:41 +00:00
Chris Lattner
a8ed1a187f remove CallSite and emitRValueForFunction
Swift SVN r4795
2013-04-18 05:09:38 +00:00
Chris Lattner
03394a29ea remove prepareCall and some various array handling logic now handled by SILGen.
Swift SVN r4793
2013-04-18 04:57:27 +00:00
Chris Lattner
ade66c8b10 Remove the emitIgnored, emitLValue, and tryEmitAsAddress mechanics and
supporting logic.


Swift SVN r4770
2013-04-17 05:33:23 +00:00
Joe Groff
a90338bddb IRGen: Compile builtin calls from SIL.
When lowering SIL builtin ConstantRefs, just stash away the FuncDecl, and pass that decl on to a tweaked version of emitBuiltinCall when the constant is applied.

Swift SVN r4736
2013-04-15 21:04:36 +00:00
Joe Groff
45e5909911 IRGen: Export objc methods w/ NSRect return/args.
Fix up the thunk generator so it knows how to turn byval C arguments back into Swift explosions, so that methods that take NSRects as arguments or give NSRect as their return value can be exported as objc methods.

Swift SVN r4010
2013-02-10 17:24:27 +00:00
Joe Groff
9c022d5d65 IRGen: Fudge passing large ObjC structs as byvals.
Push LLVM attribute generation from expandAbstractCC into getFunctionSignature and CallEmission so that they can generate sret and/or byval attributes per-argument according to the calling convention. Copy our bogus rule for emitting sret returns (more than three elements in the explosion) and reuse it to pass large struct values as byvals rather than as explosions. This should be good enough to get both 'NSRect' and
'NSRange', 'NSSize' etc. to pass correctly to ObjC methods. Next step is to set the AbstractCC correctly for imported func decls so that standalone C functions follow the same bogus rule.

Swift SVN r3993
2013-02-08 21:50:08 +00:00
Joe Groff
6cca08826a IRGen: Hack in calls to block converter funcs.
Add a mangling for 'block converter' functions and for [objc_block] function types. [objc_block] types also need their own HeapTypeInfo representation that uses ObjC retain/release. When we see a BridgeToBlockExpr, feed the function pointer and context from the Swift closure to the external conversion function and hope we get a block back.

Swift SVN r3899
2013-01-30 01:01:34 +00:00
Joe Groff
0bf66dae4b IRGen: Separate allocating and initializing ctors.
Emit separate entry points for the allocating and initializing constructors. 'super.constructor' now works for the small subset of cases for which I've implemented sema support.

Swift SVN r3864
2013-01-25 17:50:55 +00:00
Joe Groff
c9d6a351f5 IRGen: SIL ClosureInsts (almost).
Implement lowering of SIL ClosureInsts by packing the partial arguments into a heap allocation and emitting a thunk to unpack them and apply the closure function, similar to curried entry points. The test doesn't work quite yet because nested FuncDecls don't get visited anymore. I need to replace my hacked SIL path with a proper walk of the SIL module to generate functions and the AST to generate types.

Swift SVN r3817
2013-01-20 19:50:10 +00:00
Joe Groff
9259c0d912 IRGen: Get "hello world" to compile through SIL.
Add a path through IRGenModule to optionally codegen FuncDecls using their corresponding SIL Functions when constructed with a SILModule. Jury-rig an IRGenSILFunction subclass of IRGenFunction that does the bare minimum necessary to compile "hello world" from SIL. There are some impedance mismatches between irgen and SIL that need to be smoothed out, particularly the AST-dependent way irgen currently handles function calls. Nonetheless, `swift -sil-i hello.swift` works!

Swift SVN r3759
2013-01-14 02:57:11 +00:00
John McCall
9106aa6254 Rewrite the function-call infrastructure. This gets us
a lot closer to successfully emitting the polymorphic-min-over-ranges
example;  the main blocker right now seems to be that the witness
for a static member function is not, in fact, a static member
function at al, but a freestanding function.  That's legitimate,
but it probably needs some shepherding through the witness
system.

Swift SVN r2532
2012-08-03 08:10:47 +00:00
John McCall
ed38caaa04 Support generic return types, as long as they don't differ
by abstraction from the concrete return type.

This basically gets generic calls working totally as long
as there's no remapping required.

Swift SVN r2402
2012-07-23 07:06:28 +00:00
John McCall
3950a6af41 Generic calls status code dump activate!
Swift SVN r2386
2012-07-20 21:59:14 +00:00
John McCall
b5381edb88 Some overlooked uses of std::vector that are unnecessary
now that SmallVector is move-only-compatible.

Swift SVN r2151
2012-06-05 04:51:12 +00:00
John McCall
24a84132ca More CC-related changes.
Swift SVN r2150
2012-06-05 04:51:04 +00:00
John McCall
5064f39024 Refactor towards the goal of using different CCs when
passing this pointers or data arguments.

Swift SVN r2149
2012-06-05 04:50:58 +00:00