Skip to content

Commit d2f8c0c

Browse files
committed
Swift SIL: add some Instruction APIs
* `OpenExistentialAddrInst.isImmutable` * `YieldInst.convention` * `CopyAddrInst.set(isTakeOfSource:)` and `CopyAddrInst.set(isInitializationOfDestination:)`
1 parent 8f39c3c commit d2f8c0c

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

SwiftCompilerSources/Sources/Optimizer/PassManager/Context.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,20 @@ extension PointerToAddressInst {
757757
}
758758
}
759759

760+
extension CopyAddrInst {
761+
func set(isTakeOfSource: Bool, _ context: some MutatingContext) {
762+
context.notifyInstructionsChanged()
763+
bridged.CopyAddrInst_setIsTakeOfSrc(isTakeOfSource)
764+
context.notifyInstructionChanged(self)
765+
}
766+
767+
func set(isInitializationOfDestination: Bool, _ context: some MutatingContext) {
768+
context.notifyInstructionsChanged()
769+
bridged.CopyAddrInst_setIsInitializationOfDest(isInitializationOfDestination)
770+
context.notifyInstructionChanged(self)
771+
}
772+
}
773+
760774
extension TermInst {
761775
func replaceBranchTarget(from fromBlock: BasicBlock, to toBlock: BasicBlock, _ context: some MutatingContext) {
762776
context.notifyBranchesChanged()

SwiftCompilerSources/Sources/SIL/Instruction.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,9 @@ final public
829829
class DeinitExistentialValueInst : Instruction {}
830830

831831
final public
832-
class OpenExistentialAddrInst : SingleValueInstruction, UnaryInstruction {}
832+
class OpenExistentialAddrInst : SingleValueInstruction, UnaryInstruction {
833+
public var isImmutable: Bool { bridged.OpenExistentialAddr_isImmutable() }
834+
}
833835

834836
final public
835837
class OpenExistentialBoxInst : SingleValueInstruction, UnaryInstruction {}
@@ -1696,6 +1698,9 @@ final public class ThrowAddrInst : TermInst {
16961698
}
16971699

16981700
final public class YieldInst : TermInst {
1701+
public func convention(of operand: Operand) -> ArgumentConvention {
1702+
return bridged.YieldInst_getConvention(operand.bridged).convention
1703+
}
16991704
}
17001705

17011706
final public class UnwindInst : TermInst {

include/swift/SIL/SILBridging.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,7 @@ struct BridgedInstruction {
732732
BRIDGED_INLINE bool IndexAddrInst_needsStackProtection() const;
733733
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedConformanceArray InitExistentialRefInst_getConformances() const;
734734
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedCanType InitExistentialRefInst_getFormalConcreteType() const;
735+
BRIDGED_INLINE bool OpenExistentialAddr_isImmutable() const;
735736
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedGlobalVar GlobalAccessInst_getGlobal() const;
736737
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedGlobalVar AllocGlobalInst_getGlobal() const;
737738
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedFunction FunctionRefBaseInst_getReferencedFunction() const;
@@ -791,6 +792,7 @@ struct BridgedInstruction {
791792
BRIDGED_INLINE SwiftInt BeginApplyInst_numArguments() const;
792793
BRIDGED_INLINE bool BeginApplyInst_isCalleeAllocated() const;
793794
BRIDGED_INLINE SwiftInt TryApplyInst_numArguments() const;
795+
BRIDGED_INLINE BridgedArgumentConvention YieldInst_getConvention(BridgedOperand forOperand) const;
794796
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedBasicBlock BranchInst_getTargetBlock() const;
795797
BRIDGED_INLINE SwiftInt SwitchEnumInst_getNumCases() const;
796798
BRIDGED_INLINE SwiftInt SwitchEnumInst_getCaseIndex(SwiftInt idx) const;
@@ -807,6 +809,8 @@ struct BridgedInstruction {
807809
BRIDGED_INLINE bool BeginAccessInst_isUnsafe() const;
808810
BRIDGED_INLINE bool CopyAddrInst_isTakeOfSrc() const;
809811
BRIDGED_INLINE bool CopyAddrInst_isInitializationOfDest() const;
812+
BRIDGED_INLINE void CopyAddrInst_setIsTakeOfSrc(bool isTakeOfSrc) const;
813+
BRIDGED_INLINE void CopyAddrInst_setIsInitializationOfDest(bool isInitializationOfDest) const;
810814
BRIDGED_INLINE bool ExplicitCopyAddrInst_isTakeOfSrc() const;
811815
BRIDGED_INLINE bool ExplicitCopyAddrInst_isInitializationOfDest() const;
812816
BRIDGED_INLINE SwiftInt MarkUninitializedInst_getKind() const;

include/swift/SIL/SILBridgingImpl.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,13 @@ BridgedCanType BridgedInstruction::InitExistentialRefInst_getFormalConcreteType(
11441144
return getAs<swift::InitExistentialRefInst>()->getFormalConcreteType();
11451145
}
11461146

1147+
bool BridgedInstruction::OpenExistentialAddr_isImmutable() const {
1148+
switch (getAs<swift::OpenExistentialAddrInst>()->getAccessKind()) {
1149+
case swift::OpenedExistentialAccess::Immutable: return true;
1150+
case swift::OpenedExistentialAccess::Mutable: return false;
1151+
}
1152+
}
1153+
11471154
BridgedGlobalVar BridgedInstruction::GlobalAccessInst_getGlobal() const {
11481155
return {getAs<swift::GlobalAccessInst>()->getReferencedGlobal()};
11491156
}
@@ -1381,6 +1388,10 @@ SwiftInt BridgedInstruction::TryApplyInst_numArguments() const {
13811388
return getAs<swift::TryApplyInst>()->getNumArguments();
13821389
}
13831390

1391+
BridgedArgumentConvention BridgedInstruction::YieldInst_getConvention(BridgedOperand forOperand) const {
1392+
return castToArgumentConvention(getAs<swift::YieldInst>()->getArgumentConventionForOperand(*forOperand.op));
1393+
}
1394+
13841395
BridgedBasicBlock BridgedInstruction::BranchInst_getTargetBlock() const {
13851396
return {getAs<swift::BranchInst>()->getDestBB()};
13861397
}
@@ -1446,6 +1457,15 @@ bool BridgedInstruction::CopyAddrInst_isInitializationOfDest() const {
14461457
return getAs<swift::CopyAddrInst>()->isInitializationOfDest();
14471458
}
14481459

1460+
void BridgedInstruction::CopyAddrInst_setIsTakeOfSrc(bool isTakeOfSrc) const {
1461+
return getAs<swift::CopyAddrInst>()->setIsTakeOfSrc(isTakeOfSrc ? swift::IsTake : swift::IsNotTake);
1462+
}
1463+
1464+
void BridgedInstruction::CopyAddrInst_setIsInitializationOfDest(bool isInitializationOfDest) const {
1465+
return getAs<swift::CopyAddrInst>()->setIsInitializationOfDest(
1466+
isInitializationOfDest ? swift::IsInitialization : swift::IsNotInitialization);
1467+
}
1468+
14491469
bool BridgedInstruction::ExplicitCopyAddrInst_isTakeOfSrc() const {
14501470
return getAs<swift::ExplicitCopyAddrInst>()->isTakeOfSrc();
14511471
}

0 commit comments

Comments
 (0)