On 06/05/14 15:32, Richard Sandiford wrote:
Now that all extra constraints are defined in .md files, there's no real
need for the old REG_CLASS_FROM_CONSTRAINT-style macros.  The macros also
seem dangerous performance-wise, since each one contains an embedded call to
lookup_constraint.  This means that code like:

                    if (REG_CLASS_FROM_CONSTRAINT (c, p) == NO_REGS)
                      {
                        if (EXTRA_MEMORY_CONSTRAINT (c, p))
                          ... EXTRA_CONSTRAINT_STR ...
                        if (EXTRA_ADDRESS_CONSTRAINT (c, p))
                          ... EXTRA_CONSTRAINT_STR ...
                        ... EXTRA_CONSTRAINT_STR ...
                      }
                    ...REG_CLASS_FROM_CONSTRAINT...

looks up the same constraint several times.

This patch replaces all uses of:

     REG_CLASS_FROM_CONSTRAINT
     REG_CLASS_FOR_CONSTRAINT
     EXTRA_CONSTRAINT_STR
     EXTRA_MEMORY_CONSTRAINT
     EXTRA_ADDRESS_CONSTRAINT

with separate calls to lookup_constraint and the underlying query function.
It poisons the old macros as a way of protecting against accidental use
(e.g. in #ifdef EXTRA_CONSTRAINT_STR blocks).

Several places want to handle each specific type of constraint in a
different way, so I added a convenience function for classifying constraints
into a type enum.  This also makes the range checks more efficient.
I've treated CONSTRAINT__UNKNOWN as a register constraint (the first type)
since that avoids one more range check and means that each consumer doesn't
have to handle non-constraints specially.  The range check in
reg_class_for_constraint already ensures that the CONSTRAINT__UNKNOWN->
NO_REGS mapping is inline.

Richard


gcc/
        * system.h (REG_CLASS_FROM_CONSTRAINT): Poison.
        (REG_CLASS_FOR_CONSTRAINT, EXTRA_CONSTRAINT_STR): Likewise.
        (EXTRA_MEMORY_CONSTRAINT, EXTRA_ADDRESS_CONSTRAINT): Likewise.
        * genpreds.c (print_type_tree): New function.
        (write_tm_preds_h): Remove REG_CLASS_FROM_CONSTRAINT,
        REG_CLASS_FOR_CONSTRAINT, EXTRA_MEMORY_CONSTRAINT,
        EXTRA_ADDRESS_CONSTRAINT and EXTRA_CONSTRAINT_STR.
        Write out enum constraint_type and get_constraint_type.
        * lra-constraints.c (satisfies_memory_constraint_p): Take a
        constraint_num rather than a constraint string.
        (satisfies_address_constraint_p): Likewise.
        (reg_class_from_constraints): Avoid old constraint macros.
        (process_alt_operands, process_address_1): Likewise.
        (curr_insn_transform): Likewise.
        * ira-costs.c (record_reg_classes): Likewise.
        (record_operand_costs): Likewise.
        * ira-lives.c (single_reg_class): Likewise.
        (ira_implicitly_set_insn_hard_regs): Likewise.
        * ira.c (ira_setup_alts, ira_get_dup_out_num): Likewise.
        * postreload.c (reload_cse_simplify_operands): Likewise.
        * recog.c (asm_operand_ok, preprocess_constraints): Likewise.
        (constrain_operands, peep2_find_free_register): Likewise.
        * reload.c (push_secondary_reload, scratch_reload_class): Likewise.
        (find_reloads, alternative_allows_const_pool_ref): Likewise.
        * reload1.c (maybe_fix_stack_asms): Likewise.
        * stmt.c (parse_output_constraint, parse_input_constraint): Likewise.
        * targhooks.c (default_secondary_reload): Likewise.
        * config/m32c/m32c.c (m32c_matches_constraint_p): Avoid reference
        to EXTRA_CONSTRAINT_STR.
        * config/sparc/constraints.md (U): Likewise REG_CLASS_FROM_CONSTRAINT.
Given the level of testing you've done, I only spot checked a few places after concluding the general direction you were going makes sense. I don't expect any fallout, but I'm confident you'll deal with it if it happens.

Thanks.  OK for the trunk,

Jeff


Reply via email to