From: Bart Van Assche Date: Mon, 16 Jun 2008 20:22:18 +0000 (+0000) Subject: Yet another optimization: do not instrument loads and stores that match the address... X-Git-Tag: svn/VALGRIND_3_4_0~470 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f684e11d60257ee93c0a172dd79c03954b214ca7;p=thirdparty%2Fvalgrind.git Yet another optimization: do not instrument loads and stores that match the address pattern (stack pointer + offset) when data race detection on stack variables is disabled. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@8236 --- diff --git a/exp-drd/drd_main.c b/exp-drd/drd_main.c index 5b688ec4c1..9760ca1636 100644 --- a/exp-drd/drd_main.c +++ b/exp-drd/drd_main.c @@ -38,6 +38,7 @@ #include "drd_thread_bitmap.h" #include "drd_track.h" #include "drd_vc.h" +#include "libvex_guest_offsets.h" #include "priv_drd_clientreq.h" #include "pub_drd_bitmap.h" #include "pub_tool_vki.h" // Must be included before pub_tool_libcproc @@ -843,6 +844,50 @@ void drd_post_clo_init(void) } } +#if defined(VGA_x86) +#define STACK_POINTER_OFFSET OFFSET_x86_ESP +#elif defined(VGA_amd64) +#define STACK_POINTER_OFFSET OFFSET_amd64_RSP +#elif defined(VGA_ppc32) +#define STACK_POINTER_OFFSET ((OFFSET_ppc32_GPR0 + OFFSET_ppc32_GPR2) / 2) +#elif defined(VGA_ppc64) +#define STACK_POINTER_OFFSET ((OFFSET_ppc64_GPR0 + OFFSET_ppc64_GPR2) / 2) +#else +#error Unknown architecture. +#endif + + +/** Return true if and only if addr_expr matches the pattern (SP) or + * (SP). + */ +static Bool is_stack_access(IRSB* const bb, IRExpr* const addr_expr) +{ + Bool result = False; + + if (addr_expr->tag == Iex_RdTmp) + { + int i; + for (i = 0; i < bb->stmts_size; i++) + { + if (bb->stmts[i] + && bb->stmts[i]->tag == Ist_WrTmp + && bb->stmts[i]->Ist.WrTmp.tmp == addr_expr->Iex.RdTmp.tmp) + { + IRExpr* e = bb->stmts[i]->Ist.WrTmp.data; + if (e->tag == Iex_Get && e->Iex.Get.offset == STACK_POINTER_OFFSET) + { + result = True; + } + + //ppIRExpr(e); + //VG_(printf)(" (%s)\n", result ? "True" : "False"); + break; + } + } + } + return result; +} + static void instrument_load(IRSB* const bb, IRExpr* const addr_expr, const HWord size) @@ -863,6 +908,9 @@ static void instrument_load(IRSB* const bb, mkIRExpr_HWord(size))))); } + if (! s_drd_check_stack_accesses && is_stack_access(bb, addr_expr)) + return; + switch (size) { case 1: @@ -925,6 +973,9 @@ static void instrument_store(IRSB* const bb, mkIRExpr_HWord(size))))); } + if (! s_drd_check_stack_accesses && is_stack_access(bb, addr_expr)) + return; + switch (size) { case 1: