This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Allow nested use of attributes in MD-files


Hi,
This patch allows to use attributes inside other attributes in MD-files.
Currently we can't have an attribute depending on both mode and code - we have
only mode attribute and code attribute and mode_attribute can't depend on the
code.

So, if we write, for example,
  (define_mode_attr attr_name [(SI "ps") (DI "<code>")])
then <attr_name> in a pattern with both mode and code iterators will be replaced
with "ps" and "<code>" depending on the mode, but "<code>" won't be expanded
further.

Here is a small example to show when it could be needed.  Suppose we have two
instructions: add and substract, and each of them operates on SI and DI mode
registers.  Suppose also that for DI-mode addition it's prefferable to
use an alias (suppose, it's
a faster version of similar instruction).  I.e. we want to have patterns to emit
the following:

  plus,  SI: add_32
  plus,  DI: fast_add_64
  minus, SI: sub_32
  minus, DI: sub_64

Currently we need to have a separate pattern in MD-file for fast_add_64, but
with the change I suggest it could be written within one pattern as follows:

(define_mode_iterator MI [SI DI])
(define_code_iterator plusminus [plus minus])

(define_mode_attr Madd [(SI "add_32") (DI "fast_add_64")])
(define_mode_attr Msub [(SI "sub_32") (DI "sub_64")])
(define_code_attr CodeModeAttribute [(plus "<Madd>") (minus "<Msub>")])

(define_insn "<code><mode>"
  [(set:MI (match_operand:MI 0 "register_operand" "r")
           (plusminus:MI (match_operand:MI 1 "register_operand" "r")
                         (match_operand:MI 2 "register_operand" "r")))]
   ""
    "<CodeModeAttribute>")

This could be used for all kinds of iterators and it could be very useful
when several different substs are applied to the same pattern.

The patch is regtested and bootstrapped on i386 and x86_64, and tested on
Specs2k, 2k6.

Is it ok for trunk?

gcc/ChangeLog
2013-04-26  Michael Zolotukhin  <michael.v.zolotukhin@intel.com>

        * read-rtl.c (copy_rtx_for_iterators): Continue applying iterators
        while it has any effect.


--
---
Best regards,
Michael V. Zolotukhin,
Software Engineer
Intel Corporation.

Attachment: attr.patch
Description: Binary data


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]