Commit Graph

1065 Commits

Author SHA1 Message Date
Nate Chandler
6b6e585d54 [MemAccessUtils] Visit product type tree of addr.
Added a function that visits the leaves of the type/projection tree of
the specified address and calls its visitor with the path node to and
type of each.
2022-03-14 09:45:47 -07:00
Nate Chandler
c1adf24abc [MemAccessUtils] Returned visitor's return. 2022-03-09 10:12:10 -08:00
Ben Langmuir
779bdf0bf3 Merge pull request #41550 from benlangmuir/make-next-less-sad
Pre-fix some build failures that we'll see with newer llvm
2022-03-02 09:23:07 -08:00
Nate Chandler
6226fa7f5c [MemAccessUtils] Regard end/abort_apply as use.
Unique storage use visitor was not previously considering end_apply and
abort_apply as uses of an address even when the begin_apply took that
address as an argument.  They are uses of it though because the address
may be stored into the coroutine's frame and used when the second
partial function is invoked.
2022-02-25 07:17:09 -08:00
Ben Langmuir
35478637d3 Migrate from SmallVector.set_size to resize_for_overwrite
In the "next" branch, set_size has been made protected. Instead, users
can use resize_for_overwrite, optionally followed by truncate, to
handle the same use cases more safely.
2022-02-24 13:54:22 -08:00
Nate Chandler
8a81d41514 [MemAccessUtils] Corrected inverted condition.
The function mayAccessPointer is attempting to determine whether the
specified instruction accesses a raw/unsafe pointer of unknown
provenance.  To do that, it visits all the address operands and checks
whether any of them have an ::Unidentified access representation kind.

Previously, the condition was inverted: all address uses _except_ those
whose kinds were unidentified were judged to be potential accessors to
raw/unsafe pointers.  Here that's fixed by inverting the condition.  To
help clarify things, the variable name is changed too.
2022-02-24 13:06:27 -08:00
Rintaro Ishizaki
7486cd1c21 [SwiftCompiler] Move common bridging facilities to 'Basic'
A preparation for AST/DiagnosticEngine bridging
2022-02-20 22:06:39 -08:00
Nate Chandler
d227cef874 [MemAccessUtils] Visit access as unique storage uses.
Add a new member functino UniqueStorageUseVisitor::visitBeginAccess and
call it when GatherUniqueStorageUses runs.
2022-02-18 10:10:17 -08:00
nate-chandler
a3709b0ab4 Merge pull request #41450 from atrick/rauw-fix-rebase
Temporary fix for OSSA RAUW utilities.
2022-02-18 07:23:48 -08:00
Andrew Trick
9dba1c1fb5 Temporary fix for OSSA RAUW utilities.
This fix unblocks unrelated optimizer commits. A unit test will be
introduced with those commits.

The RAUW utility does not correctly handle reborrows. It is in the
middle of being rewritten. For now, simply bail out since this isn't
an important case to optimize.
2022-02-17 23:55:32 -08:00
nate-chandler
0011b075fa Merge pull request #41387 from nate-chandler/lexical_lifetimes/destroy_hoisting/add
Hoist destroys of owned lexical values.
2022-02-17 11:36:50 -08:00
Andrew Trick
bad72e2d62 Don't allow findInnerTransitiveGuaranteedUses to exit early.
Useful for inserting on-the-fly lexical borrow scopes to cover only
the known uses ignoring pointer escapes.
2022-02-16 12:23:01 -08:00
Andrew Trick
218f33e216 Add a FIXME to remove PrunedLiveness::nonLifetimeEndingUsesInLiveOut
Looks like it was added as a bootstrapping hack but doesn't belong
here and won't work in general.
2022-02-16 12:23:01 -08:00
Andrew Trick
8f20da7024 Add computeDominanceFrontier().
A trivial utility that returns the leaf blocks in a dominance subtree.
2022-02-16 12:23:01 -08:00
Nate Chandler
c3a81f0334 [OwnershipUtils] Fixed uses of simple value.
Previously, a typo resulted in failing to add end_borrows to the list of
uses.
2022-02-16 10:31:24 -08:00
Andrew Trick
83b01d8ebe Improve the SILPhiArgument API
This subclass of SILArgument should be eliminated--it's not always a
phi, and whether it is a "phi argument" has nothing whatsoever to do
with the opcode. That is a property of a value's uses, not a property of the
value.

Until then, provide a logical and useful API within the type. This
often avoids the need to explicitly cast to a SILPhiArgument type and
avoids a lot of boilerplate in code that deals with phis.

Note: PhiOperand and PhiValue are improved abstractions on top of this
API. But the SILArgument-level API is still an important bridge
between SILArgument and other phi abstractions.
2022-02-15 13:28:46 -08:00
Andrew Trick
05224aaa1f Improve the SILInstruction::getOperandValues() API.
Add NonTypeDependentOperandToValue predicate for composability.

Add a getNonTypeDependentOperandValues(), which can be used as a functor.

The skipTypeDependentOperands parameter complicated the API.
2022-02-15 13:24:29 -08:00
nate-chandler
827df0110f Merge pull request #41310 from nate-chandler/lexical_lifetimes/destroy_hoisting/enable
[SILOpt] Enabled SSADestroyHoisting.
2022-02-14 15:52:48 -08:00
nate-chandler
63161e6ee5 Merge pull request #41228 from nate-chandler/lexical_lifetimes/owned_function_args_are_lexical
[SIL] Make owned function arguments lexical.
2022-02-11 18:11:59 -08:00
Nate Chandler
e91b08b2fb [MemAccessUtils] Bailed when visitor bailed.
Previously, in GatherUniqueStorageUses::visiteUse, the results of calls
to visit#### on the visitor were not used.  Here, they are returned from
the function.
2022-02-10 20:17:37 -08:00
Nate Chandler
d23139ff15 [OwnershipUtils] Added find for simple value. 2022-02-10 16:28:35 -08:00
Erik Eckstein
88219da06c PerformanceDiagnostics: don't issue a metatype diagnostics when using MemoryLayout
The metatype is not code-gend for the memory layout builtins.
Also fix the wrong help test for the -experimental-performance-annotations option.
2022-02-10 16:46:09 +01:00
Nate Chandler
2c0a35aa54 [PrunedLiveness] Added areUsesOutsideBoundary. 2022-02-02 09:58:25 -08:00
Michael Gottesman
68d37e142b [no-implicit-copy] Add a new instruction called MarkMustCheckInst and use it in the move checker.
This is an instruction that I am going to use to drive some of the ownership
based dataflow optimizations that I am writing now. The instruction contains a
kind that allows one to know what type of checking is required and allows the
need to add a bunch of independent instructions for independent checkers. Each
checker is responsible for removing all of its own mark instructions. NOTE:
MarkMustCheckInst is only allowed in Raw SIL since once we are in Canonical SIL
we want to ensure that all such checking has already occurred.
2022-01-29 14:49:39 -08:00
Erik Eckstein
603e837a8f Swift optimizations: make isSwift51RuntimeAvailable sensitive to the resilience domain of the function. 2022-01-27 13:20:38 +01:00
nate-chandler
bc74ac7a85 Merge pull request #41007 from nate-chandler/rdar87985420
[SILOptimizer] Let visitTransitiveEndBorrows take SILValues.
2022-01-25 21:33:29 -08:00
Andrew Trick
782ce7cddb Minor latent bug fix in findGuaranteedReferenceRoots.
Fix an obvious mistake that happens to not break anything in practice.

Note that the argument index of a terminator result is not the same as
an operand index for the terminator instruction.
2022-01-25 17:32:14 -08:00
Nate Chandler
e3fbadf7b7 [SILOptimizer] Let visitTransitiveEndBorrows take SILValues.
Previously, visitTransitiveEndBorrows took BorrowedValues.  However,
there is at least one kind of borrow--namely,
unchecked_ownership_conversion insts--that is not currently permitted by
the BorrowedValue API.  The long term fix is to make BorrowedValue
handle such instructions.  For now, change visitTransitiveEndBorrows to
take SILValues so that unchecked_ownership_conversion can be passed to
the API.

rdar://87985420
2022-01-25 15:55:08 -08:00
Erik Eckstein
f09dfc93a9 Swift SIL: escape effects for function arguments.
Store a list of argument effects in a function, which specify if and how arguments escape.
Such effects can be specified in the Swift source code (for details see docs/ReferenceGuides/UnderscoredAttributes.md) or derived in an optimization pass.

For details see the documentation in SwiftCompilerSources/Sources/SIL/Effects.swift.
2022-01-25 11:29:44 +01:00
Erik Eckstein
93f5d9f176 swift SIL: Type.getStructFields -> Type.getNominalFields
To be able to get class fields as well as struct fields
2022-01-25 11:29:25 +01:00
Max Desiatov
1f53563780 libswift: remove Instruction.mayReadRefCount 2022-01-19 18:51:19 +00:00
Max Desiatov
d7144c0046 libswift: implement isFieldOnlyNonTrivialField 2022-01-19 18:51:19 +00:00
Max Desiatov
848fa70529 libswift: reimplement Instruction helpers in Swift 2022-01-19 18:51:19 +00:00
Erik Eckstein
cec4b82b39 swift SIL: add some SIL type related bridging
* `Function.argumentTypes` and `Function.resultType`
* `Type.isNominal`, `Type.isClass`, `Type.isTuple`, `Type.isStruct` and `Type.isEnum`
* `Type.getFieldIndexOfNominal`
* `Type.getFieldTypeOfNominal`
* `Type.tupleElements`
* `Type.description` for better debugging

# Conflicts:
#	SwiftCompilerSources/Sources/SIL/Type.swift
#	SwiftCompilerSources/Sources/SIL/Utils.swift
#	SwiftCompilerSources/Sources/SIL/Value.swift
#	include/swift/SIL/SILBridging.h
#	lib/SIL/Utils/SILBridging.cpp
2022-01-19 18:51:19 +00:00
Max Desiatov
b964dba177 libswift: implement ReleaseDevirtualizer in Swift 2022-01-19 18:51:19 +00:00
Max Desiatov
7d961001d3 libswift: bridge more functions from SILBuilder 2022-01-19 18:51:18 +00:00
Holly Borla
6e6ca13268 [Type System] Use the constraint type of an existential type in
various places that expect ProtocolType or ProtocoolCompositionType.
2022-01-13 19:30:44 -08:00
Holly Borla
6cee193fc0 [Type System] When explicit existential types are enabled, wrap Error
in ExistentialType for the type of error values.
2022-01-13 19:30:44 -08:00
Erik Eckstein
24b62d4d7c Swift SIL: add a few utilities and instructions
* instructions: function_ref, mark_dependence
* add `BuiltinInst.id`
* add isObjC and canAllocOnStack for alloc_ref and alloc_ref_dynamic
* add `ApplySite::referencedFunction`
* add `Builder.createDeallocStackRef`
* add == and != operators for `Function`
* add `List.first` and `ReverseList.first`
2022-01-12 15:47:15 +01:00
Max Desiatov
42e6fac1ea libswift: reimplement AssumeSingleThreaded pass 2022-01-10 08:47:43 +00:00
Erik Eckstein
383c52aa35 SIL: rename dealloc_ref [stack] -> dealloc_stack_ref
Introduce a new instruction `dealloc_stack_ref ` and remove the `stack` flag from `dealloc_ref`.

The `dealloc_ref [stack]` was confusing, because all it does is to mark the deallocation of the stack space for a stack promoted object.
2022-01-07 16:20:27 +01:00
zoecarver
036361d1e4 [cxx-interop] Add SIL function representation cxx_method; Support extending C++ types.
There are three major changes here:
    1. The addition of "SILFunctionTypeRepresentation::CXXMethod".
    2. C++ methods are imported with their members *last*. Then the arguments are switched when emitting the IR for an application of the function.
    3. Clang decls are now marked as foreign witnesses.

These are all steps towards being able to have C++ protocol conformance.
2022-01-06 14:26:47 -08:00
swift-ci
e32105eb44 Merge pull request #40392 from atrick/destroy-hoist 2021-12-22 14:50:02 -08:00
Erik Eckstein
3540c01125 rename initializeLibSwift -> InitializeSwiftModules
and some updates in comments.
2021-12-22 11:31:52 +01:00
Andrew Trick
547d87f347 Add a UniqueAddressUses utility.
Analyze and classify the leaf uses of unique storage.

Storage that has a unique set of roots within this function includes
alloc_stack, alloc_box, exclusive argument, and global variables. All access
to the storage within this function is derived from these roots.

Gather the kinds of uses that are typically relevant to algorithms:
- loads	      (including copies out of, not including inout args)
- stores      (including copies into and inout args)
- destroys    (of the entire aggregate)
- debugUses   (only populated when preserveDebugInfo == false)
2021-12-22 01:54:05 -08:00
Andrew Trick
0836b6af61 MemAccessUtils comments 2021-12-22 01:54:05 -08:00
Andrew Trick
0325e296fe Add an isDeinitBarrier() utility.
Needs to be common across ShrinkBorrowScopes and SSADestroyHoisting.
2021-12-22 01:54:05 -08:00
eeckstein
31a1c08083 Merge pull request #40607 from eeckstein/revert-cpp-string
Revert [cxx-interop][libswift] Use `std::string` instead of `BridgedStringRef`
2021-12-20 11:32:07 +01:00
Nate Chandler
148e166196 [OwnershipUtils] Repurpose utility.
Replaced findInnerTransitiveGuaranteeedUsesOfBorrowedValue with
findExtendedUsesOfSimpleBorrowedValue.  Starting from a borrowed value,
it finds all extended (i.e., seeing through copies) uses of the borrow
and its projections within the simple (i.e. without considering
reborrowing) borrow scope.
2021-12-19 08:14:45 -08:00
Erik Eckstein
2900dec755 Revert [cxx-interop][libswift] Use std::string instead of BridgedStringRef
This causes problem with the Windows build and also causes a deserialization crash on Linux.
2021-12-17 13:45:46 +01:00