Skip to content

Commit 922a9d2

Browse files
PetroZarytskyivgvassilev
authored andcommitted
Move special real const array initialization to RMV::DifferentiateVarDecl
1 parent 54eda64 commit 922a9d2

File tree

1 file changed

+8
-22
lines changed

1 file changed

+8
-22
lines changed

lib/Differentiator/ReverseModeVisitor.cpp

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,17 +1388,6 @@ Expr* ReverseModeVisitor::getStdInitListSizeExpr(const Expr* E) {
13881388
QualType ILEType = ILE->getType();
13891389
llvm::SmallVector<Expr*, 16> clonedExprs(ILE->getNumInits());
13901390
llvm::SmallVector<Expr*, 16> exprsDiff(ILE->getNumInits());
1391-
bool isRealConstArray = false;
1392-
if (const auto* arrType = dyn_cast<ConstantArrayType>(ILEType)) {
1393-
QualType elemTy = arrType->getElementType();
1394-
if (elemTy->isRealType()) {
1395-
isRealConstArray = true;
1396-
exprsDiff.resize(1);
1397-
Expr* zero = ConstantFolder::synthesizeLiteral(m_Context.IntTy,
1398-
m_Context, /*val=*/0);
1399-
exprsDiff[0] = zero;
1400-
}
1401-
}
14021391
for (unsigned i = 0, e = ILE->getNumInits(); i < e; i++) {
14031392
Expr* I =
14041393
ConstantFolder::synthesizeLiteral(m_Context.IntTy, m_Context, i);
@@ -1418,12 +1407,10 @@ Expr* ReverseModeVisitor::getStdInitListSizeExpr(const Expr* E) {
14181407
}
14191408
StmtDiff elemDiff = Visit(ILE->getInit(i), elemDfDx);
14201409
clonedExprs[i] = elemDiff.getExpr();
1421-
if (!isRealConstArray) {
1422-
if (elemDiff.getExpr_dx())
1423-
exprsDiff[i] = elemDiff.getExpr_dx();
1424-
else
1425-
exprsDiff[i] = getZeroInit(ILE->getInit(i)->getType());
1426-
}
1410+
if (elemDiff.getExpr_dx())
1411+
exprsDiff[i] = elemDiff.getExpr_dx();
1412+
else
1413+
exprsDiff[i] = getZeroInit(ILE->getInit(i)->getType());
14271414
}
14281415

14291416
Expr* clonedILE = m_Sema.ActOnInitList(noLoc, clonedExprs, noLoc).get();
@@ -3093,14 +3080,13 @@ Expr* ReverseModeVisitor::getStdInitListSizeExpr(const Expr* E) {
30933080
isLambdaDS ? m_Context.getTrivialTypeSourceInfo(VDCloneType, noLoc)
30943081
: nullptr);
30953082
// The choice of isDirectInit is mostly stylistic.
3083+
bool isRealConstArray = false;
3084+
if (const auto* arrType = dyn_cast<ConstantArrayType>(VDType))
3085+
isRealConstArray = arrType->getElementType()->isRealType();
30963086
bool isDirectInit = VD->isDirectInit() && (!RD || isNonAggrClass);
3097-
if (VDDerivedType->isBuiltinType() || !VD->getInit()) {
3087+
if (VDDerivedType->isBuiltinType() || !VD->getInit() || isRealConstArray) {
30983088
initDiff.updateStmtDx(getZeroInit(VDType));
30993089
isDirectInit = false;
3100-
} else if (const auto* arrType = dyn_cast<ConstantArrayType>(VDType)) {
3101-
QualType elemTy = arrType->getElementType();
3102-
if (elemTy->isRealType())
3103-
isDirectInit = false;
31043090
} else if (Expr* size = getStdInitListSizeExpr(VD->getInit())) {
31053091
initDiff.updateStmtDx(Clone(size));
31063092
isConstructInit = true;

0 commit comments

Comments
 (0)