@@ -245,6 +245,7 @@ Value *GradientUtils::unwrapM(Value *const val, IRBuilder<> &BuilderM,
245
245
newi->copyIRFlags (op);
246
246
if (permitCache)
247
247
unwrap_cache[BuilderM.GetInsertBlock ()][idx] = toreturn;
248
+ unwrappedLoads[toreturn] = val;
248
249
assert (val->getType () == toreturn->getType ());
249
250
return toreturn;
250
251
} else if (auto op = dyn_cast<ExtractValueInst>(val)) {
@@ -255,6 +256,7 @@ Value *GradientUtils::unwrapM(Value *const val, IRBuilder<> &BuilderM,
255
256
op->getName () + " _unwrap" );
256
257
if (permitCache)
257
258
unwrap_cache[BuilderM.GetInsertBlock ()][idx] = toreturn;
259
+ unwrappedLoads[toreturn] = val;
258
260
if (auto newi = dyn_cast<Instruction>(toreturn))
259
261
newi->copyIRFlags (op);
260
262
assert (val->getType () == toreturn->getType ());
@@ -270,6 +272,7 @@ Value *GradientUtils::unwrapM(Value *const val, IRBuilder<> &BuilderM,
270
272
op->getName () + " _unwrap" );
271
273
if (permitCache)
272
274
unwrap_cache[BuilderM.GetInsertBlock ()][idx] = toreturn;
275
+ unwrappedLoads[toreturn] = val;
273
276
if (auto newi = dyn_cast<Instruction>(toreturn))
274
277
newi->copyIRFlags (op);
275
278
assert (val->getType () == toreturn->getType ());
@@ -285,6 +288,7 @@ Value *GradientUtils::unwrapM(Value *const val, IRBuilder<> &BuilderM,
285
288
BuilderM.CreateExtractElement (op0, op1, op->getName () + " _unwrap" );
286
289
if (permitCache)
287
290
unwrap_cache[BuilderM.GetInsertBlock ()][idx] = toreturn;
291
+ unwrappedLoads[toreturn] = val;
288
292
if (auto newi = dyn_cast<Instruction>(toreturn))
289
293
newi->copyIRFlags (op);
290
294
assert (val->getType () == toreturn->getType ());
@@ -303,6 +307,7 @@ Value *GradientUtils::unwrapM(Value *const val, IRBuilder<> &BuilderM,
303
307
BuilderM.CreateInsertElement (op0, op1, op2, op->getName () + " _unwrap" );
304
308
if (permitCache)
305
309
unwrap_cache[BuilderM.GetInsertBlock ()][idx] = toreturn;
310
+ unwrappedLoads[toreturn] = val;
306
311
if (auto newi = dyn_cast<Instruction>(toreturn))
307
312
newi->copyIRFlags (op);
308
313
assert (val->getType () == toreturn->getType ());
@@ -323,6 +328,7 @@ Value *GradientUtils::unwrapM(Value *const val, IRBuilder<> &BuilderM,
323
328
#endif
324
329
if (permitCache)
325
330
unwrap_cache[BuilderM.GetInsertBlock ()][idx] = toreturn;
331
+ unwrappedLoads[toreturn] = val;
326
332
if (auto newi = dyn_cast<Instruction>(toreturn))
327
333
newi->copyIRFlags (op);
328
334
assert (val->getType () == toreturn->getType ());
@@ -342,6 +348,7 @@ Value *GradientUtils::unwrapM(Value *const val, IRBuilder<> &BuilderM,
342
348
assert (op0->getType () == op1->getType ());
343
349
auto toreturn = BuilderM.CreateBinOp (op->getOpcode (), op0, op1,
344
350
op->getName () + " _unwrap" );
351
+ unwrappedLoads[toreturn] = val;
345
352
if (auto newi = dyn_cast<Instruction>(toreturn))
346
353
newi->copyIRFlags (op);
347
354
if (permitCache)
@@ -361,6 +368,7 @@ Value *GradientUtils::unwrapM(Value *const val, IRBuilder<> &BuilderM,
361
368
newi->copyIRFlags (op);
362
369
if (permitCache)
363
370
unwrap_cache[BuilderM.GetInsertBlock ()][idx] = toreturn;
371
+ unwrappedLoads[toreturn] = val;
364
372
assert (val->getType () == toreturn->getType ());
365
373
return toreturn;
366
374
} else if (auto op = dyn_cast<FCmpInst>(val)) {
@@ -376,6 +384,7 @@ Value *GradientUtils::unwrapM(Value *const val, IRBuilder<> &BuilderM,
376
384
newi->copyIRFlags (op);
377
385
if (permitCache)
378
386
unwrap_cache[BuilderM.GetInsertBlock ()][idx] = toreturn;
387
+ unwrappedLoads[toreturn] = val;
379
388
assert (val->getType () == toreturn->getType ());
380
389
return toreturn;
381
390
#if LLVM_VERSION_MAJOR >= 9
@@ -390,6 +399,7 @@ Value *GradientUtils::unwrapM(Value *const val, IRBuilder<> &BuilderM,
390
399
newi->copyIRFlags (op);
391
400
if (permitCache)
392
401
unwrap_cache[BuilderM.GetInsertBlock ()][idx] = toreturn;
402
+ unwrappedLoads[toreturn] = val;
393
403
assert (val->getType () == toreturn->getType ());
394
404
return toreturn;
395
405
#endif
@@ -409,6 +419,7 @@ Value *GradientUtils::unwrapM(Value *const val, IRBuilder<> &BuilderM,
409
419
newi->copyIRFlags (op);
410
420
if (permitCache)
411
421
unwrap_cache[BuilderM.GetInsertBlock ()][idx] = toreturn;
422
+ unwrappedLoads[toreturn] = val;
412
423
assert (val->getType () == toreturn->getType ());
413
424
return toreturn;
414
425
} else if (auto inst = dyn_cast<GetElementPtrInst>(val)) {
@@ -437,6 +448,7 @@ Value *GradientUtils::unwrapM(Value *const val, IRBuilder<> &BuilderM,
437
448
newi->copyIRFlags (inst);
438
449
if (permitCache)
439
450
unwrap_cache[BuilderM.GetInsertBlock ()][idx] = toreturn;
451
+ unwrappedLoads[toreturn] = val;
440
452
assert (val->getType () == toreturn->getType ());
441
453
return toreturn;
442
454
} else if (auto load = dyn_cast<LoadInst>(val)) {
@@ -532,6 +544,7 @@ Value *GradientUtils::unwrapM(Value *const val, IRBuilder<> &BuilderM,
532
544
toreturn->setDebugLoc (getNewFromOriginal (op->getDebugLoc ()));
533
545
if (permitCache)
534
546
unwrap_cache[BuilderM.GetInsertBlock ()][idx] = toreturn;
547
+ unwrappedLoads[toreturn] = val;
535
548
return toreturn;
536
549
} else if (auto phi = dyn_cast<PHINode>(val)) {
537
550
if (phi->getNumIncomingValues () == 0 ) {
@@ -913,6 +926,7 @@ Value *GradientUtils::unwrapM(Value *const val, IRBuilder<> &BuilderM,
913
926
if (permitCache) {
914
927
unwrap_cache[bret][idx] = toret;
915
928
}
929
+ unwrappedLoads[toret] = val;
916
930
unwrap_cache[bret] = unwrap_cache[oldB];
917
931
lookup_cache[bret] = lookup_cache[oldB];
918
932
return toret;
@@ -1077,6 +1091,7 @@ Value *GradientUtils::unwrapM(Value *const val, IRBuilder<> &BuilderM,
1077
1091
}
1078
1092
unwrap_cache[bret] = unwrap_cache[oldB];
1079
1093
lookup_cache[bret] = lookup_cache[oldB];
1094
+ unwrappedLoads[toret] = val;
1080
1095
return toret;
1081
1096
}
1082
1097
goto endCheck;
0 commit comments