memmodel.h 3.4 KB

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