From 15dc354d4fb8ce197283c6f260314d172f37626e Mon Sep 17 00:00:00 2001 From: fruffy Date: Fri, 8 Nov 2024 18:44:43 -0500 Subject: [PATCH] Fix miscellaneous Tofino warnings. Signed-off-by: fruffy --- .../bf-p4c/arch/fromv1.0/stateful_alu.cpp | 1 - .../bf-p4c/arch/fromv1.0/v1_converters.h | 8 ++-- backends/tofino/bf-p4c/arch/psa/psa.cpp | 2 +- .../tofino/bf-p4c/common/field_defuse.cpp | 2 +- .../control-plane/bfruntime_arch_handler.h | 21 +++++----- .../bf-p4c/logging/constrained_fields.h | 6 +-- .../tofino/bf-p4c/logging/resources_clot.h | 6 +-- .../tofino/bf-p4c/mau/action_analysis.cpp | 1 - backends/tofino/bf-p4c/mau/action_format.cpp | 2 - .../bf-p4c/mau/determine_power_usage.cpp | 2 - backends/tofino/bf-p4c/mau/gateway.cpp | 4 +- .../bf-p4c/mau/instruction_selection.cpp | 4 +- .../tofino/bf-p4c/mau/jbay_next_table.cpp | 4 +- backends/tofino/bf-p4c/mau/stateful_alu.cpp | 12 +++--- .../tofino/bf-p4c/mau/table_placement.cpp | 4 +- .../tofino/bf-p4c/mau/tofino/input_xbar.cpp | 4 -- .../tofino/bf-p4c/mau/tofino/memories.cpp | 12 ++---- backends/tofino/bf-p4c/mau/tofino/memories.h | 35 +++++++--------- backends/tofino/bf-p4c/mau/validate_actions.h | 2 +- .../tofino/bf-p4c/mau/walk_power_graph.cpp | 2 - .../midend/drop_packet_with_mirror_engine.cpp | 4 +- .../tofino/bf-p4c/midend/move_to_egress.cpp | 2 +- .../bf-p4c/midend/ping_pong_generation.h | 1 - backends/tofino/bf-p4c/midend/table_mutex.h | 2 +- .../bf-p4c/parde/check_parser_multi_write.cpp | 4 +- .../bf-p4c/parde/check_parser_multi_write.h | 3 +- .../lowered/compute_lowered_deparser_ir.cpp | 2 - backends/tofino/bf-p4c/parde/marshal.h | 4 +- backends/tofino/bf-p4c/parde/parde_utils.h | 4 +- .../bf-p4c/phv/action_phv_constraints.cpp | 3 +- backends/tofino/bf-p4c/phv/allocate_phv.cpp | 2 - backends/tofino/bf-p4c/phv/allocate_phv.h | 3 +- .../allocate_temps_and_finalize_liverange.cpp | 42 ++++++++++--------- .../tofino/bf-p4c/phv/analysis/header_mutex.h | 4 +- .../bf-p4c/phv/collect_strided_headers.h | 2 +- backends/tofino/bf-p4c/phv/phv_fields.cpp | 4 +- backends/tofino/bf-p4c/phv/phv_fields.h | 3 +- .../tofino/bf-p4c/phv/pragma/pa_byte_pack.cpp | 2 - .../bf-p4c/phv/v2/metadata_initialization.cpp | 8 ++-- 39 files changed, 102 insertions(+), 131 deletions(-) diff --git a/backends/tofino/bf-p4c/arch/fromv1.0/stateful_alu.cpp b/backends/tofino/bf-p4c/arch/fromv1.0/stateful_alu.cpp index 721f3cf2b0..2a95090f9a 100644 --- a/backends/tofino/bf-p4c/arch/fromv1.0/stateful_alu.cpp +++ b/backends/tofino/bf-p4c/arch/fromv1.0/stateful_alu.cpp @@ -231,7 +231,6 @@ class CreateSaluApplyFunction : public Inspector { int expr_idx[NUM_EXPR_INDEX_T] = {0}; Util::SourceInfo expr_src_info[NUM_EXPR_INDEX_T]; Util::SourceInfo expr_pred_src_info[NUM_EXPR_INDEX_T]; - const IR::Statement *output = nullptr; const Util::SourceInfo *applyLoc = nullptr; enum expr_index_t { LO1, LO2, HI1, HI2, OUT, UNUSED } expr_index = UNUSED; bool saturating = false; diff --git a/backends/tofino/bf-p4c/arch/fromv1.0/v1_converters.h b/backends/tofino/bf-p4c/arch/fromv1.0/v1_converters.h index 9659e7c5e2..c369a533e3 100644 --- a/backends/tofino/bf-p4c/arch/fromv1.0/v1_converters.h +++ b/backends/tofino/bf-p4c/arch/fromv1.0/v1_converters.h @@ -78,15 +78,17 @@ class ControlConverter : public Transform { CHECK_NULL(structure); } - const IR::Node *postorder(IR::Declaration_Instance *node) { + const IR::Node *postorder(IR::Declaration_Instance *node) override { return substitute(node); } - const IR::Node *postorder(IR::MethodCallStatement *node) { + const IR::Node *postorder(IR::MethodCallStatement *node) override { return substitute(node); } - const IR::Node *postorder(IR::Property *node) { return substitute(node); } + const IR::Node *postorder(IR::Property *node) override { + return substitute(node); + } const IR::Node *postorder(IR::BFN::TnaControl *node) override; diff --git a/backends/tofino/bf-p4c/arch/psa/psa.cpp b/backends/tofino/bf-p4c/arch/psa/psa.cpp index 98148a7832..dd430a6a50 100644 --- a/backends/tofino/bf-p4c/arch/psa/psa.cpp +++ b/backends/tofino/bf-p4c/arch/psa/psa.cpp @@ -450,7 +450,7 @@ class TranslateProgram : public Inspector { return; } - void postorder(const IR::ParserState *state) { + void postorder(const IR::ParserState *state) override { auto ctxt = findContext(); CHECK_NULL(ctxt); for (auto stmt : state->components) { diff --git a/backends/tofino/bf-p4c/common/field_defuse.cpp b/backends/tofino/bf-p4c/common/field_defuse.cpp index 9a10c01860..6549524b28 100644 --- a/backends/tofino/bf-p4c/common/field_defuse.cpp +++ b/backends/tofino/bf-p4c/common/field_defuse.cpp @@ -636,7 +636,7 @@ static inline auto getParserRangeDefMatcher(const PhvInfo &phv, const PHV::Field le_bitrange range = bits ? *bits : StartLen(0, f->size); // note that we need to capture f (pointer) and range by value to avoid dangling reference, // but phv by reference (it is large and we got it by reference) - return [&phv, range, f](const FieldDefUse::locpair &lp) { + return [&phv, range](const FieldDefUse::locpair &lp) { le_bitrange rng; if (!(lp.first->is() || lp.first->is())) return false; diff --git a/backends/tofino/bf-p4c/control-plane/bfruntime_arch_handler.h b/backends/tofino/bf-p4c/control-plane/bfruntime_arch_handler.h index 5369b2d2d1..44d33feacd 100644 --- a/backends/tofino/bf-p4c/control-plane/bfruntime_arch_handler.h +++ b/backends/tofino/bf-p4c/control-plane/bfruntime_arch_handler.h @@ -100,11 +100,11 @@ struct CounterlikeTraits<::BFN::CounterExtern> { /// CounterlikeTraits specialization for BFN::CounterExtern for PSA template <> struct CounterlikeTraits<::BFN::CounterExtern> { - static const cstring name() { return "counter"_cs; } - static const cstring directPropertyName() { return "psa_direct_counter"_cs; } - static const cstring typeName() { return "Counter"_cs; } - static const cstring directTypeName() { return "DirectCounter"_cs; } - static const cstring sizeParamName() { return "n_counters"_cs; } + static cstring name() { return "counter"_cs; } + static cstring directPropertyName() { return "psa_direct_counter"_cs; } + static cstring typeName() { return "Counter"_cs; } + static cstring directTypeName() { return "DirectCounter"_cs; } + static cstring sizeParamName() { return "n_counters"_cs; } static ::barefoot::CounterSpec::Unit mapUnitName(const cstring name) { using ::barefoot::CounterSpec; if (name == "PACKETS") @@ -519,8 +519,7 @@ struct SnapshotFieldInfo { uint32_t id; int32_t bitwidth; bool operator==(const SnapshotFieldInfo &s) const { - if (s.name == name && s.id == id && s.bitwidth == bitwidth) return true; - return false; + return s.name == name && s.id == id && s.bitwidth == bitwidth; } bool operator<(const SnapshotFieldInfo &s) const { return (id < s.id); } }; @@ -2392,7 +2391,7 @@ class BFRuntimeArchHandlerPSA final : public BFRuntimeArchHandlerCommon ConstrainedFieldMap; diff --git a/backends/tofino/bf-p4c/logging/resources_clot.h b/backends/tofino/bf-p4c/logging/resources_clot.h index eb385c0abe..f91895e4e5 100644 --- a/backends/tofino/bf-p4c/logging/resources_clot.h +++ b/backends/tofino/bf-p4c/logging/resources_clot.h @@ -19,13 +19,11 @@ #ifndef _BACKENDS_TOFINO_BF_P4C_LOGGING_RESOURCES_CLOT_H_ #define _BACKENDS_TOFINO_BF_P4C_LOGGING_RESOURCES_CLOT_H_ -/* clang-format off */ #include #include -#include "ir/ir.h" #include "backends/tofino/bf-p4c/logging/resources_schema.h" -/* clang-format on */ +#include "ir/ir.h" using Logging::Resources_Schema_Logger; class ClotInfo; // Forward declaration @@ -50,7 +48,7 @@ class ClotResourcesLogging : public ParserInspector { std::vector &getUsageData(gress_t gress, unsigned tag); - bool preorder(const IR::BFN::LoweredParserState *state); + bool preorder(const IR::BFN::LoweredParserState *state) override; void end_apply() override; void collectClotUsages(const IR::BFN::LoweredParserMatch *match, diff --git a/backends/tofino/bf-p4c/mau/action_analysis.cpp b/backends/tofino/bf-p4c/mau/action_analysis.cpp index 7d527924f2..3ec4dc731b 100644 --- a/backends/tofino/bf-p4c/mau/action_analysis.cpp +++ b/backends/tofino/bf-p4c/mau/action_analysis.cpp @@ -1154,7 +1154,6 @@ bool ActionAnalysis::init_simple_alignment(const ActionParam &read, ContainerAct if (read.type == ActionParam::ACTIONDATA) { le_bitrange read_bits; - cstring key; if (cont_action.is_deposit_field_variant || cont_action.convert_instr_to_deposit_field || cont_action.convert_instr_to_byte_rotate_merge || cont_action.name == "set") { // if the instruction is or could be a deposit field or byte rotate, then we don't diff --git a/backends/tofino/bf-p4c/mau/action_format.cpp b/backends/tofino/bf-p4c/mau/action_format.cpp index ee635affbd..2891bdf257 100644 --- a/backends/tofino/bf-p4c/mau/action_format.cpp +++ b/backends/tofino/bf-p4c/mau/action_format.cpp @@ -2101,7 +2101,6 @@ const ALUParameter *Format::Use::find_param_alloc(UniqueLocationKey &key, Log::TempIndent indent; LOG3(" Finding ALU Param with container " << indent << indent << key.container << " for action " << key.action_name); - bool container_match = false; for (auto alu_position : action_alu_positions) { LOG3(alu_position); if (alu_position.alu_op->container() != key.container) continue; @@ -2113,7 +2112,6 @@ const ALUParameter *Format::Use::find_param_alloc(UniqueLocationKey &key, "in container %s in action %s", key.container, key.action_name); rv = loc; - container_match |= alu_position.alu_op->container() == key.container; if (alu_pos_p) *alu_pos_p = new ALUPosition(alu_position); } if (!rv) { diff --git a/backends/tofino/bf-p4c/mau/determine_power_usage.cpp b/backends/tofino/bf-p4c/mau/determine_power_usage.cpp index 7f47d5829b..b1d13c1562 100644 --- a/backends/tofino/bf-p4c/mau/determine_power_usage.cpp +++ b/backends/tofino/bf-p4c/mau/determine_power_usage.cpp @@ -289,10 +289,8 @@ void DeterminePowerUsage::postorder(const IR::MAU::Table *t) { } else if (mem.type == Memories::Use::EXACT) { // One unit of depth in each way is accessed on a table read. // Total RAMs accessed will then be the sum of the widths of ways. - int num_ways = 0; for (auto way : t->ways) { // LOG4(" exact match width = " << way.width); - ++num_ways; match_table.ram_read += way.width; } mau_features_->has_exact_[t->gress][t->stage()] = true; diff --git a/backends/tofino/bf-p4c/mau/gateway.cpp b/backends/tofino/bf-p4c/mau/gateway.cpp index 93038b4682..727e570d8c 100644 --- a/backends/tofino/bf-p4c/mau/gateway.cpp +++ b/backends/tofino/bf-p4c/mau/gateway.cpp @@ -1287,7 +1287,7 @@ bool BuildGatewayMatch::preorder(const IR::Expression *e) { const IR::Expression *tmp; BUG_CHECK(orig_mask == donemask, "failed to match all bits of %s", (tmp = findContext()) ? tmp : e); - BUG_CHECK((mask ^ upper_bit_mask) << shift == 0, "Didn't cover all bytes"); + BUG_CHECK(((mask ^ upper_bit_mask) << shift) == 0, "Didn't cover all bytes"); match_field = {}; } return false; @@ -1375,7 +1375,7 @@ void BuildGatewayMatch::constant(big_int c) { } LOG6(" match now " << match); } - BUG_CHECK((mask ^ upper_bits_mask) << shift == 0, "Didn't cover all bytes"); + BUG_CHECK(((mask ^ upper_bits_mask) << shift) == 0, "Didn't cover all bytes"); match_field = {}; } else { BUG("Invalid context for constant in BuildGatewayMatch"); diff --git a/backends/tofino/bf-p4c/mau/instruction_selection.cpp b/backends/tofino/bf-p4c/mau/instruction_selection.cpp index a867001523..7792f5e0cf 100644 --- a/backends/tofino/bf-p4c/mau/instruction_selection.cpp +++ b/backends/tofino/bf-p4c/mau/instruction_selection.cpp @@ -3197,12 +3197,12 @@ class ExpandInstructions : public MauTransform { } } - IR::Node *preorder(IR::MAU::Action *act) { + IR::Node *preorder(IR::MAU::Action *act) override { check_action_data_bus_params(act); return act; } - IR::Node *postorder(IR::Expression *expr) { + IR::Node *postorder(IR::Expression *expr) override { auto orig_expr = getOriginal(); BUG_CHECK(orig_expr, "Couldn't find original IR node"); diff --git a/backends/tofino/bf-p4c/mau/jbay_next_table.cpp b/backends/tofino/bf-p4c/mau/jbay_next_table.cpp index 5754f1f44d..e2f495c3f6 100644 --- a/backends/tofino/bf-p4c/mau/jbay_next_table.cpp +++ b/backends/tofino/bf-p4c/mau/jbay_next_table.cpp @@ -349,7 +349,7 @@ class JbayNextTable::FindNextTableUse : public MauTableInspector { return r1.second > r2.first && r2.second > r1.first; } - profile_t init_apply(const IR::Node *root) { + profile_t init_apply(const IR::Node *root) override { self.use_next_table.clear(); tables.clear(); return MauTableInspector::init_apply(root); @@ -360,7 +360,7 @@ class JbayNextTable::FindNextTableUse : public MauTableInspector { // containing seq, if that was useful. Probably almost never useful? if (!t->next.empty()) tables.push_back(t); } - void postorder(const IR::BFN::Pipe *) { + void postorder(const IR::BFN::Pipe *) override { std::stable_sort(tables.begin(), tables.end(), [this](const IR::MAU::Table *a, const IR::MAU::Table *b) { return self.control_dep.paths(a) > self.control_dep.paths(b); diff --git a/backends/tofino/bf-p4c/mau/stateful_alu.cpp b/backends/tofino/bf-p4c/mau/stateful_alu.cpp index 7e7b96f38b..bb419a004e 100644 --- a/backends/tofino/bf-p4c/mau/stateful_alu.cpp +++ b/backends/tofino/bf-p4c/mau/stateful_alu.cpp @@ -1581,12 +1581,12 @@ bool CreateSaluInstruction::isComplexInstruction(const IR::Operation_Binary *op) // IR::L* operators (LAnd, LOr, etc.) are working with predicates bool ret = false; - for (auto oper : {op->left, op->right}) { - ret |= oper->is() | oper->is(); - ret |= oper->is() | oper->is(); - ret |= oper->is() | oper->is() | oper->is(); - ret |= oper->is() | oper->is(); - ret |= oper->is(); + for (const auto *oper : {op->left, op->right}) { + ret = ret || oper->is() || oper->is(); + ret = ret || oper->is() || oper->is(); + ret = ret || oper->is() || oper->is() || oper->is(); + ret = ret || oper->is() || oper->is(); + ret = ret || oper->is(); } return ret; diff --git a/backends/tofino/bf-p4c/mau/table_placement.cpp b/backends/tofino/bf-p4c/mau/table_placement.cpp index b2bbfbd132..9d7bfce1e5 100644 --- a/backends/tofino/bf-p4c/mau/table_placement.cpp +++ b/backends/tofino/bf-p4c/mau/table_placement.cpp @@ -4881,7 +4881,7 @@ std::ostream &operator<<(std::ostream &out, TablePlacement::choice_t choice) { "control dom set has more placeable tables", "average chain length of control dom set", "default choice"}; - if (choice < sizeof(choice_names) / sizeof(choice_names[0])) { + if (static_cast(choice) < sizeof(choice_names) / sizeof(choice_names[0])) { out << choice_names[choice]; } else { out << "unknown choice <0x" << hex(choice) << ">"; @@ -5476,7 +5476,6 @@ IR::Node *TransformTables::preorder(IR::MAU::Table *tbl) { return tbl; } int stage_table = 0; - int prev_entries = 0; IR::Vector *rv = new IR::Vector; IR::MAU::Table *prev = 0; IR::MAU::Table *atcam_last = nullptr; @@ -5679,7 +5678,6 @@ IR::Node *TransformTables::preorder(IR::MAU::Table *tbl) { stage_table++; prev = table_part; if (atcam_last) prev = atcam_last; - prev_entries += pl->entries; } BUG_CHECK(!rv->empty(), "Failed to place any stage tables for %s", tbl->name); return rv; diff --git a/backends/tofino/bf-p4c/mau/tofino/input_xbar.cpp b/backends/tofino/bf-p4c/mau/tofino/input_xbar.cpp index 2fc447c294..24f4d78d7b 100644 --- a/backends/tofino/bf-p4c/mau/tofino/input_xbar.cpp +++ b/backends/tofino/bf-p4c/mau/tofino/input_xbar.cpp @@ -2098,7 +2098,6 @@ bool IXBar::allocHashWay(const IR::MAU::Table *tbl, const LayoutOption *layout_o } // Calculation of the separate select bits among many stages unsigned free_bits = 0; - unsigned used_bits = 0; for (int bit = 0; bit < IXBar::get_hash_single_bits(); bit++) { if (!(hash_single_bit_inuse[bit] & hf_hash_table_input)) { @@ -2107,7 +2106,6 @@ bool IXBar::allocHashWay(const IR::MAU::Table *tbl, const LayoutOption *layout_o } for (auto &way_use : alloc.way_use) { BUG_CHECK(way_use.select.lo == RAM_SELECT_BIT_START, "invalid select range for tofino"); - used_bits |= way_use.select_mask; } if (way_bits == 0) { @@ -3796,7 +3794,6 @@ void IXBar::XBarHashDist::immediate_inputs() { auto hash = pos.second->to(); if (hash == nullptr) continue; le_bitrange immed_range = {pos.first, pos.first + hash->size() - 1}; - int bits_seen = 0; for (int i = 0; i < 2; i++) { le_bitrange immed_impact = {i * HASH_DIST_BITS, (i + 1) * HASH_DIST_BITS - 1}; auto boost_sl = toClosedRange( @@ -3810,7 +3807,6 @@ void IXBar::XBarHashDist::immediate_inputs() { func->slice(hash_range); HashDistDest_t dest = static_cast(i); alloc_reqs.emplace_back(func, hash_dist_range, dest, 0); - bits_seen += overlap.size(); } } } diff --git a/backends/tofino/bf-p4c/mau/tofino/memories.cpp b/backends/tofino/bf-p4c/mau/tofino/memories.cpp index 44e85a2a86..c309e1a184 100644 --- a/backends/tofino/bf-p4c/mau/tofino/memories.cpp +++ b/backends/tofino/bf-p4c/mau/tofino/memories.cpp @@ -3530,11 +3530,9 @@ bool Memories::allocate_all_swbox_users() { } if (!action_bus_users.empty() || !synth_bus_users.empty()) { - int act_unused = 0; - for (auto abu : action_bus_users) act_unused += abu->left_to_place(); + for (auto abu : action_bus_users) abu->left_to_place(); - int sup_unused = 0; - for (auto sbu : synth_bus_users) sup_unused += sbu->left_to_place(); + for (auto sbu : synth_bus_users) sbu->left_to_place(); failure_reason = "allocate_all_swbox_users failed"_cs; LOG4(failure_reason); @@ -4034,10 +4032,9 @@ bool Memories::allocate_all_gw() { } } - int search_bus_free = 0; for (int i = 0; i < SRAM_ROWS; i++) { for (int j = 0; j < 2; j++) { - if (sram_search_bus[i][j].free()) search_bus_free++; + sram_search_bus[i][j].free(); } } @@ -4061,7 +4058,6 @@ bool Memories::allocate_all_no_match_miss() { // so this is essentially what I'm doing. More discussion is needed with the driver // team in order to determine if this is correct, or if this has to go through ternary and // tind tables - size_t no_match_tables_allocated = 0; for (auto *ta : no_match_miss_tables) { for (auto u_id : ta->allocation_units(nullptr, false, UniqueAttachedId::TIND_PP)) { auto &alloc = (*ta->memuse)[u_id]; @@ -4086,8 +4082,6 @@ bool Memories::allocate_all_no_match_miss() { failure_reason = "failed to place no match miss "_cs + u_id.build_name(); LOG4(failure_reason); return false; - } else { - no_match_tables_allocated++; } } } diff --git a/backends/tofino/bf-p4c/mau/tofino/memories.h b/backends/tofino/bf-p4c/mau/tofino/memories.h index d6f5f100dc..8bc9df7e05 100644 --- a/backends/tofino/bf-p4c/mau/tofino/memories.h +++ b/backends/tofino/bf-p4c/mau/tofino/memories.h @@ -112,7 +112,7 @@ struct Memories : public ::Memories { int hash_group = 0; // Each hash function requires a different hash function bool init = false; - search_bus_info() {} + search_bus_info() = default; search_bus_info(cstring n, int ws, int hg) : name(n), width_section(ws), hash_group(hg), init(true) {} @@ -392,7 +392,7 @@ struct Memories : public ::Memories { : ta(t), depth(d), number(n), type(ty) {} SRAM_group(table_alloc *t, int d, int w, int n, int h, type_t ty) : ta(t), depth(d), width(w), number(n), hash_group(h), type(ty) {} - void dbprint(std::ostream &out) const; + void dbprint(std::ostream &out) const override; search_bus_info build_search_bus(int width_sect) const { return search_bus_info(ta->table->name, width_sect, hash_group); } @@ -413,11 +413,8 @@ struct Memories : public ::Memories { return type == STATS || type == METER || type == REGISTER || type == SELECTOR; } bool sel_act_placed(SRAM_group *corr) { - if (type == ACTION && sel.sel_linked() && sel.is_sel_corr_group(corr) && - corr->sel.action_all_placed()) - return true; - else - return false; + return type == ACTION && sel.sel_linked() && sel.is_sel_corr_group(corr) && + corr->sel.action_all_placed(); } int RAMs_required() const { if (type == SELECTOR) { @@ -689,23 +686,23 @@ struct Memories : public ::Memories { friend std::ostream &operator<<(std::ostream &, const safe_vector &); public: - bool allocate_all(); - bool allocate_all_dummies(); - void update(cstring name, const Use &alloc); - void update(const std::map &alloc); - void remove(cstring name, const Use &alloc); - void remove(const std::map &alloc); - void clear(); + bool allocate_all() override; + bool allocate_all_dummies() override; + void update(cstring name, const Use &alloc) override; + void update(const std::map &alloc) override; + void remove(cstring name, const Use &alloc) override; + void remove(const std::map &alloc) override; + void clear() override; void add_table(const IR::MAU::Table *t, const IR::MAU::Table *gw, TableResourceAlloc *resources, const LayoutOption *lo, const ActionData::Format::Use *af, ActionData::FormatType_t ft, int entries, int stage_table, - attached_entries_t attached_entries); - void shrink_allowed_lts() { logical_tables_allowed--; } - void fill_placed_scm_table(const IR::MAU::Table *, const TableResourceAlloc *) { + attached_entries_t attached_entries) override; + void shrink_allowed_lts() override { logical_tables_allowed--; } + void fill_placed_scm_table(const IR::MAU::Table *, const TableResourceAlloc *) override { BUG("SCM Not supported on this device"); } - void printOn(std::ostream &) const; - void visitUse(const Use &, std::function fn); + void printOn(std::ostream &) const override; + void visitUse(const Use &, std::function fn) override; const ordered_map collect_sram_block_alloc_info() override { const BFN::Alloc2Dbase *arrays[] = {&tcam_use, &sram_print_search_bus, diff --git a/backends/tofino/bf-p4c/mau/validate_actions.h b/backends/tofino/bf-p4c/mau/validate_actions.h index 14f44f040b..05204e1ce8 100644 --- a/backends/tofino/bf-p4c/mau/validate_actions.h +++ b/backends/tofino/bf-p4c/mau/validate_actions.h @@ -24,7 +24,7 @@ #include "ir/visitor.h" class PhvInfo; -class ReductionOrInfo; +struct ReductionOrInfo; class ValidateActions final : public MauInspector { private: diff --git a/backends/tofino/bf-p4c/mau/walk_power_graph.cpp b/backends/tofino/bf-p4c/mau/walk_power_graph.cpp index ff597970d0..7a727149c5 100644 --- a/backends/tofino/bf-p4c/mau/walk_power_graph.cpp +++ b/backends/tofino/bf-p4c/mau/walk_power_graph.cpp @@ -940,7 +940,6 @@ void WalkPowerGraph::print_worst_power(std::ofstream &out) const { #ifdef BAREFOOT_INTERNAL int itot_sramr = 0, itot_sramw = 0, itot_tcams = 0; - double itot_power = 0.0; #endif for (int stage = 0; stage < Device::numStages(); ++stage) { @@ -982,7 +981,6 @@ void WalkPowerGraph::print_worst_power(std::ofstream &out) const { itot_sramr += pma.ram_read; itot_sramw += pma.ram_write; itot_tcams += pma.tcam_read; - itot_power += tpwr; #endif std::stringstream line; diff --git a/backends/tofino/bf-p4c/midend/drop_packet_with_mirror_engine.cpp b/backends/tofino/bf-p4c/midend/drop_packet_with_mirror_engine.cpp index 9ea13bbaa7..290a10bd8d 100644 --- a/backends/tofino/bf-p4c/midend/drop_packet_with_mirror_engine.cpp +++ b/backends/tofino/bf-p4c/midend/drop_packet_with_mirror_engine.cpp @@ -115,8 +115,8 @@ const IR::Node *DropPacketWithMirrorEngine_::postorder(IR::BFN::TnaDeparser *dp) new IR::Member(new IR::PathExpression(igIntrMdForDprsrName), "mirror_type"), new IR::Constant(IR::Type::Bits::get(Device::mirrorTypeWidth()), 0)), new IR::MethodCallStatement( - {new IR::MethodCallExpression(new IR::Member(new IR::PathExpression(name), "emit"), - emit_invalid_mirror_session_args)}), + new IR::MethodCallExpression(new IR::Member(new IR::PathExpression(name), "emit"), + emit_invalid_mirror_session_args)), nullptr); // prepend Mirror() mirror to deparser statements; diff --git a/backends/tofino/bf-p4c/midend/move_to_egress.cpp b/backends/tofino/bf-p4c/midend/move_to_egress.cpp index 69167a4c6e..4cd95f76a0 100644 --- a/backends/tofino/bf-p4c/midend/move_to_egress.cpp +++ b/backends/tofino/bf-p4c/midend/move_to_egress.cpp @@ -68,7 +68,7 @@ MoveToEgress::MoveToEgress(BFN::EvaluatorPass *ev) } } }, - [this](const IR::Node *root) { + [](const IR::Node *root) { if (LOGGING(5)) dump(::Log::Detail::fileLogOutput(__FILE__), root); else diff --git a/backends/tofino/bf-p4c/midend/ping_pong_generation.h b/backends/tofino/bf-p4c/midend/ping_pong_generation.h index 495d9c28b2..e8e75970d8 100644 --- a/backends/tofino/bf-p4c/midend/ping_pong_generation.h +++ b/backends/tofino/bf-p4c/midend/ping_pong_generation.h @@ -181,7 +181,6 @@ class PingPongGeneration : public PassManager { */ class CheckPingPongTables : public Inspector { PingPongGeneration &self; - unsigned pipes = 0; // Finds ghost_metadata structure presence bool preorder(const IR::Type_Header *) override; diff --git a/backends/tofino/bf-p4c/midend/table_mutex.h b/backends/tofino/bf-p4c/midend/table_mutex.h index 2b6f0f80de..6ccb8c6174 100644 --- a/backends/tofino/bf-p4c/midend/table_mutex.h +++ b/backends/tofino/bf-p4c/midend/table_mutex.h @@ -28,7 +28,7 @@ * after running this pass, the operator() method can be used to query iff * two tables arte mutalluy exclusive */ class TableMutex : public Inspector, public ControlFlowVisitor, public P4::ResolutionContext { - TableMutex *clone() const { return new TableMutex(*this); } + TableMutex *clone() const override { return new TableMutex(*this); } void flow_merge(Visitor &) override; void flow_copy(ControlFlowVisitor &) override; struct Shared; diff --git a/backends/tofino/bf-p4c/parde/check_parser_multi_write.cpp b/backends/tofino/bf-p4c/parde/check_parser_multi_write.cpp index 9833754504..d4d95ad962 100644 --- a/backends/tofino/bf-p4c/parde/check_parser_multi_write.cpp +++ b/backends/tofino/bf-p4c/parde/check_parser_multi_write.cpp @@ -472,7 +472,7 @@ struct InferWriteMode : public ParserTransform { // granularity // FIXME: this can be done if all extracts to the given byte are eliminated bool partial = - std::any_of(writes.begin(), writes.end(), [this](const IR::BFN::ParserPrimitive *pr) { + std::any_of(writes.begin(), writes.end(), [](const IR::BFN::ParserPrimitive *pr) { auto range = get_extract_range(pr); return range && (!range->isLoAligned() || !range->isHiAligned()); }); @@ -611,7 +611,6 @@ bool CheckWriteModeConsistency::check(const std::vectorwrite_mode != first_mode) { consistent = false; } - bitwise_or |= e->write_mode == WrMode::BITWISE_OR; clear_on_write |= e->write_mode == WrMode::CLEAR_ON_WRITE; } diff --git a/backends/tofino/bf-p4c/parde/check_parser_multi_write.h b/backends/tofino/bf-p4c/parde/check_parser_multi_write.h index 2a382815cd..6767fb84a2 100644 --- a/backends/tofino/bf-p4c/parde/check_parser_multi_write.h +++ b/backends/tofino/bf-p4c/parde/check_parser_multi_write.h @@ -33,9 +33,10 @@ using namespace P4; * @brief Checks multiple writes to the same field on non-mutually exclusive paths. */ -struct CheckParserMultiWrite : public PassManager { +class CheckParserMultiWrite : public PassManager { const PhvInfo &phv; + public: explicit CheckParserMultiWrite(const PhvInfo &phv); }; diff --git a/backends/tofino/bf-p4c/parde/lowered/compute_lowered_deparser_ir.cpp b/backends/tofino/bf-p4c/parde/lowered/compute_lowered_deparser_ir.cpp index 0e4272e308..426a44c234 100644 --- a/backends/tofino/bf-p4c/parde/lowered/compute_lowered_deparser_ir.cpp +++ b/backends/tofino/bf-p4c/parde/lowered/compute_lowered_deparser_ir.cpp @@ -96,7 +96,6 @@ ComputeLoweredDeparserIR::getPartialUnit(const IR::BFN::EmitChecksum *emitChecks } } if (newGroup) groups[newGroup] = lastPov; - int groupidx = 0; for (auto &group : groups) { phvSources.clear(); clotSources.clear(); @@ -116,7 +115,6 @@ ComputeLoweredDeparserIR::getPartialUnit(const IR::BFN::EmitChecksum *emitChecks clots.push_back(input); } } - groupidx++; } unitConfig->povBit = lowerSingleBit(phv, emitChecksum->povBit, PHV::AllocContext::DEPARSER); } diff --git a/backends/tofino/bf-p4c/parde/marshal.h b/backends/tofino/bf-p4c/parde/marshal.h index 98e116d259..af8b49efb7 100644 --- a/backends/tofino/bf-p4c/parde/marshal.h +++ b/backends/tofino/bf-p4c/parde/marshal.h @@ -40,7 +40,7 @@ struct MarshaledFrom { size_t pre_padding; // size_t post_padding; - std::string toString() const; + [[nodiscard]] std::string toString() const; bool operator==(const MarshaledFrom &other) const { return gress == other.gress && field_name == other.field_name && @@ -54,7 +54,7 @@ struct MarshaledFrom { friend std::ostream &operator<<(std::ostream &s, const MarshaledFrom &m); friend P4::JSONGenerator &operator<<(P4::JSONGenerator &out, const MarshaledFrom &c); - MarshaledFrom() : gress(INGRESS), field_name(""), pre_padding(0) {} + MarshaledFrom() : gress(INGRESS), field_name(cstring::empty), pre_padding(0) {} MarshaledFrom(gress_t gress, cstring name) : gress(gress), field_name(name), pre_padding(0) {} MarshaledFrom(gress_t gress, cstring name, size_t pre_padding) : gress(gress), field_name(name), pre_padding(pre_padding) {} diff --git a/backends/tofino/bf-p4c/parde/parde_utils.h b/backends/tofino/bf-p4c/parde/parde_utils.h index b7c6936eff..08fe169a8e 100644 --- a/backends/tofino/bf-p4c/parde/parde_utils.h +++ b/backends/tofino/bf-p4c/parde/parde_utils.h @@ -92,7 +92,7 @@ struct ShiftPacketRVal : Shift { return rval; } - IR::Node *postorder(IR::BFN::ChecksumSubtract *csum) { + IR::Node *postorder(IR::BFN::ChecksumSubtract *csum) override { auto *orig = getOriginal(); if (csum->source->range.loByte() % 2 != orig->source->range.loByte() % 2) { return new IR::BFN::ChecksumSubtract(csum->declName, csum->source, !csum->swap, @@ -101,7 +101,7 @@ struct ShiftPacketRVal : Shift { return csum; } - IR::Node *postorder(IR::BFN::ChecksumAdd *csum) { + IR::Node *postorder(IR::BFN::ChecksumAdd *csum) override { auto *orig = getOriginal(); if (csum->source->range.loByte() % 2 != orig->source->range.loByte() % 2) { return new IR::BFN::ChecksumAdd(csum->declName, csum->source, !csum->swap, diff --git a/backends/tofino/bf-p4c/phv/action_phv_constraints.cpp b/backends/tofino/bf-p4c/phv/action_phv_constraints.cpp index aac67637fa..32ffd16937 100644 --- a/backends/tofino/bf-p4c/phv/action_phv_constraints.cpp +++ b/backends/tofino/bf-p4c/phv/action_phv_constraints.cpp @@ -3036,7 +3036,8 @@ bool ActionPhvConstraints::is_aligned(const PHV::Allocation::MutuallyLiveSlices auto reads = constraint_tracker.sources(slice, action); BUG_CHECK(reads.size() > 0, "Slice %1% must be written in action %2%", slice, action->name); for (auto operand : reads) { - BUG_CHECK(operand.phv_used->field(), "There must be a field read for slice %1%", slice); + BUG_CHECK(operand.phv_used.has_value() && operand.phv_used->field() != nullptr, + "There must be a field read for slice %1%", slice); for (const int stage : stages(action, slice.isPhysicalStageBased())) { ordered_set per_source_slices = alloc.slices(operand.phv_used->field(), operand.phv_used->range(), stage, diff --git a/backends/tofino/bf-p4c/phv/allocate_phv.cpp b/backends/tofino/bf-p4c/phv/allocate_phv.cpp index 02d233a1c2..74c1edb345 100644 --- a/backends/tofino/bf-p4c/phv/allocate_phv.cpp +++ b/backends/tofino/bf-p4c/phv/allocate_phv.cpp @@ -2233,11 +2233,9 @@ bool CoreAllocation::try_pack_slice_list( LOG_DEBUG5(TAB3 "Found field in another slice list."); int offset = 0; bool absolute = false; - int size = 0; std::optional requiredContainer = std::nullopt; std::map bitPositions; for (auto &slice : **slice_list) { - size += slice.range().size(); if (kv_source.second.find(slice) == kv_source.second.end()) { bitPositions[slice] = offset; offset += slice.range().size(); diff --git a/backends/tofino/bf-p4c/phv/allocate_phv.h b/backends/tofino/bf-p4c/phv/allocate_phv.h index 31e59a76af..cd0fd209af 100644 --- a/backends/tofino/bf-p4c/phv/allocate_phv.h +++ b/backends/tofino/bf-p4c/phv/allocate_phv.h @@ -52,7 +52,8 @@ namespace PHV { /// AllocUtils is a collection of const references to misc passes that PHV allocation depends on. /// It also provides some helper methods that are used by different allocation strategies. -struct AllocUtils { +class AllocUtils { + public: // PHV fields and clot info. const PhvInfo &phv; const ClotInfo &clot; diff --git a/backends/tofino/bf-p4c/phv/allocate_temps_and_finalize_liverange.cpp b/backends/tofino/bf-p4c/phv/allocate_temps_and_finalize_liverange.cpp index cbf3754e9b..a129450f39 100644 --- a/backends/tofino/bf-p4c/phv/allocate_temps_and_finalize_liverange.cpp +++ b/backends/tofino/bf-p4c/phv/allocate_temps_and_finalize_liverange.cpp @@ -146,26 +146,28 @@ AllocateTempsAndFinalizeLiverange::AllocateTempsAndFinalizeLiverange(PhvInfo &ph const auto get_temp_vars = [finalize_lr]() { return finalize_lr->unallocated_temp_var_live_ranges(); }; - addPasses({pragma_no_init, tb_mutex, - new PassIf([this] { return ts_i.getActualState() == State::FAILURE; }, - {new UpdateDeparserStage(phv_i)}), - finalize_lr, - new PassIf([get_temp_vars]() { return !get_temp_vars().empty(); }, - { - new VisitFunctor([get_temp_vars, &phv]() { - auto rst = allocate_temp_vars(phv, get_temp_vars()); - if (!rst.ok) { - error("Failed to allocated temp vars: %1%", rst.err.str()); - } - }), - // TODO: even if temp var allocation does not introduce - // a container conflict, the table layout does not have the - // correct action data as this temp var was not allocated during last - // TP. So we need to redo table placement. - new VisitFunctor([]() { - throw TablePlacement::FinalRerunTablePlacementTrigger(false); - }), - })}); + addPasses({ + pragma_no_init, + tb_mutex, + new PassIf([this] { return ts_i.getActualState() == State::FAILURE; }, + {new UpdateDeparserStage(phv_i)}), + finalize_lr, + new PassIf([get_temp_vars]() { return !get_temp_vars().empty(); }, + { + new VisitFunctor([get_temp_vars, &phv]() { + auto rst = allocate_temp_vars(phv, get_temp_vars()); + if (!rst.ok) { + error("Failed to allocated temp vars: %1%", rst.err.str()); + } + }), + // TODO: even if temp var allocation does not introduce + // a container conflict, the table layout does not have the + // correct action data as this temp var was not allocated during last + // TP. So we need to redo table placement. + new VisitFunctor( + []() { throw TablePlacement::FinalRerunTablePlacementTrigger(false); }), + }), + }); } } // namespace PHV diff --git a/backends/tofino/bf-p4c/phv/analysis/header_mutex.h b/backends/tofino/bf-p4c/phv/analysis/header_mutex.h index 17c8dfb6c0..bd8489717d 100644 --- a/backends/tofino/bf-p4c/phv/analysis/header_mutex.h +++ b/backends/tofino/bf-p4c/phv/analysis/header_mutex.h @@ -263,8 +263,8 @@ class FieldLevelOptimisation : public Inspector { ordered_map table_to_index; ordered_map index_to_table; - bool preorder(const IR::MAU::Table *table); - bool preorder(const IR::Expression *expression); + bool preorder(const IR::MAU::Table *table) override; + bool preorder(const IR::Expression *expression) override; ordered_set get_tables(bitvec tables_bv); ordered_set get_fields(bitvec fields_bv); diff --git a/backends/tofino/bf-p4c/phv/collect_strided_headers.h b/backends/tofino/bf-p4c/phv/collect_strided_headers.h index 420a0232b2..06c32ae151 100644 --- a/backends/tofino/bf-p4c/phv/collect_strided_headers.h +++ b/backends/tofino/bf-p4c/phv/collect_strided_headers.h @@ -32,7 +32,7 @@ struct CollectStridedHeaders : public Inspector { explicit CollectStridedHeaders(PhvInfo &p) : phv(p) {} - bool preorder(const IR::HeaderStack *hs) { + bool preorder(const IR::HeaderStack *hs) override { auto state = findContext(); if (state && state->stride) { diff --git a/backends/tofino/bf-p4c/phv/phv_fields.cpp b/backends/tofino/bf-p4c/phv/phv_fields.cpp index a601ebf38a..9d2f42115e 100644 --- a/backends/tofino/bf-p4c/phv/phv_fields.cpp +++ b/backends/tofino/bf-p4c/phv/phv_fields.cpp @@ -436,14 +436,12 @@ void PhvInfo::allocatePOV(const BFN::HeaderStackInfo &stacks) { pov_alloc_done = true; int size[GRESS_T_COUNT] = {0, 0, 0}; - int stacks_num = 0; for (auto &stack : stacks) { StructInfo info = struct_info(stack.name); LOG3(" ...preanalyzing header stack " << stack.name << " (" << info.gress << ")"); BUG_CHECK(!info.metadata, "metadata stack?"); size[info.gress] += stack.size + stack.maxpush + stack.maxpop; // size for $stkvalid size[info.gress] += stack.size; // size for $valid - stacks_num++; } for (auto &hdr : simple_headers) { @@ -1563,7 +1561,7 @@ struct ComputeFieldAlignments : public Inspector { return false; } - bool preorder(const IR::MAU::Instruction *instr) { + bool preorder(const IR::MAU::Instruction *instr) override { Log::TempIndent indent; LOG5("Preorder Instruction: " << *instr << " name: " << instr->name << indent); PHV::Field *dst_f; diff --git a/backends/tofino/bf-p4c/phv/phv_fields.h b/backends/tofino/bf-p4c/phv/phv_fields.h index 2107a96f96..00826fe1e3 100644 --- a/backends/tofino/bf-p4c/phv/phv_fields.h +++ b/backends/tofino/bf-p4c/phv/phv_fields.h @@ -1752,7 +1752,8 @@ class CollectExtractedTogetherFields : public Inspector { }; /// Map field to the parser states in which they are extracted or assigned from checksums. -struct MapFieldToParserStates : public Inspector { +class MapFieldToParserStates : public Inspector { + public: const PhvInfo &phv_i; ordered_map> diff --git a/backends/tofino/bf-p4c/phv/pragma/pa_byte_pack.cpp b/backends/tofino/bf-p4c/phv/pragma/pa_byte_pack.cpp index 97a5114995..47ae1d5410 100644 --- a/backends/tofino/bf-p4c/phv/pragma/pa_byte_pack.cpp +++ b/backends/tofino/bf-p4c/phv/pragma/pa_byte_pack.cpp @@ -90,7 +90,6 @@ bool PragmaBytePack::preorder(const IR::BFN::Pipe *pipe) { // Extract the rest of the arguments bool ignore = false; - int n_bits = 0; PackConstraint pack; pack.compiler_added = false; pack.src_info = annotation->getSourceInfo(); @@ -134,7 +133,6 @@ bool PragmaBytePack::preorder(const IR::BFN::Pipe *pipe) { ignore = true; break; } - n_bits += pack.packing.layout.back().size(); } if (!ignore) { diff --git a/backends/tofino/bf-p4c/phv/v2/metadata_initialization.cpp b/backends/tofino/bf-p4c/phv/v2/metadata_initialization.cpp index cf87bdda57..ae9953d357 100644 --- a/backends/tofino/bf-p4c/phv/v2/metadata_initialization.cpp +++ b/backends/tofino/bf-p4c/phv/v2/metadata_initialization.cpp @@ -127,7 +127,7 @@ class WriteTableInfo : public BFN::ControlFlowVisitor, public MauInspector, Tofi return Inspector::init_apply(root); } - void end_apply() { + void end_apply() override { if (LOGGING(5)) { LOG5("After Write Table List:"); for (const auto &f : phv) { @@ -541,12 +541,12 @@ class CollectPOVProtectedField : public Inspector { public: ordered_set pov_protected_fields; const PhvInfo &phv; - bool preorder(const IR::BFN::DeparserParameter *param) { + bool preorder(const IR::BFN::DeparserParameter *param) override { if (param->source) pov_protected_fields.insert(phv.field(param->source->field)); return false; } - bool preorder(const IR::BFN::Digest *digest) { + bool preorder(const IR::BFN::Digest *digest) override { pov_protected_fields.insert(phv.field(digest->selector->field)); return false; } @@ -738,7 +738,7 @@ class TableFlowGraphBuilder : public Inspector { LOG4("Table Flow Graph:"); LOG4(graph); } - Visitor::profile_t init_apply(const IR::Node *root) { + Visitor::profile_t init_apply(const IR::Node *root) override { profile_t rv = Inspector::init_apply(root); graph.clear(); placement_stages = Device::numStages();