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

  1. /* Emit RTL for the GNU C-Compiler expander.
  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. /* Middle-to-low level generation of rtx code and insns.
  22.  
  23.    This file contains the functions `gen_rtx', `gen_reg_rtx'
  24.    and `gen_label_rtx' that are the usual ways of creating rtl
  25.    expressions for most purposes.
  26.  
  27.    It also has the functions for creating insns and linking
  28.    them in the doubly-linked chain.
  29.  
  30.    The patterns of the insns are created by machine-dependent
  31.    routines in insn-emit.c, which is generated automatically from
  32.    the machine description.  These routines use `gen_rtx' to make
  33.    the individual rtx's of the pattern; what is machine dependent
  34.    is the kind of rtx's they make and what arguments they use.  */
  35.  
  36. #include "config.h"
  37. #include <stdio.h>
  38. #include "gvarargs.h"
  39. #include "rtl.h"
  40. #include "function.h"
  41. #include "expr.h"
  42. #include "regs.h"
  43. #include "insn-config.h"
  44. #include "real.h"
  45.  
  46. #define max(A,B) ((A) > (B) ? (A) : (B))
  47. #define min(A,B) ((A) < (B) ? (A) : (B))
  48.  
  49. /* This is reset to FIRST_PSEUDO_REGISTER at the start each function.
  50.    After rtl generation, it is 1 plus the largest register number used.  */
  51.  
  52. int reg_rtx_no = FIRST_PSEUDO_REGISTER;
  53.  
  54. /* This is *not* reset after each function.  It gives each CODE_LABEL
  55.    in the entire compilation a unique label number.  */
  56.  
  57. static int label_num = 1;
  58.  
  59. /* Value of `label_num' at start of current function.  */
  60.  
  61. static int first_label_num;
  62.  
  63. /* Nonzero means do not generate NOTEs for source line numbers.  */
  64.  
  65. static int no_line_numbers;
  66.  
  67. /* Commonly used rtx's, so that we only need space for one copy.
  68.    These are initialized once for the entire compilation.
  69.    All of these except perhaps fconst0_rtx and dconst0_rtx
  70.    are unique; no other rtx-object will be equal to any of these.  */
  71.  
  72. rtx pc_rtx;            /* (PC) */
  73. rtx cc0_rtx;            /* (CC0) */
  74. rtx cc1_rtx;            /* (CC1) (not actually used nowadays) */
  75. rtx const0_rtx;            /* (CONST_INT 0) */
  76. rtx const1_rtx;            /* (CONST_INT 1) */
  77. rtx constm1_rtx;        /* (CONST_INT -1) */
  78. rtx const_true_rtx;        /* (CONST_INT STORE_FLAG_VALUE) */
  79. rtx fconst0_rtx;        /* (CONST_DOUBLE:SF 0) */
  80. rtx fconst1_rtx;        /* (CONST_DOUBLE:SF 1) */
  81. rtx dconst0_rtx;        /* (CONST_DOUBLE:DF 0) */
  82. rtx dconst1_rtx;        /* (CONST_DOUBLE:DF 1) */
  83.  
  84. REAL_VALUE_TYPE dconst0;
  85. REAL_VALUE_TYPE dconst1;
  86. REAL_VALUE_TYPE dconst2;
  87. REAL_VALUE_TYPE dconstm1;
  88.  
  89. /* All references to the following fixed hard registers go through
  90.    these unique rtl objects.  On machines where the frame-pointer and
  91.    arg-pointer are the same register, they use the same unique object.
  92.  
  93.    After register allocation, other rtl objects which used to be pseudo-regs
  94.    may be clobbered to refer to the frame-pointer register.
  95.    But references that were originally to the frame-pointer can be
  96.    distinguished from the others because they contain frame_pointer_rtx.
  97.  
  98.    In an inline procedure, the stack and frame pointer rtxs may not be
  99.    used for anything else.  */
  100. rtx stack_pointer_rtx;        /* (REG:Pmode STACK_POINTER_REGNUM) */
  101. rtx frame_pointer_rtx;        /* (REG:Pmode FRAME_POINTER_REGNUM) */
  102. rtx arg_pointer_rtx;        /* (REG:Pmode ARG_POINTER_REGNUM) */
  103. rtx struct_value_rtx;        /* (REG:Pmode STRUCT_VALUE_REGNUM) */
  104. rtx struct_value_incoming_rtx;    /* (REG:Pmode STRUCT_VALUE_INCOMING_REGNUM) */
  105. rtx static_chain_rtx;        /* (REG:Pmode STATIC_CHAIN_REGNUM) */
  106. rtx static_chain_incoming_rtx;    /* (REG:Pmode STATIC_CHAIN_INCOMING_REGNUM) */
  107. rtx pic_offset_table_rtx;    /* (REG:Pmode PIC_OFFSET_TABLE_REGNUM) */
  108.  
  109. rtx virtual_incoming_args_rtx;    /* (REG:Pmode VIRTUAL_INCOMING_ARGS_REGNUM) */
  110. rtx virtual_stack_vars_rtx;    /* (REG:Pmode VIRTUAL_STACK_VARS_REGNUM) */
  111. rtx virtual_stack_dynamic_rtx;    /* (REG:Pmode VIRTUAL_STACK_DYNAMIC_REGNUM) */
  112. rtx virtual_outgoing_args_rtx;    /* (REG:Pmode VIRTUAL_OUTGOING_ARGS_REGNUM) */
  113.  
  114. /* We make one copy of (const_int C) where C is in
  115.    [- MAX_SAVED_CONST_INT, MAX_SAVED_CONST_INT]
  116.    to save space during the compilation and simplify comparisons of
  117.    integers.  */
  118.  
  119. #define MAX_SAVED_CONST_INT 64
  120.  
  121. static rtx const_int_rtx[MAX_SAVED_CONST_INT * 2 + 1];
  122.  
  123. /* The ends of the doubly-linked chain of rtl for the current function.
  124.    Both are reset to null at the start of rtl generation for the function.
  125.    
  126.    start_sequence saves both of these on `sequence_stack' and then
  127.    starts a new, nested sequence of insns.  */
  128.  
  129. static rtx first_insn = NULL;
  130. static rtx last_insn = NULL;
  131.  
  132. /* INSN_UID for next insn emitted.
  133.    Reset to 1 for each function compiled.  */
  134.  
  135. static int cur_insn_uid = 1;
  136.  
  137. /* Line number and source file of the last line-number NOTE emitted.
  138.    This is used to avoid generating duplicates.  */
  139.  
  140. static int last_linenum = 0;
  141. static char *last_filename = 0;
  142.  
  143. /* A vector indexed by pseudo reg number.  The allocated length
  144.    of this vector is regno_pointer_flag_length.  Since this
  145.    vector is needed during the expansion phase when the total
  146.    number of registers in the function is not yet known,
  147.    it is copied and made bigger when necessary.  */
  148.  
  149. char *regno_pointer_flag;
  150. int regno_pointer_flag_length;
  151.  
  152. /* Indexed by pseudo register number, gives the rtx for that pseudo.
  153.    Allocated in parallel with regno_pointer_flag.  */
  154.  
  155. rtx *regno_reg_rtx;
  156.  
  157. /* Stack of pending (incomplete) sequences saved by `start_sequence'.
  158.    Each element describes one pending sequence.
  159.    The main insn-chain is saved in the last element of the chain,
  160.    unless the chain is empty.  */
  161.  
  162. struct sequence_stack *sequence_stack;
  163.  
  164. /* start_sequence and gen_sequence can make a lot of rtx expressions which are
  165.    shortly thrown away.  We use two mechanisms to prevent this waste:
  166.  
  167.    First, we keep a list of the expressions used to represent the sequence
  168.    stack in sequence_element_free_list.
  169.  
  170.    Second, for sizes up to 5 elements, we keep a SEQUENCE and its associated
  171.    rtvec for use by gen_sequence.  One entry for each size is sufficient
  172.    because most cases are calls to gen_sequence followed by immediately
  173.    emitting the SEQUENCE.  Reuse is safe since emitting a sequence is
  174.    destructive on the insn in it anyway and hence can't be redone.
  175.  
  176.    We do not bother to save this cached data over nested function calls.
  177.    Instead, we just reinitialize them.  */
  178.  
  179. #define SEQUENCE_RESULT_SIZE 5
  180.  
  181. static struct sequence_stack *sequence_element_free_list;
  182. static rtx sequence_result[SEQUENCE_RESULT_SIZE];
  183.  
  184. /* Filename and line number of last line-number note,
  185.    whether we actually emitted it or not.  */
  186. extern char *emit_filename;
  187. extern int emit_lineno;
  188.  
  189. rtx change_address ();
  190. void init_emit ();
  191.  
  192. /* rtx gen_rtx (code, mode, [element1, ..., elementn])
  193. **
  194. **        This routine generates an RTX of the size specified by
  195. **    <code>, which is an RTX code.   The RTX structure is initialized
  196. **    from the arguments <element1> through <elementn>, which are
  197. **    interpreted according to the specific RTX type's format.   The
  198. **    special machine mode associated with the rtx (if any) is specified
  199. **    in <mode>.
  200. **
  201. **        gen_rtx() can be invoked in a way which resembles the lisp-like
  202. **    rtx it will generate.   For example, the following rtx structure:
  203. **
  204. **          (plus:QI (mem:QI (reg:SI 1))
  205. **               (mem:QI (plusw:SI (reg:SI 2) (reg:SI 3))))
  206. **
  207. **        ...would be generated by the following C code:
  208. **
  209. **            gen_rtx (PLUS, QImode,
  210. **            gen_rtx (MEM, QImode,
  211. **            gen_rtx (REG, SImode, 1)),
  212. **            gen_rtx (MEM, QImode,
  213. **            gen_rtx (PLUS, SImode,
  214. **                gen_rtx (REG, SImode, 2),
  215. **                gen_rtx (REG, SImode, 3)))),
  216. */
  217.  
  218. /*VARARGS2*/
  219. rtx
  220. gen_rtx (va_alist)
  221.      va_dcl
  222. {
  223.   va_list p;
  224.   enum rtx_code code;
  225.   enum machine_mode mode;
  226.   register int i;        /* Array indices...            */
  227.   register char *fmt;        /* Current rtx's format...        */
  228.   register rtx rt_val;        /* RTX to return to caller...        */
  229.  
  230.   va_start (p);
  231.   code = va_arg (p, enum rtx_code);
  232.   mode = va_arg (p, enum machine_mode);
  233.  
  234.   if (code == CONST_INT)
  235.     {
  236.       int arg = va_arg (p, int);
  237.  
  238.       if (arg >= - MAX_SAVED_CONST_INT && arg <= MAX_SAVED_CONST_INT)
  239.     return const_int_rtx[arg + MAX_SAVED_CONST_INT];
  240.  
  241.       if (const_true_rtx && arg == STORE_FLAG_VALUE)
  242.     return const_true_rtx;
  243.  
  244.       rt_val = rtx_alloc (code);
  245.       INTVAL (rt_val) = arg;
  246.     }
  247.   else if (code == REG)
  248.     {
  249.       int regno = va_arg (p, int);
  250.  
  251.       /* In case the MD file explicitly references the frame pointer, have
  252.      all such references point to the same frame pointer.  This is used
  253.      during frame pointer elimination to distinguish the explicit
  254.      references to these registers from psuedos that happened to be
  255.      assigned to them.  */
  256.  
  257.       if (frame_pointer_rtx && regno == FRAME_POINTER_REGNUM)
  258.     return frame_pointer_rtx;
  259. #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
  260.       if (arg_pointer_rtx && regno == ARG_POINTER_REGNUM)
  261.     return arg_pointer_rtx;
  262. #endif
  263.       if (stack_pointer_rtx && regno == STACK_POINTER_REGNUM)
  264.     return stack_pointer_rtx;
  265.       else
  266.     {
  267.       rt_val = rtx_alloc (code);
  268.       rt_val->mode = mode;
  269.       REGNO (rt_val) = regno;
  270.       return rt_val;
  271.     }
  272.     }
  273.   else
  274.     {
  275.       rt_val = rtx_alloc (code);    /* Allocate the storage space.  */
  276.       rt_val->mode = mode;        /* Store the machine mode...  */
  277.  
  278.       fmt = GET_RTX_FORMAT (code);    /* Find the right format...  */
  279.       for (i = 0; i < GET_RTX_LENGTH (code); i++)
  280.     {
  281.       switch (*fmt++)
  282.         {
  283.         case '0':        /* Unused field.  */
  284.           break;
  285.  
  286.         case 'i':        /* An integer?  */
  287.           XINT (rt_val, i) = va_arg (p, int);
  288.           break;
  289.  
  290.         case 's':        /* A string?  */
  291.           XSTR (rt_val, i) = va_arg (p, char *);
  292.           break;
  293.  
  294.         case 'e':        /* An expression?  */
  295.         case 'u':        /* An insn?  Same except when printing.  */
  296.           XEXP (rt_val, i) = va_arg (p, rtx);
  297.           break;
  298.  
  299.         case 'E':        /* An RTX vector?  */
  300.           XVEC (rt_val, i) = va_arg (p, rtvec);
  301.           break;
  302.  
  303.         default:
  304.           abort();
  305.         }
  306.     }
  307.     }
  308.   va_end (p);
  309.   return rt_val;        /* Return the new RTX...        */
  310. }
  311.  
  312. /* gen_rtvec (n, [rt1, ..., rtn])
  313. **
  314. **        This routine creates an rtvec and stores within it the
  315. **    pointers to rtx's which are its arguments.
  316. */
  317.  
  318. /*VARARGS1*/
  319. rtvec
  320. gen_rtvec (va_alist)
  321.      va_dcl
  322. {
  323.   int n, i;
  324.   va_list p;
  325.   rtx *vector;
  326.  
  327.   va_start (p);
  328.   n = va_arg (p, int);
  329.  
  330.   if (n == 0)
  331.     return NULL_RTVEC;        /* Don't allocate an empty rtvec...    */
  332.  
  333.   vector = (rtx *) alloca (n * sizeof (rtx));
  334.   for (i = 0; i < n; i++)
  335.     vector[i] = va_arg (p, rtx);
  336.   va_end (p);
  337.  
  338.   return gen_rtvec_v (n, vector);
  339. }
  340.  
  341. rtvec
  342. gen_rtvec_v (n, argp)
  343.      int n;
  344.      rtx *argp;
  345. {
  346.   register int i;
  347.   register rtvec rt_val;
  348.  
  349.   if (n == 0)
  350.     return NULL_RTVEC;        /* Don't allocate an empty rtvec...    */
  351.  
  352.   rt_val = rtvec_alloc (n);    /* Allocate an rtvec...            */
  353.  
  354.   for (i = 0; i < n; i++)
  355.     rt_val->elem[i].rtx = *argp++;
  356.  
  357.   return rt_val;
  358. }
  359.  
  360. /* Generate a REG rtx for a new pseudo register of mode MODE.
  361.    This pseudo is assigned the next sequential register number.  */
  362.  
  363. rtx
  364. gen_reg_rtx (mode)
  365.      enum machine_mode mode;
  366. {
  367.   register rtx val;
  368.  
  369.   /* Don't let anything called by or after reload create new registers
  370.      (actually, registers can't be created after flow, but this is a good
  371.      approximation).  */
  372.  
  373.   if (reload_in_progress || reload_completed)
  374.     abort ();
  375.  
  376.   /* Make sure regno_pointer_flag and regno_reg_rtx are large
  377.      enough to have an element for this pseudo reg number.  */
  378.  
  379.   if (reg_rtx_no == regno_pointer_flag_length)
  380.     {
  381.       rtx *new1;
  382.       char *new =
  383.     (char *) oballoc (regno_pointer_flag_length * 2);
  384.       bzero (new, regno_pointer_flag_length * 2);
  385.       bcopy (regno_pointer_flag, new, regno_pointer_flag_length);
  386.       regno_pointer_flag = new;
  387.  
  388.       new1 = (rtx *) oballoc (regno_pointer_flag_length * 2 * sizeof (rtx));
  389.       bzero (new1, regno_pointer_flag_length * 2 * sizeof (rtx));
  390.       bcopy (regno_reg_rtx, new1, regno_pointer_flag_length * sizeof (rtx));
  391.       regno_reg_rtx = new1;
  392.  
  393.       regno_pointer_flag_length *= 2;
  394.     }
  395.  
  396.   val = gen_rtx (REG, mode, reg_rtx_no);
  397.   regno_reg_rtx[reg_rtx_no++] = val;
  398.   return val;
  399. }
  400.  
  401. /* Identify REG as a probable pointer register.  */
  402.  
  403. void
  404. mark_reg_pointer (reg)
  405.      rtx reg;
  406. {
  407.   REGNO_POINTER_FLAG (REGNO (reg)) = 1;
  408. }
  409.  
  410. /* Return 1 plus largest pseudo reg number used in the current function.  */
  411.  
  412. int
  413. max_reg_num ()
  414. {
  415.   return reg_rtx_no;
  416. }
  417.  
  418. /* Return 1 + the largest label number used so far.  */
  419.  
  420. int
  421. max_label_num ()
  422. {
  423.   return label_num;
  424. }
  425.  
  426. /* Return first label number used in this function (if any were used).  */
  427.  
  428. int
  429. get_first_label_num ()
  430. {
  431.   return first_label_num;
  432. }
  433.  
  434. /* Return a value representing some low-order bits of X, where the number
  435.    of low-order bits is given by MODE.  Note that no conversion is done
  436.    between floating-point and fixed-point values, rather, the bit 
  437.    representation is returned.
  438.  
  439.    This function handles the cases in common between gen_lowpart, below,
  440.    and two variants in cse.c and combine.c.  These are the cases that can
  441.    be safely handled at all points in the compilation.
  442.  
  443.    If this is not a case we can handle, return 0.  */
  444.  
  445. rtx
  446. gen_lowpart_common (mode, x)
  447.      enum machine_mode mode;
  448.      register rtx x;
  449. {
  450.   int word = 0;
  451.  
  452.   if (GET_MODE (x) == mode)
  453.     return x;
  454.  
  455.   /* MODE must occupy no more words than the mode of X.  */
  456.   if (GET_MODE (x) != VOIDmode
  457.       && ((GET_MODE_SIZE (mode) + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD
  458.       > ((GET_MODE_SIZE (GET_MODE (x)) + (UNITS_PER_WORD - 1))
  459.          / UNITS_PER_WORD)))
  460.     return 0;
  461.  
  462.   if (WORDS_BIG_ENDIAN && GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD)
  463.     word = ((GET_MODE_SIZE (GET_MODE (x))
  464.          - max (GET_MODE_SIZE (mode), UNITS_PER_WORD))
  465.         / UNITS_PER_WORD);
  466.  
  467.   if ((GET_CODE (x) == ZERO_EXTEND || GET_CODE (x) == SIGN_EXTEND)
  468.       && GET_MODE_CLASS (mode) == MODE_INT)
  469.     {
  470.       /* If we are getting the low-order part of something that has been
  471.      sign- or zero-extended, we can either just use the object being
  472.      extended or make a narrower extension.  If we want an even smaller
  473.      piece than the size of the object being extended, call ourselves
  474.      recursively.
  475.  
  476.      This case is used mostly by combine and cse.  */
  477.  
  478.       if (GET_MODE (XEXP (x, 0)) == mode)
  479.     return XEXP (x, 0);
  480.       else if (GET_MODE_SIZE (mode) < GET_MODE_SIZE (GET_MODE (XEXP (x, 0))))
  481.     return gen_lowpart_common (mode, XEXP (x, 0));
  482.       else if (GET_MODE_SIZE (mode) < GET_MODE_SIZE (GET_MODE (x)))
  483.     return gen_rtx (GET_CODE (x), mode, XEXP (x, 0));
  484.     }
  485.   else if (GET_CODE (x) == SUBREG
  486.        && (GET_MODE_SIZE (mode) <= UNITS_PER_WORD
  487.            || GET_MODE_SIZE (mode) == GET_MODE_UNIT_SIZE (GET_MODE (x))))
  488.     return (GET_MODE (SUBREG_REG (x)) == mode && SUBREG_WORD (x) == 0
  489.         ? SUBREG_REG (x)
  490.         : gen_rtx (SUBREG, mode, SUBREG_REG (x), SUBREG_WORD (x)));
  491.   else if (GET_CODE (x) == REG)
  492.     {
  493.       if (REGNO (x) < FIRST_PSEUDO_REGISTER)
  494.     return gen_rtx (REG, mode, REGNO (x) + word);
  495.       else
  496.     return gen_rtx (SUBREG, mode, x, word);
  497.     }
  498.   else if (GET_CODE (x) == CONST_INT && GET_MODE_CLASS (mode) == MODE_INT
  499.        && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_INT)
  500.     return gen_rtx (CONST_INT, VOIDmode, INTVAL (x) & GET_MODE_MASK (mode));
  501.  
  502.   else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE_CLASS (mode) == MODE_INT
  503.        && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_INT)
  504.     return gen_rtx (CONST_INT, VOIDmode,
  505.             CONST_DOUBLE_LOW (x) & GET_MODE_MASK (mode));
  506.  
  507.   /* Otherwise, we can't do this.  */
  508.   return 0;
  509. }
  510.  
  511. /* Assuming that X is an rtx (e.g., MEM, REG or SUBREG) for a value,
  512.    return an rtx (MEM, SUBREG, or CONST_INT) that refers to the
  513.    least-significant part of X.
  514.    MODE specifies how big a part of X to return;
  515.    it usually should not be larger than a word.
  516.    If X is a MEM whose address is a QUEUED, the value may be so also.  */
  517.  
  518. rtx
  519. gen_lowpart (mode, x)
  520.      enum machine_mode mode;
  521.      register rtx x;
  522. {
  523.   rtx result = gen_lowpart_common (mode, x);
  524.  
  525.   if (result)
  526.     return result;
  527.   else if (GET_CODE (x) == MEM)
  528.     {
  529.       /* The only additional case we can do is MEM.  */
  530.       register int offset = 0;
  531.       if (WORDS_BIG_ENDIAN)
  532.     offset = (max (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD)
  533.           - max (GET_MODE_SIZE (mode), UNITS_PER_WORD));
  534.  
  535.       if (BYTES_BIG_ENDIAN)
  536.     /* Adjust the address so that the address-after-the-data
  537.        is unchanged.  */
  538.     offset -= (min (UNITS_PER_WORD, GET_MODE_SIZE (mode))
  539.            - min (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x))));
  540.  
  541.       return change_address (x, mode, plus_constant (XEXP (x, 0), offset));
  542.     }
  543.   else
  544.     abort ();
  545. }
  546.  
  547. /* Return 1 iff X, assumed to be a SUBREG,
  548.    refers to the least significant part of its containing reg.
  549.    If X is not a SUBREG, always return 1 (it is its own low part!).  */
  550.  
  551. int
  552. subreg_lowpart_p (x)
  553.      rtx x;
  554. {
  555.   if (GET_CODE (x) != SUBREG)
  556.     return 1;
  557.  
  558.   if (WORDS_BIG_ENDIAN
  559.       && GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))) > UNITS_PER_WORD)
  560.     return (SUBREG_WORD (x)
  561.         == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))
  562.          - max (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD))
  563.         / UNITS_PER_WORD));
  564.  
  565.   return SUBREG_WORD (x) == 0;
  566. }
  567.  
  568. /* Return subword I of operand OP.
  569.    The word number, I, is interpreted as the word number starting at the
  570.    low-order address.  Word 0 is the low-order word if not WORDS_BIG_ENDIAN,
  571.    otherwise it is the high-order word.
  572.  
  573.    If we cannot extract the required word, we return zero.  Otherwise, an
  574.    rtx corresponding to the requested word will be returned.
  575.  
  576.    VALIDATE_ADDRESS is nonzero if the address should be validated.  Before
  577.    reload has completed, a valid address will always be returned.  After
  578.    reload, if a valid address cannot be returned, we return zero.
  579.  
  580.    If VALIDATE_ADDRESS is zero, we simply form the required address; validating
  581.    it is the responsibility of the caller.
  582.  
  583.    MODE is the mode of OP in case it is a CONST_INT.  */
  584.  
  585. rtx
  586. operand_subword (op, i, validate_address, mode)
  587.      rtx op;
  588.      int i;
  589.      int validate_address;
  590.      enum machine_mode mode;
  591. {
  592.   int val;
  593.  
  594.   if (mode == VOIDmode)
  595.     mode = GET_MODE (op);
  596.  
  597.   if (mode == VOIDmode)
  598.     abort ();
  599.  
  600.   /* If OP is narrower than a word or if we want a word outside OP, fail.  */
  601.   if (mode != BLKmode
  602.       && (GET_MODE_SIZE (mode) < UNITS_PER_WORD
  603.       || (i + 1) * UNITS_PER_WORD > GET_MODE_SIZE (mode)))
  604.     return 0;
  605.  
  606.   /* If OP is already an integer word, return it.  */
  607.   if (GET_MODE_CLASS (mode) == MODE_INT
  608.       && GET_MODE_SIZE (mode) == UNITS_PER_WORD)
  609.     return op;
  610.  
  611.   /* If OP is a REG or SUBREG, we can handle it very simply.  */
  612.   if (GET_CODE (op) == REG)
  613.     {
  614.       if (REGNO (op) >= FIRST_PSEUDO_REGISTER)
  615.     return gen_rtx (SUBREG, SImode, op, i);
  616.       else
  617.     return gen_rtx (REG, SImode, REGNO (op) + i);
  618.     }
  619.   else if (GET_CODE (op) == SUBREG)
  620.     return gen_rtx (SUBREG, SImode, SUBREG_REG (op), i + SUBREG_WORD (op));
  621.  
  622.   /* Form a new MEM at the requested address.  */
  623.   if (GET_CODE (op) == MEM)
  624.     {
  625.       rtx addr = plus_constant (XEXP (op, 0), i * UNITS_PER_WORD);
  626.       rtx new;
  627.  
  628.       if (validate_address)
  629.     {
  630.       if (reload_completed)
  631.         {
  632.           if (! strict_memory_address_p (SImode, addr))
  633.         return 0;
  634.         }
  635.       else
  636.         addr = memory_address (SImode, addr);
  637.     }
  638.  
  639.       new = gen_rtx (MEM, SImode, addr);
  640.  
  641.       MEM_VOLATILE_P (new) = MEM_VOLATILE_P (op);
  642.       MEM_IN_STRUCT_P (new) = MEM_IN_STRUCT_P (op);
  643.       RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (op);
  644.  
  645.       return new;
  646.     }
  647.  
  648.   /* The only remaining cases are when OP is a constant.  If the host and
  649.      target floating formats are the same, handling two-word floating
  650.      constants are easy.  */
  651.   if (HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
  652.       && HOST_BITS_PER_INT == BITS_PER_WORD
  653.       && GET_MODE_CLASS (mode) == MODE_FLOAT
  654.       && GET_MODE_SIZE (mode) == 2 * UNITS_PER_WORD
  655.       && GET_CODE (op) == CONST_DOUBLE)
  656.     return gen_rtx (CONST_INT, VOIDmode,
  657.             i ? CONST_DOUBLE_HIGH (op) : CONST_DOUBLE_LOW (op));
  658.  
  659.   /* Single word float is a little harder, since single- and double-word
  660.      values often do not have the same high-order bits.  We have already
  661.      verified that we want the only defined word of the single-word value.  */
  662.   if (HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
  663.       && HOST_BITS_PER_INT == BITS_PER_WORD
  664.       && GET_MODE_CLASS (mode) == MODE_FLOAT
  665.       && GET_MODE_SIZE (mode) == UNITS_PER_WORD
  666.       && GET_CODE (op) == CONST_DOUBLE)
  667.     {
  668.       double d;
  669.       union {float f; int i; } u;
  670.  
  671.       REAL_VALUE_FROM_CONST_DOUBLE (d, op);
  672.  
  673.       u.f = d;
  674.       return gen_rtx (CONST_INT, VOIDmode, u.i);
  675.     }
  676.       
  677.   /* The only remaining cases that we can handle are integers.
  678.      Convert to proper endianness now since these cases need it.
  679.      At this point, i == 0 means the low-order word.  
  680.  
  681.      Note that it must be that BITS_PER_WORD <= HOST_BITS_PER_INT.
  682.      This is because if it were greater, it could only have been two
  683.      times greater since we do not support making wider constants.  In
  684.      that case, it MODE would have already been the proper size and
  685.      it would have been handled above.  This means we do not have to
  686.      worry about the case where we would be returning a CONST_DOUBLE.  */
  687.  
  688.   if (GET_MODE_CLASS (mode) != MODE_INT
  689.       || (GET_CODE (op) != CONST_INT && GET_CODE (op) != CONST_DOUBLE))
  690.     return 0;
  691.  
  692.   if (WORDS_BIG_ENDIAN)
  693.     i = GET_MODE_SIZE (mode) / UNITS_PER_WORD - 1 - i;
  694.  
  695.   /* Find out which word on the host machine this value is in and get
  696.      it from the constant.  */
  697.   val = (i / (HOST_BITS_PER_INT / BITS_PER_WORD) == 0
  698.      ? (GET_CODE (op) == CONST_INT ? INTVAL (op) : CONST_DOUBLE_LOW (op))
  699.      : (GET_CODE (op) == CONST_INT
  700.         ? (INTVAL (op) < 0 ? ~0 : 0) : CONST_DOUBLE_HIGH (op)));
  701.  
  702.   /* If BITS_PER_WORD is smaller than an int, get the appropriate bits.  */
  703. #if BITS_PER_WORD < HOST_BITS_PER_INT
  704.   val = ((val >> ((i % (HOST_BITS_PER_INT / BITS_PER_WORD)) * BITS_PER_WORD))
  705.      & ((1 << BITS_PER_WORD) - 1));
  706. #endif
  707.  
  708.   return gen_rtx (CONST_INT, VOIDmode, val);
  709. }
  710.  
  711. /* Similar to `operand_subword', but never return 0.  If we can't extract
  712.    the required subword, put OP into a register and try again.  If that fails,
  713.    abort.  We always validate the address in this case.  It is not valid
  714.    to call this function after reload; it is mostly meant for RTL
  715.    generation. 
  716.  
  717.    MODE is the mode of OP, in case it is CONST_INT.  */
  718.  
  719. rtx
  720. operand_subword_force (op, i, mode)
  721.      rtx op;
  722.      int i;
  723.      enum machine_mode mode;
  724. {
  725.   rtx result = operand_subword (op, i, 1, mode);
  726.  
  727.   if (result)
  728.     return result;
  729.  
  730.   if (mode != BLKmode && mode != VOIDmode)
  731.     op = force_reg (mode, op);
  732.  
  733.   result = operand_subword (op, i, 1, mode);
  734.   if (result == 0)
  735.     abort ();
  736.  
  737.   return result;
  738. }
  739.  
  740. /* Given a compare instruction, swap the operands.
  741.    A test instruction is changed into a compare of 0 against the operand.  */
  742.  
  743. void
  744. reverse_comparison (insn)
  745.      rtx insn;
  746. {
  747.   rtx body = PATTERN (insn);
  748.   rtx comp;
  749.  
  750.   if (GET_CODE (body) == SET)
  751.     comp = SET_SRC (body);
  752.   else
  753.     comp = SET_SRC (XVECEXP (body, 0, 0));
  754.  
  755.   if (GET_CODE (comp) == COMPARE)
  756.     {
  757.       rtx op0 = XEXP (comp, 0);
  758.       rtx op1 = XEXP (comp, 1);
  759.       XEXP (comp, 0) = op1;
  760.       XEXP (comp, 1) = op0;
  761.     }
  762.   else
  763.     {
  764.       rtx new = gen_rtx (COMPARE, VOIDmode,
  765.              CONST0_RTX (GET_MODE (comp)), comp);
  766.       if (GET_CODE (body) == SET)
  767.     SET_SRC (body) = new;
  768.       else
  769.     SET_SRC (XVECEXP (body, 0, 0)) = new;
  770.     }
  771. }
  772.  
  773. /* Return a memory reference like MEMREF, but with its mode changed
  774.    to MODE and its address changed to ADDR.
  775.    (VOIDmode means don't change the mode.
  776.    NULL for ADDR means don't change the address.)  */
  777.  
  778. rtx
  779. change_address (memref, mode, addr)
  780.      rtx memref;
  781.      enum machine_mode mode;
  782.      rtx addr;
  783. {
  784.   rtx new;
  785.  
  786.   if (GET_CODE (memref) != MEM)
  787.     abort ();
  788.   if (mode == VOIDmode)
  789.     mode = GET_MODE (memref);
  790.   if (addr == 0)
  791.     addr = XEXP (memref, 0);
  792.  
  793.   /* If reload is in progress or has completed, ADDR must be valid.
  794.      Otherwise, we can call memory_address to make it valid.  */
  795.   if (reload_completed || reload_in_progress)
  796.     {
  797.       if (! memory_address_p (mode, addr))
  798.     abort ();
  799.     }
  800.   else
  801.     addr = memory_address (mode, addr);
  802.     
  803.   new = gen_rtx (MEM, mode, addr);
  804.   MEM_VOLATILE_P (new) = MEM_VOLATILE_P (memref);
  805.   RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (memref);
  806.   MEM_IN_STRUCT_P (new) = MEM_IN_STRUCT_P (memref);
  807.   return new;
  808. }
  809.  
  810. /* Return a newly created CODE_LABEL rtx with a unique label number.  */
  811.  
  812. rtx
  813. gen_label_rtx ()
  814. {
  815.   register rtx label = gen_rtx (CODE_LABEL, VOIDmode, 0, 0, 0, label_num++, 0);
  816.   LABEL_NUSES (label) = 0;
  817.   return label;
  818. }
  819.  
  820. /* For procedure integration.  */
  821.  
  822. /* Return a newly created INLINE_HEADER rtx.  Should allocate this
  823.    from a permanent obstack when the opportunity arises.  */
  824.  
  825. rtx
  826. gen_inline_header_rtx (first_insn, first_parm_insn, first_labelno,
  827.                last_labelno, max_parm_regnum, max_regnum, args_size,
  828.                pops_args, stack_slots, function_flags,
  829.                outgoing_args_size, original_arg_vector,
  830.                original_decl_initial)
  831.      rtx first_insn, first_parm_insn;
  832.      int first_labelno, last_labelno, max_parm_regnum, max_regnum, args_size;
  833.      int pops_args;
  834.      rtx stack_slots;
  835.      int function_flags;
  836.      int outgoing_args_size;
  837.      rtvec original_arg_vector;
  838.      rtx original_decl_initial;
  839. {
  840.   rtx header = gen_rtx (INLINE_HEADER, VOIDmode,
  841.             cur_insn_uid++, NULL,
  842.             first_insn, first_parm_insn,
  843.             first_labelno, last_labelno,
  844.             max_parm_regnum, max_regnum, args_size, pops_args,
  845.             stack_slots, function_flags, outgoing_args_size,
  846.             original_arg_vector, original_decl_initial);
  847.   return header;
  848. }
  849.  
  850. /* Install new pointers to the first and last insns in the chain.
  851.    Used for an inline-procedure after copying the insn chain.  */
  852.  
  853. void
  854. set_new_first_and_last_insn (first, last)
  855.      rtx first, last;
  856. {
  857.   first_insn = first;
  858.   last_insn = last;
  859. }
  860.  
  861. /* Save all variables describing the current status into the structure *P.
  862.    This is used before starting a nested function.  */
  863.  
  864. void
  865. save_emit_status (p)
  866.      struct function *p;
  867. {
  868.   p->reg_rtx_no = reg_rtx_no;
  869.   p->first_label_num = first_label_num;
  870.   p->first_insn = first_insn;
  871.   p->last_insn = last_insn;
  872.   p->sequence_stack = sequence_stack;
  873.   p->cur_insn_uid = cur_insn_uid;
  874.   p->last_linenum = last_linenum;
  875.   p->last_filename = last_filename;
  876.   p->regno_pointer_flag = regno_pointer_flag;
  877.   p->regno_pointer_flag_length = regno_pointer_flag_length;
  878.   p->regno_reg_rtx = regno_reg_rtx;
  879. }
  880.  
  881. /* Restore all variables describing the current status from the structure *P.
  882.    This is used after a nested function.  */
  883.  
  884. void
  885. restore_emit_status (p)
  886.      struct function *p;
  887. {
  888.   int i;
  889.  
  890.   reg_rtx_no = p->reg_rtx_no;
  891.   first_label_num = p->first_label_num;
  892.   first_insn = p->first_insn;
  893.   last_insn = p->last_insn;
  894.   sequence_stack = p->sequence_stack;
  895.   cur_insn_uid = p->cur_insn_uid;
  896.   last_linenum = p->last_linenum;
  897.   last_filename = p->last_filename;
  898.   regno_pointer_flag = p->regno_pointer_flag;
  899.   regno_pointer_flag_length = p->regno_pointer_flag_length;
  900.   regno_reg_rtx = p->regno_reg_rtx;
  901.  
  902.   /* Clear our cache of rtx expressions for start_sequence and gen_sequence. */
  903.   sequence_element_free_list = 0;
  904.   for (i = 0; i < SEQUENCE_RESULT_SIZE; i++)
  905.     sequence_result[i] = 0;
  906. }
  907.  
  908. /* Go through all the RTL insn bodies and copy any invalid shared structure.
  909.    It does not work to do this twice, because the mark bits set here
  910.    are not cleared afterwards.  */
  911.  
  912. static int unshare_copies = 0;    /* Count rtx's that were copied.  */
  913.  
  914. static rtx copy_rtx_if_shared ();
  915.  
  916. void
  917. unshare_all_rtl (insn)
  918.      register rtx insn;
  919. {
  920.   extern rtx stack_slot_list;
  921.  
  922.   for (; insn; insn = NEXT_INSN (insn))
  923.     if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
  924.     || GET_CODE (insn) == CALL_INSN)
  925.       {
  926.     PATTERN (insn) = copy_rtx_if_shared (PATTERN (insn));
  927.     REG_NOTES (insn) = copy_rtx_if_shared (REG_NOTES (insn));
  928.     LOG_LINKS (insn) = copy_rtx_if_shared (LOG_LINKS (insn));
  929.       }
  930.  
  931.   /* Make sure the addresses of stack slots found outside the insn chain
  932.      (such as, in DECL_RTL of a variable) are not shared
  933.      with the insn chain.
  934.  
  935.      This special care is necessary when the stack slot MEM does not
  936.      actually appear in the insn chain.  If it does appear, its address
  937.      is unshared from all else at that point.  */
  938.  
  939.   copy_rtx_if_shared (stack_slot_list);
  940. }
  941.  
  942. /* Mark ORIG as in use, and return a copy of it if it was already in use.
  943.    Recursively does the same for subexpressions.  */
  944.  
  945. static rtx
  946. copy_rtx_if_shared (orig)
  947.      rtx orig;
  948. {
  949.   register rtx x = orig;
  950.   register int i;
  951.   register enum rtx_code code;
  952.   register char *format_ptr;
  953.   int copied = 0;
  954.  
  955.   if (x == 0)
  956.     return 0;
  957.  
  958.   code = GET_CODE (x);
  959.  
  960.   /* These types may be freely shared.  */
  961.  
  962.   switch (code)
  963.     {
  964.     case REG:
  965.     case QUEUED:
  966.     case CONST_INT:
  967.     case CONST_DOUBLE:
  968.     case SYMBOL_REF:
  969.     case CODE_LABEL:
  970.     case PC:
  971.     case CC0:
  972.       return x;
  973.  
  974.     case INSN:
  975.     case JUMP_INSN:
  976.     case CALL_INSN:
  977.     case NOTE:
  978.     case LABEL_REF:
  979.     case BARRIER:
  980.       /* The chain of insns is not being copied.  */
  981.       return x;
  982.  
  983.     case MEM:
  984.       /* A MEM is allowed to be shared if its address is constant
  985.      or is a constant plus one of the special registers.  */
  986.       if (CONSTANT_ADDRESS_P (XEXP (x, 0))
  987.       || XEXP (x, 0) == virtual_stack_vars_rtx
  988.       || XEXP (x, 0) == virtual_incoming_args_rtx)
  989.     return x;
  990.  
  991.       if (GET_CODE (XEXP (x, 0)) == PLUS
  992.       && (XEXP (XEXP (x, 0), 0) == virtual_stack_vars_rtx
  993.           || XEXP (XEXP (x, 0), 0) == virtual_incoming_args_rtx)
  994.       && CONSTANT_ADDRESS_P (XEXP (XEXP (x, 0), 1)))
  995.     {
  996.       /* This MEM can appear in more than one place,
  997.          but its address better not be shared with anything else.  */
  998.       if (! x->used)
  999.         XEXP (x, 0) = copy_rtx_if_shared (XEXP (x, 0));
  1000.       x->used = 1;
  1001.       return x;
  1002.     }
  1003.     }
  1004.  
  1005.   /* This rtx may not be shared.  If it has already been seen,
  1006.      replace it with a copy of itself.  */
  1007.  
  1008.   if (x->used)
  1009.     {
  1010.       register rtx copy;
  1011.  
  1012.       unshare_copies++;
  1013.  
  1014.       copy = rtx_alloc (code);
  1015.       bcopy (x, copy, (sizeof (*copy) - sizeof (copy->fld)
  1016.                + sizeof (copy->fld[0]) * GET_RTX_LENGTH (code)));
  1017.       x = copy;
  1018.       copied = 1;
  1019.     }
  1020.   x->used = 1;
  1021.  
  1022.   /* Now scan the subexpressions recursively.
  1023.      We can store any replaced subexpressions directly into X
  1024.      since we know X is not shared!  Any vectors in X
  1025.      must be copied if X was copied.  */
  1026.  
  1027.   format_ptr = GET_RTX_FORMAT (code);
  1028.  
  1029.   for (i = 0; i < GET_RTX_LENGTH (code); i++)
  1030.     {
  1031.       switch (*format_ptr++)
  1032.     {
  1033.     case 'e':
  1034.       XEXP (x, i) = copy_rtx_if_shared (XEXP (x, i));
  1035.       break;
  1036.  
  1037.     case 'E':
  1038.       if (XVEC (x, i) != NULL)
  1039.         {
  1040.           register int j;
  1041.  
  1042.           if (copied)
  1043.         XVEC (x, i) = gen_rtvec_v (XVECLEN (x, i), &XVECEXP (x, i, 0));
  1044.           for (j = 0; j < XVECLEN (x, i); j++)
  1045.         XVECEXP (x, i, j)
  1046.           = copy_rtx_if_shared (XVECEXP (x, i, j));
  1047.         }
  1048.       break;
  1049.     }
  1050.     }
  1051.   return x;
  1052. }
  1053.  
  1054. /* Copy X if necessary so that it won't be altered by changes in OTHER.
  1055.    Return X or the rtx for the pseudo reg the value of X was copied into.
  1056.    OTHER must be valid as a SET_DEST.  */
  1057.  
  1058. rtx
  1059. make_safe_from (x, other)
  1060.      rtx x, other;
  1061. {
  1062.   while (1)
  1063.     switch (GET_CODE (other))
  1064.       {
  1065.       case SUBREG:
  1066.     other = SUBREG_REG (other);
  1067.     break;
  1068.       case STRICT_LOW_PART:
  1069.       case SIGN_EXTEND:
  1070.       case ZERO_EXTEND:
  1071.     other = XEXP (other, 0);
  1072.     break;
  1073.       default:
  1074.     goto done;
  1075.       }
  1076.  done:
  1077.   if ((GET_CODE (other) == MEM
  1078.        && ! CONSTANT_P (x)
  1079.        && GET_CODE (x) != REG
  1080.        && GET_CODE (x) != SUBREG)
  1081.       || (GET_CODE (other) == REG
  1082.       && (REGNO (other) < FIRST_PSEUDO_REGISTER
  1083.           || reg_mentioned_p (other, x))))
  1084.     {
  1085.       rtx temp = gen_reg_rtx (GET_MODE (x));
  1086.       emit_move_insn (temp, x);
  1087.       return temp;
  1088.     }
  1089.   return x;
  1090. }
  1091.  
  1092. /* Emission of insns (adding them to the doubly-linked list).  */
  1093.  
  1094. /* Return the first insn of the current sequence or current function.  */
  1095.  
  1096. rtx
  1097. get_insns ()
  1098. {
  1099.   return first_insn;
  1100. }
  1101.  
  1102. /* Return the last insn emitted in current sequence or current function.  */
  1103.  
  1104. rtx
  1105. get_last_insn ()
  1106. {
  1107.   return last_insn;
  1108. }
  1109.  
  1110. /* Specify a new insn as the last in the chain.  */
  1111.  
  1112. void
  1113. set_last_insn (insn)
  1114.      rtx insn;
  1115. {
  1116.   if (NEXT_INSN (insn) != 0)
  1117.     abort ();
  1118.   last_insn = insn;
  1119. }
  1120.  
  1121. /* Return the last insn emitted, even if it is in a sequence now pushed.  */
  1122.  
  1123. rtx
  1124. get_last_insn_anywhere ()
  1125. {
  1126.   struct sequence_stack *stack;
  1127.   if (last_insn)
  1128.     return last_insn;
  1129.   for (stack = sequence_stack; stack; stack = stack->next)
  1130.     if (stack->last != 0)
  1131.       return stack->last;
  1132.   return 0;
  1133. }
  1134.  
  1135. /* Return a number larger than any instruction's uid in this function.  */
  1136.  
  1137. int
  1138. get_max_uid ()
  1139. {
  1140.   return cur_insn_uid;
  1141. }
  1142.  
  1143. /* Return the next insn.  If it is a SEQUENCE, return the first insn
  1144.    of the sequence.  */
  1145.  
  1146. rtx
  1147. next_insn (insn)
  1148.      rtx insn;
  1149. {
  1150.   if (insn)
  1151.     {
  1152.       insn = NEXT_INSN (insn);
  1153.       if (insn && GET_CODE (insn) == INSN
  1154.       && GET_CODE (PATTERN (insn)) == SEQUENCE)
  1155.     insn = XVECEXP (PATTERN (insn), 0, 0);
  1156.     }
  1157.  
  1158.   return insn;
  1159. }
  1160.  
  1161. /* Return the previous insn.  If it is a SEQUENCE, return the last insn
  1162.    of the sequence.  */
  1163.  
  1164. rtx
  1165. previous_insn (insn)
  1166.      rtx insn;
  1167. {
  1168.   if (insn)
  1169.     {
  1170.       insn = PREV_INSN (insn);
  1171.       if (insn && GET_CODE (insn) == INSN
  1172.       && GET_CODE (PATTERN (insn)) == SEQUENCE)
  1173.     insn = XVECEXP (PATTERN (insn), 0, XVECLEN (PATTERN (insn), 0) - 1);
  1174.     }
  1175.  
  1176.   return insn;
  1177. }
  1178.  
  1179. /* Return the next insn after INSN that is not a NOTE.  This routine does not
  1180.    look inside SEQUENCEs.  */
  1181.  
  1182. rtx
  1183. next_nonnote_insn (insn)
  1184.      rtx insn;
  1185. {
  1186.   while (insn)
  1187.     {
  1188.       insn = NEXT_INSN (insn);
  1189.       if (insn == 0 || GET_CODE (insn) != NOTE)
  1190.     break;
  1191.     }
  1192.  
  1193.   return insn;
  1194. }
  1195.  
  1196. /* Return the previous insn before INSN that is not a NOTE.  This routine does
  1197.    not look inside SEQUENCEs.  */
  1198.  
  1199. rtx
  1200. prev_nonnote_insn (insn)
  1201.      rtx insn;
  1202. {
  1203.   while (insn)
  1204.     {
  1205.       insn = PREV_INSN (insn);
  1206.       if (insn == 0 || GET_CODE (insn) != NOTE)
  1207.     break;
  1208.     }
  1209.  
  1210.   return insn;
  1211. }
  1212.  
  1213. /* Return the next INSN, CALL_INSN or JUMP_INSN after INSN;
  1214.    or 0, if there is none.  This routine does not look inside
  1215.    SEQUENCEs. */
  1216.  
  1217. rtx
  1218. next_real_insn (insn)
  1219.      rtx insn;
  1220. {
  1221.   while (insn)
  1222.     {
  1223.       insn = NEXT_INSN (insn);
  1224.       if (insn == 0 || GET_CODE (insn) == INSN
  1225.       || GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == JUMP_INSN)
  1226.     break;
  1227.     }
  1228.  
  1229.   return insn;
  1230. }
  1231.  
  1232. /* Return the last INSN, CALL_INSN or JUMP_INSN before INSN;
  1233.    or 0, if there is none.  This routine does not look inside
  1234.    SEQUENCEs.  */
  1235.  
  1236. rtx
  1237. prev_real_insn (insn)
  1238.      rtx insn;
  1239. {
  1240.   while (insn)
  1241.     {
  1242.       insn = PREV_INSN (insn);
  1243.       if (insn == 0 || GET_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN
  1244.       || GET_CODE (insn) == JUMP_INSN)
  1245.     break;
  1246.     }
  1247.  
  1248.   return insn;
  1249. }
  1250.  
  1251. /* Find the next insn after INSN that really does something.  This routine
  1252.    does not look inside SEQUENCEs.  Until reload has completed, this is the
  1253.    same as next_real_insn.  */
  1254.  
  1255. rtx
  1256. next_active_insn (insn)
  1257.      rtx insn;
  1258. {
  1259.   while (insn)
  1260.     {
  1261.       insn = NEXT_INSN (insn);
  1262.       if (insn == 0
  1263.       || GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == JUMP_INSN
  1264.       || (GET_CODE (insn) == INSN
  1265.           && (! reload_completed
  1266.           || (GET_CODE (PATTERN (insn)) != USE
  1267.               && GET_CODE (PATTERN (insn)) != CLOBBER))))
  1268.     break;
  1269.     }
  1270.  
  1271.   return insn;
  1272. }
  1273.  
  1274. /* Find the last insn before INSN that really does something.  This routine
  1275.    does not look inside SEQUENCEs.  Until reload has completed, this is the
  1276.    same as prev_real_insn.  */
  1277.  
  1278. rtx
  1279. prev_active_insn (insn)
  1280.      rtx insn;
  1281. {
  1282.   while (insn)
  1283.     {
  1284.       insn = PREV_INSN (insn);
  1285.       if (insn == 0
  1286.       || GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == JUMP_INSN
  1287.       || (GET_CODE (insn) == INSN
  1288.           && (! reload_completed
  1289.           || (GET_CODE (PATTERN (insn)) != USE
  1290.               && GET_CODE (PATTERN (insn)) != CLOBBER))))
  1291.     break;
  1292.     }
  1293.  
  1294.   return insn;
  1295. }
  1296.  
  1297. /* Return the next CODE_LABEL after the insn INSN, or 0 if there is none.  */
  1298.  
  1299. rtx
  1300. next_label (insn)
  1301.      rtx insn;
  1302. {
  1303.   while (insn)
  1304.     {
  1305.       insn = NEXT_INSN (insn);
  1306.       if (insn == 0 || GET_CODE (insn) == CODE_LABEL)
  1307.     break;
  1308.     }
  1309.  
  1310.   return insn;
  1311. }
  1312.  
  1313. /* Return the last CODE_LABEL before the insn INSN, or 0 if there is none.  */
  1314.  
  1315. rtx
  1316. prev_label (insn)
  1317.      rtx insn;
  1318. {
  1319.   while (insn)
  1320.     {
  1321.       insn = PREV_INSN (insn);
  1322.       if (insn == 0 || GET_CODE (insn) == CODE_LABEL)
  1323.     break;
  1324.     }
  1325.  
  1326.   return insn;
  1327. }
  1328.  
  1329. #ifdef HAVE_cc0
  1330. /* Return the next insn that uses CC0 after INSN, which is assumed to
  1331.    set it.  This is the inverse of prev_cc0_setter (i.e., prev_cc0_setter
  1332.    applied to the result of this function should yield INSN).
  1333.  
  1334.    Normally, this is simply the next insn.  However, if a REG_CC_USER note
  1335.    is present, it contains the insn that uses CC0.
  1336.  
  1337.    Return 0 if we can't find the insn.  */
  1338.  
  1339. rtx
  1340. next_cc0_user (insn)
  1341.      rtx insn;
  1342. {
  1343.   rtx note = find_reg_note (insn, REG_CC_USER, 0);
  1344.  
  1345.   if (note)
  1346.     return XEXP (note, 0);
  1347.  
  1348.   insn = next_nonnote_insn (insn);
  1349.   if (insn && GET_CODE (insn) == INSN && GET_CODE (PATTERN (insn)) == SEQUENCE)
  1350.     insn = XVECEXP (PATTERN (insn), 0, 0);
  1351.  
  1352.   if (insn && GET_RTX_CLASS (GET_CODE (insn)) == 'i'
  1353.       && reg_mentioned_p (cc0_rtx, PATTERN (insn)))
  1354.     return insn;
  1355.  
  1356.   return 0;
  1357. }
  1358.  
  1359. /* Find the insn that set CC0 for INSN.  Unless INSN has a REG_CC_SETTER
  1360.    note, it is the previous insn.  */
  1361.  
  1362. rtx
  1363. prev_cc0_setter (insn)
  1364.      rtx insn;
  1365. {
  1366.   rtx note = find_reg_note (insn, REG_CC_SETTER, 0);
  1367.   rtx link;
  1368.  
  1369.   if (note)
  1370.     return XEXP (note, 0);
  1371.  
  1372.   insn = prev_nonnote_insn (insn);
  1373.   if (! sets_cc0_p (PATTERN (insn)))
  1374.     abort ();
  1375.  
  1376.   return insn;
  1377. }
  1378. #endif
  1379.  
  1380. /* Try splitting insns that can be split for better scheduling.
  1381.    PAT is the pattern which might split.
  1382.    TRIAL is the insn providing PAT.
  1383.    BACKWARDS is non-zero if we are scanning insns from last to first.
  1384.  
  1385.    If this routine succeeds in splitting, it returns the first or last
  1386.    replacement insn depending on the value of BACKWARDS.  Otherwise, it
  1387.    returns TRIAL.  If the insn to be returned can be split, it will be.  */
  1388.  
  1389. rtx
  1390. try_split (pat, trial, backwards)
  1391.      rtx pat, trial;
  1392.      int backwards;
  1393. {
  1394.   rtx before = PREV_INSN (trial);
  1395.   rtx after = NEXT_INSN (trial);
  1396.   rtx seq = split_insns (pat, trial);
  1397.   int has_barrier = 0;
  1398.   rtx tem;
  1399.  
  1400.   /* If we are splitting a JUMP_INSN, it might be followed by a BARRIER.
  1401.      We may need to handle this specially.  */
  1402.   if (after && GET_CODE (after) == BARRIER)
  1403.     {
  1404.       has_barrier = 1;
  1405.       after = NEXT_INSN (after);
  1406.     }
  1407.  
  1408.   if (seq)
  1409.     {
  1410.       /* SEQ can either be a SEQUENCE or the pattern of a single insn.
  1411.      The latter case will normally arise only when being done so that
  1412.      it, in turn, will be split (SFmode on the 29k is an example).  */
  1413.       if (GET_CODE (seq) == SEQUENCE)
  1414.     {
  1415.       tem = emit_insn_after (seq, before);
  1416.       delete_insn (trial);
  1417.       if (has_barrier)
  1418.         emit_barrier_after (tem);
  1419.     }
  1420.       else
  1421.     {
  1422.       PATTERN (trial) = seq;
  1423.       INSN_CODE (trial) = -1;
  1424.     }
  1425.  
  1426.       /* Set TEM to the insn we should return.  */
  1427.       tem = backwards ? prev_active_insn (after) : next_active_insn (before);
  1428.       return try_split (PATTERN (tem), tem, backwards);
  1429.     }
  1430.  
  1431.   return trial;
  1432. }
  1433.  
  1434. /* Make and return an INSN rtx, initializing all its slots.
  1435.    Store PATTERN in the pattern slots.
  1436.    PAT_FORMALS is an idea that never really went anywhere.  */
  1437.  
  1438. rtx
  1439. make_insn_raw (pattern, pat_formals)
  1440.      rtx pattern;
  1441.      rtvec pat_formals;
  1442. {
  1443.   register rtx insn;
  1444.  
  1445.   insn = rtx_alloc(INSN);
  1446.   INSN_UID(insn) = cur_insn_uid++;
  1447.  
  1448.   PATTERN (insn) = pattern;
  1449.   INSN_CODE (insn) = -1;
  1450.   LOG_LINKS(insn) = NULL;
  1451.   REG_NOTES(insn) = NULL;
  1452.  
  1453.   return insn;
  1454. }
  1455.  
  1456. /* Like `make_insn' but make a JUMP_INSN instead of an insn.  */
  1457.  
  1458. static rtx
  1459. make_jump_insn_raw (pattern, pat_formals)
  1460.      rtx pattern;
  1461.      rtvec pat_formals;
  1462. {
  1463.   register rtx insn;
  1464.  
  1465.   insn = rtx_alloc(JUMP_INSN);
  1466.   INSN_UID(insn) = cur_insn_uid++;
  1467.  
  1468.   PATTERN (insn) = pattern;
  1469.   INSN_CODE (insn) = -1;
  1470.   LOG_LINKS(insn) = NULL;
  1471.   REG_NOTES(insn) = NULL;
  1472.   JUMP_LABEL(insn) = NULL;
  1473.  
  1474.   return insn;
  1475. }
  1476.  
  1477. /* Add INSN to the end of the doubly-linked list.
  1478.    INSN may be an INSN, JUMP_INSN, CALL_INSN, CODE_LABEL, BARRIER or NOTE.  */
  1479.  
  1480. static void
  1481. add_insn (insn)
  1482.      register rtx insn;
  1483. {
  1484.   PREV_INSN (insn) = last_insn;
  1485.   NEXT_INSN (insn) = 0;
  1486.  
  1487.   if (NULL != last_insn)
  1488.     NEXT_INSN (last_insn) = insn;
  1489.  
  1490.   if (NULL == first_insn)
  1491.     first_insn = insn;
  1492.  
  1493.   last_insn = insn;
  1494. }
  1495.  
  1496. /* Add INSN into the doubly-linked list after insn AFTER.  This should be the
  1497.    only function called to insert an insn once delay slots have been filled
  1498.    since only it knows how to update a SEQUENCE.  */
  1499.  
  1500. void
  1501. add_insn_after (insn, after)
  1502.      rtx insn, after;
  1503. {
  1504.   rtx next = NEXT_INSN (after);
  1505.  
  1506.   NEXT_INSN (insn) = next;
  1507.   PREV_INSN (insn) = after;
  1508.  
  1509.   if (next)
  1510.     {
  1511.       PREV_INSN (next) = insn;
  1512.       if (GET_CODE (next) == INSN && GET_CODE (PATTERN (next)) == SEQUENCE)
  1513.     PREV_INSN (XVECEXP (PATTERN (next), 0, 0)) = insn;
  1514.     }
  1515.   else if (last_insn == after)
  1516.     last_insn = insn;
  1517.   else
  1518.     {
  1519.       struct sequence_stack *stack = sequence_stack;
  1520.       /* Scan all pending sequences too.  */
  1521.       for (; stack; stack = stack->next)
  1522.     if (after == stack->last)
  1523.       stack->last = insn;
  1524.     }
  1525.  
  1526.   NEXT_INSN (after) = insn;
  1527.   if (GET_CODE (after) == INSN && GET_CODE (PATTERN (after)) == SEQUENCE)
  1528.     {
  1529.       rtx sequence = PATTERN (after);
  1530.       NEXT_INSN (XVECEXP (sequence, 0, XVECLEN (sequence, 0) - 1)) = insn;
  1531.     }
  1532. }
  1533.  
  1534. /* Delete all insns made since FROM.
  1535.    FROM becomes the new last instruction.  */
  1536.  
  1537. void
  1538. delete_insns_since (from)
  1539.      rtx from;
  1540. {
  1541.   if (from == 0)
  1542.     first_insn = 0;
  1543.   else
  1544.     NEXT_INSN (from) = 0;
  1545.   last_insn = from;
  1546. }
  1547.  
  1548. /* Move a consecutive bunch of insns to a different place in the chain.
  1549.    The insns to be moved are those between FROM and TO.
  1550.    They are moved to a new position after the insn AFTER.
  1551.    AFTER must not be FROM or TO or any insn in between.
  1552.  
  1553.    This function does not know about SEQUENCEs and hence should not be
  1554.    called after delay-slot filling has been done.  */
  1555.  
  1556. void
  1557. reorder_insns (from, to, after)
  1558.      rtx from, to, after;
  1559. {
  1560.   /* Splice this bunch out of where it is now.  */
  1561.   if (PREV_INSN (from))
  1562.     NEXT_INSN (PREV_INSN (from)) = NEXT_INSN (to);
  1563.   if (NEXT_INSN (to))
  1564.     PREV_INSN (NEXT_INSN (to)) = PREV_INSN (from);
  1565.   if (last_insn == to)
  1566.     last_insn = PREV_INSN (from);
  1567.   if (first_insn == from)
  1568.     first_insn = NEXT_INSN (to);
  1569.  
  1570.   /* Make the new neighbors point to it and it to them.  */
  1571.   if (NEXT_INSN (after))
  1572.     {
  1573.       PREV_INSN (NEXT_INSN (after)) = to;
  1574.       NEXT_INSN (to) = NEXT_INSN (after);
  1575.     }
  1576.   PREV_INSN (from) = after;
  1577.   NEXT_INSN (after) = from;
  1578.   if (after == last_insn)
  1579.     last_insn = to;
  1580. }
  1581.  
  1582. /* Emit an insn of given code and pattern
  1583.    at a specified place within the doubly-linked list.  */
  1584.  
  1585. /* Make an instruction with body PATTERN
  1586.    and output it before the instruction BEFORE.  */
  1587.  
  1588. rtx
  1589. emit_insn_before (pattern, before)
  1590.      register rtx pattern, before;
  1591. {
  1592.   register rtx insn = before;
  1593.  
  1594.   if (GET_CODE (pattern) == SEQUENCE)
  1595.     {
  1596.       register int i;
  1597.  
  1598.       for (i = 0; i < XVECLEN (pattern, 0); i++)
  1599.     {
  1600.       insn = XVECEXP (pattern, 0, i);
  1601.       add_insn_after (insn, PREV_INSN (before));
  1602.     }
  1603.       if (XVECLEN (pattern, 0) < SEQUENCE_RESULT_SIZE)
  1604.     sequence_result[XVECLEN (pattern, 0)] = pattern;
  1605.     }
  1606.   else
  1607.     {
  1608.       insn = make_insn_raw (pattern, 0);
  1609.       add_insn_after (insn, PREV_INSN (before));
  1610.     }
  1611.  
  1612.   return insn;
  1613. }
  1614.  
  1615. /* Make an instruction with body PATTERN and code JUMP_INSN
  1616.    and output it before the instruction BEFORE.  */
  1617.  
  1618. rtx
  1619. emit_jump_insn_before (pattern, before)
  1620.      register rtx pattern, before;
  1621. {
  1622.   register rtx insn;
  1623.  
  1624.   if (GET_CODE (pattern) == SEQUENCE)
  1625.     insn = emit_insn_before (pattern, before);
  1626.   else
  1627.     {
  1628.       insn = make_jump_insn_raw (pattern, 0);
  1629.       add_insn_after (insn, PREV_INSN (before));
  1630.     }
  1631.  
  1632.   return insn;
  1633. }
  1634.  
  1635. /* Make an instruction with body PATTERN and code CALL_INSN
  1636.    and output it before the instruction BEFORE.  */
  1637.  
  1638. rtx
  1639. emit_call_insn_before (pattern, before)
  1640.      register rtx pattern, before;
  1641. {
  1642.   rtx insn = emit_insn_before (pattern, before);
  1643.   PUT_CODE (insn, CALL_INSN);
  1644.   return insn;
  1645. }
  1646.  
  1647. /* Make an insn of code BARRIER
  1648.    and output it before the insn AFTER.  */
  1649.  
  1650. rtx
  1651. emit_barrier_before (before)
  1652.      register rtx before;
  1653. {
  1654.   register rtx insn = rtx_alloc (BARRIER);
  1655.  
  1656.   INSN_UID (insn) = cur_insn_uid++;
  1657.  
  1658.   add_insn_after (insn, PREV_INSN (before));
  1659.   return insn;
  1660. }
  1661.  
  1662. /* Emit a note of subtype SUBTYPE before the insn BEFORE.  */
  1663.  
  1664. rtx
  1665. emit_note_before (subtype, before)
  1666.      int subtype;
  1667.      rtx before;
  1668. {
  1669.   register rtx note = rtx_alloc (NOTE);
  1670.   INSN_UID (note) = cur_insn_uid++;
  1671.   NOTE_SOURCE_FILE (note) = 0;
  1672.   NOTE_LINE_NUMBER (note) = subtype;
  1673.  
  1674.   add_insn_after (note, PREV_INSN (before));
  1675.   return note;
  1676. }
  1677.  
  1678. /* Make an insn of code INSN with body PATTERN
  1679.    and output it after the insn AFTER.  */
  1680.  
  1681. rtx
  1682. emit_insn_after (pattern, after)
  1683.      register rtx pattern, after;
  1684. {
  1685.   register rtx insn = after;
  1686.  
  1687.   if (GET_CODE (pattern) == SEQUENCE)
  1688.     {
  1689.       register int i;
  1690.  
  1691.       for (i = 0; i < XVECLEN (pattern, 0); i++)
  1692.     {
  1693.       insn = XVECEXP (pattern, 0, i);
  1694.       add_insn_after (insn, after);
  1695.       after = insn;
  1696.     }
  1697.       if (XVECLEN (pattern, 0) < SEQUENCE_RESULT_SIZE)
  1698.     sequence_result[XVECLEN (pattern, 0)] = pattern;
  1699.     }
  1700.   else
  1701.     {
  1702.       insn = make_insn_raw (pattern, 0);
  1703.       add_insn_after (insn, after);
  1704.     }
  1705.  
  1706.   return insn;
  1707. }
  1708.  
  1709. /* Make an insn of code JUMP_INSN with body PATTERN
  1710.    and output it after the insn AFTER.  */
  1711.  
  1712. rtx
  1713. emit_jump_insn_after (pattern, after)
  1714.      register rtx pattern, after;
  1715. {
  1716.   register rtx insn;
  1717.  
  1718.   if (GET_CODE (pattern) == SEQUENCE)
  1719.     insn = emit_insn_after (pattern, after);
  1720.   else
  1721.     {
  1722.       insn = make_jump_insn_raw (pattern, 0);
  1723.       add_insn_after (insn, after);
  1724.     }
  1725.  
  1726.   return insn;
  1727. }
  1728.  
  1729. /* Make an insn of code BARRIER
  1730.    and output it after the insn AFTER.  */
  1731.  
  1732. rtx
  1733. emit_barrier_after (after)
  1734.      register rtx after;
  1735. {
  1736.   register rtx insn = rtx_alloc (BARRIER);
  1737.  
  1738.   INSN_UID (insn) = cur_insn_uid++;
  1739.  
  1740.   add_insn_after (insn, after);
  1741.   return insn;
  1742. }
  1743.  
  1744. /* Emit the label LABEL after the insn AFTER.  */
  1745.  
  1746. rtx
  1747. emit_label_after (label, after)
  1748.      rtx label, after;
  1749. {
  1750.   /* This can be called twice for the same label
  1751.      as a result of the confusion that follows a syntax error!
  1752.      So make it harmless.  */
  1753.   if (INSN_UID (label) == 0)
  1754.     {
  1755.       INSN_UID (label) = cur_insn_uid++;
  1756.       add_insn_after (label, after);
  1757.     }
  1758.  
  1759.   return label;
  1760. }
  1761.  
  1762. /* Emit a note of subtype SUBTYPE after the insn AFTER.  */
  1763.  
  1764. rtx
  1765. emit_note_after (subtype, after)
  1766.      int subtype;
  1767.      rtx after;
  1768. {
  1769.   register rtx note = rtx_alloc (NOTE);
  1770.   INSN_UID (note) = cur_insn_uid++;
  1771.   NOTE_SOURCE_FILE (note) = 0;
  1772.   NOTE_LINE_NUMBER (note) = subtype;
  1773.   add_insn_after (note, after);
  1774.   return note;
  1775. }
  1776.  
  1777. /* Make an insn of code INSN with pattern PATTERN
  1778.    and add it to the end of the doubly-linked list.
  1779.    If PATTERN is a SEQUENCE, take the elements of it
  1780.    and emit an insn for each element.
  1781.  
  1782.    Returns the last insn emitted.  */
  1783.  
  1784. rtx
  1785. emit_insn (pattern)
  1786.      rtx pattern;
  1787. {
  1788.   rtx insn = last_insn;
  1789.  
  1790.   if (GET_CODE (pattern) == SEQUENCE)
  1791.     {
  1792.       register int i;
  1793.  
  1794.       for (i = 0; i < XVECLEN (pattern, 0); i++)
  1795.     {
  1796.       insn = XVECEXP (pattern, 0, i);
  1797.       add_insn (insn);
  1798.     }
  1799.       if (XVECLEN (pattern, 0) < SEQUENCE_RESULT_SIZE)
  1800.     sequence_result[XVECLEN (pattern, 0)] = pattern;
  1801.     }
  1802.   else
  1803.     {
  1804.       insn = make_insn_raw (pattern, NULL);
  1805.       add_insn (insn);
  1806.     }
  1807.  
  1808.   return insn;
  1809. }
  1810.  
  1811. /* Emit the insns in a chain starting with INSN.
  1812.    Return the last insn emitted.  */
  1813.  
  1814. rtx
  1815. emit_insns (insn)
  1816.      rtx insn;
  1817. {
  1818.   rtx last = 0;
  1819.  
  1820.   while (insn)
  1821.     {
  1822.       rtx next = NEXT_INSN (insn);
  1823.       add_insn (insn);
  1824.       last = insn;
  1825.       insn = next;
  1826.     }
  1827.  
  1828.   return last;
  1829. }
  1830.  
  1831. /* Emit the insns in a chain starting with INSN and place them in front of
  1832.    the insn BEFORE.  Return the last insn emitted.  */
  1833.  
  1834. rtx
  1835. emit_insns_before (insn, before)
  1836.      rtx insn;
  1837.      rtx before;
  1838. {
  1839.   rtx last = 0;
  1840.  
  1841.   while (insn)
  1842.     {
  1843.       rtx next = NEXT_INSN (insn);
  1844.       add_insn_after (insn, PREV_INSN (before));
  1845.       last = insn;
  1846.       insn = next;
  1847.     }
  1848.  
  1849.   return last;
  1850. }
  1851.  
  1852. /* Make an insn of code JUMP_INSN with pattern PATTERN
  1853.    and add it to the end of the doubly-linked list.  */
  1854.  
  1855. rtx
  1856. emit_jump_insn (pattern)
  1857.      rtx pattern;
  1858. {
  1859.   if (GET_CODE (pattern) == SEQUENCE)
  1860.     return emit_insn (pattern);
  1861.   else
  1862.     {
  1863.       register rtx insn = make_jump_insn_raw (pattern, NULL);
  1864.       add_insn (insn);
  1865.       return insn;
  1866.     }
  1867. }
  1868.  
  1869. /* Make an insn of code CALL_INSN with pattern PATTERN
  1870.    and add it to the end of the doubly-linked list.  */
  1871.  
  1872. rtx
  1873. emit_call_insn (pattern)
  1874.      rtx pattern;
  1875. {
  1876.   if (GET_CODE (pattern) == SEQUENCE)
  1877.     return emit_insn (pattern);
  1878.   else
  1879.     {
  1880.       register rtx insn = make_insn_raw (pattern, NULL);
  1881.       add_insn (insn);
  1882.       PUT_CODE (insn, CALL_INSN);
  1883.       return insn;
  1884.     }
  1885. }
  1886.  
  1887. /* Add the label LABEL to the end of the doubly-linked list.  */
  1888.  
  1889. rtx
  1890. emit_label (label)
  1891.      rtx label;
  1892. {
  1893.   /* This can be called twice for the same label
  1894.      as a result of the confusion that follows a syntax error!
  1895.      So make it harmless.  */
  1896.   if (INSN_UID (label) == 0)
  1897.     {
  1898.       INSN_UID (label) = cur_insn_uid++;
  1899.       add_insn (label);
  1900.     }
  1901.   return label;
  1902. }
  1903.  
  1904. /* Make an insn of code BARRIER
  1905.    and add it to the end of the doubly-linked list.  */
  1906.  
  1907. rtx
  1908. emit_barrier ()
  1909. {
  1910.   register rtx barrier = rtx_alloc (BARRIER);
  1911.   INSN_UID (barrier) = cur_insn_uid++;
  1912.   add_insn (barrier);
  1913.   return barrier;
  1914. }
  1915.  
  1916. /* Make an insn of code NOTE
  1917.    with data-fields specified by FILE and LINE
  1918.    and add it to the end of the doubly-linked list,
  1919.    but only if line-numbers are desired for debugging info.  */
  1920.  
  1921. rtx
  1922. emit_line_note (file, line)
  1923.      char *file;
  1924.      int line;
  1925. {
  1926.   emit_filename = file;
  1927.   emit_lineno = line;
  1928.  
  1929. #if 0
  1930.   if (no_line_numbers)
  1931.     return 0;
  1932. #endif
  1933.  
  1934.   return emit_note (file, line);
  1935. }
  1936.  
  1937. /* Make an insn of code NOTE
  1938.    with data-fields specified by FILE and LINE
  1939.    and add it to the end of the doubly-linked list.
  1940.    If it is a line-number NOTE, omit it if it matches the previous one.  */
  1941.  
  1942. rtx
  1943. emit_note (file, line)
  1944.      char *file;
  1945.      int line;
  1946. {
  1947.   register rtx note;
  1948.  
  1949.   if (line > 0)
  1950.     {
  1951.       if (file && last_filename && !strcmp (file, last_filename)
  1952.       && line == last_linenum)
  1953.     return 0;
  1954.       last_filename = file;
  1955.       last_linenum = line;
  1956.     }
  1957.  
  1958.   if (no_line_numbers && line > 0)
  1959.     {
  1960.       cur_insn_uid++;
  1961.       return 0;
  1962.     }
  1963.  
  1964.   note = rtx_alloc (NOTE);
  1965.   INSN_UID (note) = cur_insn_uid++;
  1966.   NOTE_SOURCE_FILE (note) = file;
  1967.   NOTE_LINE_NUMBER (note) = line;
  1968.   add_insn (note);
  1969.   return note;
  1970. }
  1971.  
  1972. /* Emit a NOTE, and don't omit it even if LINE it the previous note.  */
  1973.  
  1974. rtx
  1975. emit_line_note_force (file, line)
  1976.      char *file;
  1977.      int line;
  1978. {
  1979.   last_linenum = -1;
  1980.   return emit_line_note (file, line);
  1981. }
  1982.  
  1983. /* Cause next statement to emit a line note even if the line number
  1984.    has not changed.  This is used at the beginning of a function.  */
  1985.  
  1986. void
  1987. force_next_line_note ()
  1988. {
  1989.   last_linenum = -1;
  1990. }
  1991.  
  1992. /* Return an indication of which type of insn should have X as a body.
  1993.    The value is CODE_LABEL, INSN, CALL_INSN or JUMP_INSN.  */
  1994.  
  1995. enum rtx_code
  1996. classify_insn (x)
  1997.      rtx x;
  1998. {
  1999.   if (GET_CODE (x) == CODE_LABEL)
  2000.     return CODE_LABEL;
  2001.   if (GET_CODE (x) == CALL)
  2002.     return CALL_INSN;
  2003.   if (GET_CODE (x) == RETURN)
  2004.     return JUMP_INSN;
  2005.   if (GET_CODE (x) == SET)
  2006.     {
  2007.       if (SET_DEST (x) == pc_rtx)
  2008.     return JUMP_INSN;
  2009.       else if (GET_CODE (SET_SRC (x)) == CALL)
  2010.     return CALL_INSN;
  2011.       else
  2012.     return INSN;
  2013.     }
  2014.   if (GET_CODE (x) == PARALLEL)
  2015.     {
  2016.       register int j;
  2017.       for (j = XVECLEN (x, 0) - 1; j >= 0; j--)
  2018.     if (GET_CODE (XVECEXP (x, 0, j)) == CALL)
  2019.       return CALL_INSN;
  2020.     else if (GET_CODE (XVECEXP (x, 0, j)) == SET
  2021.          && SET_DEST (XVECEXP (x, 0, j)) == pc_rtx)
  2022.       return JUMP_INSN;
  2023.     else if (GET_CODE (XVECEXP (x, 0, j)) == SET
  2024.          && GET_CODE (SET_SRC (XVECEXP (x, 0, j))) == CALL)
  2025.       return CALL_INSN;
  2026.     }
  2027.   return INSN;
  2028. }
  2029.  
  2030. /* Emit the rtl pattern X as an appropriate kind of insn.
  2031.    If X is a label, it is simply added into the insn chain.  */
  2032.  
  2033. rtx
  2034. emit (x)
  2035.      rtx x;
  2036. {
  2037.   enum rtx_code code = classify_insn (x);
  2038.  
  2039.   if (code == CODE_LABEL)
  2040.     return emit_label (x);
  2041.   else if (code == INSN)
  2042.     return emit_insn (x);
  2043.   else if (code == JUMP_INSN)
  2044.     {
  2045.       register rtx insn = emit_jump_insn (x);
  2046.       if (simplejump_p (insn) || GET_CODE (x) == RETURN)
  2047.     return emit_barrier ();
  2048.       return insn;
  2049.     }
  2050.   else if (code == CALL_INSN)
  2051.     return emit_call_insn (x);
  2052. }
  2053.  
  2054. /* Begin emitting insns to a sequence which can be packaged in an RTL_EXPR.  */
  2055.  
  2056. void
  2057. start_sequence ()
  2058. {
  2059.   struct sequence_stack *tem;
  2060.  
  2061.   if (sequence_element_free_list)
  2062.     {
  2063.       /* Reuse a previously-saved struct sequence_stack.  */
  2064.       tem = sequence_element_free_list;
  2065.       sequence_element_free_list = tem->next;
  2066.     }
  2067.   else
  2068.     tem = (struct sequence_stack *) permalloc (sizeof (struct sequence_stack));
  2069.  
  2070.   tem->next = sequence_stack;
  2071.   tem->first = first_insn;
  2072.   tem->last = last_insn;
  2073.  
  2074.   sequence_stack = tem;
  2075.  
  2076.   first_insn = 0;
  2077.   last_insn = 0;
  2078. }
  2079.  
  2080. /* Set up the insn chain starting with FIRST
  2081.    as the current sequence, saving the previously current one.  */
  2082.  
  2083. void
  2084. push_to_sequence (first)
  2085.      rtx first;
  2086. {
  2087.   rtx last;
  2088.  
  2089.   start_sequence ();
  2090.  
  2091.   for (last = first; last && NEXT_INSN (last); last = NEXT_INSN (last));
  2092.  
  2093.   first_insn = first;
  2094.   last_insn = last;
  2095. }
  2096.  
  2097. /* After emitting to a sequence, restore previous saved state.
  2098.  
  2099.    To get the contents of the sequence just made,
  2100.    you must call `gen_sequence' *before* calling here.  */
  2101.  
  2102. void
  2103. end_sequence ()
  2104. {
  2105.   struct sequence_stack *tem = sequence_stack;
  2106.  
  2107.   first_insn = tem->first;
  2108.   last_insn = tem->last;
  2109.   sequence_stack = tem->next;
  2110.  
  2111.   tem->next = sequence_element_free_list;
  2112.   sequence_element_free_list = tem;
  2113. }
  2114.  
  2115. /* Return 1 if currently emitting into a sequence.  */
  2116.  
  2117. int
  2118. in_sequence_p ()
  2119. {
  2120.   return sequence_stack != 0;
  2121. }
  2122.  
  2123. /* Generate a SEQUENCE rtx containing the insns already emitted
  2124.    to the current sequence.
  2125.  
  2126.    This is how the gen_... function from a DEFINE_EXPAND
  2127.    constructs the SEQUENCE that it returns.  */
  2128.  
  2129. rtx
  2130. gen_sequence ()
  2131. {
  2132.   rtx result;
  2133.   rtx tem;
  2134.   rtvec newvec;
  2135.   int i;
  2136.   int len;
  2137.  
  2138.   /* Count the insns in the chain.  */
  2139.   len = 0;
  2140.   for (tem = first_insn; tem; tem = NEXT_INSN (tem))
  2141.     len++;
  2142.  
  2143.   /* If only one insn, return its pattern rather than a SEQUENCE.
  2144.      (Now that we cache SEQUENCE expressions, it isn't worth special-casing
  2145.      the case of an empty list.)  */
  2146.   if (len == 1
  2147.       && (GET_CODE (first_insn) == INSN
  2148.       || GET_CODE (first_insn) == JUMP_INSN
  2149.       || GET_CODE (first_insn) == CALL_INSN))
  2150.     return PATTERN (first_insn);
  2151.  
  2152.   /* Put them in a vector.  See if we already have a SEQUENCE of the
  2153.      appropriate length around.  */
  2154.   if (len < SEQUENCE_RESULT_SIZE && (result = sequence_result[len]) != 0)
  2155.     sequence_result[len] = 0;
  2156.   else
  2157.     {
  2158.       /* Ensure that this rtl goes in saveable_obstack, since we may be
  2159.      caching it.  */
  2160.       int in_current_obstack = rtl_in_saveable_obstack ();
  2161.       result = gen_rtx (SEQUENCE, VOIDmode, rtvec_alloc (len));
  2162.       if (in_current_obstack)
  2163.     rtl_in_current_obstack ();
  2164.     }
  2165.  
  2166.   for (i = 0, tem = first_insn; tem; tem = NEXT_INSN (tem), i++)
  2167.     XVECEXP (result, 0, i) = tem;
  2168.  
  2169.   return result;
  2170. }
  2171.  
  2172. /* Set up regno_reg_rtx, reg_rtx_no and regno_pointer_flag
  2173.    according to the chain of insns starting with FIRST.
  2174.  
  2175.    Also set cur_insn_uid to exceed the largest uid in that chain.
  2176.  
  2177.    This is used when an inline function's rtl is saved
  2178.    and passed to rest_of_compilation later.  */
  2179.  
  2180. static void restore_reg_data_1 ();
  2181.  
  2182. void
  2183. restore_reg_data (first)
  2184.      rtx first;
  2185. {
  2186.   register rtx insn;
  2187.   int i;
  2188.   register int max_uid = 0;
  2189.  
  2190.   for (insn = first; insn; insn = NEXT_INSN (insn))
  2191.     {
  2192.       if (INSN_UID (insn) >= max_uid)
  2193.     max_uid = INSN_UID (insn);
  2194.  
  2195.       switch (GET_CODE (insn))
  2196.     {
  2197.     case NOTE:
  2198.     case CODE_LABEL:
  2199.     case BARRIER:
  2200.       break;
  2201.  
  2202.     case JUMP_INSN:
  2203.     case CALL_INSN:
  2204.     case INSN:
  2205.       restore_reg_data_1 (PATTERN (insn));
  2206.       break;
  2207.     }
  2208.     }
  2209.  
  2210.   /* Don't duplicate the uids already in use.  */
  2211.   cur_insn_uid = max_uid + 1;
  2212.  
  2213.   /* If any regs are missing, make them up.  */
  2214.   for (i = FIRST_PSEUDO_REGISTER; i < reg_rtx_no; i++)
  2215.     if (regno_reg_rtx[i] == 0)
  2216.       regno_reg_rtx[i] = gen_rtx (REG, SImode, i);
  2217. }
  2218.  
  2219. static void
  2220. restore_reg_data_1 (orig)
  2221.      rtx orig;
  2222. {
  2223.   register rtx x = orig;
  2224.   register int i;
  2225.   register enum rtx_code code;
  2226.   register char *format_ptr;
  2227.  
  2228.   code = GET_CODE (x);
  2229.  
  2230.   switch (code)
  2231.     {
  2232.     case QUEUED:
  2233.     case CONST_INT:
  2234.     case CONST_DOUBLE:
  2235.     case SYMBOL_REF:
  2236.     case CODE_LABEL:
  2237.     case PC:
  2238.     case CC0:
  2239.     case LABEL_REF:
  2240.       return;
  2241.  
  2242.     case REG:
  2243.       if (REGNO (x) >= FIRST_PSEUDO_REGISTER)
  2244.     {
  2245.       /* Make sure regno_pointer_flag and regno_reg_rtx are large
  2246.          enough to have an element for this pseudo reg number.  */
  2247.       if (REGNO (x) >= reg_rtx_no)
  2248.         {
  2249.           reg_rtx_no = REGNO (x);
  2250.  
  2251.           if (reg_rtx_no >= regno_pointer_flag_length)
  2252.         {
  2253.           int newlen = max (regno_pointer_flag_length * 2,
  2254.                     reg_rtx_no + 30);
  2255.           rtx *new1;
  2256.           char *new = (char *) oballoc (newlen);
  2257.           bzero (new, newlen);
  2258.           bcopy (regno_pointer_flag, new, regno_pointer_flag_length);
  2259.  
  2260.           new1 = (rtx *) oballoc (newlen * sizeof (rtx));
  2261.           bzero (new1, newlen * sizeof (rtx));
  2262.           bcopy (regno_reg_rtx, new1, regno_pointer_flag_length * sizeof (rtx));
  2263.  
  2264.           regno_pointer_flag = new;
  2265.           regno_reg_rtx = new1;
  2266.           regno_pointer_flag_length = newlen;
  2267.         }
  2268.           reg_rtx_no ++;
  2269.         }
  2270.       regno_reg_rtx[REGNO (x)] = x;
  2271.     }
  2272.       return;
  2273.  
  2274.     case MEM:
  2275.       if (GET_CODE (XEXP (x, 0)) == REG)
  2276.     mark_reg_pointer (XEXP (x, 0));
  2277.       restore_reg_data_1 (XEXP (x, 0));
  2278.       return;
  2279.     }
  2280.  
  2281.   /* Now scan the subexpressions recursively.  */
  2282.  
  2283.   format_ptr = GET_RTX_FORMAT (code);
  2284.  
  2285.   for (i = 0; i < GET_RTX_LENGTH (code); i++)
  2286.     {
  2287.       switch (*format_ptr++)
  2288.     {
  2289.     case 'e':
  2290.       restore_reg_data_1 (XEXP (x, i));
  2291.       break;
  2292.  
  2293.     case 'E':
  2294.       if (XVEC (x, i) != NULL)
  2295.         {
  2296.           register int j;
  2297.  
  2298.           for (j = 0; j < XVECLEN (x, i); j++)
  2299.         restore_reg_data_1 (XVECEXP (x, i, j));
  2300.         }
  2301.       break;
  2302.     }
  2303.     }
  2304. }
  2305.  
  2306. /* Initialize data structures and variables in this file
  2307.    before generating rtl for each function.  */
  2308.  
  2309. void
  2310. init_emit ()
  2311. {
  2312.   int i;
  2313.  
  2314.   first_insn = NULL;
  2315.   last_insn = NULL;
  2316.   cur_insn_uid = 1;
  2317.   reg_rtx_no = LAST_VIRTUAL_REGISTER + 1;
  2318.   last_linenum = 0;
  2319.   last_filename = 0;
  2320.   first_label_num = label_num;
  2321.  
  2322.   /* Clear the start_sequence/gen_sequence cache.  */
  2323.   sequence_element_free_list = 0;
  2324.   for (i = 0; i < SEQUENCE_RESULT_SIZE; i++)
  2325.     sequence_result[i] = 0;
  2326.  
  2327.   /* Init the tables that describe all the pseudo regs.  */
  2328.  
  2329.   regno_pointer_flag_length = LAST_VIRTUAL_REGISTER + 101;
  2330.  
  2331.   regno_pointer_flag 
  2332.     = (char *) oballoc (regno_pointer_flag_length);
  2333.   bzero (regno_pointer_flag, regno_pointer_flag_length);
  2334.  
  2335.   regno_reg_rtx 
  2336.     = (rtx *) oballoc (regno_pointer_flag_length * sizeof (rtx));
  2337.   bzero (regno_reg_rtx, regno_pointer_flag_length * sizeof (rtx));
  2338.  
  2339.   /* Put copies of all the virtual register rtx into regno_reg_rtx.  */
  2340.   regno_reg_rtx[VIRTUAL_INCOMING_ARGS_REGNUM] = virtual_incoming_args_rtx;
  2341.   regno_reg_rtx[VIRTUAL_STACK_VARS_REGNUM] = virtual_stack_vars_rtx;
  2342.   regno_reg_rtx[VIRTUAL_STACK_DYNAMIC_REGNUM] = virtual_stack_dynamic_rtx;
  2343.   regno_reg_rtx[VIRTUAL_OUTGOING_ARGS_REGNUM] = virtual_outgoing_args_rtx;
  2344. }
  2345.  
  2346. /* Create some permanent unique rtl objects shared between all functions.
  2347.    WRITE_SYMBOLS is nonzero if any kind of debugging info
  2348.    is to be generated.  */
  2349.  
  2350. void
  2351. init_emit_once (write_symbols)
  2352.      int write_symbols;
  2353. {
  2354.   int i;
  2355.  
  2356.   no_line_numbers = ! write_symbols;
  2357.  
  2358.   sequence_stack = NULL;
  2359.  
  2360.   /* Create the unique rtx's for certain rtx codes and operand values.  */
  2361.  
  2362.   pc_rtx = gen_rtx (PC, VOIDmode);
  2363.   cc0_rtx = gen_rtx (CC0, VOIDmode);
  2364.  
  2365.   /* Don't use gen_rtx here since gen_rtx in this case
  2366.      tries to use these variables.  */
  2367.   for (i = - MAX_SAVED_CONST_INT; i <= MAX_SAVED_CONST_INT; i++)
  2368.     {
  2369.       const_int_rtx[i + MAX_SAVED_CONST_INT] = rtx_alloc (CONST_INT);
  2370.       PUT_MODE (const_int_rtx[i + MAX_SAVED_CONST_INT], VOIDmode);
  2371.       INTVAL (const_int_rtx[i + MAX_SAVED_CONST_INT]) = i;
  2372.     }
  2373.  
  2374.   /* These three calls obtain some of the rtx expressions made above.  */
  2375.   const0_rtx = gen_rtx (CONST_INT, VOIDmode, 0);
  2376.   const1_rtx = gen_rtx (CONST_INT, VOIDmode, 1);
  2377.   constm1_rtx = gen_rtx (CONST_INT, VOIDmode, -1);
  2378.  
  2379.   /* This will usually be one of the above constants, but may be a new rtx.  */
  2380.   const_true_rtx = gen_rtx (CONST_INT, VOIDmode, STORE_FLAG_VALUE);
  2381.  
  2382.   dconst0 = REAL_VALUE_ATOF ("0");
  2383.   dconst1 = REAL_VALUE_ATOF ("1");
  2384.   dconst2 = REAL_VALUE_ATOF ("2");
  2385.   dconstm1 = REAL_VALUE_ATOF ("-1");
  2386.  
  2387.   fconst0_rtx = rtx_alloc (CONST_DOUBLE);
  2388.   fconst1_rtx = rtx_alloc (CONST_DOUBLE);
  2389.   dconst0_rtx = rtx_alloc (CONST_DOUBLE);
  2390.   dconst1_rtx = rtx_alloc (CONST_DOUBLE);
  2391.  
  2392.   {
  2393.     union real_extract u;
  2394.     bzero (&u, sizeof u);  /* Zero any holes in a structure.  */
  2395.     u.d = dconst0;
  2396.  
  2397.     bcopy (&u, &CONST_DOUBLE_LOW (fconst0_rtx), sizeof u);
  2398.     CONST_DOUBLE_MEM (fconst0_rtx) = cc0_rtx;
  2399.     PUT_MODE (fconst0_rtx, SFmode);
  2400.  
  2401.     bcopy (&u, &CONST_DOUBLE_LOW (dconst0_rtx), sizeof u);
  2402.     CONST_DOUBLE_MEM (dconst0_rtx) = cc0_rtx;
  2403.     PUT_MODE (dconst0_rtx, DFmode);
  2404.  
  2405.     u.d = dconst1;
  2406.  
  2407.     bcopy (&u, &CONST_DOUBLE_LOW (fconst1_rtx), sizeof u);
  2408.     CONST_DOUBLE_MEM (fconst1_rtx) = cc0_rtx;
  2409.     PUT_MODE (fconst1_rtx, SFmode);
  2410.  
  2411.     bcopy (&u, &CONST_DOUBLE_LOW (dconst1_rtx), sizeof u);
  2412.     CONST_DOUBLE_MEM (dconst1_rtx) = cc0_rtx;
  2413.     PUT_MODE (dconst1_rtx, DFmode);
  2414.   }
  2415.  
  2416.   stack_pointer_rtx = gen_rtx (REG, Pmode, STACK_POINTER_REGNUM);
  2417.   frame_pointer_rtx = gen_rtx (REG, Pmode, FRAME_POINTER_REGNUM);
  2418.  
  2419.   if (FRAME_POINTER_REGNUM == ARG_POINTER_REGNUM)
  2420.     arg_pointer_rtx = frame_pointer_rtx;
  2421.   else if (STACK_POINTER_REGNUM == ARG_POINTER_REGNUM)
  2422.     arg_pointer_rtx = stack_pointer_rtx;
  2423.   else
  2424.     arg_pointer_rtx = gen_rtx (REG, Pmode, ARG_POINTER_REGNUM);
  2425.  
  2426. #ifdef STRUCT_VALUE
  2427.   struct_value_rtx = STRUCT_VALUE;
  2428. #else
  2429.   struct_value_rtx = gen_rtx (REG, Pmode, STRUCT_VALUE_REGNUM);
  2430. #endif
  2431.  
  2432. #ifdef STRUCT_VALUE_INCOMING
  2433.   struct_value_incoming_rtx = STRUCT_VALUE_INCOMING;
  2434. #else
  2435. #ifdef STRUCT_VALUE_INCOMING_REGNUM
  2436.   struct_value_incoming_rtx
  2437.     = gen_rtx (REG, Pmode, STRUCT_VALUE_INCOMING_REGNUM);
  2438. #else
  2439.   struct_value_incoming_rtx = struct_value_rtx;
  2440. #endif
  2441. #endif
  2442.  
  2443. #ifdef STATIC_CHAIN_REGNUM
  2444.   static_chain_rtx = gen_rtx (REG, Pmode, STATIC_CHAIN_REGNUM);
  2445.  
  2446. #ifdef STATIC_CHAIN_INCOMING_REGNUM
  2447.   if (STATIC_CHAIN_INCOMING_REGNUM != STATIC_CHAIN_REGNUM)
  2448.     static_chain_incoming_rtx = gen_rtx (REG, Pmode, STATIC_CHAIN_INCOMING_REGNUM);
  2449.   else
  2450. #endif
  2451.     static_chain_incoming_rtx = static_chain_rtx;
  2452. #endif
  2453.  
  2454. #ifdef STATIC_CHAIN
  2455.   static_chain_rtx = STATIC_CHAIN;
  2456.  
  2457. #ifdef STATIC_CHAIN_INCOMING
  2458.   static_chain_incoming_rtx = STATIC_CHAIN_INCOMING;
  2459. #else
  2460.   static_chain_incoming_rtx = static_chain_rtx;
  2461. #endif
  2462. #endif
  2463.  
  2464.   /* Create the virtual registers.  */
  2465.   virtual_incoming_args_rtx = gen_rtx (REG, Pmode, VIRTUAL_INCOMING_ARGS_REGNUM);
  2466.   virtual_stack_vars_rtx = gen_rtx (REG, Pmode, VIRTUAL_STACK_VARS_REGNUM);
  2467.   virtual_stack_dynamic_rtx = gen_rtx (REG, Pmode, VIRTUAL_STACK_DYNAMIC_REGNUM);
  2468.   virtual_outgoing_args_rtx = gen_rtx (REG, Pmode, VIRTUAL_OUTGOING_ARGS_REGNUM);
  2469. #ifdef PIC_OFFSET_TABLE_REGNUM
  2470.   pic_offset_table_rtx = gen_rtx (REG, Pmode, PIC_OFFSET_TABLE_REGNUM);
  2471. #endif
  2472. }
  2473.