-
Notifications
You must be signed in to change notification settings - Fork 122
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
Rev ref returns #601
Rev ref returns #601
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,7 +77,7 @@ namespace clad { | |
friend class ReverseModeVisitor; | ||
friend class HessianModeVisitor; | ||
friend class JacobianModeVisitor; | ||
|
||
friend class ReverseModeForwPassVisitor; | ||
clang::Sema& m_Sema; | ||
plugin::CladPlugin& m_CladPlugin; | ||
clang::ASTContext& m_Context; | ||
|
@@ -93,9 +93,7 @@ namespace clad { | |
llvm::SmallVector<std::unique_ptr<ErrorEstimationHandler>, 4> | ||
m_ErrorEstHandler; | ||
DeclWithContext cloneFunction(const clang::FunctionDecl* FD, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: function 'clad::DerivativeBuilder::cloneFunction' has a definition with different parameter names [readability-inconsistent-declaration-parameter-name] DeclWithContext cloneFunction(const clang::FunctionDecl* FD,
^ Additional contextlib/Differentiator/DerivativeBuilder.cpp:93: the definition seen here DeclWithContext DerivativeBuilder::cloneFunction(
^ include/clad/Differentiator/DerivativeBuilder.h:94: differing parameters are named here: ('VB'), in definition: ('VD') DeclWithContext cloneFunction(const clang::FunctionDecl* FD,
^ |
||
clad::VisitorBase VB, clang::DeclContext* DC, | ||
clang::Sema& m_Sema, | ||
clang::ASTContext& m_Context, | ||
clad::VisitorBase& VB, clang::DeclContext* DC, | ||
clang::SourceLocation& noLoc, | ||
clang::DeclarationNameInfo name, | ||
clang::QualType functionType); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ enum class DiffMode { | |
reverse, | ||
hessian, | ||
jacobian, | ||
reverse_mode_forward_pass, | ||
error_estimation | ||
}; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#ifndef CLAD_DIFFERENTIATOR_REVERSEMODEFORWPASSVISITOR_H | ||
#define CLAD_DIFFERENTIATOR_REVERSEMODEFORWPASSVISITOR_H | ||
|
||
#include "clad/Differentiator/ParseDiffArgsTypes.h" | ||
#include "clad/Differentiator/ReverseModeVisitor.h" | ||
|
||
#include "clang/AST/StmtVisitor.h" | ||
#include "clang/Sema/Sema.h" | ||
|
||
#include "llvm/ADT/SmallVector.h" | ||
|
||
namespace clad { | ||
class ReverseModeForwPassVisitor : public ReverseModeVisitor { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: destructor of 'ReverseModeForwPassVisitor' is public and non-virtual [cppcoreguidelines-virtual-class-destructor] class ReverseModeForwPassVisitor : public ReverseModeVisitor {
^ Additional contextinclude/clad/Differentiator/ReverseModeForwPassVisitor.h:12: make it public and virtual class ReverseModeForwPassVisitor : public ReverseModeVisitor {
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Likewise. |
||
private: | ||
Stmts m_Globals; | ||
|
||
llvm::SmallVector<clang::QualType, 8> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: 8 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers] llvm::SmallVector<clang::QualType, 8>
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should be able to suppress these by adding |
||
ComputeParamTypes(const DiffParams& diffParams); | ||
clang::QualType ComputeReturnType(); | ||
llvm::SmallVector<clang::ParmVarDecl*, 8> BuildParams(DiffParams& diffParams); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: 8 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers] llvm::SmallVector<clang::ParmVarDecl*, 8> BuildParams(DiffParams& diffParams);
^ |
||
clang::QualType GetParameterDerivativeType(clang::QualType yType, | ||
clang::QualType xType); | ||
|
||
public: | ||
ReverseModeForwPassVisitor(DerivativeBuilder& builder); | ||
DerivativeAndOverload Derive(const clang::FunctionDecl* FD, | ||
const DiffRequest& request); | ||
|
||
StmtDiff ProcessSingleStmt(const clang::Stmt* S); | ||
StmtDiff VisitCompoundStmt(const clang::CompoundStmt* CS) override; | ||
StmtDiff VisitDeclRefExpr(const clang::DeclRefExpr* DRE) override; | ||
StmtDiff VisitReturnStmt(const clang::ReturnStmt* RS) override; | ||
}; | ||
} // namespace clad | ||
|
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
#include "clad/Differentiator/ForwardModeVisitor.h" | ||
#include "clad/Differentiator/HessianModeVisitor.h" | ||
#include "clad/Differentiator/JacobianModeVisitor.h" | ||
#include "clad/Differentiator/ReverseModeForwPassVisitor.h" | ||
#include "clad/Differentiator/ReverseModeVisitor.h" | ||
#include "clad/Differentiator/StmtClone.h" | ||
#include "clad/Differentiator/VectorForwardModeVisitor.h" | ||
|
@@ -88,15 +89,10 @@ namespace clad { | |
return false; | ||
} | ||
|
||
DeclWithContext | ||
DerivativeBuilder::cloneFunction(const clang::FunctionDecl* FD, | ||
clad::VisitorBase VD, | ||
clang::DeclContext* DC, | ||
clang::Sema& m_Sema, | ||
clang::ASTContext& m_Context, | ||
clang::SourceLocation& noLoc, | ||
clang::DeclarationNameInfo name, | ||
clang::QualType functionType) { | ||
DeclWithContext DerivativeBuilder::cloneFunction( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: method 'cloneFunction' can be made static [readability-convert-member-functions-to-static] include/clad/Differentiator/DerivativeBuilder.h:94: - DeclWithContext cloneFunction(const clang::FunctionDecl* FD,
+ static DeclWithContext cloneFunction(const clang::FunctionDecl* FD, |
||
const clang::FunctionDecl* FD, clad::VisitorBase& VB, | ||
clang::DeclContext* DC, clang::SourceLocation& noLoc, | ||
clang::DeclarationNameInfo name, clang::QualType functionType) { | ||
FunctionDecl* returnedFD = nullptr; | ||
NamespaceDecl* enclosingNS = nullptr; | ||
if (isa<CXXMethodDecl>(FD)) { | ||
|
@@ -115,7 +111,7 @@ namespace clad { | |
returnedFD->setAccess(FD->getAccess()); | ||
} else { | ||
assert (isa<FunctionDecl>(FD) && "Unexpected!"); | ||
enclosingNS = VD.RebuildEnclosingNamespaces(DC); | ||
enclosingNS = VB.RebuildEnclosingNamespaces(DC); | ||
returnedFD = FunctionDecl::Create(m_Context, | ||
m_Sema.CurContext, | ||
noLoc, | ||
|
@@ -230,6 +226,9 @@ namespace clad { | |
result = V.DerivePullback(FD, request); | ||
if (!m_ErrorEstHandler.empty()) | ||
CleanupErrorEstimation(m_ErrorEstHandler, m_EstModel); | ||
} else if (request.Mode == DiffMode::reverse_mode_forward_pass) { | ||
ReverseModeForwPassVisitor V(*this); | ||
result = V.Derive(FD, request); | ||
} else if (request.Mode == DiffMode::hessian) { | ||
HessianModeVisitor H(*this); | ||
result = H.Derive(FD, request); | ||
|
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: function-like macro 'CLAD_COMPAT_CLANG10_FunctionDecl_Create_ExtraParams' used; consider a 'constexpr' template function [cppcoreguidelines-macro-usage]