home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Source / GNU / gcc / gcc.info-18 (.txt) < prev    next >
GNU Info File  |  1995-06-16  |  47KB  |  847 lines

  1. This is Info file gcc.info, produced by Makeinfo-1.55 from the input
  2. file gcc.texi.
  3.    This file documents the use and the internals of the GNU compiler.
  4.    Published by the Free Software Foundation 59 Temple Place - Suite 330
  5. Boston, MA 02111-1307 USA
  6.    Copyright (C) 1988, 1989, 1992, 1993, 1994, 1995 Free Software
  7. Foundation, Inc.
  8.    Permission is granted to make and distribute verbatim copies of this
  9. manual provided the copyright notice and this permission notice are
  10. preserved on all copies.
  11.    Permission is granted to copy and distribute modified versions of
  12. this manual under the conditions for verbatim copying, provided also
  13. that the sections entitled "GNU General Public License," "Funding for
  14. Free Software," and "Protect Your Freedom--Fight `Look And Feel'" are
  15. included exactly as in the original, and provided that the entire
  16. resulting derived work is distributed under the terms of a permission
  17. notice identical to this one.
  18.    Permission is granted to copy and distribute translations of this
  19. manual into another language, under the above conditions for modified
  20. versions, except that the sections entitled "GNU General Public
  21. License," "Funding for Free Software," and "Protect Your Freedom--Fight
  22. `Look And Feel'", and this permission notice, may be included in
  23. translations approved by the Free Software Foundation instead of in the
  24. original English.
  25. File: gcc.info,  Node: Expander Definitions,  Next: Insn Splitting,  Prev: Peephole Definitions,  Up: Machine Desc
  26. Defining RTL Sequences for Code Generation
  27. ==========================================
  28.    On some target machines, some standard pattern names for RTL
  29. generation cannot be handled with single insn, but a sequence of RTL
  30. insns can represent them.  For these target machines, you can write a
  31. `define_expand' to specify how to generate the sequence of RTL.
  32.    A `define_expand' is an RTL expression that looks almost like a
  33. `define_insn'; but, unlike the latter, a `define_expand' is used only
  34. for RTL generation and it can produce more than one RTL insn.
  35.    A `define_expand' RTX has four operands:
  36.    * The name.  Each `define_expand' must have a name, since the only
  37.      use for it is to refer to it by name.
  38.    * The RTL template.  This is just like the RTL template for a
  39.      `define_peephole' in that it is a vector of RTL expressions each
  40.      being one insn.
  41.    * The condition, a string containing a C expression.  This
  42.      expression is used to express how the availability of this pattern
  43.      depends on subclasses of target machine, selected by command-line
  44.      options when GNU CC is run.  This is just like the condition of a
  45.      `define_insn' that has a standard name.  Therefore, the condition
  46.      (if present) may not depend on the data in the insn being matched,
  47.      but only the target-machine-type flags.  The compiler needs to
  48.      test these conditions during initialization in order to learn
  49.      exactly which named instructions are available in a particular run.
  50.    * The preparation statements, a string containing zero or more C
  51.      statements which are to be executed before RTL code is generated
  52.      from the RTL template.
  53.      Usually these statements prepare temporary registers for use as
  54.      internal operands in the RTL template, but they can also generate
  55.      RTL insns directly by calling routines such as `emit_insn', etc.
  56.      Any such insns precede the ones that come from the RTL template.
  57.    Every RTL insn emitted by a `define_expand' must match some
  58. `define_insn' in the machine description.  Otherwise, the compiler will
  59. crash when trying to generate code for the insn or trying to optimize
  60.    The RTL template, in addition to controlling generation of RTL insns,
  61. also describes the operands that need to be specified when this pattern
  62. is used.  In particular, it gives a predicate for each operand.
  63.    A true operand, which needs to be specified in order to generate RTL
  64. from the pattern, should be described with a `match_operand' in its
  65. first occurrence in the RTL template.  This enters information on the
  66. operand's predicate into the tables that record such things.  GNU CC
  67. uses the information to preload the operand into a register if that is
  68. required for valid RTL code.  If the operand is referred to more than
  69. once, subsequent references should use `match_dup'.
  70.    The RTL template may also refer to internal "operands" which are
  71. temporary registers or labels used only within the sequence made by the
  72. `define_expand'.  Internal operands are substituted into the RTL
  73. template with `match_dup', never with `match_operand'.  The values of
  74. the internal operands are not passed in as arguments by the compiler
  75. when it requests use of this pattern.  Instead, they are computed
  76. within the pattern, in the preparation statements.  These statements
  77. compute the values and store them into the appropriate elements of
  78. `operands' so that `match_dup' can find them.
  79.    There are two special macros defined for use in the preparation
  80. statements: `DONE' and `FAIL'.  Use them with a following semicolon, as
  81. a statement.
  82. `DONE'
  83.      Use the `DONE' macro to end RTL generation for the pattern.  The
  84.      only RTL insns resulting from the pattern on this occasion will be
  85.      those already emitted by explicit calls to `emit_insn' within the
  86.      preparation statements; the RTL template will not be generated.
  87. `FAIL'
  88.      Make the pattern fail on this occasion.  When a pattern fails, it
  89.      means that the pattern was not truly available.  The calling
  90.      routines in the compiler will try other strategies for code
  91.      generation using other patterns.
  92.      Failure is currently supported only for binary (addition,
  93.      multiplication, shifting, etc.) and bitfield (`extv', `extzv', and
  94.      `insv') operations.
  95.    Here is an example, the definition of left-shift for the SPUR chip:
  96.      (define_expand "ashlsi3"
  97.        [(set (match_operand:SI 0 "register_operand" "")
  98.              (ashift:SI
  99.      (match_operand:SI 1 "register_operand" "")
  100.                (match_operand:SI 2 "nonmemory_operand" "")))]
  101.        ""
  102.        "
  103.      {
  104.        if (GET_CODE (operands[2]) != CONST_INT
  105.            || (unsigned) INTVAL (operands[2]) > 3)
  106.          FAIL;
  107.      }")
  108. This example uses `define_expand' so that it can generate an RTL insn
  109. for shifting when the shift-count is in the supported range of 0 to 3
  110. but fail in other cases where machine insns aren't available.  When it
  111. fails, the compiler tries another strategy using different patterns
  112. (such as, a library call).
  113.    If the compiler were able to handle nontrivial condition-strings in
  114. patterns with names, then it would be possible to use a `define_insn'
  115. in that case.  Here is another case (zero-extension on the 68000) which
  116. makes more use of the power of `define_expand':
  117.      (define_expand "zero_extendhisi2"
  118.        [(set (match_operand:SI 0 "general_operand" "")
  119.              (const_int 0))
  120.         (set (strict_low_part
  121.                (subreg:HI
  122.                  (match_dup 0)
  123.                  0))
  124.              (match_operand:HI 1 "general_operand" ""))]
  125.        ""
  126.        "operands[1] = make_safe_from (operands[1], operands[0]);")
  127. Here two RTL insns are generated, one to clear the entire output operand
  128. and the other to copy the input operand into its low half.  This
  129. sequence is incorrect if the input operand refers to [the old value of]
  130. the output operand, so the preparation statement makes sure this isn't
  131. so.  The function `make_safe_from' copies the `operands[1]' into a
  132. temporary register if it refers to `operands[0]'.  It does this by
  133. emitting another RTL insn.
  134.    Finally, a third example shows the use of an internal operand.
  135. Zero-extension on the SPUR chip is done by `and'-ing the result against
  136. a halfword mask.  But this mask cannot be represented by a `const_int'
  137. because the constant value is too large to be legitimate on this
  138. machine.  So it must be copied into a register with `force_reg' and
  139. then the register used in the `and'.
  140.      (define_expand "zero_extendhisi2"
  141.        [(set (match_operand:SI 0 "register_operand" "")
  142.              (and:SI (subreg:SI
  143.                        (match_operand:HI 1 "register_operand" "")
  144.                        0)
  145.                      (match_dup 2)))]
  146.        ""
  147.        "operands[2]
  148.           = force_reg (SImode, gen_rtx (CONST_INT,
  149.                                         VOIDmode, 65535)); ")
  150.    *Note:* If the `define_expand' is used to serve a standard binary or
  151. unary arithmetic operation or a bitfield operation, then the last insn
  152. it generates must not be a `code_label', `barrier' or `note'.  It must
  153. be an `insn', `jump_insn' or `call_insn'.  If you don't need a real insn
  154. at the end, emit an insn to copy the result of the operation into
  155. itself.  Such an insn will generate no code, but it can avoid problems
  156. in the compiler.
  157. File: gcc.info,  Node: Insn Splitting,  Next: Insn Attributes,  Prev: Expander Definitions,  Up: Machine Desc
  158. Defining How to Split Instructions
  159. ==================================
  160.    There are two cases where you should specify how to split a pattern
  161. into multiple insns.  On machines that have instructions requiring delay
  162. slots (*note Delay Slots::.) or that have instructions whose output is
  163. not available for multiple cycles (*note Function Units::.), the
  164. compiler phases that optimize these cases need to be able to move insns
  165. into one-instruction delay slots.  However, some insns may generate
  166. more than one machine instruction.  These insns cannot be placed into a
  167. delay slot.
  168.    Often you can rewrite the single insn as a list of individual insns,
  169. each corresponding to one machine instruction.  The disadvantage of
  170. doing so is that it will cause the compilation to be slower and require
  171. more space.  If the resulting insns are too complex, it may also
  172. suppress some optimizations.  The compiler splits the insn if there is a
  173. reason to believe that it might improve instruction or delay slot
  174. scheduling.
  175.    The insn combiner phase also splits putative insns.  If three insns
  176. are merged into one insn with a complex expression that cannot be
  177. matched by some `define_insn' pattern, the combiner phase attempts to
  178. split the complex pattern into two insns that are recognized.  Usually
  179. it can break the complex pattern into two patterns by splitting out some
  180. subexpression.  However, in some other cases, such as performing an
  181. addition of a large constant in two insns on a RISC machine, the way to
  182. split the addition into two insns is machine-dependent.
  183.    The `define_split' definition tells the compiler how to split a
  184. complex insn into several simpler insns.  It looks like this:
  185.      (define_split
  186.        [INSN-PATTERN]
  187.        "CONDITION"
  188.        [NEW-INSN-PATTERN-1
  189.         NEW-INSN-PATTERN-2
  190.         ...]
  191.        "PREPARATION STATEMENTS")
  192.    INSN-PATTERN is a pattern that needs to be split and CONDITION is
  193. the final condition to be tested, as in a `define_insn'.  When an insn
  194. matching INSN-PATTERN and satisfying CONDITION is found, it is replaced
  195. in the insn list with the insns given by NEW-INSN-PATTERN-1,
  196. NEW-INSN-PATTERN-2, etc.
  197.    The PREPARATION STATEMENTS are similar to those statements that are
  198. specified for `define_expand' (*note Expander Definitions::.) and are
  199. executed before the new RTL is generated to prepare for the generated
  200. code or emit some insns whose pattern is not fixed.  Unlike those in
  201. `define_expand', however, these statements must not generate any new
  202. pseudo-registers.  Once reload has completed, they also must not
  203. allocate any space in the stack frame.
  204.    Patterns are matched against INSN-PATTERN in two different
  205. circumstances.  If an insn needs to be split for delay slot scheduling
  206. or insn scheduling, the insn is already known to be valid, which means
  207. that it must have been matched by some `define_insn' and, if
  208. `reload_completed' is non-zero, is known to satisfy the constraints of
  209. that `define_insn'.  In that case, the new insn patterns must also be
  210. insns that are matched by some `define_insn' and, if `reload_completed'
  211. is non-zero, must also satisfy the constraints of those definitions.
  212.    As an example of this usage of `define_split', consider the following
  213. example from `a29k.md', which splits a `sign_extend' from `HImode' to
  214. `SImode' into a pair of shift insns:
  215.      (define_split
  216.        [(set (match_operand:SI 0 "gen_reg_operand" "")
  217.              (sign_extend:SI (match_operand:HI 1 "gen_reg_operand" "")))]
  218.        ""
  219.        [(set (match_dup 0)
  220.              (ashift:SI (match_dup 1)
  221.                         (const_int 16)))
  222.         (set (match_dup 0)
  223.              (ashiftrt:SI (match_dup 0)
  224.                           (const_int 16)))]
  225.        "
  226.      { operands[1] = gen_lowpart (SImode, operands[1]); }")
  227.    When the combiner phase tries to split an insn pattern, it is always
  228. the case that the pattern is *not* matched by any `define_insn'.  The
  229. combiner pass first tries to split a single `set' expression and then
  230. the same `set' expression inside a `parallel', but followed by a
  231. `clobber' of a pseudo-reg to use as a scratch register.  In these
  232. cases, the combiner expects exactly two new insn patterns to be
  233. generated.  It will verify that these patterns match some `define_insn'
  234. definitions, so you need not do this test in the `define_split' (of
  235. course, there is no point in writing a `define_split' that will never
  236. produce insns that match).
  237.    Here is an example of this use of `define_split', taken from
  238. `rs6000.md':
  239.      (define_split
  240.        [(set (match_operand:SI 0 "gen_reg_operand" "")
  241.              (plus:SI (match_operand:SI 1 "gen_reg_operand" "")
  242.                       (match_operand:SI 2 "non_add_cint_operand" "")))]
  243.        ""
  244.        [(set (match_dup 0) (plus:SI (match_dup 1) (match_dup 3)))
  245.         (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 4)))]
  246.      "
  247.      {
  248.        int low = INTVAL (operands[2]) & 0xffff;
  249.        int high = (unsigned) INTVAL (operands[2]) >> 16;
  250.      
  251.        if (low & 0x8000)
  252.          high++, low |= 0xffff0000;
  253.      
  254.        operands[3] = gen_rtx (CONST_INT, VOIDmode, high << 16);
  255.        operands[4] = gen_rtx (CONST_INT, VOIDmode, low);
  256.      }")
  257.    Here the predicate `non_add_cint_operand' matches any `const_int'
  258. that is *not* a valid operand of a single add insn.  The add with the
  259. smaller displacement is written so that it can be substituted into the
  260. address of a subsequent operation.
  261.    An example that uses a scratch register, from the same file,
  262. generates an equality comparison of a register and a large constant:
  263.      (define_split
  264.        [(set (match_operand:CC 0 "cc_reg_operand" "")
  265.              (compare:CC (match_operand:SI 1 "gen_reg_operand" "")
  266.                          (match_operand:SI 2 "non_short_cint_operand" "")))
  267.         (clobber (match_operand:SI 3 "gen_reg_operand" ""))]
  268.        "find_single_use (operands[0], insn, 0)
  269.         && (GET_CODE (*find_single_use (operands[0], insn, 0)) == EQ
  270.             || GET_CODE (*find_single_use (operands[0], insn, 0)) == NE)"
  271.        [(set (match_dup 3) (xor:SI (match_dup 1) (match_dup 4)))
  272.         (set (match_dup 0) (compare:CC (match_dup 3) (match_dup 5)))]
  273.        "
  274.      {
  275.        /* Get the constant we are comparing against, C, and see what it
  276.           looks like sign-extended to 16 bits.  Then see what constant
  277.           could be XOR'ed with C to get the sign-extended value.  */
  278.      
  279.        int c = INTVAL (operands[2]);
  280.        int sextc = (c << 16) >> 16;
  281.        int xorv = c ^ sextc;
  282.      
  283.        operands[4] = gen_rtx (CONST_INT, VOIDmode, xorv);
  284.        operands[5] = gen_rtx (CONST_INT, VOIDmode, sextc);
  285.      }")
  286.    To avoid confusion, don't write a single `define_split' that accepts
  287. some insns that match some `define_insn' as well as some insns that
  288. don't.  Instead, write two separate `define_split' definitions, one for
  289. the insns that are valid and one for the insns that are not valid.
  290. File: gcc.info,  Node: Insn Attributes,  Prev: Insn Splitting,  Up: Machine Desc
  291. Instruction Attributes
  292. ======================
  293.    In addition to describing the instruction supported by the target
  294. machine, the `md' file also defines a group of "attributes" and a set of
  295. values for each.  Every generated insn is assigned a value for each
  296. attribute.  One possible attribute would be the effect that the insn
  297. has on the machine's condition code.  This attribute can then be used
  298. by `NOTICE_UPDATE_CC' to track the condition codes.
  299. * Menu:
  300. * Defining Attributes:: Specifying attributes and their values.
  301. * Expressions::         Valid expressions for attribute values.
  302. * Tagging Insns::       Assigning attribute values to insns.
  303. * Attr Example::        An example of assigning attributes.
  304. * Insn Lengths::        Computing the length of insns.
  305. * Constant Attributes:: Defining attributes that are constant.
  306. * Delay Slots::         Defining delay slots required for a machine.
  307. * Function Units::      Specifying information for insn scheduling.
  308. File: gcc.info,  Node: Defining Attributes,  Next: Expressions,  Up: Insn Attributes
  309. Defining Attributes and their Values
  310. ------------------------------------
  311.    The `define_attr' expression is used to define each attribute
  312. required by the target machine.  It looks like:
  313.      (define_attr NAME LIST-OF-VALUES DEFAULT)
  314.    NAME is a string specifying the name of the attribute being defined.
  315.    LIST-OF-VALUES is either a string that specifies a comma-separated
  316. list of values that can be assigned to the attribute, or a null string
  317. to indicate that the attribute takes numeric values.
  318.    DEFAULT is an attribute expression that gives the value of this
  319. attribute for insns that match patterns whose definition does not
  320. include an explicit value for this attribute.  *Note Attr Example::,
  321. for more information on the handling of defaults.  *Note Constant
  322. Attributes::, for information on attributes that do not depend on any
  323. particular insn.
  324.    For each defined attribute, a number of definitions are written to
  325. the `insn-attr.h' file.  For cases where an explicit set of values is
  326. specified for an attribute, the following are defined:
  327.    * A `#define' is written for the symbol `HAVE_ATTR_NAME'.
  328.    * An enumeral class is defined for `attr_NAME' with elements of the
  329.      form `UPPER-NAME_UPPER-VALUE' where the attribute name and value
  330.      are first converted to upper case.
  331.    * A function `get_attr_NAME' is defined that is passed an insn and
  332.      returns the attribute value for that insn.
  333.    For example, if the following is present in the `md' file:
  334.      (define_attr "type" "branch,fp,load,store,arith" ...)
  335. the following lines will be written to the file `insn-attr.h'.
  336.      #define HAVE_ATTR_type
  337.      enum attr_type {TYPE_BRANCH, TYPE_FP, TYPE_LOAD,
  338.                       TYPE_STORE, TYPE_ARITH};
  339.      extern enum attr_type get_attr_type ();
  340.    If the attribute takes numeric values, no `enum' type will be
  341. defined and the function to obtain the attribute's value will return
  342. `int'.
  343. File: gcc.info,  Node: Expressions,  Next: Tagging Insns,  Prev: Defining Attributes,  Up: Insn Attributes
  344. Attribute Expressions
  345. ---------------------
  346.    RTL expressions used to define attributes use the codes described
  347. above plus a few specific to attribute definitions, to be discussed
  348. below.  Attribute value expressions must have one of the following
  349. forms:
  350. `(const_int I)'
  351.      The integer I specifies the value of a numeric attribute.  I must
  352.      be non-negative.
  353.      The value of a numeric attribute can be specified either with a
  354.      `const_int' or as an integer represented as a string in
  355.      `const_string', `eq_attr' (see below), and `set_attr' (*note
  356.      Tagging Insns::.) expressions.
  357. `(const_string VALUE)'
  358.      The string VALUE specifies a constant attribute value.  If VALUE
  359.      is specified as `"*"', it means that the default value of the
  360.      attribute is to be used for the insn containing this expression.
  361.      `"*"' obviously cannot be used in the DEFAULT expression of a
  362.      `define_attr'.
  363.      If the attribute whose value is being specified is numeric, VALUE
  364.      must be a string containing a non-negative integer (normally
  365.      `const_int' would be used in this case).  Otherwise, it must
  366.      contain one of the valid values for the attribute.
  367. `(if_then_else TEST TRUE-VALUE FALSE-VALUE)'
  368.      TEST specifies an attribute test, whose format is defined below.
  369.      The value of this expression is TRUE-VALUE if TEST is true,
  370.      otherwise it is FALSE-VALUE.
  371. `(cond [TEST1 VALUE1 ...] DEFAULT)'
  372.      The first operand of this expression is a vector containing an even
  373.      number of expressions and consisting of pairs of TEST and VALUE
  374.      expressions.  The value of the `cond' expression is that of the
  375.      VALUE corresponding to the first true TEST expression.  If none of
  376.      the TEST expressions are true, the value of the `cond' expression
  377.      is that of the DEFAULT expression.
  378.    TEST expressions can have one of the following forms:
  379. `(const_int I)'
  380.      This test is true if I is non-zero and false otherwise.
  381. `(not TEST)'
  382. `(ior TEST1 TEST2)'
  383. `(and TEST1 TEST2)'
  384.      These tests are true if the indicated logical function is true.
  385. `(match_operand:M N PRED CONSTRAINTS)'
  386.      This test is true if operand N of the insn whose attribute value
  387.      is being determined has mode M (this part of the test is ignored
  388.      if M is `VOIDmode') and the function specified by the string PRED
  389.      returns a non-zero value when passed operand N and mode M (this
  390.      part of the test is ignored if PRED is the null string).
  391.      The CONSTRAINTS operand is ignored and should be the null string.
  392. `(le ARITH1 ARITH2)'
  393. `(leu ARITH1 ARITH2)'
  394. `(lt ARITH1 ARITH2)'
  395. `(ltu ARITH1 ARITH2)'
  396. `(gt ARITH1 ARITH2)'
  397. `(gtu ARITH1 ARITH2)'
  398. `(ge ARITH1 ARITH2)'
  399. `(geu ARITH1 ARITH2)'
  400. `(ne ARITH1 ARITH2)'
  401. `(eq ARITH1 ARITH2)'
  402.      These tests are true if the indicated comparison of the two
  403.      arithmetic expressions is true.  Arithmetic expressions are formed
  404.      with `plus', `minus', `mult', `div', `mod', `abs', `neg', `and',
  405.      `ior', `xor', `not', `ashift', `lshiftrt', and `ashiftrt'
  406.      expressions.
  407.      `const_int' and `symbol_ref' are always valid terms (*note Insn
  408.      Lengths::.,for additional forms).  `symbol_ref' is a string
  409.      denoting a C expression that yields an `int' when evaluated by the
  410.      `get_attr_...' routine.  It should normally be a global variable.
  411. `(eq_attr NAME VALUE)'
  412.      NAME is a string specifying the name of an attribute.
  413.      VALUE is a string that is either a valid value for attribute NAME,
  414.      a comma-separated list of values, or `!' followed by a value or
  415.      list.  If VALUE does not begin with a `!', this test is true if
  416.      the value of the NAME attribute of the current insn is in the list
  417.      specified by VALUE.  If VALUE begins with a `!', this test is true
  418.      if the attribute's value is *not* in the specified list.
  419.      For example,
  420.           (eq_attr "type" "load,store")
  421.      is equivalent to
  422.           (ior (eq_attr "type" "load") (eq_attr "type" "store"))
  423.      If NAME specifies an attribute of `alternative', it refers to the
  424.      value of the compiler variable `which_alternative' (*note Output
  425.      Statement::.) and the values must be small integers.  For example,
  426.           (eq_attr "alternative" "2,3")
  427.      is equivalent to
  428.           (ior (eq (symbol_ref "which_alternative") (const_int 2))
  429.                (eq (symbol_ref "which_alternative") (const_int 3)))
  430.      Note that, for most attributes, an `eq_attr' test is simplified in
  431.      cases where the value of the attribute being tested is known for
  432.      all insns matching a particular pattern.  This is by far the most
  433.      common case.
  434. `(attr_flag NAME)'
  435.      The value of an `attr_flag' expression is true if the flag
  436.      specified by NAME is true for the `insn' currently being scheduled.
  437.      NAME is a string specifying one of a fixed set of flags to test.
  438.      Test the flags `forward' and `backward' to determine the direction
  439.      of a conditional branch.  Test the flags `very_likely', `likely',
  440.      `very_unlikely', and `unlikely' to determine if a conditional
  441.      branch is expected to be taken.
  442.      If the `very_likely' flag is true, then the `likely' flag is also
  443.      true.  Likewise for the `very_unlikely' and `unlikely' flags.
  444.      This example describes a conditional branch delay slot which can
  445.      be nullified for forward branches that are taken (annul-true) or
  446.      for backward branches which are not taken (annul-false).
  447.           (define_delay (eq_attr "type" "cbranch")
  448.             [(eq_attr "in_branch_delay" "true")
  449.              (and (eq_attr "in_branch_delay" "true")
  450.                   (attr_flag "forward"))
  451.              (and (eq_attr "in_branch_delay" "true")
  452.                   (attr_flag "backward"))])
  453.      The `forward' and `backward' flags are false if the current `insn'
  454.      being scheduled is not a conditional branch.
  455.      The `very_likely' and `likely' flags are true if the `insn' being
  456.      scheduled is not a conditional branch.  The The `very_unlikely'
  457.      and `unlikely' flags are false if the `insn' being scheduled is
  458.      not a conditional branch.
  459.      `attr_flag' is only used during delay slot scheduling and has no
  460.      meaning to other passes of the compiler.
  461. File: gcc.info,  Node: Tagging Insns,  Next: Attr Example,  Prev: Expressions,  Up: Insn Attributes
  462. Assigning Attribute Values to Insns
  463. -----------------------------------
  464.    The value assigned to an attribute of an insn is primarily
  465. determined by which pattern is matched by that insn (or which
  466. `define_peephole' generated it).  Every `define_insn' and
  467. `define_peephole' can have an optional last argument to specify the
  468. values of attributes for matching insns.  The value of any attribute
  469. not specified in a particular insn is set to the default value for that
  470. attribute, as specified in its `define_attr'.  Extensive use of default
  471. values for attributes permits the specification of the values for only
  472. one or two attributes in the definition of most insn patterns, as seen
  473. in the example in the next section.
  474.    The optional last argument of `define_insn' and `define_peephole' is
  475. a vector of expressions, each of which defines the value for a single
  476. attribute.  The most general way of assigning an attribute's value is
  477. to use a `set' expression whose first operand is an `attr' expression
  478. giving the name of the attribute being set.  The second operand of the
  479. `set' is an attribute expression (*note Expressions::.) giving the
  480. value of the attribute.
  481.    When the attribute value depends on the `alternative' attribute
  482. (i.e., which is the applicable alternative in the constraint of the
  483. insn), the `set_attr_alternative' expression can be used.  It allows
  484. the specification of a vector of attribute expressions, one for each
  485. alternative.
  486.    When the generality of arbitrary attribute expressions is not
  487. required, the simpler `set_attr' expression can be used, which allows
  488. specifying a string giving either a single attribute value or a list of
  489. attribute values, one for each alternative.
  490.    The form of each of the above specifications is shown below.  In
  491. each case, NAME is a string specifying the attribute to be set.
  492. `(set_attr NAME VALUE-STRING)'
  493.      VALUE-STRING is either a string giving the desired attribute value,
  494.      or a string containing a comma-separated list giving the values for
  495.      succeeding alternatives.  The number of elements must match the
  496.      number of alternatives in the constraint of the insn pattern.
  497.      Note that it may be useful to specify `*' for some alternative, in
  498.      which case the attribute will assume its default value for insns
  499.      matching that alternative.
  500. `(set_attr_alternative NAME [VALUE1 VALUE2 ...])'
  501.      Depending on the alternative of the insn, the value will be one of
  502.      the specified values.  This is a shorthand for using a `cond' with
  503.      tests on the `alternative' attribute.
  504. `(set (attr NAME) VALUE)'
  505.      The first operand of this `set' must be the special RTL expression
  506.      `attr', whose sole operand is a string giving the name of the
  507.      attribute being set.  VALUE is the value of the attribute.
  508.    The following shows three different ways of representing the same
  509. attribute value specification:
  510.      (set_attr "type" "load,store,arith")
  511.      
  512.      (set_attr_alternative "type"
  513.                            [(const_string "load") (const_string "store")
  514.                             (const_string "arith")])
  515.      
  516.      (set (attr "type")
  517.           (cond [(eq_attr "alternative" "1") (const_string "load")
  518.                  (eq_attr "alternative" "2") (const_string "store")]
  519.                 (const_string "arith")))
  520.    The `define_asm_attributes' expression provides a mechanism to
  521. specify the attributes assigned to insns produced from an `asm'
  522. statement.  It has the form:
  523.      (define_asm_attributes [ATTR-SETS])
  524. where ATTR-SETS is specified the same as for both the `define_insn' and
  525. the `define_peephole' expressions.
  526.    These values will typically be the "worst case" attribute values.
  527. For example, they might indicate that the condition code will be
  528. clobbered.
  529.    A specification for a `length' attribute is handled specially.  The
  530. way to compute the length of an `asm' insn is to multiply the length
  531. specified in the expression `define_asm_attributes' by the number of
  532. machine instructions specified in the `asm' statement, determined by
  533. counting the number of semicolons and newlines in the string.
  534. Therefore, the value of the `length' attribute specified in a
  535. `define_asm_attributes' should be the maximum possible length of a
  536. single machine instruction.
  537. File: gcc.info,  Node: Attr Example,  Next: Insn Lengths,  Prev: Tagging Insns,  Up: Insn Attributes
  538. Example of Attribute Specifications
  539. -----------------------------------
  540.    The judicious use of defaulting is important in the efficient use of
  541. insn attributes.  Typically, insns are divided into "types" and an
  542. attribute, customarily called `type', is used to represent this value.
  543. This attribute is normally used only to define the default value for
  544. other attributes.  An example will clarify this usage.
  545.    Assume we have a RISC machine with a condition code and in which only
  546. full-word operations are performed in registers.  Let us assume that we
  547. can divide all insns into loads, stores, (integer) arithmetic
  548. operations, floating point operations, and branches.
  549.    Here we will concern ourselves with determining the effect of an
  550. insn on the condition code and will limit ourselves to the following
  551. possible effects:  The condition code can be set unpredictably
  552. (clobbered), not be changed, be set to agree with the results of the
  553. operation, or only changed if the item previously set into the
  554. condition code has been modified.
  555.    Here is part of a sample `md' file for such a machine:
  556.      (define_attr "type" "load,store,arith,fp,branch" (const_string "arith"))
  557.      
  558.      (define_attr "cc" "clobber,unchanged,set,change0"
  559.                   (cond [(eq_attr "type" "load")
  560.                              (const_string "change0")
  561.                          (eq_attr "type" "store,branch")
  562.                              (const_string "unchanged")
  563.                          (eq_attr "type" "arith")
  564.                              (if_then_else (match_operand:SI 0 "" "")
  565.                                            (const_string "set")
  566.                                            (const_string "clobber"))]
  567.                         (const_string "clobber")))
  568.      
  569.      (define_insn ""
  570.        [(set (match_operand:SI 0 "general_operand" "=r,r,m")
  571.              (match_operand:SI 1 "general_operand" "r,m,r"))]
  572.        ""
  573.        "@
  574.         move %0,%1
  575.         load %0,%1
  576.         store %0,%1"
  577.        [(set_attr "type" "arith,load,store")])
  578.    Note that we assume in the above example that arithmetic operations
  579. performed on quantities smaller than a machine word clobber the
  580. condition code since they will set the condition code to a value
  581. corresponding to the full-word result.
  582. File: gcc.info,  Node: Insn Lengths,  Next: Constant Attributes,  Prev: Attr Example,  Up: Insn Attributes
  583. Computing the Length of an Insn
  584. -------------------------------
  585.    For many machines, multiple types of branch instructions are
  586. provided, each for different length branch displacements.  In most
  587. cases, the assembler will choose the correct instruction to use.
  588. However, when the assembler cannot do so, GCC can when a special
  589. attribute, the `length' attribute, is defined.  This attribute must be
  590. defined to have numeric values by specifying a null string in its
  591. `define_attr'.
  592.    In the case of the `length' attribute, two additional forms of
  593. arithmetic terms are allowed in test expressions:
  594. `(match_dup N)'
  595.      This refers to the address of operand N of the current insn, which
  596.      must be a `label_ref'.
  597. `(pc)'
  598.      This refers to the address of the *current* insn.  It might have
  599.      been more consistent with other usage to make this the address of
  600.      the *next* insn but this would be confusing because the length of
  601.      the current insn is to be computed.
  602.    For normal insns, the length will be determined by value of the
  603. `length' attribute.  In the case of `addr_vec' and `addr_diff_vec' insn
  604. patterns, the length is computed as the number of vectors multiplied by
  605. the size of each vector.
  606.    Lengths are measured in addressable storage units (bytes).
  607.    The following macros can be used to refine the length computation:
  608. `FIRST_INSN_ADDRESS'
  609.      When the `length' insn attribute is used, this macro specifies the
  610.      value to be assigned to the address of the first insn in a
  611.      function.  If not specified, 0 is used.
  612. `ADJUST_INSN_LENGTH (INSN, LENGTH)'
  613.      If defined, modifies the length assigned to instruction INSN as a
  614.      function of the context in which it is used.  LENGTH is an lvalue
  615.      that contains the initially computed length of the insn and should
  616.      be updated with the correct length of the insn.  If updating is
  617.      required, INSN must not be a varying-length insn.
  618.      This macro will normally not be required.  A case in which it is
  619.      required is the ROMP.  On this machine, the size of an `addr_vec'
  620.      insn must be increased by two to compensate for the fact that
  621.      alignment may be required.
  622.    The routine that returns `get_attr_length' (the value of the
  623. `length' attribute) can be used by the output routine to determine the
  624. form of the branch instruction to be written, as the example below
  625. illustrates.
  626.    As an example of the specification of variable-length branches,
  627. consider the IBM 360.  If we adopt the convention that a register will
  628. be set to the starting address of a function, we can jump to labels
  629. within 4k of the start using a four-byte instruction.  Otherwise, we
  630. need a six-byte sequence to load the address from memory and then
  631. branch to it.
  632.    On such a machine, a pattern for a branch instruction might be
  633. specified as follows:
  634.      (define_insn "jump"
  635.        [(set (pc)
  636.              (label_ref (match_operand 0 "" "")))]
  637.        ""
  638.        "*
  639.      {
  640.         return (get_attr_length (insn) == 4
  641.                 ? \"b %l0\" : \"l r15,=a(%l0); br r15\");
  642.      }"
  643.        [(set (attr "length") (if_then_else (lt (match_dup 0) (const_int 4096))
  644.                                            (const_int 4)
  645.                                            (const_int 6)))])
  646. File: gcc.info,  Node: Constant Attributes,  Next: Delay Slots,  Prev: Insn Lengths,  Up: Insn Attributes
  647. Constant Attributes
  648. -------------------
  649.    A special form of `define_attr', where the expression for the
  650. default value is a `const' expression, indicates an attribute that is
  651. constant for a given run of the compiler.  Constant attributes may be
  652. used to specify which variety of processor is used.  For example,
  653.      (define_attr "cpu" "m88100,m88110,m88000"
  654.       (const
  655.        (cond [(symbol_ref "TARGET_88100") (const_string "m88100")
  656.               (symbol_ref "TARGET_88110") (const_string "m88110")]
  657.              (const_string "m88000"))))
  658.      
  659.      (define_attr "memory" "fast,slow"
  660.       (const
  661.        (if_then_else (symbol_ref "TARGET_FAST_MEM")
  662.                      (const_string "fast")
  663.                      (const_string "slow"))))
  664.    The routine generated for constant attributes has no parameters as it
  665. does not depend on any particular insn.  RTL expressions used to define
  666. the value of a constant attribute may use the `symbol_ref' form, but
  667. may not use either the `match_operand' form or `eq_attr' forms
  668. involving insn attributes.
  669. File: gcc.info,  Node: Delay Slots,  Next: Function Units,  Prev: Constant Attributes,  Up: Insn Attributes
  670. Delay Slot Scheduling
  671. ---------------------
  672.    The insn attribute mechanism can be used to specify the requirements
  673. for delay slots, if any, on a target machine.  An instruction is said to
  674. require a "delay slot" if some instructions that are physically after
  675. the instruction are executed as if they were located before it.
  676. Classic examples are branch and call instructions, which often execute
  677. the following instruction before the branch or call is performed.
  678.    On some machines, conditional branch instructions can optionally
  679. "annul" instructions in the delay slot.  This means that the
  680. instruction will not be executed for certain branch outcomes.  Both
  681. instructions that annul if the branch is true and instructions that
  682. annul if the branch is false are supported.
  683.    Delay slot scheduling differs from instruction scheduling in that
  684. determining whether an instruction needs a delay slot is dependent only
  685. on the type of instruction being generated, not on data flow between the
  686. instructions.  See the next section for a discussion of data-dependent
  687. instruction scheduling.
  688.    The requirement of an insn needing one or more delay slots is
  689. indicated via the `define_delay' expression.  It has the following form:
  690.      (define_delay TEST
  691.                    [DELAY-1 ANNUL-TRUE-1 ANNUL-FALSE-1
  692.                     DELAY-2 ANNUL-TRUE-2 ANNUL-FALSE-2
  693.                     ...])
  694.    TEST is an attribute test that indicates whether this `define_delay'
  695. applies to a particular insn.  If so, the number of required delay
  696. slots is determined by the length of the vector specified as the second
  697. argument.  An insn placed in delay slot N must satisfy attribute test
  698. DELAY-N.  ANNUL-TRUE-N is an attribute test that specifies which insns
  699. may be annulled if the branch is true.  Similarly, ANNUL-FALSE-N
  700. specifies which insns in the delay slot may be annulled if the branch
  701. is false.  If annulling is not supported for that delay slot, `(nil)'
  702. should be coded.
  703.    For example, in the common case where branch and call insns require
  704. a single delay slot, which may contain any insn other than a branch or
  705. call, the following would be placed in the `md' file:
  706.      (define_delay (eq_attr "type" "branch,call")
  707.                    [(eq_attr "type" "!branch,call") (nil) (nil)])
  708.    Multiple `define_delay' expressions may be specified.  In this case,
  709. each such expression specifies different delay slot requirements and
  710. there must be no insn for which tests in two `define_delay' expressions
  711. are both true.
  712.    For example, if we have a machine that requires one delay slot for
  713. branches but two for calls,  no delay slot can contain a branch or call
  714. insn, and any valid insn in the delay slot for the branch can be
  715. annulled if the branch is true, we might represent this as follows:
  716.      (define_delay (eq_attr "type" "branch")
  717.         [(eq_attr "type" "!branch,call")
  718.          (eq_attr "type" "!branch,call")
  719.          (nil)])
  720.      
  721.      (define_delay (eq_attr "type" "call")
  722.                    [(eq_attr "type" "!branch,call") (nil) (nil)
  723.                     (eq_attr "type" "!branch,call") (nil) (nil)])
  724. File: gcc.info,  Node: Function Units,  Prev: Delay Slots,  Up: Insn Attributes
  725. Specifying Function Units
  726. -------------------------
  727.    On most RISC machines, there are instructions whose results are not
  728. available for a specific number of cycles.  Common cases are
  729. instructions that load data from memory.  On many machines, a pipeline
  730. stall will result if the data is referenced too soon after the load
  731. instruction.
  732.    In addition, many newer microprocessors have multiple function
  733. units, usually one for integer and one for floating point, and often
  734. will incur pipeline stalls when a result that is needed is not yet
  735. ready.
  736.    The descriptions in this section allow the specification of how much
  737. time must elapse between the execution of an instruction and the time
  738. when its result is used.  It also allows specification of when the
  739. execution of an instruction will delay execution of similar instructions
  740. due to function unit conflicts.
  741.    For the purposes of the specifications in this section, a machine is
  742. divided into "function units", each of which execute a specific class
  743. of instructions in first-in-first-out order.  Function units that
  744. accept one instruction each cycle and allow a result to be used in the
  745. succeeding instruction (usually via forwarding) need not be specified.
  746. Classic RISC microprocessors will normally have a single function unit,
  747. which we can call `memory'.  The newer "superscalar" processors will
  748. often have function units for floating point operations, usually at
  749. least a floating point adder and multiplier.
  750.    Each usage of a function units by a class of insns is specified with
  751. a `define_function_unit' expression, which looks like this:
  752.      (define_function_unit NAME MULTIPLICITY SIMULTANEITY
  753.                            TEST READY-DELAY ISSUE-DELAY
  754.                           [CONFLICT-LIST])
  755.    NAME is a string giving the name of the function unit.
  756.    MULTIPLICITY is an integer specifying the number of identical units
  757. in the processor.  If more than one unit is specified, they will be
  758. scheduled independently.  Only truly independent units should be
  759. counted; a pipelined unit should be specified as a single unit.  (The
  760. only common example of a machine that has multiple function units for a
  761. single instruction class that are truly independent and not pipelined
  762. are the two multiply and two increment units of the CDC 6600.)
  763.    SIMULTANEITY specifies the maximum number of insns that can be
  764. executing in each instance of the function unit simultaneously or zero
  765. if the unit is pipelined and has no limit.
  766.    All `define_function_unit' definitions referring to function unit
  767. NAME must have the same name and values for MULTIPLICITY and
  768. SIMULTANEITY.
  769.    TEST is an attribute test that selects the insns we are describing
  770. in this definition.  Note that an insn may use more than one function
  771. unit and a function unit may be specified in more than one
  772. `define_function_unit'.
  773.    READY-DELAY is an integer that specifies the number of cycles after
  774. which the result of the instruction can be used without introducing any
  775. stalls.
  776.    ISSUE-DELAY is an integer that specifies the number of cycles after
  777. the instruction matching the TEST expression begins using this unit
  778. until a subsequent instruction can begin.  A cost of N indicates an N-1
  779. cycle delay.  A subsequent instruction may also be delayed if an
  780. earlier instruction has a longer READY-DELAY value.  This blocking
  781. effect is computed using the SIMULTANEITY, READY-DELAY, ISSUE-DELAY,
  782. and CONFLICT-LIST terms.  For a normal non-pipelined function unit,
  783. SIMULTANEITY is one, the unit is taken to block for the READY-DELAY
  784. cycles of the executing insn, and smaller values of ISSUE-DELAY are
  785. ignored.
  786.    CONFLICT-LIST is an optional list giving detailed conflict costs for
  787. this unit.  If specified, it is a list of condition test expressions to
  788. be applied to insns chosen to execute in NAME following the particular
  789. insn matching TEST that is already executing in NAME.  For each insn in
  790. the list, ISSUE-DELAY specifies the conflict cost; for insns not in the
  791. list, the cost is zero.  If not specified, CONFLICT-LIST defaults to
  792. all instructions that use the function unit.
  793.    Typical uses of this vector are where a floating point function unit
  794. can pipeline either single- or double-precision operations, but not
  795. both, or where a memory unit can pipeline loads, but not stores, etc.
  796.    As an example, consider a classic RISC machine where the result of a
  797. load instruction is not available for two cycles (a single "delay"
  798. instruction is required) and where only one load instruction can be
  799. executed simultaneously.  This would be specified as:
  800.      (define_function_unit "memory" 1 1 (eq_attr "type" "load") 2 0)
  801.    For the case of a floating point function unit that can pipeline
  802. either single or double precision, but not both, the following could be
  803. specified:
  804.      (define_function_unit
  805.         "fp" 1 0 (eq_attr "type" "sp_fp") 4 4 [(eq_attr "type" "dp_fp")])
  806.      (define_function_unit
  807.         "fp" 1 0 (eq_attr "type" "dp_fp") 4 4 [(eq_attr "type" "sp_fp")])
  808.    *Note:* The scheduler attempts to avoid function unit conflicts and
  809. uses all the specifications in the `define_function_unit' expression.
  810. It has recently come to our attention that these specifications may not
  811. allow modeling of some of the newer "superscalar" processors that have
  812. insns using multiple pipelined units.  These insns will cause a
  813. potential conflict for the second unit used during their execution and
  814. there is no way of representing that conflict.  We welcome any examples
  815. of how function unit conflicts work in such processors and suggestions
  816. for their representation.
  817. File: gcc.info,  Node: Target Macros,  Next: Config,  Prev: Machine Desc,  Up: Top
  818. Target Description Macros
  819. *************************
  820.    In addition to the file `MACHINE.md', a machine description includes
  821. a C header file conventionally given the name `MACHINE.h'.  This header
  822. file defines numerous macros that convey the information about the
  823. target machine that does not fit into the scheme of the `.md' file.
  824. The file `tm.h' should be a link to `MACHINE.h'.  The header file
  825. `config.h' includes `tm.h' and most compiler source files include
  826. `config.h'.
  827. * Menu:
  828. * Driver::              Controlling how the driver runs the compilation passes.
  829. * Run-time Target::     Defining `-m' options like `-m68000' and `-m68020'.
  830. * Storage Layout::      Defining sizes and alignments of data.
  831. * Type Layout::         Defining sizes and properties of basic user data types.
  832. * Registers::           Naming and describing the hardware registers.
  833. * Register Classes::    Defining the classes of hardware registers.
  834. * Stack and Calling::   Defining which way the stack grows and by how much.
  835. * Varargs::        Defining the varargs macros.
  836. * Trampolines::         Code set up at run time to enter a nested function.
  837. * Library Calls::       Controlling how library routines are implicitly called.
  838. * Addressing Modes::    Defining addressing modes valid for memory operands.
  839. * Condition Code::      Defining how insns update the condition code.
  840. * Costs::               Defining relative costs of different operations.
  841. * Sections::            Dividing storage into text, data, and other sections.
  842. * PIC::            Macros for position independent code.
  843. * Assembler Format::    Defining how to write insns and pseudo-ops to output.
  844. * Debugging Info::      Defining the format of debugging output.
  845. * Cross-compilation::   Handling floating point for cross-compilers.
  846. * Misc::                Everything else.
  847.