`InstructionRange.contains` did yield a wrong result if the range ended in the begin-block and another instruction was inserted in an unreachable block.
When extending a coroutine, handle the end_borrow instruction used to end a
coroutine lifetime at a dead-end block.
Fixes rdar://153479358 (Compiler crash when force-unwrapping optional ~Copyable type)
LifetimeDependenceInsertion inserts mark_dependence on token result of a begin_apply
when it yields a lifetime dependent value. When such a begin_apply gets inlined,
the inliner can crash because of the remaining uses of the token result.
Fix this by inserting mark_dependence on parameter operands that are lifetime dependence sources
and deleting the mark_dependence on token results in the inliner.
Fixes rdar://151568816
It used to also set it for functions which are referenced from a global with a const/section attribute - even if not performance attribute was present in the whole module. This is unnecessary and can lead to worse code generation.
rdar://152665294
When extending an access scope over a coroutines, instead of simply
considering the lifetime of the coroutine scope, recurse through all
uses of yielded values. They may be copyable, non-Escapable values
that depend on the coroutine operand.
Fixes rdar://152693622 (Extend coroutines over copied yields)
* re-implement the pass in swift
* support alloc_stack liveranges which span over multiple basic blocks
* support `load`-`store` pairs, copying from the alloc_stack (in addition to `copy_addr`)
Those improvements help to reduce temporary stack allocations, especially for InlineArrays.
rdar://151606382
Instead, remove `Operand.users(ofType:)` which returned a sequence of `Instruction` - which was a kind of replacement for the missing `InstructionSet` API
We are going to need to add more flags to the various checked cast
instructions. Generalize the CastingIsolatedConformances bit in all of
these SIL instructions to an "options" struct that's easier to extend.
Precursor to rdar://152335805.
Add support for diagnosing calls to closures that return a generic
non-Escapable result.
Closures do not yet model lifetime dependencies. The diagnostics have
a special case for handling nonescaple result with no lifetime
dependence, but it previously only handled direct results. This fix handles
cases like the following:
func callIndirectClosure<T>(f: () -> NE<T>) -> NE<T> {
f()
}
Fixes rdar://134318846 ([nonescapable] diagnose function types with nonescapable results)
When de-serializing a function and this function allocates a class, the methods of the de-serialized vtable must be handled, too.
Fixes an IRGen crash
rdar://152311945
This mostly makes it easier to test dependency corner cases. The analysis still
doesn't recognize UnsafeRawPointer.init(), so regular users still need to use
_overrideLifetime.
Fixes rdar://137608270 ([borrows] Add Builtin.addressof() support
for @addressable arguments)
Optimize (the very inefficient) RawRepresentable comparison function call to a simple compare of enum tags.
For example,
```
enum E: String {
case a, b, c
}
```
is compared by getting the raw values of both operands and doing a string compare.
This peephole optimizations replaces the call to such a comparison function with a direct compare of the enum tags, which boils down to a single integer comparison instruction.
rdar://151788987
Introduce a new pass MandatoryTempRValueElimination, which works as the original TempRValueElimination, except that it does not remove any alloc_stack instruction which are associated with source variables.
Running this pass at Onone helps to reduce copies of large structs, e.g. InlineArrays or structs containing InlineArrays.
Copying large structs can be a performance problem, even at Onone.
rdar://151629149
This is a workaround for a bug in the move-only checker: rdar://151841926.
The move-only checker sometimes inserts destroy_addr within read-only static access scopes.
Therefore don't consider static access scopes as immutable scopes.
* Move the mutating APIs into Context.swift, because SIL can only be mutated through a MutatingContext
* move the `baseOperand` and `base` properties from the instruction classes to the `MarkDependenceInstruction` protocol
* add `valueOrAddressOperand` and `valueOrAddress` in the `MarkDependenceInstruction` protocol
This prevents simplification and SILCombine passes to remove (alive) `mark_dependence_addr`.
The instruction is conceptually equivalent to
```
%v = load %addr
%d = mark_dependence %v on %base
store %d to %addr
```
Therefore the address operand has to be defined as writing to the address.
Instead of looking for a single store to the global in a global-init function, build a GlobalInitValue tree.
This is a data structure representing the init value of the global. It can handle complex InlineArray initializations,
like `init(repeating:)`.
rdar://150859232
It is like `zeroInitializer`, but does not actually initialize the memory.
It only indicates to mandatory passes that the memory is going to be initialized.
Diagnostics only work with `SourceLoc` which is basically a pointer into a buffer of the loaded source file.
But when debug info is de-serialized, the SIL `Location` consists of a filename+line+column.
To "convert" this to a `SourceLoc`, the file must be loaded.
This change adds `DiagnosticEngine.getLocationFromExternalSource` for this purpose.
Also, the new protocol `ProvidingSourceLocation` - to which `SourceLoc` and `Location` conform - help to generalize the helper struct `Diagnostic` and make this "conversion" happen automatically.
Treat `load`-`store` pairs as if they were `copy_addr` instructions.
This can catch more cases. For example it can eliminate unnecessary copies of InlineArray when subscripting it.
rdar://149250346
Add a boolean parameter `salvageDebugInfo` to `Context.erase(instruction:)`.
Sometimes it needs to be turned off because the caller might require that after erasing the original instruction the operands no users anymore.
Reimplement the simplification in swift and add a new transformation:
```
%1 = unchecked_addr_cast %0 : $*Builtin.FixedArray<N, Element> to $*Element
```
->
```
%1 = vector_base_addr %0 : $*Builtin.FixedArray<N, Element>
```
It derives the address of the first element of a vector, i.e. a `Builtin.FixedArray`, from the address of the vector itself.
Addresses of other vector elements can then be derived with `index_addr`.