> get_best_mode has various checks to decide what counts as an acceptable
> bitfield mode. It actually has two copies of them, with slightly different
> alignment checks:
>
> MIN (unit, BIGGEST_ALIGNMENT) > align
>
> vs.
>
> unit <= MIN (align, BIGGEST_ALIGNMENT)
>
> The second looks more correct, since we can't necessarily guarantee
> larger alignments than BIGGEST_ALIGNMENT in all cases.
Under the assumption that integer modes really require maximal alignment, i.e.
whatever BIGGEST_ALIGNMENT is, I agree.
> This patch adds a new iterator class that can be used to walk through
> the modes, and rewrites get_best_mode to use it. I kept the existing
> checks with two changes:
>
> - bitregion_start is now tested independently of bitregion_end
The comments needs to be updated then.
> - MAX_FIXED_MODE_SIZE is used as a limit even if a bitregion is defined
This makes sense I think.
> It shouldn't make any difference in practice, but both changes felt
> more in keeping with the documentation of bitregion_start and
> MAX_FIXED_MODE_SIZE, and the next patch wants the bitregion_end
> test to be separate from bitregion_start.
>
> The behaviour of the Sequent i386 compiler probably isn't the
> issue it once was, but that's also dealt with in the next patch.
>
> Tested as described in the covering note. OK to install?
>
> Richard
>
>
> gcc/
> * machmode.h (bit_field_mode_iterator): New class.
> (get_best_mode): Change final parameter to bool.
> * stor-layout.c (bit_field_mode_iterator::bit_field_mode_iterator)
> (bit_field_mode_iterator::next_mode): New functions, split out from...
> (get_best_mode): ...here. Change final parameter to bool.
> Use bit_field_mode_iterator.
This looks good to me, modulo:
> + volatilep_ (volatilep), count_ (0)
> +{
> + if (bitregion_end_)
> + bitregion_end_ += 1;
> +}
IMO this is confusing. I think bitregion_end/bitregion_end_ should have a
consistent meaning.
> +/* Calls to this function return successively larger modes that can be used
> + to represent the bitfield. Return true if another bitfield mode is +
> available, storing it in *OUT_MODE if so. */
> +
> +bool bit_field_mode_iterator::next_mode (enum machine_mode *out_mode)
'bool' on its own line I think.
I find the interface a bit awkward though. Can't we model it on the existing
iterators in basic-block.h or tree-flow.h? get_best_mode would be written:
FOR_EACH_BITFIELD_MODE (mode, iter, bitsize, bitpos,
bitregion_start, bitregion_end,
align, volatilep)
{
if (largest_mode != VOIDmode
&& GET_MODE_SIZE (mode) > GET_MODE_SIZE (largest_mode)
break;
if (iter.prefer_smaller_modes ())
return mode;
widest_mode = mode;
}
return widest_mode;
and the implementation entirely hidden.
--
Eric Botcazou