@@ -1916,14 +1916,6 @@ static SILValue joinElements(ArrayRef<SILValue> elements, SILBuilder &builder,
1916
1916
return builder.createTuple (loc, elements);
1917
1917
}
1918
1918
1919
- // Emits a release based on the value's type category (address or object).
1920
- static void emitCleanup (SILBuilder &builder, SILLocation loc, SILValue v) {
1921
- if (v->getType ().isAddress ())
1922
- builder.createDestroyAddr (loc, v);
1923
- else
1924
- builder.createReleaseValue (loc, v, builder.getDefaultAtomicity ());
1925
- }
1926
-
1927
1919
// / When a function value is used in an instruction (usually `apply`), there's
1928
1920
// / some conversion instruction in between, e.g. `thin_to_thick_function`. Given
1929
1921
// / a new function value and an old function value, this helper function
@@ -3407,8 +3399,7 @@ class VJPEmitter final
3407
3399
3408
3400
// Release the differentiable function.
3409
3401
if (differentiableFunc)
3410
- builder.createReleaseValue (loc, differentiableFunc,
3411
- builder.getDefaultAtomicity ());
3402
+ builder.emitReleaseValueAndFold (loc, differentiableFunc);
3412
3403
3413
3404
// Get the VJP results (original results and pullback).
3414
3405
SmallVector<SILValue, 8 > vjpDirectResults;
@@ -3974,7 +3965,7 @@ class PullbackEmitter final : public SILInstructionVisitor<PullbackEmitter> {
3974
3965
LLVM_DEBUG (getADDebugStream () << " Cleaning up temporaries for bb"
3975
3966
<< bb->getDebugID () << ' \n ' );
3976
3967
for (auto temp : blockTemporaries[bb]) {
3977
- emitCleanup ( builder, loc, temp);
3968
+ builder. emitReleaseValueAndFold ( loc, temp);
3978
3969
blockTemporarySet.erase (temp);
3979
3970
}
3980
3971
}
@@ -4846,7 +4837,7 @@ class PullbackEmitter final : public SILInstructionVisitor<PullbackEmitter> {
4846
4837
ApplyInst *ai, CopyAddrInst *cai, AllocStackInst *subscriptBuffer) {
4847
4838
addToAdjointBuffer (cai->getParent (), cai->getSrc (), subscriptBuffer,
4848
4839
cai->getLoc ());
4849
- emitCleanup ( builder, cai->getLoc (), subscriptBuffer);
4840
+ builder. emitDestroyAddrAndFold ( cai->getLoc (), subscriptBuffer);
4850
4841
builder.createDeallocStack (ai->getLoc (), subscriptBuffer);
4851
4842
}
4852
4843
@@ -5042,7 +5033,7 @@ class PullbackEmitter final : public SILInstructionVisitor<PullbackEmitter> {
5042
5033
auto tan = *allResultsIt++;
5043
5034
if (tan->getType ().isAddress ()) {
5044
5035
addToAdjointBuffer (bb, origArg, tan, loc);
5045
- emitCleanup ( builder, loc, tan);
5036
+ builder. emitDestroyAddrAndFold ( loc, tan);
5046
5037
} else {
5047
5038
if (origArg->getType ().isAddress ()) {
5048
5039
if (errorOccurred)
@@ -5051,7 +5042,7 @@ class PullbackEmitter final : public SILInstructionVisitor<PullbackEmitter> {
5051
5042
builder.createStore (loc, tan, tmpBuf,
5052
5043
getBufferSOQ (tmpBuf->getType ().getASTType (), getPullback ()));
5053
5044
addToAdjointBuffer (bb, origArg, tmpBuf, loc);
5054
- emitCleanup ( builder, loc, tmpBuf);
5045
+ builder. emitDestroyAddrAndFold ( loc, tmpBuf);
5055
5046
builder.createDeallocStack (loc, tmpBuf);
5056
5047
}
5057
5048
else {
@@ -5347,7 +5338,7 @@ class PullbackEmitter final : public SILInstructionVisitor<PullbackEmitter> {
5347
5338
return ;
5348
5339
auto destType = remapType (adjDest->getType ());
5349
5340
addToAdjointBuffer (bb, cai->getSrc (), adjDest, cai->getLoc ());
5350
- emitCleanup ( builder, cai->getLoc (), adjDest);
5341
+ builder. emitDestroyAddrAndFold ( cai->getLoc (), adjDest);
5351
5342
emitZeroIndirect (destType.getASTType (), adjDest, cai->getLoc ());
5352
5343
}
5353
5344
@@ -6306,13 +6297,15 @@ ADContext::getOrCreateSubsetParametersThunkForLinearMap(
6306
6297
// - Push it to `results` if result is direct.
6307
6298
auto result = allResults[mapOriginalParameterIndex (i)];
6308
6299
if (desiredIndices.isWrtParameter (i)) {
6309
- if (result->getType ().isAddress ())
6310
- continue ;
6311
- results.push_back (result);
6300
+ if (result->getType ().isObject ())
6301
+ results.push_back (result);
6312
6302
}
6313
6303
// Otherwise, cleanup the unused results.
6314
6304
else {
6315
- emitCleanup (builder, loc, result);
6305
+ if (result->getType ().isAddress ())
6306
+ builder.emitDestroyAddrAndFold (loc, result);
6307
+ else
6308
+ builder.emitReleaseValueAndFold (loc, result);
6316
6309
}
6317
6310
}
6318
6311
// Deallocate local allocations and return final direct result.
@@ -6685,7 +6678,7 @@ void ADContext::foldAutoDiffFunctionExtraction(AutoDiffFunctionInst *source) {
6685
6678
if (isInstructionTriviallyDead (source)) {
6686
6679
SILBuilder builder (source);
6687
6680
for (auto &assocFn : source->getAssociatedFunctions ())
6688
- emitCleanup ( builder, source->getLoc (), assocFn.get ());
6681
+ builder. emitDestroyAddrAndFold ( source->getLoc (), assocFn.get ());
6689
6682
source->eraseFromParent ();
6690
6683
}
6691
6684
// Mark `source` as processed so that it won't be reprocessed after deletion.
0 commit comments