Skip to content

Commit 6a59808

Browse files
committed
Add [nonatomic] attribute to all SIL reference counting instructions.
1 parent 78b059c commit 6a59808

33 files changed

+392
-199
lines changed

include/swift/SIL/SILBuilder.h

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -658,26 +658,29 @@ class SILBuilder {
658658
targetType));
659659
}
660660

661-
RetainValueInst *createRetainValue(SILLocation Loc, SILValue operand) {
662-
return insert(new (F.getModule())
663-
RetainValueInst(getSILDebugLocation(Loc), operand));
661+
RetainValueInst *createRetainValue(SILLocation Loc, SILValue operand,
662+
bool NonAtomic) {
663+
return insert(new (F.getModule()) RetainValueInst(getSILDebugLocation(Loc),
664+
operand, NonAtomic));
664665
}
665666

666-
ReleaseValueInst *createReleaseValue(SILLocation Loc, SILValue operand) {
667-
return insert(new (F.getModule())
668-
ReleaseValueInst(getSILDebugLocation(Loc), operand));
667+
ReleaseValueInst *createReleaseValue(SILLocation Loc, SILValue operand,
668+
bool NonAtomic) {
669+
return insert(new (F.getModule()) ReleaseValueInst(getSILDebugLocation(Loc),
670+
operand, NonAtomic));
669671
}
670672

671-
AutoreleaseValueInst *createAutoreleaseValue(SILLocation Loc,
672-
SILValue operand) {
673+
AutoreleaseValueInst *
674+
createAutoreleaseValue(SILLocation Loc, SILValue operand, bool NonAtomic) {
673675
return insert(new (F.getModule()) AutoreleaseValueInst(
674-
getSILDebugLocation(Loc), operand));
676+
getSILDebugLocation(Loc), operand, NonAtomic));
675677
}
676678

677679
SetDeallocatingInst *createSetDeallocating(SILLocation Loc,
678-
SILValue operand) {
680+
SILValue operand,
681+
bool NonAtomic) {
679682
return insert(new (F.getModule()) SetDeallocatingInst(
680-
getSILDebugLocation(Loc), operand));
683+
getSILDebugLocation(Loc), operand, NonAtomic));
681684
}
682685

683686
StructInst *createStruct(SILLocation Loc, SILType Ty,
@@ -1018,35 +1021,42 @@ class SILBuilder {
10181021
return insert(new (F.getModule())
10191022
CopyBlockInst(getSILDebugLocation(Loc), Operand));
10201023
}
1021-
StrongRetainInst *createStrongRetain(SILLocation Loc, SILValue Operand) {
1022-
return insert(new (F.getModule())
1023-
StrongRetainInst(getSILDebugLocation(Loc), Operand));
1024+
StrongRetainInst *createStrongRetain(SILLocation Loc, SILValue Operand,
1025+
bool NonAtomic) {
1026+
return insert(new (F.getModule()) StrongRetainInst(getSILDebugLocation(Loc),
1027+
Operand, NonAtomic));
10241028
}
1025-
StrongReleaseInst *createStrongRelease(SILLocation Loc, SILValue Operand) {
1026-
return insert(new (F.getModule())
1027-
StrongReleaseInst(getSILDebugLocation(Loc), Operand));
1029+
StrongReleaseInst *createStrongRelease(SILLocation Loc, SILValue Operand,
1030+
bool NonAtomic) {
1031+
return insert(new (F.getModule()) StrongReleaseInst(
1032+
getSILDebugLocation(Loc), Operand, NonAtomic));
10281033
}
1029-
StrongPinInst *createStrongPin(SILLocation Loc, SILValue Operand) {
1030-
return insert(new (F.getModule())
1031-
StrongPinInst(getSILDebugLocation(Loc), Operand));
1034+
StrongPinInst *createStrongPin(SILLocation Loc, SILValue Operand,
1035+
bool NonAtomic) {
1036+
return insert(new (F.getModule()) StrongPinInst(getSILDebugLocation(Loc),
1037+
Operand, NonAtomic));
10321038
}
1033-
StrongUnpinInst *createStrongUnpin(SILLocation Loc, SILValue Operand) {
1034-
return insert(new (F.getModule())
1035-
StrongUnpinInst(getSILDebugLocation(Loc), Operand));
1039+
StrongUnpinInst *createStrongUnpin(SILLocation Loc, SILValue Operand,
1040+
bool NonAtomic) {
1041+
return insert(new (F.getModule()) StrongUnpinInst(getSILDebugLocation(Loc),
1042+
Operand, NonAtomic));
10361043
}
1037-
StrongRetainUnownedInst *createStrongRetainUnowned(SILLocation Loc,
1038-
SILValue Operand) {
1044+
StrongRetainUnownedInst *
1045+
createStrongRetainUnowned(SILLocation Loc, SILValue Operand, bool NonAtomic) {
10391046
return insert(new (F.getModule()) StrongRetainUnownedInst(
1040-
getSILDebugLocation(Loc), Operand));
1047+
getSILDebugLocation(Loc), Operand, NonAtomic));
10411048
}
1042-
UnownedRetainInst *createUnownedRetain(SILLocation Loc, SILValue Operand) {
1043-
return insert(new (F.getModule())
1044-
UnownedRetainInst(getSILDebugLocation(Loc), Operand));
1049+
UnownedRetainInst *createUnownedRetain(SILLocation Loc, SILValue Operand,
1050+
bool NonAtomic) {
1051+
return insert(new (F.getModule()) UnownedRetainInst(
1052+
getSILDebugLocation(Loc), Operand, NonAtomic));
10451053
}
1046-
UnownedReleaseInst *createUnownedRelease(SILLocation Loc, SILValue Operand) {
1047-
return insert(new (F.getModule())
1048-
UnownedReleaseInst(getSILDebugLocation(Loc), Operand));
1054+
UnownedReleaseInst *createUnownedRelease(SILLocation Loc, SILValue Operand,
1055+
bool NonAtomic) {
1056+
return insert(new (F.getModule()) UnownedReleaseInst(
1057+
getSILDebugLocation(Loc), Operand, NonAtomic));
10491058
}
1059+
10501060
FixLifetimeInst *createFixLifetime(SILLocation Loc, SILValue Operand) {
10511061
return insert(new (F.getModule())
10521062
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->isNonAtomic()));
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->isNonAtomic()));
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->isNonAtomic()));
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->isNonAtomic()));
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->isNonAtomic()));
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->isNonAtomic()));
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->isNonAtomic()));
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->isNonAtomic()));
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->isNonAtomic()));
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->isNonAtomic()));
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->isNonAtomic()));
15011512
}
15021513
template<typename ImplClass>
15031514
void SILCloner<ImplClass>::visitIsUniqueInst(IsUniqueInst *Inst) {

include/swift/SIL/SILInstruction.h

Lines changed: 56 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2285,15 +2285,24 @@ class StructInst : public SILInstruction {
22852285
/// RefCountingInst - An abstract class of instructions which
22862286
/// manipulate the reference count of their object operand.
22872287
class RefCountingInst : public SILInstruction {
2288+
protected:
2289+
bool NonAtomic;
22882290
protected:
22892291
RefCountingInst(ValueKind Kind, SILDebugLocation DebugLoc)
22902292
: SILInstruction(Kind, DebugLoc) {}
22912293

2294+
RefCountingInst(ValueKind Kind, SILDebugLocation DebugLoc, SILType Type)
2295+
: SILInstruction(Kind, DebugLoc, Type) {}
2296+
22922297
public:
22932298
static bool classof(const ValueBase *V) {
22942299
return V->getKind() >= ValueKind::First_RefCountingInst &&
22952300
V->getKind() <= ValueKind::Last_RefCountingInst;
22962301
}
2302+
2303+
void setNonAtomic(bool flag) { NonAtomic = flag; }
2304+
bool isNonAtomic() const { return NonAtomic; }
2305+
bool isAtomic() const { return !NonAtomic; }
22972306
};
22982307

22992308
/// RetainValueInst - Copies a loadable value.
@@ -2302,8 +2311,10 @@ class RetainValueInst : public UnaryInstructionBase<ValueKind::RetainValueInst,
23022311
/*HasValue*/ false> {
23032312
friend class SILBuilder;
23042313

2305-
RetainValueInst(SILDebugLocation DebugLoc, SILValue operand)
2306-
: UnaryInstructionBase(DebugLoc, operand) {}
2314+
RetainValueInst(SILDebugLocation DebugLoc, SILValue operand, bool NonAtomic)
2315+
: UnaryInstructionBase(DebugLoc, operand) {
2316+
setNonAtomic(NonAtomic);
2317+
}
23072318
};
23082319

23092320
/// ReleaseValueInst - Destroys a loadable value.
@@ -2312,8 +2323,10 @@ class ReleaseValueInst : public UnaryInstructionBase<ValueKind::ReleaseValueInst
23122323
/*HasValue*/ false> {
23132324
friend class SILBuilder;
23142325

2315-
ReleaseValueInst(SILDebugLocation DebugLoc, SILValue operand)
2316-
: UnaryInstructionBase(DebugLoc, operand) {}
2326+
ReleaseValueInst(SILDebugLocation DebugLoc, SILValue operand, bool NonAtomic)
2327+
: UnaryInstructionBase(DebugLoc, operand) {
2328+
setNonAtomic(NonAtomic);
2329+
}
23172330
};
23182331

23192332
/// Transfers ownership of a loadable value to the current autorelease pool.
@@ -2323,8 +2336,11 @@ class AutoreleaseValueInst
23232336
/*HasValue*/ false> {
23242337
friend class SILBuilder;
23252338

2326-
AutoreleaseValueInst(SILDebugLocation DebugLoc, SILValue operand)
2327-
: UnaryInstructionBase(DebugLoc, operand) {}
2339+
AutoreleaseValueInst(SILDebugLocation DebugLoc, SILValue operand,
2340+
bool NonAtomic)
2341+
: UnaryInstructionBase(DebugLoc, operand) {
2342+
setNonAtomic(NonAtomic);
2343+
}
23282344
};
23292345

23302346
/// SetDeallocatingInst - Sets the operand in deallocating state.
@@ -2337,8 +2353,11 @@ class SetDeallocatingInst
23372353
/*HasValue*/ false> {
23382354
friend class SILBuilder;
23392355

2340-
SetDeallocatingInst(SILDebugLocation DebugLoc, SILValue operand)
2341-
: UnaryInstructionBase(DebugLoc, operand) {}
2356+
SetDeallocatingInst(SILDebugLocation DebugLoc, SILValue operand,
2357+
bool NonAtomic)
2358+
: UnaryInstructionBase(DebugLoc, operand) {
2359+
setNonAtomic(NonAtomic);
2360+
}
23422361
};
23432362

23442363
/// StrongPinInst - Ensure that the operand is retained and pinned, if
@@ -2349,24 +2368,26 @@ class SetDeallocatingInst
23492368
/// unpin may be conservatively assumed to have arbitrary
23502369
/// side-effects.)
23512370
class StrongPinInst
2352-
: public UnaryInstructionBase<ValueKind::StrongPinInst, SILInstruction,
2371+
: public UnaryInstructionBase<ValueKind::StrongPinInst, RefCountingInst,
23532372
/*HasResult*/ true>
23542373
{
23552374
friend class SILBuilder;
23562375

2357-
StrongPinInst(SILDebugLocation DebugLoc, SILValue operand);
2376+
StrongPinInst(SILDebugLocation DebugLoc, SILValue operand, bool NonAtomic);
23582377
};
23592378

23602379
/// StrongUnpinInst - Given that the operand is the result of a
23612380
/// strong_pin instruction, unpin it.
23622381
class StrongUnpinInst
2363-
: public UnaryInstructionBase<ValueKind::StrongUnpinInst, SILInstruction,
2382+
: public UnaryInstructionBase<ValueKind::StrongUnpinInst, RefCountingInst,
23642383
/*HasResult*/ false>
23652384
{
23662385
friend class SILBuilder;
23672386

2368-
StrongUnpinInst(SILDebugLocation DebugLoc, SILValue operand)
2369-
: UnaryInstructionBase(DebugLoc, operand) {}
2387+
StrongUnpinInst(SILDebugLocation DebugLoc, SILValue operand, bool NonAtomic)
2388+
: UnaryInstructionBase(DebugLoc, operand) {
2389+
setNonAtomic(NonAtomic);
2390+
}
23702391
};
23712392

23722393
/// TupleInst - Represents a constructed loadable tuple.
@@ -3330,8 +3351,10 @@ class StrongRetainInst
33303351
{
33313352
friend class SILBuilder;
33323353

3333-
StrongRetainInst(SILDebugLocation DebugLoc, SILValue Operand)
3334-
: UnaryInstructionBase(DebugLoc, Operand) {}
3354+
StrongRetainInst(SILDebugLocation DebugLoc, SILValue Operand, bool NonAtomic)
3355+
: UnaryInstructionBase(DebugLoc, Operand) {
3356+
setNonAtomic(NonAtomic);
3357+
}
33353358
};
33363359

33373360
/// StrongReleaseInst - Decrease the strong reference count of an object.
@@ -3345,8 +3368,10 @@ class StrongReleaseInst
33453368
{
33463369
friend class SILBuilder;
33473370

3348-
StrongReleaseInst(SILDebugLocation DebugLoc, SILValue Operand)
3349-
: UnaryInstructionBase(DebugLoc, Operand) {}
3371+
StrongReleaseInst(SILDebugLocation DebugLoc, SILValue Operand, bool NonAtomic)
3372+
: UnaryInstructionBase(DebugLoc, Operand) {
3373+
setNonAtomic(NonAtomic);
3374+
}
33503375
};
33513376

33523377
/// StrongRetainUnownedInst - Increase the strong reference count of an object
@@ -3359,8 +3384,11 @@ class StrongRetainUnownedInst :
33593384
{
33603385
friend class SILBuilder;
33613386

3362-
StrongRetainUnownedInst(SILDebugLocation DebugLoc, SILValue operand)
3363-
: UnaryInstructionBase(DebugLoc, operand) {}
3387+
StrongRetainUnownedInst(SILDebugLocation DebugLoc, SILValue operand,
3388+
bool NonAtomic)
3389+
: UnaryInstructionBase(DebugLoc, operand) {
3390+
setNonAtomic(NonAtomic);
3391+
}
33643392
};
33653393

33663394
/// UnownedRetainInst - Increase the unowned reference count of an object.
@@ -3370,8 +3398,10 @@ class UnownedRetainInst :
33703398
{
33713399
friend class SILBuilder;
33723400

3373-
UnownedRetainInst(SILDebugLocation DebugLoc, SILValue Operand)
3374-
: UnaryInstructionBase(DebugLoc, Operand) {}
3401+
UnownedRetainInst(SILDebugLocation DebugLoc, SILValue Operand, bool NonAtomic)
3402+
: UnaryInstructionBase(DebugLoc, Operand) {
3403+
setNonAtomic(NonAtomic);
3404+
}
33753405
};
33763406

33773407
/// UnownedReleaseInst - Decrease the unowned reference count of an object.
@@ -3381,8 +3411,11 @@ class UnownedReleaseInst :
33813411
{
33823412
friend class SILBuilder;
33833413

3384-
UnownedReleaseInst(SILDebugLocation DebugLoc, SILValue Operand)
3385-
: UnaryInstructionBase(DebugLoc, Operand) {}
3414+
UnownedReleaseInst(SILDebugLocation DebugLoc, SILValue Operand,
3415+
bool NonAtomic)
3416+
: UnaryInstructionBase(DebugLoc, Operand) {
3417+
setNonAtomic(NonAtomic);
3418+
}
33863419
};
33873420

33883421
/// FixLifetimeInst - An artificial use of a value for the purposes of ARC or

0 commit comments

Comments
 (0)