Line 111... |
Line 111... |
/* sw off (r1),rx */
|
/* sw off (r1),rx */
|
if (insn[i].index == II_SW
|
if (insn[i].index == II_SW
|
&& (insn[i].opt[0] & OPT_CONST)
|
&& (insn[i].opt[0] & OPT_CONST)
|
&& insn[i].op[1] == 1 && (insn[i].opt[1] & OPT_REGISTER)) {
|
&& insn[i].op[1] == 1 && (insn[i].opt[1] & OPT_REGISTER)) {
|
|
|
if (insn[i].op[0] < MAX_STACK) { /* Convert to normal move */
|
if (insn[i].op[0] < MAX_STACK/* && insn[i].op[1] >= 4*/) { /* Convert to normal move */
|
stack[insn[i].op[0]] = i;
|
stack[insn[i].op[0]] = i;
|
insn[i].type &= IT_INDELAY | IT_BBSTART;
|
insn[i].type &= IT_INDELAY | IT_BBSTART;
|
change_insn_type (&insn[i], II_ADD);
|
change_insn_type (&insn[i], II_ADD);
|
insn[i].op[0] = -1; insn[i].opt[0] = OPT_REGISTER | OPT_DEST;
|
insn[i].op[0] = -1; insn[i].opt[0] = OPT_REGISTER | OPT_DEST;
|
insn[i].op[1] = insn[i].op[2]; insn[i].opt[1] = insn[i].opt[2];
|
insn[i].op[1] = insn[i].op[2]; insn[i].opt[1] = insn[i].opt[2];
|
Line 124... |
Line 124... |
/* lw rx,off (r1) */
|
/* lw rx,off (r1) */
|
} else if (insn[i].index == II_LW
|
} else if (insn[i].index == II_LW
|
&& (insn[i].opt[1] & OPT_CONST)
|
&& (insn[i].opt[1] & OPT_CONST)
|
&& insn[i].op[2] == 1 && (insn[i].opt[2] & OPT_REGISTER)) {
|
&& insn[i].op[2] == 1 && (insn[i].opt[2] & OPT_REGISTER)) {
|
|
|
if (insn[i].op[1] < MAX_STACK) { /* Convert to normal move */
|
if (insn[i].op[1] < MAX_STACK && stack[insn[i].op[1]] >= 0) { /* Convert to normal move */
|
insn[i].type &= IT_INDELAY | IT_BBSTART;
|
insn[i].type &= IT_INDELAY | IT_BBSTART;
|
change_insn_type (&insn[i], II_ADD);
|
change_insn_type (&insn[i], II_ADD);
|
assert (stack[insn[i].op[1]] >= 0);
|
|
insn[i].op[1] = stack[insn[i].op[1]]; insn[i].opt[1] = OPT_REF;
|
insn[i].op[1] = stack[insn[i].op[1]]; insn[i].opt[1] = OPT_REF;
|
insn[i].op[2] = 0; insn[i].opt[2] = OPT_CONST;
|
insn[i].op[2] = 0; insn[i].opt[2] = OPT_CONST;
|
} else can_remove_stack = 0;
|
} else can_remove_stack = 0;
|
/* Check for defined stack size */
|
/* Check for defined stack size */
|
} else if (insn[i].index == II_ADD && !real_stack_size
|
} else if (insn[i].index == II_ADD && !real_stack_size
|
Line 139... |
Line 138... |
&& (insn[i].opt[1] & OPT_REGISTER) && insn[i].op[1] == 1
|
&& (insn[i].opt[1] & OPT_REGISTER) && insn[i].op[1] == 1
|
&& (insn[i].opt[2] & OPT_CONST)) {
|
&& (insn[i].opt[2] & OPT_CONST)) {
|
real_stack_size = -insn[i].op[2];
|
real_stack_size = -insn[i].op[2];
|
}
|
}
|
}
|
}
|
assert (can_remove_stack); /* TODO */
|
//assert (can_remove_stack); /* TODO */
|
}
|
}
|
|
|
/* Disassemble one instruction from insn index and generate parameters */
|
/* Disassemble one instruction from insn index and generate parameters */
|
const char *build_insn (unsigned long data, cuc_insn *insn)
|
const char *build_insn (unsigned long data, cuc_insn *insn)
|
{
|
{
|
Line 289... |
Line 288... |
if (insn[i].opt[j] & OPT_REF || insn[i].opt[j] & OPT_JUMP)
|
if (insn[i].opt[j] & OPT_REF || insn[i].opt[j] & OPT_JUMP)
|
insn[i].op[j] = reloc[insn[i].op[j]];
|
insn[i].op[j] = reloc[insn[i].op[j]];
|
} else insn[i].type &= ~IT_SIGNED;
|
} else insn[i].type &= ~IT_SIGNED;
|
}
|
}
|
|
|
/* CSE -- common subexpression elimination */
|
|
void cse ()
|
|
{
|
|
int i, j, k, l;
|
|
for (i = 0; i < num_insn; i++)
|
|
for (j = 0; j < i; j++) {
|
|
if (insn[i].index == insn[j].index) continue;
|
|
if (insn[i].type & IT_VOLATILE) continue;
|
|
|
|
/* Do we have an exact match? */
|
|
if (insn[i].op[1] != insn[j].op[1] || insn[i].opt[1] != insn[j].opt[1]) continue;
|
|
if (insn[i].op[2] != insn[j].op[2] || insn[i].opt[2] != insn[j].opt[2]) continue;
|
|
|
|
/* Check if we drive outputs? */
|
|
if ((insn[i].opt[0] & OPT_REGISTER) && insn[i].op[0] >= 0)
|
|
if ((insn[j].opt[0] & OPT_REGISTER) && insn[j].op[0] >= 0) continue;
|
|
else insn[j].op[0] = insn[i].op[0];
|
|
|
|
/* remove duplicated instruction and relink the references */
|
|
change_insn_type (&insn[i], II_NOP);
|
|
for (k = i + 1; k < num_insn; k++)
|
|
for (l = 0; l < MAX_OPERANDS; l++)
|
|
if (insn[k].op[l] == i && (insn[k].opt[l] & OPT_REF)) insn[k].op[l] = j;
|
|
}
|
|
}
|
|
|
|
/* Loads from file into global array insn */
|
/* Loads from file into global array insn */
|
void cuc_load (char *in_fn)
|
void cuc_load (char *in_fn)
|
{
|
{
|
int i, j, in_delay;
|
int i, j, in_delay;
|
FILE *fi;
|
FILE *fi;
|
Line 409... |
Line 382... |
fprintf (stderr, "Unsupported function structure.\n");
|
fprintf (stderr, "Unsupported function structure.\n");
|
exit (1);
|
exit (1);
|
}
|
}
|
|
|
log ("Number of instructions loaded = %i\n", num_insn);
|
log ("Number of instructions loaded = %i\n", num_insn);
|
if (DEBUG > 3) print_cuc_insns ("INITIAL", 1);
|
if (cuc_debug >= 3) print_cuc_insns ("INITIAL", 1);
|
|
|
log ("Converting.\n");
|
log ("Converting.\n");
|
remove_dslots ();
|
remove_dslots ();
|
if (DEBUG > 8) print_cuc_insns ("NO_DELAY_SLOTS", 0);
|
if (cuc_debug >= 6) print_cuc_insns ("NO_DELAY_SLOTS", 0);
|
|
|
if (calling_convention) {
|
if (calling_convention) {
|
detect_locals ();
|
detect_locals ();
|
if (DEBUG > 7) print_cuc_insns ("AFTER_LOCALS", 0);
|
if (cuc_debug >= 7) print_cuc_insns ("AFTER_LOCALS", 0);
|
}
|
}
|
expand_memory ();
|
expand_memory ();
|
if (DEBUG > 3) print_cuc_insns ("AFTER_EXP_MEM", 0);
|
if (cuc_debug >= 3) print_cuc_insns ("AFTER_EXP_MEM", 0);
|
|
|
expand_signed ();
|
expand_signed ();
|
if (DEBUG > 3) print_cuc_insns ("AFTER_EXP_SIG", 0);
|
if (cuc_debug >= 3) print_cuc_insns ("AFTER_EXP_SIG", 0);
|
|
|
log ("Common subexpression elimination.\n");
|
|
cse ();
|
|
if (DEBUG > 8) print_cuc_insns ("AFTER_CSE", 0);
|
|
}
|
}
|
|
|
No newline at end of file
|
No newline at end of file
|