Skip to content

Recommit benchmark changes with precondition #12092

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

Merged
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
109 changes: 34 additions & 75 deletions benchmark/cmake/modules/AddSwiftBenchmarkSuite.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

include(CMakeParseArguments)
include(SwiftBenchmarkUtils)

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

function (add_swift_benchmark_library objfile_out sibfile_out)
cmake_parse_arguments(BENCHLIB "" "MODULE_PATH;SOURCE_DIR;OBJECT_DIR" "SOURCES;LIBRARY_FLAGS" ${ARGN})
cmake_parse_arguments(BENCHLIB "" "MODULE_PATH;SOURCE_DIR;OBJECT_DIR" "SOURCES;LIBRARY_FLAGS;DEPENDS" ${ARGN})

precondition(BENCHLIB_MODULE_PATH)
precondition(BENCHLIB_SOURCE_DIR)
Expand All @@ -39,7 +40,7 @@ function (add_swift_benchmark_library objfile_out sibfile_out)
precondition(objfile_out)
add_custom_command(
OUTPUT "${objfile}"
DEPENDS ${stdlib_dependencies} ${sources}
DEPENDS ${stdlib_dependencies} ${sources} ${BENCHLIB_DEPENDS}
COMMAND "${SWIFT_EXEC}"
${BENCHLIB_LIBRARY_FLAGS}
"-force-single-frontend-invocation"
Expand All @@ -58,7 +59,7 @@ function (add_swift_benchmark_library objfile_out sibfile_out)
add_custom_command(
OUTPUT "${sibfile}"
DEPENDS
${stdlib_dependencies} ${sources}
${stdlib_dependencies} ${sources} ${BENCHLIB_DEPENDS}
COMMAND "${SWIFT_EXEC}"
${BENCHLIB_LIBRARY_FLAGS}
"-force-single-frontend-invocation"
Expand Down Expand Up @@ -120,89 +121,47 @@ function (swift_benchmark_compile_archopts)
set(bench_library_sibfiles)
# Build libraries used by the driver and benchmarks.
foreach(module_name_path ${BENCH_LIBRARY_MODULES})
get_filename_component(module_name "${module_name_path}" NAME)

set(objfile "${objdir}/${module_name}.o")
set(swiftmodule "${objdir}/${module_name}.swiftmodule")
set(source "${srcdir}/${module_name_path}.swift")
list(APPEND bench_library_objects "${objfile}")
add_custom_command(
OUTPUT "${objfile}"
DEPENDS
${stdlib_dependencies} "${source}" ${extra_sources}
COMMAND "${SWIFT_EXEC}"
${common_options}
"-force-single-frontend-invocation"
"-parse-as-library"
"-module-name" "${module_name}"
"-emit-module" "-emit-module-path" "${swiftmodule}"
"-o" "${objfile}"
"${source}" ${extra_sources})
set(sources "${srcdir}/${module_name_path}.swift")

add_swift_benchmark_library(objfile_out sibfile_out
MODULE_PATH "${module_name_path}"
SOURCE_DIR "${srcdir}"
OBJECT_DIR "${objdir}"
SOURCES ${sources}
LIBRARY_FLAGS ${common_options})
precondition(objfile_out)
list(APPEND bench_library_objects "${objfile_out}")
if (SWIFT_BENCHMARK_EMIT_SIB)
set(sibfile "${objdir}/${module_name}.sib")
list(APPEND bench_library_sibfiles "${sibfile}")
add_custom_command(
OUTPUT "${sibfile}"
DEPENDS
${stdlib_dependencies} "${srcdir}/${module_name_path}.swift"
${extra_sources}
COMMAND "${SWIFT_EXEC}"
${common_options}
"-force-single-frontend-invocation"
"-parse-as-library"
"-module-name" "${module_name}"
"-emit-sib"
"-o" "${sibfile}"
"${source}" ${extra_sources})
precondition(sibfile_out)
list(APPEND bench_library_sibfiles "${sibfile_out}")
endif()
endforeach()
precondition(bench_library_objects)

set(bench_driver_objects)
set(bench_driver_sibfiles)
foreach(module_name_path ${BENCH_DRIVER_LIBRARY_MODULES})
get_filename_component(module_name "${module_name_path}" NAME)
set(sources "${srcdir}/${module_name_path}.swift")

get_filename_component(module_name "${module_name_path}" NAME)
if("${module_name}" STREQUAL "DriverUtils")
set(extra_sources "${srcdir}/utils/ArgParse.swift")
list(APPEND sources "${srcdir}/utils/ArgParse.swift")
endif()

set(objfile "${objdir}/${module_name}.o")
set(swiftmodule "${objdir}/${module_name}.swiftmodule")
list(APPEND bench_driver_objects "${objfile}")
set(source "${srcdir}/${module_name_path}.swift")
add_custom_command(
OUTPUT "${objfile}"
DEPENDS
${stdlib_dependencies} ${bench_library_objects} ${source}
${extra_sources}
COMMAND "${SWIFT_EXEC}"
${common_options_driver}
${BENCH_DRIVER_LIBRARY_FLAGS}
"-force-single-frontend-invocation"
"-parse-as-library"
"-module-name" "${module_name}"
"-emit-module" "-emit-module-path" "${swiftmodule}"
"-I" "${objdir}"
"-o" "${objfile}"
"${source}" ${extra_sources})
if(SWIFT_BENCHMARK_EMIT_SIB)
set(sibfile "${objdir}/${module_name}.sib")
list(APPEND bench_driver_sibfiles "${sibfile}")
add_custom_command(
OUTPUT "${sibfile}"
DEPENDS
${stdlib_dependencies} ${bench_library_objects} ${source}
${extra_sources}
COMMAND "${SWIFT_EXEC}"
${common_options_driver}
${BENCH_DRIVER_LIBRARY_FLAGS}
"-force-single-frontend-invocation"
"-parse-as-library"
"-module-name" "${module_name}"
"-emit-sib"
"-I" "${objdir}"
"-o" "${sibfile}"
"${source}" ${extra_sources})
set(objfile_out)
set(sibfile_out)
add_swift_benchmark_library(objfile_out sibfile_out
MODULE_PATH "${module_name_path}"
SOURCE_DIR "${srcdir}"
OBJECT_DIR "${objdir}"
SOURCES ${sources}
LIBRARY_FLAGS ${common_options_driver} ${BENCH_DRIVER_LIBRARY_FLAGS}
DEPENDS ${bench_library_objects})
precondition(objfile_out)
list(APPEND bench_driver_objects "${objfile_out}")
if (SWIFT_BENCHMARK_EMIT_SIB)
precondition(sibfile_out)
list(APPEND bench_driver_sibfiles "${sibfile_out}")
endif()
endforeach()

Expand Down
29 changes: 29 additions & 0 deletions benchmark/cmake/modules/SwiftBenchmarkUtils.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

include(CMakeParseArguments)

function(precondition var)
cmake_parse_arguments(
PRECONDITION # prefix
"NEGATE" # options
"MESSAGE" # single-value args
"" # multi-value args
${ARGN})

if (PRECONDITION_NEGATE)
if (${var})
if (PRECONDITION_MESSAGE)
message(FATAL_ERROR "Error! ${PRECONDITION_MESSAGE}")
else()
message(FATAL_ERROR "Error! Variable ${var} is true or not empty. The value of ${var} is ${${var}}.")
endif()
endif()
else()
if (NOT ${var})
if (PRECONDITION_MESSAGE)
message(FATAL_ERROR "Error! ${PRECONDITION_MESSAGE}")
else()
message(FATAL_ERROR "Error! Variable ${var} is false, empty or not set.")
endif()
endif()
endif()
endfunction()