Skip to content

[AutoDiff] NFC: silence no-asserts unused variable warnings. #32675

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/SILOptimizer/Differentiation/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,14 @@ void collectMinimalIndicesForFunctionCall(
resultIndices.push_back(inoutParamResultIndex++);
}
// Make sure the function call has active results.
#ifndef NDEBUG
auto numResults = calleeFnTy->getNumResults() +
calleeFnTy->getNumIndirectMutatingParameters();
assert(results.size() == numResults);
assert(llvm::any_of(results, [&](SILValue result) {
return activityInfo.isActive(result, parentIndices);
}));
#endif
}

//===----------------------------------------------------------------------===//
Expand Down
33 changes: 18 additions & 15 deletions lib/SILOptimizer/Differentiation/JVPEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ AdjointValue JVPEmitter::getTangentValue(SILValue originalValue) {

void JVPEmitter::setTangentValue(SILBasicBlock *origBB, SILValue originalValue,
AdjointValue newTangentValue) {
#ifndef NDEBUG
if (auto *defInst = originalValue->getDefiningInstruction()) {
bool isTupleTypedApplyResult =
isa<ApplyInst>(defInst) && originalValue->getType().is<TupleType>();
Expand All @@ -320,6 +321,7 @@ void JVPEmitter::setTangentValue(SILBasicBlock *origBB, SILValue originalValue,
"instruction; use `destructure_tuple` on `apply` result and set "
"tangent value for `destructure_tuple` results instead.");
}
#endif
assert(originalValue->getType().isObject());
assert(newTangentValue.getType().isObject());
assert(originalValue->getFunction() == original);
Expand All @@ -328,8 +330,8 @@ void JVPEmitter::setTangentValue(SILBasicBlock *origBB, SILValue originalValue,
assert(newTangentValue.getType() ==
getRemappedTangentType(originalValue->getType()));
auto insertion = tangentValueMap.try_emplace(originalValue, newTangentValue);
auto inserted = insertion.second;
assert(inserted && "The tangent value should not already exist.");
(void)insertion;
assert(insertion.second && "The tangent value should not already exist.");
}

//--------------------------------------------------------------------------//
Expand Down Expand Up @@ -861,20 +863,19 @@ void JVPEmitter::prepareForDifferentialGeneration() {
for (auto &origBB : *original) {
auto *diffBB = differential.createBasicBlock();
diffBBMap.insert({&origBB, diffBB});
{
// If the BB is the original entry, then the differential block that we
// just created must be the differential function's entry. Create
// differential entry arguments and continue.
if (&origBB == origEntry) {
assert(diffBB->isEntry());
createEntryArguments(&differential);
auto *lastArg = diffBB->getArguments().back();
#ifndef NDEBUG
auto diffStructLoweredType = remapSILTypeInDifferential(
differentialInfo.getLinearMapStructLoweredType(&origBB));

// If the BB is the original entry, then the differential block that we
// just created must be the differential function's entry. Create
// differential entry arguments and continue.
if (&origBB == origEntry) {
assert(diffBB->isEntry());
createEntryArguments(&differential);
auto *lastArg = diffBB->getArguments().back();
assert(lastArg->getType() == diffStructLoweredType);
differentialStructArguments[&origBB] = lastArg;
}
assert(lastArg->getType() == diffStructLoweredType);
#endif
differentialStructArguments[&origBB] = lastArg;
}

LLVM_DEBUG({
Expand Down Expand Up @@ -942,10 +943,12 @@ void JVPEmitter::prepareForDifferentialGeneration() {
// Initialize tangent mapping for indirect results.
auto origIndResults = original->getIndirectResults();
auto diffIndResults = differential.getIndirectResults();
#ifndef NDEBUG
unsigned numInoutParameters = llvm::count_if(
original->getLoweredFunctionType()->getParameters(),
[](SILParameterInfo paramInfo) { return paramInfo.isIndirectInOut(); });
assert(origIndResults.size() + numInoutParameters == diffIndResults.size());
#endif
for (auto &origBB : *original)
for (auto i : indices(origIndResults))
setTangentBuffer(&origBB, origIndResults[i], diffIndResults[i]);
Expand Down Expand Up @@ -1101,12 +1104,12 @@ SILBasicBlock *JVPEmitter::remapBasicBlock(SILBasicBlock *bb) {
}

void JVPEmitter::visit(SILInstruction *inst) {
auto diffBuilder = getDifferentialBuilder();
if (errorOccurred)
return;
if (differentialInfo.shouldDifferentiateInstruction(inst)) {
LLVM_DEBUG(getADDebugStream() << "JVPEmitter visited:\n[ORIG]" << *inst);
#ifndef NDEBUG
auto diffBuilder = getDifferentialBuilder();
auto beforeInsertion = std::prev(diffBuilder.getInsertionPoint());
#endif
TypeSubstCloner::visit(inst);
Expand Down
9 changes: 6 additions & 3 deletions lib/SILOptimizer/Differentiation/PullbackEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1329,6 +1329,7 @@ void PullbackEmitter::visitSILBasicBlock(SILBasicBlock *bb) {
// 1. Get the pullback struct pullback block argument.
// 2. Extract the predecessor enum value from the pullback struct value.
auto *predEnum = getPullbackInfo().getBranchingTraceDecl(bb);
(void)predEnum;
auto *predEnumField = getPullbackInfo().lookUpLinearMapStructEnumField(bb);
auto predEnumVal = getPullbackStructElement(bb, predEnumField);

Expand Down Expand Up @@ -1680,14 +1681,16 @@ void PullbackEmitter::visitStructInst(StructInst *si) {
break;
case AdjointValueKind::Concrete: {
auto adjStruct = materializeAdjointDirect(std::move(av), loc);
auto *dti = builder.createDestructureStruct(si->getLoc(), adjStruct);

// Find the struct `TangentVector` type.
auto structTy = remapType(si->getType()).getASTType();
#ifndef NDEBUG
auto tangentVectorTy = getTangentSpace(structTy)->getCanonicalType();
assert(!getTypeLowering(tangentVectorTy).isAddressOnly());
auto *tangentVectorDecl = tangentVectorTy->getStructOrBoundGenericStruct();
assert(tangentVectorDecl);
assert(tangentVectorTy->getStructOrBoundGenericStruct());
#endif

auto *dti = builder.createDestructureStruct(si->getLoc(), adjStruct);
// Accumulate adjoints for the fields of the `struct` operand.
unsigned fieldIndex = 0;
for (auto it = structDecl->getStoredProperties().begin();
Expand Down
4 changes: 4 additions & 0 deletions lib/SILOptimizer/Differentiation/Thunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,11 @@ SILFunction *getOrCreateReabstractionThunk(SILOptFunctionBuilder &fb,
}
// Store direct results to indirect results.
assert(toRes.isFormalIndirect());
#ifndef NDEBUG
SILType resultTy =
toConv.getSILType(toRes, builder.getTypeExpansionContext());
assert(resultTy.isAddress());
#endif
auto indRes = *toIndResultsIter++;
builder.createStore(loc, *fromDirResultsIter++, indRes,
StoreOwnershipQualifier::Unqualified);
Expand Down Expand Up @@ -837,8 +839,10 @@ getOrCreateSubsetParametersThunkForDerivativeFunction(
peerThroughFunctionConversions<ClassMethodInst>(
derivativeFn)) {
auto classOperand = thunk->getArgumentsWithoutIndirectResults().back();
#ifndef NDEBUG
auto classOperandType = assocMethodInst->getOperand()->getType();
assert(classOperand->getType() == classOperandType);
#endif
assocRef = builder.createClassMethod(
loc, classOperand, assocMethodInst->getMember(),
thunk->mapTypeIntoContext(assocMethodInst->getType()));
Expand Down