Documentation Archive Developer
Search

Next: , Previous: Defining Mode Macros, Up: Mode Macros


14.22.1.2 Substitution in Mode Macros

If an .md file construct uses mode macros, each version of the construct will often need slightly different strings or modes. For example:

GCC supports such variations through a system of “mode attributes”. There are two standard attributes: mode, which is the name of the mode in lower case, and MODE, which is the same thing in upper case. You can define other attributes using:

     (define_mode_attr name [(mode1 "value1") ... (moden "valuen")])

where name is the name of the attribute and valuei is the value associated with modei.

When GCC replaces some :macro with :mode, it will scan each string and mode in the pattern for sequences of the form <macro:attr>, where attr is the name of a mode attribute. If the attribute is defined for mode, the whole <...> sequence will be replaced by the appropriate attribute value.

For example, suppose an .md file has:

     (define_mode_macro P [(SI "Pmode == SImode") (DI "Pmode == DImode")])
     (define_mode_attr load [(SI "lw") (DI "ld")])

If one of the patterns that uses :P contains the string "<P:load>\t%0,%1", the SI version of that pattern will use "lw\t%0,%1" and the DI version will use "ld\t%0,%1".

Here is an example of using an attribute for a mode:

     (define_mode_macro LONG [SI DI])
     (define_mode_attr SHORT [(SI "HI") (DI "SI")])
     (define_insn ...
       (sign_extend:LONG (match_operand:<LONG:SHORT> ...)) ...)

The macro: prefix may be omitted, in which case the substitution will be attempted for every macro expansion.