OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [gcc/] [regrename.c] - Blame information for rev 827

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 38 julius
/* Register renaming for the GNU compiler.
2
   Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2007
3
   Free Software Foundation, Inc.
4
 
5
   This file is part of GCC.
6
 
7
   GCC is free software; you can redistribute it and/or modify it
8
   under the terms of the GNU General Public License as published by
9
   the Free Software Foundation; either version 3, or (at your option)
10
   any later version.
11
 
12
   GCC is distributed in the hope that it will be useful, but WITHOUT
13
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14
   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
15
   License for more details.
16
 
17
   You should have received a copy of the GNU General Public License
18
   along with GCC; see the file COPYING3.  If not see
19
   <http://www.gnu.org/licenses/>.  */
20
 
21
#include "config.h"
22
#include "system.h"
23
#include "coretypes.h"
24
#include "tm.h"
25
#include "rtl.h"
26
#include "tm_p.h"
27
#include "insn-config.h"
28
#include "regs.h"
29
#include "addresses.h"
30
#include "hard-reg-set.h"
31
#include "basic-block.h"
32
#include "reload.h"
33
#include "output.h"
34
#include "function.h"
35
#include "recog.h"
36
#include "flags.h"
37
#include "toplev.h"
38
#include "obstack.h"
39
#include "timevar.h"
40
#include "tree-pass.h"
41
 
42
struct du_chain
43
{
44
  struct du_chain *next_chain;
45
  struct du_chain *next_use;
46
 
47
  rtx insn;
48
  rtx *loc;
49
  ENUM_BITFIELD(reg_class) cl : 16;
50
  unsigned int need_caller_save_reg:1;
51
  unsigned int earlyclobber:1;
52
};
53
 
54
enum scan_actions
55
{
56
  terminate_all_read,
57
  terminate_overlapping_read,
58
  terminate_write,
59
  terminate_dead,
60
  mark_read,
61
  mark_write,
62
  /* mark_access is for marking the destination regs in
63
     REG_FRAME_RELATED_EXPR notes (as if they were read) so that the
64
     note is updated properly.  */
65
  mark_access
66
};
67
 
68
static const char * const scan_actions_name[] =
69
{
70
  "terminate_all_read",
71
  "terminate_overlapping_read",
72
  "terminate_write",
73
  "terminate_dead",
74
  "mark_read",
75
  "mark_write",
76
  "mark_access"
77
};
78
 
79
static struct obstack rename_obstack;
80
 
81
static void do_replace (struct du_chain *, int);
82
static void scan_rtx_reg (rtx, rtx *, enum reg_class,
83
                          enum scan_actions, enum op_type, int);
84
static void scan_rtx_address (rtx, rtx *, enum reg_class,
85
                              enum scan_actions, enum machine_mode);
86
static void scan_rtx (rtx, rtx *, enum reg_class, enum scan_actions,
87
                      enum op_type, int);
88
static struct du_chain *build_def_use (basic_block);
89
static void dump_def_use_chain (struct du_chain *);
90
static void note_sets (rtx, rtx, void *);
91
static void clear_dead_regs (HARD_REG_SET *, enum machine_mode, rtx);
92
static void merge_overlapping_regs (basic_block, HARD_REG_SET *,
93
                                    struct du_chain *);
94
 
95
/* Called through note_stores from update_life.  Find sets of registers, and
96
   record them in *DATA (which is actually a HARD_REG_SET *).  */
97
 
98
static void
99
note_sets (rtx x, rtx set ATTRIBUTE_UNUSED, void *data)
100
{
101
  HARD_REG_SET *pset = (HARD_REG_SET *) data;
102
  unsigned int regno;
103
  int nregs;
104
 
105
  if (GET_CODE (x) == SUBREG)
106
    x = SUBREG_REG (x);
107
  if (!REG_P (x))
108
    return;
109
  regno = REGNO (x);
110
  nregs = hard_regno_nregs[regno][GET_MODE (x)];
111
 
112
  /* There must not be pseudos at this point.  */
113
  gcc_assert (regno + nregs <= FIRST_PSEUDO_REGISTER);
114
 
115
  while (nregs-- > 0)
116
    SET_HARD_REG_BIT (*pset, regno + nregs);
117
}
118
 
119
/* Clear all registers from *PSET for which a note of kind KIND can be found
120
   in the list NOTES.  */
121
 
122
static void
123
clear_dead_regs (HARD_REG_SET *pset, enum machine_mode kind, rtx notes)
124
{
125
  rtx note;
126
  for (note = notes; note; note = XEXP (note, 1))
127
    if (REG_NOTE_KIND (note) == kind && REG_P (XEXP (note, 0)))
128
      {
129
        rtx reg = XEXP (note, 0);
130
        unsigned int regno = REGNO (reg);
131
        int nregs = hard_regno_nregs[regno][GET_MODE (reg)];
132
 
133
        /* There must not be pseudos at this point.  */
134
        gcc_assert (regno + nregs <= FIRST_PSEUDO_REGISTER);
135
 
136
        while (nregs-- > 0)
137
          CLEAR_HARD_REG_BIT (*pset, regno + nregs);
138
      }
139
}
140
 
141
/* For a def-use chain CHAIN in basic block B, find which registers overlap
142
   its lifetime and set the corresponding bits in *PSET.  */
143
 
144
static void
145
merge_overlapping_regs (basic_block b, HARD_REG_SET *pset,
146
                        struct du_chain *chain)
147
{
148
  struct du_chain *t = chain;
149
  rtx insn;
150
  HARD_REG_SET live;
151
 
152
  REG_SET_TO_HARD_REG_SET (live, b->il.rtl->global_live_at_start);
153
  insn = BB_HEAD (b);
154
  while (t)
155
    {
156
      /* Search forward until the next reference to the register to be
157
         renamed.  */
158
      while (insn != t->insn)
159
        {
160
          if (INSN_P (insn))
161
            {
162
              clear_dead_regs (&live, REG_DEAD, REG_NOTES (insn));
163
              note_stores (PATTERN (insn), note_sets, (void *) &live);
164
              /* Only record currently live regs if we are inside the
165
                 reg's live range.  */
166
              if (t != chain)
167
                IOR_HARD_REG_SET (*pset, live);
168
              clear_dead_regs (&live, REG_UNUSED, REG_NOTES (insn));
169
            }
170
          insn = NEXT_INSN (insn);
171
        }
172
 
173
      IOR_HARD_REG_SET (*pset, live);
174
 
175
      /* For the last reference, also merge in all registers set in the
176
         same insn.
177
         @@@ We only have take earlyclobbered sets into account.  */
178
      if (! t->next_use)
179
        note_stores (PATTERN (insn), note_sets, (void *) pset);
180
 
181
      t = t->next_use;
182
    }
183
}
184
 
185
/* Perform register renaming on the current function.  */
186
 
187
static void
188
regrename_optimize (void)
189
{
190
  int tick[FIRST_PSEUDO_REGISTER];
191
  int this_tick = 0;
192
  basic_block bb;
193
  char *first_obj;
194
 
195
  memset (tick, 0, sizeof tick);
196
 
197
  gcc_obstack_init (&rename_obstack);
198
  first_obj = obstack_alloc (&rename_obstack, 0);
199
 
200
  FOR_EACH_BB (bb)
201
    {
202
      struct du_chain *all_chains = 0;
203
      HARD_REG_SET unavailable;
204
      HARD_REG_SET regs_seen;
205
 
206
      CLEAR_HARD_REG_SET (unavailable);
207
 
208
      if (dump_file)
209
        fprintf (dump_file, "\nBasic block %d:\n", bb->index);
210
 
211
      all_chains = build_def_use (bb);
212
 
213
      if (dump_file)
214
        dump_def_use_chain (all_chains);
215
 
216
      CLEAR_HARD_REG_SET (unavailable);
217
      /* Don't clobber traceback for noreturn functions.  */
218
      if (frame_pointer_needed)
219
        {
220
          int i;
221
 
222
          for (i = hard_regno_nregs[FRAME_POINTER_REGNUM][Pmode]; i--;)
223
            SET_HARD_REG_BIT (unavailable, FRAME_POINTER_REGNUM + i);
224
 
225
#if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
226
          for (i = hard_regno_nregs[HARD_FRAME_POINTER_REGNUM][Pmode]; i--;)
227
            SET_HARD_REG_BIT (unavailable, HARD_FRAME_POINTER_REGNUM + i);
228
#endif
229
        }
230
 
231
      CLEAR_HARD_REG_SET (regs_seen);
232
      while (all_chains)
233
        {
234
          int new_reg, best_new_reg;
235
          int n_uses;
236
          struct du_chain *this = all_chains;
237
          struct du_chain *tmp, *last;
238
          HARD_REG_SET this_unavailable;
239
          int reg = REGNO (*this->loc);
240
          int i;
241
 
242
          all_chains = this->next_chain;
243
 
244
          best_new_reg = reg;
245
 
246
#if 0 /* This just disables optimization opportunities.  */
247
          /* Only rename once we've seen the reg more than once.  */
248
          if (! TEST_HARD_REG_BIT (regs_seen, reg))
249
            {
250
              SET_HARD_REG_BIT (regs_seen, reg);
251
              continue;
252
            }
253
#endif
254
 
255
          if (fixed_regs[reg] || global_regs[reg]
256
#if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
257
              || (frame_pointer_needed && reg == HARD_FRAME_POINTER_REGNUM)
258
#else
259
              || (frame_pointer_needed && reg == FRAME_POINTER_REGNUM)
260
#endif
261
              )
262
            continue;
263
 
264
          COPY_HARD_REG_SET (this_unavailable, unavailable);
265
 
266
          /* Find last entry on chain (which has the need_caller_save bit),
267
             count number of uses, and narrow the set of registers we can
268
             use for renaming.  */
269
          n_uses = 0;
270
          for (last = this; last->next_use; last = last->next_use)
271
            {
272
              n_uses++;
273
              IOR_COMPL_HARD_REG_SET (this_unavailable,
274
                                      reg_class_contents[last->cl]);
275
            }
276
          if (n_uses < 1)
277
            continue;
278
 
279
          IOR_COMPL_HARD_REG_SET (this_unavailable,
280
                                  reg_class_contents[last->cl]);
281
 
282
          if (this->need_caller_save_reg)
283
            IOR_HARD_REG_SET (this_unavailable, call_used_reg_set);
284
 
285
          merge_overlapping_regs (bb, &this_unavailable, this);
286
 
287
          /* Now potential_regs is a reasonable approximation, let's
288
             have a closer look at each register still in there.  */
289
          for (new_reg = 0; new_reg < FIRST_PSEUDO_REGISTER; new_reg++)
290
            {
291
              int nregs = hard_regno_nregs[new_reg][GET_MODE (*this->loc)];
292
 
293
              for (i = nregs - 1; i >= 0; --i)
294
                if (TEST_HARD_REG_BIT (this_unavailable, new_reg + i)
295
                    || fixed_regs[new_reg + i]
296
                    || global_regs[new_reg + i]
297
                    /* Can't use regs which aren't saved by the prologue.  */
298
                    || (! regs_ever_live[new_reg + i]
299
                        && ! call_used_regs[new_reg + i])
300
#ifdef LEAF_REGISTERS
301
                    /* We can't use a non-leaf register if we're in a
302
                       leaf function.  */
303
                    || (current_function_is_leaf
304
                        && !LEAF_REGISTERS[new_reg + i])
305
#endif
306
#ifdef HARD_REGNO_RENAME_OK
307
                    || ! HARD_REGNO_RENAME_OK (reg + i, new_reg + i)
308
#endif
309
                    )
310
                  break;
311
              if (i >= 0)
312
                continue;
313
 
314
              /* See whether it accepts all modes that occur in
315
                 definition and uses.  */
316
              for (tmp = this; tmp; tmp = tmp->next_use)
317
                if (! HARD_REGNO_MODE_OK (new_reg, GET_MODE (*tmp->loc))
318
                    || (tmp->need_caller_save_reg
319
                        && ! (HARD_REGNO_CALL_PART_CLOBBERED
320
                              (reg, GET_MODE (*tmp->loc)))
321
                        && (HARD_REGNO_CALL_PART_CLOBBERED
322
                            (new_reg, GET_MODE (*tmp->loc)))))
323
                  break;
324
              if (! tmp)
325
                {
326
                  if (tick[best_new_reg] > tick[new_reg])
327
                    best_new_reg = new_reg;
328
                }
329
            }
330
 
331
          if (dump_file)
332
            {
333
              fprintf (dump_file, "Register %s in insn %d",
334
                       reg_names[reg], INSN_UID (last->insn));
335
              if (last->need_caller_save_reg)
336
                fprintf (dump_file, " crosses a call");
337
            }
338
 
339
          if (best_new_reg == reg)
340
            {
341
              tick[reg] = ++this_tick;
342
              if (dump_file)
343
                fprintf (dump_file, "; no available better choice\n");
344
              continue;
345
            }
346
 
347
          do_replace (this, best_new_reg);
348
          tick[best_new_reg] = ++this_tick;
349
          regs_ever_live[best_new_reg] = 1;
350
 
351
          if (dump_file)
352
            fprintf (dump_file, ", renamed as %s\n", reg_names[best_new_reg]);
353
        }
354
 
355
      obstack_free (&rename_obstack, first_obj);
356
    }
357
 
358
  obstack_free (&rename_obstack, NULL);
359
 
360
  if (dump_file)
361
    fputc ('\n', dump_file);
362
 
363
  count_or_remove_death_notes (NULL, 1);
364
  update_life_info (NULL, UPDATE_LIFE_LOCAL,
365
                    PROP_DEATH_NOTES);
366
}
367
 
368
static void
369
do_replace (struct du_chain *chain, int reg)
370
{
371
  while (chain)
372
    {
373
      unsigned int regno = ORIGINAL_REGNO (*chain->loc);
374
      struct reg_attrs * attr = REG_ATTRS (*chain->loc);
375
 
376
      *chain->loc = gen_raw_REG (GET_MODE (*chain->loc), reg);
377
      if (regno >= FIRST_PSEUDO_REGISTER)
378
        ORIGINAL_REGNO (*chain->loc) = regno;
379
      REG_ATTRS (*chain->loc) = attr;
380
      chain = chain->next_use;
381
    }
382
}
383
 
384
 
385
static struct du_chain *open_chains;
386
static struct du_chain *closed_chains;
387
 
388
static void
389
scan_rtx_reg (rtx insn, rtx *loc, enum reg_class cl,
390
              enum scan_actions action, enum op_type type, int earlyclobber)
391
{
392
  struct du_chain **p;
393
  rtx x = *loc;
394
  enum machine_mode mode = GET_MODE (x);
395
  int this_regno = REGNO (x);
396
  int this_nregs = hard_regno_nregs[this_regno][mode];
397
 
398
  if (action == mark_write)
399
    {
400
      if (type == OP_OUT)
401
        {
402
          struct du_chain *this
403
            = obstack_alloc (&rename_obstack, sizeof (struct du_chain));
404
          this->next_use = 0;
405
          this->next_chain = open_chains;
406
          this->loc = loc;
407
          this->insn = insn;
408
          this->cl = cl;
409
          this->need_caller_save_reg = 0;
410
          this->earlyclobber = earlyclobber;
411
          open_chains = this;
412
        }
413
      return;
414
    }
415
 
416
  if ((type == OP_OUT) != (action == terminate_write || action == mark_access))
417
    return;
418
 
419
  for (p = &open_chains; *p;)
420
    {
421
      struct du_chain *this = *p;
422
 
423
      /* Check if the chain has been terminated if it has then skip to
424
         the next chain.
425
 
426
         This can happen when we've already appended the location to
427
         the chain in Step 3, but are trying to hide in-out operands
428
         from terminate_write in Step 5.  */
429
 
430
      if (*this->loc == cc0_rtx)
431
        p = &this->next_chain;
432
      else
433
        {
434
          int regno = REGNO (*this->loc);
435
          int nregs = hard_regno_nregs[regno][GET_MODE (*this->loc)];
436
          int exact_match = (regno == this_regno && nregs == this_nregs);
437
 
438
          if (regno + nregs <= this_regno
439
              || this_regno + this_nregs <= regno)
440
            {
441
              p = &this->next_chain;
442
              continue;
443
            }
444
 
445
          if (action == mark_read || action == mark_access)
446
            {
447
              gcc_assert (exact_match);
448
 
449
              /* ??? Class NO_REGS can happen if the md file makes use of
450
                 EXTRA_CONSTRAINTS to match registers.  Which is arguably
451
                 wrong, but there we are.  Since we know not what this may
452
                 be replaced with, terminate the chain.  */
453
              if (cl != NO_REGS)
454
                {
455
                  this = obstack_alloc (&rename_obstack, sizeof (struct du_chain));
456
                  this->next_use = 0;
457
                  this->next_chain = (*p)->next_chain;
458
                  this->loc = loc;
459
                  this->insn = insn;
460
                  this->cl = cl;
461
                  this->need_caller_save_reg = 0;
462
                  while (*p)
463
                    p = &(*p)->next_use;
464
                  *p = this;
465
                  return;
466
                }
467
            }
468
 
469
          if (action != terminate_overlapping_read || ! exact_match)
470
            {
471
              struct du_chain *next = this->next_chain;
472
 
473
              /* Whether the terminated chain can be used for renaming
474
                 depends on the action and this being an exact match.
475
                 In either case, we remove this element from open_chains.  */
476
 
477
              if ((action == terminate_dead || action == terminate_write)
478
                  && exact_match)
479
                {
480
                  this->next_chain = closed_chains;
481
                  closed_chains = this;
482
                  if (dump_file)
483
                    fprintf (dump_file,
484
                             "Closing chain %s at insn %d (%s)\n",
485
                             reg_names[REGNO (*this->loc)], INSN_UID (insn),
486
                             scan_actions_name[(int) action]);
487
                }
488
              else
489
                {
490
                  if (dump_file)
491
                    fprintf (dump_file,
492
                             "Discarding chain %s at insn %d (%s)\n",
493
                             reg_names[REGNO (*this->loc)], INSN_UID (insn),
494
                             scan_actions_name[(int) action]);
495
                }
496
              *p = next;
497
            }
498
          else
499
            p = &this->next_chain;
500
        }
501
    }
502
}
503
 
504
/* Adapted from find_reloads_address_1.  CL is INDEX_REG_CLASS or
505
   BASE_REG_CLASS depending on how the register is being considered.  */
506
 
507
static void
508
scan_rtx_address (rtx insn, rtx *loc, enum reg_class cl,
509
                  enum scan_actions action, enum machine_mode mode)
510
{
511
  rtx x = *loc;
512
  RTX_CODE code = GET_CODE (x);
513
  const char *fmt;
514
  int i, j;
515
 
516
  if (action == mark_write || action == mark_access)
517
    return;
518
 
519
  switch (code)
520
    {
521
    case PLUS:
522
      {
523
        rtx orig_op0 = XEXP (x, 0);
524
        rtx orig_op1 = XEXP (x, 1);
525
        RTX_CODE code0 = GET_CODE (orig_op0);
526
        RTX_CODE code1 = GET_CODE (orig_op1);
527
        rtx op0 = orig_op0;
528
        rtx op1 = orig_op1;
529
        rtx *locI = NULL;
530
        rtx *locB = NULL;
531
        enum rtx_code index_code = SCRATCH;
532
 
533
        if (GET_CODE (op0) == SUBREG)
534
          {
535
            op0 = SUBREG_REG (op0);
536
            code0 = GET_CODE (op0);
537
          }
538
 
539
        if (GET_CODE (op1) == SUBREG)
540
          {
541
            op1 = SUBREG_REG (op1);
542
            code1 = GET_CODE (op1);
543
          }
544
 
545
        if (code0 == MULT || code0 == SIGN_EXTEND || code0 == TRUNCATE
546
            || code0 == ZERO_EXTEND || code1 == MEM)
547
          {
548
            locI = &XEXP (x, 0);
549
            locB = &XEXP (x, 1);
550
            index_code = GET_CODE (*locI);
551
          }
552
        else if (code1 == MULT || code1 == SIGN_EXTEND || code1 == TRUNCATE
553
                 || code1 == ZERO_EXTEND || code0 == MEM)
554
          {
555
            locI = &XEXP (x, 1);
556
            locB = &XEXP (x, 0);
557
            index_code = GET_CODE (*locI);
558
          }
559
        else if (code0 == CONST_INT || code0 == CONST
560
                 || code0 == SYMBOL_REF || code0 == LABEL_REF)
561
          {
562
            locB = &XEXP (x, 1);
563
            index_code = GET_CODE (XEXP (x, 0));
564
          }
565
        else if (code1 == CONST_INT || code1 == CONST
566
                 || code1 == SYMBOL_REF || code1 == LABEL_REF)
567
          {
568
            locB = &XEXP (x, 0);
569
            index_code = GET_CODE (XEXP (x, 1));
570
          }
571
        else if (code0 == REG && code1 == REG)
572
          {
573
            int index_op;
574
            unsigned regno0 = REGNO (op0), regno1 = REGNO (op1);
575
 
576
            if (REGNO_OK_FOR_INDEX_P (regno0)
577
                && regno_ok_for_base_p (regno1, mode, PLUS, REG))
578
              index_op = 0;
579
            else if (REGNO_OK_FOR_INDEX_P (regno1)
580
                     && regno_ok_for_base_p (regno0, mode, PLUS, REG))
581
              index_op = 1;
582
            else if (regno_ok_for_base_p (regno1, mode, PLUS, REG))
583
              index_op = 0;
584
            else if (regno_ok_for_base_p (regno0, mode, PLUS, REG))
585
              index_op = 1;
586
            else if (REGNO_OK_FOR_INDEX_P (regno1))
587
              index_op = 1;
588
            else
589
              index_op = 0;
590
 
591
            locI = &XEXP (x, index_op);
592
            locB = &XEXP (x, !index_op);
593
            index_code = GET_CODE (*locI);
594
          }
595
        else if (code0 == REG)
596
          {
597
            locI = &XEXP (x, 0);
598
            locB = &XEXP (x, 1);
599
            index_code = GET_CODE (*locI);
600
          }
601
        else if (code1 == REG)
602
          {
603
            locI = &XEXP (x, 1);
604
            locB = &XEXP (x, 0);
605
            index_code = GET_CODE (*locI);
606
          }
607
 
608
        if (locI)
609
          scan_rtx_address (insn, locI, INDEX_REG_CLASS, action, mode);
610
        if (locB)
611
          scan_rtx_address (insn, locB, base_reg_class (mode, PLUS, index_code),
612
                            action, mode);
613
 
614
        return;
615
      }
616
 
617
    case POST_INC:
618
    case POST_DEC:
619
    case POST_MODIFY:
620
    case PRE_INC:
621
    case PRE_DEC:
622
    case PRE_MODIFY:
623
#ifndef AUTO_INC_DEC
624
      /* If the target doesn't claim to handle autoinc, this must be
625
         something special, like a stack push.  Kill this chain.  */
626
      action = terminate_all_read;
627
#endif
628
      break;
629
 
630
    case MEM:
631
      scan_rtx_address (insn, &XEXP (x, 0),
632
                        base_reg_class (GET_MODE (x), MEM, SCRATCH), action,
633
                        GET_MODE (x));
634
      return;
635
 
636
    case REG:
637
      scan_rtx_reg (insn, loc, cl, action, OP_IN, 0);
638
      return;
639
 
640
    default:
641
      break;
642
    }
643
 
644
  fmt = GET_RTX_FORMAT (code);
645
  for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
646
    {
647
      if (fmt[i] == 'e')
648
        scan_rtx_address (insn, &XEXP (x, i), cl, action, mode);
649
      else if (fmt[i] == 'E')
650
        for (j = XVECLEN (x, i) - 1; j >= 0; j--)
651
          scan_rtx_address (insn, &XVECEXP (x, i, j), cl, action, mode);
652
    }
653
}
654
 
655
static void
656
scan_rtx (rtx insn, rtx *loc, enum reg_class cl,
657
          enum scan_actions action, enum op_type type, int earlyclobber)
658
{
659
  const char *fmt;
660
  rtx x = *loc;
661
  enum rtx_code code = GET_CODE (x);
662
  int i, j;
663
 
664
  code = GET_CODE (x);
665
  switch (code)
666
    {
667
    case CONST:
668
    case CONST_INT:
669
    case CONST_DOUBLE:
670
    case CONST_VECTOR:
671
    case SYMBOL_REF:
672
    case LABEL_REF:
673
    case CC0:
674
    case PC:
675
      return;
676
 
677
    case REG:
678
      scan_rtx_reg (insn, loc, cl, action, type, earlyclobber);
679
      return;
680
 
681
    case MEM:
682
      scan_rtx_address (insn, &XEXP (x, 0),
683
                        base_reg_class (GET_MODE (x), MEM, SCRATCH), action,
684
                        GET_MODE (x));
685
      return;
686
 
687
    case SET:
688
      scan_rtx (insn, &SET_SRC (x), cl, action, OP_IN, 0);
689
      scan_rtx (insn, &SET_DEST (x), cl, action,
690
                GET_CODE (PATTERN (insn)) == COND_EXEC ? OP_INOUT : OP_OUT, 0);
691
      return;
692
 
693
    case STRICT_LOW_PART:
694
      scan_rtx (insn, &XEXP (x, 0), cl, action, OP_INOUT, earlyclobber);
695
      return;
696
 
697
    case ZERO_EXTRACT:
698
    case SIGN_EXTRACT:
699
      scan_rtx (insn, &XEXP (x, 0), cl, action,
700
                type == OP_IN ? OP_IN : OP_INOUT, earlyclobber);
701
      scan_rtx (insn, &XEXP (x, 1), cl, action, OP_IN, 0);
702
      scan_rtx (insn, &XEXP (x, 2), cl, action, OP_IN, 0);
703
      return;
704
 
705
    case POST_INC:
706
    case PRE_INC:
707
    case POST_DEC:
708
    case PRE_DEC:
709
    case POST_MODIFY:
710
    case PRE_MODIFY:
711
      /* Should only happen inside MEM.  */
712
      gcc_unreachable ();
713
 
714
    case CLOBBER:
715
      scan_rtx (insn, &SET_DEST (x), cl, action,
716
                GET_CODE (PATTERN (insn)) == COND_EXEC ? OP_INOUT : OP_OUT, 0);
717
      return;
718
 
719
    case EXPR_LIST:
720
      scan_rtx (insn, &XEXP (x, 0), cl, action, type, 0);
721
      if (XEXP (x, 1))
722
        scan_rtx (insn, &XEXP (x, 1), cl, action, type, 0);
723
      return;
724
 
725
    default:
726
      break;
727
    }
728
 
729
  fmt = GET_RTX_FORMAT (code);
730
  for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
731
    {
732
      if (fmt[i] == 'e')
733
        scan_rtx (insn, &XEXP (x, i), cl, action, type, 0);
734
      else if (fmt[i] == 'E')
735
        for (j = XVECLEN (x, i) - 1; j >= 0; j--)
736
          scan_rtx (insn, &XVECEXP (x, i, j), cl, action, type, 0);
737
    }
738
}
739
 
740
/* Build def/use chain.  */
741
 
742
static struct du_chain *
743
build_def_use (basic_block bb)
744
{
745
  rtx insn;
746
 
747
  open_chains = closed_chains = NULL;
748
 
749
  for (insn = BB_HEAD (bb); ; insn = NEXT_INSN (insn))
750
    {
751
      if (INSN_P (insn))
752
        {
753
          int n_ops;
754
          rtx note;
755
          rtx old_operands[MAX_RECOG_OPERANDS];
756
          rtx old_dups[MAX_DUP_OPERANDS];
757
          int i, icode;
758
          int alt;
759
          int predicated;
760
 
761
          /* Process the insn, determining its effect on the def-use
762
             chains.  We perform the following steps with the register
763
             references in the insn:
764
             (1) Any read that overlaps an open chain, but doesn't exactly
765
                 match, causes that chain to be closed.  We can't deal
766
                 with overlaps yet.
767
             (2) Any read outside an operand causes any chain it overlaps
768
                 with to be closed, since we can't replace it.
769
             (3) Any read inside an operand is added if there's already
770
                 an open chain for it.
771
             (4) For any REG_DEAD note we find, close open chains that
772
                 overlap it.
773
             (5) For any write we find, close open chains that overlap it.
774
             (6) For any write we find in an operand, make a new chain.
775
             (7) For any REG_UNUSED, close any chains we just opened.  */
776
 
777
          icode = recog_memoized (insn);
778
          extract_insn (insn);
779
          if (! constrain_operands (1))
780
            fatal_insn_not_found (insn);
781
          preprocess_constraints ();
782
          alt = which_alternative;
783
          n_ops = recog_data.n_operands;
784
 
785
          /* Simplify the code below by rewriting things to reflect
786
             matching constraints.  Also promote OP_OUT to OP_INOUT
787
             in predicated instructions.  */
788
 
789
          predicated = GET_CODE (PATTERN (insn)) == COND_EXEC;
790
          for (i = 0; i < n_ops; ++i)
791
            {
792
              int matches = recog_op_alt[i][alt].matches;
793
              if (matches >= 0)
794
                recog_op_alt[i][alt].cl = recog_op_alt[matches][alt].cl;
795
              if (matches >= 0 || recog_op_alt[i][alt].matched >= 0
796
                  || (predicated && recog_data.operand_type[i] == OP_OUT))
797
                recog_data.operand_type[i] = OP_INOUT;
798
            }
799
 
800
          /* Step 1: Close chains for which we have overlapping reads.  */
801
          for (i = 0; i < n_ops; i++)
802
            scan_rtx (insn, recog_data.operand_loc[i],
803
                      NO_REGS, terminate_overlapping_read,
804
                      recog_data.operand_type[i], 0);
805
 
806
          /* Step 2: Close chains for which we have reads outside operands.
807
             We do this by munging all operands into CC0, and closing
808
             everything remaining.  */
809
 
810
          for (i = 0; i < n_ops; i++)
811
            {
812
              old_operands[i] = recog_data.operand[i];
813
              /* Don't squash match_operator or match_parallel here, since
814
                 we don't know that all of the contained registers are
815
                 reachable by proper operands.  */
816
              if (recog_data.constraints[i][0] == '\0')
817
                continue;
818
              *recog_data.operand_loc[i] = cc0_rtx;
819
            }
820
          for (i = 0; i < recog_data.n_dups; i++)
821
            {
822
              int dup_num = recog_data.dup_num[i];
823
 
824
              old_dups[i] = *recog_data.dup_loc[i];
825
              *recog_data.dup_loc[i] = cc0_rtx;
826
 
827
              /* For match_dup of match_operator or match_parallel, share
828
                 them, so that we don't miss changes in the dup.  */
829
              if (icode >= 0
830
                  && insn_data[icode].operand[dup_num].eliminable == 0)
831
                old_dups[i] = recog_data.operand[dup_num];
832
            }
833
 
834
          scan_rtx (insn, &PATTERN (insn), NO_REGS, terminate_all_read,
835
                    OP_IN, 0);
836
 
837
          for (i = 0; i < recog_data.n_dups; i++)
838
            *recog_data.dup_loc[i] = old_dups[i];
839
          for (i = 0; i < n_ops; i++)
840
            *recog_data.operand_loc[i] = old_operands[i];
841
 
842
          /* Step 2B: Can't rename function call argument registers.  */
843
          if (CALL_P (insn) && CALL_INSN_FUNCTION_USAGE (insn))
844
            scan_rtx (insn, &CALL_INSN_FUNCTION_USAGE (insn),
845
                      NO_REGS, terminate_all_read, OP_IN, 0);
846
 
847
          /* Step 2C: Can't rename asm operands that were originally
848
             hard registers.  */
849
          if (asm_noperands (PATTERN (insn)) > 0)
850
            for (i = 0; i < n_ops; i++)
851
              {
852
                rtx *loc = recog_data.operand_loc[i];
853
                rtx op = *loc;
854
 
855
                if (REG_P (op)
856
                    && REGNO (op) == ORIGINAL_REGNO (op)
857
                    && (recog_data.operand_type[i] == OP_IN
858
                        || recog_data.operand_type[i] == OP_INOUT))
859
                  scan_rtx (insn, loc, NO_REGS, terminate_all_read, OP_IN, 0);
860
              }
861
 
862
          /* Step 3: Append to chains for reads inside operands.  */
863
          for (i = 0; i < n_ops + recog_data.n_dups; i++)
864
            {
865
              int opn = i < n_ops ? i : recog_data.dup_num[i - n_ops];
866
              rtx *loc = (i < n_ops
867
                          ? recog_data.operand_loc[opn]
868
                          : recog_data.dup_loc[i - n_ops]);
869
              enum reg_class cl = recog_op_alt[opn][alt].cl;
870
              enum op_type type = recog_data.operand_type[opn];
871
 
872
              /* Don't scan match_operand here, since we've no reg class
873
                 information to pass down.  Any operands that we could
874
                 substitute in will be represented elsewhere.  */
875
              if (recog_data.constraints[opn][0] == '\0')
876
                continue;
877
 
878
              if (recog_op_alt[opn][alt].is_address)
879
                scan_rtx_address (insn, loc, cl, mark_read, VOIDmode);
880
              else
881
                scan_rtx (insn, loc, cl, mark_read, type, 0);
882
            }
883
 
884
          /* Step 3B: Record updates for regs in REG_INC notes, and
885
             source regs in REG_FRAME_RELATED_EXPR notes.  */
886
          for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
887
            if (REG_NOTE_KIND (note) == REG_INC
888
                || REG_NOTE_KIND (note) == REG_FRAME_RELATED_EXPR)
889
              scan_rtx (insn, &XEXP (note, 0), ALL_REGS, mark_read,
890
                        OP_INOUT, 0);
891
 
892
          /* Step 4: Close chains for registers that die here.  */
893
          for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
894
            if (REG_NOTE_KIND (note) == REG_DEAD)
895
              scan_rtx (insn, &XEXP (note, 0), NO_REGS, terminate_dead,
896
                        OP_IN, 0);
897
 
898
          /* Step 4B: If this is a call, any chain live at this point
899
             requires a caller-saved reg.  */
900
          if (CALL_P (insn))
901
            {
902
              struct du_chain *p;
903
              for (p = open_chains; p; p = p->next_chain)
904
                p->need_caller_save_reg = 1;
905
            }
906
 
907
          /* Step 5: Close open chains that overlap writes.  Similar to
908
             step 2, we hide in-out operands, since we do not want to
909
             close these chains.  */
910
 
911
          for (i = 0; i < n_ops; i++)
912
            {
913
              old_operands[i] = recog_data.operand[i];
914
              if (recog_data.operand_type[i] == OP_INOUT)
915
                *recog_data.operand_loc[i] = cc0_rtx;
916
            }
917
          for (i = 0; i < recog_data.n_dups; i++)
918
            {
919
              int opn = recog_data.dup_num[i];
920
              old_dups[i] = *recog_data.dup_loc[i];
921
              if (recog_data.operand_type[opn] == OP_INOUT)
922
                *recog_data.dup_loc[i] = cc0_rtx;
923
            }
924
 
925
          scan_rtx (insn, &PATTERN (insn), NO_REGS, terminate_write, OP_IN, 0);
926
 
927
          for (i = 0; i < recog_data.n_dups; i++)
928
            *recog_data.dup_loc[i] = old_dups[i];
929
          for (i = 0; i < n_ops; i++)
930
            *recog_data.operand_loc[i] = old_operands[i];
931
 
932
          /* Step 6: Begin new chains for writes inside operands.  */
933
          /* ??? Many targets have output constraints on the SET_DEST
934
             of a call insn, which is stupid, since these are certainly
935
             ABI defined hard registers.  Don't change calls at all.
936
             Similarly take special care for asm statement that originally
937
             referenced hard registers.  */
938
          if (asm_noperands (PATTERN (insn)) > 0)
939
            {
940
              for (i = 0; i < n_ops; i++)
941
                if (recog_data.operand_type[i] == OP_OUT)
942
                  {
943
                    rtx *loc = recog_data.operand_loc[i];
944
                    rtx op = *loc;
945
                    enum reg_class cl = recog_op_alt[i][alt].cl;
946
 
947
                    if (REG_P (op)
948
                        && REGNO (op) == ORIGINAL_REGNO (op))
949
                      continue;
950
 
951
                    scan_rtx (insn, loc, cl, mark_write, OP_OUT,
952
                              recog_op_alt[i][alt].earlyclobber);
953
                  }
954
            }
955
          else if (!CALL_P (insn))
956
            for (i = 0; i < n_ops + recog_data.n_dups; i++)
957
              {
958
                int opn = i < n_ops ? i : recog_data.dup_num[i - n_ops];
959
                rtx *loc = (i < n_ops
960
                            ? recog_data.operand_loc[opn]
961
                            : recog_data.dup_loc[i - n_ops]);
962
                enum reg_class cl = recog_op_alt[opn][alt].cl;
963
 
964
                if (recog_data.operand_type[opn] == OP_OUT)
965
                  scan_rtx (insn, loc, cl, mark_write, OP_OUT,
966
                            recog_op_alt[opn][alt].earlyclobber);
967
              }
968
 
969
          /* Step 6B: Record destination regs in REG_FRAME_RELATED_EXPR
970
             notes for update.  */
971
          for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
972
            if (REG_NOTE_KIND (note) == REG_FRAME_RELATED_EXPR)
973
              scan_rtx (insn, &XEXP (note, 0), ALL_REGS, mark_access,
974
                        OP_INOUT, 0);
975
 
976
          /* Step 7: Close chains for registers that were never
977
             really used here.  */
978
          for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
979
            if (REG_NOTE_KIND (note) == REG_UNUSED)
980
              scan_rtx (insn, &XEXP (note, 0), NO_REGS, terminate_dead,
981
                        OP_IN, 0);
982
        }
983
      if (insn == BB_END (bb))
984
        break;
985
    }
986
 
987
  /* Since we close every chain when we find a REG_DEAD note, anything that
988
     is still open lives past the basic block, so it can't be renamed.  */
989
  return closed_chains;
990
}
991
 
992
/* Dump all def/use chains in CHAINS to DUMP_FILE.  They are
993
   printed in reverse order as that's how we build them.  */
994
 
995
static void
996
dump_def_use_chain (struct du_chain *chains)
997
{
998
  while (chains)
999
    {
1000
      struct du_chain *this = chains;
1001
      int r = REGNO (*this->loc);
1002
      int nregs = hard_regno_nregs[r][GET_MODE (*this->loc)];
1003
      fprintf (dump_file, "Register %s (%d):", reg_names[r], nregs);
1004
      while (this)
1005
        {
1006
          fprintf (dump_file, " %d [%s]", INSN_UID (this->insn),
1007
                   reg_class_names[this->cl]);
1008
          this = this->next_use;
1009
        }
1010
      fprintf (dump_file, "\n");
1011
      chains = chains->next_chain;
1012
    }
1013
}
1014
 
1015
/* The following code does forward propagation of hard register copies.
1016
   The object is to eliminate as many dependencies as possible, so that
1017
   we have the most scheduling freedom.  As a side effect, we also clean
1018
   up some silly register allocation decisions made by reload.  This
1019
   code may be obsoleted by a new register allocator.  */
1020
 
1021
/* For each register, we have a list of registers that contain the same
1022
   value.  The OLDEST_REGNO field points to the head of the list, and
1023
   the NEXT_REGNO field runs through the list.  The MODE field indicates
1024
   what mode the data is known to be in; this field is VOIDmode when the
1025
   register is not known to contain valid data.  */
1026
 
1027
struct value_data_entry
1028
{
1029
  enum machine_mode mode;
1030
  unsigned int oldest_regno;
1031
  unsigned int next_regno;
1032
};
1033
 
1034
struct value_data
1035
{
1036
  struct value_data_entry e[FIRST_PSEUDO_REGISTER];
1037
  unsigned int max_value_regs;
1038
};
1039
 
1040
static void kill_value_one_regno (unsigned, struct value_data *);
1041
static void kill_value_regno (unsigned, unsigned, struct value_data *);
1042
static void kill_value (rtx, struct value_data *);
1043
static void set_value_regno (unsigned, enum machine_mode, struct value_data *);
1044
static void init_value_data (struct value_data *);
1045
static void kill_clobbered_value (rtx, rtx, void *);
1046
static void kill_set_value (rtx, rtx, void *);
1047
static int kill_autoinc_value (rtx *, void *);
1048
static void copy_value (rtx, rtx, struct value_data *);
1049
static bool mode_change_ok (enum machine_mode, enum machine_mode,
1050
                            unsigned int);
1051
static rtx maybe_mode_change (enum machine_mode, enum machine_mode,
1052
                              enum machine_mode, unsigned int, unsigned int);
1053
static rtx find_oldest_value_reg (enum reg_class, rtx, struct value_data *);
1054
static bool replace_oldest_value_reg (rtx *, enum reg_class, rtx,
1055
                                      struct value_data *);
1056
static bool replace_oldest_value_addr (rtx *, enum reg_class,
1057
                                       enum machine_mode, rtx,
1058
                                       struct value_data *);
1059
static bool replace_oldest_value_mem (rtx, rtx, struct value_data *);
1060
static bool copyprop_hardreg_forward_1 (basic_block, struct value_data *);
1061
extern void debug_value_data (struct value_data *);
1062
#ifdef ENABLE_CHECKING
1063
static void validate_value_data (struct value_data *);
1064
#endif
1065
 
1066
/* Kill register REGNO.  This involves removing it from any value
1067
   lists, and resetting the value mode to VOIDmode.  This is only a
1068
   helper function; it does not handle any hard registers overlapping
1069
   with REGNO.  */
1070
 
1071
static void
1072
kill_value_one_regno (unsigned int regno, struct value_data *vd)
1073
{
1074
  unsigned int i, next;
1075
 
1076
  if (vd->e[regno].oldest_regno != regno)
1077
    {
1078
      for (i = vd->e[regno].oldest_regno;
1079
           vd->e[i].next_regno != regno;
1080
           i = vd->e[i].next_regno)
1081
        continue;
1082
      vd->e[i].next_regno = vd->e[regno].next_regno;
1083
    }
1084
  else if ((next = vd->e[regno].next_regno) != INVALID_REGNUM)
1085
    {
1086
      for (i = next; i != INVALID_REGNUM; i = vd->e[i].next_regno)
1087
        vd->e[i].oldest_regno = next;
1088
    }
1089
 
1090
  vd->e[regno].mode = VOIDmode;
1091
  vd->e[regno].oldest_regno = regno;
1092
  vd->e[regno].next_regno = INVALID_REGNUM;
1093
 
1094
#ifdef ENABLE_CHECKING
1095
  validate_value_data (vd);
1096
#endif
1097
}
1098
 
1099
/* Kill the value in register REGNO for NREGS, and any other registers
1100
   whose values overlap.  */
1101
 
1102
static void
1103
kill_value_regno (unsigned int regno, unsigned int nregs,
1104
                  struct value_data *vd)
1105
{
1106
  unsigned int j;
1107
 
1108
  /* Kill the value we're told to kill.  */
1109
  for (j = 0; j < nregs; ++j)
1110
    kill_value_one_regno (regno + j, vd);
1111
 
1112
  /* Kill everything that overlapped what we're told to kill.  */
1113
  if (regno < vd->max_value_regs)
1114
    j = 0;
1115
  else
1116
    j = regno - vd->max_value_regs;
1117
  for (; j < regno; ++j)
1118
    {
1119
      unsigned int i, n;
1120
      if (vd->e[j].mode == VOIDmode)
1121
        continue;
1122
      n = hard_regno_nregs[j][vd->e[j].mode];
1123
      if (j + n > regno)
1124
        for (i = 0; i < n; ++i)
1125
          kill_value_one_regno (j + i, vd);
1126
    }
1127
}
1128
 
1129
/* Kill X.  This is a convenience function wrapping kill_value_regno
1130
   so that we mind the mode the register is in.  */
1131
 
1132
static void
1133
kill_value (rtx x, struct value_data *vd)
1134
{
1135
  rtx orig_rtx = x;
1136
 
1137
  if (GET_CODE (x) == SUBREG)
1138
    {
1139
      x = simplify_subreg (GET_MODE (x), SUBREG_REG (x),
1140
                           GET_MODE (SUBREG_REG (x)), SUBREG_BYTE (x));
1141
      if (x == NULL_RTX)
1142
        x = SUBREG_REG (orig_rtx);
1143
    }
1144
  if (REG_P (x))
1145
    {
1146
      unsigned int regno = REGNO (x);
1147
      unsigned int n = hard_regno_nregs[regno][GET_MODE (x)];
1148
 
1149
      kill_value_regno (regno, n, vd);
1150
    }
1151
}
1152
 
1153
/* Remember that REGNO is valid in MODE.  */
1154
 
1155
static void
1156
set_value_regno (unsigned int regno, enum machine_mode mode,
1157
                 struct value_data *vd)
1158
{
1159
  unsigned int nregs;
1160
 
1161
  vd->e[regno].mode = mode;
1162
 
1163
  nregs = hard_regno_nregs[regno][mode];
1164
  if (nregs > vd->max_value_regs)
1165
    vd->max_value_regs = nregs;
1166
}
1167
 
1168
/* Initialize VD such that there are no known relationships between regs.  */
1169
 
1170
static void
1171
init_value_data (struct value_data *vd)
1172
{
1173
  int i;
1174
  for (i = 0; i < FIRST_PSEUDO_REGISTER; ++i)
1175
    {
1176
      vd->e[i].mode = VOIDmode;
1177
      vd->e[i].oldest_regno = i;
1178
      vd->e[i].next_regno = INVALID_REGNUM;
1179
    }
1180
  vd->max_value_regs = 0;
1181
}
1182
 
1183
/* Called through note_stores.  If X is clobbered, kill its value.  */
1184
 
1185
static void
1186
kill_clobbered_value (rtx x, rtx set, void *data)
1187
{
1188
  struct value_data *vd = data;
1189
  if (GET_CODE (set) == CLOBBER)
1190
    kill_value (x, vd);
1191
}
1192
 
1193
/* Called through note_stores.  If X is set, not clobbered, kill its
1194
   current value and install it as the root of its own value list.  */
1195
 
1196
static void
1197
kill_set_value (rtx x, rtx set, void *data)
1198
{
1199
  struct value_data *vd = data;
1200
  if (GET_CODE (set) != CLOBBER)
1201
    {
1202
      kill_value (x, vd);
1203
      if (REG_P (x))
1204
        set_value_regno (REGNO (x), GET_MODE (x), vd);
1205
    }
1206
}
1207
 
1208
/* Called through for_each_rtx.  Kill any register used as the base of an
1209
   auto-increment expression, and install that register as the root of its
1210
   own value list.  */
1211
 
1212
static int
1213
kill_autoinc_value (rtx *px, void *data)
1214
{
1215
  rtx x = *px;
1216
  struct value_data *vd = data;
1217
 
1218
  if (GET_RTX_CLASS (GET_CODE (x)) == RTX_AUTOINC)
1219
    {
1220
      x = XEXP (x, 0);
1221
      kill_value (x, vd);
1222
      set_value_regno (REGNO (x), Pmode, vd);
1223
      return -1;
1224
    }
1225
 
1226
  return 0;
1227
}
1228
 
1229
/* Assert that SRC has been copied to DEST.  Adjust the data structures
1230
   to reflect that SRC contains an older copy of the shared value.  */
1231
 
1232
static void
1233
copy_value (rtx dest, rtx src, struct value_data *vd)
1234
{
1235
  unsigned int dr = REGNO (dest);
1236
  unsigned int sr = REGNO (src);
1237
  unsigned int dn, sn;
1238
  unsigned int i;
1239
 
1240
  /* ??? At present, it's possible to see noop sets.  It'd be nice if
1241
     this were cleaned up beforehand...  */
1242
  if (sr == dr)
1243
    return;
1244
 
1245
  /* Do not propagate copies to the stack pointer, as that can leave
1246
     memory accesses with no scheduling dependency on the stack update.  */
1247
  if (dr == STACK_POINTER_REGNUM)
1248
    return;
1249
 
1250
  /* Likewise with the frame pointer, if we're using one.  */
1251
  if (frame_pointer_needed && dr == HARD_FRAME_POINTER_REGNUM)
1252
    return;
1253
 
1254
  /* Do not propagate copies to fixed or global registers, patterns
1255
     can be relying to see particular fixed register or users can
1256
     expect the chosen global register in asm.  */
1257
  if (fixed_regs[dr] || global_regs[dr])
1258
    return;
1259
 
1260
  /* If SRC and DEST overlap, don't record anything.  */
1261
  dn = hard_regno_nregs[dr][GET_MODE (dest)];
1262
  sn = hard_regno_nregs[sr][GET_MODE (dest)];
1263
  if ((dr > sr && dr < sr + sn)
1264
      || (sr > dr && sr < dr + dn))
1265
    return;
1266
 
1267
  /* If SRC had no assigned mode (i.e. we didn't know it was live)
1268
     assign it now and assume the value came from an input argument
1269
     or somesuch.  */
1270
  if (vd->e[sr].mode == VOIDmode)
1271
    set_value_regno (sr, vd->e[dr].mode, vd);
1272
 
1273
  /* If we are narrowing the input to a smaller number of hard regs,
1274
     and it is in big endian, we are really extracting a high part.
1275
     Since we generally associate a low part of a value with the value itself,
1276
     we must not do the same for the high part.
1277
     Note we can still get low parts for the same mode combination through
1278
     a two-step copy involving differently sized hard regs.
1279
     Assume hard regs fr* are 32 bits bits each, while r* are 64 bits each:
1280
     (set (reg:DI r0) (reg:DI fr0))
1281
     (set (reg:SI fr2) (reg:SI r0))
1282
     loads the low part of (reg:DI fr0) - i.e. fr1 - into fr2, while:
1283
     (set (reg:SI fr2) (reg:SI fr0))
1284
     loads the high part of (reg:DI fr0) into fr2.
1285
 
1286
     We can't properly represent the latter case in our tables, so don't
1287
     record anything then.  */
1288
  else if (sn < (unsigned int) hard_regno_nregs[sr][vd->e[sr].mode]
1289
           && (GET_MODE_SIZE (vd->e[sr].mode) > UNITS_PER_WORD
1290
               ? WORDS_BIG_ENDIAN : BYTES_BIG_ENDIAN))
1291
    return;
1292
 
1293
  /* If SRC had been assigned a mode narrower than the copy, we can't
1294
     link DEST into the chain, because not all of the pieces of the
1295
     copy came from oldest_regno.  */
1296
  else if (sn > (unsigned int) hard_regno_nregs[sr][vd->e[sr].mode])
1297
    return;
1298
 
1299
  /* Link DR at the end of the value chain used by SR.  */
1300
 
1301
  vd->e[dr].oldest_regno = vd->e[sr].oldest_regno;
1302
 
1303
  for (i = sr; vd->e[i].next_regno != INVALID_REGNUM; i = vd->e[i].next_regno)
1304
    continue;
1305
  vd->e[i].next_regno = dr;
1306
 
1307
#ifdef ENABLE_CHECKING
1308
  validate_value_data (vd);
1309
#endif
1310
}
1311
 
1312
/* Return true if a mode change from ORIG to NEW is allowed for REGNO.  */
1313
 
1314
static bool
1315
mode_change_ok (enum machine_mode orig_mode, enum machine_mode new_mode,
1316
                unsigned int regno ATTRIBUTE_UNUSED)
1317
{
1318
  if (GET_MODE_SIZE (orig_mode) < GET_MODE_SIZE (new_mode))
1319
    return false;
1320
 
1321
#ifdef CANNOT_CHANGE_MODE_CLASS
1322
  return !REG_CANNOT_CHANGE_MODE_P (regno, orig_mode, new_mode);
1323
#endif
1324
 
1325
  return true;
1326
}
1327
 
1328
/* Register REGNO was originally set in ORIG_MODE.  It - or a copy of it -
1329
   was copied in COPY_MODE to COPY_REGNO, and then COPY_REGNO was accessed
1330
   in NEW_MODE.
1331
   Return a NEW_MODE rtx for REGNO if that's OK, otherwise return NULL_RTX.  */
1332
 
1333
static rtx
1334
maybe_mode_change (enum machine_mode orig_mode, enum machine_mode copy_mode,
1335
                   enum machine_mode new_mode, unsigned int regno,
1336
                   unsigned int copy_regno ATTRIBUTE_UNUSED)
1337
{
1338
  if (orig_mode == new_mode)
1339
    return gen_rtx_raw_REG (new_mode, regno);
1340
  else if (mode_change_ok (orig_mode, new_mode, regno))
1341
    {
1342
      int copy_nregs = hard_regno_nregs[copy_regno][copy_mode];
1343
      int use_nregs = hard_regno_nregs[copy_regno][new_mode];
1344
      int copy_offset
1345
        = GET_MODE_SIZE (copy_mode) / copy_nregs * (copy_nregs - use_nregs);
1346
      int offset
1347
        = GET_MODE_SIZE (orig_mode) - GET_MODE_SIZE (new_mode) - copy_offset;
1348
      int byteoffset = offset % UNITS_PER_WORD;
1349
      int wordoffset = offset - byteoffset;
1350
 
1351
      offset = ((WORDS_BIG_ENDIAN ? wordoffset : 0)
1352
                + (BYTES_BIG_ENDIAN ? byteoffset : 0));
1353
      return gen_rtx_raw_REG (new_mode,
1354
                              regno + subreg_regno_offset (regno, orig_mode,
1355
                                                           offset,
1356
                                                           new_mode));
1357
    }
1358
  return NULL_RTX;
1359
}
1360
 
1361
/* Find the oldest copy of the value contained in REGNO that is in
1362
   register class CL and has mode MODE.  If found, return an rtx
1363
   of that oldest register, otherwise return NULL.  */
1364
 
1365
static rtx
1366
find_oldest_value_reg (enum reg_class cl, rtx reg, struct value_data *vd)
1367
{
1368
  unsigned int regno = REGNO (reg);
1369
  enum machine_mode mode = GET_MODE (reg);
1370
  unsigned int i;
1371
 
1372
  /* If we are accessing REG in some mode other that what we set it in,
1373
     make sure that the replacement is valid.  In particular, consider
1374
        (set (reg:DI r11) (...))
1375
        (set (reg:SI r9) (reg:SI r11))
1376
        (set (reg:SI r10) (...))
1377
        (set (...) (reg:DI r9))
1378
     Replacing r9 with r11 is invalid.  */
1379
  if (mode != vd->e[regno].mode)
1380
    {
1381
      if (hard_regno_nregs[regno][mode]
1382
          > hard_regno_nregs[regno][vd->e[regno].mode])
1383
        return NULL_RTX;
1384
    }
1385
 
1386
  for (i = vd->e[regno].oldest_regno; i != regno; i = vd->e[i].next_regno)
1387
    {
1388
      enum machine_mode oldmode = vd->e[i].mode;
1389
      rtx new;
1390
      unsigned int last;
1391
 
1392
      for (last = i; last < i + hard_regno_nregs[i][mode]; last++)
1393
        if (!TEST_HARD_REG_BIT (reg_class_contents[cl], last))
1394
          return NULL_RTX;
1395
 
1396
      new = maybe_mode_change (oldmode, vd->e[regno].mode, mode, i, regno);
1397
      if (new)
1398
        {
1399
          ORIGINAL_REGNO (new) = ORIGINAL_REGNO (reg);
1400
          REG_ATTRS (new) = REG_ATTRS (reg);
1401
          return new;
1402
        }
1403
    }
1404
 
1405
  return NULL_RTX;
1406
}
1407
 
1408
/* If possible, replace the register at *LOC with the oldest register
1409
   in register class CL.  Return true if successfully replaced.  */
1410
 
1411
static bool
1412
replace_oldest_value_reg (rtx *loc, enum reg_class cl, rtx insn,
1413
                          struct value_data *vd)
1414
{
1415
  rtx new = find_oldest_value_reg (cl, *loc, vd);
1416
  if (new)
1417
    {
1418
      if (dump_file)
1419
        fprintf (dump_file, "insn %u: replaced reg %u with %u\n",
1420
                 INSN_UID (insn), REGNO (*loc), REGNO (new));
1421
 
1422
      validate_change (insn, loc, new, 1);
1423
      return true;
1424
    }
1425
  return false;
1426
}
1427
 
1428
/* Similar to replace_oldest_value_reg, but *LOC contains an address.
1429
   Adapted from find_reloads_address_1.  CL is INDEX_REG_CLASS or
1430
   BASE_REG_CLASS depending on how the register is being considered.  */
1431
 
1432
static bool
1433
replace_oldest_value_addr (rtx *loc, enum reg_class cl,
1434
                           enum machine_mode mode, rtx insn,
1435
                           struct value_data *vd)
1436
{
1437
  rtx x = *loc;
1438
  RTX_CODE code = GET_CODE (x);
1439
  const char *fmt;
1440
  int i, j;
1441
  bool changed = false;
1442
 
1443
  switch (code)
1444
    {
1445
    case PLUS:
1446
      {
1447
        rtx orig_op0 = XEXP (x, 0);
1448
        rtx orig_op1 = XEXP (x, 1);
1449
        RTX_CODE code0 = GET_CODE (orig_op0);
1450
        RTX_CODE code1 = GET_CODE (orig_op1);
1451
        rtx op0 = orig_op0;
1452
        rtx op1 = orig_op1;
1453
        rtx *locI = NULL;
1454
        rtx *locB = NULL;
1455
        enum rtx_code index_code = SCRATCH;
1456
 
1457
        if (GET_CODE (op0) == SUBREG)
1458
          {
1459
            op0 = SUBREG_REG (op0);
1460
            code0 = GET_CODE (op0);
1461
          }
1462
 
1463
        if (GET_CODE (op1) == SUBREG)
1464
          {
1465
            op1 = SUBREG_REG (op1);
1466
            code1 = GET_CODE (op1);
1467
          }
1468
 
1469
        if (code0 == MULT || code0 == SIGN_EXTEND || code0 == TRUNCATE
1470
            || code0 == ZERO_EXTEND || code1 == MEM)
1471
          {
1472
            locI = &XEXP (x, 0);
1473
            locB = &XEXP (x, 1);
1474
            index_code = GET_CODE (*locI);
1475
          }
1476
        else if (code1 == MULT || code1 == SIGN_EXTEND || code1 == TRUNCATE
1477
                 || code1 == ZERO_EXTEND || code0 == MEM)
1478
          {
1479
            locI = &XEXP (x, 1);
1480
            locB = &XEXP (x, 0);
1481
            index_code = GET_CODE (*locI);
1482
          }
1483
        else if (code0 == CONST_INT || code0 == CONST
1484
                 || code0 == SYMBOL_REF || code0 == LABEL_REF)
1485
          {
1486
            locB = &XEXP (x, 1);
1487
            index_code = GET_CODE (XEXP (x, 0));
1488
          }
1489
        else if (code1 == CONST_INT || code1 == CONST
1490
                 || code1 == SYMBOL_REF || code1 == LABEL_REF)
1491
          {
1492
            locB = &XEXP (x, 0);
1493
            index_code = GET_CODE (XEXP (x, 1));
1494
          }
1495
        else if (code0 == REG && code1 == REG)
1496
          {
1497
            int index_op;
1498
            unsigned regno0 = REGNO (op0), regno1 = REGNO (op1);
1499
 
1500
            if (REGNO_OK_FOR_INDEX_P (regno0)
1501
                && regno_ok_for_base_p (regno1, mode, PLUS, REG))
1502
              index_op = 0;
1503
            else if (REGNO_OK_FOR_INDEX_P (regno1)
1504
                     && regno_ok_for_base_p (regno0, mode, PLUS, REG))
1505
              index_op = 1;
1506
            else if (regno_ok_for_base_p (regno1, mode, PLUS, REG))
1507
              index_op = 0;
1508
            else if (regno_ok_for_base_p (regno0, mode, PLUS, REG))
1509
              index_op = 1;
1510
            else if (REGNO_OK_FOR_INDEX_P (regno1))
1511
              index_op = 1;
1512
            else
1513
              index_op = 0;
1514
 
1515
            locI = &XEXP (x, index_op);
1516
            locB = &XEXP (x, !index_op);
1517
            index_code = GET_CODE (*locI);
1518
          }
1519
        else if (code0 == REG)
1520
          {
1521
            locI = &XEXP (x, 0);
1522
            locB = &XEXP (x, 1);
1523
            index_code = GET_CODE (*locI);
1524
          }
1525
        else if (code1 == REG)
1526
          {
1527
            locI = &XEXP (x, 1);
1528
            locB = &XEXP (x, 0);
1529
            index_code = GET_CODE (*locI);
1530
          }
1531
 
1532
        if (locI)
1533
          changed |= replace_oldest_value_addr (locI, INDEX_REG_CLASS, mode,
1534
                                                insn, vd);
1535
        if (locB)
1536
          changed |= replace_oldest_value_addr (locB,
1537
                                                base_reg_class (mode, PLUS,
1538
                                                                index_code),
1539
                                                mode, insn, vd);
1540
        return changed;
1541
      }
1542
 
1543
    case POST_INC:
1544
    case POST_DEC:
1545
    case POST_MODIFY:
1546
    case PRE_INC:
1547
    case PRE_DEC:
1548
    case PRE_MODIFY:
1549
      return false;
1550
 
1551
    case MEM:
1552
      return replace_oldest_value_mem (x, insn, vd);
1553
 
1554
    case REG:
1555
      return replace_oldest_value_reg (loc, cl, insn, vd);
1556
 
1557
    default:
1558
      break;
1559
    }
1560
 
1561
  fmt = GET_RTX_FORMAT (code);
1562
  for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1563
    {
1564
      if (fmt[i] == 'e')
1565
        changed |= replace_oldest_value_addr (&XEXP (x, i), cl, mode,
1566
                                              insn, vd);
1567
      else if (fmt[i] == 'E')
1568
        for (j = XVECLEN (x, i) - 1; j >= 0; j--)
1569
          changed |= replace_oldest_value_addr (&XVECEXP (x, i, j), cl,
1570
                                                mode, insn, vd);
1571
    }
1572
 
1573
  return changed;
1574
}
1575
 
1576
/* Similar to replace_oldest_value_reg, but X contains a memory.  */
1577
 
1578
static bool
1579
replace_oldest_value_mem (rtx x, rtx insn, struct value_data *vd)
1580
{
1581
  return replace_oldest_value_addr (&XEXP (x, 0),
1582
                                    base_reg_class (GET_MODE (x), MEM,
1583
                                                    SCRATCH),
1584
                                    GET_MODE (x), insn, vd);
1585
}
1586
 
1587
/* Perform the forward copy propagation on basic block BB.  */
1588
 
1589
static bool
1590
copyprop_hardreg_forward_1 (basic_block bb, struct value_data *vd)
1591
{
1592
  bool changed = false;
1593
  rtx insn;
1594
 
1595
  for (insn = BB_HEAD (bb); ; insn = NEXT_INSN (insn))
1596
    {
1597
      int n_ops, i, alt, predicated;
1598
      bool is_asm, any_replacements;
1599
      rtx set;
1600
      bool replaced[MAX_RECOG_OPERANDS];
1601
 
1602
      if (! INSN_P (insn))
1603
        {
1604
          if (insn == BB_END (bb))
1605
            break;
1606
          else
1607
            continue;
1608
        }
1609
 
1610
      set = single_set (insn);
1611
      extract_insn (insn);
1612
      if (! constrain_operands (1))
1613
        fatal_insn_not_found (insn);
1614
      preprocess_constraints ();
1615
      alt = which_alternative;
1616
      n_ops = recog_data.n_operands;
1617
      is_asm = asm_noperands (PATTERN (insn)) >= 0;
1618
 
1619
      /* Simplify the code below by rewriting things to reflect
1620
         matching constraints.  Also promote OP_OUT to OP_INOUT
1621
         in predicated instructions.  */
1622
 
1623
      predicated = GET_CODE (PATTERN (insn)) == COND_EXEC;
1624
      for (i = 0; i < n_ops; ++i)
1625
        {
1626
          int matches = recog_op_alt[i][alt].matches;
1627
          if (matches >= 0)
1628
            recog_op_alt[i][alt].cl = recog_op_alt[matches][alt].cl;
1629
          if (matches >= 0 || recog_op_alt[i][alt].matched >= 0
1630
              || (predicated && recog_data.operand_type[i] == OP_OUT))
1631
            recog_data.operand_type[i] = OP_INOUT;
1632
        }
1633
 
1634
      /* For each earlyclobber operand, zap the value data.  */
1635
      for (i = 0; i < n_ops; i++)
1636
        if (recog_op_alt[i][alt].earlyclobber)
1637
          kill_value (recog_data.operand[i], vd);
1638
 
1639
      /* Within asms, a clobber cannot overlap inputs or outputs.
1640
         I wouldn't think this were true for regular insns, but
1641
         scan_rtx treats them like that...  */
1642
      note_stores (PATTERN (insn), kill_clobbered_value, vd);
1643
 
1644
      /* Kill all auto-incremented values.  */
1645
      /* ??? REG_INC is useless, since stack pushes aren't done that way.  */
1646
      for_each_rtx (&PATTERN (insn), kill_autoinc_value, vd);
1647
 
1648
      /* Kill all early-clobbered operands.  */
1649
      for (i = 0; i < n_ops; i++)
1650
        if (recog_op_alt[i][alt].earlyclobber)
1651
          kill_value (recog_data.operand[i], vd);
1652
 
1653
      /* Special-case plain move instructions, since we may well
1654
         be able to do the move from a different register class.  */
1655
      if (set && REG_P (SET_SRC (set)))
1656
        {
1657
          rtx src = SET_SRC (set);
1658
          unsigned int regno = REGNO (src);
1659
          enum machine_mode mode = GET_MODE (src);
1660
          unsigned int i;
1661
          rtx new;
1662
 
1663
          /* If we are accessing SRC in some mode other that what we
1664
             set it in, make sure that the replacement is valid.  */
1665
          if (mode != vd->e[regno].mode)
1666
            {
1667
              if (hard_regno_nregs[regno][mode]
1668
                  > hard_regno_nregs[regno][vd->e[regno].mode])
1669
                goto no_move_special_case;
1670
            }
1671
 
1672
          /* If the destination is also a register, try to find a source
1673
             register in the same class.  */
1674
          if (REG_P (SET_DEST (set)))
1675
            {
1676
              new = find_oldest_value_reg (REGNO_REG_CLASS (regno), src, vd);
1677
              if (new && validate_change (insn, &SET_SRC (set), new, 0))
1678
                {
1679
                  if (dump_file)
1680
                    fprintf (dump_file,
1681
                             "insn %u: replaced reg %u with %u\n",
1682
                             INSN_UID (insn), regno, REGNO (new));
1683
                  changed = true;
1684
                  goto did_replacement;
1685
                }
1686
            }
1687
 
1688
          /* Otherwise, try all valid registers and see if its valid.  */
1689
          for (i = vd->e[regno].oldest_regno; i != regno;
1690
               i = vd->e[i].next_regno)
1691
            {
1692
              new = maybe_mode_change (vd->e[i].mode, vd->e[regno].mode,
1693
                                       mode, i, regno);
1694
              if (new != NULL_RTX)
1695
                {
1696
                  if (validate_change (insn, &SET_SRC (set), new, 0))
1697
                    {
1698
                      ORIGINAL_REGNO (new) = ORIGINAL_REGNO (src);
1699
                      REG_ATTRS (new) = REG_ATTRS (src);
1700
                      if (dump_file)
1701
                        fprintf (dump_file,
1702
                                 "insn %u: replaced reg %u with %u\n",
1703
                                 INSN_UID (insn), regno, REGNO (new));
1704
                      changed = true;
1705
                      goto did_replacement;
1706
                    }
1707
                }
1708
            }
1709
        }
1710
      no_move_special_case:
1711
 
1712
      any_replacements = false;
1713
 
1714
      /* For each input operand, replace a hard register with the
1715
         eldest live copy that's in an appropriate register class.  */
1716
      for (i = 0; i < n_ops; i++)
1717
        {
1718
          replaced[i] = false;
1719
 
1720
          /* Don't scan match_operand here, since we've no reg class
1721
             information to pass down.  Any operands that we could
1722
             substitute in will be represented elsewhere.  */
1723
          if (recog_data.constraints[i][0] == '\0')
1724
            continue;
1725
 
1726
          /* Don't replace in asms intentionally referencing hard regs.  */
1727
          if (is_asm && REG_P (recog_data.operand[i])
1728
              && (REGNO (recog_data.operand[i])
1729
                  == ORIGINAL_REGNO (recog_data.operand[i])))
1730
            continue;
1731
 
1732
          if (recog_data.operand_type[i] == OP_IN)
1733
            {
1734
              if (recog_op_alt[i][alt].is_address)
1735
                replaced[i]
1736
                  = replace_oldest_value_addr (recog_data.operand_loc[i],
1737
                                               recog_op_alt[i][alt].cl,
1738
                                               VOIDmode, insn, vd);
1739
              else if (REG_P (recog_data.operand[i]))
1740
                replaced[i]
1741
                  = replace_oldest_value_reg (recog_data.operand_loc[i],
1742
                                              recog_op_alt[i][alt].cl,
1743
                                              insn, vd);
1744
              else if (MEM_P (recog_data.operand[i]))
1745
                replaced[i] = replace_oldest_value_mem (recog_data.operand[i],
1746
                                                        insn, vd);
1747
            }
1748
          else if (MEM_P (recog_data.operand[i]))
1749
            replaced[i] = replace_oldest_value_mem (recog_data.operand[i],
1750
                                                    insn, vd);
1751
 
1752
          /* If we performed any replacement, update match_dups.  */
1753
          if (replaced[i])
1754
            {
1755
              int j;
1756
              rtx new;
1757
 
1758
              new = *recog_data.operand_loc[i];
1759
              recog_data.operand[i] = new;
1760
              for (j = 0; j < recog_data.n_dups; j++)
1761
                if (recog_data.dup_num[j] == i)
1762
                  validate_change (insn, recog_data.dup_loc[j], new, 1);
1763
 
1764
              any_replacements = true;
1765
            }
1766
        }
1767
 
1768
      if (any_replacements)
1769
        {
1770
          if (! apply_change_group ())
1771
            {
1772
              for (i = 0; i < n_ops; i++)
1773
                if (replaced[i])
1774
                  {
1775
                    rtx old = *recog_data.operand_loc[i];
1776
                    recog_data.operand[i] = old;
1777
                  }
1778
 
1779
              if (dump_file)
1780
                fprintf (dump_file,
1781
                         "insn %u: reg replacements not verified\n",
1782
                         INSN_UID (insn));
1783
            }
1784
          else
1785
            changed = true;
1786
        }
1787
 
1788
    did_replacement:
1789
      /* Clobber call-clobbered registers.  */
1790
      if (CALL_P (insn))
1791
        for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1792
          if (TEST_HARD_REG_BIT (regs_invalidated_by_call, i))
1793
            kill_value_regno (i, 1, vd);
1794
 
1795
      /* Notice stores.  */
1796
      note_stores (PATTERN (insn), kill_set_value, vd);
1797
 
1798
      /* Notice copies.  */
1799
      if (set && REG_P (SET_DEST (set)) && REG_P (SET_SRC (set)))
1800
        copy_value (SET_DEST (set), SET_SRC (set), vd);
1801
 
1802
      if (insn == BB_END (bb))
1803
        break;
1804
    }
1805
 
1806
  return changed;
1807
}
1808
 
1809
/* Main entry point for the forward copy propagation optimization.  */
1810
 
1811
static void
1812
copyprop_hardreg_forward (void)
1813
{
1814
  struct value_data *all_vd;
1815
  bool need_refresh;
1816
  basic_block bb;
1817
  sbitmap visited;
1818
 
1819
  need_refresh = false;
1820
 
1821
  all_vd = XNEWVEC (struct value_data, last_basic_block);
1822
 
1823
  visited = sbitmap_alloc (last_basic_block);
1824
  sbitmap_zero (visited);
1825
 
1826
  FOR_EACH_BB (bb)
1827
    {
1828
      SET_BIT (visited, bb->index);
1829
 
1830
      /* If a block has a single predecessor, that we've already
1831
         processed, begin with the value data that was live at
1832
         the end of the predecessor block.  */
1833
      /* ??? Ought to use more intelligent queuing of blocks.  */
1834
      if (single_pred_p (bb)
1835
          && TEST_BIT (visited, single_pred (bb)->index)
1836
          && ! (single_pred_edge (bb)->flags & (EDGE_ABNORMAL_CALL | EDGE_EH)))
1837
        all_vd[bb->index] = all_vd[single_pred (bb)->index];
1838
      else
1839
        init_value_data (all_vd + bb->index);
1840
 
1841
      if (copyprop_hardreg_forward_1 (bb, all_vd + bb->index))
1842
        need_refresh = true;
1843
    }
1844
 
1845
  sbitmap_free (visited);
1846
 
1847
  if (need_refresh)
1848
    {
1849
      if (dump_file)
1850
        fputs ("\n\n", dump_file);
1851
 
1852
      /* ??? Irritatingly, delete_noop_moves does not take a set of blocks
1853
         to scan, so we have to do a life update with no initial set of
1854
         blocks Just In Case.  */
1855
      delete_noop_moves ();
1856
      update_life_info (NULL, UPDATE_LIFE_GLOBAL_RM_NOTES,
1857
                        PROP_DEATH_NOTES
1858
                        | PROP_SCAN_DEAD_CODE
1859
                        | PROP_KILL_DEAD_CODE);
1860
    }
1861
 
1862
  free (all_vd);
1863
}
1864
 
1865
/* Dump the value chain data to stderr.  */
1866
 
1867
void
1868
debug_value_data (struct value_data *vd)
1869
{
1870
  HARD_REG_SET set;
1871
  unsigned int i, j;
1872
 
1873
  CLEAR_HARD_REG_SET (set);
1874
 
1875
  for (i = 0; i < FIRST_PSEUDO_REGISTER; ++i)
1876
    if (vd->e[i].oldest_regno == i)
1877
      {
1878
        if (vd->e[i].mode == VOIDmode)
1879
          {
1880
            if (vd->e[i].next_regno != INVALID_REGNUM)
1881
              fprintf (stderr, "[%u] Bad next_regno for empty chain (%u)\n",
1882
                       i, vd->e[i].next_regno);
1883
            continue;
1884
          }
1885
 
1886
        SET_HARD_REG_BIT (set, i);
1887
        fprintf (stderr, "[%u %s] ", i, GET_MODE_NAME (vd->e[i].mode));
1888
 
1889
        for (j = vd->e[i].next_regno;
1890
             j != INVALID_REGNUM;
1891
             j = vd->e[j].next_regno)
1892
          {
1893
            if (TEST_HARD_REG_BIT (set, j))
1894
              {
1895
                fprintf (stderr, "[%u] Loop in regno chain\n", j);
1896
                return;
1897
              }
1898
 
1899
            if (vd->e[j].oldest_regno != i)
1900
              {
1901
                fprintf (stderr, "[%u] Bad oldest_regno (%u)\n",
1902
                         j, vd->e[j].oldest_regno);
1903
                return;
1904
              }
1905
            SET_HARD_REG_BIT (set, j);
1906
            fprintf (stderr, "[%u %s] ", j, GET_MODE_NAME (vd->e[j].mode));
1907
          }
1908
        fputc ('\n', stderr);
1909
      }
1910
 
1911
  for (i = 0; i < FIRST_PSEUDO_REGISTER; ++i)
1912
    if (! TEST_HARD_REG_BIT (set, i)
1913
        && (vd->e[i].mode != VOIDmode
1914
            || vd->e[i].oldest_regno != i
1915
            || vd->e[i].next_regno != INVALID_REGNUM))
1916
      fprintf (stderr, "[%u] Non-empty reg in chain (%s %u %i)\n",
1917
               i, GET_MODE_NAME (vd->e[i].mode), vd->e[i].oldest_regno,
1918
               vd->e[i].next_regno);
1919
}
1920
 
1921
#ifdef ENABLE_CHECKING
1922
static void
1923
validate_value_data (struct value_data *vd)
1924
{
1925
  HARD_REG_SET set;
1926
  unsigned int i, j;
1927
 
1928
  CLEAR_HARD_REG_SET (set);
1929
 
1930
  for (i = 0; i < FIRST_PSEUDO_REGISTER; ++i)
1931
    if (vd->e[i].oldest_regno == i)
1932
      {
1933
        if (vd->e[i].mode == VOIDmode)
1934
          {
1935
            if (vd->e[i].next_regno != INVALID_REGNUM)
1936
              internal_error ("validate_value_data: [%u] Bad next_regno for empty chain (%u)",
1937
                              i, vd->e[i].next_regno);
1938
            continue;
1939
          }
1940
 
1941
        SET_HARD_REG_BIT (set, i);
1942
 
1943
        for (j = vd->e[i].next_regno;
1944
             j != INVALID_REGNUM;
1945
             j = vd->e[j].next_regno)
1946
          {
1947
            if (TEST_HARD_REG_BIT (set, j))
1948
              internal_error ("validate_value_data: Loop in regno chain (%u)",
1949
                              j);
1950
            if (vd->e[j].oldest_regno != i)
1951
              internal_error ("validate_value_data: [%u] Bad oldest_regno (%u)",
1952
                              j, vd->e[j].oldest_regno);
1953
 
1954
            SET_HARD_REG_BIT (set, j);
1955
          }
1956
      }
1957
 
1958
  for (i = 0; i < FIRST_PSEUDO_REGISTER; ++i)
1959
    if (! TEST_HARD_REG_BIT (set, i)
1960
        && (vd->e[i].mode != VOIDmode
1961
            || vd->e[i].oldest_regno != i
1962
            || vd->e[i].next_regno != INVALID_REGNUM))
1963
      internal_error ("validate_value_data: [%u] Non-empty reg in chain (%s %u %i)",
1964
                      i, GET_MODE_NAME (vd->e[i].mode), vd->e[i].oldest_regno,
1965
                      vd->e[i].next_regno);
1966
}
1967
#endif
1968
 
1969
static bool
1970
gate_handle_regrename (void)
1971
{
1972
  return (optimize > 0 && (flag_rename_registers || flag_cprop_registers));
1973
}
1974
 
1975
 
1976
/* Run the regrename and cprop passes.  */
1977
static unsigned int
1978
rest_of_handle_regrename (void)
1979
{
1980
  if (flag_rename_registers)
1981
    regrename_optimize ();
1982
  if (flag_cprop_registers)
1983
    copyprop_hardreg_forward ();
1984
  return 0;
1985
}
1986
 
1987
struct tree_opt_pass pass_regrename =
1988
{
1989
  "rnreg",                              /* name */
1990
  gate_handle_regrename,                /* gate */
1991
  rest_of_handle_regrename,             /* execute */
1992
  NULL,                                 /* sub */
1993
  NULL,                                 /* next */
1994
  0,                                    /* static_pass_number */
1995
  TV_RENAME_REGISTERS,                  /* tv_id */
1996
  0,                                    /* properties_required */
1997
  0,                                    /* properties_provided */
1998
  0,                                    /* properties_destroyed */
1999
  0,                                    /* todo_flags_start */
2000
  TODO_dump_func,                       /* todo_flags_finish */
2001
  'n'                                   /* letter */
2002
};
2003
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.