Skip to content

Commit 5fddd4a

Browse files
committed
Remove the autorelease_return and strong_retain_autoreleased instructions.
There's a buggy SIL verifier check that was previously tautological, and it turns out that it's violated, apparently harmlessly. Since it was already doing nothing, I've commented it out temporarily while I figure out the right way to fix SILGen to get the invariant right.
1 parent 5f2f090 commit 5fddd4a

27 files changed

+33
-232
lines changed

docs/ARCOptimization.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ Reference Counting Instructions
1515
===============================
1616

1717
- strong_retain
18-
- strong_retain_autoreleased
1918
- strong_release
2019
- strong_retain_unowned
2120
- unowned_retain

docs/SIL.rst

Lines changed: 13 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -511,9 +511,19 @@ throughout the execution of the call. This means that any
511511
argument can be eliminated.
512512

513513
An autoreleased direct result must have a type with a retainable
514-
pointer representation. It may have been autoreleased, and the caller
515-
should take action to reclaim that autorelease with
516-
``strong_retain_autoreleased``.
514+
pointer representation. Autoreleased results are nominally transferred
515+
at +0, but the runtime takes steps to ensure that a +1 can be safely
516+
transferred, and those steps require precise code-layout control.
517+
Accordingly, the SIL pattern for an autoreleased convention looks exactly
518+
like the SIL pattern for an owned convention, and the extra runtime
519+
instrumentation is inserted on both sides when the SIL is lowered into
520+
LLVM IR. An autoreleased ``apply`` of a function that is defined with
521+
an autoreleased result has the effect of a +1 transfer of the result.
522+
An autoreleased ``apply`` of a function that is not defined with
523+
an autoreleased result has the effect of performing a strong retain in
524+
the caller. A non-autoreleased ``apply`` of a function that is defined
525+
with an autoreleased result has the effect of performing an
526+
autorelease in the callee.
517527

518528
- The @noescape declaration attribute on Swift parameters (which is valid only
519529
on parameters of function type, and is implied by the @autoclosure attribute)
@@ -2184,23 +2194,6 @@ strong_retain
21842194

21852195
Increases the strong retain count of the heap object referenced by ``%0``.
21862196

2187-
strong_retain_autoreleased
2188-
``````````````````````````
2189-
::
2190-
2191-
sil-instruction ::= 'strong_retain_autoreleased' sil-operand
2192-
2193-
strong_retain_autoreleased %0 : $T
2194-
// $T must have a retainable pointer representation
2195-
2196-
Retains the heap object referenced by ``%0`` using the Objective-C ARC
2197-
"autoreleased return value" optimization. The operand must be the result of an
2198-
``apply`` instruction with an Objective-C method callee, and the
2199-
``strong_retain_autoreleased`` instruction must be first use of the value after
2200-
the defining ``apply`` instruction.
2201-
2202-
TODO: Specify all the other strong_retain_autoreleased constraints here.
2203-
22042197
strong_release
22052198
``````````````
22062199
::
@@ -3952,23 +3945,6 @@ will be the operand of this ``return`` instruction.
39523945

39533946
A function must not contain more than one ``return`` instruction.
39543947

3955-
autorelease_return
3956-
``````````````````
3957-
::
3958-
3959-
sil-terminator ::= 'autorelease_return' sil-operand
3960-
3961-
autorelease_return %0 : $T
3962-
// $T must be the return type of the current function, which must be of
3963-
// class type
3964-
3965-
Exits the current function and returns control to the calling function. The
3966-
result of the ``apply`` instruction that invoked the current function will be
3967-
the operand of this ``return`` instruction. The return value is autoreleased
3968-
into the active Objective-C autorelease pool using the "autoreleased return
3969-
value" optimization. The current function must use the ``@cc(objc_method)``
3970-
calling convention.
3971-
39723948
throw
39733949
`````
39743950
::

include/swift/SIL/PatternMatch.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,6 @@ UNARY_OP_MATCH_WITH_ARG_MATCHER(DeinitExistentialAddrInst)
370370
UNARY_OP_MATCH_WITH_ARG_MATCHER(ProjectBlockStorageInst)
371371
UNARY_OP_MATCH_WITH_ARG_MATCHER(StrongRetainInst)
372372
UNARY_OP_MATCH_WITH_ARG_MATCHER(StrongReleaseInst)
373-
UNARY_OP_MATCH_WITH_ARG_MATCHER(StrongRetainAutoreleasedInst)
374373
UNARY_OP_MATCH_WITH_ARG_MATCHER(StrongRetainUnownedInst)
375374
UNARY_OP_MATCH_WITH_ARG_MATCHER(UnownedRetainInst)
376375
UNARY_OP_MATCH_WITH_ARG_MATCHER(UnownedReleaseInst)
@@ -383,7 +382,6 @@ UNARY_OP_MATCH_WITH_ARG_MATCHER(DeallocBoxInst)
383382
UNARY_OP_MATCH_WITH_ARG_MATCHER(DestroyAddrInst)
384383
UNARY_OP_MATCH_WITH_ARG_MATCHER(CondFailInst)
385384
UNARY_OP_MATCH_WITH_ARG_MATCHER(ReturnInst)
386-
UNARY_OP_MATCH_WITH_ARG_MATCHER(AutoreleaseReturnInst)
387385
#undef UNARY_OP_MATCH_WITH_ARG_MATCHER
388386

389387
//===----------------------------------------------------------------------===//

include/swift/SIL/SILBuilder.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,11 +1010,6 @@ class SILBuilder {
10101010
return insert(new (F.getModule())
10111011
StrongReleaseInst(createSILDebugLocation(Loc), Operand));
10121012
}
1013-
StrongRetainAutoreleasedInst *
1014-
createStrongRetainAutoreleased(SILLocation Loc, SILValue Operand) {
1015-
return insert(new (F.getModule()) StrongRetainAutoreleasedInst(
1016-
createSILDebugLocation(Loc), Operand));
1017-
}
10181013
StrongPinInst *createStrongPin(SILLocation Loc, SILValue Operand) {
10191014
return insert(new (F.getModule())
10201015
StrongPinInst(createSILDebugLocation(Loc), Operand));
@@ -1184,12 +1179,6 @@ class SILBuilder {
11841179
createSILDebugLocation(Loc), ReturnValue));
11851180
}
11861181

1187-
AutoreleaseReturnInst *createAutoreleaseReturn(SILLocation Loc,
1188-
SILValue ReturnValue) {
1189-
return insertTerminator(new (F.getModule()) AutoreleaseReturnInst(
1190-
createSILDebugLocation(Loc), ReturnValue));
1191-
}
1192-
11931182
ThrowInst *createThrow(SILLocation Loc, SILValue errorValue) {
11941183
return insertTerminator(
11951184
new (F.getModule()) ThrowInst(createSILDebugLocation(Loc), errorValue));

include/swift/SIL/SILCloner.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,17 +1432,6 @@ SILCloner<ImplClass>::visitStrongRetainInst(StrongRetainInst *Inst) {
14321432
getOpValue(Inst->getOperand())));
14331433
}
14341434

1435-
template<typename ImplClass>
1436-
void
1437-
SILCloner<ImplClass>::
1438-
visitStrongRetainAutoreleasedInst(StrongRetainAutoreleasedInst *Inst) {
1439-
SILValue OpValue = getOpValue(Inst->getOperand());
1440-
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
1441-
doPostProcess(Inst,
1442-
getBuilder().createStrongRetainAutoreleased(getOpLocation(Inst->getLoc()),
1443-
OpValue));
1444-
}
1445-
14461435
template<typename ImplClass>
14471436
void
14481437
SILCloner<ImplClass>::visitFixLifetimeInst(FixLifetimeInst *Inst) {
@@ -1667,15 +1656,6 @@ SILCloner<ImplClass>::visitReturnInst(ReturnInst *Inst) {
16671656
getOpValue(Inst->getOperand())));
16681657
}
16691658

1670-
template<typename ImplClass>
1671-
void
1672-
SILCloner<ImplClass>::visitAutoreleaseReturnInst(AutoreleaseReturnInst *Inst) {
1673-
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
1674-
doPostProcess(Inst,
1675-
getBuilder().createAutoreleaseReturn(getOpLocation(Inst->getLoc()),
1676-
getOpValue(Inst->getOperand())));
1677-
}
1678-
16791659
template<typename ImplClass>
16801660
void
16811661
SILCloner<ImplClass>::visitThrowInst(ThrowInst *Inst) {

include/swift/SIL/SILFunction.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,6 @@ class SILFunction
517517
return std::find_if(begin(), end(),
518518
[](const SILBasicBlock &BB) -> bool {
519519
const TermInst *TI = BB.getTerminator();
520-
// TODO: We autorelease_return should also be handled here.
521520
return isa<ReturnInst>(TI);
522521
});
523522
}

include/swift/SIL/SILInstruction.h

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3185,18 +3185,6 @@ class StrongRetainInst
31853185
: UnaryInstructionBase(DebugLoc, Operand) {}
31863186
};
31873187

3188-
/// StrongRetainAutoreleasedInst - Take ownership of the autoreleased return
3189-
/// value of an ObjC method.
3190-
class StrongRetainAutoreleasedInst
3191-
: public UnaryInstructionBase<ValueKind::StrongRetainAutoreleasedInst,
3192-
RefCountingInst, /*HAS_RESULT*/ false>
3193-
{
3194-
friend class SILBuilder;
3195-
3196-
StrongRetainAutoreleasedInst(SILDebugLocation *DebugLoc, SILValue Operand)
3197-
: UnaryInstructionBase(DebugLoc, Operand) {}
3198-
};
3199-
32003188
/// StrongReleaseInst - Decrease the strong reference count of an object.
32013189
///
32023190
/// An object can be destroyed when its strong reference count is
@@ -3665,31 +3653,6 @@ class ReturnInst
36653653
}
36663654
};
36673655

3668-
/// AutoreleaseReturnInst - Transfer ownership of a value to an ObjC
3669-
/// autorelease pool, and then return the value.
3670-
class AutoreleaseReturnInst
3671-
: public UnaryInstructionBase<ValueKind::AutoreleaseReturnInst, TermInst,
3672-
/*HAS_RESULT*/ false>
3673-
{
3674-
friend class SILBuilder;
3675-
3676-
/// Constructs an AutoreleaseReturnInst representing an autorelease-return
3677-
/// sequence.
3678-
///
3679-
/// \param DebugLoc The backing AST location.
3680-
///
3681-
/// \param ReturnValue The value to be returned.
3682-
///
3683-
AutoreleaseReturnInst(SILDebugLocation *DebugLoc, SILValue ReturnValue)
3684-
: UnaryInstructionBase(DebugLoc, ReturnValue) {}
3685-
3686-
public:
3687-
SuccessorListTy getSuccessors() {
3688-
// No Successors.
3689-
return SuccessorListTy();
3690-
}
3691-
};
3692-
36933656
/// ThrowInst - Throw a typed error (which, in our system, is
36943657
/// essentially just a funny kind of return).
36953658
class ThrowInst

include/swift/SIL/SILLocation.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ class RegularLocation : public SILLocation {
399399

400400
/// Used to represent a return instruction in user code.
401401
///
402-
/// Allowed on an BranchInst, ReturnInst, AutoreleaseReturnInst.
402+
/// Allowed on an BranchInst, ReturnInst.
403403
class ReturnLocation : public SILLocation {
404404
public:
405405
ReturnLocation(ReturnStmt *RS) : SILLocation(RS, ReturnKind) {}
@@ -423,7 +423,7 @@ class ReturnLocation : public SILLocation {
423423
/// Used on the instruction that was generated to represent an implicit
424424
/// return from a function.
425425
///
426-
/// Allowed on an BranchInst, ReturnInst, AutoreleaseReturnInst.
426+
/// Allowed on an BranchInst, ReturnInst.
427427
class ImplicitReturnLocation : public SILLocation {
428428
public:
429429

@@ -467,7 +467,7 @@ class ImplicitReturnLocation : public SILLocation {
467467
///
468468
/// This location wraps the call site ASTNode.
469469
///
470-
/// Allowed on any instruction except for ReturnInst, AutoreleaseReturnInst.
470+
/// Allowed on any instruction except for ReturnInst.
471471
class InlinedLocation : public SILLocation {
472472
public:
473473
InlinedLocation(Expr *CallSite) : SILLocation(CallSite, InlinedKind) {}
@@ -514,7 +514,7 @@ class InlinedLocation : public SILLocation {
514514
///
515515
/// This location wraps the call site ASTNode.
516516
///
517-
/// Allowed on any instruction except for ReturnInst, AutoreleaseReturnInst.
517+
/// Allowed on any instruction except for ReturnInst.
518518
class MandatoryInlinedLocation : public SILLocation {
519519
public:
520520
MandatoryInlinedLocation(Expr *CallSite) :
@@ -572,7 +572,7 @@ class MandatoryInlinedLocation : public SILLocation {
572572
/// scope's end location points to the SourceLoc that shows when the operation
573573
/// is performed at runtime.
574574
///
575-
/// Allowed on any instruction except for ReturnInst, AutoreleaseReturnInst.
575+
/// Allowed on any instruction except for ReturnInst.
576576
/// Locations of an inlined destructor should also be represented by this.
577577
class CleanupLocation : public SILLocation {
578578
public:

include/swift/SIL/SILNodes.def

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@ ABSTRACT_VALUE(SILInstruction, ValueBase)
113113
// Reference Counting
114114
ABSTRACT_VALUE(RefCountingInst, SILInstruction)
115115
INST(StrongRetainInst, RefCountingInst, MayHaveSideEffects, DoesNotRelease)
116-
INST(StrongRetainAutoreleasedInst, RefCountingInst, MayHaveSideEffects,
117-
DoesNotRelease)
118116
INST(StrongReleaseInst, RefCountingInst, MayHaveSideEffects, MayRelease)
119117
INST(StrongRetainUnownedInst, RefCountingInst, MayHaveSideEffects,
120118
DoesNotRelease)
@@ -245,7 +243,6 @@ ABSTRACT_VALUE(SILInstruction, ValueBase)
245243
ABSTRACT_VALUE(TermInst, SILInstruction)
246244
TERMINATOR(UnreachableInst, TermInst, None, DoesNotRelease)
247245
TERMINATOR(ReturnInst, TermInst, None, DoesNotRelease)
248-
TERMINATOR(AutoreleaseReturnInst, TermInst, None, DoesNotRelease)
249246
TERMINATOR(ThrowInst, TermInst, None, DoesNotRelease)
250247
TERMINATOR(TryApplyInst, TermInst, MayHaveSideEffects, MayRelease)
251248
TERMINATOR(BranchInst, TermInst, None, DoesNotRelease)

include/swift/SILPasses/Utils/SCCVisitor.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ class SCCVisitor {
131131

132132
case ValueKind::UnreachableInst:
133133
case ValueKind::ReturnInst:
134-
case ValueKind::AutoreleaseReturnInst:
135134
case ValueKind::SwitchValueInst:
136135
case ValueKind::ThrowInst:
137136
llvm_unreachable("Did not expect terminator that does not have args!");

lib/IRGen/IRGenSIL.cpp

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,6 @@ class IRGenSILFunction :
667667
void visitStrongUnpinInst(StrongUnpinInst *i);
668668
void visitStrongRetainInst(StrongRetainInst *i);
669669
void visitStrongReleaseInst(StrongReleaseInst *i);
670-
void visitStrongRetainAutoreleasedInst(StrongRetainAutoreleasedInst *i);
671670
void visitStrongRetainUnownedInst(StrongRetainUnownedInst *i);
672671
void visitUnownedRetainInst(UnownedRetainInst *i);
673672
void visitUnownedReleaseInst(UnownedReleaseInst *i);
@@ -723,7 +722,6 @@ class IRGenSILFunction :
723722
void visitBranchInst(BranchInst *i);
724723
void visitCondBranchInst(CondBranchInst *i);
725724
void visitReturnInst(ReturnInst *i);
726-
void visitAutoreleaseReturnInst(AutoreleaseReturnInst *i);
727725
void visitThrowInst(ThrowInst *i);
728726
void visitSwitchValueInst(SwitchValueInst *i);
729727
void visitSwitchEnumInst(SwitchEnumInst *i);
@@ -2170,15 +2168,6 @@ void IRGenSILFunction::visitReturnInst(swift::ReturnInst *i) {
21702168
emitReturnInst(*this, i->getOperand().getType(), result);
21712169
}
21722170

2173-
void IRGenSILFunction::visitAutoreleaseReturnInst(AutoreleaseReturnInst *i) {
2174-
Explosion result = getLoweredExplosion(i->getOperand());
2175-
assert(result.size() == 1 &&
2176-
"should have one objc pointer value for autorelease_return");
2177-
Explosion temp;
2178-
temp.add(emitObjCAutoreleaseReturnValue(*this, result.claimNext()));
2179-
emitReturnInst(*this, i->getOperand().getType(), temp);
2180-
}
2181-
21822171
void IRGenSILFunction::visitThrowInst(swift::ThrowInst *i) {
21832172
// Store the exception to the error slot.
21842173
llvm::Value *exn = getLoweredSingletonExplosion(i->getOperand());
@@ -3078,29 +3067,6 @@ void IRGenSILFunction::visitStrongReleaseInst(swift::StrongReleaseInst *i) {
30783067
ti.strongRelease(*this, lowered);
30793068
}
30803069

3081-
void IRGenSILFunction::
3082-
visitStrongRetainAutoreleasedInst(swift::StrongRetainAutoreleasedInst *i) {
3083-
Explosion lowered = getLoweredExplosion(i->getOperand());
3084-
llvm::Value *value = lowered.claimNext();
3085-
value = emitObjCRetainAutoreleasedReturnValue(*this, value);
3086-
3087-
// Overwrite the stored explosion value with the result of
3088-
// objc_retainAutoreleasedReturnValue. This is actually
3089-
// semantically important: if the call result is live across this
3090-
// call, the backend will have to emit instructions that interfere
3091-
// with the reclaim optimization.
3092-
//
3093-
// This is only sound if the retainAutoreleasedReturnValue
3094-
// immediately follows the call, but that should be reliably true.
3095-
//
3096-
// ...the reclaim here should really be implicit in the SIL calling
3097-
// convention.
3098-
3099-
Explosion out;
3100-
out.add(value);
3101-
overwriteLoweredExplosion(i->getOperand(), out);
3102-
}
3103-
31043070
/// Given a SILType which is a ReferenceStorageType, return the type
31053071
/// info for the underlying reference type.
31063072
static const ReferenceTypeInfo &getReferentTypeInfo(IRGenFunction &IGF,

lib/Parse/ParseSIL.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,6 @@ bool SILParser::parseSILOpcode(ValueKind &Opcode, SourceLoc &OpcodeLoc,
11941194
.Case("witness_method", ValueKind::WitnessMethodInst)
11951195
.Case("apply", ValueKind::ApplyInst)
11961196
.Case("assign", ValueKind::AssignInst)
1197-
.Case("autorelease_return", ValueKind::AutoreleaseReturnInst)
11981197
.Case("autorelease_value", ValueKind::AutoreleaseValueInst)
11991198
.Case("br", ValueKind::BranchInst)
12001199
.Case("builtin", ValueKind::BuiltinInst)
@@ -1271,7 +1270,6 @@ bool SILParser::parseSILOpcode(ValueKind &Opcode, SourceLoc &OpcodeLoc,
12711270
.Case("strong_pin", ValueKind::StrongPinInst)
12721271
.Case("strong_release", ValueKind::StrongReleaseInst)
12731272
.Case("strong_retain", ValueKind::StrongRetainInst)
1274-
.Case("strong_retain_autoreleased", ValueKind::StrongRetainAutoreleasedInst)
12751273
.Case("strong_retain_unowned", ValueKind::StrongRetainUnownedInst)
12761274
.Case("strong_unpin", ValueKind::StrongUnpinInst)
12771275
.Case("return", ValueKind::ReturnInst)
@@ -1934,9 +1932,7 @@ bool SILParser::parseSILInstruction(SILBasicBlock *BB) {
19341932
UNARY_INSTRUCTION(StrongPin)
19351933
UNARY_INSTRUCTION(StrongRetain)
19361934
UNARY_INSTRUCTION(StrongRelease)
1937-
UNARY_INSTRUCTION(StrongRetainAutoreleased)
19381935
UNARY_INSTRUCTION(StrongUnpin)
1939-
UNARY_INSTRUCTION(AutoreleaseReturn)
19401936
UNARY_INSTRUCTION(StrongRetainUnowned)
19411937
UNARY_INSTRUCTION(UnownedRetain)
19421938
UNARY_INSTRUCTION(UnownedRelease)

lib/SIL/SILPrinter.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,9 +1255,6 @@ class SILPrinter : public SILVisitor<SILPrinter> {
12551255
void visitStrongRetainInst(StrongRetainInst *RI) {
12561256
*this << "strong_retain " << getIDAndType(RI->getOperand());
12571257
}
1258-
void visitStrongRetainAutoreleasedInst(StrongRetainAutoreleasedInst *RI) {
1259-
*this << "strong_retain_autoreleased " << getIDAndType(RI->getOperand());
1260-
}
12611258
void visitStrongReleaseInst(StrongReleaseInst *RI) {
12621259
*this << "strong_release " << getIDAndType(RI->getOperand());
12631260
}
@@ -1337,10 +1334,6 @@ class SILPrinter : public SILVisitor<SILPrinter> {
13371334
*this << "return " << getIDAndType(RI->getOperand());
13381335
}
13391336

1340-
void visitAutoreleaseReturnInst(AutoreleaseReturnInst *RI) {
1341-
*this << "autorelease_return " << getIDAndType(RI->getOperand());
1342-
}
1343-
13441337
void visitThrowInst(ThrowInst *TI) {
13451338
*this << "throw " << getIDAndType(TI->getOperand());
13461339
}

0 commit comments

Comments
 (0)