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 / regclass.c < prev    next >
C/C++ Source or Header  |  1994-02-06  |  49KB  |  1,688 lines

  1. /* Compute register class preferences for pseudo-registers.
  2.    Copyright (C) 1987, 1988, 1991, 1992 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. /* This file contains two passes of the compiler: reg_scan and reg_class.
  22.    It also defines some tables of information about the hardware registers
  23.    and a function init_reg_sets to initialize the tables.  */
  24.  
  25. #include "config.h"
  26. #include "rtl.h"
  27. #include "hard-reg-set.h"
  28. #include "flags.h"
  29. #include "basic-block.h"
  30. #include "regs.h"
  31. #include "insn-config.h"
  32. #include "recog.h"
  33. #include "reload.h"
  34. #include "real.h"
  35.  
  36. #ifndef REGISTER_MOVE_COST
  37. #define REGISTER_MOVE_COST(x, y) 2
  38. #endif
  39.  
  40. #ifndef MEMORY_MOVE_COST
  41. #define MEMORY_MOVE_COST(x) 4
  42. #endif
  43.  
  44. /* If we have auto-increment or auto-decrement and we can have secondary
  45.    reloads, we are not allowed to use classes requiring secondary
  46.    reloads for psuedos auto-incremented since reload can't handle it.  */
  47.  
  48. #ifdef AUTO_INC_DEC
  49. #if defined(SECONDARY_INPUT_RELOAD_CLASS) || defined(SECONDARY_OUTPUT_RELOAD_CLASS)
  50. #define FORBIDDEN_INC_DEC_CLASSES
  51. #endif
  52. #endif
  53.  
  54. /* Register tables used by many passes.  */
  55.  
  56. /* Indexed by hard register number, contains 1 for registers
  57.    that are fixed use (stack pointer, pc, frame pointer, etc.).
  58.    These are the registers that cannot be used to allocate
  59.    a pseudo reg whose life does not cross calls.  */
  60.  
  61. char fixed_regs[FIRST_PSEUDO_REGISTER];
  62.  
  63. /* Same info as a HARD_REG_SET.  */
  64.  
  65. HARD_REG_SET fixed_reg_set;
  66.  
  67. /* Data for initializing the above.  */
  68.  
  69. static char initial_fixed_regs[] = FIXED_REGISTERS;
  70.  
  71. /* Indexed by hard register number, contains 1 for registers
  72.    that are fixed use or are clobbered by function calls.
  73.    These are the registers that cannot be used to allocate
  74.    a pseudo reg whose life crosses calls.  */
  75.  
  76. char call_used_regs[FIRST_PSEUDO_REGISTER];
  77.  
  78. /* Same info as a HARD_REG_SET.  */
  79.  
  80. HARD_REG_SET call_used_reg_set;
  81.  
  82. /* Data for initializing the above.  */
  83.  
  84. static char initial_call_used_regs[] = CALL_USED_REGISTERS;
  85.   
  86. /* Indexed by hard register number, contains 1 for registers that are
  87.    fixed use -- i.e. in fixed_regs -- or a function value return register
  88.    or STRUCT_VALUE_REGNUM or STATIC_CHAIN_REGNUM.  These are the
  89.    registers that cannot hold quantities across calls even if we are
  90.    willing to save and restore them.  */
  91.  
  92. char call_fixed_regs[FIRST_PSEUDO_REGISTER];
  93.  
  94. /* The same info as a HARD_REG_SET.  */
  95.  
  96. HARD_REG_SET call_fixed_reg_set;
  97.  
  98. /* Number of non-fixed registers.  */
  99.  
  100. int n_non_fixed_regs;
  101.  
  102. /* Indexed by hard register number, contains 1 for registers
  103.    that are being used for global register decls.
  104.    These must be exempt from ordinary flow analysis
  105.    and are also considered fixed.  */
  106.  
  107. char global_regs[FIRST_PSEUDO_REGISTER];
  108.   
  109. /* Table of register numbers in the order in which to try to use them.  */
  110. #ifdef REG_ALLOC_ORDER
  111. int reg_alloc_order[FIRST_PSEUDO_REGISTER] = REG_ALLOC_ORDER;
  112. #endif
  113.  
  114. /* For each reg class, a HARD_REG_SET saying which registers are in it.  */
  115.  
  116. HARD_REG_SET reg_class_contents[N_REG_CLASSES];
  117.  
  118. /* The same information, but as an array of ints.  We copy from these
  119.    ints to the table above.  This is done so that the tm.h files do
  120.    not have to be aware of the wordsize for machines with <= 64 regs.  */
  121.  
  122. #define N_REG_INTS  \
  123.   ((FIRST_PSEUDO_REGISTER + (HOST_BITS_PER_INT - 1)) / HOST_BITS_PER_INT)
  124.  
  125. static int int_reg_class_contents[N_REG_CLASSES][N_REG_INTS] 
  126.   = REG_CLASS_CONTENTS;
  127.  
  128. /* For each reg class, number of regs it contains.  */
  129.  
  130. int reg_class_size[N_REG_CLASSES];
  131.  
  132. /* For each reg class, table listing all the containing classes.  */
  133.  
  134. enum reg_class reg_class_superclasses[N_REG_CLASSES][N_REG_CLASSES];
  135.  
  136. /* For each reg class, table listing all the classes contained in it.  */
  137.  
  138. enum reg_class reg_class_subclasses[N_REG_CLASSES][N_REG_CLASSES];
  139.  
  140. /* For each pair of reg classes,
  141.    a largest reg class contained in their union.  */
  142.  
  143. enum reg_class reg_class_subunion[N_REG_CLASSES][N_REG_CLASSES];
  144.  
  145. /* For each pair of reg classes,
  146.    the smallest reg class containing their union.  */
  147.  
  148. enum reg_class reg_class_superunion[N_REG_CLASSES][N_REG_CLASSES];
  149.  
  150. /* Array containing all of the register names */
  151.  
  152. char *reg_names[] = REGISTER_NAMES;
  153.  
  154. /* Indexed by n, gives number of times (REG n) is set or clobbered.
  155.    This information remains valid for the rest of the compilation
  156.    of the current function; it is used to control register allocation.
  157.  
  158.    This information applies to both hard registers and pseudo registers,
  159.    unlike much of the information above.  */
  160.  
  161. short *reg_n_sets;
  162.  
  163. /* Maximum cost of moving from a register in one class to a register in
  164.    another class.  Based on REGISTER_MOVE_COST.  */
  165.  
  166. static int move_cost[N_REG_CLASSES][N_REG_CLASSES];
  167.  
  168. /* Similar, but here we don't have to move if the first index is a subset
  169.    of the second so in that case the cost is zero.  */
  170.  
  171. static int may_move_cost[N_REG_CLASSES][N_REG_CLASSES];
  172.  
  173. #ifdef FORBIDDEN_INC_DEC_CLASSES
  174.  
  175. /* These are the classes that regs which are auto-incremented or decremented
  176.    cannot be put in.  */
  177.  
  178. static int forbidden_inc_dec_class[N_REG_CLASSES];
  179.  
  180. /* Indexed by n, is non-zero if (REG n) is used in an auto-inc or auto-dec
  181.    context.  */
  182.  
  183. static char *in_inc_dec;
  184.  
  185. #endif /* FORBIDDEN_INC_DEC_CLASSES */
  186.  
  187. /* Function called only once to initialize the above data on reg usage.
  188.    Once this is done, various switches may override.  */
  189.  
  190. void
  191. init_reg_sets ()
  192. {
  193.   register int i, j;
  194.  
  195.   /* First copy the register information from the initial int form into
  196.      the regsets.  */
  197.  
  198.   for (i = 0; i < N_REG_CLASSES; i++)
  199.     {
  200.       CLEAR_HARD_REG_SET (reg_class_contents[i]);
  201.  
  202.       for (j = 0; j < FIRST_PSEUDO_REGISTER; j++)
  203.     if (int_reg_class_contents[i][j / HOST_BITS_PER_INT]
  204.         & (1 << (j % HOST_BITS_PER_INT)))
  205.       SET_HARD_REG_BIT (reg_class_contents[i], j);
  206.     }
  207.  
  208.   bcopy (initial_fixed_regs, fixed_regs, sizeof fixed_regs);
  209.   bcopy (initial_call_used_regs, call_used_regs, sizeof call_used_regs);
  210.   bzero (global_regs, sizeof global_regs);
  211.  
  212.   /* Compute number of hard regs in each class.  */
  213.  
  214.   bzero (reg_class_size, sizeof reg_class_size);
  215.   for (i = 0; i < N_REG_CLASSES; i++)
  216.     for (j = 0; j < FIRST_PSEUDO_REGISTER; j++)
  217.       if (TEST_HARD_REG_BIT (reg_class_contents[i], j))
  218.     reg_class_size[i]++;
  219.  
  220.   /* Initialize the table of subunions.
  221.      reg_class_subunion[I][J] gets the largest-numbered reg-class
  222.      that is contained in the union of classes I and J.  */
  223.  
  224.   for (i = 0; i < N_REG_CLASSES; i++)
  225.     {
  226.       for (j = 0; j < N_REG_CLASSES; j++)
  227.     {
  228. #ifdef HARD_REG_SET
  229.       register        /* Declare it register if it's a scalar.  */
  230. #endif
  231.         HARD_REG_SET c;
  232.       register int k;
  233.  
  234.       COPY_HARD_REG_SET (c, reg_class_contents[i]);
  235.       IOR_HARD_REG_SET (c, reg_class_contents[j]);
  236.       for (k = 0; k < N_REG_CLASSES; k++)
  237.         {
  238.           GO_IF_HARD_REG_SUBSET (reg_class_contents[k], c,
  239.                      subclass1);
  240.           continue;
  241.  
  242.         subclass1:
  243.           /* keep the largest subclass */        /* SPEE 900308 */
  244.           GO_IF_HARD_REG_SUBSET (reg_class_contents[k],
  245.                      reg_class_contents[(int) reg_class_subunion[i][j]],
  246.                      subclass2);
  247.           reg_class_subunion[i][j] = (enum reg_class) k;
  248.         subclass2:
  249.           ;
  250.         }
  251.     }
  252.     }
  253.  
  254.   /* Initialize the table of superunions.
  255.      reg_class_superunion[I][J] gets the smallest-numbered reg-class
  256.      containing the union of classes I and J.  */
  257.  
  258.   for (i = 0; i < N_REG_CLASSES; i++)
  259.     {
  260.       for (j = 0; j < N_REG_CLASSES; j++)
  261.     {
  262. #ifdef HARD_REG_SET
  263.       register        /* Declare it register if it's a scalar.  */
  264.