On Tue, 9 Jul 2019 16:36:46 -0500
Segher Boessenkool <seg...@kernel.crashing.org> wrote:

> On Tue, Jul 09, 2019 at 10:16:31PM +0100, Jozef Lawrynowicz wrote:
> > On Mon, 8 Jul 2019 16:42:15 -0500
> > Segher Boessenkool <seg...@kernel.crashing.org> wrote:
> >   
> > > > Ok, yes a DEFHOOKPOD or similar sounds like a good idea, I'll look into 
> > > > this
> > > > alternative.    
> > > 
> > > What is that, like target macros?  But with some indirection?  
> > 
> > Yes its for target macros, it looks like the "POD" in DEFHOOKPOD stands for
> > "piece-of-data", i.e. the hook represents a variable rather than function.  
> 
> But it is data, not a constant, so it does not allow optimising based
> on its potentially constant value?  Where "potentially" in this case
> means "always" :-/
> 
> 
> Segher

I can think of two alternatives so far which should get around this
optimization issue you point out.

1. a regular target macro defined in tm.texi such as
TARGET_CASE_INSENSITIVE_REGISTER_NAMES, defined to 0 by default. Overriden
with 1 for MSP430 

>         for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
>         if (reg_names[i][0]
> +#if TARGET_CASE_INSENSITIVE_REGISTER_NAMES
> +           && ! strcasecmp (asmspec, strip_reg_name (reg_names[i])))
> +#else
>             && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
> +#endif
>           return i;

2. a function-like target macro TARGET_COMPARE_REGISTER_NAMES in tm.texi which
defines the function to use for register name comparisons. Defined to
"strcmp" by default and overriden with strcasecmp for MSP430.

>         for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
>         if (reg_names[i][0]
> -           && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
> +           && ! TARGET_COMPARE_REGISTER_NAMES (asmspec, strip_reg_name 
> (reg_names[i])))
>          return i;

Alternatively a DEFHOOK could be used for above so we'd have
targetm.compare_register_names (asmspec, ...) which would essentially be a
wrapper round strcmp or strcasecmp. But I'm unsure if GCC would end up
inlining the str{,case}cmp call from the target hook - maybe if the file is
built with lto.. So we may end up with sub-optimal code again with this.

I think (1) is more immediately clear as to what the macro is doing, although
it is less concise than (2) as 3 of these #if..else blocks would be required.
Nevertheless (1) would still be my preferred solution.
Any thoughts?

Thanks,
Jozef

Reply via email to