gccint: Attr Example

1 
1 17.19.4 Example of Attribute Specifications
1 -------------------------------------------
1 
1 The judicious use of defaulting is important in the efficient use of
1 insn attributes.  Typically, insns are divided into "types" and an
1 attribute, customarily called 'type', is used to represent this value.
1 This attribute is normally used only to define the default value for
1 other attributes.  An example will clarify this usage.
1 
1  Assume we have a RISC machine with a condition code and in which only
1 full-word operations are performed in registers.  Let us assume that we
1 can divide all insns into loads, stores, (integer) arithmetic
1 operations, floating point operations, and branches.
1 
1  Here we will concern ourselves with determining the effect of an insn
1 on the condition code and will limit ourselves to the following possible
1 effects: The condition code can be set unpredictably (clobbered), not be
1 changed, be set to agree with the results of the operation, or only
1 changed if the item previously set into the condition code has been
1 modified.
1 
1  Here is part of a sample 'md' file for such a machine:
1 
1      (define_attr "type" "load,store,arith,fp,branch" (const_string "arith"))
1 
1      (define_attr "cc" "clobber,unchanged,set,change0"
1                   (cond [(eq_attr "type" "load")
1                              (const_string "change0")
1                          (eq_attr "type" "store,branch")
1                              (const_string "unchanged")
1                          (eq_attr "type" "arith")
1                              (if_then_else (match_operand:SI 0 "" "")
1                                            (const_string "set")
1                                            (const_string "clobber"))]
1                         (const_string "clobber")))
1 
1      (define_insn ""
1        [(set (match_operand:SI 0 "general_operand" "=r,r,m")
1              (match_operand:SI 1 "general_operand" "r,m,r"))]
1        ""
1        "@
1         move %0,%1
1         load %0,%1
1         store %0,%1"
1        [(set_attr "type" "arith,load,store")])
1 
1  Note that we assume in the above example that arithmetic operations
1 performed on quantities smaller than a machine word clobber the
1 condition code since they will set the condition code to a value
1 corresponding to the full-word result.
1