Commit Graph

2610 Commits

Author SHA1 Message Date
Emil Pedersen
a31d15c438 Merge pull request #72964 from Snowy1803/mem2reg-salvage-store
[DebugInfo] Salvage all stores
2024-04-25 16:52:37 -07:00
Emil Pedersen
450db6e530 [DebugInfo] Add special cases for copy forwarding 2024-04-24 18:23:39 -07:00
Nate Chandler
7fd4311d7d [SIL] Verify complete lifetimes when option set.
Only pass DeadEndBlocks to verifyOwnership if OSSAVerifyComplete is not
set.  The verifier keys off of the nullness of DeadEndBlocks to decide
whether to verify complete lifetimes or not.
2024-04-24 12:59:45 -07:00
Emil Pedersen
523a769e34 [DebugInfo] [Mem2Reg] Move debug info promotion to salvageDebugInfo 2024-04-23 13:12:21 -07:00
Adrian Prantl
6357d12cfc Merge pull request #73009 from Snowy1803/debuginfo-small-fixes
[Debuginfo] Small fixes
2024-04-17 00:03:53 +02:00
Emil Pedersen
fac61c5e55 [DebugInfo] [SILSROA] Fix variable scope in some cases
SILBuilderWithScope ignores the scope of the debug value and uses the
scope of the next real instruction. We want to preserve the scope
of the original debug value, so we pass it explicitly.
2024-04-16 10:28:13 -07:00
Erik Eckstein
e14c1d1f62 SIL, Optimizer: update and handle borrowed-from instructions
Compute, update and handle borrowed-from instruction in various utilities and passes.
Also, used borrowed-from to simplify `gatherBorrowIntroducers` and `gatherEnclosingValues`.
Replace those utilities by `Value.getBorrowIntroducers` and `Value.getEnclosingValues`, which return a lazily computed Sequence of borrowed/enclosing values.
2024-04-10 13:38:10 +02:00
Erik Eckstein
44f4ea9099 DeadCodeElimination: fix debug logging of to-instruction when adding a reverse dependency 2024-04-10 13:38:10 +02:00
Meghana Gupta
2ef1aa5525 Merge pull request #72792 from meg-gupta/improvephireplace
Update SimplifyCFG's replacement of phi with its incoming value
2024-04-03 16:05:02 -07:00
Meghana Gupta
5bfa560b35 Update SimplifyCFG's replacement of phi with its incoming value
Previously we replaced phi with its incoming values when all incoming values were the same.
If the phi had itself as incoming value, it wasn't optimized. This PR handles such cases.
2024-04-03 10:46:05 -07:00
Emil Pedersen
e8ce02e0a3 [DebugInfo] Salvage debug info for allocations in SILSROA 2024-04-02 11:34:23 -07:00
Alejandro Alonso
36bf2ae3bf Merge pull request #72592 from Azoy/raw-layout-inst
[IRGen] Add Builtin.addressOfRawLayout
2024-03-29 07:38:37 -07:00
Alejandro Alonso
f5e10e2c0b Get rid of sil instruction and use a builtin for addressOfRawLayout 2024-03-27 11:36:29 -07:00
Emil Pedersen
4c8beefff4 [DebugInfo] Salvage debug info for stores removed by DeadObject-Elim
rdar://124283055
2024-03-26 10:02:34 -07:00
Erik Eckstein
a5320a6fcd EagerSpecializer: fix a SIL verifier crash
When inserting type checks for pre-specialized functions, the existing return-block can only be re-used if it has no arguments.
Otherwise we are creating an argument-less branch to a block with arguments.

rdar://124638266
2024-03-19 12:28:33 +01:00
Kuba Mracek
f5797941b7 [embedded] Specialize superclasses in VTableSpecializer as part of MandatoryPerformanceOptimizations 2024-03-15 21:30:08 -07:00
Ben Barham
9779c18da3 Rename startswith to starts_with
LLVM is presumably moving towards `std::string_view` -
`StringRef::startswith` is deprecated on tip. `SmallString::startswith`
was just renamed there (maybe with some small deprecation inbetween, but
if so, we've missed it).

The `SmallString::startswith` references were moved to
`.str().starts_with()`, rather than adding the `starts_with` on
`stable/20230725` as we only had a few of them. Open to switching that
over if anyone feels strongly though.
2024-03-13 22:25:47 -07:00
Meghana Gupta
2d27ec581c Merge pull request #72267 from meg-gupta/enablesilcombineempty
Enable SILCombine of inject_enum_addr for empty types
2024-03-12 20:34:09 -07:00
Alejandro Alonso
6e9e9c4ca7 Merge pull request #72086 from Azoy/kill-dead-atomics
[DeadObjectElimination] Zero init is not a barrier
2024-03-12 14:39:56 -07:00
Meghana Gupta
50f0fd232c Enable SILCombine of inject_enum_addr for empty types 2024-03-12 13:01:44 -07:00
Nate Chandler
08a832b803 [AllocBoxToStack] Transfer var_decl flag.
As with the lexical flag, when creating an alloc_stack corresponding to
an alloc_box, transfer the var_decl flag from any begin_borrow users of
the box.
2024-03-08 22:28:22 -08:00
Nate Chandler
3dbeebaa9b [SIL] Add var_decl flag to alloc_stack. 2024-03-08 22:28:22 -08:00
Nate Chandler
7db84f25b1 [NFC] SIL: Typed move_value's isLexical. 2024-03-08 22:27:52 -08:00
Nate Chandler
9f6c30919b [NFC] SIL: Typed begin_borrow's isLexical. 2024-03-08 22:27:50 -08:00
Nate Chandler
c6eb3112b5 [NFC] SIL: Typed alloc_stack's isLexical. 2024-03-08 21:24:39 -08:00
Nate Chandler
ec6b447b68 [NFC] SIL: Typed alloc_box's hasDynamicLifetime. 2024-03-08 21:24:39 -08:00
Nate Chandler
dfa5c9814b [NFC] SIL: Typed alloc_stack's hasDynamicLifetime. 2024-03-08 21:24:39 -08:00
Nate Chandler
611511a71f [NFC] SIL: Typed alloc_stack's wasMoved.
Help avoid errors with boolean flags by introducing
UsesMoveableValueDebugInfo_t.
2024-03-08 21:24:39 -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
Emil Pedersen
7c9a8769a1 Merge pull request #72072 from Snowy1803/tuple-fragments
Add support for op_tuple_fragment in SIL DIExpression and SIL SROA
2024-03-06 15:20:08 -08:00
Erik Eckstein
ad3178a403 CSE: fix checking convention of tuple apply results
We didn't catch the case where a function returns a tuple where at least one of the tuple elements is returned as `owned`.
In such a case the apply must not be cse'd.

Fixes a miscompile which results in an over-release.
rdar://121597250
2024-03-06 11:07:56 +01:00
Alejandro Alonso
135533e205 Zero init is not a barrier for DOE 2024-03-04 23:17:32 -08:00
Emil Pedersen
35e346fd8d Add support for op_tuple_fragment in SIL DIExpression and SIL SROA
rdar://124034536
2024-03-04 15:46:02 -08:00
Erik Eckstein
f8640e6ba6 CSE: visit uses of block arguments when replacing an open_existental_ref
Fixes a verifier crash.

rdar://122190393
2024-03-04 23:05:33 +01:00
Michael Gottesman
3236bc26fa [region-isolation] Refactor out the stubify dead function if no longer used functionality from move only checker into its own pass and put it before region based isolation.
I am doing this since region based isolation hit the same issue that the move
checker did. So it makes sense to refactor the functionality into its own pass
and move it into a helper pass that runs before both.

It is very conservative and only stubifies functions that the specialization
passes explicitly mark as this being ok to be done to.
2024-03-01 13:11:07 -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
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
71fcae7fe8 SwiftCompilerSources: add the ability to implement SIL verification in swift 2024-02-22 07:12:10 +01:00
Ben Barham
5637284e48 Merge pull request #71368 from bnbarham/std-optional-all-the-things
Migrate llvm::Optional to std::optional
2024-02-21 16:54:00 -08: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
Nate Chandler
5a6873b98f [SILOptimizer] Remove DestroyHoisting pass.
It's no longer used.
2024-02-19 11:41:38 -08:00
Erik Eckstein
0dc7dd5d71 VTableSpecializer: make sure to specialize tables of superclasses
Fixes an IRGen crash if a superclass of a class is generic and not used otherwise.

rdar://122405558
2024-02-14 09:51:42 +01:00
John McCall
b23bc82cdb Merge pull request #71574 from rjmccall/isolation-any-sil-irgen
SIL and IRGen support for `@isolated(any)` function types
2024-02-13 11:57:16 -05:00
Joe Groff
2170b4e725 Merge pull request #71489 from jckarter/borrowing-switch-8
MoveOnlyAddressUtils: Fixes for borrowing switch over address-only types.
2024-02-13 07:51:40 -08:00
John McCall
d5142668f4 SIL and IRGen support for @isolated(any). SILGen to come. 2024-02-13 03:04:13 -05:00
Joe Groff
0365c6abba MoveOnlyAddressUtils: Fixes for borrowing switch over address-only types.
Relax some existing pattern matches and add some unhandled instructions to the
walkers so that borrowing switches over address-only enums are properly analyzed
for incorrect consumption. Add a `[strict]` flag to `mark_unresolved_move_only_value`
to indicate a borrow access that should remain a borrow access even if the subject
is later stack-promoted from a box.
2024-02-12 20:20:50 -08:00
nate-chandler
85437a22bc Merge pull request #71521 from nate-chandler/rdar122417297
[Mem2Reg] When materializing an empty type projected from a non-empty aggregate, populate the non-empty fields of the aggregate with undef.
2024-02-12 06:55:38 -08:00
Nate Chandler
b4e336ebdb [Mem2Reg] Undef types in empty projection sources.
Mem2Reg may materialize the unique instance of empty types when
promoting an address of that empty type.  Previously, it was required
that the top-most type in the aggregate be empty.  This failed to handle
the case where a projection of empty type from a non-empty aggregate was
promoted.

For example:

```
%addr = alloc_stack $((), C)
%empty_addr = tuple_element_addr $addr : $*((), C), 0
%addr = load %empty_addr : $*()
```

where `C` is some non-empty type.

Here, that case is handled by using `undef` for each non-empty field in
the projected-from aggregate.

In the example,

```
%empty = tuple ()
%tuple = tuple (%empty : $(), undef : $C)
%empty_again = tuple_extract %tuple : $((), C), 0
```

rdar://122417297
2024-02-09 13:54:14 -08:00
Andrew Trick
da3f583492 Add mark_dependence [unresolved]
In preparation for inserting mark_dependence instructions for lifetime
dependencies early, immediately after SILGen. That will simplify the
implementation of borrowed arguments.

Marking them unresolved is needed to make OSSA verification
conservative until lifetime dependence diagnostics runs.
2024-02-08 22:53:16 -08:00
Kuba Mracek
d9624abc81 [embedded] Print function name + class name when missing loc in 'non-final generic fuctions' diagnostic 2024-02-06 11:20:25 -08:00