Skip to content

Commit 0d40ec5

Browse files
committed
Fix byval
1 parent 33bee0d commit 0d40ec5

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

enzyme/Enzyme/Enzyme.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ class Enzyme : public ModulePass {
147147
bool AtomicAdd = Arch == Triple::nvptx || Arch == Triple::nvptx64 ||
148148
Arch == Triple::amdgcn;
149149

150+
std::map<int, Type*> byVal;
150151
for (unsigned i = 1; i < CI->getNumArgOperands(); ++i) {
151152
Value *res = CI->getArgOperand(i);
152153

@@ -357,7 +358,9 @@ class Enzyme : public ModulePass {
357358
}
358359
res = Builder.CreateBitCast(res, PTy);
359360
}
360-
361+
if (CI->isByValArgument(i)) {
362+
byVal[args.size()] = CI->getParamByValType(i);
363+
}
361364
args.push_back(res);
362365
if (ty == DIFFE_TYPE::DUP_ARG || ty == DIFFE_TYPE::DUP_NONEED) {
363366
++i;
@@ -476,6 +479,9 @@ class Enzyme : public ModulePass {
476479
CallInst *diffret = cast<CallInst>(Builder.CreateCall(newFunc, args));
477480
diffret->setCallingConv(CI->getCallingConv());
478481
diffret->setDebugLoc(CI->getDebugLoc());
482+
for (auto pair : byVal) {
483+
diffret->addParamAttr(pair.first, Attribute::getWithByValType(diffret->getContext(), pair.second));
484+
}
479485

480486
if (!diffret->getType()->isEmptyTy() && !diffret->getType()->isVoidTy()) {
481487
unsigned idxs[] = {0};

0 commit comments

Comments
 (0)