GCC Middle and Back End API Reference
memmodel.h
Go to the documentation of this file.
1/* Prototypes of memory model helper functions.
2 Copyright (C) 2011-2024 Free Software Foundation, Inc.
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
8Software Foundation; either version 3, or (at your option) any later
9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14for more details.
15
16You should have received a copy of the GNU General Public License
17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
19
20#ifndef GCC_MEMMODEL_H
21#define GCC_MEMMODEL_H
22
23/* Suppose that higher bits are target dependent. */
24#define MEMMODEL_MASK ((1<<16)-1)
25
26/* Legacy sync operations set this upper flag in the memory model. This allows
27 targets that need to do something stronger for sync operations to
28 differentiate with their target patterns and issue a more appropriate insn
29 sequence. See bugzilla 65697 for background. */
30#define MEMMODEL_SYNC (1<<15)
31
32/* Memory model without SYNC bit for targets/operations that do not care. */
33#define MEMMODEL_BASE_MASK (MEMMODEL_SYNC-1)
34
35/* Memory model types for the __atomic* builtins.
36 This must match the order in libstdc++-v3/include/bits/atomic_base.h. */
52
53/* Return the memory model from a host integer. */
54inline enum memmodel
55memmodel_from_int (unsigned HOST_WIDE_INT val)
56{
57 return (enum memmodel) (val & MEMMODEL_MASK);
58}
59
60/* Return the base memory model from a host integer. */
61inline enum memmodel
62memmodel_base (unsigned HOST_WIDE_INT val)
63{
64 return (enum memmodel) (val & MEMMODEL_BASE_MASK);
65}
66
67/* Return TRUE if the memory model is RELAXED. */
68inline bool
70{
71 return (model & MEMMODEL_BASE_MASK) == MEMMODEL_RELAXED;
72}
73
74/* Return TRUE if the memory model is CONSUME. */
75inline bool
77{
78 return (model & MEMMODEL_BASE_MASK) == MEMMODEL_CONSUME;
79}
80
81/* Return TRUE if the memory model is ACQUIRE. */
82inline bool
84{
85 return (model & MEMMODEL_BASE_MASK) == MEMMODEL_ACQUIRE;
86}
87
88/* Return TRUE if the memory model is RELEASE. */
89inline bool
91{
92 return (model & MEMMODEL_BASE_MASK) == MEMMODEL_RELEASE;
93}
94
95/* Return TRUE if the memory model is ACQ_REL. */
96inline bool
98{
99 return (model & MEMMODEL_BASE_MASK) == MEMMODEL_ACQ_REL;
100}
101
102/* Return TRUE if the memory model is SEQ_CST. */
103inline bool
105{
106 return (model & MEMMODEL_BASE_MASK) == MEMMODEL_SEQ_CST;
107}
108
109/* Return TRUE if the memory model is a SYNC variant. */
110inline bool
112{
113 return (model & MEMMODEL_SYNC);
114}
115
116#endif /* GCC_MEMMODEL_H */
enum memmodel memmodel_from_int(unsigned HOST_WIDE_INT val)
Definition memmodel.h:55
bool is_mm_sync(enum memmodel model)
Definition memmodel.h:111
memmodel
Definition memmodel.h:38
@ MEMMODEL_ACQUIRE
Definition memmodel.h:41
@ MEMMODEL_SYNC_RELEASE
Definition memmodel.h:47
@ MEMMODEL_MAX
Definition memmodel.h:50
@ MEMMODEL_ACQ_REL
Definition memmodel.h:43
@ MEMMODEL_CONSUME
Definition memmodel.h:40
@ MEMMODEL_SYNC_SEQ_CST
Definition memmodel.h:48
@ MEMMODEL_RELAXED
Definition memmodel.h:39
@ MEMMODEL_SEQ_CST
Definition memmodel.h:44
@ MEMMODEL_RELEASE
Definition memmodel.h:42
@ MEMMODEL_SYNC_ACQUIRE
Definition memmodel.h:46
@ MEMMODEL_LAST
Definition memmodel.h:45
bool is_mm_release(enum memmodel model)
Definition memmodel.h:90
bool is_mm_acq_rel(enum memmodel model)
Definition memmodel.h:97
#define MEMMODEL_BASE_MASK
Definition memmodel.h:33
bool is_mm_seq_cst(enum memmodel model)
Definition memmodel.h:104
bool is_mm_relaxed(enum memmodel model)
Definition memmodel.h:69
bool is_mm_acquire(enum memmodel model)
Definition memmodel.h:83
#define MEMMODEL_SYNC
Definition memmodel.h:30
enum memmodel memmodel_base(unsigned HOST_WIDE_INT val)
Definition memmodel.h:62
#define MEMMODEL_MASK
Definition memmodel.h:24
bool is_mm_consume(enum memmodel model)
Definition memmodel.h:76
#define INTTYPE_MAXIMUM(t)
Definition system.h:333