home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 4 / FreshFish_May-June1994.bin / 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_i