home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / unix / info / gcc.i11 (.txt) < prev    next >
GNU Info File  |  1993-06-12  |  46KB  |  767 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: Patterns,  Next: Example,  Prev: Machine Desc,  Up: Machine Desc
  21. Everything about Instruction Patterns
  22. =====================================
  23.    Each instruction pattern contains an incomplete RTL expression, with
  24. pieces to be filled in later, operand constraints that restrict how the
  25. pieces can be filled in, and an output pattern or C code to generate
  26. the assembler output, all wrapped up in a `define_insn' expression.
  27.    A `define_insn' is an RTL expression containing four or five
  28. operands:
  29.   1. An optional name.  The presence of a name indicate that this
  30.      instruction pattern can perform a certain standard job for the
  31.      RTL-generation pass of the compiler.  This pass knows certain
  32.      names and will use the instruction patterns with those names, if
  33.      the names are defined in the machine description.
  34.      The absence of a name is indicated by writing an empty string
  35.      where the name should go.  Nameless instruction patterns are never
  36.      used for generating RTL code, but they may permit several simpler
  37.      insns to be combined later on.
  38.      Names that are not thus known and used in RTL-generation have no
  39.      effect; they are equivalent to no name at all.
  40.   2. The "RTL template" (*note RTL Template::.) is a vector of
  41.      incomplete RTL expressions which show what the instruction should
  42.      look like.  It is incomplete because it may contain
  43.      `match_operand', `match_operator', and `match_dup' expressions
  44.      that stand for operands of the instruction.
  45.      If the vector has only one element, that element is the template
  46.      for the instruction pattern.  If the vector has multiple elements,
  47.      then the instruction pattern is a `parallel' expression containing
  48.      the elements described.
  49.   3. A condition.  This is a string which contains a C expression that
  50.      is the final test to decide whether an insn body matches this
  51.      pattern.
  52.      For a named pattern, the condition (if present) may not depend on
  53.      the data in the insn being matched, but only the
  54.      target-machine-type flags.  The compiler needs to test these
  55.      conditions during initialization in order to learn exactly which
  56.      named instructions are available in a particular run.
  57.      For nameless patterns, the condition is applied only when matching
  58.      an individual insn, and only after the insn has matched the
  59.      pattern's recognition template.  The insn's operands may be found
  60.      in the vector `operands'.
  61.   4. The "output template": a string that says how to output matching
  62.      insns as assembler code.  `%' in this string specifies where to
  63.      substitute the value of an operand.  *Note Output Template::.
  64.      When simple substitution isn't general enough, you can specify a
  65.      piece of C code to compute the output.  *Note Output Statement::.
  66.   5. Optionally, a vector containing the values of attributes for insns
  67.      matching this pattern.  *Note Insn Attributes::.
  68. File: gcc.info,  Node: Example,  Next: RTL Template,  Prev: Patterns,  Up: Machine Desc
  69. Example of `define_insn'
  70. ========================
  71.    Here is an actual example of an instruction pattern, for the
  72. 68000/68020.
  73.      (define_insn "tstsi"
  74.        [(set (cc0)
  75.              (match_operand:SI 0 "general_operand" "rm"))]
  76.        ""
  77.        "*
  78.      { if (TARGET_68020 || ! ADDRESS_REG_P (operands[0]))
  79.          return \"tstl %0\";
  80.        return \"cmpl #0,%0\"; }")
  81.    This is an instruction that sets the condition codes based on the
  82. value of a general operand.  It has no condition, so any insn whose RTL
  83. description has the form shown may be handled according to this
  84. pattern.  The name `tstsi' means "test a `SImode' value" and tells the
  85. RTL generation pass that, when it is necessary to test such a value, an
  86. insn to do so can be constructed using this pattern.
  87.    The output control string is a piece of C code which chooses which
  88. output template to return based on the kind of operand and the specific
  89. type of CPU for which code is being generated.
  90.    `"rm"' is an operand constraint.  Its meaning is explained below.
  91. File: gcc.info,  Node: RTL Template,  Next: Output Template,  Prev: Example,  Up: Machine Desc
  92. RTL Template for Generating and Recognizing Insns
  93. =================================================
  94.    The RTL template is used to define which insns match the particular
  95. pattern and how to find their operands.  For named patterns, the RTL
  96. template also says how to construct an insn from specified operands.
  97.    Construction involves substituting specified operands into a copy of
  98. the template.  Matching involves determining the values that serve as
  99. the operands in the insn being matched.  Both of these activities are
  100. controlled by special expression types that direct matching and
  101. substitution of the operands.
  102. `(match_operand:M N PREDICATE CONSTRAINT)'
  103.      This expression is a placeholder for operand number N of the insn.
  104.       When constructing an insn, operand number N will be substituted
  105.      at this point.  When matching an insn, whatever appears at this
  106.      position in the insn will be taken as operand number N; but it
  107.      must satisfy PREDICATE or this instruction pattern will not match
  108.      at all.
  109.      Operand numbers must be chosen consecutively counting from zero in
  110.      each instruction pattern.  There may be only one `match_operand'
  111.      expression in the pattern for each operand number.  Usually
  112.      operands are numbered in the order of appearance in `match_operand'
  113.      expressions.
  114.      PREDICATE is a string that is the name of a C function that
  115.      accepts two arguments, an expression and a machine mode.  During
  116.      matching, the function will be called with the putative operand as
  117.      the expression and M as the mode argument (if M is not specified,
  118.      `VOIDmode' will be used, which normally causes PREDICATE to accept
  119.      any mode).  If it returns zero, this instruction pattern fails to
  120.      match. PREDICATE may be an empty string; then it means no test is
  121.      to be done on the operand, so anything which occurs in this
  122.      position is valid.
  123.      Most of the time, PREDICATE will reject modes other than M--but
  124.      not always.  For example, the predicate `address_operand' uses M
  125.      as the mode of memory ref that the address should be valid for.
  126.      Many predicates accept `const_int' nodes even though their mode is
  127.      `VOIDmode'.
  128.      CONSTRAINT controls reloading and the choice of the best register
  129.      class to use for a value, as explained later (*note
  130.      Constraints::.).
  131.      People are often unclear on the difference between the constraint
  132.      and the predicate.  The predicate helps decide whether a given
  133.      insn matches the pattern.  The constraint plays no role in this
  134.      decision; instead, it controls various decisions in the case of an
  135.      insn which does match.
  136.      On CISC machines, PREDICATE is most often `"general_operand"'.
  137.      This function checks that the putative operand is either a
  138.      constant, a register or a memory reference, and that it is valid
  139.      for mode M.
  140.      For an operand that must be a register, PREDICATE should be
  141.      `"register_operand"'.  It would be valid to use
  142.      `"general_operand"', since the reload pass would copy any
  143.      non-register operands through registers, but this would make GNU
  144.      CC do extra work, it would prevent invariant operands (such as
  145.      constant) from being removed from loops, and it would prevent the
  146.      register allocator from doing the best possible job.  On RISC
  147.      machines, it is usually most efficient to allow PREDICATE to
  148.      accept only objects that the constraints allow.
  149.      For an operand that must be a constant, either use
  150.      `"immediate_operand"' for PREDICATE, or make the instruction
  151.      pattern's extra condition require a constant, or both.  You cannot
  152.      expect the constraints to do this work!  If the constraints allow
  153.      only constants, but the predicate allows something else, the
  154.      compiler will crash when that case arises.
  155. `(match_scratch:M N CONSTRAINT)'
  156.      This expression is also a placeholder for operand number N and
  157.      indicates that operand must be a `scratch' or `reg' expression.
  158.      When matching patterns, this is completely equivalent to
  159.           (match_operand:M N "scratch_operand" PRED)
  160.      but, when generating RTL, it produces a (`scratch':M) expression.
  161.      If the last few expressions in a `parallel' are `clobber'
  162.      expressions whose operands are either a hard register or
  163.      `match_scratch', the combiner can add them when necessary. *Note
  164.      Side Effects::.
  165. `(match_dup N)'
  166.      This expression is also a placeholder for operand number N. It is
  167.      used when the operand needs to appear more than once in the insn.
  168.      In construction, `match_dup' behaves exactly like `match_operand':
  169.      the operand is substituted into the insn being constructed.  But
  170.      in matching, `match_dup' behaves differently. It assumes that
  171.      operand number N has already been determined by a `match_operand'
  172.      appearing earlier in the recognition template, and it matches only
  173.      an identical-looking expression.
  174. `(match_operator:M N PREDICATE [OPERANDS...])'
  175.      This pattern is a kind of placeholder for a variable RTL expression
  176.      code.
  177.      When constructing an insn, it stands for an RTL expression whose
  178.      expression code is taken from that of operand N, and whose
  179.      operands are constructed from the patterns OPERANDS.
  180.      When matching an expression, it matches an expression if the
  181.      function PREDICATE returns nonzero on that expression *and* the
  182.      patterns OPERANDS match the operands of the expression.
  183.      Suppose that the function `commutative_operator' is defined as
  184.      follows, to match any expression whose operator is one of the
  185.      commutative arithmetic operators of RTL and whose mode is MODE:
  186.           int
  187.           commutative_operator (x, mode)
  188.                rtx x;
  189.                enum machine_mode mode;
  190.           {
  191.             enum rtx_code code = GET_CODE (x);
  192.             if (GET_MODE (x) != mode)
  193.               return 0;
  194.             return GET_RTX_CLASS (code) == 'c' || code == EQ || code == NE;
  195.           }
  196.      Then the following pattern will match any RTL expression consisting
  197.      of a commutative operator applied to two general operands:
  198.           (match_operator:SI 3 "commutative_operator"
  199.             [(match_operand:SI 1 "general_operand" "g")
  200.              (match_operand:SI 2 "general_operand" "g")])
  201.      Here the vector `[OPERANDS...]' contains two patterns because the
  202.      expressions to be matched all contain two operands.
  203.      When this pattern does match, the two operands of the commutative
  204.      operator are recorded as operands 1 and 2 of the insn.  (This is
  205.      done by the two instances of `match_operand'.)  Operand 3 of the
  206.      insn will be the entire commutative expression: use `GET_CODE
  207.      (operands[3])' to see which commutative operator was used.
  208.      The machine mode M of `match_operator' works like that of
  209.      `match_operand': it is passed as the second argument to the
  210.      predicate function, and that function is solely responsible for
  211.      deciding whether the expression to be matched "has" that mode.
  212.      When constructing an insn, argument 3 of the gen-function will
  213.      specify the operation (i.e. the expression code) for the
  214.      expression to be made.  It should be an RTL expression, whose
  215.      expression code is copied into a new expression whose operands are
  216.      arguments 1 and 2 of the gen-function.  The subexpressions of
  217.      argument 3 are not used; only its expression code matters.
  218.      When `match_operator' is used in a pattern for matching an insn,
  219.      it usually best if the operand number of the `match_operator' is
  220.      higher than that of the actual operands of the insn.  This improves
  221.      register allocation because the register allocator often looks at
  222.      operands 1 and 2 of insns to see if it can do register tying.
  223.      There is no way to specify constraints in `match_operator'.  The
  224.      operand of the insn which corresponds to the `match_operator'
  225.      never has any constraints because it is never reloaded as a whole.
  226.      However, if parts of its OPERANDS are matched by `match_operand'
  227.      patterns, those parts may have constraints of their own.
  228. `(match_op_dup:M N[OPERANDS...])'
  229.      Like `match_dup', except that it applies to operators instead of
  230.      operands.  When constructing an insn, operand number N will be
  231.      substituted at this point.  But in matching, `match_op_dup' behaves
  232.      differently.  It assumes that operand number N has already been
  233.      determined by a `match_operator' appearing earlier in the
  234.      recognition template, and it matches only an identical-looking
  235.      expression.
  236. `(match_parallel N PREDICATE [SUBPAT...])'
  237.      This pattern is a placeholder for an insn that consists of a
  238.      `parallel' expression with a variable number of elements.  This
  239.      expression should only appear at the top level of an insn pattern.
  240.      When constructing an insn, operand number N will be substituted at
  241.      this point.  When matching an insn, it matches if the body of the
  242.      insn is a `parallel' expression with at least as many elements as
  243.      the vector of SUBPAT expressions in the `match_parallel', if each
  244.      SUBPAT matches the corresponding element of the `parallel', *and*
  245.      the function PREDICATE returns nonzero on the `parallel' that is
  246.      the body of the insn.  It is the responsibility of the predicate
  247.      to validate elements of the `parallel' beyond those listed in the
  248.      `match_parallel'.
  249.      A typical use of `match_parallel' is to match load and store
  250.      multiple expressions, which can contains a variable number of
  251.      elements in a `parallel'.  For example,
  252.           (define_insn ""
  253.             [(match_parallel 0 "load_multiple_operation"
  254.                              [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
  255.                                    (match_operand:SI 2 "memory_operand" "m"))
  256.                               (use (reg:SI 179))
  257.                               (clobber (reg:SI 179))])]
  258.             ""
  259.             "loadm 0,0,%1,%2")
  260.      This example comes from `a29k.md'.  The function
  261.      `load_multiple_operations' is defined in `a29k.c' and checks that
  262.      subsequent elements in the `parallel' are the same as the `set' in
  263.      the pattern, except that they are referencing subsequent registers
  264.      and memory locations.
  265.      An insn that matches this pattern might look like:
  266.           (parallel [(set (reg:SI 20) (mem:SI (reg:SI 100)))
  267.                      (use (reg:SI 179))
  268.                      (clobber (reg:SI 179))
  269.                      (set (reg:SI 21) (mem:SI (plus:SI (reg:SI 100) (const_int 4))))
  270.                      (set (reg:SI 22) (mem:SI (plus:SI (reg:SI 100) (const_int 8))))])
  271. `(match_par_dup N [SUBPAT...])'
  272.      Like `match_op_dup', but for `match_parallel' instead of
  273.      `match_operator'.
  274. `(address (match_operand:M N "address_operand" ""))'
  275.      This complex of expressions is a placeholder for an operand number
  276.      N in a "load address" instruction: an operand which specifies a
  277.      memory location in the usual way, but for which the actual operand
  278.      value used is the address of the location, not the contents of the
  279.      location.
  280.      `address' expressions never appear in RTL code, only in machine
  281.      descriptions.  And they are used only in machine descriptions that
  282.      do not use the operand constraint feature.  When operand
  283.      constraints are in use, the letter `p' in the constraint serves
  284.      this purpose.
  285.      M is the machine mode of the *memory location being addressed*,
  286.      not the machine mode of the address itself.  That mode is always
  287.      the same on a given target machine (it is `Pmode', which normally
  288.      is `SImode'), so there is no point in mentioning it; thus, no
  289.      machine mode is written in the `address' expression.  If some day
  290.      support is added for machines in which addresses of different
  291.      kinds of objects appear differently or are used differently (such
  292.      as the PDP-10), different formats would perhaps need different
  293.      machine modes and these modes might be written in the `address'
  294.      expression.
  295. File: gcc.info,  Node: Output Template,  Next: Output Statement,  Prev: RTL Template,  Up: Machine Desc
  296. Output Templates and Operand Substitution
  297. =========================================
  298.    The "output template" is a string which specifies how to output the
  299. assembler code for an instruction pattern.  Most of the template is a
  300. fixed string which is output literally.  The character `%' is used to
  301. specify where to substitute an operand; it can also be used to identify
  302. places where different variants of the assembler require different
  303. syntax.
  304.    In the simplest case, a `%' followed by a digit N says to output
  305. operand N at that point in the string.
  306.    `%' followed by a letter and a digit says to output an operand in an
  307. alternate fashion.  Four letters have standard, built-in meanings
  308. described below.  The machine description macro `PRINT_OPERAND' can
  309. define additional letters with nonstandard meanings.
  310.    `%cDIGIT' can be used to substitute an operand that is a constant
  311. value without the syntax that normally indicates an immediate operand.
  312.    `%nDIGIT' is like `%cDIGIT' except that the value of the constant is
  313. negated before printing.
  314.    `%aDIGIT' can be used to substitute an operand as if it were a
  315. memory reference, with the actual operand treated as the address.  This
  316. may be useful when outputting a "load address" instruction, because
  317. often the assembler syntax for such an instruction requires you to
  318. write the operand as if it were a memory reference.
  319.    `%lDIGIT' is used to substitute a `label_ref' into a jump
  320. instruction.
  321.    `%=' outputs a number which is unique to each instruction in the
  322. entire compilation.  This is useful for making local labels to be
  323. referred to more than once in a single template that generates multiple
  324. assembler instructions.
  325.    `%' followed by a punctuation character specifies a substitution that
  326. does not use an operand.  Only one case is standard: `%%' outputs a `%'
  327. into the assembler code.  Other nonstandard cases can be defined in the
  328. `PRINT_OPERAND' macro.  You must also define which punctuation
  329. characters are valid with the `PRINT_OPERAND_PUNCT_VALID_P' macro.
  330.    The template may generate multiple assembler instructions.  Write
  331. the text for the instructions, with `\;' between them.
  332.    When the RTL contains two operands which are required by constraint
  333. to match each other, the output template must refer only to the
  334. lower-numbered operand. Matching operands are not always identical, and
  335. the rest of the compiler arranges to put the proper RTL expression for
  336. printing into the lower-numbered operand.
  337.    One use of nonstandard letters or punctuation following `%' is to
  338. distinguish between different assembler languages for the same machine;
  339. for example, Motorola syntax versus MIT syntax for the 68000.  Motorola
  340. syntax requires periods in most opcode names, while MIT syntax does
  341. not.  For example, the opcode `movel' in MIT syntax is `move.l' in
  342. Motorola syntax.  The same file of patterns is used for both kinds of
  343. output syntax, but the character sequence `%.' is used in each place
  344. where Motorola syntax wants a period.  The `PRINT_OPERAND' macro for
  345. Motorola syntax defines the sequence to output a period; the macro for
  346. MIT syntax defines it to do nothing.
  347. File: gcc.info,  Node: Output Statement,  Next: Constraints,  Prev: Output Template,  Up: Machine Desc
  348. C Statements for Generating Assembler Output
  349. ============================================
  350.    Often a single fixed template string cannot produce correct and
  351. efficient assembler code for all the cases that are recognized by a
  352. single instruction pattern.  For example, the opcodes may depend on the
  353. kinds of operands; or some unfortunate combinations of operands may
  354. require extra machine instructions.
  355.    If the output control string starts with a `@', then it is actually
  356. a series of templates, each on a separate line.  (Blank lines and
  357. leading spaces and tabs are ignored.)  The templates correspond to the
  358. pattern's constraint alternatives (*note Multi-Alternative::.).  For
  359. example, if a target machine has a two-address add instruction `addr'
  360. to add into a register and another `addm' to add a register to memory,
  361. you might write this pattern:
  362.      (define_insn "addsi3"
  363.        [(set (match_operand:SI 0 "general_operand" "=r,m")
  364.              (plus:SI (match_operand:SI 1 "general_operand" "0,0")
  365.                       (match_operand:SI 2 "general_operand" "g,r")))]
  366.        ""
  367.        "@
  368.         addr %2,%0
  369.         addm %2,%0")
  370.    If the output control string starts with a `*', then it is not an
  371. output template but rather a piece of C program that should compute a
  372. template.  It should execute a `return' statement to return the
  373. template-string you want.  Most such templates use C string literals,
  374. which require doublequote characters to delimit them.  To include these
  375. doublequote characters in the string, prefix each one with `\'.
  376.    The operands may be found in the array `operands', whose C data type
  377. is `rtx []'.
  378.    It is very common to select different ways of generating assembler
  379. code based on whether an immediate operand is within a certain range. 
  380. Be careful when doing this, because the result of `INTVAL' is an
  381. integer on the host machine.  If the host machine has more bits in an
  382. `int' than the target machine has in the mode in which the constant
  383. will be used, then some of the bits you get from `INTVAL' will be
  384. superfluous.  For proper results, you must carefully disregard the
  385. values of those bits.
  386.    It is possible to output an assembler instruction and then go on to
  387. output or compute more of them, using the subroutine `output_asm_insn'.
  388.  This receives two arguments: a template-string and a vector of
  389. operands.  The vector may be `operands', or it may be another array of
  390. `rtx' that you declare locally and initialize yourself.
  391.    When an insn pattern has multiple alternatives in its constraints,
  392. often the appearance of the assembler code is determined mostly by
  393. which alternative was matched.  When this is so, the C code can test
  394. the variable `which_alternative', which is the ordinal number of the
  395. alternative that was actually satisfied (0 for the first, 1 for the
  396. second alternative, etc.).
  397.    For example, suppose there are two opcodes for storing zero, `clrreg'
  398. for registers and `clrmem' for memory locations.  Here is how a pattern
  399. could use `which_alternative' to choose between them:
  400.      (define_insn ""
  401.        [(set (match_operand:SI 0 "general_operand" "=r,m")
  402.              (const_int 0))]
  403.        ""
  404.        "*
  405.        return (which_alternative == 0
  406.                ? \"clrreg %0\" : \"clrmem %0\");
  407.        ")
  408.    The example above, where the assembler code to generate was *solely*
  409. determined by the alternative, could also have been specified as
  410. follows, having the output control string start with a `@':
  411.      (define_insn ""
  412.        [(set (match_operand:SI 0 "general_operand" "=r,m")
  413.              (const_int 0))]
  414.        ""
  415.        "@
  416.         clrreg %0
  417.         clrmem %0")
  418. File: gcc.info,  Node: Constraints,  Next: Standard Names,  Prev: Output Statement,  Up: Machine Desc
  419. Operand Constraints
  420. ===================
  421.    Each `match_operand' in an instruction pattern can specify a
  422. constraint for the type of operands allowed.  Constraints can say
  423. whether an operand may be in a register, and which kinds of register;
  424. whether the operand can be a memory reference, and which kinds of
  425. address; whether the operand may be an immediate constant, and which
  426. possible values it may have.  Constraints can also require two operands
  427. to match.
  428. * Menu:
  429. * Simple Constraints::  Basic use of constraints.
  430. * Multi-Alternative::   When an insn has two alternative constraint-patterns.
  431. * Class Preferences::   Constraints guide which hard register to put things in.
  432. * Modifiers::           More precise control over effects of constraints.
  433. * No Constraints::      Describing a clean machine without constraints.
  434. File: gcc.info,  Node: Simple Constraints,  Next: Multi-Alternative,  Prev: Constraints,  Up: Constraints
  435. Simple Constraints
  436. ------------------
  437.    The simplest kind of constraint is a string full of letters, each of
  438. which describes one kind of operand that is permitted.  Here are the
  439. letters that are allowed:
  440.      A memory operand is allowed, with any kind of address that the
  441.      machine supports in general.
  442.      A memory operand is allowed, but only if the address is
  443.      "offsettable".  This means that adding a small integer (actually,
  444.      the width in bytes of the operand, as determined by its machine
  445.      mode) may be added to the address and the result is also a valid
  446.      memory address.
  447.      For example, an address which is constant is offsettable; so is an
  448.      address that is the sum of a register and a constant (as long as a
  449.      slightly larger constant is also within the range of
  450.      address-offsets supported by the machine); but an autoincrement or
  451.      autodecrement address is not offsettable.  More complicated
  452.      indirect/indexed addresses may or may not be offsettable depending
  453.      on the other addressing modes that the machine supports.
  454.      Note that in an output operand which can be matched by another
  455.      operand, the constraint letter `o' is valid only when accompanied
  456.      by both `<' (if the target machine has predecrement addressing)
  457.      and `>' (if the target machine has preincrement addressing).
  458.      A memory operand that is not offsettable.  In other words,
  459.      anything that would fit the `m' constraint but not the `o'
  460.      constraint.
  461.      A memory operand with autodecrement addressing (either
  462.      predecrement or postdecrement) is allowed.
  463.      A memory operand with autoincrement addressing (either
  464.      preincrement or postincrement) is allowed.
  465.      A register operand is allowed provided that it is in a general
  466.      register.
  467. `d', `a', `f', ...
  468.      Other letters can be defined in machine-dependent fashion to stand
  469.      for particular classes of registers.  `d', `a' and `f' are defined
  470.      on the 68000/68020 to stand for data, address and floating point
  471.      registers.
  472.      An immediate integer operand (one with constant value) is allowed.
  473.      This includes symbolic constants whose values will be known only at
  474.      assembly time.
  475.      An immediate integer operand with a known numeric value is allowed.
  476.      Many systems cannot support assembly-time constants for operands
  477.      less than a word wide.  Constraints for these operands should use
  478.      `n' rather than `i'.
  479. `I', `J', `K', ... `P'
  480.      Other letters in the range `I' through `P' may be defined in a
  481.      machine-dependent fashion to permit immediate integer operands with
  482.      explicit integer values in specified ranges.  For example, on the
  483.      68000, `I' is defined to stand for the range of values 1 to 8.
  484.      This is the range permitted as a shift count in the shift
  485.      instructions.
  486.      An immediate floating operand (expression code `const_double') is
  487.      allowed, but only if the target floating point format is the same
  488.      as that of the host machine (on which the compiler is running).
  489.      An immediate floating operand (expression code `const_double') is
  490.      allowed.
  491. `G', `H'
  492.      `G' and `H' may be defined in a machine-dependent fashion to
  493.      permit immediate floating operands in particular ranges of values.
  494.      An immediate integer operand whose value is not an explicit
  495.      integer is allowed.
  496.      This might appear strange; if an insn allows a constant operand
  497.      with a value not known at compile time, it certainly must allow
  498.      any known value.  So why use `s' instead of `i'?  Sometimes it
  499.      allows better code to be generated.
  500.      For example, on the 68000 in a fullword instruction it is possible
  501.      to use an immediate operand; but if the immediate value is between
  502.      -128 and 127, better code results from loading the value into a
  503.      register and using the register.  This is because the load into
  504.      the register can be done with a `moveq' instruction.  We arrange
  505.      for this to happen by defining the letter `K' to mean "any integer
  506.      outside the range -128 to 127", and then specifying `Ks' in the
  507.      operand constraints.
  508.      Any register, memory or immediate integer operand is allowed,
  509.      except for registers that are not general registers.
  510.      Any operand whatsoever is allowed, even if it does not satisfy
  511.      `general_operand'.  This is normally used in the constraint of a
  512.      `match_scratch' when certain alternatives will not actually
  513.      require a scratch register.
  514. `0', `1', `2', ... `9'
  515.      An operand that matches the specified operand number is allowed. 
  516.      If a digit is used together with letters within the same
  517.      alternative, the digit should come last.
  518.      This is called a "matching constraint" and what it really means is
  519.      that the assembler has only a single operand that fills two roles
  520.      considered separate in the RTL insn.  For example, an add insn has
  521.      two input operands and one output operand in the RTL, but on most
  522.      CISC machines an add instruction really has only two operands, one
  523.      of them an input-output operand:
  524.           addl #35,r12
  525.      Matching constraints are used in these circumstances. More
  526.      precisely, the two operands that match must include one input-only
  527.      operand and one output-only operand.  Moreover, the digit must be a
  528.      smaller number than the number of the operand that uses it in the
  529.      constraint.
  530.      For operands to match in a particular case usually means that they
  531.      are identical-looking RTL expressions.  But in a few special cases
  532.      specific kinds of dissimilarity are allowed.  For example, `*x' as
  533.      an input operand will match `*x++' as an output operand. For
  534.      proper results in such cases, the output template should always
  535.      use the output-operand's number when printing the operand.
  536.      An operand that is a valid memory address is allowed.  This is for
  537.      "load address" and "push address" instructions.
  538.      `p' in the constraint must be accompanied by `address_operand' as
  539.      the predicate in the `match_operand'.  This predicate interprets
  540.      the mode specified in the `match_operand' as the mode of the memory
  541.      reference for which the address would be valid.
  542. `Q', `R', `S', ... `U'
  543.      Letters in the range `Q' through `U' may be defined in a
  544.      machine-dependent fashion to stand for arbitrary operand types.
  545.      The machine description macro `EXTRA_CONSTRAINT' is passed the
  546.      operand as its first argument and the constraint letter as its
  547.      second operand.
  548.      A typical use for this would be to distinguish certain types of
  549.      memory references that affect other insn operands.
  550.      Do not define these constraint letters to accept register
  551.      references (`reg'); the reload pass does not expect this and would
  552.      not handle it properly.
  553.    In order to have valid assembler code, each operand must satisfy its
  554. constraint.  But a failure to do so does not prevent the pattern from
  555. applying to an insn.  Instead, it directs the compiler to modify the
  556. code so that the constraint will be satisfied.  Usually this is done by
  557. copying an operand into a register.
  558.    Contrast, therefore, the two instruction patterns that follow:
  559.      (define_insn ""
  560.        [(set (match_operand:SI 0 "general_operand" "=r")
  561.              (plus:SI (match_dup 0)
  562.                       (match_operand:SI 1 "general_operand" "r")))]
  563.        ""
  564.        "...")
  565. which has two operands, one of which must appear in two places, and
  566.      (define_insn ""
  567.        [(set (match_operand:SI 0 "general_operand" "=r")
  568.              (plus:SI (match_operand:SI 1 "general_operand" "0")
  569.                       (match_operand:SI 2 "general_operand" "r")))]
  570.        ""
  571.        "...")
  572. which has three operands, two of which are required by a constraint to
  573. be identical.  If we are considering an insn of the form
  574.      (insn N PREV NEXT
  575.        (set (reg:SI 3)
  576.             (plus:SI (reg:SI 6) (reg:SI 109)))
  577.        ...)
  578. the first pattern would not apply at all, because this insn does not
  579. contain two identical subexpressions in the right place.  The pattern
  580. would say, "That does not look like an add instruction; try other
  581. patterns." The second pattern would say, "Yes, that's an add
  582. instruction, but there is something wrong with it."  It would direct
  583. the reload pass of the compiler to generate additional insns to make
  584. the constraint true.  The results might look like this:
  585.      (insn N2 PREV N
  586.        (set (reg:SI 3) (reg:SI 6))
  587.        ...)
  588.      
  589.      (insn N N2 NEXT
  590.        (set (reg:SI 3)
  591.             (plus:SI (reg:SI 3) (reg:SI 109)))
  592.        ...)
  593.    It is up to you to make sure that each operand, in each pattern, has
  594. constraints that can handle any RTL expression that could be present for
  595. that operand.  (When multiple alternatives are in use, each pattern
  596. must, for each possible combination of operand expressions, have at
  597. least one alternative which can handle that combination of operands.) 
  598. The constraints don't need to *allow* any possible operand--when this is
  599. the case, they do not constrain--but they must at least point the way to
  600. reloading any possible operand so that it will fit.
  601.    * If the constraint accepts whatever operands the predicate permits,
  602.      there is no problem: reloading is never necessary for this operand.
  603.      For example, an operand whose constraints permit everything except
  604.      registers is safe provided its predicate rejects registers.
  605.      An operand whose predicate accepts only constant values is safe
  606.      provided its constraints include the letter `i'.  If any possible
  607.      constant value is accepted, then nothing less than `i' will do; if
  608.      the predicate is more selective, then the constraints may also be
  609.      more selective.
  610.    * Any operand expression can be reloaded by copying it into a
  611.      register. So if an operand's constraints allow some kind of
  612.      register, it is certain to be safe.  It need not permit all
  613.      classes of registers; the compiler knows how to copy a register
  614.      into another register of the proper class in order to make an
  615.      instruction valid.
  616.    * A nonoffsettable memory reference can be reloaded by copying the
  617.      address into a register.  So if the constraint uses the letter
  618.      `o', all memory references are taken care of.
  619.    * A constant operand can be reloaded by allocating space in memory to
  620.      hold it as preinitialized data.  Then the memory reference can be
  621.      used in place of the constant.  So if the constraint uses the
  622.      letters `o' or `m', constant operands are not a problem.
  623.    * If the constraint permits a constant and a pseudo register used in
  624.      an insn was not allocated to a hard register and is equivalent to
  625.      a constant, the register will be replaced with the constant.  If
  626.      the predicate does not permit a constant and the insn is
  627.      re-recognized for some reason, the compiler will crash.  Thus the
  628.      predicate must always recognize any objects allowed by the
  629.      constraint.
  630.    If the operand's predicate can recognize registers, but the
  631. constraint does not permit them, it can make the compiler crash.  When
  632. this operand happens to be a register, the reload pass will be stymied,
  633. because it does not know how to copy a register temporarily into memory.
  634. File: gcc.info,  Node: Multi-Alternative,  Next: Class Preferences,  Prev: Simple Constraints,  Up: Constraints
  635. Multiple Alternative Constraints
  636. --------------------------------
  637.    Sometimes a single instruction has multiple alternative sets of
  638. possible operands.  For example, on the 68000, a logical-or instruction
  639. can combine register or an immediate value into memory, or it can
  640. combine any kind of operand into a register; but it cannot combine one
  641. memory location into another.
  642.    These constraints are represented as multiple alternatives.  An
  643. alternative can be described by a series of letters for each operand. 
  644. The overall constraint for an operand is made from the letters for this
  645. operand from the first alternative, a comma, the letters for this
  646. operand from the second alternative, a comma, and so on until the last
  647. alternative. Here is how it is done for fullword logical-or on the
  648. 68000:
  649.      (define_insn "iorsi3"
  650.        [(set (match_operand:SI 0 "general_operand" "=m,d")
  651.              (ior:SI (match_operand:SI 1 "general_operand" "%0,0")
  652.                      (match_operand:SI 2 "general_operand" "dKs,dmKs")))]
  653.        ...)
  654.    The first alternative has `m' (memory) for operand 0, `0' for
  655. operand 1 (meaning it must match operand 0), and `dKs' for operand 2. 
  656. The second alternative has `d' (data register) for operand 0, `0' for
  657. operand 1, and `dmKs' for operand 2.  The `=' and `%' in the
  658. constraints apply to all the alternatives; their meaning is explained
  659. in the next section (*note Class Preferences::.).
  660.    If all the operands fit any one alternative, the instruction is
  661. valid. Otherwise, for each alternative, the compiler counts how many
  662. instructions must be added to copy the operands so that that
  663. alternative applies. The alternative requiring the least copying is
  664. chosen.  If two alternatives need the same amount of copying, the one
  665. that comes first is chosen. These choices can be altered with the `?'
  666. and `!' characters:
  667.      Disparage slightly the alternative that the `?' appears in, as a
  668.      choice when no alternative applies exactly.  The compiler regards
  669.      this alternative as one unit more costly for each `?' that appears
  670.      in it.
  671.      Disparage severely the alternative that the `!' appears in. This
  672.      alternative can still be used if it fits without reloading, but if
  673.      reloading is needed, some other alternative will be used.
  674.    When an insn pattern has multiple alternatives in its constraints,
  675. often the appearance of the assembler code is determined mostly by which
  676. alternative was matched.  When this is so, the C code for writing the
  677. assembler code can use the variable `which_alternative', which is the
  678. ordinal number of the alternative that was actually satisfied (0 for
  679. the first, 1 for the second alternative, etc.).  *Note Output
  680. Statement::.
  681. File: gcc.info,  Node: Class Preferences,  Next: Modifiers,  Prev: Multi-Alternative,  Up: Constraints
  682. Register Class Preferences
  683. --------------------------
  684.    The operand constraints have another function: they enable the
  685. compiler to decide which kind of hardware register a pseudo register is
  686. best allocated to.  The compiler examines the constraints that apply to
  687. the insns that use the pseudo register, looking for the
  688. machine-dependent letters such as `d' and `a' that specify classes of
  689. registers. The pseudo register is put in whichever class gets the most
  690. "votes". The constraint letters `g' and `r' also vote: they vote in
  691. favor of a general register.  The machine description says which
  692. registers are considered general.
  693.    Of course, on some machines all registers are equivalent, and no
  694. register classes are defined.  Then none of this complexity is relevant.
  695. File: gcc.info,  Node: Modifiers,  Next: No Constraints,  Prev: Class Preferences,  Up: Constraints
  696. Constraint Modifier Characters
  697. ------------------------------
  698.      Means that this operand is write-only for this instruction: the
  699.      previous value is discarded and replaced by output data.
  700.      Means that this operand is both read and written by the
  701.      instruction.
  702.      When the compiler fixes up the operands to satisfy the constraints,
  703.      it needs to know which operands are inputs to the instruction and
  704.      which are outputs from it.  `=' identifies an output; `+'
  705.      identifies an operand that is both input and output; all other
  706.      operands are assumed to be input only.
  707.      Means (in a particular alternative) that this operand is written
  708.      before the instruction is finished using the input operands.
  709.      Therefore, this operand may not lie in a register that is used as
  710.      an input operand or as part of any memory address.
  711.      `&' applies only to the alternative in which it is written.  In
  712.      constraints with multiple alternatives, sometimes one alternative
  713.      requires `&' while others do not.  See, for example, the `movdf'
  714.      insn of the 68000.
  715.      `&' does not obviate the need to write `='.
  716.      Declares the instruction to be commutative for this operand and the
  717.      following operand.  This means that the compiler may interchange
  718.      the two operands if that is the cheapest way to make all operands
  719.      fit the constraints.  This is often used in patterns for addition
  720.      instructions that really have only two operands: the result must
  721.      go in one of the arguments.  Here for example, is how the 68000
  722.      halfword-add instruction is defined:
  723.           (define_insn "addhi3"
  724.             [(set (match_operand:HI 0 "general_operand" "=m,r")
  725.                (plus:HI (match_operand:HI 1 "general_operand" "%0,0")
  726.                         (match_operand:HI 2 "general_operand" "di,g")))]
  727.             ...)
  728.      Says that all following characters, up to the next comma, are to be
  729.      ignored as a constraint.  They are significant only for choosing
  730.      register preferences.
  731.      Says that the following character should be ignored when choosing
  732.      register preferences.  `*' has no effect on the meaning of the
  733.      constraint as a constraint, and no effect on reloading.
  734.      Here is an example: the 68000 has an instruction to sign-extend a
  735.      halfword in a data register, and can also sign-extend a value by
  736.      copying it into an address register.  While either kind of
  737.      register is acceptable, the constraints on an address-register
  738.      destination are less strict, so it is best if register allocation
  739.      makes an address register its goal.  Therefore, `*' is used so
  740.      that the `d' constraint letter (for data register) is ignored when
  741.      computing register preferences.
  742.           (define_insn "extendhisi2"
  743.             [(set (match_operand:SI 0 "general_operand" "=*d,a")
  744.                   (sign_extend:SI
  745.                    (match_operand:HI 1 "general_operand" "0,g")))]
  746.             ...)
  747. File: gcc.info,  Node: No Constraints,  Prev: Modifiers,  Up: Constraints
  748. Not Using Constraints
  749. ---------------------
  750.    Some machines are so clean that operand constraints are not
  751. required.  For example, on the Vax, an operand valid in one context is
  752. valid in any other context.  On such a machine, every operand
  753. constraint would be `g', excepting only operands of "load address"
  754. instructions which are written as if they referred to a memory
  755. location's contents but actual refer to its address.  They would have
  756. constraint `p'.
  757.    For such machines, instead of writing `g' and `p' for all the
  758. constraints, you can choose to write a description with empty
  759. constraints. Then you write `""' for the constraint in every
  760. `match_operand'. Address operands are identified by writing an
  761. `address' expression around the `match_operand', not by their
  762. constraints.
  763.    When the machine description has just empty constraints, certain
  764. parts of compilation are skipped, making the compiler faster.  However,
  765. few machines actually do not need constraints; all machine descriptions
  766. now in existence use constraints.
  767.