Skip to content

Commit 9defc0a

Browse files
authored
[AutoDiff] NFC: silence no-asserts unused variable warnings. (#32675)
1 parent a091d4f commit 9defc0a

File tree

4 files changed

+30
-18
lines changed

4 files changed

+30
-18
lines changed

lib/SILOptimizer/Differentiation/Common.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,14 @@ void collectMinimalIndicesForFunctionCall(
238238
resultIndices.push_back(inoutParamResultIndex++);
239239
}
240240
// Make sure the function call has active results.
241+
#ifndef NDEBUG
241242
auto numResults = calleeFnTy->getNumResults() +
242243
calleeFnTy->getNumIndirectMutatingParameters();
243244
assert(results.size() == numResults);
244245
assert(llvm::any_of(results, [&](SILValue result) {
245246
return activityInfo.isActive(result, parentIndices);
246247
}));
248+
#endif
247249
}
248250

249251
//===----------------------------------------------------------------------===//

lib/SILOptimizer/Differentiation/JVPEmitter.cpp

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ AdjointValue JVPEmitter::getTangentValue(SILValue originalValue) {
312312

313313
void JVPEmitter::setTangentValue(SILBasicBlock *origBB, SILValue originalValue,
314314
AdjointValue newTangentValue) {
315+
#ifndef NDEBUG
315316
if (auto *defInst = originalValue->getDefiningInstruction()) {
316317
bool isTupleTypedApplyResult =
317318
isa<ApplyInst>(defInst) && originalValue->getType().is<TupleType>();
@@ -320,6 +321,7 @@ void JVPEmitter::setTangentValue(SILBasicBlock *origBB, SILValue originalValue,
320321
"instruction; use `destructure_tuple` on `apply` result and set "
321322
"tangent value for `destructure_tuple` results instead.");
322323
}
324+
#endif
323325
assert(originalValue->getType().isObject());
324326
assert(newTangentValue.getType().isObject());
325327
assert(originalValue->getFunction() == original);
@@ -328,8 +330,8 @@ void JVPEmitter::setTangentValue(SILBasicBlock *origBB, SILValue originalValue,
328330
assert(newTangentValue.getType() ==
329331
getRemappedTangentType(originalValue->getType()));
330332
auto insertion = tangentValueMap.try_emplace(originalValue, newTangentValue);
331-
auto inserted = insertion.second;
332-
assert(inserted && "The tangent value should not already exist.");
333+
(void)insertion;
334+
assert(insertion.second && "The tangent value should not already exist.");
333335
}
334336

335337
//--------------------------------------------------------------------------//
@@ -861,20 +863,19 @@ void JVPEmitter::prepareForDifferentialGeneration() {
861863
for (auto &origBB : *original) {
862864
auto *diffBB = differential.createBasicBlock();
863865
diffBBMap.insert({&origBB, diffBB});
864-
{
866+
// If the BB is the original entry, then the differential block that we
867+
// just created must be the differential function's entry. Create
868+
// differential entry arguments and continue.
869+
if (&origBB == origEntry) {
870+
assert(diffBB->isEntry());
871+
createEntryArguments(&differential);
872+
auto *lastArg = diffBB->getArguments().back();
873+
#ifndef NDEBUG
865874
auto diffStructLoweredType = remapSILTypeInDifferential(
866875
differentialInfo.getLinearMapStructLoweredType(&origBB));
867-
868-
// If the BB is the original entry, then the differential block that we
869-
// just created must be the differential function's entry. Create
870-
// differential entry arguments and continue.
871-
if (&origBB == origEntry) {
872-
assert(diffBB->isEntry());
873-
createEntryArguments(&differential);
874-
auto *lastArg = diffBB->getArguments().back();
875-
assert(lastArg->getType() == diffStructLoweredType);
876-
differentialStructArguments[&origBB] = lastArg;
877-
}
876+
assert(lastArg->getType() == diffStructLoweredType);
877+
#endif
878+
differentialStructArguments[&origBB] = lastArg;
878879
}
879880

880881
LLVM_DEBUG({
@@ -942,10 +943,12 @@ void JVPEmitter::prepareForDifferentialGeneration() {
942943
// Initialize tangent mapping for indirect results.
943944
auto origIndResults = original->getIndirectResults();
944945
auto diffIndResults = differential.getIndirectResults();
946+
#ifndef NDEBUG
945947
unsigned numInoutParameters = llvm::count_if(
946948
original->getLoweredFunctionType()->getParameters(),
947949
[](SILParameterInfo paramInfo) { return paramInfo.isIndirectInOut(); });
948950
assert(origIndResults.size() + numInoutParameters == diffIndResults.size());
951+
#endif
949952
for (auto &origBB : *original)
950953
for (auto i : indices(origIndResults))
951954
setTangentBuffer(&origBB, origIndResults[i], diffIndResults[i]);
@@ -1101,12 +1104,12 @@ SILBasicBlock *JVPEmitter::remapBasicBlock(SILBasicBlock *bb) {
11011104
}
11021105

11031106
void JVPEmitter::visit(SILInstruction *inst) {
1104-
auto diffBuilder = getDifferentialBuilder();
11051107
if (errorOccurred)
11061108
return;
11071109
if (differentialInfo.shouldDifferentiateInstruction(inst)) {
11081110
LLVM_DEBUG(getADDebugStream() << "JVPEmitter visited:\n[ORIG]" << *inst);
11091111
#ifndef NDEBUG
1112+
auto diffBuilder = getDifferentialBuilder();
11101113
auto beforeInsertion = std::prev(diffBuilder.getInsertionPoint());
11111114
#endif
11121115
TypeSubstCloner::visit(inst);

lib/SILOptimizer/Differentiation/PullbackEmitter.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,6 +1329,7 @@ void PullbackEmitter::visitSILBasicBlock(SILBasicBlock *bb) {
13291329
// 1. Get the pullback struct pullback block argument.
13301330
// 2. Extract the predecessor enum value from the pullback struct value.
13311331
auto *predEnum = getPullbackInfo().getBranchingTraceDecl(bb);
1332+
(void)predEnum;
13321333
auto *predEnumField = getPullbackInfo().lookUpLinearMapStructEnumField(bb);
13331334
auto predEnumVal = getPullbackStructElement(bb, predEnumField);
13341335

@@ -1680,14 +1681,16 @@ void PullbackEmitter::visitStructInst(StructInst *si) {
16801681
break;
16811682
case AdjointValueKind::Concrete: {
16821683
auto adjStruct = materializeAdjointDirect(std::move(av), loc);
1684+
auto *dti = builder.createDestructureStruct(si->getLoc(), adjStruct);
1685+
16831686
// Find the struct `TangentVector` type.
16841687
auto structTy = remapType(si->getType()).getASTType();
1688+
#ifndef NDEBUG
16851689
auto tangentVectorTy = getTangentSpace(structTy)->getCanonicalType();
16861690
assert(!getTypeLowering(tangentVectorTy).isAddressOnly());
1687-
auto *tangentVectorDecl = tangentVectorTy->getStructOrBoundGenericStruct();
1688-
assert(tangentVectorDecl);
1691+
assert(tangentVectorTy->getStructOrBoundGenericStruct());
1692+
#endif
16891693

1690-
auto *dti = builder.createDestructureStruct(si->getLoc(), adjStruct);
16911694
// Accumulate adjoints for the fields of the `struct` operand.
16921695
unsigned fieldIndex = 0;
16931696
for (auto it = structDecl->getStoredProperties().begin();

lib/SILOptimizer/Differentiation/Thunk.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,9 +419,11 @@ SILFunction *getOrCreateReabstractionThunk(SILOptFunctionBuilder &fb,
419419
}
420420
// Store direct results to indirect results.
421421
assert(toRes.isFormalIndirect());
422+
#ifndef NDEBUG
422423
SILType resultTy =
423424
toConv.getSILType(toRes, builder.getTypeExpansionContext());
424425
assert(resultTy.isAddress());
426+
#endif
425427
auto indRes = *toIndResultsIter++;
426428
builder.createStore(loc, *fromDirResultsIter++, indRes,
427429
StoreOwnershipQualifier::Unqualified);
@@ -837,8 +839,10 @@ getOrCreateSubsetParametersThunkForDerivativeFunction(
837839
peerThroughFunctionConversions<ClassMethodInst>(
838840
derivativeFn)) {
839841
auto classOperand = thunk->getArgumentsWithoutIndirectResults().back();
842+
#ifndef NDEBUG
840843
auto classOperandType = assocMethodInst->getOperand()->getType();
841844
assert(classOperand->getType() == classOperandType);
845+
#endif
842846
assocRef = builder.createClassMethod(
843847
loc, classOperand, assocMethodInst->getMember(),
844848
thunk->mapTypeIntoContext(assocMethodInst->getType()));

0 commit comments

Comments
 (0)