@@ -3129,15 +3129,19 @@ class AdjointGenerator
3129
3129
if (vdiff && !gutils->isConstantValue (orig_ops[0 ])) {
3130
3130
SmallVector<Value *, 2 > args = {
3131
3131
lookup (gutils->getNewFromOriginal (orig_ops[0 ]), Builder2)};
3132
- Type *tys[] = {orig_ops[0 ]->getType ()};
3133
- Function *SqrtF;
3134
- if (ID == Intrinsic::sqrt)
3135
- SqrtF = Intrinsic::getDeclaration (M, ID, tys);
3136
- else
3137
- SqrtF = Intrinsic::getDeclaration (M, ID);
3138
3132
3139
- auto cal = cast<CallInst>(Builder2.CreateCall (SqrtF, args));
3140
- cal->setCallingConv (SqrtF->getCallingConv ());
3133
+ auto &CI = cast<CallInst>(I);
3134
+ #if LLVM_VERSION_MAJOR >= 11
3135
+ auto *SqrtF = CI.getCalledOperand ();
3136
+ #else
3137
+ auto *SqrtF = CI.getCalledValue ();
3138
+ #endif
3139
+ assert (SqrtF);
3140
+ auto FT =
3141
+ cast<FunctionType>(SqrtF->getType ()->getPointerElementType ());
3142
+
3143
+ auto cal = cast<CallInst>(Builder2.CreateCall (FT, SqrtF, args));
3144
+ cal->setCallingConv (CI.getCallingConv ());
3141
3145
cal->setDebugLoc (gutils->getNewFromOriginal (I.getDebugLoc ()));
3142
3146
3143
3147
Value *dif0 = Builder2.CreateBinOp (
@@ -3529,15 +3533,18 @@ class AdjointGenerator
3529
3533
Value *args[1 ] = {gutils->getNewFromOriginal (orig_ops[0 ])};
3530
3534
Type *tys[] = {orig_ops[0 ]->getType ()};
3531
3535
3532
- Function *SqrtF;
3533
- if (ID == Intrinsic::sqrt)
3534
- SqrtF = Intrinsic::getDeclaration (M, ID, tys);
3535
- else
3536
- SqrtF = Intrinsic::getDeclaration (M, ID);
3536
+ auto &CI = cast<CallInst>(I);
3537
+ #if LLVM_VERSION_MAJOR >= 11
3538
+ auto *SqrtF = CI.getCalledOperand ();
3539
+ #else
3540
+ auto *SqrtF = CI.getCalledValue ();
3541
+ #endif
3542
+ assert (SqrtF);
3543
+ auto FT = cast<FunctionType>(SqrtF->getType ()->getPointerElementType ());
3537
3544
3538
3545
auto rule = [&](Value *op) {
3539
- CallInst *cal = cast<CallInst>(Builder2.CreateCall (SqrtF, args));
3540
- cal->setCallingConv (SqrtF-> getCallingConv ());
3546
+ CallInst *cal = cast<CallInst>(Builder2.CreateCall (FT, SqrtF, args));
3547
+ cal->setCallingConv (CI. getCallingConv ());
3541
3548
cal->setDebugLoc (gutils->getNewFromOriginal (I.getDebugLoc ()));
3542
3549
3543
3550
Value *half = ConstantFP::get (orig_ops[0 ]->getType (), 0.5 );
0 commit comments