Gabe Black has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/45230 )

Change subject: base: Move the macros in compiler.hh to a GEM5_ prefix.
......................................................................

base: Move the macros in compiler.hh to a GEM5_ prefix.

Also add macros which define the old names to the new names for
backwards compatibility.

This change also takes the opportunity to rename the M5_ATTR_PACKED
macro to GEM5_PACKED, dropping the ATTR. None of the other attribute
based macros bother to specify that they stand for an attribute, making
this one inconsistent and overly verbose.

Similarly, it renames M5_NODISCARD to GEM5_NO_DISCARD to be consistent
with other macros which separate out individual words like GEM5_VAR_USED
and GEM5_NO_INLINE

Change-Id: I22d404492faf28b79a8247f869f14af21c9cf967
---
M src/base/compiler.hh
1 file changed, 41 insertions(+), 25 deletions(-)



diff --git a/src/base/compiler.hh b/src/base/compiler.hh
index 97dec94..4ea0dbb 100644
--- a/src/base/compiler.hh
+++ b/src/base/compiler.hh
@@ -50,32 +50,32 @@
  * Attributes that become standard in later versions of c++.
  */

-// Use M5_FALLTHROUGH to mark when you're intentionally falling through from +// Use GEM5_FALLTHROUGH to mark when you're intentionally falling through from
 // one case to another in a switch statement.
 #if __has_cpp_attribute(fallthrough) // Standard in c++17.
-#  define M5_FALLTHROUGH [[fallthrough]]
+#  define GEM5_FALLTHROUGH [[fallthrough]]
 #else
 // Not supported, so it's not necessary to avoid warnings.
-#  define M5_FALLTHROUGH
+#  define GEM5_FALLTHROUGH
 #endif

// When the return value of a function should not be discarded, mark it with
-// M5_NODISCARD.
+// GEM5_NO_DISCARD.
#if __has_cpp_attribute(nodiscard) // Standard in c++17, with message in c++20.
-#  define M5_NODISCARD [[nodiscard]]
+#  define GEM5_NO_DISCARD [[nodiscard]]
 #else
 // Not supported, but it's optional so we can just omit it.
-#  define M5_NODISCARD
+#  define GEM5_NO_DISCARD
 #endif

// When a variable may purposefully not be used, for instance if it's only used
-// in debug statements which might be disabled, mark it with M5_VAR_USED.
+// in debug statements which might be disabled, mark it with GEM5_VAR_USED.
 #if __has_cpp_attribute(maybe_unused) // Standard in c++17.
-#  define M5_VAR_USED [[maybe_unused]]
+#  define GEM5_VAR_USED [[maybe_unused]]
 #elif defined(__GNUC__)
 // gcc and clang support a custom attribute which is essentially the same
 // thing.
-#  define M5_VAR_USED [[gnu::unused]]
+#  define GEM5_VAR_USED [[gnu::unused]]
 #else
 #  error "Don't know what to do for your compiler."
 #endif
@@ -89,29 +89,29 @@
// Mark a structure as packed, so that no padding is added to its layout. This // padding might be added to, for instance, ensure certain fields have certain
 // alignment.
-#  define M5_ATTR_PACKED [[gnu::packed]]
+#  define GEM5_PACKED [[gnu::packed]]

 // Prevent a function from being inlined.
-#  define M5_NO_INLINE [[gnu::noinline]]
+#  define GEM5_NO_INLINE [[gnu::noinline]]

 // Set the visibility of a symbol.
-#  define M5_PUBLIC [[gnu:visibility("default")]]
-#  define M5_LOCAL [[gnu::visibility("hidden")]]
-#  define M5_WEAK [[gnu::weak]]
+#  define GEM5_PUBLIC [[gnu:visibility("default")]]
+#  define GEM5_LOCAL [[gnu::visibility("hidden")]]
+#  define GEM5_WEAK [[gnu::weak]]

 // Force an alignment for a variable.
-#  define M5_ALIGNED(alignment) [[gnu::aligned(alignment)]]
+#  define GEM5_ALIGNED(alignment) [[gnu::aligned(alignment)]]

 // Marker for what should be an unreachable point in the code.
-#  define M5_UNREACHABLE __builtin_unreachable()
+#  define GEM5_UNREACHABLE __builtin_unreachable()

 // To mark a branch condition as likely taken, wrap it's condition with
-// M5_LIKELY. To mark it as likely not taken, wrap it's condition with
-// M5_UNLIKELY. These can be replaced with the standard attributes [[likely]]
+// GEM5_LIKELY. To mark it as likely not taken, wrap it's condition with
+// GEM5_UNLIKELY. These can be replaced with the standard attributes [[likely]]
 // and [[unlikely]] in c++20, although the syntax is different enough that
 // we can't do that with direct substitution.
-#  define M5_LIKELY(cond) __builtin_expect(!!(cond), 1)
-#  define M5_UNLIKELY(cond) __builtin_expect(!!(cond), 0)
+#  define GEM5_LIKELY(cond) __builtin_expect(!!(cond), 1)
+#  define GEM5_UNLIKELY(cond) __builtin_expect(!!(cond), 0)

// Mark a c++ declaration as deprecated, with a message explaining what to do
 // to update to a non-deprecated alternative.
@@ -134,21 +134,37 @@
// the elements of a brace inclosed initializer list are evaluated in order,
 // as are the arguments to the comma operator, which evaluates to the last
 // value. This is compiler specific because it uses variadic macros.
-#define M5_FOR_EACH_IN_PACK(...) \
-do { M5_VAR_USED int i[] = { 0, ((void)(__VA_ARGS__), 0)... }; } while (false)
+#define GEM5_FOR_EACH_IN_PACK(...) \
+do { GEM5_VAR_USED int i[] = { 0, ((void)(__VA_ARGS__), 0)... }; } while (0)

 #else
 #  error "Don't know what to do for your compiler."
 #endif

-// When a member variable may be unused, mark it with M5_CLASS_VAR_USED. This +// When a member variable may be unused, mark it with GEM5_CLASS_VAR_USED. This
 // needs to be limitted to clang only since clang warns on these unused
 // variables, and g++ will actually warn if you use this attribute since it
 // won't do anything there.
 #if defined(__clang__) // clang only.
-#  define M5_CLASS_VAR_USED M5_VAR_USED
+#  define GEM5_CLASS_VAR_USED GEM5_VAR_USED
 #else
-#  define M5_CLASS_VAR_USED
+#  define GEM5_CLASS_VAR_USED
 #endif

+// Aliases for macros using the deprecated M5 prefix.
+#define M5_VAR_USED GEM5_VAR_USED
+#define M5_NODISCARD GEM5_NO_DISCARD
+#define M5_FALLTHROUGH GEM5_FALLTHROUGH
+#define M5_ATTR_PACKED GEM5_PACKED
+#define M5_NO_INLINE GEM5_NO_INLINE
+#define M5_PUBLIC GEM5_PUBLIC
+#define M5_LOCAL GEM5_LOCAL
+#define M5_WEAK GEM5_WEAK
+#define M5_ALIGNED(x) GEM5_ALIGNED(x)
+#define M5_UNREACHABLE GEM5_UNREACHABLE
+#define M5_LIKELY(x) GEM5_LIKELY(x)
+#define M5_UNLIKELY(x) GEM5_UNLIKELY(x)
+#define M5_FOR_EACH_IN_PACK(...) GEM5_FOR_EACH_IN_PACK(__VA_ARGS__)
+#define M5_CLASS_VAR_USED GEM5_CLASS_VAR_USED
+
 #endif // __BASE_COMPILER_HH__

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/45230
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I22d404492faf28b79a8247f869f14af21c9cf967
Gerrit-Change-Number: 45230
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <gabe.bl...@gmail.com>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to