]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Various plumbing to allow the optimiser (really, just a subset) to be
authorJulian Seward <jseward@acm.org>
Thu, 4 Nov 2004 19:44:48 +0000 (19:44 +0000)
committerJulian Seward <jseward@acm.org>
Thu, 4 Nov 2004 19:44:48 +0000 (19:44 +0000)
run post-instrumentation.

git-svn-id: svn://svn.valgrind.org/vex/trunk@492

VEX/head20041019/coregrind/vg_translate.c
VEX/priv/ir/iropt.h
VEX/priv/main/vex_main.c
VEX/pub/libvex.h
VEX/test_main.c

index 321a6cbe8a9c950a791b5c1e54e6042a16735713..509890e3b905ae5406349481c10b689148a6e4ca 100644 (file)
@@ -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)
           );
index d5a30863bf797712c7a3e779746298db685039d4..24e5bdecdfef799f77d794cb9e0f070846881ec5 100644 (file)
@@ -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
index e0b0983655c94a290178470d684f8d645184b2ab..2ba4e477da760bbadb6bdad6ea97730a31a984f2 100644 (file)
@@ -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 );
index 757ae9f3aaa66ddc225a5bcb56151ba2d53dd7f6..be34d91b901942987f8a43f37660a12aeb7da85a 100644 (file)
@@ -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 */
index 7ca579d4388ee06f216b96bd0424835c4a666688..5c2d3005905576c741fd06574967629b6d1941ea 100644 (file)
@@ -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