Commit Graph

2610 Commits

Author SHA1 Message Date
eeckstein
ca50c55eb5 Merge pull request #77806 from eeckstein/rle-of-array-elements
Optimizer: remove the ArrayElementPropagation optimization
2024-12-02 07:13:08 +01:00
Erik Eckstein
63f6a2f30d Optimizer: remove the ArrayElementPropagation optimization
Propagating array element values is done by load-simplification and redundant-load-elimination.
So ArrayElementPropagation is not needed anymore.

ArrayElementPropagation also replaced `Array.append(contentsOf:)` with individual `Array.append` calls.
This optimization is removed, because the benefit is questionably, anyway.
In most cases it resulted in a code size increase.
2024-11-28 10:35:40 +01:00
Erik Eckstein
ca09336154 ConditionForwarding: fix a wrong assert
Some terminator instructions can have type-dependent operands.
Therefore we need to use `getNumRealOperands` instead of `getNumOperands`.

Fixes a compiler crash.
2024-11-27 13:19:12 +01:00
Anton Korobeynikov
55d51b782d Closure specialization might create functions with lots of arguments. (#77629)
Increase inlining benefits for functions with more than 5 arguments and / or results.
We assume that each argument beyond these 5 would be passed on stack and therefore would incur a pair of load and store.
2024-11-20 16:31:47 -08:00
Andrew Trick
4612728581 [NFC] Add BeginApplyInst::getEndApplyUses() API.
A begin_apply token may be used by operands that do not end the coroutine:
mark_dependence.

We need an API that gives us only the coroutine-ending uses. This blocks
~Escapable accessors.

end_borrow is considered coroutine-ending even though it does not actually
terminate the coroutine.

We cannot simply ask isLifetimeEnding, because end_apply and abort_apply do not
end any lifetime.
2024-11-18 01:37:00 -08:00
eeckstein
972ac6ff28 Merge pull request #77610 from eeckstein/fix-array-element-propagation
ArrayElementValuePropagation: require that the initialization and element-get are in the same block for non-trivial values.
2024-11-15 07:53:11 +01:00
Meghana Gupta
434461d8f4 Fix DCE of load_borrow when it is derived from another borrow scope
Fixes rdar://138663452
2024-11-14 12:09:11 -08:00
Meghana Gupta
5486b7a289 Merge pull request #77571 from meg-gupta/fixsimplifycfgunreachable
Fix simplifySwitchEnumUnreachableBlocks for default cases in ossa
2024-11-14 07:44:19 -08:00
Erik Eckstein
16c77d97dc ArrayElementValuePropagation: require that the initialization and element-get are in the same block for non-trivial values.
In OSSA we only insert a copy_value of the element at the array initialization point.
This would result in an over-consume if the getElement is in a loop.
Therefore require that both semantic calls are in the same block.

Fixes an ownership verifier crash.
2024-11-14 13:30:06 +01:00
eeckstein
6d4db0e649 Merge pull request #77583 from eeckstein/fix-dce
DeadCodeElimination: don't remove end_lifetime instructions with address operands
2024-11-13 18:51:45 +01:00
Meghana Gupta
452ae3b994 Merge pull request #77568 from meg-gupta/dceupdate2
Insert end_borrow for dead phi operands only when required
2024-11-13 04:10:30 -08:00
Erik Eckstein
64698ca6bb DeadCodeElimination: don't remove end_lifetime instructions with address operands
DCE cannot reason about values in memory.

Fixes a memory lifetime verification error
rdar://139779406
2024-11-13 12:04:41 +01:00
Meghana Gupta
106dc8a7e0 Fix simplifySwitchEnumUnreachableBlocks for default cases in ossa
Unlike non-ossa, ossa's switch_enum accepts an argument for the default case
When all other cases are unreachable, replace the default block's phi with
the switch_enum's operand and transform the switch_enum to a branch.

Fixes rdar://139441002
2024-11-12 21:11:54 -08:00
Meghana Gupta
fd6d29d10b Insert end_borrow for dead phi operands only when required
DCE inserts end_borrow at phi operands when a guaranteed phi becomes dead.
This should be done for reborrows which end the lifetime of the incoming value.
The existing check was not accurate and ended up inserting end_borrow for forwarded values as well.

Fixes rdar://139283745
2024-11-12 14:05:23 -08:00
Erik Eckstein
51e3e5ed80 Optimizer: rename BorrowArgumentsUpdater -> GuaranteedPhiUpdater
NFC
2024-11-12 09:26:59 +01:00
Erik Eckstein
6b8c6a3c3b SIL: rename updateBorrowedFrom to updateBorrowArguments
NFC
2024-11-12 09:26:58 +01:00
Erik Eckstein
15c6abf66d SIL: avoid creating SIL functions for not used imported specialization attributes
This ended up in creating a lot of Array functions, even if a program didn't use Array at all.
Now, only add specialization attributes if a function is already there.
Otherwise remember the attributes and add them to a function once it is created.
2024-11-05 20:37:15 +01:00
Meghana Gupta
359f6d14bf DCE unconditional_checked_cast 2024-10-16 16:55:22 -07:00
Arnold Schwaighofer
8d8951768c Revert "Merge pull request #76656 from nate-chandler/rdar136388508"
This reverts commit b9228c81d1, reversing
changes made to 6fb2989bcf.

After PR#76686 this bailout should no longer be neccessary.

rdar://136681998
2024-09-26 09:26:21 -07:00
Erik Eckstein
7ffd270008 embedded: move the VTableSpecializer pass into MandatoryPerformanceOptimizations
MandatoryPerformanceOptimizations already did most of the vtable specialization work.
So it makes sense to remove the VTableSpecializerPass completely and do everything in MandatoryPerformanceOptimizations.
2024-09-25 19:32:14 +02:00
Nate Chandler
c420b0e481 [Mem2Reg] Always bail on dynamic_lifetime.
rdar://136388508
2024-09-23 12:12:11 -07:00
nate-chandler
d177df981b Merge pull request #76440 from nate-chandler/rdar134198292
[Outliner] Handle multiple consumes of a value.
2024-09-13 07:45:02 -07:00
Nate Chandler
e7365aa857 [Outliner] Handle multiple consumes of a value.
If a single native value is bridged multiple times, it cannot be
consumed without other changes.  One option would be to copy it.  The
other option is taken here: sink the destroy of the native value to
after the apply and have the outlined function take the value
guaranteed.

rdar://134198292
2024-09-12 18:42:28 -07:00
Kavon Farvardin
ba0aac3f39 Merge pull request #76093 from kavon/coldsplit-2
ColdBlockInfo: overhaul analysis pass
2024-09-12 16:06:07 -07:00
Kavon Farvardin
7203a4fa73 ColdBlockInfo: overhaul analysis pass
The old analysis pass doesn't take into account profile data, nor does
it consider post-dominance. It primarily dealt with _fastPath/_slowPath.

A block that is dominated by a cold block is itself cold. That's true
whether it's forwards or backwards dominance.

We can also consider a call to any `Never` returning function as a
cold-exit, though the block(s) leading up to that call may be executed
frequently because of concurrency. For now, I'm ignoring the concurrency
case and assuming it's cold. To make use of this "no return" prediction,
use the `-enable-noreturn-prediction` flag, which is currently off by
default.
2024-09-03 15:41:10 -07:00
nate-chandler
c56a313d6c Merge pull request #76114 from nate-chandler/rdar133969821_2
[DAH] Bail on pointer use if ignoring barriers.
2024-08-27 21:57:39 -07:00
Nate Chandler
74c4bc9c55 [DAH] Bail on pointer use if ignoring barriers.
Unknown uses of raw pointers should not result in bailing out when an
address is lexical--the destroy of the address will already not be
hoisted over any instructions which may access pointers.  If the address
is not lexical however (such as any address when lexical lifetimes are
disabled), that rationale does not apply, so unknown uses of raw
pointers must cause hoisting to bail.

rdar://133969821
2024-08-27 16:18:39 -07:00
Slava Pestov
8315120eaf Merge pull request #76051 from slavapestov/archetype-get-parent
AST: Remove ArchetypeType::getParent()
2024-08-24 15:31:01 -04:00
Slava Pestov
63028be348 SILCloner: Redo local archetype remapping 2024-08-22 17:17:53 -04:00
eeckstein
b1a88beab5 Merge pull request #75836 from eeckstein/fix-vtable-specializer
VTableSpecializer: fix a crash for methods which have their own generic parameters
2024-08-22 08:20:19 +02:00
Slava Pestov
39b4bda1dc AST: Introduce SubstFlags::SubstituteLocalArchetypes 2024-08-21 14:23:37 -04:00
Slava Pestov
ae77d6f0c1 AST: Replace one-off predicates with SubstitutionMap::getRecursiveProperties() 2024-08-21 13:19:10 -04:00
Erik Eckstein
ba9bfaf5d5 VTableSpecializer: fix a crash for methods which have their own generic parameters
rdar://133334324
2024-08-21 17:01:35 +02:00
Erik Eckstein
9053cce8a4 SimplifyCFG: fix an ownership verifier error caused by switch_enum simplification
If constant folding a switch_enum ends up in branching to a no-payload case, the enum value still needs to be destroyed to satisfy the ownership verifier.

https://github.com/swiftlang/swift/issues/74903
rdar://131726690
2024-08-20 10:13:52 +02:00
Meghana Gupta
920c5603fc Merge pull request #75807 from meg-gupta/fixdebuginfodoe
Fix debug info in DeadObjectElimination in OSSA
2024-08-10 11:28:43 +05:30
Meghana Gupta
f71ab17e7a Fix debug info in DeadObjectElimination in OSSA
Move debug_value insertion before destroy_value insertion.
2024-08-09 22:39:38 +05:30
Slava Pestov
375363a473 AST: Move global conformance lookup entry points to ConformanceLookup.h 2024-08-08 23:35:58 -04:00
Erik Eckstein
80a0da9615 Optimizer: update borrowed-from instructions in some passes
Fixes verifier crashes (once the borrowed-from verifier is fixed).
2024-08-07 18:02:38 +02:00
Erik Eckstein
f9b524b1cb AliasAnalysis: a complete overhaul of alias- and memory-behavior analysis
The main changes are:

*) Rewrite everything in swift. So far, parts of memory-behavior analysis were already implemented in swift. Now everything is done in swift and lives in `AliasAnalysis.swift`. This is a big code simplification.

*) Support many more instructions in the memory-behavior analysis - especially OSSA instructions, like `begin_borrow`, `end_borrow`, `store_borrow`, `load_borrow`. The computation of end_borrow effects is now much more precise. Also, partial_apply is now handled more precisely.

*) Simplify and reduce type-based alias analysis (TBAA). The complexity of the old TBAA comes from old days where the language and SIL didn't have strict aliasing and exclusivity rules (e.g. for inout arguments). Now TBAA is only needed for code using unsafe pointers. The new TBAA handles this - and not more. Note that TBAA for classes is already done in `AccessBase.isDistinct`.

*) Handle aliasing in `begin_access [modify]` scopes. We already supported truly immutable scopes like `begin_access [read]` or `ref_element_addr [immutable]`. For `begin_access [modify]` we know that there are no other reads or writes to the access-address within the scope.

*) Don't cache memory-behavior results. It turned out that the hit-miss rate was pretty bad (~ 1:7). The overhead of the cache lookup took as long as recomputing the memory behavior.
2024-07-29 17:33:46 +02:00
Erik Eckstein
04e0907ab0 SIL: rename Type.instanceTypeOfMetatype -> Type.loweredInstanceTypeOfMetatype
The same for SILType

It needs to be made clear that this is not the "original", but the lowered SIL type.

NFC
2024-07-29 17:33:36 +02:00
Nate Chandler
9825b26e3a [Test] Underscored simplify_cfg_simplify_argument.
Use underscores rather than hyphens so that text editors understand the
name as a single word.
2024-07-25 13:50:17 -07:00
Nate Chandler
2878b053ec [Test] Underscored simplify_cfg_simplify_block_args.
Use underscores rather than hyphens so that text editors understand the
name as a single word.
2024-07-25 13:50:17 -07:00
Nate Chandler
dd19acdf68 [Test] Underscored simplify_cfg_canonicalize_switch_enum.
Use underscores rather than hyphens so that text editors understand the
name as a single word.
2024-07-25 13:50:17 -07:00
Nate Chandler
4329512fb0 [Test] Underscored simplify_cfg_simplify_term_with_identical_dest_blocks.
Use underscores rather than hyphens so that text editors understand the
name as a single word.
2024-07-25 13:50:17 -07:00
Nate Chandler
b0bb97467f [Test] Underscored simplify_cfg_simplify_switch_enum_block.
Use underscores rather than hyphens so that text editors understand the
name as a single word.
2024-07-25 13:50:17 -07:00
Nate Chandler
c0d95c121b [Test] Underscored simplify_cfg_simplify_switch_enum_on_objc_class_optional.
Use underscores rather than hyphens so that text editors understand the
name as a single word.
2024-07-25 13:50:14 -07:00
Nate Chandler
7470c29cfe [Test] Underscored simplify_cfg_simplify_switch_enum_unreachable_blocks.
Use underscores rather than hyphens so that text editors understand the
name as a single word.
2024-07-25 13:48:22 -07:00
Nate Chandler
8d3a5a17d9 [Test] Underscored simplify_cfg_try_jump_threading.
Use underscores rather than hyphens so that text editors understand the
name as a single word.
2024-07-25 13:47:45 -07:00
Allan Shortlidge
e4331af916 IRGen: Introduce macCatalyst target variant version check builtins. 2024-07-23 17:00:10 -07:00
Nate Chandler
4a397cc018 [NFC] OwnedLifetimeCan: Take DeadEndBlocksAnalysis
All clients of OwnedLifetimeCanonicalization pass an instance of the
analysis in.  For now, it's unused.
2024-07-22 21:51:28 -07:00