Skip to content

Commit a69fb95

Browse files
committed
SwiftCompilerSources API for SourceDestAddrInstructions.
1 parent 7b4225c commit a69fb95

File tree

4 files changed

+52
-5
lines changed

4 files changed

+52
-5
lines changed

SwiftCompilerSources/Sources/SIL/Instruction.swift

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ extension UnaryInstruction {
254254
final public class UnimplementedInstruction : Instruction {
255255
}
256256

257+
/// Only one of the operands may have an address type.
257258
public protocol StoringInstruction : Instruction {
258259
var operands: OperandArray { get }
259260
}
@@ -303,14 +304,16 @@ final public class AssignInst : Instruction, StoringInstruction {
303304
}
304305
}
305306

306-
final public class AssignByWrapperInst : Instruction {}
307+
final public class AssignByWrapperInst : Instruction, StoringInstruction {}
307308

308-
final public class AssignOrInitInst : Instruction {}
309+
final public class AssignOrInitInst : Instruction, StoringInstruction {}
309310

310311
/// Instruction that copy or move from a source to destination address.
311312
public protocol SourceDestAddrInstruction : Instruction {
312313
var sourceOperand: Operand { get }
313314
var destinationOperand: Operand { get }
315+
var isTakeOfSrc: Bool { get }
316+
var isInitializationOfDest: Bool { get }
314317
}
315318

316319
extension SourceDestAddrInstruction {
@@ -333,6 +336,13 @@ final public class CopyAddrInst : Instruction, SourceDestAddrInstruction {
333336
final public class ExplicitCopyAddrInst : Instruction, SourceDestAddrInstruction {
334337
public var source: Value { return sourceOperand.value }
335338
public var destination: Value { return destinationOperand.value }
339+
340+
public var isTakeOfSrc: Bool {
341+
bridged.ExplicitCopyAddrInst_isTakeOfSrc()
342+
}
343+
public var isInitializationOfDest: Bool {
344+
bridged.ExplicitCopyAddrInst_isInitializationOfDest()
345+
}
336346
}
337347

338348
final public class EndAccessInst : Instruction, UnaryInstruction {
@@ -590,7 +600,10 @@ class UncheckedRefCastInst : SingleValueInstruction, ConversionInstruction {
590600
}
591601

592602
final public
593-
class UncheckedRefCastAddrInst : Instruction, SourceDestAddrInstruction {}
603+
class UncheckedRefCastAddrInst : Instruction, SourceDestAddrInstruction {
604+
public var isTakeOfSrc: Bool { true }
605+
public var isInitializationOfDest: Bool { true }
606+
}
594607

595608
final public class UncheckedAddrCastInst : SingleValueInstruction, UnaryInstruction {
596609
public var fromAddress: Value { operand.value }
@@ -777,7 +790,9 @@ class TupleElementAddrInst : SingleValueInstruction, UnaryInstruction {
777790
public var fieldIndex: Int { bridged.TupleElementAddrInst_fieldIndex() }
778791
}
779792

780-
final public class TupleAddrConstructorInst : Instruction {}
793+
final public class TupleAddrConstructorInst : Instruction {
794+
public var destinationOperand: Operand { operands[0] }
795+
}
781796

782797
final public class StructInst : SingleValueInstruction, ForwardingInstruction {
783798
}
@@ -1027,7 +1042,10 @@ final public class IsEscapingClosureInst : SingleValueInstruction, UnaryInstruct
10271042
final public
10281043
class MarkUnresolvedNonCopyableValueInst : SingleValueInstruction, UnaryInstruction {}
10291044

1030-
final public class MarkUnresolvedMoveAddrInst : Instruction, SourceDestAddrInstruction {}
1045+
final public class MarkUnresolvedMoveAddrInst : Instruction, SourceDestAddrInstruction {
1046+
public var isTakeOfSrc: Bool { true }
1047+
public var isInitializationOfDest: Bool { true }
1048+
}
10311049

10321050
final public
10331051
class CopyableToMoveOnlyWrapperAddrInst : SingleValueInstruction, UnaryInstruction {}

SwiftCompilerSources/Sources/SIL/Operand.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,25 @@ extension Sequence where Element == Operand {
163163
}
164164
}
165165

166+
extension Operand {
167+
/// Return true if this operation will store a full value into this
168+
/// operand's address.
169+
public var isAddressInitialization: Bool {
170+
if !value.type.isAddress {
171+
return false
172+
}
173+
switch instruction {
174+
case is StoringInstruction:
175+
return true
176+
case let srcDestInst as SourceDestAddrInstruction
177+
where srcDestInst.destinationOperand == self:
178+
return true
179+
default:
180+
return false
181+
}
182+
}
183+
}
184+
166185
extension OptionalBridgedOperand {
167186
init(bridged: BridgedOperand?) {
168187
self = OptionalBridgedOperand(op: bridged?.op)

include/swift/SIL/SILBridging.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,8 @@ struct BridgedInstruction {
826826
BRIDGED_INLINE bool BeginAccessInst_isStatic() const;
827827
BRIDGED_INLINE bool CopyAddrInst_isTakeOfSrc() const;
828828
BRIDGED_INLINE bool CopyAddrInst_isInitializationOfDest() const;
829+
BRIDGED_INLINE bool ExplicitCopyAddrInst_isTakeOfSrc() const;
830+
BRIDGED_INLINE bool ExplicitCopyAddrInst_isInitializationOfDest() const;
829831
BRIDGED_INLINE SwiftInt MarkUninitializedInst_getKind() const;
830832
BRIDGED_INLINE void RefCountingInst_setIsAtomic(bool isAtomic) const;
831833
BRIDGED_INLINE bool RefCountingInst_getIsAtomic() const;

include/swift/SIL/SILBridgingImpl.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,14 @@ bool BridgedInstruction::CopyAddrInst_isInitializationOfDest() const {
10921092
return getAs<swift::CopyAddrInst>()->isInitializationOfDest();
10931093
}
10941094

1095+
bool BridgedInstruction::ExplicitCopyAddrInst_isTakeOfSrc() const {
1096+
return getAs<swift::ExplicitCopyAddrInst>()->isTakeOfSrc();
1097+
}
1098+
1099+
bool BridgedInstruction::ExplicitCopyAddrInst_isInitializationOfDest() const {
1100+
return getAs<swift::ExplicitCopyAddrInst>()->isInitializationOfDest();
1101+
}
1102+
10951103
SwiftInt BridgedInstruction::MarkUninitializedInst_getKind() const {
10961104
return (SwiftInt)getAs<swift::MarkUninitializedInst>()->getMarkUninitializedKind();
10971105
}

0 commit comments

Comments
 (0)