@@ -200,6 +200,18 @@ function (swift_benchmark_compile_archopts)
200
200
"-${BENCH_COMPILE_ARCHOPTS_OPT} "
201
201
"-no-link-objc-runtime"
202
202
"-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
+
203
215
set (common_swift3_options ${common_options} "-swift-version" "3" )
204
216
set (common_swift4_options ${common_options} "-swift-version" "4" )
205
217
@@ -218,6 +230,7 @@ function (swift_benchmark_compile_archopts)
218
230
219
231
set (bench_library_objects )
220
232
set (bench_library_sibfiles )
233
+ set (opt_view_dirs )
221
234
# Build libraries used by the driver and benchmarks.
222
235
foreach (module_name_path ${BENCH_LIBRARY_MODULES} )
223
236
set (sources "${srcdir} /${module_name_path} .swift" )
@@ -323,6 +336,17 @@ function (swift_benchmark_compile_archopts)
323
336
"-o" "${sibfile} "
324
337
"${source} " )
325
338
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 ()
326
350
endif ()
327
351
endforeach ()
328
352
@@ -435,7 +459,7 @@ function (swift_benchmark_compile_archopts)
435
459
OUTPUT "${OUTPUT_EXEC} "
436
460
DEPENDS
437
461
${bench_library_objects} ${bench_driver_objects} ${SWIFT_BENCH_OBJFILES}
438
- "${objcfile} "
462
+ "${objcfile} " ${opt_view_dirs}
439
463
COMMAND
440
464
"${CLANG_EXEC} "
441
465
"-fno-stack-protector"
0 commit comments