Skip to content

Commit

Permalink
Fix some obvious Tofino cstring misuse
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Korobeynikov <[email protected]>
  • Loading branch information
asl committed Nov 1, 2024
1 parent 6ff7a30 commit 62781fb
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions backends/tofino/bf-p4c/ir/mau.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ void Table::visit_match_table(THIS *self, Visitor &v, payload_info_t &payload_in
auto exit_visitor = &saved->flow_clone();
if (payload_info.action_info.count(action_name))
exit_visitor->flow_merge(*payload_info.action_info.at(action_name).flow_state);
exit_visitor->visit(action, "actions"_cs);
exit_visitor->visit(action, "actions");
exit_visitor->flow_merge_global_to("-EXIT-"_cs);
}

Expand Down Expand Up @@ -345,7 +345,7 @@ void Table::visit_match_table(THIS *self, Visitor &v, payload_info_t &payload_in
}

// Visit the action.
current->visit(action, "actions"_cs);
current->visit(action, "actions");

// Figure out which keys in the next_visitors table need updating.
if (pinfo) {
Expand Down
28 changes: 14 additions & 14 deletions backends/tofino/bf-p4c/ir/tofino.def
Original file line number Diff line number Diff line change
Expand Up @@ -157,27 +157,27 @@ class BFN::Pipe {
visit_children {
if (auto *th = dynamic_cast<ThreadVisitor *>(&v)) {
if (th->thread == GHOST) {
v.visit(ghost_thread.ghost_parser, "ghost_parser"_cs);
v.visit(ghost_thread.ghost_mau, "ghost_mau"_cs);
v.visit(ghost_thread.ghost_parser, "ghost_parser");
v.visit(ghost_thread.ghost_mau, "ghost_mau");
} else {
thread[th->thread].parsers.parallel_visit_children(v);
ControlFlowVisitor::GuardGlobal guard_except(v, "-EXIT-"_cs);
v.visit(thread[th->thread].mau, "mau"_cs);
v.visit(thread[th->thread].mau, "mau");
v.flow_merge_global_from("-EXIT-"_cs);
v.visit(ghost_thread.ghost_parser, "ghost_parser"_cs);
v.visit(ghost_thread.ghost_mau, "ghost_mau"_cs);
v.visit(thread[th->thread].deparser, "deparser"_cs); }
v.visit(ghost_thread.ghost_parser, "ghost_parser");
v.visit(ghost_thread.ghost_mau, "ghost_mau");
v.visit(thread[th->thread].deparser, "deparser"); }
} else {
// FIXME -- doesn't do flow_clone/merge properly, but fixing will
// break ParserGraph (at least) as it doesn't do merge properly
for (auto &th : thread) {
th.parsers.parallel_visit_children(v);
ControlFlowVisitor::GuardGlobal guard_except(v, "-EXIT-"_cs);
v.visit(th.mau, "mau"_cs);
v.visit(th.mau, "mau");
v.flow_merge_global_from("-EXIT-"_cs);
v.visit(th.deparser, "deparser"_cs); }
v.visit(ghost_thread.ghost_parser, "ghost_parser"_cs);
v.visit(ghost_thread.ghost_mau, "ghost_mau"_cs); } }
v.visit(th.deparser, "deparser"); }
v.visit(ghost_thread.ghost_parser, "ghost_parser");
v.visit(ghost_thread.ghost_mau, "ghost_mau"); } }
}

// A path that may span more than two pipeline gresses, depending on how the
Expand All @@ -198,15 +198,15 @@ class BFN::BridgePath : BFN::Pipe {
for (auto &th : threads.at(INGRESS)) {
th.parsers.parallel_visit_children(v);
ControlFlowVisitor::GuardGlobal guard_except(v, "-EXIT-"_cs);
v.visit(th.mau, "mau"_cs);
v.visit(th.mau, "mau");
v.flow_merge_global_from("-EXIT-"_cs);
v.visit(th.deparser, "deparser"_cs); }
v.visit(th.deparser, "deparser"); }
for (auto &th : threads.at(EGRESS)) {
th.parsers.parallel_visit_children(v);
ControlFlowVisitor::GuardGlobal guard_except(v, "-EXIT-"_cs);
v.visit(th.mau, "mau"_cs);
v.visit(th.mau, "mau");
v.flow_merge_global_from("-EXIT-"_cs);
v.visit(th.deparser, "deparser"_cs); } }
v.visit(th.deparser, "deparser"); } }
}

// BFN::Toplevel stores the midend and backend representation of a P4Program.
Expand Down
10 changes: 5 additions & 5 deletions backends/tofino/bf-p4c/midend/defuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class ComputeDefUse::SetupJoinPoints : public ControlFlowVisitor::SetupJoinPoint
LOG6("SetupJoinPoints(P4Parser " << p->name << ")" << indent);
LOG8(" " << Log::indent << Log::indent << *p << Log::unindent << Log::unindent);
if (auto start = p->states.getDeclaration<IR::ParserState>("start"_cs))
visit(start, "start"_cs);
visit(start, "start");
return false;
}
bool preorder(const IR::P4Control *) override { return false; }
Expand Down Expand Up @@ -220,7 +220,7 @@ bool ComputeDefUse::preorder(const IR::P4Control *c) {
if (p->direction == IR::Direction::In || p->direction == IR::Direction::InOut)
def_info[p].defs.insert(getLoc(p));
state = NORMAL;
visit(c->body, "body"_cs); // just visit the body; tables/actions will be visited when applied
visit(c->body, "body"); // just visit the body; tables/actions will be visited when applied
for (auto *p : c->getApplyParameters()->parameters)
if (p->direction == IR::Direction::Out || p->direction == IR::Direction::InOut)
add_uses(getLoc(p), def_info[p]);
Expand All @@ -233,7 +233,7 @@ bool ComputeDefUse::preorder(const IR::P4Table *tbl) {
if (state == SKIPPING) return false;
IndentCtl::TempIndent indent;
LOG5("ComputeDefUse(P4Table " << tbl->name << ")" << indent);
if (auto key = tbl->getKey()) visit(key, "key"_cs);
if (auto key = tbl->getKey()) visit(key, "key");
if (auto actions = tbl->getActionList()) {
parallel_visit(actions->actionList, "actions");
} else {
Expand All @@ -247,7 +247,7 @@ bool ComputeDefUse::preorder(const IR::P4Action *act) {
for (auto *p : *act->parameters) def_info[p].defs.insert(getLoc(p));
IndentCtl::TempIndent indent;
LOG5("ComputeDefUse(P4Action " << act->name << ")" << indent);
visit(act->body, "body"_cs);
visit(act->body, "body");
return false;
}

Expand All @@ -260,7 +260,7 @@ bool ComputeDefUse::preorder(const IR::P4Parser *p) {
def_info[a].defs.insert(getLoc(a));
state = NORMAL;
if (auto start = p->states.getDeclaration<IR::ParserState>("start"_cs)) {
visit(start, "start"_cs);
visit(start, "start");
} else {
BUG("No start state in %s", p);
}
Expand Down
2 changes: 1 addition & 1 deletion backends/tofino/bf-p4c/phv/phv_fields.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ class Field : public LiftLess<Field> {
bitvec getStartBits(PHV::Size size) const;

/// @returns the header to which this field belongs.
cstring header() const { return name.before(strrchr(name, '.')); }
cstring header() const { return name.before(strrchr(name.c_str(), '.')); }

private:
/// When set, use this name rather than PHV::Field::name when generating
Expand Down

0 comments on commit 62781fb

Please sign in to comment.