Hi Zack,

> So, the plan: Step 1 introduces - one at a time - target hooks
> corresponding to each of the above macros.  All callers are changed to
> use the hooks.  The default definitions of the hooks invoke the
> existing macros.  The hardest part of this is working out exactly what
> their sole callers expect of LEGITIMIZE_ADDRESS and
> LEGITIMIZE_RELOAD_ADDRESS.  The manual, unfortunately, is not very
> clear.  I think that in both cases it amounts to "either replace X
> with a new value and jump to WIN, or leave X unmodified and drop
> through", which can be translated to "return a new value for X, or
> NULL", but I'm not sure, particularly about LEGITIMIZE_RELOAD_ADDRESS
> and its interaction with push_reload.
> 
> Step 2 is to convert each architecture, one at a time, to make
> target-hook definitions.  I think it makes most sense to do each
> architecture in one go, because the definitions of these macros tend
> to be intertwined.  In particular, REG_OK_FOR_BASE_P etc are often
> used in the definition of GO_IF_LEGITIMATE_ADDRESS.  It will require
> some care to be sure that the hooks retain the same semantics wrt
> REG_OK_STRICT.  Some of the macros have sensible defaults; for
> instance, it is allowed to define a LEGITIMIZE_ADDRESS that does
> nothing.  In this stage we should identify what those defaults are,
> and add appropriate functions to hooks.c; but we cannot change the
> default settings in target-def.h until all architectures are
> converted.
I would swap these two steps.

Last time I looked at this stuff, I was surprised by how many things
depended on REG_OK_STRICT.  Even if macro A does not mention
REG_OK_STRICT, macro B used in A might use REG_OK_STRICT, so it's
difficult to tell in advance which macro depends on REG_OK_STRICT
either directly or indirectly.  So I would change each macro to an
architecture-specific function in each architecture first.  For
example, GO_IF_LEGITIMATE_ADDRESS should look like this (taken from
i386.h):

#ifdef REG_OK_STRICT
#define GO_IF_LEGITIMATE_ADDRESS(MODE, X, ADDR)                         \
do {                                                                    \
  if (legitimate_address_p ((MODE), (X), 1))                            \
    goto ADDR;                                                          \
} while (0)

#else
#define GO_IF_LEGITIMATE_ADDRESS(MODE, X, ADDR)                         \
do {                                                                    \
  if (legitimate_address_p ((MODE), (X), 0))                            \
    goto ADDR;                                                          \
} while (0)

#endif

Note that REG_OK_STRICT is essentially used as an argument to
legitimate_address_p and that the use of the function argument
decouples legitimate_address_p and REG_OK_STRICT.

Once REG_OK_STRICT appears in this way only, we are ready to introduce
new target hooks.  The new target hooks would have a REG_OK_STRICT as
an argument.  So in the above example, we would simply psas that
argument to the last argument of legitimate_address_p.

Kazu Hirata

Reply via email to