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