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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_61/] [or1ksim/] [cuc/] [memory.c] - Blame information for rev 997

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

powered by: WebSVN 2.1.0

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