Skip to content

Commit 0d0cac3

Browse files
author
Joe Shajrawi
committed
retain_value_addr and release_value_addr SIL instructions: take as an input an address, load the value inside it and call retain_value and release_value respectively
1 parent d17258c commit 0d0cac3

30 files changed

+288
-6
lines changed

docs/ABI.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,8 @@ Globals
794794

795795
global ::= type 'Wy' // Outlined Copy Function Type
796796
global ::= type 'We' // Outlined Consume Function Type
797+
global ::= type 'Wr' // Outlined Retain Function Type
798+
global ::= type 'Ws' // Outlined Release Function Type
797799

798800
DIRECTNESS ::= 'd' // direct
799801
DIRECTNESS ::= 'i' // indirect

docs/SIL.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3299,6 +3299,18 @@ For aggregate types, especially enums, it is typically both easier
32993299
and more efficient to reason about aggregate copies than it is to
33003300
reason about copies of the subobjects.
33013301

3302+
retain_value_addr
3303+
`````````````````
3304+
3305+
::
3306+
3307+
sil-instruction ::= 'retain_value_addr' sil-operand
3308+
3309+
retain_value_addr %0 : $*A
3310+
3311+
Retains a loadable value inside given address,
3312+
which simply retains any references it holds.
3313+
33023314
unmanaged_retain_value
33033315
``````````````````````
33043316

@@ -3365,6 +3377,18 @@ For aggregate types, especially enums, it is typically both easier
33653377
and more efficient to reason about aggregate destroys than it is to
33663378
reason about destroys of the subobjects.
33673379

3380+
release_value_addr
3381+
``````````````````
3382+
3383+
::
3384+
3385+
sil-instruction ::= 'release_value_addr' sil-operand
3386+
3387+
release_value_addr %0 : $*A
3388+
3389+
Destroys a loadable value inside given address,
3390+
by releasing any retainable pointers within it.
3391+
33683392
unmanaged_release_value
33693393
```````````````````````
33703394

include/swift/Demangling/DemangleNodes.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,5 +181,7 @@ NODE(FirstElementMarker)
181181
NODE(VariadicMarker)
182182
NODE(OutlinedCopy)
183183
NODE(OutlinedConsume)
184+
NODE(OutlinedRetain)
185+
NODE(OutlinedRelease)
184186
#undef CONTEXT_NODE
185187
#undef NODE

include/swift/SIL/PatternMatch.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,9 @@ UNARY_OP_MATCH_WITH_ARG_MATCHER(ObjCMetatypeToObjectInst)
345345
UNARY_OP_MATCH_WITH_ARG_MATCHER(ObjCExistentialMetatypeToObjectInst)
346346
UNARY_OP_MATCH_WITH_ARG_MATCHER(IsNonnullInst)
347347
UNARY_OP_MATCH_WITH_ARG_MATCHER(RetainValueInst)
348+
UNARY_OP_MATCH_WITH_ARG_MATCHER(RetainValueAddrInst)
348349
UNARY_OP_MATCH_WITH_ARG_MATCHER(ReleaseValueInst)
350+
UNARY_OP_MATCH_WITH_ARG_MATCHER(ReleaseValueAddrInst)
349351
UNARY_OP_MATCH_WITH_ARG_MATCHER(AutoreleaseValueInst)
350352
UNARY_OP_MATCH_WITH_ARG_MATCHER(UncheckedEnumDataInst)
351353
UNARY_OP_MATCH_WITH_ARG_MATCHER(InitEnumDataAddrInst)

include/swift/SIL/SILBuilder.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,13 +864,28 @@ class SILBuilder {
864864
operand, atomicity));
865865
}
866866

867+
RetainValueAddrInst *createRetainValueAddr(SILLocation Loc, SILValue operand,
868+
Atomicity atomicity) {
869+
assert(isParsing || F.hasUnqualifiedOwnership());
870+
return insert(new (F.getModule()) RetainValueAddrInst(
871+
getSILDebugLocation(Loc), operand, atomicity));
872+
}
873+
867874
ReleaseValueInst *createReleaseValue(SILLocation Loc, SILValue operand,
868875
Atomicity atomicity) {
869876
assert(isParsing || F.hasUnqualifiedOwnership());
870877
return insert(new (F.getModule()) ReleaseValueInst(getSILDebugLocation(Loc),
871878
operand, atomicity));
872879
}
873880

881+
ReleaseValueAddrInst *createReleaseValueAddr(SILLocation Loc,
882+
SILValue operand,
883+
Atomicity atomicity) {
884+
assert(isParsing || F.hasUnqualifiedOwnership());
885+
return insert(new (F.getModule()) ReleaseValueAddrInst(
886+
getSILDebugLocation(Loc), operand, atomicity));
887+
}
888+
874889
UnmanagedRetainValueInst *createUnmanagedRetainValue(SILLocation Loc,
875890
SILValue operand,
876891
Atomicity atomicity) {

include/swift/SIL/SILCloner.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,15 @@ void SILCloner<ImplClass>::visitRetainValueInst(RetainValueInst *Inst) {
12321232
Inst->getAtomicity()));
12331233
}
12341234

1235+
template <typename ImplClass>
1236+
void SILCloner<ImplClass>::visitRetainValueAddrInst(RetainValueAddrInst *Inst) {
1237+
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
1238+
doPostProcess(
1239+
Inst, getBuilder().createRetainValueAddr(getOpLocation(Inst->getLoc()),
1240+
getOpValue(Inst->getOperand()),
1241+
Inst->getAtomicity()));
1242+
}
1243+
12351244
template <typename ImplClass>
12361245
void SILCloner<ImplClass>::visitUnmanagedRetainValueInst(
12371246
UnmanagedRetainValueInst *Inst) {
@@ -1268,6 +1277,16 @@ void SILCloner<ImplClass>::visitReleaseValueInst(ReleaseValueInst *Inst) {
12681277
Inst->getAtomicity()));
12691278
}
12701279

1280+
template <typename ImplClass>
1281+
void SILCloner<ImplClass>::visitReleaseValueAddrInst(
1282+
ReleaseValueAddrInst *Inst) {
1283+
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
1284+
doPostProcess(
1285+
Inst, getBuilder().createReleaseValueAddr(getOpLocation(Inst->getLoc()),
1286+
getOpValue(Inst->getOperand()),
1287+
Inst->getAtomicity()));
1288+
}
1289+
12711290
template <typename ImplClass>
12721291
void SILCloner<ImplClass>::visitUnmanagedReleaseValueInst(
12731292
UnmanagedReleaseValueInst *Inst) {

include/swift/SIL/SILInstruction.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3667,6 +3667,19 @@ class RetainValueInst : public UnaryInstructionBase<ValueKind::RetainValueInst,
36673667
}
36683668
};
36693669

3670+
/// RetainValueAddrInst - Copies a loadable value by address.
3671+
class RetainValueAddrInst
3672+
: public UnaryInstructionBase<ValueKind::RetainValueAddrInst,
3673+
RefCountingInst, /*HasValue*/ false> {
3674+
friend SILBuilder;
3675+
3676+
RetainValueAddrInst(SILDebugLocation DebugLoc, SILValue operand,
3677+
Atomicity atomicity)
3678+
: UnaryInstructionBase(DebugLoc, operand) {
3679+
setAtomicity(atomicity);
3680+
}
3681+
};
3682+
36703683
/// ReleaseValueInst - Destroys a loadable value.
36713684
class ReleaseValueInst : public UnaryInstructionBase<ValueKind::ReleaseValueInst,
36723685
RefCountingInst,
@@ -3680,6 +3693,19 @@ class ReleaseValueInst : public UnaryInstructionBase<ValueKind::ReleaseValueInst
36803693
}
36813694
};
36823695

3696+
/// ReleaseValueInst - Destroys a loadable value by address.
3697+
class ReleaseValueAddrInst
3698+
: public UnaryInstructionBase<ValueKind::ReleaseValueAddrInst,
3699+
RefCountingInst, /*HasValue*/ false> {
3700+
friend SILBuilder;
3701+
3702+
ReleaseValueAddrInst(SILDebugLocation DebugLoc, SILValue operand,
3703+
Atomicity atomicity)
3704+
: UnaryInstructionBase(DebugLoc, operand) {
3705+
setAtomicity(atomicity);
3706+
}
3707+
};
3708+
36833709
/// Copies a loadable value in an unmanaged, unbalanced way. Only meant for use
36843710
/// in ownership qualified SIL. Please do not use this EVER unless you are
36853711
/// implementing a part of the stdlib called Unmanaged.

include/swift/SIL/SILNodes.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ ABSTRACT_VALUE(SILInstruction, ValueBase)
152152
INST(UnownedReleaseInst, RefCountingInst, unowned_release, MayHaveSideEffects,
153153
MayRelease)
154154
INST(RetainValueInst, RefCountingInst, retain_value, MayHaveSideEffects, DoesNotRelease)
155+
INST(RetainValueAddrInst, RefCountingInst, retain_value_addr, MayHaveSideEffects, DoesNotRelease)
155156
INST(ReleaseValueInst, RefCountingInst, release_value, MayHaveSideEffects, MayRelease)
157+
INST(ReleaseValueAddrInst, RefCountingInst, release_value_addr, MayHaveSideEffects, MayRelease)
156158
INST(SetDeallocatingInst, RefCountingInst, set_deallocating, MayHaveSideEffects,
157159
DoesNotRelease)
158160
INST(AutoreleaseValueInst, RefCountingInst, autorelease_value, MayHaveSideEffects,

include/swift/Serialization/ModuleFormat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const uint16_t VERSION_MAJOR = 0;
5454
/// in source control, you should also update the comment to briefly
5555
/// describe what change you made. The content of this comment isn't important;
5656
/// it just ensures a conflict if two people change the module format.
57-
const uint16_t VERSION_MINOR = 340; // Last change: Indirect_In_Constant
57+
const uint16_t VERSION_MINOR = 341; // Last change: retain/release addr
5858

5959
using DeclID = PointerEmbeddedInt<unsigned, 31>;
6060
using DeclIDField = BCFixed<31>;

lib/Demangling/Demangler.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,6 +1541,14 @@ NodePointer Demangler::demangleWitness() {
15411541
return createWithChild(Node::Kind::OutlinedConsume,
15421542
popNode(Node::Kind::Type));
15431543
}
1544+
case 'r': {
1545+
return createWithChild(Node::Kind::OutlinedRetain,
1546+
popNode(Node::Kind::Type));
1547+
}
1548+
case 's': {
1549+
return createWithChild(Node::Kind::OutlinedRelease,
1550+
popNode(Node::Kind::Type));
1551+
}
15441552
default:
15451553
return nullptr;
15461554
}

0 commit comments

Comments
 (0)