]> git.ipfire.org Git - thirdparty/gcc.git/blame - libitm/local.cc
gcc/testsuite/
[thirdparty/gcc.git] / libitm / local.cc
CommitLineData
fbd26352 1/* Copyright (C) 2008-2019 Free Software Foundation, Inc.
4c0315d0 2 Contributed by Richard Henderson <rth@redhat.com>.
3
4 This file is part of the GNU Transactional Memory Library (libitm).
5
6 Libitm is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 Libitm is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 more details.
15
16 Under Section 7 of GPL version 3, you are granted additional
17 permissions described in the GCC Runtime Library Exception, version
18 3.1, as published by the Free Software Foundation.
19
20 You should have received a copy of the GNU General Public License and
21 a copy of the GCC Runtime Library Exception along with this program;
22 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 <http://www.gnu.org/licenses/>. */
24
25#include "libitm_i.h"
26
27namespace GTM HIDDEN {
28
16cd8302 29// This function needs to be noinline because we need to prevent that it gets
30// inlined into another function that calls further functions. This could
31// break our assumption that we only call memcpy and thus only need to
32// additionally protect the memcpy stack (see the hack in mask_stack_bottom()).
33// Even if that isn't an issue because those other calls don't happen during
34// copying, we still need mask_stack_bottom() to be called "close" to the
35// memcpy in terms of stack frames, so just ensure that for now using the
36// noinline.
37void __attribute__((noinline))
38gtm_undolog::rollback (gtm_thread* tx, size_t until_size)
4c0315d0 39{
40 size_t i, n = undolog.size();
16cd8302 41 void *top = mask_stack_top(tx);
42 void *bot = mask_stack_bottom(tx);
4c0315d0 43
44 if (n > 0)
45 {
46 for (i = n; i-- > until_size; )
47 {
df4a1bb5 48 void *ptr = (void *) undolog[i--];
49 size_t len = undolog[i];
50 size_t words = (len + sizeof(gtm_word) - 1) / sizeof(gtm_word);
51 i -= words;
16cd8302 52 // Filter out any updates that overlap the libitm stack. We don't
53 // bother filtering out just the overlapping bytes because we don't
54 // merge writes and thus any overlapping write is either bogus or
55 // would restore data on stack frames that are not in use anymore.
56 // FIXME The memcpy can/will end up as another call but we
57 // calculated BOT based on the current function. Can we inline or
58 // reimplement this without too much trouble due to unaligned calls
59 // and still have good performance, so that we can remove the hack
60 // in mask_stack_bottom()?
61 if (likely(ptr > top || (uint8_t*)ptr + len <= bot))
62 __builtin_memcpy (ptr, &undolog[i], len);
4c0315d0 63 }
9b4e4856 64 undolog.set_size(until_size);
4c0315d0 65 }
66}
67
68void ITM_REGPARM
69GTM_LB (const void *ptr, size_t len)
70{
71 gtm_thread *tx = gtm_thr();
df4a1bb5 72 tx->undolog.log(ptr, len);
4c0315d0 73}
74
75} // namespace GTM
76
77using namespace GTM;
78
275b7639 79/* ??? Use configure to determine if aliases are supported. Or convince
80 the compiler to not just tail call this, but actually generate the
81 same_body_alias itself. */
82void ITM_REGPARM
83_ITM_LB (const void *ptr, size_t len)
84{
85 GTM_LB (ptr, len);
86}
4c0315d0 87
88#define ITM_LOG_DEF(T) \
89void ITM_REGPARM _ITM_L##T (const _ITM_TYPE_##T *ptr) \
90{ GTM_LB (ptr, sizeof (*ptr)); }
91
92ITM_LOG_DEF(U1)
93ITM_LOG_DEF(U2)
94ITM_LOG_DEF(U4)
95ITM_LOG_DEF(U8)
96ITM_LOG_DEF(F)
97ITM_LOG_DEF(D)
98ITM_LOG_DEF(E)
99ITM_LOG_DEF(CF)
100ITM_LOG_DEF(CD)
101ITM_LOG_DEF(CE)