Skip to content

Commit 574b05d

Browse files
authored
Merge pull request #12092 from gottesmm/recommit_benchmark_changes_with_precondition
Recommit benchmark changes with precondition
2 parents fc9a7b7 + 84f5446 commit 574b05d

File tree

2 files changed

+63
-75
lines changed

2 files changed

+63
-75
lines changed

benchmark/cmake/modules/AddSwiftBenchmarkSuite.cmake

Lines changed: 34 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
include(CMakeParseArguments)
3+
include(SwiftBenchmarkUtils)
34

45
# Run a shell command and assign output to a variable or fail with an error.
56
# Example usage:
@@ -20,7 +21,7 @@ function(runcmd)
2021
endfunction(runcmd)
2122

2223
function (add_swift_benchmark_library objfile_out sibfile_out)
23-
cmake_parse_arguments(BENCHLIB "" "MODULE_PATH;SOURCE_DIR;OBJECT_DIR" "SOURCES;LIBRARY_FLAGS" ${ARGN})
24+
cmake_parse_arguments(BENCHLIB "" "MODULE_PATH;SOURCE_DIR;OBJECT_DIR" "SOURCES;LIBRARY_FLAGS;DEPENDS" ${ARGN})
2425

2526
precondition(BENCHLIB_MODULE_PATH)
2627
precondition(BENCHLIB_SOURCE_DIR)
@@ -39,7 +40,7 @@ function (add_swift_benchmark_library objfile_out sibfile_out)
3940
precondition(objfile_out)
4041
add_custom_command(
4142
OUTPUT "${objfile}"
42-
DEPENDS ${stdlib_dependencies} ${sources}
43+
DEPENDS ${stdlib_dependencies} ${sources} ${BENCHLIB_DEPENDS}
4344
COMMAND "${SWIFT_EXEC}"
4445
${BENCHLIB_LIBRARY_FLAGS}
4546
"-force-single-frontend-invocation"
@@ -58,7 +59,7 @@ function (add_swift_benchmark_library objfile_out sibfile_out)
5859
add_custom_command(
5960
OUTPUT "${sibfile}"
6061
DEPENDS
61-
${stdlib_dependencies} ${sources}
62+
${stdlib_dependencies} ${sources} ${BENCHLIB_DEPENDS}
6263
COMMAND "${SWIFT_EXEC}"
6364
${BENCHLIB_LIBRARY_FLAGS}
6465
"-force-single-frontend-invocation"
@@ -120,89 +121,47 @@ function (swift_benchmark_compile_archopts)
120121
set(bench_library_sibfiles)
121122
# Build libraries used by the driver and benchmarks.
122123
foreach(module_name_path ${BENCH_LIBRARY_MODULES})
123-
get_filename_component(module_name "${module_name_path}" NAME)
124-
125-
set(objfile "${objdir}/${module_name}.o")
126-
set(swiftmodule "${objdir}/${module_name}.swiftmodule")
127-
set(source "${srcdir}/${module_name_path}.swift")
128-
list(APPEND bench_library_objects "${objfile}")
129-
add_custom_command(
130-
OUTPUT "${objfile}"
131-
DEPENDS
132-
${stdlib_dependencies} "${source}" ${extra_sources}
133-
COMMAND "${SWIFT_EXEC}"
134-
${common_options}
135-
"-force-single-frontend-invocation"
136-
"-parse-as-library"
137-
"-module-name" "${module_name}"
138-
"-emit-module" "-emit-module-path" "${swiftmodule}"
139-
"-o" "${objfile}"
140-
"${source}" ${extra_sources})
124+
set(sources "${srcdir}/${module_name_path}.swift")
125+
126+
add_swift_benchmark_library(objfile_out sibfile_out
127+
MODULE_PATH "${module_name_path}"
128+
SOURCE_DIR "${srcdir}"
129+
OBJECT_DIR "${objdir}"
130+
SOURCES ${sources}
131+
LIBRARY_FLAGS ${common_options})
132+
precondition(objfile_out)
133+
list(APPEND bench_library_objects "${objfile_out}")
141134
if (SWIFT_BENCHMARK_EMIT_SIB)
142-
set(sibfile "${objdir}/${module_name}.sib")
143-
list(APPEND bench_library_sibfiles "${sibfile}")
144-
add_custom_command(
145-
OUTPUT "${sibfile}"
146-
DEPENDS
147-
${stdlib_dependencies} "${srcdir}/${module_name_path}.swift"
148-
${extra_sources}
149-
COMMAND "${SWIFT_EXEC}"
150-
${common_options}
151-
"-force-single-frontend-invocation"
152-
"-parse-as-library"
153-
"-module-name" "${module_name}"
154-
"-emit-sib"
155-
"-o" "${sibfile}"
156-
"${source}" ${extra_sources})
135+
precondition(sibfile_out)
136+
list(APPEND bench_library_sibfiles "${sibfile_out}")
157137
endif()
158138
endforeach()
139+
precondition(bench_library_objects)
159140

160141
set(bench_driver_objects)
161142
set(bench_driver_sibfiles)
162143
foreach(module_name_path ${BENCH_DRIVER_LIBRARY_MODULES})
163-
get_filename_component(module_name "${module_name_path}" NAME)
144+
set(sources "${srcdir}/${module_name_path}.swift")
164145

146+
get_filename_component(module_name "${module_name_path}" NAME)
165147
if("${module_name}" STREQUAL "DriverUtils")
166-
set(extra_sources "${srcdir}/utils/ArgParse.swift")
148+
list(APPEND sources "${srcdir}/utils/ArgParse.swift")
167149
endif()
168150

169-
set(objfile "${objdir}/${module_name}.o")
170-
set(swiftmodule "${objdir}/${module_name}.swiftmodule")
171-
list(APPEND bench_driver_objects "${objfile}")
172-
set(source "${srcdir}/${module_name_path}.swift")
173-
add_custom_command(
174-
OUTPUT "${objfile}"
175-
DEPENDS
176-
${stdlib_dependencies} ${bench_library_objects} ${source}
177-
${extra_sources}
178-
COMMAND "${SWIFT_EXEC}"
179-
${common_options_driver}
180-
${BENCH_DRIVER_LIBRARY_FLAGS}
181-
"-force-single-frontend-invocation"
182-
"-parse-as-library"
183-
"-module-name" "${module_name}"
184-
"-emit-module" "-emit-module-path" "${swiftmodule}"
185-
"-I" "${objdir}"
186-
"-o" "${objfile}"
187-
"${source}" ${extra_sources})
188-
if(SWIFT_BENCHMARK_EMIT_SIB)
189-
set(sibfile "${objdir}/${module_name}.sib")
190-
list(APPEND bench_driver_sibfiles "${sibfile}")
191-
add_custom_command(
192-
OUTPUT "${sibfile}"
193-
DEPENDS
194-
${stdlib_dependencies} ${bench_library_objects} ${source}
195-
${extra_sources}
196-
COMMAND "${SWIFT_EXEC}"
197-
${common_options_driver}
198-
${BENCH_DRIVER_LIBRARY_FLAGS}
199-
"-force-single-frontend-invocation"
200-
"-parse-as-library"
201-
"-module-name" "${module_name}"
202-
"-emit-sib"
203-
"-I" "${objdir}"
204-
"-o" "${sibfile}"
205-
"${source}" ${extra_sources})
151+
set(objfile_out)
152+
set(sibfile_out)
153+
add_swift_benchmark_library(objfile_out sibfile_out
154+
MODULE_PATH "${module_name_path}"
155+
SOURCE_DIR "${srcdir}"
156+
OBJECT_DIR "${objdir}"
157+
SOURCES ${sources}
158+
LIBRARY_FLAGS ${common_options_driver} ${BENCH_DRIVER_LIBRARY_FLAGS}
159+
DEPENDS ${bench_library_objects})
160+
precondition(objfile_out)
161+
list(APPEND bench_driver_objects "${objfile_out}")
162+
if (SWIFT_BENCHMARK_EMIT_SIB)
163+
precondition(sibfile_out)
164+
list(APPEND bench_driver_sibfiles "${sibfile_out}")
206165
endif()
207166
endforeach()
208167

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
include(CMakeParseArguments)
3+
4+
function(precondition var)
5+
cmake_parse_arguments(
6+
PRECONDITION # prefix
7+
"NEGATE" # options
8+
"MESSAGE" # single-value args
9+
"" # multi-value args
10+
${ARGN})
11+
12+
if (PRECONDITION_NEGATE)
13+
if (${var})
14+
if (PRECONDITION_MESSAGE)
15+
message(FATAL_ERROR "Error! ${PRECONDITION_MESSAGE}")
16+
else()
17+
message(FATAL_ERROR "Error! Variable ${var} is true or not empty. The value of ${var} is ${${var}}.")
18+
endif()
19+
endif()
20+
else()
21+
if (NOT ${var})
22+
if (PRECONDITION_MESSAGE)
23+
message(FATAL_ERROR "Error! ${PRECONDITION_MESSAGE}")
24+
else()
25+
message(FATAL_ERROR "Error! Variable ${var} is false, empty or not set.")
26+
endif()
27+
endif()
28+
endif()
29+
endfunction()

0 commit comments

Comments
 (0)