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

Add TBR analysis in the reverse mode of Clad #616

Closed
wants to merge 10 commits into from

Conversation

PetroZarytskyi
Copy link
Collaborator

This pull request adds TBR (To-BeRecorded) analysis in the reverse mode of Clad. There are still that issues must be addressed before merging this to the master branch.

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 206. Check the log or trigger a new build to see more.

// ConstExprUsage Usage, ASTContext &)
// => bool Expr::EvaluateAsConstantExpr(EvalResult &Result, ASTContext &)

static inline bool Expr_EvaluateAsConstantExpr(const Expr* E,
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: unused function 'Expr_EvaluateAsConstantExpr' [clang-diagnostic-unused-function]

static inline bool Expr_EvaluateAsConstantExpr(const Expr* E,
                   ^

Comment on lines +137 to +140
else if (d == direction::reverse)
return m_Reverse.back();
else
return m_EssentialReverse.back();
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 'else' after 'return' [llvm-else-after-return]

Suggested change
else if (d == direction::reverse)
return m_Reverse.back();
else
return m_EssentialReverse.back();
if (d == direction::reverse)
return m_Reverse.back();
else
return m_EssentialReverse.back();

m_Reverse.push_back({});
else
m_EssentialReverse.push_back({});
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 emplace_back instead of push_back [modernize-use-emplace]

Suggested change
m_EssentialReverse.push_back({});
m_EssentialReverse.emplace_back();

Comment on lines +158 to 167
} else if (d == direction::reverse) {
auto CS = MakeCompoundStmt(getCurrentBlock(direction::reverse));
std::reverse(CS->body_begin(), CS->body_end());
m_Reverse.pop_back();
return CS;
} else {
auto CS = MakeCompoundStmt(getCurrentBlock(d));
m_EssentialReverse.pop_back();
return CS;
}
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 'else' after 'return' [llvm-else-after-return]

Suggested change
} else if (d == direction::reverse) {
auto CS = MakeCompoundStmt(getCurrentBlock(direction::reverse));
std::reverse(CS->body_begin(), CS->body_end());
m_Reverse.pop_back();
return CS;
} else {
auto CS = MakeCompoundStmt(getCurrentBlock(d));
m_EssentialReverse.pop_back();
return CS;
}
} if (d == direction::reverse) {
auto CS = MakeCompoundStmt(getCurrentBlock(direction::reverse));
std::reverse(CS->body_begin(), CS->body_end());
m_Reverse.pop_back();
return CS;
} else {
auto CS = MakeCompoundStmt(getCurrentBlock(d));
m_EssentialReverse.pop_back();
return CS;
}

auto CS = MakeCompoundStmt(getCurrentBlock(direction::reverse));
std::reverse(CS->body_begin(), CS->body_end());
m_Reverse.pop_back();
return CS;
} else {
auto CS = MakeCompoundStmt(getCurrentBlock(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: 'auto CS' can be declared as 'auto *CS' [llvm-qualified-auto]

        auto CS = MakeCompoundStmt(getCurrentBlock(d));
        ^

this fix will not be applied because it overlaps with another fix

@@ -553,7 +583,9 @@
void PopBreakContStmtHandler() {
m_BreakContStmtHandlers.pop_back();
}


std::map<clang::SourceLocation, bool> m_ToBeRecorded;
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 'm_ToBeRecorded' has public visibility [cppcoreguidelines-non-private-member-variables-in-classes]

    std::map<clang::SourceLocation, bool> m_ToBeRecorded;
                                          ^

Comment on lines +1 to +2
#ifndef CLAD_TBR_ANALYZER_H
#define CLAD_TBR_ANALYZER_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
#ifndef CLAD_TBR_ANALYZER_H
#define CLAD_TBR_ANALYZER_H
#ifndef CLAD_DIFFERENTIATOR_TBRANALYZER_H
#define CLAD_DIFFERENTIATOR_TBRANALYZER_H

include/clad/Differentiator/TBRAnalyzer.h:303:

- #endif // CLAD_TBR_ANALYZER_H
+ #endif // CLAD_DIFFERENTIATOR_TBRANALYZER_H


namespace clad {

class TBRAnalyzer : public clang::ConstStmtVisitor<TBRAnalyzer> {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: class 'TBRAnalyzer' defines a non-default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions]

class TBRAnalyzer : public clang::ConstStmtVisitor<TBRAnalyzer> {
      ^

/// type keys.
struct APIntHash {
size_t operator()(const llvm::APInt& apint) const {
return std::hash<std::string>{}(apint.toString(10, 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: 10 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers]

      return std::hash<std::string>{}(apint.toString(10, true));
                                                     ^

/// Just a helper struct serving as a wrapper for IdxOrMemberValue union.
/// Used to unwrap expressions like a[6].x.t[3]. Only used in
/// TBRAnalyzer::overlay().
struct IdxOrMember {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: class 'IdxOrMember' defines a copy constructor but does not define a destructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions]

  struct IdxOrMember {
         ^

@PetroZarytskyi PetroZarytskyi deleted the tbr-analyzer branch August 14, 2023 12:56
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.

3 participants