Skip to content

Commit

Permalink
fix some linter warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ckrause committed Feb 4, 2024
1 parent 700715f commit dd99cef
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 38 deletions.
13 changes: 4 additions & 9 deletions src/form/expression_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,17 +216,12 @@ bool zeroProduct(Expression& e) {
return false;
}
const Expression zero(Expression::Type::CONSTANT, "", Number::ZERO);
bool found = false;
for (auto& c : e.children) {
if (c == zero) {
found = true;
break;
}
}
if (found) {
bool hasZero = std::any_of(e.children.begin(), e.children.end(),
[&](const Expression& c) { return c == zero; });
if (hasZero) {
e = zero;
}
return found;
return hasZero;
}

bool lessExpr(const Expression& lhs, const Expression& rhs) {
Expand Down
24 changes: 11 additions & 13 deletions src/form/formula.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,19 @@ std::string Formula::toString() const {
void Formula::clear() { entries.clear(); }

bool Formula::contains(const Expression& search) const {
for (auto& e : entries) {
if (e.first.contains(search) || e.second.contains(search)) {
return true;
}
}
return false;
return std::any_of(entries.begin(), entries.end(),
[&](const std::pair<Expression, Expression>& e) {
return e.first.contains(search) ||
e.second.contains(search);
});
}

bool Formula::containsFunctionDef(const std::string& fname) const {
for (const auto& e : entries) {
if (e.first.type == Expression::Type::FUNCTION && e.first.name == fname) {
return true;
}
}
return false;
return std::any_of(entries.begin(), entries.end(),
[&](const std::pair<Expression, Expression>& e) {
return e.first.type == Expression::Type::FUNCTION &&
e.first.name == fname;
});
}

bool containsPair(std::multimap<std::string, std::string>& deps,
Expand All @@ -54,7 +52,7 @@ void collectDeps(const std::string& fname, const Expression& e,
!containsPair(deps, fname, e.name)) {
deps.insert({fname, e.name});
}
for (auto& c : e.children) {
for (const auto& c : e.children) {
collectDeps(fname, c, deps);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/form/variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ bool gaussElim(const Variant& lookup, Variant& target) {
bool findVariants(VariantsManager& manager) {
auto variants = manager.variants; // copy
bool updated = false;
for (auto& target : variants) {
for (auto& target_variant : target.second) {
for (auto& lookup : variants) {
for (auto& lookup_variant : lookup.second) {
for (const auto& target : variants) {
for (const auto& target_variant : target.second) {
for (const auto& lookup : variants) {
for (const auto& lookup_variant : lookup.second) {
auto new_variant = target_variant; // copy
if (resolve(lookup_variant, new_variant) &&
manager.update(new_variant)) {
Expand Down
16 changes: 4 additions & 12 deletions src/lang/optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,18 +495,10 @@ bool Optimizer::fixSandwich(Program &p) const {
}

bool Optimizer::canChangeVariableOrder(const Program &p) const {
for (const auto &op : p.ops) {
if (op.source.type == Operand::Type::INDIRECT ||
op.target.type == Operand::Type::INDIRECT) {
return false;
}
if (op.type == Operation::Type::LPB) {
if (op.source.type != Operand::Type::CONSTANT || op.source.value != 1) {
return false;
}
}
}
return true;
return (std::none_of(p.ops.begin(), p.ops.end(), [&](const Operation &op) {
return ProgramUtil::hasIndirectOperand(op) ||
ProgramUtil::isNonTrivialLoopBegin(op);
}));
}

bool Optimizer::reduceMemoryCells(Program &p) const {
Expand Down
6 changes: 6 additions & 0 deletions src/lang/program_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ bool ProgramUtil::isAdditive(Operation::Type t) {
return (t == Operation::Type::ADD || t == Operation::Type::SUB);
}

bool ProgramUtil::isNonTrivialLoopBegin(const Operation &op) {
return (op.type == Operation::Type::LPB &&
(op.source.type != Operand::Type::CONSTANT ||
op.source.value != Number::ONE));
}

bool ProgramUtil::hasIndirectOperand(const Operation &op) {
const auto num_ops = Operation::Metadata::get(op.type).num_operands;
return (num_ops > 0 && op.target.type == Operand::Type::INDIRECT) ||
Expand Down
2 changes: 2 additions & 0 deletions src/lang/program_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class ProgramUtil {

static bool isAdditive(Operation::Type t);

static bool isNonTrivialLoopBegin(const Operation &op);

static bool hasIndirectOperand(const Operation &op);

static bool hasIndirectOperand(const Program &p);
Expand Down

0 comments on commit dd99cef

Please sign in to comment.