Daily bump.
[official-gcc.git] / libitm / local.cc
blobd87cd1505f7f635dec11cae72edf64ffac2db24a
1 /* Copyright (C) 2008-2017 Free Software Foundation, Inc.
2 Contributed by Richard Henderson <rth@redhat.com>.
4 This file is part of the GNU Transactional Memory Library (libitm).
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.
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.
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.
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/>. */
25 #include "libitm_i.h"
27 namespace GTM HIDDEN {
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.
37 void __attribute__((noinline))
38 gtm_undolog::rollback (gtm_thread* tx, size_t until_size)
40 size_t i, n = undolog.size();
41 void *top = mask_stack_top(tx);
42 void *bot = mask_stack_bottom(tx);
44 if (n > 0)
46 for (i = n; i-- > until_size; )
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;
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);
64 undolog.set_size(until_size);
68 void ITM_REGPARM
69 GTM_LB (const void *ptr, size_t len)
71 gtm_thread *tx = gtm_thr();
72 tx->undolog.log(ptr, len);
75 } // namespace GTM
77 using namespace GTM;
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. */
82 void ITM_REGPARM
83 _ITM_LB (const void *ptr, size_t len)
85 GTM_LB (ptr, len);
88 #define ITM_LOG_DEF(T) \
89 void ITM_REGPARM _ITM_L##T (const _ITM_TYPE_##T *ptr) \
90 { GTM_LB (ptr, sizeof (*ptr)); }
92 ITM_LOG_DEF(U1)
93 ITM_LOG_DEF(U2)
94 ITM_LOG_DEF(U4)
95 ITM_LOG_DEF(U8)
96 ITM_LOG_DEF(F)
97 ITM_LOG_DEF(D)
98 ITM_LOG_DEF(E)
99 ITM_LOG_DEF(CF)
100 ITM_LOG_DEF(CD)
101 ITM_LOG_DEF(CE)