From: Julian Seward Date: Thu, 4 Nov 2004 19:44:48 +0000 (+0000) Subject: Various plumbing to allow the optimiser (really, just a subset) to be X-Git-Tag: svn/VALGRIND_3_0_1^2~842 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5048dbe3ad3c1d9fd8cf51f83eb64999d641bfd7;p=thirdparty%2Fvalgrind.git Various plumbing to allow the optimiser (really, just a subset) to be run post-instrumentation. git-svn-id: svn://svn.valgrind.org/vex/trunk@492 --- diff --git a/VEX/head20041019/coregrind/vg_translate.c b/VEX/head20041019/coregrind/vg_translate.c index 321a6cbe8a..509890e3b9 100644 --- a/VEX/head20041019/coregrind/vg_translate.c +++ b/VEX/head20041019/coregrind/vg_translate.c @@ -1727,6 +1727,7 @@ Bool VG_(translate) ( ThreadId tid, Addr orig_addr, VG_(need_to_handle_esp_assignment)() ? vg_SP_update_pass : NULL, + True, /* cleanup after instrumentation */ NULL, VG_(clo_trace_codegen) ); diff --git a/VEX/priv/ir/iropt.h b/VEX/priv/ir/iropt.h index d5a30863bf..24e5bdecdf 100644 --- a/VEX/priv/ir/iropt.h +++ b/VEX/priv/ir/iropt.h @@ -18,6 +18,10 @@ IRBB* do_iropt_BB ( IRBB* bb, Bool (*preciseMemExnsFn)(Int,Int), Addr64 guest_addr ); +/* Do a constant folding/propagation pass. */ +extern +IRBB* cprop_BB ( IRBB* ); + /* Do a dead-code removal pass, which is generally needed to avoid crashing the tree-builder. bb is destructively modified. */ extern diff --git a/VEX/priv/main/vex_main.c b/VEX/priv/main/vex_main.c index e0b0983655..2ba4e477da 100644 --- a/VEX/priv/main/vex_main.c +++ b/VEX/priv/main/vex_main.c @@ -128,6 +128,7 @@ TranslateResult LibVEX_Translate ( /* IN: optionally, two instrumentation functions. */ IRBB* (*instrument1) ( IRBB*, VexGuestLayout*, IRType hWordTy ), IRBB* (*instrument2) ( IRBB*, VexGuestLayout*, IRType hWordTy ), + Bool cleanup_after_instrumentation, /* IN: optionally, an access check function for guest code. */ Bool (*byte_accessible) ( Addr64 ), /* IN: debug: trace vex activity at various points */ @@ -281,6 +282,22 @@ TranslateResult LibVEX_Translate ( if (instrument1 || instrument2) sanityCheckIRBB(irbb, guest_word_type); + /* Do a post-instrumentation cleanup pass. */ + if (cleanup_after_instrumentation) { + do_deadcode_BB( irbb ); + irbb = cprop_BB( irbb ); + do_deadcode_BB( irbb ); + sanityCheckIRBB(irbb, guest_word_type); + } + + if (vex_traceflags & VEX_TRACE_OPT2) { + vex_printf("\n------------------------" + " After post-instr IR optimisation " + "------------------------\n\n"); + ppIRBB ( irbb ); + vex_printf("\n"); + } + /* Turn it into virtual-registerised code. */ do_deadcode_BB( irbb ); do_treebuild_BB( irbb ); diff --git a/VEX/pub/libvex.h b/VEX/pub/libvex.h index 757ae9f3aa..be34d91b90 100644 --- a/VEX/pub/libvex.h +++ b/VEX/pub/libvex.h @@ -150,6 +150,7 @@ TranslateResult LibVEX_Translate ( /* IN: optionally, two instrumentation functions. */ IRBB* (*instrument1) ( IRBB*, VexGuestLayout*, IRType hWordTy ), IRBB* (*instrument2) ( IRBB*, VexGuestLayout*, IRType hWordTy ), + Bool cleanup_after_instrumentation, /* IN: optionally, an access check function for guest code. */ Bool (*byte_accessible) ( Addr64 ), /* IN: debug: trace vex activity at various points */ diff --git a/VEX/test_main.c b/VEX/test_main.c index 7ca579d438..5c2d300590 100644 --- a/VEX/test_main.c +++ b/VEX/test_main.c @@ -48,7 +48,7 @@ static UChar transbuf[N_TRANSBUF]; static Bool verbose = True; /* Forwards */ -static IRBB* ac_instrument ( IRBB*, VexGuestLayout* ); +static IRBB* ac_instrument ( IRBB*, VexGuestLayout*, IRType ); int main ( int argc, char** argv ) @@ -123,6 +123,7 @@ int main ( int argc, char** argv ) transbuf, N_TRANSBUF, &trans_used, ac_instrument, //NULL, /* instrument1 */ NULL, /* instrument2 */ + False, /* cleanup after instrument */ NULL, /* access checker */ TEST_FLAGS ); @@ -155,7 +156,7 @@ void panic ( Char* s ) } static -IRBB* ac_instrument (IRBB* bb_in, VexGuestLayout* layout) +IRBB* ac_instrument (IRBB* bb_in, VexGuestLayout* layout, IRType hWordTy ) { /* Use this rather than eg. -1 because it's a UInt. */ #define INVALID_DATA_SIZE 999999