home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 7 / FreshFishVol7.bin / bbs / gnu / gcc-2.3.3-src.lha / GNU / src / amiga / gcc-2.3.3 / rtl.c < prev    next >
C/C++ Source or Header  |  1994-02-06  |  21KB  |  838 lines

  1. /* Allocate and read RTL for GNU C Compiler.
  2.    Copyright (C) 1987, 1988, 1991 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. #include "config.h"
  22. #include <ctype.h>
  23. #include <stdio.h>
  24. #include "rtl.h"
  25.  
  26. #include "obstack.h"
  27. #define    obstack_chunk_alloc    xmalloc
  28. #define    obstack_chunk_free    free
  29.  
  30. /* Obstack used for allocating RTL objects.
  31.    Between functions, this is the permanent_obstack.
  32.    While parsing and expanding a function, this is maybepermanent_obstack
  33.    so we can save it if it is an inline function.
  34.    During optimization and output, this is function_obstack.  */
  35.  
  36. extern struct obstack *rtl_obstack;
  37.  
  38. #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
  39. extern long atol();
  40. #endif
  41.  
  42. /* Indexed by rtx code, gives number of operands for an rtx with that code.
  43.    Does NOT include rtx header data (code and links).
  44.    This array is initialized in init_rtl.  */
  45.  
  46. int rtx_length[NUM_RTX_CODE + 1];
  47.  
  48. /* Indexed by rtx code, gives the name of that kind of rtx, as a C string.  */
  49.  
  50. #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS)   NAME ,
  51.  
  52. char * const rtx_name[] = {
  53. #include "rtl.def"        /* rtl expressions are documented here */
  54. };
  55.  
  56. #undef DEF_RTL_EXPR
  57.  
  58. /* Indexed by machine mode, gives the name of that machine mode.
  59.    This name does not include the letters "mode".  */
  60.  
  61. #define DEF_MACHMODE(SYM, NAME, CLASS, SIZE, UNIT, WIDER)  NAME,
  62.  
  63. char * const mode_name[(int) MAX_MACHINE_MODE] = {
  64. #include "machmode.def"
  65.  
  66. #ifdef EXTRA_CC_MODES
  67.   EXTRA_CC_NAMES
  68. #endif
  69.  
  70. };
  71.  
  72. #undef DEF_MACHMODE
  73.  
  74. /* Indexed by machine mode, gives the length of the mode, in bytes.
  75.    GET_MODE_CLASS uses this.  */
  76.  
  77. #define DEF_MACHMODE(SYM, NAME, CLASS, SIZE, UNIT, WIDER)  CLASS,
  78.  
  79. const enum mode_class mode_class[(int) MAX_MACHINE_MODE] = {
  80. #include "machmode.def"
  81. };
  82.  
  83. #undef DEF_MACHMODE
  84.  
  85. /* Indexed by machine mode, gives the length of the mode, in bytes.
  86.    GET_MODE_SIZE uses this.  */
  87.  
  88. #define DEF_MACHMODE(SYM, NAME, CLASS, SIZE, UNIT, WIDER)  SIZE,
  89.  
  90. const int mode_size[(int) MAX_MACHINE_MODE] = {
  91. #include "machmode.def"
  92. };
  93.  
  94. #undef DEF_MACHMODE
  95.  
  96. /* Indexed by machine mode, gives the length of the mode's subunit.
  97.    GET_MODE_UNIT_SIZE uses this.  */
  98.  
  99. #define DEF_MACHMODE(SYM, NAME, CLASS, SIZE, UNIT, WIDER)  UNIT,
  100.  
  101. const int mode_unit_size[(int) MAX_MACHINE_MODE] = {
  102. #include "machmode.def"        /* machine modes are documented here */
  103. };
  104.  
  105. #undef DEF_MACHMODE
  106.  
  107. /* Indexed by machine mode, gives next wider natural mode
  108.    (QI -> HI -> SI -> DI, etc.)  Widening multiply instructions
  109.    use this.  */
  110.  
  111. #define DEF_MACHMODE(SYM, NAME, CLASS, SIZE, UNIT, WIDER)  \
  112.   (enum machine_mode) WIDER,
  113.  
  114. const enum machine_mode mode_wider_mode[(int) MAX_MACHINE_MODE] = {
  115. #include "machmode.def"        /* machine modes are documented here */
  116. };
  117.  
  118. #undef DEF_MACHMODE
  119.  
  120. /* Indexed by mode class, gives the narrowest mode for each class.  */
  121.  
  122. enum machine_mode class_narrowest_mode[(int) MAX_MODE_CLASS];
  123.  
  124. /* Commonly used modes.  */
  125.  
  126. enum machine_mode byte_mode;    /* Mode whose width is BITS_PER_UNIT */
  127. enum machine_mode word_mode;    /* Mode whose width is BITS_PER_WORD */
  128.  
  129. /* Indexed by rtx code, gives a sequence of operand-types for
  130.    rtx's of that code.  The sequence is a C string in which
  131.    each character describes one operand.  */
  132.  
  133. char *const rtx_format[] = {
  134.   /* "*" undefined.
  135.          can cause a warning message
  136.      "0" field is unused (or used in a phase-dependent manner)
  137.          prints nothing
  138.      "i" an integer
  139.          prints the integer
  140.      "n" like "i", but prints entries from `note_insn_name'
  141.      "w" an integer of width HOST_BITS_PER_WIDE_INT
  142.          prints the integer
  143.      "s" a pointer to a string
  144.          prints the string
  145.      "S" like "s", but optional:
  146.      the containing rtx may end before this operand
  147.      "e" a pointer to an rtl expression
  148.          prints the expression
  149.      "E" a pointer to a vector that points to a number of rtl expressions
  150.          prints a list of the rtl expressions
  151.      "V" like "E", but optional:
  152.      the containing rtx may end before this operand
  153.      "u" a pointer to another insn
  154.          prints the uid of the insn.  */
  155.  
  156. #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS)   FORMAT ,
  157. #include "rtl.def"        /* rtl expressions are defined here */
  158. #undef DEF_RTL_EXPR
  159. };
  160.  
  161. /* Indexed by rtx code, gives a character representing the "class" of
  162.    that rtx code.  See rtl.def for documentation on the defined classes.  */
  163.  
  164. const char rtx_class[] = {
  165. #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS)   CLASS, 
  166. #include "rtl.def"        /* rtl expressions are defined here */
  167. #undef DEF_RTL_EXPR
  168. };
  169.  
  170. /* Names for kinds of NOTEs and REG_NOTEs.  */
  171.  
  172. char * const note_insn_name[] = 
  173.              { "NOTE_INSN_FUNCTION_BEG", "NOTE_INSN_DELETED",
  174.                "NOTE_INSN_BLOCK_BEG", "NOTE_INSN_BLOCK_END",
  175.                "NOTE_INSN_LOOP_BEG", "NOTE_INSN_LOOP_END",
  176.                "NOTE_INSN_FUNCTION_END", "NOTE_INSN_SETJMP",
  177.                "NOTE_INSN_LOOP_CONT", "NOTE_INSN_LOOP_VTOP",
  178.                "NOTE_INSN_PROLOGUE_END", "NOTE_INSN_EPILOGUE_BEG",
  179.                "NOTE_INSN_DELETED_LABEL"};
  180.  
  181. char * const reg_note_name[] = 
  182.             { "", "REG_DEAD", "REG_INC", "REG_EQUIV", "REG_WAS_0",
  183.               "REG_EQUAL", "REG_RETVAL", "REG_LIBCALL",
  184.               "REG_NONNEG", "REG_NO_CONFLICT", "REG_UNUSED",
  185.               "REG_CC_SETTER", "REG_CC_USER", "REG_LABEL",
  186.               "REG_DEP_ANTI", "REG_DEP_OUTPUT" };
  187.  
  188. /* Allocate an rtx vector of N elements.
  189.    Store the length, and initialize all elements to zero.  */
  190.  
  191. rtvec
  192. rtvec_alloc (n)
  193.      int n;
  194. {
  195.   rtvec rt;
  196.   int i;
  197.  
  198.   rt = (rtvec) obstack_alloc (rtl_obstack,
  199.                   sizeof (struct rtvec_def)
  200.                   + (( n - 1) * sizeof (rtunion)));
  201.  
  202.   /* clear out the vector */
  203.   PUT_NUM_ELEM(rt, n);
  204.   for (i=0; i < n; i++)
  205.     rt->elem[i].rtvec = NULL;    /* @@ not portable due to rtunion */
  206.  
  207.   return rt;
  208. }
  209.  
  210. /* Allocate an rtx of code CODE.  The CODE is stored in the rtx;
  211.    all the rest is initialized to zero.  */
  212.  
  213. rtx
  214. rtx_alloc (code)
  215.   RTX_CODE code;
  216. {
  217.   rtx rt;
  218.   register struct obstack *ob = rtl_obstack;
  219.   register int nelts = GET_RTX_LENGTH (code);
  220.   register int length = sizeof (struct rtx_def)
  221.     + (nelts - 1) * sizeof (rtunion);
  222.  
  223.   /* This function is called more than any other in GCC,
  224.      so we manipulate the obstack directly.
  225.  
  226.      Even though rtx objects are word aligned, we may be sharing an obstack
  227.      with tree nodes, which may have to be double-word aligned.  So align
  228.      our length to the alignment mask in the obstack.  */
  229.  
  230.   length = (length + ob->alignment_mask) & ~ ob->alignment_mask;
  231.  
  232.   if (ob->chunk_limit - ob->next_free < length)
  233.     _obstack_newchunk (ob, length);
  234.   rt = (rtx)ob->object_base;
  235.   ob->next_free += length;
  236.   ob->object_base = ob->next_free;
  237.  
  238.   * (int *) rt = 0;
  239.   PUT_CODE (rt, code);
  240.  
  241.   return rt;
  242. }
  243.  
  244. /* Create a new copy of an rtx.
  245.    Recursively copies the operands of the rtx,
  246.    except for those few rtx codes that are sharable.  */
  247.  
  248. rtx
  249. copy_rtx (orig)
  250.      register rtx orig;
  251. {
  252.   register rtx copy;
  253.   register int i, j;
  254.   register RTX_CODE code;
  255.   register char *format_ptr;
  256.  
  257.   code = GET_CODE (orig);
  258.  
  259.   switch (code)
  260.     {
  261.     case REG:
  262.     case QUEUED:
  263.     case CONST_INT:
  264.     case CONST_DOUBLE:
  265.     case SYMBOL_REF:
  266.     case CODE_LABEL:
  267.     case PC:
  268.     case CC0:
  269.       return orig;
  270.     }
  271.  
  272.   copy = rtx_alloc (code);
  273.   PUT_MODE (copy, GET_MODE (orig));
  274.   copy->in_struct = orig->in_struct;
  275.   copy->volatil = orig->volatil;
  276.   copy->unchanging = orig->unchanging;
  277.   copy->integrated = orig->integrated;
  278.   
  279.   format_ptr = GET_RTX_FORMAT (GET_CODE (copy));
  280.  
  281.   for (i = 0; i < GET_RTX_LENGTH (GET_CODE (copy)); i++)
  282.     {
  283.       switch (*format_ptr++)
  284.     {
  285.     case 'e':
  286.       XEXP (copy, i) = XEXP (ori