Commit Graph

74 Commits

Author SHA1 Message Date
Nate Chandler
e59dcd1725 [NFC] IRGen: Vend a FunctionPointer of this helper 2025-10-30 03:59:17 -07:00
Erik Eckstein
db65f2f4e2 IRGen: fix a compiler warning
Move a static inline function into the cpp file.
Fixes
```
warning: unused function 'getCoroFrameAllocStubFn'
```

NFC
2025-04-17 13:01:17 +02: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
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
John McCall
d5142668f4 SIL and IRGen support for @isolated(any). SILGen to come. 2024-02-13 03:04:13 -05:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
Nate Chandler
2d21932672 [Async CC] Add constant "pointer" for async func.
An AsyncFunctionPointer, defined in Task.h, is a struct consisting of
two i32s: (1) the relative address of the async function and (2) the
size of the async context to be allocated when calling that function.

Here, such structs are emitted for every async SILFunction that is
emitted.
2020-11-12 18:20:10 -08: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
Arnold Schwaighofer
6f822a227c IRGen for partial_apply [stack] 2019-01-15 11:20:33 -08:00
Doug Gregor
d457f1c752 [IRGen/SIL] More widespread use of SubstitutionMap. 2018-05-11 13:18:06 -07:00
Joe Shajrawi
62d823c56d Code size: Do not use a global state for isOutlined 2017-11-15 15:28:27 -08:00
John McCall
750d397909 Substantially rework how IRGen handles function pointers.
The goals here are four-fold:
  - provide cleaner internal abstractions
  - avoid IR bloat from extra bitcasts
  - avoid recomputing function-type lowering information
  - allow more information to be propagated from the function
    access site (e.g. class_method) to the call site

Use this framework immediately for class and protocol methods.
2017-07-20 14:33:18 -04:00
Slava Pestov
3519e0cd25 AST: Introduce new SubstitutionList type to replace ArrayRef<Substitution>
SubstitutionList is going to be a more compact representation of
a SubstitutionMap, suitable for inline allocation inside another
object.

For now, it's just a typedef for ArrayRef<Substitution>.
2017-02-06 21:36:33 -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
David Farler
09d0cfee8d Hang closure capture descriptors from their heap metadata
Now we can discern the types of values in heap boxes at runtime!
Closure reference captures are a common way of creating reference
cycles, so this provides some basic infrastructure for detecting those
someday.

A closure capture descriptor has the following:

- The number of captures.
- The number of sources of metadata reachable from the closure.
  This is important for substituting generics at runtime since we
  can't know precisely what will get captured until we observe a
  closure.
- The number of types in the NecessaryBindings structure.
  This is a holding tank in a closure for sources of metadata that
  can't be gotten from the captured values themselves.
- The metadata source map, a list of pairs, for each
  source of metadata for every generic argument needed to perform
  substitution at runtime.
  Key: The typeref for the generic parameter visible from the closure
  in the Swift source.
  Value: The metadata source, which describes how to crawl the heap from
  the closure to get to the metadata for that generic argument.
- A list of typerefs for the captured values themselves.

Follow-up: IRGen tests for various capture scenarios, which will include
MetadataSource encoding tests.

rdar://problem/24989531
2016-04-22 19:09:06 -07:00
John McCall
52cd8718de Split GenFunc.cpp in three: GenFunc for function types and blocks,
GenCall for function signatures, calls, and prologue/epilogue, and
GenBuiltin for builtin operations.

NFC.
2016-04-04 23:52:14 -07:00
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