Skip to content

Commit

Permalink
Improve no return index error (#2040)
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmoses authored Aug 11, 2024
1 parent 5acac24 commit 0367300
Showing 1 changed file with 34 additions and 11 deletions.
45 changes: 34 additions & 11 deletions enzyme/Enzyme/AdjointGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -5658,18 +5658,41 @@ class AdjointGenerator : public llvm::InstVisitor<AdjointGenerator> {
if (Mode == DerivativeMode::ReverseModeCombined ||
Mode == DerivativeMode::ReverseModePrimal) {

auto drval = *differetIdx;
newip = (drval < 0)
? augmentcall
: BuilderZ.CreateExtractValue(augmentcall,
{(unsigned)drval},
call.getName() + "'ac");
assert(newip->getType() == placeholder->getType());
placeholder->replaceAllUsesWith(newip);
if (placeholder == &*BuilderZ.GetInsertPoint()) {
BuilderZ.SetInsertPoint(placeholder->getNextNode());
if (!differetIdx) {
std::string str;
raw_string_ostream ss(str);
ss << "Did not have return index set when differentiating "
"function\n";
ss << " call" << call << "\n";
ss << " augmentcall" << *augmentcall << "\n";
if (CustomErrorHandler) {
CustomErrorHandler(str.c_str(), wrap(&call),
ErrorType::InternalError, nullptr, nullptr,
nullptr);
} else {
EmitFailure("GetIndexError", call.getDebugLoc(), &call,
ss.str());
}
placeholder->replaceAllUsesWith(
UndefValue::get(placeholder->getType()));
if (placeholder == &*BuilderZ.GetInsertPoint()) {
BuilderZ.SetInsertPoint(placeholder->getNextNode());
}
gutils->erase(placeholder);
} else {
auto drval = *differetIdx;
newip = (drval < 0)
? augmentcall
: BuilderZ.CreateExtractValue(augmentcall,
{(unsigned)drval},
call.getName() + "'ac");
assert(newip->getType() == placeholder->getType());
placeholder->replaceAllUsesWith(newip);
if (placeholder == &*BuilderZ.GetInsertPoint()) {
BuilderZ.SetInsertPoint(placeholder->getNextNode());
}
gutils->erase(placeholder);
}
gutils->erase(placeholder);
} else {
newip = placeholder;
}
Expand Down

0 comments on commit 0367300

Please sign in to comment.