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

Subversion Repositories or1k

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

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

Rev 933 Rev 934
Line 328... Line 328...
  if (cuc_debug) printf ("cuc_check\n");
  if (cuc_debug) printf ("cuc_check\n");
  for (i = 0; i < f->num_bb; i++) {
  for (i = 0; i < f->num_bb; i++) {
    if (!f->bb[i].insn && f->bb[i].ninsn) goto err;
    if (!f->bb[i].insn && f->bb[i].ninsn) goto err;
    for (j = 0; j < f->bb[i].ninsn; j++) {
    for (j = 0; j < f->bb[i].ninsn; j++) {
      cuc_insn *ii = &f->bb[i].insn[j];
      cuc_insn *ii = &f->bb[i].insn[j];
      if (ii->index == II_CMOV && ii->type & IT_COND) {
      if ((ii->index == II_CMOV || ii->index == II_ADD) && ii->type & IT_COND) {
        k = 0;
        k = 0;
        assert (ii->opt[k] & OPT_REGISTER);
        assert (ii->opt[k] & OPT_REGISTER);
        if ((signed)ii->op[k] >= 0 && ii->op[k] != FLAG_REG && ii->op[k] != LRBB_REG) {
        if ((signed)ii->op[k] >= 0 && ii->op[k] != FLAG_REG && ii->op[k] != LRBB_REG) {
          printf ("%x %x\n", ii->opt[0], ii->op[0]);
          printf ("%x %x\n", ii->opt[0], ii->op[0]);
          goto err;
          goto err;
Line 340... Line 340...
      }
      }
      for (k = 0; k < MAX_OPERANDS; k++)
      for (k = 0; k < MAX_OPERANDS; k++)
        if (ii->opt[k] & OPT_REF) {
        if (ii->opt[k] & OPT_REF) {
          int t = ii->op[k];
          int t = ii->op[k];
          if (REF_BB(t) >= f->num_bb || REF_I (t) >= f->bb[REF_BB(t)].ninsn
          if (REF_BB(t) >= f->num_bb || REF_I (t) >= f->bb[REF_BB(t)].ninsn
           || ii->index == II_CMOV && (
           || (ii->index == II_CMOV || ii->index == II_ADD) && (
                (f->INSN(t).type & IT_COND) != (ii->type & IT_COND) && k < 3
                (f->INSN(t).type & IT_COND) != (ii->type & IT_COND) && k < 3
              || !(f->INSN(t).type & IT_COND) && k == 3)) goto err;
              || !(f->INSN(t).type & IT_COND) && k == 3)) goto err;
        }
        }
    }
    }
  }
  }
Line 652... Line 652...
          f->bb[i].insn[j].type &= ~IT_VOLATILE;
          f->bb[i].insn[j].type &= ~IT_VOLATILE;
          f->bb[i].insn[j].opt[1] = f->bb[i].insn[j].opt[2] = OPT_CONST;
          f->bb[i].insn[j].opt[1] = f->bb[i].insn[j].opt[2] = OPT_CONST;
          f->bb[i].insn[j].op[1] = f->bb[i].insn[j].op[2] = 0; /* always use left block */
          f->bb[i].insn[j].op[1] = f->bb[i].insn[j].op[2] = 0; /* always use left block */
          f->bb[i].insn[j].opt[3] = OPT_NONE;
          f->bb[i].insn[j].opt[3] = OPT_NONE;
          modified = 1;
          modified = 1;
          if (f->bb[i].prev[0] != BBID_START) {
          if (f->bb[i].prev[0] != BBID_START && f->bb[f->bb[i].prev[0]].ninsn > 0) {
            t = &f->bb[f->bb[i].prev[0]].insn[f->bb[f->bb[i].prev[0]].ninsn - 1];
            t = &f->bb[f->bb[i].prev[0]].insn[f->bb[f->bb[i].prev[0]].ninsn - 1];
 
 
            /* If the predecessor still has a conditional jump instruction, we must be careful.
            /* If the predecessor still has a conditional jump instruction, we must be careful.
               If next[0] == next[1] join them. Now we will link lrbb and correct the situation */
               If next[0] == next[1] join them. Now we will link lrbb and correct the situation */
            if (t->type & IT_BRANCH) { /* We must set a reference to branch result */
            if (t->type & IT_BRANCH) { /* We must set a reference to branch result */
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 */
/* Calculates facts, that are determined by conditionals */
void insert_conditional_facts (cuc_func *f)
void insert_conditional_facts (cuc_func *f)
{
{
  int b, i, j;
  int b, i, j;
 
  int b1, i1, j1;
  cuc_insn n[2];
  cuc_insn n[2];
  for (b = 0; b < f->num_bb; b++) {
  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];
    cuc_insn *ii = &f->bb[b].insn[f->bb[b].ninsn - 1];
    if (ii->type & IT_BRANCH
    if (ii->type & IT_BRANCH && ii->opt[1] & OPT_REF && REF_BB(ii->op[1]) == b
     && ii->opt[1] & OPT_REF && f->INSN(ii->op[1]).opt[2] & OPT_CONST) {
     && f->INSN(ii->op[1]).opt[2] & OPT_CONST) {
      int ok = 1;
      int ok = 1;
      unsigned long c = f->INSN(ii->op[1]).op[2];
      unsigned long c = f->INSN(ii->op[1]).op[2];
      change_insn_type (&n[0], II_NOP);
      int rref = f->INSN(ii->op[1]).op[1];
      change_insn_type (&n[1], II_NOP);
      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 */
      /* First get the conditional and two instruction to place after the current BB */
      switch (f->INSN(ii->op[1]).index) {
      switch (f->INSN(ii->op[1]).index) {
        case II_SFEQ:
        case II_SFEQ:
          change_insn_type (&n[0], II_ADD);
          change_insn_type (&n[0], II_ADD);
          n[0].type = 0;
          n[0].op[0] = r; n[0].opt[0] = OPT_REGISTER | OPT_DEST;
          n[0].dep = NULL;
 
          n[0].op[0] = -1; n[0].opt[0] = OPT_REGISTER | OPT_DEST;
 
          n[0].op[1] = 0; n[0].opt[1] = OPT_CONST;
          n[0].op[1] = 0; n[0].opt[1] = OPT_CONST;
          n[0].op[2] = c; n[0].opt[2] = OPT_CONST;
          n[0].op[2] = c; n[0].opt[2] = OPT_CONST;
          break;
          break;
        case II_SFNE:
        case II_SFNE:
          change_insn_type (&n[1], II_ADD);
          change_insn_type (&n[1], II_ADD);
          n[1].type = 0;
          n[1].op[0] = r; n[1].opt[0] = OPT_REGISTER | OPT_DEST;
          n[1].dep = NULL;
 
          n[1].op[0] = -1; n[1].opt[0] = OPT_REGISTER | OPT_DEST;
 
          n[1].op[1] = 0; n[1].opt[1] = OPT_CONST;
          n[1].op[1] = 0; n[1].opt[1] = OPT_CONST;
          n[1].op[2] = c; n[1].opt[2] = OPT_CONST;
          n[1].op[2] = c; n[1].opt[2] = OPT_CONST;
          break;
          break;
        case II_SFLT:
        case II_SFLT:
          change_insn_type (&n[0], II_AND);
          change_insn_type (&n[0], II_AND);
          n[0].type = 0;
          n[0].op[0] = r; n[0].opt[0] = OPT_REGISTER | OPT_DEST;
          n[0].dep = NULL;
          n[0].op[1] = rref; n[0].opt[1] = OPT_REF;
          n[0].op[0] = -1; n[0].opt[0] = OPT_REGISTER | OPT_DEST;
          n[0].op[2] = mask (c); n[0].opt[2] = OPT_CONST;
          n[0].op[1] = 0; n[0].opt[1] = OPT_CONST;
 
          n[0].op[2] = (1 << (log2 (c) + 1)) - 1; n[0].opt[2] = OPT_CONST;
 
          break;
          break;
        case II_SFGT:
        case II_SFGT:
          change_insn_type (&n[1], II_ADD);
          change_insn_type (&n[1], II_ADD);
          n[1].type = 0;
          n[1].op[0] = r; n[1].opt[0] = OPT_REGISTER | OPT_DEST;
          n[1].dep = NULL;
          n[1].op[1] = rref; n[1].opt[1] = OPT_REF;
          n[1].op[0] = -1; n[1].opt[0] = OPT_REGISTER | OPT_DEST;
          n[1].op[2] = mask (c + 1); n[1].opt[2] = OPT_CONST;
          n[1].op[1] = 0; n[1].opt[1] = OPT_CONST;
 
          n[1].op[2] = (1 << (log2 (c + 1) + 1)) - 1; n[1].opt[2] = OPT_CONST;
 
          break;
          break;
        case II_SFLE:
        case II_SFLE:
          change_insn_type (&n[0], II_AND);
          change_insn_type (&n[0], II_AND);
          n[0].type = 0;
          n[0].op[0] = r; n[0].opt[0] = OPT_REGISTER | OPT_DEST;
          n[0].dep = NULL;
          n[0].op[1] = rref; n[0].opt[1] = OPT_REF;
          n[0].op[0] = -1; n[0].opt[0] = OPT_REGISTER | OPT_DEST;
          n[0].op[2] = mask (c); n[0].opt[2] = OPT_CONST;
          n[0].op[1] = 0; n[0].opt[1] = OPT_CONST;
 
          n[0].op[2] = (1 << (log2 (c + 1) + 1)) - 1; n[0].opt[2] = OPT_CONST;
 
          break;
          break;
        case II_SFGE:
        case II_SFGE:
          change_insn_type (&n[1], II_ADD);
          change_insn_type (&n[1], II_ADD);
          n[1].type = 0;
          n[1].op[0] = r; n[1].opt[0] = OPT_REGISTER | OPT_DEST;
          n[1].dep = NULL;
          n[1].op[1] = rref; n[1].opt[1] = OPT_REF;
          n[1].op[0] = -1; n[1].opt[0] = OPT_REGISTER | OPT_DEST;
          n[1].op[2] = mask (c + 1); n[1].opt[2] = OPT_CONST;
          n[1].op[1] = 0; n[1].opt[1] = OPT_CONST;
 
          n[1].op[2] = (1 << (log2 (c) + 1)) - 1; n[1].opt[2] = OPT_CONST;
 
          break;
          break;
        default:
        default:
          ok = 0;
          ok = 0;
          break;
          break;
      }
      }
 
 
      /* Now add two BBs at the end and relink */
      /* Now add two BBs at the end and relink */
      if (ok) {
      if (ok) {
        for (j = 0; j < 2; j++) {
        for (j = 0; j < 2; j++) {
          int nb = f->num_bb++;
          int nb = f->num_bb++;
          int sb;
          int sb;
Line 1597... Line 1617...
          f->bb[nb].cnt = 0;
          f->bb[nb].cnt = 0;
          f->bb[nb].unrolled = 0;
          f->bb[nb].unrolled = 0;
          f->bb[nb].ntim = 0;
          f->bb[nb].ntim = 0;
          f->bb[nb].selected_tim = -1;
          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.