Skip to content

Commit 084d60d

Browse files
committed
Swift SIL: add some APIs to instructions and other small improvments
1 parent 0f359ff commit 084d60d

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

SwiftCompilerSources/Sources/SIL/Instruction.swift

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ public class Instruction : CustomStringConvertible, Hashable {
4848
return OperandArray(base: operands.base, count: operands.count)
4949
}
5050

51-
// All operands defined by the operation. Returns the prefix of `operands` that does not include trailing type dependent operands.
51+
// All operands defined by the operation.
52+
// Returns the prefix of `operands` that does not include trailing type dependent operands.
5253
final public var definedOperands: OperandArray {
5354
let operands = bridged.getOperands()
5455
let typeOperands = bridged.getTypeDependentOperands()
@@ -237,7 +238,7 @@ public class MultipleValueInstruction : Instruction {
237238
}
238239
}
239240

240-
/// Instructions, which have a single operand.
241+
/// Instructions, which have a single operand (not including type-dependent operands).
241242
public protocol UnaryInstruction : Instruction {
242243
var operand: Operand { get }
243244
}
@@ -311,14 +312,13 @@ public protocol SourceDestAddrInstruction : Instruction {
311312
}
312313

313314
extension SourceDestAddrInstruction {
314-
public var sourceOperand: Operand { return operands[0] }
315-
public var destinationOperand: Operand { return operands[1] }
315+
public var sourceOperand: Operand { operands[0] }
316+
public var destinationOperand: Operand { operands[1] }
317+
public var source: Value { sourceOperand.value }
318+
public var destination: Value { destinationOperand.value }
316319
}
317320

318321
final public class CopyAddrInst : Instruction, SourceDestAddrInstruction {
319-
public var source: Value { return sourceOperand.value }
320-
public var destination: Value { return destinationOperand.value }
321-
322322
public var isTakeOfSrc: Bool {
323323
bridged.CopyAddrInst_isTakeOfSrc()
324324
}
@@ -681,7 +681,7 @@ final public
681681
class InitExistentialAddrInst : SingleValueInstruction, UnaryInstruction {}
682682

683683
final public
684-
class DeinitExistentialAddrInst : Instruction {}
684+
class DeinitExistentialAddrInst : Instruction, UnaryInstruction {}
685685

686686
final public
687687
class DeinitExistentialValueInst : Instruction {}
@@ -873,6 +873,8 @@ final public class RefElementAddrInst : SingleValueInstruction, UnaryInstruction
873873

874874
final public class RefTailAddrInst : SingleValueInstruction, UnaryInstruction {
875875
public var instance: Value { operand.value }
876+
877+
public var isImmutable: Bool { bridged.RefTailAddrInst_isImmutable() }
876878
}
877879

878880
final public class KeyPathInst : SingleValueInstruction {
@@ -1219,7 +1221,9 @@ extension Instruction {
12191221
/// Instructions beginning a borrow-scope which must be ended by `end_borrow`.
12201222
public protocol BorrowIntroducingInstruction : SingleValueInstruction, ScopedInstruction {}
12211223

1222-
final public class EndBorrowInst : Instruction, UnaryInstruction {}
1224+
final public class EndBorrowInst : Instruction, UnaryInstruction {
1225+
public var borrow: Value { operand.value }
1226+
}
12231227

12241228
extension BorrowIntroducingInstruction {
12251229
public var endOperands: LazyFilterSequence<UseList> {
@@ -1264,6 +1268,7 @@ final public class BeginAccessInst : SingleValueInstruction, UnaryInstruction {
12641268
}
12651269

12661270
public var isStatic: Bool { bridged.BeginAccessInst_isStatic() }
1271+
public var isUnsafe: Bool { bridged.BeginAccessInst_isUnsafe() }
12671272

12681273
public var address: Value { operand.value }
12691274

@@ -1304,8 +1309,15 @@ final public class BeginApplyInst : MultipleValueInstruction, FullApplySite {
13041309
}
13051310
}
13061311

1307-
final public class EndApplyInst : Instruction, UnaryInstruction {}
1308-
final public class AbortApplyInst : Instruction, UnaryInstruction {}
1312+
final public class EndApplyInst : Instruction, UnaryInstruction {
1313+
public var token: MultipleValueInstructionResult { operand.value as! MultipleValueInstructionResult }
1314+
public var beginApply: BeginApplyInst { token.parentInstruction as! BeginApplyInst }
1315+
}
1316+
1317+
final public class AbortApplyInst : Instruction, UnaryInstruction {
1318+
public var token: MultipleValueInstructionResult { operand.value as! MultipleValueInstructionResult }
1319+
public var beginApply: BeginApplyInst { token.parentInstruction as! BeginApplyInst }
1320+
}
13091321

13101322
extension BeginApplyInst : ScopedInstruction {
13111323
public var endOperands: LazyFilterSequence<UseList> {

include/swift/SIL/SILBridging.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,7 @@ struct BridgedInstruction {
960960
BRIDGED_INLINE bool RefElementAddrInst_fieldIsLet() const;
961961
BRIDGED_INLINE bool RefElementAddrInst_isImmutable() const;
962962
BRIDGED_INLINE void RefElementAddrInst_setImmutable(bool isImmutable) const;
963+
BRIDGED_INLINE bool RefTailAddrInst_isImmutable() const;
963964
BRIDGED_INLINE SwiftInt PartialApplyInst_numArguments() const;
964965
BRIDGED_INLINE SwiftInt ApplyInst_numArguments() const;
965966
BRIDGED_INLINE bool ApplyInst_getNonThrowing() const;
@@ -987,6 +988,7 @@ struct BridgedInstruction {
987988
BRIDGED_INLINE void MarkDependenceInst_resolveToNonEscaping() const;
988989
BRIDGED_INLINE SwiftInt BeginAccessInst_getAccessKind() const;
989990
BRIDGED_INLINE bool BeginAccessInst_isStatic() const;
991+
BRIDGED_INLINE bool BeginAccessInst_isUnsafe() const;
990992
BRIDGED_INLINE bool CopyAddrInst_isTakeOfSrc() const;
991993
BRIDGED_INLINE bool CopyAddrInst_isInitializationOfDest() const;
992994
BRIDGED_INLINE bool ExplicitCopyAddrInst_isTakeOfSrc() const;

include/swift/SIL/SILBridgingImpl.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,10 @@ void BridgedInstruction::RefElementAddrInst_setImmutable(bool isImmutable) const
11471147
getAs<swift::RefElementAddrInst>()->setImmutable(isImmutable);
11481148
}
11491149

1150+
bool BridgedInstruction::RefTailAddrInst_isImmutable() const {
1151+
return getAs<swift::RefTailAddrInst>()->isImmutable();
1152+
}
1153+
11501154
SwiftInt BridgedInstruction::PartialApplyInst_numArguments() const {
11511155
return getAs<swift::PartialApplyInst>()->getNumArguments();
11521156
}
@@ -1256,6 +1260,10 @@ bool BridgedInstruction::BeginAccessInst_isStatic() const {
12561260
return getAs<swift::BeginAccessInst>()->getEnforcement() == swift::SILAccessEnforcement::Static;
12571261
}
12581262

1263+
bool BridgedInstruction::BeginAccessInst_isUnsafe() const {
1264+
return getAs<swift::BeginAccessInst>()->getEnforcement() == swift::SILAccessEnforcement::Unsafe;
1265+
}
1266+
12591267
bool BridgedInstruction::CopyAddrInst_isTakeOfSrc() const {
12601268
return getAs<swift::CopyAddrInst>()->isTakeOfSrc();
12611269
}

0 commit comments

Comments
 (0)