Skip to content

Commit 33d7529

Browse files
authored
Merge pull request #13384 from anemet/opt-remark-multi-source-benchmarks
Support opt-viewer with multi-source benchmarks as well
2 parents 4c2d55d + 30cbf7e commit 33d7529

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

benchmark/cmake/modules/AddSwiftBenchmarkSuite.cmake

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,17 @@ function(_construct_sources_for_multibench sources_out objfile_out)
9696
set(${objfile_out} ${objfiles} PARENT_SCOPE)
9797
endfunction()
9898

99+
function(add_opt_view opt_view_main_dir, module_name, opt_view_dir_out)
100+
set(opt_view_dir "${opt_view_main_dir}/${module_name}")
101+
set(opt_record "${objdir}/${module_name}.opt.yaml")
102+
set(opt_viewer "${LLVM_BUILD_MAIN_SRC_DIR}/tools/opt-viewer/opt-viewer.py")
103+
add_custom_command(
104+
OUTPUT ${opt_view_dir}
105+
DEPENDS "${objfile}"
106+
COMMAND ${opt_viewer} ${opt_record} "-o" ${opt_view_dir})
107+
set(${opt_view_dir_out} ${opt_view_dir} PARENT_SCOPE)
108+
endfunction()
109+
99110
# Regular whole-module-compilation: only a single object file is
100111
# generated.
101112
function (add_swift_multisource_wmo_benchmark_library objfile_out)
@@ -201,14 +212,14 @@ function (swift_benchmark_compile_archopts)
201212
"-no-link-objc-runtime"
202213
"-I" "${srcdir}/utils/ObjectiveCTests")
203214

204-
set(optview_main_dir)
215+
set(opt_view_main_dir)
205216
if(SWIFT_BENCHMARK_GENERATE_OPT_VIEW AND LLVM_HAVE_OPT_VIEWER_MODULES)
206217
precondition(SWIFT_BENCHMARK_BUILT_STANDALONE NEGATE
207218
"Opt-viewer is not supported when running the benchmarks outside the Swift tree")
208219

209220
if(NOT ${optflag} STREQUAL "Onone" AND "${bench_flags}" MATCHES "-whole-module.*")
210221
list(APPEND common_options "-save-optimization-record")
211-
set(optview_main_dir "${objdir}/opt-view")
222+
set(opt_view_main_dir "${objdir}/opt-view")
212223
endif()
213224
endif()
214225

@@ -337,14 +348,10 @@ function (swift_benchmark_compile_archopts)
337348
"${source}")
338349
endif()
339350

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})
351+
if(opt_view_main_dir)
352+
set(opt_view_dir)
353+
add_opt_view(${opt_view_main_dir}, ${module_name}, opt_view_dir)
354+
precondition(opt_view_dir)
348355
list(APPEND opt_view_dirs ${opt_view_dir})
349356
endif()
350357
endif()
@@ -365,6 +372,13 @@ function (swift_benchmark_compile_archopts)
365372
DEPENDS ${bench_library_objects} ${stdlib_dependencies})
366373
precondition(objfile_out)
367374
list(APPEND SWIFT_BENCH_OBJFILES "${objfile_out}")
375+
376+
if(opt_view_main_dir)
377+
set(opt_view_dir)
378+
add_opt_view(${opt_view_main_dir}, ${module_name}, opt_view_dir)
379+
precondition(opt_view_dir)
380+
list(APPEND opt_view_dirs ${opt_view_dir})
381+
endif()
368382
else()
369383
set(objfiles_out)
370384
add_swift_multisource_nonwmo_benchmark_library(objfiles_out
@@ -394,6 +408,13 @@ function (swift_benchmark_compile_archopts)
394408
DEPENDS ${bench_library_objects} ${stdlib_dependencies})
395409
precondition(objfile_out)
396410
list(APPEND SWIFT_BENCH_OBJFILES "${objfile_out}")
411+
412+
if(opt_view_main_dir)
413+
set(opt_view_dir)
414+
add_opt_view(${opt_view_main_dir}, ${module_name}, opt_view_dir)
415+
precondition(opt_view_dir)
416+
list(APPEND opt_view_dirs ${opt_view_dir})
417+
endif()
397418
else()
398419
set(objfiles_out)
399420
add_swift_multisource_nonwmo_benchmark_library(objfiles_out

0 commit comments

Comments
 (0)