diff --git a/CMakeLists.txt b/CMakeLists.txt index 0f992fce4..0626e43b8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -212,6 +212,18 @@ if (${SPIRV_CHECK_CONTEXT}) add_definitions(-DSPIRV_CHECK_CONTEXT) endif() +# Precompiled header macro. Parameters are source file list and filename for pch cpp file. +macro(PCH SRCS PCHPREFIX) + if(MSVC AND CMAKE_GENERATOR MATCHES "^Visual Studio") + set(PCH_NAME "$(IntDir)\\${PCHPREFIX}.pch") + # make source files use/depend on PCH_NAME + set_source_files_properties(${${SRCS}} PROPERTIES COMPILE_FLAGS "/Yu${PCHPREFIX}.h /FI${PCHPREFIX}.h /Fp${PCH_NAME} /Zm300" OBJECT_DEPENDS "${PCH_NAME}") + # make PCHPREFIX.cpp file compile and generate PCH_NAME + set_source_files_properties("${PCHPREFIX}.cpp" PROPERTIES COMPILE_FLAGS "/Yc${PCHPREFIX}.h /Fp${PCH_NAME} /Zm300" OBJECT_OUTPUTS "${PCH_NAME}") + list(APPEND ${SRCS} "${PCHPREFIX}.cpp") + endif() +endmacro(PCH) + add_subdirectory(external) add_subdirectory(source) diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index ea619f28c..068fbbf86 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -184,10 +184,10 @@ set_source_files_properties( PROPERTIES OBJECT_DEPENDS "${ENUM_STRING_MAPPING_CPP_DEPENDS}") set_source_files_properties( - ${CMAKE_CURRENT_SOURCE_DIR}/extension.h + ${CMAKE_CURRENT_SOURCE_DIR}/extensions.h PROPERTIES HEADER_FILE_ONLY TRUE) set_source_files_properties( - ${CMAKE_CURRENT_SOURCE_DIR}/extension.h + ${CMAKE_CURRENT_SOURCE_DIR}/extensions.h PROPERTIES OBJECT_DEPENDS "${EXTENSION_H_DEPENDS}") set(SPIRV_TOOLS_BUILD_VERSION_INC @@ -209,6 +209,11 @@ add_custom_target(spirv-tools-build-version DEPENDS ${SPIRV_TOOLS_BUILD_VERSION_INC}) set_property(TARGET spirv-tools-build-version PROPERTY FOLDER "SPIRV-Tools build") +list(APPEND PCH_DEPENDS ${ENUM_STRING_MAPPING_CPP_DEPENDS} ${OPCODE_CPP_DEPENDS} ${OPERAND_CPP_DEPENDS} ${EXTENSION_H_DEPENDS} ${EXTINST_CPP_DEPENDS} ${SPIRV_TOOLS_BUILD_VERSION_INC}) +set_source_files_properties( + ${CMAKE_CURRENT_SOURCE_DIR}/pch_source.cpp + PROPERTIES OBJECT_DEPENDS "${PCH_DEPENDS}") + add_subdirectory(comp) add_subdirectory(opt) add_subdirectory(link) @@ -340,6 +345,8 @@ set_source_files_properties( ${CMAKE_CURRENT_SOURCE_DIR}/software_version.cpp PROPERTIES OBJECT_DEPENDS "${SPIRV_TOOLS_BUILD_VERSION_INC}") +PCH(SPIRV_SOURCES pch_source) + add_library(${SPIRV_TOOLS} ${SPIRV_SOURCES}) spvtools_default_compile_options(${SPIRV_TOOLS}) target_include_directories(${SPIRV_TOOLS} diff --git a/source/opt/CMakeLists.txt b/source/opt/CMakeLists.txt index fd52ca6c4..eab78a64b 100644 --- a/source/opt/CMakeLists.txt +++ b/source/opt/CMakeLists.txt @@ -188,18 +188,10 @@ set(SPIRV_TOOLS_OPT_SOURCES if(MSVC) # Enable parallel builds across four cores for this lib add_definitions(/MP4) - - # Enable precompiled header - if (CMAKE_GENERATOR MATCHES "^Visual Studio") - set(PCH_NAME "$(IntDir)\\pch.pch") - else() - set(PCH_NAME "pch.pch") - endif() - set_source_files_properties(${SPIRV_TOOLS_OPT_SOURCES} PROPERTIES COMPILE_FLAGS "/Yupch.h /FIpch.h /Fp${PCH_NAME} /Zm300" OBJECT_DEPENDS "${PCH_NAME}") - set_source_files_properties(pch.cpp PROPERTIES COMPILE_FLAGS "/Ycpch.h /Fp${PCH_NAME} /Zm300" OBJECT_OUTPUTS "${PCH_NAME}") - list(APPEND SPIRV_TOOLS_OPT_SOURCES "pch.cpp") endif() +PCH(SPIRV_TOOLS_OPT_SOURCES pch_source_opt) + add_library(SPIRV-Tools-opt ${SPIRV_TOOLS_OPT_SOURCES}) spvtools_default_compile_options(SPIRV-Tools-opt) diff --git a/source/opt/pch_source_opt.cpp b/source/opt/pch_source_opt.cpp new file mode 100644 index 000000000..f45448dc5 --- /dev/null +++ b/source/opt/pch_source_opt.cpp @@ -0,0 +1,15 @@ +// Copyright (c) 2018 The Khronos Group Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "pch_source_opt.h" diff --git a/source/opt/pch.h b/source/opt/pch_source_opt.h similarity index 100% rename from source/opt/pch.h rename to source/opt/pch_source_opt.h diff --git a/source/pch_source.cpp b/source/pch_source.cpp new file mode 100644 index 000000000..032e29ec4 --- /dev/null +++ b/source/pch_source.cpp @@ -0,0 +1,15 @@ +// Copyright (c) 2018 The Khronos Group Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "pch_source.h" diff --git a/source/pch_source.h b/source/pch_source.h new file mode 100644 index 000000000..6695ba268 --- /dev/null +++ b/source/pch_source.h @@ -0,0 +1,15 @@ +// Copyright (c) 2018 The Khronos Group Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "source/val/validation_state.h" diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a8db33ca9..f2d05bead 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -30,12 +30,16 @@ endif() function(add_spvtools_unittest) if (NOT "${SPIRV_SKIP_TESTS}" AND TARGET gmock_main) - set(one_value_args TARGET) + set(one_value_args TARGET PCH_FILE) set(multi_value_args SRCS LIBS ENVIRONMENT) cmake_parse_arguments( ARG "" "${one_value_args}" "${multi_value_args}" ${ARGN}) set(target test_${ARG_TARGET}) - add_executable(${target} ${ARG_SRCS}) + set(SRC_COPY ${ARG_SRCS}) + if (DEFINED ARG_PCH_FILE) + PCH(SRC_COPY ${ARG_PCH_FILE}) + endif() + add_executable(${target} ${SRC_COPY}) spvtools_default_compile_options(${target}) if(${COMPILER_IS_LIKE_GNU}) target_compile_options(${target} PRIVATE -Wno-undef) @@ -147,6 +151,8 @@ set(TEST_SOURCES unit_spirv.cpp ) +PCH(TEST_SOURCES pch_test) + add_spvtools_unittest( TARGET spirv_unit_tests SRCS ${TEST_SOURCES} diff --git a/test/opt/dominator_tree/CMakeLists.txt b/test/opt/dominator_tree/CMakeLists.txt index f95a56da8..813d628a0 100644 --- a/test/opt/dominator_tree/CMakeLists.txt +++ b/test/opt/dominator_tree/CMakeLists.txt @@ -27,4 +27,5 @@ add_spvtools_unittest(TARGET dominator_analysis unreachable_for.cpp unreachable_for_post.cpp LIBS SPIRV-Tools-opt + PCH_FILE pch_test_opt_dom ) diff --git a/test/opt/dominator_tree/pch_test_opt_dom.cpp b/test/opt/dominator_tree/pch_test_opt_dom.cpp new file mode 100644 index 000000000..a28310e57 --- /dev/null +++ b/test/opt/dominator_tree/pch_test_opt_dom.cpp @@ -0,0 +1,15 @@ +// Copyright (c) 2018 The Khronos Group Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "pch_test_opt_dom.h" diff --git a/test/opt/dominator_tree/pch_test_opt_dom.h b/test/opt/dominator_tree/pch_test_opt_dom.h new file mode 100644 index 000000000..4e8106fbf --- /dev/null +++ b/test/opt/dominator_tree/pch_test_opt_dom.h @@ -0,0 +1,25 @@ +// Copyright (c) 2018 The Khronos Group Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "gmock/gmock.h" +#include "source/opt/iterator.h" +#include "source/opt/loop_dependence.h" +#include "source/opt/loop_descriptor.h" +#include "source/opt/pass.h" +#include "source/opt/scalar_analysis.h" +#include "source/opt/tree_iterator.h" +#include "test/opt/assembly_builder.h" +#include "test/opt/function_utils.h" +#include "test/opt/pass_fixture.h" +#include "test/opt/pass_utils.h" diff --git a/test/opt/loop_optimizations/CMakeLists.txt b/test/opt/loop_optimizations/CMakeLists.txt index 8c7971b7f..e3620787d 100644 --- a/test/opt/loop_optimizations/CMakeLists.txt +++ b/test/opt/loop_optimizations/CMakeLists.txt @@ -37,4 +37,5 @@ add_spvtools_unittest(TARGET opt_loops unroll_simple.cpp unswitch.cpp LIBS SPIRV-Tools-opt + PCH_FILE pch_test_opt_loop ) diff --git a/test/opt/loop_optimizations/pch_test_opt_loop.cpp b/test/opt/loop_optimizations/pch_test_opt_loop.cpp new file mode 100644 index 000000000..f4ac7b298 --- /dev/null +++ b/test/opt/loop_optimizations/pch_test_opt_loop.cpp @@ -0,0 +1,15 @@ +// Copyright (c) 2018 The Khronos Group Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "pch_test_opt_loop.h" diff --git a/test/opt/loop_optimizations/pch_test_opt_loop.h b/test/opt/loop_optimizations/pch_test_opt_loop.h new file mode 100644 index 000000000..4e8106fbf --- /dev/null +++ b/test/opt/loop_optimizations/pch_test_opt_loop.h @@ -0,0 +1,25 @@ +// Copyright (c) 2018 The Khronos Group Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "gmock/gmock.h" +#include "source/opt/iterator.h" +#include "source/opt/loop_dependence.h" +#include "source/opt/loop_descriptor.h" +#include "source/opt/pass.h" +#include "source/opt/scalar_analysis.h" +#include "source/opt/tree_iterator.h" +#include "test/opt/assembly_builder.h" +#include "test/opt/function_utils.h" +#include "test/opt/pass_fixture.h" +#include "test/opt/pass_utils.h" diff --git a/source/opt/pch.cpp b/test/pch_test.cpp similarity index 96% rename from source/opt/pch.cpp rename to test/pch_test.cpp index b8d3f6c3b..3b06a0aa2 100644 --- a/source/opt/pch.cpp +++ b/test/pch_test.cpp @@ -12,4 +12,4 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "pch.h" +#include "pch_test.h" diff --git a/test/pch_test.h b/test/pch_test.h new file mode 100644 index 000000000..7dac06acf --- /dev/null +++ b/test/pch_test.h @@ -0,0 +1,18 @@ +// Copyright (c) 2018 The Khronos Group Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "gmock/gmock.h" +#include "source/spirv_constant.h" +#include "test/test_fixture.h" +#include "test/unit_spirv.h" diff --git a/test/val/CMakeLists.txt b/test/val/CMakeLists.txt index 14f355a38..3d0eeba08 100644 --- a/test/val/CMakeLists.txt +++ b/test/val/CMakeLists.txt @@ -38,6 +38,7 @@ add_spvtools_unittest(TARGET val_abcde val_ext_inst_test.cpp ${VAL_TEST_COMMON_SRCS} LIBS ${SPIRV_TOOLS} + PCH_FILE pch_test_val ) add_spvtools_unittest(TARGET val_limits @@ -59,6 +60,7 @@ add_spvtools_unittest(TARGET val_ijklmnop val_primitives_test.cpp ${VAL_TEST_COMMON_SRCS} LIBS ${SPIRV_TOOLS} + PCH_FILE pch_test_val ) add_spvtools_unittest(TARGET val_stuvw @@ -72,4 +74,5 @@ add_spvtools_unittest(TARGET val_stuvw val_webgpu_test.cpp ${VAL_TEST_COMMON_SRCS} LIBS ${SPIRV_TOOLS} + PCH_FILE pch_test_val ) diff --git a/test/val/pch_test_val.cpp b/test/val/pch_test_val.cpp new file mode 100644 index 000000000..fc92e375a --- /dev/null +++ b/test/val/pch_test_val.cpp @@ -0,0 +1,15 @@ +// Copyright (c) 2018 The Khronos Group Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "pch_test_val.h" diff --git a/test/val/pch_test_val.h b/test/val/pch_test_val.h new file mode 100644 index 000000000..7b5881c43 --- /dev/null +++ b/test/val/pch_test_val.h @@ -0,0 +1,19 @@ +// Copyright (c) 2018 The Khronos Group Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include + +#include "gmock/gmock.h" +#include "test/unit_spirv.h" +#include "test/val/val_fixtures.h"