Commit Graph

1186 Commits

Author SHA1 Message Date
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
887b5ca891 add a Swift pass which can run unit tests.
The `run-unit-tests` is a "pseudo" pass which is invoked from sil-opt and runs all the unit tests, implemented in Swift.
This is done from the `swift-unit-tests.sil` lit test.
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
40e805de11 libswift: simplify ReleaseDevirtualizer.swift 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
Max Desiatov
7eb3bdd746 libswift: add SubstitutionMap to Swift code 2022-01-19 18:51:18 +00:00
Max Desiatov
f2aefad246 libswift: clean up SIL/Function.swift formatting 2022-01-19 18:51:18 +00:00
Max Desiatov
c780969f79 libswift: clean up SIL/Type.swift formatting 2022-01-19 18:51:18 +00:00
Max Desiatov
196140ab95 libswift: clean up SIL/Utils.swift formatting 2022-01-19 18:51:18 +00:00
Max Desiatov
a0a2d8887b libswift: clean up Instruction.swift formatting 2022-01-19 18:51:18 +00:00
Erik Eckstein
82ad1fa5a1 CalleeAnalysis: add getDestructors(destroyInst: Instruction) 2022-01-12 15:47:16 +01: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
e028239cc2 Swift Optimizer: add AllocRefInstBase.setIsStackAllocatable 2022-01-12 15:47:16 +01:00
Erik Eckstein
e152b2cb4a Swift Optimizer: add the fixStackNesting utility in PassContext
This bridges to the StackNesting utility in C++
2022-01-12 15:47:16 +01:00
Erik Eckstein
a24b17a333 Swift Optimizer: add the dominator and post-dominator tree analysis 2022-01-12 15:47:16 +01:00
Erik Eckstein
4440beb555 Swift Optimizer: add bridging to the DeadEndBlocksAnalysis 2022-01-12 15:47:16 +01: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
Erik Eckstein
345fcbe39a Improve collections in the swift SIL/Optimizer
Improve block/instruction lists and similar collections

* pretty print collections in the form “[a, b, c]”
* also do this for lazy sequences
* define a custom Mirror
* in a collection, only print the name of blocks, functions and globals (instead of the full object)
* replace `BasicBlock.reverseInstructions` with `BasicBlock.instructions.reversed()` - in an efficient way
2022-01-12 15:47:16 +01: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
e90fc5f2d0 libswift: add single-threaded pass docs, fix test 2022-01-10 12:03:14 +00:00
Max Desiatov
42e6fac1ea libswift: reimplement AssumeSingleThreaded pass 2022-01-10 08:47:43 +00:00
Max Desiatov
e54524d7a5 Gardening: remove trailing whitespaces in libswift 2022-01-09 21:09:57 +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
Erik Eckstein
3540c01125 rename initializeLibSwift -> InitializeSwiftModules
and some updates in comments.
2021-12-22 11:31:52 +01:00
Erik Eckstein
ba364a17ef libswift: rename cmake targets and functions
libswift -> swiftCompilerModules or swiftCompilerSources
2021-12-22 11:31:52 +01:00
Erik Eckstein
4beb94c2f9 Rename the libswift directory to SwiftCompilerSources 2021-12-22 09:46:25 +01:00