Andrew Trick
801c192af1
SwiftCompilerSources: fix EndApplyInst to be SingleValueInstruction.
...
To be consistent with the C++ implementation.
2024-11-18 01:37:00 -08:00
Andrew Trick
b5bef612ed
SwiftCompilerSources: fix BeginApply.endOperands()/endInstructions()
...
Only return the EndApplyInst and AbortApplyInst uses.
2024-11-18 01:37:00 -08:00
Andrew Trick
3e26cf81d0
SwiftCompilerSources: bridge createEndApply and createAbortApply.
2024-11-18 01:37:00 -08:00
Erik Eckstein
cea7da8d26
RedundantLoadElimination: correctly handle end_borrow instructions
...
Scope-ending instructions, like `end_borrow` are only irrelevant for RLE if the preceding load is not changed.
If it is changed from `load [copy]` -> `load [take]` the memory effects of those scope-ending instructions prevent that the `load [take]` will illegally mutate memory which is protected from mutation by the scope.
Fixes a memory verifier crash
rdar://139824805
2024-11-14 18:25:11 +01:00
Erik Eckstein
99ef6f727d
Optimizer: replace unchecked_enum_data simplification in SILCombine with the corresponding instruction simplification from SwiftCompilerSources
...
The optimization in SILCombine had a bug (which is already fixed in the instruction simplification).
2024-11-14 09:18:29 +01:00
Erik Eckstein
2519c343e6
Optimizer: fix simplification of unchecked_enum_data
...
When replacing an `enum` - `unchecked_enum_data` pair and the enum's operand is another non-trivial enum which is constructed with a trivial payload, and this happens in different basic blocks, we need to insert a compensating `destroy_value`.
Fixes a verifier crash
rdar://139787167
2024-11-14 07:21:10 +01:00
Erik Eckstein
75e75831f2
AliasAnalysis: fix the memory behavior of end_borrow
...
Checking if an access base is derived from a begin-borrow was too optimistic.
We have to bail for instructions which are not handled by the walker utilities.
Fixes a verifier crash.
rdar://139788357
2024-11-13 17:44:01 +01:00
eeckstein
53f772cd43
Merge pull request #77582 from eeckstein/fix-comment
...
GuaranteedPhiUpdater: fix a comment
2024-11-13 14:44:47 +01:00
Andrew Trick
eb8d9f4960
Merge pull request #77575 from atrick/preserve_extend_lifetime
...
Preserve extend_lifetime during dead instruction code elimination.
2024-11-13 05:22:30 -08:00
Erik Eckstein
2182f44d54
GuaranteedPhiUpdater: fix a comment
2024-11-13 10:49:58 +01:00
Andrew Trick
c5ab1287f3
Preserve extend_lifetime during dead instruction code elimination.
2024-11-12 23:53:56 -08:00
Erik Eckstein
51e3e5ed80
Optimizer: rename BorrowArgumentsUpdater -> GuaranteedPhiUpdater
...
NFC
2024-11-12 09:26:59 +01:00
Erik Eckstein
68d0f6120a
SIL Verifier: verify the re-borrow flags for guaranteed phi arguments
2024-11-12 09:26:59 +01:00
Erik Eckstein
8462459f07
Optimizer: re-compute the re-borrow flags of phi arguments in updateAllBorrowArguments and updateBorrowArguments
2024-11-12 09:26:59 +01:00
Erik Eckstein
e934bb1321
BorrowUtils: support guaranteed forwarding phis without forwarding instructions when computing enclosing values
...
For example:
```
%1 = begin_borrow %0
%2 = br bb1(%1, %1)
bb1(%3 : @reborrow @guaranteed, %4: @guaranteed):
// %4 is a guaranteed forwarding phi without any forwarding instructions between the begin_borrow and the incoming value.
```
Also improve the comments
2024-11-12 09:26:58 +01:00
Erik Eckstein
f7d49a9680
SIL: add the Argument.set(reborrow:) and Argument.hasBorrowEndingUse APIs
2024-11-12 09:26:58 +01:00
Erik Eckstein
6b8c6a3c3b
SIL: rename updateBorrowedFrom to updateBorrowArguments
...
NFC
2024-11-12 09:26:58 +01:00
Erik Eckstein
1c5e185e89
Simplification: don't delete trivially dead borrowed-from instruction
...
A dead borrowed-from can only be removed if the argument (= operand) is also removed.
Fixes a compiler crash.
2024-11-11 14:06:16 +01:00
Arnold Schwaighofer
9093e1b0d2
Add comments to SwiftCompilerSources for shouldExpand()
2024-11-05 09:05:24 -08:00
Erik Eckstein
7786596a48
RedundantLoadElimination: support redundant loads of array elements with non-constant index
...
For example:
```
func test3(_ arr: Array<Int>, index: Int) -> Int {
return arr[index] + arr[index]
}
```
rdar://138519664
2024-11-04 19:26:45 +01:00
Erik Eckstein
f0633d5638
AccessUtils: support computing "constant" access paths
...
Add `Value.constantAccessPath`. It is like `accessPath`, but ensures that the projectionPath only contains "constant" elements.
This means: if the access contains an `index_addr` projection with a non-constant index, the `projectionPath` does _not_ contain the `index_addr`.
Instead, the `base` is an `AccessBase.index` which refers to the `index_addr`.
2024-11-04 19:26:44 +01:00
Konrad `ktoso` Malawski
43839ac5fd
Merge pull request #76995 from nickolas-pohilets/mpokhylets/disable-stack-promotion
...
Disable stack promotion for classes with isolated deinit
2024-11-04 18:07:11 +09:00
Michael Gottesman
3c38c79f7a
[region-isolation] Implement MergeIsolationRegionInst.
...
I am adding this instruction to express artificially that two non-Sendable
values should be part of the same region. It is meant to be used in cases where
due to unsafe code using Sendable, we stop propagating a non-Sendable dependency
that needs to be made in the same region of a use of said Sendable value. I
included an example in ./docs/SIL.rst of where this comes up with @out results
of continuations.
2024-11-01 11:25:53 -07:00
Arnold Schwaighofer
787c996394
LargeTypesReg2Mem: Add a new heuristic that trys harder to keep large
...
values on the stack
This heuristic can be enabled by passing -Xfrontend
-enable-aggressive-reg2mem.
rdar://123916109
2024-10-31 13:22:06 -07:00
Mykola Pokhylets
cb7a8d5cfc
Disable stack promotion for classes with isolated deinit
2024-10-31 20:43:11 +01:00
Erik Eckstein
b8a91c95aa
embedded: make sure to de-serialize vtable/wtable methods before trying to specialize them
...
Fixes a compiler crash.
rdar://138341211
2024-10-24 10:29:50 +02:00
Erik Eckstein
b8026d74e6
Revert "Revert "Optimizer: improve the load-copy-to-borrow optimization and implement it in swift""
...
This reverts commit 0666c446ec .
2024-10-22 08:40:18 +02:00
Erik Eckstein
44a9919308
Revert "Revert "SIL Verifier: implement load-borrow-immutability checkin in the swift verifier""
...
This reverts commit d7810450fe .
2024-10-22 08:40:18 +02:00
Erik Eckstein
d7810450fe
Revert "SIL Verifier: implement load-borrow-immutability checkin in the swift verifier"
...
This reverts commit b01e703ff3 .
2024-10-18 11:13:33 +02:00
Erik Eckstein
0666c446ec
Revert "Optimizer: improve the load-copy-to-borrow optimization and implement it in swift"
...
This reverts commit eed8645610 .
2024-10-18 10:36:06 +02:00
Erik Eckstein
709dfc2d21
MandatoryPerformanceOptimization: don't let not-inlinable functions to be inlined
...
Also refactor canInline.
Fixes a compiler crash.
rdar://137544788
2024-10-15 12:19:50 +02:00
Erik Eckstein
5c8fe55449
embedded: fix several issues with vtable specialization
...
* fix a false error if a derived class has different generic parameters than its base class
* fix a similar problem if a non-generic class derives from a generic class
* fix a compiler crash for calling a class method on a class metatype
rdar://137692055
2024-10-14 14:43:11 +02:00
Erik Eckstein
e0533e6125
SIL: add an API to replace all entries of a VTable
...
* add `ModulePassContext.replaceVTableEntries()`
* add `ModulePassContext.notifyFunctionTablesChanged()`
2024-10-14 14:43:11 +02:00
Erik Eckstein
eed8645610
Optimizer: improve the load-copy-to-borrow optimization and implement it in swift
...
The optimization replaces a `load [copy]` with a `load_borrow` if possible.
```
%1 = load [copy] %0
// no writes to %0
destroy_value %1
```
->
```
%1 = load_borrow %0
// no writes to %0
end_borrow %1
```
The new implementation uses alias-analysis (instead of a simple def-use walk), which is much more powerful.
rdar://115315849
2024-10-11 09:41:37 +02:00
Erik Eckstein
f249fa7289
OwnershipLiveness: add a flag visitInnerUses to enable constructing incomplete liveranges
...
If `visitInnerUses ` is true, it's not assumed that inner scopes are linear.
It forces to visit all interior uses if inner scopes.
2024-10-11 09:41:37 +02:00
Erik Eckstein
52deb58251
Optimizer: add the FunctionPassContext.completeLifetime(of: Value) utility
...
Implemented by bridging the OSSALifetimeCompletion utility
2024-10-11 09:41:37 +02:00
Erik Eckstein
b01e703ff3
SIL Verifier: implement load-borrow-immutability checkin in the swift verifier
2024-10-11 09:41:37 +02:00
Erik Eckstein
62317d86a6
SwiftCompilerSources: add the LoadBorrowInst.isUnchecked API
2024-10-11 09:41:36 +02:00
Erik Eckstein
c8473da3a9
Swift Optimizer: add SpecificInstructionSet and SpecificInstructionWorklist
...
To be used for specific instruction types
2024-10-11 09:41:36 +02:00
Erik Eckstein
6bf7cc8f2f
Swift SIL: add flag parameters to Builder.createBeginBorrow
2024-10-11 09:41:36 +02:00
Erik Eckstein
6ecb85a863
Swift SIL: add Operand.changeOwnership
2024-10-11 09:41:36 +02:00
Erik Eckstein
c97502374b
Optimizer: add constant folding of classify_bridge_object
...
Constant fold `classify_bridge_object` to `(false, false)` if the operand is known to be a swift class.
2024-10-08 16:24:46 +02:00
Erik Eckstein
1856e7f68a
SwiftCompilerSources: add the ValueDecl.isObjC API
2024-10-08 16:23:22 +02:00
Erik Eckstein
a3e6e86383
Embedded: support existentials with inherited conformances
...
That means: derived classes where the base conforms to a protocol
2024-10-07 12:25:18 +02:00
Erik Eckstein
f7aaf7e5a5
MandatoryPerformanceOptimizations: handle all kind of witness-table entries when specializing witness-tables
...
Support associated-type and associated-conformance entries.
This enable existentials with associated types.
2024-10-07 09:00:32 +02:00
Erik Eckstein
c05234e677
MandatoryPerformanceOptimizations: specialize witness_method instructions
...
In Embedded Swift, witness method lookup is done from specialized witness tables.
For this to work, the type of witness_method must be specialized as well.
Otherwise the method call would be done with wrong parameter conventions (indirect instead of direct).
2024-10-07 09:00:31 +02:00
Erik Eckstein
d4192d5d00
SwiftCompilerSources: add Type.subst(with substitutionMap: SubstitutionMap) -> Type API
2024-10-07 09:00:31 +02:00
Erik Eckstein
b0dd1ab4ab
SIL: make SubstitutionMap CustomStringConvertible
2024-10-07 09:00:27 +02:00
Erik Eckstein
a67d9c5bed
embedded: Support class existentials with inherited protocols
...
For example:
```
protocol Base: AnyObject {}
protocol Derived: Base {}
class C: Derived {}
let e: Derived = C()
```
2024-10-07 08:49:56 +02:00
Erik Eckstein
25728853b8
GenericSpecialization: change how new specialized witness tables are added to MandatoryPerformanceOptimization's worklist
...
Do it by passing a closure instead of returning the new witness table.
This allows to add more than one new witness table to the worklist
2024-10-07 08:49:56 +02:00