The ABI does not require a TM runtime library to immediately start a transaction in irrevocable mode if the beginTransaction flag "doesGoIrrevocable" is set. This patch fixes this by inserting a call to changeTransactionMode(0) into the entry block of all transactions that always go irrevocable eventually. Once we generate uninstrumented code paths too, we can optimize this by telling the runtime that it is probably preferable to use uninstrumented code right away. The instrumented path, if we generate it, should then go irrevocable as late as possible, so that there is actually a choice that the TM runtime can make (e.g., if we go irrevocable close to the end of a long transaction, then being irrevocable for a shorter time can increase overall performance).
OK for branch?
commit 64e5f9da61ea7f45748b411aa58404628040c343 Author: Torvald Riegel <trie...@redhat.com> Date: Fri Oct 28 10:55:38 2011 +0200 Explicitly go irrevocable even if transaction will always go irrevocable. * trans-mem.c (ipa_tm_transform_transaction): Insert explicit request to go irrevocable even if transaction will always go irrevocable. * testsuite/gcc.dg/tm/irrevocable-8.c: New file. * testsuite/gcc.dg/tm/memopt-1.c: Re-focus this test on tmmemopt. --- a/gcc/ChangeLog.tm +++ b/gcc/ChangeLog.tm @@ -1,5 +1,12 @@ 2011-10-27 Torvald Riegel <trie...@redhat.com> + * trans-mem.c (ipa_tm_transform_transaction): Insert explicit request + to go irrevocable even if transaction will always go irrevocable. + * testsuite/gcc.dg/tm/irrevocable-8.c: New file. + * testsuite/gcc.dg/tm/memopt-1.c: Re-focus this test on tmmemopt. + +2011-10-27 Torvald Riegel <trie...@redhat.com> + * trans-mem.c (struct tm_region): Extended comment. (tm_region_init): Fix tm_region association of blocks with the "over" label used for transcation abort. diff --git a/gcc/testsuite/gcc.dg/tm/irrevocable-8.c b/gcc/testsuite/gcc.dg/tm/irrevocable-8.c new file mode 100644 index 0000000..1fe6c0a --- /dev/null +++ b/gcc/testsuite/gcc.dg/tm/irrevocable-8.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-fgnu-tm -fdump-ipa-tmipa" } */ + +void unsafe(void) __attribute__((transaction_unsafe)); + +void +f(void) +{ + __transaction_relaxed { + unsafe(); + } +} + +/* { dg-final { scan-ipa-dump-times "changeTransactionMode \\(0\\)" 1 "tmipa" } } */ +/* { dg-final { cleanup-ipa-dump "tmipa" } } */ diff --git a/gcc/testsuite/gcc.dg/tm/memopt-1.c b/gcc/testsuite/gcc.dg/tm/memopt-1.c index 06d4f64..9a48dcb 100644 --- a/gcc/testsuite/gcc.dg/tm/memopt-1.c +++ b/gcc/testsuite/gcc.dg/tm/memopt-1.c @@ -2,8 +2,8 @@ /* { dg-options "-fgnu-tm -O -fdump-tree-tmmemopt" } */ long g, xxx, yyy; -extern george() __attribute__((transaction_callable)); -extern ringo(long int); +extern george() __attribute__((transaction_safe)); +extern ringo(long int) __attribute__((transaction_safe)); int i; f() diff --git a/gcc/trans-mem.c b/gcc/trans-mem.c index e88c7ad..994cf09 100644 --- a/gcc/trans-mem.c +++ b/gcc/trans-mem.c @@ -4521,6 +4521,14 @@ ipa_tm_transform_transaction (struct cgraph_node *node) { transaction_subcode_ior (region, GTMA_DOES_GO_IRREVOCABLE); transaction_subcode_ior (region, GTMA_MAY_ENTER_IRREVOCABLE); + /* ??? We still have to insert a call to explicitly request + to go irrevocable because the ABI does not require the runtime + to immediately go irrevocable. Once we generate an + uninstrumented code path for transactions, we can avoid this + extra call and only make uninstrumented code available, which + tells the runtime that it must go irrevocable immediately. */ + ipa_tm_insert_irr_call (node, region, region->entry_block); + need_ssa_rename = true; continue; }