Commit Graph

1057 Commits

Author SHA1 Message Date
Andrew Trick
e1e59ac621 Handle OperandOwnerhip::NonUse in PrunedLiveness::computeSSALiveness.
Fixes a bug in the simple PrunedLiveness routine for SSA values.

Without this fix, the init_existential_ref instruction below was not
considered a lifetime-ending use because the non-use type dependednt
operand (which is not really an operand at all) would override the
forwarding operand:

  %1 = open_existential_ref %0 : $any P to $@opened("...", any P) Self
  %2 = init_existential_ref %1 : $@opened("...", any P) Self : $@opened("...", any P) Self, $AnyObject

This will be tested by silgen_cleanup_complete_ossa.sil.
2022-09-15 11:13:56 -07:00
Egor Zhdan
710443ae6f [cxx-interop][SwiftCompilerSources] Use swift::SubstitutionMap instead of BridgedSubstitutionMap
rdar://83361087
2022-09-15 14:18:31 +01:00
Egor Zhdan
3dc584e948 [cxx-interop][SwiftCompilerSources] Use swift::SILDebugLocation instead of BridgedLocation
rdar://83361087
2022-09-15 11:36:29 +01:00
Meghana Gupta
88782ac939 Don't shrink escaped borrow scopes in DCE 2022-09-14 21:02:02 -07:00
Meghana Gupta
d5f6b12830 Avoid generating address phis in LoopUnroll 2022-09-12 11:25:55 -07:00
Michael Gottesman
0a16cc362a [move-only] Implement an initial version of the move only address checker.
Some notes:

1. I added support for both loadable/address only types.

2. These tests are based off of porting the move only object tests for inout,
vars, mutating self, etc.

3. I did not include already written tests for address only types in this
specific merge since I need to change us to borrow move only var like types.
Without that, we get a lot of spurious error msgs and the burden of writing that
is not worth it. So instead in a forthcoming commit where I fix that issue in
SILGen, I will commit the corresponding address only tests for this work.

4. I did not include support for trivial types in this. I am going to do
object/address for that at the same time.
2022-09-11 18:57:32 -07:00
Michael Gottesman
467b742a5c [move-only] Update the non-address move checker part of the optimizer to handle mark_must_check on addresses. 2022-09-09 13:38:18 -07:00
eeckstein
468b7b9486 Merge pull request #60994 from eeckstein/silnodes-def
SIL: no need for `BRIDGED_...` macros in SILNodes.def
2022-09-08 15:50:00 +02:00
Erik Eckstein
e790bf225c SIL: no need for BRIDGED_... macros in SILNodes.def
It's not needed to distinguish between bridged and not bridged node classes in SILNodes.def.
NFC.
2022-09-08 12:32:26 +02:00
Erik Eckstein
97b2354be6 SIL: add needsStackProtection flags for address_to_pointer and index_addr instructions.
Also add new "unprotected" variants of the `addressof` builtins:
* `Builtin.unprotectedAddressOf`
* `Builtin.unprotectedAddressOfBorrow`
2022-09-08 08:42:22 +02:00
Erik Eckstein
fdca208335 SIL: add the SILFunction.needsStackProtection flag
Indicates that stack protectors are inserted into this function to detect stack related buffer overflows.
2022-09-08 08:37:21 +02:00
Hamish Knight
b12015c343 [SIL] Introduce the increment_profiler_counter instruction
This is a dedicated instruction for incrementing a
profiler counter, which lowers to the
`llvm.instrprof.increment` intrinsic. This
replaces the builtin instruction that was
previously used, and ensures that its arguments
are statically known. This ensures that SIL
optimization passes do not invalidate the
instruction, fixing some code coverage cases in
`-O`.

rdar://39146527
2022-09-07 17:55:13 +01:00
Michael Gottesman
4dc6e6ecc4 [move-keyword] Remove old implementation.
By using the keyword instead of the function, we actually get a much simpler
implementation since we avoid all of the machinery of SILGenApply. Given that we
are going down that path, I am removing the old builtin implementation since it
is dead code.

The reason why I am removing this now is that in a subsequent commit, I want to
move all of the ownership checking passes to run /before/ mandatory inlining. I
originally placed the passes after mandatory inlining since the function version
of the move keyword was transparent and needing to be inlined before we could
process it. Since we use the keyword now, that is no longer an issue.
2022-09-04 01:19:01 -07:00
Erik Eckstein
32af2dd5a4 Swift SIL: an autogenerated Location needs to keep the debug scope.
Therefore, instead of creating an autogenerated location with a null scope, make an existing location `autoGenerated`.
2022-09-02 08:56:38 +02:00
Erik Eckstein
082aec0990 Swift SIL: add var FunctionArgument.convention
Also:
* move the `ArgumentConvention` enum from Function.swift to Argument.swift.
* `FunctionArgument.isExclusiveIndirectParameter` -> `ArgumentConvention.isExclusiveIndirect`
* add `ArgumentConvention.isInout`
2022-09-02 07:11:49 +02:00
Michael Gottesman
7c452ca400 [pruned-liveness] Implement FieldSensitiveAddressPrunedLiveness.
This is the same algorithm as pruned liveness but assumes that one is tracking
liveness from an address and uses the same scheme as DI to track liveness as a
bit vector.
2022-08-30 17:25:55 -07:00
Erik Eckstein
f7aaa35092 Swift SIL: fix KeyPathInst.visitReferencedFunctions
It crashed for keypath instructions with zero components.
2022-08-26 18:00:11 +02:00
Erik Eckstein
f6e6b2ecf3 Swift SIL: add the possibility to pass a custom location to Builder initializers.
And add the static property `Location.autoGeneratedLocation`
2022-08-26 18:00:11 +02:00
Erik Eckstein
2745565a83 Swift SIL: correctly bridge "invalid" witness table entries.
Originally, I thought that couldn't appear in valid SIL, but there are "no_default" entries in default witness tables, which map to "invalid" entries.
2022-08-26 18:00:11 +02:00
Erik Eckstein
2fe1ee5533 Swift SIL: add a few Builder functions
* add `createAllocStack`
* add `createDeallocStack`
* add `createCopyAddr`
* add `@discardableResult` to the existing `createDeallocStackRef`
2022-08-24 17:55:02 +02:00
Erik Eckstein
bfb284f827 Swift SIL: add a few instructions and Instruction.visitReferencedFunctions
* add `DynamicFunctionRefInst` and `PreviousDynamicFunctionRefInst`
* add a common base class to all function-referencing instructions: `FunctionRefBaseInst`
* add `KeyPathInst`
* add `IndexAddrInst.base` and `IndexAddrInst.index` getters
* add `Instruction.visitReferencedFunctions` to visit all functions which are referenced by an instruction
2022-08-24 17:55:02 +02:00
Erik Eckstein
fbb694bcde Swift SIL: add bridging for witness and default witness tables 2022-08-24 17:55:02 +02:00
Erik Eckstein
7816513f0d Swift SIL: add bridging for vTables 2022-08-24 17:55:02 +02:00
Erik Eckstein
fe40707d5e Swift SIL: add Function.isPossiblyUsedExternally and Function.isAvailableExternally 2022-08-24 17:54:46 +02:00
eeckstein
210b39df91 Merge pull request #60646 from eeckstein/improve-accessutils
Swift AccessUtils: improvements and bug fixes
2022-08-24 09:31:34 +02:00
Michael Gottesman
a95e018354 Merge pull request #60710 from gottesmm/pr-1212688e62da727448883168d77ba9b98fa6d4dc
[pruned-liveness] Teach PrunedLiveBlocks how to handle liveness for multiple bits.
2022-08-23 15:49:54 -07:00
Michael Gottesman
36893aa260 Merge pull request #60717 from gottesmm/pr-00503aff6555a1f03b7b992c1db47b30ca05eaa9
[move-only] Add support for explicit_copy_addr in a few places in MemAccessUtils that I missed when introducing the instruction.
2022-08-22 23:37:58 -07:00
Michael Gottesman
7361639a85 [move-only] Add support for explicit_copy_addr in a few places in MemAccessUtils that I missed when introducing the instruction.
I discovered these were missing when using explicit_copy_addr with the move only
address checker.
2022-08-22 17:29:52 -07:00
Nate Chandler
e2698edb7c [MemAccessUtils] Non-trivial Cxx node is leaf.
Nodes which are non-trivial C++ decls must be destroyed, they cannot be
destroyed by way of destroying their subobjects.  This was exposed by
producing more non-lexical alloc_stacks which enjoy more aggressive
destroy_addr hoisting.
2022-08-22 15:28:00 -07:00
Michael Gottesman
e51e17fa5e [pruned-liveness] Change the internal bit-vector to use 2 bits to represent its state instead of 1 + missing value in DenseMap.
The reason why I am doing this is that in order to be able to use
PrunedLivenessBlocks with multiple elements, we can no longer rely on dead being
represented by a block not having any state, since a dead bit could have a
neighboring live bit.

That being said, the only place that this is used now is the current
PrunedLiveness implementation which only stores a single bit... but that still
at least exercises the code and lets us know that it works.
2022-08-22 13:26:34 -07:00
Michael Gottesman
04144d8214 [pruned-liveness] Change PrunedLiveBlocks so that it can propagate multiple bits of liveness rather than just one.
This is useful for making a form of PrunedLiveness that is sensitive to address
fields. I wired up the current PrunedLiveness to just use PrunedLiveBlocks with
num bits set to 1.
2022-08-22 12:11:18 -07:00
Erik Eckstein
05d62293e6 Swift SIL: add NominalFieldsArray.getNameOfField(withIndex:) 2022-08-22 13:22:06 +02:00
Michael Gottesman
3e52007562 [builtin] Remove "unsafeGuaranteed" and related code since Unmanaged now has an Ownership SSA based implementation that works completely in SILGen.
This isn't used in the stdlib anymore as well.
2022-08-21 01:22:36 -07:00
Meghana Gupta
f374f2bad3 Handle store_borrow in MemAccessUtils 2022-08-17 16:26:17 -07:00
Meghana Gupta
98fa7f079f Handle ValueMetatypeInst as a leaf user in swift::findTransitiveUsesForAddress 2022-08-16 15:08:23 -07:00
Meghana Gupta
bf7cbb5504 Add new utilities for store borrow extension and ending store borrow scope 2022-08-16 15:08:22 -07:00
Meghana Gupta
5244e6f3d5 Improve verification for store_borrow
Add ScopedAddressOperand and ScopedAddressValue abstraction utilities
Introduce verification for store_borrow to validate its uses are correctly enclosed in their scope.

Include end_borrow/end_access as implicit uses while validating a borrow introducer

Add flow sensitive verifier rule for store_borrow/end_borrow pair

Make sure store_borrow is always to an alloc_stack

Make sure uses to store borrow location are via its return address only
2022-08-16 15:08:22 -07:00
Anxhelo Xhebraj
633cc340ac Merge pull request #60512 from Angelogeb/accessutils-pr
Adds a set of utilities and concepts (AccessBase, AccessPath and AccessStoragePath) to
identify and analyze formal accesses in SIL.
2022-08-12 14:16:19 -07:00
Michael Gottesman
5baf2af88a [sil] Add a new instruction called explicit_copy_addr.
This is exactly like copy_addr except that it is not viewed from the verifiers
perspective as an "invalid" copy of a move only value. It is intended to be used
in two contexts:

1. When the move checker emits a diagnostic since it could not eliminate a copy,
we still need to produce valid SIL without copy_addr on move only types since we
will hit canonical SIL eventually even if we don't actually codegen the SIL. The
pass can just convert said copy_addr to explicit_copy_addr and everyone is
happy.

2. To implement the explicit copy function for address only types.
2022-08-11 11:40:53 -07:00
Anxhelo Xhebraj
e748f01d90 Swift SIL: add constant checking for ref_element_addr field and global 2022-08-11 10:16:40 -07:00
Anxhelo Xhebraj
303ed781ff Swift SIL: add AccessKind to BeginAccess 2022-08-11 10:16:40 -07:00
Michael Gottesman
1e6187c4f4 [sil] Update all usages of old API SILValue::getOwnershipKind() in favor of new ValueBase::getOwnershipKind().
Andy some time ago already created the new API but didn't go through and update
the old occurences. I did that in this PR and then deprecated the old API. The
tree is clean, so I could just remove it, but I decided to be nicer to
downstream people by deprecating it first.
2022-07-26 11:46:23 -07:00
Egor Zhdan
8165806aa0 Merge pull request #60174 from apple/egorzhdan/scs-stringref-p1
[cxx-interop][SwiftCompilerSources] Use `llvm::StringRef` instead of `BridgedStringRef`
2022-07-25 14:26:59 +01:00
nate-chandler
83d97819ad Merge pull request #60121 from nate-chandler/rdar94346482
[SILOpt] Handle reborrows of owned phis in CanonicalizeOSSALifetime.
2022-07-22 11:08:02 -07:00
Nate Chandler
fe435312a1 [OwnershipUtils] Visit owned phi's reborrows.
The new utility, given an phi, visits all adjacent phis (i.e. arguments
to the same block) which are (potentially iterated) reborrows of a value
reaching the given phi.
2022-07-21 15:03:43 -07:00
Egor Zhdan
0e2d438c5b [cxx-interop][SwiftCompilerSources] Use llvm::StringRef instead of BridgedStringRef
rdar://83361000
2022-07-21 16:32:16 +01:00
Michael Gottesman
9b625588f0 [sil] Make copyable_to_moveonlywrapper forwarding like moveonlywrapper_to_copyable.
Specifically this means that rather than always being owned, we now have owned
and guaranteed versions of copyable_to_moveonlywrapper. Similar to
moveonlywrapper_to_copyable, one chooses which variant one gets by using
specific SILBuilder APIs:
create{Owned,Guaranteed}CopyableToMoveOnlyWrapperValueInst. It is still
forwarding and the rest of the forwarding APIs work as expected except that the
forwarding ownership is fixed (and an assertion will result if one attempts to
do so).

NOTE: It is assumed that trivial operands are always passed to the owned
variant.
2022-07-19 14:39:59 -07:00
nate-chandler
aff4e799d9 Merge pull request #59726 from nate-chandler/freestanding/task-to-thread-model
[Freestanding] Disable unstructured tasks.
2022-07-11 07:40:31 -07:00
Nate Chandler
34c08b8344 [TaskToThread] Add Task.runInline.
The new intrinsic, exposed via static functions on Task<T, Never> and
Task<T, Error> (rethrowing), begins an asynchronous context within a
synchronous caller's context.  This is only available for use under the
task-to-thread concurrency model, and even then only under SPI.
2022-07-08 08:44:18 -07:00
eeckstein
224cac56ec Merge pull request #59916 from eeckstein/perf-annotation-fixes
Several fixes for performance diagnostics
2022-07-07 13:58:06 +02:00