Bladeren bron

Added SLI reduce

ceriel 33 jaren geleden
bovenliggende
commit
a00336f3dc

+ 1 - 1
util/ego/descr/Makefile

@@ -4,7 +4,7 @@ EMLIB=$(EMHOME)/lib
 SHARE=../share
 CPP=$(EMLIB)/cpp
 
-LDFLAGS=-i
+LDFLAGS=
 CPPFLAGS=-DVERBOSE -DNOTCOMPACT
 CFLAGS=$(CPPFLAGS) -O
 LINTFLAGS=-hbu

+ 1 - 0
util/ego/descr/em22.descr

@@ -68,6 +68,7 @@ access costs of local variables:
 %%SR
 overflow harmful?:  yes
 array bound harmful?:  yes
+reduce sli if shift count larger than:  0
 %%CS
 #include "../../../h/em_mnem.h"
 first time then space:

+ 1 - 0
util/ego/descr/em24.descr

@@ -68,6 +68,7 @@ access costs of local variables:
 %%SR
 overflow harmful?:  yes
 array bound harmful?:  yes
+reduce sli if shift count larger than:  0
 %%CS
 #include "../../../h/em_mnem.h"
 first time then space:

+ 1 - 0
util/ego/descr/em44.descr

@@ -68,6 +68,7 @@ access costs of local variables:
 %%SR
 overflow harmful?:  yes
 array bound harmful?:  yes
+reduce sli if shift count larger than:  0
 %%CS
 #include "../../../h/em_mnem.h"
 first time then space:

+ 1 - 0
util/ego/descr/i86.descr

@@ -83,6 +83,7 @@ access costs of local variables:
 %%SR
 overflow harmful?:  no
 array bound harmful?:  no
+reduce sli if shift count larger than:  0
 %%CS
 #include "../../../h/em_mnem.h"
 first time then space:

+ 1 - 0
util/ego/descr/m68020.descr

@@ -92,6 +92,7 @@ access costs of local variables:
 %%SR
 overflow harmful?:  no
 array bound harmful?:  no
+reduce sli if shift count larger than:  3
 %%CS
 #include "../../../h/em_mnem.h"
 first time then space:

+ 1 - 0
util/ego/descr/m68k2.descr

@@ -90,6 +90,7 @@ access costs of local variables:
 %%SR
 overflow harmful?:  no
 array bound harmful?:  no
+reduce sli if shift count larger than:  0
 %%CS
 #include "../../../h/em_mnem.h"
 first time then space:

+ 1 - 0
util/ego/descr/m68k4.descr

@@ -92,6 +92,7 @@ access costs of local variables:
 %%SR
 overflow harmful?:  no
 array bound harmful?:  no
+reduce sli if shift count larger than:  0
 %%CS
 #include "../../../h/em_mnem.h"
 first time then space:

+ 1 - 0
util/ego/descr/pdp.descr

@@ -82,6 +82,7 @@ access costs of local variables:
 %%SR
 overflow harmful?:  no
 array bound harmful?:  no
+reduce sli if shift count larger than:  0
 %%CS
 #include "../../../h/em_mnem.h"
 first time then space:

+ 1 - 0
util/ego/descr/sparc.descr

@@ -87,6 +87,7 @@ access costs of local variables:
 %%SR
 overflow harmful?:  no
 array bound harmful?:  yes
+reduce sli if shift count larger than:  0
 %%CS
 #include "../../../h/em_mnem.h"
 first time then space:

+ 1 - 1
util/ego/descr/vax4.descr

@@ -101,7 +101,7 @@ access costs of local variables:
 %%SR
 overflow harmful?:  no
 array bound harmful?:  no
-
+reduce sli if shift count larger than:  3
 %%CS
 #include "../../../h/em_mnem.h"
 first time then space:

+ 1 - 1
util/ego/sr/Makefile

@@ -4,7 +4,7 @@ EMH=$(EMHOME)/h
 EMLIB=$(EMHOME)/lib
 SHR=../share
 
-LDFLAGS=-i
+LDFLAGS=
 CPPFLAGS=-DVERBOSE -DNOTCOMPACT
 CFLAGS=$(CPPFLAGS) -O
 LINTFLAGS=-hbu

+ 3 - 1
util/ego/sr/sr.c

@@ -24,7 +24,7 @@
 
 /* Strength reduction tries to change expensive operators occurring
  * in a loop into cheaper operators. The expensive operators considered
- * are multiplication and array referencing.
+ * are multiplication, left-shift and array referencing.
  * The transformations can be expressed in C as:
  *
  * [1]:		for (i = e1; i <= e2; i++)
@@ -46,6 +46,7 @@
 
 int ovfl_harmful;
 int arrbound_harmful;
+int sli_threshold;
 
 int Ssr;  /* #optimizations found */
 
@@ -63,6 +64,7 @@ sr_machinit(f)
 	}
 	fscanf(f,"%d",&ovfl_harmful);
 	fscanf(f,"%d",&arrbound_harmful);
+	fscanf(f,"%d",&sli_threshold);
 }
 
 STATIC del_ivs(ivs)

+ 3 - 5
util/ego/sr/sr.h

@@ -9,11 +9,6 @@
  *
  */
 
-/*#define SLI_REDUCE		/* if defined, shift-lefts are also reduced */
-				/* not defined for the moment; should use
-				 * machine specific information (as should
-				 * reduction of array instructions	*/
-
 typedef struct iv	*iv_p;
 typedef struct code_info *code_p;
 
@@ -70,6 +65,9 @@ extern int ovfl_harmful;  /* Does overflow during multiplication
 extern int arrbound_harmful;  /* Is it harmful to take the address of
 				* a non-existing array element ?
 				*/
+extern int sli_threshold; /* Try to optimize SLI if shift-count larger than
+			    * this
+			    */
 extern int Ssr;  /* #optimizations found */
 
 /* core allocation macros */

+ 1 - 15
util/ego/sr/sr_reduce.c

@@ -45,10 +45,8 @@ STATIC int regtyp(code)
 	switch(code->co_instr) {
 		case op_mli:
 		case op_mlu:
-#ifdef SLI_REDUCE
 		case op_sli:
 		case op_slu:
-#endif
 			return reg_any;
 		default:
 			return reg_pointer;
@@ -92,10 +90,8 @@ STATIC line_p newcode(code,tmp)
 	switch(code->co_instr) {
 		case op_mli:
 		case op_mlu:
-#ifdef SLI_REDUCE
 		case op_sli:
 		case op_slu:
-#endif
 			/* new code is just a LOL tmp */
 			l = int_line(tmp);
 			l->l_instr = op_lol;
@@ -201,7 +197,6 @@ STATIC init_code(code,tmp)
 			l->l_next = int_line(tmp);
 			l->l_next->l_instr = op_stl;
 			break;
-#ifdef SLI_REDUCE
 		case op_sli:
 		case op_slu:
 			/* reduced code is: iv_expr << lc
@@ -211,7 +206,6 @@ STATIC init_code(code,tmp)
 			l->l_next = int_line(tmp);
 			l->l_next->l_instr = op_stl;
 			break;
-#endif
 		case op_lar:
 		case op_sar:
 			/* reduced code is: ...= A[iv_expr] resp.
@@ -283,7 +277,6 @@ STATIC incr_code(code,tmp)
 			store_tmp = int_line(tmp);
 			store_tmp->l_instr = op_stl;
 			break;
-#ifdef SLI_REDUCE
 		case op_sli:
 		case op_slu:
 			loc = int_line(
@@ -297,7 +290,6 @@ STATIC incr_code(code,tmp)
 			store_tmp = int_line(tmp);
 			store_tmp->l_instr = op_stl;
 			break;
-#endif
 		case op_lar:
 		case op_sar:
 		case op_aar:
@@ -416,10 +408,8 @@ STATIC bool same_code(c1,c2,vars)
 	switch(c1->co_instr) {
 		case op_mli:
 		case op_mlu:
-#ifdef SLI_REDUCE
 		case op_sli:
 		case op_slu:
-#endif
 			return c1->co_instr == c2->co_instr &&
 			off_set(c1->c_o.co_loadlc) ==
 			off_set(c2->c_o.co_loadlc) &&
@@ -616,7 +606,6 @@ STATIC try_multiply(lp,ivs,vars,b,mul)
 
 
 
-#ifdef SLI_REDUCE
 STATIC try_leftshift(lp,ivs,vars,b,shft)
 	loop_p   lp;
 	lset	 ivs,vars;
@@ -642,7 +631,7 @@ STATIC try_leftshift(lp,ivs,vars,b,shft)
 	 */
 
 	l2 = PREV(shft); /* Instruction before the shift */
-	if (is_const(l2) &&
+	if (is_const(l2) && off_set(l2) > sli_threshold &&
 		(is_ivexpr(PREV(l2),ivs,vars,&lbegin,&iv,&sign))) {
 			/* recognized "iv << const " */
 			c = newcinfo();
@@ -668,7 +657,6 @@ STATIC try_leftshift(lp,ivs,vars,b,shft)
 }
 
 
-#endif
 STATIC try_array(lp,ivs,vars,b,arr)
 	loop_p   lp;
 	lset	 ivs,vars;
@@ -760,12 +748,10 @@ strength_reduction(lp,ivs,vars)
 			next = l->l_next;
 			if (TYPE(l) == OPSHORT && SHORT(l) == ws) {
 				switch(INSTR(l)) {
-#ifdef SLI_REDUCE
 					case op_sli:
 					case op_slu:
 						try_leftshift(lp,ivs,vars,b,l);
 						break;
-#endif
 					case op_mlu:
 					case op_mli:
 						try_multiply(lp,ivs,vars,b,l);