home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / gnu / info / gcc.info-17 (.txt) < prev    next >
GNU Info File  |  1994-12-22  |  47KB  |  842 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, 1994 Free Software Foundation,
  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," "Funding for
  13. Free Software," and "Protect Your Freedom--Fight `Look And Feel'" are
  14. included exactly as in the original, and provided that the entire
  15. resulting derived work is distributed under the terms of a permission
  16. notice identical to this one.
  17.    Permission is granted to copy and distribute translations of this
  18. manual into another language, under the above conditions for modified
  19. versions, except that the sections entitled "GNU General Public
  20. License," "Funding for Free Software," and "Protect Your Freedom--Fight
  21. `Look And Feel'", and this permission notice, may be included in
  22. translations approved by the Free Software Foundation instead of in the
  23. original English.
  24. File: gcc.info,  Node: Expander Definitions,  Next: Insn Splitting,  Prev: Peephole Definitions,  Up: Machine Desc
  25. Defining RTL Sequences for Code Generation
  26. ==========================================
  27.    On some target machines, some standard pattern names for RTL
  28. generation cannot be handled with single insn, but a sequence of RTL
  29. insns can represent them.  For these target machines, you can write a
  30. `define_expand' to specify how to generate the sequence of RTL.
  31.    A `define_expand' is an RTL expression that looks almost like a
  32. `define_insn'; but, unlike the latter, a `define_expand' is used only
  33. for RTL generation and it can produce more than one RTL insn.
  34.    A `define_expand' RTX has four operands:
  35.    * The name.  Each `define_expand' must have a name, since the only
  36.      use for it is to refer to it by name.
  37.    * The RTL template.  This is just like the RTL template for a
  38.      `define_peephole' in that it is a vector of RTL expressions each
  39.      being one insn.
  40.    * The condition, a string containing a C expression.  This
  41.      expression is used to express how the availability of this pattern
  42.      depends on subclasses of target machine, selected by command-line
  43.      options when GNU CC is run.  This is just like the condition of a
  44.      `define_insn' that has a standard name.
  45.    * The preparation statements, a string containing zero or more C
  46.      statements which are to be executed before RTL code is generated
  47.      from the RTL template.
  48.      Usually these statements prepare temporary registers for use as
  49.      internal operands in the RTL template, but they can also generate
  50.      RTL insns directly by calling routines such as `emit_insn', etc.
  51.      Any such insns precede the ones that come from the RTL template.
  52.    Every RTL insn emitted by a `define_expand' must match some
  53. `define_insn' in the machine description.  Otherwise, the compiler will
  54. crash when trying to generate code for the insn or trying to optimize
  55.    The RTL template, in addition to controlling generation of RTL insns,
  56. also describes the operands that need to be specified when this pattern
  57. is used.  In particular, it gives a predicate for each operand.
  58.    A true operand, which needs to be specified in order to generate RTL
  59. from the pattern, should be described with a `match_operand' in its
  60. first occurrence in the RTL template.  This enters information on the
  61. operand's predicate into the tables that record such things.  GNU CC
  62. uses the information to preload the operand into a register if that is
  63. required for valid RTL code.  If the operand is referred to more than
  64. once, subsequent references should use `match_dup'.
  65.    The RTL template may also refer to internal "operands" which are
  66. temporary registers or labels used only within the sequence made by the
  67. `define_expand'.  Internal operands are substituted into the RTL
  68. template with `match_dup', never with `match_operand'.  The values of
  69. the internal operands are not passed in as arguments by the compiler
  70. when it requests use of this pattern.  Instead, they are computed
  71. within the pattern, in the preparation statements.  These statements
  72. compute the values and store them into the appropriate elements of
  73. `operands' so that `match_dup' can find them.
  74.    There are two special macros defined for use in the preparation
  75. statements: `DONE' and `FAIL'.  Use them with a following semicolon, as
  76. a statement.
  77. `DONE'
  78.      Use the `DONE' macro to end RTL generation for the pattern.  The
  79.      only RTL insns resulting from the pattern on this occasion will be
  80.      those already emitted by explicit calls to `emit_insn' within the
  81.      preparation statements; the RTL template will not be generated.
  82. `FAIL'
  83.      Make the pattern fail on this occasion.  When a pattern fails, it
  84.      means that the pattern was not truly available.  The calling
  85.      routines in the compiler will try other strategies for code
  86.      generation using other patterns.
  87.      Failure is currently supported only for binary (addition,
  88.      multiplication, shifting, etc.) and bitfield (`extv', `extzv', and
  89.      `insv') operations.
  90.    Here is an example, the definition of left-shift for the SPUR chip:
  91.      (define_expand "ashlsi3"
  92.        [(set (match_operand:SI 0 "register_operand" "")
  93.              (ashift:SI
  94.      (match_operand:SI 1 "register_operand" "")
  95.                (match_operand:SI 2 "nonmemory_operand" "")))]
  96.        ""
  97.        "
  98.      {
  99.        if (GET_CODE (operands[2]) != CONST_INT
  100.            || (unsigned) INTVAL (operands[2]) > 3)
  101.          FAIL;
  102.      }")
  103. This example uses `define_expand' so that it can generate an RTL insn
  104. for shifting when the shift-count is in the supported range of 0 to 3
  105. but fail in other cases where machine insns aren't available.  When it
  106. fails, the compiler tries another strategy using different patterns
  107. (such as, a library call).
  108.    If the compiler were able to handle nontrivial condition-strings in
  109. patterns with names, then it would be possible to use a `define_insn'
  110. in that case.  Here is another case (zero-extension on the 68000) which
  111. makes more use of the power of `define_expand':
  112.      (define_expand "zero_extendhisi2"
  113.        [(set (match_operand:SI 0 "general_operand" "")
  114.              (const_int 0))
  115.         (set (strict_low_part
  116.                (subreg:HI
  117.                  (match_dup 0)
  118.                  0))
  119.              (match_operand:HI 1 "general_operand" ""))]
  120.        ""
  121.        "operands[1] = make_safe_from (operands[1], operands[0]);")
  122. Here two RTL insns are generated, one to clear the entire output operand
  123. and the other to copy the input operand into its low half.  This
  124. sequence is incorrect if the input operand refers to [the old value of]
  125. the output operand, so the preparation statement makes sure this isn't
  126. so.  The function `make_safe_from' copies the `operands[1]' into a
  127. temporary register if it refers to `operands[0]'.  It does this by
  128. emitting another RTL insn.
  129.    Finally, a third example shows the use of an internal operand.
  130. Zero-extension on the SPUR chip is done by `and'-ing the result against
  131. a halfword mask.  But this mask cannot be represented by a `const_int'
  132. because the constant value is too large to be legitimate on this
  133. machine.  So it must be copied into a register with `force_reg' and
  134. then the register used in the `and'.
  135.      (define_expand "zero_extendhisi2"
  136.        [(set (match_operand:SI 0 "register_operand" "")
  137.              (and:SI (subreg:SI
  138.                        (match_operand:HI 1 "register_operand" "")
  139.                        0)
  140.                      (match_dup 2)))]
  141.        ""
  142.        "operands[2]
  143.           = force_reg (SImode, gen_rtx (CONST_INT,
  144.                                         VOIDmode, 65535)); ")
  145.    *Note:* If the `define_expand' is used to serve a standard binary or
  146. unary arithmetic operation or a bitfield operation, then the last insn
  147. it generates must not be a