@@ -312,6 +312,7 @@ AdjointValue JVPEmitter::getTangentValue(SILValue originalValue) {
312312
313313void 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
11031106void 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);
0 commit comments