Commit Graph

6583 Commits

Author SHA1 Message Date
Michael Gottesman
058345740d [sil] Add a try_emplace/simple failable get method to BasicBlockData. 2022-09-09 13:38:18 -07:00
Michael Gottesman
925a211ed8 Merge pull request #60989 from gottesmm/pr-d5933fd70a08a0acd36e29c39312cf34cc50f904
[move-only] Fix a few small issues around mark must check.
2022-09-08 13:19:53 -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
Michael Gottesman
03986db44f [mem-access] Teach mem-access about mark_must_check. 2022-09-07 18:20:33 -07: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
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
Andrew Trick
c14059e92c [comment] Add a semantics note to SIL BindMemory 2022-08-29 13:20:45 -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
Erik Eckstein
beebd5a920 PassManager: add a invalidation kind for non-body function data
E.g. used if function effects are changed. This tells the passmanager that something changed, but no SIL-specific analysis have to be invalidated.
2022-08-24 17:54:46 +02:00
Slava Pestov
046c2040ce Merge pull request #60726 from slavapestov/variadic-generics-bits
AST: Plumbing for pack conformances and a few other variadic generics bits
2022-08-24 08:59:40 -04: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
Slava Pestov
5c32f2136e AST: Introduce RequirementKind::SameCount 2022-08-23 11:12:00 -04:00
Nate Chandler
e9595ab845 [TypeLowering] Verify lexical property.
Check that if a type is non-trivial then either (1) it is lexical or (2)
its non-trivial leaves are @_eagerMove.
2022-08-22 15:28:00 -07:00
Nate Chandler
496c1d2194 [SIL] Added SILType::isAggregate. 2022-08-22 15:28:00 -07:00
Nate Chandler
3c78a0bb90 [SILGen] Only lexical types get lexical lifetimes.
Only emit `begin_borrow [lexical]` and only mark `alloc_stack`s
`[lexical]` when the variable in question's lifetime is lexical, not
eager move.
2022-08-22 15:28:00 -07:00
Nate Chandler
eb3f8002ed [SIL] Added SILType::getLifetime.
The function describes the lifetime that variables of that type have by
default (unless otherwise annotated).  This is done by looking at leaf
nodes until one that is not eager move is found, at which point the
lifetime is known to be lexical.  Otherwise, the lifetime is eager move
(i.e. if every leaf is eager move).
2022-08-22 15:27:59 -07:00
Nate Chandler
6f582336bf [TypeLowering] Record whether a type is lexical.
Used RecursiveProperties to keep track of whether a type is lexical.

This is done in the usual way by OR'ing together whether components are
lexicial.  The the values to be OR'd together come from primitives:
everything is non-lexical except reference types and resilient types
(because they could become reference types).  Those values can however
be affected by user annotations: marking a class @_lexical makes the
value for that primitive lexical; markinig an enum or struct @_eagerMove
overrides the value obtained by OR'ing together its components and makes
it be non-lexical.
2022-08-22 15:27:59 -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
Nate Chandler
8074ce087d [SIL] Function args may have lifetime annotations.
By default, whether a function argument's lifetime is determined by its
type.  To allow that behavior to be overridden on an
argument-by-argument basis, the argument may have its own lifetime.
2022-08-21 21:44:31 -07:00
Nate Chandler
f3ea548a3e [SIL] Added simple Lifetime enum.
The new enum makes keeping track of what flavor of lifetime values ought
to have a little bit type-safer.
2022-08-21 21:44:31 -07:00
Nate Chandler
8450e37ddb [SIL] Removed SILArgument::isNoImplicitCopy.
The attribute can't be applied to non-function arguments and may cause
confusion by being available on them.
2022-08-21 21:44:30 -07:00
Allan Shortlidge
40eb1422bb IRGen/SIL: Fix IR linkage computation for inlined function references from modules imported @_weakLinked.
Include the parent `ModuleDecl` when serializing a `SILFunction` so that it is available on deserialized functions even though the full `DeclContext` is not present. With the parent module always available we can reliably compute whether the `SILFunction` comes from a module that was imported `@_weakLinked`.

Serialize the `DeclContext` member of `SILFunction` so that it can be used to look up the module that a function belongs to in order to compute weak import status.

Resolves rdar://98521248
2022-08-19 09:56:45 -07:00
swift-ci
ba001ec4fe Merge pull request #60467 from meg-gupta/fixstoreborrowsilgen
Fix store_borrow generation and improve its verification
2022-08-17 20:27:08 -07:00
Meghana Gupta
f374f2bad3 Handle store_borrow in MemAccessUtils 2022-08-17 16:26:17 -07:00
Michael Gottesman
65b7777e3c [pruned-liveness] Fix incorrect header comment that didn't describe the algorithm correctly. 2022-08-17 12:35:45 -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
69d6781338 Update utility to allow end_borrow on addresses which have OwnershipKind::None 2022-08-16 15:08:22 -07:00
Meghana Gupta
c3ef007979 Fix store_borrow cloning when we are cloning into a function w/o ownership
Map store_borrow return_address with the destination, so that while cloning a store_borrow into a function w/o ownership,
users of store_borrow return address can be mapped with the lowered store's destination.
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
Slava Pestov
cfb4e60a48 Merge pull request #60523 from slavapestov/fix-opened-generic-environment-identity
Serialization: Preserve identity of opened generic environments
2022-08-16 14:33:44 -04:00
Slava Pestov
9c094c59a2 SIL: Simplify SILCloner::remapRootOpenedType() 2022-08-16 11:54:22 -04:00
Mishal Shah
91b2abe996 Merge pull request #60531 from apple/pull-request-rebranch
Merge `rebranch` into  `main` to support llvm-project `stable/20220421`
2022-08-15 17:10:56 -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
swift-ci
117d22acd9 Merge remote-tracking branch 'origin/main' into rebranch 2022-08-11 16:34:43 -07:00
Michael Gottesman
accc2820f8 Merge pull request #60511 from gottesmm/pr-0796eed23b86f5812f817b15b928dbe11485c361
[move-only-addresses] Slicing some patches off of the larger patch.
2022-08-11 16:25:10 -07:00