This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[testsuite] preliminary: directives in profile-directed opt tests


Honza and I recently chatted on IRC about support for looking at dump
files in tests of profile-directed optimizations.  Here's a preliminary
attempt to support that.  I'm primarily intested in Honza's feedback
right now, but anyone is welcome to jump in with suggestions.

I'll add to the testsuite documentation in sourcebuild.texi, but this
lets tests that use profopt.exp include a few test directives:
dg-options, dg-skip-if, dg-require-*, and variants of dg-final for
checks to run after the profile-generate run and the profile-use run.
I haven't though much about dg-skip-if except to realize that it would
be messy and would probably need variants for the first and second
compilations.

The new test directory is merely an example.

2005-05-xx  Janis Johnson  <janis187@us.ibm.com>

	* lib/profopt.exp (dg-final-generate, dg-final-use,
	profopt-final-code, profopt-get-options): New.
	(profopt-execute): Use new procs.
	* gcc.dg/tree-prof: New directory.
	* gcc.dg/tree-prof/tree-prof.exp: New.
	* gcc.dg/tree-prof/test-1.c: Dummy new test.
	* gcc.dg/tree-prof/test-2.c: Dummy new test.

Index: gcc/testsuite/lib/profopt.exp
===================================================================
RCS file: /opt/gcc-cvs/gcc/gcc/testsuite/lib/profopt.exp,v
retrieving revision 1.7
diff -u -p -r1.7 profopt.exp
--- gcc/testsuite/lib/profopt.exp	31 Mar 2005 18:36:30 -0000	1.7
+++ gcc/testsuite/lib/profopt.exp	20 May 2005 23:29:06 -0000
@@ -1,4 +1,4 @@
-#   Copyright (C) 2001, 2004 Free Software Foundation, Inc.
+#   Copyright (C) 2001, 2004, 2005 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
@@ -30,6 +30,9 @@
 # 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.
@@ -116,6 +119,89 @@ proc profopt-perf-value { testcase perf_
 }
 
 #
+# 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"
+}
+
+#
+# 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 testcase } {
+    regsub -all "\\\\(\[{}\])" $final_code "\\1" final_code
+    proc profopt-final-proc { args } $final_code
+    if [catch "profopt-final-proc $testcase" 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 
+
+    set tmp [dg-get-options $src]
+    foreach op $tmp {
+	set cmd [lindex $op 0]
+	if { ![string compare "dg-options" $cmd] \
+	     || ![string compare "dg-skip-if" $cmd] \
+	     || ![string compare "dg-final-generate" $cmd] \
+	     || ![string compare "dg-final-use" $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 "compat.exp does not support $cmd"
+	}
+    }
+
+    # Return flags to use for compiling the primary source file and for
+    # linking.
+    return ${dg-extra-tool-flags}
+}
+
+#
 # c-prof-execute -- compile for profiling and then feedback, then normal
 #
 # SRC is the full pathname of the testcase.
@@ -124,6 +210,7 @@ proc profopt-execute { src } {
     global srcdir tmpdir
     global prof_option_list
     global tool profile_option feedback_option prof_ext perf_ext perf_delta
+    global generate_final_code use_final_code
     global verbose
 
     if ![info exists profile_option] {
@@ -162,10 +249,22 @@ proc profopt-execute { src } {
 	    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 "$src"
+	    verbose "$src not supported on this target, skipping it" 3
+	    return
+	}
+
 	# Compile for profiling.
 
 	set options ""
-	lappend options "additional_flags=$option $profile_option"
+	lappend options "additional_flags=$option $extra_flags $profile_option"
 	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] {
@@ -179,6 +278,7 @@ proc profopt-execute { src } {
 
 	set result [${tool}_load $execname1 "" ""]
 	set status [lindex $result 0]
+	set missing_file 0
 	# Make sure the profile data was generated, and fail if not.
 	if { $status == "pass" } {
 	    set basename [file tail $testcase]
@@ -187,26 +287,33 @@ proc profopt-execute { src } {
 		set files [glob -nocomplain $base.$ext]
 		if { $files == "" } {
 		    set status "fail"
+		    set missing_file 1
 		    fail "$testcase execution: file $base.$ext does not exist, $option $profile_option"
-		} else {
-	            $status "$testcase execution,   $optstr"
 		}
 	    }
-	} else {
+	}
+        if { $missing_file == 0 } {
 	    $status "$testcase execution,   $optstr"
 	}
+
 	# Quit for this round if it failed
 	if { $status != "pass" } {
  	    unresolved "$testcase compilation, $option $feedback_option"
  	    unresolved "$testcase execution,   $option $feedback_option"
 	    continue
 	}
+
+	# If there is dg-final code to execute for the generate step, do it.
+	if ![string match $generate_final_code ""] {
+	    profopt-final-code "generate" $generate_final_code $testcase
+	}
+
 	remote_file build delete $execname1
 
 	# Compile with feedback-directed optimizations.
 
 	set options ""
-	lappend options "additional_flags=$option $feedback_option"
+	lappend options "additional_flags=$option $extra_flags $feedback_option"
 	set optstr "$option $feedback_option"
 	set comp_output [${tool}_target_compile "$src" "$execname2" "executable" $options]
 	if ![${tool}_check_compile "$testcase compilation" $optstr $execname2 $comp_output] {
@@ -221,6 +328,11 @@ proc profopt-execute { src } {
 	$status "$testcase execution,   $optstr"
 	if { $status != "pass" } {
 	    continue
+	}
+
+	# 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.
--- /dev/null	2004-06-24 11:06:20.000000000 -0700
+++ gcc/testsuite/gcc.dg/tree-prof/tree-prof.exp	2005-05-20 16:27:17.000000000 -0700
@@ -0,0 +1,58 @@
+#   Copyright (C) 2001, 2002, 2004, 2005 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 2 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 this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
+
+# Test the functionality of programs compiled with profile-directed block
+# ordering using -fprofile-arcs followed by -fbranch-probabilities.
+
+load_lib target-supports.exp
+
+# Some targets don't support tree profiling.
+if { ![check_profiling_available "-ftree-based-profiling"] } {
+    return
+}
+
+# The procedures in profopt.exp need these parameters.
+set tool gcc
+set prof_ext "gcda gcno"
+
+# Override the list defined in profopt.exp.
+set PROFOPT_OPTIONS [list {}]
+
+if $tracelevel then {
+    strace $tracelevel
+}
+
+# This is a dummy proc for testing dg-final-generate and dg-final-use.
+proc pass-with-message { msg } {
+    pass "$msg"
+}
+
+# Load support procs.
+load_lib profopt.exp
+
+# These are globals used by profopt-execute.  The first is options
+# needed to generate profile data, the second is options to use the
+# profile data.
+set profile_option "-ftree-based-profiling -fprofile-arcs"
+set feedback_option "-ftree-based-profiling -fbranch-probabilities"
+
+foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.c]] {
+    # If we're only testing specific files and this isn't one of them, skip it.
+    if ![runtest_file_p $runtests $src] then {
+        continue
+    }
+    profopt-execute $src
+}
--- /dev/null	2004-06-24 11:06:20.000000000 -0700
+++ gcc/testsuite/gcc.dg/tree-prof/test-1.c	2005-05-20 16:07:28.000000000 -0700
@@ -0,0 +1,10 @@
+/* { dg-require-effective-target ilp32 } */
+/* { dg-options "-g" } */
+
+int
+main ()
+{
+    return 0;
+}
+
+/* { dg-final-use { pass-with-message "final step for profile-use" } } */
--- /dev/null	2004-06-24 11:06:20.000000000 -0700
+++ gcc/testsuite/gcc.dg/tree-prof/test-2.c	2005-05-20 16:06:33.000000000 -0700
@@ -0,0 +1,11 @@
+/* { dg-skip-if "" { ilp32 } } */
+/* { dg-options "-g" } */
+
+int
+main ()
+{
+    return 0;
+}
+
+/* { dg-final-generate { pass-with-message "final step for profile-generate" } } */
+/* { dg-final-use { pass-with-message "final step for profile-use" } } */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]