This patch simplifies (!!!) the logic governing the naming of dump files and auxiliary output files in the driver, in the compiler, and in the LTO wrapper. No changes are made to the naming of primary outputs, there are often ways to restore past behavior, and a number of inconsistencies are fixed. Some internal options are removed (-auxbase and -auxbase-strip), sensible existing uses of -dumpdir and -dumpbase options remain unchanged, additional useful cases are added, making for what is still admittedly quite complex. Extensive documentation and testcases provide numerous examples, from normal to corner cases. The most visible changes are: - aux and dump files now always go in the same directory, that defaults to the directory of the primary output, but that can be overridden with -dumpdir, -save-temps=*, or, preserving past behavior, with a -dumpbase with a directory component. - driver and compiler now have the same notion of naming of auxiliary outputs, e.g. .dwo files will no longer be in one location while the debug info suggests they are elsewhere, and -save-temps and .dwo auxiliary outputs now go in the same location as .su, .ci and coverage data, with consistent naming. - explicitly-specified primary output names guide not only the location of aux and dump outputs: the output base name is also used in their base name, as a prefix when also linking (e.g. foo.c bar.c -o foobar creates foobar-foo.dwo and foobar-bar.dwo with -gsplit-dwarf), or as the base name instead of the input name (foo.c -c -o whatever.o creates whatever.su rather than foo.su with -fstack-usage). The preference for the input file base name, quite useful for our testsuite, can be restored with -dumpbase "". When compiling and linking tests in the testsuite with additional inputs, we now use this flag. Files named in dejagnu board ldflags, libs, and ldscripts are now quoted in the gcc testsuite with -Wl, so that they are not counted as additional inputs by the compiler driver. - naming a -dumpbase when compiling multiple sources used to cause dumps from later compiles to overwrite those of earlier ones; it is now used as a prefix when compiling multiple sources, like an executable name above. - the dumpbase, explicitly specified or computed from output or input names, now also governs the naming of aux outputs; since aux outputs usually replaced the suffix from the input name, while dump outputs append their own additional suffixes, a -dumpbase-ext option is introduced to enable a chosen suffix to be dropped from dumpbase to form aux output names. - LTO dump and aux outputs were quite a mess, sometimes leaking temporary output names into -save-temps output names, sometimes conversely generating desirable aux outputs in temporary locations. They now obey the same logic of compiler aux and dump outputs, landing in the expected location and taking the linker output name or an explicit dumpbase overrider into account. - Naming of -fdump-final-insns outputs now follows the dump file naming logic for the .gkd files, and the .gk dump files generated in the second -fcompare-debug compilation get the .gk inserted before the suffix that -dumpbase-ext drops in aux outputs. gcc/ChangeLog: * common.opt (aux_base_name): Define. (dumpbase, dumpdir): Mark as Driver options. (-dumpbase, -dumpdir): Likewise. (dumpbase-ext, -dumpbase-ext): New. (auxbase, auxbase-strip): Drop. * doc/invoke.texi (-dumpbase, -dumpbase-ext, -dumpdir): Document. (-o): Introduce the notion of primary output, mention it influences auxiliary and dump output names as well, add examples. (-save-temps): Adjust, move examples into -dump*. (-save-temps=cwd, -save-temps=obj): Likewise. (-fdump-final-insns): Adjust. * dwarf2out.c (gen_producer_string): Drop auxbase and auxbase_strip; add dumpbase_ext. * gcc.c (enum save_temps): Add SAVE_TEMPS_DUMP. (save_temps_prefix, save_temps_length): Drop. (save_temps_overrides_dumpdir): New. (dumpdir, dumpbase, dumpbase_ext): New. (dumpdir_length, dumpdir_trailing_dash_added): New. (outbase, outbase_length): New. (The Specs Language): Introduce %". Adjust %b and %B. (ASM_FINAL_SPEC): Use %b.dwo for an aux output name always. Precede object file with %w when it's the primary output. (cpp_debug_options): Do not pass on incoming -dumpdir, -dumpbase and -dumpbase-ext options; recompute them with %:dumps. (cc1_options): Drop auxbase with and without compare-debug; use cpp_debug_options instead of dumpbase. Mark asm output with %w when it's the primary output. (static_spec_functions): Drop %:compare-debug-auxbase-opt and %:replace-exception. Add %:dumps. (driver_handle_option): Implement -save-temps=*/-dumpdir mutual overriding logic. Save dumpdir, dumpbase and dumpbase-ext options. Do not save output_file in save_temps_prefix. (adds_single_suffix_p): New. (single_input_file_index): New. (process_command): Combine output dir, output base name, and dumpbase into dumpdir and outbase. (set_collect_gcc_options): Pass a possibly-adjusted -dumpdir. (do_spec_1): Optionally dumpdir instead of save_temps_prefix, and outbase instead of input_basename in %b, %B and in -save-temps aux files. Handle empty argument %". (driver::maybe_run_linker): Adjust dumpdir and auxbase. (compare_debug_dump_opt_spec_function): Adjust gkd dump file naming. Spec-quote the computed -fdump-final-insns file name. (debug_auxbase_opt): Drop. (compare_debug_self_opt_spec_function): Drop auxbase-strip computation. (compare_debug_auxbase_opt_spec_function): Drop. (not_actual_file_p): New. (replace_extension_spec_func): Drop. (dumps_spec_func): New. (convert_white_space): Split-out parts into... (quote_string, whitespace_to_convert_p): ... these. New. (quote_spec_char_p, quote_spec, quote_spec_arg): New. (driver::finalize): Release and reset new variables; drop removed ones. * lto-wrapper.c (HAVE_TARGET_EXECUTABLE_SUFFIX): Define if... (TARGET_EXECUTABLE_SUFFIX): ... is defined; define this to the empty string otherwise. (DUMPBASE_SUFFIX): Drop leading period. (debug_objcopy): Use concat. (run_gcc): Recognize -save-temps=* as -save-temps too. Obey -dumpdir. Pass on empty dumpdir and dumpbase with a directory component. Simplify temp file names. * opts.c (finish_options): Drop aux base name handling. (common_handle_option): Drop auxbase-strip handling. * toplev.c (print_switch_values): Drop auxbase, add dumpbase-ext. (process_options): Derive aux_base_name from dump_base_name and dump_base_ext. (lang_dependent_init): Compute dump_base_ext along with dump_base_name. Disable stack usage and callgraph-info during lto generation and compare-debug recompilation. gcc/fortran/ChangeLog: * options.c (gfc_get_option_string): Drop auxbase, add dumpbase_ext. gcc/ada/ChangeLog: * gcc-interface/lang-specs.h: Drop auxbase and auxbase-strip. Use %:dumps instead of -dumpbase. Add %w for implicit .s primary output. * switch.adb (Is_Internal_GCC_Switch): Recognize dumpdir and dumpbase-ext. Drop auxbase and auxbase-strip. lto-plugin/ChangeLog: * lto-plugin.c (skip_in_suffix): New. (exec_lto_wrapper): Use skip_in_suffix and concat to build non-temporary output names. (onload): Look for -dumpdir in COLLECT_GCC_OPTIONS, and override link_output_name with it. contrib/ChangeLog: * compare-debug: Adjust for .gkd files named as dump files, with the source suffix rather than the object suffix. gcc/testsuite/ChangeLog: * gcc.misc-tests/outputs.exp: New. * gcc.misc-tests/outputs-0.c: New. * gcc.misc-tests/outputs-1.c: New. * gcc.misc-tests/outputs-2.c: New. * lib/gcc-defs.exp (gcc_adjusted_linker_flags): New. (gcc_adjust_linker_flags): New. (dg-additional-files-options): Call it. Pass -dumpbase "" when there are additional sources. * lib/profopt.exp (profopt-execute): Pass the executable suffix with -dumpbase-ext. * lib/scandump.exp (dump-base): Mention -dumpbase "" use. * lib/scanltranstree.exp: Adjust dump suffix expectation. * lib/scanwpaipa.exp: Likewise.
607 lines
18 KiB
Plaintext
607 lines
18 KiB
Plaintext
# Copyright (C) 2001-2020 Free Software Foundation, Inc.
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with GCC; see the file COPYING3. If not see
|
|
# <http://www.gnu.org/licenses/>.
|
|
#
|
|
# This script was submitted by Janis Johnson <janis187@us.ibm.com>.
|
|
|
|
# Test the functionality and optionally, performance improvement, of
|
|
# programs compiled with profile-directed optimizations. Compile and
|
|
# run a test with profile options, compile it with options using the
|
|
# profile feedback, and then run the test again. Optionally compile
|
|
# and run a third time without the profile-directed optimization and
|
|
# compare timing results of the program with normal optimization and
|
|
# with the profile-directed optimization. Each test is run using
|
|
# multiple sets of optimization and/or code generation options in
|
|
# addition to the profiling and feedback options.
|
|
|
|
# If perf_ext is defined and the performance value for the
|
|
# profile-directed test run is nonzero then the performance check will
|
|
# be done.
|
|
|
|
load_lib dg.exp
|
|
load_lib gcc-dg.exp
|
|
|
|
global PROFOPT_OPTIONS perf_delta
|
|
|
|
# The including .exp file must define these.
|
|
global tool profile_option feedback_option prof_ext profile_wrapper
|
|
if ![info exists tool] {
|
|
error "Tools is not specified."
|
|
}
|
|
if ![info exists prof_ext] {
|
|
error "No profile data file extensions specified."
|
|
}
|
|
|
|
# The maximum perforance degradation can be defined in the including file.
|
|
if ![info exists perf_delta] {
|
|
set perf_delta 4
|
|
}
|
|
|
|
# The default option list can be overridden by
|
|
# PROFOPT_OPTIONS="{ { list1 } ... { list2 } }"
|
|
|
|
if ![info exists PROFOPT_OPTIONS] {
|
|
set PROFOPT_OPTIONS [list \
|
|
{ -g } \
|
|
{ -O0 } \
|
|
{ -O1 } \
|
|
{ -O2 } \
|
|
{ -O3 } \
|
|
{ -O3 -g } \
|
|
{ -Os } ]
|
|
}
|
|
|
|
#
|
|
# profopt-cleanup -- remove profiling or performance results files.
|
|
#
|
|
# TESTCASE is the name of the test
|
|
# EXT is the extensions of files to remove
|
|
#
|
|
proc profopt-cleanup { testcase extlist } {
|
|
set basename [file tail $testcase]
|
|
set base [file rootname $basename]
|
|
foreach ext $extlist {
|
|
set files [glob -nocomplain $base.$ext]
|
|
if { $files != "" } {
|
|
eval "remote_file build delete $files"
|
|
}
|
|
}
|
|
}
|
|
|
|
#
|
|
# profopt-target-cleanup -- remove profiling result files.
|
|
#
|
|
# DIR is the name of the directory
|
|
# TESTCASE is the name of the test
|
|
# EXT is the extensions of files to remove
|
|
#
|
|
proc profopt-target-cleanup { dir testcase ext } {
|
|
global additional_sources_used
|
|
set basename [file tail $testcase]
|
|
set base [file rootname $basename]
|
|
set file "$dir/$base.$ext"
|
|
eval "remote_file target delete $file"
|
|
|
|
if [info exists additional_sources_used] {
|
|
foreach srcfile $additional_sources_used {
|
|
set basename [file tail $srcfile]
|
|
set base [file rootname $basename]
|
|
set file "$dir/$base.$ext"
|
|
eval "remote_file target delete $file"
|
|
}
|
|
}
|
|
}
|
|
|
|
#
|
|
# profopt-perf-value -- get performance value for a test
|
|
#
|
|
# TESTCASE is the name of the test
|
|
# PERF_EXT is the extension of the performance result file
|
|
# OPTSTR is the string of compiler options
|
|
#
|
|
proc profopt-perf-value { testcase perf_ext optstr } {
|
|
set basename [file tail $testcase]
|
|
set base [file rootname $basename]
|
|
set files [glob -nocomplain $base.$perf_ext]
|
|
# The file doesn't exist; let the caller decide if that's a problem.
|
|
if { $files == "" } {
|
|
return -2
|
|
}
|
|
remote_upload host $base.$perf_ext $base.$perf_ext
|
|
set fd [open $base.$perf_ext r]
|
|
gets $fd line
|
|
set val -2
|
|
if [regexp "TIME" $line] {
|
|
if [regexp "TIME -1" $line] {
|
|
fail "$testcase perf check: no consistent time available, $optstr"
|
|
set val -1
|
|
} elseif ![regexp "(\[0-9\]+)" "$line" val] {
|
|
set val -2
|
|
}
|
|
}
|
|
# Report problems with an existing file.
|
|
if { $val == -2 } {
|
|
fail "$testcase perf check: file $base.$perf_ext has wrong format, $optstr"
|
|
}
|
|
close $fd
|
|
profopt-cleanup $testcase $perf_ext
|
|
return $val
|
|
}
|
|
|
|
#
|
|
# dg-final-generate -- process code to run after the profile-generate step
|
|
#
|
|
# ARGS is the line number of the directive followed by the commands.
|
|
#
|
|
proc dg-final-generate { args } {
|
|
global generate_final_code
|
|
|
|
if { [llength $args] > 2 } {
|
|
error "[lindex $args 0]: too many arguments"
|
|
return
|
|
}
|
|
append generate_final_code "[lindex $args 1]\n"
|
|
}
|
|
|
|
#
|
|
# dg-final-use -- process code to run after the profile-use step
|
|
#
|
|
# ARGS is the line number of the directive followed by the commands.
|
|
#
|
|
proc dg-final-use { args } {
|
|
global use_final_code
|
|
|
|
if { [llength $args] > 2 } {
|
|
error "[lindex $args 0]: too many arguments"
|
|
return
|
|
}
|
|
append use_final_code "[lindex $args 1]\n"
|
|
}
|
|
|
|
#
|
|
# dg-final-use-not-autofdo -- process code to run after the profile-use step
|
|
# but only if not running autofdo
|
|
# ARGS is the line number of the directive followed by the commands.
|
|
#
|
|
proc dg-final-use-not-autofdo { args } {
|
|
global use_final_code
|
|
global run_autofdo
|
|
|
|
if { [llength $args] > 2 } {
|
|
error "[lindex $args 0]: too many arguments"
|
|
return
|
|
}
|
|
|
|
if { $run_autofdo == 1 } {
|
|
return
|
|
}
|
|
append use_final_code "[lindex $args 1]\n"
|
|
}
|
|
|
|
#
|
|
# dg-final-use-autofdo -- process code to run after the profile-use step
|
|
# but only if running autofdo
|
|
# ARGS is the line number of the directive followed by the commands.
|
|
#
|
|
|
|
proc dg-final-use-autofdo { args } {
|
|
global use_final_code
|
|
global run_autofdo
|
|
|
|
if { [llength $args] > 2 } {
|
|
error "[lindex $args 0]: too many arguments"
|
|
return
|
|
}
|
|
|
|
if { $run_autofdo != 1 } {
|
|
return
|
|
}
|
|
append use_final_code "[lindex $args 1]\n"
|
|
}
|
|
|
|
#
|
|
# profopt-final-code -- run final code
|
|
#
|
|
# WHICH is "generate" or "use".
|
|
# FINAL_CODE is the TCL code to run.
|
|
# TESTCASE is the name of the test, for error messages.
|
|
#
|
|
proc profopt-final-code { which final_code name } {
|
|
# This is copied from dg-test in dg.exp of DejaGnu.
|
|
regsub -all "\\\\(\[{}\])" $final_code "\\1" final_code
|
|
proc profopt-final-proc { args } $final_code
|
|
if [catch "profopt-final-proc $name" errmsg] {
|
|
perror "$name: error executing dg-final-${which}: $errmsg"
|
|
unresolved "$name: Error executing dg-final-${which}: $errmsg"
|
|
}
|
|
}
|
|
|
|
#
|
|
# profopt-get-options -- process test directives
|
|
#
|
|
# SRC is the full pathname of the testcase.
|
|
#
|
|
proc profopt-get-options { src } {
|
|
# dg-options sets a variable called dg-extra-tool-flags.
|
|
set dg-extra-tool-flags ""
|
|
|
|
# dg-require-* sets dg-do-what.
|
|
upvar dg-do-what dg-do-what
|
|
|
|
# current_compiler_flags reads tool_flags from the same stack frame
|
|
# as dg-extra-tool-flags
|
|
set tool_flags ""
|
|
|
|
set tmp [dg-get-options $src]
|
|
foreach op $tmp {
|
|
set cmd [lindex $op 0]
|
|
if { ![string compare "dg-options" $cmd] \
|
|
|| ![string compare "dg-additional-options" $cmd] \
|
|
|| ![string compare "dg-add-options" $cmd] \
|
|
|| ![string compare "dg-skip-if" $cmd] \
|
|
|| ![string compare "dg-final-generate" $cmd] \
|
|
|| ![string compare "dg-final-use" $cmd] \
|
|
|| ![string compare "dg-final-use-not-autofdo" $cmd] \
|
|
|| ![string compare "dg-final-use-autofdo" $cmd] \
|
|
|| ![string compare "dg-additional-sources" $cmd] \
|
|
|| [string match "dg-require-*" $cmd] } {
|
|
set status [catch "$op" errmsg]
|
|
if { $status != 0 } {
|
|
perror "$src: $errmsg for \"$op\"\n"
|
|
unresolved "$src: $errmsg for \"$op\""
|
|
return
|
|
}
|
|
} else {
|
|
# Ignore unrecognized dg- commands, but warn about them.
|
|
warning "profopt.exp does not support $cmd"
|
|
}
|
|
}
|
|
|
|
# Return flags to use for compiling the primary source file and for
|
|
# linking.
|
|
return ${dg-extra-tool-flags}
|
|
}
|
|
|
|
# auto-profopt-execute -- Compile for auto profiling and then feedback,
|
|
# then normal. SRC is the full path name of the testcase.
|
|
proc auto-profopt-execute { src } {
|
|
global profile_wrapper
|
|
global profile_option
|
|
global feedback_option
|
|
global run_autofdo
|
|
global srcdir
|
|
|
|
if { ! [check_profiling_available "-fauto-profile"] } {
|
|
regsub "(?q)$srcdir/" $src "" testcase
|
|
unsupported "$testcase -fauto-profile"
|
|
return
|
|
}
|
|
set profile_wrapper [profopt-perf-wrapper]
|
|
set profile_option "-g"
|
|
set feedback_option "-fauto-profile"
|
|
set run_autofdo 1
|
|
profopt-execute $src
|
|
unset profile_wrapper
|
|
unset profile_option
|
|
unset feedback_option
|
|
unset run_autofdo
|
|
}
|
|
|
|
#
|
|
# c-prof-execute -- compile for profiling and then feedback, then normal
|
|
#
|
|
# SRC is the full pathname of the testcase.
|
|
#
|
|
proc profopt-execute { src } {
|
|
global srcdir tmpdir
|
|
global PROFOPT_OPTIONS
|
|
global tool profile_option feedback_option prof_ext perf_ext perf_delta
|
|
global profile_wrapper run_autofdo ld_library_path
|
|
global generate_final_code use_final_code
|
|
global verbose
|
|
global testname_with_flags
|
|
|
|
if ![info exists profile_option] {
|
|
error "No profile option specified for first compile."
|
|
}
|
|
if ![info exists feedback_option] {
|
|
error "No feedback option specified for second compile."
|
|
}
|
|
if ![info exists profile_wrapper] {
|
|
set profile_wrapper ""
|
|
}
|
|
if ![info exists run_autofdo] {
|
|
set run_autofdo ""
|
|
}
|
|
|
|
# Use the default option list or one defined for a set of tests.
|
|
if ![info exists PROFOPT_OPTIONS] {
|
|
error "PROFOPT_OPTIONS is not defined"
|
|
}
|
|
set prof_option_list $PROFOPT_OPTIONS
|
|
|
|
regsub "(?q)$srcdir/" $src "" testcase
|
|
# If we couldn't rip $srcdir out of `src' then just do the best we can.
|
|
# The point is to reduce the unnecessary noise in the logs. Don't strip
|
|
# out too much because different testcases with the same name can confuse
|
|
# `test-tool'.
|
|
if [string match "/*" $testcase] {
|
|
set testcase "[file tail [file dirname $src]]/[file tail $src]"
|
|
}
|
|
|
|
# Several procedures access the name of the test with torture flags,
|
|
# normally defined in dg-test. Profile optimization tests don't
|
|
# use dg-test, so define it here to make it accessible via
|
|
# testname-for-summary.
|
|
set testname_with_flags $testcase
|
|
|
|
set executable $tmpdir/[file tail [file rootname $src].x]
|
|
set basename [file tail $testcase]
|
|
set base [file rootname $basename]
|
|
|
|
set count 0
|
|
foreach option $prof_option_list {
|
|
# We pass -dumpbase-ext ${execext}[123] to the compile&link
|
|
# commands so as to avoid the combination of the executable
|
|
# with the source name in the aux outputs.
|
|
set execext ".x${count}"
|
|
set execname1 "${executable}${count}1"
|
|
set execname2 "${executable}${count}2"
|
|
set execname3 "${executable}${count}3"
|
|
incr count
|
|
|
|
remote_file build delete $execname1
|
|
remote_file build delete $execname2
|
|
remote_file build delete $execname3
|
|
verbose "Testing $testcase, $option" 1
|
|
|
|
# Remove old performance data files.
|
|
if [info exists perf_ext] {
|
|
profopt-cleanup $testcase $perf_ext
|
|
}
|
|
|
|
# Process test directives.
|
|
|
|
set generate_final_code ""
|
|
set use_final_code ""
|
|
set dg-do-what [list "run" "" P]
|
|
set extra_flags [profopt-get-options $src]
|
|
if { [lindex ${dg-do-what} 1 ] == "N" } {
|
|
unsupported "$testcase"
|
|
unset testname_with_flags
|
|
verbose "$src not supported on this target, skipping it" 3
|
|
return
|
|
}
|
|
|
|
# schedule removal of dump files et al
|
|
# Do this before the call below destroys additional_sources..
|
|
append use_final_code [schedule-cleanups "$option $extra_flags"]
|
|
set extra_options [dg-additional-files-options "" "$src"]
|
|
|
|
# Remove old profiling data files. Make sure additional_sources_used is
|
|
# valid, by running it after dg-additional-files-options.
|
|
foreach ext $prof_ext {
|
|
profopt-target-cleanup $tmpdir $base $ext
|
|
profopt-target-cleanup $tmpdir $base "perf.data"
|
|
}
|
|
|
|
# Tree profiling requires TLS runtime support, which may need
|
|
# additional flags.
|
|
if { [string first "-fprofile-generate" $profile_option] >= 0 } {
|
|
set extra_flags [add_options_for_tls $extra_flags]
|
|
}
|
|
|
|
# Compile for profiling.
|
|
|
|
set options "$extra_options"
|
|
lappend options "additional_flags=$option $extra_flags $profile_option -dumpbase-ext ${execext}1"
|
|
set optstr "$option $profile_option"
|
|
set comp_output [${tool}_target_compile "$src" "$execname1" executable $options]
|
|
if ![${tool}_check_compile "$testcase compilation" $optstr $execname1 $comp_output] {
|
|
unresolved "$testcase execution, $optstr"
|
|
unresolved "$testcase compilation, $option $feedback_option"
|
|
unresolved "$testcase execution, $option $feedback_option"
|
|
continue
|
|
}
|
|
|
|
# Run the profiled test.
|
|
if { $run_autofdo == 1 } {
|
|
if { ![info exists ld_library_path]} {
|
|
set ld_library_path ""
|
|
}
|
|
set orig_ld_library_path "[getenv LD_LIBRARY_PATH]"
|
|
setenv LD_LIBRARY_PATH "$ld_library_path:$orig_ld_library_path"
|
|
verbose -log "Running $profile_wrapper -o $tmpdir/$base.perf.data $execname1"
|
|
set id [remote_spawn "" "$profile_wrapper -o $tmpdir/$base.perf.data $execname1" "readonly"]
|
|
setenv LD_LIBRARY_PATH $orig_ld_library_path
|
|
if { $id < 0 } {
|
|
warning "Failed to run profiler"
|
|
set status "fail"
|
|
} else {
|
|
set result [remote_wait "" 300]
|
|
set status [lindex $result 0]
|
|
verbose "perf result $result"
|
|
if { $status == 0 } {
|
|
set status "pass"
|
|
} else {
|
|
set status "fail"
|
|
}
|
|
}
|
|
} else {
|
|
set result [${tool}_load $execname1 "" ""]
|
|
set status [lindex $result 0]
|
|
}
|
|
|
|
set missing_file 0
|
|
set bprefix ""
|
|
# Make sure the profile data was generated, and fail if not.
|
|
if { $status == "pass" } {
|
|
# convert profile
|
|
if { $run_autofdo == 1 } {
|
|
set bprefix "afdo."
|
|
set cmd "create_gcov --binary $execname1 --profile=$tmpdir/$base.perf.data -gcov_version=1 --gcov=$tmpdir/$bprefix$base.$ext"
|
|
verbose "Running $cmd"
|
|
set id [remote_spawn "" $cmd]
|
|
if { $id < 0 } {
|
|
unsupported "$testcase -fauto-profile: cannot run create_gcov"
|
|
set status "fail"
|
|
return
|
|
}
|
|
set status [remote_wait "" 300]
|
|
set status "pass"
|
|
}
|
|
|
|
foreach ext $prof_ext {
|
|
remote_upload target $tmpdir/$bprefix$base.$ext
|
|
set files [glob -nocomplain $bprefix$base.$ext]
|
|
if { $files == "" } {
|
|
set status "fail"
|
|
set missing_file 1
|
|
fail "$testcase execution: file $bprefix$base.$ext does not exist, $option $profile_option"
|
|
}
|
|
}
|
|
}
|
|
if { $missing_file == 0 } {
|
|
$status "$testcase execution, $optstr"
|
|
}
|
|
|
|
# If there is dg-final code to execute for the generate step, do it
|
|
# even if it failed; it might clean up temporary files.
|
|
if ![string match $generate_final_code ""] {
|
|
profopt-final-code "generate" $generate_final_code $testcase
|
|
}
|
|
|
|
remote_file build delete $execname1
|
|
|
|
# Quit for this round if it failed
|
|
if { $status != "pass" } {
|
|
unresolved "$testcase compilation, $option $feedback_option"
|
|
unresolved "$testcase execution, $option $feedback_option"
|
|
continue
|
|
}
|
|
|
|
# Compile with feedback-directed optimizations.
|
|
|
|
set options "$extra_options"
|
|
lappend options "additional_flags=$option $extra_flags $feedback_option -dumpbase-ext ${execext}2"
|
|
set optstr "$option $feedback_option"
|
|
if { [string first "-fauto-profile" $options] >= 0} {
|
|
set options [regsub -- "-fauto-profile" $options "-fauto-profile=$tmpdir/$bprefix$base.$ext"]
|
|
}
|
|
|
|
set comp_output [${tool}_target_compile "$src" "$execname2" "executable" $options]
|
|
|
|
# Prune warnings we know are unwanted.
|
|
set comp_output [prune_warnings $comp_output]
|
|
|
|
if ![${tool}_check_compile "$testcase compilation" $optstr $execname2 $comp_output] {
|
|
unresolved "$testcase execution, $optstr"
|
|
continue
|
|
}
|
|
|
|
# Run the profile-directed optimized test.
|
|
|
|
set result [${tool}_load "$execname2" "" ""]
|
|
set status [lindex $result 0]
|
|
$status "$testcase execution, $optstr"
|
|
|
|
# If there is dg-final code to execute for the use step, do it.
|
|
if ![string match $use_final_code ""] {
|
|
profopt-final-code "use" $use_final_code $testcase
|
|
}
|
|
|
|
# Remove the profiling data files.
|
|
foreach ext $prof_ext {
|
|
profopt-target-cleanup $tmpdir "$bprefix$base" $ext
|
|
profopt-target-cleanup $tmpdir $base "perf.data"
|
|
profopt-target-cleanup $tmpdir $base "gcda.imports"
|
|
}
|
|
|
|
if { $status != "pass" } {
|
|
continue
|
|
}
|
|
|
|
# If the test is not expected to produce performance data then
|
|
# we're done now.
|
|
if ![info exists perf_ext] {
|
|
remote_file build delete $execname2
|
|
continue
|
|
}
|
|
|
|
# Get the performance data from the test built with
|
|
# profile-directed optimization. If the file doesn't exist or if
|
|
# the value is zero, skip the performance comparison.
|
|
set val2 [profopt-perf-value $testcase $perf_ext $optstr]
|
|
if { $val2 <= 0 } {
|
|
remote_file build delete $execname2
|
|
continue
|
|
}
|
|
|
|
# Compile with normal optimizations.
|
|
|
|
set options "$extra_options"
|
|
lappend options "additional_flags=$option -dumpbase-ext ${execext}3"
|
|
set optstr "$option"
|
|
set comp_output [${tool}_target_compile "$src" "$execname3" "executable" $options]
|
|
if ![${tool}_check_compile "$testcase compilation" $optstr $execname3 $comp_output] {
|
|
unresolved "$testcase execution, $optstr"
|
|
unresolved "$testcase perf check, $optstr"
|
|
continue
|
|
}
|
|
|
|
# Run the test with normal optimizations.
|
|
|
|
set result [${tool}_load "$execname3" "" ""]
|
|
set status [lindex $result 0]
|
|
$status "$testcase execution, $optstr"
|
|
if { $status != "pass" } {
|
|
unresolved "$testcase perf check, $optstr"
|
|
continue
|
|
}
|
|
|
|
# Get the performance data from the test built with normal
|
|
# optimization.
|
|
set val1 [profopt-perf-value $testcase $perf_ext $optstr]
|
|
if { $val1 < 0 } {
|
|
if { $val1 == -2 } {
|
|
# The data file existed with the profile-directed
|
|
# optimization so this one should, too.
|
|
fail "$testcase perf check: file $base.$perf_ext does not exist, $optstr"
|
|
}
|
|
continue
|
|
}
|
|
|
|
# Compare results of the two runs and fail if the time with the
|
|
# profile-directed optimization is significantly more than the time
|
|
# without it.
|
|
set status "pass"
|
|
if { $val2 > $val1 } {
|
|
# Check for a performance degration outside of allowable limits.
|
|
if { [expr $val2 - $val1] > [expr [expr $val1 * $perf_delta] / 100] } {
|
|
set status "fail"
|
|
}
|
|
}
|
|
if { $status == "fail" } {
|
|
fail "$testcase perf check: orig: $val1 new: $val2, $optstr"
|
|
} else {
|
|
$status "$testcase perf check, $optstr"
|
|
verbose "$testcase orig: $val1 new: $val2, $optstr" 2
|
|
remote_file build delete $execname2
|
|
remote_file build delete $execname3
|
|
}
|
|
}
|
|
unset testname_with_flags
|
|
}
|