Skip to content

Commit 20d9f21

Browse files
authored
Merge pull request #12938 from anemet/opt-remark-benchmark
Generate opt-view for benchmarks
2 parents 0f1b616 + 7ed42f3 commit 20d9f21

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

benchmark/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ set(SWIFT_BENCHMARK_NUM_ONONE_ITERATIONS "" CACHE STRING
213213
# Options for the default (= empty) configuration
214214
set(BENCHOPTS "-whole-module-optimization")
215215

216+
option(SWIFT_BENCHMARK_GENERATE_OPT_VIEW
217+
"Produce optimization view for benchmarks"
218+
FALSE)
219+
216220
# Options for other configurations
217221
set(BENCHOPTS_MULTITHREADED
218222
"-whole-module-optimization" "-num-threads" "4")

benchmark/cmake/modules/AddSwiftBenchmarkSuite.cmake

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,18 @@ function (swift_benchmark_compile_archopts)
200200
"-${BENCH_COMPILE_ARCHOPTS_OPT}"
201201
"-no-link-objc-runtime"
202202
"-I" "${srcdir}/utils/ObjectiveCTests")
203+
204+
set(optview_main_dir)
205+
if(SWIFT_BENCHMARK_GENERATE_OPT_VIEW AND LLVM_HAVE_OPT_VIEWER_MODULES)
206+
precondition(SWIFT_BENCHMARK_BUILT_STANDALONE NEGATE
207+
"Opt-viewer is not supported when running the benchmarks outside the Swift tree")
208+
209+
if(NOT ${optflag} STREQUAL "Onone" AND "${bench_flags}" MATCHES "-whole-module.*")
210+
list(APPEND common_options "-save-optimization-record")
211+
set(optview_main_dir "${objdir}/opt-view")
212+
endif()
213+
endif()
214+
203215
set(common_swift3_options ${common_options} "-swift-version" "3")
204216
set(common_swift4_options ${common_options} "-swift-version" "4")
205217

@@ -218,6 +230,7 @@ function (swift_benchmark_compile_archopts)
218230

219231
set(bench_library_objects)
220232
set(bench_library_sibfiles)
233+
set(opt_view_dirs)
221234
# Build libraries used by the driver and benchmarks.
222235
foreach(module_name_path ${BENCH_LIBRARY_MODULES})
223236
set(sources "${srcdir}/${module_name_path}.swift")
@@ -323,6 +336,17 @@ function (swift_benchmark_compile_archopts)
323336
"-o" "${sibfile}"
324337
"${source}")
325338
endif()
339+
340+
if(optview_main_dir)
341+
set(opt_record "${objdir}/${module_name}.opt.yaml")
342+
set(opt_viewer "${LLVM_BUILD_MAIN_SRC_DIR}/tools/opt-viewer/opt-viewer.py")
343+
set(opt_view_dir "${optview_main_dir}/${module_name}")
344+
add_custom_command(
345+
OUTPUT ${opt_view_dir}
346+
DEPENDS "${objfile}"
347+
COMMAND ${opt_viewer} ${opt_record} "-o" ${opt_view_dir})
348+
list(APPEND opt_view_dirs ${opt_view_dir})
349+
endif()
326350
endif()
327351
endforeach()
328352

@@ -435,7 +459,7 @@ function (swift_benchmark_compile_archopts)
435459
OUTPUT "${OUTPUT_EXEC}"
436460
DEPENDS
437461
${bench_library_objects} ${bench_driver_objects} ${SWIFT_BENCH_OBJFILES}
438-
"${objcfile}"
462+
"${objcfile}" ${opt_view_dirs}
439463
COMMAND
440464
"${CLANG_EXEC}"
441465
"-fno-stack-protector"

0 commit comments

Comments
 (0)