Skip to content

Commit

Permalink
clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisDodd committed Apr 3, 2024
1 parent 6922f5f commit e34ef1d
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 30 deletions.
3 changes: 2 additions & 1 deletion frontends/p4/def_use.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ bool LocationSet::operator==(const LocationSet &other) const {
auto it = other.begin();
for (auto s : locations) {
if (it == other.end() || *it != s) return false;
++it; }
++it;
}
return it == other.end();
}

Expand Down
6 changes: 4 additions & 2 deletions frontends/p4/toP4/toP4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1204,7 +1204,8 @@ bool ToP4::preorder(const IR::ForStatement *s) {
if (!first) builder.append(", ");
builder.supressStatementSemi();
visit(d, "init");
first = false; }
first = false;
}
builder.append("; ");
visit(s->condition, "condition");
builder.append("; ");
Expand All @@ -1214,7 +1215,8 @@ bool ToP4::preorder(const IR::ForStatement *s) {
if (!first) builder.append(", ");
builder.supressStatementSemi();
visit(e, "updates");
first = false; }
first = false;
}
builder.append(") ");
if (!s->body->is<IR::BlockStatement>()) {
builder.append("{");
Expand Down
6 changes: 4 additions & 2 deletions ir/dbprint-stmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,15 @@ void IR::ForStatement::dbprint(std::ostream &out) const {
for (auto *sd : init) {
if (!first) out << ", ";
out << sd;
first = false; }
first = false;
}
out << "; " << condition << "; ";
first = true;
for (auto *sd : updates) {
if (!first) out << ", ";
out << sd;
first = false; }
first = false;
}
out << ") {" << indent << Log::endl << body << " }" << unindent << setprec(prec);
}

Expand Down
4 changes: 2 additions & 2 deletions ir/loop-visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ limitations under the License.
*/
#include "ir/ir.h"

template<class THIS>
template <class THIS>
void IR::ForStatement::visit_children(THIS *self, Visitor &v) {
v.visit(self->annotations, "annotations");
v.visit(self->init, "init");
Expand Down Expand Up @@ -50,7 +50,7 @@ void IR::ForStatement::visit_children(THIS *self, Visitor &v) {
void IR::ForStatement::visit_children(Visitor &v) { visit_children(this, v); }
void IR::ForStatement::visit_children(Visitor &v) const { visit_children(this, v); }

template<class THIS>
template <class THIS>
void IR::ForInStatement::visit_children(THIS *self, Visitor &v) {
v.visit(self->annotations, "annotations");
v.visit(self->decl, "decl", 0);
Expand Down
12 changes: 6 additions & 6 deletions ir/visitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,8 @@ class ControlFlowVisitor : public virtual Visitor {
void flow_merge(Visitor &) override = 0;
virtual void flow_copy(ControlFlowVisitor &) = 0;
virtual bool operator==(const ControlFlowVisitor &) const {
BUG("%s pass does not support loops", name()); }
BUG("%s pass does not support loops", name());
}
bool operator!=(const ControlFlowVisitor &v) const { return !(*this == v); }
void setUnreachable() { unreachable = true; }
bool isUnreachable() { return unreachable; }
Expand All @@ -556,8 +557,7 @@ class ControlFlowVisitor : public virtual Visitor {
}
void restore_global(std::pair<cstring, ControlFlowVisitor *> saved) {
globals.erase(saved.first);
if (saved.second)
globals.emplace(saved.first, *saved.second);
if (saved.second) globals.emplace(saved.first, *saved.second);
}

/// RAII class to ensure global key is only used in one place
Expand All @@ -574,7 +574,8 @@ class ControlFlowVisitor : public virtual Visitor {
/// RAII class to save and restore one or more global keys
class SaveGlobal {
ControlFlowVisitor &self;
std::vector<std::pair<cstring, ControlFlowVisitor *>> saved;
std::vector<std::pair<cstring, ControlFlowVisitor *>> saved;

public:
SaveGlobal(ControlFlowVisitor &self, cstring key) : self(self) {
saved.push_back(self.save_global(key));
Expand All @@ -584,8 +585,7 @@ class ControlFlowVisitor : public virtual Visitor {
saved.push_back(self.save_global(k2));
}
~SaveGlobal() {
for (auto it = saved.rbegin(); it != saved.rend(); ++it)
self.restore_global(*it);
for (auto it = saved.rbegin(); it != saved.rend(); ++it) self.restore_global(*it);
}
};

Expand Down
3 changes: 2 additions & 1 deletion lib/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ void increaseVerbosity();
#define LOGN(N, X) \
(LOGGING(N) ? ::Log::Detail::fileLogOutput(__FILE__) \
<< ::Log::Detail::OutputLogPrefix(__FILE__, N) << X \
<< ::Log::Detail::clearPrefix << std::endl << std::flush \
<< ::Log::Detail::clearPrefix << std::endl \
<< std::flush \
: std::clog)
#define LOG1(X) LOGN(1, X)
#define LOG2(X) LOGN(2, X)
Expand Down
4 changes: 1 addition & 3 deletions lib/sourceCodeBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ class SourceCodeBuilder {
supressSemi = false;
if (addNl) newline();
}
void supressStatementSemi() {
supressSemi = true;
}
void supressStatementSemi() { supressSemi = true; }

void blockStart() {
append("{");
Expand Down
18 changes: 8 additions & 10 deletions midend/def_use.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,27 +85,25 @@ void ComputeDefUse::def_info_t::flow_merge(def_info_t &a) {

bool ComputeDefUse::def_info_t::operator==(const def_info_t &a) const {
if (defs.size() != a.defs.size()) return false;
for (auto *l : defs) if (!a.defs.count(l)) return false;
for (auto *l : defs)
if (!a.defs.count(l)) return false;
if (live != a.live) return false;
// Don't check the parent field as it is not set consistently (it is only set in
// copy/move ctors above) and nothing appears to depend on it. Should be removed?
if (valid_bit_defs.size() != a.valid_bit_defs.size()) return false;
for (auto *l : valid_bit_defs) if (!a.valid_bit_defs.count(l)) return false;
for (auto *l : valid_bit_defs)
if (!a.valid_bit_defs.count(l)) return false;
if (fields.size() != a.fields.size()) return false;
for (auto &[field, info] : fields) {
auto it = a.fields.find(field);
if (it == a.fields.end())
return false;
if (info != it->second)
return false;
if (it == a.fields.end()) return false;
if (info != it->second) return false;
}
if (slices.size() != a.slices.size()) return false;
for (auto &[slice, info] : slices) {
auto it = a.slices.find(slice);
if (it == a.slices.end())
return false;
if (info != it->second)
return false;
if (it == a.slices.end()) return false;
if (info != it->second) return false;
}
return true;
}
Expand Down
3 changes: 1 addition & 2 deletions midend/local_copyprop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,7 @@ IR::AssignmentStatement *DoLocalCopyPropagation::postorder(IR::AssignmentStateme
}

void DoLocalCopyPropagation::LoopPrepass::postorder(const IR::AssignmentStatement *as) {
if (auto dest = expr_name(as->left))
self.dropValuesUsing(dest);
if (auto dest = expr_name(as->left)) self.dropValuesUsing(dest);
}

IR::IfStatement *DoLocalCopyPropagation::postorder(IR::IfStatement *s) {
Expand Down
3 changes: 2 additions & 1 deletion midend/local_copyprop.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,12 @@ class DoLocalCopyPropagation : public ControlFlowVisitor, Transform, P4WriteCont
bool isHeaderUnionIsValid(const IR::Expression *e);

class LoopPrepass : public Inspector {
DoLocalCopyPropagation &self;
DoLocalCopyPropagation &self;
void postorder(const IR::AssignmentStatement *) override;
void postorder(const IR::MethodCallExpression *) override;
void apply_table(TableInfo *tbl);
void apply_function(FuncInfo *tbl);

public:
explicit LoopPrepass(DoLocalCopyPropagation &s) : self(s) {}
};
Expand Down

0 comments on commit e34ef1d

Please sign in to comment.