Anxhelo Xhebraj
462d208d15
Swift SIL: add GlobalVariable equality
2022-08-11 10:16:40 -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
Egor Zhdan
0e2d438c5b
[cxx-interop][SwiftCompilerSources] Use llvm::StringRef instead of BridgedStringRef
...
rdar://83361000
2022-07-21 16:32:16 +01:00
Erik Eckstein
b52297bb79
Swift SIL: some improvements for WalkUtils and EscapeInfo
...
* "merge" the `Path` and `State` in WalkUtils into a single `WalkingPath`. This makes it simpler for clients to configure a path and additional state variables. EscapeInfo now defines `EscapePath` which includes the projection path and EscapeInfo's specific state variables.
* Make the `WalkerCache` part of the WalkUtils, so that not all clients have to re-implement it.
* Rename `walkDownResults` -> `walkDownAllResults` and `walkUpOperands` -> `walkUpAllOperands` and make these functions client configurable.
2022-07-20 13:50:18 +02:00
Erik Eckstein
c871197e1a
Swift SIL: fix ApplySite.callerArgIndex
...
It needs to return nil in case the callee argument is not really applied by the ApplySite.
This fixes a crash in EscapeInfo when handling "escaping-to" effects:
If the callee operand of an apply instruction is a `partial_apply` of a `function_ref`, the callee-analysis looks through the `partial_apply` and we get the referenced function as a callee.
In this case there are less apply arguments than callee arguments, because the `partial_apply` already "applies" some of the callee arguments.
rdar://96830171
2022-07-12 17:53:27 +02:00
Anxhelo Xhebraj
03e4e5cdb2
Merge pull request #59729 from Angelogeb/apple/walkutils
...
Swift Optimizer: add def-use/use-def walker utilities
2022-07-07 08:44:31 -07:00
Egor Zhdan
38edc7f377
[cxx-interop][SwiftCompilerSources] Remove getCopiedBridgedStringRef and freeBridgedStringRef
...
`std::string`s can now be passed directly between Swift and C++.
rdar://83361087
2022-07-06 12:57:50 +01:00
Anxhelo Xhebraj
c3ccbde52b
Swift Optimizer: update EscapeInfo to use the generic walker utilities
...
`EscapeInfo` now conforms to the generic protocols defined in `WalkUtils`.
This simplifies the implementation a bit, since trivial instructions are handled
by `WalkUtils` and `EscapeInfo` only has to handle a subset of instructions
inherent to escape information.
Passes using `EscapeInfo` are updated accordingly to become visitors that
customize the `EscapeInfo` walk.
2022-07-05 11:28:49 -07:00
Egor Zhdan
f476f6245c
[cxx-interop][SwiftCompilerSources] Workaround for std::string crash on arm64 Linux
...
`std::string` constructor crashes when called from `SILBridging.cpp`, likely due to a miscompile. This is a workaround that fixes the crash.
2022-06-15 15:54:45 +01:00
Egor Zhdan
ffb9ee9422
Revert "Revert "[cxx-interop][SwiftCompilerSources] Fix conversion between std::string and Swift.String""
...
This reverts commit 9542837a18 .
2022-06-09 23:40:51 +01:00
Erik Eckstein
a17ee435b6
Swift SIL: fix var ApplySite.arguments
...
In case of type-dependent operands, not all operands are part of the arguments
2022-06-08 22:51:57 +02:00
Egor Zhdan
9542837a18
Revert "[cxx-interop][SwiftCompilerSources] Fix conversion between std::string and Swift.String"
...
This reverts commit be711e387f .
2022-06-08 14:10:04 +01:00
Egor Zhdan
be711e387f
[cxx-interop][SwiftCompilerSources] Fix conversion between std::string and Swift.String
...
This fixes a dangling pointer issue when creating a `Swift.String` from `std::string`.
Also fixes a warning:
```
warning: variable 's' was never mutated; consider changing to 'let' constant
var s = SILBasicBlock_debugDescription(bridged)
~~~ ^
let
```
rdar://92963081
rdar://93053488
2022-05-30 20:06:36 +01:00
Erik Eckstein
a91d541a26
Swift SIL: add ApplySite.substitutionMap and ApplySite.getArgumentConvention()
2022-05-12 21:48:37 +02:00
Erik Eckstein
1a933fc76e
Swift SIL: add Type.getIndexOfEnumCase(withName:)
...
... to get the enum case index with a given name.
2022-05-12 21:48:37 +02:00
Erik Eckstein
b0003d51da
Swift SIL: add an initializer to create an empty SubstitutionMap
2022-05-12 21:48:37 +02:00
Erik Eckstein
7c71f0091e
Swift SIL: add UseList.isSingleUse
2022-05-12 21:48:37 +02:00
Erik Eckstein
dd5d5f97c4
Swift SIL: add Function.hasSemanticsAttribute
2022-05-12 21:48:37 +02:00
Erik Eckstein
ad9dafc9bf
Swift SIL: add Value.definingBlock
...
and re-factor `Value.definingInstruction`
2022-05-12 21:48:37 +02:00
Erik Eckstein
3b43da9637
Swift Optimizer: improve ergonomics of Builder and PassContext
...
* split the PassUtils.swift file into PassContext.swift and Passes.swift
* rework `Builder` bridging allowing more insertion point variations, e.g. inserting at the end of a block.
* add Builder.create functions for more instructions
* add `PassContext.splitBlock`
* move SIL modification functions from PassContext to extensions of the relevant types (e.g. instructions).
* rename `Location.bridgedLocation` -> `Location.bridged`
2022-05-12 21:48:37 +02:00
Erik Eckstein
14b985d87e
Swift SIL: support ownership
...
* add the `Ownership` enum and the `Value.ownership` getter
* add `Function.hasOwnership`
2022-05-12 21:48:37 +02:00
Erik Eckstein
cd456fa792
Swift SIL: make Function.name and GlobalVariable.name return a StringRef and not a String
...
and introduce the StringRef struct.
It's more efficient.
Also, rename the `HasName` protocol to `HasShortDescription`, which introduces the new requirement `shortDescription`. This is need because `name` now has `StringRef` type and not `String` anymore
2022-05-12 21:48:37 +02:00
Allan Shortlidge
1ffe55b856
Revert "swift SIL: Fix variable 's' was never mutated; consider changing to 'let' constant warnings."
...
This reverts commit d83c17e832 .
2022-05-10 10:38:58 -07:00
Allan Shortlidge
d83c17e832
swift SIL: Fix variable 's' was never mutated; consider changing to 'let' constant warnings.
2022-05-06 17:29:12 -07:00
Egor Zhdan
145ed33482
[cxx-interop][SwiftCompilerSources] Use std::string instead of BridgedStringRef
...
This reverts commit 2900dec7
2022-05-03 19:48:14 +01:00
Erik Eckstein
1c4ba46c3b
EscapeInfo: fix a bug and some refactoring
...
Add a flag `analyzeAddresses` for distinguishing address vs value escape analysis. This is simpler than handling that in the visitUse/visitDef closures.
Also, fix a related bug, which let an address, which is escaping to a function, get unnoticed.
2022-04-25 08:56:24 +02:00
Josh Soref
d767912be2
Spelling sil ( #42471 )
...
* spelling: accessible
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: accessories
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: allocated
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: amortizes
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: are
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: arguments
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: cacheable
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: check
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: clazz
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: compatible
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: compilation
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: completely
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: construct
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: conversion
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: declarations
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: derivation
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: deserialization
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: destroyed
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: determined
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: different
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: doesn't
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: equality
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: equivalent
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: formation
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: forwards
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: global
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: guaranteed
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: have
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: identify
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: inaccessible
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: indeterminate
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: indices
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: inefficient
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: inheritance
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: instantaneous
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: instruction
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: intentionally
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: interior
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: intrinsic
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: introducing
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: irrelevant
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: message
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: multi
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: necessarily
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: object
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: one
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: optimization
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: otherwise
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: overridden
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: parameter
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: pattern
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: pipeline
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: possibility
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: postdominance
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: providing
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: reached
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: recognized
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: refrigerator
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: remaining
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: resilient
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: retrieve
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: scavenge
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: scheduled
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: separately
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: serializable
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: signature
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: simplicity
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: specifically
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: substituted
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: substitution
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: subtypes
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: supplement
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: syntax
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: the
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: there
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: these
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: this
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: though
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: through
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: transitively
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: transpose
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: trivial
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: value
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: verification
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: visibility
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: weird
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
* spelling: whole
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com >
Co-authored-by: Josh Soref <jsoref@users.noreply.github.com >
2022-04-22 15:11:09 -07:00
Erik Eckstein
a5ac6c2cff
TypeLowering: add a recursive property to check if a type contains a RawPointer
...
This is needed for the new escape analysis
2022-04-22 09:50:07 +02:00
Erik Eckstein
b75108e70a
Swift SIL: a few small addition to SmallProjectionPath
...
* rename `matchesAllValueFields` -> `topMatchesAnyValueField`
* add `hasSingleClassIndirection` and `hasClassProjection`
* add `popLastClassAndValuesFromTail`
2022-04-22 09:50:07 +02:00
Erik Eckstein
340efd9e6f
Swift SIL: add MultipleValueInstructionResult.index
...
And make DestructureStructInst and DestructureTupleInst a UnaryInstruction
2022-04-22 09:50:07 +02:00
Saleem Abdulrasool
218ef587e6
Revert "Merge pull request #42242 from eeckstein/escapeinfo"
...
This reverts commit c05e064cd8 , reversing
changes made to c1534d5af9 .
This caused a regression on Windows.
2022-04-21 20:33:37 -07:00
Erik Eckstein
3b2e409d41
TypeLowering: add a recursive property to check if a type contains a RawPointer
...
This is needed for the new escape analysis
2022-04-21 08:45:08 +02:00
Erik Eckstein
003fdec7fb
Swift SIL: a few small addition to SmallProjectionPath
...
* rename `matchesAllValueFields` -> `topMatchesAnyValueField`
* add `hasSingleClassIndirection` and `hasClassProjection`
* add `popLastClassAndValuesFromTail`
2022-04-21 08:45:08 +02:00
Erik Eckstein
325a0b1f48
swift SIL: add some Instruction, Value and Type APIs
...
* instructions `RefToBridgeObjectInst`, `BridgeObjectToWordInst`, `StringLiteralInst`, `ProjectBoxInst`, `InitEnumDataAddrInst`, `UncheckedTakeEnumDataAddrInst`, `InjectEnumAddrInst`
* protocols `StoringInstruction` and `EnumInstruction`
* load/store-weak/unowned instructions
* `CopyAddrInst.isTakeOfSrc/isInitializationOfDest`
* `ApplySite.calleeArgIndex/callerArgIndex`
* `SILValue.definingInstruction/definingBlock/function`
* `Type.isReferenceCounted`
* `FunctionArgument.isExclusiveIndirectParameter`
* support `CondBranchInst` in `incomingPhiValues`
2022-03-30 14:45:58 +02:00
Andrew Trick
05fb8c7930
Remove CheckedCastValue from Swift compiler sources.
2022-03-22 18:09:48 -07:00
Rintaro Ishizaki
da6814d510
[SwiftCompiler] Make BridgedArrayRef.data nullable
...
ArrayRef.data() can be nullptr when the array is empty.
2022-02-20 22:30:18 -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
Arnold Schwaighofer
9f2b6a4ebb
Reuse _ContiguousArrayStorage<AnyObject> metadata for any class or objc generic type
...
Reduces the number of _ContiguousArrayStorage metadata.
In order to support constant time bridging we do need to set the correct
metadata when we bridge to Objective-C. This is so that the type check
succeeds when bridging back from Objective-C to reuse the storage
instance rather than bridging the elements.
To support dynamically setting the `_ContiguousArrayStorage` element
type i needed to add support for optimizing `alloc_ref_dynamic`
throughout the optimizer.
Possible future improvements:
* Use different metadata such that we can disambiguate native Swift
classes during destruction -- allowing native release rather then unknown
release usage.
* Optimize the newly added semantic function
getContiguousArrayStorageType
rdar://86171143
2022-02-16 07:55:34 -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
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
fb00bc3b44
Swift SIL: add the SmallProjectionPath utility
...
The `SmallProjectionPath` represents a path of value or address projections.
It’s used for defining argument effects for functions and for the new escape analysis.
2022-01-25 11:29:25 +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
Erik Eckstein
75da7d9d3e
Swift SIL: add a StringParser utility for simple parsing tasks
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