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

[WIP] Add Useful Analysis to the forward mode #1120

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ovdiiuv
Copy link
Collaborator

@ovdiiuv ovdiiuv commented Oct 18, 2024

No description provided.

@ovdiiuv ovdiiuv force-pushed the useful branch 2 times, most recently from 18258de to d7bef62 Compare October 18, 2024 17:25
Copy link
Contributor

@github-actions github-actions bot left a 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

There were too many comments to post at once. Showing the first 10 out of 11. Check the log or trigger a new build to see more.

public:
/// Function to be differentiated.
const clang::FunctionDecl* Function = nullptr;
bool ReqAdj = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: member variable 'ReqAdj' has public visibility [cppcoreguidelines-non-private-member-variables-in-classes]

  bool ReqAdj = true;
       ^

include/clad/Differentiator/DiffPlanner.h Show resolved Hide resolved
@@ -1063,7 +1063,14 @@ 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);

if (auto* i = cast<VarDecl>(DRE->getDecl())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: 'auto *i' can be declared as 'const auto *i' [readability-qualified-auto]

Suggested change
if (auto* i = cast<VarDecl>(DRE->getDecl())) {
if (const auto* i = cast<VarDecl>(DRE->getDecl())) {

@@ -1063,7 +1063,14 @@
// If DRE is of type pointer, then the derivative is a null pointer.
if (clonedDRE->getType()->isPointerType())
return StmtDiff(clonedDRE, nullptr);

if (auto* i = cast<VarDecl>(DRE->getDecl())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: cast<> in conditional will assert rather than return a null pointer [llvm-prefer-isa-or-dyn-cast-in-conditionals]

Suggested change
if (auto* i = cast<VarDecl>(DRE->getDecl())) {
if (auto* i = dyn_cast<VarDecl>(DRE->getDecl())) {

for (Decl* D : DS->decls()) {
if (!isa<VarDecl>(D))
continue;
if (auto* VD = cast<VarDecl>(D)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: cast<> in conditional will assert rather than return a null pointer [llvm-prefer-isa-or-dyn-cast-in-conditionals]

Suggested change
if (auto* VD = cast<VarDecl>(D)) {
if (auto* VD = dyn_cast<VarDecl>(D)) {

@@ -0,0 +1,69 @@
#include "clang/AST/RecursiveASTVisitor.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: header is missing header guard [llvm-header-guard]

Suggested change
#include "clang/AST/RecursiveASTVisitor.h"
#ifndef GITHUB_WORKSPACE_LIB_DIFFERENTIATOR_USEFULANALYZER_H
#define GITHUB_WORKSPACE_LIB_DIFFERENTIATOR_USEFULANALYZER_H
#include "clang/AST/RecursiveASTVisitor.h"

lib/Differentiator/UsefulAnalyzer.h:-1:

+ 
+ #endif

bool m_Useful = false;
bool m_Marking = false;

std::set<const clang::VarDecl*>& m_UsefulDecls;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: member 'm_UsefulDecls' of type 'std::set<const clang::VarDecl *> &' is a reference [cppcoreguidelines-avoid-const-or-ref-data-members]

  std::set<const clang::VarDecl*>& m_UsefulDecls;
                                   ^

bool m_Marking = false;

std::set<const clang::VarDecl*>& m_UsefulDecls;
std::set<const clang::FunctionDecl*>& m_UsefulFuncs;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: member 'm_UsefulFuncs' of type 'std::set<const clang::FunctionDecl *> &' is a reference [cppcoreguidelines-avoid-const-or-ref-data-members]

  std::set<const clang::FunctionDecl*>& m_UsefulFuncs;
                                        ^

/// \param toAssign - Parameter to initialize new VarsData with.
/// \return Unique pointer to a new object of type Varsdata.
static std::unique_ptr<VarsData> createNewVarsData(VarsData toAssign) {
return std::unique_ptr<VarsData>(new VarsData(std::move(toAssign)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: use std::make_unique instead [modernize-make-unique]

lib/Differentiator/UsefulAnalyzer.h:7:

- #include <stack>
+ #include <memory>
+ #include <stack>
Suggested change
return std::unique_ptr<VarsData>(new VarsData(std::move(toAssign)));
return std::make_unique<VarsData>(std::move(toAssign));


clang::CFGBlock* getCFGBlockByID(unsigned ID);

clang::ASTContext& m_Context;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: member 'm_Context' of type 'clang::ASTContext &' is a reference [cppcoreguidelines-avoid-const-or-ref-data-members]

  clang::ASTContext& m_Context;
                     ^

@ovdiiuv ovdiiuv force-pushed the useful branch 4 times, most recently from 8f8e30e to 7d344aa Compare October 19, 2024 17:51
Copy link
Contributor

@github-actions github-actions bot left a 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

@@ -0,0 +1,72 @@
#ifndef CLAD_DIFFERENTIATOR_USEFULANALYZER_H
#define CLAD_DIFFERENTIATOR_USEFULANALYZER_H
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: header guard does not follow preferred style [llvm-header-guard]

Suggested change
#define CLAD_DIFFERENTIATOR_USEFULANALYZER_H
#ifndef GITHUB_WORKSPACE_LIB_DIFFERENTIATOR_USEFULANALYZER_H
#define GITHUB_WORKSPACE_LIB_DIFFERENTIATOR_USEFULANALYZER_H

lib/Differentiator/UsefulAnalyzer.h:71:

+ endif // GITHUB_WORKSPACE_LIB_DIFFERENTIATOR_USEFULANALYZER_H

/// \param toAssign - Parameter to initialize new VarsData with.
/// \return Unique pointer to a new object of type Varsdata.
static std::unique_ptr<VarsData> createNewVarsData(VarsData toAssign) {
return std::unique_ptr<VarsData>(new VarsData(std::move(toAssign)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: use std::make_unique instead [modernize-make-unique]

lib/Differentiator/UsefulAnalyzer.h:9:

- #include <stack>
+ #include <memory>
+ #include <stack>
Suggested change
return std::unique_ptr<VarsData>(new VarsData(std::move(toAssign)));
return std::make_unique<VarsData>(std::move(toAssign));

void copyVarToCurBlock(const clang::VarDecl* VD);
VarsData& getCurBlockVarsData() { return *m_BlockData[m_CurBlockID]; }
[[nodiscard]] const VarsData& getCurBlockVarsData() const {
return const_cast<UsefulAnalyzer*>(this)->getCurBlockVarsData();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not use const_cast [cppcoreguidelines-pro-type-const-cast]

    return const_cast<UsefulAnalyzer*>(this)->getCurBlockVarsData();
           ^

WIP
format
Copy link

codecov bot commented Oct 19, 2024

Codecov Report

Attention: Patch coverage is 20.12579% with 127 lines in your changes missing coverage. Please review.

Project coverage is 91.49%. Comparing base (2d08ce1) to head (cc32d1a).
Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
lib/Differentiator/UsefulAnalyzer.cpp 0.00% 100 Missing ⚠️
lib/Differentiator/DiffPlanner.cpp 47.36% 10 Missing ⚠️
lib/Differentiator/UsefulAnalyzer.h 0.00% 8 Missing ⚠️
tools/ClangPlugin.h 63.63% 4 Missing ⚠️
tools/ClangPlugin.cpp 66.66% 3 Missing ⚠️
lib/Differentiator/BaseForwardModeVisitor.cpp 81.81% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1120      +/-   ##
==========================================
- Coverage   94.36%   91.49%   -2.88%     
==========================================
  Files          50       52       +2     
  Lines        8365     8837     +472     
==========================================
+ Hits         7894     8085     +191     
- Misses        471      752     +281     
Files with missing lines Coverage Δ
include/clad/Differentiator/CladConfig.h 100.00% <ø> (ø)
include/clad/Differentiator/DiffPlanner.h 69.56% <100.00%> (+1.38%) ⬆️
lib/Differentiator/PushForwardModeVisitor.cpp 100.00% <ø> (ø)
lib/Differentiator/BaseForwardModeVisitor.cpp 98.59% <81.81%> (-0.14%) ⬇️
tools/ClangPlugin.cpp 94.97% <66.66%> (-1.18%) ⬇️
tools/ClangPlugin.h 91.71% <63.63%> (-1.34%) ⬇️
lib/Differentiator/UsefulAnalyzer.h 0.00% <0.00%> (ø)
lib/Differentiator/DiffPlanner.cpp 93.54% <47.36%> (-5.02%) ⬇️
lib/Differentiator/UsefulAnalyzer.cpp 0.00% <0.00%> (ø)

... and 29 files with indirect coverage changes

Files with missing lines Coverage Δ
include/clad/Differentiator/CladConfig.h 100.00% <ø> (ø)
include/clad/Differentiator/DiffPlanner.h 69.56% <100.00%> (+1.38%) ⬆️
lib/Differentiator/PushForwardModeVisitor.cpp 100.00% <ø> (ø)
lib/Differentiator/BaseForwardModeVisitor.cpp 98.59% <81.81%> (-0.14%) ⬇️
tools/ClangPlugin.cpp 94.97% <66.66%> (-1.18%) ⬇️
tools/ClangPlugin.h 91.71% <63.63%> (-1.34%) ⬇️
lib/Differentiator/UsefulAnalyzer.h 0.00% <0.00%> (ø)
lib/Differentiator/DiffPlanner.cpp 93.54% <47.36%> (-5.02%) ⬇️
lib/Differentiator/UsefulAnalyzer.cpp 0.00% <0.00%> (ø)

... and 29 files with indirect coverage changes

Copy link
Contributor

@github-actions github-actions bot left a 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

@@ -1063,7 +1063,14 @@
// If DRE is of type pointer, then the derivative is a null pointer.
if (clonedDRE->getType()->isPointerType())
return StmtDiff(clonedDRE, nullptr);

if (auto* i = dyn_cast<VarDecl>(DRE->getDecl())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: 'auto *i' can be declared as 'const auto *i' [readability-qualified-auto]

Suggested change
if (auto* i = dyn_cast<VarDecl>(DRE->getDecl())) {
if (const auto* i = dyn_cast<VarDecl>(DRE->getDecl())) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant