Commit Graph

1592 Commits

Author SHA1 Message Date
Arnold Schwaighofer
eaf90dff38 IRGen: Add metadata for async funclets denoting frame entry and frame exists
Adds sections `__TEXT,__swift_as_entry`, and `__TEXT,__swift_as_ret` that
contain relative pointers to async functlets modelling async function entries,
and function returns, respectively.

Emission of the sections can be trigger with the frontend option
`-Xfrontend -enable-async-frame-push-pop-metadata`.

This is done by:

* IRGen adding a `async_entry` function attribute to async functions.
* LLVM's coroutine splitting identifying continuation funclets that
  model the return from an async function call by adding the function
  attribute `async_ret`.  (see #llvm-project/pull/9204)
* An LLVM pass that keys off these two function attribute and emits the
  metadata into the above mention sections.

rdar://134460666
2024-09-03 08:44:16 -07:00
Arnold Schwaighofer
7fc028c57f IRGen: We need to map the direct type error explosion back to the native result in IRGenThunk
rdar://134730970
2024-08-28 10:56:25 -07:00
Slava Pestov
0c2f28fd3d AST: Remove GenericSignature parameter from OpenedArchetypeType::get() 2024-08-20 12:15:27 -04:00
Kavon Farvardin
9d69f2bceb Merge pull request #75382 from kavon/static-branch-prediction
Throws Prediction + HotColdSplitting
2024-08-09 15:24:22 -04:00
Andrew Savonichev
5aa9d3e29b Add partial_apply support for coroutines (#71653)
The patch adds lowering of partial_apply instructions for coroutines.

This pattern seems to trigger a lot of type mismatch errors in IRGen, because
coroutine functions are not substituted in the same way as regular functions
(see the patch 07f03bd2 "Use pattern substitutions to consistently abstract
yields" for more details). 

Other than that, lowering of partial_apply for coroutines is straightforward: we
generate another coroutine that captures arguments passed to the partial_apply
instructions. It calls the original coroutine for yields (first return) and
yields the resulting values. Then it calls the original function's continuation
for return or unwind, and forwards them to the caller as well.

After IRGen, LLVM's Coroutine pass transforms the generated coroutine (along with
all other coroutines) and eliminates llvm.coro.* intrinsics. LIT tests check
LLVM IR after this transformation.

Co-authored-by: Anton Korobeynikov <anton@korobeynikov.info>
Co-authored-by: Arnold Schwaighofer <aschwaighofer@apple.com>
2024-08-08 18:36:42 -07:00
Kavon Farvardin
885b758a52 IRGen: throws prediction for non-SIL calls
Some calls to throwing functions aren't represented with `try_apply` in
SIL, so we generate llvm.expect's when throw prediction is enabled.
2024-08-08 21:21:52 -04:00
Kavon Farvardin
0cce602bce SIL: branch weights for try_apply's 2024-08-08 21:21:52 -04:00
Dario Rexin
be1f8cd6fa [IRGen] Properly handle conversion between ptr and int for non-matching sizes in direct error returns
rdar://133006541

This caused issues on 32 bit platforms when merging a 64 bit and ptr types for direct error returns.
2024-08-04 11:34:02 -07:00
Anton Korobeynikov
8b7a75c8f3 [IRGen] Support indirect results for coroutines (#75322) 2024-08-02 19:36:07 -07:00
Dario Rexin
e0d9da454c [IRGen] Properly extract values in visitThrowInst for empty error
rdar://132122011

For async functions we have to extract the values, which was not happening when the error type was empty.
2024-07-19 17:01:13 -07:00
Dario Rexin
9b1a82d9ec [IRGen] Add direct error return support for async functions
rdar://129359370

Second part of direct error support. This implements direct errors for async functions. Instead of always returning typed errors indirectly, we are returning them directly when possible.
2024-07-13 17:02:32 -07:00
Dario Rexin
8fca31efde Merge pull request #75150 from drexin/wip-130971168
[IRGen] Don't apply direct error return to functions with indirect result
2024-07-10 21:07:40 -07:00
Dario Rexin
e3c0bc880c [IRGen] Don't apply direct error return to functions with indirect result
rdar://130971168

Having direct and indirect results on the same function is illegal.
2024-07-10 16:11:03 -07:00
Slava Pestov
fae01d9776 AST: Remove ModuleDecl parameter from more places 2024-07-06 12:05:46 -04:00
Dario Rexin
22fec31574 [IRGen] Properly convert between ptr and int in typed error mapping
rdar://130781414
2024-06-28 16:29:10 -07:00
Ben Barham
d72f5b12c4 Update StringRef::equals references to operator==
`equals` has been deprecated upstream, use `operator==` instead.
2024-06-27 19:14:06 -07:00
Dario Rexin
35b2b71475 Merge pull request #74192 from drexin/wip-typed-throws-abi
[IRGen] Return typed errors directly in synchronous functions when po…
2024-06-22 02:35:10 -07:00
Tim Kientzle
1098054291 Merge branch 'main' into tbkka-assertions2 2024-06-18 17:52:00 -07:00
Dario Rexin
d9bc2cb2fa [IRGen] Return typed errors directly in synchronous functions when possible
rdar://129359355

This PR implements the basic support for returning typed errors directly and applies it to synchronous functions.
2024-06-14 17:20:01 -07:00
Konrad `ktoso` Malawski
2ec717b115 [Concurrency] TaskExecutor ownership fixes (#74000) 2024-06-14 22:56:33 +09:00
Arnold Schwaighofer
19557cd6a2 Merge pull request #74304 from aschwaighofer/use_static_alloca_for_stackAlloc
IRGen: Use static alloca for builtin stackAlloc when possible
2024-06-14 06:54:41 -07:00
Nate Chandler
2d70de8a7f [IRGen] Assert on retaining noncopyable. 2024-06-11 14:46:03 -07:00
Arnold Schwaighofer
89b6f91a9f IRGen: Use static alloca for builtin stackAlloc when possible
rdar://129599643
2024-06-11 12:14:09 -07:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Nate Chandler
2a5d07522d [SIL] Add extend_lifetime instruction.
It indicates that the value's lifetime continues to at least this point.
The boundary formed by all consuming uses together with these
instructions will encompass all uses of the value.
2024-06-05 16:28:26 -07:00
Akira Hatanaka
b5cc5615bd [SILGen] Fix a crash when a closure is converted to a block returning a value indirectly (#73520) 2024-05-23 21:22:32 -07:00
Arnold Schwaighofer
d89bf2893b IRGen: Properly adjust the closure type of a partial_apply of an objc_method
It needs to match with the (large loadable) lowered closure type in the rest of
the program: Large types in the signature need to be passed indirectly.

rdar://127367321
2024-05-22 09:39:15 -07:00
Emil Pedersen
0be63d0422 [DebugInfo] Return complete variable info from getVarInfo by default
getVarInfo() now always returns a variable with a location and scope.
To opt out of this change, getVarInfo(false) returns an incomplete variable.
This can be used to work around bugs, but should only really be used for
printing.

The complete var info will also contain the type, except for debug_values,
as its type depends on another instruction, which may be inconsistent if
called mid-pass.

All locations in debug variables are now also stripped of flags, to avoid
issues when comparing or hashing debug variables.
2024-05-10 16:12:56 -07:00
Emil Pedersen
ce68d74025 Merge pull request #73276 from Snowy1803/doc-and-fixes
[DebugInfo] Improve documentation & Fix discovered bugs
2024-04-29 10:22:46 -07:00
Emil Pedersen
c2c16f53dd [DebugInfo] Fix undef debug values being removed 2024-04-26 16:31:16 -07:00
Arnold Schwaighofer
6794012ea1 IRGen: Fix the load to indirect argument peephole
When the source of the load is a projection we have to bail because the
code later can't handle it.
2024-04-25 15:41:51 -07:00
nate-chandler
c1ecef79dc Merge pull request #73191 from nate-chandler/rdar125265980
[IRGen] Deadends don't need dealloc_pack_metadata.
2024-04-24 16:17:08 -07:00
Nate Chandler
da38fb51fb [IRGen] Deadends don't need dealloc_pack_metadata.
There is a debug-build-only verification that is done for
alloc_pack_metadata instructions that checks that there exist paired
dealloc_pack_metadata instructions which will be keyed off of to clean
up the on-stack variadic metadata packs corresponding to (the
instruction after) the alloc_pack_metadata.

StackNesting omits the deallocation instruction (as does
PackMetadataMarkerInserter) if it would be created in a dead end block.
If all blocks in the dominance frontier of the alloc_pack_metadata
instruction are dead-end blocks, then the verification will incorrectly
fail.  It should not fail because it is not necessary to clean up the
on-stack pack metadata (or any other stack allocations) in such a case.

If all such blocks are dead-end blocks, however, the
alloc_pack_metadata's block itself is a dead-end block as well.  So
during the verification, check whether the alloc_pack_metadata occurs in
a dead-end block and do not fail verification if it does.

rdar://125265980
2024-04-24 07:24:20 -07:00
Arnold Schwaighofer
93f0615555 IRGen: Freeze undef switch, select, cond_br arguments
Let's make `cond_br undef : $Builtin.Int1, then, else` (and the like) a defined
LLVM IR operation with un-specfied behavior.

rdar://126231554
2024-04-12 16:24:43 -07:00
Erik Eckstein
ac4bc89c9a SIL: add the borrowed-from instruction.
It declares from which enclosing values a guaranteed phi argument is borrowed from.
2024-04-10 13:38:10 +02:00
Erik Eckstein
1b1d5ed020 IRGen: support the @sensitive attribute
Call `swift_clearSensitive` after destroying or taking "sensitive" struct types.

Also, support calling C-functions with "sensitive" parameters or return values. In SIL, sensitive types are address-only and so are sensitive parameters/return values.
Though, (small) sensitive C-structs are passed directly to/from C-functions. We need re-abstract such parameter and return values for C-functions.
2024-04-09 12:01:11 +02:00
Arnold Schwaighofer
917ae2d051 LargeTypesReg2Mem: Forward the address of large formally by-val arguments and return values of C functions
rdar://47978338
2024-04-02 13:11:16 -07:00
Anton Korobeynikov
d84847ac9d Reland Allow normal function results of @yield_once coroutines (#71645)
* Allow normal function results of @yield_once coroutines

* Address review comments

* Workaround LLVM coroutine codegen problem: it assumes that unwind path never returns.
This is not true to Swift coroutines as unwind path should end with error result.
2024-03-27 13:09:02 -07:00
Ellie Shin
56d337d322 Merge pull request #72249 from apple/es/pkg-cmo 2024-03-13 09:26:35 -07:00
John McCall
27e0edfacc Merge pull request #72244 from rjmccall/builtin-initial-serial-executor
Add builtin support for starting a task on a specific executor
2024-03-12 18:54:29 -04:00
Ellie Shin
a3250e426d Support Package CMO
* Add a new flag -experimental-package-cmo that requires -experimental-allow-non-resilient-access.
* Support serializing package decls for CMO in package if enabled.
* Only applies to default mode CMO.
* Unlike the existing CMO, package CMO can be built with -enable-library-evolution as package
modules are required to be built together in the same project.
* Create hasPublicOrPackageVisibility to opt in for package decls; needed for CMO, SILVerifier,
and other call sites that verify or determine codegen.

Resolves rdar://121976014
2024-03-12 15:00:24 -07:00
John McCall
0901b2b0b3 Add builtin support for starting a task on a specific executor.
This should be close enough to the creation of this builtin that we don't
need a new feature for it specifically.
2024-03-11 19:44:50 -04:00
Emil Pedersen
8df1abe111 Merge pull request #72158 from Snowy1803/simplify-dbg-type-size
[DebugInfo] Move type size information to CompletedDebugTypeInfo
2024-03-11 10:31:45 -07:00
Nate Chandler
5ccec0e31c [NFC] SIL: Shortened member name.
Renamed "getUsesMoveableValueDebugInfo" to "usesMoveableValueDebugInfo".
Clarifies the predicate from "does the receiver have the
usesMoveableValueDebugInfo field set?" to "does the receiver use moveable
value debug info?".
2024-03-08 21:24:38 -08:00
Emil Pedersen
4ede40e2f7 [DebugInfo] Remove passing of the unused SizeIsFragmentSize (NFC) 2024-03-07 15:21:44 -08:00
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
Pavel Yaskevich
1e06448da7 [IRGen] Distributed: Remove a requirement that accessible function should be backed by SILFunction
Distributed protocol requirements don't have associated SILFunction,
let's introduce a more flexible way to define it that collects only
the information necessary for the function to become accessible.
2024-03-04 15:59:57 -08:00
Adrian Prantl
23e6e54ca1 Merge pull request #71925 from Snowy1803/recursive-sroa
[DebugInfo] Add debug info support for recursive SIL SROA
2024-02-28 20:05:57 -08:00
Emil Pedersen
0faa055c11 [DebugInfo] Add debug info support for recursive SIL SROA
This removes the restriction that only one fragment is allowed at
the end of a SIL DIExpression.

rdar://100046900
2024-02-28 12:48:17 -08:00
Michael Gottesman
11f0ff6e32 [sil] Ensure that all SILValues have a parent function by making it so that SILUndef is uniqued at the function instead of module level.
For years, optimizer engineers have been hitting a common bug caused by passes
assuming all SILValues have a parent function only to be surprised by SILUndef.
Generally we see SILUndef not that often so we see this come up later in
testing. This patch eliminates that problem by making SILUndef uniqued at the
function level instead of the module level. This ensures that it makes sense for
SILUndef to have a parent function, eliminating this possibility since we can
define an API to get its parent function.

rdar://123484595
2024-02-27 13:14:47 -08:00