home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: Alpha / Whiteline Alpha.iso / progtool / c / gcc / gcc258s.zoo / gcc.info-15 < prev    next >
Encoding:
GNU Info File  |  1993-11-30  |  47.8 KB  |  1,093 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.    Published by the Free Software Foundation 675 Massachusetts Avenue
  7. Cambridge, MA 02139 USA
  8.  
  9.    Copyright (C) 1988, 1989, 1992, 1993 Free Software Foundation, Inc.
  10.  
  11.    Permission is granted to make and distribute verbatim copies of this
  12. manual provided the copyright notice and this permission notice are
  13. preserved on all copies.
  14.  
  15.    Permission is granted to copy and distribute modified versions of
  16. this manual under the conditions for verbatim copying, provided also
  17. that the sections entitled "GNU General Public License" and "Protect
  18. Your Freedom--Fight `Look And Feel'" are included exactly as in the
  19. original, and provided that the entire resulting derived work is
  20. distributed under the terms of a permission notice identical to this
  21. one.
  22.  
  23.    Permission is granted to copy and distribute translations of this
  24. manual into another language, under the above conditions for modified
  25. versions, except that the sections entitled "GNU General Public
  26. License" and "Protect Your Freedom--Fight `Look And Feel'", and this
  27. permission notice, may be included in translations approved by the Free
  28. Software Foundation instead of in the original English.
  29.  
  30. File: gcc.info,  Node: Standard Names,  Next: Pattern Ordering,  Prev: Constraints,  Up: Machine Desc
  31.  
  32. Standard Pattern Names For Generation
  33. =====================================
  34.  
  35.    Here is a table of the instruction names that are meaningful in the
  36. RTL generation pass of the compiler.  Giving one of these names to an
  37. instruction pattern tells the RTL generation pass that it can use the
  38. pattern in to accomplish a certain task.
  39.  
  40. `movM'
  41.      Here M stands for a two-letter machine mode name, in lower case.
  42.      This instruction pattern moves data with that machine mode from
  43.      operand 1 to operand 0.  For example, `movsi' moves full-word data.
  44.  
  45.      If operand 0 is a `subreg' with mode M of a register whose own
  46.      mode is wider than M, the effect of this instruction is to store
  47.      the specified value in the part of the register that corresponds
  48.      to mode M.  The effect on the rest of the register is undefined.
  49.  
  50.      This class of patterns is special in several ways.  First of all,
  51.      each of these names *must* be defined, because there is no other
  52.      way to copy a datum from one place to another.
  53.  
  54.      Second, these patterns are not used solely in the RTL generation
  55.      pass.  Even the reload pass can generate move insns to copy values
  56.      from stack slots into temporary registers.  When it does so, one
  57.      of the operands is a hard register and the other is an operand
  58.      that can need to be reloaded into a register.
  59.  
  60.      Therefore, when given such a pair of operands, the pattern must
  61.      generate RTL which needs no reloading and needs no temporary
  62.      registers--no registers other than the operands.  For example, if
  63.      you support the pattern with a `define_expand', then in such a
  64.      case the `define_expand' mustn't call `force_reg' or any other such
  65.      function which might generate new pseudo registers.
  66.  
  67.      This requirement exists even for subword modes on a RISC machine
  68.      where fetching those modes from memory normally requires several
  69.      insns and some temporary registers.  Look in `spur.md' to see how
  70.      the requirement can be satisfied.
  71.  
  72.      During reload a memory reference with an invalid address may be
  73.      passed as an operand.  Such an address will be replaced with a
  74.      valid address later in the reload pass.  In this case, nothing may
  75.      be done with the address except to use it as it stands.  If it is
  76.      copied, it will not be replaced with a valid address.  No attempt
  77.      should be made to make such an address into a valid address and no
  78.      routine (such as `change_address') that will do so may be called.
  79.      Note that `general_operand' will fail when applied to such an
  80.      address.
  81.  
  82.      The global variable `reload_in_progress' (which must be explicitly
  83.      declared if required) can be used to determine whether such special
  84.      handling is required.
  85.  
  86.      The variety of operands that have reloads depends on the rest of
  87.      the machine description, but typically on a RISC machine these can
  88.      only be pseudo registers that did not get hard registers, while on
  89.      other machines explicit memory references will get optional
  90.      reloads.
  91.  
  92.      If a scratch register is required to move an object to or from
  93.      memory, it can be allocated using `gen_reg_rtx' prior to reload.
  94.      But this is impossible during and after reload.  If there are
  95.      cases needing scratch registers after reload, you must define
  96.      `SECONDARY_INPUT_RELOAD_CLASS' and perhaps also
  97.      `SECONDARY_OUTPUT_RELOAD_CLASS' to detect them, and provide
  98.      patterns `reload_inM' or `reload_outM' to handle them.  *Note
  99.      Register Classes::.
  100.  
  101.      The constraints on a `moveM' must permit moving any hard register
  102.      to any other hard register provided that `HARD_REGNO_MODE_OK'
  103.      permits mode M in both registers and `REGISTER_MOVE_COST' applied
  104.      to their classes returns a value of 2.
  105.  
  106.      It is obligatory to support floating point `moveM' instructions
  107.      into and out of any registers that can hold fixed point values,
  108.      because unions and structures (which have modes `SImode' or
  109.      `DImode') can be in those registers and they may have floating
  110.      point members.
  111.  
  112.      There may also be a need to support fixed point `moveM'
  113.      instructions in and out of floating point registers.
  114.      Unfortunately, I have forgotten why this was so, and I don't know
  115.      whether it is still true.  If `HARD_REGNO_MODE_OK' rejects fixed
  116.      point values in floating point registers, then the constraints of
  117.      the fixed point `moveM' instructions must be designed to avoid
  118.      ever trying to reload into a floating point register.
  119.  
  120. `reload_inM'
  121. `reload_outM'
  122.      Like `movM', but used when a scratch register is required to move
  123.      between operand 0 and operand 1.  Operand 2 describes the scratch
  124.      register.  See the discussion of the `SECONDARY_RELOAD_CLASS'
  125.      macro in *note Register Classes::..
  126.  
  127. `movstrictM'
  128.      Like `movM' except that if operand 0 is a `subreg' with mode M of
  129.      a register whose natural mode is wider, the `movstrictM'
  130.      instruction is guaranteed not to alter any of the register except
  131.      the part which belongs to mode M.
  132.  
  133. `load_multiple'
  134.      Load several consecutive memory locations into consecutive
  135.      registers.  Operand 0 is the first of the consecutive registers,
  136.      operand 1 is the first memory location, and operand 2 is a
  137.      constant: the number of consecutive registers.
  138.  
  139.      Define this only if the target machine really has such an
  140.      instruction; do not define this if the most efficient way of
  141.      loading consecutive registers from memory is to do them one at a
  142.      time.
  143.  
  144.      On some machines, there are restrictions as to which consecutive
  145.      registers can be stored into memory, such as particular starting or
  146.      ending register numbers or only a range of valid counts.  For those
  147.      machines, use a `define_expand' (*note Expander Definitions::.)
  148.      and make the pattern fail if the restrictions are not met.
  149.  
  150.      Write the generated insn as a `parallel' with elements being a
  151.      `set' of one register from the appropriate memory location (you may
  152.      also need `use' or `clobber' elements).  Use a `match_parallel'
  153.      (*note RTL Template::.) to recognize the insn.  See `a29k.md' and
  154.      `rs6000.md' for examples of the use of this insn pattern.
  155.  
  156. `store_multiple'
  157.      Similar to `load_multiple', but store several consecutive registers
  158.      into consecutive memory locations.  Operand 0 is the first of the
  159.      consecutive memory locations, operand 1 is the first register, and
  160.      operand 2 is a constant: the number of consecutive registers.
  161.  
  162. `addM3'
  163.      Add operand 2 and operand 1, storing the result in operand 0.  All
  164.      operands must have mode M.  This can be used even on two-address
  165.      machines, by means of constraints requiring operands 1 and 0 to be
  166.      the same location.
  167.  
  168. `subM3', `mulM3'
  169. `divM3', `udivM3', `modM3', `umodM3'
  170. `sminM3', `smaxM3', `uminM3', `umaxM3'
  171. `andM3', `iorM3', `xorM3'
  172.      Similar, for other arithmetic operations.
  173.  
  174. `mulhisi3'
  175.      Multiply operands 1 and 2, which have mode `HImode', and store a
  176.      `SImode' product in operand 0.
  177.  
  178. `mulqihi3', `mulsidi3'
  179.      Similar widening-multiplication instructions of other widths.
  180.  
  181. `umulqihi3', `umulhisi3', `umulsidi3'
  182.      Similar widening-multiplication instructions that do unsigned
  183.      multiplication.
  184.  
  185. `divmodM4'
  186.      Signed division that produces both a quotient and a remainder.
  187.      Operand 1 is divided by operand 2 to produce a quotient stored in
  188.      operand 0 and a remainder stored in operand 3.
  189.  
  190.      For machines with an instruction that produces both a quotient and
  191.      a remainder, provide a pattern for `divmodM4' but do not provide
  192.      patterns for `divM3' and `modM3'.  This allows optimization in the
  193.      relatively common case when both the quotient and remainder are
  194.      computed.
  195.  
  196.      If an instruction that just produces a quotient or just a remainder
  197.      exists and is more efficient than the instruction that produces
  198.      both, write the output routine of `divmodM4' to call
  199.      `find_reg_note' and look for a `REG_UNUSED' note on the quotient
  200.      or remainder and generate the appropriate instruction.
  201.  
  202. `udivmodM4'
  203.      Similar, but does unsigned division.
  204.  
  205. `ashlM3'
  206.      Arithmetic-shift operand 1 left by a number of bits specified by
  207.      operand 2, and store the result in operand 0.  Here M is the mode
  208.      of operand 0 and operand 1; operand 2's mode is specified by the
  209.      instruction pattern, and the compiler will convert the operand to
  210.      that mode before generating the instruction.
  211.  
  212. `ashrM3', `lshlM3', `lshrM3', `rotlM3', `rotrM3'
  213.      Other shift and rotate instructions, analogous to the `ashlM3'
  214.      instructions.
  215.  
  216.      Logical and arithmetic left shift are the same.  Machines that do
  217.      not allow negative shift counts often have only one instruction for
  218.      shifting left.  On such machines, you should define a pattern named
  219.      `ashlM3' and leave `lshlM3' undefined.
  220.  
  221. `negM2'
  222.      Negate operand 1 and store the result in operand 0.
  223.  
  224. `absM2'
  225.      Store the absolute value of operand 1 into operand 0.
  226.  
  227. `sqrtM2'
  228.      Store the square root of operand 1 into operand 0.
  229.  
  230.      The `sqrt' built-in function of C always uses the mode which
  231.      corresponds to the C data type `double'.
  232.  
  233. `ffsM2'
  234.      Store into operand 0 one plus the index of the least significant
  235.      1-bit of operand 1.  If operand 1 is zero, store zero.  M is the
  236.      mode of operand 0; operand 1's mode is specified by the instruction
  237.      pattern, and the compiler will convert the operand to that mode
  238.      before generating the instruction.
  239.  
  240.      The `ffs' built-in function of C always uses the mode which
  241.      corresponds to the C data type `int'.
  242.  
  243. `one_cmplM2'
  244.      Store the bitwise-complement of operand 1 into operand 0.
  245.  
  246. `cmpM'
  247.      Compare operand 0 and operand 1, and set the condition codes.  The
  248.      RTL pattern should look like this:
  249.  
  250.           (set (cc0) (compare (match_operand:M 0 ...)
  251.                               (match_operand:M 1 ...)))
  252.  
  253. `tstM'
  254.      Compare operand 0 against zero, and set the condition codes.  The
  255.      RTL pattern should look like this:
  256.  
  257.           (set (cc0) (match_operand:M 0 ...))
  258.  
  259.      `tstM' patterns should not be defined for machines that do not use
  260.      `(cc0)'.  Doing so would confuse the optimizer since it would no
  261.      longer be clear which `set' operations were comparisons.  The
  262.      `cmpM' patterns should be used instead.
  263.  
  264. `movstrM'
  265.      Block move instruction.  The addresses of the destination and
  266.      source strings are the first two operands, and both are in mode
  267.      `Pmode'.  The number of bytes to move is the third operand, in
  268.      mode M.
  269.  
  270.      The fourth operand is the known shared alignment of the source and
  271.      destination, in the form of a `const_int' rtx.  Thus, if the
  272.      compiler knows that both source and destination are word-aligned,
  273.      it may provide the value 4 for this operand.
  274.  
  275.      These patterns need not give special consideration to the
  276.      possibility that the source and destination strings might overlap.
  277.  
  278. `cmpstrM'
  279.      Block compare instruction, with five operands.  Operand 0 is the
  280.      output; it has mode M.  The remaining four operands are like the
  281.      operands of `movstrM'.  The two memory blocks specified are
  282.      compared byte by byte in lexicographic order.  The effect of the
  283.      instruction is to store a value in operand 0 whose sign indicates
  284.      the result of the comparison.
  285.  
  286.      Compute the length of a string, with three operands.  Operand 0 is
  287.      the result (of mode M), operand 1 is a `mem' referring to the
  288.      first character of the string, operand 2 is the character to
  289.      search for (normally zero), and operand 3 is a constant describing
  290.      the known alignment of the beginning of the string.
  291.  
  292. `floatMN2'
  293.      Convert signed integer operand 1 (valid for fixed point mode M) to
  294.      floating point mode N and store in operand 0 (which has mode N).
  295.  
  296. `floatunsMN2'
  297.      Convert unsigned integer operand 1 (valid for fixed point mode M)
  298.      to floating point mode N and store in operand 0 (which has mode N).
  299.  
  300. `fixMN2'
  301.      Convert operand 1 (valid for floating point mode M) to fixed point
  302.      mode N as a signed number and store in operand 0 (which has mode
  303.      N).  This instruction's result is defined only when the value of
  304.      operand 1 is an integer.
  305.  
  306. `fixunsMN2'
  307.      Convert operand 1 (valid for floating point mode M) to fixed point
  308.      mode N as an unsigned number and store in operand 0 (which has
  309.      mode N).  This instruction's result is defined only when the value
  310.      of operand 1 is an integer.
  311.  
  312. `ftruncM2'
  313.      Convert operand 1 (valid for floating point mode M) to an integer
  314.      value, still represented in floating point mode M, and store it in
  315.      operand 0 (valid for floating point mode M).
  316.  
  317. `fix_truncMN2'
  318.      Like `fixMN2' but works for any floating point value of mode M by
  319.      converting the value to an integer.
  320.  
  321. `fixuns_truncMN2'
  322.      Like `fixunsMN2' but works for any floating point value of mode M
  323.      by converting the value to an integer.
  324.  
  325. `truncMN'
  326.      Truncate operand 1 (valid for mode M) to mode N and store in
  327.      operand 0 (which has mode N).  Both modes must be fixed point or
  328.      both floating point.
  329.  
  330. `extendMN'
  331.      Sign-extend operand 1 (valid for mode M) to mode N and store in
  332.      operand 0 (which has mode N).  Both modes must be fixed point or
  333.      both floating point.
  334.  
  335. `zero_extendMN'
  336.      Zero-extend operand 1 (valid for mode M) to mode N and store in
  337.      operand 0 (which has mode N).  Both modes must be fixed point.
  338.  
  339. `extv'
  340.      Extract a bit field from operand 1 (a register or memory operand),
  341.      where operand 2 specifies the width in bits and operand 3 the
  342.      starting bit, and store it in operand 0.  Operand 0 must have mode
  343.      `word_mode'.  Operand 1 may have mode `byte_mode' or `word_mode';
  344.      often `word_mode' is allowed only for registers.  Operands 2 and 3
  345.      must be valid for `word_mode'.
  346.  
  347.      The RTL generation pass generates this instruction only with
  348.      constants for operands 2 and 3.
  349.  
  350.      The bit-field value is sign-extended to a full word integer before
  351.      it is stored in operand 0.
  352.  
  353. `extzv'
  354.      Like `extv' except that the bit-field value is zero-extended.
  355.  
  356. `insv'
  357.      Store operand 3 (which must be valid for `word_mode') into a bit
  358.      field in operand 0, where operand 1 specifies the width in bits and
  359.      operand 2 the starting bit.  Operand 0 may have mode `byte_mode' or
  360.      `word_mode'; often `word_mode' is allowed only for registers.
  361.      Operands 1 and 2 must be valid for `word_mode'.
  362.  
  363.      The RTL generation pass generates this instruction only with
  364.      constants for operands 1 and 2.
  365.  
  366. `sCOND'
  367.      Store zero or nonzero in the operand according to the condition
  368.      codes.  Value stored is nonzero iff the condition COND is true.
  369.      cOND is the name of a comparison operation expression code, such
  370.      as `eq', `lt' or `leu'.
  371.  
  372.      You specify the mode that the operand must have when you write the
  373.      `match_operand' expression.  The compiler automatically sees which
  374.      mode you have used and supplies an operand of that mode.
  375.  
  376.      The value stored for a true condition must have 1 as its low bit,
  377.      or else must be negative.  Otherwise the instruction is not
  378.      suitable and you should omit it from the machine description.  You
  379.      describe to the compiler exactly which value is stored by defining
  380.      the macro `STORE_FLAG_VALUE' (*note Misc::.).  If a description
  381.      cannot be found that can be used for all the `sCOND' patterns, you
  382.      should omit those operations from the machine description.
  383.  
  384.      These operations may fail, but should do so only in relatively
  385.      uncommon cases; if they would fail for common cases involving
  386.      integer comparisons, it is best to omit these patterns.
  387.  
  388.      If these operations are omitted, the compiler will usually
  389.      generate code that copies the constant one to the target and
  390.      branches around an assignment of zero to the target.  If this code
  391.      is more efficient than the potential instructions used for the
  392.      `sCOND' pattern followed by those required to convert the result
  393.      into a 1 or a zero in `SImode', you should omit the `sCOND'
  394.      operations from the machine description.
  395.  
  396. `bCOND'
  397.      Conditional branch instruction.  Operand 0 is a `label_ref' that
  398.      refers to the label to jump to.  Jump if the condition codes meet
  399.      condition COND.
  400.  
  401.      Some machines do not follow the model assumed here where a
  402.      comparison instruction is followed by a conditional branch
  403.      instruction.  In that case, the `cmpM' (and `tstM') patterns should
  404.      simply store the operands away and generate all the required insns
  405.      in a `define_expand' (*note Expander Definitions::.) for the
  406.      conditional branch operations.  All calls to expand `bCOND'
  407.      patterns are immediately preceded by calls to expand either a
  408.      `cmpM' pattern or a `tstM' pattern.
  409.  
  410.      Machines that use a pseudo register for the condition code value,
  411.      or where the mode used for the comparison depends on the condition
  412.      being tested, should also use the above mechanism.  *Note Jump
  413.      Patterns::
  414.  
  415.      The above discussion also applies to `sCOND' patterns.
  416.  
  417. `call'
  418.      Subroutine call instruction returning no value.  Operand 0 is the
  419.      function to call; operand 1 is the number of bytes of arguments
  420.      pushed (in mode `SImode', except it is normally a `const_int');
  421.      operand 2 is the number of registers used as operands.
  422.  
  423.      On most machines, operand 2 is not actually stored into the RTL
  424.      pattern.  It is supplied for the sake of some RISC machines which
  425.      need to put this information into the assembler code; they can put
  426.      it in the RTL instead of operand 1.
  427.  
  428.      Operand 0 should be a `mem' RTX whose address is the address of the
  429.      function.  Note, however, that this address can be a `symbol_ref'
  430.      expression even if it would not be a legitimate memory address on
  431.      the target machine.  If it is also not a valid argument for a call
  432.      instruction, the pattern for this operation should be a
  433.      `define_expand' (*note Expander Definitions::.) that places the
  434.      address into a register and uses that register in the call
  435.      instruction.
  436.  
  437. `call_value'
  438.      Subroutine call instruction returning a value.  Operand 0 is the
  439.      hard register in which the value is returned.  There are three more
  440.      operands, the same as the three operands of the `call' instruction
  441.      (but with numbers increased by one).
  442.  
  443.      Subroutines that return `BLKmode' objects use the `call' insn.
  444.  
  445. `call_pop', `call_value_pop'
  446.      Similar to `call' and `call_value', except used if defined and if
  447.      `RETURN_POPS_ARGS' is non-zero.  They should emit a `parallel'
  448.      that contains both the function call and a `set' to indicate the
  449.      adjustment made to the frame pointer.
  450.  
  451.      For machines where `RETURN_POPS_ARGS' can be non-zero, the use of
  452.      these patterns increases the number of functions for which the
  453.      frame pointer can be eliminated, if desired.
  454.  
  455. `untyped_call'
  456.      Subroutine call instruction returning a value of any type.
  457.      Operand 0 is the function to call; operand 1 is a memory location
  458.      where the result of calling the function is to be stored; operand
  459.      2 is a `parallel' expression where each element is a `set'
  460.      expression that indicates the saving of a function return value
  461.      into the result block.
  462.  
  463.      This instruction pattern should be defined to support
  464.      `__builtin_apply' on machines where special instructions are needed
  465.      to call a subroutine with arbitrary arguments or to save the value
  466.      returned.  This instruction pattern is required on machines that
  467.      have multiple registers that can hold a return value (i.e.
  468.      `FUNCTION_VALUE_REGNO_P' is true for more than one register).
  469.  
  470. `return'
  471.      Subroutine return instruction.  This instruction pattern name
  472.      should be defined only if a single instruction can do all the work
  473.      of returning from a function.
  474.  
  475.      Like the `movM' patterns, this pattern is also used after the RTL
  476.      generation phase.  In this case it is to support machines where
  477.      multiple instructions are usually needed to return from a
  478.      function, but some class of functions only requires one
  479.      instruction to implement a return.  Normally, the applicable
  480.      functions are those which do not need to save any registers or
  481.      allocate stack space.
  482.  
  483.      For such machines, the condition specified in this pattern should
  484.      only be true when `reload_completed' is non-zero and the function's
  485.      epilogue would only be a single instruction.  For machines with
  486.      register windows, the routine `leaf_function_p' may be used to
  487.      determine if a register window push is required.
  488.  
  489.      Machines that have conditional return instructions should define
  490.      patterns such as
  491.  
  492.           (define_insn ""
  493.             [(set (pc)
  494.                   (if_then_else (match_operator
  495.                                    0 "comparison_operator"
  496.                                    [(cc0) (const_int 0)])
  497.                                 (return)
  498.                                 (pc)))]
  499.             "CONDITION"
  500.             "...")
  501.  
  502.      where CONDITION would normally be the same condition specified on
  503.      the named `return' pattern.
  504.  
  505. `untyped_return'
  506.      Untyped subroutine return instruction.  This instruction pattern
  507.      should be defined to support `__builtin_return' on machines where
  508.      special instructions are needed to return a value of any type.
  509.  
  510.      Operand 0 is a memory location where the result of calling a
  511.      function with `__builtin_apply' is stored; operand 1 is a
  512.      `parallel' expression where each element is a `set' expression
  513.      that indicates the restoring of a function return value from the
  514.      result block.
  515.  
  516. `nop'
  517.      No-op instruction.  This instruction pattern name should always be
  518.      defined to output a no-op in assembler code.  `(const_int 0)' will
  519.      do as an RTL pattern.
  520.  
  521. `indirect_jump'
  522.      An instruction to jump to an address which is operand zero.  This
  523.      pattern name is mandatory on all machines.
  524.  
  525. `casesi'
  526.      Instruction to jump through a dispatch table, including bounds
  527.      checking.  This instruction takes five operands:
  528.  
  529.        1. The index to dispatch on, which has mode `SImode'.
  530.  
  531.        2. The lower bound for indices in the table, an integer constant.
  532.  
  533.        3. The total range of indices in the table--the largest index
  534.           minus the smallest one (both inclusive).
  535.  
  536.        4. A label that precedes the table itself.
  537.  
  538.        5. A label to jump to if the index has a value outside the
  539.           bounds.  (If the machine-description macro
  540.           `CASE_DROPS_THROUGH' is defined, then an out-of-bounds index
  541.           drops through to the code following the jump table instead of
  542.           jumping to this label.  In that case, this label is not
  543.           actually used by the `casesi' instruction, but it is always
  544.           provided as an operand.)
  545.  
  546.      The table is a `addr_vec' or `addr_diff_vec' inside of a
  547.      `jump_insn'.  The number of elements in the table is one plus the
  548.      difference between the upper bound and the lower bound.
  549.  
  550. `tablejump'
  551.      Instruction to jump to a variable address.  This is a low-level
  552.      capability which can be used to implement a dispatch table when
  553.      there is no `casesi' pattern.
  554.  
  555.      This pattern requires two operands: the address or offset, and a
  556.      label which should immediately precede the jump table.  If the
  557.      macro `CASE_VECTOR_PC_RELATIVE' is defined then the first operand
  558.      is an offset which counts from the address of the table;
  559.      otherwise, it is an absolute address to jump to.  In either case,
  560.      the first operand has mode `Pmode'.
  561.  
  562.      The `tablejump' insn is always the last insn before the jump table
  563.      it uses.  Its assembler code normally has no need to use the
  564.      second operand, but you should incorporate it in the RTL pattern so
  565.      that the jump optimizer will not delete the table as unreachable
  566.      code.
  567.  
  568. `save_stack_block'
  569. `save_stack_function'
  570. `save_stack_nonlocal'
  571. `restore_stack_block'
  572. `restore_stack_function'
  573. `restore_stack_nonlocal'
  574.      Most machines save and restore the stack pointer by copying it to
  575.      or from an object of mode `Pmode'.  Do not define these patterns on
  576.      such machines.
  577.  
  578.      Some machines require special handling for stack pointer saves and
  579.      restores.  On those machines, define the patterns corresponding to
  580.      the non-standard cases by using a `define_expand' (*note Expander
  581.      Definitions::.) that produces the required insns.  The three types
  582.      of saves and restores are:
  583.  
  584.        1. `save_stack_block' saves the stack pointer at the start of a
  585.           block that allocates a variable-sized object, and
  586.           `restore_stack_block' restores the stack pointer when the
  587.           block is exited.
  588.  
  589.        2. `save_stack_function' and `restore_stack_function' do a
  590.           similar job for the outermost block of a function and are
  591.           used when the function allocates variable-sized objects or
  592.           calls `alloca'.  Only the epilogue uses the restored stack
  593.           pointer, allowing a simpler save or restore sequence on some
  594.           machines.
  595.  
  596.        3. `save_stack_nonlocal' is used in functions that contain labels
  597.           branched to by nested functions.  It saves the stack pointer
  598.           in such a way that the inner function can use
  599.           `restore_stack_nonlocal' to restore the stack pointer.  The
  600.           compiler generates code to restore the frame and argument
  601.           pointer registers, but some machines require saving and
  602.           restoring additional data such as register window information
  603.           or stack backchains.  Place insns in these patterns to save
  604.           and restore any such required data.
  605.  
  606.      When saving the stack pointer, operand 0 is the save area and
  607.      operand 1 is the stack pointer.  The mode used to allocate the
  608.      save area is the mode of operand 0.  You must specify an integral
  609.      mode, or `VOIDmode' if no save area is needed for a particular
  610.      type of save (either because no save is needed or because a
  611.      machine-specific save area can be used).  Operand 0 is the stack
  612.      pointer and operand 1 is the save area for restore operations.  If
  613.      `save_stack_block' is defined, operand 0 must not be `VOIDmode'
  614.      since these saves can be arbitrarily nested.
  615.  
  616.      A save area is a `mem' that is at a constant offset from
  617.      `virtual_stack_vars_rtx' when the stack pointer is saved for use by
  618.      nonlocal gotos and a `reg' in the other two cases.
  619.  
  620. `allocate_stack'
  621.      Subtract (or add if `STACK_GROWS_DOWNWARD' is undefined) operand 0
  622.      from the stack pointer to create space for dynamically allocated
  623.      data.
  624.  
  625.      Do not define this pattern if all that must be done is the
  626.      subtraction.  Some machines require other operations such as stack
  627.      probes or maintaining the back chain.  Define this pattern to emit
  628.      those operations in addition to updating the stack pointer.
  629.  
  630. File: gcc.info,  Node: Pattern Ordering,  Next: Dependent Patterns,  Prev: Standard Names,  Up: Machine Desc
  631.  
  632. When the Order of Patterns Matters
  633. ==================================
  634.  
  635.    Sometimes an insn can match more than one instruction pattern.  Then
  636. the pattern that appears first in the machine description is the one
  637. used.  Therefore, more specific patterns (patterns that will match
  638. fewer things) and faster instructions (those that will produce better
  639. code when they do match) should usually go first in the description.
  640.  
  641.    In some cases the effect of ordering the patterns can be used to hide
  642. a pattern when it is not valid.  For example, the 68000 has an
  643. instruction for converting a fullword to floating point and another for
  644. converting a byte to floating point.  An instruction converting an
  645. integer to floating point could match either one.  We put the pattern
  646. to convert the fullword first to make sure that one will be used rather
  647. than the other.  (Otherwise a large integer might be generated as a
  648. single-byte immediate quantity, which would not work.) Instead of using
  649. this pattern ordering it would be possible to make the pattern for
  650. convert-a-byte smart enough to deal properly with any constant value.
  651.  
  652. File: gcc.info,  Node: Dependent Patterns,  Next: Jump Patterns,  Prev: Pattern Ordering,  Up: Machine Desc
  653.  
  654. Interdependence of Patterns
  655. ===========================
  656.  
  657.    Every machine description must have a named pattern for each of the
  658. conditional branch names `bCOND'.  The recognition template must always
  659. have the form
  660.  
  661.      (set (pc)
  662.           (if_then_else (COND (cc0) (const_int 0))
  663.                         (label_ref (match_operand 0 "" ""))
  664.                         (pc)))
  665.  
  666. In addition, every machine description must have an anonymous pattern
  667. for each of the possible reverse-conditional branches.  Their templates
  668. look like
  669.  
  670.      (set (pc)
  671.           (if_then_else (COND (cc0) (const_int 0))
  672.                         (pc)
  673.                         (label_ref (match_operand 0 "" ""))))
  674.  
  675. They are necessary because jump optimization can turn direct-conditional
  676. branches into reverse-conditional branches.
  677.  
  678.    It is often convenient to use the `match_operator' construct to
  679. reduce the number of patterns that must be specified for branches.  For
  680. example,
  681.  
  682.      (define_insn ""
  683.        [(set (pc)
  684.              (if_then_else (match_operator 0 "comparison_operator"
  685.                                            [(cc0) (const_int 0)])
  686.                            (pc)
  687.                            (label_ref (match_operand 1 "" ""))))]
  688.        "CONDITION"
  689.        "...")
  690.  
  691.    In some cases machines support instructions identical except for the
  692. machine mode of one or more operands.  For example, there may be
  693. "sign-extend halfword" and "sign-extend byte" instructions whose
  694. patterns are
  695.  
  696.      (set (match_operand:SI 0 ...)
  697.           (extend:SI (match_operand:HI 1 ...)))
  698.      
  699.      (set (match_operand:SI 0 ...)
  700.           (extend:SI (match_operand:QI 1 ...)))
  701.  
  702. Constant integers do not specify a machine mode, so an instruction to
  703. extend a constant value could match either pattern.  The pattern it
  704. actually will match is the one that appears first in the file.  For
  705. correct results, this must be the one for the widest possible mode
  706. (`HImode', here).  If the pattern matches the `QImode' instruction, the
  707. results will be incorrect if the constant value does not actually fit
  708. that mode.
  709.  
  710.    Such instructions to extend constants are rarely generated because
  711. they are optimized away, but they do occasionally happen in nonoptimized
  712. compilations.
  713.  
  714.    If a constraint in a pattern allows a constant, the reload pass may
  715. replace a register with a constant permitted by the constraint in some
  716. cases.  Similarly for memory references.  You must ensure that the
  717. predicate permits all objects allowed by the constraints to prevent the
  718. compiler from crashing.
  719.  
  720.    Because of this substitution, you should not provide separate
  721. patterns for increment and decrement instructions.  Instead, they
  722. should be generated from the same pattern that supports
  723. register-register add insns by examining the operands and generating
  724. the appropriate machine instruction.
  725.  
  726. File: gcc.info,  Node: Jump Patterns,  Next: Insn Canonicalizations,  Prev: Dependent Patterns,  Up: Machine Desc
  727.  
  728. Defining Jump Instruction Patterns
  729. ==================================
  730.  
  731.    For most machines, GNU CC assumes that the machine has a condition
  732. code.  A comparison insn sets the condition code, recording the results
  733. of both signed and unsigned comparison of the given operands.  A
  734. separate branch insn tests the condition code and branches or not
  735. according its value.  The branch insns come in distinct signed and
  736. unsigned flavors.  Many common machines, such as the Vax, the 68000 and
  737. the 32000, work this way.
  738.  
  739.    Some machines have distinct signed and unsigned compare
  740. instructions, and only one set of conditional branch instructions.  The
  741. easiest way to handle these machines is to treat them just like the
  742. others until the final stage where assembly code is written.  At this
  743. time, when outputting code for the compare instruction, peek ahead at
  744. the following branch using `next_cc0_user (insn)'.  (The variable
  745. `insn' refers to the insn being output, in the output-writing code in
  746. an instruction pattern.)  If the RTL says that is an unsigned branch,
  747. output an unsigned compare; otherwise output a signed compare.  When
  748. the branch itself is output, you can treat signed and unsigned branches
  749. identically.
  750.  
  751.    The reason you can do this is that GNU CC always generates a pair of
  752. consecutive RTL insns, possibly separated by `note' insns, one to set
  753. the condition code and one to test it, and keeps the pair inviolate
  754. until the end.
  755.  
  756.    To go with this technique, you must define the machine-description
  757. macro `NOTICE_UPDATE_CC' to do `CC_STATUS_INIT'; in other words, no
  758. compare instruction is superfluous.
  759.  
  760.    Some machines have compare-and-branch instructions and no condition
  761. code.  A similar technique works for them.  When it is time to "output"
  762. a compare instruction, record its operands in two static variables.
  763. When outputting the branch-on-condition-code instruction that follows,
  764. actually output a compare-and-branch instruction that uses the
  765. remembered operands.
  766.  
  767.    It also works to define patterns for compare-and-branch instructions.
  768. In optimizing compilation, the pair of compare and branch instructions
  769. will be combined according to these patterns.  But this does not happen
  770. if optimization is not requested.  So you must use one of the solutions
  771. above in addition to any special patterns you define.
  772.  
  773.    In many RISC machines, most instructions do not affect the condition
  774. code and there may not even be a separate condition code register.  On
  775. these machines, the restriction that the definition and use of the
  776. condition code be adjacent insns is not necessary and can prevent
  777. important optimizations.  For example, on the IBM RS/6000, there is a
  778. delay for taken branches unless the condition code register is set three
  779. instructions earlier than the conditional branch.  The instruction
  780. scheduler cannot perform this optimization if it is not permitted to
  781. separate the definition and use of the condition code register.
  782.  
  783.    On these machines, do not use `(cc0)', but instead use a register to
  784. represent the condition code.  If there is a specific condition code
  785. register in the machine, use a hard register.  If the condition code or
  786. comparison result can be placed in any general register, or if there are
  787. multiple condition registers, use a pseudo register.
  788.  
  789.    On some machines, the type of branch instruction generated may
  790. depend on the way the condition code was produced; for example, on the
  791. 68k and Sparc, setting the condition code directly from an add or
  792. subtract instruction does not clear the overflow bit the way that a test
  793. instruction does, so a different branch instruction must be used for
  794. some conditional branches.  For machines that use `(cc0)', the set and
  795. use of the condition code must be adjacent (separated only by `note'
  796. insns) allowing flags in `cc_status' to be used.  (*Note Condition
  797. Code::.)  Also, the comparison and branch insns can be located from
  798. each other by using the functions `prev_cc0_setter' and `next_cc0_user'.
  799.  
  800.    However, this is not true on machines that do not use `(cc0)'.  On
  801. those machines, no assumptions can be made about the adjacency of the
  802. compare and branch insns and the above methods cannot be used.  Instead,
  803. we use the machine mode of the condition code register to record
  804. different formats of the condition code register.
  805.  
  806.    Registers used to store the condition code value should have a mode
  807. that is in class `MODE_CC'.  Normally, it will be `CCmode'.  If
  808. additional modes are required (as for the add example mentioned above in
  809. the Sparc), define the macro `EXTRA_CC_MODES' to list the additional
  810. modes required (*note Condition Code::.).  Also define `EXTRA_CC_NAMES'
  811. to list the names of those modes and `SELECT_CC_MODE' to choose a mode
  812. given an operand of a compare.
  813.  
  814.    If it is known during RTL generation that a different mode will be
  815. required (for example, if the machine has separate compare instructions
  816. for signed and unsigned quantities, like most IBM processors), they can
  817. be specified at that time.
  818.  
  819.    If the cases that require different modes would be made by
  820. instruction combination, the macro `SELECT_CC_MODE' determines which
  821. machine mode should be used for the comparison result.  The patterns
  822. should be written using that mode.  To support the case of the add on
  823. the Sparc discussed above, we have the pattern
  824.  
  825.      (define_insn ""
  826.        [(set (reg:CC_NOOV 0)
  827.              (compare:CC_NOOV
  828.                (plus:SI (match_operand:SI 0 "register_operand" "%r")
  829.                         (match_operand:SI 1 "arith_operand" "rI"))
  830.                (const_int 0)))]
  831.        ""
  832.        "...")
  833.  
  834.    The `SELECT_CC_MODE' macro on the Sparc returns `CC_NOOVmode' for
  835. comparisons whose argument is a `plus'.
  836.  
  837. File: gcc.info,  Node: Insn Canonicalizations,  Next: Peephole Definitions,  Prev: Jump Patterns,  Up: Machine Desc
  838.  
  839. Canonicalization of Instructions
  840. ================================
  841.  
  842.    There are often cases where multiple RTL expressions could represent
  843. an operation performed by a single machine instruction.  This situation
  844. is most commonly encountered with logical, branch, and
  845. multiply-accumulate instructions.  In such cases, the compiler attempts
  846. to convert these multiple RTL expressions into a single canonical form
  847. to reduce the number of insn patterns required.
  848.  
  849.    In addition to algebraic simplifications, following canonicalizations
  850. are performed:
  851.  
  852.    * For commutative and comparison operators, a constant is always
  853.      made the second operand.  If a machine only supports a constant as
  854.      the second operand, only patterns that match a constant in the
  855.      second operand need be supplied.
  856.  
  857.      For these operators, if only one operand is a `neg', `not',
  858.      `mult', `plus', or `minus' expression, it will be the first
  859.      operand.
  860.  
  861.    * For the `compare' operator, a constant is always the second operand
  862.      on machines where `cc0' is used (*note Jump Patterns::.).  On other
  863.      machines, there are rare cases where the compiler might want to
  864.      construct a `compare' with a constant as the first operand.
  865.      However, these cases are not common enough for it to be worthwhile
  866.      to provide a pattern matching a constant as the first operand
  867.      unless the machine actually has such an instruction.
  868.  
  869.      An operand of `neg', `not', `mult', `plus', or `minus' is made the
  870.      first operand under the same conditions as above.
  871.  
  872.    * `(minus X (const_int N))' is converted to `(plus X (const_int
  873.      -N))'.
  874.  
  875.    * Within address computations (i.e., inside `mem'), a left shift is
  876.      converted into the appropriate multiplication by a power of two.
  877.  
  878.      De`Morgan's Law is used to move bitwise negation inside a bitwise
  879.      logical-and or logical-or operation.  If this results in only one
  880.      operand being a `not' expression, it will be the first one.
  881.  
  882.      A machine that has an instruction that performs a bitwise
  883.      logical-and of one operand with the bitwise negation of the other
  884.      should specify the pattern for that instruction as
  885.  
  886.           (define_insn ""
  887.             [(set (match_operand:M 0 ...)
  888.                   (and:M (not:M (match_operand:M 1 ...))
  889.                                (match_operand:M 2 ...)))]
  890.             "..."
  891.             "...")
  892.  
  893.      Similarly, a pattern for a "NAND" instruction should be written
  894.  
  895.           (define_insn ""
  896.             [(set (match_operand:M 0 ...)
  897.                   (ior:M (not:M (match_operand:M 1 ...))
  898.                                (not:M (match_operand:M 2 ...))))]
  899.             "..."
  900.             "...")
  901.  
  902.      In both cases, it is not necessary to include patterns for the many
  903.      logically equivalent RTL expressions.
  904.  
  905.    * The only possible RTL expressions involving both bitwise
  906.      exclusive-or and bitwise negation are `(xor:M X Y)' and `(not:M
  907.      (xor:M X Y))'.
  908.  
  909.    * The sum of three items, one of which is a constant, will only
  910.      appear in the form
  911.  
  912.           (plus:M (plus:M X Y) CONSTANT)
  913.  
  914.    * On machines that do not use `cc0', `(compare X (const_int 0))'
  915.      will be converted to X.
  916.  
  917.    * Equality comparisons of a group of bits (usually a single bit)
  918.      with zero will be written using `zero_extract' rather than the
  919.      equivalent `and' or `sign_extract' operations.
  920.  
  921. File: gcc.info,  Node: Peephole Definitions,  Next: Expander Definitions,  Prev: Insn Canonicalizations,  Up: Machine Desc
  922.  
  923. Machine-Specific Peephole Optimizers
  924. ====================================
  925.  
  926.    In addition to instruction patterns the `md' file may contain
  927. definitions of machine-specific peephole optimizations.
  928.  
  929.    The combiner does not notice certain peephole optimizations when the
  930. data flow in the program does not suggest that it should try them.  For
  931. example, sometimes two consecutive insns related in purpose can be
  932. combined even though the second one does not appear to use a register
  933. computed in the first one.  A machine-specific peephole optimizer can
  934. detect such opportunities.
  935.  
  936.    A definition looks like this:
  937.  
  938.      (define_peephole
  939.        [INSN-PATTERN-1
  940.         INSN-PATTERN-2
  941.         ...]
  942.        "CONDITION"
  943.        "TEMPLATE"
  944.        "OPTIONAL INSN-ATTRIBUTES")
  945.  
  946. The last string operand may be omitted if you are not using any
  947. machine-specific information in this machine description.  If present,
  948. it must obey the same rules as in a `define_insn'.
  949.  
  950.    In this skeleton, INSN-PATTERN-1 and so on are patterns to match
  951. consecutive insns.  The optimization applies to a sequence of insns when
  952. INSN-PATTERN-1 matches the first one, INSN-PATTERN-2 matches the next,
  953. and so on.
  954.  
  955.    Each of the insns matched by a peephole must also match a
  956. `define_insn'.  Peepholes are checked only at the last stage just
  957. before code generation, and only optionally.  Therefore, any insn which
  958. would match a peephole but no `define_insn' will cause a crash in code
  959. generation in an unoptimized compilation, or at various optimization
  960. stages.
  961.  
  962.    The operands of the insns are matched with `match_operands',
  963. `match_operator', and `match_dup', as usual.  What is not usual is that
  964. the operand numbers apply to all the insn patterns in the definition.
  965. So, you can check for identical operands in two insns by using
  966. `match_operand' in one insn and `match_dup' in the other.
  967.  
  968.    The operand constraints used in `match_operand' patterns do not have
  969. any direct effect on the applicability of the peephole, but they will
  970. be validated afterward, so make sure your constraints are general enough
  971. to apply whenever the peephole matches.  If the peephole matches but
  972. the constraints are not satisfied, the compiler will crash.
  973.  
  974.    It is safe to omit constraints in all the operands of the peephole;
  975. or you can write constraints which serve as a double-check on the
  976. criteria previously tested.
  977.  
  978.    Once a sequence of insns matches the patterns, the CONDITION is
  979. checked.  This is a C expression which makes the final decision whether
  980. to perform the optimization (we do so if the expression is nonzero).  If
  981. CONDITION is omitted (in other words, the string is empty) then the
  982. optimization is applied to every sequence of insns that matches the
  983. patterns.
  984.  
  985.    The defined peephole optimizations are applied after register
  986. allocation is complete.  Therefore, the peephole definition can check
  987. which operands have ended up in which kinds of registers, just by
  988. looking at the operands.
  989.  
  990.    The way to refer to the operands in CONDITION is to write
  991. `operands[I]' for operand number I (as matched by `(match_operand I
  992. ...)').  Use the variable `insn' to refer to the last of the insns
  993. being matched; use `prev_nonnote_insn' to find the preceding insns.
  994.  
  995.    When optimizing computations with intermediate results, you can use
  996. CONDITION to match only when the intermediate results are not used
  997. elsewhere.  Use the C expression `dead_or_set_p (INSN, OP)', where INSN
  998. is the insn in which you expect the value to be used for the last time
  999. (from the value of `insn', together with use of `prev_nonnote_insn'),
  1000. and OP is the intermediate value (from `operands[I]').
  1001.  
  1002.    Applying the optimization means replacing the sequence of insns with
  1003. one new insn.  The TEMPLATE controls ultimate output of assembler code
  1004. for this combined insn.  It works exactly like the template of a
  1005. `define_insn'.  Operand numbers in this template are the same ones used
  1006. in matching the original sequence of insns.
  1007.  
  1008.    The result of a defined peephole optimizer does not need to match
  1009. any of the insn patterns in the machine description; it does not even
  1010. have an opportunity to match them.  The peephole optimizer definition
  1011. itself serves as the insn pattern to control how the insn is output.
  1012.  
  1013.    Defined peephole optimizers are run as assembler code is being
  1014. output, so the insns they produce are never combined or rearranged in
  1015. any way.
  1016.  
  1017.    Here is an example, taken from the 68000 machine description:
  1018.  
  1019.      (define_peephole
  1020.        [(set (reg:SI 15) (plus:SI (reg:SI 15) (const_int 4)))
  1021.         (set (match_operand:DF 0 "register_operand" "=f")
  1022.              (match_operand:DF 1 "register_operand" "ad"))]
  1023.        "FP_REG_P (operands[0]) && ! FP_REG_P (operands[1])"
  1024.        "*
  1025.      {
  1026.        rtx xoperands[2];
  1027.        xoperands[1] = gen_rtx (REG, SImode, REGNO (operands[1]) + 1);
  1028.      #ifdef MOTOROLA
  1029.        output_asm_insn (\"move.l %1,(sp)\", xoperands);
  1030.        output_asm_insn (\"move.l %1,-(sp)\", operands);
  1031.        return \"fmove.d (sp)+,%0\";
  1032.      #else
  1033.        output_asm_insn (\"movel %1,sp@\", xoperands);
  1034.        output_asm_insn (\"movel %1,sp@-\", operands);
  1035.        return \"fmoved sp@+,%0\";
  1036.      #endif
  1037.      }
  1038.      ")
  1039.  
  1040.    The effect of this optimization is to change
  1041.  
  1042.      jbsr _foobar
  1043.      addql #4,sp
  1044.      movel d1,sp@-
  1045.      movel d0,sp@-
  1046.      fmoved sp@+,fp0
  1047.  
  1048. into
  1049.  
  1050.      jbsr _foobar
  1051.      movel d1,sp@
  1052.      movel d0,sp@-
  1053.      fmoved sp@+,fp0
  1054.  
  1055.    INSN-PATTERN-1 and so on look *almost* like the second operand of
  1056. `define_insn'.  There is one important difference: the second operand
  1057. of `define_insn' consists of one or more RTX's enclosed in square
  1058. brackets.  Usually, there is only one: then the same action can be
  1059. written as an element of a `define_peephole'.  But when there are
  1060. multiple actions in a `define_insn', they are implicitly enclosed in a
  1061. `parallel'.  Then you must explicitly write the `parallel', and the
  1062. square brackets within it, in the `define_peephole'.  Thus, if an insn
  1063. pattern looks like this,
  1064.  
  1065.      (define_insn "divmodsi4"
  1066.        [(set (match_operand:SI 0 "general_operand" "=d")
  1067.              (div:SI (match_operand:SI 1 "general_operand" "0")
  1068.                      (match_operand:SI 2 "general_operand" "dmsK")))
  1069.         (set (match_operand:SI 3 "general_operand" "=d")
  1070.              (mod:SI (match_dup 1) (match_dup 2)))]
  1071.        "TARGET_68020"
  1072.        "divsl%.l %2,%3:%0")
  1073.  
  1074. then the way to mention this insn in a peephole is as follows:
  1075.  
  1076.      (define_peephole
  1077.        [...
  1078.         (parallel
  1079.          [(set (match_operand:SI 0 "general_operand" "=d")
  1080.                (div:SI (match_operand:SI 1 "general_operand" "0")
  1081.                        (match_operand:SI 2 "general_operand" "dmsK")))
  1082.           (set (match_operand:SI 3 "general_operand" "=d")
  1083.                (mod:SI (match_dup 1) (match_dup 2)))])
  1084.         ...]
  1085.        ...)
  1086.  
  1087.