Commit Graph

1696 Commits

Author SHA1 Message Date
nate-chandler
c0fa16e7be Merge pull request #68000 from nate-chandler/cherrypick/main/rdar114013709
[IRGen] Cast fixed-size opaque globals.
2023-08-18 06:59:30 -07:00
Nate Chandler
9981a82d01 [IRGen] Cast fixed-size opaque globals.
In https://github.com/apple/swift/pull/66560 , a bug in the lowering of
`global_addr` was fixed.  Part of that fix was to postpone mapping the
type of the global into context until getting the address of the global
and projecting the buffer for the out-of-line value; at that point, the
type is mapped into context and the address is cast.

It introduced an issue for fixed-size globals, however: the type of such
globals was not mapped into context; the result was that the lowered
value set for the corresponding SIL value would have the wrong type.

Fix that by extracting the code which mapped the type into context and
cast the address to the appropriate lowered type into a lambda and call
that lambda both in both the fixed-size (newly) and non-fixed-size (as
before) cases.

rdar://114013709
2023-08-17 17:23:02 -07:00
swift-ci
9d38c6b53e Merge remote-tracking branch 'origin/main' into rebranch 2023-08-17 14:34:52 -07:00
nate-chandler
8cab09e429 Merge pull request #67966 from nate-chandler/opaque-values/20230816/1/indirect-pack-tuple-handling
[AddressLowering] Handle indexing into variadic tuples.
2023-08-17 14:20:44 -07:00
swift-ci
56b676b5e1 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-17 07:14:15 -07:00
Felipe de Azevedo Piovezan
cb4aeefe64 Merge pull request #67911 from felipepiovezan/felipe/delete_dead_code
[IRGen] Delete no-op code
2023-08-17 10:01:20 -04:00
Nate Chandler
7bddaf36a0 [SIL] Added tuple_pack_extract.
The new instruction is needed for opaque values mode to allow values to
be extracted from tuples containing packs which will appear for example
as function arguments.
2023-08-16 11:15:05 -07:00
swift-ci
460699a165 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-15 19:14:21 -07:00
Meghana Gupta
672565749c Generate appropriate LLVM IR attributes for custom optimization modes set on a SILFunction 2023-08-15 15:45:54 -07:00
Felipe de Azevedo Piovezan
af6599ff31 [IRGen] Delete no-op code
Commit 5c3ccf5050 added a number of blocks of code which were partially
removed by 39af79f491. This partial remove left lines of code doing nothin; we
remove them here.
2023-08-14 10:02:22 -04:00
swift-ci
a4bb99bd1b Merge remote-tracking branch 'origin/main' into rebranch 2023-08-09 07:15:49 -07:00
Nate Chandler
f938287710 [SIL] Added unowned_copy_value. 2023-08-08 15:49:17 -07:00
Nate Chandler
c007bae723 [SIL] Added weak_copy_value.
The new instruction wraps a value in a `@sil_weak` box and produces an
owned value. It is only legal in opaque values mode and is transformed
by `AddressLowering` to `store_weak`.
2023-08-08 15:47:13 -07:00
Nate Chandler
e135c5cac7 [SIL] Added strong_copy_weak_value.
The new instruction unwraps an `@sil_weak` box and produces an owned
value. It is only legal in opaque values mode and is transformed by
`AddressLowering` to `load_weak`.
2023-08-08 15:47:13 -07:00
swift-ci
ae4b70bf28 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-04 18:59:37 -07:00
Slava Pestov
9ebb5f2e03 AST: Rename VarDecl::getType() to VarDecl::getTypeInContext()
This is a futile attempt to discourage future use of getType() by
giving it a "scary" name.

We want people to use getInterfaceType() like with the other decl kinds.
2023-08-04 14:19:25 -04:00
Ben Barham
b134541111 [rebranch] Fix API changes from LLVM update
`insert` inserts *before* the given iterator. The `insertAfter` calls
thus need a `std::next` when converted to `insert`.

Resolves rdar://113145355.
2023-08-01 13:10:33 -07:00
Evan Wilde
f5cd20c34a llvm::Function basic block list fix
`llvm::Function` hid the basic block list. Making adjustments for
splicing and appending.
2023-07-25 12:28:28 -07:00
Nate Chandler
3f069df550 [IRGen] Add metadata pack markers for destroys.
Destroys of values whose types feature a pack may require allocating the
pack on-stack.

Thanks to @slavapestov for the test case.

rdar://112792831
2023-07-24 14:19:24 -07:00
Meghana Gupta
5c743650ec Merge pull request #66995 from meg-gupta/removeselectmixin
Simplify select_enum forwarding instruction
2023-06-29 09:52:49 -07:00
Erik Eckstein
e77e2bcff7 IRGen: don't initialize the object headers of bare objects
For `alloc_ref [bare] [stack]` and `global_value [bare]` omit the object header initialization.
The `bare` flag means that the object header is not used.

This was already done with a peephole optimization inside IRGen for `global_value`. But now rely on the SIL `bare` flag.
2023-06-29 06:57:05 +02:00
Meghana Gupta
c8001d86b1 Add a wrapper type SelectEnumOperation
SelectEnumInstBase will be templated in the next commit.
Instead of using templated SelectEnumInstBase everywhere, introduce
a new wrapper type SelectEnumOperation.
2023-06-28 14:29:10 -07:00
Evan Wilde
250082df25 [NFC] Reformat all the LLVMs
Reformatting everything now that we have `llvm` namespaces. I've
separated this from the main commit to help manage merge-conflicts and
for making it a bit easier to read the mega-patch.
2023-06-27 09:03:52 -07: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
Meghana Gupta
03b8c49371 Merge pull request #66645 from meg-gupta/mixinremovesmall
Simplify forwarding instruction definitions in SIL
2023-06-21 13:02:13 -07:00
Meghana Gupta
16c300c2af Remove OwnershipForwardingConversionInst, ConversionInst.
Add new ConversionOperation abstraction, use this in place of ConversionInst
2023-06-15 10:53:28 -07:00
Arnold Schwaighofer
0d4dec1acb Attempt to fix debug info under opaque pointers
Based on https://github.com/apple/swift/pull/66409

With the observation that the pre-opaque world was using bitcast as an
indication that the storage type and the type of the variable were
different. We can recover this information from the storage type of the
alloca and the storage type of the type info.
2023-06-14 10:49:50 -07:00
Meghana Gupta
5d401fb70a Remove select_value SIL instruction 2023-06-13 14:13:43 -07:00
Arnold Schwaighofer
b6e9c8e51c IRGen: alloc_global and global_addr instructions need to agree on the storage
If the storage is opaque we need to project to the underlying buffer.

rdar://109636344
2023-06-09 11:37:50 -07:00
Alex Lorenz
138def7627 Merge pull request #65922 from hyp/eng/excp-cons-spec
[cxx-interop] evaluate default constructor's unevaluated exception sp…
2023-06-08 15:35:23 -07:00
Alex Lorenz
b0dab0b48c [cxx-interop] evaluate default constructor's unevaluated exception spec if needed when emitting C++ constructor call
Fixes https://github.com/apple/swift/issues/65891
2023-06-08 11:02:29 -07:00
Holly Borla
ac66a06199 [SIL] Add a new AssignOrInit instruction for init accessors.
This instruction is similar to AssignByWrapperInst, but instead of having
a destination operand, the initialization is fully factored into the init
function operand. Like AssignByWrapper, AssignOrInit has partial application
operands of both the initializer and the setter, and DI will lower the
instruction to a call based on whether the assignment is initialization or
a setter call.
2023-06-06 18:59:10 -07:00
Michael Gottesman
29672c503a Merge pull request #66381 from gottesmm/noimplicitcopy-borrow-consuming
[borrowing/consuming] Make borrowing and consuming parameters no implicit copy.
2023-06-06 21:41:18 -04:00
Andrew Trick
4325c0ae0b Merge pull request #66314 from atrick/fix-dropdeinit
[move-only] Fix SIL representation and SILOptimizer to preserve value deinits
2023-06-06 12:09:34 -07:00
Michael Gottesman
70ab38d9da [move-only] Add a new instruction: moveonlywrapper_to_copyable_box.
I am going to use this to unwrap ${ @moveOnly T } so that I can pass it to
partial_apply that expect a ${ T }
2023-06-06 14:26:22 -04:00
Alastair Houghton
d3d345bb23 Merge pull request #66333 from al45tair/eng/PR-110260855
[Backtracing][IRGen] Add a semantic attribute to force frame pointer.
2023-06-06 17:51:20 +01:00
Michael Gottesman
611e6760f5 [borrowing/consuming] Add a new instruction called copyable_to_moveonlywrapper_addr.
Just the $*T -> $*@moveOnly T variant for addresses. Unlike the object version
this acts like a cast rather than something that provides semantics from the
frontend to the optimizer.
2023-06-06 12:42:23 -04:00
Michael Gottesman
43f42e2c04 [borrowing/consuming] Add new instruction: moveonlywrapper_to_copyable_addr.
The reason why I am using a different instruction for addresses and objects here
is that the object checker doesnt have to deal with things like initialization.
2023-06-06 12:42:23 -04:00
Andrew Trick
521f0ffc9e [move-only] Verify drop_deinit
drop_deinit only exists in ownership SIL. Remove IRGen support.

A drop_deinit can only ever be destroyed or destructured.

A destructure of a struct-with-deinit requires a drop_deinit operand.
2023-06-06 09:17:53 -07:00
Nate Chandler
2af114cf17 [IRGen] NFC: Assert cleanups for metadata emits.
In debug builds, before SIL function emission, pass over the function to
collect cleanups.  After emitting an instruction for which an on-stack
metadata/wtable pack was emitted, assert that there were cleanups for
it in the function.
2023-06-05 08:11:28 -07:00
Nate Chandler
d1ec1e6693 [IRGen] Dealloc metadata packs on dom frontier.
Deallocate dynamic allocas done for metadata/wtable packs.  These
stackrestore calls are inserted on the dominance frontier and then stack
nesting is fixed up.  That was achieved as follows:

Added a new IRGen pass PackMetadataMarkerInserter; it
- determines if there are any instructions which might allocate on-stack
  pack metadata
- if there aren't, no changes are made
- if there are, alloc_pack_metadata just before instructions that could
  allocate pack metadata on the stack and dealloc_pack_metadata on the
  dominance frontier of those instructions
- fixup stack nesting

During IRGen, the allocations done for metadata/wtable packs are
recorded and IRGenSILFunction associates them with the instruction that
lowered.  It must be the instruction after some alloc_pack_metadata
instruction.  Then, when visiting the dealloc_pack_metadata instructions
corresponding to that alloc_pack_metadata, deallocate those packs.
2023-06-05 08:11:28 -07:00
Nate Chandler
172be49bcc [IRGen] Disable on-stack pack metadata via attr.
When lowering a SIL function, if it bears the no_onstack_pack_metadata
annotation, disable on-stack pack metadata.
2023-06-05 08:11:28 -07:00
Nate Chandler
efca4e57c8 [SIL] Added on-stack pack metadata marker insts.
The new alloc_pack_metadata and dealloc_pack_metadata are inserted as
part of IRGen lowering.  The former indicates that the next instruction
might result in on-stack pack metadata being emitted.  The latter
indicates that this is the position at which metadata emitted on behalf
of its operand should be cleaned up.
2023-06-05 08:11:28 -07:00
Alastair Houghton
f8fe8b1ecc [Backtracing][IRGen] Add a semantic attribute to force frame pointer.
The Swift backtracer's frame pointer unwinder cannot work on Linux
without this change, because the compiler omits the frame pointer from
the function in libSwift_Backtracing that actually captures the stack.

rdar://110260855
2023-06-05 15:18:22 +01: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
Erik Eckstein
24837b4d10 IRGen: change a few enum utility functions to be able to create enums in static initializers
Instead of passing `IRGenFunction`, pass the `IRGenModule` and the `IRBuilder`.
This makes enum creation not dependent on the presence of a function.

NFC, just refactoring.
2023-05-25 16:28:41 +02:00
Erik Eckstein
54aacf64e1 SIL: don't allow upcast to be done on address types
It's not needed and just complicates the SIL
2023-05-22 15:34:26 +02:00
Arnold Schwaighofer
218e4f9f7c IRGen: Fix lowering of static async function pointers under opaque-pointers
Read the pointer type off the signature rather than the global value
2023-05-08 07:59:30 -07:00
Adrian Prantl
85dcd50605 Emit debug info for count arguments of variadic generic types.
rdar://107491524
2023-05-02 17:35:28 -07:00
Erik Eckstein
7d70a70acf SIL: add the drop_deinit instruction
his instruction is a marker for a following destroy instruction to suppress the call of the move-only type's deinitializer.
2023-04-11 10:25:48 +02:00