Skip to content

Commit baf8e7d

Browse files
committed
Merge pull request #2067 from swiftix/SR-249
Add [nonatomic] attribute to all SIL reference counting instructions. Support this attribute at SIL level, IRGen and LLVM-based ARC passes.
2 parents 7097fac + d8e28bb commit baf8e7d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1118
-478
lines changed

include/swift/SIL/SILBuilder.h

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
namespace swift {
2323

24+
using Atomicity = RefCountingInst::Atomicity;
25+
2426
class SILDebugScope;
2527

2628
class SILBuilder {
@@ -658,26 +660,30 @@ class SILBuilder {
658660
targetType));
659661
}
660662

661-
RetainValueInst *createRetainValue(SILLocation Loc, SILValue operand) {
662-
return insert(new (F.getModule())
663-
RetainValueInst(getSILDebugLocation(Loc), operand));
663+
RetainValueInst *createRetainValue(SILLocation Loc, SILValue operand,
664+
Atomicity atomicity) {
665+
return insert(new (F.getModule()) RetainValueInst(getSILDebugLocation(Loc),
666+
operand, atomicity));
664667
}
665668

666-
ReleaseValueInst *createReleaseValue(SILLocation Loc, SILValue operand) {
667-
return insert(new (F.getModule())
668-
ReleaseValueInst(getSILDebugLocation(Loc), operand));
669+
ReleaseValueInst *createReleaseValue(SILLocation Loc, SILValue operand,
670+
Atomicity atomicity) {
671+
return insert(new (F.getModule()) ReleaseValueInst(getSILDebugLocation(Loc),
672+
operand, atomicity));
669673
}
670674

671675
AutoreleaseValueInst *createAutoreleaseValue(SILLocation Loc,
672-
SILValue operand) {
676+
SILValue operand,
677+
Atomicity atomicity) {
673678
return insert(new (F.getModule()) AutoreleaseValueInst(
674-
getSILDebugLocation(Loc), operand));
679+
getSILDebugLocation(Loc), operand, atomicity));
675680
}
676681

677682
SetDeallocatingInst *createSetDeallocating(SILLocation Loc,
678-
SILValue operand) {
683+
SILValue operand,
684+
Atomicity atomicity) {
679685
return insert(new (F.getModule()) SetDeallocatingInst(
680-
getSILDebugLocation(Loc), operand));
686+
getSILDebugLocation(Loc), operand, atomicity));
681687
}
682688

683689
StructInst *createStruct(SILLocation Loc, SILType Ty,
@@ -1018,35 +1024,43 @@ class SILBuilder {
10181024
return insert(new (F.getModule())
10191025
CopyBlockInst(getSILDebugLocation(Loc), Operand));
10201026
}
1021-
StrongRetainInst *createStrongRetain(SILLocation Loc, SILValue Operand) {
1022-
return insert(new (F.getModule())
1023-
StrongRetainInst(getSILDebugLocation(Loc), Operand));
1027+
StrongRetainInst *createStrongRetain(SILLocation Loc, SILValue Operand,
1028+
Atomicity atomicity) {
1029+
return insert(new (F.getModule()) StrongRetainInst(getSILDebugLocation(Loc),
1030+
Operand, atomicity));
10241031
}
1025-
StrongReleaseInst *createStrongRelease(SILLocation Loc, SILValue Operand) {
1026-
return insert(new (F.getModule())
1027-
StrongReleaseInst(getSILDebugLocation(Loc), Operand));
1032+
StrongReleaseInst *createStrongRelease(SILLocation Loc, SILValue Operand,
1033+
Atomicity atomicity) {
1034+
return insert(new (F.getModule()) StrongReleaseInst(
1035+
getSILDebugLocation(Loc), Operand, atomicity));
10281036
}
1029-
StrongPinInst *createStrongPin(SILLocation Loc, SILValue Operand) {
1030-
return insert(new (F.getModule())
1031-
StrongPinInst(getSILDebugLocation(Loc), Operand));
1037+
StrongPinInst *createStrongPin(SILLocation Loc, SILValue Operand,
1038+
Atomicity atomicity) {
1039+
return insert(new (F.getModule()) StrongPinInst(getSILDebugLocation(Loc),
1040+
Operand, atomicity));
10321041
}
1033-
StrongUnpinInst *createStrongUnpin(SILLocation Loc, SILValue Operand) {
1034-
return insert(new (F.getModule())
1035-
StrongUnpinInst(getSILDebugLocation(Loc), Operand));
1042+
StrongUnpinInst *createStrongUnpin(SILLocation Loc, SILValue Operand,
1043+
Atomicity atomicity) {
1044+
return insert(new (F.getModule()) StrongUnpinInst(getSILDebugLocation(Loc),
1045+
Operand, atomicity));
10361046
}
10371047
StrongRetainUnownedInst *createStrongRetainUnowned(SILLocation Loc,
1038-
SILValue Operand) {
1048+
SILValue Operand,
1049+
Atomicity atomicity) {
10391050
return insert(new (F.getModule()) StrongRetainUnownedInst(
1040-
getSILDebugLocation(Loc), Operand));
1051+
getSILDebugLocation(Loc), Operand, atomicity));
10411052
}
1042-
UnownedRetainInst *createUnownedRetain(SILLocation Loc, SILValue Operand) {
1043-
return insert(new (F.getModule())
1044-
UnownedRetainInst(getSILDebugLocation(Loc), Operand));
1053+
UnownedRetainInst *createUnownedRetain(SILLocation Loc, SILValue Operand,
1054+
Atomicity atomicity) {
1055+
return insert(new (F.getModule()) UnownedRetainInst(
1056+
getSILDebugLocation(Loc), Operand, atomicity));
10451057
}
1046-
UnownedReleaseInst *createUnownedRelease(SILLocation Loc, SILValue Operand) {
1047-
return insert(new (F.getModule())
1048-
UnownedReleaseInst(getSILDebugLocation(Loc), Operand));
1058+
UnownedReleaseInst *createUnownedRelease(SILLocation Loc, SILValue Operand,
1059+
Atomicity atomicity) {
1060+
return insert(new (F.getModule()) UnownedReleaseInst(
1061+
getSILDebugLocation(Loc), Operand, atomicity));
10491062
}
1063+
10501064
FixLifetimeInst *createFixLifetime(SILLocation Loc, SILValue Operand) {
10511065
return insert(new (F.getModule())
10521066
FixLifetimeInst(getSILDebugLocation(Loc), Operand));

include/swift/SIL/SILCloner.h

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,8 @@ SILCloner<ImplClass>::visitRetainValueInst(RetainValueInst *Inst) {
10291029
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
10301030
doPostProcess(Inst,
10311031
getBuilder().createRetainValue(getOpLocation(Inst->getLoc()),
1032-
getOpValue(Inst->getOperand())));
1032+
getOpValue(Inst->getOperand()),
1033+
Inst->getAtomicity()));
10331034
}
10341035

10351036
template<typename ImplClass>
@@ -1038,7 +1039,8 @@ SILCloner<ImplClass>::visitReleaseValueInst(ReleaseValueInst *Inst) {
10381039
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
10391040
doPostProcess(Inst,
10401041
getBuilder().createReleaseValue(getOpLocation(Inst->getLoc()),
1041-
getOpValue(Inst->getOperand())));
1042+
getOpValue(Inst->getOperand()),
1043+
Inst->getAtomicity()));
10421044
}
10431045

10441046
template<typename ImplClass>
@@ -1047,7 +1049,8 @@ SILCloner<ImplClass>::visitAutoreleaseValueInst(AutoreleaseValueInst *Inst) {
10471049
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
10481050
doPostProcess(Inst,
10491051
getBuilder().createAutoreleaseValue(getOpLocation(Inst->getLoc()),
1050-
getOpValue(Inst->getOperand())));
1052+
getOpValue(Inst->getOperand()),
1053+
Inst->getAtomicity()));
10511054
}
10521055

10531056
template<typename ImplClass>
@@ -1056,7 +1059,8 @@ SILCloner<ImplClass>::visitSetDeallocatingInst(SetDeallocatingInst *Inst) {
10561059
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
10571060
doPostProcess(Inst,
10581061
getBuilder().createSetDeallocating(getOpLocation(Inst->getLoc()),
1059-
getOpValue(Inst->getOperand())));
1062+
getOpValue(Inst->getOperand()),
1063+
Inst->getAtomicity()));
10601064
}
10611065

10621066
template<typename ImplClass>
@@ -1423,7 +1427,8 @@ SILCloner<ImplClass>::visitStrongRetainInst(StrongRetainInst *Inst) {
14231427
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
14241428
doPostProcess(Inst,
14251429
getBuilder().createStrongRetain(getOpLocation(Inst->getLoc()),
1426-
getOpValue(Inst->getOperand())));
1430+
getOpValue(Inst->getOperand()),
1431+
Inst->getAtomicity()));
14271432
}
14281433

14291434
template<typename ImplClass>
@@ -1451,7 +1456,8 @@ SILCloner<ImplClass>::visitStrongPinInst(StrongPinInst *Inst) {
14511456
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
14521457
doPostProcess(Inst,
14531458
getBuilder().createStrongPin(getOpLocation(Inst->getLoc()),
1454-
getOpValue(Inst->getOperand())));
1459+
getOpValue(Inst->getOperand()),
1460+
Inst->getAtomicity()));
14551461
}
14561462

14571463
template<typename ImplClass>
@@ -1460,7 +1466,8 @@ SILCloner<ImplClass>::visitStrongUnpinInst(StrongUnpinInst *Inst) {
14601466
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
14611467
doPostProcess(Inst,
14621468
getBuilder().createStrongUnpin(getOpLocation(Inst->getLoc()),
1463-
getOpValue(Inst->getOperand())));
1469+
getOpValue(Inst->getOperand()),
1470+
Inst->getAtomicity()));
14641471
}
14651472

14661473
template<typename ImplClass>
@@ -1469,7 +1476,8 @@ SILCloner<ImplClass>::visitStrongReleaseInst(StrongReleaseInst *Inst) {
14691476
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
14701477
doPostProcess(Inst,
14711478
getBuilder().createStrongRelease(getOpLocation(Inst->getLoc()),
1472-
getOpValue(Inst->getOperand())));
1479+
getOpValue(Inst->getOperand()),
1480+
Inst->getAtomicity()));
14731481
}
14741482

14751483
template<typename ImplClass>
@@ -1479,7 +1487,8 @@ visitStrongRetainUnownedInst(StrongRetainUnownedInst *Inst) {
14791487
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
14801488
doPostProcess(Inst,
14811489
getBuilder().createStrongRetainUnowned(getOpLocation(Inst->getLoc()),
1482-
getOpValue(Inst->getOperand())));
1490+
getOpValue(Inst->getOperand()),
1491+
Inst->getAtomicity()));
14831492
}
14841493

14851494
template<typename ImplClass>
@@ -1488,7 +1497,8 @@ SILCloner<ImplClass>::visitUnownedRetainInst(UnownedRetainInst *Inst) {
14881497
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
14891498
doPostProcess(Inst,
14901499
getBuilder().createUnownedRetain(getOpLocation(Inst->getLoc()),
1491-
getOpValue(Inst->getOperand())));
1500+
getOpValue(Inst->getOperand()),
1501+
Inst->getAtomicity()));
14921502
}
14931503

14941504
template<typename ImplClass>
@@ -1497,7 +1507,8 @@ SILCloner<ImplClass>::visitUnownedReleaseInst(UnownedReleaseInst *Inst) {
14971507
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
14981508
doPostProcess(Inst,
14991509
getBuilder().createUnownedRelease(getOpLocation(Inst->getLoc()),
1500-
getOpValue(Inst->getOperand())));
1510+
getOpValue(Inst->getOperand()),
1511+
Inst->getAtomicity()));
15011512
}
15021513
template<typename ImplClass>
15031514
void SILCloner<ImplClass>::visitIsUniqueInst(IsUniqueInst *Inst) {

0 commit comments

Comments
 (0)