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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_69/] [or1ksim/] [cuc/] [bb.c] - Diff between revs 934 and 936

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 934 Rev 936
Line 1501... Line 1501...
  //print_cuc_bb (n, "preunroll");
  //print_cuc_bb (n, "preunroll");
  free (counts);
  free (counts);
  return n;
  return n;
}
}
 
 
/* Marks successor of b with mask m */
 
static void mark_successors (cuc_func *f, int b, int m, int stopb)
 
{
 
  if (b < 0 || b == BBID_END) return;
 
  if (f->bb[b].tmp & m) return;
 
  f->bb[b].tmp |= m;
 
  /* mark stopb also; and stop searching -- we will gen new result in stopb */
 
  if (b == stopb) return;
 
  mark_successors (f, f->bb[b].next[0], m, stopb);
 
  mark_successors (f, f->bb[b].next[1], m, stopb);
 
}
 
 
 
static unsigned long mask (unsigned long c)
 
{
 
  if (c) return (1 << (log2 (c) + 1)) - 1;
 
  else return 0;
 
}
 
 
 
/* Calculates facts, that are determined by conditionals */
 
void insert_conditional_facts (cuc_func *f)
 
{
 
  int b, i, j;
 
  int b1, i1, j1;
 
  cuc_insn n[2];
 
  for (b = 0; b < f->num_bb; b++) if (f->bb[b].ninsn > 0) {
 
    cuc_insn *ii = &f->bb[b].insn[f->bb[b].ninsn - 1];
 
    if (ii->type & IT_BRANCH && ii->opt[1] & OPT_REF && REF_BB(ii->op[1]) == b
 
     && f->INSN(ii->op[1]).opt[2] & OPT_CONST) {
 
      int ok = 1;
 
      unsigned long c = f->INSN(ii->op[1]).op[2];
 
      int rref = f->INSN(ii->op[1]).op[1];
 
      unsigned long r;
 
      if (!(f->INSN(ii->op[1]).opt[1] & OPT_REF)) continue;
 
      r = f->INSN(rref).op[0];
 
      for (j = 0; j < 2; j++) {
 
        change_insn_type (&n[j], II_ADD);
 
        n[j].type = 0;
 
        n[j].dep = NULL;
 
        n[j].op[0] = r; n[j].opt[0] = OPT_REGISTER | OPT_DEST;
 
        n[j].op[1] = 0; n[j].opt[1] = OPT_CONST;
 
        n[j].op[2] = rref; n[j].opt[2] = OPT_REF;
 
        n[j].opt[3] = OPT_NONE;
 
        sprintf (n[j].disasm, "conditional %s fact", j ? "false" : "true");
 
      }
 
 
 
      /* First get the conditional and two instruction to place after the current BB */
 
      switch (f->INSN(ii->op[1]).index) {
 
        case II_SFEQ:
 
          change_insn_type (&n[0], II_ADD);
 
          n[0].op[0] = r; n[0].opt[0] = OPT_REGISTER | OPT_DEST;
 
          n[0].op[1] = 0; n[0].opt[1] = OPT_CONST;
 
          n[0].op[2] = c; n[0].opt[2] = OPT_CONST;
 
          break;
 
        case II_SFNE:
 
          change_insn_type (&n[1], II_ADD);
 
          n[1].op[0] = r; n[1].opt[0] = OPT_REGISTER | OPT_DEST;
 
          n[1].op[1] = 0; n[1].opt[1] = OPT_CONST;
 
          n[1].op[2] = c; n[1].opt[2] = OPT_CONST;
 
          break;
 
        case II_SFLT:
 
          change_insn_type (&n[0], II_AND);
 
          n[0].op[0] = r; n[0].opt[0] = OPT_REGISTER | OPT_DEST;
 
          n[0].op[1] = rref; n[0].opt[1] = OPT_REF;
 
          n[0].op[2] = mask (c); n[0].opt[2] = OPT_CONST;
 
          break;
 
        case II_SFGT:
 
          change_insn_type (&n[1], II_ADD);
 
          n[1].op[0] = r; n[1].opt[0] = OPT_REGISTER | OPT_DEST;
 
          n[1].op[1] = rref; n[1].opt[1] = OPT_REF;
 
          n[1].op[2] = mask (c + 1); n[1].opt[2] = OPT_CONST;
 
          break;
 
        case II_SFLE:
 
          change_insn_type (&n[0], II_AND);
 
          n[0].op[0] = r; n[0].opt[0] = OPT_REGISTER | OPT_DEST;
 
          n[0].op[1] = rref; n[0].opt[1] = OPT_REF;
 
          n[0].op[2] = mask (c); n[0].opt[2] = OPT_CONST;
 
          break;
 
        case II_SFGE:
 
          change_insn_type (&n[1], II_ADD);
 
          n[1].op[0] = r; n[1].opt[0] = OPT_REGISTER | OPT_DEST;
 
          n[1].op[1] = rref; n[1].opt[1] = OPT_REF;
 
          n[1].op[2] = mask (c + 1); n[1].opt[2] = OPT_CONST;
 
          break;
 
        default:
 
          ok = 0;
 
          break;
 
      }
 
 
 
      /* Now add two BBs at the end and relink */
 
      if (ok) {
 
        for (j = 0; j < 2; j++) {
 
          int nb = f->num_bb++;
 
          int sb;
 
          assert (nb < MAX_BB);
 
          f->bb[nb].type = 0;
 
          f->bb[nb].first = -1; f->bb[nb].last = -1;
 
          f->bb[nb].prev[0] = b; f->bb[nb].prev[1] = -1;
 
          sb = f->bb[nb].next[0] = f->bb[b].next[j]; f->bb[nb].next[1] = -1;
 
          printf ("%x %x %x\n", b, sb, nb);
 
          assert (sb >= 0);
 
          f->bb[b].next[j] = nb;
 
          if (sb != BBID_END) {
 
            if (f->bb[sb].prev[0] == b) f->bb[sb].prev[0] = nb;
 
            else if (f->bb[sb].prev[1] == b) f->bb[sb].prev[1] = nb;
 
            else assert (0);
 
          }
 
          f->bb[nb].insn = (cuc_insn *) malloc (sizeof (cuc_insn));
 
          f->bb[nb].insn[0] = n[j];
 
          f->bb[nb].ninsn = 1;
 
          f->bb[nb].mdep = NULL;
 
          f->bb[nb].nmemory = 0;
 
          f->bb[nb].cnt = 0;
 
          f->bb[nb].unrolled = 0;
 
          f->bb[nb].ntim = 0;
 
          f->bb[nb].selected_tim = -1;
 
        }
 
        for (b1 = 0; b1 < f->num_bb; b1++) f->bb[b1].tmp = 0;
 
 
 
        /* Find successor blocks and change links accordingly */
 
        mark_successors (f, f->num_bb - 2, 2, b);
 
        mark_successors (f, f->num_bb - 1, 1, b);
 
        for (b1 = 0; b1 < f->num_bb - 2; b1++) if (f->bb[b1].tmp == 1 || f->bb[b1].tmp == 2) {
 
          int end;
 
          if (REF_BB (rref) == b1) end = REF_I (rref);
 
          else end = f->bb[b1].ninsn;
 
          for (i1 = 0; i1 < end; i1++)
 
            for (j1 = 0; j1 < MAX_OPERANDS; j1++)
 
              if (f->bb[b1].insn[i1].opt[j1] & OPT_REF && f->bb[b1].insn[i1].op[j1] == rref)
 
                f->bb[b1].insn[i1].op[j1] = REF (f->num_bb - f->bb[b1].tmp, 0);
 
        }
 
        print_cuc_bb (f, "FACT");
 
      }
 
    }
 
  }
 
}
 
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

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