Skip to content

Commit

Permalink
Apply clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
PetroZarytskyi committed Mar 6, 2024
1 parent de69cd2 commit 760e3c2
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 30 deletions.
6 changes: 3 additions & 3 deletions include/clad/Differentiator/ErrorEstimator.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class ErrorEstimationHandler : public ExternalRMVSource {
public:
using direction = rmv::direction;
ErrorEstimationHandler()
: m_FinalError(nullptr), m_RetErrorExpr(nullptr),
m_EstModel(nullptr), m_IdxExpr(nullptr) {}
: m_FinalError(nullptr), m_RetErrorExpr(nullptr), m_EstModel(nullptr),
m_IdxExpr(nullptr) {}
~ErrorEstimationHandler() override = default;

/// Function to set the error estimation model currently in use.
Expand All @@ -74,7 +74,7 @@ class ErrorEstimationHandler : public ExternalRMVSource {
/// \param[in] errorExpr The error expression (LHS) of the variable.
/// \param[in] addToTheFront A flag to decide whether the error stmts
/// should be added to the beginning of the block or the current position.
void AddErrorStmtToBlock(clang::Expr* errorExpr, bool addToTheFront=true);
void AddErrorStmtToBlock(clang::Expr* errorExpr, bool addToTheFront = true);

/// Emit the error estimation related statements that were saved to be
/// emitted at later points into specific blocks.
Expand Down
3 changes: 2 additions & 1 deletion include/clad/Differentiator/ExternalRMVSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ class ExternalRMVSource {
}

/// This is called just after finalising processing of assignment operator.
virtual void ActBeforeFinalizingAssignOp(clang::Expr*&, clang::Expr*&, clang::Expr*&,
virtual void ActBeforeFinalizingAssignOp(clang::Expr*&, clang::Expr*&,

Check warning on line 142 in include/clad/Differentiator/ExternalRMVSource.h

View check run for this annotation

Codecov / codecov/patch

include/clad/Differentiator/ExternalRMVSource.h#L142

Added line #L142 was not covered by tests
clang::Expr*&,
clang::BinaryOperator::Opcode&){};

Check warning on line 144 in include/clad/Differentiator/ExternalRMVSource.h

View check run for this annotation

Codecov / codecov/patch

include/clad/Differentiator/ExternalRMVSource.h#L144

Added line #L144 was not covered by tests

/// This is called at that beginning of
Expand Down
4 changes: 1 addition & 3 deletions include/clad/Differentiator/VisitorBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,7 @@ namespace clad {

/// Build an array subscript expression with a given base expression and
/// one index.
clang::Expr*
BuildArraySubscript(clang::Expr* Base,
clang::Expr*& Idx) {
clang::Expr* BuildArraySubscript(clang::Expr* Base, clang::Expr*& Idx) {
llvm::SmallVector<clang::Expr*, 1> IS = {Idx};
return BuildArraySubscript(Base, IS);
}
Expand Down
42 changes: 20 additions & 22 deletions lib/Differentiator/ErrorEstimator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,16 @@ void ErrorEstimationHandler::BuildReturnErrorStmt() {
Expr* finExpr =
m_EstModel->AssignError(StmtDiff(m_RetErrorExpr, flitr), "return_expr");
m_RMV->addToCurrentBlock(
m_RMV->BuildOp(BO_AddAssign, m_FinalError, finExpr),
direction::forward);
m_RMV->BuildOp(BO_AddAssign, m_FinalError, finExpr),
direction::forward);
}
}

void ErrorEstimationHandler::AddErrorStmtToBlock(Expr* errorExpr, bool addToTheFront) {
void ErrorEstimationHandler::AddErrorStmtToBlock(Expr* errorExpr,
bool addToTheFront) {
Stmt* errorStmt = m_RMV->BuildOp(BO_AddAssign, m_FinalError, errorExpr);
if (addToTheFront) {
auto &block = m_RMV->getCurrentBlock(direction::reverse);
if (addToTheFront) {
auto& block = m_RMV->getCurrentBlock(direction::reverse);
block.insert(block.begin(), errorStmt);
} else {
m_RMV->addToCurrentBlock(errorStmt, direction::reverse);
Expand Down Expand Up @@ -119,8 +120,7 @@ bool ErrorEstimationHandler::ShouldEstimateErrorFor(VarDecl* VD) {

// Get the types on the declartion and initalization expression.
QualType varDeclBase = VD->getType();
QualType varDeclType =
getUnderlyingArrayType(varDeclBase, m_RMV->m_Context);
QualType varDeclType = getUnderlyingArrayType(varDeclBase, m_RMV->m_Context);
const Expr* init = VD->getInit();
// If declarationg type in not floating point type, we want to do two
// things.
Expand Down Expand Up @@ -176,7 +176,7 @@ void ErrorEstimationHandler::EmitFinalErrorStmts(
auto* paramClone = m_RMV->BuildDeclRef(decl);
// Finally emit the error.
auto* errorExpr = GetError(paramClone, m_RMV->m_Variables[decl],
params[i]->getNameAsString());
params[i]->getNameAsString());
m_RMV->addToCurrentBlock(
m_RMV->BuildOp(BO_AddAssign, m_FinalError, errorExpr));
} else {
Expand All @@ -190,8 +190,7 @@ void ErrorEstimationHandler::EmitFinalErrorStmts(
m_IdxExpr = m_RMV->BuildDeclRef(idxExprDecl);
}
Expr* Ldiff = nullptr;
Ldiff = m_RMV->BuildArraySubscript(
LdiffExpr, m_IdxExpr);
Ldiff = m_RMV->BuildArraySubscript(LdiffExpr, m_IdxExpr);
auto* paramClone = m_RMV->BuildDeclRef(decl);
auto* LRepl = m_RMV->BuildArraySubscript(paramClone, m_IdxExpr);
// Build the loop to put in reverse mode.
Expand Down Expand Up @@ -228,22 +227,22 @@ void ErrorEstimationHandler::EmitUnaryOpErrorStmts(StmtDiff var,
// First check if it was registered.
// If not, we don't care about it.
if (ShouldEstimateErrorFor(cast<VarDecl>(DRE->getDecl()))) {
Expr* erroExpr = GetError(DRE, var.getExpr_dx(),
DRE->getDecl()->getNameAsString());
Expr* erroExpr =
GetError(DRE, var.getExpr_dx(), DRE->getDecl()->getNameAsString());
AddErrorStmtToBlock(erroExpr);
}
}
}

void ErrorEstimationHandler::EmitBinaryOpErrorStmts(Expr* LExpr, Expr* oldValue) {
void ErrorEstimationHandler::EmitBinaryOpErrorStmts(Expr* LExpr,
Expr* oldValue) {
// Assign the error.
auto decl = GetUnderlyingDeclRefOrNull(LExpr)->getDecl();
if (!ShouldEstimateErrorFor(cast<VarDecl>(decl)))
return;
return;
bool errorFromFunctionCall = (bool)m_NestedFuncError;
Expr* errorExpr =
UpdateErrorForFuncCallAssigns(this, LExpr, oldValue,
m_NestedFuncError, decl->getNameAsString());
Expr* errorExpr = UpdateErrorForFuncCallAssigns(
this, LExpr, oldValue, m_NestedFuncError, decl->getNameAsString());
AddErrorStmtToBlock(errorExpr, /*addToTheFront=*/!errorFromFunctionCall);
// If there are assign statements to emit in reverse, do that.
EmitErrorEstimationStmts(direction::reverse);
Expand All @@ -262,9 +261,8 @@ void ErrorEstimationHandler::EmitDeclErrorStmts(VarDeclDiff VDDiff,
if (VD->getInit() && !GetUnderlyingDeclRefOrNull(VD->getInit())) {
bool errorFromFunctionCall = (bool)m_NestedFuncError;
Expr* errorExpr = UpdateErrorForFuncCallAssigns(
this, VDRef,
m_RMV->BuildDeclRef(VDDiff.getDecl_dx()), m_NestedFuncError,
VD->getNameAsString());
this, VDRef, m_RMV->BuildDeclRef(VDDiff.getDecl_dx()),
m_NestedFuncError, VD->getNameAsString());
AddErrorStmtToBlock(errorExpr, /*addToTheFront=*/!errorFromFunctionCall);
}
}
Expand Down Expand Up @@ -390,8 +388,8 @@ void ErrorEstimationHandler::ActBeforeFinalizingVisitCallExpr(
}

void ErrorEstimationHandler::ActBeforeFinalizingAssignOp(
clang::Expr*& LCloned, clang::Expr*& oldValue,
clang::Expr*& R, clang::BinaryOperator::Opcode& opCode) {
clang::Expr*& LCloned, clang::Expr*& oldValue, clang::Expr*& R,
clang::BinaryOperator::Opcode& opCode) {
DeclRefExpr* RRef = GetUnderlyingDeclRefOrNull(R);
// In the case that an RHS expression is a declReference, we do not emit
// any error because the assignment operation entials zero error.
Expand Down
3 changes: 2 additions & 1 deletion lib/Differentiator/ReverseModeVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2572,7 +2572,8 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context,
} else
llvm_unreachable("unknown assignment opCode");
if (m_ExternalSource)
m_ExternalSource->ActBeforeFinalizingAssignOp(LCloned, ResultRef, R, opCode);
m_ExternalSource->ActBeforeFinalizingAssignOp(LCloned, ResultRef, R,
opCode);

// Output statements from Visit(L).
for (auto it = Lblock_begin; it != Lblock_end; ++it)
Expand Down

0 comments on commit 760e3c2

Please sign in to comment.