Skip to content
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

Lambda support in the reverse mode #1126

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions include/clad/Differentiator/Compatibility.h
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,16 @@ getConstantArrayType(const ASTContext& Ctx, QualType EltTy,
#define CLAD_COMPAT_CLANG15_Declarator_DeclarationAttrs_ExtraParam clang::ParsedAttributesView::none(),
#endif

#if CLANG_VERSION_MAJOR > 12
#define CLAD_COMPAT_CXXRecordDecl_CreateLambda_DependencyKind( \
LAMBDACXXRECORDDECL) \
LAMBDACXXRECORDDECL->getLambdaDependencyKind()
#else
#define CLAD_COMPAT_CXXRecordDecl_CreateLambda_DependencyKind( \
LAMBDACXXRECORDDECL) \
LAMBDACXXRECORDDECL->isDependentLambda()
#endif

// Clang 12 add one extra param (FPO) that we get from Node in Create method of:
// ImplicitCastExpr, CStyleCastExpr, CXXStaticCastExpr and CXXFunctionalCastExpr

Expand Down
6 changes: 6 additions & 0 deletions include/clad/Differentiator/ReverseModeVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,11 @@ namespace clad {
llvm::SmallVectorImpl<clang::Expr*>& args,
llvm::SmallVectorImpl<clang::Expr*>& outputArgs);

clang::CXXRecordDecl*
diffLambdaCXXRecordDecl(const clang::CXXRecordDecl* Original);
clang::CXXMethodDecl*
DifferentiateCallOperatorIfLambda(const clang::CXXRecordDecl* RD);

public:
ReverseModeVisitor(DerivativeBuilder& builder, const DiffRequest& request);
virtual ~ReverseModeVisitor();
Expand All @@ -375,6 +380,7 @@ namespace clad {
DerivativeAndOverload DerivePullback();
StmtDiff VisitArraySubscriptExpr(const clang::ArraySubscriptExpr* ASE);
StmtDiff VisitBinaryOperator(const clang::BinaryOperator* BinOp);
StmtDiff VisitLambdaExpr(const clang::LambdaExpr* LE);
StmtDiff VisitCallExpr(const clang::CallExpr* CE);
virtual StmtDiff VisitCompoundStmt(const clang::CompoundStmt* CS);
StmtDiff VisitConditionalOperator(const clang::ConditionalOperator* CO);
Expand Down
6 changes: 3 additions & 3 deletions include/clad/Differentiator/VisitorBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ namespace clad {
clang::Scope* scope, clang::Expr* Init = nullptr,
bool DirectInit = false, clang::TypeSourceInfo* TSI = nullptr,
clang::VarDecl::InitializationStyle IS =
clang::VarDecl::InitializationStyle::CInit);
clang::VarDecl::InitializationStyle::CInit, bool pushCodeSynthCtxt = false);
/// Builds variable declaration to be used inside the derivative
/// body.
/// \param[in] Type The type of variable declaration to build.
Expand All @@ -310,7 +310,7 @@ namespace clad {
clang::Expr* Init = nullptr, bool DirectInit = false,
clang::TypeSourceInfo* TSI = nullptr,
clang::VarDecl::InitializationStyle IS =
clang::VarDecl::InitializationStyle::CInit);
clang::VarDecl::InitializationStyle::CInit, bool pushCodeSynthCtxt = false);
/// Builds variable declaration to be used inside the derivative
/// body.
/// \param[in] Type The type of variable declaration to build.
Expand All @@ -326,7 +326,7 @@ namespace clad {
clang::Expr* Init = nullptr, bool DirectInit = false,
clang::TypeSourceInfo* TSI = nullptr,
clang::VarDecl::InitializationStyle IS =
clang::VarDecl::InitializationStyle::CInit);
clang::VarDecl::InitializationStyle::CInit, bool pushCodeSynthCtxt = false);
/// Builds variable declaration to be used inside the derivative
/// body in the derivative function global scope.
clang::VarDecl*
Expand Down
Loading