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

Subversion Repositories or1k

[/] [or1k/] [branches/] [stable_0_2_x/] [or1ksim/] [cuc/] [memory.c] - Blame information for rev 1308

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

Line No. Rev Author Line
1 879 markom
/* memory.c -- OpenRISC Custom Unit Compiler, memory optimization and scheduling
2
 *    Copyright (C) 2002 Marko Mlinar, markom@opencores.org
3
 *
4
 *    This file is part of OpenRISC 1000 Architectural Simulator.
5
 *
6
 *    This program is free software; you can redistribute it and/or modify
7
 *    it under the terms of the GNU General Public License as published by
8
 *    the Free Software Foundation; either version 2 of the License, or
9
 *    (at your option) any later version.
10
 *
11
 *    This program is distributed in the hope that it will be useful,
12
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 *    GNU General Public License for more details.
15
 *
16
 *    You should have received a copy of the GNU General Public License
17
 *    along with this program; if not, write to the Free Software
18
 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
 
20
#include <stdio.h>
21
#include <stdlib.h>
22
#include <stdarg.h>
23
#include <assert.h>
24 1308 phoenix
 
25
#include "abstract.h"
26 897 markom
#include "sim-config.h"
27 879 markom
#include "cuc.h"
28
#include "insn.h"
29
 
30 941 markom
 
31
/* Cleans memory & data dependencies */
32
void clean_deps (cuc_func *f)
33
{
34
  int b, i;
35
  dep_list *t;
36
  for (b = 0; b < f->num_bb; b++) {
37
    for (i = 0; i < f->bb[b].ninsn; i++) {
38
      t = f->bb[b].insn[i].dep;
39
      while (t) {
40
        dep_list *tmp = t;
41
        t = t->next;
42
        free (tmp);
43
      }
44
      f->bb[b].insn[i].dep = NULL;
45
    }
46
 
47
    t = f->bb[b].mdep;
48
    while (t) {
49
      dep_list *tmp = t;
50
      t = t->next;
51
      free (tmp);
52
    }
53
    f->bb[b].mdep = NULL;
54
  }
55
 
56
  f->nmsched = 0;
57
}
58
 
59 879 markom
/* Checks for memory conflicts between two instructions; returns 1 if detected
60
 
61
static int check_memory_conflict (cuc_func *f, cuc_insn *a, cuc_insn *b, int otype)
62
{
63
  switch (otype) {
64 897 markom
    case MO_EXACT: /* exact */
65
    case MO_STRONG: /* strong */
66 879 markom
      return 1;
67 897 markom
    case MO_WEAK: /* weak */
68 879 markom
      assert (a->type & IT_MEMORY);
69
      assert (b->type & IT_MEMORY);
70
      if ((a->opt[1] & OPT_REF) && f->INSN(a->op[1]).index == II_ADD
71
        &&(b->opt[1] & OPT_REF) && f->INSN(b->op[1]).index == II_ADD) {
72
        int aw, bw;
73
        assert ((aw = II_MEM_WIDTH (a->index)) >= 0);
74
        assert ((bw = II_MEM_WIDTH (b->index)) >= 0);
75
 
76
        a = &f->INSN(a->op[1]);
77
        b = &f->INSN(b->op[1]);
78
        if (a->opt[1] != b->opt[1] || a->op[1] != b->op[1]
79
         || a->opt[2] != OPT_CONST || b->opt[2] != OPT_CONST) return 1;
80
 
81
        /* Check if they overlap */
82
        if (a->op[2] >= b->op[2] && a->op[2] < b->op[2] + bw) return 1;
83
        if (b->op[2] >= a->op[2] && b->op[2] < a->op[2] + aw) return 1;
84
        return 0;
85
      } else return 1;
86 897 markom
    case MO_NONE: /* none */
87 879 markom
      return 0;
88
    default:
89
      assert (0);
90
  }
91
  return 1;
92
}
93
 
94
/* Adds memory dependencies based on ordering type:
95
 
96
void add_memory_dep (cuc_func *f, int otype)
97
{
98
  int b, i;
99
  dep_list *all_mem = NULL;
100
 
101
  for (b = 0; b < f->num_bb; b++) {
102
    cuc_insn *insn = f->bb[b].insn;
103
    for (i = 0; i < f->bb[b].ninsn; i++)
104
      if (insn[i].type & IT_MEMORY) {
105
        dep_list *tmp = all_mem;
106
        while (tmp) {
107 997 markom
          //PRINTF ("%x %x\n", REF (b,i), tmp->ref);
108 879 markom
          if (check_memory_conflict (f, &insn[i], &f->INSN(tmp->ref), otype))
109
            add_dep (&insn[i].dep, tmp->ref);
110
          tmp = tmp->next;
111
        }
112
        add_dep (&all_mem, REF (b, i));
113
      }
114
  }
115
  dispose_list (&all_mem);
116
}
117
 
118 953 markom
/* Check if they address the same location, so we can join them */
119
static int same_transfers (cuc_func *f, int otype)
120
{
121
  int i, j;
122
  int modified = 0;
123
  if (otype == MO_WEAK || otype == MO_NONE) {
124
    for (i = 1, j = 1; i < f->nmsched; i++)
125
      /* Exclude memory stores and different memory types */
126
      if (f->mtype[i - 1] == f->mtype[i] && f->mtype[i] & MT_LOAD) {
127
        cuc_insn *a = &f->INSN(f->msched[i - 1]);
128
        cuc_insn *b = &f->INSN(f->msched[i]);
129
        if ((a->opt[1] & OPT_REF) && f->INSN(a->op[1]).index == II_ADD
130
          &&(b->opt[1] & OPT_REF) && f->INSN(b->op[1]).index == II_ADD) {
131
          a = &f->INSN(a->op[1]);
132
          b = &f->INSN(b->op[1]);
133
          /* Not in usual form? */
134
          if (a->opt[1] != b->opt[1] || a->op[1] != b->op[1]
135
           || a->opt[2] != OPT_CONST || b->opt[2] != OPT_CONST) goto keep;
136
 
137 997 markom
          //PRINTF ("%i %i, ", a->op[2], b->op[2]);
138 953 markom
 
139
          /* Check if they are the same => do not copy */
140
          if (a->op[2] == b->op[2]
141
            && REF_BB(f->msched[i - 1]) == REF_BB(f->msched[i])) {
142
            /* yes => remove actual instruction */
143
            int t1 = MIN (f->msched[i - 1], f->msched[i]);
144
            int t2 = MAX (f->msched[i - 1], f->msched[i]);
145
            int b, i, j;
146
            cucdebug (2, "Removing %x_%x and using %x_%x instead.\n",
147
              REF_BB(t2), REF_I(t2), REF_BB(t1), REF_I(t1));
148
            change_insn_type (&f->INSN(t2), II_NOP);
149
            modified = 1;
150
            /* Update references */
151
            for (b = 0; b < f->num_bb; b++)
152
              for (i = 0; i < f->bb[b].ninsn; i++)
153
                for (j = 0; j < MAX_OPERANDS; j++)
154
                  if (f->bb[b].insn[i].opt[j] & OPT_REF && f->bb[b].insn[i].op[j] == t2)
155
                    f->bb[b].insn[i].op[j] = t1;
156
 
157
          } else goto keep;
158
        } else goto keep;
159
      } else {
160
keep:
161
        f->msched[j] = f->msched[i];
162
        f->mtype[j++] = f->mtype[i];
163
      }
164
    f->nmsched = j;
165
  }
166
  return modified;
167
}
168
 
169
/* Check if two consecutive lb[zs] can be joined into lhz and if
170
   two consecutive lh[zs] can be joined into lwz */
171
static int join_transfers (cuc_func *f, int otype)
172
{
173
  int i, j;
174
  int modified = 0;
175
 
176
  /* We can change width even with strong memory ordering */
177
  if (otype == MO_WEAK || otype == MO_NONE || otype == MO_STRONG) {
178
    for (i = 1, j = 1; i < f->nmsched; i++)
179
      /* Exclude memory stores and different memory types */
180
      if (f->mtype[i - 1] == f->mtype[i] && f->mtype[i] & MT_LOAD) {
181
        cuc_insn *a = &f->INSN(f->msched[i - 1]);
182
        cuc_insn *b = &f->INSN(f->msched[i]);
183
        int aw = f->mtype[i - 1] & MT_WIDTH;
184
        if ((a->opt[1] & OPT_REF) && f->INSN(a->op[1]).index == II_ADD
185
          &&(b->opt[1] & OPT_REF) && f->INSN(b->op[1]).index == II_ADD) {
186
          a = &f->INSN(a->op[1]);
187
          b = &f->INSN(b->op[1]);
188
 
189
          /* Not in usual form? */
190
          if (a->opt[1] != b->opt[1] || a->op[1] != b->op[1]
191
           || a->opt[2] != OPT_CONST || b->opt[2] != OPT_CONST) goto keep;
192
 
193
          /* Check if they touch together */
194
          if (a->op[2] + aw == b->op[2]
195
            && REF_BB(f->msched[i - 1]) == REF_BB(f->msched[i])) {
196
            /* yes => remove second instruction */
197
            int t1 = MIN (f->msched[i - 1], f->msched[i]);
198
            int t2 = MAX (f->msched[i - 1], f->msched[i]);
199
            dep_list *t1dep = f->INSN(t1).dep;
200
            int x, p;
201
            cuc_insn *ii;
202
 
203
            cucdebug (2, "Joining %x and %x.\n", t1, t2);
204 954 markom
            if (cuc_debug >= 8) print_cuc_bb (f, "PREJT");
205 953 markom
            change_insn_type (&f->INSN(t1), II_NOP);
206
            change_insn_type (&f->INSN(t2), II_NOP);
207
            /* We will reuse the memadd before the first load, and add some
208
               custom code at the end */
209
            insert_insns (f, t1, 10);
210 954 markom
            if (cuc_debug > 8) print_cuc_bb (f, "PREJT2");
211 953 markom
 
212
            /* Remove all dependencies to second access */
213
            for (x = 0; x < f->num_bb; x++) {
214
              int i;
215
              for (i = 0; i < f->bb[x].ninsn; i++) {
216
                dep_list *d = f->bb[x].insn[i].dep;
217
                dep_list **old = &f->bb[x].insn[i].dep;
218
                while (d) {
219
                  if (d->ref == t2) {
220
                    d = d->next;
221
                    *old = d;
222
                  } else {
223
                    d = d->next;
224
                    old = &((*old)->next);
225
                  }
226
                }
227
              }
228
            }
229
 
230
            /* Build the folowing code:
231
               l[hw]z p-1
232
               and p-1, 0xff
233
               sfle p-1, 0x7f
234
               or p-2, 0xffffff00
235
               cmov p-3, p-1, p-2
236
               shr p-5, 8
237
               and p-1, 0xff
238
               sfle p-1 0x7f
239
               or p-2 0xffffff00
240
               cmov p-3, p-1, p-2*/
241
            p = REF_I(t1);
242 954 markom
            cucdebug (8, "%x %x\n", f->mtype[i - 1], f->mtype[i]);
243 953 markom
            for (x = 0; x < 2; x++) {
244
              int t = f->mtype[i - 1 + x];
245
              ii = &f->bb[REF_BB(t1)].insn[p];
246
              if (!x) {
247
                change_insn_type (ii, aw == 1 ? II_LH : II_LW);
248
                ii->type = IT_MEMORY | IT_VOLATILE;
249
                ii->op[0] = -1; ii->opt[0] = OPT_REGISTER | OPT_DEST;
250
                ii->op[1] = t1 - 1; ii->opt[1] = OPT_REF;
251
                ii->opt[2] = ii->opt[3] = OPT_NONE;
252
                ii->dep = t1dep;
253
                f->mtype[i - 1] = MT_LOAD | (aw == 1 ? 2 : 4);
254
                f->msched[i - 1] = REF (REF_BB(t1), p);
255
              } else {
256
                change_insn_type (ii, II_SRL);
257
                ii->type = 0;
258
                ii->op[0] = -1; ii->opt[0] = OPT_REGISTER | OPT_DEST;
259
                ii->op[1] = t1; ii->opt[1] = OPT_REF;
260
                ii->op[2] = 8; ii->opt[2] = OPT_CONST;
261
                ii->opt[3] = OPT_NONE;
262
              }
263
 
264
              ii = &f->bb[REF_BB(t1)].insn[++p];
265
              change_insn_type (ii, II_AND);
266
              ii->type = 0;
267
              ii->op[0] = -1; ii->opt[0] = OPT_REGISTER | OPT_DEST;
268
              ii->op[1] = REF (REF_BB(t1), p - 1); ii->opt[1] = OPT_REF;
269
              ii->op[2] = 0xff; ii->opt[2] = OPT_CONST;
270
              ii->opt[3] = OPT_NONE;
271
 
272
              ii = &f->bb[REF_BB(t1)].insn[++p];
273
              change_insn_type (ii, II_SFLE);
274
              ii->type = IT_COND;
275
              ii->op[0] = -1; ii->opt[0] = OPT_REGISTER | OPT_DEST;
276
              ii->op[1] = REF (REF_BB(t1), p - 1); ii->opt[1] = OPT_REF;
277
              ii->op[2] = 0x7f; ii->opt[2] = OPT_CONST;
278
              ii->opt[3] = OPT_NONE;
279
 
280
              ii = &f->bb[REF_BB(t1)].insn[++p];
281
              change_insn_type (ii, II_OR);
282
              ii->type = 0;
283
              ii->op[0] = -1; ii->opt[0] = OPT_REGISTER | OPT_DEST;
284
              ii->op[1] = REF (REF_BB(t1), p - 2); ii->opt[1] = OPT_REF;
285
              if (t & MT_SIGNED) ii->op[2] = 0xffffff00;
286
              else ii->op[2] = 0;
287
              ii->opt[2] = OPT_CONST;
288
              ii->opt[3] = OPT_NONE;
289
 
290
              ii = &f->bb[REF_BB(t1)].insn[++p];
291
              change_insn_type (ii, II_CMOV);
292
              ii->type = 0;
293
              ii->op[0] = -1; ii->opt[0] = OPT_REGISTER | OPT_DEST;
294
              ii->op[1] = REF (REF_BB(t1), p - 1); ii->opt[1] = OPT_REF;
295
              ii->op[2] = REF (REF_BB(t1), p - 3); ii->opt[2] = OPT_REF;
296
              ii->op[3] = REF (REF_BB(t1), p - 2); ii->opt[3] = OPT_REF;
297
              p++;
298
            }
299
 
300
            modified = 1;
301
 
302
            {
303
              int b, i, j;
304
              /* Update references */
305
              for (b = 0; b < f->num_bb; b++)
306
                for (i = 0; i < f->bb[b].ninsn; i++)
307
                  for (j = 0; j < MAX_OPERANDS; j++)
308
                    if (REF_I (f->bb[b].insn[i].op[j]) < REF_I (t1)
309
                     || REF_I(f->bb[b].insn[i].op[j]) >= REF_I (t1) + 10) {
310
                      if (f->bb[b].insn[i].opt[j] & OPT_REF && f->bb[b].insn[i].op[j] == t1)
311
                        f->bb[b].insn[i].op[j] = t1 + 4;
312
                      else if (f->bb[b].insn[i].opt[j] & OPT_REF && f->bb[b].insn[i].op[j] == t2)
313
                        f->bb[b].insn[i].op[j] = t1 + 9;
314
                    }
315
            }
316 954 markom
            if (cuc_debug >= 8) print_cuc_bb (f, "POSTJT");
317 953 markom
          } else goto keep;
318
        } else goto keep;
319
      } else {
320
keep:
321
        f->msched[j] = f->msched[i];
322
        f->mtype[j++] = f->mtype[i];
323
      }
324
    f->nmsched = j;
325
  }
326
  return modified;
327
}
328
 
329 879 markom
/* returns nonzero if a < b */
330
int mem_ordering_cmp (cuc_func *f, cuc_insn *a, cuc_insn *b)
331
{
332
  assert (a->type & IT_MEMORY);
333
  assert (b->type & IT_MEMORY);
334
  if ((a->opt[1] & OPT_REF) && f->INSN(a->op[1]).index == II_ADD
335
    &&(b->opt[1] & OPT_REF) && f->INSN(b->op[1]).index == II_ADD) {
336
    a = &f->INSN(a->op[1]);
337
    b = &f->INSN(b->op[1]);
338
    if (a->opt[1] != b->opt[1] || a->op[1] != b->op[1]
339
     || a->opt[2] != OPT_CONST || b->opt[2] != OPT_CONST) return 0;
340
 
341
    /* Order linearly, we can then join them to bursts */
342
    return a->op[2] < b->op[2];
343
  } else return 0;
344
}
345
 
346
/* Schedule memory accesses
347
 
348 953 markom
int schedule_memory (cuc_func *f, int otype)
349 879 markom
{
350
  int b, i, j;
351 953 markom
  int modified = 0;
352 879 markom
  f->nmsched = 0;
353
 
354
  for (b = 0; b < f->num_bb; b++) {
355
    cuc_insn *insn = f->bb[b].insn;
356
    for (i = 0; i < f->bb[b].ninsn; i++)
357
      if (insn[i].type & IT_MEMORY) {
358
        f->msched[f->nmsched++] = REF (b, i);
359 897 markom
        if (otype == MO_NONE || otype == MO_WEAK) insn[i].type |= IT_FLAG1; /* mark unscheduled */
360 879 markom
      }
361
  }
362 937 markom
 
363 879 markom
  for (i = 0; i < f->nmsched; i++)
364 937 markom
    cucdebug (2, "[%x]%x%c ", f->msched[i], f->mtype[i] & MT_WIDTH, (f->mtype[i] & MT_BURST) ? (f->mtype[i] & MT_BURSTE) ? 'E' : 'B' : ' ');
365
  cucdebug (2, "\n");
366
 
367 879 markom
  /* We can reorder just more loose types
368
     We assume, that memory accesses are currently in valid (but not neccesserly)
369
     optimal order */
370 897 markom
  if (otype == MO_WEAK || otype == MO_NONE) {
371 879 markom
    for (i = 0; i < f->nmsched; i++) {
372
      int best = i;
373
      int tmp;
374
      for (j = i + 1; j < f->nmsched; j++) if (REF_BB(f->msched[j]) == REF_BB(f->msched[best])) {
375
        if (mem_ordering_cmp (f, &f->INSN (f->msched[j]), &f->INSN(f->msched[best]))) {
376
          /* Check dependencies */
377
          dep_list *t = f->INSN(f->msched[j]).dep;
378
          while (t) {
379
            if (f->INSN(t->ref).type & IT_FLAG1) break;
380
            t = t->next;
381
          }
382
          if (!t) best = j; /* no conflicts -> ok */
383
        }
384
      }
385
 
386
      /* we have to shift instructions up, to maintain valid dependencies
387
         and make space for best candidate */
388
 
389
      /* make local copy */
390
      tmp = f->msched[best];
391
      for (j = best; j > i; j--) f->msched[j] = f->msched[j - 1];
392
      f->msched[i] = tmp;
393
      f->INSN(f->msched[i]).type &= ~IT_FLAG1; /* mark scheduled */
394
    }
395
  }
396
 
397
  for (i = 0; i < f->nmsched; i++)
398 937 markom
    cucdebug (2, "[%x]%x%c ", f->msched[i], f->mtype[i] & MT_WIDTH, (f->mtype[i] & MT_BURST) ? (f->mtype[i] & MT_BURSTE) ? 'E' : 'B' : ' ');
399
  cucdebug (2, "\n");
400 879 markom
 
401 904 markom
  /* Assign memory types */
402 879 markom
  for (i = 0; i < f->nmsched; i++) {
403
    cuc_insn *a = &f->INSN(f->msched[i]);
404 907 markom
    f->mtype[i] = !II_IS_LOAD(a->index) ? MT_STORE : MT_LOAD;
405 879 markom
    f->mtype[i] |= II_MEM_WIDTH (a->index);
406
    if (a->type & IT_SIGNED) f->mtype[i] |= MT_SIGNED;
407
  }
408
 
409 953 markom
  if (same_transfers (f, otype)) modified = 1;
410
  if (join_transfers (f, otype)) modified = 1;
411 904 markom
 
412 937 markom
  for (i = 0; i < f->nmsched; i++)
413
    cucdebug (2, "[%x]%x%c ", f->msched[i], f->mtype[i] & MT_WIDTH, (f->mtype[i] & MT_BURST) ? (f->mtype[i] & MT_BURSTE) ? 'E' : 'B' : ' ');
414
  cucdebug (2, "\n");
415
  if (cuc_debug > 5) print_cuc_bb (f, "AFTER_MEM_REMOVAL");
416
 
417 897 markom
  if (config.cuc.enable_bursts) {
418 997 markom
    //PRINTF ("\n");
419 879 markom
    for (i = 1; i < f->nmsched; i++) {
420
      cuc_insn *a = &f->INSN(f->msched[i - 1]);
421
      cuc_insn *b = &f->INSN(f->msched[i]);
422
      int aw = f->mtype[i - 1] & MT_WIDTH;
423
 
424 953 markom
      /* Burst can only be out of words */
425
      if (aw != 4) continue;
426
 
427 879 markom
      if ((a->opt[1] & OPT_REF) && f->INSN(a->op[1]).index == II_ADD
428
        &&(b->opt[1] & OPT_REF) && f->INSN(b->op[1]).index == II_ADD) {
429
        a = &f->INSN(a->op[1]);
430
        b = &f->INSN(b->op[1]);
431
        /* Not in usual form? */
432
        if (a->opt[1] != b->opt[1] || a->op[1] != b->op[1]
433
         || a->opt[2] != OPT_CONST || b->opt[2] != OPT_CONST) continue;
434
 
435 997 markom
        //PRINTF ("%i %i, ", a->op[2], b->op[2]);
436 879 markom
 
437
        /* Check if they touch together */
438 953 markom
        if (a->op[2] + aw == b->op[2]
439
          && REF_BB(f->msched[i - 1]) == REF_BB(f->msched[i])) {
440 879 markom
          /* yes => do burst */
441
          f->mtype[i - 1] &= ~MT_BURSTE;
442
          f->mtype[i - 1] |= MT_BURST;
443
          f->mtype[i] |= MT_BURST | MT_BURSTE;
444
        }
445
      }
446
    }
447
  }
448
 
449
  for (i = 0; i < f->nmsched; i++)
450 937 markom
    cucdebug (2, "[%x]%x%c ", f->msched[i], f->mtype[i] & MT_WIDTH, (f->mtype[i] & MT_BURST) ? (f->mtype[i] & MT_BURSTE) ? 'E' : 'B' : ' ');
451
  cucdebug (2, "\n");
452 879 markom
 
453
  /* We don't need dependencies in non-memory instructions */
454
  for (b = 0; b < f->num_bb; b++) {
455
    cuc_insn *insn = f->bb[b].insn;
456
    for (i = 0; i < f->bb[b].ninsn; i++) if (!(insn[i].type & IT_MEMORY))
457
      dispose_list (&insn[i].dep);
458
  }
459
 
460 953 markom
  if (cuc_debug > 5) print_cuc_bb (f, "AFTER_MEM_REMOVAL2");
461 879 markom
  /* Reduce number of dependecies, keeping just direct dependencies, based on memory schedule */
462
  {
463 907 markom
    int lastl[3] = {-1, -1, -1};
464
    int lasts[3] = {-1, -1, -1};
465
    int lastc[3] = {-1, -1, -1};
466
    int last_load = -1, last_store = -1, last_call = -1;
467 879 markom
    for (i = 0; i < f->nmsched; i++) {
468 907 markom
      int t = f->mtype[i] & MT_LOAD ? 0 : f->mtype[i] & MT_STORE ? 1 : 2;
469 879 markom
      int maxl = lastl[t];
470
      int maxs = lasts[t];
471 907 markom
      int maxc = lastc[t];
472 879 markom
      dep_list *tmp = f->INSN(f->msched[i]).dep;
473 1308 phoenix
      cucdebug (7, "!%i %x %p\n", i, f->msched[i], tmp);
474 879 markom
      while (tmp) {
475
        if (f->INSN(tmp->ref).type & IT_MEMORY && REF_BB(tmp->ref) == REF_BB(f->msched[i])) {
476 1308 phoenix
          cucdebug (7, "%i %x %lx\n", i, f->msched[i], tmp->ref);
477 879 markom
          /* Search for the reference */
478
          for (j = 0; j < f->nmsched; j++) if (f->msched[j] == tmp->ref) break;
479
          assert (j < f->nmsched);
480 907 markom
          if (f->mtype[j] & MT_STORE) {
481 879 markom
            if (maxs < j) maxs = j;
482 907 markom
          } else if (f->mtype[j] & MT_LOAD) {
483 879 markom
            if (maxl < j) maxl = j;
484 907 markom
          } else if (f->mtype[j] & MT_CALL) {
485
            if (maxc < j) maxc = j;
486 879 markom
          }
487
        }
488
        tmp = tmp->next;
489
      }
490
      dispose_list (&f->INSN(f->msched[i]).dep);
491 907 markom
      if (f->mtype[i] & MT_STORE) {
492 879 markom
        maxs = last_store;
493
        last_store = i;
494 907 markom
      } else if (f->mtype[i] & MT_LOAD) {
495 879 markom
        maxl = last_load;
496
        last_load = i;
497 907 markom
      } else if (f->mtype[i] & MT_CALL) {
498
        maxc = last_call;
499
        last_call = i;
500 879 markom
      }
501
 
502
      if (maxl > lastl[t]) {
503
        add_dep (&f->INSN(f->msched[i]).dep, f->msched[maxl]);
504
        lastl[t] = maxl;
505
      }
506
      if (maxs > lasts[t]) {
507
        add_dep (&f->INSN(f->msched[i]).dep, f->msched[maxs]);
508
        lasts[t] = maxs;
509
      }
510 907 markom
      if (maxc > lastc[t]) {
511
        add_dep (&f->INSN(f->msched[i]).dep, f->msched[maxc]);
512
        lastc[t] = maxc;
513
      }
514 997 markom
      //PRINTF ("%i(%i)> ml %i(%i) ms %i(%i) lastl %i %i lasts %i %i last_load %i last_store %i\n", i, f->msched[i], maxl, f->msched[maxl], maxs, f->msched[maxs], lastl[0], lastl[1], lasts[0], lasts[1], last_load, last_store);
515 879 markom
 
516
      /* What we have to wait to finish this BB? */
517
      if (i + 1 >= f->nmsched || REF_BB(f->msched[i + 1]) != REF_BB(f->msched[i])) {
518
        if (last_load > lastl[t]) {
519
          add_dep (&f->bb[REF_BB(f->msched[i])].mdep, f->msched[last_load]);
520
          lastl[t] = last_load;
521
        }
522
        if (last_store > lasts[t]) {
523
          add_dep (&f->bb[REF_BB(f->msched[i])].mdep, f->msched[last_store]);
524
          lasts[t] = last_store;
525
        }
526 907 markom
        if (last_call > lastc[t]) {
527
          add_dep (&f->bb[REF_BB(f->msched[i])].mdep, f->msched[last_call]);
528
          lastc[t] = last_call;
529
        }
530 879 markom
      }
531
    }
532
  }
533 953 markom
  return modified;
534 879 markom
}

powered by: WebSVN 2.1.0

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