Skip to content

Commit ad0c27e

Browse files
committed
Handle Unmanaged(Retain|Release)ValueInst as RefCountingInst
1 parent d203164 commit ad0c27e

File tree

7 files changed

+29
-17
lines changed

7 files changed

+29
-17
lines changed

include/swift/SIL/SILBuilder.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -819,17 +819,19 @@ class SILBuilder {
819819
}
820820

821821
UnmanagedRetainValueInst *createUnmanagedRetainValue(SILLocation Loc,
822-
SILValue operand) {
822+
SILValue operand,
823+
Atomicity atomicity) {
823824
assert(F.hasQualifiedOwnership());
824825
return insert(new (F.getModule()) UnmanagedRetainValueInst(
825-
getSILDebugLocation(Loc), operand));
826+
getSILDebugLocation(Loc), operand, atomicity));
826827
}
827828

828829
UnmanagedReleaseValueInst *createUnmanagedReleaseValue(SILLocation Loc,
829-
SILValue operand) {
830+
SILValue operand,
831+
Atomicity atomicity) {
830832
assert(F.hasQualifiedOwnership());
831833
return insert(new (F.getModule()) UnmanagedReleaseValueInst(
832-
getSILDebugLocation(Loc), operand));
834+
getSILDebugLocation(Loc), operand, atomicity));
833835
}
834836

835837
CopyValueInst *createCopyValue(SILLocation Loc, SILValue operand) {

include/swift/SIL/SILCloner.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,8 @@ void SILCloner<ImplClass>::visitUnmanagedRetainValueInst(
11761176
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
11771177
doPostProcess(
11781178
Inst, getBuilder().createUnmanagedRetainValue(
1179-
getOpLocation(Inst->getLoc()), getOpValue(Inst->getOperand())));
1179+
getOpLocation(Inst->getLoc()), getOpValue(Inst->getOperand()),
1180+
Inst->getAtomicity()));
11801181
}
11811182

11821183
template <typename ImplClass>
@@ -1211,7 +1212,8 @@ void SILCloner<ImplClass>::visitUnmanagedReleaseValueInst(
12111212
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
12121213
doPostProcess(
12131214
Inst, getBuilder().createUnmanagedReleaseValue(
1214-
getOpLocation(Inst->getLoc()), getOpValue(Inst->getOperand())));
1215+
getOpLocation(Inst->getLoc()), getOpValue(Inst->getOperand()),
1216+
Inst->getAtomicity()));
12151217
}
12161218

12171219
template <typename ImplClass>

include/swift/SIL/SILInstruction.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3021,8 +3021,11 @@ class UnmanagedRetainValueInst
30213021
/*HasValue*/ false> {
30223022
friend SILBuilder;
30233023

3024-
UnmanagedRetainValueInst(SILDebugLocation DebugLoc, SILValue operand)
3025-
: UnaryInstructionBase(DebugLoc, operand) {}
3024+
UnmanagedRetainValueInst(SILDebugLocation DebugLoc, SILValue operand,
3025+
Atomicity atomicity)
3026+
: UnaryInstructionBase(DebugLoc, operand) {
3027+
setAtomicity(atomicity);
3028+
}
30263029
};
30273030

30283031
/// Destroys a loadable value in an unmanaged, unbalanced way. Only meant for
@@ -3034,8 +3037,11 @@ class UnmanagedReleaseValueInst
30343037
/*HasValue*/ false> {
30353038
friend SILBuilder;
30363039

3037-
UnmanagedReleaseValueInst(SILDebugLocation DebugLoc, SILValue operand)
3038-
: UnaryInstructionBase(DebugLoc, operand) {}
3040+
UnmanagedReleaseValueInst(SILDebugLocation DebugLoc, SILValue operand,
3041+
Atomicity atomicity)
3042+
: UnaryInstructionBase(DebugLoc, operand) {
3043+
setAtomicity(atomicity);
3044+
}
30393045
};
30403046

30413047
/// Transfers ownership of a loadable value to the current autorelease

lib/Parse/ParseSIL.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2133,8 +2133,8 @@ bool SILParser::parseSILInstruction(SILBasicBlock *BB, SILBuilder &B) {
21332133
UNARY_INSTRUCTION(DestroyValue)
21342134
UNARY_INSTRUCTION(CondFail)
21352135
UNARY_INSTRUCTION(EndBorrowArgument)
2136-
UNARY_INSTRUCTION(UnmanagedReleaseValue)
2137-
UNARY_INSTRUCTION(UnmanagedRetainValue)
2136+
REFCOUNTING_INSTRUCTION(UnmanagedReleaseValue)
2137+
REFCOUNTING_INSTRUCTION(UnmanagedRetainValue)
21382138
REFCOUNTING_INSTRUCTION(UnmanagedAutoreleaseValue)
21392139
REFCOUNTING_INSTRUCTION(StrongPin)
21402140
REFCOUNTING_INSTRUCTION(StrongRetain)

lib/SILGen/SILGenBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ SILGenBuilder::createUnsafeCopyUnownedValue(SILLocation loc,
209209
SILValue result = SILBuilder::createUnmanagedToRef(
210210
loc, originalValue.getValue(),
211211
SILType::getPrimitiveObjectType(unmanagedType.getReferentType()));
212-
SILBuilder::createUnmanagedRetainValue(loc, result);
212+
SILBuilder::createUnmanagedRetainValue(loc, result, getDefaultAtomicity());
213213
return gen.emitManagedRValueWithCleanup(result);
214214
}
215215

lib/SILGen/SILGenBuiltin.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ static ManagedValue emitBuiltinRetain(SILGenFunction &gen,
7272
// The value was produced at +1; we can produce an unbalanced retain simply by
7373
// disabling the cleanup. But this would violate ownership semantics. Instead,
7474
// we must allow for the cleanup and emit a new unmanaged retain value.
75-
gen.B.createUnmanagedRetainValue(loc, args[0].getValue());
75+
gen.B.createUnmanagedRetainValue(loc, args[0].getValue(),
76+
gen.B.getDefaultAtomicity());
7677
return ManagedValue::forUnmanaged(gen.emitEmptyTuple(loc));
7778
}
7879

@@ -85,7 +86,8 @@ static ManagedValue emitBuiltinRelease(SILGenFunction &gen,
8586
// The value was produced at +1, so to produce an unbalanced
8687
// release we need to leave the cleanup intact and then do a *second*
8788
// release.
88-
gen.B.createUnmanagedReleaseValue(loc, args[0].getValue());
89+
gen.B.createUnmanagedReleaseValue(loc, args[0].getValue(),
90+
gen.B.getDefaultAtomicity());
8991
return ManagedValue::forUnmanaged(gen.emitEmptyTuple(loc));
9092
}
9193

lib/Serialization/DeserializeSIL.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,12 +1343,12 @@ bool SILDeserializer::readSILInstruction(SILFunction *Fn, SILBasicBlock *BB,
13431343

13441344
UNARY_INSTRUCTION(CondFail)
13451345
REFCOUNTING_INSTRUCTION(RetainValue)
1346-
UNARY_INSTRUCTION(UnmanagedRetainValue)
1346+
REFCOUNTING_INSTRUCTION(UnmanagedRetainValue)
13471347
UNARY_INSTRUCTION(CopyValue)
13481348
UNARY_INSTRUCTION(CopyUnownedValue)
13491349
UNARY_INSTRUCTION(DestroyValue)
13501350
REFCOUNTING_INSTRUCTION(ReleaseValue)
1351-
UNARY_INSTRUCTION(UnmanagedReleaseValue)
1351+
REFCOUNTING_INSTRUCTION(UnmanagedReleaseValue)
13521352
REFCOUNTING_INSTRUCTION(AutoreleaseValue)
13531353
REFCOUNTING_INSTRUCTION(UnmanagedAutoreleaseValue)
13541354
REFCOUNTING_INSTRUCTION(SetDeallocating)

0 commit comments

Comments
 (0)