@@ -312,6 +312,7 @@ AdjointValue JVPEmitter::getTangentValue(SILValue originalValue) {
312
312
313
313
void JVPEmitter::setTangentValue (SILBasicBlock *origBB, SILValue originalValue,
314
314
AdjointValue newTangentValue) {
315
+ #ifndef NDEBUG
315
316
if (auto *defInst = originalValue->getDefiningInstruction ()) {
316
317
bool isTupleTypedApplyResult =
317
318
isa<ApplyInst>(defInst) && originalValue->getType ().is <TupleType>();
@@ -320,6 +321,7 @@ void JVPEmitter::setTangentValue(SILBasicBlock *origBB, SILValue originalValue,
320
321
" instruction; use `destructure_tuple` on `apply` result and set "
321
322
" tangent value for `destructure_tuple` results instead." );
322
323
}
324
+ #endif
323
325
assert (originalValue->getType ().isObject ());
324
326
assert (newTangentValue.getType ().isObject ());
325
327
assert (originalValue->getFunction () == original);
@@ -328,8 +330,8 @@ void JVPEmitter::setTangentValue(SILBasicBlock *origBB, SILValue originalValue,
328
330
assert (newTangentValue.getType () ==
329
331
getRemappedTangentType (originalValue->getType ()));
330
332
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." );
333
335
}
334
336
335
337
// --------------------------------------------------------------------------//
@@ -861,20 +863,19 @@ void JVPEmitter::prepareForDifferentialGeneration() {
861
863
for (auto &origBB : *original) {
862
864
auto *diffBB = differential.createBasicBlock ();
863
865
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
865
874
auto diffStructLoweredType = remapSILTypeInDifferential (
866
875
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;
878
879
}
879
880
880
881
LLVM_DEBUG ({
@@ -942,10 +943,12 @@ void JVPEmitter::prepareForDifferentialGeneration() {
942
943
// Initialize tangent mapping for indirect results.
943
944
auto origIndResults = original->getIndirectResults ();
944
945
auto diffIndResults = differential.getIndirectResults ();
946
+ #ifndef NDEBUG
945
947
unsigned numInoutParameters = llvm::count_if (
946
948
original->getLoweredFunctionType ()->getParameters (),
947
949
[](SILParameterInfo paramInfo) { return paramInfo.isIndirectInOut (); });
948
950
assert (origIndResults.size () + numInoutParameters == diffIndResults.size ());
951
+ #endif
949
952
for (auto &origBB : *original)
950
953
for (auto i : indices (origIndResults))
951
954
setTangentBuffer (&origBB, origIndResults[i], diffIndResults[i]);
@@ -1101,12 +1104,12 @@ SILBasicBlock *JVPEmitter::remapBasicBlock(SILBasicBlock *bb) {
1101
1104
}
1102
1105
1103
1106
void JVPEmitter::visit (SILInstruction *inst) {
1104
- auto diffBuilder = getDifferentialBuilder ();
1105
1107
if (errorOccurred)
1106
1108
return ;
1107
1109
if (differentialInfo.shouldDifferentiateInstruction (inst)) {
1108
1110
LLVM_DEBUG (getADDebugStream () << " JVPEmitter visited:\n [ORIG]" << *inst);
1109
1111
#ifndef NDEBUG
1112
+ auto diffBuilder = getDifferentialBuilder ();
1110
1113
auto beforeInsertion = std::prev (diffBuilder.getInsertionPoint ());
1111
1114
#endif
1112
1115
TypeSubstCloner::visit (inst);
0 commit comments