diff mbox

[RFC/CFT] auto-wipe dump files [was: Re: [committed] Fix up bb-slp-31.c testcase]

Message ID 20131030094133.GA22154@nbbrfq.cc.univie.ac.at
State New
Headers show

Commit Message

Bernhard Reutner-Fischer Oct. 30, 2013, 9:41 a.m. UTC
> Hi!
>
> I've noticed that this testcase doesn't clean up after itself.
> Fixed thusly, committed as obvious to trunk.

This was nagging me last weekend.. ;)
What about automating this?

Manual part is attached.
The "Adjust all callers" below is too big to send to the list:
git grep -l -E "(cleanup-.*-dump|cleanup-saved-temps)" | \
egrep -v "(ChangeLog|/lib/)" | sed -e "s|[^/]*$||" | sort | uniq | \
while read d;
do
  find $d -type f \
    -exec sed -i -e "/cleanup-[^-]*[-]*dump/d;/cleanup-saved-temps/d" {} +
done


Full regstrap on x86_64-unknown-linux-gnu with no regressions with
trunk@204119 for
configure \
--enable-bootstrap \
--with-system-zlib \
--without-included-gettext \
--disable-werror \
--enable-link-mutex \
--enable-nls \
--enable-plugin \
--enable-__cxa_atexit \
--enable-debug \
--enable-checking=yes,rtl \
--enable-gather-detailed-mem-stats \
--enable-multilib \
--enable-multiarch \
--with-linker-hash-style=both \
--with-as=$BINU/as \
--with-ld=$BINU/ld.gold \
--enable-languages=c,c++,fortran,lto,go,objc,obj-c++ \
&& make -k check -j4

Ok for trunk?
Comments?

Given the "Fix comment delimiter" hunks in the manual patch, i'd suggest
to add -Wcomment as default flags where possible to catch these early on
in the future.

gcc/testsuite/ChangeLog

2013-10-12  Bernhard Reutner-Fischer  <aldot@gcc.gnu.org>

	* lib/gcc-dg.exp (cleanup-ipa-dump, cleanup-rtl-dump,
	cleanup-tree-dump, cleanup-dump): Remove. Adjust all callers.
	(schedule-cleanups): New proc.
	(gcc-dg-test-1): Call it.
	* lib/profopt.exp (profopt-execute): Likewise.
	* g++.dg/cdce3.C: Adjust expected line numbers.
	* gcc.dg/cdce1.c: Likewise.
	* gcc.dg/cdce2.c: Likewise.
	* gcc.dg/strlenopt-22.c: Fix comment delimiter.
	* gcc.dg/strlenopt-24.c: Likewise.
	* gcc.dg/tree-ssa/vrp26.c: Likewise.
	* gcc.dg/tree-ssa/vrp28.c: Likewise.
	* obj-c++.dg/encode-2.mm: Likewise.

libgomp/ChangeLog

2013-10-12  Bernhard Reutner-Fischer  <aldot@gcc.gnu.org>

	* testsuite/libgomp.graphite/bounds.c: Adjust for
	cleanup-tree-dump removal.
	* testsuite/libgomp.graphite/force-parallel-1.c: Likewise.
	* testsuite/libgomp.graphite/force-parallel-2.c: Likewise.
	* testsuite/libgomp.graphite/force-parallel-3.c: Likewise.
	* testsuite/libgomp.graphite/force-parallel-4.c: Likewise.
	* testsuite/libgomp.graphite/force-parallel-5.c: Likewise.
	* testsuite/libgomp.graphite/force-parallel-6.c: Likewise.
	* testsuite/libgomp.graphite/force-parallel-7.c: Likewise.
	* testsuite/libgomp.graphite/force-parallel-8.c: Likewise.
	* testsuite/libgomp.graphite/force-parallel-9.c: Likewise.
	* testsuite/libgomp.graphite/pr41118.c: Likewise.


gcc/ChangeLog

2013-10-12  Bernhard Reutner-Fischer  <aldot@gcc.gnu.org>

	* config/arm/neon-testgen.ml (emit_epilogue): Remove manual call
	to cleanup-saved-temps.

gcc/doc/ChangeLog

2013-10-12  Bernhard Reutner-Fischer  <aldot@gcc.gnu.org>

	* doc/sourcebuild.texi (Clean up generated test files): Expand
	introduction.
	(cleanup-ipa-dump, cleanup-rtl-dump, cleanup-tree-dump,
	cleanup-saved-temps): Remove.

Comments

Mike Stump Oct. 31, 2013, 12:01 a.m. UTC | #1
On Oct 30, 2013, at 2:41 AM, Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> wrote:
>> I've noticed that this testcase doesn't clean up after itself.

> This was nagging me last weekend.. ;)
> What about automating this?

So, the idea sounds very nice.

One thing that I worry about is the testing speed hit for people (test cases) that don't need cleanups.  I don't know the speed hit of the code, so, don't know how necessary it is to try and go faster.

I was thinking the presence of a scan-tree-dump, would set a bit that said, do a scan-tree-dump style cleanup.

The common code then does, if cleanups needed, do cleanups

The idea, most test cases don't do this, and don't need the big cleanup routine to fire.  A scan-tree-dump would setup a cleanup tree dumps flags, and then in the big cleanup routine, you have:

do cleanups()
{
	if (need tree cleanups) do tree cleanups();
	if (need rtl cleanups) do rtl cleanups();
}

this way, we avoid randomly doing cleanups for things we don't need them for, and avoid even asking if we need any cleanups, as we can have a global flag that says if we need any extra, special cleanups.

So, all that would be bad to do, if the speed hit is small…  Can you collect with/without numbers and post them?  If you can, include user, sys and elapsed.  You can run a subset of one testsuite, say, dg.exp, as representative.
Bernhard Reutner-Fischer Oct. 31, 2013, 8:34 a.m. UTC | #2
On 31 October 2013 01:01, Mike Stump <mikestump@comcast.net> wrote:
> On Oct 30, 2013, at 2:41 AM, Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> wrote:
>>> I've noticed that this testcase doesn't clean up after itself.
>
>> This was nagging me last weekend.. ;)
>> What about automating this?
>
> So, the idea sounds very nice.
>
> One thing that I worry about is the testing speed hit for people (test cases) that don't need cleanups.  I don't know the speed hit of the code, so, don't know how necessary it is to try and go faster.
>
> I was thinking the presence of a scan-tree-dump, would set a bit that said, do a scan-tree-dump style cleanup.

Well, since the -fdump-* are the one to produce the dumps, i keyed the
cleanup off that.
Initially i had the idea to use an exact per-pass wiper but that
turned out to be too complicated for no real benefit.
>
> The common code then does, if cleanups needed, do cleanups
>
> The idea, most test cases don't do this, and don't need the big cleanup routine to fire.  A scan-tree-dump would setup a cleanup tree dumps flags, and then in the big cleanup routine, you have:

The cleanup routine would currently run 7 regexes on the incoming
compiler-flags which is supposedly pretty fast.
But yes, we could as well key off scan-dump. If we do that, i'd
suggest to simply wipe all potential dumps, regardless of the "family"
etc, like:
"$ltrans\[0-9\]\[0-9\]\[0-9\][itr].*"
What do you think?
>
> do cleanups()
> {
>         if (need tree cleanups) do tree cleanups();
>         if (need rtl cleanups) do rtl cleanups();
> }
>
> this way, we avoid randomly doing cleanups for things we don't need them for, and avoid even asking if we need any cleanups, as we can have a global flag that says if we need any extra, special cleanups.
>
> So, all that would be bad to do, if the speed hit is small…  Can you collect with/without numbers and post them?  If you can, include user, sys and elapsed.  You can run a subset of one testsuite, say, dg.exp, as representative.

The pristine trunk, i.e. with manual cleanup was a couple of seconds
slower than with the patch (10s or 20s IIRC, let me measure this on an
idle box again now).
As you can see, the number of globs before and after the patch
decreases quite a lot, i guess the fact that we glob less is
responsible for the improved runtime. Let me double-check that,
though.

thanks,
Jakub Jelinek Oct. 31, 2013, 8:39 a.m. UTC | #3
On Thu, Oct 31, 2013 at 09:34:41AM +0100, Bernhard Reutner-Fischer wrote:
> The cleanup routine would currently run 7 regexes on the incoming
> compiler-flags which is supposedly pretty fast.
> But yes, we could as well key off scan-dump. If we do that, i'd
> suggest to simply wipe all potential dumps, regardless of the "family"
> etc, like:
> "$ltrans\[0-9\]\[0-9\]\[0-9\][itr].*"
> What do you think?

Many tests (e.g. in gcc.dg/vect/) pass -fdump-* flags and require cleanups,
even if they don't have any scan directives.

	Jakub
Bernhard Reutner-Fischer April 25, 2022, 10:27 p.m. UTC | #4
On Wed, 30 Oct 2013 10:41:33 +0100
Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> wrote:

> > Hi!
> >
> > I've noticed that this testcase doesn't clean up after itself.
> > Fixed thusly, committed as obvious to trunk.  
> 
> This was nagging me last weekend.. ;)
> What about automating this?
> 
> Manual part is attached.
> The "Adjust all callers" below is too big to send to the list:
> git grep -l -E "(cleanup-.*-dump|cleanup-saved-temps)" | \
> egrep -v "(ChangeLog|/lib/)" | sed -e "s|[^/]*$||" | sort | uniq | \
> while read d;
> do
>   find $d -type f \
>     -exec sed -i -e "/cleanup-[^-]*[-]*dump/d;/cleanup-saved-temps/d" {} +
> done
> 
> 
> Full regstrap on x86_64-unknown-linux-gnu with no regressions with
> trunk@204119 for
> configure \
> --enable-bootstrap \
> --with-system-zlib \
> --without-included-gettext \
> --disable-werror \
> --enable-link-mutex \
> --enable-nls \
> --enable-plugin \
> --enable-__cxa_atexit \
> --enable-debug \
> --enable-checking=yes,rtl \
> --enable-gather-detailed-mem-stats \
> --enable-multilib \
> --enable-multiarch \
> --with-linker-hash-style=both \
> --with-as=$BINU/as \
> --with-ld=$BINU/ld.gold \
> --enable-languages=c,c++,fortran,lto,go,objc,obj-c++ \
> && make -k check -j4
> 
> Ok for trunk?
> Comments?
> 
> Given the "Fix comment delimiter" hunks in the manual patch, i'd suggest
> to add -Wcomment as default flags where possible to catch these early on
> in the future.

I should not dare to ping this proposal just yet again, now, without due
patience. But, maybe, we want to automatically add -Wcomment to the
testsuite unless a testcase mentions "comment" in their flags to catch
such malformed comments with dejagnu directives, next stage 1?

The handling should probably be about like what we did with the
-fno-ident that was added to the testsuite as to not confuse
scan-assembler test due to local branch names which was applied in
eb6ffc66825a8d36cf89881517624ff2df510aa9 ( r9-2792 )
https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=eb6ffc66825a8d36cf89881517624ff2df510aa9
iff maybe this can aid as a guide for someone to fix this for good.

TIA,
> 
> gcc/testsuite/ChangeLog
> 
> 2013-10-12  Bernhard Reutner-Fischer  <aldot@gcc.gnu.org>
> 
> 	* lib/gcc-dg.exp (cleanup-ipa-dump, cleanup-rtl-dump,
> 	cleanup-tree-dump, cleanup-dump): Remove. Adjust all callers.
> 	(schedule-cleanups): New proc.
> 	(gcc-dg-test-1): Call it.
> 	* lib/profopt.exp (profopt-execute): Likewise.
> 	* g++.dg/cdce3.C: Adjust expected line numbers.
> 	* gcc.dg/cdce1.c: Likewise.
> 	* gcc.dg/cdce2.c: Likewise.
> 	* gcc.dg/strlenopt-22.c: Fix comment delimiter.
> 	* gcc.dg/strlenopt-24.c: Likewise.
> 	* gcc.dg/tree-ssa/vrp26.c: Likewise.
> 	* gcc.dg/tree-ssa/vrp28.c: Likewise.
> 	* obj-c++.dg/encode-2.mm: Likewise.
> 
> libgomp/ChangeLog
> 
> 2013-10-12  Bernhard Reutner-Fischer  <aldot@gcc.gnu.org>
> 
> 	* testsuite/libgomp.graphite/bounds.c: Adjust for
> 	cleanup-tree-dump removal.
> 	* testsuite/libgomp.graphite/force-parallel-1.c: Likewise.
> 	* testsuite/libgomp.graphite/force-parallel-2.c: Likewise.
> 	* testsuite/libgomp.graphite/force-parallel-3.c: Likewise.
> 	* testsuite/libgomp.graphite/force-parallel-4.c: Likewise.
> 	* testsuite/libgomp.graphite/force-parallel-5.c: Likewise.
> 	* testsuite/libgomp.graphite/force-parallel-6.c: Likewise.
> 	* testsuite/libgomp.graphite/force-parallel-7.c: Likewise.
> 	* testsuite/libgomp.graphite/force-parallel-8.c: Likewise.
> 	* testsuite/libgomp.graphite/force-parallel-9.c: Likewise.
> 	* testsuite/libgomp.graphite/pr41118.c: Likewise.
> 
> 
> gcc/ChangeLog
> 
> 2013-10-12  Bernhard Reutner-Fischer  <aldot@gcc.gnu.org>
> 
> 	* config/arm/neon-testgen.ml (emit_epilogue): Remove manual call
> 	to cleanup-saved-temps.
> 
> gcc/doc/ChangeLog
> 
> 2013-10-12  Bernhard Reutner-Fischer  <aldot@gcc.gnu.org>
> 
> 	* doc/sourcebuild.texi (Clean up generated test files): Expand
> 	introduction.
> 	(cleanup-ipa-dump, cleanup-rtl-dump, cleanup-tree-dump,
> 	cleanup-saved-temps): Remove.
diff mbox

Patch

From dc181880947cbfb3d652c6d9530cea07cf8280d8 Mon Sep 17 00:00:00 2001
From: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Date: Fri, 18 Oct 2013 21:08:49 +0200
Subject: [PATCH] auto-wipe dump files

---
 gcc/config/arm/neon-testgen.ml        |   1 -
 gcc/doc/sourcebuild.texi              |  19 ++--
 gcc/testsuite/g++.dg/cdce3.C          |   5 +-
 gcc/testsuite/gcc.dg/cdce1.c          |   3 +-
 gcc/testsuite/gcc.dg/cdce2.c          |   3 +-
 gcc/testsuite/gcc.dg/strlenopt-22.c   |   3 +-
 gcc/testsuite/gcc.dg/strlenopt-24.c   |   3 +-
 gcc/testsuite/gcc.dg/tree-ssa/vrp26.c |   3 +-
 gcc/testsuite/gcc.dg/tree-ssa/vrp28.c |   3 +-
 gcc/testsuite/lib/dg-pch.exp          |  18 +++-
 gcc/testsuite/lib/gcc-dg.exp          | 160 ++++++++++++++++++++++++----------
 gcc/testsuite/lib/profopt.exp         |   3 +
 gcc/testsuite/obj-c++.dg/encode-2.mm  |   3 +-
 13 files changed, 151 insertions(+), 76 deletions(-)

diff --git a/gcc/config/arm/neon-testgen.ml b/gcc/config/arm/neon-testgen.ml
index 543318b..4734ac0 100644
--- a/gcc/config/arm/neon-testgen.ml
+++ b/gcc/config/arm/neon-testgen.ml
@@ -139,7 +139,6 @@  let emit_epilogue chan features regexps =
      else
        ()
     );
-    Printf.fprintf chan "/* { dg-final { cleanup-saved-temps } } */\n"
 
 (* Check a list of C types to determine which ones are pointers and which
    ones are const.  *)
diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi
index 1a70916..7e0ebd9 100644
--- a/gcc/doc/sourcebuild.texi
+++ b/gcc/doc/sourcebuild.texi
@@ -2145,13 +2145,17 @@  Check branch and/or call counts, in addition to line counts, in
 
 @subsubsection Clean up generated test files
 
+Usually the test-framework removes files that were generated during
+testing. If a testcase, for example, uses any dumping mechanism to
+inspect a passes dump file, the testsuite recognized the dumping option
+passed to the tool and schedules a final cleanup to remove these files.
+
+There are, however, following additional cleanup directives that can be
+used to annotate a testcase "manually".
 @table @code
 @item cleanup-coverage-files
 Removes coverage data files generated for this test.
 
-@item cleanup-ipa-dump @var{suffix}
-Removes IPA dump files generated for this test.
-
 @item cleanup-modules "@var{list-of-extra-modules}"
 Removes Fortran module files generated for this test, excluding the
 module names listed in keep-modules.
@@ -2192,15 +2196,6 @@  Removes profiling files generated for this test.
 @item cleanup-repo-files
 Removes files generated for this test for @option{-frepo}.
 
-@item cleanup-rtl-dump @var{suffix}
-Removes RTL dump files generated for this test.
-
-@item cleanup-saved-temps
-Removes files for the current test which were kept for @option{-save-temps}.
-
-@item cleanup-tree-dump @var{suffix}
-Removes tree dump files matching @var{suffix} which were generated for
-this test.
 @end table
 
 @node Ada Tests
diff --git a/gcc/testsuite/g++.dg/cdce3.C b/gcc/testsuite/g++.dg/cdce3.C
index 726e9ec..3937953 100644
--- a/gcc/testsuite/g++.dg/cdce3.C
+++ b/gcc/testsuite/g++.dg/cdce3.C
@@ -4,8 +4,9 @@ 
 /* { dg-additional-options "-DLARGE_LONG_DOUBLE" { target large_long_double } } */
 /* { dg-additional-options "-DGNU_EXTENSION" { target pow10 } } */
 /* { dg-add-options ieee } */
+/* { dg-final { scan-tree-dump  "cdce3.C:91: note: function call is shrink-wrapped into error conditions\." "cdce" { target pow10 } } } */
 /* { dg-final { scan-tree-dump  "cdce3.C:92: note: function call is shrink-wrapped into error conditions\." "cdce" { target pow10 } } } */
-/* { dg-final { scan-tree-dump  "cdce3.C:93: note: function call is shrink-wrapped into error conditions\." "cdce" { target pow10 } } } */
+/* { dg-final { scan-tree-dump  "cdce3.C:94: note: function call is shrink-wrapped into error conditions\." "cdce" } } */
 /* { dg-final { scan-tree-dump  "cdce3.C:95: note: function call is shrink-wrapped into error conditions\." "cdce" } } */
 /* { dg-final { scan-tree-dump  "cdce3.C:96: note: function call is shrink-wrapped into error conditions\." "cdce" } } */
 /* { dg-final { scan-tree-dump  "cdce3.C:97: note: function call is shrink-wrapped into error conditions\." "cdce" } } */
@@ -19,8 +20,6 @@ 
 /* { dg-final { scan-tree-dump  "cdce3.C:105: note: function call is shrink-wrapped into error conditions\." "cdce" } } */
 /* { dg-final { scan-tree-dump  "cdce3.C:106: note: function call is shrink-wrapped into error conditions\." "cdce" } } */
 /* { dg-final { scan-tree-dump  "cdce3.C:107: note: function call is shrink-wrapped into error conditions\." "cdce" } } */
-/* { dg-final { scan-tree-dump  "cdce3.C:108: note: function call is shrink-wrapped into error conditions\." "cdce" } } */
-/* { dg-final { cleanup-tree-dump "cdce" } } */
 
 #include <stdlib.h>
 #include <math.h>
diff --git a/gcc/testsuite/gcc.dg/cdce1.c b/gcc/testsuite/gcc.dg/cdce1.c
index 2123f7f..02b47c0 100644
--- a/gcc/testsuite/gcc.dg/cdce1.c
+++ b/gcc/testsuite/gcc.dg/cdce1.c
@@ -1,8 +1,7 @@ 
 /* { dg-do  run  } */
 /* { dg-options "-O2 -fmath-errno -fdump-tree-cdce-details  -lm" } */
 /* { dg-require-effective-target int32plus } */
-/* { dg-final { scan-tree-dump  "cdce1.c:17: note: function call is shrink-wrapped into error conditions\."  "cdce" } } */
-/* { dg-final { cleanup-tree-dump "cdce" } } */
+/* { dg-final { scan-tree-dump  "cdce1.c:16: note: function call is shrink-wrapped into error conditions\."  "cdce" } } */
 /* { dg-require-effective-target large_double } */
 
 #include <stdlib.h>
diff --git a/gcc/testsuite/gcc.dg/cdce2.c b/gcc/testsuite/gcc.dg/cdce2.c
index a461ce7..dafaeab 100644
--- a/gcc/testsuite/gcc.dg/cdce2.c
+++ b/gcc/testsuite/gcc.dg/cdce2.c
@@ -1,8 +1,7 @@ 
 /* { dg-do  run  } */
 /* { dg-skip-if "doubles are floats" { "avr-*-*" } { "*" } { "" } } */
 /* { dg-options "-O2 -fmath-errno -fdump-tree-cdce-details  -lm" } */
-/* { dg-final { scan-tree-dump  "cdce2.c:16: note: function call is shrink-wrapped into error conditions\." "cdce" } }*/
-/* { dg-final { cleanup-tree-dump "cdce" } } */
+/* { dg-final { scan-tree-dump  "cdce2.c:15: note: function call is shrink-wrapped into error conditions\." "cdce" } }*/
  
 #include <stdlib.h>
 #include <math.h>
diff --git a/gcc/testsuite/gcc.dg/strlenopt-22.c b/gcc/testsuite/gcc.dg/strlenopt-22.c
index d6fd4df..aa55f5e 100644
--- a/gcc/testsuite/gcc.dg/strlenopt-22.c
+++ b/gcc/testsuite/gcc.dg/strlenopt-22.c
@@ -36,5 +36,4 @@  main ()
 /* { dg-final { scan-tree-dump-times "strcpy \\(" 1 "strlen" } } */
 /* { dg-final { scan-tree-dump-times "strcat \\(" 0 "strlen" } } */
 /* { dg-final { scan-tree-dump-times "strchr \\(" 1 "strlen" } } */
-/* { dg-final { scan-tree-dump-times "stpcpy \\(" 0 "strlen" } } *
-/* { dg-final { cleanup-tree-dump "strlen" } } */
+/* { dg-final { scan-tree-dump-times "stpcpy \\(" 0 "strlen" } } */
diff --git a/gcc/testsuite/gcc.dg/strlenopt-24.c b/gcc/testsuite/gcc.dg/strlenopt-24.c
index 962e04f..639501a 100644
--- a/gcc/testsuite/gcc.dg/strlenopt-24.c
+++ b/gcc/testsuite/gcc.dg/strlenopt-24.c
@@ -13,5 +13,4 @@  main ()
   return 0;
 }
 
-/* { dg-final { scan-tree-dump-times "strlen \\(" 0 "strlen" } } *
-/* { dg-final { cleanup-tree-dump "strlen" } } */
+/* { dg-final { scan-tree-dump-times "strlen \\(" 0 "strlen" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp26.c b/gcc/testsuite/gcc.dg/tree-ssa/vrp26.c
index 6215416..021d2de 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/vrp26.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/vrp26.c
@@ -9,8 +9,7 @@  foo(int a)
 }
 
 /* VRP should optimize this to a trivial "return 1".   */
-/* { dg-final { scan-tree-dump-times "return 1" 1 "vrp1" } } * /
-/* { dg-final { cleanup-tree-dump "vrp1" } } */
+/* { dg-final { scan-tree-dump-times "return 1" 1 "vrp1" } } */
 
 
 
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp28.c b/gcc/testsuite/gcc.dg/tree-ssa/vrp28.c
index 6b2a1fd..8c2a72b 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/vrp28.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/vrp28.c
@@ -26,7 +26,6 @@  int f3 (unsigned char c)
     return 0;
 }
 
-/* { dg-final { scan-tree-dump-times "if " 0 "vrp1" } } * /
-/* { dg-final { cleanup-tree-dump "vrp1" } } */
+/* { dg-final { scan-tree-dump-times "if " 0 "vrp1" } } */
 
 
diff --git a/gcc/testsuite/lib/gcc-dg.exp b/gcc/testsuite/lib/gcc-dg.exp
index f64f4a1..1f96226 100644
--- a/gcc/testsuite/lib/gcc-dg.exp
+++ b/gcc/testsuite/lib/gcc-dg.exp
@@ -106,6 +106,121 @@  if { $orig_environment_saved == 0 } {
     set_ld_library_path_env_vars
 }
 
+# Deduce generated files from tool flags, return finalcode string
+proc schedule-cleanups { opts } {
+    global additional_sources
+    set finalcode ""
+    set testcases {}
+    lappend testcases [lindex [testname-for-summary] 0]
+    verbose "Cleanup testcases: $testcases" 4
+    if { [info exists additional_sources] && $additional_sources != "" } {
+	lappend testcases $additional_sources
+	verbose "Cleanup testcases, additional: $additional_sources" 4
+    }
+    # tuple of <fam>.<pass> where <pass> might be '*' for all
+    set fams {}
+    verbose "Cleanup all options: $opts" 4
+
+    # fixups
+    # --dump= should translate to -d with joined operand.
+    if [regexp -- {(^|\s+)--dump=[^\s]+(\s+|$)} $opts] {
+	regsub -all -- {--dump=} $opts {-d} opts
+    }
+    # ??? -fdump-class-hierarchy misnomer: missing -tree
+    if [regexp -- {(^|\s+)-fdump-class-hierarchy(\s+|$)} $opts] {
+	regsub -all -- {-fdump-class-hierarchy} $opts {-fdump-tree-class-hierarchy} opts
+    }
+
+    # -fprofile-generate -> cleanup-coverage-files()
+    # -fstack-usage -> cleanup-stack-usage()
+    if [regexp -- {(^|\s+)-fstack-usage(\s+|$)} $opts] {
+	verbose "Cleanup -fstack-usage seen" 4
+#	append finalcode "cleanup-stack-usage\n"
+    }
+    # -save-temps -> cleanup-saved-temps()
+    if [regexp -- {(^|\s+)-save-temps(\s+|$)} $opts] {
+	verbose "Cleanup -save-temps seen" 4
+	append finalcode "cleanup-saved-temps\n"
+    }
+    if [regexp -- {(^|\s+)-da(\s+|$)} $opts] { # shorthand for -fdump-rtl-all
+	verbose "Cleanup -da seen" 4
+	lappend fams "r"
+    }
+    if [regexp -- {(^|\s+)-flto(\s+|$)} $opts] {
+	verbose "Cleanup -flto seen" 4
+	set ltrans "{ltrans\[0-9\]*.,}"
+    } else {
+	set ltrans ""
+    }
+
+    # -fdump-<family>-<passname>-<detail> (plus exceptions)
+    set dflags [regexp -all -inline -- {(?=(?:^|[ \t]+)?)-fdump-[^ \t]+(?=(?:$|[ \t]+)?)} $opts]
+    verbose "Cleanup -fdump-* flags: $dflags" 4
+    foreach d $dflags {
+	verbose "Cleanup examine $d" 4
+	foreach { _ fam pas lvl } \
+		[regexp -all -inline -- {[^-]+(?=(?:-)?)} $d] {
+	    regsub -- {^all$} $pas {*} pas
+	    # -fdump-rtl-<passname>-graph -> .dot and ignore rest
+	    set lvl [lindex [list "" ".dot"] [string equal "graph" $lvl]]
+	    verbose "Cleanup fam=$fam pas=$pas lvl=$lvl" 4
+	    if [regexp {(rtl|tree|ipa)} $fam] {
+		# per-pass in the light of -fdump-tree-local-pure-const1
+		# is a bit too much for the moment..
+                set f [string index $fam 0]
+                if { [lsearch -exact $fams $f] < 0 } {
+		    lappend fams $f
+		}
+	    }
+	}
+    }
+    if { [llength $fams] < 1 } {
+	return $finalcode
+    } elseif { [llength $fams] == 1 } {
+	set fams [lindex $fams 0]
+    } else {
+	set fams [join $fams ","]
+	set fams "{$fams}"
+    }
+    # stem.ext.<passnum><fam>.<passname><pass-instances>
+    # (tree)passes can have multiple instances, thus optional trailing [0-9]
+    # That will generate *{\[0-9\],} for -fdump-fam-all but is nicer otherwise
+    #set tuples "\[0-9\]\[0-9\]\[0-9\]$tuples{\[0-9\],}"
+    set fams "\[0-9\]\[0-9\]\[0-9\]$fams.*"
+    set fams "$ltrans$fams"
+    verbose "Cleanup final fams: $fams" 4
+    set tfiles {}
+    foreach src $testcases {
+	set basename [file tail $src]
+	if { $ltrans != "" } {
+	    # ??? should we use upvar 1 output_file instead of this (dup ?)
+	    set stem [file rootname $basename]
+	    set basename_ext [file extension $basename]
+	    if {$basename_ext != ""} {
+		regsub -- {^.*\.} $basename_ext {} basename_ext
+	    }
+	    lappend tfiles "$stem.{$basename_ext,exe}"
+	    unset basename_ext
+	} else {
+	    lappend tfiles $basename
+	}
+    }
+    if { [llength $tfiles] > 1 } {
+	set tfiles [join $tfiles ","]
+	set tfiles "{$tfiles}"
+    }
+    verbose "Cleanup final testcases: $tfiles" 4
+    # We have to quote the regex
+    regsub -all {([][$^?+*()|\\{}])} "$tfiles.$fams" {\\\1} ptn
+    set final ""
+    append final {remove-build-file }
+    append final "\"$ptn\""
+    verbose "Cleanup final: $final" 4
+    append finalcode "$final\n"
+
+    return $finalcode
+}
+
 # Define gcc callbacks for dg.exp.
 
 proc gcc-dg-test-1 { target_compile prog do_what extra_tool_flags } {
@@ -177,6 +292,7 @@  proc gcc-dg-test-1 { target_compile prog do_what extra_tool_flags } {
 	}
     }
 
+    append finalcode [schedule-cleanups "$options $extra_tool_flags"]
     if { $extra_tool_flags != "" } {
 	lappend options "additional_flags=$extra_tool_flags"
     }
@@ -518,27 +634,6 @@  proc cleanup-repo-files { } {
     }
 }
 
-# Remove compiler-generated RTL dump files for the current test.
-#
-# SUFFIX is the filename suffix pattern.
-proc cleanup-rtl-dump { suffix } {
-  cleanup-dump "\[0-9\]\[0-9\]\[0-9\]r.$suffix"
-}
-
-# Remove a specific tree dump file for the current test.
-#
-# SUFFIX is the tree dump file suffix pattern.
-proc cleanup-tree-dump { suffix } {
-  cleanup-dump "\[0-9\]\[0-9\]\[0-9\]t.$suffix"
-}
-
-# Remove a specific ipa dump file for the current test.
-#
-# SUFFIX is the ipa dump file suffix pattern.
-proc cleanup-ipa-dump { suffix } {
-  cleanup-dump "\[0-9\]\[0-9\]\[0-9\]i.$suffix"
-}
-
 # Remove a stack usage file for the current test.
 proc cleanup-stack-usage { } {
     set testcase [testname-for-summary]
@@ -567,29 +662,6 @@  proc cleanup-ada-spec { } {
     }
 }
 
-# Remove all dump files with the provided suffix.
-proc cleanup-dump { suffix } {
-    set testcase [testname-for-summary]
-    # The name might include a list of options; extract the file name.
-    set src [file tail [lindex $testcase 0]]
-    remove-build-file "[file tail $src].$suffix"
-    remove-build-file "[file rootname [file tail $src]].exe.$suffix"
-    remove-build-file "[file rootname [file tail $src]].exe.ltrans\[0-9\]*.$suffix"
-    # -fcompare-debug dumps
-    remove-build-file "[file tail $src].gk.$suffix"
-
-    # Clean up dump files for additional source files.
-    if [info exists additional_sources] {
-	foreach srcfile $additional_sources {
-	    remove-build-file "[file tail $srcfile].$suffix"
-	    remove-build-file "[file rootname [file tail $srcfile]].exe.$suffix"
-	    remove-build-file "[file rootname [file tail $srcfile]].exe.ltrans\[0-9\]*.$suffix"
-	    # -fcompare-debug dumps
-	    remove-build-file "[file tail $srcfile].gk.$suffix"
-	}
-    }
-}
-
 # Remove files kept by --save-temps for the current test.
 #
 # Currently this is only .i, .ii, .s and .o files, but more can be added
diff --git a/gcc/testsuite/lib/profopt.exp b/gcc/testsuite/lib/profopt.exp
index cdc6b00..a5aa84d 100644
--- a/gcc/testsuite/lib/profopt.exp
+++ b/gcc/testsuite/lib/profopt.exp
@@ -283,6 +283,9 @@  proc profopt-execute { src } {
 	    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"]
 
 	# Tree profiling requires TLS runtime support, which may need
diff --git a/gcc/testsuite/obj-c++.dg/encode-2.mm b/gcc/testsuite/obj-c++.dg/encode-2.mm
index 157bb52..77eb6ad 100644
--- a/gcc/testsuite/obj-c++.dg/encode-2.mm
+++ b/gcc/testsuite/obj-c++.dg/encode-2.mm
@@ -24,5 +24,4 @@  const char *enc3 = @encode(anonymous);
 
 /* { dg-final { scan-assembler "{Vec<float>=ffi}" } }  */
 /* { dg-final { scan-assembler "{Vec<double>=ddi}" } }  */
-/* { dg-final { scan-file "encode-2.o" "{?={Vec<double>=ddi}{Vec<float>=ffi}fd{Vec<signed char>=cci}i}" } }
-/* { dg-final cleanup-saved-temps } */
+/* { dg-final { scan-file "encode-2.o" "{?={Vec<double>=ddi}{Vec<float>=ffi}fd{Vec<signed char>=cci}i}" } } */
-- 
1.8.4.rc3