Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix many Tofino warnings. #5007

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 26 additions & 49 deletions backends/tofino/bf-p4c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@

MESSAGE("-- Adding p4c-barefoot")

# Set dynamic hash include directory
set(LIBDYNHASH_INCLUDE_DIR "${BFN_P4C_SOURCE_DIR}/bf-utils/include")
include_directories(${LIBDYNHASH_INCLUDE_DIR})

# An option to configure the chunk size we use for unified builds in bf-p4c. By
# default, this is tuned to use smaller chunks than the p4c repo uses. The goal
# is to gain most of the benefit of unified builds when many files change, while
Expand Down Expand Up @@ -87,24 +83,12 @@ get_schema_version(resources_schema RESOURCES_SCHEMA_VERSION)
MESSAGE(STATUS "Found source info schema version ${RESOURCES_SCHEMA_VERSION}")
add_definitions("-DRESOURCES_SCHEMA_VERSION=\"${RESOURCES_SCHEMA_VERSION}\"")

include_directories(${BFN_P4C_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
${Boost_INCLUDE_DIRS} ${LIBDYNHASH_INCLUDE_DIR} ${Z3_INCLUDE_DIR} )
# The generated code for protobuf has an excessive number of warnings so we
# include the build directory as a system directory
include_directories(SYSTEM ${P4C_BINARY_DIR}/control-plane)
set (HAVE_LIBBOOST_GRAPH 1)
message(STATUS "Z3_LIBRARY value: ${Z3_LIB}")

set (P4C_LIB_DEPS "${P4C_LIB_DEPS};${Boost_GRAPH_LIBRARY};${LIBDYNHASH_LIBRARY};${Z3_LIB}")
set (P4C_LIB_DEPS ${P4C_LIB_DEPS} PARENT_SCOPE)

add_subdirectory(logging)
include_directories(logging)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/logging)

set_source_files_properties(${BF_P4C_IR_SRCS} PROPERTIES
COMPILE_FLAGS "-I${Z3_INCLUDE_DIR}")

set (BF_P4C_MIDEND_SRCS
midend/annotate_with_in_hash.cpp
Expand Down Expand Up @@ -977,12 +961,16 @@ if(BUILD_STATIC_BFP4C_LIBS)
else()
add_library(tofinobackend OBJECT ${BF_P4C_SOURCES})
endif()
target_link_libraries(tofinobackend PRIVATE absl::prefetch ${P4C_LIB_DEPS} ir)
target_link_libraries(tofinobackend PRIVATE absl::prefetch ${P4C_LIB_DEPS} controlplane-gen ir)
target_include_directories(
tofinobackend
# We also export Z3's includes with the common library.
# This is necessary because the z3 target itself does not export its includes.
SYSTEM BEFORE PUBLIC ${Z3_INCLUDE_DIR}
# FIXME: This should be pulled with FetchContent.
PRIVATE "${BFN_P4C_SOURCE_DIR}/third_party/spdlog/include"
)
add_dependencies(tofinobackend ir-generated frontend genLogging bfn_p4runtime)
target_include_directories(tofinobackend PRIVATE "${BFN_P4C_SOURCE_DIR}/third_party/spdlog/include")
foreach(dir ${Protobuf_INCLUDE_DIRS})
target_include_directories(tofinobackend SYSTEM BEFORE PUBLIC ${dir})
endforeach()

if(BUILD_STATIC_BFP4C_LIBS)
add_library(bfp4c STATIC ${P4C_BAREFOOT_SRCS})
Expand All @@ -993,7 +981,6 @@ else()
endif()
target_link_libraries (bfp4c tofinobackend bfn_p4runtime
${P4C_LIBRARIES} ${P4C_LIB_DEPS} ${CMAKE_THREAD_LIBS_INIT})

# XXX These compile definitions and include directories should be inherited
# XXX from bfp4c's dependencies, but these CMake files aren't very modular.
target_compile_definitions(bfp4c
Expand All @@ -1011,25 +998,6 @@ if (ENABLE_BAREFOOT_INTERNAL)
INTERFACE "-DBAREFOOT_INTERNAL=1"
)
endif()
target_include_directories(bfp4c
INTERFACE ${LIBDYNHASH_INCLUDE_DIR}
INTERFACE ${PROTOBUF_INCLUDE_DIRS}
INTERFACE ${P4C_SOURCE_DIR}/frontends
INTERFACE ${P4C_SOURCE_DIR}/backends
INTERFACE ${P4C_SOURCE_DIR}/extensions
INTERFACE ${P4C_SOURCE_DIR}
INTERFACE ${P4C_BINARY_DIR}
INTERFACE ${BFN_P4C_SOURCE_DIR}
INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}
)
target_include_directories(bfp4c
SYSTEM INTERFACE ${P4C_BINARY_DIR}/control-plane
)
target_include_directories(bfp4c
INTERFACE logging
INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/logging
INTERFACE ${CMAKE_SOURCE_DIR}/third_party/spdlog/include
)

if(BUILD_STATIC_BFP4C_LIBS)
add_executable(p4c-barefoot p4c-barefoot.cpp)
Expand All @@ -1055,6 +1023,15 @@ else()
add_executable(p4c-barefoot p4c-barefoot.cpp $<TARGET_OBJECTS:bfp4c>
$<TARGET_OBJECTS:tofinobackend> $<TARGET_OBJECTS:bfn_p4runtime>)
target_link_libraries(p4c-barefoot ${P4C_LIBRARIES} ${P4C_LIB_DEPS} ${CMAKE_THREAD_LIBS_INIT})
# FIXME: These includes should be exported by earlier libraries.
target_include_directories(
p4c-barefoot
# We also export Z3's includes with the common library.
# This is necessary because the z3 target itself does not export its includes.
SYSTEM BEFORE PUBLIC ${Z3_INCLUDE_DIR}
# FIXME: This should be pulled with FetchContent.
PRIVATE "${BFN_P4C_SOURCE_DIR}/third_party/spdlog/include"
)
endif()


Expand Down Expand Up @@ -1291,12 +1268,9 @@ if(BUILD_STATIC_BFP4C_LIBS)
else()
add_library(bfn_p4runtime OBJECT ${BFN_P4RUNTIME_INFO_GEN_SRCS})
endif()
target_link_libraries(bfn_p4runtime PRIVATE absl::prefetch)
target_link_libraries(bfn_p4runtime PUBLIC controlplane-gen PRIVATE absl::prefetch)
set_source_files_properties(${BFN_P4RUNTIME_INFO_GEN_SRCS} PROPERTIES GENERATED TRUE)
add_dependencies(bfn_p4runtime barefootdir controlplane)
foreach(dir ${Protobuf_INCLUDE_DIRS})
target_include_directories(bfn_p4runtime SYSTEM BEFORE PUBLIC ${dir})
endforeach()

################ Testing

Expand Down Expand Up @@ -1377,7 +1351,12 @@ if (ENABLE_GTESTS)
# test_bf_gtest_helpers should be in its own testlib - & requies 'whole_archive' hack!
# Leave it in GTEST_BF_P4C_SOURCES for now.
target_link_libraries (bf_gtest_support PRIVATE absl::flat_hash_map PRIVATE absl::flat_hash_set PRIVATE ir ${P4C_LIB_DEPS})
target_include_directories (bf_gtest_support PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/test/gtest}" PRIVATE "${P4C_BINARY_DIR}")
target_include_directories(
bf_gtest_support
# We also export Z3's includes with the common library.
# This is necessary because the z3 target itself does not export its includes.
SYSTEM BEFORE PUBLIC ${Z3_INCLUDE_DIR}
)
add_dependencies (bf_gtest_support p4headers_h p4headers_cpp ir-generated gtest frontend-parser-gen) # Indirectly we #include "ir/gen-tree-macro.h" and "p4parser.hpp"

set (GTEST_BF_P4C_SOURCES
Expand Down Expand Up @@ -1502,7 +1481,5 @@ if (ENABLE_GTESTS)
endif(ENABLE_GTESTS)


set (EVEN_MORE_FILES_TO_LINT
p4c-barefoot.cpp
)
set(EVEN_MORE_FILES_TO_LINT p4c-barefoot.cpp)
add_cpplint_files(${CMAKE_CURRENT_SOURCE_DIR} "${EVEN_MORE_FILES_TO_LINT}")
1 change: 0 additions & 1 deletion backends/tofino/bf-p4c/arch/arch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include "frontends/p4/methodInstance.h"
#include "ir/declaration.h"
#include "ir/id.h"
#include "ir/ir-generated.h"
#include "lib/cstring.h"

namespace BFN {
Expand Down
1 change: 0 additions & 1 deletion backends/tofino/bf-p4c/arch/arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
#include "frontends/p4/typeChecking/typeChecker.h"
#include "frontends/p4/typeMap.h"
#include "frontends/p4/uniqueNames.h"
#include "ir/ir-generated.h"
#include "ir/ir.h"
#include "ir/namemap.h"
#include "ir/pass_manager.h"
Expand Down
2 changes: 1 addition & 1 deletion backends/tofino/bf-p4c/arch/arch_spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include "arch/arch_spec.h"
#include "backends/tofino/bf-p4c/arch/arch_spec.h"

ArchSpec::ArchSpec() {
// ingress_intrinsic_metadata_for_tm
Expand Down
2 changes: 1 addition & 1 deletion backends/tofino/bf-p4c/arch/collect_bridged_fields.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <optional>
#include <utility>

#include "ir/control_flow_visitor.h"
#include "backends/tofino/bf-p4c/ir/control_flow_visitor.h"
#include "ir/ir.h"
#include "lib/cstring.h"
#include "lib/ordered_map.h"
Expand Down
1 change: 0 additions & 1 deletion backends/tofino/bf-p4c/arch/fromv1.0/stateful_alu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 5 additions & 3 deletions backends/tofino/bf-p4c/arch/fromv1.0/v1_converters.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<IR::Declaration_Instance>(node);
}

const IR::Node *postorder(IR::MethodCallStatement *node) {
const IR::Node *postorder(IR::MethodCallStatement *node) override {
return substitute<IR::MethodCallStatement>(node);
}

const IR::Node *postorder(IR::Property *node) { return substitute<IR::Property>(node); }
const IR::Node *postorder(IR::Property *node) override {
return substitute<IR::Property>(node);
}

const IR::Node *postorder(IR::BFN::TnaControl *node) override;

Expand Down
2 changes: 1 addition & 1 deletion backends/tofino/bf-p4c/arch/psa/psa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<IR::P4Parser>();
CHECK_NULL(ctxt);
for (auto stmt : state->components) {
Expand Down
3 changes: 1 addition & 2 deletions backends/tofino/bf-p4c/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
* - BFN::CollectIXBarInfo
*/

#include "backend.h"
#include "backends/tofino/bf-p4c/backend.h"

#include <fstream>
#include <set>
Expand Down Expand Up @@ -128,7 +128,6 @@
#include "backends/tofino/bf-p4c/phv/split_padding.h"
#include "backends/tofino/bf-p4c/phv/utils/slice_alloc.h"
#include "backends/tofino/bf-p4c/phv/v2/metadata_initialization.h"
#include "ir/ir-generated.h"
#include "ir/pass_manager.h"
#include "lib/indent.h"

Expand Down
1 change: 0 additions & 1 deletion backends/tofino/bf-p4c/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#include "backends/tofino/bf-p4c/phv/phv_fields.h"
#include "backends/tofino/bf-p4c/phv/phv_parde_mau_use.h"
#include "backends/tofino/bf-p4c/phv/utils/live_range_report.h"
#include "bf-p4c-options.h"
#include "ir/ir.h"

class FieldDefUse;
Expand Down
2 changes: 1 addition & 1 deletion backends/tofino/bf-p4c/bf-p4c-options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include "bf-p4c-options.h"
#include "backends/tofino/bf-p4c/bf-p4c-options.h"

#include <libgen.h>

Expand Down
3 changes: 2 additions & 1 deletion backends/tofino/bf-p4c/common/bridged_packing.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#ifndef BACKENDS_TOFINO_BF_P4C_COMMON_BRIDGED_PACKING_H_
#define BACKENDS_TOFINO_BF_P4C_COMMON_BRIDGED_PACKING_H_

#include <z3++.h>

#include "backends/tofino/bf-p4c/bf-p4c-options.h"
#include "backends/tofino/bf-p4c/common/extract_maupipe.h"
#include "backends/tofino/bf-p4c/common/field_defuse.h"
Expand All @@ -37,7 +39,6 @@
#include "frontends/common/resolveReferences/resolveReferences.h"
#include "frontends/p4/methodInstance.h"
#include "frontends/p4/typeMap.h"
#include "z3++.h"

using namespace P4;

Expand Down
3 changes: 1 addition & 2 deletions backends/tofino/bf-p4c/common/extract_maupipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "backends/tofino/bf-p4c/arch/helpers.h"
#include "backends/tofino/bf-p4c/common/bridged_packing.h"
#include "backends/tofino/bf-p4c/common/pragma/collect_global_pragma.h"
#include "backends/tofino/bf-p4c/common/slice.h"
#include "backends/tofino/bf-p4c/common/utils.h"
#include "backends/tofino/bf-p4c/lib/safe_width.h"
#include "backends/tofino/bf-p4c/mau/mau_visitor.h"
Expand All @@ -45,12 +46,10 @@
#include "frontends/p4/externInstance.h"
#include "frontends/p4/methodInstance.h"
#include "ir/dbprint.h"
#include "ir/ir-generated.h"
#include "ir/ir.h"
#include "lib/algorithm.h"
#include "lib/error.h"
#include "lib/safe_vector.h"
#include "slice.h"

namespace BFN {

Expand Down
2 changes: 1 addition & 1 deletion backends/tofino/bf-p4c/common/field_defuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<IR::BFN::ParserState>() || lp.first->is<IR::BFN::Parser>()))
return false;
Expand Down
2 changes: 1 addition & 1 deletion backends/tofino/bf-p4c/common/scc_toposort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include <common/scc_toposort.h>
#include "backends/tofino/bf-p4c/common/scc_toposort.h"

#include <functional>
#include <queue>
Expand Down
22 changes: 10 additions & 12 deletions backends/tofino/bf-p4c/control-plane/bfruntime_arch_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
#include "frontends/p4/externInstance.h"
#include "frontends/p4/methodInstance.h"
#include "frontends/p4/typeMap.h"
#include "ir/ir-generated.h"
#include "lib/log.h"
#include "midend/eliminateTypedefs.h"

Expand Down Expand Up @@ -101,11 +100,11 @@ struct CounterlikeTraits<::BFN::CounterExtern<BFN::Arch::TNA>> {
/// CounterlikeTraits specialization for BFN::CounterExtern for PSA
template <>
struct CounterlikeTraits<::BFN::CounterExtern<BFN::Arch::PSA>> {
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")
Expand Down Expand Up @@ -520,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); }
};
Expand Down Expand Up @@ -2393,7 +2391,7 @@ class BFRuntimeArchHandlerPSA final : public BFRuntimeArchHandlerCommon<Arch::PS
implementationString = "psa_implementation"_cs;
}

void postCollect(const P4RuntimeSymbolTableIface &symbols) {
void postCollect(const P4RuntimeSymbolTableIface &symbols) override {
(void)symbols;
// analyze action profiles / selectors and build a mapping from action
// profile / selector name to the set of tables referencing them
Expand Down Expand Up @@ -2440,15 +2438,15 @@ class BFRuntimeArchHandlerPSA final : public BFRuntimeArchHandlerCommon<Arch::PS
collectExternInstanceCommon(symbols, externBlock);
}

void collectExternFunction(P4RuntimeSymbolTableIface *, const P4::ExternFunction *) {}
void collectExternFunction(P4RuntimeSymbolTableIface *, const P4::ExternFunction *) override {}

void addExternInstance(const P4RuntimeSymbolTableIface &symbols, p4configv1::P4Info *p4info,
const IR::ExternBlock *externBlock) {
const IR::ExternBlock *externBlock) override {
addExternInstanceCommon(symbols, p4info, externBlock, defaultPipeName);
}

void addExternFunction(const P4RuntimeSymbolTableIface &, p4configv1::P4Info *,
const P4::ExternFunction *) {}
const P4::ExternFunction *) override {}
};

/// The architecture handler builder implementation for Tofino.
Expand Down
2 changes: 1 addition & 1 deletion backends/tofino/bf-p4c/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include "device.h"
#include "backends/tofino/bf-p4c/device.h"

#include <algorithm>

Expand Down
Loading
Loading