Commit Graph

22 Commits

Author SHA1 Message Date
Erik Eckstein
9eb5da4a0f SwiftCompilerSources: add the InstructionRange.insert(borrowScopeOf:) utility
Adds the instruction range of a borrow-scope by transitively visiting all (potential) re-borrows.
2023-11-27 16:20:47 +01:00
Erik Eckstein
fc534e1c28 SwiftCompilerSources: better APIs for handling resilient nominal types
* add `NominalTypeDecl.isResilient`

* make the return type of `Type.getNominalFields` optional and return nil in case the nominal type is resilient.
This forces users of this API to think about what to do in case the nominal type is resilient.
2023-11-27 09:21:33 +01:00
Erik Eckstein
0509a056fb SwiftCompilerSources: improve APIs for UseList
Make filter APIs for UseList chainable by adding them to Sequence where Element == Operand

For example, it allows to write:
```
let singleUse = value.uses.ignoreDebugUses.ignoreUsers(ofType: EndAccessInst.self).singleUse
```

Also, add `UseList.getSingleUser(notOfType:)`
2023-11-13 20:18:07 +01:00
Erik Eckstein
2c84de3f4f Optimizer: add a few "lookThrough" utilities
* move `Value.lookThoughOwnershipInstructions` from the ObjCBridgingOptimization pass to OptUtils
* add `lookThroughBorrow` and `lookThroughCopy`
2023-11-09 18:34:53 +01:00
Erik Eckstein
d457368014 SIL Optimizer: move some projection path utilities from RedundantLoadElimination and AccessUtils into OptUtils
NFC
2023-09-19 15:10:30 +02:00
Erik Eckstein
afc0f617e0 Optimizer: support statically initialized globals which contain pointers to other globals
For example:
```
  var p = Point(x: 10, y: 20)
  let o = UnsafePointer(&p)
```

Also support outlined arrays with pointers to other globals. For example:
```
var g1 = 1
var g2 = 2

func f() -> [UnsafePointer<Int>] {
  return [UnsafePointer(&g1), UnsafePointer(&g2)]
}
```
2023-08-10 20:50:36 +02:00
Erik Eckstein
8223b3e210 MandatoryPerformanceOptimizations: fix some problems with inilning
* don't inline functions if it's not possible - by checking `SILInliner::canInlineApplySite`
* fix stack nesting after inlining a `begin_apply`
2023-08-10 15:01:47 +02:00
Erik Eckstein
86771468fc Swift Optimizer: move StoreInst.split into OpUtils.swift
To make it available in other optimizations as well.
Also, a few problems:
* Use destructre instructions when in OSSA
* Don't split the store if it's nominal type has unreferenceable stoarge
* rename it to `trySplit` because it's not guaranteed to work

Also, add the counterpart for load instructions: `LoadInst.trySplit()`
2023-07-21 07:19:56 +02:00
Erik Eckstein
50c23a1640 Optimizer: implement the SILCombine peephole optimizations for retain_value and release_value in Swift 2023-06-07 14:18:38 +02:00
Erik Eckstein
dc3cb18029 Swift Optimizer: add the MandatoryPerformanceOptimizations pass
As a replacement for the old MandatoryGenericSpecializer

The pass it not enabled yet in the pass pipeline
2023-05-11 08:11:44 +02:00
Erik Eckstein
e95c6425f2 Swift SIL: add some APIs for global variables 2023-05-08 21:23:36 +02:00
Erik Eckstein
2d88482c9f EscapeUtils: add a computational limit to avoid quadratic complexity in some corner cases.
The `isEscaping` function is called a lot from ARCSequenceOpt and ReleaseHoisting.
To avoid quadratic complexity for large functions, limit the amount of work what the EscapeUtils are allowed to to.
This keeps the complexity linear.

The arbitrary limit is good enough for almost all functions.
It lets the EscapeUtils do several hundred up/down walks which is much more than needed in most cases.

Fixes a compiler hang
https://github.com/apple/swift/issues/63846
rdar://105795976
2023-02-24 18:58:01 +01:00
Erik Eckstein
1c1d17e18b Swift Optimizer: add some small optimization utilities
* `Instruction.isTriviallyDead` and `Instruction.isTriviallyDeadIgnoringDebugUses`
* `Instruction.hasSameDebugLocationAsPreviousOrNextInstruction`
* `UseList.singleNonDebugUse`
* `UseList.isEmptyIgnoringDebugUses`
* `removeDeadBlocks`
* `FunctionPassContext.removeTriviallyDeadInstructionsPreservingDebugInfo` and `FunctionPassContext.removeTriviallyDeadInstructionsIgnoringDebugUses`
* `BasicBlock.dropAllReferences`
* `SimplifyContext.tryReplaceRedundantInstructionPair`
2023-02-09 06:49:58 +01:00
Erik Eckstein
393d1a1488 SIL Builder: rename insert(at:) -> insert(before:)
It matches with `insert(after:)` and the intent should be clearer now
2023-01-16 15:11:34 +01:00
Erik Eckstein
cc68bd98c9 Swift Optimizer: rework pass context types and instruction passes
* split the `PassContext` into multiple protocols and structs: `Context`, `MutatingContext`, `FunctionPassContext` and `SimplifyContext`
* change how instruction passes work: implement the `simplify` function in conformance to `SILCombineSimplifyable`
* add a mechanism to add a callback for inserted instructions
2023-01-16 15:11:34 +01:00
Erik Eckstein
c32d6cd0fb EscapeUitls: some refactoring 2023-01-16 15:11:34 +01:00
Erik Eckstein
6c35258f83 Swift SIL: rename parent accessors to parentX, e.g. Instruction.parentBlock
It makes it easier to read
2023-01-16 15:11:34 +01:00
Erik Eckstein
4554939dc4 SwiftCompilerSources: consistently use assert instead of precondition
It's better to use the new assert implementation (defined in the "Basic" module) than Swift's `precondition`
2022-09-14 14:16:26 +02:00
Erik Eckstein
4011e086f0 Swift optimizer: add Value.makeAvailable and `Value.copy(at:andMakeAvailableIn:)
Utilities to make a value available to be used in another basic block.
Inserts required `copy_value` and `destroy_value` operations in case the destination block is in a different control region than the value.
For example, if the destination block is in a loop while the value is not in that loop, the value has to be copied for each loop iteration.
2022-05-12 21:48:37 +02:00
Josh Soref
1b0aa6d7f1 Spelling swiftcompilersources (#42617)
* spelling: diagnose

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: diagnostic

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: intentionally

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: optimization

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: target

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: unbalanced

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-25 09:01:23 -07:00
Erik Eckstein
31143bf79c Swift Optimizer: add the Builder.insert(after: Instruction ...) utility
For inserting new instruction after another instruction. This is especially interesting if the insertion point is a terminator.
In this case, the new instruction(s) are inserted in the successor block(s).
2022-01-12 15:47:16 +01:00
Erik Eckstein
4beb94c2f9 Rename the libswift directory to SwiftCompilerSources 2021-12-22 09:46:25 +01:00