Commit Graph

6583 Commits

Author SHA1 Message Date
Meghana Gupta
18fd845732 Create begin_borrow in OSSA only
Fixes rdar://103512260

Creating begin_borrow in non-ossa can raise asserts or reach unreachable in some utils.
2022-12-20 14:37:37 -08:00
Pavel Yaskevich
b83b0943b5 [SILDeclRef] RuntimeMetadata: Add a special kind for runtime attribute generator
A new `RuntimeAttributeGenerator` is used to reference runtime
attribute generator functions synthesized by SILGen.
`#function` magic literal points to the declaration that declaration
attribute is attached to.
2022-12-20 09:45:01 -08:00
Pavel Yaskevich
3fb69b3c3c [SIL] SILFunction: Add runtime accessible function attribute
This attribute indicates that the given SILFunction has to be
added to "accessible functions" section and could be looked up
at runtime using a special API.
2022-12-20 09:33:44 -08:00
Pavel Yaskevich
84c2ff6445 [SILDeclRef] Make it possible to identify references to runtime accessible entities
`asRuntimeAccessible` is going to be coupled with a flag on `SILFunction`
and would allow IRGen to emit such functions into a special section.
2022-12-20 09:33:44 -08:00
Andrew Trick
02f7450759 At -Onone preserve debug info after splitting loads
Load splitting converts an aggregate load into a set of subobject
loads. This is required at -Onone for exclusivity diagnostics.

We cannot preserve the original debug information by redirecting debug
info to the memory address, because that might result in incorrect
debug values if the memory is reused.

Before this fix, we "conservatively" drop debug info in those
cases. This fix preserves full debug info by keeping the original
aggregate load intact alongside the new subobject loads. To avoid
exclusivity violations, it create a new unsafe access scope for the
old load.

Fixes LLDB missing variables in certain case #62241
2022-12-19 00:02:18 -08:00
Meghana Gupta
6ee4c17abe Merge pull request #62573 from meg-gupta/sbiverify
Update store_borrow checking in MemoryLifetimeVerifier and fix ForEachLoopUnroll and GenericCloner
2022-12-15 09:53:00 -08:00
Michael Gottesman
6fff307328 Merge pull request #62592 from gottesmm/pr-cbfd912fd4d58ff272d3f1fe4ceb8cf02589da9a
[sil] Add a new attribute called @closureCaptured to SILFunctionArguments that are closure capture arguments.
2022-12-15 01:14:46 -08:00
John McCall
6d4588c40b Change SIL to track all LocalArchetypes and not just OpenedArchetypes. 2022-12-14 19:43:23 -05:00
Michael Gottesman
9e44011e4d [sil] Add a new attribute called @closureCaptured to SILFunctionArguments that are closure capture arguments.
I am adding this to make it easy to determine if a SILFunction that is not inout
aliasable is captured. This is useful when emitting certain types of
diagnostics like I need to emit with move only.
2022-12-14 15:16:43 -08:00
Meghana Gupta
b79a383386 Delete unused/vague apis 2022-12-14 02:11:19 -08:00
swift-ci
6d0a3257a3 Merge pull request #62454 from meg-gupta/guaranteedforwardingphiverify
Update guaranteed forwarding phi apis and verification
2022-12-13 20:04:00 -08:00
Meghana Gupta
511739b494 Delete OperandOwnership::GuaranteedForwardingPhi
Use OperandOwnership::GuaranteedForwarding instead.
2022-12-13 12:51:31 -08:00
Meghana Gupta
b10563909c Update isGuaranteedForwarding api and delete isGuaranteedForwardingPhi api 2022-12-13 12:51:25 -08:00
John McCall
f524f3de69 [NFC] Support instructions that define multiple opened archetypes
I've also fixed this so that it should work on instructions that
define multiple values.  Someday we'll change all the open_existential
instructions to produce different values for the type dependency and
the value result; today is not that day, though.
2022-12-13 13:28:13 -05:00
eeckstein
cb6737269d Merge pull request #62480 from eeckstein/instruction-iteration
SIL: simplify deleting instructions while iterating over instructions.
2022-12-13 10:45:06 +01:00
Andrew Trick
f9861ec9c0 Add APIs for terminator results that forward ownership.
Add TermInst::forwardedOperand.

Add SILArgument::forwardedTerminatorResultOperand. This API will be
moved into a proper TerminatorResult abstraction.

Remove getSingleTerminatorOperand, which could be misused because it's
not necessarilly forwarding ownership.

Remove the isTransformationTerminator API, which is not useful or well
defined.

Rewrite several instances of complex logic to handle block arguments
with the simple terminator result API. This defines away potential
bugs where we don't detect casts that perform implicit conversion.

Replace uses of the SILPhiArgument type and code that explicitly
handle block arguments. Control flow is irrelevant in these
situations. SILPhiArgument needs to be deleted ASAP. Instead, use
simple APIs like SILArgument::isTerminatorResult(). Eventually this
will be replaced by a TerminatorResult type.
2022-12-12 12:37:35 -08:00
Andrew Trick
fe44dce4e7 Add SILValue::getDefiningInstructionOrTerminator().
This allows code to handle terminator results similar to any other
instruction result. Data flow should generally handle terminator
results like any other instruction that may forward operand ownership
to its results. The fact that it is represented as a block argument is
an implementation detail that gets in the way of conceptual
simplicity.
2022-12-12 12:23:40 -08:00
Erik Eckstein
a8ba48e71d Swift SIL: add Instruction.isDeleted API 2022-12-12 19:08:57 +01:00
Erik Eckstein
9e0b86ddbd Swift SIL: add Builder.createUnreachable() 2022-12-12 19:08:57 +01:00
Erik Eckstein
c180d1363e SIL: simplify deleting instruction while iterating over instructions.
Add `deletableInstructions()` and `reverseDeletableInstructions()` in SILBasicBlock.
It allows deleting instructions while iterating over all instructions of the block.
This is a replacement for `InstructionDeleter::updatingRange()`.
It's a simpler implementation than the existing `UpdatingListIterator` and `UpdatingInstructionIteratorRegistry`, because it just needs to keep the prev/next pointers for "deleted" instructions instead of the iterator-registration machinery.
It's also safer, because it doesn't require to delete instructions via a specific instance of an InstructionDeleter (which can be missed easily).
2022-12-12 19:08:54 +01:00
Erik Eckstein
05a63c70c5 SIL: change way how a SILInstruction is marked as deleted
Instead of setting the parent pointer to null, set the `lastInitializedBitfieldID` to -1.
This allows to keep the parent block information, even when an instruction is removed from it's list.
2022-12-12 19:06:00 +01:00
Erik Eckstein
d8c2e8ae77 SIL: change SILModule's scheduledForDeletion from a double linked list to a std::vector 2022-12-12 19:05:59 +01:00
Erik Eckstein
2ca9a3b9ce SIL: fix APIs for (re)moving instructions
Instructions can only be moved and erased, but never _removed_ from a block.
2022-12-12 19:05:59 +01:00
nate-chandler
48f63c5055 Merge pull request #62502 from nate-chandler/remove-silvalue-getownershipkind
[NFC] Removed SILValue::getOwnershipKind.
2022-12-12 07:29:54 -08:00
Nate Chandler
8d8577e5b0 [SIL] Removed Indirect_In_Constant convention.
It is no different from @in.

Continue parse @in_constant in textual and serialized SIL, but just as
an alias for @in.
2022-12-09 21:54:00 -08:00
Nate Chandler
fff993a31b [NFC] Removed SILValue::getOwnershipKind.
It has been deprecated for awhile.
2022-12-09 18:30:10 -08:00
nate-chandler
d5e8625db9 Merge pull request #62442 from nate-chandler/opaque-values/1/20221201
[AddressLowering] Handle indirectly yielded values used outside of coroutine range.
2022-12-09 07:00:16 -08:00
Nate Chandler
8617a5d751 [SIL] Marked @in_constant as owned.
Matches the behavior of the memory lifetime verifier (and
OperandOwnership which was updated to match the memory lifetime verify
at 65fe910130).
2022-12-08 18:29:16 -08:00
Nate Chandler
e1cb0b5522 [MemAccessUtils] Look thru nested for guar roots.
Previously, findGuaranteedReferenceRoots always stopped searching when
finding a begin_borrow, because it's not an ownership-forwarding
instruction.  Here, it is conditionally allowed to keep search through
the borrowee of that begin_borrow if it itself is guaranteed.
2022-12-08 18:29:14 -08:00
Michael Gottesman
d1d3c1262e Merge pull request #62464 from gottesmm/pr-6d0c4626f8ea10597ecc6b876f1bbfd6432cd4db
[move-addr] Move Field Sensitive Pruned Liveness into its own header/cpp impl.
2022-12-08 15:07:25 -08:00
Michael Gottesman
3f90afb901 [move-addr] Move Field Sensitive Pruned Liveness into its own header/cpp impl. 2022-12-08 10:29:48 -08:00
Slava Pestov
c8100bd321 Merge pull request #62414 from slavapestov/variadic-metatypes
Allow forming PackExpansionTypes in expression context
2022-12-07 17:43:45 -05:00
Slava Pestov
f9141e1aa1 SIL: Stub out type lowering of function types containing pack expansions 2022-12-06 14:15:07 -05:00
Hamish Knight
d59ff45468 [Profiler] Track the parent SourceFile for a SILCoverageMap
This tracks the source file that the profiled
entity was defined in.
2022-12-06 14:28:34 +00:00
swift-ci
5d3232f1b8 Merge pull request #62189 from nate-chandler/opaque-values/1/20221118
[AddressLowering] Shorten stack lifetimes.
2022-12-05 17:56:06 -08:00
nate-chandler
cfbd52d5a0 Merge pull request #62343 from nate-chandler/opaque-values/1/20221130
[TypeConverter] Track address lowering.
2022-12-05 09:22:27 -08:00
Nate Chandler
4d42269e3b [Gardening] Fixed typo. 2022-12-04 11:40:59 -08:00
Nate Chandler
e9e93c1590 [Opaque Values] Address-lower TypeLowerings.
When opaque values are enabled, TypeConverter associates to an
address-only type an OpaqueValueTypeLowering.  That lowering stores a
single lowered SIL type, and its value category is "object".  So long as
the module has not yet been address-lowered, that type has the
appropriate value category.  After the module has been address-lowered,
however, that type has the wrong value category: the type is
address-only, and in an address-lowered module, its lowered type's value
category must be "address".

Code that obtains a lowered type expects the value category to reflect
the state of the module.  So somewhere, it's necessary to fixup that
single lowered type's value category.

One option would be to update all code that uses lowered types.  That
would require many changes across the codebase and all new code that
used lowered types would need to account for this.

Another option would be to update some popular conveniences that call
through to TypeConverter, for example those on SILFunction, and ensure
that all code used those conveniences.  Even if this were done
completely, it would be easy enough for new code to be added which
didn't use the conveniences.

A third option would be to update TypeLowering::getLoweredType to take
in the context necessary to determine whether the stored SILType should
be fixed up.  That would require each callsite to be changed and
potentially to carry around more context than it already had in order to
be able to pass it along.

A fourth option would be to make TypeConverter aware of the
address-loweredness, and to update its state at the end of
AddressLowering.

Updating TypeConverter's state would entail updating all cached
OpaqueValueTypeLowering instances at the end of the AddressLowering
pass.  Additionally, when TypeConverter produces new
OpaqueValueTypeLowerings, they would need to have the "address" value
category from creation.

Of all the options, the last is least invasive and least error-prone, so
it is taken here.
2022-12-01 14:18:17 -08:00
nate-chandler
d069fff105 [SILDebugInfo] Only print under !NDEBUG. (#62325) 2022-11-30 13:11:50 -08:00
Cyndy Ishida
af742ad02b [TBDGen] Ensure classes that emit ObjC MetaClass also emit (#62283)
matching ObjC Class symbols

This is to account for swift class definitions that have objc class
ancestory.

resolves: rdar://102525824
2022-11-29 07:14:42 -08:00
Erik Eckstein
ab1b343dad use new llvm::Optional API
`getValue` -> `value`
`getValueOr` -> `value_or`
`hasValue` -> `has_value`
`map` -> `transform`

The old API will be deprecated in the rebranch.
To avoid merge conflicts, use the new API already in the main branch.

rdar://102362022
2022-11-21 19:44:24 +01:00
Xi Ge
c5a7eff0c9 Merge pull request #62147 from tshortli/has-symbol-sil-instruction 2022-11-18 04:34:24 -08:00
Anton Korobeynikov
a5e83817b2 Reapply "Implement several peephole optimizations to unblock further optimizations of autodiff code" with correctness fix (#62012)
* Implement several peephole optimizations to unblock further optimizations of autodiff code

1. Simplify differentiable_function_extract of differentiable_function.
Before:
%x = differentiable_function(%orig, %jvp, %vjp)
%y = differentiable_function_extract [original] %x
After:
%y = %orig

2. Push conversion instructions inside of differentiable_function.
This unblocks inlining and specialization.
Before:
%x = differentiable_function(%orig, %jvp, %vjp)
%y = convert_escape_to_noescape %x
After:
%orig' = convert_escape_to_noescape %orig
%jvp' = convert_escape_to_noescape %jvp
%vjp' = convert_escape_to_noescape %vjp
%y = differentiable_function(%orig', %jvp', %vjp')

3. Another peephole is needed for reordering function conversion instructions to enable full inlining:
(convert_escape_to_noescape (convert_function (thin_to_thick_function x)))
=>
(convert_escape_to_noescape (thin_to_thick_function (convert_function x)))

Co-authored-by: Dan Zheng <danielzheng@google.com>
2022-11-16 23:21:27 -08:00
Allan Shortlidge
3da18b6e68 SIL: Serialize and deserialize has_symbol instructions. 2022-11-16 16:07:59 -08:00
Allan Shortlidge
ae32b8e148 IRGen: Implement lowering of has_symbol SIL instruction. 2022-11-16 16:07:29 -08:00
Allan Shortlidge
abdc4d9112 SILGen: Use has_symbol instruction in SILGen. 2022-11-16 16:07:29 -08:00
Allan Shortlidge
0a24042cdd SIL: Introduce the has_symbol SIL instruction. 2022-11-16 16:07:26 -08:00
Erik Eckstein
8ca0143279 Remove uses of std::iterator
It's deprecated in C++17
2022-11-14 09:35:40 +01:00
Cyndy Ishida
98fa58408f [swift][TBDGen] Stop adding redundant ObjC Classes (#62068)
TBD files contain a section reserved for obj-c classes. Previously,
TBDGen was adding symbols with this + normal globals with objc class
prefixes. This patch removes the extra globals being added.

This also accounts for this behavior for `validate-tbd-against-ir`
checking.

Resolves: rdar://101442087
2022-11-11 20:36:31 -08:00
Erik Eckstein
0eacaabfef SIL: add SILArgument::isErased()
Similar to SILInstruction, it's now possible to check if an argument was erased from a SILBasicBlock.
2022-11-11 07:58:51 +01:00