gccint: Defining Attributes
1
1 17.19.1 Defining Attributes and their Values
1 --------------------------------------------
1
1 The 'define_attr' expression is used to define each attribute required
1 by the target machine. It looks like:
1
1 (define_attr NAME LIST-OF-VALUES DEFAULT)
1
1 NAME is a string specifying the name of the attribute being defined.
1 Some attributes are used in a special way by the rest of the compiler.
1 The 'enabled' attribute can be used to conditionally enable or disable
1 insn alternatives (⇒Disable Insn Alternatives). The 'predicable'
11 attribute, together with a suitable 'define_cond_exec' (⇒
Conditional Execution), can be used to automatically generate
1 conditional variants of instruction patterns. The 'mnemonic' attribute
11 can be used to check for the instruction mnemonic (⇒Mnemonic
Attribute). The compiler internally uses the names 'ce_enabled' and
1 'nonce_enabled', so they should not be used elsewhere as alternative
1 names.
1
1 LIST-OF-VALUES is either a string that specifies a comma-separated list
1 of values that can be assigned to the attribute, or a null string to
1 indicate that the attribute takes numeric values.
1
1 DEFAULT is an attribute expression that gives the value of this
1 attribute for insns that match patterns whose definition does not
1 include an explicit value for this attribute. ⇒Attr Example, for
11 more information on the handling of defaults. ⇒Constant
Attributes, for information on attributes that do not depend on any
1 particular insn.
1
1 For each defined attribute, a number of definitions are written to the
1 'insn-attr.h' file. For cases where an explicit set of values is
1 specified for an attribute, the following are defined:
1
1 * A '#define' is written for the symbol 'HAVE_ATTR_NAME'.
1
1 * An enumerated class is defined for 'attr_NAME' with elements of the
1 form 'UPPER-NAME_UPPER-VALUE' where the attribute name and value
1 are first converted to uppercase.
1
1 * A function 'get_attr_NAME' is defined that is passed an insn and
1 returns the attribute value for that insn.
1
1 For example, if the following is present in the 'md' file:
1
1 (define_attr "type" "branch,fp,load,store,arith" ...)
1
1 the following lines will be written to the file 'insn-attr.h'.
1
1 #define HAVE_ATTR_type 1
1 enum attr_type {TYPE_BRANCH, TYPE_FP, TYPE_LOAD,
1 TYPE_STORE, TYPE_ARITH};
1 extern enum attr_type get_attr_type ();
1
1 If the attribute takes numeric values, no 'enum' type will be defined
1 and the function to obtain the attribute's value will return 'int'.
1
1 There are attributes which are tied to a specific meaning. These
1 attributes are not free to use for other purposes:
1
1 'length'
1 The 'length' attribute is used to calculate the length of emitted
1 code chunks. This is especially important when verifying branch
1 distances. ⇒Insn Lengths.
1
1 'enabled'
1 The 'enabled' attribute can be defined to prevent certain
1 alternatives of an insn definition from being used during code
1 generation. ⇒Disable Insn Alternatives.
1
1 'mnemonic'
1 The 'mnemonic' attribute can be defined to implement instruction
11 specific checks in e.g. the pipeline description. ⇒Mnemonic
Attribute.
1
1 For each of these special attributes, the corresponding
1 'HAVE_ATTR_NAME' '#define' is also written when the attribute is not
1 defined; in that case, it is defined as '0'.
1
1 Another way of defining an attribute is to use:
1
1 (define_enum_attr "ATTR" "ENUM" DEFAULT)
1
1 This works in just the same way as 'define_attr', except that the list
11 of values is taken from a separate enumeration called ENUM (⇒
define_enum). This form allows you to use the same list of values for
1 several attributes without having to repeat the list each time. For
1 example:
1
1 (define_enum "processor" [
1 model_a
1 model_b
1 ...
1 ])
1 (define_enum_attr "arch" "processor"
1 (const (symbol_ref "target_arch")))
1 (define_enum_attr "tune" "processor"
1 (const (symbol_ref "target_tune")))
1
1 defines the same attributes as:
1
1 (define_attr "arch" "model_a,model_b,..."
1 (const (symbol_ref "target_arch")))
1 (define_attr "tune" "model_a,model_b,..."
1 (const (symbol_ref "target_tune")))
1
1 but without duplicating the processor list. The second example defines
1 two separate C enums ('attr_arch' and 'attr_tune') whereas the first
1 defines a single C enum ('processor').
1