home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / program / 321 / compsrc3 / regclass.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-20  |  21.6 KB  |  816 lines

  1. /* Compute register class preferences for pseudo-registers.
  2.    Copyright (C) 1987 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY.  No author or distributor
  8. accepts responsibility to anyone for the consequences of using it
  9. or for whether it serves any particular purpose or works at all,
  10. unless he says so in writing.  Refer to the GNU CC General Public
  11. License for full details.
  12.  
  13. Everyone is granted permission to copy, modify and redistribute
  14. GNU CC, but only under the conditions described in the
  15. GNU CC General Public License.   A copy of this license is
  16. supposed to have been given to you along with GNU CC so you
  17. can know your rights and responsibilities.  It should be in a
  18. file named COPYING.  Among other things, the copyright notice
  19. and this notice must be preserved on all copies.  */
  20.  
  21.  
  22. /* This file contains two passes of the compiler: reg_scan and reg_class.
  23.    It also defines some tables of information about the hardware registers
  24.    and a function init_reg_sets to initialize the tables.  */
  25.  
  26. #include "config.h"
  27. #include "rtl.h"
  28. #include "hard-reg-set.h"
  29. #include "flags.h"
  30. #include "basic-block.h"
  31. #include "regs.h"
  32. #include "insn-config.h"
  33. #include "recog.h"
  34.  
  35. #define max(A,B) ((A) > (B) ? (A) : (B))
  36. #define min(A,B) ((A) < (B) ? (A) : (B))
  37.  
  38. /* Register tables used by many passes.  */
  39.  
  40. /* Indexed by hard register number, contains 1 for registers
  41.    that are fixed use (stack pointer, pc, frame pointer, etc.).
  42.    These are the registers that cannot be used to allocate
  43.    a pseudo reg whose life does not cross calls.  */
  44.  
  45. char fixed_regs[FIRST_PSEUDO_REGISTER];
  46.  
  47. /* Same info as a HARD_REG_SET.  */
  48.  
  49. HARD_REG_SET fixed_reg_set;
  50.  
  51. /* Data for initializing the above.  */
  52.  
  53. static char initial_fixed_regs[] = FIXED_REGISTERS;
  54.  
  55. /* Indexed by hard register number, contains 1 for registers
  56.    that are fixed use or are clobbered by function calls.
  57.    These are the registers that cannot be used to allocate
  58.    a pseudo reg whose life crosses calls.  */
  59.  
  60. char call_used_regs[FIRST_PSEUDO_REGISTER];
  61.  
  62. /* Same info as a HARD_REG_SET.  */
  63.  
  64. HARD_REG_SET call_used_reg_set;
  65.  
  66. /* Data for initializing the above.  */
  67.  
  68. static char initial_call_used_regs[] = CALL_USED_REGISTERS;
  69.  
  70. /* For each reg class, a HARD_REG_SET saying which registers are in it.  */
  71.  
  72. HARD_REG_SET reg_class_contents[] = REG_CLASS_CONTENTS;
  73.  
  74. /* For each reg class, table listing all the containing classes.  */
  75.  
  76. enum reg_class reg_class_superclasses[N_REG_CLASSES][N_REG_CLASSES];
  77.  
  78. /* For each reg class, table listing all the classes contained in it.  */
  79.  
  80. enum reg_class reg_class_subclasses[N_REG_CLASSES][N_REG_CLASSES];
  81.  
  82. /* For each pair of reg classes,
  83.    a largest reg class contained in their union.  */
  84.  
  85. enum reg_class reg_class_subunion[N_REG_CLASSES][N_REG_CLASSES];
  86.  
  87.  
  88. /* Function called only once to initialize the above data on reg usage.
  89.    Once this is done, various switches may override.  */
  90.  
  91. void
  92. init_reg_sets ()
  93. {
  94.   register int i, j;
  95.  
  96.   bcopy (initial_fixed_regs, fixed_regs, sizeof fixed_regs);
  97.   bcopy (initial_call_used_regs, call_used_regs, sizeof call_used_regs);
  98.  
  99.   /* Initialize the table of subunions.
  100.      reg_class_subunion[I][J] gets the largest-numbered reg-class
  101.      that is contained in the union of classes I and J.  */
  102.  
  103.   for (i = 0; i < N_REG_CLASSES; i++)
  104.     {
  105.       for (j = 0; j < N_REG_CLASSES; j++)
  106.     {
  107. #ifdef HARD_REG_SET
  108.       register        /* Declare it register if it's a scalar.  */
  109. #endif
  110.         HARD_REG_SET c;
  111.       register int k;
  112.  
  113.       COPY_HARD_REG_SET (c, reg_class_contents[i]);
  114.       IOR_HARD_REG_SET (c, reg_class_contents[j]);
  115.       for (k = 0; k < N_REG_CLASSES; k++)
  116.         {
  117.           GO_IF_HARD_REG_SUBSET (reg_class_contents[k], c,
  118.                      subclass1);
  119.           continue;
  120.  
  121.         subclass1:
  122.           reg_class_subunion[i][j] = (enum reg_class) k;
  123.         }
  124.     }
  125.     }
  126.  
  127.   /* Initialize the tables of subclasses and superclasses of each reg class.
  128.      First clear the whole table, then add the elements as they are found.  */
  129.  
  130.   for (i = 0; i < N_REG_CLASSES; i++)
  131.     {
  132.       for (j = 0; j < N_REG_CLASSES; j++)
  133.     {
  134.       reg_class_superclasses[i][j] = LIM_REG_CLASSES;
  135.       reg_class_subclasses[i][j] = LIM_REG_CLASSES;
  136.     }
  137.     }
  138.  
  139.   for (i = 0; i < N_REG_CLASSES; i++)
  140.     {
  141.       if (i == (int) NO_REGS)
  142.     continue;
  143.  
  144.       for (j = i + 1; j < N_REG_CLASSES; j++)
  145.     {
  146.       enum reg_class *p;
  147.  
  148.       GO_IF_HARD_REG_SUBSET (reg_class_contents[i], reg_class_contents[j],
  149.                  subclass);
  150.       continue;
  151.     subclass:
  152.       /* Reg class I is a subclass of J.
  153.          Add J to the table of superclasses of I.  */
  154.       p = ®_class_superclasses[i][0];
  155.       while (*p != LIM_REG_CLASSES) p++;
  156.       *p = (enum reg_class) j;
  157.       /* Add I to the table of superclasses of J.  */
  158.       p = ®_class_subclasses[j][0];
  159.       while (*p != LIM_REG_CLASSES) p++;
  160.       *p = (enum reg_class) i;
  161.     }
  162.     }
  163.  
  164. }
  165.  
  166. /* After switches have been processed, which perhaps alter
  167.    `fixed_regs' and `call_used_regs', convert them to HARD_REG_SETs.  */
  168.  
  169. void
  170. init_reg_sets_1 ()
  171. {
  172.   register int i;
  173.  
  174.   /* This macro allows the fixed or call-used registers
  175.      to depend on target flags.  */
  176.  
  177. #ifdef CONDITIONAL_REGISTER_USAGE
  178.   CONDITIONAL_REGISTER_USAGE;
  179. #endif
  180.  
  181.   /* Initialize "constant" tables.  */
  182.  
  183.   CLEAR_HARD_REG_SET (fixed_reg_set);
  184.   CLEAR_HARD_REG_SET (call_used_reg_set);
  185.  
  186.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  187.     {
  188.       if (fixed_regs[i])
  189.     SET_HARD_REG_BIT (fixed_reg_set, i);
  190.       if (call_used_regs[i])
  191.     SET_HARD_REG_BIT (call_used_reg_set, i);
  192.     }
  193. }
  194.  
  195. /* Specify the usage characteristics of the register named NAME.
  196.    It should be a fixed register if FIXED and a
  197.    call-used register if CALL_USED.  */
  198.  
  199. void
  200. fix_register (name, fixed, call_used)
  201.      char *name;
  202.      int fixed, call_used;
  203. {
  204.   static char *reg_names[] = REGISTER_NAMES;
  205.   int i;
  206.  
  207.   /* Decode the name and update the primary form of
  208.      the register info.  */
  209.  
  210.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  211.     if (!strcmp (reg_names[i], name))
  212.       {
  213.     fixed_regs[i] = fixed;
  214.     call_used_regs[i] = call_used;
  215.     break;
  216.       }
  217.  
  218.   if (i == FIRST_PSEUDO_REGISTER)
  219.     {
  220.       warning ("unknown register name: %s", name);
  221.       return;
  222.     }
  223. }
  224.  
  225. /* Now the data and code for the `regclass' pass, which happens
  226.    just before local-alloc.  */
  227.  
  228. /* savings[R].savings[CL] is twice the amount saved by putting register R
  229.    in class CL.  This data is used within `regclass' and freed
  230.    when it is finished.  */
  231.  
  232. struct savings
  233. {
  234.   short savings[N_REG_CLASSES];
  235.   short memcost;
  236. };
  237.  
  238. static struct savings *savings;
  239.  
  240. /* (enum reg_class) prefclass[R] is the preferred class for pseudo number R.
  241.    This is available after `regclass' is run.  */
  242.  
  243. static char *prefclass;
  244.  
  245. /* preferred_or_nothing[R] is nonzero if we should put pseudo number R
  246.    in memory if we can't get its perferred class.
  247.    This is available after `regclass' is run.  */
  248.  
  249. static char *preferred_or_nothing;
  250.  
  251. void reg_class_record ();
  252. void record_address_regs ();
  253.  
  254.  
  255. /* Return the reg_class in which pseudo reg number REGNO is best allocated.
  256.    This function is sometimes called before the info has been computed.
  257.    When that happens, just return GENERAL_REGS, which is innocuous.  */
  258.  
  259. enum reg_class
  260. reg_preferred_class (regno)
  261.      int regno;
  262. {
  263.   if (prefclass == 0)
  264.     return GENERAL_REGS;
  265.   return (enum reg_class) prefclass[regno];
  266. }
  267.  
  268. int
  269. reg_preferred_or_nothing (regno)
  270. {
  271.   if (prefclass == 0)
  272.     return 0;
  273.   return preferred_or_nothing[regno];
  274. }
  275.  
  276. /* This prevents dump_flow_info from losing if called
  277.    before regclass is run.  */
  278.  
  279. int
  280. regclass_init ()
  281. {
  282.   prefclass = 0;
  283. }
  284.  
  285. /* This is a pass of the compiler that scans all instructions
  286.    and calculates the preferred class for each pseudo-register.
  287.    This information can be accessed later by calling `reg_preferred_class'.
  288.    This pass comes just before local register allocation.  */
  289.  
  290. void
  291. regclass (f, nregs)
  292.      rtx f;
  293.      int nregs;
  294. {
  295. #ifdef REGISTER_CONSTRAINTS
  296.   register rtx insn;
  297.   register int i;
  298.  
  299.   init_recog ();
  300.  
  301.   /* Zero out our accumulation of the cost of each class for each reg.  */
  302.  
  303.   savings = (struct savings *) alloca (nregs * sizeof (struct savings));
  304.   bzero (savings, nregs * sizeof (struct savings));
  305.  
  306.   /* Scan the instructions and record each time it would
  307.      save code to put a certain register in a certain class.  */
  308.  
  309.   for (insn = f; insn; insn = NEXT_INSN (insn))
  310.     if ((GET_CODE (insn) == INSN
  311.      && GET_CODE (PATTERN (insn)) != USE
  312.      && GET_CODE (PATTERN (insn)) != CLOBBER
  313.      && GET_CODE (PATTERN (insn)) != ASM_INPUT)
  314.     || (GET_CODE (insn) == JUMP_INSN
  315.         && GET_CODE (PATTERN (insn)) != ADDR_VEC
  316.         && GET_CODE (PATTERN (insn)) != ADDR_DIFF_VEC)
  317.     || GET_CODE (insn) == CALL_INSN)
  318.       {
  319.     if (GET_CODE (insn) == INSN && asm_noperands (PATTERN (insn)) > 0)
  320.       {
  321.         int noperands = asm_noperands (PATTERN (insn));
  322.         rtx *operands = (rtx *) oballoc (noperands * sizeof (rtx));
  323.         char **constraints
  324.           = (char **) oballoc (noperands * sizeof (char *));
  325.  
  326.         decode_asm_operands (PATTERN (insn), operands, 0, constraints, 0);
  327.  
  328.         for (i = noperands - 1; i >= 0; i--)
  329.           reg_class_record (operands[i],
  330.                 &constraints[i]);
  331.  
  332.         obfree (operands);
  333.       }
  334.     else
  335.       {
  336.         int insn_code_number = recog_memoized (insn);
  337.  
  338.         insn_extract (insn);
  339.  
  340.         for (i = insn_n_operands[insn_code_number] - 1; i >= 0; i--)
  341.           reg_class_record (recog_operand[i],
  342.                 &insn_operand_constraint[insn_code_number][i]);
  343.  
  344.         /* Improve handling of two-address insns such as
  345.            (set X (ashift CONST Y)) where CONST must be made to match X.
  346.            Change it into two insns: (set X CONST)  (set X (ashift X Y)).
  347.            If we left this for reloading, it would probably get three insns
  348.            because X and Y might go in the same place.
  349.            This prevents X and Y from receiving the same hard reg.  */
  350.  
  351.         if (optimize
  352.         && insn_n_operands[insn_code_number] >= 3
  353.         && insn_operand_constraint[insn_code_number][1][0] == '0'
  354.         && insn_operand_constraint[insn_code_number][1][1] == 0
  355.         && CONSTANT_P (recog_operand[1])
  356.         && ! rtx_equal_p (recog_operand[0], recog_operand[1])
  357.         && ! rtx_equal_p (recog_operand[0], recog_operand[2])
  358.         && GET_CODE (recog_operand[0]) == REG)
  359.           {
  360.         rtx previnsn = prev_real_insn (insn);
  361.         rtx newinsn
  362.           = emit_insn_before (gen_move_insn (recog_operand[0],
  363.                              recog_operand[1]),
  364.                       insn);
  365.  
  366.         /* If this insn was the start of a basic block,
  367.            include the new insn in that block.  */
  368.         if (previnsn == 0 || GET_CODE (previnsn) == JUMP_INSN)
  369.           {
  370.             int b;
  371.             for (b = 0; b < n_basic_blocks; b++)
  372.               if (insn == basic_block_head[b])
  373.             basic_block_head[b] = newinsn;
  374.           }
  375.  
  376.         /* This makes one more setting of new insns's destination.  */
  377.         reg_n_sets[REGNO (recog_operand[0])]++;
  378.  
  379.         *recog_operand_loc[1] = recog_operand[0];
  380.         for (i = insn_n_dups[insn_code_number] - 1; i >= 0; i--)
  381.           if (recog_dup_num[i] == 1)
  382.             *recog_dup_loc[i] = recog_operand[0];
  383.  
  384.  
  385.           }
  386.       }
  387.       }
  388.  
  389.   /* Now for each register look at how desirable each class is
  390.      and find which class is preferred.  Store that in `prefclass[REGNO]'.  */
  391.     
  392.   prefclass = (char *) oballoc (nregs);
  393.     
  394.   preferred_or_nothing = (char *) oballoc (nregs);
  395.  
  396.   for (i = FIRST_PSEUDO_REGISTER; i < nregs; i++)
  397.     {
  398.       register int best_savings = 0;
  399.       enum reg_class best = ALL_REGS;
  400.  
  401.       /* This is an enum reg_class, but we call it an int
  402.      to save lots of casts.  */
  403.       register int class;
  404.       register struct savings *p = &savings[i];
  405.  
  406.       for (class = (int) ALL_REGS - 1; class > 0; class--)
  407.     {
  408.       if (p->savings[class] > best_savings)
  409.         {
  410.           best_savings = p->savings[class];
  411.           best = (enum reg_class) class;
  412.         }
  413.       else if (p->savings[class] == best_savings)
  414.         {
  415.           best = reg_class_subunion[(int)best][class];
  416.         }
  417.     }
  418.  
  419. #if 0
  420.       /* Note that best_savings is twice number of places something
  421.      is saved.  */
  422.       if ((best_savings - p->savings[(int) GENERAL_REGS]) * 5 < reg_n_refs[i])
  423.     prefclass[i] = (char) GENERAL_REGS;
  424.       else
  425.     prefclass[i] = (char) best;
  426. #else
  427.       prefclass[i] = (char) best;
  428. #endif
  429.  
  430.       /* reg_n_refs + p->memcost measures the cost of putting in memory.
  431.      If a GENERAL_REG is no better, don't even try for one.  */
  432.       if (reg_n_refs != 0)
  433.     preferred_or_nothing[i]
  434.       = ((best_savings - p->savings[(int) GENERAL_REGS]) / 2 
  435.          >= reg_n_refs[i] + p->memcost);
  436.     }
  437. #endif /* REGISTER_CONSTRAINTS */
  438. }
  439.  
  440. #ifdef REGISTER_CONSTRAINTS
  441.  
  442. /* Scan an operand OP to which the constraint *CONSTRAINT_LOC should apply
  443.    and record the preferred register classes from the constraint for OP
  444.    if OP is a register.  If OP is a memory reference, record suitable
  445.    preferences for registers used in the address.
  446.  
  447.    We can deduce both the insn code number and which operand in the insn
  448.    this is supposed to be from the position of CONSTRAINT_LOC
  449.    in the table of constraints.  */
  450.  
  451. void
  452. reg_class_record (op, constraint_loc)
  453.      rtx op;
  454.      char **constraint_loc;
  455. {
  456.   char *constraint = *constraint_loc;
  457.   register char *p;
  458.   register enum reg_class class = NO_REGS;
  459.   char *next = 0;
  460.   int insn_code = (constraint_loc - insn_operand_constraint[0]) / MAX_RECOG_OPERANDS;
  461.   int memok = 0;
  462.   int double_cost = 0;
  463.  
  464.   while (1)
  465.     {
  466.       if (GET_CODE (op) == SUBREG)
  467.     op = SUBREG_REG (op);
  468.       else break;
  469.     }
  470.  
  471.   /* Memory reference: scan the address.  */
  472.  
  473.   if (GET_CODE (op) == MEM)
  474.     record_address_regs (XEXP (op, 0), 2, 0);
  475.  
  476.   if (GET_CODE (op) != REG)
  477.     {
  478.       /* If the constraint says the operand is supposed to BE an address,
  479.      scan it as one.  */
  480.  
  481.       if (constraint != 0 && constraint[0] == 'p')
  482.     record_address_regs (op, 2, 0);
  483.       return;
  484.     }
  485.  
  486.   /* Operand is a register: examine the constraint for specified classes.  */
  487.  
  488.   for (p = constraint; *p || next; p++)
  489.     {
  490.       if (*p == 0)
  491.     {
  492.       p = next;
  493.       next = 0;
  494.     }
  495.       switch (*p)
  496.     {
  497.     case '=':
  498.     case '?':
  499.     case '#':
  500.     case '&':
  501.     case '!':
  502.     case '%':
  503.     case 'F':
  504.     case 'G':
  505.     case 'H':
  506.     case 'i':
  507.     case 'n':
  508.     case 's':
  509.     case 'p':
  510.     case ',':
  511.       break;
  512.  
  513.     case '+':
  514.       /* An input-output operand is twice as costly if it loses.  */
  515.       double_cost = 1;
  516.       break;
  517.  
  518.     case 'm':
  519.     case 'o':
  520.       memok = 1;
  521.       break;
  522.  
  523.       /* * means ignore following letter
  524.          when choosing register preferences.  */
  525.     case '*':
  526.       p++;
  527.       break;
  528.  
  529.     case 'g':
  530.     case 'r':
  531.       class
  532.         = reg_class_subunion[(int) class][(int) GENERAL_REGS];
  533.       break;
  534.  
  535.     case '0':
  536.     case '1':
  537.     case '2':
  538.     case '3':
  539.     case '4':
  540.       /* If constraint says "match another operand",
  541.          use that operand's constraint to choose preferences.  */
  542.       next = insn_operand_constraint[insn_code][*p - '0'];
  543.       break;
  544.  
  545.     default:
  546.       class
  547.         = reg_class_subunion[(int) class][(int) REG_CLASS_FROM_LETTER (*p)];
  548.     }
  549.     }
  550.  
  551.   {
  552.     register int i;
  553.     register struct savings *pp;
  554.     register enum reg_class class1;
  555.     int cost = 2 * (1 + double_cost);
  556.     pp = &savings[REGNO (op)];
  557.  
  558.     /* Increment the savings for this reg
  559.        for each class contained in the one the constraint asks for.  */
  560.  
  561.     if (class != NO_REGS && class != ALL_REGS)
  562.       {
  563.     pp->savings[(int) class] += cost;
  564.     for (i = 0; ; i++)
  565.       {
  566.         class1 = reg_class_subclasses[(int)class][i];
  567.         if (class1 == LIM_REG_CLASSES)
  568.           break;
  569.         pp->savings[(int) class1] += cost;
  570.       }
  571.       }
  572.  
  573.     if (! memok)
  574.       pp->memcost += 1 + 2 * double_cost;
  575.   }
  576. }
  577.  
  578. /* Record the pseudo registers we must reload into hard registers
  579.    in a subexpression of a memory address, X.
  580.    BCOST is the cost if X is a register and it fails to be in BASE_REG_CLASS.
  581.    ICOST is the cost if it fails to be in INDEX_REG_CLASS. */
  582.  
  583. void
  584. record_address_regs (x, bcost, icost)
  585.      rtx x;
  586.      int bcost, icost;
  587. {
  588.   register RTX_CODE code = GET_CODE (x);
  589.  
  590.   switch (code)
  591.     {
  592.     case CONST_INT:
  593.     case CONST:
  594.     case CC0:
  595.     case PC:
  596.     case SYMBOL_REF:
  597.     case LABEL_REF:
  598.       return;
  599.  
  600.     case PLUS:
  601.       /* When we have an address that is a sum,
  602.      we must determine whether registers are "base" or "index" regs.
  603.      If there is a sum of two registers, we must choose one to be
  604.      the "base".  Luckily, we can use the REGNO_POINTER_FLAG
  605.      to make a good choice most of the time.  */
  606.       {
  607.     register RTX_CODE code0 = GET_CODE (XEXP (x, 0));
  608.     register RTX_CODE code1 = GET_CODE (XEXP (x, 1));
  609.     int icost0 = 0;
  610.     int icost1 = 0;
  611.     int suppress1 = 0;
  612.     int suppress0 = 0;
  613.  
  614.     if (code0 == MULT || code1 == MEM)
  615.       icost0 = 2;
  616.     else if (code1 == MULT || code0 == MEM)
  617.       icost1 = 2;
  618.     else if (code0 == CONST_INT)
  619.       suppress0 = 1;
  620.     else if (code1 == CONST_INT)
  621.       suppress1 = 1;
  622.     else if (code0 == REG && code1 == REG)
  623.       {
  624.         if (REGNO_POINTER_FLAG (REGNO (XEXP (x, 0))))
  625.           icost1 = 2;
  626.         else if (REGNO_POINTER_FLAG (REGNO (XEXP (x, 1))))
  627.           icost0 = 2;
  628.         else
  629.           icost0 = icost1 = 1;
  630.       }
  631.     else if (code0 == REG)
  632.       {
  633.         if (code1 == PLUS
  634.         && ! REGNO_POINTER_FLAG (REGNO (XEXP (x, 0))))
  635.           icost0 = 2;
  636.         else
  637.           REGNO_POINTER_FLAG (REGNO (XEXP (x, 0))) = 1;
  638.       }
  639.     else if (code1 == REG)
  640.       {
  641.         if (code0 == PLUS
  642.         && ! REGNO_POINTER_FLAG (REGNO (XEXP (x, 1))))
  643.           icost1 = 2;
  644.         else
  645.           REGNO_POINTER_FLAG (REGNO (XEXP (x, 1))) = 1;
  646.       }
  647.  
  648.     /* ICOST0 determines whether we are treating operand 0
  649.        as a base register or as an index register.
  650.        SUPPRESS0 nonzero means it isn't a register at all.
  651.        ICOST1 and SUPPRESS1 are likewise for operand 1.  */
  652.  
  653.     if (! suppress0)
  654.       record_address_regs (XEXP (x, 0), 2 - icost0, icost0);
  655.     if (! suppress1)
  656.       record_address_regs (XEXP (x, 1), 2 - icost1, icost1);
  657.       }
  658.       break;
  659.  
  660.     case POST_INC:
  661.     case PRE_INC:
  662.     case POST_DEC:
  663.     case PRE_DEC:
  664.       /* Double the importance of a pseudo register that is incremented
  665.      or decremented, since it would take two extra insns
  666.      if it ends up in the wrong place.  */
  667.       record_address_regs (XEXP (x, 0), 2 * bcost, 2 * icost);
  668.       break;
  669.  
  670.     case REG:
  671.       {
  672.     register struct savings *pp;
  673.     register enum reg_class class, class1;
  674.     pp = &savings[REGNO (x)];
  675.  
  676.     /* We have an address (or part of one) that is just one register.  */
  677.  
  678.     /* Record BCOST worth of savings for classes contained
  679.        in BASE_REG_CLASS.  */
  680.  
  681.     class = BASE_REG_CLASS;
  682.     if (class != NO_REGS && class != ALL_REGS)
  683.       {
  684.         register int i;
  685.         pp->savings[(int) class] += bcost;
  686.         for (i = 0; ; i++)
  687.           {
  688.         class1 = reg_class_subclasses[(int)class][i];
  689.         if (class1 == LIM_REG_CLASSES)
  690.           break;
  691.         pp->savings[(int) class1] += bcost;
  692.           }
  693.       }
  694.  
  695.     /* Record ICOST worth of savings for classes contained
  696.        in INDEX_REG_CLASS.  */
  697.  
  698.     class = INDEX_REG_CLASS;
  699.     if (icost != 0 && class != NO_REGS && class != ALL_REGS)
  700.       {
  701.         register int i;
  702.         pp->savings[(int) class] += icost;
  703.         for (i = 0; ; i++)
  704.           {
  705.         class1 = reg_class_subclasses[(int)class][i];
  706.         if (class1 == LIM_REG_CLASSES)
  707.           break;
  708.         pp->savings[(int) class1] += icost;
  709.           }
  710.       }
  711.       }
  712.       break;
  713.  
  714.     default:
  715.       {
  716.     register char *fmt = GET_RTX_FORMAT (code);
  717.     register int i;
  718.     for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  719.       if (fmt[i] == 'e')
  720.         record_address_regs (XEXP (x, i), bcost, icost);
  721.       }
  722.     }
  723. }
  724. #endif /* REGISTER_CONSTRAINTS */
  725.  
  726. /* This is the `regscan' pass of the compiler, run just before cse
  727.    and again just before loop.
  728.  
  729.    It finds the first and last use of each pseudo-register
  730.    and records them in the vectors regno_first_uid, regno_last_uid.
  731.    REPEAT is nonzero the second time this is called.  */
  732.  
  733. /* Indexed by pseudo register number, gives uid of first insn using the reg
  734.    (as of the time reg_scan is called).  */
  735.  
  736. short *regno_first_uid;
  737.  
  738. /* Indexed by pseudo register number, gives uid of last insn using the reg
  739.    (as of the time reg_scan is called).  */
  740.  
  741. short *regno_last_uid;
  742.  
  743. void reg_scan_mark_refs ();
  744.  
  745. void
  746. reg_scan (f, nregs, repeat)
  747.      rtx f;
  748.      int nregs;
  749.      int repeat;
  750. {
  751.   register rtx insn;
  752.  
  753.   if (!repeat)
  754.     regno_first_uid = (short *) oballoc (nregs * sizeof (short));
  755.   bzero (regno_first_uid, nregs * sizeof (short));
  756.  
  757.   if (!repeat)
  758.     regno_last_uid = (short *) oballoc (nregs * sizeof (short));
  759.   bzero (regno_last_uid, nregs * sizeof (short));
  760.  
  761.   for (insn = f; insn; insn = NEXT_INSN (insn))
  762.     if (GET_CODE (insn) == INSN
  763.     || GET_CODE (insn) == CALL_INSN
  764.     || GET_CODE (insn) == JUMP_INSN)
  765.       reg_scan_mark_refs (PATTERN (insn), INSN_UID (insn));
  766. }
  767.  
  768. void
  769. reg_scan_mark_refs (x, uid)
  770.      rtx x;
  771.      int uid;
  772. {
  773.   register RTX_CODE code = GET_CODE (x);
  774.  
  775.   switch (code)
  776.     {
  777.     case CONST_INT:
  778.     case CONST:
  779.     case CONST_DOUBLE:
  780.     case CC0:
  781.     case PC:
  782.     case SYMBOL_REF:
  783.     case LABEL_REF:
  784.     case ADDR_VEC:
  785.     case ADDR_DIFF_VEC:
  786.       return;
  787.  
  788.     case REG:
  789.       {
  790.     register int regno = REGNO (x);
  791.  
  792.     regno_last_uid[regno] = uid;
  793.     if (regno_first_uid[regno] == 0)
  794.       regno_first_uid[regno] = uid;
  795.       }
  796.       break;
  797.  
  798.     default:
  799.       {
  800.     register char *fmt = GET_RTX_FORMAT (code);
  801.     register int i;
  802.     for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  803.       {
  804.         if (fmt[i] == 'e')
  805.           reg_scan_mark_refs (XEXP (x, i), uid);
  806.         else if (fmt[i] == 'E' && XVEC (x, i) != 0)
  807.           {
  808.         register int j;
  809.         for (j = XVECLEN (x, i) - 1; j >= 0; j--)
  810.           reg_scan_mark_refs (XVECEXP (x, i, j), uid);          
  811.           }
  812.       }
  813.       }
  814.     }
  815. }
  816.