From 3c882590dfffdc14c184dea03af66e91150bcf14 Mon Sep 17 00:00:00 2001 From: fruffy Date: Fri, 21 Oct 2022 14:10:18 -0400 Subject: [PATCH 1/9] Remove the unified build. Fix build. Missing build_unified. Clean up cmakelists. Fix build flags. Need to include GENERATED property. Wrap clashing variable names in appropriate namespace. Cpplint. Simplify CI. Aggressive batch size. Fix template. cpplint. Build fixes. Fixup. --- .github/workflows/ci-p4tools.yml | 4 +- .github/workflows/ci-ptf-kernels-weekly.yml | 3 +- .github/workflows/ci-ptf.yml | 2 +- .github/workflows/ci-static-build-test.yml | 2 +- .github/workflows/ci-test.yml | 14 +++--- .github/workflows/ci-validation.yml | 1 - CMakeLists.txt | 6 ++- Dockerfile | 2 +- backends/bmv2/CMakeLists.txt | 3 -- backends/ebpf/CMakeLists.txt | 1 - backends/graphs/CMakeLists.txt | 2 +- backends/p4test/CMakeLists.txt | 2 +- .../p4tools/modules/testgen/register.h.in | 4 +- .../bmv2/backend/protobuf/protobuf.cpp | 4 +- .../targets/bmv2/backend/protobuf/protobuf.h | 3 ++ .../testgen/targets/bmv2/backend/ptf/ptf.cpp | 4 +- .../testgen/targets/bmv2/backend/ptf/ptf.h | 3 ++ .../testgen/targets/bmv2/backend/stf/stf.cpp | 4 +- .../testgen/targets/bmv2/backend/stf/stf.h | 3 ++ .../modules/testgen/targets/bmv2/register.h | 4 +- .../testgen/targets/ebpf/backend/stf/stf.cpp | 4 +- .../testgen/targets/ebpf/backend/stf/stf.h | 3 ++ .../modules/testgen/targets/ebpf/register.h | 4 +- .../transformations/saturation_arithm.cpp | 4 +- .../testgen/test/z3-solver/expressions.cpp | 4 +- backends/ubpf/CMakeLists.txt | 2 +- cmake/UnifiedBuild.cmake | 2 +- control-plane/CMakeLists.txt | 1 - frontends/CMakeLists.txt | 5 ++- ir/CMakeLists.txt | 1 - lib/CMakeLists.txt | 2 +- midend/CMakeLists.txt | 2 +- midend/global_copyprop.cpp | 45 ++++++++++--------- midend/predication.cpp | 36 ++++++++------- test/CMakeLists.txt | 1 - tools/ci-build.sh | 4 +- tools/debian-build/packaging.conf | 2 +- tools/ir-generator/CMakeLists.txt | 1 - 38 files changed, 102 insertions(+), 92 deletions(-) diff --git a/.github/workflows/ci-p4tools.yml b/.github/workflows/ci-p4tools.yml index 6f0101d7cf6..77388b231ed 100644 --- a/.github/workflows/ci-p4tools.yml +++ b/.github/workflows/ci-p4tools.yml @@ -20,7 +20,7 @@ jobs: env: CTEST_PARALLEL_LEVEL: 4 IMAGE_TYPE: test - ENABLE_UNIFIED_COMPILATION: ON + CMAKE_UNITY_BUILD: ON ENABLE_TEST_TOOLS: ON steps: - uses: actions/checkout@v3 @@ -30,7 +30,7 @@ jobs: - name: ccache uses: hendrikmuhs/ccache-action@v1 with: - key: test-tools-${{ matrix.unified }}-${{ runner.os }} + key: test-tools-${{ runner.os }} max-size: 1000M - name: Build (Ubuntu 20.04) diff --git a/.github/workflows/ci-ptf-kernels-weekly.yml b/.github/workflows/ci-ptf-kernels-weekly.yml index b2a0baa5948..0a45a8c7a50 100644 --- a/.github/workflows/ci-ptf-kernels-weekly.yml +++ b/.github/workflows/ci-ptf-kernels-weekly.yml @@ -41,7 +41,6 @@ jobs: kernel_version: 5.15.0-48 os: ubuntu-20.04 env: - UNIFIED: ON # Used by virt-builder and virt-install, for valid values see `virt-builder --list`. OS_TYPE: ${{ matrix.os }} # List of kernels to use in a single job @@ -78,7 +77,7 @@ jobs: - name: Build (Linux) run: | - docker build --network host -t p4c --build-arg MAKEFLAGS=-j8 --build-arg IMAGE_TYPE=test --build-arg ENABLE_UNIFIED_COMPILATION=$UNIFIED --build-arg INSTALL_PTF_EBPF_DEPENDENCIES=ON --build-arg KERNEL_VERSIONS="$KERNEL_VERSIONS" . + docker build --network host -t p4c --build-arg MAKEFLAGS=-j8 --build-arg IMAGE_TYPE=test --build-arg CMAKE_UNITY_BUILD=ON --build-arg INSTALL_PTF_EBPF_DEPENDENCIES=ON --build-arg KERNEL_VERSIONS="$KERNEL_VERSIONS" . ./tools/export_ccache.sh - name: Install VM diff --git a/.github/workflows/ci-ptf.yml b/.github/workflows/ci-ptf.yml index 6c7698ad6e3..e0204a378c2 100644 --- a/.github/workflows/ci-ptf.yml +++ b/.github/workflows/ci-ptf.yml @@ -34,7 +34,7 @@ jobs: env: CTEST_PARALLEL_LEVEL: 4 IMAGE_TYPE: test - ENABLE_UNIFIED_COMPILATION: ON + CMAKE_UNITY_BUILD: ON MAKEFLAGS: -j8 INSTALL_PTF_EBPF_DEPENDENCIES: ON steps: diff --git a/.github/workflows/ci-static-build-test.yml b/.github/workflows/ci-static-build-test.yml index 9eb44876286..9bf3a688043 100644 --- a/.github/workflows/ci-static-build-test.yml +++ b/.github/workflows/ci-static-build-test.yml @@ -20,7 +20,7 @@ jobs: runs-on: ubuntu-20.04 env: IMAGE_TYPE: test - ENABLE_UNIFIED_COMPILATION: ON + CMAKE_UNITY_BUILD: ON BUILD_STATIC_RELEASE: ON steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml index f4cffb7b028..9c297a87d6e 100644 --- a/.github/workflows/ci-test.yml +++ b/.github/workflows/ci-test.yml @@ -20,7 +20,6 @@ jobs: env: CTEST_PARALLEL_LEVEL: 4 IMAGE_TYPE: test - ENABLE_UNIFIED_COMPILATION: ON steps: - uses: actions/checkout@v3 with: @@ -53,7 +52,7 @@ jobs: env: CTEST_PARALLEL_LEVEL: 4 IMAGE_TYPE: test - ENABLE_UNIFIED_COMPILATION: ${{ matrix.unified }} + CMAKE_UNITY_BUILD: ${{ matrix.unified }} steps: - uses: actions/checkout@v3 with: @@ -84,7 +83,6 @@ jobs: env: CTEST_PARALLEL_LEVEL: 2 IMAGE_TYPE: test - ENABLE_UNIFIED_COMPILATION: ON COMPILE_WITH_CLANG: ON BUILD_AUTO_VAR_INIT_PATTERN: ON ENABLE_SANITIZERS: ON @@ -117,7 +115,6 @@ jobs: runs-on: ubuntu-latest env: CTEST_PARALLEL_LEVEL: 4 - ENABLE_UNIFIED_COMPILATION: ON steps: - uses: actions/checkout@v3 with: @@ -132,7 +129,7 @@ jobs: - name: Build (Ubuntu 18.04, GCC) run: | - docker build -t p4c --build-arg BASE_IMAGE=ubuntu:18.04 --build-arg IMAGE_TYPE=test --build-arg ENABLE_UNIFIED_COMPILATION=ON . + docker build -t p4c --build-arg BASE_IMAGE=ubuntu:18.04 --build-arg IMAGE_TYPE=test . ./tools/export_ccache.sh # run with sudo (...) --privileged @@ -172,9 +169,8 @@ jobs: - name: Build p4c (Fedora Linux) run: | - ./bootstrap.sh -DCMAKE_BUILD_TYPE=RELEASE -DENABLE_UNIFIED_COMPILATION=ON - make -j2 -C build - + ./bootstrap.sh -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_UNITY_BUILD=ON + make -j2 -C build - name: Run p4c tests (Fedora Linux) # Need to use sudo for the eBPF kernel tests. @@ -213,7 +209,7 @@ jobs: run: | PROTOBUF=`brew --prefix --installed protobuf` ./bootstrap.sh -DENABLE_GC=ON -DCMAKE_BUILD_TYPE=RELEASE \ - -DENABLE_UNIFIED_COMPILATION=ON \ + -DCMAKE_UNITY_BUILD=ON \ -DProtobuf_INCLUDE_DIR=$PROTOBUF/include \ -DProtobuf_LIBRARY=$PROTOBUF/lib/libprotobuf.dylib \ -DENABLE_PROTOBUF_STATIC=OFF diff --git a/.github/workflows/ci-validation.yml b/.github/workflows/ci-validation.yml index ac0976fdfca..09098853f4c 100644 --- a/.github/workflows/ci-validation.yml +++ b/.github/workflows/ci-validation.yml @@ -19,7 +19,6 @@ jobs: env: CTEST_PARALLEL_LEVEL: 4 IMAGE_TYPE: test - ENABLE_UNIFIED_COMPILATION: ON VALIDATION: ON runs-on: ubuntu-20.04 steps: diff --git a/CMakeLists.txt b/CMakeLists.txt index 837bf33c55e..93c9056fe84 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -83,13 +83,17 @@ else() set (P4C_VERSION "${P4C_SEM_VERSION_STRING} (SHA: ${P4C_GIT_SHA} BUILD: ${CMAKE_BUILD_TYPE})") endif() include(P4CUtils) -include(UnifiedBuild) # # search in /usr/local first # set (CMAKE_FIND_ROOT_PATH "/usr/local/bin" "${CMAKE_FIND_ROOT_PATH}") set (P4C_CXX_FLAGS "") set (P4C_LIB_DEPS) + +# If unity builds are enable, choose an aggressive batch size. +if (CMAKE_UNITY_BUILD) + set(CMAKE_UNITY_BUILD_BATCH_SIZE 16 CACHE UNINITIALIZED "Set the unity build batch size.") +endif () # set the required options for a static release build if (BUILD_STATIC_RELEASE) message(STATUS "Building static release binaries") diff --git a/Dockerfile b/Dockerfile index dec88bab213..78da118e3a3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,7 @@ ARG IN_DOCKER=TRUE # removed from the image. ARG IMAGE_TYPE=build # Whether to do a unified build. -ARG ENABLE_UNIFIED_COMPILATION=ON +ARG CMAKE_UNITY_BUILD=ON # Whether to enable translation validation ARG VALIDATION=OFF # This creates a release build that includes link time optimization and links diff --git a/backends/bmv2/CMakeLists.txt b/backends/bmv2/CMakeLists.txt index 1d06b31542d..21625392308 100644 --- a/backends/bmv2/CMakeLists.txt +++ b/backends/bmv2/CMakeLists.txt @@ -82,17 +82,14 @@ set (BMV2_BACKEND_COMMON_HDRS set (IR_DEF_FILES ${IR_DEF_FILES} ${CMAKE_CURRENT_SOURCE_DIR}/bmv2.def PARENT_SCOPE) -build_unified(BMV2_BACKEND_COMMON_SRCS) add_library(bmv2backend ${P4C_STATIC_BUILD} ${BMV2_BACKEND_COMMON_SRCS}) add_dependencies(bmv2backend genIR frontend) -build_unified(BMV2_SIMPLE_SWITCH_SRCS) add_executable(p4c-bm2-ss ${BMV2_SIMPLE_SWITCH_SRCS}) target_link_libraries (p4c-bm2-ss bmv2backend ${P4C_LIBRARIES} ${P4C_LIB_DEPS}) install(TARGETS p4c-bm2-ss RUNTIME DESTINATION ${P4C_RUNTIME_OUTPUT_DIRECTORY}) -build_unified(BMV2_PSA_SWITCH_SRCS) add_executable(p4c-bm2-psa ${BMV2_PSA_SWITCH_SRCS}) target_link_libraries (p4c-bm2-psa bmv2backend ${P4C_LIBRARIES} ${P4C_LIB_DEPS}) install(TARGETS p4c-bm2-psa RUNTIME DESTINATION ${P4C_RUNTIME_OUTPUT_DIRECTORY}) diff --git a/backends/ebpf/CMakeLists.txt b/backends/ebpf/CMakeLists.txt index 18f35840a25..3ff818e5b69 100644 --- a/backends/ebpf/CMakeLists.txt +++ b/backends/ebpf/CMakeLists.txt @@ -90,7 +90,6 @@ set (P4C_EBPF_HDRS set (P4C_EBPF_DIST_HEADERS p4include/ebpf_model.p4) -build_unified(P4C_EBPF_SRCS) add_executable(p4c-ebpf ${P4C_EBPF_SRCS}) target_link_libraries (p4c-ebpf ${P4C_LIBRARIES} ${P4C_LIB_DEPS}) add_dependencies(p4c-ebpf genIR frontend) diff --git a/backends/graphs/CMakeLists.txt b/backends/graphs/CMakeLists.txt index 867423662b6..0cad2270ec6 100644 --- a/backends/graphs/CMakeLists.txt +++ b/backends/graphs/CMakeLists.txt @@ -30,7 +30,7 @@ set (GRAPHS_HDRS graph_visitor.h ) -build_unified(GRAPHS_SRCS ALL) + add_executable(p4c-graphs ${GRAPHS_SRCS} ${EXTENSION_P4_14_CONV_SOURCES}) target_link_libraries (p4c-graphs ${P4C_LIBRARIES} ${P4C_LIB_DEPS}) add_dependencies(p4c-graphs genIR frontend) diff --git a/backends/p4test/CMakeLists.txt b/backends/p4test/CMakeLists.txt index 03ef639496e..6673f68efba 100644 --- a/backends/p4test/CMakeLists.txt +++ b/backends/p4test/CMakeLists.txt @@ -25,7 +25,7 @@ set (P4TEST_HDRS midend.h ) -build_unified(P4TEST_SRCS ALL) + add_executable(p4test ${P4TEST_SRCS} ${EXTENSION_P4_14_CONV_SOURCES}) target_link_libraries (p4test ${P4C_LIBRARIES} ${P4C_LIB_DEPS}) add_dependencies(p4test genIR frontend) diff --git a/backends/p4tools/modules/testgen/register.h.in b/backends/p4tools/modules/testgen/register.h.in index b17a37d72fc..29173f5b6d0 100644 --- a/backends/p4tools/modules/testgen/register.h.in +++ b/backends/p4tools/modules/testgen/register.h.in @@ -7,10 +7,10 @@ namespace P4Tools { namespace P4Testgen { -void registerCompilerTargets() { +inline void registerCompilerTargets() { @compiler_targets_var@} -void registerTestgenTargets() { +inline void registerTestgenTargets() { @testgen_targets_var@} } // namespace P4Tools diff --git a/backends/p4tools/modules/testgen/targets/bmv2/backend/protobuf/protobuf.cpp b/backends/p4tools/modules/testgen/targets/bmv2/backend/protobuf/protobuf.cpp index a954a356198..ac89858a130 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/backend/protobuf/protobuf.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/backend/protobuf/protobuf.cpp @@ -277,7 +277,7 @@ inja::json Protobuf::getVerify(const TestSpec *testSpec) { return verifyData; } -static std::string getTestCase() { +std::string Protobuf::getTestCaseTemplate() { static std::string TEST_CASE( R"""(# A P4TestGen-generated test case for {{test_name}}.p4 metadata: "p4testgen seed: {{ default(seed, "none") }}" @@ -429,7 +429,7 @@ void Protobuf::outputTest(const TestSpec *testSpec, cstring selectedBranches, si auto incrementedTestName = testName + "_" + std::to_string(testIdx); protobufFile = std::ofstream(incrementedTestName + ".proto"); - std::string testCase = getTestCase(); + std::string testCase = getTestCaseTemplate(); emitTestcase(testSpec, selectedBranches, testIdx, testCase, currentCoverage); } diff --git a/backends/p4tools/modules/testgen/targets/bmv2/backend/protobuf/protobuf.h b/backends/p4tools/modules/testgen/targets/bmv2/backend/protobuf/protobuf.h index 421c3daa2b8..5a8a39d479b 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/backend/protobuf/protobuf.h +++ b/backends/p4tools/modules/testgen/targets/bmv2/backend/protobuf/protobuf.h @@ -63,6 +63,9 @@ class Protobuf : public TF { void emitTestcase(const TestSpec *testSpec, cstring selectedBranches, size_t testId, const std::string &testCase, float currentCoverage); + /// @returns the inja test case template as a string. + static std::string getTestCaseTemplate(); + /// Converts all the control plane objects into Inja format. static inja::json getControlPlane(const TestSpec *testSpec); diff --git a/backends/p4tools/modules/testgen/targets/bmv2/backend/ptf/ptf.cpp b/backends/p4tools/modules/testgen/targets/bmv2/backend/ptf/ptf.cpp index 1853097d061..1746ff6776c 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/backend/ptf/ptf.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/backend/ptf/ptf.cpp @@ -282,7 +282,7 @@ void PTF::emitPreamble(const std::string &preamble) { ptfFile.flush(); } -static std::string getTestCase() { +std::string PTF::getTestCaseTemplate() { static std::string TEST_CASE( R"""( class Test{{test_id}}(AbstractTest): @@ -419,7 +419,7 @@ void PTF::outputTest(const TestSpec *testSpec, cstring selectedBranches, size_t emitPreamble(preamble); preambleEmitted = true; } - std::string testCase = getTestCase(); + std::string testCase = getTestCaseTemplate(); emitTestcase(testSpec, selectedBranches, testIdx, testCase, currentCoverage); } diff --git a/backends/p4tools/modules/testgen/targets/bmv2/backend/ptf/ptf.h b/backends/p4tools/modules/testgen/targets/bmv2/backend/ptf/ptf.h index abc8dd38204..b29c265ebf0 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/backend/ptf/ptf.h +++ b/backends/p4tools/modules/testgen/targets/bmv2/backend/ptf/ptf.h @@ -58,6 +58,9 @@ class PTF : public TF { void emitTestcase(const TestSpec *testSpec, cstring selectedBranches, size_t testId, const std::string &testCase, float currentCoverage); + /// @returns the inja test case template as a string. + static std::string getTestCaseTemplate(); + /// Converts all the control plane objects into Inja format. static inja::json getControlPlane(const TestSpec *testSpec); diff --git a/backends/p4tools/modules/testgen/targets/bmv2/backend/stf/stf.cpp b/backends/p4tools/modules/testgen/targets/bmv2/backend/stf/stf.cpp index 3f02ef272df..e4dc3f5f9b2 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/backend/stf/stf.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/backend/stf/stf.cpp @@ -235,7 +235,7 @@ inja::json::array_t STF::getClone(const std::map &c return cloneJson; } -static std::string getTestCase() { +std::string STF::getTestCaseTemplate() { static std::string TEST_CASE( R"""(# p4testgen seed: {{ default(seed, "none") }} # Date generated: {{timestamp}} @@ -328,7 +328,7 @@ void STF::outputTest(const TestSpec *testSpec, cstring selectedBranches, size_t auto incrementedTestName = testName + "_" + std::to_string(testIdx); stfFile = std::ofstream(incrementedTestName + ".stf"); - std::string testCase = getTestCase(); + std::string testCase = getTestCaseTemplate(); emitTestcase(testSpec, selectedBranches, testIdx, testCase, currentCoverage); } diff --git a/backends/p4tools/modules/testgen/targets/bmv2/backend/stf/stf.h b/backends/p4tools/modules/testgen/targets/bmv2/backend/stf/stf.h index f8a9bb59d72..81fb7ae72a7 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/backend/stf/stf.h +++ b/backends/p4tools/modules/testgen/targets/bmv2/backend/stf/stf.h @@ -52,6 +52,9 @@ class STF : public TF { void emitTestcase(const TestSpec *testSpec, cstring selectedBranches, size_t testId, const std::string &testCase, float currentCoverage); + /// @returns the inja test case template as a string. + static std::string getTestCaseTemplate(); + /// Converts all the control plane objects into Inja format. static inja::json getControlPlane(const TestSpec *testSpec); diff --git a/backends/p4tools/modules/testgen/targets/bmv2/register.h b/backends/p4tools/modules/testgen/targets/bmv2/register.h index c6afb397362..99e29c356c5 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/register.h +++ b/backends/p4tools/modules/testgen/targets/bmv2/register.h @@ -13,10 +13,10 @@ namespace P4Tools { namespace P4Testgen { /// Register the BMv2 compiler target with the tools framework. -void bmv2_registerCompilerTarget() { Bmv2::BMv2_V1ModelCompilerTarget::make(); } +inline void bmv2_registerCompilerTarget() { Bmv2::BMv2_V1ModelCompilerTarget::make(); } /// Register the BMv2 testgen target with the testgen framework. -void bmv2_registerTestgenTarget() { Bmv2::BMv2_V1ModelTestgenTarget::make(); } +inline void bmv2_registerTestgenTarget() { Bmv2::BMv2_V1ModelTestgenTarget::make(); } } // namespace P4Testgen diff --git a/backends/p4tools/modules/testgen/targets/ebpf/backend/stf/stf.cpp b/backends/p4tools/modules/testgen/targets/ebpf/backend/stf/stf.cpp index ef35f022c92..56b0ec6e7e3 100644 --- a/backends/p4tools/modules/testgen/targets/ebpf/backend/stf/stf.cpp +++ b/backends/p4tools/modules/testgen/targets/ebpf/backend/stf/stf.cpp @@ -219,7 +219,7 @@ inja::json STF::getVerify(const TestSpec *testSpec) { return verifyData; } -static std::string getTestCase() { +std::string STF::getTestCaseTemplate() { static std::string TEST_CASE( R"""(# p4testgen seed: {{ default(seed, "none") }} # Date generated: {{timestamp}} @@ -280,7 +280,7 @@ void STF::outputTest(const TestSpec *testSpec, cstring selectedBranches, size_t auto incrementedTestName = testName + "_" + std::to_string(testIdx); stfFile = std::ofstream(incrementedTestName + ".stf"); - std::string testCase = getTestCase(); + std::string testCase = getTestCaseTemplate(); emitTestcase(testSpec, selectedBranches, testIdx, testCase, currentCoverage); } diff --git a/backends/p4tools/modules/testgen/targets/ebpf/backend/stf/stf.h b/backends/p4tools/modules/testgen/targets/ebpf/backend/stf/stf.h index 71f520ab722..aaec86f38c8 100644 --- a/backends/p4tools/modules/testgen/targets/ebpf/backend/stf/stf.h +++ b/backends/p4tools/modules/testgen/targets/ebpf/backend/stf/stf.h @@ -52,6 +52,9 @@ class STF : public TF { void emitTestcase(const TestSpec *testSpec, cstring selectedBranches, size_t testId, const std::string &testCase, float currentCoverage); + /// @returns the inja test case template as a string. + static std::string getTestCaseTemplate(); + /// Converts all the control plane objects into Inja format. static inja::json getControlPlane(const TestSpec *testSpec); diff --git a/backends/p4tools/modules/testgen/targets/ebpf/register.h b/backends/p4tools/modules/testgen/targets/ebpf/register.h index 37f90c16f08..76840f7b3e6 100644 --- a/backends/p4tools/modules/testgen/targets/ebpf/register.h +++ b/backends/p4tools/modules/testgen/targets/ebpf/register.h @@ -13,10 +13,10 @@ namespace P4Tools { namespace P4Testgen { /// Register the ebpf compiler target with the tools framework. -void ebpf_registerCompilerTarget() { EBPF::EBPFCompilerTarget::make(); } +inline void ebpf_registerCompilerTarget() { EBPF::EBPFCompilerTarget::make(); } /// Register the ebpf testgen target with the testgen framework. -void ebpf_registerTestgenTarget() { EBPF::EBPFTestgenTarget::make(); } +inline void ebpf_registerTestgenTarget() { EBPF::EBPFTestgenTarget::make(); } } // namespace P4Testgen diff --git a/backends/p4tools/modules/testgen/test/transformations/saturation_arithm.cpp b/backends/p4tools/modules/testgen/test/transformations/saturation_arithm.cpp index adaa0ae963f..9f1ad731924 100644 --- a/backends/p4tools/modules/testgen/test/transformations/saturation_arithm.cpp +++ b/backends/p4tools/modules/testgen/test/transformations/saturation_arithm.cpp @@ -108,7 +108,7 @@ class Z3SolverSatTests : public ::testing::Test { std::string equation; }; -namespace { +namespace ArithmTest { /// The main class for saturation transformation. class SaturationTransform : public Transform { @@ -242,6 +242,6 @@ class Z3SolverSubSat05 : public Z3SolverSatTests { TEST_F(Z3SolverSubSat05, SubSat05) { test(expression, variableValue); } -} // anonymous namespace +} // namespace ArithmTest } // namespace Test diff --git a/backends/p4tools/modules/testgen/test/z3-solver/expressions.cpp b/backends/p4tools/modules/testgen/test/z3-solver/expressions.cpp index 1cd54a651bd..deda585bc72 100644 --- a/backends/p4tools/modules/testgen/test/z3-solver/expressions.cpp +++ b/backends/p4tools/modules/testgen/test/z3-solver/expressions.cpp @@ -110,7 +110,7 @@ class Z3SolverTests : public ::testing::Test { std::string equation; }; -namespace { +namespace Z3Test { void test(const IR::Expression *expression, const IR::AssignmentStatement *variableValue) { // checking initial data @@ -306,6 +306,6 @@ class Z3SolverCastBit2Bool : public Z3SolverTests { TEST_F(Z3SolverCastBit2Bool, Cast) { test(expression, variableValue); } -} // anonymous namespace +} // namespace Z3Test } // namespace Test diff --git a/backends/ubpf/CMakeLists.txt b/backends/ubpf/CMakeLists.txt index d0f49f1c0b4..31ef28ff2d1 100644 --- a/backends/ubpf/CMakeLists.txt +++ b/backends/ubpf/CMakeLists.txt @@ -57,7 +57,7 @@ set(P4C_UBPF_HEADERS set (P4C_UBPF_DIST_HEADERS p4include/ubpf_model.p4) -build_unified(P4C_UBPF_SOURCES ALL) + add_executable(p4c-ubpf ${P4C_UBPF_SOURCES}) target_link_libraries (p4c-ubpf ${P4C_LIBRARIES} ${P4C_LIB_DEPS}) add_dependencies(p4c-ubpf genIR frontend) diff --git a/cmake/UnifiedBuild.cmake b/cmake/UnifiedBuild.cmake index 2b3ea2040bc..949d2bf6447 100644 --- a/cmake/UnifiedBuild.cmake +++ b/cmake/UnifiedBuild.cmake @@ -1,6 +1,6 @@ # Options to control unified compilation. More information is available in the # documentation for `build_unified`. -OPTION (ENABLE_UNIFIED_COMPILATION "Merge source files to speed up compilation" ON) +OPTION (ENABLE_UNIFIED_COMPILATION "Merge source files to speed up compilation" OFF) set(UNIFIED_SOURCE_CHUNK_SIZE "10" CACHE STRING "Target unified compilation chunk size (an integer or ALL)") # Helper function: compute `divided / divisor`, round up to the next highest diff --git a/control-plane/CMakeLists.txt b/control-plane/CMakeLists.txt index 01d23e885f4..4f5f710f7ba 100644 --- a/control-plane/CMakeLists.txt +++ b/control-plane/CMakeLists.txt @@ -102,7 +102,6 @@ include_directories (${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) # Silence -Warray-bounds as the root issue is out of our control: https://github.com/protocolbuffers/protobuf/issues/7140 set_source_files_properties (${CONTROLPLANE_SOURCES} PROPERTIES COMPILE_FLAGS "-Wno-unused-parameter -Wno-array-bounds") set_source_files_properties (${P4RUNTIME_GEN_SRCS} PROPERTIES GENERATED TRUE) -build_unified(CONTROLPLANE_SOURCES) add_library (controlplane STATIC ${CONTROLPLANE_SOURCES} ) target_link_libraries (controlplane ${PROTOBUF_LIBRARY} ${CMAKE_THREAD_LIBS_INIT}) add_dependencies (controlplane mkP4configdir genIR frontend) diff --git a/frontends/CMakeLists.txt b/frontends/CMakeLists.txt index 89abb8c9c9a..dfd1b5a412e 100644 --- a/frontends/CMakeLists.txt +++ b/frontends/CMakeLists.txt @@ -252,6 +252,9 @@ set (FRONTEND_SOURCES ${v1PARSER_GEN_SRCS} ) +set_source_files_properties(${p4PARSER_GEN_SRCS} PROPERTIES SKIP_UNITY_BUILD_INCLUSION TRUE) +set_source_files_properties(${v1PARSER_GEN_SRCS} PROPERTIES SKIP_UNITY_BUILD_INCLUSION TRUE) + set_source_files_properties(${IR_GENERATED_SRCS} PROPERTIES GENERATED TRUE) set (FRONTEND_CPPLINT_FILES @@ -260,8 +263,6 @@ set (FRONTEND_CPPLINT_FILES ${V1_FRONTEND_SRCS} ${V1_FRONTEND_HDRS} ${PARSERS_SRCS} ${PARSERS_HDRS}) -build_unified(FRONTEND_SOURCES) -build_unified(EXTENSION_FRONTEND_SOURCES) if (FLEX_INCLUDE_DIRS) include_directories(${FLEX_INCLUDE_DIRS}) endif () diff --git a/ir/CMakeLists.txt b/ir/CMakeLists.txt index 312c3d0d884..e0dbd226070 100644 --- a/ir/CMakeLists.txt +++ b/ir/CMakeLists.txt @@ -63,6 +63,5 @@ set (BASE_IR_DEF_FILES set (IR_DEF_FILES ${IR_DEF_FILES} ${BASE_IR_DEF_FILES} PARENT_SCOPE) -build_unified(IR_SRCS) add_library (ir STATIC ${IR_SRCS}) add_dependencies(ir genIR) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 376ff346d37..1a30cbc7bf8 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -81,7 +81,7 @@ set (LIBP4CTOOLKIT_HDRS timer.h ) -build_unified(LIBP4CTOOLKIT_SRCS ALL) + add_library(p4ctoolkit STATIC ${LIBP4CTOOLKIT_SRCS}) # Disable libcall (realloc, malloc) optimizations which may cause infinite loops. diff --git a/midend/CMakeLists.txt b/midend/CMakeLists.txt index a8e5b6c4e38..3fc152d9adf 100644 --- a/midend/CMakeLists.txt +++ b/midend/CMakeLists.txt @@ -112,6 +112,6 @@ set (MIDEND_HDRS validateProperties.h ) -build_unified(MIDEND_SRCS) + add_library (midend STATIC ${MIDEND_SRCS}) add_dependencies(midend genIR) diff --git a/midend/global_copyprop.cpp b/midend/global_copyprop.cpp index e4f38ed1b25..ee664cd8a01 100644 --- a/midend/global_copyprop.cpp +++ b/midend/global_copyprop.cpp @@ -2,23 +2,27 @@ namespace P4 { -/// Convert an expression into a string that uniqely identifies the lvalue referenced. -/// Return null cstring if not a reference to a lvalue. -static cstring lvalue_name(const IR::Expression *exp) { +namespace GlobalCopyProp { + +/// Convert an expression into a string that uniqely identifies the lvalue +/// referenced. Return null cstring if not a reference to a lvalue. +static cstring lValueName(const IR::Expression *exp) { if (auto p = exp->to()) return p->path->name; if (auto m = exp->to()) { - if (auto base = lvalue_name(m->expr)) return base + "." + m->member; + if (auto base = lValueName(m->expr)) return base + "." + m->member; } else if (auto a = exp->to()) { if (auto k = a->right->to()) { - if (auto base = lvalue_name(a->left)) + if (auto base = lValueName(a->left)) return base + "[" + std::to_string(k->asInt()) + "]"; } } else if (auto sl = exp->to()) { - if (auto e0 = lvalue_name(sl->e0)) return e0; + if (auto e0 = lValueName(sl->e0)) return e0; } return cstring(); } +} // namespace GlobalCopyProp + /// Test to see if names denote overlapping locations. bool names_overlap(cstring name1, cstring name2) { if (name1 == name2) return true; @@ -120,23 +124,23 @@ bool FindVariableValues::preorder(const IR::SwitchStatement *stat) { // Update the value for the 'stat->left' variable. bool FindVariableValues::preorder(const IR::AssignmentStatement *stat) { - if (!working || lvalue_name(stat->left).isNullOrEmpty()) return false; + if (!working || GlobalCopyProp::lValueName(stat->left).isNullOrEmpty()) return false; LOG5("Working on statement: " << stat); // Remove old values - if (vars[lvalue_name(stat->left)] == nullptr || - !(stat->right->equiv(*(vars[lvalue_name(stat->left)])))) - removeVarsContaining(&vars, lvalue_name(stat->left)); + if (vars[GlobalCopyProp::lValueName(stat->left)] == nullptr || + !(stat->right->equiv(*(vars[GlobalCopyProp::lValueName(stat->left)])))) + removeVarsContaining(&vars, GlobalCopyProp::lValueName(stat->left)); // Set value if (auto lit = stat->right->to()) { if (stat->left->is()) return false; - vars[lvalue_name(stat->left)] = lit; + vars[GlobalCopyProp::lValueName(stat->left)] = lit; LOG5(" Setting value: " << lit << ", for: " << stat->left); - } else if (auto v = vars[lvalue_name(stat->right)]) { + } else if (auto v = vars[GlobalCopyProp::lValueName(stat->right)]) { auto lit = v->to(); if (lit == nullptr) return false; if (stat->left->is() || stat->right->is()) return false; - vars[lvalue_name(stat->left)] = lit; + vars[GlobalCopyProp::lValueName(stat->left)] = lit; LOG5(" Setting value: " << lit << ", for: " << stat->left); } @@ -192,7 +196,7 @@ const IR::Expression *DoGlobalCopyPropagation::postorder(IR::PathExpression *pat const IR::Expression *DoGlobalCopyPropagation::preorder(IR::Member *member) { if (!performRewrite) return member; - if (auto name = lvalue_name(member)) { + if (auto name = GlobalCopyProp::lValueName(member)) { prune(); if (auto rv = copyprop_name(name)) return rv; } @@ -202,7 +206,7 @@ const IR::Expression *DoGlobalCopyPropagation::preorder(IR::Member *member) { const IR::Expression *DoGlobalCopyPropagation::preorder(IR::ArrayIndex *arr) { if (!performRewrite) return arr; - if (auto name = lvalue_name(arr)) { + if (auto name = GlobalCopyProp::lValueName(arr)) { prune(); if (auto rv = copyprop_name(name)) { return rv; @@ -285,9 +289,9 @@ const IR::Node *DoGlobalCopyPropagation::preorder(IR::AssignmentStatement *stat) LOG6(" Visiting right side of statement"); visit(stat->right); // Remove old values - if ((*vars)[lvalue_name(stat->left)] == nullptr || - !(stat->right->equiv(*((*vars)[lvalue_name(stat->left)])))) - removeVarsContaining(vars, lvalue_name(stat->left)); + if ((*vars)[GlobalCopyProp::lValueName(stat->left)] == nullptr || + !(stat->right->equiv(*((*vars)[GlobalCopyProp::lValueName(stat->left)])))) + removeVarsContaining(vars, GlobalCopyProp::lValueName(stat->left)); performRewrite = false; LOG6(" Visiting left side of statement"); visit(stat->left); @@ -297,9 +301,10 @@ const IR::Node *DoGlobalCopyPropagation::preorder(IR::AssignmentStatement *stat) // identical literal as already stored in the 'vars' container the statement is removed. if (auto lit = stat->right->to()) { if (stat->left->is()) return stat; - if ((*vars)[lvalue_name(stat->left)] && lit->equiv(*((*vars)[lvalue_name(stat->left)]))) + if ((*vars)[GlobalCopyProp::lValueName(stat->left)] && + lit->equiv(*((*vars)[GlobalCopyProp::lValueName(stat->left)]))) return new IR::EmptyStatement(stat->srcInfo); - (*vars)[lvalue_name(stat->left)] = lit; + (*vars)[GlobalCopyProp::lValueName(stat->left)] = lit; LOG5(" Setting value: " << lit << ", for: " << stat->left); } diff --git a/midend/predication.cpp b/midend/predication.cpp index aab0545d2b5..d24325647df 100644 --- a/midend/predication.cpp +++ b/midend/predication.cpp @@ -18,21 +18,22 @@ limitations under the License. #include "frontends/p4/cloner.h" namespace P4 { -/// convert an expression into a string that uniqely identifies the lvalue referenced +namespace Pred { + /// return null cstring if not a reference to a lvalue. -static cstring predication_lvalue_name(const IR::Expression *exp) { +static cstring lvalueName(const IR::Expression *exp) { if (auto p = exp->to()) return p->path->name; if (auto m = exp->to()) { - if (auto base = predication_lvalue_name(m->expr)) return base + "." + m->member; + if (auto base = lvalueName(m->expr)) return base + "." + m->member; } else if (auto a = exp->to()) { if (auto k = a->right->to()) { - if (auto base = predication_lvalue_name(a->left)) + if (auto base = lvalueName(a->left)) return base + "[" + std::to_string(k->asInt()) + "]"; - } else if (auto index = predication_lvalue_name(a->right)) { - if (auto base = predication_lvalue_name(a->left)) return base + "[" + index + "]"; + } else if (auto index = lvalueName(a->right)) { + if (auto base = lvalueName(a->left)) return base + "[" + index + "]"; } } else if (auto s = exp->to()) { - if (auto base = predication_lvalue_name(s->e0)) + if (auto base = lvalueName(s->e0)) if (auto h = s->e1->to()) if (auto l = s->e2->to()) return base + "." + std::to_string(h->asInt()) + ":" + @@ -41,6 +42,8 @@ static cstring predication_lvalue_name(const IR::Expression *exp) { return cstring(); } +} // namespace Pred + const IR::Node *Predication::EmptyStatementRemover::postorder(IR::EmptyStatement *) { return nullptr; } @@ -86,9 +89,9 @@ void Predication::ExpressionReplacer::emplaceExpression(IR::Mux *mux) { /// according to the current nesting level and also the structure of the 'mux' variable void Predication::ExpressionReplacer::visitBranch(IR::Mux *mux, bool then) { auto condition = conditions[conditions.size() - currentNestingLevel - 1]; - auto leftName = predication_lvalue_name(statement->left); - auto thenExprName = predication_lvalue_name(mux->e1); - auto elseExprName = predication_lvalue_name(mux->e2); + auto leftName = Pred::lvalueName(statement->left); + auto thenExprName = Pred::lvalueName(mux->e1); + auto elseExprName = Pred::lvalueName(mux->e2); if (leftName.isNullOrEmpty()) { ::error(ErrorType::ERR_EXPRESSION, @@ -179,13 +182,13 @@ const IR::Node *Predication::preorder(IR::AssignmentStatement *statement) { for (auto dependency : dependencies) { if (liveAssignments.find(dependency) != liveAssignments.end()) { // Save statement's name if it is dependent - dependentNames.push_back(predication_lvalue_name(statement->left)); + dependentNames.push_back(Pred::lvalueName(statement->left)); // remove dependency from liveAssignments to not duplicate liveAssignments.erase(dependency); depNestingLevel = ifNestingLevel; } } - auto statementName = predication_lvalue_name(statement->left); + auto statementName = Pred::lvalueName(statement->left); // Set value to true in isStatementDependent map // if the name of a current statement is the same as // the name of any in dependentNames. @@ -216,8 +219,7 @@ const IR::Node *Predication::preorder(IR::AssignmentStatement *statement) { // Remove statement for 'then' if there is a statement // with the same statement name in the else branch. if (liveAssigns.size() > 0 && !isStatementDependent[statementName] && - predication_lvalue_name(liveAssigns.back()->left) == - predication_lvalue_name(statement->left)) { + Pred::lvalueName(liveAssigns.back()->left) == Pred::lvalueName(statement->left)) { liveAssigns.pop_back(); } } @@ -235,12 +237,12 @@ const IR::Node *Predication::preorder(IR::AssignmentStatement *statement) { } const IR::Node *Predication::preorder(IR::PathExpression *pathExpr) { - dependencies.push_back(predication_lvalue_name(pathExpr)); + dependencies.push_back(Pred::lvalueName(pathExpr)); return pathExpr; } const IR::Node *Predication::preorder(IR::Member *member) { visit(member->expr); - dependencies.push_back(predication_lvalue_name(member)); + dependencies.push_back(Pred::lvalueName(member)); return member; } const IR::Node *Predication::preorder(IR::ArrayIndex *arrInd) { @@ -274,7 +276,7 @@ const IR::Node *Predication::preorder(IR::ArrayIndex *arrInd) { arrInd->right = index; } - dependencies.push_back(predication_lvalue_name(arrInd)); + dependencies.push_back(Pred::lvalueName(arrInd)); return arrInd; } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0807c125a1e..a57c27d7e42 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -74,7 +74,6 @@ set (GTEST_BASE_SOURCES gtest/gtestp4c.cpp ${GTEST_UNITTEST_SOURCES} ) -build_unified(GTEST_BASE_SOURCES) # Merge the base sources with the tests added to GTEST_SOURCES by specific # backends or by extensions. We can't assume that one extension's GTests can be diff --git a/tools/ci-build.sh b/tools/ci-build.sh index e63def57751..b261bda5137 100755 --- a/tools/ci-build.sh +++ b/tools/ci-build.sh @@ -18,7 +18,7 @@ P4C_DIR=$(readlink -f ${THIS_DIR}/..) # removed from the image. : "${IMAGE_TYPE:=build}" # Whether to do a unified build. -: "${ENABLE_UNIFIED_COMPILATION:=ON}" +: "${CMAKE_UNITY_BUILD:=ON}" # Whether to enable translation validation : "${VALIDATION:=OFF}" # This creates a release build that includes link time optimization and links @@ -231,7 +231,7 @@ fi # Strong optimization. export CXXFLAGS="${CXXFLAGS} -O3" # Toggle unified compilation. -CMAKE_FLAGS+="-DENABLE_UNIFIED_COMPILATION=${ENABLE_UNIFIED_COMPILATION} " +CMAKE_FLAGS+="-DCMAKE_UNITY_BUILD=${CMAKE_UNITY_BUILD} " # Toggle static builds. CMAKE_FLAGS+="-DBUILD_STATIC_RELEASE=${BUILD_STATIC_RELEASE} " # Toggle the installation of the tools back end. diff --git a/tools/debian-build/packaging.conf b/tools/debian-build/packaging.conf index d204cef28c4..848568876ed 100644 --- a/tools/debian-build/packaging.conf +++ b/tools/debian-build/packaging.conf @@ -10,7 +10,7 @@ CONFOPT="" # Strong optimization. export CXXFLAGS="${CXXFLAGS} -O3" # Enable unified compilation. -CONFOPT+="-DENABLE_UNIFIED_COMPILATION=ON " +CONFOPT+="-DCMAKE_UNITY_BUILD=ON " # RELEASE should be default, but we want to make sure. CONFOPT+="-DCMAKE_BUILD_TYPE=RELEASE " # The binaries we produce should not depend on system libraries. diff --git a/tools/ir-generator/CMakeLists.txt b/tools/ir-generator/CMakeLists.txt index 66b5b925b95..120b8c61912 100644 --- a/tools/ir-generator/CMakeLists.txt +++ b/tools/ir-generator/CMakeLists.txt @@ -39,7 +39,6 @@ set (IRGENERATOR_GEN_SRCS include_directories (${CMAKE_CURRENT_BINARY_DIR}) set_source_files_properties(${IRGENERATOR_GEN_SRCS} PROPERTIES GENERATED TRUE) set_source_files_properties(${IRGENERATOR_GEN_SRCS} PROPERTIES OBJECT_DEPENDS ${FLEX_IRgenLexer_OUTPUTS}) -build_unified(IRGENERATOR_SRCS ALL) add_executable (irgenerator ${IRGENERATOR_SRCS} ${IRGENERATOR_GEN_SRCS}) # Unconditionally set the output directory for the irgenerator to the path # where the custom command that generates IR sources expects to find it. From f63dd6744ededbb4396b6497bc104f9479b4d836 Mon Sep 17 00:00:00 2001 From: fruffy Date: Fri, 16 Dec 2022 11:02:00 +0100 Subject: [PATCH 2/9] Legacy options for unified compilation. --- CMakeLists.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 93c9056fe84..5d8985267ff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,6 +47,8 @@ OPTION (ENABLE_SANITIZERS "Enable sanitizers" OFF) OPTION (BUILD_STATIC_RELEASE "Build a statically linked release binary" OFF) OPTION (BUILD_AUTO_VAR_INIT_PATTERN "Initialize variables with pattern during build" OFF) OPTION (ENABLE_IWYU "Enable checking includes with IWYU" OFF) +# Support a legacy option. TODO: Remove? +OPTION (ENABLE_UNIFIED_COMPILATION "Enable CMAKE_UNITY_BUILD" OFF) set (P4C_DRIVER_NAME "p4c" CACHE STRING "Customize the name of the driver script") @@ -90,6 +92,11 @@ set (P4C_CXX_FLAGS "") set (P4C_LIB_DEPS) +# Support a legacy option. +if (ENABLE_UNIFIED_COMPILATION) + set(CMAKE_UNITY_BUILD ON) +endif() + # If unity builds are enable, choose an aggressive batch size. if (CMAKE_UNITY_BUILD) set(CMAKE_UNITY_BUILD_BATCH_SIZE 16 CACHE UNINITIALIZED "Set the unity build batch size.") From a7164736e827e3ddb96a4c6981277a2e3d68964f Mon Sep 17 00:00:00 2001 From: fruffy Date: Fri, 16 Dec 2022 16:52:23 +0100 Subject: [PATCH 3/9] Warning. --- CMakeLists.txt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5d8985267ff..7fa590aab58 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -92,8 +92,12 @@ set (P4C_CXX_FLAGS "") set (P4C_LIB_DEPS) -# Support a legacy option. -if (ENABLE_UNIFIED_COMPILATION) +# Support the legacy unified build option. +if(ENABLE_UNIFIED_COMPILATION) + message( + WARNING + "Using deprecated option \"ENABLE_UNIFIED_COMPILATION\". Please use \"CMAKE_UNITY_BUILD\" instead." + ) set(CMAKE_UNITY_BUILD ON) endif() From 47da77d184a308f060d25e63a22d953e02e6d186 Mon Sep 17 00:00:00 2001 From: fruffy Date: Fri, 16 Dec 2022 17:01:18 +0100 Subject: [PATCH 4/9] Versioning. --- CMakeLists.txt | 4 ++-- README.md | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7fa590aab58..f4a4cb32172 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -# This is the CMake version supplied by Ubuntu 18.04. -cmake_minimum_required (VERSION 3.10.2 FATAL_ERROR) +# This is the CMake version supplied by Ubuntu 20.04. +cmake_minimum_required (VERSION 3.16.3 FATAL_ERROR) find_program(CCACHE_PROGRAM ccache) if(CCACHE_PROGRAM) diff --git a/README.md b/README.md index 71acc45ea94..dc83eeb4944 100644 --- a/README.md +++ b/README.md @@ -230,7 +230,7 @@ use them, but YMMV. - `git` for version control -- CMake 3.10.2 or higher +- CMake 3.16.3 or higher - Boehm-Weiser garbage-collector C++ library @@ -283,6 +283,9 @@ Please note that while all Protobuf versions newer than 3.0 should work for `p4c` itself, you may run into trouble with some extensions and other p4lang projects unless you install version 3.18.1. +### CMake +p4c requires a CMake version of at least 3.16.3 or higher. On older systems, a newer version of CMake can be installed using `pip3 install --user cmake==3.16.3`. We have a CI test on Ubuntu 18.04 that uses this option, but there is no guarantee that this will lead to a successful build. + ## Fedora dependencies ```bash From 4d947a8e7a3ba2b29d178c522e24eaba1c041f07 Mon Sep 17 00:00:00 2001 From: fruffy Date: Mon, 19 Dec 2022 11:20:29 +0100 Subject: [PATCH 5/9] Install CMake 3.16.3 for Ubuntu 18.04. --- tools/ci-build.sh | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tools/ci-build.sh b/tools/ci-build.sh index b261bda5137..0be69e1b1bc 100755 --- a/tools/ci-build.sh +++ b/tools/ci-build.sh @@ -50,7 +50,6 @@ P4C_DIR=$(readlink -f ${THIS_DIR}/..) P4C_DEPS="bison \ build-essential \ ccache \ - cmake \ flex \ g++ \ git \ @@ -109,20 +108,28 @@ else P4C_DEPS+=" p4lang-bmv2" fi +# TODO: Remove this check once 18.04 is deprecated. +if [[ "${DISTRIB_RELEASE}" != "18.04" ]] ; then + P4C_DEPS+=" cmake" +fi + sudo apt-get update sudo apt-get install -y --no-install-recommends \ ${P4C_DEPS} \ ${P4C_EBPF_DEPS} \ ${P4C_RUNTIME_DEPS} +sudo pip3 install --upgrade pip +sudo pip3 install -r ${P4C_DIR}/requirements.txt + # TODO: Remove this check once 18.04 is deprecated. if [[ "${DISTRIB_RELEASE}" == "18.04" ]] ; then ccache --set-config cache_dir=.ccache + # For Ubuntu 18.04 install the pypi-supplied version of cmake instead. + sudo pip3 install cmake==3.16.3 fi ccache --set-config max_size=1G -sudo pip3 install --upgrade pip -sudo pip3 install -r ${P4C_DIR}/requirements.txt # Install add-ons to communicate with simple_switch_grpc via P4Runtime. # These packages are necessary because of a protobuf version mismatch in more recent Ubuntu distributions. From 44e8b98d4976071256d87ca8468b765d58e3fb01 Mon Sep 17 00:00:00 2001 From: fruffy Date: Fri, 6 Jan 2023 12:22:13 +0100 Subject: [PATCH 6/9] Cosmetic edits. --- .github/workflows/ci-test.yml | 10 +++++----- .github/workflows/ci-validation.yml | 12 ++++++++++-- CMakeLists.txt | 2 +- Dockerfile | 2 +- test/CMakeLists.txt | 4 ++-- tools/ci-build.sh | 4 ++-- tools/debian-build/packaging.conf | 2 +- 7 files changed, 22 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml index 9c297a87d6e..df088f2faca 100644 --- a/.github/workflows/ci-test.yml +++ b/.github/workflows/ci-test.yml @@ -43,16 +43,16 @@ jobs: # Build with gcc and test p4c on Ubuntu 20.04. test-ubuntu20: - name: test-ubuntu20 (Unified ${{ matrix.unified }}) + name: test-ubuntu20 (Unity ${{ matrix.unity }}) strategy: fail-fast: false matrix: - unified: [ON, OFF] + unity: [ON, OFF] runs-on: ubuntu-20.04 env: CTEST_PARALLEL_LEVEL: 4 IMAGE_TYPE: test - CMAKE_UNITY_BUILD: ${{ matrix.unified }} + CMAKE_UNITY_BUILD: ${{ matrix.unity }} steps: - uses: actions/checkout@v3 with: @@ -62,7 +62,7 @@ jobs: - name: ccache uses: hendrikmuhs/ccache-action@v1 with: - key: test-${{ matrix.unified }}-${{ runner.os }}-gcc + key: test-${{ matrix.unity }}-${{ runner.os }}-gcc max-size: 1000M - name: Build (Ubuntu 20.04, GCC) @@ -73,7 +73,7 @@ jobs: # Need to use sudo for the eBPF kernel tests. run: sudo -E ctest --output-on-failure --schedule-random working-directory: ./build - if: matrix.unified == 'ON' + if: matrix.unity == 'ON' # Build with clang and test p4c on Ubuntu 20.04. test-ubuntu20-clang-sanitizers: diff --git a/.github/workflows/ci-validation.yml b/.github/workflows/ci-validation.yml index 09098853f4c..939f9c4f502 100644 --- a/.github/workflows/ci-validation.yml +++ b/.github/workflows/ci-validation.yml @@ -20,6 +20,7 @@ jobs: CTEST_PARALLEL_LEVEL: 4 IMAGE_TYPE: test VALIDATION: ON + BUILD_SUCCESS: true runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v3 @@ -34,8 +35,15 @@ jobs: - name: Build (Ubuntu 20.04) run: | - tools/ci-build.sh + tools/ci-build.sh || echo "BUILD_SUCCESS=false" >> $GITHUB_ENV - name: Validate - run: ctest -R toz3-validate-p4c --output-on-failure --schedule-random + if: env.BUILD_SUCCESS == 'true' + run: | + ctest -R toz3-validate-p4c --output-on-failure --schedule-random working-directory: ./build + + - name: Build Failed + if: env.BUILD_SUCCESS == 'false' + run: | + echo "Building Gauntlet failed." diff --git a/CMakeLists.txt b/CMakeLists.txt index f4a4cb32172..9b6362d3092 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -101,7 +101,7 @@ if(ENABLE_UNIFIED_COMPILATION) set(CMAKE_UNITY_BUILD ON) endif() -# If unity builds are enable, choose an aggressive batch size. +# If unity builds are enabled, choose an aggressive batch size. if (CMAKE_UNITY_BUILD) set(CMAKE_UNITY_BUILD_BATCH_SIZE 16 CACHE UNINITIALIZED "Set the unity build batch size.") endif () diff --git a/Dockerfile b/Dockerfile index 78da118e3a3..651681475f7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,7 @@ ARG IN_DOCKER=TRUE # testing; in this case, the source code and build-only dependencies will not be # removed from the image. ARG IMAGE_TYPE=build -# Whether to do a unified build. +# Whether to do a unity build. ARG CMAKE_UNITY_BUILD=ON # Whether to enable translation validation ARG VALIDATION=OFF diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a57c27d7e42..b2ec649e326 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -69,7 +69,7 @@ set (GTEST_UNITTEST_HEADERS ) # Combine the executable and the non-backend-specific unit tests into a single -# unified compilation group. +# unity compilation group. set (GTEST_BASE_SOURCES gtest/gtestp4c.cpp ${GTEST_UNITTEST_SOURCES} @@ -77,7 +77,7 @@ set (GTEST_BASE_SOURCES # Merge the base sources with the tests added to GTEST_SOURCES by specific # backends or by extensions. We can't assume that one extension's GTests can be -# unified with another's, so we can't handle unified compilation transparently +# unity with another's, so we can't handle unity compilation transparently # for all GTests. # XXX(seth): The current approach is an awkward fit for cmake anyway. We should # restructure backend-specific GTests to live in their own libraries, and just diff --git a/tools/ci-build.sh b/tools/ci-build.sh index 0be69e1b1bc..6285588293c 100755 --- a/tools/ci-build.sh +++ b/tools/ci-build.sh @@ -17,7 +17,7 @@ P4C_DIR=$(readlink -f ${THIS_DIR}/..) # testing; in this case, the source code and build-only dependencies will not be # removed from the image. : "${IMAGE_TYPE:=build}" -# Whether to do a unified build. +# Whether to do a unity build. : "${CMAKE_UNITY_BUILD:=ON}" # Whether to enable translation validation : "${VALIDATION:=OFF}" @@ -237,7 +237,7 @@ fi # Strong optimization. export CXXFLAGS="${CXXFLAGS} -O3" -# Toggle unified compilation. +# Toggle unity compilation. CMAKE_FLAGS+="-DCMAKE_UNITY_BUILD=${CMAKE_UNITY_BUILD} " # Toggle static builds. CMAKE_FLAGS+="-DBUILD_STATIC_RELEASE=${BUILD_STATIC_RELEASE} " diff --git a/tools/debian-build/packaging.conf b/tools/debian-build/packaging.conf index 848568876ed..9da877b5e79 100644 --- a/tools/debian-build/packaging.conf +++ b/tools/debian-build/packaging.conf @@ -9,7 +9,7 @@ DEBIAN_DIR="${P4C_DIR}/debian" CONFOPT="" # Strong optimization. export CXXFLAGS="${CXXFLAGS} -O3" -# Enable unified compilation. +# Enable unity compilation. CONFOPT+="-DCMAKE_UNITY_BUILD=ON " # RELEASE should be default, but we want to make sure. CONFOPT+="-DCMAKE_BUILD_TYPE=RELEASE " From 94cf84feee65ced947621f63df9c493908e6a2be Mon Sep 17 00:00:00 2001 From: fruffy Date: Fri, 17 Feb 2023 10:47:38 -0500 Subject: [PATCH 7/9] Do not use generic namespaces when boost is present. --- frontends/common/parser_options.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/common/parser_options.cpp b/frontends/common/parser_options.cpp index bd196e1b53f..927f644971d 100644 --- a/frontends/common/parser_options.cpp +++ b/frontends/common/parser_options.cpp @@ -490,8 +490,8 @@ bool ParserOptions::isAnnotationDisabled(const IR::Annotation *a) const { } DebugHook ParserOptions::getDebugHook() const { - using namespace std::placeholders; - auto dp = std::bind(&ParserOptions::dumpPass, this, _1, _2, _3, _4); + auto dp = std::bind(&ParserOptions::dumpPass, this, std::placeholders::_1, + std::placeholders::_2, std::placeholders::_3, std::placeholders::_4); return dp; } From d5734d715715ed3f36d6ebbcb3ffc7cc7d8364be Mon Sep 17 00:00:00 2001 From: fruffy Date: Tue, 21 Feb 2023 15:56:33 -0500 Subject: [PATCH 8/9] Do not ignore Gauntlet build issues. --- .github/workflows/ci-validation.yml | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/.github/workflows/ci-validation.yml b/.github/workflows/ci-validation.yml index 939f9c4f502..dee4e98d0a0 100644 --- a/.github/workflows/ci-validation.yml +++ b/.github/workflows/ci-validation.yml @@ -20,7 +20,6 @@ jobs: CTEST_PARALLEL_LEVEL: 4 IMAGE_TYPE: test VALIDATION: ON - BUILD_SUCCESS: true runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v3 @@ -35,15 +34,9 @@ jobs: - name: Build (Ubuntu 20.04) run: | - tools/ci-build.sh || echo "BUILD_SUCCESS=false" >> $GITHUB_ENV + tools/ci-build.sh - name: Validate - if: env.BUILD_SUCCESS == 'true' run: | ctest -R toz3-validate-p4c --output-on-failure --schedule-random working-directory: ./build - - - name: Build Failed - if: env.BUILD_SUCCESS == 'false' - run: | - echo "Building Gauntlet failed." From d7a2c555acb27646a26074fc45e341d2d036568a Mon Sep 17 00:00:00 2001 From: fruffy Date: Wed, 22 Feb 2023 17:02:17 -0500 Subject: [PATCH 9/9] Rename p4runtime functions because of conflict gmock macro. --- .../control-plane/bfruntime_arch_handler.h | 19 +++--- .../bmv2/backend/protobuf/protobuf.cpp | 8 +-- .../targets/bmv2/backend/protobuf/protobuf.h | 5 +- control-plane/addMissingIds.cpp | 9 +-- control-plane/p4RuntimeArchHandler.h | 8 +-- control-plane/p4RuntimeArchStandard.cpp | 2 +- control-plane/p4RuntimeArchStandard.h | 60 +++++++++---------- control-plane/p4RuntimeSerializer.cpp | 19 +++--- control-plane/p4RuntimeSymbolTable.cpp | 10 ++-- 9 files changed, 71 insertions(+), 69 deletions(-) diff --git a/backends/dpdk/control-plane/bfruntime_arch_handler.h b/backends/dpdk/control-plane/bfruntime_arch_handler.h index 1a5ae0249d5..80a73bda8a2 100644 --- a/backends/dpdk/control-plane/bfruntime_arch_handler.h +++ b/backends/dpdk/control-plane/bfruntime_arch_handler.h @@ -58,7 +58,7 @@ class SymbolTypeDPDK final : public SymbolType { public: SymbolTypeDPDK() = delete; - static P4RuntimeSymbolType ACTION_SELECTOR() { + static P4RuntimeSymbolType P4RT_ACTION_SELECTOR() { return P4RuntimeSymbolType::make(dpdk::P4Ids::ACTION_SELECTOR); } }; @@ -76,7 +76,7 @@ struct ActionSelector { static constexpr int64_t defaultMaxGroupSize = 120; p4rt_id_t getId(const P4RuntimeSymbolTableIface &symbols) const { - return symbols.getId(SymbolTypeDPDK::ACTION_SELECTOR(), name + "_sel"); + return symbols.getId(SymbolTypeDPDK::P4RT_ACTION_SELECTOR(), name + "_sel"); } }; @@ -184,16 +184,17 @@ class BFRuntimeArchHandler : public P4RuntimeArchHandlerCommon { auto tablesIt = this->actionProfilesRefs.find(actionSelector.name); if (tablesIt != this->actionProfilesRefs.end()) { for (const auto &table : tablesIt->second) { - profile.add_table_ids(symbols.getId(P4RuntimeSymbolType::TABLE(), table)); - selector.add_table_ids(symbols.getId(P4RuntimeSymbolType::TABLE(), table)); + profile.add_table_ids(symbols.getId(P4RuntimeSymbolType::P4RT_TABLE(), table)); + selector.add_table_ids(symbols.getId(P4RuntimeSymbolType::P4RT_TABLE(), table)); } } // We use the ActionSelector name for the action profile, and add a "_sel" suffix for // the action selector. cstring profileName = actionSelector.name; - selector.set_action_profile_id(symbols.getId(SymbolType::ACTION_PROFILE(), profileName)); + selector.set_action_profile_id( + symbols.getId(SymbolType::P4RT_ACTION_PROFILE(), profileName)); cstring selectorName = profileName + "_sel"; - addP4InfoExternInstance(symbols, SymbolTypeDPDK::ACTION_SELECTOR(), "ActionSelector", + addP4InfoExternInstance(symbols, SymbolTypeDPDK::P4RT_ACTION_SELECTOR(), "ActionSelector", selectorName, actionSelector.annotations, selector, p4Info, pipeName); } @@ -205,12 +206,12 @@ class BFRuntimeArchHandler : public P4RuntimeArchHandlerCommon { auto decl = externBlock->node->to(); if (decl == nullptr) return; if (externBlock->type->name == "Digest") { - symbols->add(SymbolType::DIGEST(), decl); + symbols->add(SymbolType::P4RT_DIGEST(), decl); } else if (externBlock->type->name == ActionSelectorTraits::typeName()) { auto selName = decl->controlPlaneName() + "_sel"; auto profName = decl->controlPlaneName(); - symbols->add(SymbolTypeDPDK::ACTION_SELECTOR(), selName); - symbols->add(SymbolType::ACTION_PROFILE(), profName); + symbols->add(SymbolTypeDPDK::P4RT_ACTION_SELECTOR(), selName); + symbols->add(SymbolType::P4RT_ACTION_PROFILE(), profName); } } diff --git a/backends/p4tools/modules/testgen/targets/bmv2/backend/protobuf/protobuf.cpp b/backends/p4tools/modules/testgen/targets/bmv2/backend/protobuf/protobuf.cpp index ac89858a130..3d55d38132e 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/backend/protobuf/protobuf.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/backend/protobuf/protobuf.cpp @@ -62,8 +62,8 @@ boost::optional Protobuf::getIdAnnotation(const IR::IAnnotated *node) return static_cast(idConstant->value); } -boost::optional Protobuf::externalId(const P4RuntimeSymbolType &type, - const IR::IDeclaration *declaration) { +boost::optional Protobuf::externalId( + const P4::ControlPlaneAPI::P4RuntimeSymbolType &type, const IR::IDeclaration *declaration) { CHECK_NULL(declaration); if (!declaration->is()) { return boost::none; // Assign an id later; see below. @@ -129,7 +129,7 @@ inja::json Protobuf::getControlPlane(const TestSpec *testSpec) { const auto *const tblConfig = testObject.second->checkedTo(); const auto *table = tblConfig->getTable(); - auto p4RuntimeId = externalId(SymbolType::TABLE(), table); + auto p4RuntimeId = externalId(SymbolType::P4RT_TABLE(), table); BUG_CHECK(p4RuntimeId, "Id not present for table %1%. Can not generate test.", table); tblJson["id"] = *p4RuntimeId; @@ -142,7 +142,7 @@ inja::json Protobuf::getControlPlane(const TestSpec *testSpec) { const auto *actionDecl = actionCall->getAction(); const auto *actionArgs = actionCall->getArgs(); rule["action_name"] = actionCall->getActionName().c_str(); - auto p4RuntimeId = externalId(SymbolType::ACTION(), actionDecl); + auto p4RuntimeId = externalId(SymbolType::P4RT_ACTION(), actionDecl); BUG_CHECK(p4RuntimeId, "Id not present for action %1%. Can not generate test.", actionDecl); rule["action_id"] = *p4RuntimeId; diff --git a/backends/p4tools/modules/testgen/targets/bmv2/backend/protobuf/protobuf.h b/backends/p4tools/modules/testgen/targets/bmv2/backend/protobuf/protobuf.h index 5a8a39d479b..cd003c5123a 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/backend/protobuf/protobuf.h +++ b/backends/p4tools/modules/testgen/targets/bmv2/backend/protobuf/protobuf.h @@ -25,7 +25,6 @@ namespace P4Testgen { namespace Bmv2 { using P4::ControlPlaneAPI::p4rt_id_t; -using P4::ControlPlaneAPI::P4RuntimeSymbolType; using P4::ControlPlaneAPI::Standard::SymbolType; /// Extracts information from the @testSpec to emit a Protobuf test case. @@ -90,8 +89,8 @@ class Protobuf : public TF { /// @return the value of any P4 '@id' annotation @declaration may have, and /// ensure that the value is correct with respect to the P4Runtime /// specification. The name 'externalId' is in analogy with externalName(). - static boost::optional externalId(const P4RuntimeSymbolType &type, - const IR::IDeclaration *declaration); + static boost::optional externalId( + const P4::ControlPlaneAPI::P4RuntimeSymbolType &type, const IR::IDeclaration *declaration); }; } // namespace Bmv2 diff --git a/control-plane/addMissingIds.cpp b/control-plane/addMissingIds.cpp index c3edad531a7..6dedfccba56 100644 --- a/control-plane/addMissingIds.cpp +++ b/control-plane/addMissingIds.cpp @@ -59,7 +59,7 @@ const IR::P4Table *MissingIdAssigner::postorder(IR::P4Table *table) { const auto *annos = table->getAnnotations(); auto *newAnnos = annos->clone(); IR::Vector annoExprs; - auto symbolId = symbols->getId(ControlPlaneAPI::P4RuntimeSymbolType::TABLE(), table); + auto symbolId = symbols->getId(ControlPlaneAPI::P4RuntimeSymbolType::P4RT_TABLE(), table); const auto *idConst = new IR::Constant(new IR::Type_Bits(ID_BIT_WIDTH, false), symbolId); annoExprs.push_back(idConst); newAnnos->add(new IR::Annotation("id", annoExprs)); @@ -79,7 +79,7 @@ const IR::Type_Header *MissingIdAssigner::postorder(IR::Type_Header *hdr) { auto *newAnnos = annos->clone(); IR::Vector annoExprs; auto symbolId = - symbols->getId(ControlPlaneAPI::P4RuntimeSymbolType::CONTROLLER_HEADER(), hdr); + symbols->getId(ControlPlaneAPI::P4RuntimeSymbolType::P4RT_CONTROLLER_HEADER(), hdr); const auto *idConst = new IR::Constant(new IR::Type_Bits(ID_BIT_WIDTH, false), symbolId); annoExprs.push_back(idConst); newAnnos->add(new IR::Annotation("id", annoExprs)); @@ -99,7 +99,8 @@ const IR::P4ValueSet *MissingIdAssigner::postorder(IR::P4ValueSet *valueSet) { const auto *annos = valueSet->getAnnotations(); auto *newAnnos = annos->clone(); IR::Vector annoExprs; - auto symbolId = symbols->getId(ControlPlaneAPI::P4RuntimeSymbolType::VALUE_SET(), valueSet); + auto symbolId = + symbols->getId(ControlPlaneAPI::P4RuntimeSymbolType::P4RT_VALUE_SET(), valueSet); const auto *idConst = new IR::Constant(new IR::Type_Bits(ID_BIT_WIDTH, false), symbolId); annoExprs.push_back(idConst); newAnnos->add(new IR::Annotation("id", annoExprs)); @@ -118,7 +119,7 @@ const IR::P4Action *MissingIdAssigner::postorder(IR::P4Action *action) { const auto *annos = action->getAnnotations(); auto *newAnnos = annos->clone(); IR::Vector annoExprs; - auto symbolId = symbols->getId(ControlPlaneAPI::P4RuntimeSymbolType::ACTION(), action); + auto symbolId = symbols->getId(ControlPlaneAPI::P4RuntimeSymbolType::P4RT_ACTION(), action); const auto *idConst = new IR::Constant(new IR::Type_Bits(ID_BIT_WIDTH, false), symbolId); annoExprs.push_back(idConst); newAnnos->add(new IR::Annotation("id", annoExprs)); diff --git a/control-plane/p4RuntimeArchHandler.h b/control-plane/p4RuntimeArchHandler.h index 7f1716b3c5d..985f5e39a62 100644 --- a/control-plane/p4RuntimeArchHandler.h +++ b/control-plane/p4RuntimeArchHandler.h @@ -59,16 +59,16 @@ class P4RuntimeSymbolType { /// p4info.proto file. explicit operator p4rt_id_t() const { return id; } - static P4RuntimeSymbolType ACTION() { + static P4RuntimeSymbolType P4RT_ACTION() { return P4RuntimeSymbolType(::p4::config::v1::P4Ids::ACTION); } - static P4RuntimeSymbolType TABLE() { + static P4RuntimeSymbolType P4RT_TABLE() { return P4RuntimeSymbolType(::p4::config::v1::P4Ids::TABLE); } - static P4RuntimeSymbolType VALUE_SET() { + static P4RuntimeSymbolType P4RT_VALUE_SET() { return P4RuntimeSymbolType(::p4::config::v1::P4Ids::VALUE_SET); } - static P4RuntimeSymbolType CONTROLLER_HEADER() { + static P4RuntimeSymbolType P4RT_CONTROLLER_HEADER() { return P4RuntimeSymbolType(::p4::config::v1::P4Ids::CONTROLLER_HEADER); } diff --git a/control-plane/p4RuntimeArchStandard.cpp b/control-plane/p4RuntimeArchStandard.cpp index 8bb48d3eedd..b291046c50a 100644 --- a/control-plane/p4RuntimeArchStandard.cpp +++ b/control-plane/p4RuntimeArchStandard.cpp @@ -50,7 +50,7 @@ class P4RuntimeArchHandlerV1Model final : public P4RuntimeArchHandlerCommonadd(SymbolType::DIGEST(), digest->name); + if (digest) symbols->add(SymbolType::P4RT_DIGEST(), digest->name); } void addTableProperties(const P4RuntimeSymbolTableIface &symbols, p4configv1::P4Info *p4info, diff --git a/control-plane/p4RuntimeArchStandard.h b/control-plane/p4RuntimeArchStandard.h index a39aa84f1b2..e264199caf7 100644 --- a/control-plane/p4RuntimeArchStandard.h +++ b/control-plane/p4RuntimeArchStandard.h @@ -278,25 +278,25 @@ class SymbolType : public P4RuntimeSymbolType { public: SymbolType() = delete; - static P4RuntimeSymbolType ACTION_PROFILE() { + static P4RuntimeSymbolType P4RT_ACTION_PROFILE() { return P4RuntimeSymbolType::make(p4configv1::P4Ids::ACTION_PROFILE); } - static P4RuntimeSymbolType COUNTER() { + static P4RuntimeSymbolType P4RT_COUNTER() { return P4RuntimeSymbolType::make(p4configv1::P4Ids::COUNTER); } - static P4RuntimeSymbolType DIGEST() { + static P4RuntimeSymbolType P4RT_DIGEST() { return P4RuntimeSymbolType::make(p4configv1::P4Ids::DIGEST); } - static P4RuntimeSymbolType DIRECT_COUNTER() { + static P4RuntimeSymbolType P4RT_DIRECT_COUNTER() { return P4RuntimeSymbolType::make(p4configv1::P4Ids::DIRECT_COUNTER); } - static P4RuntimeSymbolType DIRECT_METER() { + static P4RuntimeSymbolType P4RT_DIRECT_METER() { return P4RuntimeSymbolType::make(p4configv1::P4Ids::DIRECT_METER); } - static P4RuntimeSymbolType METER() { + static P4RuntimeSymbolType P4RT_METER() { return P4RuntimeSymbolType::make(p4configv1::P4Ids::METER); } - static P4RuntimeSymbolType REGISTER() { + static P4RuntimeSymbolType P4RT_REGISTER() { return P4RuntimeSymbolType::make(p4configv1::P4Ids::REGISTER); } }; @@ -553,7 +553,7 @@ class P4RuntimeArchHandlerCommon : public P4RuntimeArchHandlerIface { "Expected an action profile or action selector: %1%", instance->expression); } else if (isConstructedInPlace) { - symbols->add(SymbolType::ACTION_PROFILE(), *instance->name); + symbols->add(SymbolType::P4RT_ACTION_PROFILE(), *instance->name); } } } @@ -565,7 +565,7 @@ class P4RuntimeArchHandlerCommon : public P4RuntimeArchHandlerIface { ::error(ErrorType::ERR_EXPECTED, "Expected a direct counter: %1%", instance->expression); } else if (isConstructedInPlace) { - symbols->add(SymbolType::DIRECT_COUNTER(), *instance->name); + symbols->add(SymbolType::P4RT_DIRECT_COUNTER(), *instance->name); } } } @@ -577,7 +577,7 @@ class P4RuntimeArchHandlerCommon : public P4RuntimeArchHandlerIface { ::error(ErrorType::ERR_EXPECTED, "Expected a direct meter: %1%", instance->expression); } else if (isConstructedInPlace) { - symbols->add(SymbolType::DIRECT_METER(), *instance->name); + symbols->add(SymbolType::P4RT_DIRECT_METER(), *instance->name); } } } @@ -594,18 +594,18 @@ class P4RuntimeArchHandlerCommon : public P4RuntimeArchHandlerIface { if (decl == nullptr) return; if (externBlock->type->name == CounterTraits::typeName()) { - symbols->add(SymbolType::COUNTER(), decl); + symbols->add(SymbolType::P4RT_COUNTER(), decl); } else if (externBlock->type->name == CounterTraits::directTypeName()) { - symbols->add(SymbolType::DIRECT_COUNTER(), decl); + symbols->add(SymbolType::P4RT_DIRECT_COUNTER(), decl); } else if (externBlock->type->name == MeterTraits::typeName()) { - symbols->add(SymbolType::METER(), decl); + symbols->add(SymbolType::P4RT_METER(), decl); } else if (externBlock->type->name == MeterTraits::directTypeName()) { - symbols->add(SymbolType::DIRECT_METER(), decl); + symbols->add(SymbolType::P4RT_DIRECT_METER(), decl); } else if (externBlock->type->name == ActionProfileTraits::typeName() || externBlock->type->name == ActionSelectorTraits::typeName()) { - symbols->add(SymbolType::ACTION_PROFILE(), decl); + symbols->add(SymbolType::P4RT_ACTION_PROFILE(), decl); } else if (externBlock->type->name == RegisterTraits::typeName()) { - symbols->add(SymbolType::REGISTER(), decl); + symbols->add(SymbolType::P4RT_REGISTER(), decl); } } @@ -648,7 +648,7 @@ class P4RuntimeArchHandlerCommon : public P4RuntimeArchHandlerIface { Helpers::getDirectCounterlike(tableDeclaration, refMap, typeMap); if (implementation) { - auto id = symbols.getId(SymbolType::ACTION_PROFILE(), implementation->name); + auto id = symbols.getId(SymbolType::P4RT_ACTION_PROFILE(), implementation->name); table->set_implementation_id(id); auto propertyName = ActionProfileTraits::propertyName(); if (isExternPropertyConstructedInPlace(tableDeclaration, propertyName)) @@ -656,14 +656,14 @@ class P4RuntimeArchHandlerCommon : public P4RuntimeArchHandlerIface { } if (directCounter) { - auto id = symbols.getId(SymbolType::DIRECT_COUNTER(), directCounter->name); + auto id = symbols.getId(SymbolType::P4RT_DIRECT_COUNTER(), directCounter->name); table->add_direct_resource_ids(id); // no risk to add twice because direct counters cannot be shared addCounter(symbols, p4info, *directCounter); } if (directMeter) { - auto id = symbols.getId(SymbolType::DIRECT_METER(), directMeter->name); + auto id = symbols.getId(SymbolType::P4RT_DIRECT_METER(), directMeter->name); table->add_direct_resource_ids(id); // no risk to add twice because direct meters cannot be shared addMeter(symbols, p4info, *directMeter); @@ -761,7 +761,7 @@ class P4RuntimeArchHandlerCommon : public P4RuntimeArchHandlerIface { void addActionProfile(const P4RuntimeSymbolTableIface &symbols, p4configv1::P4Info *p4Info, const ActionProfile &actionProfile) { auto profile = p4Info->add_action_profiles(); - auto id = symbols.getId(SymbolType::ACTION_PROFILE(), actionProfile.name); + auto id = symbols.getId(SymbolType::P4RT_ACTION_PROFILE(), actionProfile.name); setPreamble(profile->mutable_preamble(), id, actionProfile.name, symbols.getAlias(actionProfile.name), actionProfile.annotations, // exclude @max_group_size if present @@ -785,7 +785,7 @@ class P4RuntimeArchHandlerCommon : public P4RuntimeArchHandlerIface { auto tablesIt = actionProfilesRefs.find(actionProfile.name); if (tablesIt != actionProfilesRefs.end()) { for (const auto &table : tablesIt->second) - profile->add_table_ids(symbols.getId(P4RuntimeSymbolType::TABLE(), table)); + profile->add_table_ids(symbols.getId(P4RuntimeSymbolType::P4RT_TABLE(), table)); } } @@ -803,13 +803,13 @@ class P4RuntimeArchHandlerCommon : public P4RuntimeArchHandlerIface { const Helpers::Counterlike &counterInstance) { if (counterInstance.table) { auto counter = p4Info->add_direct_counters(); - auto id = symbols.getId(SymbolType::DIRECT_COUNTER(), counterInstance.name); + auto id = symbols.getId(SymbolType::P4RT_DIRECT_COUNTER(), counterInstance.name); setCounterCommon(symbols, counter, id, counterInstance); - auto tableId = symbols.getId(P4RuntimeSymbolType::TABLE(), *counterInstance.table); + auto tableId = symbols.getId(P4RuntimeSymbolType::P4RT_TABLE(), *counterInstance.table); counter->set_direct_table_id(tableId); } else { auto counter = p4Info->add_counters(); - auto id = symbols.getId(SymbolType::COUNTER(), counterInstance.name); + auto id = symbols.getId(SymbolType::P4RT_COUNTER(), counterInstance.name); setCounterCommon(symbols, counter, id, counterInstance); counter->set_size(counterInstance.size); if (counterInstance.index_type_name) { @@ -832,13 +832,13 @@ class P4RuntimeArchHandlerCommon : public P4RuntimeArchHandlerIface { const Helpers::Counterlike &meterInstance) { if (meterInstance.table) { auto meter = p4Info->add_direct_meters(); - auto id = symbols.getId(SymbolType::DIRECT_METER(), meterInstance.name); + auto id = symbols.getId(SymbolType::P4RT_DIRECT_METER(), meterInstance.name); setMeterCommon(symbols, meter, id, meterInstance); - auto tableId = symbols.getId(P4RuntimeSymbolType::TABLE(), *meterInstance.table); + auto tableId = symbols.getId(P4RuntimeSymbolType::P4RT_TABLE(), *meterInstance.table); meter->set_direct_table_id(tableId); } else { auto meter = p4Info->add_meters(); - auto id = symbols.getId(SymbolType::METER(), meterInstance.name); + auto id = symbols.getId(SymbolType::P4RT_METER(), meterInstance.name); setMeterCommon(symbols, meter, id, meterInstance); meter->set_size(meterInstance.size); if (meterInstance.index_type_name) { @@ -850,7 +850,7 @@ class P4RuntimeArchHandlerCommon : public P4RuntimeArchHandlerIface { void addRegister(const P4RuntimeSymbolTableIface &symbols, p4configv1::P4Info *p4Info, const Register ®isterInstance) { auto register_ = p4Info->add_registers(); - auto id = symbols.getId(SymbolType::REGISTER(), registerInstance.name); + auto id = symbols.getId(SymbolType::P4RT_REGISTER(), registerInstance.name); setPreamble(register_->mutable_preamble(), id, registerInstance.name, symbols.getAlias(registerInstance.name), registerInstance.annotations); register_->set_size(registerInstance.size); @@ -866,7 +866,7 @@ class P4RuntimeArchHandlerCommon : public P4RuntimeArchHandlerIface { // Right now we only take the type of data included in the digest // (encoded in its name) into account, but it may be that we should also // consider the receiver. - auto id = symbols.getId(SymbolType::DIGEST(), digest.name); + auto id = symbols.getId(SymbolType::P4RT_DIGEST(), digest.name); if (serializedInstances.find(id) != serializedInstances.end()) return; serializedInstances.insert(id); @@ -945,7 +945,7 @@ class P4RuntimeArchHandlerPSAPNA : public P4RuntimeArchHandlerCommon { auto decl = externBlock->node->to(); if (decl == nullptr) return; if (externBlock->type->name == "Digest") { - symbols->add(SymbolType::DIGEST(), decl); + symbols->add(SymbolType::P4RT_DIGEST(), decl); } } diff --git a/control-plane/p4RuntimeSerializer.cpp b/control-plane/p4RuntimeSerializer.cpp index 5b0701d83e8..ffec6452012 100644 --- a/control-plane/p4RuntimeSerializer.cpp +++ b/control-plane/p4RuntimeSerializer.cpp @@ -526,7 +526,7 @@ class P4RuntimeAnalyzer { if (isHidden(actionDeclaration)) return; auto name = actionDeclaration->controlPlaneName(); - auto id = symbols.getId(P4RuntimeSymbolType::ACTION(), name); + auto id = symbols.getId(P4RuntimeSymbolType::P4RT_ACTION(), name); auto annotations = actionDeclaration->to(); // TODO(antonin): The compiler creates a new instance of an action for @@ -599,7 +599,7 @@ class P4RuntimeAnalyzer { auto flattenedHeaderType = FlattenHeader::flatten(typeMap, type); auto name = type->controlPlaneName(); - auto id = symbols.getId(P4RuntimeSymbolType::CONTROLLER_HEADER(), name); + auto id = symbols.getId(P4RuntimeSymbolType::P4RT_CONTROLLER_HEADER(), name); auto annotations = type->to(); auto controllerAnnotation = type->getAnnotation("controller_header"); @@ -665,17 +665,18 @@ class P4RuntimeAnalyzer { auto annotations = tableDeclaration->to(); auto table = p4Info->add_tables(); - setPreamble(table->mutable_preamble(), symbols.getId(P4RuntimeSymbolType::TABLE(), name), - name, symbols.getAlias(name), annotations); + setPreamble(table->mutable_preamble(), + symbols.getId(P4RuntimeSymbolType::P4RT_TABLE(), name), name, + symbols.getAlias(name), annotations); table->set_size(tableSize); if (defaultAction && defaultAction->isConst) { - auto id = symbols.getId(P4RuntimeSymbolType::ACTION(), defaultAction->name); + auto id = symbols.getId(P4RuntimeSymbolType::P4RT_ACTION(), defaultAction->name); table->set_const_default_action_id(id); } for (const auto &action : actions) { - auto id = symbols.getId(P4RuntimeSymbolType::ACTION(), action.name); + auto id = symbols.getId(P4RuntimeSymbolType::P4RT_ACTION(), action.name); auto action_ref = table->add_action_refs(); action_ref->set_id(id); addAnnotations(action_ref, action.annotations); @@ -778,7 +779,7 @@ class P4RuntimeAnalyzer { } size = static_cast(sizeConstant->value); - auto id = symbols.getId(P4RuntimeSymbolType::VALUE_SET(), name); + auto id = symbols.getId(P4RuntimeSymbolType::P4RT_VALUE_SET(), name); setPreamble(vs->mutable_preamble(), id, name, symbols.getAlias(name), inst->to()); vs->set_size(size); @@ -1003,7 +1004,7 @@ class P4RuntimeEntriesConverter { if (entriesList == nullptr) return; auto tableName = archHandler->getControlPlaneName(tableBlock); - auto tableId = symbols.getId(P4RuntimeSymbolType::TABLE(), tableName); + auto tableId = symbols.getId(P4RuntimeSymbolType::P4RT_TABLE(), tableName); int entryPriority = entriesList->entries.size(); auto needsPriority = tableNeedsPriority(table, refMap); @@ -1060,7 +1061,7 @@ class P4RuntimeEntriesConverter { auto decl = refMap->getDeclaration(method, true); auto actionDecl = decl->to(); auto actionName = actionDecl->controlPlaneName(); - auto actionId = symbols.getId(P4RuntimeSymbolType::ACTION(), actionName); + auto actionId = symbols.getId(P4RuntimeSymbolType::P4RT_ACTION(), actionName); auto protoAction = protoEntry->mutable_action()->mutable_action(); protoAction->set_action_id(actionId); diff --git a/control-plane/p4RuntimeSymbolTable.cpp b/control-plane/p4RuntimeSymbolTable.cpp index abb023611ca..8e693bf254b 100644 --- a/control-plane/p4RuntimeSymbolTable.cpp +++ b/control-plane/p4RuntimeSymbolTable.cpp @@ -91,7 +91,7 @@ void collectControlSymbols(P4RuntimeSymbolTable &symbols, P4RuntimeArchHandlerIf forAllMatching(&control->controlLocals, [&](const IR::P4Action *action) { // Collect the action itself. - symbols.add(P4RuntimeSymbolType::ACTION(), action); + symbols.add(P4RuntimeSymbolType::P4RT_ACTION(), action); // Collect any extern functions it may invoke. forAllMatching( @@ -124,8 +124,8 @@ void collectTableSymbols(P4RuntimeSymbolTable &symbols, P4RuntimeArchHandlerIfac const IR::TableBlock *tableBlock) { CHECK_NULL(tableBlock); auto name = archHandler->getControlPlaneName(tableBlock); - auto id = externalId(P4RuntimeSymbolType::TABLE(), tableBlock->container); - symbols.add(P4RuntimeSymbolType::TABLE(), name, id); + auto id = externalId(P4RuntimeSymbolType::P4RT_TABLE(), tableBlock->container); + symbols.add(P4RuntimeSymbolType::P4RT_TABLE(), name, id); archHandler->collectTableProperties(&symbols, tableBlock); } @@ -137,7 +137,7 @@ void collectParserSymbols(P4RuntimeSymbolTable &symbols, const IR::ParserBlock * for (const auto *s : parser->parserLocals) { if (const auto *inst = s->to()) { - symbols.add(P4RuntimeSymbolType::VALUE_SET(), inst); + symbols.add(P4RuntimeSymbolType::P4RT_VALUE_SET(), inst); } } } @@ -161,7 +161,7 @@ P4::ControlPlaneAPI::P4RuntimeSymbolTable::generateSymbols( }); forAllMatching(program, [&](const IR::Type_Header *type) { if (isControllerHeader(type)) { - symbols.add(P4RuntimeSymbolType::CONTROLLER_HEADER(), type); + symbols.add(P4RuntimeSymbolType::P4RT_CONTROLLER_HEADER(), type); } }); archHandler->collectExtra(&symbols);