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]

Optimization level iteration for dg framework


This patch implements optimization-level iteration (as is done in
c-torture) for the dg framework.  At the moment it's only active in
gcc.dg/noncompile, because some of the top level tests don't like
being run over and over with different options.  If the patch is
approved, I'll split the top level tests into ones that should and
ones that should not be iterated.

There is unfortunately no way short of modifying dejagnu itself to get
the optimization level into the PASS: or FAIL: messages.  (I'm not a
dejagnu expert, and I would be delighted to be proven wrong.)

Some of this code is copied from c-torture.exp and should probably be
factored out into an overall gcc library file.

zw

	* lib/gcc-dg.exp: Set up TORTURE_OPTIONS, torture_with_loops,
	and torture_without_loops as is done by c-torture.exp.
	(search_for): Copy from c-torture.exp.
	(gcc-dg-runtest): New function, drives a directory of tests
	iterating over the TORTURE_OPTIONS.
	(scan-assembler, scan-assembler-not): Move here from
	individual directory drivers.

	* gcc.dg/dg.exp: scan-assembler, scan-assembler-not now
	defined by lib/gcc-dg.exp.
	* gcc.dg/cpp/cpp.exp: Likewise.
	* gcc.dg/noncompile/noncompile.exp: Likewise.  Use
	gcc-dg-runtest, so we cycle over optimization options.

===================================================================
Index: testsuite/lib/gcc-dg.exp
--- testsuite/lib/gcc-dg.exp	1999/11/08 10:14:21	1.5
+++ testsuite/lib/gcc-dg.exp	2000/07/04 02:02:11
@@ -1,4 +1,4 @@
-#   Copyright (C) 1997, 1999 Free Software Foundation, Inc.
+#   Copyright (C) 1997, 1999, 2000 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
@@ -17,12 +17,44 @@
 # Please email any bugs, comments, and/or additions to this file to:
 # bug-gcc@prep.ai.mit.edu
 
-# Define gcc callbacks for dg.exp.
-
 load_lib dg.exp
 load_lib file-format.exp
 load_lib target-supports.exp
 
+if ![info exists TORTURE_OPTIONS] {
+    # It is theoretically beneficial to group all of the O2/O3 options together,
+    # as in many cases the compiler will generate identical executables for
+    # all of them--and the c-torture testsuite will skip testing identical
+    # executables multiple times.
+    # Also note that -finline-functions is explicitly included in one of the
+    # items below, even though -O3 is also specified, because some ports may
+    # choose to disable inlining functions by default, even when optimizing.
+    set TORTURE_OPTIONS [list \
+	{ -O0 } \
+	{ -O1 } \
+	{ -O2 } \
+	{ -O3 -fomit-frame-pointer } \
+	{ -O3 -fomit-frame-pointer -funroll-loops } \
+	{ -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions } \
+	{ -O3 -g } \
+	{ -O3 -fssa } \
+	{ -Os } ]
+}
+
+
+# Split TORTURE_OPTIONS into two choices: one for testcases with loops and
+# one for testcases without loops.
+
+set torture_with_loops $TORTURE_OPTIONS
+set torture_without_loops ""
+foreach option $TORTURE_OPTIONS {
+    if ![string match "*loop*" $option] {
+	lappend torture_without_loops $option
+    }
+}
+
+# Define gcc callbacks for dg.exp.
+
 proc gcc-dg-test { prog do_what extra_tool_flags } {
     # Set up the compiler flags, based on what we're going to do.
 
@@ -70,7 +102,6 @@ proc gcc-dg-test { prog do_what extra_to
     return [list $comp_output $output_file]
 }
 
-
 proc gcc-dg-prune { system text } {
     set text [prune_gcc_output $text]
 
@@ -84,3 +115,82 @@ proc gcc-dg-prune { system text } {
 
     return $text
 }
+
+# Utility routines.
+
+#
+# search_for -- looks for a string match in a file
+#
+proc search_for { file pattern } {
+    set fd [open $file r]
+    while { [gets $fd cur_line]>=0 } {
+	if [string match "*$pattern*" $cur_line] then {
+	    close $fd
+	    return 1
+	}
+    }
+    close $fd
+    return 0
+}
+
+# Modified dg-runtest that can cycle through a list of optimization options
+# as c-torture does.
+proc gcc-dg-runtest { testcases default-extra-flags } {
+    global runtests
+
+    foreach test $testcases {
+	# If we're only testing specific files and this isn't one of 
+	# them, skip it.
+	if ![runtest_file_p $runtests $test] {
+	    continue
+        }
+
+	# Look for a loop within the source code - if we don't find one,
+	# don't pass -funroll[-all]-loops.
+	global torture_with_loops torture_without_loops
+	if [expr [search_for $test "for*("]+[search_for $test "while*("]] {
+	    set option_list $torture_with_loops
+	} else {
+	    set option_list $torture_without_loops
+	}
+
+	set nshort [file tail [file dirname $test]]/[file tail $test]
+
+	foreach flags $option_list {
+	    verbose "Testing $nshort, $flags" 1
+	    dg-test $test $flags ${default-extra-flags}
+	}
+    }
+}
+
+# Utility for scanning compiler result, invoked via dg-final.
+# Call pass if pattern is present, otherwise fail.
+proc scan-assembler { testcase pattern } {
+    global subdir
+
+    set fd [open [file rootname $testcase].s r]
+    set text [read $fd]
+    close $fd
+
+    if [regexp -- $pattern $text] {
+	pass "$subdir/$testcase scan-assembler"
+    } else {
+	fail "$subdir/$testcase scan-assembler"
+    }
+}
+
+# Call pass if pattern is not present, otherwise fail.
+proc scan-assembler-not { testcase pattern } {
+    global subdir
+
+    set fd [open [file rootname $testcase].s r]
+    set text [read $fd]
+    close $fd
+
+    if ![regexp -- $pattern $text] {
+	pass "$subdir/$testcase scan-assembler-not"
+    } else {
+	fail "$subdir/$testcase scan-assembler-not"
+    }
+}
+
===================================================================
Index: testsuite/gcc.dg/dg.exp
--- testsuite/gcc.dg/dg.exp	2000/05/11 08:43:56	1.3
+++ testsuite/gcc.dg/dg.exp	2000/07/04 02:02:11
@@ -22,37 +22,6 @@
 # Load support procs.
 load_lib gcc-dg.exp
 
-# Utility for scanning compiler result, invoked via dg-final.
-# Call pass if pattern is present, otherwise fail.
-proc scan-assembler { testcase pattern } {
-    global subdir
-
-    set fd [open [file rootname $testcase].s r]
-    set text [read $fd]
-    close $fd
-
-    if [regexp -- $pattern $text] {
-	pass "$subdir/$testcase scan-assembler"
-    } else {
-	fail "$subdir/$testcase scan-assembler"
-    }
-}
-
-# Call pass if pattern is not present, otherwise fail.
-proc scan-assembler-not { testcase pattern } {
-    global subdir
-
-    set fd [open [file rootname $testcase].s r]
-    set text [read $fd]
-    close $fd
-
-    if ![regexp -- $pattern $text] {
-	pass "$subdir/$testcase scan-assembler-not"
-    } else {
-	fail "$subdir/$testcase scan-assembler-not"
-    }
-}
-
 # If a testcase doesn't have special options, use these.
 global DEFAULT_CFLAGS
 if ![info exists DEFAULT_CFLAGS] then {
===================================================================
Index: testsuite/gcc.dg/cpp/cpp.exp
--- testsuite/gcc.dg/cpp/cpp.exp	2000/06/27 22:26:11	1.1
+++ testsuite/gcc.dg/cpp/cpp.exp	2000/07/04 02:02:11
@@ -22,37 +22,6 @@
 # Load support procs.
 load_lib gcc-dg.exp
 
-# Utility for scanning compiler result, invoked via dg-final.
-# Call pass if pattern is present, otherwise fail.
-proc scan-assembler { testcase pattern } {
-    global subdir
-
-    set fd [open [file rootname $testcase].s r]
-    set text [read $fd]
-    close $fd
-
-    if [regexp -- $pattern $text] {
-	pass "$subdir/$testcase scan-assembler"
-    } else {
-	fail "$subdir/$testcase scan-assembler"
-    }
-}
-
-# Call pass if pattern is not present, otherwise fail.
-proc scan-assembler-not { testcase pattern } {
-    global subdir
-
-    set fd [open [file rootname $testcase].s r]
-    set text [read $fd]
-    close $fd
-
-    if ![regexp -- $pattern $text] {
-	pass "$subdir/$testcase scan-assembler-not"
-    } else {
-	fail "$subdir/$testcase scan-assembler-not"
-    }
-}
-
 # If a testcase doesn't have special options, use these.
 global DEFAULT_CFLAGS
 if ![info exists DEFAULT_CFLAGS] then {
===================================================================
Index: testsuite/gcc.dg/noncompile/noncompile.exp
--- testsuite/gcc.dg/noncompile/noncompile.exp	2000/06/29 19:55:26	1.1
+++ testsuite/gcc.dg/noncompile/noncompile.exp	2000/07/04 02:02:11
@@ -17,48 +17,12 @@
 # Please email any bugs, comments, and/or additions to this file to:
 # bug-gcc@prep.ai.mit.edu
 
-# GCC testsuite that uses the `dg.exp' driver.
+# Test error reporting.
+# Don't run this directory with any default CFLAGS, but do cycle through
+# torture options.
 
-# Load support procs.
 load_lib gcc-dg.exp
 
-# Utility for scanning compiler result, invoked via dg-final.
-# Call pass if pattern is present, otherwise fail.
-proc scan-assembler { testcase pattern } {
-    global subdir
-
-    set fd [open [file rootname $testcase].s r]
-    set text [read $fd]
-    close $fd
-
-    if [regexp -- $pattern $text] {
-	pass "$subdir/$testcase scan-assembler"
-    } else {
-	fail "$subdir/$testcase scan-assembler"
-    }
-}
-
-# Call pass if pattern is not present, otherwise fail.
-proc scan-assembler-not { testcase pattern } {
-    global subdir
-
-    set fd [open [file rootname $testcase].s r]
-    set text [read $fd]
-    close $fd
-
-    if ![regexp -- $pattern $text] {
-	pass "$subdir/$testcase scan-assembler-not"
-    } else {
-	fail "$subdir/$testcase scan-assembler-not"
-    }
-}
-
-# Initialize `dg'.
 dg-init
-
-# Main loop.
-# Don't run this directory with any default CFLAGS.
-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cS\]]] "" ""
-
-# All done.
+gcc-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cS\]]] ""
 dg-finish

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