Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Andriychuk authored and Max Andriychuk committed Sep 10, 2024
1 parent 811a883 commit 3849b66
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
18 changes: 9 additions & 9 deletions lib/Differentiator/ActivityAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,13 @@ void VariedAnalyzer::AnalyzeCFGBlock(const CFGBlock& block) {

merge(succData.get(), m_BlockData[block.getBlockID()].get());
}
// FIXME: Information about the varied variables is stored in the last block, so we should be able to get it form there
// FIXME: Information about the varied variables is stored in the last block,
// so we should be able to get it form there
for (const VarDecl* i : *m_BlockData[block.getBlockID()])
m_VariedDecls.insert(i);
}

bool VariedAnalyzer::isVaried(const VarDecl* VD) const{
bool VariedAnalyzer::isVaried(const VarDecl* VD) const {
const VarsData& curBranch = getCurBlockVarsData();
return curBranch.find(VD) != curBranch.end();
}
Expand Down Expand Up @@ -113,21 +114,21 @@ bool VariedAnalyzer::VisitConditionalOperator(ConditionalOperator* CO) {
}

bool VariedAnalyzer::VisitCallExpr(CallExpr* CE) {
FunctionDecl* FD = CE->getDirectCallee();
FunctionDecl* FD = CE->getDirectCallee();
bool noHiddenParam = (CE->getNumArgs() == FD->getNumParams());
std::set<const clang::VarDecl*> variedParam;
if(noHiddenParam){
MutableArrayRef<ParmVarDecl *> FDparam = FD->parameters();
for (std::size_t i = 0, e = CE->getNumArgs(); i != e; ++i){
if (noHiddenParam) {
MutableArrayRef<ParmVarDecl*> FDparam = FD->parameters();
for (std::size_t i = 0, e = CE->getNumArgs(); i != e; ++i) {
clang::Expr* par = CE->getArg(i);
TraverseStmt(par);
if(m_Varied){
if (m_Varied) {
m_VariedDecls.insert(FDparam[i]);
m_Varied = false;
}
}
}
return true;
return true;
}

bool VariedAnalyzer::VisitDeclStmt(DeclStmt* DS) {
Expand Down Expand Up @@ -163,4 +164,3 @@ bool VariedAnalyzer::VisitDeclRefExpr(DeclRefExpr* DRE) {
return true;
}
} // namespace clad

14 changes: 8 additions & 6 deletions lib/Differentiator/ActivityAnalyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@
#include "clad/Differentiator/Compatibility.h"

#include <algorithm>
#include <utility>
#include <iterator>
#include <memory>
#include <set>
#include <unordered_map>
#include <utility>
/// @brief Class that implemets Varied part of the Activity analysis.
/// By performing static data-flow analysis, so called Varied variables
/// are determined, meaning variables that depend on input parameters
/// in a differentiable way. That result enables us to remove redundant
/// By performing static data-flow analysis, so called Varied variables
/// are determined, meaning variables that depend on input parameters
/// in a differentiable way. That result enables us to remove redundant
/// statements in the reverse mode, improving generated codes efficiency.
namespace clad {
class VariedAnalyzer : public clang::RecursiveASTVisitor<VariedAnalyzer> {
Expand Down Expand Up @@ -45,12 +44,15 @@ class VariedAnalyzer : public clang::RecursiveASTVisitor<VariedAnalyzer> {
bool isVaried(const clang::VarDecl* VD) const;
void copyVarToCurBlock(const clang::VarDecl* VD);
VarsData& getCurBlockVarsData() { return *m_BlockData[m_CurBlockID]; }
const VarsData& getCurBlockVarsData() const { return const_cast<VariedAnalyzer*>(this)->getCurBlockVarsData();}
const VarsData& getCurBlockVarsData() const {
return const_cast<VariedAnalyzer*>(this)->getCurBlockVarsData();
}
void AnalyzeCFGBlock(const clang::CFGBlock& block);

public:
/// Constructor
VariedAnalyzer(clang::ASTContext& Context, std::set<const clang::VarDecl*>& Decls)
VariedAnalyzer(clang::ASTContext& Context,
std::set<const clang::VarDecl*>& Decls)
: m_VariedDecls(Decls), m_Context(Context) {}

/// Destructor
Expand Down

0 comments on commit 3849b66

Please sign in to comment.