Commit Graph

21 Commits

Author SHA1 Message Date
Erik Eckstein
010efc1ca6 Swift Bridging: use C++ instead of C bridging for the optimizer 2023-03-21 15:33:09 +01:00
Erik Eckstein
22f03cdde6 Swift Optimizer: generalize the worklist data structure
Rename `BasicBlockWorklist.swift` to `Worklist` and make it generic for any elements.
Also, add methods `popAndForget` and `isEmpty`
2023-01-16 16:16:51 +01:00
Erik Eckstein
f3717d5127 Swift Optimizer: add the ReachableBlocks utility 2023-01-16 16:16:51 +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
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
d4d1620f28 Swift SIL: rework Instruction and BasicBlock lists to support deleting instructions during iteration
Replace the generic `List` with the (non-generic) `InstructionList` and `BasicBlockList`.
The `InstructionList` is now a bit different than the `BasicBlockList` because it supports that instructions are deleted while iterating over the list.
Also add a test pass which tests instruction modification while iteration.
2022-12-12 19:08:57 +01:00
Egor Zhdan
94ec683ba5 Revert "Revert "[cxx-interop][SwiftCompilerSources] Use C++ enums directly from Swift""
This reverts commit 69431f00
2022-10-18 18:55:57 +01:00
Erik Eckstein
81ac311c83 Swift Optimizer: add the DeadEndBlocks utility for finding dead-end blocks.
Dead-end blocks are blocks from which there is no path to the function exit (`return`, `throw` or unwind).
These are blocks which end with an unreachable instruction and blocks from which all paths end in "unreachable" blocks.
2022-10-05 07:37:41 +02:00
Erik Eckstein
aea26bbc6e Swift SIL: add a utility protocol NoReflectionChildren for better debug output with lldb po
Let's lldb's `po` command not print any "internal" properties of the conforming type.
This is useful if the `description` already contains all the information of a type instance.
2022-10-05 07:37:41 +02:00
eeckstein
69431f00e8 Revert "[cxx-interop][SwiftCompilerSources] Use C++ enums directly from Swift" 2022-09-22 11:45:41 +02:00
Egor Zhdan
5f2a641513 [cxx-interop][SwiftCompilerSources] Use swift::SILWitnessTable::WitnessKind instead of `
SILWitnessTableEntryKind`

rdar://83361087
2022-09-20 12:03:48 +01:00
Erik Eckstein
275861f832 FunctionUses: don't eagerly reserve array capacities in the initializer
Instead do it in `collect`. This allows creating a `FunctionUses` with zero cost - in case `collect` is never called.
2022-09-02 07:11:49 +02:00
Erik Eckstein
a12e33e9e9 Swift Optimizer: add the FunctionUses utility
Provides a list of instructions, which reference a function.

A function "use" is an instruction in another (or the same) function which references the function.
In most cases those are `function_ref` instructions, but can also be e.g. `keypath` instructions.

'FunctionUses' performs an analysis of all functions in the module and collects instructions which reference other functions.
This utility can be used to do inter-procedural caller-analysis.
2022-08-24 17:55:02 +02:00
Erik Eckstein
90c83be7a6 Swift Optimizer: make the Stack data structure also work with a ModulePassContext 2022-08-24 17:55:02 +02:00
Erik Eckstein
de6e539a0a Swift Optimizer: make the set's insert functions return a Bool.
Returning true if the element was not contained in the set before inserting
2022-08-24 17:54:46 +02:00
Erik Eckstein
3bba7caacc Swift SIL: add var Function.instructions
To be used to iterate over all instructions in a function without the need of two loops - one for blocks and one for instructions.
2022-08-24 17:54:46 +02:00
Erik Eckstein
ce5e2fb637 Swift SIL: use InstructionSet (instead of Set<Instruction>) in InstructionRange 2022-07-13 14:27:50 +02:00
Erik Eckstein
49a5b3ebdc Swift SIL: add ValueSet and InstructionSet utilities.
These sets are _much_ more efficient than `Set<Value>` and `Set<Instruction>` because they bridge to the efficient `NodeSet`.
Insertions/deletions are just bit operations.
2022-07-13 14:27:50 +02:00
Erik Eckstein
6760dc420c SIL: add a utility which can manage per-value and per-instruction bitfields and flags efficiently.
It's used to implement `InstructionSet` and `ValueSet`: sets of SILValues and SILInstructions.
Just like `BasicBlockSet` for basic blocks, the set is implemented by setting bits directly in SILNode.
This is super efficient because insertion and deletion to/from the set are basic bit operations.

The cost is an additional word in SILNode. But this is basically negligible: it just adds ~0.7% of memory used for SILInstructions.
In my experiments, I didn't see any relevant changes in memory consumption or compile time.
2022-07-13 14:27:50 +02:00
Erik Eckstein
4824d6d940 Swift SIL: improve BasicBlockRange and InstructionRange and add tests
* add `BasicBlockRange.inclusiveRange`
* add `insert(contentsOf:)`
* add the RangeDumper pass to dump ranges for testing
* and add a test file
2022-03-30 14:45:58 +02:00
Erik Eckstein
40200d6544 Swift Optimizer: add BasicBlock utility data structures and rename StackList
* add `BasicBlockSet`
* add `BasicBlockWorklist`
* add `BasicBlockRange`, which defines a range of blocks from a common dominating “begin” block to a set of “end” blocks.
* add  `InstructionRange`, which is similar to `BasicBlockRange`, just on instruction level. It can be used for value lifetime analysis.
* rename `StackList` -> `Stack` and move it to `Optimizer/DataStructures`
* rename `PassContext.passContext` to `PassContext._bridged`
* add notify-functions to PassContext
2022-01-12 15:47:16 +01:00