Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Enable PCHs for IR headers #5033

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ OPTION (BUILD_AUTO_VAR_INIT_PATTERN "Initialize variables with pattern during bu
OPTION (ENABLE_IWYU "Enable checking includes with IWYU" OFF)
# Support a legacy option. TODO: Remove?
OPTION (ENABLE_UNIFIED_COMPILATION "Enable CMAKE_UNITY_BUILD" OFF)
OPTION (ENABLE_PCH "Enable PCH for IR headers" OFF)

set (P4C_DRIVER_NAME "p4c" CACHE STRING "Customize the name of the driver script")

Expand Down Expand Up @@ -135,8 +136,8 @@ if(ENABLE_UNIFIED_COMPILATION)
set(CMAKE_UNITY_BUILD ON)
endif()

# If unity builds are enabled, choose an aggressive batch size.
if (CMAKE_UNITY_BUILD)
# If unity builds are enabled, choose an aggressive batch size.
set(CMAKE_UNITY_BUILD_BATCH_SIZE 10 CACHE UNINITIALIZED "Set the unity build batch size.")
endif ()

Expand Down Expand Up @@ -535,7 +536,9 @@ set_source_files_properties(${IR_GENERATOR} PROPERTIES GENERATED TRUE)
add_library(ir-generated OBJECT ${IR_GENERATED_SRCS} ${EXTENSION_IR_SOURCES})
add_dependencies(ir-generated ir genIR)
target_link_libraries(ir-generated PUBLIC ir ${P4C_LIB_DEPS})

if (ENABLE_PCH)
target_precompile_headers(ir-generated REUSE_FROM ir)
endif()

######################################## IR Generation End ########################################

Expand Down
9 changes: 9 additions & 0 deletions backends/bmv2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ target_link_libraries(bmv2backend ir-generated frontend backends-common)

add_executable(p4c-bm2-ss ${BMV2_SIMPLE_SWITCH_SRCS})
target_link_libraries (p4c-bm2-ss bmv2backend ${P4C_LIBRARIES} ${P4C_LIB_DEPS})
if (ENABLE_PCH)
target_precompile_headers(p4c-bm2-ss REUSE_FROM ir)
endif()

install(TARGETS p4c-bm2-ss RUNTIME DESTINATION ${P4C_RUNTIME_OUTPUT_DIRECTORY})

Expand All @@ -113,10 +116,16 @@ target_link_libraries(portable-common bmv2backend)

add_executable(p4c-bm2-psa ${BMV2_PSA_SWITCH_SRCS})
target_link_libraries (p4c-bm2-psa portable-common ${P4C_LIBRARIES} ${P4C_LIB_DEPS})
if (ENABLE_PCH)
target_precompile_headers(p4c-bm2-psa REUSE_FROM ir)
endif()
install(TARGETS p4c-bm2-psa RUNTIME DESTINATION ${P4C_RUNTIME_OUTPUT_DIRECTORY})

add_executable(p4c-bm2-pna ${BMV2_PNA_NIC_SRCS})
target_link_libraries (p4c-bm2-pna portable-common ${P4C_LIBRARIES} ${P4C_LIB_DEPS})
if (ENABLE_PCH)
target_precompile_headers(p4c-bm2-pna REUSE_FROM ir)
endif()
install(TARGETS p4c-bm2-pna RUNTIME DESTINATION ${P4C_RUNTIME_OUTPUT_DIRECTORY})

file(RELATIVE_PATH
Expand Down
3 changes: 3 additions & 0 deletions backends/dpdk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ set(EXTENSION_IR_SOURCES ${EXTENSION_IR_SOURCES} ${QUAL_DPDK_IR_SRCS} PARENT_SCO

add_executable(p4c-dpdk ${P4C_DPDK_SOURCES})
target_link_libraries (p4c-dpdk dpdk_runtime frontend ${P4C_LIBRARIES} ${P4C_LIB_DEPS})
if (ENABLE_PCH)
target_precompile_headers(p4c-dpdk REUSE_FROM ir)
endif()

install (TARGETS p4c-dpdk
RUNTIME DESTINATION ${P4C_RUNTIME_OUTPUT_DIRECTORY})
Expand Down
4 changes: 3 additions & 1 deletion backends/ebpf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ set (P4C_EBPF_DIST_HEADERS

add_executable(p4c-ebpf ${P4C_EBPF_SRCS})
target_link_libraries (p4c-ebpf ${P4C_LIBRARIES} ${P4C_LIB_DEPS} backends-common)
add_dependencies(p4c-ebpf ir-generated frontend)
if (ENABLE_PCH)
target_precompile_headers(p4c-ebpf REUSE_FROM ir)
endif()

install (TARGETS p4c-ebpf
RUNTIME DESTINATION ${P4C_RUNTIME_OUTPUT_DIRECTORY})
Expand Down
5 changes: 4 additions & 1 deletion backends/graphs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ add_library(p4cgraphs STATIC ${GRAPHS_SRCS} ${EXTENSION_P4_14_CONV_SOURCES})
target_link_libraries(p4cgraphs ir-generated frontend)

add_executable(p4c-graphs p4c-graphs.cpp)
target_link_libraries (p4c-graphs p4cgraphs ir-generated frontend ${P4C_LIBRARIES} ${P4C_LIB_DEPS})
target_link_libraries (p4c-graphs p4cgraphs frontend ${P4C_LIBRARIES} ${P4C_LIB_DEPS})
if (ENABLE_PCH)
target_precompile_headers(p4c-graphs REUSE_FROM ir)
endif()

install (TARGETS p4c-graphs
RUNTIME DESTINATION ${P4C_RUNTIME_OUTPUT_DIRECTORY})
Expand Down
7 changes: 6 additions & 1 deletion backends/p4fmt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ set(REFCHECK_SRCS
# p4fmt
add_executable(p4fmt ${FMT_SRCS})
target_link_libraries(p4fmt ${P4C_LIBRARIES} ${P4C_LIB_DEPS})
add_dependencies(p4fmt frontend)
if (ENABLE_PCH)
target_precompile_headers(p4fmt REUSE_FROM ir)
endif()

add_custom_target(p4formatter
COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_CURRENT_BINARY_DIR}/p4fmt ${P4C_BINARY_DIR}/p4fmt
Expand All @@ -26,6 +28,9 @@ add_custom_target(p4formatter
# p4fmt - reference checker
add_executable(checkfmt ${REFCHECK_SRCS})
target_link_libraries(checkfmt ${P4C_LIBRARIES} ${P4C_LIB_DEPS})
if (ENABLE_PCH)
target_precompile_headers(checkfmt REUSE_FROM ir)
endif()

add_custom_target(p4refchecker
COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_CURRENT_BINARY_DIR}/checkfmt ${P4C_BINARY_DIR}/checkfmt
Expand Down
4 changes: 3 additions & 1 deletion backends/p4test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ set (P4TEST_HDRS

add_executable(p4test ${P4TEST_SRCS} ${EXTENSION_P4_14_CONV_SOURCES})
target_link_libraries (p4test ${P4C_LIBRARIES} ${P4C_LIB_DEPS})
add_dependencies(p4test ir-generated frontend)
if (ENABLE_PCH)
target_precompile_headers(p4test REUSE_FROM ir)
endif()

install (TARGETS p4test
RUNTIME DESTINATION ${P4C_RUNTIME_OUTPUT_DIRECTORY})
Expand Down
3 changes: 3 additions & 0 deletions backends/p4tools/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ target_link_libraries(
# For Abseil includes.
PRIVATE frontend
)
if (ENABLE_PCH)
target_precompile_headers(p4tools-common REUSE_FROM ir)
endif()

target_include_directories(
p4tools-common
Expand Down
3 changes: 3 additions & 0 deletions backends/p4tools/modules/smith/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ target_link_libraries(smith
# For Abseil includes.
PRIVATE frontend
)
if (ENABLE_PCH)
target_precompile_headers(smith REUSE_FROM ir)
endif()

add_dependencies(smith p4tools-common)

Expand Down
3 changes: 3 additions & 0 deletions backends/p4tools/modules/testgen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ target_link_libraries(testgen
if (TESTGEN_INCLUDES)
target_include_directories(testgen ${TESTGEN_INCLUDES})
endif()
if (ENABLE_PCH)
target_precompile_headers(testgen REUSE_FROM ir)
endif()

# The executable.
add_p4tools_executable(p4testgen main.cpp)
Expand Down
4 changes: 3 additions & 1 deletion backends/tc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ set (IR_DEF_FILES ${IR_DEF_FILES} ${CMAKE_CURRENT_SOURCE_DIR}/tc.def PARENT_SCOP
# build
add_executable(p4c-pna-p4tc ${P4TC_BACKEND_SOURCES})
target_link_libraries (p4c-pna-p4tc ${P4C_LIBRARIES} ${P4C_LIB_DEPS} backends-common)
add_dependencies(p4c-pna-p4tc genIR)
if (ENABLE_PCH)
target_precompile_headers(p4c-pna-p4tc REUSE_FROM ir)
endif()

# install
install (TARGETS p4c-pna-p4tc
Expand Down
4 changes: 3 additions & 1 deletion backends/ubpf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ set (P4C_UBPF_DIST_HEADERS p4include/ubpf_model.p4)

add_executable(p4c-ubpf ${P4C_UBPF_SOURCES})
target_link_libraries (p4c-ubpf ${P4C_LIBRARIES} ${P4C_LIB_DEPS})
add_dependencies(p4c-ubpf ir-generated frontend)
if (ENABLE_PCH)
target_precompile_headers(p4c-ubpf REUSE_FROM ir)
endif()

install (TARGETS p4c-ubpf
RUNTIME DESTINATION ${P4C_RUNTIME_OUTPUT_DIRECTORY})
Expand Down
3 changes: 3 additions & 0 deletions frontends/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,6 @@ target_link_libraries (frontend
PUBLIC absl::flat_hash_set
PUBLIC absl::flat_hash_map
)
if (ENABLE_PCH)
target_precompile_headers(frontend REUSE_FROM ir)
endif()
13 changes: 10 additions & 3 deletions ir/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,18 @@ set (BASE_IR_DEF_FILES
)

set (IR_DEF_FILES ${IR_DEF_FILES} ${BASE_IR_DEF_FILES} PARENT_SCOPE)
set (PCH_IR_HDRS ${IR_HDRS})
list(REMOVE_ITEM PCH_IR_HDRS ir-inline.h)

add_library (ir STATIC ${IR_SRCS})
add_library(ir STATIC ${IR_SRCS})
target_link_libraries(ir PRIVATE absl::flat_hash_map ${LIBGC_LIBRARIES})


if (ENABLE_PCH)
# We use PRIVATE here not to populate PRECOMPILED_HEADERS of anything that
# links to IR (as this would re-build PCH for every such target). Instead,
# we rely on consumer to manage PCH usage explicitly
# (e.g. via target_precompile_headers(<user> REUSE_FROM ir)
target_precompile_headers(ir PRIVATE ${PCH_IR_HDRS})
endif()
add_dependencies(ir genIR)


8 changes: 6 additions & 2 deletions ir/irutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
#include "lib/big_int_util.h"
#include "lib/source_file.h"

namespace P4 {

class Transform;

namespace P4::IR {
namespace IR {

// Forward-declare some IR classes that are used in function declarations.
class BoolLiteral;
Expand Down Expand Up @@ -128,6 +130,8 @@ const IR::Node *inlineBlock(const Transform &, std::initializer_list<const IR::S
const IR::Node *inlineBlock(const Transform &, const IR::IndexedVector<IR::StatOrDecl> &);
const IR::Node *inlineBlock(const Transform &, IR::IndexedVector<IR::StatOrDecl> &&);

} // namespace P4::IR
} // namespace IR

} // namespace P4

#endif /* IR_IRUTILS_H_ */
3 changes: 3 additions & 0 deletions midend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,6 @@ target_link_libraries(midend
PRIVATE frontend
)
add_dependencies(midend genIR ir-generated)
if (ENABLE_PCH)
target_precompile_headers(midend REUSE_FROM ir)
endif()
Loading