|
From: <sv...@va...> - 2007-01-10 13:04:57
|
Author: njn
Date: 2007-01-10 13:04:52 +0000 (Wed, 10 Jan 2007)
New Revision: 6501
Log:
Specialise some of the value-error C helpers, for common cases. This
reduces code expansion by about 5%, and speed by about 1%, judging from t=
he
perf suite.
Modified:
branches/ORIGIN_TRACKING/memcheck/mc_include.h
branches/ORIGIN_TRACKING/memcheck/mc_main.c
branches/ORIGIN_TRACKING/memcheck/mc_translate.c
branches/ORIGIN_TRACKING/memcheck/tests/origin-yes.c
Modified: branches/ORIGIN_TRACKING/memcheck/mc_include.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- branches/ORIGIN_TRACKING/memcheck/mc_include.h 2007-01-10 12:06:01 UT=
C (rev 6500)
+++ branches/ORIGIN_TRACKING/memcheck/mc_include.h 2007-01-10 13:04:52 UT=
C (rev 6501)
@@ -299,10 +299,21 @@
/*------------------------------------------------------------*/
=20
/* Functions defined in mc_main.c */
+extern VG_REGPARM(0) void MC_(helperc_value_error_0_origins_szWord) ( vo=
id );
+extern VG_REGPARM(0) void MC_(helperc_value_error_0_origins_sz0) ( vo=
id );
extern VG_REGPARM(1) void MC_(helperc_value_error_0_origins) ( HWord );
+
+extern VG_REGPARM(1) void MC_(helperc_value_error_1_origin_szWord) ( HWo=
rd );
+extern VG_REGPARM(1) void MC_(helperc_value_error_1_origin_sz0) ( HWo=
rd );
extern VG_REGPARM(2) void MC_(helperc_value_error_1_origin) ( HWord, HW=
ord );
+
+extern VG_REGPARM(2) void MC_(helperc_value_error_2_origins_szWord) ( HW=
ord,
+ HW=
ord );
+extern VG_REGPARM(2) void MC_(helperc_value_error_2_origins_sz0) ( HW=
ord,
+ HW=
ord );
extern VG_REGPARM(3) void MC_(helperc_value_error_2_origins) ( HWord, HW=
ord,
- HWord );
+ HW=
ord );
+
extern VG_REGPARM(3) void MC_(helperc_value_error_3_origins) ( HWord, HW=
ord,
HWord, HW=
ord );
extern VG_REGPARM(3) void MC_(helperc_value_error_4_origins) ( HWord, HW=
ord,
Modified: branches/ORIGIN_TRACKING/memcheck/mc_main.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- branches/ORIGIN_TRACKING/memcheck/mc_main.c 2007-01-10 12:06:01 UTC (=
rev 6500)
+++ branches/ORIGIN_TRACKING/memcheck/mc_main.c 2007-01-10 13:04:52 UTC (=
rev 6501)
@@ -4288,28 +4288,65 @@
mc_record_value_error ( VG_(get_running_tid)(), (Int)szB, origins, n_=
origins );
}
=20
-VG_REGPARM(1) void MC_(helperc_value_error_0_origins) ( HWord szB )
-{
- mc_helperc_value_error_N_origins(szB, NULL, 0);
+// Here we specialise the common cases (0, 1 and 2 origins with szB of 0=
and
+// VG_WORDSIZE) to reduce the number of args passed. Remaining cases ar=
e
+// done with the more general functions.
+
+// Zero origins
+VG_REGPARM(0) void MC_(helperc_value_error_0_origins_szWord) ( void ) {
+ mc_helperc_value_error_N_origins(VG_WORDSIZE, NULL, 0);
}
+VG_REGPARM(0) void MC_(helperc_value_error_0_origins_sz0) ( void ) {
+ mc_helperc_value_error_N_origins(0, NULL, 0);
+}
+VG_REGPARM(1) void MC_(helperc_value_error_0_origins) ( HWord szB ) {
+ mc_helperc_value_error_N_origins(szB, NULL, 0);
+}
=20
+// One origin
+VG_REGPARM(1) void MC_(helperc_value_error_1_origin_szWord) (=20
+ HWord origin_hword0 ) {
+ HWord origin_hwords[1];
+ origin_hwords[0] =3D origin_hword0;
+ mc_helperc_value_error_N_origins(VG_WORDSIZE, origin_hwords, 1);
+}
+VG_REGPARM(1) void MC_(helperc_value_error_1_origin_sz0) (=20
+ HWord origin_hword0 ) {
+ HWord origin_hwords[1];
+ origin_hwords[0] =3D origin_hword0;
+ mc_helperc_value_error_N_origins(0, origin_hwords, 1);
+}
VG_REGPARM(2) void MC_(helperc_value_error_1_origin) ( HWord szB,
- HWord origin_hword0 )
-{
+ HWord origin_hword0 ) {
HWord origin_hwords[1];
origin_hwords[0] =3D origin_hword0;
- mc_helperc_value_error_N_origins(szB, origin_hwords, 1);
+ mc_helperc_value_error_N_origins(szB, origin_hwords, 1);
}
=20
+// Two origins
+VG_REGPARM(2) void MC_(helperc_value_error_2_origins_szWord) (
+ HWord origin_hword0, HWord origin_hword1 ) {
+ HWord origin_hwords[2];
+ origin_hwords[0] =3D origin_hword0;
+ origin_hwords[1] =3D origin_hword1;
+ mc_helperc_value_error_N_origins(VG_WORDSIZE, origin_hwords, 2);
+}
+VG_REGPARM(2) void MC_(helperc_value_error_2_origins_sz0) (
+ HWord origin_hword0, HWord origin_hword1 ) {
+ HWord origin_hwords[2];
+ origin_hwords[0] =3D origin_hword0;
+ origin_hwords[1] =3D origin_hword1;
+ mc_helperc_value_error_N_origins(0, origin_hwords, 2);
+}
VG_REGPARM(3) void MC_(helperc_value_error_2_origins) ( HWord szB,
- HWord origin_hword0, HWord origin_hword1 )
-{
+ HWord origin_hword0, HWord origin_hword1 ) {
HWord origin_hwords[2];
origin_hwords[0] =3D origin_hword0;
origin_hwords[1] =3D origin_hword1;
- mc_helperc_value_error_N_origins(szB, origin_hwords, 2);
+ mc_helperc_value_error_N_origins(szB, origin_hwords, 2);
}
=20
+// More than two origins
VG_REGPARM(3) void MC_(helperc_value_error_3_origins) ( HWord szB,
HWord origin_hword0, HWord origin_hword1,
HWord origin_hword2)
@@ -4320,7 +4357,6 @@
origin_hwords[2] =3D origin_hword2;
mc_helperc_value_error_N_origins(szB, origin_hwords, 3);
}
-
VG_REGPARM(3) void MC_(helperc_value_error_4_origins) ( HWord szB,
HWord origin_hword0, HWord origin_hword1,
HWord origin_hword2, HWord origin_hword3)
@@ -4332,7 +4368,6 @@
origin_hwords[3] =3D origin_hword3;
mc_helperc_value_error_N_origins(szB, origin_hwords, 4);
}
-
VG_REGPARM(3) void MC_(helperc_value_error_5_origins) ( HWord szB,
HWord origin_hword0, HWord origin_hword1,
HWord origin_hword2, HWord origin_hword3,
@@ -4346,7 +4381,6 @@
origin_hwords[4] =3D origin_hword4;
mc_helperc_value_error_N_origins(szB, origin_hwords, 5);
}
-
VG_REGPARM(3) void MC_(helperc_value_error_6_origins) ( HWord szB,
HWord origin_hword0, HWord origin_hword1,
HWord origin_hword2, HWord origin_hword3,
Modified: branches/ORIGIN_TRACKING/memcheck/mc_translate.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- branches/ORIGIN_TRACKING/memcheck/mc_translate.c 2007-01-10 12:06:01 =
UTC (rev 6500)
+++ branches/ORIGIN_TRACKING/memcheck/mc_translate.c 2007-01-10 13:04:52 =
UTC (rev 6501)
@@ -812,6 +812,7 @@
=20
// XXX: there's an off-by-one error in percentify -- if I use 6 inste=
ad
// of 5 here, the buffers get overrun. (there's one in snprintf, too=
)
+ // [XXX: the snprintf one has been fixed, I think]
VG_(percentify)(origin_tracking_2, n_total, 1, 7, perc2);
VG_(percentify)(origin_tracking_1, n_total, 1, 7, perc1);
VG_(percentify)(origin_tracking_0, n_total, 1, 7, perc0);
@@ -896,8 +897,6 @@
// are all 8-bits.
static void getOriginTmps(MCEnv* mce, IRTemp currTemp, OriginsList* orig=
inTmps)
{
- // XXX: write a test that adds a whole lot of undefined numbers, and
- // should be able to give origins for all of them.
// XXX: write a test where two undefined chars are compared, but they=
're
// recently converted from 32-bit values and so can be identified.
OriginsList worklist_actual, *worklist =3D &worklist_actual;
@@ -1247,23 +1246,67 @@
szHWordExpr =3D mkIRExpr_HWord( sz );
=20
if (0 =3D=3D n_origins_found) {
- fn_name =3D "MC_(helperc_value_error_0_origins)";
- fn_ptr =3D &MC_(helperc_value_error_0_origins);
- regparms =3D 1;
- arg_vec =3D mkIRExprVec_1(szHWordExpr);
+ if (VG_WORDSIZE =3D=3D sz) {
+ // Specialise the word-sized case
+ fn_name =3D "MC_(helperc_value_error_0_origins_szWord)";
+ fn_ptr =3D &MC_(helperc_value_error_0_origins_szWord);
+ regparms =3D 0;
+ arg_vec =3D mkIRExprVec_0();
+ } else if (0 =3D=3D sz) {
+ // Specialise the cond case
+ fn_name =3D "MC_(helperc_value_error_0_origins_sz0)";
+ fn_ptr =3D &MC_(helperc_value_error_0_origins_sz0);
+ regparms =3D 0;
+ arg_vec =3D mkIRExprVec_0();
+ } else {
+ fn_name =3D "MC_(helperc_value_error_0_origins)";
+ fn_ptr =3D &MC_(helperc_value_error_0_origins);
+ regparms =3D 1;
+ arg_vec =3D mkIRExprVec_1(szHWordExpr);
+ }
=20
} else if (1 =3D=3D n_origins_found) {
- fn_name =3D "MC_(helperc_value_error_1_origin)";
- fn_ptr =3D &MC_(helperc_value_error_1_origin);
- regparms =3D 2;
- arg_vec =3D mkIRExprVec_2(szHWordExpr, mkexpr(originTmps.tmps[0])=
);
+ if (VG_WORDSIZE =3D=3D sz) {
+ // Specialise the word-sized case
+ fn_name =3D "MC_(helperc_value_error_1_origin_szWord)";
+ fn_ptr =3D &MC_(helperc_value_error_1_origin_szWord);
+ regparms =3D 1;
+ arg_vec =3D mkIRExprVec_1(mkexpr(originTmps.tmps[0]));
+ } else if (0 =3D=3D sz) {
+ // Specialise the cond case
+ fn_name =3D "MC_(helperc_value_error_1_origin_sz0)";
+ fn_ptr =3D &MC_(helperc_value_error_1_origin_sz0);
+ regparms =3D 1;
+ arg_vec =3D mkIRExprVec_1(mkexpr(originTmps.tmps[0]));
+ } else {
+ fn_name =3D "MC_(helperc_value_error_1_origin)";
+ fn_ptr =3D &MC_(helperc_value_error_1_origin);
+ regparms =3D 2;
+ arg_vec =3D mkIRExprVec_2(szHWordExpr, mkexpr(originTmps.tmps[=
0]));
+ }
=20
} else if (2 =3D=3D n_origins_found) {
- fn_name =3D "MC_(helperc_value_error_2_origins)";
- fn_ptr =3D &MC_(helperc_value_error_2_origins);
- regparms =3D 3;
- arg_vec =3D mkIRExprVec_3(szHWordExpr, mkexpr(originTmps.tmps[0])=
,
- mkexpr(originTmps.tmps[1]));
+ if (VG_WORDSIZE =3D=3D sz) {
+ // Specialise the word-sized case
+ fn_name =3D "MC_(helperc_value_error_2_origins_szWord)";
+ fn_ptr =3D &MC_(helperc_value_error_2_origins_szWord);
+ regparms =3D 2;
+ arg_vec =3D mkIRExprVec_2(mkexpr(originTmps.tmps[0]),
+ mkexpr(originTmps.tmps[1]));
+ } else if (0 =3D=3D sz) {
+ // Specialise the cond case
+ fn_name =3D "MC_(helperc_value_error_2_origins_sz0)";
+ fn_ptr =3D &MC_(helperc_value_error_2_origins_sz0);
+ regparms =3D 2;
+ arg_vec =3D mkIRExprVec_2(mkexpr(originTmps.tmps[0]),
+ mkexpr(originTmps.tmps[1]));
+ } else {
+ fn_name =3D "MC_(helperc_value_error_2_origins)";
+ fn_ptr =3D &MC_(helperc_value_error_2_origins);
+ regparms =3D 3;
+ arg_vec =3D mkIRExprVec_3(szHWordExpr, mkexpr(originTmps.tmps[=
0]),
+ mkexpr(originTmps.tmps[1]=
));
+ }
} else if (3 =3D=3D n_origins_found) {
fn_name =3D "MC_(helperc_value_error_3_origins)";
fn_ptr =3D &MC_(helperc_value_error_3_origins);
Modified: branches/ORIGIN_TRACKING/memcheck/tests/origin-yes.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- branches/ORIGIN_TRACKING/memcheck/tests/origin-yes.c 2007-01-10 12:06=
:01 UTC (rev 6500)
+++ branches/ORIGIN_TRACKING/memcheck/tests/origin-yes.c 2007-01-10 13:04=
:52 UTC (rev 6501)
@@ -17,6 +17,8 @@
=20
int main(void)
{
+ assert(1 =3D=3D sizeof(char));
+ assert(2 =3D=3D sizeof(short));
assert(4 =3D=3D sizeof(int));
assert(8 =3D=3D sizeof(long long));
=20
@@ -30,6 +32,29 @@
x +=3D (undef_stack_int =3D=3D 0x12345678 ? 10 : 21);
}
=20
+ // Stack, 32-bit, recently modified
+ // XXX: this should work, as the unmodified version should be visible
+ // within the IRSB. Same for the next two cases -- what's going wron=
g?
+ {
+ int modified_undef_stack_int;
+ modified_undef_stack_int++;
+ x +=3D (modified_undef_stack_int =3D=3D 0x1234 ? 11 : 22);
+ }
+ =20
+ // Stack, 16-bit from (recently) 32-bit
+ {
+ int undef_stack_int;
+ short undef_stack_short =3D (short)undef_stack_int;
+ x +=3D (undef_stack_short =3D=3D 0x1234 ? 11 : 22);
+ }
+ =20
+ // Stack, 8-bit from (recently) 32-bit
+ {
+ int undef_stack_int;
+ char undef_stack_char =3D (char)undef_stack_int;
+ x +=3D (undef_stack_char =3D=3D 0x12 ? 11 : 22);
+ }
+ =20
// Stack, 64-bit
{
long long undef_stack_longlong;
|