diff --git a/.github/workflows/ci-p4tools.yml b/.github/workflows/ci-p4tools.yml index 6f0101d7cf..77388b231e 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 b2a0baa594..0a45a8c7a5 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 6c7698ad6e..e0204a378c 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 9eb4487628..9bf3a68804 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 f4cffb7b02..df088f2fac 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: @@ -44,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 - ENABLE_UNIFIED_COMPILATION: ${{ matrix.unified }} + CMAKE_UNITY_BUILD: ${{ matrix.unity }} steps: - uses: actions/checkout@v3 with: @@ -63,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) @@ -74,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: @@ -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 ac0976fdfc..dee4e98d0a 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: @@ -38,5 +37,6 @@ jobs: tools/ci-build.sh - name: Validate - run: ctest -R toz3-validate-p4c --output-on-failure --schedule-random + run: | + ctest -R toz3-validate-p4c --output-on-failure --schedule-random working-directory: ./build diff --git a/CMakeLists.txt b/CMakeLists.txt index 837bf33c55..9b6362d309 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) @@ -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") @@ -83,13 +85,26 @@ 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) + +# 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() + +# 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 () # 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 dec88bab21..651681475f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,8 +13,8 @@ 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. -ARG ENABLE_UNIFIED_COMPILATION=ON +# Whether to do a unity build. +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/README.md b/README.md index 71acc45ea9..dc83eeb494 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 diff --git a/backends/bmv2/CMakeLists.txt b/backends/bmv2/CMakeLists.txt index 1d06b31542..2162539230 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/dpdk/control-plane/bfruntime_arch_handler.h b/backends/dpdk/control-plane/bfruntime_arch_handler.h index 1a5ae0249d..80a73bda8a 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/ebpf/CMakeLists.txt b/backends/ebpf/CMakeLists.txt index 18f35840a2..3ff818e5b6 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 867423662b..0cad2270ec 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 03ef639496..6673f68efb 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 b17a37d72f..29173f5b6d 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 a954a35619..3d55d38132 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; @@ -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 421c3daa2b..cd003c5123 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. @@ -63,6 +62,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); @@ -87,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/backends/p4tools/modules/testgen/targets/bmv2/backend/ptf/ptf.cpp b/backends/p4tools/modules/testgen/targets/bmv2/backend/ptf/ptf.cpp index 1853097d06..1746ff6776 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 abc8dd3820..b29c265ebf 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 3f02ef272d..e4dc3f5f9b 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 f8a9bb59d7..81fb7ae72a 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 c6afb39736..99e29c356c 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 ef35f022c9..56b0ec6e7e 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 71f520ab72..aaec86f38c 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 37f90c16f0..76840f7b3e 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 adaa0ae963..9f1ad73192 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 1cd54a651b..deda585bc7 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 d0f49f1c0b..31ef28ff2d 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 2b3ea2040b..949d2bf644 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 01d23e885f..4f5f710f7b 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/control-plane/addMissingIds.cpp b/control-plane/addMissingIds.cpp index c3edad531a..6dedfccba5 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 7f1716b3c5..985f5e39a6 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 8bb48d3eed..b291046c50 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 a39aa84f1b..e264199caf 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 5b0701d83e..ffec645201 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 abb023611c..8e693bf254 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); diff --git a/frontends/CMakeLists.txt b/frontends/CMakeLists.txt index 89abb8c9c9..dfd1b5a412 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/frontends/common/parser_options.cpp b/frontends/common/parser_options.cpp index bd196e1b53..927f644971 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; } diff --git a/ir/CMakeLists.txt b/ir/CMakeLists.txt index 312c3d0d88..e0dbd22607 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 376ff346d3..1a30cbc7bf 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 a8e5b6c4e3..3fc152d9ad 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 e4f38ed1b2..ee664cd8a0 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 aab0545d2b..d24325647d 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 0807c125a1..b2ec649e32 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -69,16 +69,15 @@ 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} ) -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 -# 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 e63def5775..6285588293 100755 --- a/tools/ci-build.sh +++ b/tools/ci-build.sh @@ -17,8 +17,8 @@ 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. -: "${ENABLE_UNIFIED_COMPILATION:=ON}" +# Whether to do a unity build. +: "${CMAKE_UNITY_BUILD:=ON}" # Whether to enable translation validation : "${VALIDATION:=OFF}" # This creates a release build that includes link time optimization and links @@ -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. @@ -230,8 +237,8 @@ fi # Strong optimization. export CXXFLAGS="${CXXFLAGS} -O3" -# Toggle unified compilation. -CMAKE_FLAGS+="-DENABLE_UNIFIED_COMPILATION=${ENABLE_UNIFIED_COMPILATION} " +# Toggle unity 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 d204cef28c..9da877b5e7 100644 --- a/tools/debian-build/packaging.conf +++ b/tools/debian-build/packaging.conf @@ -9,8 +9,8 @@ DEBIAN_DIR="${P4C_DIR}/debian" CONFOPT="" # Strong optimization. export CXXFLAGS="${CXXFLAGS} -O3" -# Enable unified compilation. -CONFOPT+="-DENABLE_UNIFIED_COMPILATION=ON " +# Enable unity compilation. +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 66b5b925b9..120b8c6191 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.