From c8aaa59e1c8a509c8b869cdf695fcc6c0c1f7834 Mon Sep 17 00:00:00 2001 From: bruce Date: Fri, 10 Jul 1987 14:16:32 +0000 Subject: [PATCH] New patterns, man page changes, other little fixes --- modules/src/em_opt/em_nopt.6 | 2 +- modules/src/em_opt/em_opt.3 | 16 ++++++++++------ modules/src/em_opt/nopt.h | 12 +++++------- modules/src/em_opt/patterns | 11 +++++++++-- 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/modules/src/em_opt/em_nopt.6 b/modules/src/em_opt/em_nopt.6 index fcd33d6a4..4dd8c9f17 100644 --- a/modules/src/em_opt/em_nopt.6 +++ b/modules/src/em_opt/em_nopt.6 @@ -5,7 +5,7 @@ em_nopt \- EM peephole optimizer .SH SYNOPSIS ~em/lib/em_nopt [ inputfile [ outputfile ] ] .SH DESCRIPTION -Em_nopt reads a compact EM-program, inputfile or standard input, +Em_nopt reads a compact EM-program inputfile or standard input, and produces another compact EM program on outputfile or standard output that is functionally equivalent, but smaller. diff --git a/modules/src/em_opt/em_opt.3 b/modules/src/em_opt/em_opt.3 index 92f5c43f2..6fd9fbdc6 100644 --- a/modules/src/em_opt/em_opt.3 +++ b/modules/src/em_opt/em_opt.3 @@ -70,20 +70,24 @@ used in compilers and other EM code producing programs. The interface routines are identical to the EM_CODE(3) procedure interface except that all names have been replaced by .I O_xxx -. It is possible to convert -a program that is currently using the EM_CODE interface by defining PEEPHOLE -before including em.h which enables a series of macros to map all the +It is possible to convert +a program that is currently using the EM_CODE interface +to use this module instead by defining +.I PEEPHOLE +before including +.I em.h. +This defines a series of macros to map all the .I C_xxx names to the corresponding .I O_xxx names. The module in turn calls .I C_xxx routines to output the optimized code. Hence it is possible to add peephole -optimization to any program that outputs EM code usng the EM_CODE module. +optimization to any program that outputs EM code using the EM_CODE module. .PP Details of the .I O_xxx -routines may be obtained by refering to the description +routines may be obtained by referring to the description of the corresponding .I C_xxx routine in EM_CODE(3). @@ -94,7 +98,7 @@ routine in EM_CODE(3). .fi .SH MODULES .nf -alloc(3), system(3), string(3) +alloc(3), system(3), string(3), em_code(3) .fi .SH SEE ALSO em_nopt(1) em_code(3), read_em(3), em_mes(3) diff --git a/modules/src/em_opt/nopt.h b/modules/src/em_opt/nopt.h index 528c6f1b4..c5303d407 100644 --- a/modules/src/em_opt/nopt.h +++ b/modules/src/em_opt/nopt.h @@ -10,21 +10,19 @@ #include #include #include -#include #include -#define OTHER 255 +#define OTHER 0 +#define op_lab sp_fpseu + +typedef struct e_instr *p_instr; #define FLUSHDFA() if(OO_state) {\ *OO_nxtpatt++ = OO_OTHER; OO_dfa(OTHER);\ } else if(OO_noutput) OO_flush(); #define GETINSTR() (OO_nxtifree>OO_freeiqueue)?*(--OO_nxtifree):\ - ((p_instr)Malloc(sizeof(struct e_instr))) - -#define op_lab sp_ilb1 - -typedef struct e_instr *p_instr; + ((p_instr)Malloc(sizeof(struct e_instr))) extern p_instr *OO_freeiqueue; extern p_instr *OO_nxtifree; diff --git a/modules/src/em_opt/patterns b/modules/src/em_opt/patterns index 84109ff3b..18f992ed8 100644 --- a/modules/src/em_opt/patterns +++ b/modules/src/em_opt/patterns @@ -175,16 +175,20 @@ loc 1 mlu w : ldc 1 mlu 2*w : loc 1 sbi w : dec loc loe mli w : loe $2 loc $1 mli w +loc loe mlu w : loe $2 loc $1 mlu w loc loe adi w loc : loe $2 loc $1 adi w loc $4 loc loe adi w inc : loe $2 loc $1 adi w inc loc loe adi w dec : loe $2 loc $1 adi w dec loc lol mli w : lol $2 loc $1 mli w +loc lol mlu w : lol $2 loc $1 mlu w loc lol adi w loc : lol $2 loc $1 adi w loc $4 loc lol adi w inc : lol $2 loc $1 adi w dec loc lol adi w dec : lol $2 loc $1 adi w dec ldc lde mli 2*w : lde $2 ldc $1 mli 2*w +ldc lde mlu 2*w : lde $2 ldc $1 mlu 2*w ldc lde adi 2*w : lde $2 ldc $1 adi 2*w ldc ldl mli 2*w : ldl $2 ldc $1 mli 2*w +ldc ldl mlu 2*w : ldl $2 ldc $1 mlu 2*w ldc ldl adi 2*w : ldl $2 ldc $1 adi 2*w loc 2 mli w : loc 1 sli w loc 4 mli w : loc 2 sli w @@ -407,6 +411,8 @@ loi 1 loc 1 loc w cii loc cmi w zne ? $5>=0&&$5<128 : loi 1 loc $5 cmi w zne loi 1 loc 1 loc w cii loc w loc w ciu loc 255 and w: loi 1 cmp teq : cms p teq cmp tne : cms p tne +cmp zeq : cms p zeq $2 +cmp zne : cms p zne $2 cmu defined teq : cms $1 teq cmu defined tne : cms $1 tne cms w zeq : beq $2 @@ -427,6 +433,7 @@ adp dup p sdl adp -$1 ? p==2*w : dup p adp $1 sdl $3 inc dup w ste dec : dup w inc ste $3 inc dup w stl dec : dup w inc stl $3 #endif +bra lab $1 : lab $2 zeq bra lab $1 : zne $2 lab $1 zge bra lab $1: zlt $2 lab $1 zgt bra lab $1 : zle $2 lab $1 @@ -542,8 +549,8 @@ lal loi 4*w loc loc loc loc ior 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 loc dup 2 stl loc dup 2 stl : loc $1 stl $3 loc $4 stl $6 loc $1 loc $4 -/*LLP LLP adp SLP $2 sti ? (!notreg($2) || $5!=p): */ -/* LLP $1 sti $5 LLP $2 adp $3 SLP $4 */ +lol lol adp stl $2 sti != p ? p==w : lol $1 sti $5 lol $2 adp $3 stl $4 +ldl ldl adp sdl $2 sti != p ? p==2*w : ldl $1 sti $5 ldl $2 adp $3 sdl $4 loe loe adp ste $2 sti !=p ? p==w : loe $1 sti $5 loe $2 adp $3 ste $4 lde lde adp sde $2 sti !=p ? p==2*w : lde $1 sti $5 lde $2 adp $3 sde $4 #ifndef INT