Commit Graph

699 Commits

Author SHA1 Message Date
Erik Eckstein
cee4505840 SimplifyLoad: improve simplification of load of global variable
Inline the initialization code of a global initializer if the load is a global_addr with a builtin "once" dependency.
2024-01-10 09:34:01 +01:00
Erik Eckstein
3229749257 SwiftCompilerSources: move some private utilities of passes into OptUtils
* `var Function.initializedGlobal`
* `func getGlobalInitialization`

and add `var CollectionLikeSequence.singleElement`
2024-01-10 09:34:01 +01:00
Erik Eckstein
543fe31e8f SwiftCompilerSources: add Context.notifyDependency(onBodyOf:)
It notifies the pass manager that the optimization result of the current pass depends on the body (i.e. SIL instructions) of another function than the currently optimized one.
2024-01-10 09:34:00 +01:00
Erik Eckstein
bc99986cf9 SIL: add a dependency token operand to global_addr
Optionally, the dependency to the initialization of the global can be specified with a dependency token `depends_on <token>`.
This is usually a `builtin "once"` which calls the initializer for the global variable.
2024-01-10 09:33:58 +01:00
nate-chandler
7365f9f36b Merge pull request #70774 from nate-chandler/nfc/20240108/1/deinit-barrier-component-predicates
[NFC] SIL: Clarified deinit barrier APIs.
2024-01-08 23:11:38 -08:00
Nate Chandler
82b7495bb1 [NFC] SIL: Clarified deinit barrier APIs.
An instruction is a deinit barrier whenever one of three component
predicates is true for it.  In the case of applies, it is true whenever
one of those three predicates is true for any of the instructions in any
of its callees; that fact is cached in the side-effect analysis of every
function.

If side-effect analysis or callee analysis is unavailable, in order to
define each of those three component predicates on a
`FullApplySite`/`EndApplyInst`/`AbortApplyInst`, it would be necessary
to define them to conservatively return true: it isn't known whether any
of the instructions in any of the callees were deinit barriers.

Refactored the two versions of the deinit barrier predicate (namely
`Instruction.isDeinitBarrier(_:) and
`swift::mayBeDeinitBarrierNotConsideringSideEffects`) to handle
`FullApplySite`/`EndApplyInst`/`AbortApplyInst`s specially first (to
look up the callees' side-effect and to conservatively bail,
respectively).  Asserted that the three component predicates are not
called with `FullApplySite`/`EndApplyInst`/`AbortApplyInst`s.  Callers
should instead use the `isDeinitBarrier` APIs.

An alternative would be to conservatively return true from the three
components.  That seems more likely to result in direct calls to these
member predicates, however, and at the moment at least there is no
reason for such calls to exist.  If some other caller besides the
deinit-barrier predicates needs to call this function, side-effect
analysis should be updated to cache these three properties separately at
that point.
2024-01-08 15:25:24 -08:00
Nate Chandler
77fd37be99 [NFC] SIL: Renamed maySynchronize.
Dropped the NotConsideringSideEffects suffix.
2024-01-08 13:35:20 -08:00
Andrew Trick
264cbaea42 Add mark_dependence [nonescaping] flag.
The dependent 'value' may be marked 'nonescaping', which guarantees that the
lifetime dependence is statically enforceable. In this case, the compiler
must be able to follow all values forwarded from the dependent 'value', and
recognize all final (non-forwarded, non-escaping) use points. This implies
that `findPointerEscape` is false. A diagnostic pass checks that the
incoming SIL to verify that these use points are all initially within the
'base' lifetime. Regular 'mark_dependence' semantics ensure that
optimizations cannot violate the lifetime dependence after diagnostics.
2024-01-04 14:47:35 -08:00
Andrew Trick
2128c21106 Migrate SwiftCompilerSources to FunctionConvention.
Layers:
- FunctionConvention: AST FunctionType: results, parameters
- ArgumentConventions: SIL function arguments
- ApplyOperandConventions: applied operands

The meaning of an integer index is determined by the collection
type. All the mapping between the various indices (results,
parameters, SIL argument, applied arguments) is restricted to the
collection type that owns that mapping. Remove the concept of a
"caller argument index".
2024-01-03 12:24:50 -08:00
Meghana Gupta
ba4cedd5e5 Merge pull request #70582 from meg-gupta/resultdependsoninsil
Make _resultDependsOn/_resultDependsOnSelf available in SIL
2024-01-02 10:49:20 -08:00
Steven Wu
234e61b207 Merge pull request #70597 from cachemeifyoucan/eng/PR-119997353
[CMake] Change include path in HeaderDependencies.cpp
2024-01-02 09:04:02 -08:00
Erik Eckstein
85be96354f SimplifyBuiltin: fix simplification of is_same_metatype with dynamic_self types
Dynamic self types are not the same as non-dynamic self types.

Fixes a miscompile with dynamic self type comparisons.

rdar://119943508
2024-01-02 09:23:42 +01:00
Meghana Gupta
3c56a7a88e Bridge hasResultDependsOnSelf() 2023-12-29 02:06:15 -08:00
Meghana Gupta
334ede0b01 Bridge hasResultDependsOn() 2023-12-29 02:06:12 -08:00
Steven Wu
21e779f0c3 [CMake] Change include path in HeaderDependencies.cpp
Update the #include in generated HeaderDependencies.cpp so it doesn't
need a special include path that points into `include/swift`. In the
swift sub-directory, there is a `Strings.h` that can be mistaken as
<string.h> on a case-insensitive file system.

rdar://119997353
2023-12-21 10:12:14 -08:00
Erik Eckstein
16697882e8 SimplifyBeginBorrow: fix isDestroyed(after:)
The previous implementation just checked that a value's only uses besides the begin_borrow were destroys. That's insufficient to say the value is destroyed after the borrow (i.e. that all its destroys are dominated by the borrow). Add the relevant dominance check.

Fixes a compiler crash

rdar://119873930
2023-12-20 11:41:40 +01:00
Andrew Trick
7dc3d72483 Merge pull request #70485 from atrick/bridge-util
[NFC] Bridging and utilities for SwiftCompilerSources required by lifetime dependence utilities.
2023-12-19 13:07:45 -08:00
Andrew Trick
d0b47b878c SwiftCompilerSources: add CollectionLikeSequence.contains() 2023-12-19 02:05:16 -08:00
Andrew Trick
3f0d309ed4 SwiftCompilerSources: add Sequence.walk() 2023-12-19 02:05:16 -08:00
Andrew Trick
53d3c63ef7 [SIL] add Value.hasLifetime 2023-12-19 02:05:16 -08:00
Andrew Trick
ed53ab764a [SIL] add Value.lifetimeEndingUses 2023-12-19 02:05:16 -08:00
Andrew Trick
2a9aef9eb8 [SIL] add BeginApplyInst.token 2023-12-19 02:05:16 -08:00
Andrew Trick
0ddf2a8514 [SIL] add BasicBlock.singleSuccessor 2023-12-19 02:05:16 -08:00
Andrew Trick
a396cc3c2a [SIL] InstructionRange API; exitBlocks 2023-12-19 02:05:16 -08:00
Andrew Trick
c1f0f06907 [SIL] Add FunctionConvention.swift
Bridge information about the AST function type that does not require a
SIL function body.

Support querying the function type's ResultInfo.
2023-12-18 09:43:18 -08:00
Andrew Trick
7a18dd46d5 [SIL] Add Argument.incomingOperand(inPredecessor:) 2023-12-18 09:43:10 -08:00
Andrew Trick
3407ccd693 [SIL] bridge Argument.isReborrow 2023-12-18 09:28:23 -08:00
Andrew Trick
b637f06acd [SIL] Bridge findPointerEscape() and fix OnoneSimplifyable
Do not bridge the hasPointerEscape flag until it is implemented.
2023-12-18 09:16:55 -08:00
Erik Eckstein
84e06322b9 SwiftCompilerSources: bridge_object_to_word is not a ForwardingInstruction
Fix this mismatch between C++ SIL and swift SIL.
Fixes a crash in begin_borrow simplification
Also add an assert to catch such cases.

rdar://119763595
2023-12-18 11:08:22 +01:00
eeckstein
4eddc1d70b Merge pull request #70494 from eeckstein/instruction-simplifications
Add some instruction simplifications
2023-12-17 16:39:02 +01:00
Meghana Gupta
890ec7d855 Merge pull request #70477 from meg-gupta/fixpredmemopt
Use OSSALifetimeCompletion in PredictableMemOpt
2023-12-15 19:18:22 -08:00
Meghana Gupta
06f0d15c45 Use OSSALifetimeCompletion in PredictableMemOpt
The current algorithm to complete lifetimes is incorrect in a few cases.
Use OSSALifetimeCompletion instead.

Fixes rdar://119204768
2023-12-15 15:16:55 -08:00
Ben Barham
406d5337dc Merge pull request #69538 from finagolfin/android
[android] Add more changes to build the compiler
2023-12-15 10:57:21 -08:00
Erik Eckstein
691fa9e755 SimplifyBuiltin: add constant folding of null pointer checks against string literals
A pointer to a string literal is never null
2023-12-15 17:11:50 +01:00
Erik Eckstein
94b6e511ba Optimizer: add simplification for switch_enum
Replace
```
    %1 = enum $E, #someCase, %payload
    switch_enum %1, case #someCase: bb1, ...
  bb1(%payloadArgument):
```
->
```
  br bb1(%payload)
  bb1(%payloadArgument):
```
2023-12-15 17:11:49 +01:00
Ben Barham
2e85a4c68f Merge pull request #70346 from bnbarham/fix-redefine-warning
[CMake] Fix SWIFT_TARGET redefinition warning
2023-12-14 12:03:10 -08:00
Erik Eckstein
60baf111ff Remove Type.selfOrAnyFieldHasValueDeinit
It's not needed anymore
2023-12-13 20:03:02 +01:00
Erik Eckstein
11c74317a9 deinit-devirtualization: completely de-compose non-copyable destroys
Even if the destroyed value doesn't have a deinit.
This fixes a false alarm when a non-copyable value ends its lifetime in a function with performance annotations.

rdar://117002721
2023-12-13 20:03:02 +01:00
Erik Eckstein
773d6b179d SwiftCompilerSources: remove the redundant BridgedPassContext.Feature enum
And replace it with the existing BridgedFeature
2023-12-13 13:28:17 +01:00
Erik Eckstein
ae278058e6 Add an experimental pass to lower allocateVector builtins
By default it lowers the builtin to an `alloc_vector` with a paired `dealloc_stack`.
If the builtin appears in the initializer of a global variable and the vector elements are initialized,
a statically initialized global is created where the initializer is a `vector` instruction.
2023-12-09 18:49:58 +01:00
Erik Eckstein
ded20d3c11 SwiftCompilerSources: add Value.isValidGlobalInitValue and FullApplySite.isSemanticCall
`Value.isValidGlobalInitValue` was privately used by the ObjectOutliner. Make it a generally usable utility.
2023-12-09 18:49:58 +01:00
Erik Eckstein
ca20ebc158 SwiftCompilerSources: add bridging to hasFeature 2023-12-09 18:49:57 +01:00
Erik Eckstein
dd9ce40ba1 add the allocVector builtin 2023-12-09 18:49:57 +01:00
Erik Eckstein
e652f2c92e SIL: add the alloc_vector and vector instructions
* `alloc_vector`: allocates an uninitialized vector of elements on the stack or in a statically initialized global
* `vector`: creates an initialized vector in a statically initialized global
2023-12-09 18:49:55 +01:00
Erik Eckstein
2a54f98c62 SimplificationPasses: add @discardableResult to runSimplification
NFC
2023-12-09 18:48:50 +01:00
Erik Eckstein
9514b3450c SwiftCompilerSources: add some context APIs
* `Context.moduleIsSerialized`
* `Context.getBuiltinIntegerType`
* `Instruction.move(before:)`
2023-12-09 18:48:50 +01:00
Erik Eckstein
0bd6034270 SwiftCompilerSources: add some Builder APIs
* `createAddressToPointer`
* `createLoadBorrow`
2023-12-09 18:48:50 +01:00
Ben Barham
0966c7b7a8 [CMake] Fix SWIFT_TARGET redefinition warning
`HeaderDependencies.cpp` is (as in the name) C++, which means it
receives `-DSWIFT_TARGET` from the top level `add_definitions`. No need
to add it again.
2023-12-08 17:10:01 -08:00
Rintaro Ishizaki
4673d63776 Merge pull request #70271 from rintaro/cmake-swiftsrc-colordiag 2023-12-06 17:45:32 -08:00
Ben Barham
a9df7d132b Merge pull request #70273 from apple/ignore-none-warning
[CMake] Ignore `None` and `NoneType` deprecations
2023-12-06 17:38:26 -08:00