Skip to content

Commit 3105733

Browse files
committed
Swift SIL: add some Instruction APIs
* getting the formal source and target types of casts * `isFromVarDecl` and `usesMoveableValueDebugInfo` for AllocStackInst * WitnessMethod APIs * `TryApply.isNonAsync`
1 parent 8adec32 commit 3105733

File tree

3 files changed

+96
-1
lines changed

3 files changed

+96
-1
lines changed

SwiftCompilerSources/Sources/SIL/Instruction.swift

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,13 @@ final public class DebugStepInst : Instruction {}
513513
final public class SpecifyTestInst : Instruction {}
514514

515515
final public class UnconditionalCheckedCastAddrInst : Instruction, SourceDestAddrInstruction {
516+
public var sourceFormalType: CanonicalType {
517+
CanonicalType(bridged: bridged.UnconditionalCheckedCastAddr_getSourceFormalType())
518+
}
519+
public var targetFormalType: CanonicalType {
520+
CanonicalType(bridged: bridged.UnconditionalCheckedCastAddr_getTargetFormalType())
521+
}
522+
516523
public var isTakeOfSrc: Bool { true }
517524
public var isInitializationOfDest: Bool { true }
518525
public override var mayTrap: Bool { true }
@@ -1013,6 +1020,13 @@ final public class KeyPathInst : SingleValueInstruction {
10131020
final public
10141021
class UnconditionalCheckedCastInst : SingleValueInstruction, UnaryInstruction {
10151022
public override var mayTrap: Bool { true }
1023+
1024+
public var sourceFormalType: CanonicalType {
1025+
CanonicalType(bridged: bridged.UnconditionalCheckedCast_getSourceFormalType())
1026+
}
1027+
public var targetFormalType: CanonicalType {
1028+
CanonicalType(bridged: bridged.UnconditionalCheckedCast_getTargetFormalType())
1029+
}
10161030
}
10171031

10181032
final public
@@ -1205,7 +1219,12 @@ final public class ObjCMethodInst : SingleValueInstruction, UnaryInstruction {}
12051219

12061220
final public class ObjCSuperMethodInst : SingleValueInstruction, UnaryInstruction {}
12071221

1208-
final public class WitnessMethodInst : SingleValueInstruction {}
1222+
final public class WitnessMethodInst : SingleValueInstruction {
1223+
public var member: DeclRef { DeclRef(bridged: bridged.WitnessMethodInst_getMember()) }
1224+
public var lookupType: CanonicalType { CanonicalType(bridged: bridged.WitnessMethodInst_getLookupType()) }
1225+
public var lookupProtocol: ProtocolDecl { bridged.WitnessMethodInst_getLookupProtocol().getAs(ProtocolDecl.self) }
1226+
public var conformance: Conformance { Conformance(bridged: bridged.WitnessMethodInst_getConformance()) }
1227+
}
12091228

12101229
final public class IsUniqueInst : SingleValueInstruction, UnaryInstruction {}
12111230

@@ -1265,6 +1284,8 @@ public protocol Allocation : SingleValueInstruction { }
12651284

12661285
final public class AllocStackInst : SingleValueInstruction, Allocation, DebugVariableInstruction, MetaInstruction {
12671286
public var hasDynamicLifetime: Bool { bridged.AllocStackInst_hasDynamicLifetime() }
1287+
public var isFromVarDecl: Bool { bridged.AllocStackInst_isFromVarDecl() }
1288+
public var usesMoveableValueDebugInfo: Bool { bridged.AllocStackInst_usesMoveableValueDebugInfo() }
12681289

12691290
public var varDecl: VarDecl? {
12701291
bridged.AllocStack_getDecl().getAs(VarDecl.self)
@@ -1612,6 +1633,7 @@ final public class TryApplyInst : TermInst, FullApplySite {
16121633

16131634
public var singleDirectResult: Value? { normalBlock.arguments[0] }
16141635

1636+
public var isNonAsync: Bool { bridged.TryApplyInst_getNonAsync() }
16151637
public var specializationInfo: ApplyInst.SpecializationInfo { bridged.TryApplyInst_getSpecializationInfo() }
16161638
}
16171639

@@ -1717,6 +1739,13 @@ final public class CheckedCastAddrBranchInst : TermInst {
17171739
public var source: Value { operands[0].value }
17181740
public var destination: Value { operands[1].value }
17191741

1742+
public var sourceFormalType: CanonicalType {
1743+
CanonicalType(bridged: bridged.CheckedCastAddrBranch_getSourceFormalType())
1744+
}
1745+
public var targetFormalType: CanonicalType {
1746+
CanonicalType(bridged: bridged.CheckedCastAddrBranch_getTargetFormalType())
1747+
}
1748+
17201749
public var successBlock: BasicBlock { bridged.CheckedCastAddrBranch_getSuccessBlock().block }
17211750
public var failureBlock: BasicBlock { bridged.CheckedCastAddrBranch_getFailureBlock().block }
17221751

include/swift/SIL/SILBridging.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ struct BridgedFunction;
3838
struct BridgedBasicBlock;
3939
struct BridgedSuccessorArray;
4040
struct OptionalBridgedBasicBlock;
41+
struct BridgedDeclRef;
4142

4243
namespace swift {
4344
class ValueBase;
@@ -769,12 +770,19 @@ struct BridgedInstruction {
769770
BRIDGED_INLINE bool ApplyInst_getNonThrowing() const;
770771
BRIDGED_INLINE bool ApplyInst_getNonAsync() const;
771772
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedGenericSpecializationInformation ApplyInst_getSpecializationInfo() const;
773+
BRIDGED_INLINE bool TryApplyInst_getNonAsync() const;
772774
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedGenericSpecializationInformation TryApplyInst_getSpecializationInfo() const;
775+
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedDeclRef WitnessMethodInst_getMember() const;
776+
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedCanType WitnessMethodInst_getLookupType() const;
777+
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedDeclObj WitnessMethodInst_getLookupProtocol() const;
778+
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedConformance WitnessMethodInst_getConformance() const;
773779
BRIDGED_INLINE SwiftInt ObjectInst_getNumBaseElements() const;
774780
BRIDGED_INLINE SwiftInt PartialApply_getCalleeArgIndexOfFirstAppliedArg() const;
775781
BRIDGED_INLINE bool PartialApplyInst_isOnStack() const;
776782
BRIDGED_INLINE bool PartialApplyInst_hasUnknownResultIsolation() const;
777783
BRIDGED_INLINE bool AllocStackInst_hasDynamicLifetime() const;
784+
BRIDGED_INLINE bool AllocStackInst_isFromVarDecl() const;
785+
BRIDGED_INLINE bool AllocStackInst_usesMoveableValueDebugInfo() const;
778786
BRIDGED_INLINE bool AllocRefInstBase_isObjc() const;
779787
BRIDGED_INLINE bool AllocRefInstBase_canAllocOnStack() const;
780788
BRIDGED_INLINE SwiftInt AllocRefInstBase_getNumTailTypes() const;
@@ -811,8 +819,14 @@ struct BridgedInstruction {
811819
BRIDGED_INLINE bool GlobalValueInst_isBare() const;
812820
BRIDGED_INLINE void GlobalValueInst_setIsBare() const;
813821
BRIDGED_INLINE void LoadInst_setOwnership(SwiftInt ownership) const;
822+
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedCanType UnconditionalCheckedCast_getSourceFormalType() const;
823+
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedCanType UnconditionalCheckedCast_getTargetFormalType() const;
824+
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedCanType UnconditionalCheckedCastAddr_getSourceFormalType() const;
825+
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedCanType UnconditionalCheckedCastAddr_getTargetFormalType() const;
814826
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedBasicBlock CheckedCastBranch_getSuccessBlock() const;
815827
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedBasicBlock CheckedCastBranch_getFailureBlock() const;
828+
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedCanType CheckedCastAddrBranch_getSourceFormalType() const;
829+
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedCanType CheckedCastAddrBranch_getTargetFormalType() const;
816830
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedBasicBlock CheckedCastAddrBranch_getSuccessBlock() const;
817831
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedBasicBlock CheckedCastAddrBranch_getFailureBlock() const;
818832
BRIDGED_INLINE void CheckedCastBranch_updateSourceFormalTypeFromOperandLoweredType() const;

include/swift/SIL/SILBridgingImpl.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,10 +1336,30 @@ BridgedGenericSpecializationInformation BridgedInstruction::ApplyInst_getSpecial
13361336
return {getAs<swift::ApplyInst>()->getSpecializationInfo()};
13371337
}
13381338

1339+
bool BridgedInstruction::TryApplyInst_getNonAsync() const {
1340+
return getAs<swift::TryApplyInst>()->isNonAsync();
1341+
}
1342+
13391343
BridgedGenericSpecializationInformation BridgedInstruction::TryApplyInst_getSpecializationInfo() const {
13401344
return {getAs<swift::TryApplyInst>()->getSpecializationInfo()};
13411345
}
13421346

1347+
BridgedDeclRef BridgedInstruction::WitnessMethodInst_getMember() const {
1348+
return getAs<swift::WitnessMethodInst>()->getMember();
1349+
}
1350+
1351+
BridgedCanType BridgedInstruction::WitnessMethodInst_getLookupType() const {
1352+
return getAs<swift::WitnessMethodInst>()->getLookupType();
1353+
}
1354+
1355+
BridgedDeclObj BridgedInstruction::WitnessMethodInst_getLookupProtocol() const {
1356+
return getAs<swift::WitnessMethodInst>()->getLookupProtocol();
1357+
}
1358+
1359+
BridgedConformance BridgedInstruction::WitnessMethodInst_getConformance() const {
1360+
return getAs<swift::WitnessMethodInst>()->getConformance();
1361+
}
1362+
13431363
SwiftInt BridgedInstruction::ObjectInst_getNumBaseElements() const {
13441364
return getAs<swift::ObjectInst>()->getNumBaseElements();
13451365
}
@@ -1360,6 +1380,14 @@ bool BridgedInstruction::AllocStackInst_hasDynamicLifetime() const {
13601380
return getAs<swift::AllocStackInst>()->hasDynamicLifetime();
13611381
}
13621382

1383+
bool BridgedInstruction::AllocStackInst_isFromVarDecl() const {
1384+
return getAs<swift::AllocStackInst>()->isFromVarDecl();
1385+
}
1386+
1387+
bool BridgedInstruction::AllocStackInst_usesMoveableValueDebugInfo() const {
1388+
return getAs<swift::AllocStackInst>()->usesMoveableValueDebugInfo();
1389+
}
1390+
13631391
bool BridgedInstruction::AllocRefInstBase_isObjc() const {
13641392
return getAs<swift::AllocRefInstBase>()->isObjC();
13651393
}
@@ -1523,6 +1551,22 @@ void BridgedInstruction::CheckedCastBranch_updateSourceFormalTypeFromOperandLowe
15231551
getAs<swift::CheckedCastBranchInst>()->updateSourceFormalTypeFromOperandLoweredType();
15241552
}
15251553

1554+
BridgedCanType BridgedInstruction::UnconditionalCheckedCast_getSourceFormalType() const {
1555+
return {getAs<swift::UnconditionalCheckedCastInst>()->getSourceFormalType()};
1556+
}
1557+
1558+
BridgedCanType BridgedInstruction::UnconditionalCheckedCast_getTargetFormalType() const {
1559+
return {getAs<swift::UnconditionalCheckedCastInst>()->getTargetFormalType()};
1560+
}
1561+
1562+
BridgedCanType BridgedInstruction::UnconditionalCheckedCastAddr_getSourceFormalType() const {
1563+
return {getAs<swift::UnconditionalCheckedCastAddrInst>()->getSourceFormalType()};
1564+
}
1565+
1566+
BridgedCanType BridgedInstruction::UnconditionalCheckedCastAddr_getTargetFormalType() const {
1567+
return {getAs<swift::UnconditionalCheckedCastAddrInst>()->getTargetFormalType()};
1568+
}
1569+
15261570
BridgedBasicBlock BridgedInstruction::CheckedCastBranch_getSuccessBlock() const {
15271571
return {getAs<swift::CheckedCastBranchInst>()->getSuccessBB()};
15281572
}
@@ -1531,6 +1575,14 @@ BridgedBasicBlock BridgedInstruction::CheckedCastBranch_getFailureBlock() const
15311575
return {getAs<swift::CheckedCastBranchInst>()->getFailureBB()};
15321576
}
15331577

1578+
BridgedCanType BridgedInstruction::CheckedCastAddrBranch_getSourceFormalType() const {
1579+
return {getAs<swift::CheckedCastAddrBranchInst>()->getSourceFormalType()};
1580+
}
1581+
1582+
BridgedCanType BridgedInstruction::CheckedCastAddrBranch_getTargetFormalType() const {
1583+
return {getAs<swift::CheckedCastAddrBranchInst>()->getTargetFormalType()};
1584+
}
1585+
15341586
BridgedBasicBlock BridgedInstruction::CheckedCastAddrBranch_getSuccessBlock() const {
15351587
return {getAs<swift::CheckedCastAddrBranchInst>()->getSuccessBB()};
15361588
}

0 commit comments

Comments
 (0)