Skip to content

Commit

Permalink
More Tofino include fixes. (#5006)
Browse files Browse the repository at this point in the history
* Remove include_directories from CMake.

Signed-off-by: fruffy <fruffy@nyu.edu>

* Fix includes.

Signed-off-by: fruffy <fruffy@nyu.edu>

---------

Signed-off-by: fruffy <fruffy@nyu.edu>
  • Loading branch information
fruffy authored Nov 26, 2024
1 parent 70694bc commit a3583db
Show file tree
Hide file tree
Showing 72 changed files with 151 additions and 191 deletions.
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
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/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
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
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
12 changes: 6 additions & 6 deletions backends/tofino/bf-p4c/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
#ifndef BACKENDS_TOFINO_BF_P4C_DEVICE_H_
#define BACKENDS_TOFINO_BF_P4C_DEVICE_H_

#include "arch/arch_spec.h"
#include "ir/gress.h"
#include "backends/tofino/bf-p4c/arch/arch_spec.h"
#include "backends/tofino/bf-p4c/ir/gress.h"
#include "backends/tofino/bf-p4c/mau/mau_spec.h"
#include "backends/tofino/bf-p4c/mau/power_spec.h"
#include "backends/tofino/bf-p4c/parde/parde_spec.h"
#include "backends/tofino/bf-p4c/phv/phv_spec.h"
#include "lib/cstring.h"
#include "lib/exceptions.h"
#include "lib/range.h"
#include "mau/mau_spec.h"
#include "mau/power_spec.h"
#include "parde/parde_spec.h"
#include "phv/phv_spec.h"

class Device {
public:
Expand Down
12 changes: 5 additions & 7 deletions backends/tofino/bf-p4c/logging/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Copyright (C) 2024 Intel Corporation
#
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy
# of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
#
#
#
#
# SPDX-License-Identifier: Apache-2.0

find_package(PkgConfig QUIET)
Expand Down Expand Up @@ -48,8 +48,6 @@ add_custom_command(OUTPUT ${GEN_LOGGING_HDRS}
add_custom_target(genLogging
DEPENDS ${GEN_LOGGING_HDRS})

include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/..
${CMAKE_CURRENT_BINARY_DIR} ${LIBRAPIDJSON_INCLUDE_DIRS})
add_executable(test_phv_logging test_phv.cpp ${BFN_P4C_SOURCE_DIR}/bf-p4c/common/run_id.cpp)
add_dependencies(test_phv_logging genLogging)
target_link_libraries(test_phv_logging PRIVATE absl::strings)
Expand Down
2 changes: 1 addition & 1 deletion backends/tofino/bf-p4c/logging/bf_error_reporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <numeric>
#include <regex>

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

static bool has_output_already_been_silenced = false;
Expand Down
2 changes: 1 addition & 1 deletion backends/tofino/bf-p4c/logging/constrained_fields.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

#include <map>

#include "backends/tofino/bf-p4c/logging/phv_schema.h"
#include "backends/tofino/bf-p4c/phv/phv_fields.h"
#include "backends/tofino/bf-p4c/phv/utils/utils.h"
#include "phv_schema.h"

/**
* \brief Class with handle for logging constraints
Expand Down
6 changes: 3 additions & 3 deletions backends/tofino/bf-p4c/logging/event_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include "event_logger.h"
#include "backends/tofino/bf-p4c/logging/event_logger.h"

#include <rapidjson/prettywriter.h>
#include <spdlog/sinks/basic_file_sink.h>
Expand All @@ -25,8 +25,8 @@

#include <ctime>

#include "event_log_schema.h"
#include "rapidjson_adapter.h"
#include "backends/tofino/bf-p4c/logging/event_log_schema.h"
#include "backends/tofino/bf-p4c/logging/rapidjson_adapter.h"

#ifndef EVENT_LOG_SCHEMA_VERSION
#error "event_logger.cpp: EVENT_LOG_SCHEMA_VERSION is not defined!"
Expand Down
2 changes: 1 addition & 1 deletion backends/tofino/bf-p4c/logging/generate_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ def genPreamble(self):
self.write('#include <memory>\n')
self.write('#include <string>\n')
self.write('#include <vector>\n')
self.write('#include <logging.h>\n')
self.write('\n#include \"backends/tofino/bf-p4c/logging/logging.h\"\n\n')
self.write('namespace Logging {\n')
self.write('\n')

Expand Down
4 changes: 2 additions & 2 deletions backends/tofino/bf-p4c/logging/manifest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
#include <filesystem>
#include <string>

#include "../git_sha_version.h" // for BF_P4C_GIT_SHA
#include "backends/graphs/controls.h"
#include "backends/graphs/graph_visitor.h"
#include "backends/graphs/parsers.h"
#include "backends/tofino/bf-p4c/common/run_id.h"
#include "backends/tofino/bf-p4c/version.h" // for BF_P4C_VERSION
#include "backends/tofino/bf-p4c/git_sha_version.h" // for BF_P4C_GIT_SHA
#include "backends/tofino/bf-p4c/version.h" // for BF_P4C_VERSION
#include "ir/ir.h"

using Manifest = Logging::Manifest;
Expand Down
Loading

0 comments on commit a3583db

Please sign in to comment.