home *** CD-ROM | disk | FTP | other *** search
/ Education Sampler 1992 [NeXTSTEP] / Education_1992_Sampler.iso / NeXT / GnuSource / cc-61.0.1 / cc / recog.c < prev    next >
C/C++ Source or Header  |  1991-06-04  |  50KB  |  1,794 lines

  1. /* Subroutines used by or related to instruction recognition.
  2.    Copyright (C) 1987-1991 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. #include "config.h"
  22. #include "rtl.h"
  23. #include <stdio.h>
  24. #include "insn-config.h"
  25. #include "insn-attr.h"
  26. #include "insn-flags.h"
  27. #include "insn-codes.h"
  28. #include "recog.h"
  29. #include "regs.h"
  30. #include "hard-reg-set.h"
  31. #include "flags.h"
  32. #include "real.h"
  33.  
  34. #define MAX(x,y) (((x) > (y)) ? (x) : (y))
  35. #define MIN(x,y) (((x) < (y)) ? (x) : (y))
  36.  
  37. #ifndef STACK_PUSH_CODE
  38. #ifdef STACK_GROWS_DOWNWARD
  39. #define STACK_PUSH_CODE PRE_DEC
  40. #else
  41. #define STACK_PUSH_CODE PRE_INC
  42. #endif
  43. #endif
  44.  
  45. /* Import from final.c: */
  46. extern rtx alter_subreg ();
  47.  
  48. int strict_memory_address_p ();
  49. int memory_address_p ();
  50.  
  51. /* Nonzero means allow operands to be volatile.
  52.    This should be 0 if you are generating rtl, such as if you are calling
  53.    the functions in optabs.c and expmed.c (most of the time).
  54.    This should be 1 if all valid insns need to be recognized,
  55.    such as in regclass.c and final.c and reload.c.
  56.  
  57.    init_recog and init_recog_no_volatile are responsible for setting this.  */
  58.  
  59. int volatile_ok;
  60.  
  61. rtx recog_addr_dummy;
  62.  
  63. /* On return from `constrain_operands', indicate which alternative
  64.    was satisfied.  */
  65.  
  66. int which_alternative;
  67.  
  68. /* Nonzero after end of reload pass.
  69.    Set to 1 or 0 by toplev.c.
  70.    Controls the significance of (SUBREG (MEM)).  */
  71.  
  72. int reload_completed;
  73.  
  74. /* Initialize data used by the function `recog'.
  75.    This must be called once in the compilation of a function
  76.    before any insn recognition may be done in the function.  */
  77.  
  78. void
  79. init_recog_no_volatile ()
  80. {
  81.   volatile_ok = 0;
  82.   recog_addr_dummy = gen_rtx (MEM, VOIDmode, 0);
  83. }
  84.  
  85. init_recog ()
  86. {
  87.   volatile_ok = 1;
  88.   recog_addr_dummy = gen_rtx (MEM, VOIDmode, 0);
  89. }
  90.  
  91. /* Try recognizing the instruction INSN,
  92.    and return the code number that results.
  93.    Remeber the code so that repeated calls do not
  94.    need to spend the time for actual rerecognition.
  95.  
  96.    This function is the normal interface to instruction recognition.
  97.    The automatically-generated function `recog' is normally called
  98.    through this one.  (The only exception is in combine.c.)  */
  99.  
  100. int
  101. recog_memoized (insn)
  102.      rtx insn;
  103. {
  104.   if (INSN_CODE (insn) < 0)
  105.     INSN_CODE (insn) = recog (PATTERN (insn), insn, 0);
  106.   return INSN_CODE (insn);
  107. }
  108.  
  109. /* Check that X is an insn-body for an `asm' with operands
  110.    and that the operands mentioned in it are legitimate.  */
  111.  
  112. int
  113. check_asm_operands (x)
  114.      rtx x;
  115. {
  116.   int noperands = asm_noperands (x);
  117.   rtx *operands;
  118.   int i;
  119.  
  120.   if (noperands < 0)
  121.     return 0;
  122.   if (noperands == 0)
  123.     return 1;
  124.  
  125.   operands = (rtx *) alloca (noperands * sizeof (rtx));
  126.   decode_asm_operands (x, operands, 0, 0, 0);
  127.  
  128.   for (i = 0; i < noperands; i++)
  129.     if (!general_operand (operands[i], VOIDmode))
  130.       return 0;
  131.  
  132.   return 1;
  133. }
  134.  
  135. /* Static data for the next two routines.
  136.  
  137.    The maximum number of changes supported is defined as the maximum
  138.    number of operands times 5.  This allows for repeated substitutions
  139.    inside complex indexed address, or, alternatively, changes in up
  140.    to 5 insns.  */
  141.  
  142. #define MAX_CHANGE_LOCS    (MAX_RECOG_OPERANDS * 5)
  143.  
  144. static rtx change_objects[MAX_CHANGE_LOCS];
  145. static int change_old_codes[MAX_CHANGE_LOCS];
  146. static rtx *change_locs[MAX_CHANGE_LOCS];
  147. static rtx change_olds[MAX_CHANGE_LOCS];
  148.  
  149. static int num_changes = 0;
  150.  
  151. /* Validate a proposed change to OBJECT.  LOC is the location in the rtl for
  152.    at which NEW will be placed.  If OBJECT is zero, no validation is done,
  153.    the change is simply made.
  154.  
  155.    Two types of objects are supported:  If OBJECT is a MEM, memory_address_p
  156.    will be called with the address and mode as parameters.  If OBJECT is
  157.    an INSN, CALL_INSN, or JUMP_INSN, the insn will be re-recognized with
  158.    the change in place.
  159.  
  160.    IN_GROUP is non-zero if this is part of a group of changes that must be
  161.    performed as a group.  In that case, the changes will be stored.  The
  162.    function `apply_change_group' will validate and apply the changes.
  163.  
  164.    If IN_GROUP is zero, this is a single change.  Try to recognize the insn
  165.    or validate the memory reference with the change applied.  If the result
  166.    is not valid for the machine, suppress the change and return zero.
  167.    Otherwise, perform the change and return 1.  */
  168.  
  169. int
  170. validate_change (object, loc, new, in_group)
  171.     rtx object;
  172.     rtx *loc;
  173.     rtx new;
  174.     int in_group;
  175. {
  176.   rtx old = *loc;
  177.  
  178.   if (old == new || rtx_equal_p (old, new))
  179.     return 1;
  180.  
  181.   if (num_changes >= MAX_CHANGE_LOCS
  182.       || (in_group == 0 && num_changes != 0))
  183.     abort ();
  184.  
  185.   *loc = new;
  186.  
  187.   /* Save the information describing this change.  */
  188.   change_objects[num_changes] = object;
  189.   change_locs[num_changes] = loc;
  190.   change_olds[num_changes] = old;
  191.  
  192.   if (object && GET_CODE (object) != MEM)
  193.     {
  194.       /* Set INSN_CODE to force rerecognition of insn.  Save old code in
  195.      case invalid.  */
  196.       change_old_codes[num_changes] = INSN_CODE (object);
  197.       INSN_CODE (object) = -1;
  198.     }
  199.  
  200.   num_changes++;
  201.  
  202.   /* If we are making a group of changes, return 1.  Otherwise, validate the
  203.      change group we made.  */
  204.  
  205.   if (in_group)
  206.     return 1;
  207.   else
  208.     return apply_change_group ();
  209. }
  210.  
  211. /* Apply a group of changes previously issued with `validate_change'.
  212.    Return 1 if all changes are valid, zero otherwise.  */
  213.  
  214. int
  215. apply_change_group ()
  216. {
  217.   int i;
  218.  
  219.   /* The changes have been applied and all INSN_CODEs have been reset to force
  220.      rerecognition.
  221.  
  222.      The changes are valid if we aren't given an object, or if we are
  223.      given a MEM and it still is a valid address, or if this is in insn
  224.      and it is recognized.  In the latter case, if reload has completed,
  225.      we also require that the operands meet the constraints for
  226.      the insn.  We do not allow modifying an ASM_OPERANDS after reload
  227.      has completed because verifying the constraints is too difficult.  */
  228.  
  229.   for (i = 0; i < num_changes; i++)
  230.     {
  231.       rtx object = change_objects[i];
  232.  
  233.       if (object == 0)
  234.     continue;
  235.  
  236.       if (GET_CODE (object) == MEM)
  237.     {
  238.       if (! memory_address_p (GET_MODE (object), XEXP (object, 0)))
  239.         break;
  240.     }
  241.       else if ((recog_memoized (object) < 0
  242.         && (asm_noperands (PATTERN (object)) < 0
  243.             || ! check_asm_operands (PATTERN (object))
  244.             || reload_completed))
  245.            || (reload_completed
  246.            && (insn_extract (object),
  247.                ! constrain_operands (INSN_CODE (object), 1))))
  248.     {
  249.       rtx pat = PATTERN (object);
  250.  
  251.       /* Perhaps we couldn't recognize the insn because there were
  252.          extra CLOBBERs at the end.  If so, try to re-recognize
  253.          without the last CLOBBER (later iterations will cause each of
  254.          them to be eliminated, in turn).  But don't do this if we
  255.          have an ASM_OPERAND.  */
  256.       if (GET_CODE (pat) == PARALLEL
  257.           && GET_CODE (XVECEXP (pat, 0, XVECLEN (pat, 0) - 1)) == CLOBBER
  258.           && asm_noperands (PATTERN (object)) < 0)
  259.         {
  260.            rtx newpat;
  261.  
  262.            if (XVECLEN (pat, 0) == 2)
  263.          newpat = XVECEXP (pat, 0, 0);
  264.            else
  265.          {
  266.            int j;
  267.  
  268.            newpat = gen_rtx (PARALLEL, VOIDmode, 
  269.                      gen_rtvec (XVECLEN (pat, 0) - 1));
  270.            for (j = 0; j < XVECLEN (newpat, 0); j++)
  271.              XVECEXP (newpat, 0, j) = XVECEXP (pat, 0, j);
  272.          }
  273.  
  274.            /* Add a new change to this group to replace the pattern
  275.           with this new pattern.  Then consider this change
  276.           as having succeeded.  The change we added will
  277.           cause the entire call to fail if things remain invalid.
  278.  
  279.           Note that this can lose if a later change than the one
  280.           we are processing specified &XVECEXP (PATTERN (object), 0, X)
  281.           but this shouldn't occur.  */
  282.  
  283.            validate_change (object, &PATTERN (object), newpat, 1);
  284.          }
  285.       else if (GET_CODE (pat) == USE || GET_CODE (pat) == CLOBBER)
  286.         /* If this insn is a CLOBBER or USE, it is always valid, but is
  287.            never recognized.  */
  288.         continue;
  289.       else
  290.         break;
  291.     }
  292.     }
  293.  
  294.   if (i == num_changes)
  295.     {
  296.       num_changes = 0;
  297.       return 1;
  298.     }
  299.   else
  300.     {
  301.       cancel_changes (0);
  302.       return 0;
  303.     }
  304. }
  305.  
  306. /* Return the number of changes so far in the current group.   */
  307.  
  308. int
  309. num_validated_changes ()
  310. {
  311.   return num_changes;
  312. }
  313.  
  314. /* Retract the changes numbered NUM and up.  */
  315.  
  316. void
  317. cancel_changes (num)
  318.      int num;
  319. {
  320.   int i;
  321.  
  322.   /* Back out all the changes.  Do this in the opposite order in which
  323.      they were made.  */
  324.   for (i = num_changes - 1; i >= num; i--)
  325.     {
  326.       *change_locs[i] = change_olds[i];
  327.       if (change_objects[i] && GET_CODE (change_objects[i]) != MEM)
  328.     INSN_CODE (change_objects[i]) = change_old_codes[i];
  329.     }
  330.   num_changes = num;
  331. }
  332.  
  333. /* Replace every occurrence of FROM in X with TO.  Mark each change with
  334.    validate_change passing OBJECT.  */
  335.  
  336. static void
  337. validate_replace_rtx_1 (loc, from, to, object)
  338.      rtx *loc;
  339.      rtx from, to, object;
  340. {
  341.   register int i, j;
  342.   register char *fmt;
  343.   register rtx x = *loc;
  344.   enum rtx_code code = GET_CODE (x);
  345.  
  346.   /* X matches FROM if it is the same rtx or they are both referring to the
  347.      same register in the same mode.  */
  348.   if (x == from
  349.       || (GET_CODE (x) == REG && GET_CODE (from) == REG
  350.       && GET_MODE (x) == GET_MODE (from)
  351.       && REGNO (x) == REGNO (from)))
  352.     {
  353.       validate_change (object, loc, to, 1);
  354.       return;
  355.     }
  356.  
  357.  
  358.   /* For commutative or comparison operations, try replacing each argument
  359.      separately and seeing if we made any changes.  If so, put a constant
  360.      argument last.*/
  361.   if (GET_RTX_CLASS (code) == '<' || GET_RTX_CLASS (code) == 'c')
  362.     {
  363.       int prev_changes = num_changes;
  364.  
  365.       validate_replace_rtx_1 (&XEXP (x, 0), from, to, object);
  366.       validate_replace_rtx_1 (&XEXP (x, 1), from, to, object);
  367.       if (prev_changes != num_changes && CONSTANT_P (XEXP (x, 0)))
  368.     {
  369.       validate_change (object, loc,
  370.                gen_rtx (GET_RTX_CLASS (code) == 'c' ? code
  371.                     : swap_condition (code),
  372.                     GET_MODE (x), XEXP (x, 1), XEXP (x, 0)),
  373.                1);
  374.       x = *loc;
  375.       code = GET_CODE (x);
  376.     }
  377.     }
  378.  
  379.   switch (code)
  380.     {
  381.     case PLUS:
  382.       /* If we have have a PLUS whose second operand is now a CONST_INT, use
  383.      plus_constant to try to simplify it.  */
  384.       if (GET_CODE (XEXP (x, 1)) == CONST_INT && XEXP (x, 1) == to)
  385.     validate_change (object, loc, 
  386.              plus_constant (XEXP (x, 0), INTVAL (XEXP (x, 1))), 1);
  387.       return;
  388.       
  389.     case SUBREG:
  390.       /* If we have a SUBREG of a register that we are replacing and we are
  391.      replacing it with a MEM, make a new MEM and try replacing the
  392.      SUBREG with it.  Don't do this if the MEM has a mode-dependent address
  393.      or if we would be widening it.  */
  394.  
  395.       if (SUBREG_REG (x) == from
  396.       && GET_CODE (from) == REG
  397.       && GET_CODE (to) == MEM
  398.       && ! mode_dependent_address_p (XEXP (to, 0))
  399.       && GET_MODE_SIZE (GET_MODE (x)) <= GET_MODE_SIZE (GET_MODE (to)))
  400.     {
  401.       int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
  402.       enum machine_mode mode = GET_MODE (x);
  403.       rtx new;
  404.  
  405. #if BYTES_BIG_ENDIAN
  406.       offset += (MIN (UNITS_PER_WORD,
  407.               GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
  408.              - MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode)));
  409. #endif
  410.  
  411.       new = gen_rtx (MEM, mode, plus_constant (XEXP (to, 0), offset));
  412.       MEM_VOLATILE_P (new) = MEM_VOLATILE_P (to);
  413.       RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (to);
  414.       MEM_IN_STRUCT_P (new) = MEM_IN_STRUCT_P (to);
  415.       validate_change (object, loc, new, 1);
  416.       return;
  417.     }
  418.       break;
  419.  
  420.     case ZERO_EXTRACT:
  421.     case SIGN_EXTRACT:
  422.       /* If we are replacing a register with memory, try to change the memory
  423.      to be the mode required for memory in extract operations (this isn't
  424.      likely to be an insertion operation; if it was, nothing bad will
  425.      happen, we might just fail in some cases).  */
  426.  
  427.       if (XEXP (x, 0) == from && GET_CODE (from) == REG && GET_CODE (to) == MEM
  428.       && GET_CODE (XEXP (x, 1)) == CONST_INT
  429.       && GET_CODE (XEXP (x, 2)) == CONST_INT
  430.       && ! mode_dependent_address_p (XEXP (to, 0)))
  431.     {
  432.       enum machine_mode wanted_mode = VOIDmode;
  433.       enum machine_mode is_mode = GET_MODE (to);
  434.       int width = INTVAL (XEXP (x, 1));
  435.       int pos = INTVAL (XEXP (x, 2));
  436.  
  437. #ifdef HAVE_extzv
  438.       if (code == ZERO_EXTRACT)
  439.         wanted_mode = insn_operand_mode[(int) CODE_FOR_extzv][1];
  440. #endif
  441. #ifdef HAVE_extv
  442.       if (code == SIGN_EXTRACT)
  443.         wanted_mode = insn_operand_mode[(int) CODE_FOR_extv][1];
  444. #endif
  445.  
  446.       /* If we have a narrower mode, we can do someting.  */
  447.       if (wanted_mode != VOIDmode
  448.           && GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
  449.         {
  450.           int offset = pos / BITS_PER_UNIT;
  451.           rtx newmem;
  452.  
  453.           /* If the bytes and bits are counted differently, we
  454.              must adjust the offset.  */
  455. #if BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN
  456.           offset = (GET_MODE_SIZE (is_mode) - GET_MODE_SIZE (wanted_mode)
  457.             - offset);
  458. #endif
  459.  
  460.           pos %= GET_MODE_BITSIZE (wanted_mode);
  461.  
  462.           newmem = gen_rtx (MEM, wanted_mode,
  463.                 plus_constant (XEXP (to, 0), offset));
  464.           RTX_UNCHANGING_P (newmem) = RTX_UNCHANGING_P (to);
  465.           MEM_VOLATILE_P (newmem) = MEM_VOLATILE_P (to);
  466.           MEM_IN_STRUCT_P (newmem) = MEM_IN_STRUCT_P (to);
  467.  
  468.           validate_change (object, &XEXP (x, 2),
  469.                    gen_rtx (CONST_INT, VOIDmode, pos), 1);
  470.           validate_change (object, &XEXP (x, 0), newmem, 1);
  471.         }
  472.     }
  473.  
  474.       break;
  475.     }
  476.       
  477.   fmt = GET_RTX_FORMAT (code);
  478.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  479.     {
  480.       if (fmt[i] == 'e')
  481.     validate_replace_rtx_1 (&XEXP (x, i), from, to, object);
  482.       else if (fmt[i] == 'E')
  483.     for (j = XVECLEN (x, i) - 1; j >= 0; j--)
  484.       validate_replace_rtx_1 (&XVECEXP (x, i, j), from, to, object);
  485.     }
  486. }
  487.  
  488. /* Try replacing every occurrence of FROM in INSN with TO.  After all
  489.    changes have been made, validate by seeing if INSN is still valid.  */
  490.  
  491. int
  492. validate_replace_rtx (from, to, insn)
  493.      rtx from, to, insn;
  494. {
  495.   validate_replace_rtx_1 (&PATTERN (insn), from, to, insn);
  496.   return apply_change_group ();
  497. }
  498.  
  499. #ifdef HAVE_cc0
  500. /* Return 1 if the insn using CC0 set by INSN does not contain
  501.    any ordered tests applied to the condition codes.
  502.    EQ and NE tests do not count.  */
  503.  
  504. int
  505. next_insn_tests_no_inequality (insn)
  506.      rtx insn;
  507. {
  508.   register rtx next = next_cc0_user (insn);
  509.  
  510.   /* If there is no next insn, we have to take the conservative choice.  */
  511.   if (next == 0)
  512.     return 0;
  513.  
  514.   return ((GET_CODE (next) == JUMP_INSN
  515.        || GET_CODE (next) == INSN
  516.        || GET_CODE (next) == CALL_INSN)
  517.       && ! inequality_comparisons_p (PATTERN (next)));
  518. }
  519.  
  520. #if 0  /* This is useless since the insn that sets the cc's
  521.       must be followed immediately by the use of them.  */
  522. /* Return 1 if the CC value set up by INSN is not used.  */
  523.  
  524. int
  525. next_insns_test_no_inequality (insn)
  526.      rtx insn;
  527. {
  528.   register rtx next = NEXT_INSN (insn);
  529.  
  530.   for (; next != 0; next = NEXT_INSN (next))
  531.     {
  532.       if (GET_CODE (next) == CODE_LABEL
  533.       || GET_CODE (next) == BARRIER)
  534.     return 1;
  535.       if (GET_CODE (next) == NOTE)
  536.     continue;
  537.       if (inequality_comparisons_p (PATTERN (next)))
  538.     return 0;
  539.       if (sets_cc0_p (PATTERN (next)) == 1)
  540.     return 1;
  541.       if (! reg_mentioned_p (cc0_rtx, PATTERN (next)))
  542.     return 1;
  543.     }
  544.   return 1;
  545. }
  546. #endif
  547. #endif
  548.  
  549. /* This is used by find_single_use to locate an rtx that contains exactly one
  550.    use of DEST, which is typically either a REG or CC0.  It returns a
  551.    pointer to the innermost rtx expression containing DEST.  */
  552.  
  553. static rtx *
  554. find_single_use_1 (dest, loc)
  555.      rtx dest;
  556.      rtx *loc;
  557. {
  558.   rtx x = *loc;
  559.   enum rtx_code code = GET_CODE (x);
  560.   rtx *result = 0;
  561.   rtx *this_result;
  562.   int i;
  563.   char *fmt = GET_RTX_FORMAT (code);
  564.  
  565.   /* Check each expression and vector of this code.  Look for a unique usage
  566.      of DEST.  */
  567.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  568.     {
  569.       if (fmt[i] == 'e')
  570.     {
  571.       if (XEXP (x, i) == dest
  572.           || (GET_CODE (XEXP (x, i)) == REG && GET_CODE (dest) == REG
  573.           && REGNO (dest) == REGNO (XEXP (x, i))))
  574.         this_result = loc;
  575.       else
  576.         this_result = find_single_use_1 (dest, &XEXP (x, i));
  577.  
  578.       if (result == 0)
  579.         result = this_result;
  580.       else if (this_result)
  581.         /* Duplicate usage.  */
  582.         return 0;
  583.     }
  584.       else if (fmt[i] == 'E')
  585.     {
  586.       int j;
  587.  
  588.       for (j = XVECLEN (x, i) - 1; i >= 0; i--)
  589.         {
  590.           if (XVECEXP (x, i, j) == dest
  591.           || (GET_CODE (XVECEXP (x, i, j)) == REG
  592.               && GET_CODE (dest) == REG
  593.               && REGNO (XVECEXP (x, i, j)) == REGNO (dest)))
  594.         this_result = loc;
  595.           else
  596.         this_result = find_single_use_1 (dest, &XVECEXP (x, i, j));
  597.  
  598.           if (result == 0)
  599.         result = this_result;
  600.           else if (this_result)
  601.         return 0;
  602.         }
  603.     }
  604.     }
  605.  
  606.   return result;
  607. }
  608.  
  609. /* See if DEST, produced in INSN, is used only a single time in the
  610.    sequel.  If so, return a pointer to the innermost rtx expression in which
  611.    it is used.
  612.  
  613.    If PLOC is non-zero, *PLOC is set to the insn containing the single use.
  614.  
  615.    This routine will return usually zero either before flow is called (because
  616.    there will be no LOG_LINKS notes) or after reload (because the REG_DEAD
  617.    note can't be trusted).
  618.  
  619.    If DEST is cc0_rtx, we look only at the next insn.  In that case, we don't
  620.    care about REG_DEAD notes or LOG_LINKS.
  621.  
  622.    Otherwise, we find the single use by finding an insn that has a
  623.    LOG_LINKS pointing at INSN and has a REG_DEAD note for DEST.  If DEST is
  624.    only referenced once in that insn, we know that it must be the first
  625.    and last insn referencing DEST.  */
  626.  
  627. rtx *
  628. find_single_use (dest, insn, ploc)
  629.      rtx dest;
  630.      rtx insn;
  631.      rtx *ploc;
  632. {
  633.   rtx next;
  634.   rtx *result;
  635.   rtx link;
  636.   int regno;
  637.  
  638. #ifdef HAVE_cc0
  639.   if (dest == cc0_rtx)
  640.     {
  641.       next = NEXT_INSN (insn);
  642.       if (next == 0
  643.       || (GET_CODE (next) != INSN && GET_CODE (next) != JUMP_INSN))
  644.     return 0;
  645.  
  646.       result = find_single_use_1 (dest, &PATTERN (next));
  647.       if (result && ploc)
  648.     *ploc = next;
  649.       return result;
  650.     }
  651. #endif
  652.  
  653.   if (reload_completed || reload_in_progress || GET_CODE (dest) != REG)
  654.     return 0;
  655.  
  656.   regno = REGNO (dest);
  657.  
  658.   for (next = next_nonnote_insn (insn);
  659.        next != 0 && GET_CODE (next) != CODE_LABEL;
  660.        next = next_nonnote_insn (next))
  661.     if ((GET_CODE (next) == INSN || GET_CODE (next) == JUMP_INSN
  662.      || GET_CODE (next) == CALL_INSN)
  663.     && find_regno_note (next, REG_DEAD, regno))
  664.       {
  665.     for (link = LOG_LINKS (next); link; link = XEXP (link, 1))
  666.       if (XEXP (link, 0) == insn)
  667.         break;
  668.  
  669.     if (link)
  670.       {
  671.         result = find_single_use_1 (dest, &PATTERN (next));
  672.         if (ploc)
  673.           *ploc = next;
  674.         return result;
  675.       }
  676.       }
  677.  
  678.   return 0;
  679. }
  680.  
  681. /* Return 1 if OP is a valid general operand for machine mode MODE.
  682.    This is either a register reference, a memory reference,
  683.    or a constant.  In the case of a memory reference, the address
  684.    is checked for general validity for the target machine.
  685.  
  686.    Register and memory references must have mode MODE in order to be valid,
  687.    but some constants have no machine mode and are valid for any mode.
  688.  
  689.    If MODE is VOIDmode, OP is checked for validity for whatever mode
  690.    it has.
  691.  
  692.    The main use of this function is as a predicate in match_operand
  693.    expressions in the machine description.
  694.  
  695.    For an explaination of this function's behavior for registers of
  696.    class NO_REGS, see the comment for `register_operand'.  */
  697.  
  698. int
  699. general_operand (op, mode)
  700.      register rtx op;
  701.      enum machine_mode mode;
  702. {
  703.   register enum rtx_code code = GET_CODE (op);
  704.   int mode_altering_drug = 0;
  705.  
  706.   if (mode == VOIDmode)
  707.     mode = GET_MODE (op);
  708.  
  709.   if (CONSTANT_P (op))
  710.     return ((GET_MODE (op) == VOIDmode || GET_MODE (op) == mode)
  711.         && LEGITIMATE_CONSTANT_P (op));
  712.  
  713.   /* Except for certain constants with VOIDmode, already checked for,
  714.      OP's mode must match MODE if MODE specifies a mode.  */
  715.  
  716.   if (GET_MODE (op) != mode)
  717.     return 0;
  718.  
  719.   if (code == SUBREG)
  720.     {
  721. #ifdef INSN_SCHEDULING
  722.       /* On machines that have insn scheduling, we want all memory
  723.      reference to be explicit, so outlaw paradoxical SUBREGs.  */
  724.       if (GET_CODE (SUBREG_REG (op)) == MEM
  725.       && GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (op))))
  726.     return 0;
  727. #endif
  728.  
  729.       op = SUBREG_REG (op);
  730.       code = GET_CODE (op);
  731. #if 0
  732.       /* No longer needed, since (SUBREG (MEM...))
  733.      will load the MEM into a reload reg in the MEM's own mode.  */
  734.       mode_altering_drug = 1;
  735. #endif
  736.     }
  737.  
  738.   if (code == REG)
  739.     /* A register whose class is NO_REGS is not a general operand.  */
  740.     return (REGNO (op) >= FIRST_PSEUDO_REGISTER
  741.         || REGNO_REG_CLASS (REGNO (op)) != NO_REGS);
  742.  
  743.   if (code == MEM)
  744.     {
  745.       register rtx y = XEXP (op, 0);
  746.       if (! volatile_ok && MEM_VOLATILE_P (op))
  747.     return 0;
  748.       /* Use the mem's mode, since it will be reloaded thus.  */
  749.       mode = GET_MODE (op);
  750.       GO_IF_LEGITIMATE_ADDRESS (mode, y, win);
  751.     }
  752.   return 0;
  753.  
  754.  win:
  755.   if (mode_altering_drug)
  756.     return ! mode_dependent_address_p (XEXP (op, 0));
  757.   return 1;
  758. }
  759.  
  760. /* Return 1 if OP is a valid memory address for a memory reference
  761.    of mode MODE.
  762.  
  763.    The main use of this function is as a predicate in match_operand
  764.    expressions in the machine description.  */
  765.  
  766. int
  767. address_operand (op, mode)
  768.      register rtx op;
  769.      enum machine_mode mode;
  770. {
  771.   return memory_address_p (mode, op);
  772. }
  773.  
  774. /* Return 1 if OP is a register reference of mode MODE.
  775.    If MODE is VOIDmode, accept a register in any mode.
  776.  
  777.    The main use of this function is as a predicate in match_operand
  778.    expressions in the machine description.
  779.  
  780.    As a special exception, registers whose class is NO_REGS are
  781.    not accepted by `register_operand'.  The reason for this change
  782.    is to allow the representation of special architecture artifacts
  783.    (such as a condition code register) without extending the rtl
  784.    definitions.  Since registers of class NO_REGS cannot be used
  785.    as registers in any case where register classes are examined,
  786.    it is most consistent to keep this function from accepting them.  */
  787.  
  788. int
  789. register_operand (op, mode)
  790.      register rtx op;
  791.      enum machine_mode mode;
  792. {
  793.   if (GET_MODE (op) != mode && mode != VOIDmode)
  794.     return 0;
  795.  
  796.   if (GET_CODE (op) == SUBREG)
  797.     {
  798.       /* Before reload, we can allow (SUBREG (MEM...)) as a register operand
  799.      because it is guaranteed to be reloaded into one.
  800.      Just make sure the MEM is valid in itself.
  801.      (Ideally, (SUBREG (MEM)...) should not exist after reload,
  802.      but currently it does result from (SUBREG (REG)...) where the
  803.      reg went on the stack.)  */
  804.       if (! reload_completed && GET_CODE (SUBREG_REG (op)) == MEM)
  805.     return general_operand (op, mode);
  806.       op = SUBREG_REG (op);
  807.     }
  808.  
  809.   /* We don't consider registers whose class is NO_REGS
  810.      to be a register operand.  */
  811.   return (GET_CODE (op) == REG
  812.       && (REGNO (op) >= FIRST_PSEUDO_REGISTER
  813.           || REGNO_REG_CLASS (REGNO (op)) != NO_REGS));
  814. }
  815.  
  816. /* Return 1 if OP should match a MATCH_SCRATCH, i.e., if it is a SCRATCH
  817.    or a hard register.  */
  818.  
  819. int
  820. scratch_operand (op, mode)
  821.      register rtx op;
  822.      enum machine_mode mode;
  823. {
  824.   return (GET_MODE (op) == mode
  825.       && (GET_CODE (op) == SCRATCH
  826.           || (GET_CODE (op) == REG
  827.           && REGNO (op) < FIRST_PSEUDO_REGISTER)));
  828. }
  829.  
  830. /* Return 1 if OP is a valid immediate operand for mode MODE.
  831.  
  832.    The main use of this function is as a predicate in match_operand
  833.    expressions in the machine description.  */
  834.  
  835. int
  836. immediate_operand (op, mode)
  837.      register rtx op;
  838.      enum machine_mode mode;
  839. {
  840.   /* Don't accept CONST_INT or anything similar
  841.      if the caller wants something floating.  */
  842.   if (GET_MODE (op) == VOIDmode && mode != VOIDmode
  843.       && GET_MODE_CLASS (mode) != MODE_INT)
  844.     return 0;
  845.  
  846.   return (CONSTANT_P (op)
  847.       && (GET_MODE (op) == mode || mode == VOIDmode
  848.           || GET_MODE (op) == VOIDmode)
  849.       && LEGITIMATE_CONSTANT_P (op));
  850. }
  851.  
  852. /* Returns 1 if OP is an operand that is a CONST_INT.  */
  853.  
  854. int
  855. const_int_operand (op, mode)
  856.      register rtx op;
  857.      enum machine_mode mode;
  858. {
  859.   return GET_CODE (op) == CONST_INT;
  860. }
  861.  
  862. /* Returns 1 if OP is an operand that is a constant integer or constant
  863.    floating-point number.  */
  864.  
  865. int
  866. const_double_operand (op, mode)
  867.      register rtx op;
  868.      enum machine_mode mode;
  869. {
  870.   return ((GET_CODE (op) == CONST_DOUBLE || GET_CODE (op) == CONST_INT)
  871.       && (mode == VOIDmode || GET_MODE (op) == mode
  872.           || GET_MODE (op) == VOIDmode));
  873. }
  874.  
  875. /* Return 1 if OP is a general operand that is not an immediate operand.  */
  876.  
  877. int
  878. nonimmediate_operand (op, mode)
  879.      register rtx op;
  880.      enum machine_mode mode;
  881. {
  882.   return (general_operand (op, mode) && ! CONSTANT_P (op));
  883. }
  884.  
  885. /* Return 1 if OP is a register reference or immediate value of mode MODE.  */
  886.  
  887. int
  888. nonmemory_operand (op, mode)
  889.      register rtx op;
  890.      enum machine_mode mode;
  891. {
  892.   if (CONSTANT_P (op))
  893.     {
  894.       /* Don't accept CONST_INT or anything similar
  895.      if the caller wants something floating.  */
  896.       if (GET_MODE (op) == VOIDmode && mode != VOIDmode
  897.       && GET_MODE_CLASS (mode) != MODE_INT)
  898.     return 0;
  899.  
  900.       return ((GET_MODE (op) == VOIDmode || GET_MODE (op) == mode)
  901.           && LEGITIMATE_CONSTANT_P (op));
  902.     }
  903.  
  904.   if (GET_MODE (op) != mode && mode != VOIDmode)
  905.     return 0;
  906.  
  907.   if (GET_CODE (op) == SUBREG)
  908.     {
  909.       /* Before reload, we can allow (SUBREG (MEM...)) as a register operand
  910.      because it is guaranteed to be reloaded into one.
  911.      Just make sure the MEM is valid in itself.
  912.      (Ideally, (SUBREG (MEM)...) should not exist after reload,
  913.      but currently it does result from (SUBREG (REG)...) where the
  914.      reg went on the stack.)  */
  915.       if (! reload_completed && GET_CODE (SUBREG_REG (op)) == MEM)
  916.     return general_operand (op, mode);
  917.       op = SUBREG_REG (op);
  918.     }
  919.  
  920.   /* We don't consider registers whose class is NO_REGS
  921.      to be a register operand.  */
  922.   return (GET_CODE (op) == REG
  923.       && (REGNO (op) >= FIRST_PSEUDO_REGISTER
  924.           || REGNO_REG_CLASS (REGNO (op)) != NO_REGS));
  925. }
  926.  
  927. /* Return 1 if OP is a valid operand that stands for pushing a
  928.    value of mode MODE onto the stack.
  929.  
  930.    The main use of this function is as a predicate in match_operand
  931.    expressions in the machine description.  */
  932.  
  933. int
  934. push_operand (op, mode)
  935.      rtx op;
  936.      enum machine_mode mode;
  937. {
  938.   if (GET_CODE (op) != MEM)
  939.     return 0;
  940.  
  941.   if (GET_MODE (op) != mode)
  942.     return 0;
  943.  
  944.   op = XEXP (op, 0);
  945.  
  946.   if (GET_CODE (op) != STACK_PUSH_CODE)
  947.     return 0;
  948.  
  949.   return XEXP (op, 0) == stack_pointer_rtx;
  950. }
  951.  
  952. /* Return 1 if ADDR is a valid memory address for mode MODE.  */
  953.  
  954. int
  955. memory_address_p (mode, addr)
  956.      enum machine_mode mode;
  957.      register rtx addr;
  958. {
  959.   GO_IF_LEGITIMATE_ADDRESS (mode, addr, win);
  960.   return 0;
  961.  
  962.  win:
  963.   return 1;
  964. }
  965.  
  966. /* Return 1 if OP is a valid memory reference with mode MODE,
  967.    including a valid address.
  968.  
  969.    The main use of this function is as a predicate in match_operand
  970.    expressions in the machine description.  */
  971.  
  972. int
  973. memory_operand (op, mode)
  974.      register rtx op;
  975.      enum machine_mode mode;
  976. {
  977.   rtx inner;
  978.  
  979.   if (! reload_completed)
  980.     /* Note that no SUBREG is a memory operand before end of reload pass,
  981.        because (SUBREG (MEM...)) forces reloading into a register.  */
  982.     return GET_CODE (op) == MEM && general_operand (op, mode);
  983.  
  984.   if (mode != VOIDmode && GET_MODE (op) != mode)
  985.     return 0;
  986.  
  987.   inner = op;
  988.   if (GET_CODE (inner) == SUBREG)
  989.     inner = SUBREG_REG (inner);
  990.  
  991.   return (GET_CODE (inner) == MEM && general_operand (op, mode));
  992. }
  993.  
  994. /* Return 1 if OP is a valid indirect memory reference with mode MODE;
  995.    that is, a memory reference whose address is a general_operand.  */
  996.  
  997. int
  998. indirect_operand (op, mode)
  999.      register rtx op;
  1000.      enum machine_mode mode;
  1001. {
  1002.   return (memory_operand (op, mode) && general_operand (XEXP (op, 0), Pmode));
  1003. }
  1004.  
  1005. /* Return 1 if this is a comparison operator.  This allows the use of
  1006.    MATCH_OPERATOR to recognize all the branch insns.  */
  1007.  
  1008. int
  1009. comparison_operator (op, mode)
  1010.     register rtx op;
  1011.     enum machine_mode mode;
  1012. {
  1013.   return ((mode == VOIDmode || GET_MODE (op) == mode)
  1014.       && GET_RTX_CLASS (GET_CODE (op)) == '<');
  1015. }
  1016.  
  1017. /* If BODY is an insn body that uses ASM_OPERANDS,
  1018.    return the number of operands (both input and output) in the insn.
  1019.    Otherwise return -1.  */
  1020.  
  1021. int
  1022. asm_noperands (body)
  1023.      rtx body;
  1024. {
  1025.   if (GET_CODE (body) == ASM_OPERANDS)
  1026.     /* No output operands: return number of input operands.  */
  1027.     return ASM_OPERANDS_INPUT_LENGTH (body);
  1028.   if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
  1029.     /* Single output operand: BODY is (set OUTPUT (asm_operands ...)).  */
  1030.     return ASM_OPERANDS_INPUT_LENGTH (SET_SRC (body)) + 1;
  1031.   else if (GET_CODE (body) == PARALLEL
  1032.        && GET_CODE (XVECEXP (body, 0, 0)) == SET
  1033.        && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) == ASM_OPERANDS)
  1034.     {
  1035.       /* Multiple output operands, or 1 output plus some clobbers:
  1036.      body is [(set OUTPUT (asm_operands ...))... (clobber (reg ...))...].  */
  1037.       int i;
  1038.       int n_sets;
  1039.  
  1040.       /* Count backwards through CLOBBERs to determine number of SETs.  */
  1041.       for (i = XVECLEN (body, 0); i > 0; i--)
  1042.     {
  1043.       if (GET_CODE (XVECEXP (body, 0, i - 1)) == SET)
  1044.         break;
  1045.       if (GET_CODE (XVECEXP (body, 0, i - 1)) != CLOBBER)
  1046.         return -1;
  1047.     }
  1048.  
  1049.       /* N_SETS is now number of output operands.  */
  1050.       n_sets = i;
  1051.  
  1052.       /* Verify that all the SETs we have
  1053.      came from a single original asm_operands insn
  1054.      (so that invalid combinations are blocked).  */
  1055.       for (i = 0; i < n_sets; i++)
  1056.     {
  1057.       rtx elt = XVECEXP (body, 0, i);
  1058.       if (GET_CODE (elt) != SET)
  1059.         return -1;
  1060.       if (GET_CODE (SET_SRC (elt)) != ASM_OPERANDS)
  1061.         return -1;
  1062.       /* If these ASM_OPERANDS rtx's came from different original insns
  1063.          then they aren't allowed together.  */
  1064.       if (ASM_OPERANDS_INPUT_VEC (SET_SRC (elt))
  1065.           != ASM_OPERANDS_INPUT_VEC (SET_SRC (XVECEXP (body, 0, 0))))
  1066.         return -1;
  1067.     }
  1068.       return (ASM_OPERANDS_INPUT_LENGTH (SET_SRC (XVECEXP (body, 0, 0)))
  1069.           + n_sets);
  1070.     }
  1071.   else if (GET_CODE (body) == PARALLEL
  1072.        && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
  1073.     {
  1074.       /* 0 outputs, but some clobbers:
  1075.      body is [(asm_operands ...) (clobber (reg ...))...].  */
  1076.       int i;
  1077.  
  1078.       /* Make sure all the other parallel things really are clobbers.  */
  1079.       for (i = XVECLEN (body, 0) - 1; i > 0; i--)
  1080.     if (GET_CODE (XVECEXP (body, 0, i)) != CLOBBER)
  1081.       return -1;
  1082.  
  1083.       return ASM_OPERANDS_INPUT_LENGTH (XVECEXP (body, 0, 0));
  1084.     }
  1085.   else
  1086.     return -1;
  1087. }
  1088.  
  1089. /* Assuming BODY is an insn body that uses ASM_OPERANDS,
  1090.    copy its operands (both input and output) into the vector OPERANDS,
  1091.    the locations of the operands within the insn into the vector OPERAND_LOCS,
  1092.    and the constraints for the operands into CONSTRAINTS.
  1093.    Write the modes of the operands into MODES.
  1094.    Return the assembler-template.
  1095.  
  1096.    If MODES, OPERAND_LOCS, CONSTRAINTS or OPERANDS is 0,
  1097.    we don't store that info.  */
  1098.  
  1099. char *
  1100. decode_asm_operands (body, operands, operand_locs, constraints, modes)
  1101.      rtx body;
  1102.      rtx *operands;
  1103.      rtx **operand_locs;
  1104.      char **constraints;
  1105.      enum machine_mode *modes;
  1106. {
  1107.   register int i;
  1108.   int noperands;
  1109.   char *template = 0;
  1110.  
  1111.   if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
  1112.     {
  1113.       rtx asmop = SET_SRC (body);
  1114.       /* Single output operand: BODY is (set OUTPUT (asm_operands ....)).  */
  1115.  
  1116.       noperands = ASM_OPERANDS_INPUT_LENGTH (asmop) + 1;
  1117.  
  1118.       for (i = 1; i < noperands; i++)
  1119.     {
  1120.       if (operand_locs)
  1121.         operand_locs[i] = &ASM_OPERANDS_INPUT (asmop, i - 1);
  1122.       if (operands)
  1123.         operands[i] = ASM_OPERANDS_INPUT (asmop, i - 1);
  1124.       if (constraints)
  1125.         constraints[i] = ASM_OPERANDS_INPUT_CONSTRAINT (asmop, i - 1);
  1126.       if (modes)
  1127.         modes[i] = ASM_OPERANDS_INPUT_MODE (asmop, i - 1);
  1128.     }
  1129.  
  1130.       /* The output is in the SET.
  1131.      Its constraint is in the ASM_OPERANDS itself.  */
  1132.       if (operands)
  1133.     operands[0] = SET_DEST (body);
  1134.       if (operand_locs)
  1135.     operand_locs[0] = &SET_DEST (body);
  1136.       if (constraints)
  1137.     constraints[0] = ASM_OPERANDS_OUTPUT_CONSTRAINT (asmop);
  1138.       if (modes)
  1139.     modes[0] = GET_MODE (SET_DEST (body));
  1140.       template = ASM_OPERANDS_TEMPLATE (asmop);
  1141.     }
  1142.   else if (GET_CODE (body) == ASM_OPERANDS)
  1143.     {
  1144.       rtx asmop = body;
  1145.       /* No output operands: BODY is (asm_operands ....).  */
  1146.  
  1147.       noperands = ASM_OPERANDS_INPUT_LENGTH (asmop);
  1148.  
  1149.       /* The input operands are found in the 1st element vector.  */
  1150.       /* Constraints for inputs are in the 2nd element vector.  */
  1151.       for (i = 0; i < noperands; i++)
  1152.     {
  1153.       if (operand_locs)
  1154.         operand_locs[i] = &ASM_OPERANDS_INPUT (asmop, i);
  1155.       if (operands)
  1156.         operands[i] = ASM_OPERANDS_INPUT (asmop, i);
  1157.       if (constraints)
  1158.         constraints[i] = ASM_OPERANDS_INPUT_CONSTRAINT (asmop, i);
  1159.       if (modes)
  1160.         modes[i] = ASM_OPERANDS_INPUT_MODE (asmop, i);
  1161.     }
  1162.       template = ASM_OPERANDS_TEMPLATE (asmop);
  1163.     }
  1164.   else if (GET_CODE (body) == PARALLEL
  1165.        && GET_CODE (XVECEXP (body, 0, 0)) == SET)
  1166.     {
  1167.       rtx asmop = SET_SRC (XVECEXP (body, 0, 0));
  1168.       int nparallel = XVECLEN (body, 0); /* Includes CLOBBERs.  */
  1169.       int nin = ASM_OPERANDS_INPUT_LENGTH (asmop);
  1170.       int nout = 0;        /* Does not include CLOBBERs.  */
  1171.  
  1172.       /* At least one output, plus some CLOBBERs.  */
  1173.  
  1174.       /* The outputs are in the SETs.
  1175.      Their constraints are in the ASM_OPERANDS itself.  */
  1176.       for (i = 0; i < nparallel; i++)
  1177.     {
  1178.       if (GET_CODE (XVECEXP (body, 0, i)) == CLOBBER)
  1179.         break;        /* Past last SET */
  1180.       
  1181.       if (operands)
  1182.         operands[i] = SET_DEST (XVECEXP (body, 0, i));
  1183.       if (operand_locs)
  1184.         operand_locs[i] = &SET_DEST (XVECEXP (body, 0, i));
  1185.       if (constraints)
  1186.         constraints[i] = XSTR (SET_SRC (XVECEXP (body, 0, i)), 1);
  1187.       if (modes)
  1188.         modes[i] = GET_MODE (SET_DEST (XVECEXP (body, 0, i)));
  1189.       nout++;
  1190.     }
  1191.  
  1192.       for (i = 0; i < nin; i++)
  1193.     {
  1194.       if (operand_locs)
  1195.         operand_locs[i + nout] = &ASM_OPERANDS_INPUT (asmop, i);
  1196.       if (operands)
  1197.         operands[i + nout] = ASM_OPERANDS_INPUT (asmop, i);
  1198.       if (constraints)
  1199.         constraints[i + nout] = ASM_OPERANDS_INPUT_CONSTRAINT (asmop, i);
  1200.       if (modes)
  1201.         modes[i + nout] = ASM_OPERANDS_INPUT_MODE (asmop, i);
  1202.     }
  1203.  
  1204.       template = ASM_OPERANDS_TEMPLATE (asmop);
  1205.     }
  1206.   else if (GET_CODE (body) == PARALLEL
  1207.        && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
  1208.     {
  1209.       /* No outputs, but some CLOBBERs.  */
  1210.  
  1211.       rtx asmop = XVECEXP (body, 0, 0);
  1212.       int nin = ASM_OPERANDS_INPUT_LENGTH (asmop);
  1213.  
  1214.       for (i = 0; i < nin; i++)
  1215.     {
  1216.       if (operand_locs)
  1217.         operand_locs[i] = &ASM_OPERANDS_INPUT (asmop, i);
  1218.       if (operands)
  1219.         operands[i] = ASM_OPERANDS_INPUT (asmop, i);
  1220.       if (constraints)
  1221.         constraints[i] = ASM_OPERANDS_INPUT_CONSTRAINT (asmop, i);
  1222.       if (modes)
  1223.         modes[i] = ASM_OPERANDS_INPUT_MODE (asmop, i);
  1224.     }
  1225.  
  1226.       template = ASM_OPERANDS_TEMPLATE (asmop);
  1227.     }
  1228.  
  1229.   return template;
  1230. }
  1231.  
  1232. extern rtx plus_constant_for_output ();
  1233. extern rtx copy_rtx ();
  1234.  
  1235. /* Given an rtx *P, if it is a sum containing an integer constant term,
  1236.    return the location (type rtx *) of the pointer to that constant term.
  1237.    Otherwise, return a null pointer.  */
  1238.  
  1239. static rtx *
  1240. find_constant_term_loc (p)
  1241.      rtx *p;
  1242. {
  1243.   register rtx *tem;
  1244.   register enum rtx_code code = GET_CODE (*p);
  1245.  
  1246.   /* If *P IS such a constant term, P is its location.  */
  1247.  
  1248.   if (code == CONST_INT || code == SYMBOL_REF || code == LABEL_REF
  1249.       || code == CONST)
  1250.     return p;
  1251.  
  1252.   /* Otherwise, if not a sum, it has no constant term.  */
  1253.  
  1254.   if (GET_CODE (*p) != PLUS)
  1255.     return 0;
  1256.  
  1257.   /* If one of the summands is constant, return its location.  */
  1258.  
  1259.   if (XEXP (*p, 0) && CONSTANT_P (XEXP (*p, 0))
  1260.       && XEXP (*p, 1) && CONSTANT_P (XEXP (*p, 1)))
  1261.     return p;
  1262.  
  1263.   /* Otherwise, check each summand for containing a constant term.  */
  1264.  
  1265.   if (XEXP (*p, 0) != 0)
  1266.     {
  1267.       tem = find_constant_term_loc (&XEXP (*p, 0));
  1268.       if (tem != 0)
  1269.     return tem;
  1270.     }
  1271.  
  1272.   if (XEXP (*p, 1) != 0)
  1273.     {
  1274.       tem = find_constant_term_loc (&XEXP (*p, 1));
  1275.       if (tem != 0)
  1276.     return tem;
  1277.     }
  1278.  
  1279.   return 0;
  1280. }
  1281.  
  1282. /* Return 1 if OP is a memory reference
  1283.    whose address contains no side effects
  1284.    and remains valid after the addition
  1285.    of a positive integer less than the
  1286.    size of the object being referenced.
  1287.  
  1288.    We assume that the original address is valid and do not check it.
  1289.  
  1290.    This uses strict_memory_address_p as a subroutine, so
  1291.    don't use it before reload.  */
  1292.  
  1293. int
  1294. offsettable_memref_p (op)
  1295.      rtx op;
  1296. {
  1297.   return ((GET_CODE (op) == MEM)
  1298.       && offsettable_address_p (1, GET_MODE (op), XEXP (op, 0)));
  1299. }
  1300.  
  1301. /* Similar, but don't require a strictly valid mem ref:
  1302.    consider pseudo-regs valid as index or base regs.  */
  1303.  
  1304. int
  1305. offsettable_nonstrict_memref_p (op)
  1306.      rtx op;
  1307. {
  1308.   return ((GET_CODE (op) == MEM)
  1309.       && offsettable_address_p (0, GET_MODE (op), XEXP (op, 0)));
  1310. }
  1311.  
  1312. /* Return 1 if Y is a memory address which contains no side effects
  1313.    and would remain valid after the addition of a positive integer
  1314.    less than the size of that mode.
  1315.  
  1316.    We assume that the original address is valid and do not check it.
  1317.    We do check that it is valid for narrower modes.
  1318.  
  1319.    If STRICTP is nonzero, we require a strictly valid address,
  1320.    for the sake of use in reload.c.  */
  1321.  
  1322. int
  1323. offsettable_address_p (strictp, mode, y)
  1324.      int strictp;
  1325.      enum machine_mode mode;
  1326.      register rtx y;
  1327. {
  1328.   register enum rtx_code ycode = GET_CODE (y);
  1329.   register rtx z;
  1330.   rtx y1 = y;
  1331.   rtx *y2;
  1332.   int (*addressp) () = (strictp ? strict_memory_address_p : memory_address_p);
  1333.  
  1334.   if (CONSTANT_ADDRESS_P (y))
  1335.     return 1;
  1336.  
  1337.   /* Adjusting an offsettable address involves changing to a narrower mode.
  1338.      Make sure that's OK.  */
  1339.  
  1340.   if (mode_dependent_address_p (y))
  1341.     return 0;
  1342.  
  1343.   /* If the expression contains a constant term,
  1344.      see if it remains valid when max possible offset is added.  */
  1345.  
  1346.   if ((ycode == PLUS) && (y2 = find_constant_term_loc (&y1)))
  1347.     {
  1348.       int old = INTVAL (y1 = *y2);
  1349.       int good;
  1350.       INTVAL (y1) += GET_MODE_SIZE (mode) - 1;
  1351.       good = (*addressp) (mode, y);
  1352.       /* In any case, restore old contents of memory.  */
  1353.       INTVAL (y1) = old;
  1354.       return good;
  1355.     }
  1356.  
  1357.   if (ycode == PRE_DEC || ycode == PRE_INC
  1358.       || ycode == POST_DEC || ycode == POST_INC)
  1359.     return 0;
  1360.  
  1361.   /* The offset added here is chosen as the maximum offset that
  1362.      any instruction could need to add when operating on something
  1363.      of the specified mode.  We assume that if Y and Y+c are
  1364.      valid addresses then so is Y+d for all 0<d<c.  */
  1365.  
  1366.   z = plus_constant_for_output (y, GET_MODE_SIZE (mode) - 1);
  1367.  
  1368.   /* Use QImode because an odd displacement may be automatically invalid
  1369.      for any wider mode.  But it should be valid for a single byte.  */
  1370.   return (*addressp) (QImode, z);
  1371. }
  1372.  
  1373. /* Return 1 if ADDR is an address-expression whose effect depends
  1374.    on the mode of the memory reference it is used in.
  1375.  
  1376.    Autoincrement addressing is a typical example of mode-dependence
  1377.    because the amount of the increment depends on the mode.  */
  1378.  
  1379. int
  1380. mode_dependent_address_p (addr)
  1381.      rtx addr;
  1382. {
  1383.   GO_IF_MODE_DEPENDENT_ADDRESS (addr, win);
  1384.   return 0;
  1385.  win:
  1386.   return 1;
  1387. }
  1388.  
  1389. /* Return 1 if OP is a general operand
  1390.    other than a memory ref with a mode dependent address.  */
  1391.  
  1392. int
  1393. mode_independent_operand (op, mode)
  1394.      enum machine_mode mode;
  1395.      rtx op;
  1396. {
  1397.   rtx addr;
  1398.  
  1399.   if (! general_operand (op, mode))
  1400.     return 0;
  1401.  
  1402.   if (GET_CODE (op) != MEM)
  1403.     return 1;
  1404.  
  1405.   addr = XEXP (op, 0);
  1406.   GO_IF_MODE_DEPENDENT_ADDRESS (addr, lose);
  1407.   return 1;
  1408.  lose:
  1409.   return 0;
  1410. }
  1411.  
  1412. /* Given an operand OP that is a valid memory reference
  1413.    which satisfies offsettable_memref_p,
  1414.    return a new memory reference whose address has been adjusted by OFFSET.
  1415.    OFFSET should be positive and less than the size of the object referenced.
  1416. */
  1417.  
  1418. rtx
  1419. adj_offsettable_operand (op, offset)
  1420.      rtx op;
  1421.      int offset;
  1422. {
  1423.   register enum rtx_code code = GET_CODE (op);
  1424.  
  1425.   if (code == MEM) 
  1426.     {
  1427.       register rtx y = XEXP (op, 0);
  1428.       register rtx new;
  1429.  
  1430.       if (CONSTANT_ADDRESS_P (y))
  1431.     {
  1432.       new = gen_rtx (MEM, GET_MODE (op), plus_constant_for_output (y, offset));
  1433.       RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (op);
  1434.       return new;
  1435.     }
  1436.  
  1437.       if (GET_CODE (y) == PLUS)
  1438.     {
  1439.       rtx z = y;
  1440.       register rtx *const_loc;
  1441.  
  1442.       op = copy_rtx (op);
  1443.       z = XEXP (op, 0);
  1444.       const_loc = find_constant_term_loc (&z);
  1445.       if (const_loc)
  1446.         {
  1447.           *const_loc = plus_constant_for_output (*const_loc, offset);
  1448.           return op;
  1449.         }
  1450.     }
  1451.  
  1452.       new = gen_rtx (MEM, GET_MODE (op), plus_constant_for_output (y, offset));
  1453.       RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (op);
  1454.       return new;
  1455.     }
  1456.   abort ();
  1457. }
  1458.  
  1459. #ifdef REGISTER_CONSTRAINTS
  1460.  
  1461. /* Check the operands of an insn (found in recog_operands)
  1462.    against the insn's operand constraints (found via INSN_CODE_NUM)
  1463.    and return 1 if they are valid.
  1464.  
  1465.    WHICH_ALTERNATIVE is set to a number which indicates which
  1466.    alternative of constraints was matched: 0 for the first alternative,
  1467.    1 for the next, etc.
  1468.  
  1469.    In addition, when two operands are match
  1470.    and it happens that the output operand is (reg) while the
  1471.    input operand is --(reg) or ++(reg) (a pre-inc or pre-dec),
  1472.    make the output operand look like the input.
  1473.    This is because the output operand is the one the template will print.
  1474.  
  1475.    This is used in final, just before printing the assembler code and by
  1476.    the routines that determine an insn's attribute.
  1477.  
  1478.    If STRICT is a positive non-zero value, it means that we have been
  1479.    called after reload has been completed.  In that case, we must
  1480.    do all checks strictly.  If it is zero, it means that we have been called
  1481.    before reload has completed.  In that case, we first try to see if we can
  1482.    find an alternative that matches strictly.  If not, we try again, this
  1483.    time assuming that reload will fix up the insn.  This provides a "best
  1484.    guess" for the alternative and is used to compute attributes of insns prior
  1485.    to reload.  A negative value of STRICT is used for this internal call.  */
  1486.  
  1487. struct funny_match
  1488. {
  1489.   int this, other;
  1490. };
  1491.  
  1492. int
  1493. constrain_operands (insn_code_num, strict)
  1494.      int insn_code_num;
  1495.      int strict;
  1496. {
  1497.   char *constraints[MAX_RECOG_OPERANDS];
  1498.   register int c;
  1499.   int noperands = insn_n_operands[insn_code_num];
  1500.  
  1501.   struct funny_match funny_match[MAX_RECOG_OPERANDS];
  1502.   int funny_match_index;
  1503.   int nalternatives = insn_n_alternatives[insn_code_num];
  1504.  
  1505.   if (noperands == 0 || nalternatives == 0)
  1506.     return 1;
  1507.  
  1508.   for (c = 0; c < noperands; c++)
  1509.     constraints[c] = insn_operand_constraint[insn_code_num][c];
  1510.  
  1511.   which_alternative = 0;
  1512.  
  1513.   while (which_alternative < nalternatives)
  1514.     {
  1515.       register int opno;
  1516.       int lose = 0;
  1517.       funny_match_index = 0;
  1518.  
  1519.       for (opno = 0; opno < noperands; opno++)
  1520.     {
  1521.       register rtx op = recog_operand[opno];
  1522.       enum machine_mode mode = GET_MODE (op);
  1523.       register char *p = constraints[opno];
  1524.       int offset = 0;
  1525.       int win = 0;
  1526.       int val;
  1527.  
  1528.       if (GET_CODE (op) == SUBREG)
  1529.         {
  1530.           if (GET_CODE (SUBREG_REG (op)) == REG
  1531.           && REGNO (SUBREG_REG (op)) < FIRST_PSEUDO_REGISTER)
  1532.         offset = SUBREG_WORD (op);
  1533.           op = SUBREG_REG (op);
  1534.         }
  1535.  
  1536.       /* An empty constraint or empty alternative
  1537.          allows anything which matched the pattern.  */
  1538.       if (*p == 0 || *p == ',')
  1539.         win = 1;
  1540.  
  1541.       while (*p && (c = *p++) != ',')
  1542.         switch (c)
  1543.           {
  1544.           case '=':
  1545.           case '+':
  1546.           case '?':
  1547.           case '#':
  1548.           case '&':
  1549.           case '!':
  1550.           case '*':
  1551.           case '%':
  1552.         break;
  1553.  
  1554.           case '0':
  1555.           case '1':
  1556.           case '2':
  1557.           case '3':
  1558.           case '4':
  1559.         /* This operand must be the same as a previous one.
  1560.            This kind of constraint is used for instructions such
  1561.            as add when they take only two operands.
  1562.  
  1563.            Note that the lower-numbered operand is passed first.
  1564.  
  1565.            If we are not testing strictly, assume that this constraint
  1566.            will be satisfied.  */
  1567.         if (strict < 0)
  1568.           val = 1;
  1569.         else
  1570.           val = operands_match_p (recog_operand[c - '0'],
  1571.                       recog_operand[opno]);
  1572.  
  1573.         if (val != 0)
  1574.           win = 1;
  1575.         /* If output is *x and input is *--x,
  1576.            arrange later to change the output to *--x as well,
  1577.            since the output op is the one that will be printed.  */
  1578.         if (val == 2 && strict > 0)
  1579.           {
  1580.             funny_match[funny_match_index].this = opno;
  1581.             funny_match[funny_match_index++].other = c - '0';
  1582.           }
  1583.         break;
  1584.  
  1585.           case 'p':
  1586.         /* p is used for address_operands, and everything
  1587.            that must be checked was checked already.  */
  1588.         win = 1;
  1589.         break;
  1590.  
  1591.         /* No need to check general_operand again;
  1592.            it was done in insn-recog.c.  */
  1593.           case 'g':
  1594.         /* Anything goes unless it is a REG and really has a hard reg
  1595.            but the hard reg is not in the class GENERAL_REGS.  */
  1596.         if (strict < 0
  1597.             || GENERAL_REGS == ALL_REGS
  1598.             || GET_CODE (op) != REG
  1599.             || reg_fits_class_p (op, GENERAL_REGS, offset, mode))
  1600.           win = 1;
  1601.         break;
  1602.  
  1603.           case 'r':
  1604.         if (strict < 0
  1605.             || (strict == 0
  1606.             && GET_CODE (op) == REG
  1607.             && REGNO (op) >= FIRST_PSEUDO_REGISTER)
  1608.             || (strict == 0 && GET_CODE (op) == SCRATCH)
  1609.             || (GET_CODE (op) == REG
  1610.             && (GENERAL_REGS == ALL_REGS
  1611.                 || reg_fits_class_p (op, GENERAL_REGS,
  1612.                          offset, mode))))
  1613.           win = 1;
  1614.         break;
  1615.  
  1616.           case 'X':
  1617.         /* This is used for a MATCH_SCRATCH in the cases when we
  1618.            don't actually need anything.  So anything goes any time. */
  1619.         win = 1;
  1620.         break;
  1621.  
  1622.           case 'm':
  1623.         if (GET_CODE (op) == MEM
  1624.             /* Before reload, accept what reload can turn into mem.  */
  1625.             || (strict < 0 && CONSTANT_P (op)))
  1626.           win = 1;
  1627.         break;
  1628.  
  1629.           case '<':
  1630.         if (GET_CODE (op) == MEM
  1631.             && (GET_CODE (XEXP (op, 0)) == PRE_DEC
  1632.             || GET_CODE (XEXP (op, 0)) == POST_DEC))
  1633.           win = 1;
  1634.         break;
  1635.  
  1636.           case '>':
  1637.         if (GET_CODE (op) == MEM
  1638.             && (GET_CODE (XEXP (op, 0)) == PRE_INC
  1639.             || GET_CODE (XEXP (op, 0)) == POST_INC))
  1640.           win = 1;
  1641.         break;
  1642.  
  1643.           case 'E':
  1644.         /* Match any CONST_DOUBLE, but only if
  1645.            we can examine the bits of it reliably.  */
  1646. #if HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT || HOST_BITS_PER_INT != BITS_PER_WORD
  1647.         if (GET_CODE (op) != VOIDmode && ! flag_pretend_float)
  1648.           break;
  1649. #endif
  1650.         if (GET_CODE (op) == CONST_DOUBLE)
  1651.           win = 1;
  1652.         break;
  1653.  
  1654.           case 'F':
  1655.         if (GET_CODE (op) == CONST_DOUBLE)
  1656.           win = 1;
  1657.         break;
  1658.  
  1659.           case 'G':
  1660.           case 'H':
  1661.         if (GET_CODE (op) == CONST_DOUBLE
  1662.             && CONST_DOUBLE_OK_FOR_LETTER_P (op, c))
  1663.           win = 1;
  1664.         break;
  1665.  
  1666.           case 's':
  1667.         if (GET_CODE (op) == CONST_INT
  1668.             || (GET_CODE (op) == CONST_DOUBLE
  1669.             && GET_MODE (op) == VOIDmode))
  1670.           break;
  1671.           case 'i':
  1672.         if (CONSTANT_P (op))
  1673.           win = 1;
  1674.         break;
  1675.  
  1676.           case 'n':
  1677.         if (GET_CODE (op) == CONST_INT
  1678.             || (GET_CODE (op) == CONST_DOUBLE
  1679.             && GET_MODE (op) == VOIDmode))
  1680.           win = 1;
  1681.         break;
  1682.  
  1683.           case 'I':
  1684.           case 'J':
  1685.           case 'K':
  1686.           case 'L':
  1687.           case 'M':
  1688.           case 'N':
  1689.           case 'O':
  1690.           case 'P':
  1691.         if (GET_CODE (op) == CONST_INT
  1692.             && CONST_OK_FOR_LETTER_P (INTVAL (op), c))
  1693.           win = 1;
  1694.         break;
  1695.  
  1696. #ifdef EXTRA_CONSTRAINT
  1697.               case 'Q':
  1698.               case 'R':
  1699.               case 'S':
  1700.               case 'T':
  1701.               case 'U':
  1702.         if (EXTRA_CONSTRAINT (op, c))
  1703.           win = 1;
  1704.         break;
  1705. #endif
  1706.  
  1707.           case 'V':
  1708.         if (GET_CODE (op) == MEM
  1709.             && ! offsettable_memref_p (op))
  1710.           win = 1;
  1711.         break;
  1712.  
  1713.           case 'o':
  1714.         if ((strict > 0 && offsettable_memref_p (op))
  1715.             || (strict == 0 && offsettable_nonstrict_memref_p (op))
  1716.             /* Before reload, accept what reload can handle.  */
  1717.             || (strict < 0
  1718.             && (CONSTANT_P (op) || GET_CODE (op) == MEM)))
  1719.           win = 1;
  1720.         break;
  1721.  
  1722.           default:
  1723.         if (strict < 0
  1724.             || (strict == 0
  1725.             && GET_CODE (op) == REG
  1726.             && REGNO (op) >= FIRST_PSEUDO_REGISTER)
  1727.             || (strict == 0 && GET_CODE (op) == SCRATCH)
  1728.             || (GET_CODE (op) == REG
  1729.             && reg_fits_class_p (op, REG_CLASS_FROM_LETTER (c),
  1730.                          offset, mode)))
  1731.           win = 1;
  1732.           }
  1733.  
  1734.       constraints[opno] = p;
  1735.       /* If this operand did not win somehow,
  1736.          this alternative loses.  */
  1737.       if (! win)
  1738.         lose = 1;
  1739.     }
  1740.       /* This alternative won; the operands are ok.
  1741.      Change whichever operands this alternative says to change.  */
  1742.       if (! lose)
  1743.     {
  1744.       while (--funny_match_index >= 0)
  1745.         {
  1746.           recog_operand[funny_match[funny_match_index].other]
  1747.         = recog_operand[funny_match[funny_match_index].this];
  1748.         }
  1749.       return 1;
  1750.     }
  1751.  
  1752.       which_alternative++;
  1753.     }
  1754.  
  1755.   /* If we are about to reject this, but we are not to test strictly,
  1756.      try a very loose test.  Only return failure if it fails also.  */
  1757.   if (strict == 0)
  1758.     return constrain_operands (insn_code_num, -1);
  1759.   else
  1760.     return 0;
  1761. }
  1762.  
  1763. /* Return 1 iff OPERAND (assumed to be a REG rtx)
  1764.    is a hard reg in class CLASS when its regno is offsetted by OFFSET
  1765.    and changed to mode MODE.
  1766.    If REG occupies multiple hard regs, all of them must be in CLASS.  */
  1767.  
  1768. int
  1769. reg_fits_class_p (operand, class, offset, mode)
  1770.      rtx operand;
  1771.      register enum reg_class class;
  1772.      int offset;
  1773.      enum machine_mode mode;
  1774. {
  1775.   register int regno = REGNO (operand);
  1776.   if (regno < FIRST_PSEUDO_REGISTER
  1777.       && TEST_HARD_REG_BIT (reg_class_contents[(int) class],
  1778.                 regno + offset))
  1779.     {
  1780.       register int sr;
  1781.       regno += offset;
  1782.       for (sr = HARD_REGNO_NREGS (regno, mode) - 1;
  1783.        sr > 0; sr--)
  1784.     if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class],
  1785.                  regno + sr))
  1786.       break;
  1787.       return sr == 0;
  1788.     }
  1789.  
  1790.   return 0;
  1791. }
  1792.  
  1793. #endif /* REGISTER_CONSTRAINTS */
  1794.