Commit Graph

45 Commits

Author SHA1 Message Date
John McCall
0a282c044f Unify all of the task-creation builtins coming out of SILGen.
We've been building up this exponential explosion of task-creation
builtins because it's not currently possible to overload builtins.
As long as all of the operands are scalar, though, it's pretty easy
to peephole optional injections in IRGen, which means we can at
least just use a single builtin in SIL and then break it apart in
IRGen to decide which options to set.

I also eliminated the metadata argument, which can easily be recreated
from the substitutions.  I also added proper verification for the builtin,
which required (1) getting `@Sendable` right more consistently and (2)
updating a bunch of tests checking for things that are not actually
valid, like passing a function that returns an Int directly.
2024-03-06 22:21:12 -05:00
Ben Barham
f292ec9784 Use the new template deduction guides rather than makeArrayRef
LLVM has removed `make*ArrayRef`, migrate all references to their
constructor equivalent.
2024-02-23 20:04:51 -08:00
Erik Eckstein
fe367e8013 Optimizer/IRGen: allow enums in static initializers of globals
The main change here is in IRGen which needs to be able to emit constant enum values.
Use `emitValueInjection` to create the enum constant.
Usually this method creates code in the current function.
But if all arguments to the enum are constant, the builder never has to emit an instruction.
Instead it can constant fold everything and just returns the final constant.

Also, create statically initialized let-globals as constant global (`constant` instead of `global`).
2023-05-25 16:28:41 +02:00
Ben Langmuir
35478637d3 Migrate from SmallVector.set_size to resize_for_overwrite
In the "next" branch, set_size has been made protected. Instead, users
can use resize_for_overwrite, optionally followed by truncate, to
handle the same use cases more safely.
2022-02-24 13:54:22 -08:00
Nate Chandler
d765434e2b [IRGen] Restored non-constant async function calls in PAFs.
Previously, because partial apply forwarders for async functions were
not themselves fully-fledged async functions, they were not able to
handle dynamic functions.  Specifically, the reason was that it was not
possible to produce an async function pointer for the partial apply
forwarder because the size to be used was not knowable.

Thanks to https://github.com/apple/swift/pull/36700, that cause has been
eliminated.  With it, partial apply forwarders are fully-fledged async
functions and in particular have their own async function pointers.
Consequently, it is again possible for these partial apply forwarders to
handle non-constant function pointers.

Here, that behavior is restored, by way of reverting part of
ee63777332 while preserving the ABI it
introduced.

rdar://76122027
2021-04-06 15:51:32 -07:00
Nate Chandler
409f3d253b [NFC] Removed Explosion::peek.
The convenience was added to aid with the async calling convention but
it has proven to be unnecessary.  Here, it is removed.
2020-10-21 16:19:14 -07:00
Nate Chandler
ee88152d6b [Concurrency] First steps towards async CC.
Here, the following is implemented:
- Construction of SwiftContext struct with the fields needed for calling
  functions.
- Allocating and deallocating these swift context via runtime calls
  before calling async functions and after returning from them.
- Storing arguments (including bindings and the self parameter but not
  including protocol fields for witness methods) and returns (both
  direct and indirect).
- Calling async functions.

Additional things that still need to be done:
- protocol extension methods
- protocol witness methods
- storing yields
- partial applies
2020-10-05 20:43:51 -07:00
Sho Ikeda
08644c1d8f [gardening][IRGen] Replace typedef with using 2018-03-27 09:06:33 +09:00
Arnold Schwaighofer
39fa2f0228 Use the swift calling convention for swift functions
Use the generic type lowering algorithm described in
"docs/CallingConvention.rst#physical-lowering" to map from IRGen's explosion
type to the type expected by the ABI.

Change IRGen to use the swift calling convention (swiftcc) for native swift
functions.

Use the 'swiftself' attribute on self parameters and for closures contexts.

Use the 'swifterror' parameter for swift error parameters.

Change functions in the runtime that are called as native swift functions to use
the swift calling convention.

rdar://19978563
2017-02-14 12:17:57 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Joe Groff
aad6bc87fd IRGen: Pass large explosions as indirect arguments.
It's not worth burning more than three registers on a parameter, and doing so causes code size issues for large structs and enums. Make it so that values with more than three explosion members get passed indirectly, just like they get returned indirectly.

This time, modify emitPartialApplyForwarder not to attempt to 'tail' call the original function when indirect arguments get alloca'ed on the stack, which is UB, and don't use "byval", as suggested by John.

Swift SVN r29032
2015-05-26 17:38:22 +00:00
Joe Groff
7a5b199a34 Revert "IRGen: Pass large explosions as indirect byval arguments."
This reverts commit r29016, because of a test failure on the bots.

Swift SVN r29018
2015-05-26 02:13:16 +00:00
Joe Groff
abba73c77f IRGen: Pass large explosions as indirect byval arguments.
It's not worth burning more than three registers on a parameter, and doing so causes code size issues for large structs and enums. Make it so that values with more than three explosion members get passed indirectly, just like they get returned indirectly.

Swift SVN r29016
2015-05-26 01:49:45 +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
a1b469ed2f ExplosionKind -> ResilienceExpansion. NFC.
Swift SVN r12364
2014-01-16 00:25:29 +00:00
Greg Parker
be12f30395 Move MaxScalarsForDirectResult to SwiftTargetInfo.
Swift SVN r8935
2013-10-04 22:11:46 +00:00
Dmitri Hrybenko
d0455ca1c6 Remove unneeded llvm:: qualifier for llvm::ArrayRef
Swift SVN r7093
2013-08-09 20:05:02 +00:00
Dmitri Hrybenko
de59d8dcd4 Remove unneeded llvm:: qualifier for llvm::StringRef and llvm::SmallVector
Swift SVN r7089
2013-08-09 18:41:46 +00:00
Chris Lattner
2b6902b232 eliminate the "manage" operation on TypeInfo, which is now a (complicated!) noop.
Swift SVN r4850
2013-04-21 16:27:43 +00:00
Chris Lattner
85663f6df2 simplify Explosion by eliminating (now) copies of existing methods.
This removes addUnmanaged, ignoreAndDestroy, ignoreUnmanaged, claimUnmanagedNext,
claimUnmanaged, forwardNext, and forward


Swift SVN r4846
2013-04-21 06:29:50 +00:00
Chris Lattner
0be7bbdddf remove ManagedValue.
Swift SVN r4843
2013-04-21 05:56:02 +00:00
Chris Lattner
510042f939 removed the registration logic from Initialization and Depth from Scope.
Swift SVN r4842
2013-04-21 05:39:35 +00:00
Chris Lattner
6e50329da3 remove the cleanups list from CallEmission and ManagedValue, along with the machinery for adding Cleanups.
Swift SVN r4840
2013-04-21 05:16:00 +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
John McCall
7c277001a4 Implement basic objc_msgSend capabilities.
Swift SVN r3104
2012-11-03 00:26:56 +00:00
John McCall
6e9a2aab8b Fix a conceptual bug in class metadata: the parent pointer
of a class is part of the class members section and is not
global to the entire class metadata.  This is crucial for
correct operation of functions expecting a base-class
metadata object.

That gives us the correct foundation to implement an
optimization under which generic arguments that can be
inferred from the 'this' pointer need not actually be
separately passed.  This has the important result of
making all class member functions with the same signature
up to abstraction actually have the same physical
signature.

Swift SVN r2936
2012-10-04 23:44:31 +00:00
John McCall
286a1a14dd Assert early when something tries to add null to an explosion.
Swift SVN r2621
2012-08-13 09:04:04 +00:00
John McCall
e53aed65d7 Initial support for IR-genning generic function bodies.
Mangling is still a hack, pending a better type AST.  Fixed
a bug where arguments passed indirectly were not being destroyed
by the callee (when passed by value).  Changed some of the protocol
signatures to use the generic opaque pointer type, making the
types a bit more self-documenting in the IR.

Swift SVN r2274
2012-06-28 08:50:06 +00:00
Eli Friedman
26bebcfd61 IRGen for break/continue.
Swift SVN r2089
2012-05-31 02:45:18 +00:00
John McCall
95a8c35a36 Implement IR-generation for instance method witnesses.
Swift SVN r1966
2012-05-24 12:16:40 +00:00
John McCall
85fecab3b1 Reorganize the emission of a call site so that it's abstracted over
exactly how the arguments are emitted.  Introduce a new code path
which emits arguments from existing Explosions (possibly of the wrong
resilience level).  Use that code path to implement getter/setter
code for MemberRefExpr l-values.  This is just a checkpoint for the
latter two parts, but the ApplyExpr path is working correctly in the
new framework, which is worth a commit.

Swift SVN r1589
2012-04-24 08:16:51 +00:00
John McCall
d68fee8b41 Perform Builtin.load and Builtin.store using the type
info for the result/argument type.  This makes them
properly generic over an arbitrary type.

Swift SVN r1563
2012-04-23 17:46:58 +00:00
Eli Friedman
4ab945f192 Fix Ted's currying fractal example. <rdar://problem/11278150>.
Swift SVN r1506
2012-04-19 21:52:02 +00:00
John McCall
ca9f85d694 Add code for associating cleanups with intermediate
evaluation results and then claiming or forwarding the
ownership of such results.

Swift SVN r1337
2012-04-06 07:07:28 +00:00
John McCall
edad637ddb In preparation for Explosion storing some sort of cleanup pointer,
add some APIs for working with non-cleaned-up entities.

Swift SVN r1336
2012-04-06 07:07:22 +00:00
John McCall
d76aaea2b6 Remove the outdated RValue concept; no functionality change.
Swift SVN r1216
2012-03-16 09:26:39 +00:00
John McCall
1f118dbda6 Basic support for Builtin.ObjectPointer as a completely
opaque type.  Also some rudimentary support for retain/release.

Swift SVN r1214
2012-03-16 09:26:32 +00:00
John McCall
b85ddcb34a IR generation for curried functions. For now, parameters
are stored in a malloc'ed buffer that gets leaked.



Swift SVN r1092
2012-01-19 23:29:49 +00:00
John McCall
44da666866 Move ExplosionKind to IRGen.h so that using it doesn't
require Explosion.h.  This is just to isolate the parts
of IR-generation that shouldn't have anything to do with
emitting code within functions.



Swift SVN r1039
2012-01-13 10:20:59 +00:00
John McCall
5dde760272 Switch function prologue and application over to using Explosion
and teach them about currying.



Swift SVN r1038
2012-01-13 10:08:14 +00:00
John McCall
885783ab76 Start switching things over to using explosions.
Swift SVN r1014
2012-01-12 07:05:49 +00:00
John McCall
c7bcadf450 On further reflection and use, the concept of an RValue is not actually
very useful;  it is much more interesting to divide r-value emission
into "to arguments" and "to memory" models.  To that end, introduce a
new structure for holding an "exploded" r-value.



Swift SVN r1006
2012-01-11 23:59:57 +00:00