* replace do-while macros with static inline functions
@ 2013-12-11 15:03 Prathamesh Kulkarni
2013-12-13 19:42 ` Trevor Saunders
[not found] ` <CAD_=9DRy95wpMmLAhrMr8EQ55qcWDzGouhHMckSR2SJMYRemDQ@mail.gmail.com>
0 siblings, 2 replies; 5+ messages in thread
From: Prathamesh Kulkarni @ 2013-12-11 15:03 UTC (permalink / raw)
To: gcc
I was wondering if it was a good idea to replace do-while macros with
static inline functions returning void, where appropriate ?
By "where appropriate" I mean:
a) call to macro contains no side-effects
b) macro does not modify the arguments.
c) macro does not use any preprocessor operators (like ##)
d) macro does not get undefined or is conditionally defined.
e) macro is not type independent (use inline template for these?)
f) Any other case ?
Example:
Consider C_EXPR_APPEND macro defined in c-tree.h:
/* Append a new c_expr_t element to V. */
#define C_EXPR_APPEND(V, ELEM) \
do { \
c_expr_t __elem = (ELEM); \
vec_safe_push (V, __elem); \
} while (0)
It is called at two places in c-parser.c:
0 c-parser.c <global> 6140 C_EXPR_APPEND (cexpr_list, expr);
1 c-parser.c <global> 6145 C_EXPR_APPEND (cexpr_list, expr);
Shall be replaced by:
static inline void
C_EXPR_APPEND( vec<c_expr_t, va_gc> * V, c_expr_t ELEM)
{
vec_safe_push(V, ELEM);
}
I will volunteer to do it, if it's accepted.
Thanks and Regards,
Prathamesh
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: replace do-while macros with static inline functions
2013-12-11 15:03 replace do-while macros with static inline functions Prathamesh Kulkarni
@ 2013-12-13 19:42 ` Trevor Saunders
2013-12-13 20:47 ` Ondřej Bílka
[not found] ` <CAD_=9DRy95wpMmLAhrMr8EQ55qcWDzGouhHMckSR2SJMYRemDQ@mail.gmail.com>
1 sibling, 1 reply; 5+ messages in thread
From: Trevor Saunders @ 2013-12-13 19:42 UTC (permalink / raw)
To: gcc
On Wed, Dec 11, 2013 at 08:33:03PM +0530, Prathamesh Kulkarni wrote:
> I was wondering if it was a good idea to replace do-while macros with
> static inline functions returning void, where appropriate ?
> By "where appropriate" I mean:
> a) call to macro contains no side-effects
> b) macro does not modify the arguments.
> c) macro does not use any preprocessor operators (like ##)
> d) macro does not get undefined or is conditionally defined.
> e) macro is not type independent (use inline template for these?)
> f) Any other case ?
in general I'm infavor of replacing macros with unctions / constants /
templates etc.
> Example:
> Consider C_EXPR_APPEND macro defined in c-tree.h:
>
> /* Append a new c_expr_t element to V. */
> #define C_EXPR_APPEND(V, ELEM) \
> do { \
> c_expr_t __elem = (ELEM); \
> vec_safe_push (V, __elem); \
> } while (0)
Its not my code, but that macro looks like a totally useless
abstruction, why not just inline the vec_safe_push() ?
Trev
>
> It is called at two places in c-parser.c:
> 0 c-parser.c <global> 6140 C_EXPR_APPEND (cexpr_list, expr);
> 1 c-parser.c <global> 6145 C_EXPR_APPEND (cexpr_list, expr);
>
> Shall be replaced by:
>
> static inline void
> C_EXPR_APPEND( vec<c_expr_t, va_gc> * V, c_expr_t ELEM)
> {
> vec_safe_push(V, ELEM);
> }
>
> I will volunteer to do it, if it's accepted.
>
> Thanks and Regards,
> Prathamesh
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: replace do-while macros with static inline functions
2013-12-13 19:42 ` Trevor Saunders
@ 2013-12-13 20:47 ` Ondřej Bílka
0 siblings, 0 replies; 5+ messages in thread
From: Ondřej Bílka @ 2013-12-13 20:47 UTC (permalink / raw)
To: Trevor Saunders; +Cc: gcc
On Fri, Dec 13, 2013 at 02:42:23PM -0500, Trevor Saunders wrote:
> On Wed, Dec 11, 2013 at 08:33:03PM +0530, Prathamesh Kulkarni wrote:
> > I was wondering if it was a good idea to replace do-while macros with
> > static inline functions returning void, where appropriate ?
> > By "where appropriate" I mean:
> > a) call to macro contains no side-effects
> > b) macro does not modify the arguments.
> > c) macro does not use any preprocessor operators (like ##)
> > d) macro does not get undefined or is conditionally defined.
> > e) macro is not type independent (use inline template for these?)
> > f) Any other case ?
>
> in general I'm infavor of replacing macros with unctions / constants /
> templates etc.
>
> > Example:
> > Consider C_EXPR_APPEND macro defined in c-tree.h:
> >
> > /* Append a new c_expr_t element to V. */
> > #define C_EXPR_APPEND(V, ELEM) \
> > do { \
> > c_expr_t __elem = (ELEM); \
> > vec_safe_push (V, __elem); \
> > } while (0)
>
> Its not my code, but that macro looks like a totally useless
> abstruction, why not just inline the vec_safe_push() ?
>
Anyway if you inline macros you typically need to use always_inline.
Quite often gcc makes mistake of not inlining these, a body looks much
larger than actual inline expansion. Which is understandable as reason
of macro could be avoiding a function call overhead.
^ permalink raw reply [flat|nested] 5+ messages in thread
[parent not found: <CAD_=9DRy95wpMmLAhrMr8EQ55qcWDzGouhHMckSR2SJMYRemDQ@mail.gmail.com>]
* Re: replace do-while macros with static inline functions
[not found] ` <CAD_=9DRy95wpMmLAhrMr8EQ55qcWDzGouhHMckSR2SJMYRemDQ@mail.gmail.com>
@ 2013-12-13 19:48 ` Diego Novillo
2013-12-13 22:06 ` Prathamesh Kulkarni
1 sibling, 0 replies; 5+ messages in thread
From: Diego Novillo @ 2013-12-13 19:48 UTC (permalink / raw)
To: Prathamesh Kulkarni; +Cc: gcc
Bah. Forgot to remove html.
On Fri, Dec 13, 2013 at 2:47 PM, Diego Novillo <dnovillo@google.com> wrote:
>
>
>
> On Wed, Dec 11, 2013 at 10:03 AM, Prathamesh Kulkarni
> <bilbotheelffriend@gmail.com> wrote:
>>
>> I was wondering if it was a good idea to replace do-while macros with
>> static inline functions returning void, where appropriate ?
>> By "where appropriate" I mean:
>> a) call to macro contains no side-effects
>> b) macro does not modify the arguments.
>> c) macro does not use any preprocessor operators (like ##)
>> d) macro does not get undefined or is conditionally defined.
>> e) macro is not type independent (use inline template for these?)
>> f) Any other case ?
>>
>> Example:
>> Consider C_EXPR_APPEND macro defined in c-tree.h:
>>
>> /* Append a new c_expr_t element to V. */
>> #define C_EXPR_APPEND(V, ELEM) \
>> do { \
>> c_expr_t __elem = (ELEM); \
>> vec_safe_push (V, __elem); \
>> } while (0)
>>
>
> Yes, it's a good idea. One thing you will likely need to do, however, is to
> add some of the replaced functions into gdb's list of ignored inline
> functions. Some folks are used to gdb stepping over macro calls when 's' is
> used.
>
> Not all macros need to be turned into functions. Some can be completely
> removed (Trevor mentions an example in his reply).
>
>
> Diego.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: replace do-while macros with static inline functions
[not found] ` <CAD_=9DRy95wpMmLAhrMr8EQ55qcWDzGouhHMckSR2SJMYRemDQ@mail.gmail.com>
2013-12-13 19:48 ` Diego Novillo
@ 2013-12-13 22:06 ` Prathamesh Kulkarni
1 sibling, 0 replies; 5+ messages in thread
From: Prathamesh Kulkarni @ 2013-12-13 22:06 UTC (permalink / raw)
To: Diego Novillo; +Cc: gcc
On Sat, Dec 14, 2013 at 1:17 AM, Diego Novillo <dnovillo@google.com> wrote:
>
>
>
> On Wed, Dec 11, 2013 at 10:03 AM, Prathamesh Kulkarni
> <bilbotheelffriend@gmail.com> wrote:
>>
>> I was wondering if it was a good idea to replace do-while macros with
>> static inline functions returning void, where appropriate ?
>> By "where appropriate" I mean:
>> a) call to macro contains no side-effects
>> b) macro does not modify the arguments.
>> c) macro does not use any preprocessor operators (like ##)
>> d) macro does not get undefined or is conditionally defined.
>> e) macro is not type independent (use inline template for these?)
>> f) Any other case ?
>>
>> Example:
>> Consider C_EXPR_APPEND macro defined in c-tree.h:
>>
>> /* Append a new c_expr_t element to V. */
>> #define C_EXPR_APPEND(V, ELEM) \
>> do { \
>> c_expr_t __elem = (ELEM); \
>> vec_safe_push (V, __elem); \
>> } while (0)
>>
>
> Yes, it's a good idea. One thing you will likely need to do, however, is to
> add some of the replaced functions into gdb's list of ignored inline
> functions. Some folks are used to gdb stepping over macro calls when 's' is
> used.
>
> Not all macros need to be turned into functions. Some can be completely
> removed (Trevor mentions an example in his reply).
Thanks. I shall start working on it.
>
>
> Diego.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-12-13 22:06 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-11 15:03 replace do-while macros with static inline functions Prathamesh Kulkarni
2013-12-13 19:42 ` Trevor Saunders
2013-12-13 20:47 ` Ondřej Bílka
[not found] ` <CAD_=9DRy95wpMmLAhrMr8EQ55qcWDzGouhHMckSR2SJMYRemDQ@mail.gmail.com>
2013-12-13 19:48 ` Diego Novillo
2013-12-13 22:06 ` Prathamesh Kulkarni
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).