-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Try to improve literal types #998
Conversation
clang-tidy review says "All clean, LGTM! 👍" |
@@ -1008,8 +1008,11 @@ StmtDiff BaseForwardModeVisitor::VisitDeclRefExpr(const DeclRefExpr* DRE) { | |||
// If DRE is of type pointer, then the derivative is a null pointer. | |||
if (clonedDRE->getType()->isPointerType()) | |||
return StmtDiff(clonedDRE, nullptr); | |||
QualType literalTy = utils::GetValueType(clonedDRE->getType()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should extend visitorbase::getZeroInit as discussed here #989 (comment)
cc: @gojakuch
This pull request, if the review comment is addressed, should fix #1001. |
The cuda bug was a result of not handling the enum types correctly. I fixed that part in |
Can you push to this PR? |
clang-tidy review says "All clean, LGTM! 👍" |
Sure, but I have no permissions in Vaibhav's repo, @vaithak could you change it temporarily(till this PR is merged)? |
If you accept my invite you should be able to push to this PR. |
clang-tidy review says "All clean, LGTM! 👍" |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #998 +/- ##
==========================================
- Coverage 94.41% 94.40% -0.02%
==========================================
Files 55 55
Lines 8410 8430 +20
==========================================
+ Hits 7940 7958 +18
- Misses 470 472 +2
... and 1 file with indirect coverage changes
|
clang-tidy review says "All clean, LGTM! 👍" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy made some suggestions
lib/Differentiator/VisitorBase.cpp
Outdated
ExprResult Zero = | ||
ConstantFolder::synthesizeLiteral(m_Context.IntTy, m_Context, 0); | ||
else if (T->isScalarType() && !T->isPointerType()) { | ||
ExprResult Zero = ConstantFolder::synthesizeLiteral(T, m_Context, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: argument comment missing for literal argument 'val' [bugprone-argument-comment]
ExprResult Zero = ConstantFolder::synthesizeLiteral(T, m_Context, 0);
^
this fix will not be applied because it overlaps with another fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy made some suggestions
lib/Differentiator/VisitorBase.cpp
Outdated
ExprResult Zero = | ||
ConstantFolder::synthesizeLiteral(m_Context.IntTy, m_Context, 0); | ||
if (T->isScalarType() && !T->isPointerType()) { | ||
ExprResult Zero = ConstantFolder::synthesizeLiteral(T, m_Context, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: argument comment missing for literal argument 'val' [bugprone-argument-comment]
ExprResult Zero = ConstantFolder::synthesizeLiteral(T, m_Context, 0); | |
ExprResult Zero = ConstantFolder::synthesizeLiteral(T, m_Context, /*val=*/0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy made some suggestions
@@ -128,14 +134,18 @@ namespace clad { | |||
uint64_t val) { | |||
//SourceLocation noLoc; | |||
Expr* Result = 0; | |||
if (QT->isIntegralType(C)) { | |||
if (QT->isBooleanType()) { | |||
printf("synthesizing boolean literal\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: do not call c-style vararg functions [cppcoreguidelines-pro-type-vararg]
printf("synthesizing boolean literal\n");
^
llvm::APFloat APVal(C.getFloatTypeSemantics(QT), val); | ||
Result = clad::synthesizeLiteral(QT, C, APVal); | ||
} else { | ||
Result = ConstantFolder::synthesizeLiteral(C.IntTy, C, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: argument comment missing for literal argument 'val' [bugprone-argument-comment]
Result = ConstantFolder::synthesizeLiteral(C.IntTy, C, 0); | |
Result = ConstantFolder::synthesizeLiteral(C.IntTy, C, /*val=*/0); |
clang-tidy review says "All clean, LGTM! 👍" |
This reverts commit 2e6b9d0.
clang-tidy review says "All clean, LGTM! 👍" |
@@ -1070,8 +1070,11 @@ StmtDiff BaseForwardModeVisitor::VisitDeclRefExpr(const DeclRefExpr* DRE) { | |||
// If DRE is of type pointer, then the derivative is a null pointer. | |||
if (clonedDRE->getType()->isPointerType()) | |||
return StmtDiff(clonedDRE, nullptr); | |||
QualType literalTy = utils::GetValueType(clonedDRE->getType()); | |||
if (!literalTy->isRealType()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this special check here?
if (!literalTy->isRealType()) | ||
literalTy = m_Context.IntTy; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should not need this. This gets handled in ConstantFolder::synthesizeLiteral
anyways.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, it was a leftover from Vaibhav's PR. I will remove these lines.
lib/Differentiator/VisitorBase.cpp
Outdated
@@ -379,11 +379,10 @@ namespace clad { | |||
// FIXME: Consolidate other uses of synthesizeLiteral for creation 0 or 1. | |||
if (T->isVoidType()) | |||
return nullptr; | |||
if (T->isScalarType()) { | |||
if (T->isScalarType() && !T->isPointerType()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this here? Shouldn't ConstantFolder::synthesizeLiteral
check if T is a pointer type and synthesize nullptr
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now, the pointers are initialized as an empty list, which is equivalent to nullptr
, the same way clad tapes are initialized. I can alter them to be equal to nullptr
if that's safer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that'd be more readable, too.
clang-tidy review says "All clean, LGTM! 👍" |
clang-tidy review says "All clean, LGTM! 👍" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are almost there. See this one comment.
CastKind CK = m_Sema.PrepareScalarCast(Zero, T); | ||
return m_Sema.ImpCastExprToType(Zero.get(), T, CK).get(); | ||
ConstantFolder::synthesizeLiteral(T, m_Context, /*val=*/0); | ||
return Zero.get(); | ||
} | ||
return m_Sema.ActOnInitList(noLoc, {}, noLoc).get(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably sink ActOnInitList
into synthesizeLiteral
but let's do it outside of this pr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes sense to be in getZeroInit
as we initialize with an empty list, while synthesizeLiteral is used in other places as well
test/Gradient/FunctionCalls.C
Outdated
// CHECK-NEXT: double _r0 = 0; | ||
// CHECK-NEXT: char _r1 = 0; | ||
// CHECK-NEXT: double _r0 = 0.; | ||
// CHECK-NEXT: char _r1 = 0i8; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That will fail to compile I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes indeed, fixed
// CHECK-NEXT: {{.*}}class_functions::operator_subscript_pullback(&_t26, 0, _r_d6, &_d_vec, &_r10); | ||
// CHECK-NEXT: {{.*}} _r11 = 0; | ||
// CHECK-NEXT: size_type _r11 = {{0U|0UL}}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That will not compile. We probably mean std::vector<...>::size_type
. I do not think that's a problem for this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll open an issue
clang-tidy review says "All clean, LGTM! 👍" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
This is related to the review comments of PR #975.