Skip to content

Commit

Permalink
fix storing for increments
Browse files Browse the repository at this point in the history
  • Loading branch information
PetroZarytskyi committed Aug 15, 2023
1 parent d725fe9 commit b11ccab
Showing 1 changed file with 9 additions and 29 deletions.
38 changes: 9 additions & 29 deletions lib/Differentiator/ReverseModeVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1272,16 +1272,10 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context,
llvm::SmallVector<Expr*, 4> reverseIndices(Indices.size());
llvm::SmallVector<Expr*, 4> forwSweepDerivativeIndices(Indices.size());
for (std::size_t i = 0; i < Indices.size(); i++) {
/// FIXME: Remove redundant indices vectors.
StmtDiff IdxDiff = Visit(Indices[i]);
auto idxStored = GlobalStoreAndRef(IdxDiff.getExpr(), "_t", /*force=*/true);
clonedIndices[i] = idxStored.getExpr();
reverseIndices[i] = idxStored.getExpr_dx();
if (isInsideLoop) {
auto forwIndex = StoreAndRef(idxStored.getExpr(), direction::forward);
auto revIndex = StoreAndRef(idxStored.getExpr_dx(), direction::essential_reverse, "_r");
clonedIndices[i] = forwIndex;
reverseIndices[i] = revIndex;
}
clonedIndices[i] = IdxDiff.getExpr();
reverseIndices[i] = IdxDiff.getExpr();
// reverseIndices[i] = Clone(IdxDiff.getExpr());
forwSweepDerivativeIndices[i] = IdxDiff.getExpr();
}
Expand Down Expand Up @@ -1932,26 +1926,26 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context,
auto d = BuildOp(UO_Minus, dfdx());
diff = Visit(E, d);
} else if (opCode == UO_PostInc || opCode == UO_PostDec) {
auto EStored = GlobalStoreAndRef(E);
diff = Visit(E, dfdx());
auto EStored = GlobalStoreAndRef(diff.getExpr());
auto assign =
BuildOp(BinaryOperatorKind::BO_Assign, E, EStored.getExpr_dx());
BuildOp(BinaryOperatorKind::BO_Assign, diff.getExpr(), EStored.getExpr_dx());
if (isInsideLoop)
addToCurrentBlock(EStored.getExpr(), direction::forward);
addToCurrentBlock(assign, direction::reverse);

diff = Visit(E, dfdx());
ResultRef = diff.getExpr_dx();
if (m_ExternalSource)
m_ExternalSource->ActBeforeFinalisingPostIncDecOp(diff);
} else if (opCode == UO_PreInc || opCode == UO_PreDec) {
auto EStored = GlobalStoreAndRef(E);
diff = Visit(E, dfdx());
auto EStored = GlobalStoreAndRef(diff.getExpr());
auto assign =
BuildOp(BinaryOperatorKind::BO_Assign, E, EStored.getExpr_dx());
BuildOp(BinaryOperatorKind::BO_Assign, diff.getExpr(), EStored.getExpr_dx());
if (isInsideLoop)
addToCurrentBlock(EStored.getExpr(), direction::forward);
addToCurrentBlock(assign, direction::reverse);

diff = Visit(E, dfdx());
} else if (opCode == UnaryOperatorKind::UO_Real ||
opCode == UnaryOperatorKind::UO_Imag) {
diff = VisitWithExplicitNoDfDx(E);
Expand Down Expand Up @@ -2237,10 +2231,7 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context,
Lblock_begin = std::next(Lblock_begin);
}

// llvm::errs()<<"Dumping return_exprs:\n";
for (auto E : return_exprs) {
// E->dumpColor();
// llvm::errs()<<"\n";
Lstored = GlobalStoreAndRef(E);
if (Lstored.getExpr() != E) {
auto assign =
Expand All @@ -2250,17 +2241,6 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context,
addToCurrentBlock(assign, direction::reverse);
}
}
// Lstored = GlobalStoreAndRef(L, "_t", /*force=*/true);
// // auto line =
// m_Context.getSourceManager().getPresumedLoc(L->getBeginLoc()).getLine();
// // auto column =
// m_Context.getSourceManager().getPresumedLoc(L->getBeginLoc()).getColumn();
// // llvm::errs() << line << "|" <<column << "?\n";
// auto assign = BuildOp(BinaryOperatorKind::BO_Assign, L,
// Lstored.getExpr_dx()); if (isInsideLoop) {
// addToCurrentBlock(Lstored.getExpr(), direction::forward);
// }
// addToCurrentBlock(assign, direction::reverse);

if (m_ExternalSource)
m_ExternalSource->ActAfterCloningLHSOfAssignOp(LCloned, R, opCode);
Expand Down

0 comments on commit b11ccab

Please sign in to comment.