home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 7 / FreshFishVol7.bin / bbs / gnu / gcc-2.3.3-src.lha / GNU / src / amiga / gcc-2.3.3 / gcc.info-13 (.txt) < prev    next >
GNU Info File  |  1994-02-06  |  45KB  |  807 lines

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