home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / msdos / djgpp / docs / gcc / gcc.i14 < prev    next >
Encoding:
GNU Info File  |  1993-05-29  |  45.6 KB  |  1,045 lines

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