Commit Graph

1065 Commits

Author SHA1 Message Date
Andrew Trick
cbe856e53a Cleanup PrunedLiveBlocks
Use BasicBlockBitfield to record per-block liveness state. This has
been the intention since BasicBlockBitfield was first introduced.

Remove the per-field bitfield from PrunedLiveBlocks. This
(re)specializes the data structure for scalar liveness and drastically
simplifies the implementation.

This utility is fundamental to all ownership utilities. It will be on
the critical path in many areas of the compiler, including at
-Onone. It needs to be minimal and as easy as possible for compiler
engineers to understand, investigate, and debug.

This is in preparation for fixing bugs related to multi-def liveness
as used by the move checker.
2023-03-22 02:36:57 -07:00
Andrew Trick
15796e3ff9 PrunedLiveness: add a SILFunction argument
So that liveness can migrate to using a SILBitfield.
2023-03-22 01:36:48 -07:00
nate-chandler
1482108c84 Merge pull request #64483 from nate-chandler/nfc/20230320/1/redundant-move
[NFC] Readability for isRedundantMoveValue.
2023-03-21 13:44:23 -07:00
Nate Chandler
b7f447da6c [NFC] Readability for isRedundantMoveValue.
Improved comments and flattened conditions.
2023-03-21 07:57:43 -07:00
Erik Eckstein
a092ecb5c2 remove SILBridgingUtils.h 2023-03-21 15:33:09 +01:00
Erik Eckstein
04c90166c4 Swift Bridging: use C++ instead of C bridging for BridgedBuilder 2023-03-21 15:33:09 +01:00
Erik Eckstein
b4510105a6 Swift Bridging: remove BridgedNode 2023-03-21 15:33:09 +01:00
Erik Eckstein
7905a9ac64 Swift Bridging: remove C bridging functions for SILDebugLocation 2023-03-21 15:33:09 +01:00
Erik Eckstein
82d9da5981 Swift Bridging: use C++ instead of C bridging for BridgedMultiValueResult 2023-03-21 15:33:09 +01:00
Erik Eckstein
47ac2d2818 Swift Bridging: use C++ instead of C bridging for BridgedArgument 2023-03-21 15:33:09 +01:00
Erik Eckstein
4445373808 Swift Bridging: use C++ instead of C bridging for BridgedInstruction 2023-03-21 15:33:09 +01:00
Erik Eckstein
c4f5bab5b7 Swift Bridging: use C++ instead of C bridging for BridgedBasicBlock 2023-03-21 15:33:09 +01:00
Erik Eckstein
c0c0b80c81 Swift Bridging: use C++ instead of C bridging for BridgedGlobalVar 2023-03-21 15:33:09 +01:00
Erik Eckstein
ae7770d911 Swift Bridging: use C++ instead of C bridging for BridgedFunction 2023-03-21 15:33:09 +01:00
Erik Eckstein
e469c16744 Swift Bridging: remove BridgedType and directly use the C++ SILType instead 2023-03-21 15:33:09 +01:00
Erik Eckstein
598644fb92 Swift Bridging: use C++ instead of C bridging for the bridged witness table classes 2023-03-21 15:33:09 +01:00
Erik Eckstein
151f09769f Swift Bridging: use C++ instead of C bridging for BridgedVTable and BridgedVTableEntry 2023-03-21 15:33:09 +01:00
Erik Eckstein
fc2ad09d4b Swift Bridging: use C++ instead of C bridging for BridgedSuccessor 2023-03-21 15:33:09 +01:00
Erik Eckstein
eecea088e7 Swift Bridging: use C++ instead of C bridging for BridgedOperand and BridgedValue 2023-03-21 15:33:09 +01:00
Nate Chandler
6f5114ef68 [OwnershipUtils] Classify more moves as redundant.
Moves from limited use values are redundant.  When a move separates a
non-escaping lifetime from an escaping lifetime, it is still redundant
if the original lifetime couldn't be optimized because it's already as
small as possible.
2023-03-16 18:22:58 -07:00
nate-chandler
1f3623d570 Merge pull request #64339 from nate-chandler/copy-propagation/redundant-move-elim
[CopyPropagation] Eliminate redundant moves.
2023-03-16 17:02:25 -07:00
Konrad `ktoso` Malawski
41f99fc2ae [Executors][Distributed] custom executors for distributed actor (#64237)
* [Executors][Distributed] custom executors for distributed actor

* harden ordering guarantees of synthesised fields

* the issue was that a non-default actor must implement the is remote check differently

* NonDefaultDistributedActor to complete support and remote flag handling

* invoke nonDefaultDistributedActorInitialize when necessary in SILGen

* refactor inline assertion into method

* cleanup

* [Executors][Distributed] Update module version for NonDefaultDistributedActor

* Minor docs cleanup

* we solved those fixme's

* add mangling test for non-def-dist-actor
2023-03-15 23:42:55 +09:00
Nate Chandler
ceb941d1d1 [NFC] Extracted isRedundantMoveValue.
Extracted the predicate from inline in RedundantMoveValueElimination
into the new function which can now be called from elsewhere
(CopyPropagation).
2023-03-15 07:38:59 -07:00
Erik Eckstein
318c30895f Swift Optimizer: eliminate ARC operations on types which are marked as immortal
A type (mostly classes) can be attributed with `@_semantics("arc.immortal")`.
ARC operations on values of such types are eliminated.

This is useful for the bridged SIL objects in the swift compiler sources.
2023-03-14 21:07:03 +01:00
Erik Eckstein
3fca8cd06e Swift SIL: speed up Operand.value
Instead of doing the type casts and/or conformance lookup on the swift side, do it on the C++ side.
It makes a significant performance difference because `Operand.value` is a time critical function
2023-03-14 21:07:03 +01:00
nate-chandler
20e262b35c Merge pull request #64190 from nate-chandler/redundant-move-elim
[SILOptimizer] Add RedundantMoveValueElimination.
2023-03-10 20:41:45 -08:00
Nate Chandler
af1ac900f9 [SIL] Add hasPointerEscape(SILValue).
There is a preexisting function with this name that takes a
BorrowedValue.  The new function calls that preexisting function if a
BorrowedValue can be constructed from the SILValue.  Otherwise, it looks
for direct uses of the value which qualify as "pointer escapes".
2023-03-10 10:49:53 -08:00
Michael Gottesman
d1b206b994 [move-only] Move FieldSensitivePrunedLiveness logging behind an option flag
Sometimes it is useful to have this information when debugging the move checker,
but often times it spews so much output that it is not useful.
2023-03-08 12:18:09 -08:00
Michael Gottesman
00d54ebaa8 [reference-binding] Add mark_unresolved_reference_binding to signal from SILGen to the pass to check.
Just the SIL part of this.
2023-03-03 17:14:41 -08:00
Andrew Trick
ccd08ca4b4 Add a completeOSSALifetime utility
Add local lifetime-ending operations to any owned or borrowed value.

This puts a single value into valid OSSA form so that linear lifetime
checking will pass.

Also adds UnreachableLifetimeCompletion which fixes OSSA after
converting a code path to unreachable (e.g. DiagnoseUnreachable and MandatoryInlining).
2023-03-01 21:04:09 -08:00
Andrew Trick
60d0dd6e59 Allow InteriorLiveness be run without a dominator tree. 2023-03-01 18:35:13 -08:00
Michael Gottesman
a24d46097f [sil] Teach the various address verifiers about ExplicitCopyAddrInst.
Just treating it the same as copy_addr as expected.
2023-02-17 16:04:47 -08:00
Joe Groff
69e4b95fb8 SIL: Model noescape partial_applys with ownership in OSSA.
Although nonescaping closures are representationally trivial pointers to their
on-stack context, it is useful to model them as borrowing their captures, which
allows for checking correct use of move-only values across the closure, and
lets us model the lifetime dependence between a closure and its captures without
an ad-hoc web of `mark_dependence` instructions.

During ownership elimination, We eliminate copy/destroy_value instructions and
end the partial_apply's lifetime with an explicit dealloc_stack as before,
for compatibility with existing IRGen and non-OSSA aware passes.
2023-02-16 21:43:53 -08:00
Erik Eckstein
40ed0fb388 Swift Optimizer: fix a crash when simplifying same-metatype comparisons of function types
The instance type of a metatype instruction is not necessarily a legal lowered SIL Type.
Lower the type before converting it to a SILType.

rdar://105502403
2023-02-15 21:14:32 +01:00
Erik Eckstein
748264c45f Add a unprotectedStackAlloc builtin
It's like `Builtin.stackAlloc`, but doesn't set the `[stack_protection]` flag on its containing function.
2023-02-15 08:09:38 +01:00
Andrew Trick
30f59c7367 Remove an assert from visitForwardedGuaranteedOperands
Some guaranteed forwarding instructions have multiple operands:
mark_dependence, ref_to_bridge_object.

The corresponding instruction types checked here already have
documentation that the forwarded operand is the first operand. The
assert is overly cautious, and checking for indiviudal opcodes would be
tedious maintenance.
2023-02-13 18:04:39 -08:00
John McCall
a38478724a Add a pack_length SIL instruction for measuring the length of a pack 2023-02-10 21:50:44 -05:00
Andrew Trick
13e1aa4467 Add OwnershipLiveness utilities
Encapsulate all the complexity of reborrows and guaranteed phi in 3
ownership liveness interfaces:

LinerLiveness, InteriorLiveness, and ExtendedLiveness.
2023-02-10 09:39:18 -08:00
Michael Gottesman
64ba69e3f8 Merge pull request #63556 from atrick/new-access-base-visitor
Add visitAccessPathBaseUses API
2023-02-09 21:38:54 -08:00
Andrew Trick
049d7856f4 Add visitAccessPathBaseUses API
For the move-only checker
2023-02-09 15:34:56 -08:00
eeckstein
df6677b1b6 Merge pull request #63494 from eeckstein/instruction-passes
Optimizer: Replace the MandatoryCombine pass with a Simplification pass, which is implemented in Swift
2023-02-09 10:03:31 +01:00
Michael Gottesman
97b68be9d7 Merge pull request #63530 from gottesmm/moveonly-enum-destructure
[move-only] Add support for switch_enum in borrow2destructure
2023-02-09 00:27:23 -08:00
Erik Eckstein
cef6ef9a84 SIL: add a debug_step instruction
This instruction can be inserted by Onone optimizations as a replacement for deleted instructions to
ensure that it's possible to single step on its location.
2023-02-09 06:50:05 +01:00
Erik Eckstein
b1c6ae60cd Swift SIL: add metatype APIs to Type
* `var isMetatype: Bool`
* `var instanceTypeOfMetatype: Type`
2023-02-09 06:49:58 +01:00
Erik Eckstein
713f6c3946 Swift SIL: add Type.nominal and Type.isOrContainsObjectiveCClass APIs 2023-02-09 06:49:58 +01:00
John McCall
dcf90ba3f3 Merge pull request #63512 from rjmccall/tuple_pack_element_addr
Add the tuple_pack_element_addr SIL instruction
2023-02-08 11:48:23 -05:00
John McCall
159c653780 Add the tuple_pack_element_addr SIL instruction.
This allows dynamically indexing into tuples.  IRGen not yet
implemented.

I think I'm going to need a type_refine_addr instruction in
order to handle substitutions into the operand type that
eliminate the outer layer of tuple-ness.  Gonna handle that
in a follow-up commit.
2023-02-07 23:22:35 -05:00
Michael Gottesman
d5aea69335 [sil] Refactor field sensitive pruned liveness so it can be used with different sized root values. 2023-02-07 16:27:28 -08:00
Michael Gottesman
3b72951148 [sil] Provide FieldSensitivePrunedLiveness with its own implementation of PrunedLiveBlocks called FieldSensitivePrunedLiveBlocks.
This will let the non-field sensitive version use a more performant
implementation internally. This is important since PrunedLiveBlocks is used in
the hot path when working with Ownership SSA, while the field sensitive version
is only used for certain diagnostics.

NOTE: I did not refactor PrunedLiveness to use the faster implementation... this
is just a quick pass over the code to prepare for that change.
2023-02-07 16:26:41 -08:00
Andrew Trick
2d91316c06 Merge pull request #63485 from atrick/fix-inner-adjacent
Add visitInnerAdjacentPhis OSSA helper
2023-02-07 11:34:10 -08:00