Skip to content

Commit

Permalink
Remove the redundant function arguments which are accessible in the c…
Browse files Browse the repository at this point in the history
…lass.
  • Loading branch information
vgvassilev committed Aug 22, 2023
1 parent da6a306 commit c0e0ac6
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 41 deletions.
3 changes: 2 additions & 1 deletion include/clad/Differentiator/Compatibility.h
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,8 @@ static inline QualType getConstantArrayType(const ASTContext &Ctx,
#if CLANG_VERSION_MAJOR < 10
#define CLAD_COMPAT_CLANG10_FunctionDecl_Create_ExtraParams(x) /**/
#elif CLANG_VERSION_MAJOR >= 10
#define CLAD_COMPAT_CLANG10_FunctionDecl_Create_ExtraParams(x) ,((x)?VD.Clone((x)):nullptr)
#define CLAD_COMPAT_CLANG10_FunctionDecl_Create_ExtraParams(x) \
, ((x) ? VB.Clone((x)) : nullptr)
#endif

// Clang 10 remove GetTemporaryExpr(). Use getSubExpr() instead
Expand Down
2 changes: 0 additions & 2 deletions include/clad/Differentiator/DerivativeBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ namespace clad {
m_ErrorEstHandler;
DeclWithContext cloneFunction(const clang::FunctionDecl* FD,
clad::VisitorBase& VB, clang::DeclContext* DC,
clang::Sema& m_Sema,
clang::ASTContext& m_Context,
clang::SourceLocation& noLoc,
clang::DeclarationNameInfo name,
clang::QualType functionType);
Expand Down
4 changes: 2 additions & 2 deletions lib/Differentiator/BaseForwardModeVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ BaseForwardModeVisitor::Derive(const FunctionDecl* FD,
llvm::SaveAndRestore<Scope*> SaveScope(m_CurScope);
DeclContext* DC = const_cast<DeclContext*>(m_Function->getDeclContext());
m_Sema.CurContext = DC;
DeclWithContext result = m_Builder.cloneFunction(
FD, *this, DC, m_Sema, m_Context, loc, name, FD->getType());
DeclWithContext result =
m_Builder.cloneFunction(FD, *this, DC, loc, name, FD->getType());
FunctionDecl* derivedFD = result.first;
m_Derivative = derivedFD;

Expand Down
5 changes: 2 additions & 3 deletions lib/Differentiator/DerivativeBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,8 @@ namespace clad {

DeclWithContext DerivativeBuilder::cloneFunction(
const clang::FunctionDecl* FD, clad::VisitorBase& VB,
clang::DeclContext* DC, clang::Sema& m_Sema, clang::ASTContext& m_Context,
clang::SourceLocation& noLoc, clang::DeclarationNameInfo name,
clang::QualType functionType) {
clang::DeclContext* DC, clang::SourceLocation& noLoc,
clang::DeclarationNameInfo name, clang::QualType functionType) {
FunctionDecl* returnedFD = nullptr;
NamespaceDecl* enclosingNS = nullptr;
if (isa<CXXMethodDecl>(FD)) {
Expand Down
5 changes: 2 additions & 3 deletions lib/Differentiator/ForwardModeVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,8 @@ clang::QualType ForwardModeVisitor::ComputePushforwardFnReturnType() {
DeclContext* DC = const_cast<DeclContext*>(m_Function->getDeclContext());
m_Sema.CurContext = DC;

DeclWithContext cloneFunctionResult =
m_Builder.cloneFunction(m_Function, *this, DC, m_Sema, m_Context, noLoc,
derivedFnName, derivedFnType);
DeclWithContext cloneFunctionResult = m_Builder.cloneFunction(
m_Function, *this, DC, noLoc, derivedFnName, derivedFnType);
m_Derivative = cloneFunctionResult.first;

llvm::SmallVector<ParmVarDecl*, 16> params;
Expand Down
10 changes: 2 additions & 8 deletions lib/Differentiator/HessianModeVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,8 @@ namespace clad {
llvm::SaveAndRestore<Scope*> SaveScope(m_CurScope);
m_Sema.CurContext = DC;

DeclWithContext result = m_Builder.cloneFunction(m_Function,
*this,
DC,
m_Sema,
m_Context,
noLoc,
name,
hessianFunctionType);
DeclWithContext result = m_Builder.cloneFunction(
m_Function, *this, DC, noLoc, name, hessianFunctionType);
FunctionDecl* hessianFD = result.first;

beginScope(Scope::FunctionPrototypeScope | Scope::FunctionDeclarationScope |
Expand Down
7 changes: 3 additions & 4 deletions lib/Differentiator/ReverseModeForwPassVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ ReverseModeForwPassVisitor::Derive(const FunctionDecl* FD,
m_Function
->getDeclContext()); // NOLINT(cppcoreguidelines-pro-type-const-cast)

DeclWithContext fnBuildRes =
m_Builder.cloneFunction(m_Function, *this, m_Sema.CurContext, m_Sema,
m_Context, noLoc, fnDNI, fnType);
DeclWithContext fnBuildRes = m_Builder.cloneFunction(
m_Function, *this, m_Sema.CurContext, noLoc, fnDNI, fnType);
m_Derivative = fnBuildRes.first;

beginScope(Scope::FunctionPrototypeScope | Scope::FunctionDeclarationScope |
Expand Down Expand Up @@ -276,4 +275,4 @@ ReverseModeForwPassVisitor::VisitReturnStmt(const clang::ReturnStmt* RS) {
Stmt* newRS = m_Sema.BuildReturnStmt(noLoc, returnInitList).get();
return {newRS};
}
} // namespace clad
} // namespace clad
19 changes: 6 additions & 13 deletions lib/Differentiator/ReverseModeVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context,
DeclContext* DC = const_cast<DeclContext*>(m_Function->getDeclContext());
m_Sema.CurContext = DC;
DeclWithContext gradientOverloadFDWC =
m_Builder.cloneFunction(m_Function, *this, DC, m_Sema, m_Context, noLoc,
gradientNameInfo, gradientFunctionOverloadType);
m_Builder.cloneFunction(m_Function, *this, DC, noLoc, gradientNameInfo,
gradientFunctionOverloadType);
FunctionDecl* gradientOverloadFD = gradientOverloadFDWC.first;

beginScope(Scope::FunctionPrototypeScope | Scope::FunctionDeclarationScope |
Expand Down Expand Up @@ -353,14 +353,8 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context,
llvm::SaveAndRestore<Scope*> SaveScope(m_CurScope);
DeclContext* DC = const_cast<DeclContext*>(m_Function->getDeclContext());
m_Sema.CurContext = DC;
DeclWithContext result = m_Builder.cloneFunction(m_Function,
*this,
DC,
m_Sema,
m_Context,
noLoc,
name,
gradientFunctionType);
DeclWithContext result = m_Builder.cloneFunction(
m_Function, *this, DC, noLoc, name, gradientFunctionType);
FunctionDecl* gradientFD = result.first;
m_Derivative = gradientFD;

Expand Down Expand Up @@ -492,9 +486,8 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context,
llvm::SaveAndRestore<Scope*> saveScope(m_CurScope);
m_Sema.CurContext = const_cast<DeclContext*>(m_Function->getDeclContext());

DeclWithContext fnBuildRes =
m_Builder.cloneFunction(m_Function, *this, m_Sema.CurContext, m_Sema,
m_Context, noLoc, DNI, pullbackFnType);
DeclWithContext fnBuildRes = m_Builder.cloneFunction(
m_Function, *this, m_Sema.CurContext, noLoc, DNI, pullbackFnType);
m_Derivative = fnBuildRes.first;

if (m_ExternalSource)
Expand Down
9 changes: 4 additions & 5 deletions lib/Differentiator/VectorForwardModeVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ VectorForwardModeVisitor::DeriveVectorMode(const FunctionDecl* FD,
// Create the function declaration for the derivative.
DeclContext* DC = const_cast<DeclContext*>(m_Function->getDeclContext());
m_Sema.CurContext = DC;
DeclWithContext result =
m_Builder.cloneFunction(m_Function, *this, DC, m_Sema, m_Context, loc,
name, vectorDiffFunctionType);
DeclWithContext result = m_Builder.cloneFunction(
m_Function, *this, DC, loc, name, vectorDiffFunctionType);
FunctionDecl* vectorDiffFD = result.first;
m_Derivative = vectorDiffFD;

Expand Down Expand Up @@ -251,8 +250,8 @@ clang::FunctionDecl* VectorForwardModeVisitor::CreateVectorModeOverload() {
auto* DC = const_cast<DeclContext*>(m_Function->getDeclContext());
m_Sema.CurContext = DC;
DeclWithContext result =
m_Builder.cloneFunction(m_Function, *this, DC, m_Sema, m_Context, noLoc,
vectorModeNameInfo, vectorModeFuncOverloadType);
m_Builder.cloneFunction(m_Function, *this, DC, noLoc, vectorModeNameInfo,
vectorModeFuncOverloadType);
FunctionDecl* vectorModeOverloadFD = result.first;

// Function declaration scope
Expand Down

0 comments on commit c0e0ac6

Please sign in to comment.