From patchwork Mon Jan 31 18:20:08 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [trans-mem] handle memset (PR/47492) Date: Mon, 31 Jan 2011 08:20:08 -0000 From: Aldy Hernandez X-Patchwork-Id: 81201 Message-Id: <4D46FD58.5050207@redhat.com> To: gcc-patches , Richard Henderson Cc: MARLIER Patrick Transform memset into its transactional equivalent. Thanks to Patrick for doing all the dirty work on this patch. OK for branch? PR/47492 * tree-ssa-alias.c (ref_maybe_used_by_call_p_1): Handle BUILT_IN_TM_MEMSET. * trans-mem.c (find_tm_replacement_function): Same. * calls.c (special_function_p): Same. * tree-ssa-structalias.c: Same. * gtm-builtins.def: Add BUILT_IN_TM_MEMSET. Index: testsuite/gcc.dg/tm/memset.c =================================================================== --- testsuite/gcc.dg/tm/memset.c (revision 0) +++ testsuite/gcc.dg/tm/memset.c (revision 0) @@ -0,0 +1,24 @@ +/* { dg-do compile } */ +/* { dg-options "-fgnu-tm" } */ + +extern void *memset (void *, int, __SIZE_TYPE__); + +char array[4] = "aaaa"; + +__attribute__((transaction_safe)) +void *my_memset() +{ + return memset(array,'b',4); +} + + +int main() +{ + + __transaction [[atomic]] { + my_memset(); + } + return 0; +} + +/* { dg-final { scan-assembler "_ITM_memsetW" } } */ Index: tree-ssa-alias.c =================================================================== --- tree-ssa-alias.c (revision 169292) +++ tree-ssa-alias.c (working copy) @@ -1057,6 +1057,7 @@ ref_maybe_used_by_call_p_1 (gimple call, case BUILT_IN_MALLOC: case BUILT_IN_CALLOC: case BUILT_IN_MEMSET: + case BUILT_IN_TM_MEMSET: case BUILT_IN_FREXP: case BUILT_IN_FREXPF: case BUILT_IN_FREXPL: @@ -1234,6 +1235,7 @@ call_may_clobber_ref_p_1 (gimple call, a case BUILT_IN_STRCAT: case BUILT_IN_STRNCAT: case BUILT_IN_MEMSET: + case BUILT_IN_TM_MEMSET: CASE_BUILT_IN_TM_STORE (1): CASE_BUILT_IN_TM_STORE (2): CASE_BUILT_IN_TM_STORE (4): Index: trans-mem.c =================================================================== --- trans-mem.c (revision 169442) +++ trans-mem.c (working copy) @@ -485,6 +485,8 @@ find_tm_replacement_function (tree fndec return built_in_decls[BUILT_IN_TM_MEMCPY]; case BUILT_IN_MEMMOVE: return built_in_decls[BUILT_IN_TM_MEMMOVE]; + case BUILT_IN_MEMSET: + return built_in_decls[BUILT_IN_TM_MEMSET]; default: return NULL; } Index: calls.c =================================================================== --- calls.c (revision 169292) +++ calls.c (working copy) @@ -480,6 +480,7 @@ special_function_p (const_tree fndecl, i case BUILT_IN_TM_GETTMCLONE_IRR: case BUILT_IN_TM_MEMCPY: case BUILT_IN_TM_MEMMOVE: + case BUILT_IN_TM_MEMSET: CASE_BUILT_IN_TM_STORE (1): CASE_BUILT_IN_TM_STORE (2): CASE_BUILT_IN_TM_STORE (4): Index: gtm-builtins.def =================================================================== --- gtm-builtins.def (revision 169292) +++ gtm-builtins.def (working copy) @@ -14,6 +14,8 @@ DEF_TM_BUILTIN (BUILT_IN_TM_MEMCPY, "_IT BT_FN_PTR_PTR_CONST_PTR_SIZE, ATTR_TM_TMPURE_NOTHROW_LIST) DEF_TM_BUILTIN (BUILT_IN_TM_MEMMOVE, "_ITM_memmoveRtWt", BT_FN_PTR_PTR_CONST_PTR_SIZE, ATTR_TM_TMPURE_NOTHROW_LIST) +DEF_TM_BUILTIN (BUILT_IN_TM_MEMSET, "_ITM_memsetW", + BT_FN_PTR_PTR_INT_SIZE, ATTR_TM_TMPURE_NOTHROW_LIST) DEF_TM_BUILTIN (BUILT_IN_TM_GETTMCLONE_IRR, "_ITM_getTMCloneOrIrrevocable", BT_FN_PTR_PTR, ATTR_TM_CONST_NOTHROW_LIST) Index: tree-ssa-structalias.c =================================================================== --- tree-ssa-structalias.c (revision 169292) +++ tree-ssa-structalias.c (working copy) @@ -3720,6 +3720,7 @@ find_func_aliases (gimple t) return; } case BUILT_IN_MEMSET: + case BUILT_IN_TM_MEMSET: { tree res = gimple_call_lhs (t); tree dest = gimple_call_arg (t, 0);