home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Source / GNU / gcc / gcc.info-16 (.txt) < prev    next >
GNU Info File  |  1995-11-26  |  50KB  |  1,003 lines

  1. This is Info file gcc.info, produced by Makeinfo-1.55 from the input
  2. file gcc.texi.
  3.    This file documents the use and the internals of the GNU compiler.
  4.    Published by the Free Software Foundation 59 Temple Place - Suite 330
  5. Boston, MA 02111-1307 USA
  6.    Copyright (C) 1988, 1989, 1992, 1993, 1994, 1995 Free Software
  7. Foundation, Inc.
  8.    Permission is granted to make and distribute verbatim copies of this
  9. manual provided the copyright notice and this permission notice are
  10. preserved on all copies.
  11.    Permission is granted to copy and distribute modified versions of
  12. this manual under the conditions for verbatim copying, provided also
  13. that the sections entitled "GNU General Public License," "Funding for
  14. Free Software," and "Protect Your Freedom--Fight `Look And Feel'" are
  15. included exactly as in the original, and provided that the entire
  16. resulting derived work is distributed under the terms of a permission
  17. notice identical to this one.
  18.    Permission is granted to copy and distribute translations of this
  19. manual into another language, under the above conditions for modified
  20. versions, except that the sections entitled "GNU General Public
  21. License," "Funding for Free Software," and "Protect Your Freedom--Fight
  22. `Look And Feel'", and this permission notice, may be included in
  23. translations approved by the Free Software Foundation instead of in the
  24. original English.
  25. File: gcc.info,  Node: RTL Template,  Next: Output Template,  Prev: Example,  Up: Machine Desc
  26. RTL Template
  27. ============
  28.    The RTL template is used to define which insns match the particular
  29. pattern and how to find their operands.  For named patterns, the RTL
  30. template also says how to construct an insn from specified operands.
  31.    Construction involves substituting specified operands into a copy of
  32. the template.  Matching involves determining the values that serve as
  33. the operands in the insn being matched.  Both of these activities are
  34. controlled by special expression types that direct matching and
  35. substitution of the operands.
  36. `(match_operand:M N PREDICATE CONSTRAINT)'
  37.      This expression is a placeholder for operand number N of the insn.
  38.      When constructing an insn, operand number N will be substituted
  39.      at this point.  When matching an insn, whatever appears at this
  40.      position in the insn will be taken as operand number N; but it
  41.      must satisfy PREDICATE or this instruction pattern will not match
  42.      at all.
  43.      Operand numbers must be chosen consecutively counting from zero in
  44.      each instruction pattern.  There may be only one `match_operand'
  45.      expression in the pattern for each operand number.  Usually
  46.      operands are numbered in the order of appearance in `match_operand'
  47.      expressions.
  48.      PREDICATE is a string that is the name of a C function that
  49.      accepts two arguments, an expression and a machine mode.  During
  50.      matching, the function will be called with the putative operand as
  51.      the expression and M as the mode argument (if M is not specified,
  52.      `VOIDmode' will be used, which normally causes PREDICATE to accept
  53.      any mode).  If it returns zero, this instruction pattern fails to
  54.      match.  PREDICATE may be an empty string; then it means no test is
  55.      to be done on the operand, so anything which occurs in this
  56.      position is valid.
  57.      Most of the time, PREDICATE will reject modes other than M--but
  58.      not always.  For example, the predicate `address_operand' uses M
  59.      as the mode of memory ref that the address should be valid for.
  60.      Many predicates accept `const_int' nodes even though their mode is
  61.      `VOIDmode'.
  62.      CONSTRAINT controls reloading and the choice of the best register
  63.      class to use for a value, as explained later (*note
  64.      Constraints::.).
  65.      People are often unclear on the difference between the constraint
  66.      and the predicate.  The predicate helps decide whether a given
  67.      insn matches the pattern.  The constraint plays no role in this
  68.      decision; instead, it controls various decisions in the case of an
  69.      insn which does match.
  70.      On CISC machines, the most common PREDICATE is
  71.      `"general_operand"'.  This function checks that the putative
  72.      operand is either a constant, a register or a memory reference,
  73.      and that it is valid for mode M.
  74.      For an operand that must be a register, PREDICATE should be
  75.      `"register_operand"'.  Using `"general_operand"' would be valid,
  76.      since the reload pass would copy any non-register operands through
  77.      registers, but this would make GNU CC do extra work, it would
  78.      prevent invariant operands (such as constant) from being removed
  79.      from loops, and it would prevent the register allocator from doing
  80.      the best possible job.  On RISC machines, it is usually most
  81.      efficient to allow PREDICATE to accept only objects that the
  82.      constraints allow.
  83.      For an operand that must be a constant, you must be sure to either
  84.      use `"immediate_operand"' for PREDICATE, or make the instruction
  85.      pattern's extra condition require a constant, or both.  You cannot
  86.      expect the constraints to do this work!  If the constraints allow
  87.      only constants, but the predicate allows something else, the
  88.      compiler will crash when that case arises.
  89. `(match_scratch:M N CONSTRAINT)'
  90.      This expression is also a placeholder for operand number N and
  91.      indicates that operand must be a `scratch' or `reg' expression.
  92.      When matching patterns, this is equivalent to
  93.           (match_operand:M N "scratch_operand" PRED)
  94.      but, when generating RTL, it produces a (`scratch':M) expression.
  95.      If the last few expressions in a `parallel' are `clobber'
  96.      expressions whose operands are either a hard register or
  97.      `match_scratch', the combiner can add or delete them when
  98.      necessary.  *Note Side Effects::.
  99. `(match_dup N)'
  100.      This expression is also a placeholder for operand number N.  It is
  101.      used when the operand needs to appear more than once in the insn.
  102.      In construction, `match_dup' acts just like `match_operand': the
  103.      operand is substituted into the insn being constructed.  But in
  104.      matching, `match_dup' behaves differently.  It assumes that operand
  105.      number N has already been determined by a `match_operand'
  106.      appearing earlier in the recognition template, and it matches only
  107.      an identical-looking expression.
  108. `(match_operator:M N PREDICATE [OPERANDS...])'
  109.      This pattern is a kind of placeholder for a variable RTL expression
  110.      code.
  111.      When constructing an insn, it stands for an RTL expression whose
  112.      expression code is taken from that of operand N, and whose
  113.      operands are constructed from the patterns OPERANDS.
  114.      When matching an expression, it matches an expression if the
  115.      function PREDICATE returns nonzero on that expression *and* the
  116.      patterns OPERANDS match the operands of the expression.
  117.      Suppose that the function `commutative_operator' is defined as
  118.      follows, to match any expression whose operator is one of the
  119.      commutative arithmetic operators of RTL and whose mode is MODE:
  120.           int
  121.           commutative_operator (x, mode)
  122.                rtx x;
  123.                enum machine_mode mode;
  124.           {
  125.             enum rtx_code code = GET_CODE (x);
  126.             if (GET_MODE (x) != mode)
  127.               return 0;
  128.             return (GET_RTX_CLASS (code) == 'c'
  129.                     || code == EQ || code == NE);
  130.           }
  131.      Then the following pattern will match any RTL expression consisting
  132.      of a commutative operator applied to two general operands:
  133.           (match_operator:SI 3 "commutative_operator"
  134.             [(match_operand:SI 1 "general_operand" "g")
  135.              (match_operand:SI 2 "general_operand" "g")])
  136.      Here the vector `[OPERANDS...]' contains two patterns because the
  137.      expressions to be matched all contain two operands.
  138.      When this pattern does match, the two operands of the commutative
  139.      operator are recorded as operands 1 and 2 of the insn.  (This is
  140.      done by the two instances of `match_operand'.)  Operand 3 of the
  141.      insn will be the entire commutative expression: use `GET_CODE
  142.      (operands[3])' to see which commutative operator was used.
  143.      The machine mode M of `match_operator' works like that of
  144.      `match_operand': it is passed as the second argument to the
  145.      predicate function, and that function is solely responsible for
  146.      deciding whether the expression to be matched "has" that mode.
  147.      When constructing an insn, argument 3 of the gen-function will
  148.      specify the operation (i.e. the expression code) for the
  149.      expression to be made.  It should be an RTL expression, whose
  150.      expression code is copied into a new expression whose operands are
  151.      arguments 1 and 2 of the gen-function.  The subexpressions of
  152.      argument 3 are not used; only its expression code matters.
  153.      When `match_operator' is used in a pattern for matching an insn,
  154.      it usually best if the operand number of the `match_operator' is
  155.      higher than that of the actual operands of the insn.  This improves
  156.      register allocation because the register allocator often looks at
  157.      operands 1 and 2 of insns to see if it can do register tying.
  158.      There is no way to specify constraints in `match_operator'.  The
  159.      operand of the insn which corresponds to the `match_operator'
  160.      never has any constraints because it is never reloaded as a whole.
  161.      However, if parts of its OPERANDS are matched by `match_operand'
  162.      patterns, those parts may have constraints of their own.
  163. `(match_op_dup:M N[OPERANDS...])'
  164.      Like `match_dup', except that it applies to operators instead of
  165.      operands.  When constructing an insn, operand number N will be
  166.      substituted at this point.  But in matching, `match_op_dup' behaves
  167.      differently.  It assumes that operand number N has already been
  168.      determined by a `match_operator' appearing earlier in the
  169.      recognition template, and it matches only an identical-looking
  170.      expression.
  171. `(match_parallel N PREDICATE [SUBPAT...])'
  172.      This pattern is a placeholder for an insn that consists of a
  173.      `parallel' expression with a variable number of elements.  This
  174.      expression should only appear at the top level of an insn pattern.
  175.      When constructing an insn, operand number N will be substituted at
  176.      this point.  When matching an insn, it matches if the body of the
  177.      insn is a `parallel' expression with at least as many elements as
  178.      the vector of SUBPAT expressions in the `match_parallel', if each
  179.      SUBPAT matches the corresponding element of the `parallel', *and*
  180.      the function PREDICATE returns nonzero on the `parallel' that is
  181.      the body of the insn.  It is the responsibility of the predicate
  182.      to validate elements of the `parallel' beyond those listed in the
  183.      `match_parallel'.
  184.      A typical use of `match_parallel' is to match load and store
  185.      multiple expressions, which can contain a variable number of
  186.      elements in a `parallel'.  For example,
  187.           (define_insn ""
  188.             [(match_parallel 0 "load_multiple_operation"
  189.                [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
  190.                      (match_operand:SI 2 "memory_operand" "m"))
  191.                 (use (reg:SI 179))
  192.                 (clobber (reg:SI 179))])]
  193.             ""
  194.             "loadm 0,0,%1,%2")
  195.      This example comes from `a29k.md'.  The function
  196.      `load_multiple_operations' is defined in `a29k.c' and checks that
  197.      subsequent elements in the `parallel' are the same as the `set' in
  198.      the pattern, except that they are referencing subsequent registers
  199.      and memory locations.
  200.      An insn that matches this pattern might look like:
  201.           (parallel
  202.            [(set (reg:SI 20) (mem:SI (reg:SI 100)))
  203.             (use (reg:SI 179))
  204.             (clobber (reg:SI 179))
  205.             (set (reg:SI 21)
  206.                  (mem:SI (plus:SI (reg:SI 100)
  207.                                   (const_int 4))))
  208.             (set (reg:SI 22)
  209.                  (mem:SI (plus:SI (reg:SI 100)
  210.                                   (const_int 8))))])
  211. `(match_par_dup N [SUBPAT...])'
  212.      Like `match_op_dup', but for `match_parallel' instead of
  213.      `match_operator'.
  214. `(address (match_operand:M N "address_operand" ""))'
  215.      This complex of expressions is a placeholder for an operand number
  216.      N in a "load address" instruction: an operand which specifies a
  217.      memory location in the usual way, but for which the actual operand
  218.      value used is the address of the location, not the contents of the
  219.      location.
  220.      `address' expressions never appear in RTL code, only in machine
  221.      descriptions.  And they are used only in machine descriptions that
  222.      do not use the operand constraint feature.  When operand
  223.      constraints are in use, the letter `p' in the constraint serves
  224.      this purpose.
  225.      M is the machine mode of the *memory location being addressed*,
  226.      not the machine mode of the address itself.  That mode is always
  227.      the same on a given target machine (it is `Pmode', which normally
  228.      is `SImode'), so there is no point in mentioning it; thus, no
  229.      machine mode is written in the `address' expression.  If some day
  230.      support is added for machines in which addresses of different
  231.      kinds of objects appear differently or are used differently (such
  232.      as the PDP-10), different formats would perhaps need different
  233.      machine modes and these modes might be written in the `address'
  234.      expression.
  235. File: gcc.info,  Node: Output Template,  Next: Output Statement,  Prev: RTL Template,  Up: Machine Desc
  236. Output Templates and Operand Substitution
  237. =========================================
  238.    The "output template" is a string which specifies how to output the
  239. assembler code for an instruction pattern.  Most of the template is a
  240. fixed string which is output literally.  The character `%' is used to
  241. specify where to substitute an operand; it can also be used to identify
  242. places where different variants of the assembler require different
  243. syntax.
  244.    In the simplest case, a `%' followed by a digit N says to output
  245. operand N at that point in the string.
  246.    `%' followed by a letter and a digit says to output an operand in an
  247. alternate fashion.  Four letters have standard, built-in meanings
  248. described below.  The machine description macro `PRINT_OPERAND' can
  249. define additional letters with nonstandard meanings.
  250.    `%cDIGIT' can be used to substitute an operand that is a constant
  251. value without the syntax that normally indicates an immediate operand.
  252.    `%nDIGIT' is like `%cDIGIT' except that the value of the constant is
  253. negated before printing.
  254.    `%aDIGIT' can be used to substitute an operand as if it were a
  255. memory reference, with the actual operand treated as the address.  This
  256. may be useful when outputting a "load address" instruction, because
  257. often the assembler syntax for such an instruction requires you to
  258. write the operand as if it were a memory reference.
  259.    `%lDIGIT' is used to substitute a `label_ref' into a jump
  260. instruction.
  261.    `%=' outputs a number which is unique to each instruction in the
  262. entire compilation.  This is useful for making local labels to be
  263. referred to more than once in a single template that generates multiple
  264. assembler instructions.
  265.    `%' followed by a punctuation character specifies a substitution that
  266. does not use an operand.  Only one case is standard: `%%' outputs a `%'
  267. into the assembler code.  Other nonstandard cases can be defined in the
  268. `PRINT_OPERAND' macro.  You must also define which punctuation
  269. characters are valid with the `PRINT_OPERAND_PUNCT_VALID_P' macro.
  270.    The template may generate multiple assembler instructions.  Write
  271. the text for the instructions, with `\;' between them.
  272.    When the RTL contains two operands which are required by constraint
  273. to match each other, the output template must refer only to the
  274. lower-numbered operand.  Matching operands are not always identical,
  275. and the rest of the compiler arranges to put the proper RTL expression
  276. for printing into the lower-numbered operand.
  277.    One use of nonstandard letters or punctuation following `%' is to
  278. distinguish between different assembler languages for the same machine;
  279. for example, Motorola syntax versus MIT syntax for the 68000.  Motorola
  280. syntax requires periods in most opcode names, while MIT syntax does
  281. not.  For example, the opcode `movel' in MIT syntax is `move.l' in
  282. Motorola syntax.  The same file of patterns is used for both kinds of
  283. output syntax, but the character sequence `%.' is used in each place
  284. where Motorola syntax wants a period.  The `PRINT_OPERAND' macro for
  285. Motorola syntax defines the sequence to output a period; the macro for
  286. MIT syntax defines it to do nothing.
  287.    As a special case, a template consisting of the single character `#'
  288. instructs the compiler to first split the insn, and then output the
  289. resulting instructions separately.  This helps eliminate redundancy in
  290. the output templates.   If you have a `define_insn' that needs to emit
  291. multiple assembler instructions, and there is an matching `define_split'
  292. already defined, then you can simply use `#' as the output template
  293. instead of writing an output template that emits the multiple assembler
  294. instructions.
  295.    If `ASSEMBLER_DIALECT' is defined, you can use
  296. `{option0|option1|option2}' constructs in the templates.  These
  297. describe multiple variants of assembler language syntax.  *Note
  298. Instruction Output::.
  299. File: gcc.info,  Node: Output Statement,  Next: Constraints,  Prev: Output Template,  Up: Machine Desc
  300. C Statements for Assembler Output
  301. =================================
  302.    Often a single fixed template string cannot produce correct and
  303. efficient assembler code for all the cases that are recognized by a
  304. single instruction pattern.  For example, the opcodes may depend on the
  305. kinds of operands; or some unfortunate combinations of operands may
  306. require extra machine instructions.
  307.    If the output control string starts with a `@', then it is actually
  308. a series of templates, each on a separate line.  (Blank lines and
  309. leading spaces and tabs are ignored.)  The templates correspond to the
  310. pattern's constraint alternatives (*note Multi-Alternative::.).  For
  311. example, if a target machine has a two-address add instruction `addr'
  312. to add into a register and another `addm' to add a register to memory,
  313. you might write this pattern:
  314.      (define_insn "addsi3"
  315.        [(set (match_operand:SI 0 "general_operand" "=r,m")
  316.              (plus:SI (match_operand:SI 1 "general_operand" "0,0")
  317.                       (match_operand:SI 2 "general_operand" "g,r")))]
  318.        ""
  319.        "@
  320.         addr %2,%0
  321.         addm %2,%0")
  322.    If the output control string starts with a `*', then it is not an
  323. output template but rather a piece of C program that should compute a
  324. template.  It should execute a `return' statement to return the
  325. template-string you want.  Most such templates use C string literals,
  326. which require doublequote characters to delimit them.  To include these
  327. doublequote characters in the string, prefix each one with `\'.
  328.    The operands may be found in the array `operands', whose C data type
  329. is `rtx []'.
  330.    It is very common to select different ways of generating assembler
  331. code based on whether an immediate operand is within a certain range.
  332. Be careful when doing this, because the result of `INTVAL' is an
  333. integer on the host machine.  If the host machine has more bits in an
  334. `int' than the target machine has in the mode in which the constant
  335. will be used, then some of the bits you get from `INTVAL' will be
  336. superfluous.  For proper results, you must carefully disregard the
  337. values of those bits.
  338.    It is possible to output an assembler instruction and then go on to
  339. output or compute more of them, using the subroutine `output_asm_insn'.
  340. This receives two arguments: a template-string and a vector of
  341. operands.  The vector may be `operands', or it may be another array of
  342. `rtx' that you declare locally and initialize yourself.
  343.    When an insn pattern has multiple alternatives in its constraints,
  344. often the appearance of the assembler code is determined mostly by
  345. which alternative was matched.  When this is so, the C code can test
  346. the variable `which_alternative', which is the ordinal number of the
  347. alternative that was actually satisfied (0 for the first, 1 for the
  348. second alternative, etc.).
  349.    For example, suppose there are two opcodes for storing zero, `clrreg'
  350. for registers and `clrmem' for memory locations.  Here is how a pattern
  351. could use `which_alternative' to choose between them:
  352.      (define_insn ""
  353.        [(set (match_operand:SI 0 "general_operand" "=r,m")
  354.              (const_int 0))]
  355.        ""
  356.        "*
  357.        return (which_alternative == 0
  358.                ? \"clrreg %0\" : \"clrmem %0\");
  359.        ")
  360.    The example above, where the assembler code to generate was *solely*
  361. determined by the alternative, could also have been specified as
  362. follows, having the output control string start with a `@':
  363.      (define_insn ""
  364.        [(set (match_operand:SI 0 "general_operand" "=r,m")
  365.              (const_int 0))]
  366.        ""
  367.        "@
  368.         clrreg %0
  369.         clrmem %0")
  370. File: gcc.info,  Node: Constraints,  Next: Standard Names,  Prev: Output Statement,  Up: Machine Desc
  371. Operand Constraints
  372. ===================
  373.    Each `match_operand' in an instruction pattern can specify a
  374. constraint for the type of operands allowed.  Constraints can say
  375. whether an operand may be in a register, and which kinds of register;
  376. whether the operand can be a memory reference, and which kinds of
  377. address; whether the operand may be an immediate constant, and which
  378. possible values it may have.  Constraints can also require two operands
  379. to match.
  380. * Menu:
  381. * Simple Constraints::  Basic use of constraints.
  382. * Multi-Alternative::   When an insn has two alternative constraint-patterns.
  383. * Class Preferences::   Constraints guide which hard register to put things in.
  384. * Modifiers::           More precise control over effects of constraints.
  385. * Machine Constraints:: Existing constraints for some particular machines.
  386. * No Constraints::      Describing a clean machine without constraints.
  387. File: gcc.info,  Node: Simple Constraints,  Next: Multi-Alternative,  Up: Constraints
  388. Simple Constraints
  389. ------------------
  390.    The simplest kind of constraint is a string full of letters, each of
  391. which describes one kind of operand that is permitted.  Here are the
  392. letters that are allowed:
  393.      A memory operand is allowed, with any kind of address that the
  394.      machine supports in general.
  395.      A memory operand is allowed, but only if the address is
  396.      "offsettable".  This means that adding a small integer (actually,
  397.      the width in bytes of the operand, as determined by its machine
  398.      mode) may be added to the address and the result is also a valid
  399.      memory address.
  400.      For example, an address which is constant is offsettable; so is an
  401.      address that is the sum of a register and a constant (as long as a
  402.      slightly larger constant is also within the range of
  403.      address-offsets supported by the machine); but an autoincrement or
  404.      autodecrement address is not offsettable.  More complicated
  405.      indirect/indexed addresses may or may not be offsettable depending
  406.      on the other addressing modes that the machine supports.
  407.      Note that in an output operand which can be matched by another
  408.      operand, the constraint letter `o' is valid only when accompanied
  409.      by both `<' (if the target machine has predecrement addressing)
  410.      and `>' (if the target machine has preincrement addressing).
  411.      A memory operand that is not offsettable.  In other words,
  412.      anything that would fit the `m' constraint but not the `o'
  413.      constraint.
  414.      A memory operand with autodecrement addressing (either
  415.      predecrement or postdecrement) is allowed.
  416.      A memory operand with autoincrement addressing (either
  417.      preincrement or postincrement) is allowed.
  418.      A register operand is allowed provided that it is in a general
  419.      register.
  420. `d', `a', `f', ...
  421.      Other letters can be defined in machine-dependent fashion to stand
  422.      for particular classes of registers.  `d', `a' and `f' are defined
  423.      on the 68000/68020 to stand for data, address and floating point
  424.      registers.
  425.      An immediate integer operand (one with constant value) is allowed.
  426.      This includes symbolic constants whose values will be known only at
  427.      assembly time.
  428.      An immediate integer operand with a known numeric value is allowed.
  429.      Many systems cannot support assembly-time constants for operands
  430.      less than a word wide.  Constraints for these operands should use
  431.      `n' rather than `i'.
  432. `I', `J', `K', ... `P'
  433.      Other letters in the range `I' through `P' may be defined in a
  434.      machine-dependent fashion to permit immediate integer operands with
  435.      explicit integer values in specified ranges.  For example, on the
  436.      68000, `I' is defined to stand for the range of values 1 to 8.
  437.      This is the range permitted as a shift count in the shift
  438.      instructions.
  439.      An immediate floating operand (expression code `const_double') is
  440.      allowed, but only if the target floating point format is the same
  441.      as that of the host machine (on which the compiler is running).
  442.      An immediate floating operand (expression code `const_double') is
  443.      allowed.
  444. `G', `H'
  445.      `G' and `H' may be defined in a machine-dependent fashion to
  446.      permit immediate floating operands in particular ranges of values.
  447.      An immediate integer operand whose value is not an explicit
  448.      integer is allowed.
  449.      This might appear strange; if an insn allows a constant operand
  450.      with a value not known at compile time, it certainly must allow
  451.      any known value.  So why use `s' instead of `i'?  Sometimes it
  452.      allows better code to be generated.
  453.      For example, on the 68000 in a fullword instruction it is possible
  454.      to use an immediate operand; but if the immediate value is between
  455.      -128 and 127, better code results from loading the value into a
  456.      register and using the register.  This is because the load into
  457.      the register can be done with a `moveq' instruction.  We arrange
  458.      for this to happen by defining the letter `K' to mean "any integer
  459.      outside the range -128 to 127", and then specifying `Ks' in the
  460.      operand constraints.
  461.      Any register, memory or immediate integer operand is allowed,
  462.      except for registers that are not general registers.
  463.      Any operand whatsoever is allowed, even if it does not satisfy
  464.      `general_operand'.  This is normally used in the constraint of a
  465.      `match_scratch' when certain alternatives will not actually
  466.      require a scratch register.
  467. `0', `1', `2', ... `9'
  468.      An operand that matches the specified operand number is allowed.
  469.      If a digit is used together with letters within the same
  470.      alternative, the digit should come last.
  471.      This is called a "matching constraint" and what it really means is
  472.      that the assembler has only a single operand that fills two roles
  473.      considered separate in the RTL insn.  For example, an add insn has
  474.      two input operands and one output operand in the RTL, but on most
  475.      CISC machines an add instruction really has only two operands, one
  476.      of them an input-output operand:
  477.           addl #35,r12
  478.      Matching constraints are used in these circumstances.  More
  479.      precisely, the two operands that match must include one input-only
  480.      operand and one output-only operand.  Moreover, the digit must be a
  481.      smaller number than the number of the operand that uses it in the
  482.      constraint.
  483.      For operands to match in a particular case usually means that they
  484.      are identical-looking RTL expressions.  But in a few special cases
  485.      specific kinds of dissimilarity are allowed.  For example, `*x' as
  486.      an input operand will match `*x++' as an output operand.  For
  487.      proper results in such cases, the output template should always
  488.      use the output-operand's number when printing the operand.
  489.      An operand that is a valid memory address is allowed.  This is for
  490.      "load address" and "push address" instructions.
  491.      `p' in the constraint must be accompanied by `address_operand' as
  492.      the predicate in the `match_operand'.  This predicate interprets
  493.      the mode specified in the `match_operand' as the mode of the memory
  494.      reference for which the address would be valid.
  495. `Q', `R', `S', ... `U'
  496.      Letters in the range `Q' through `U' may be defined in a
  497.      machine-dependent fashion to stand for arbitrary operand types.
  498.      The machine description macro `EXTRA_CONSTRAINT' is passed the
  499.      operand as its first argument and the constraint letter as its
  500.      second operand.
  501.      A typical use for this would be to distinguish certain types of
  502.      memory references that affect other insn operands.
  503.      Do not define these constraint letters to accept register
  504.      references (`reg'); the reload pass does not expect this and would
  505.      not handle it properly.
  506.    In order to have valid assembler code, each operand must satisfy its
  507. constraint.  But a failure to do so does not prevent the pattern from
  508. applying to an insn.  Instead, it directs the compiler to modify the
  509. code so that the constraint will be satisfied.  Usually this is done by
  510. copying an operand into a register.
  511.    Contrast, therefore, the two instruction patterns that follow:
  512.      (define_insn ""
  513.        [(set (match_operand:SI 0 "general_operand" "=r")
  514.              (plus:SI (match_dup 0)
  515.                       (match_operand:SI 1 "general_operand" "r")))]
  516.        ""
  517.        "...")
  518. which has two operands, one of which must appear in two places, and
  519.      (define_insn ""
  520.        [(set (match_operand:SI 0 "general_operand" "=r")
  521.              (plus:SI (match_operand:SI 1 "general_operand" "0")
  522.                       (match_operand:SI 2 "general_operand" "r")))]
  523.        ""
  524.        "...")
  525. which has three operands, two of which are required by a constraint to
  526. be identical.  If we are considering an insn of the form
  527.      (insn N PREV NEXT
  528.        (set (reg:SI 3)
  529.             (plus:SI (reg:SI 6) (reg:SI 109)))
  530.        ...)
  531. the first pattern would not apply at all, because this insn does not
  532. contain two identical subexpressions in the right place.  The pattern
  533. would say, "That does not look like an add instruction; try other
  534. patterns." The second pattern would say, "Yes, that's an add
  535. instruction, but there is something wrong with it."  It would direct
  536. the reload pass of the compiler to generate additional insns to make
  537. the constraint true.  The results might look like this:
  538.      (insn N2 PREV N
  539.        (set (reg:SI 3) (reg:SI 6))
  540.        ...)
  541.      
  542.      (insn N N2 NEXT
  543.        (set (reg:SI 3)
  544.             (plus:SI (reg:SI 3) (reg:SI 109)))
  545.        ...)
  546.    It is up to you to make sure that each operand, in each pattern, has
  547. constraints that can handle any RTL expression that could be present for
  548. that operand.  (When multiple alternatives are in use, each pattern
  549. must, for each possible combination of operand expressions, have at
  550. least one alternative which can handle that combination of operands.)
  551. The constraints don't need to *allow* any possible operand--when this is
  552. the case, they do not constrain--but they must at least point the way to
  553. reloading any possible operand so that it will fit.
  554.    * If the constraint accepts whatever operands the predicate permits,
  555.      there is no problem: reloading is never necessary for this operand.
  556.      For example, an operand whose constraints permit everything except
  557.      registers is safe provided its predicate rejects registers.
  558.      An operand whose predicate accepts only constant values is safe
  559.      provided its constraints include the letter `i'.  If any possible
  560.      constant value is accepted, then nothing less than `i' will do; if
  561.      the predicate is more selective, then the constraints may also be
  562.      more selective.
  563.    * Any operand expression can be reloaded by copying it into a
  564.      register.  So if an operand's constraints allow some kind of
  565.      register, it is certain to be safe.  It need not permit all
  566.      classes of registers; the compiler knows how to copy a register
  567.      into another register of the proper class in order to make an
  568.      instruction valid.
  569.    * A nonoffsettable memory reference can be reloaded by copying the
  570.      address into a register.  So if the constraint uses the letter
  571.      `o', all memory references are taken care of.
  572.    * A constant operand can be reloaded by allocating space in memory to
  573.      hold it as preinitialized data.  Then the memory reference can be
  574.      used in place of the constant.  So if the constraint uses the
  575.      letters `o' or `m', constant operands are not a problem.
  576.    * If the constraint permits a constant and a pseudo register used in
  577.      an insn was not allocated to a hard register and is equivalent to
  578.      a constant, the register will be replaced with the constant.  If
  579.      the predicate does not permit a constant and the insn is
  580.      re-recognized for some reason, the compiler will crash.  Thus the
  581.      predicate must always recognize any objects allowed by the
  582.      constraint.
  583.    If the operand's predicate can recognize registers, but the
  584. constraint does not permit them, it can make the compiler crash.  When
  585. this operand happens to be a register, the reload pass will be stymied,
  586. because it does not know how to copy a register temporarily into memory.
  587. File: gcc.info,  Node: Multi-Alternative,  Next: Class Preferences,  Prev: Simple Constraints,  Up: Constraints
  588. Multiple Alternative Constraints
  589. --------------------------------
  590.    Sometimes a single instruction has multiple alternative sets of
  591. possible operands.  For example, on the 68000, a logical-or instruction
  592. can combine register or an immediate value into memory, or it can
  593. combine any kind of operand into a register; but it cannot combine one
  594. memory location into another.
  595.    These constraints are represented as multiple alternatives.  An
  596. alternative can be described by a series of letters for each operand.
  597. The overall constraint for an operand is made from the letters for this
  598. operand from the first alternative, a comma, the letters for this
  599. operand from the second alternative, a comma, and so on until the last
  600. alternative.  Here is how it is done for fullword logical-or on the
  601. 68000:
  602.      (define_insn "iorsi3"
  603.        [(set (match_operand:SI 0 "general_operand" "=m,d")
  604.              (ior:SI (match_operand:SI 1 "general_operand" "%0,0")
  605.                      (match_operand:SI 2 "general_operand" "dKs,dmKs")))]
  606.        ...)
  607.    The first alternative has `m' (memory) for operand 0, `0' for
  608. operand 1 (meaning it must match operand 0), and `dKs' for operand 2.
  609. The second alternative has `d' (data register) for operand 0, `0' for
  610. operand 1, and `dmKs' for operand 2.  The `=' and `%' in the
  611. constraints apply to all the alternatives; their meaning is explained
  612. in the next section (*note Class Preferences::.).
  613.    If all the operands fit any one alternative, the instruction is
  614. valid.  Otherwise, for each alternative, the compiler counts how many
  615. instructions must be added to copy the operands so that that
  616. alternative applies.  The alternative requiring the least copying is
  617. chosen.  If two alternatives need the same amount of copying, the one
  618. that comes first is chosen.  These choices can be altered with the `?'
  619. and `!' characters:
  620.      Disparage slightly the alternative that the `?' appears in, as a
  621.      choice when no alternative applies exactly.  The compiler regards
  622.      this alternative as one unit more costly for each `?' that appears
  623.      in it.
  624.      Disparage severely the alternative that the `!' appears in.  This
  625.      alternative can still be used if it fits without reloading, but if
  626.      reloading is needed, some other alternative will be used.
  627.    When an insn pattern has multiple alternatives in its constraints,
  628. often the appearance of the assembler code is determined mostly by which
  629. alternative was matched.  When this is so, the C code for writing the
  630. assembler code can use the variable `which_alternative', which is the
  631. ordinal number of the alternative that was actually satisfied (0 for
  632. the first, 1 for the second alternative, etc.).  *Note Output
  633. Statement::.
  634. File: gcc.info,  Node: Class Preferences,  Next: Modifiers,  Prev: Multi-Alternative,  Up: Constraints
  635. Register Class Preferences
  636. --------------------------
  637.    The operand constraints have another function: they enable the
  638. compiler to decide which kind of hardware register a pseudo register is
  639. best allocated to.  The compiler examines the constraints that apply to
  640. the insns that use the pseudo register, looking for the
  641. machine-dependent letters such as `d' and `a' that specify classes of
  642. registers.  The pseudo register is put in whichever class gets the most
  643. "votes".  The constraint letters `g' and `r' also vote: they vote in
  644. favor of a general register.  The machine description says which
  645. registers are considered general.
  646.    Of course, on some machines all registers are equivalent, and no
  647. register classes are defined.  Then none of this complexity is relevant.
  648. File: gcc.info,  Node: Modifiers,  Next: Machine Constraints,  Prev: Class Preferences,  Up: Constraints
  649. Constraint Modifier Characters
  650. ------------------------------
  651.    Here are constraint modifier characters.
  652.      Means that this operand is write-only for this instruction: the
  653.      previous value is discarded and replaced by output data.
  654.      Means that this operand is both read and written by the
  655.      instruction.
  656.      When the compiler fixes up the operands to satisfy the constraints,
  657.      it needs to know which operands are inputs to the instruction and
  658.      which are outputs from it.  `=' identifies an output; `+'
  659.      identifies an operand that is both input and output; all other
  660.      operands are assumed to be input only.
  661.      Means (in a particular alternative) that this operand is written
  662.      before the instruction is finished using the input operands.
  663.      Therefore, this operand may not lie in a register that is used as
  664.      an input operand or as part of any memory address.
  665.      `&' applies only to the alternative in which it is written.  In
  666.      constraints with multiple alternatives, sometimes one alternative
  667.      requires `&' while others do not.  See, for example, the `movdf'
  668.      insn of the 68000.
  669.      `&' does not obviate the need to write `='.
  670.      Declares the instruction to be commutative for this operand and the
  671.      following operand.  This means that the compiler may interchange
  672.      the two operands if that is the cheapest way to make all operands
  673.      fit the constraints.  This is often used in patterns for addition
  674.      instructions that really have only two operands: the result must
  675.      go in one of the arguments.  Here for example, is how the 68000
  676.      halfword-add instruction is defined:
  677.           (define_insn "addhi3"
  678.             [(set (match_operand:HI 0 "general_operand" "=m,r")
  679.                (plus:HI (match_operand:HI 1 "general_operand" "%0,0")
  680.                         (match_operand:HI 2 "general_operand" "di,g")))]
  681.             ...)
  682.      Says that all following characters, up to the next comma, are to be
  683.      ignored as a constraint.  They are significant only for choosing
  684.      register preferences.
  685.      Says that the following character should be ignored when choosing
  686.      register preferences.  `*' has no effect on the meaning of the
  687.      constraint as a constraint, and no effect on reloading.
  688.      Here is an example: the 68000 has an instruction to sign-extend a
  689.      halfword in a data register, and can also sign-extend a value by
  690.      copying it into an address register.  While either kind of
  691.      register is acceptable, the constraints on an address-register
  692.      destination are less strict, so it is best if register allocation
  693.      makes an address register its goal.  Therefore, `*' is used so
  694.      that the `d' constraint letter (for data register) is ignored when
  695.      computing register preferences.
  696.           (define_insn "extendhisi2"
  697.             [(set (match_operand:SI 0 "general_operand" "=*d,a")
  698.                   (sign_extend:SI
  699.                    (match_operand:HI 1 "general_operand" "0,g")))]
  700.             ...)
  701. File: gcc.info,  Node: Machine Constraints,  Next: No Constraints,  Prev: Modifiers,  Up: Constraints
  702. Constraints for Particular Machines
  703. -----------------------------------
  704.    Whenever possible, you should use the general-purpose constraint
  705. letters in `asm' arguments, since they will convey meaning more readily
  706. to people reading your code.  Failing that, use the constraint letters
  707. that usually have very similar meanings across architectures.  The most
  708. commonly used constraints are `m' and `r' (for memory and
  709. general-purpose registers respectively; *note Simple Constraints::.),
  710. and `I', usually the letter indicating the most common
  711. immediate-constant format.
  712.    For each machine architecture, the `config/MACHINE.h' file defines
  713. additional constraints.  These constraints are used by the compiler
  714. itself for instruction generation, as well as for `asm' statements;
  715. therefore, some of the constraints are not particularly interesting for
  716. `asm'.  The constraints are defined through these macros:
  717. `REG_CLASS_FROM_LETTER'
  718.      Register class constraints (usually lower case).
  719. `CONST_OK_FOR_LETTER_P'
  720.      Immediate constant constraints, for non-floating point constants of
  721.      word size or smaller precision (usually upper case).
  722. `CONST_DOUBLE_OK_FOR_LETTER_P'
  723.      Immediate constant constraints, for all floating point constants
  724.      and for constants of greater than word size precision (usually
  725.      upper case).
  726. `EXTRA_CONSTRAINT'
  727.      Special cases of registers or memory.  This macro is not required,
  728.      and is only defined for some machines.
  729.    Inspecting these macro definitions in the compiler source for your
  730. machine is the best way to be certain you have the right constraints.
  731. However, here is a summary of the machine-dependent constraints
  732. available on some particular machines.
  733. *ARM family--`arm.h'*
  734.     `f'
  735.           Floating-point register
  736.     `F'
  737.           One of the floating-point constants 0.0, 0.5, 1.0, 2.0, 3.0,
  738.           4.0, 5.0 or 10.0
  739.     `G'
  740.           Floating-point constant that would satisfy the constraint `F'
  741.           if it were negated
  742.     `I'
  743.           Integer that is valid as an immediate operand in a data
  744.           processing instruction.  That is, an integer in the range 0
  745.           to 255 rotated by a multiple of 2
  746.     `J'
  747.           Integer in the range -4095 to 4095
  748.     `K'
  749.           Integer that satisfies constraint `I' when inverted (ones
  750.           complement)
  751.     `L'
  752.           Integer that satisfies constraint `I' when negated (twos
  753.           complement)
  754.     `M'
  755.           Integer in the range 0 to 32
  756.     `Q'
  757.           A memory reference where the exact address is in a single
  758.           register (``m'' is preferable for `asm' statements)
  759.     `R'
  760.           An item in the constant pool
  761.     `S'
  762.           A symbol in the text segment of the current file
  763. *AMD 29000 family--`a29k.h'*
  764.     `l'
  765.           Local register 0
  766.     `b'
  767.           Byte Pointer (`BP') register
  768.     `q'
  769.           `Q' register
  770.     `h'
  771.           Special purpose register
  772.     `A'
  773.           First accumulator register
  774.     `a'
  775.           Other accumulator register
  776.     `f'
  777.           Floating point register
  778.     `I'
  779.           Constant greater than 0, less than 0x100
  780.     `J'
  781.           Constant greater than 0, less than 0x10000
  782.     `K'
  783.           Constant whose high 24 bits are on (1)
  784.     `L'
  785.           16 bit constant whose high 8 bits are on (1)
  786.     `M'
  787.           32 bit constant whose high 16 bits are on (1)
  788.     `N'
  789.           32 bit negative constant that fits in 8 bits
  790.     `O'
  791.           The constant 0x80000000 or, on the 29050, any 32 bit constant
  792.           whose low 16 bits are 0.
  793.     `P'
  794.           16 bit negative constant that fits in 8 bits
  795.     `G'
  796.     `H'
  797.           A floating point constant (in `asm' statements, use the
  798.           machine independent `E' or `F' instead)
  799. *IBM RS6000--`rs6000.h'*
  800.     `b'
  801.           Address base register
  802.     `f'
  803.           Floating point register
  804.     `h'
  805.           `MQ', `CTR', or `LINK' register
  806.     `q'
  807.           `MQ' register
  808.     `c'
  809.           `CTR' register
  810.     `l'
  811.           `LINK' register
  812.     `x'
  813.           `CR' register (condition register) number 0
  814.     `y'
  815.           `CR' register (condition register)
  816.     `I'
  817.           Signed 16 bit constant
  818.     `J'
  819.           Constant whose low 16 bits are 0
  820.     `K'
  821.           Constant whose high 16 bits are 0
  822.     `L'
  823.           Constant suitable as a mask operand
  824.     `M'
  825.           Constant larger than 31
  826.     `N'
  827.           Exact power of 2
  828.     `O'
  829.           Zero
  830.     `P'
  831.           Constant whose negation is a signed 16 bit constant
  832.     `G'
  833.           Floating point constant that can be loaded into a register
  834.           with one instruction per word
  835.     `Q'
  836.           Memory operand that is an offset from a register (`m' is
  837.           preferable for `asm' statements)
  838. *Intel 386--`i386.h'*
  839.     `q'
  840.           `a', `b', `c', or `d' register
  841.     `A'
  842.           `a', or `d' register (for 64-bit ints)
  843.     `f'
  844.           Floating point register
  845.     `t'
  846.           First (top of stack) floating point register
  847.     `u'
  848.           Second floating point register
  849.     `a'
  850.           `a' register
  851.     `b'
  852.           `b' register
  853.     `c'
  854.           `c' register
  855.     `d'
  856.           `d' register
  857.     `D'
  858.           `di' register
  859.     `S'
  860.           `si' register
  861.     `I'
  862.           Constant in range 0 to 31 (for 32 bit shifts)
  863.     `J'
  864.           Constant in range 0 to 63 (for 64 bit shifts)
  865.     `K'
  866.           `0xff'
  867.     `L'
  868.           `0xffff'
  869.     `M'
  870.           0, 1, 2, or 3 (shifts for `lea' instruction)
  871.     `N'
  872.           Constant in range 0 to 255 (for `out' instruction)
  873.     `G'
  874.           Standard 80387 floating point constant
  875. *Intel 960--`i960.h'*
  876.     `f'
  877.           Floating point register (`fp0' to `fp3')
  878.     `l'
  879.           Local register (`r0' to `r15')
  880.     `b'
  881.           Global register (`g0' to `g15')
  882.     `d'
  883.           Any local or global register
  884.     `I'
  885.           Integers from 0 to 31
  886.     `J'
  887.           0
  888.     `K'
  889.           Integers from -31 to 0
  890.     `G'
  891.           Floating point 0
  892.     `H'
  893.           Floating point 1
  894. *MIPS--`mips.h'*
  895.     `d'
  896.           General-purpose integer register
  897.     `f'
  898.           Floating-point register (if available)
  899.     `h'
  900.           `Hi' register
  901.     `l'
  902.           `Lo' register
  903.     `x'
  904.           `Hi' or `Lo' register
  905.     `y'
  906.           General-purpose integer register
  907.     `z'
  908.           Floating-point status register
  909.     `I'
  910.           Signed 16 bit constant (for arithmetic instructions)
  911.     `J'
  912.           Zero
  913.     `K'
  914.           Zero-extended 16-bit constant (for logic instructions)
  915.     `L'
  916.           Constant with low 16 bits zero (can be loaded with `lui')
  917.     `M'
  918.           32 bit constant which requires two instructions to load (a
  919.           constant which is not `I', `K', or `L')
  920.     `N'
  921.           Negative 16 bit constant
  922.     `O'
  923.           Exact power of two
  924.     `P'
  925.           Positive 16 bit constant
  926.     `G'
  927.           Floating point zero
  928.     `Q'
  929.           Memory reference that can be loaded with more than one
  930.           instruction (`m' is preferable for `asm' statements)
  931.     `R'
  932.           Memory reference that can be loaded with one instruction (`m'
  933.           is preferable for `asm' statements)
  934.     `S'
  935.           Memory reference in external OSF/rose PIC format (`m' is
  936.           preferable for `asm' statements)
  937. *Motorola 680x0--`m68k.h'*
  938.     `a'
  939.           Address register
  940.     `d'
  941.           Data register
  942.     `f'
  943.           68881 floating-point register, if available
  944.     `x'
  945.           Sun FPA (floating-point) register, if available
  946.     `y'
  947.           First 16 Sun FPA registers, if available
  948.     `I'
  949.           Integer in the range 1 to 8
  950.     `J'
  951.           16 bit signed number
  952.     `K'
  953.           Signed number whose magnitude is greater than 0x80
  954.     `L'
  955.           Integer in the range -8 to -1
  956.     `G'
  957.           Floating point constant that is not a 68881 constant
  958.     `H'
  959.           Floating point constant that can be used by Sun FPA
  960. *SPARC--`sparc.h'*
  961.     `f'
  962.           Floating-point register
  963.     `I'
  964.           Signed 13 bit constant
  965.     `J'
  966.           Zero
  967.     `K'
  968.           32 bit constant with the low 12 bits clear (a constant that
  969.           can be loaded with the `sethi' instruction)
  970.     `G'
  971.           Floating-point zero
  972.     `H'
  973.           Signed 13 bit constant, sign-extended to 32 or 64 bits
  974.     `Q'
  975.           Memory reference that can be loaded with one instruction
  976.           (`m' is more appropriate for `asm' statements)
  977.     `S'
  978.           Constant, or memory address
  979.     `T'
  980.           Memory address aligned to an 8-byte boundary
  981.     `U'
  982.           Even register
  983. File: gcc.info,  Node: No Constraints,  Prev: Machine Constraints,  Up: Constraints
  984. Not Using Constraints
  985. ---------------------
  986.    Some machines are so clean that operand constraints are not
  987. required.  For example, on the Vax, an operand valid in one context is
  988. valid in any other context.  On such a machine, every operand
  989. constraint would be `g', excepting only operands of "load address"
  990. instructions which are written as if they referred to a memory
  991. location's contents but actual refer to its address.  They would have
  992. constraint `p'.
  993.    For such machines, instead of writing `g' and `p' for all the
  994. constraints, you can choose to write a description with empty
  995. constraints.  Then you write `""' for the constraint in every
  996. `match_operand'.  Address operands are identified by writing an
  997. `address' expression around the `match_operand', not by their
  998. constraints.
  999.    When the machine description has just empty constraints, certain
  1000. parts of compilation are skipped, making the compiler faster.  However,
  1001. few machines actually do not need constraints; all machine descriptions
  1002. now in existence use constraints.
  1003.