home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / unix / info / gcc.i12 (.txt) < prev    next >
GNU Info File  |  1993-06-12  |  48KB  |  844 lines

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