[Mesa-dev] [PATCH 1/2] mesa: Detect and provide macros for function attributes pure and const.

Vinson Lee vlee at freedesktop.org
Mon Jul 20 20:37:59 PDT 2015


On Tue, Jul 14, 2015 at 11:45 AM, Eric Anholt <eric at anholt.net> wrote:
> These are really useful hints to the compiler in the absence of link-time
> optimization, and I'm going to use them in VC4.
>
> I've made the const attribute be ATTRIBUTE_CONST unlike other function
> attributes, because we have other things in the tree #defining CONST for
> their own unrelated purposes.
> ---
>  configure.ac      |  2 ++
>  src/util/macros.h | 20 ++++++++++++++++++++
>  2 files changed, 22 insertions(+)
>
> diff --git a/configure.ac b/configure.ac
> index bdfd134..38ad398 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -210,6 +210,8 @@ AX_GCC_FUNC_ATTRIBUTE([format])
>  AX_GCC_FUNC_ATTRIBUTE([malloc])
>  AX_GCC_FUNC_ATTRIBUTE([packed])
>  AX_GCC_FUNC_ATTRIBUTE([unused])
> +AX_GCC_FUNC_ATTRIBUTE([const])
> +AX_GCC_FUNC_ATTRIBUTE([pure])
>  AX_GCC_FUNC_ATTRIBUTE([warn_unused_result])
>
>  AM_CONDITIONAL([GEN_ASM_OFFSETS], test "x$GEN_ASM_OFFSETS" = xyes)
> diff --git a/src/util/macros.h b/src/util/macros.h
> index 66698e7..4d16183 100644
> --- a/src/util/macros.h
> +++ b/src/util/macros.h
> @@ -130,6 +130,26 @@ do {                       \
>  #define PACKED
>  #endif
>
> +/* Attribute pure is used for functions that have no effects other than their
> + * return value.  As a result, calls to it can be dead code eliminated.
> + */
> +#ifdef HAVE_FUNC_ATTRIBUTE_PURE
> +#define PURE __attribute__((__pure__))
> +#else
> +#define PURE
> +#endif
> +
> +/* Attribute const is used for functions that have no effects other than their
> + * return value, and only rely on the argument values to compute the return
> + * value.  As a result, calls to it can be CSEed.  Note that using memory
> + * pointed to by the arguments is not allowed for const functions.
> + */
> +#ifdef HAVE_FUNC_ATTRIBUTE_CONST
> +#define ATTRIBUTE_CONST __attribute__((__const__))
> +#else
> +#define ATTRIBUTE_CONST
> +#endif
> +
>  #ifdef __cplusplus
>  /**
>   * Macro function that evaluates to true if T is a trivially
> --
> 2.1.4
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev


This patch introduced new compiler warnings.

indirect_size.h:42:0: warning: "PURE" redefined
 #define PURE __attribute__((pure))
 ^
In file included from glxclient.h:55:0,
                 from indirect.h:52,
                 from indirect.c:30:
../../src/util/macros.h:148:0: note: this is the location of the
previous definition
 #define PURE __attribute__((__pure__))
 ^


More information about the mesa-dev mailing list