Commit Graph

542 Commits

Author SHA1 Message Date
Shubham Sandeep Rastogi
17e756ba81 Set debug location to Coroutine call expression
If debug info generation is enabled, set debug location to the
coroutine call instruction to make sure there are no issues with invalid
debug information in LTO.

This happens because in LTO, if a call to a function doesn't contain a
debug location, we see the warning:

inlinable function call in a function with debug info must have a
!dbg location

ld: warning: Invalid debug info found, debug info will be stripped

Which then strips the debug info from the entire .o file linked into the
dylib.
2025-05-13 11:11:38 -07:00
Arnold Schwaighofer
3f8c743aed IRGen: Centralize logic that decides whether the platform suppports typed malloc
NFC intended
2025-04-23 10:43:06 -07:00
Arnold Schwaighofer
5762912af5 Merge pull request #80639 from aschwaighofer/store_once_async_context_addr
IRGen: Don't stored the current async frame to llvm.swift.async.context.addr twice
2025-04-17 08:23:22 -07:00
Andrew Trick
2d9df8ff78 Fix IRGen for @_addressable params which may be "captured".
Simply omit the 'nocapture' attribute on the parameter.

Fixes rdar://148039510 ([nonescapable] IRGen: lower addressable
params to LLVM: captures(ret: address, provenance))
2025-04-10 09:40:19 -07:00
Arnold Schwaighofer
0bb30d6ed3 Fix type continued 2025-04-09 07:26:41 -07:00
Rashmi Mudduluru
5e2f20b2d8 [SUA][IRGen] Add stub for swift_coroFrameAlloc that weakly links against the runtime function (#79889)
* [SUA][IRGen] Add stub for swift_coroFrameAlloc that weakly links against the runtime function

This commit modifies IRGen to emit a stub function `__swift_coroFrameAllocStub` instead of the
newly introduced swift-rt function `swift_coroFrameAlloc`. The stub checks whether the runtime has the symbol
`swift_coroFrameAlloc` and dispatches to it if it exists, uses `malloc` otherwise. This ensures the
ability to back deploy the feature to older OS targets.

rdar://145239850
2025-04-08 09:58:24 -07:00
Arnold Schwaighofer
50ebb3f579 IRGen: Don't stored the current async frame to llvm.swift.async.context.addr twice
rdar://148826951
2025-04-08 08:12:07 -07:00
Nate Chandler
24bb9bb738 [CoroutineAccessors] Adopt swiftcoro param attr. 2025-03-28 17:10:53 -07:00
Nate Chandler
b38d3eee58 [CoroutineAccessors] Use SwiftCC'd malloc/free.
Calls to the allocation functions use the same convention regardless of
which function, so if the functino being called is malloc and free,
provide a thunk with the appropriate convention.
2025-03-27 19:23:09 -07:00
Nate Chandler
c141586838 [CoroutineAccessors] Open code dealloc fn. 2025-03-27 19:23:09 -07:00
Nate Chandler
dd238343bb [CoroutineAccessors] Open code alloc fn.
Replace the runtime function with an open-coded version.
2025-03-27 19:23:09 -07:00
nate-chandler
b878155a5a Merge pull request #80335 from nate-chandler/general-coro/20250326/2
[CoroutineAccessors] Move functions and add dealloc bit.
2025-03-27 19:19:25 -07:00
Dario Rexin
b7943bb849 Merge pull request #80287 from drexin/wip-147872231
[IRGen] Map result to native representation in emitAsyncReturn
2025-03-27 13:02:07 -07:00
Nate Chandler
2412ac3dc4 [CoroutineAccessors] Dedicate bit to dealloc time.
Don't rely on the kind for this.  Allow each allocator to decide for
itself for future compatibility.
2025-03-27 11:37:26 -07:00
Nate Chandler
dbcd038959 [CoroutineAccessors] Add wrapper for dealloc.
Make the fast path faster by avoiding a dyld stub.
2025-03-27 11:37:26 -07:00
Nate Chandler
0c2a38b10b [CoroutineAccessors] Directly reference allocators
Replace the call to a runtime function that looks up the allocator with
a direct reference to a just-emittedd sought-after global allocator.
2025-03-26 08:35:35 -07:00
Dario Rexin
287e7791a0 [IRGen] Map result to native representation in emitAsyncReturn
rdar://147872231

When an async typed throwing function had a result type that combined multiple fields into a single register, we created invalid IR, that could lead to compiler crashes or in some cases even miscompiles. With this fix we are mapping the result to the native representation before mapping it to the combined result type.
2025-03-25 14:36:26 -07:00
Nate Chandler
32779713a8 [CoroutineAccessors] Adopt ret.popless intrinsic.
And annotate it musttail.
2025-03-07 20:09:54 -08:00
Nate Chandler
35d06c325d [CoroutineAccessors] Witness and vtable dispatch.
And thunking.
2025-03-07 11:46:50 -08:00
Nate Chandler
f5d03a6d11 [CoroutineAccessor] Remove old ABI support.
This was useful during bringup.  Now that retcon.once.dynamic coroutine
splitting is available, it's no longer needed.
2025-03-07 11:40:38 -08:00
Nate Chandler
d1f1b4c86b [CoroutineAccessors] Use swiftcorocc if available.
When it's available, use an open-coded allocator function that returns
an alloca without popping if the allocator is nullptr and otherwise
calls swift_coro_alloc.  When it's not available, use the malloc
allocator in the synchronous context.
2025-02-27 18:20:53 -08:00
Nate Chandler
dd8cbe3e0a [CoroutineAccessors] Use retcon.once variant.
Allocate a coroutine frame in the caller based on the size in the
corresponding "function pointer" and pass it along with an allocator to
the callee.
2025-02-27 07:53:58 -08:00
Nate Chandler
256d46a369 [NFC] IRGen: Delete another dead param. 2025-02-27 07:53:12 -08:00
Nate Chandler
32f9e8db5d [NFC] IRGen: Delete dead param. 2025-02-27 07:53:12 -08:00
Rashmi Mudduluru
0b8efc9f26 [SUA][IRGen] Change IRGen to emit calls to swift_coroFrameAlloc (#79384)
When TMO is enabled, change IRGen to pass the newly introduced runtime function `swift_coroFrameAlloc` (and pass an additional argument — the hash value) instead of `malloc` when it inserts calls to `coro_id_retcon_once`.
The hashValue is computed based on the  current function name (computed in `getDiscriminatorForString`)

rdar://141235957
2025-02-21 14:45:23 -08:00
Dario Rexin
40cdd36e6a [IRGen] Remove code duplication in CallEmission::emitToUnmappedExplosionWithDirectTypedError 2025-02-14 11:54:25 -08:00
Dario Rexin
401cd64a61 [IRGen] Apply correct type to conversion for direct values and erorrs with typed throws
rdar://144719032

When converting the combined result back to the actual types when directly returning typed errors, in case
the error or result value was a single value smaller then pointer size and the combined value was larger,
the value was converted to the combined type instead of the actual type, making it a no-op, which caused
undefined behavior when writing the value to the coerced alloca.
2025-02-13 12:53:12 -08:00
Anthony Latsis
a84dfc8387 [Gardening] Fix some set but not used variables 2025-01-30 21:34:38 +00:00
Saleem Abdulrasool
bac1554b43 IRGen: correct some invalid code
`[[fallthrough]]` must be followed by a `case` label. The current use in
IRGen did not follow this requirement. Adjust the logic to match the
requirement. This fixes a few diagnostics that MSVC emitted for this
error.
2025-01-27 11:10:41 -08:00
Becca Royal-Gordon
ebea19d7b9 Merge pull request #78697 from beccadax/rdar142693093
Work around Foundation NS_TYPED_ENUM bug
2025-01-22 00:57:41 -08:00
Becca Royal-Gordon
0ce403d680 [NFC] Add some pretty stack traces
These would have helped us to debug rdar://142693093 more quickly.
2025-01-21 17:33:09 -08:00
Dario Rexin
30e7ba13b2 [IRGen] Add indirect typed error slot when async function has indirect result
rdar://142918657

Erorrs have to be passed indirectly whenever the result type is indirect.
2025-01-16 15:29:13 -08:00
Dario Rexin
0aebbeada8 [IRGen] Fix SignatureExpansion::expandAsyncReturnType()
rdar://141962253

This fixes an issue that caused parameters to be dropped when a typed error in an async closure was too big to be returned directly.
2025-01-06 12:21:51 -08:00
Dario Rexin
38e36784d0 [IRGen] Check if type is empty instead of void in CallEmission::emitToUnmappedExplosionWithDirectTypedError
rdar://140573912

This caused assertions to fail when using other empty types, like `Never` as the result type on typed throwing functions.
2024-12-04 13:57:48 -10:00
Kuba Mracek
6f4ae28520 [ASTMangler] Pass ASTContext to all instantiations of ASTMangler 2024-12-02 15:01:04 -08:00
Dario Rexin
03c3d985aa [IRGen] Assign error flag after calling direct error returning async typed throws function 2024-11-07 10:22:54 -08:00
Dario Rexin
26521cd165 [IRGen] Properly handle empty results in direct error return in emitAsyncReturn
When the result is empty, but the error type is not, we have to return an `undef` for the result.
2024-11-07 10:22:53 -08:00
Dario Rexin
ffd9f205b3 [IRGen] Re-introduce typed throws ABI
rdar://135954459
2024-11-07 10:22:49 -08:00
Arnold Schwaighofer
5f396cd13c IRGen: Add indirect peepholes for arguments and return value coercion
Large tuples of values (e.g char[32]) can be passed directly at the abi
boundry but expand to a big explosion of values.

Peephole this explosion at argument passing and return value passing
points to avoid code size growth associated with the explosion.
2024-10-31 13:02:07 -07:00
Ben Barham
f59b2f19e6 Merge branch 'main' into 2024-rebranch-to-main 2024-10-28 13:03:35 -07:00
Hiroshi Yamauchi
fcc1f6b65e Fix the IR gen for C++ method calls and refactor around CGFunctionInfo
In GenCall, fix the IR gen for C++ method calls as under MSVC as the
calling conventions for free functions and C++ methods can be
different. This also fixes the missing inreg (on sret arguments)
issues on Windows ARM64. Also refactor to use CGFunctionInfo
returnInfo isSretAfterThis to detect when to reorder the sret and the
this arguments under MSVC.

In ClagImporter, don't drop the return type for the compound
assignment operators such as operator+= when the return value is a
reference so that the CGFunctionInfo will be correctly indicate an
indirect return for the compound assignment operators.
2024-10-24 15:40:21 -07:00
swift-ci
ffb7eef5ab Merge remote-tracking branch 'origin/main' into rebranch 2024-10-17 05:15:25 -07:00
Arnold Schwaighofer
8ebb3ec473 IRGen: Add the ability to mark certain generic entry points in back traces
Mark generic function calls with concrete parameters, generic v-table calls and
generic witness table calls where self is generic.
2024-10-14 14:06:10 -07:00
swift-ci
8a2edbc4c5 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-11 17:05:06 -07:00
Nate Chandler
71239d6357 [CoroutineAccessors] SIL represents callee alloc.
When its operand has coroutine kind `yield_once_2`, a `begin_apply`
instruction produces an additional value representing the storage
allocated by the callee.  This storage must be deallocated by a
`dealloc_stack` on every path out of the function.  Like any other stack
allocation, it must obey stack discipline.
2024-10-11 08:25:03 -07:00
Nate Chandler
49a2831d3f [CoroutineAccessors] Old ABI may be used via flag.
Add a setting to IRGenOptions and key off of it to emit yield_once_2
coroutines using either (1) the same code-path as yield_once coroutines
or (2) a new, not-yet implemented code-path.

Add flags to set the value in both directions.  During bringup, by
default, use the existing caller-allocated ABI.
2024-10-11 08:25:02 -07:00
Nate Chandler
df1c4f6b25 [CoroutineAccessors] Add new SILFnTy CoroKind.
For `modify` and `read` coroutines, produce SILFunctionType's whose
coroutineKind is ::YieldOnce2.
2024-10-11 08:25:02 -07:00
Ben Barham
a7b50f357f Merge remote-tracking branch 'origin/main' into manual-main-merge
Conflicts:
  - `lib/Driver/ToolChains.cpp` conflicting with the `addAllArgs` rename
    for multiple options
2024-09-16 13:53:18 -07:00
Felipe de Azevedo Piovezan
58bbadd28e [DebugInfo] Dont generate line information at the split point of async funclets
Unless there is some meaningful code on the same line as an await call (e.g.
other parts of an expression), there should be no additional line entries
associated with that line on the continuation funclet.

This patch changes codegen to avoid emitting debug location for the "prologue" code
at the start of a funclet, instead of simply copying the debug location of the
split point.
2024-09-13 19:06:56 -07:00
Arnold Schwaighofer
8e9cd5db68 Merge pull request #76150 from aschwaighofer/async_entry_ret_metadata
IRGen: Add metadata for async funclets denoting frame entry and frame exists
2024-09-13 11:52:00 -07:00