home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / GCC 1.37.1r14 / usr / gcc-1.37.1r14 / (gcc-1.37.π) / emit-rtl.c < prev    next >
Encoding:
Text File  |  1993-07-19  |  40.2 KB  |  862 lines  |  [TEXT/KAHL]

  1. /* Emit RTL for the GNU C-Compiler expander.
  2.    Copyright (C) 1987, 1988 Free Software Foundation, Inc.
  3.    Copyright (C) 1989, 1990 Apple Computer, Inc.
  4.  
  5. This file is part of GNU CC.
  6.  
  7. GNU CC is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 1, or (at your option)
  10. any later version.
  11.  
  12. GNU CC is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the impliedt insn emitted.
  14.    Reset to 1 for each function compiled.  */
  15.  
  16. static int cur_insn_uid = 1;
  17.  
  18. /* Line number and source file of the last line-number NOTE emitted.
  19.    This is used to avoid generating duplicates.  */
  20.  
  21. static int last_linenum = 0;
  22. static char *last_filename = 0;
  23.  
  24. /* A vector indexed by pseudo reg number.  The allocated length
  25.    of this vector is regno_pointer_flag_length.  Since this
  26.    vector is needed during the expansion phase when the total
  27.    number of registers in the function is not yet known,
  28.    it is copied and made bigger when necessary.  */
  29.  
  30. char *regno_pointer_flag;
  31. int regno_pointer_flag_length;
  32.  
  33. /* Indexed by pseudo register number, gives the rtx for that pseudo.
  34.    Allocated in parallel with regno_pointer_flag.  */
  35.  
  36. rtx *regno_reg_rtx;
  37.  
  38. /* Filename and line number of last line-number note,
  39.    whether we actually emitted it or not.  */
  40. extern char *emit_filename;
  41. extern int emit_lineno;
  42.  
  43. rtx change_address ();
  44.  
  45. /* rtx gen_rtx (code, mode, [element1, ..., elementn])
  46. **
  47. **        This routine generates an RTX of the size specified by
  48. **    <code>, which is an RTX code.   The RTX structure is initialized
  49. **    from the arguments <element1> through <elementn>, which are
  50. **    interpreted according to the specific RTX type's format.   The
  51. **    special machine mode associated with the rtx (if any) is specified
  52. **    in <mode>.
  53. **
  54. **        gen_rtx() can be invoked in a way which resembles the lisp-like
  55. **    rtx it will generate.   For example, the following rtx structure:
  56. **
  57. **          (plus:QI (mem:QI (reg:SI 1))
  58. **               (mem:QI (plusw:SI (reg:SI 2) (reg:SI 3))))
  59. **
  60. **        ...would be generated by the following C code:
  61. **
  62. **            gen_rtx (PLUS, QImode,
  63. **            gen_rtx (MEM, QImode,
  64. **            gen_rtx (REG, SImode, 1)),
  65. **            gen_rtx (MEM, QImode,
  66. **            gen_rtx (PLUS, SImode,
  67. **                gen_rtx (REG, SImode, 2),
  68. **                gen_rtx (REG, SImode, 3)))),
  69. */
  70.  
  71. /*VARARGS2*/
  72. rtx
  73. #ifdef APPLE_HAX_VA
  74. gen_rtx (
  75.   enum rtx_code code,
  76.   enum machine_mode mode, ...)
  77. {
  78.   va_list p;
  79. #else
  80. gen_rtx (va_alist)
  81.      va_dcl
  82. {
  83.   va_list p;
  84.   enum rtx_code code;
  85.   enum machine_mode mode;
  86. #endif
  87.   register int i;        /* Array indices...            */
  88.   register char *fmt;        /* Current rtx's format...        */
  89.   register rtx rt_val;        /* RTX to return to caller...        */
  90.  
  91. #ifdef APPLE_HAX_VA
  92.   va_start (p, mode);
  93. #else
  94.   va_start (p);
  95.   code = va_arg (p, enum rtx_code);
  96.   mode = va_arg (p, enum machine_mode);
  97. #endif
  98.  
  99.   if (code == CONST_INT)
  100.     {
  101.       int arg = va_arg (p, int);
  102.       if (arg == 0)
  103.     return const0_rtx;
  104.       if (arg == 1)
  105.     return const1_rtx;
  106.       rt_val = rtx_alloc (code);
  107.       INTVAL (rt_val) = arg;
  108.     }
  109.   else
  110.     {
  111.       rt_val = rtx_alloc (code);    /* Allocate the storage space.  */
  112.       rt_val->mode = mode;        /* Store the machine mode...  */
  113.  
  114.       fmt = GET_RTX_FORMAT (code);    /* Find the right format...  */
  115.       for (i = 0; i < GET_RTX_LENGTH (code); i++)
  116.     {
  117.       switch (*fmt++)
  118.         {
  119.         case '0':        /* Unused field.  */
  120.           break;
  121.  
  122.         case 'i':        /* An integer?  */
  123.           XINT (rt_val, i) = va_arg (p, int);
  124.           break;
  125.  
  126.         case 's':        /* A string?  */
  127.           XSTR (rt_val, i) = va_arg (p, char *);
  128.           break;
  129.  
  130.         case 'e':        /* An expression?  */
  131.         case 'u':        /* An insn?  Same except when printing.  */
  132.           XEXP (rt_val, i) = va_arg (p, rtx);
  133.           break;
  134.  
  135.         case 'E':        /* An RTX vector?  */
  136.           XVEC (rt_val, i) = va_arg (p, rtvec);
  137.           break;
  138.  
  139.         default:
  140.           abort();
  141.         }
  142.     }
  143.     }
  144.   va_end (p);
  145.   return rt_val;        /* Return the new RTX...        */
  146. }
  147.  
  148. /* gen_rtvec (n, [rt1, ..., rtn])
  149. **
  150. **        This routine creates an rtvec and stores within it the
  151. **    pointers to rtx's which are its arguments.
  152. */
  153.  
  154. /*VARARGS1*/
  155. rtvec
  156. #ifdef APPLE_HAX_VA
  157. gen_rtvec (int n, ...)
  158. {
  159.   int i;
  160.   va_list p;
  161. #else
  162. gen_rtvec (va_alist)
  163.      va_dcl
  164. {
  165.   int n, i;
  166.   va_list p;
  167. #endif
  168.   rtx *vector;
  169.  
  170. #ifdef APPLE_HAX_VA
  171.   va_start (p, n);
  172. #else
  173.   va_start (p);
  174.   n = va_arg (p, int);
  175. #endif
  176.  
  177.   if (n == 0)
  178.     return NULL_RTVEC;        /* Don't allocate an empty rtvec...    */
  179.  
  180.   vector = (rtx *) alloca (n * sizeof (rtx));
  181.   for (i = 0; i < n; i++)
  182.     vector[i] = va_ar to the most significant part.  */
  183.  
  184. rtx
  185. gen_highpart (mode, x)
  186.      enum machine_mode mode;
  187.      register rtx x;
  188. {
  189.   if (GET_CODE (x) == MEM)
  190.     {
  191.       register int offset = 0;
  192. #ifndef WORDS_BIG_ENDIAN
  193.       offset = (max (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD)
  194.         - max (GET_MODE_SIZE (mode), UNITS_PER_WORD));
  195. #endif
  196. #ifndef BYTES_BIG_ENDIAN
  197.       if (GET_MODE_SIZE (mode) < UNITS_PER_WORD)
  198.     offset -= (GET_MODE_SIZE (mode)
  199.            - min (UNITS_PER_WORD,
  200.               GET_MODE_SIZE (GET_MODE (x))));
  201. #endif
  202.       return change_address (x, mode, plus_constant (XEXP (x, 0), offset));
  203.     }
  204.   else if (GET_CODE (x) == REG)
  205.     {
  206. #ifndef WORDS_BIG_ENDIAN
  207.       if (GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD)
  208.     {
  209.       return gen_rtx (SUBREG, mode, x,
  210.               ((GET_MODE_SIZE (GET_MODE (x))
  211.                 - max (GET_MODE_SIZE (mode), UNITS_PER_WORD))
  212.                / UNITS_PER_WORD));
  213.     }
  214. #endif
  215.       return gen_rtx (SUBREG, mode, x, 0);
  216.     }
  217.   else
  218.     abort ();
  219. }
  220.  
  221. /* Return 1 iff X, assumed to be a SUBREG,
  222.    refers to the least significant part of its containing reg.
  223.    If X is not a SUBREG, always return 1 (it is its own low part!).  */
  224.  
  225. int
  226. subreg_lowpart_p (x)
  227.      rtx x;
  228. {
  229.   if (GET_CODE (x) != SUBREG)
  230.     return 1;
  231. #ifdef WORDS_BIG_ENDIAN
  232.   if (GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD)
  233.     {
  234.       register enum machine_mode mode = GET_MODE (SUBREG_REG (x));
  235.       return (SUBREG_WORD (x)
  236.           == ((GET_MODE_SIZE (GET_MODE (x))
  237.            - max (GET_MODE_SIZE (mode), UNITS_PER_WORD))
  238.           / UNITS_PER_WORD));
  239.     }
  240. #endif 
  241.   return SUBREG_WORD (x) == 0;
  242. }
  243.  
  244. /* Return a memory reference like MEMREF, but with its mode changed
  245.    to MODE and its address changed to ADDR.
  246.    (VOIDmode means don't change the mode.
  247.    NULL for ADDR means don't change the address.)  */
  248.  
  249. rtx
  250. change_address (memref, mode, addr)
  251.      rtx memref;
  252.      enum machine_mode mode;
  253.      rtx addr;
  254. {
  255.   rtx new;
  256.  
  257.   if (GET_CODE (memref) != MEM)
  258.     abort ();
  259.   if (mode == VOIDmode)
  260.     mode = GET_MODE (memref);
  261.   if (addr == 0)
  262.     addr = XEXP (memref, 0);
  263.  
  264.   new = gen_rtx (MEM, mode, memory_address (mode, addr));
  265.   MEM_VOLATILE_P (new) = MEM_VOLATILE_P (memref);
  266.   RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (memref);
  267.   MEM_IN_STRUCT_P (new) = MEM_IN_STRUCT_P (memref);
  268.   return new;
  269. }
  270.  
  271. /* Return a newly created CODE_LABEL rtx with a unique label number.  */
  272.  
  273. rtx
  274. gen_label_rtx ()
  275. {
  276.   register rtx label = gen_rtx (CODE_LABEL, VOIDmode, 0, 0, 0, label_num++);
  277.   LABEL_NUSES (label) = 0;
  278.   return label;
  279. }
  280.  
  281. /* For procedure integration.  */
  282.  
  283. /* Return a newly created INLINE_HEADER rtx.  Should allocate this
  284.    from a permanent obstack when the opportunity arises.  */
  285.  
  286. rtx
  287. gen_inline_header_rtx (insn, last_insn,
  288.                first_labelno, last_labelno,
  289.                max_parm_regnum, max_regnum, args_size,
  290.                stack_slots)
  291.      rtx insn, last_insn;
  292.      int first_labelno, last_labelno, max_parm_regnum, max_regnum, args_size;
  293.      rtx stack_slots;
  294. {
  295.   rtx header = gen_rtx (INLINE_HEADER, VOIDmode,
  296.             cur_insn_uid++, NULL,
  297.             insn, last_insn,
  298.             first_labelno, last_labelno,
  299.             max_parm_regnum, max_regnum, args_size, stack_slots);
  300.   return header;
  301. }
  302.  
  303. /* Install new pointers to the first and last insns in the chain.
  304.    Used for an inline-procedure after copying the insn chain.  */
  305.  
  306. void
  307. set_new_first_and_last_insn (first, last)
  308.      rtx first, last;
  309. {
  310.   first_insn = first;
  311.   last_insn = last;
  312. }
  313.  
  314. /* Go through all the RTL insn bodies and copy any invalid shared structure.
  315.    It does not work to do this twice, because the mark bits set here
  316.    are not cleared afterwards.  */
  317.  
  318. static int unshare_copies = 0;    /* Count rtx's that were copied.  */
  319.  
  320. static rtx copy_rtx_if_shared ();
  321.  
  322. void
  323. unshare_all_rtl (insn)
  324.      register rtx insn;
  325. {
  326.   extern rtx stack_slot_list;
  327.  
  328.   for (; insn; insn = NEXT_INSN (insn))
  329.     if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
  330.     || GET_CODE (insn) == CALL_INSN)
  331.       {
  332.     PATTERN (insn) = copy_rtx_if_shared (PATTERN (insn));
  333.     REG_NOTES (insn) = copy_rtx_if_shared (REG_NOTES (insn));
  334.     LOG_LINKS (insn) = copy_rtx_if_shared (LOG_LINKS (insn));
  335.       }
  336.  
  337.   /* Make sure the addresses of stack slots are not shared
  338.      with anything in the insn chain.  That could happen if
  339.      the stack slot is referenced only by its address.  */
  340.   copy_rtx_if_shared (stack_slot_list);
  341. }
  342.  
  343. /* Mark ORIG as in use, and return a copy of it if it was already in use.
  344.    Recursively does the same for subexpressions.  */
  345.  
  346. static rtx
  347. copy_rtx_if_shared (orig)
  348.      rtx orig;
  349. {
  350.   register rtx x = orig;
  351.   register int i;
  352.   register enum rtx_code code;
  353.   register char *format_ptr;
  354.   int copied = 0;
  355.  
  356.   if (x == 0)
  357.     return 0;
  358.  
  359.   code = GET_CODE (x);
  360.  
  361.   /* These types may be freely shared.  */
  362.  
  363.   switch (code)
  364.     {
  365.     case REG:
  366.     case QUEUED:
  367.     case CONST_INT:
  368.     case CONST_DOUBLE:
  369.     case SYMBOL_REF:
  370.     case CODE_LABEL:
  371.     case PC:
  372.     case CC0:
  373.       return x;
  374.  
  375.     case INSN:
  376.     case JUMP_INSN:
  377.     case CALL_INSN:
  378.     case NOTE:
  379.     case LABEL_REF:
  380.     case BARRIER:
  381.       /* The chain of insns is not being copied.  */
  382.       return x;
  383.  
  384.     case MEM:
  385.       /* A MEM is allowed to be shared if its address is constant
  386.      or is a constant plus one of the special registers.  */
  387.       if (CONSTANT_ADDRESS_P (XEXP (x, 0)))
  388.     return x;
  389.       if (GET_CODE (XEXP (x, 0)) == PLUS
  390.       && (XEXP (XEXP (x, 0), 0) == frame_pointer_rtx
  391.           || XEXP (XEXP (x, 0), 0) == arg_pointer_rtx)
  392.       && CONSTANT_ADDRESS_P (XEXP (XEXP (x, 0), 1)))
  393.     {
  394.       /* This MEM can appear in more than one place,
  395.          but its address better not be shared with anything else.  */
  396.       if (! x->used)
  397.         XEXP (x, 0) = copy_rtx_if_shared (XEXP (x, 0));
  398.       x->used = 1;
  399.       return x;
  400.     }
  401.       if (XEXP (x, 0) == frame_pointer_rtx
  402.       || XEXP (x, 0) == arg_pointer_rtx)
  403.     return x;
  404.     }
  405.  
  406.   /* This rtx may not be shared.  If it has already been seen,
  407.      replace it with a copy of itself.  */
  408.  
  409.   if (x->used)
  410.     {
  411.       register rtx copy;
  412.  
  413.       unshare_copies++;
  414.  
  415.       copy = rtx_alloc (code);
  416.       bcopy (x, copy, (sizeof (*copy) - sizeof (copy->fld)
  417.                + sizeof (copy->fld[0]) * GET_RTX_LENGTH (code)));
  418.       x = copy;
  419.       copied = 1;
  420.     }
  421.   x->used = 1;
  422.  
  423.   /* Now scan the subexpressions recursively.
  424.      We can store any replaced subexpressions directly into X
  425.      since we know X is not shared!  Any vectors in X
  426.      must be copied if X was copied.  */
  427.  
  428.   format_ptr = GET_RTX_FORMAT (code);
  429.  
  430.   for (i = 0; i < GET_RTX_LENGTH (code); i++)
  431.     {
  432.       switch (*format_ptr++)
  433.     {
  434.     case 'e':
  435.       XEXP (x, i) = copy_rtx_if_shared (XEXP (x, i));
  436.       break;
  437.  
  438.     case 'E':
  439.       if (XVEC (x, i) != NULL)
  440.         {
  441.           register int j;
  442.  
  443.           if (copied)
  444.         XVEC (x, i) = gen_rtvec_v (XVECLEN (x, i), &XVECEXP (x, i, 0));
  445.           for (j = 0; j < XVECLEN (x, i); j++)
  446.         XVECEXP (x, i, j)
  447.           = copy_rtx_if_shared (XVECEXP (x, i, j));
  448.         }
  449.       break;
  450.     }
  451.     }
  452.   return x;
  453. }
  454.  
  455. /* Copy X if necessary so that it won't be altered by changes in OTHER.
  456.    Return X or the rtx for the pseudo reg the value of X was copied into.
  457.    OTHER must be valid as a SET_DEST.  */
  458.  
  459. rtx
  460. make_safe_from (x, other)
  461.      rtx x, other;
  462. {
  463.   while (1)
  464.     switch (GET_CODE (other))
  465.       {
  466.       case SUBREG:
  467.     other = SUBREG_REG (other);
  468.     break;
  469.       case STRICT_LOW_PART:
  470.       case SIGN_EXTEND:
  471.       case ZERO_EXTEND:
  472.     other = XEXP (other, 0);
  473.     break;
  474.       default:
  475.     goto done;
  476.       }
  477.  done:
  478.   if ((GET_CODE (other) == MEM
  479.        && ! CONSTANT_P (x)
  480.        && GET_CODE (x) != CONST_DOUBLE
  481.        && GET_CODE (x) != REG
  482.        && GET_CODE (x) != SUBREG)
  483.       || (GET_CODE (other) == REG
  484.       && (REGNO (other) < FIRST_PSEUDO_REGISTER
  485.           || reg_mentioned_p (other, x))))
  486.     {
  487.       rtx temp = gen_reg_rtx (GET_MODE (x));
  488.       emit_move_insn (temp, x);
  489.       return temp;
  490.     }
  491.   return x;
  492. }
  493.  
  494. /* Emission of insns (adding them to the doubly-linked list).  */
  495.  
  496. /* Return the first insn of the current sequence or current function.  */
  497.  
  498. rtx
  499. get_insns ()
  500. {
  501.   return first_insn;
  502. }
  503.  
  504. /* Return the last insn emitted in current sequence or current function.  */
  505.  
  506. rtx
  507. get_last_insn ()
  508. {
  509.   return last_insn;
  510. }
  511.  
  512. /* Specify a new insn as the last in the chain.  */
  513.  
  514. void
  515. set_last_insn (insn)
  516.      rtx insn;
  517. {
  518.   if (NEXT_INSN (insn) != 0)
  519.     abort ();
  520.   last_insn = insn;
  521. }
  522.  
  523. /* Return a number larger than any instruction's uid in this function.  */
  524.  
  525. int
  526. get_max_uid ()
  527. {
  528.   return cur_insn_uid;
  529. }
  530.  
  531. rtx
  532. next_insn (insn)
  533.      rtx insn;
  534. {
  535.   if (insn) return NEXT_INSN (insn);
  536.   return 0;
  537. }
  538.  
  539. rtx
  540. previous_insn (insn)
  541.      rtx insn;
  542. {
  543.   if (insn) return PREV_INSN (insn);
  544.   return 0;
  545. }
  546.  
  547. /* Make and return an INSN rtx, initializing all its slots.
  548.    Store PATTERN in the pattern slots.
  549.    PAT_FORMALS is an idea that never really went anywhere.  */
  550.  
  551. static rtx
  552. make_insn_raw (pattern, pat_formals)
  553.      rtx pattern;
  554.      rtvec pat_formals;
  555. {
  556.   register rtx insn;
  557.  
  558.   insn = rtx_alloc(INSN);
  559.   INSN_UID(insn) = cur_insn_uid++;
  560.  
  561.   PATTERN (insn) = pattern;
  562.   INSN_CODE (insn) = -1;
  563.   LOG_LINKS(insn) = NULL;
  564.   REG_NOTES(insn) = NULL;
  565.  
  566.   return insn;
  567. }
  568.  
  569. /* Like `make_insn' but make a JUMP_INSN instead of an insn.  */
  570.  
  571. static rtx
  572. make_jump_insn_raw (pattern, pat_formals)
  573.      rtx pattern;
  574.      rtvec pat_formals;
  575. {
  576.   register rtx insn;
  577.  
  578.   insn = rtx_alloc(JUMP_INSN);
  579.   INSN_UID(insn) = cur_insn_uid++;
  580.  
  581.   PATTERN (insn) = pattern;
  582.   INSN_CODE (insn) = -1;
  583.   LOG_LINKS(insn) = NULL;
  584.   REG_NOTES(insn) = NULL;
  585.   JUMP_LABEL(insn) = NULL;
  586.  
  587.   return insn;
  588. }
  589.  
  590. /* Add INSN to the end of the doubly-linked list.
  591.    INSN may be an INSN, JUMP_INSN, CALL_INSN, CODE_LABEL, BARRIER or NOTE.  */
  592.  
  593. static void
  594. add_insn (insn)
  595.      register rtx insn;
  596. {
  597.   PREV_INSN (insn) = last_insn;
  598.   NEXT_INSN (insn) = 0;
  599.  
  600.   if (NULL != last_insn)
  601.     NEXT_INSN (last_insn) = insn;
  602.  
  603.   if (NULL == first_insn)
  604.     first_insn = insn;
  605.  
  606.   last_insn = insn;
  607. }
  608.  
  609. /* Add INSN, an rtx of code INSN, into the doubly-linked list
  610.    after insn AFTER.  */
  611.  
  612. static void
  613. add_insn_after (insn, after)
  614.      rtx insn, after;
  615. {
  616.   NEXT_INSN (insn) = NEXT_INSN (after);
  617.   PREV_INSN (insn) = after;
  618.  
  619.   if (NEXT_INSN (insn))
  620.     PREV_INSN (NEXT_INSN (insn)) = insn;
  621.   else if (last_insn == after)
  622.     last_insn = insn;
  623.   else
  624.     {
  625.       rtx stack = sequence_stack;
  626.       /* Scan all pending sequences too.  */
  627.       for (; stack; stack = XEXP (XEXP (stack, 1), 1))
  628.     if (after == XEXP (XEXP (stack, 1), 0))
  629.       XEXP (XEXP (stack, 1), 0) = insn;
  630.     }
  631.  
  632.   NEXT_INSN (after) = insn;
  633. }
  634.  
  635. /* Delete all insns made since FROM.
  636.    FROM becomes the new last instruction.  */
  637.  
  638. void
  639. delete_insns_since (from)
  640.      rtx from;
  641. {
  642.   if (from == 0)
  643.     first_insn = 0;
  644.   else
  645.     NEXT_INSN (from) = 0;
  646.   last_insn = from;
  647. }
  648.  
  649. /* Move a consecutive bunch of insns to a different place in the chain.
  650.    The insns to be moved are those between FROM and TO.
  651.    They are moved to a new position after the insn AFTER.  */
  652.  
  653. void
  654. reorder_insns (from, to, after)
  655.      rtx from, to, after;
  656. {
  657.   /* Splice this bunch out of where it is now.  */
  658.   if (PREV_INSN (from))
  659.     NEXT_INSN (PREV_INSN (from)) = NEXT_INSN (to);
  660.   if (NEXT_INSN (to))
  661.     PREV_INSN (NEXT_INSN (to)) = PREV_INSN (from);
  662.   if (last_insn == to)
  663.     last_insn = PREV_INSN (from);
  664.   if (first_insn == from)
  665.     first_insn = NEXT_INSN (to);
  666.  
  667.   /* Make the new neighbors point to it and it to them.  */
  668.   if (NEXT_INSN (after))
  669.     {
  670.       PREV_INSN (NEXT_INSN (after)) = to;
  671.       NEXT_INSN (to) = NEXT_INSN (after);
  672.     }
  673.   PREV_INSN (from) = after;
  674.   NEXT_INSN (after) = from;
  675.   if (after == last_insn)
  676.     last_insn = to;
  677. }
  678.  
  679. /* Emit an insn of given code and pattern
  680.    at a specified place within the doubly-linked list.  */
  681.  
  682. /* Make an instruction with body PATTERN
  683.    and output it before the instruction BEFORE.  */
  684.  
  685. rtx
  686. emit_insn_before (pattern, before)
  687.      register rtx pattern, before;
  688. {
  689.   register rtx insn;
  690.  
  691.   if (GET_CODE (pattern) == SEQUENCE)
  692.     {
  693.       register int i;
  694.       /* For an empty sequence, emit nothing.  */
  695.       if (XVEC (pattern, 0))
  696.     for (i = 0; i < XVECLEN (pattern, 0); i++)
  697.       add_insn_after (XVECEXP (pattern, 0, i), PREV_INSN (before));
  698.       return PREV_INSN (before);
  699.     }
  700.  
  701.   insn = make_insn_raw (pattern, 0);
  702.  
  703.   PREV_INSN (insn) = PREV_INSN (before);
  704.   NEXT_INSN (insn) = before;
  705.  
  706.   if (PREV_INSN (insn))
  707.     NEXT_INSN (PREV_INSN (insn)) = insn;
  708.   else
  709.     first_insn = insn;
  710.   PREV_INSN (before) = insn;
  711.  
  712.   rk_reg_pointer (XEXP (x, 0));
  713.       restore_reg_data_1 (XEXP (x, 0));
  714.       return;
  715.     }
  716.  
  717.   /* Now scan the subexpressions recursively.  */
  718.  
  719.   format_ptr = GET_RTX_FORMAT (code);
  720.  
  721.   for (i = 0; i < GET_RTX_LENGTH (code); i++)
  722.     {
  723.       switch (*format_ptr++)
  724.     {
  725.     case 'e':
  726.       restore_reg_data_1 (XEXP (x, i));
  727.       break;
  728.  
  729.     case 'E':
  730.       if (XVEC (x, i) != NULL)
  731.         {
  732.           register int j;
  733.  
  734.           for (j = 0; j < XVECLEN (x, i); j++)
  735.         restore_reg_data_1 (XVECEXP (x, i, j));
  736.         }
  737.       break;
  738.     }
  739.     }
  740. }
  741.  
  742. /* Initialize data structures and variables in this file
  743.    before generating rtl for each function.
  744.    WRITE_SYMBOLS is nonzero if any kind of debugging info
  745.    is to be generated.  */
  746.  
  747. void
  748. init_emit (write_symbols)
  749.      int write_symbols;
  750. {
  751.   first_insn = NULL;
  752.   last_insn = NULL;
  753.   sequence_stack = NULL;
  754.   cur_insn_uid = 1;
  755.   reg_rtx_no = FIRST_PSEUDO_REGISTER;
  756.   last_linenum = 0;
  757.   last_filename = 0;
  758.   first_label_num = label_num;
  759.  
  760.   no_line_numbers = ! write_symbols;
  761.   
  762.   /* Init the tables that describe all the pseudo regs.  */
  763.  
  764.   regno_pointer_flag_length = FIRST_PSEUDO_REGISTER + 100;
  765.  
  766.   regno_pointer_flag 
  767.     = (char *) oballoc (regno_pointer_flag_length);
  768.   bzero (regno_pointer_flag, regno_pointer_flag_length);
  769.  
  770.   regno_reg_rtx 
  771.     = (rtx *) oballoc (regno_pointer_flag_length * sizeof (rtx));
  772.   bzero (regno_reg_rtx, regno_pointer_flag_length * sizeof (rtx));
  773. }
  774.  
  775. /* Create some permanent unique rtl objects shared between all functions.  */
  776.  
  777. void
  778. init_emit_once ()
  779. {
  780.   /* Create the unique rtx's for certain rtx codes and operand values.  */
  781.  
  782.   pc_rtx = gen_rtx (PC, VOIDmode);
  783.   cc0_rtx = gen_rtx (CC0, VOIDmode);
  784.  
  785.   /* Don't use gen_rtx here since gen_rtx in this case
  786.      tries to use these variables.  */
  787.   const0_rtx = rtx_alloc (CONST_INT);
  788.   INTVAL (const0_rtx) = 0;
  789.   const1_rtx = rtx_alloc (CONST_INT);
  790.   INTVAL (const1_rtx) = 1;
  791.  
  792.   fconst0_rtx = rtx_alloc (CONST_DOUBLE);
  793.   dconst0_rtx = rtx_alloc (CONST_DOUBLE);
  794. #ifdef APPLE_C
  795.   /* Note that CONST_DOUBLE is misnamed, really means CONST_FLOAT, any size */
  796.   ldconst0_rtx = rtx_alloc (CONST_DOUBLE);
  797. #endif /* APPLE_C */
  798.   {
  799.     union real_extract u;
  800. #ifdef REAL_IS_NOT_DOUBLE
  801.     bzero (&u, sizeof u);
  802.     u.d = REAL_VALUE_ATOF ("0");
  803. #else
  804.     u.d = 0;
  805. #endif
  806.  
  807.     bcopy (&u, &CONST_DOUBLE_LOW (fconst0_rtx), sizeof u);
  808.     CONST_DOUBLE_MEM (fconst0_rtx) = cc0_rtx;
  809.     PUT_MODE (fconst0_rtx, SFmode);
  810.  
  811.     bcopy (&u, &CONST_DOUBLE_LOW (dconst0_rtx), sizeof u);
  812.     CONST_DOUBLE_MEM (dconst0_rtx) = cc0_rtx;
  813.     PUT_MODE (dconst0_rtx, DFmode);
  814. #ifdef APPLE_C
  815.     /* Make a long double zero rtx */
  816.     bcopy (&u, &CONST_DOUBLE_LOW (ldconst0_rtx), sizeof u);
  817.     CONST_DOUBLE_MEM (ldconst0_rtx) = cc0_rtx;
  818.     PUT_MODE (ldconst0_rtx, XFmode);
  819. #endif /* APPLE_C */
  820.   }
  821.  
  822.   stack_pointer_rtx = gen_rtx (REG, Pmode, STACK_POINTER_REGNUM);
  823.   frame_pointer_rtx = gen_rtx (REG, Pmode, FRAME_POINTER_REGNUM);
  824. #ifdef STRUCT_VALUE
  825.   struct_value_rtx = STRUCT_VALUE;
  826. #else
  827.   struct_value_rtx = gen_rtx (REG, Pmode, STRUCT_VALUE_REGNUM);
  828. #endif
  829.  
  830. #ifdef STRUCT_VALUE_INCOMING
  831.   struct_value_incoming_rtx = STRUCT_VALUE_INCOMING;
  832. #else
  833. #ifdef STRUCT_VALUE_INCOMING_REGNUM
  834.   struct_value_incoming_rtx
  835.     = gen_rtx (REG, Pmode, STRUCT_VALUE_INCOMING_REGNUM);
  836. #else
  837.   struct_value_incoming_rtx = struct_value_rtx;
  838. #endif
  839. #endif
  840.  
  841.   static_chain_rtx = gen_rtx (REG, Pmode, STATIC_CHAIN_REGNUM);
  842.  
  843. #ifdef STATIC_CHAIN_INCOMING_REGNUM
  844.   if (STATIC_CHAIN_INCOMING_REGNUM != STATIC_CHAIN_REGNUM)
  845.     static_chain_incoming_rtx = gen_rtx (REG, Pmode, STATIC_CHAIN_INCOMING_REGNUM);
  846.   else
  847. #endif
  848.     static_chain_incoming_rtx = static_chain_rtx;
  849.  
  850.   if (FRAME_POINTER_REGNUM == ARG_POINTER_REGNUM)
  851.     arg_pointer_rtx = frame_pointer_rtx;
  852.   else
  853.     arg_pointer_rtx = gen_rtx (REG, Pmode, ARG_POINTER_REGNUM);
  854. }
  855.  
  856.  
  857. init_emit2()
  858. {
  859. #define INIT_EMIT
  860. #include "init.c"
  861. }
  862.