Swift SIL: add some instruction classes and APIs

* add `UnownedRetainInst` and `UnownedReleaseInst`
* add `var value` to `RetainValueInst` and `ReleaseValueInst`
* make the protocol `UnaryInstruction` be an `Instruction`
* add `var Type.isValueTypeWithDeinit`
* add `var Type.isUnownedStorageType`
* add `var OperandArray.values`
This commit is contained in:
Erik Eckstein
2023-06-06 19:12:47 +02:00
parent ae9a0c1007
commit 5325a4fe21
9 changed files with 65 additions and 2 deletions

View File

@@ -80,7 +80,7 @@ extension ApplySite {
///
/// This does not include the callee function operand.
public var arguments: LazyMapSequence<OperandArray, Value> {
argumentOperands.lazy.map { $0.value }
argumentOperands.values
}
public var substitutionMap: SubstitutionMap {

View File

@@ -136,6 +136,18 @@ public struct Builder {
return notifyNew(release.getAs(StrongReleaseInst.self))
}
@discardableResult
public func createUnownedRetain(operand: Value) -> UnownedRetainInst {
let retain = bridged.createUnownedRetain(operand.bridged)
return notifyNew(retain.getAs(UnownedRetainInst.self))
}
@discardableResult
public func createUnownedRelease(operand: Value) -> UnownedReleaseInst {
let release = bridged.createUnownedRelease(operand.bridged)
return notifyNew(release.getAs(UnownedReleaseInst.self))
}
public func createFunctionRef(_ function: Function) -> FunctionRefInst {
let functionRef = bridged.createFunctionRef(function.bridged)
return notifyNew(functionRef.getAs(FunctionRefInst.self))

View File

@@ -197,7 +197,7 @@ public class MultipleValueInstruction : Instruction {
}
/// Instructions, which have a single operand.
public protocol UnaryInstruction : AnyObject {
public protocol UnaryInstruction : Instruction {
var operands: OperandArray { get }
var operand: Operand { get }
}
@@ -306,14 +306,24 @@ final public class StrongRetainInst : RefCountingInst {
public var instance: Value { operand.value }
}
final public class UnownedRetainInst : RefCountingInst {
public var instance: Value { operand.value }
}
final public class RetainValueInst : RefCountingInst {
public var value: Value { return operand.value }
}
final public class StrongReleaseInst : RefCountingInst {
public var instance: Value { operand.value }
}
final public class UnownedReleaseInst : RefCountingInst {
public var instance: Value { operand.value }
}
final public class ReleaseValueInst : RefCountingInst {
public var value: Value { return operand.value }
}
final public class DestroyValueInst : Instruction, UnaryInstruction {

View File

@@ -76,6 +76,10 @@ public struct OperandArray : RandomAccessCollection, CustomReflectable {
base: OptionalBridgedOperand(op: base.advancedBy(bounds.lowerBound).op),
count: bounds.upperBound - bounds.lowerBound)
}
public var values: LazyMapSequence<LazySequence<OperandArray>.Elements, Value> {
self.lazy.map { $0.value }
}
}
public struct UseList : CollectionLikeSequence {

View File

@@ -54,8 +54,10 @@ public func registerSILClasses() {
register(EndApplyInst.self)
register(AbortApplyInst.self)
register(StrongRetainInst.self)
register(UnownedRetainInst.self)
register(RetainValueInst.self)
register(StrongReleaseInst.self)
register(UnownedReleaseInst.self)
register(ReleaseValueInst.self)
register(DestroyValueInst.self)
register(DestroyAddrInst.self)

View File

@@ -31,6 +31,10 @@ public struct Type : CustomStringConvertible, NoReflectionChildren {
return !bridged.isNonTrivialOrContainsRawPointer(function.bridged.getFunction())
}
/// True if this type is a value type (struct/enum) that requires deinitialization beyond
/// destruction of its members.
public var isValueTypeWithDeinit: Bool { bridged.isValueTypeWithDeinit() }
public func isLoadable(in function: Function) -> Bool {
return bridged.isLoadable(function.bridged.getFunction())
}
@@ -39,6 +43,10 @@ public struct Type : CustomStringConvertible, NoReflectionChildren {
return bridged.isReferenceCounted(function.bridged.getFunction())
}
public var isUnownedStorageType: Bool {
return bridged.isUnownedStorageType()
}
public var hasArchetype: Bool { bridged.hasArchetype() }
public var isNominal: Bool { bridged.getNominalOrBoundGenericNominal() != nil }