Skip to content

Commit ad9c73b

Browse files
committed
Swift SIL: add Operand.changeOwnership
1 parent 24e5a82 commit ad9c73b

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

SwiftCompilerSources/Sources/Optimizer/PassManager/Context.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,12 @@ extension Operand {
640640
func set(to value: Value, _ context: some MutatingContext) {
641641
instruction.setOperand(at: index, to: value, context)
642642
}
643+
644+
func changeOwnership(from: Ownership, to: Ownership, _ context: some MutatingContext) {
645+
context.notifyInstructionsChanged()
646+
bridged.changeOwnership(from._bridged, to._bridged)
647+
context.notifyInstructionChanged(instruction)
648+
}
643649
}
644650

645651
extension Instruction {

include/swift/SIL/SILBridging.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ struct BridgedOperand {
415415
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedValue getValue() const;
416416
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction getUser() const;
417417
BRIDGED_INLINE OperandOwnership getOperandOwnership() const;
418+
void changeOwnership(BridgedValue::Ownership from, BridgedValue::Ownership to) const;
418419
};
419420

420421
struct OptionalBridgedOperand {

lib/SIL/Utils/SILBridging.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,16 @@ static_assert((int)BridgedLinkage::PublicExternal == (int)swift::SILLinkage::Pub
303303
static_assert((int)BridgedLinkage::PackageExternal == (int)swift::SILLinkage::PackageExternal);
304304
static_assert((int)BridgedLinkage::HiddenExternal == (int)swift::SILLinkage::HiddenExternal);
305305

306+
//===----------------------------------------------------------------------===//
307+
// Operand
308+
//===----------------------------------------------------------------------===//
309+
310+
void BridgedOperand::changeOwnership(BridgedValue::Ownership from, BridgedValue::Ownership to) const {
311+
swift::ForwardingOperand forwardingOp(op);
312+
assert(forwardingOp);
313+
forwardingOp.replaceOwnershipKind(BridgedValue::castToOwnership(from), BridgedValue::castToOwnership(to));
314+
}
315+
306316
//===----------------------------------------------------------------------===//
307317
// SILGlobalVariable
308318
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)