Added CBO (commutative binary operator) to make it a little easier to

write reordering patterns
This commit is contained in:
ceriel 1989-10-20 11:59:52 +00:00
parent d6fa6357f2
commit 01f77a03af
3 changed files with 161 additions and 76 deletions

View file

@ -18,6 +18,8 @@ static char rcsid[] = "$Header$";
* Author: Hans van Staveren
*/
#define op_CBO (op_plast+1)
#define MAXNODES 1000
expr_t nodes[MAXNODES];
expr_p lastnode = nodes+1;
@ -32,6 +34,18 @@ bool nonumlab[N_EX_OPS];
bool onlyconst[N_EX_OPS];
int nerrors=0;
char patid[128];
int CBO_instrs[] = {
op_adi,
op_adu,
op_and,
op_ior,
op_xor
/* don't add op_mli and op_mlu! */
};
int patCBO;
int rplCBO;
%}
%union {
@ -67,22 +81,21 @@ patternlist
;
pattern :
mnemlist optexpr ':' replacement '\n'
{ register i;
outbyte(0); outshort(prevind); prevind=curind-3;
out(patlen);
for (i=0;i<patlen;i++) outbyte(patmnem[i]);
out($2);
out(rpllen);
for (i=0;i<rpllen;i++) {
outbyte(rplmnem[i]);
out(rplexpr[i]);
{
if (patCBO) {
register int i;
if (! rplCBO) {
yyerror("No CBO in replacement");
}
for (i=0; i<sizeof(CBO_instrs)/sizeof(int); i++) {
outpat($2, CBO_instrs[i]);
}
}
#ifdef DIAGOPT
outshort(patno);
#endif
patno++;
printf("\n");
if (patlen>maxpatlen) maxpatlen=patlen;
else {
outpat($2, 0);
}
patCBO = rplCBO = 0;
}
| error '\n'
{ yyerrok; }
@ -103,12 +116,36 @@ repllist: /* empty */
| repllist repl
;
repl : MNEM optexpr
{ rplmnem[rpllen] = $1; rplexpr[rpllen++] = $2; }
{ rplmnem[rpllen] = $1; rplexpr[rpllen++] = $2;
if ($1 == op_CBO) {
if (!patCBO) {
yyerror("No CBO in pattern");
}
if (rplCBO) {
yyerror("Only one CBO allowed in replacement");
}
rplCBO = 1;
}
}
;
mnemlist: MNEM
{ patlen=0; patmnem[patlen++] = $1; }
{ patlen=0; patmnem[patlen++] = $1;
if ($1 == op_CBO) {
if (patCBO) {
yyerror("Only one CBO allowed in pattern");
}
patCBO = 1;
}
}
| mnemlist MNEM
{ patmnem[patlen++] = $2; }
{ patmnem[patlen++] = $2;
if ($2 == op_CBO) {
if (patCBO) {
yyerror("Only one CBO allowed in pattern");
}
patCBO = 1;
}
}
;
optexpr : /* empty */
{ $$ = 0; }
@ -211,6 +248,7 @@ inithash() {
enter("LEP",op_LEP);
enter("SLP",op_SLP);
enter("SEP",op_SEP);
enter("CBO",op_CBO);
for(i=0;i<=sp_lmnem-sp_fmnem;i++)
enter(em_mnem[i],i+sp_fmnem);
}
@ -334,6 +372,31 @@ initio() {
curind = 1;
}
outpat(exprno, instrno)
{
register int i;
outbyte(0); outshort(prevind); prevind=curind-3;
out(patlen);
for (i=0;i<patlen;i++) {
if (patmnem[i] == op_CBO) outbyte(instrno);
else outbyte(patmnem[i]);
}
out(exprno);
out(rpllen);
for (i=0;i<rpllen;i++) {
if (rplmnem[i] == op_CBO) outbyte(instrno);
else outbyte(rplmnem[i]);
out(rplexpr[i]);
}
#ifdef DIAGOPT
outshort(patno);
#endif
patno++;
printf("\n");
if (patlen>maxpatlen) maxpatlen=patlen;
}
outbyte(b) {
printf(",%3d",b);

View file

@ -552,80 +552,92 @@ lde loc inn $3==2*w && $2>=0 && $2<16*w :
ldf loc inn $3==2*w && $2>=0 && $2<16*w :
lof $1+($2/(8*w))*w loc $2&(8*w-1) inn w
loc inn $1<0 || $1>=8*$2 : asp $2 loc 0
lol loc adi stl $3==w && $1==$4 : loc $2 lol $1 adi w stl $4
ldl ldc adi sdl $3==2*w && $1==$4 : ldc $2 ldl $1 adi 2*w sdl $4
lol loe adi stl $3==w && $1==$4 : loe $2 lol $1 adi w stl $4
ldl lde adi sdl $3==2*w && $1==$4 : lde $2 ldl $1 adi 2*w sdl $4
lol loc CBO stl $3==w && $1==$4 : loc $2 lol $1 CBO w stl $4
lol loe CBO stl $3==w && $1==$4 : loe $2 lol $1 CBO w stl $4
lol lol CBO stl $3==w && $1==$4 && $1!=$2 : lol $2 lol $1 CBO w stl $4
lol lil CBO stl $3==w && $1==$4 : lil $2 lol $1 CBO w stl $4
ldl ldc CBO sdl $3==2*w && $1==$4 : ldc $2 ldl $1 CBO $3 sdl $4
ldl lde CBO sdl $3==2*w && $1==$4 : lde $2 ldl $1 CBO $3 sdl $4
ldl ldl CBO sdl $3==2*w && $1==$4 &&$1!=$2 : ldl $2 ldl $1 CBO $3 sdl $4
loe loc CBO ste $3==w && $1==$4 : loc $2 loe $1 CBO w ste $4
loe loe CBO ste $3==w && $1==$4 && $1!=$2 : loe $2 loe $1 CBO w ste $4
loe lol CBO ste $3==w && $1==$4 : lol $2 loe $1 CBO w ste $4
loe lil CBO ste $3==w && $1==$4 : lil $2 loe $1 CBO w ste $4
lde ldc CBO sde $3==2*w && $1==$4 : ldc $2 lde $1 CBO $3 sde $4
lde lde CBO sde $3==2*w && $1==$4 && $1!=$2 : lde $2 lde $1 CBO $3 sde $4
lde ldl CBO sde $3==2*w && $1==$4 : ldl $2 lde $1 CBO $3 sde $4
lil loc CBO sil $3==w && $1==$4 : loc $2 lil $1 CBO w sil $4
lil lol CBO sil $3==w && $1==$4 : lol $2 lil $1 CBO w sil $4
lil loe CBO sil $3==w && $1==$4 : loe $2 lil $1 CBO w sil $4
lil lil CBO sil $3==w && $1==$4 && $1!=$2 : lil $2 lil $1 CBO w sil $4
LLP loi ldc CBO LLP sti $4==2*w && $2==$4 && $6==$4 && $1==$5 :
ldc $3 LLP $1 loi $2 CBO $4 LLP $5 sti $6
LLP loi ldl CBO LLP sti $4==2*w && $2==$4 && $6==$4 && $1==$5 :
ldl $3 LLP $1 loi $2 CBO $4 LLP $5 sti $6
LLP loi lde CBO LLP sti $4==2*w && $2==$4 && $6==$4 && $1==$5 :
lde $3 LLP $1 loi $2 CBO $4 LLP $5 sti $6
LLP ldf ldc CBO LLP sdf $4==2*w && $2==$6 && $1==$5 :
ldc $3 LLP $1 ldf $2 CBO $4 LLP $5 sdf $6
LLP ldf ldl CBO LLP sdf $4==2*w && $2==$6 && $1==$5 :
ldl $3 LLP $1 ldf $2 CBO $4 LLP $5 sdf $6
LLP ldf lde CBO LLP sdf $4==2*w && $2==$6 && $1==$5 :
lde $3 LLP $1 ldf $2 CBO $4 LLP $5 sdf $6
LLP lof loc CBO LLP stf $4==w && $2==$6 && $1==$5 :
loc $3 LLP $1 lof $2 CBO $4 LLP $5 stf $6
LLP lof lol CBO LLP stf $4==w && $2==$6 && $1==$5 :
lol $3 LLP $1 lof $2 CBO $4 LLP $5 stf $6
LLP lof loe CBO LLP stf $4==w && $2==$6 && $1==$5 :
loe $3 LLP $1 lof $2 CBO $4 LLP $5 stf $6
LLP lof lil CBO LLP stf $4==w && $2==$6 && $1==$5 :
lil $3 LLP $1 lof $2 CBO $4 LLP $5 stf $6
LEP loi ldc CBO LEP sti $4==2*w && $2==$4 && $6==$4 && $1==$5 :
ldc $3 LEP $1 loi $2 CBO $4 LEP $5 sti $6
LEP loi ldl CBO LEP sti $4==2*w && $2==$4 && $6==$4 && $1==$5 :
ldl $3 LEP $1 loi $2 CBO $4 LEP $5 sti $6
LEP loi lde CBO LEP sti $4==2*w && $2==$4 && $6==$4 && $1==$5 :
lde $3 LEP $1 loi $2 CBO $4 LEP $5 sti $6
LEP ldf ldc CBO LEP sdf $4==2*w && $2==$6 && $1==$5 :
ldc $3 LEP $1 ldf $2 CBO $4 LEP $5 sdf $6
LEP ldf ldl CBO LEP sdf $4==2*w && $2==$6 && $1==$5 :
ldl $3 LEP $1 ldf $2 CBO $4 LEP $5 sdf $6
LEP ldf lde CBO LEP sdf $4==2*w && $2==$6 && $1==$5 :
lde $3 LEP $1 ldf $2 CBO $4 LEP $5 sdf $6
LEP lof loc CBO LEP stf $4==w && $2==$6 && $1==$5 :
loc $3 LEP $1 lof $2 CBO $4 LEP $5 stf $6
LEP lof lol CBO LEP stf $4==w && $2==$6 && $1==$5 :
lol $3 LEP $1 lof $2 CBO $4 LEP $5 stf $6
LEP lof loe CBO LEP stf $4==w && $2==$6 && $1==$5 :
loe $3 LEP $1 lof $2 CBO $4 LEP $5 stf $6
LEP lof lil CBO LEP stf $4==w && $2==$6 && $1==$5 :
lil $3 LEP $1 lof $2 CBO $4 LEP $5 stf $6
ldl loe loc loc cii adi sdl $6==2*w && $1==$7 && $3==w && $4==2*w :
loe $2 loc $3 loc $4 cii ldl $1 adi 2*w sdl $1
lol lol adi stl $3==w && $1==$4 && $1!=$2 : lol $2 lol $1 adi w stl $4
ldl ldl adi sdl $3==2*w && $1==$4 &&$1!=$2 : ldl $2 ldl $1 adi 2*w sdl $4
ldl lol loc loc cii adi sdl $6==2*w && $1==$7 && $3==w && $4==2*w :
lol $2 loc $3 loc $4 cii ldl $1 adi 2*w sdl $1
loe loc adi ste $3==w && $1==$4 : loc $2 loe $1 adi w ste $4
lde ldc adi sde $3==2*w && $1==$4 : ldc $2 lde $1 adi 2*w sde $4
loe loe adi ste $3==w && $1==$4 && $1!=$2 : loe $2 loe $1 adi w ste $4
lde lde adi sde $3==2*w && $1==$4 && $1!=$2 : lde $2 lde $1 adi 2*w sde $4
lde loe loc loc cii adi sde $6==2*w && $1==$7 && $3==w && $4==2*w :
loe $2 loc $3 loc $4 cii lde $1 adi 2*w sde $1
loe lol adi ste $3==w && $1==$4 : lol $2 loe $1 adi w ste $4
lde ldl adi sde $3==2*w && $1==$4 : ldl $2 lde $1 adi 2*w sde $4
lde lol loc loc cii adi sde $6==2*w && $1==$7 && $3==w && $4==2*w :
lol $2 loc $3 loc $4 cii lde $1 adi 2*w sde $1
lol loc adu stl $3==w && $1==$4 : loc $2 lol $1 adu w stl $4
ldl ldc adu sdl $3==2*w && $1==$4 : ldc $2 ldl $1 adu 2*w sdl $4
lol loe adu stl $3==w && $1==$4 : loe $2 lol $1 adu w stl $4
ldl lde adu sdl $3==2*w && $1==$4 : lde $2 ldl $1 adu 2*w sdl $4
lol lol adu stl $3==w && $1==$4 && $1!=$2 : lol $2 lol $1 adu w stl $4
ldl ldl adu sdl $3==2*w && $1==$4 &&$1!=$2 : ldl $2 ldl $1 adu 2*w sdl $4
loe loc adu ste $3==w && $1==$4 : loc $2 loe $1 adu w ste $4
lde ldc adu sde $3==2*w && $1==$4 : ldc $2 lde $1 adu 2*w sde $4
loe loe adu ste $3==w && $1==$4 && $1!=$2 : loe $2 loe $1 adu w ste $4
lde lde adu sde $3==2*w && $1==$4 && $1!=$2 : lde $2 lde $1 adu 2*w sde $4
loe lol adu ste $3==w && $1==$4 : lol $2 loe $1 adu w ste $4
lde ldl adu sde $3==2*w && $1==$4 : ldl $2 lde $1 adu 2*w sde $4
lol loe mli stl $3==w && $1==$4 : loe $2 lol $1 mli w stl $4
ldl lde mli sdl $3==2*w && $1==$4 : lde $2 ldl $1 mli 2*w sdl $4
ldl loe loc loc cii mli sdl $6==2*w && $1==$7 && $3==w && $4==2*w :
loe $2 loc $3 loc $4 cii ldl $1 mli 2*w sdl $1
lol lol mli stl $3==w && $1==$4 && $1!=$2 : lol $2 lol $1 mli w stl $4
ldl ldl mli sdl $3==2*w && $1==$4 &&$1!=$2 : ldl $2 ldl $1 mli 2*w sdl $4
ldl lol loc loc cii mli sdl $6==2*w && $1==$7 && $3==w && $4==2*w :
lol $2 loc $3 loc $4 cii ldl $1 mli 2*w sdl $1
loe loe mli ste $3==w && $1==$4 && $1!=$2 : loe $2 loe $1 mli w ste $4
lde lde mli sde $3==2*w && $1==$4 && $1!=$2 : lde $2 lde $1 mli 2*w sde $4
lde loe loc loc cii mli sde $6==2*w && $1==$7 && $3==w && $4==2*w :
loe $2 loc $3 loc $4 cii lde $1 mli 2*w sde $1
loe lol mli ste $3==w && $1==$4 : lol $2 loe $1 mli w ste $4
lde ldl mli sde $3==2*w && $1==$4 : ldl $2 lde $1 mli 2*w sde $4
lde lol loc loc cii mli sde $6==2*w && $1==$7 && $3==w && $4==2*w :
lol $2 loc $3 loc $4 cii lde $1 mli 2*w sde $1
lol loe mlu stl $3==w && $1==$4 : loe $2 lol $1 mlu w stl $4
ldl lde mlu sdl $3==2*w && $1==$4 : lde $2 ldl $1 mlu 2*w sdl $4
lol lol mlu stl $3==w && $1==$4 && $1!=$2 : lol $2 lol $1 mlu w stl $4
ldl ldl mlu sdl $3==2*w && $1==$4 &&$1!=$2 : ldl $2 ldl $1 mlu 2*w sdl $4
loe loe mlu ste $3==w && $1==$4 && $1!=$2 : loe $2 loe $1 mlu w ste $4
lde lde mlu sde $3==2*w && $1==$4 && $1!=$2 : lde $2 lde $1 mlu 2*w sde $4
loe lol mlu ste $3==w && $1==$4 : lol $2 loe $1 mlu w ste $4
lde ldl mlu sde $3==2*w && $1==$4 : ldl $2 lde $1 mlu 2*w sde $4
lol loc ior stl $3==w && $1==$4 : loc $2 lol $1 ior w stl $4
lol loe ior stl $3==w && $1==$4 : loe $2 lol $1 ior w stl $4
lol lol ior stl $3==w && $1==$4 && $1!=$2 : lol $2 lol $1 ior w stl $4
loe loc ior ste $3==w && $1==$4 : loc $2 loe $1 ior w ste $4
loe loe ior ste $3==w && $1==$4 && $1!=$2 : loe $2 loe $1 ior w ste $4
loe lol ior ste $3==w && $1==$4 : lol $2 loe $1 ior w ste $4
lol loc and stl $3==w && $1==$4 : loc $2 lol $1 and w stl $4
lol loe and stl $3==w && $1==$4 : loe $2 lol $1 and w stl $4
lol lol and stl $3==w && $1==$4 && $1!=$2 : lol $2 lol $1 and w stl $4
loe loc and ste $3==w && $1==$4 : loc $2 loe $1 and w ste $4
loe loe and ste $3==w && $1==$4 && $1!=$2 : loe $2 loe $1 and w ste $4
loe lol and ste $3==w && $1==$4 : lol $2 loe $1 and w ste $4
lol loc xor stl $3==w && $1==$4 : loc $2 lol $1 xor w stl $4
lol loe xor stl $3==w && $1==$4 : loe $2 lol $1 xor w stl $4
lol lol xor stl $3==w && $1==$4 && $1!=$2 : lol $2 lol $1 xor w stl $4
loe loc xor ste $3==w && $1==$4 : loc $2 loe $1 xor w ste $4
loe loe xor ste $3==w && $1==$4 && $1!=$2 : loe $2 loe $1 xor w ste $4
loe lol xor ste $3==w && $1==$4 : lol $2 loe $1 xor w ste $4
loi asp $1==$2 : asp p
lal loi loc loc loc loc ior $2==4*w && $7==4*w && ($3==0)+($4==0)+($5==0)+($6==0)>2 :
lol $1+3*w loc $3 ior w lol $1+2*w loc $4 ior w lol $1+w loc $5 ior w lol $1 loc $6 ior w

View file

@ -603,6 +603,7 @@ basicblock(alpp) line_p *alpp; {
int i;
short index;
bool madeopt;
int count = 0;
lpp = alpp; madeopt = FALSE;
while ((*lpp) != (line_p) 0 && ((*lpp)->l_instr&BMASK) != op_lab) {
@ -639,6 +640,15 @@ basicblock(alpp) line_p *alpp; {
index=(bp[PO_NEXT]&BMASK)|(bp[PO_NEXT+1]<<8);
}
}
if (lpp == next) {
count++;
if (count > 100) {
/* probably loop in table */
fprintf(stderr, "Warning: possible loop in patterns; call an expert\n");
next = &((*lpp)->l_next);
}
}
else count = 0;
lpp = next;
}
return madeopt;