Commit Graph

8906 Commits

Author SHA1 Message Date
nate-chandler
1f05436a99 Merge pull request #68049 from nate-chandler/opaque-values/20230821/1/all-local-archetypes
[AddressLowering] Consider opening instructions of all local archetypes.
2023-08-21 20:55:25 -07:00
Nate Chandler
efc9c6df10 [AddressLowering] Consider all local archetypes.
When determining where the "latest opening instruction" is, consider not
just `OpenedArchetypeType`s but any `LocalArchetypeType` which includes
`PackArchetypeType`s.
2023-08-21 13:46:11 -07:00
Pavel Yaskevich
2149a4630a [DI] InitAccessors: Ignore unreachable blocks when check property initialization inside of an init accessor 2023-08-21 09:04:34 -07:00
Pavel Yaskevich
1542bb5a71 Merge pull request #67763 from xedin/rdar-113412104
[DI] Properties with init accessors without "initializes" act as stored
2023-08-21 09:03:43 -07:00
Michael Gottesman
361562aef5 [consume-operator] Emit a better error message when failing to consume globals or escaping captures.
Specifically, we previously emitted a "compiler doesn't understand error", so we
were always emitting an error appropriately. This just gives a better error
message saying instead that the compiler did understand what happened and that
one cannot apply consume to globals or escaping captures.

https://github.com/apple/swift/issues/67755
rdar://112561671
2023-08-20 18:59:37 -07:00
swift-ci
978395bc11 Merge pull request #62959 from meg-gupta/simplifycfgossapr3
Migrate simple and dominator based jump threading to OSSA
2023-08-18 17:18:10 -07:00
Erik Eckstein
1603035927 PerformanceDiagnostics: fix handling of nested closures
Need to handle `mark_dependence` instruction in the use-def walk for the closure value.

Fixes a false performance error.

rdar://114008787
2023-08-18 09:08:04 +02:00
Meghana Gupta
9311e948a5 Avoid unnecessary block arguments in SimplifyCFG::threadEdge and SimplifyCFG::simplifyThreadedTerminators 2023-08-17 10:33:22 -07:00
Meghana Gupta
bbd6a87e2b Fix simplifyArguments for a few edges cases in OSSA 2023-08-16 23:14:36 -07:00
Nate Chandler
84ab0eb548 [AddressLowering] Handle tuple_pack_extract.
By analogy with tuple_extract, transform the new instruction to
tuple_pack_element_addr.
2023-08-16 17:28:00 -07: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
Allan Shortlidge
117a5ecdae Merge pull request #67920 from tshortli/unavailable-decl-opt-complete-resilient-enum-switch
SILOptimizer: Remove switch cases matching unavailable enum elements
2023-08-16 09:06:20 -07:00
Allan Shortlidge
29374cb802 SILOptimizer: Skip unreachable cases optimization when elements are available.
Cache a bit on `EnumDecl` indicating whether there are any elements that are
unavailable during lowering and then use that bit to decided whether to attempt
optimization for `switch_enum`/`switch_enum_addr` instructions.
2023-08-15 17:13:10 -07:00
Allan Shortlidge
e2bb7e8c8b SILOptimizer: Remove switch cases matching unavailable enum elements.
Unavailable enum elements cannot be instantiated at runtime without invoking
UB. Therefore the optimizer can consider a basic block unreachable if its only
predecessor is a block that terminates in a switch instruction matching an
unavailable enum element. Furthermore, removing the switch instruction cases
that refer to unavailable enum elements is _mandatory_ when
`-unavailable-decl-optimization=complete` is specified because otherwise
lowered IR for these instructions could refer to enum tag accessors that will
not be lowered, resulting in a failure during linking.

Resolves rdar://113872720.
2023-08-15 17:13:10 -07:00
Nate Chandler
35113d8a80 [AddressLowering] Fix partial_apply arg indexing.
When rewriting arguments, the index used is into the callee's argument
list.  For full applies, that is identical to the index into the
instruction's argument list.  For partial applies, it is not.

Previously, though, the index was used as if it were an index into the
instruction's argument list to get an argument ref.  Here, use instead
the newly added convenience to get the argument ref using the index into
the callee's arguments.
2023-08-15 13:06:32 -07:00
Nate Chandler
5c31339028 [AddressLowering] Loosen assert for partial_apply.
Full apply instructions have the same number of arguments as the callee
has parameters.  Partial apply instructions have some number less than
or equal to the number of callee parameters.
2023-08-15 13:06:32 -07:00
nate-chandler
2528c3378b Merge pull request #67919 from nate-chandler/rdar113762355
[Mem2Reg] Don't canonicalize erased values.
2023-08-15 06:52:12 -07:00
Nate Chandler
0403ab102d [Mem2Reg] Don't canonicalize erased vals.
To eliminate copies which become newly spurious, Mem2Reg canonicalizes
the lifetimes of values that are stored and of newly introduced phis
after rewriting.

It's possible, however, for the values that are stored to be deleted
during canonicalization if a value and its copy are both stored to the
address.  Such values must not be canonicalized.  So check whether
values have been erased before canonicalizing them.

rdar://113762355
2023-08-14 15:08:57 -07:00
Meghana Gupta
93d6f93435 Fixes to SimplifyCFG::threadEdge for OSSA 2023-08-14 11:36:05 -07:00
Meghana Gupta
05c7d64511 We don't consider it profitable to jump thread when we could optimize arc in OSSA.
Copy propagation should be able to handle such cases without jump threading.
2023-08-14 11:36:04 -07:00
Meghana Gupta
e3a98e88f3 Add new flags to enable specific SimplifyCFG operations 2023-08-14 11:36:04 -07:00
Meghana Gupta
a303bb4519 Disable SimplifyCFG::tailDuplicateObjCMethodCallSuccessorBlocks in OSSA
Support for this needs to be added
2023-08-14 11:36:04 -07:00
Meghana Gupta
bf68e3ff39 Disable ArgumentSplitter for non trivial types in ossa 2023-08-14 11:36:04 -07:00
Nate Chandler
16bd80d945 [AddressLowering] Rewrite indirect partial_apply.
In opaque values mode, all arguments are passed to a partial_apply (just
like all other flavors of apply) directly.  AddressLowering needs to
rewrite the operands whose convention is indirect as it does for other
applies.
2023-08-14 10:40:40 -07:00
nate-chandler
72bcb756f5 Merge pull request #67831 from nate-chandler/opaque-values/20230809/opaque-result-types
[AddressLowering] Type SILFunctionArguments for @out results with opaque types substituted.
2023-08-11 14:09:04 -07:00
Nate Chandler
fa98212420 [AddressLowering] Look through opaque result type.
A function which returns a value of opaque result type

    func f() -> some P { S() }

has a lowered, substituted signature

    @convention(thin) () -> @out @_opaqueReturnTypeOf("$s4main1fQryF", 0) opaque

featuring an _opaqueReturnTypeOf attr.  The SILFunctionArgument for that
@out result, however, must be of the type that the opaque result
substitutes to in the expansion context of the function.
2023-08-11 08:10:38 -07:00
swift-ci
2667df0799 Merge pull request #67760 from atrick/fix-closure-moveonly-arg
Fix compiler crashes with consuming and borrowing keywords.
2023-08-11 00:32:41 -07:00
Andrew Trick
f46d79149d ClosureLifetimeFixup review feedback 2023-08-10 18:51:48 -07:00
Michael Gottesman
33eedc1574 Merge pull request #67874 from gottesmm/pr-179e2ec3ed29bb0d8c35dc99f710a18571a0a24e
[sil] Convert AddressWalker from using virtual methods to use CRTP and add a transitive -> endpoint user API
2023-08-10 17:18:27 -07:00
swift-ci
48ca50a100 Merge pull request #67870 from nate-chandler/sil/20230810/1/fix-memmustinitialize-for-builtins
[SIL] Fix memInstMustInitialize for builtins.
2023-08-10 15:32:33 -07:00
Michael Gottesman
29350907fc Convert TransitiveAddressWalker to use CRTP instead of virtual functions. 2023-08-10 12:58:50 -07:00
Nate Chandler
dfa629a197 [SIL] Fix memInstMustInitialize for builtins.
The function's switch previously fell-through to the
SILInstructionKind::StoreWeakInst case which cast the instruction (a
BuiltinInst) to StoreWeakInst and then called isInitializationOfDest on
it.
2023-08-10 12:27:03 -07:00
Erik Eckstein
7e33e554ef SIL: a few changes regarding access to a GlobalVariable's static initializer instructions
* add `GlobalVariable.staticInitializerInstructions` to access all initializer instructions of a global
* implement `GlobalVariable.staticInitValue` with `GlobalVariable.staticInitializerInstructions`
* this requires that `InstructionList.reversed()` works without accessing the parent block of the iterator instruction
* allow `Context.erase(instruction:)` to delete instructions from a global's initializer list, which means to handle the case where a deleted instruction has no parent function.
2023-08-10 20:49:20 +02:00
Andrew Trick
20f99b2822 Verify that on-stack closures do not take owned arguments 2023-08-10 11:17:53 -07:00
Andrew Trick
83ce3a1777 Rename getArgumentOperandConvention to getCaptureConvention
The name was misleading and problematic. There is already a
getArgumentConvention which is completely different.
2023-08-10 11:17:53 -07:00
Andrew Trick
9c24933bd4 Fix compiler crashes with consuming and borrowing keywords.
Without this fix, the new 'consuming' and 'borrowing' keywords cannot
be used with trivial types. Which means, for example, they can't be
used in macro expansions that work on various types.

Fixes patterns like:

public func test1(i: consuming Int) -> Int {
  takeClosure { [i = copy i] in i }
}

public func test2(i: borrowing Int) -> Int {
  takeClosure { [i = copy i] in i }
}

public func test3(i: consuming Int) -> Int {
  takeClosure { i }
}

// Sadly, test4 is still incorrectly diagnosed.
public func test4(i: borrowing Int) -> Int {
  takeClosure { i }
}

Fixes rdar://112795074 (Crash compiling function that has a macro annotation and uses `consuming`)
2023-08-10 11:17:45 -07:00
Erik Eckstein
8223b3e210 MandatoryPerformanceOptimizations: fix some problems with inilning
* don't inline functions if it's not possible - by checking `SILInliner::canInlineApplySite`
* fix stack nesting after inlining a `begin_apply`
2023-08-10 15:01:47 +02:00
nate-chandler
1791108bde Merge pull request #67722 from nate-chandler/opaque-values/1/20230803/unowned-copies
[SIL] Represent copies to @sil_unowned values.
2023-08-09 06:59:49 -07:00
nate-chandler
3336083265 Merge pull request #67690 from nate-chandler/opaque-values/20230802/2/weak-copies
[SIL] Represent copies to and from @sil_weak values.
2023-08-09 06:59:19 -07:00
Meghana Gupta
1075f77822 Merge pull request #67521 from meg-gupta/migratedoe
Migrate DeadObjectElimination to OSSA
2023-08-08 21:27:06 -07:00
Nate Chandler
57c7c9e730 [AddressLowering] Handle unowned copies.
Lower the `strong_copy_unowned_value` and `unowned_copy_value` to
`load_unowned` and `store_unowned` respectively.
2023-08-08 15:49:17 -07:00
Nate Chandler
f938287710 [SIL] Added unowned_copy_value. 2023-08-08 15:49:17 -07:00
Nate Chandler
390d02f114 [AddressLowering] Handle weak copies.
Lower the `strong_copy_weak_value` and `weak_copy_value` to `load_weak`
and `store_weak` respectively.
2023-08-08 15:47:13 -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
Meghana Gupta
848466acbe Ensure no module transform is added in the function pipeline 2023-08-08 11:04:46 -07:00
Meghana Gupta
996fd8b978 Bail out from deleting a dead objection on seeing stores with lexical non-trivial source 2023-08-08 10:48:09 -07:00
Meghana Gupta
abdb9f0dba DeadObjectElimination: Handle allocating apply in ossa 2023-08-07 14:58:57 -07:00
Meghana Gupta
2831f2f528 Add findPointerEscape check on store source, before shortening its lifetime by inserting destroy at the store 2023-08-07 10:21:40 -07:00
Meghana Gupta
c3c78fa8f8 DeadObjectElimination: Handle alloc_ref in ossa 2023-08-07 10:21:40 -07:00