Next batch

This commit is contained in:
Manoel Trapier
2013-03-14 14:54:26 +01:00
committed by Manoël Trapier
parent bd3e7b87e6
commit 452127650a
62 changed files with 944 additions and 1307 deletions

View File

@@ -8,6 +8,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "../share/types.h"
#include "sr.h"
#include "../share/debug.h"
@@ -51,12 +52,11 @@ int sli_threshold;
int Ssr; /* #optimizations found */
sr_machinit(f)
FILE *f;
static int sr_machinit(void *param)
{
/* Read target machine dependent information */
char s[100];
FILE *f = (FILE*)param;
for (;;) {
while(getc(f) != '\n');
@@ -66,10 +66,11 @@ sr_machinit(f)
fscanf(f,"%d",&ovfl_harmful);
fscanf(f,"%d",&arrbound_harmful);
fscanf(f,"%d",&sli_threshold);
return 0;
}
STATIC del_ivs(ivs)
lset ivs;
static void del_ivs(lset ivs)
{
/* Delete the set of iv structs */
@@ -82,8 +83,7 @@ STATIC del_ivs(ivs)
}
STATIC do_loop(loop)
loop_p loop;
static void do_loop(loop_p loop)
{
lset ivs, vars;
@@ -110,13 +110,12 @@ STATIC do_loop(loop)
STATIC loopblocks(p)
proc_p p;
static void loopblocks(proc_p p)
{
/* Compute the LP_BLOCKS sets for all loops of p */
register bblock_p b;
register Lindex i;
bblock_p b;
Lindex i;
for (b = p->p_start; b != (bblock_p) 0; b = b->b_next) {
for (i = Lfirst(b->b_loops); i != (Lindex) 0;
@@ -128,8 +127,7 @@ STATIC loopblocks(p)
STATIC opt_proc(p)
proc_p p;
static void opt_proc(proc_p p)
{
/* Optimize all loops of one procedure. We first do all
* outer loops at the lowest nesting level and proceed
@@ -160,8 +158,7 @@ STATIC opt_proc(p)
STATIC bblock_p header(lp)
loop_p lp;
static bblock_p header(loop_p lp)
{
/* Try to determine the 'header' block of loop lp.
* If 'e' is the entry block of loop L, then block 'b' is
@@ -172,22 +169,21 @@ STATIC bblock_p header(lp)
bblock_p x = lp->lp_entry->b_idom;
if (x != (bblock_p) 0 && Lnrelems(x->b_succ) == 1 &&
(bblock_p) Lelem(Lfirst(x->b_succ)) == lp->lp_entry) {
if ( (x != NULL) && (Lnrelems(x->b_succ) == 1) &&
((bblock_p) Lelem(Lfirst(x->b_succ)) == lp->lp_entry) ) {
return x;
}
return (bblock_p) 0;
return NULL;
}
STATIC sr_extproc(p)
proc_p p;
static void sr_extproc(proc_p p)
{
/* Allocate the extended data structures for procedure p */
register loop_p lp;
register Lindex pi;
loop_p lp;
Lindex pi;
for (pi = Lfirst(p->p_loops); pi != (Lindex) 0;
pi = Lnext(pi,p->p_loops)) {
@@ -201,13 +197,12 @@ STATIC sr_extproc(p)
}
STATIC sr_cleanproc(p)
proc_p p;
static void sr_cleanproc(proc_p p)
{
/* Remove the extended data structures for procedure p */
register loop_p lp;
register Lindex pi;
loop_p lp;
Lindex pi;
for (pi = Lfirst(p->p_loops); pi != (Lindex) 0;
@@ -218,21 +213,21 @@ STATIC sr_cleanproc(p)
}
sr_optimize(p)
proc_p p;
static int sr_optimize(void *param)
{
if (IS_ENTERED_WITH_GTO(p)) return;
proc_p p = (proc_p)param;
if (IS_ENTERED_WITH_GTO(p)) return 0;
sr_extproc(p);
loopblocks(p);
opt_proc(p);
sr_cleanproc(p);
return 0;
}
main(argc,argv)
int argc;
char *argv[];
int main(int argc, char *argv[])
{
go(argc,argv,no_action,sr_optimize,sr_machinit,no_action);
report("strength reductions",Ssr);

View File

@@ -24,9 +24,7 @@
#define INSIDE_LOOP(b,lp) Lis_elem(b,lp->LP_BLOCKS)
bool is_loopconst(lnp,vars)
line_p lnp;
lset vars;
bool is_loopconst(line_p lnp, lset vars)
{
Lindex i;
@@ -41,9 +39,7 @@ bool is_loopconst(lnp,vars)
}
bool is_caddress(lnp,vars)
line_p lnp;
lset vars; /* variables changed in loop */
bool is_caddress(line_p lnp, lset vars)
{
/* See if lnp is a single instruction (i.e. without arguments)
* that pushes a loop-invariant entity of size pointer-size (ps)
@@ -63,13 +59,12 @@ bool is_caddress(lnp,vars)
return FALSE;
}
/* NOTREACHED */
return FALSE;
}
STATIC arg_p find_arg(n,list)
int n;
arg_p list;
static arg_p find_arg(int n, arg_p list)
{
/* Find the n-th element of the list */
@@ -81,8 +76,7 @@ STATIC arg_p find_arg(n,list)
}
int elemsize(lnp)
line_p lnp;
int elemsize(line_p lnp)
{
/* lnp is an instruction that loads the address of an array
* descriptor. Find the size of the elements of the array.
@@ -107,12 +101,11 @@ int elemsize(lnp)
concatenate(list1,list2)
line_p list1,list2;
void concatenate(line_p list1, line_p list2)
{
/* Append list2 to the end of list1. list1 may not be empty. */
register line_p l;
line_p l;
assert(list1 != (line_p) 0);
for (l =list1; l->l_next != (line_p) 0; l = l->l_next);

View File

@@ -6,20 +6,20 @@
/* S R _ A U X . H */
extern bool is_loopconst(); /* (line_p l; lset vars)
* See if l is a loop-constant. vars is the
bool is_loopconst(line_p lnp, lset vars);
/* See if l is a loop-constant. vars is the
* set of variables changed in the loop.
*/
extern bool is_caddress(); /* (line_p l)
* See if l loads a loop-invariant entity of
bool is_caddress(line_p lnp, lset vars);
/* See if l loads a loop-invariant entity of
* size pointer-size.
*/
extern int elemsize(); /* (line_p l)
* l is an instruction that loads an array
int elemsize(line_p lnp);
/* l is an instruction that loads an array
* descriptor. Try to determine the size
* of the array elements.
*/
extern concatenate(); /* (line_p list1,list2)
* Append list2 to the end of list1
void concatenate(line_p list1, line_p list2);
/* Append list2 to the end of list1
*/
#define is_const(l) (INSTR(l) == op_loc)

View File

@@ -41,7 +41,7 @@
*/
STATIC lset cand, /* set of candidates */
static lset cand, /* set of candidates */
dism; /* set of dismissed variables */
@@ -49,8 +49,7 @@ STATIC lset cand, /* set of candidates */
STATIC un_cand(lnp)
line_p lnp;
static void un_cand(line_p lnp)
{
/* remove the variable stored into by lnp from the list of
* candidates (if it was there anyway).
@@ -68,8 +67,7 @@ STATIC un_cand(lnp)
}
STATIC bool is_cand(lnp)
line_p lnp;
static bool is_cand(line_p lnp)
{
/* see if the variable stored into by lnp is a candate */
@@ -84,8 +82,7 @@ STATIC bool is_cand(lnp)
}
STATIC make_cand(lnp)
line_p lnp;
static void make_cand(line_p lnp)
{
/* make the variable stored into by lnp a candidate */
@@ -96,15 +93,13 @@ STATIC make_cand(lnp)
STATIC do_dismiss(lnp)
line_p lnp;
static void do_dismiss(line_p lnp)
{
Ladd(lnp,&dism);
}
STATIC dismiss(lnp)
line_p lnp;
static void dismiss(line_p lnp)
{
/* The variable referenced by lnp is turned definitely into
* a non-candidate.
@@ -117,8 +112,7 @@ STATIC dismiss(lnp)
}
STATIC bool not_dismissed(lnp)
line_p lnp;
static bool not_dismissed(line_p lnp)
{
Lindex i;
@@ -131,9 +125,7 @@ STATIC bool not_dismissed(lnp)
}
STATIC try_cand(lnp,b)
line_p lnp;
bblock_p b;
static void try_cand(line_p lnp, bblock_p b)
{
/* If the variable stored into by lnp was not already a candidate
* and was not dismissed, then it is made a candidate
@@ -151,9 +143,7 @@ STATIC try_cand(lnp,b)
}
candidates(lp,cand_out,vars_out)
loop_p lp;
lset *cand_out, *vars_out;
void candidates(loop_p lp, lset *cand_out, lset *vars_out)
{
/* Find the candidate induction variables.
*/

View File

@@ -9,8 +9,8 @@
*/
extern candidates(); /* (loop_p lp; lset *iv_cand, *vars)
* Find candidate induction variables,
void candidates(loop_p lp, lset *cand_out, lset *vars_out);
/* Find candidate induction variables,
* i.e. local variables that are assigned
* a value precisely once within the loop,
* within a strong block. Also find the

View File

@@ -26,10 +26,9 @@
STATIC lset ivvars; /* set of induction variables */
static lset ivvars; /* set of induction variables */
STATIC short nature(lnp)
line_p lnp;
static short nature(line_p lnp)
{
/* Auxiliary routine used by inc_or_dec, is_add and plus_or_min.
* Determine if lnp had INCREMENT/DECREMENT-nature (1),
@@ -62,8 +61,7 @@ STATIC short nature(lnp)
#define inc_or_dec(l) (nature(l) == 1)
STATIC bool is_same(l,lnp)
line_p l, lnp;
static bool is_same(line_p l, line_p lnp)
{
/* lnp is a STL x , where x is a candidate
* induction variable. See if l is a LOL x
@@ -76,9 +74,7 @@ STATIC bool is_same(l,lnp)
}
STATIC ivar(lnp,step)
line_p lnp;
int step;
static void ivar(line_p lnp, int step)
{
/* Record the fact that we've found a new induction variable.
* lnp points to the last instruction of the code that
@@ -95,8 +91,7 @@ STATIC ivar(lnp,step)
}
STATIC int sign(lnp)
line_p lnp;
static int sign(line_p lnp)
{
switch(INSTR(lnp)) {
case op_inc:
@@ -113,11 +108,11 @@ STATIC int sign(lnp)
assert(FALSE);
}
/* NOTREACHED */
return FALSE;
}
STATIC try_patterns(lnp)
line_p lnp;
static void try_patterns(line_p lnp)
{
/* lnp is a STL x; try to recognize
* one of the patterns:
@@ -153,9 +148,7 @@ STATIC try_patterns(lnp)
}
induc_vars(loop,ivar_out, vars_out)
loop_p loop;
lset *ivar_out, *vars_out;
void induc_vars(loop_p loop, lset *ivar_out, lset *vars_out)
{
/* Construct the set of induction variables. We use several
* global variables computed by 'candidates'.

View File

@@ -5,8 +5,8 @@
*/
/* S R _ I V . H */
extern induc_vars(); /* (loop_p loop; lset *ivars, *vars)
* Find the set of induction variables
void induc_vars(loop_p loop, lset *ivar_out, lset *vars_out);
/* Find the set of induction variables
* of the loop. Also find the set of (local)
* variables that are changed.
*/

View File

@@ -30,7 +30,7 @@
STATIC lset avail;
static lset avail;
/* If an expression such as "iv * const" or "A[iv]" is
* used more than once in a loop, we only use one temporary
* local for it and reuse this local each time.
@@ -38,8 +38,7 @@ STATIC lset avail;
* be available.
*/
STATIC int regtyp(code)
code_p code;
static int regtyp(code_p code)
{
switch(code->co_instr) {
case op_mli:
@@ -51,14 +50,11 @@ STATIC int regtyp(code)
return reg_pointer;
}
/* NOTREACHED */
return reg_pointer;
}
STATIC gen_regmes(tmp,score,code,p)
offset tmp;
int score;
code_p code;
proc_p p;
static void gen_regmes(offset tmp, int score, code_p code, proc_p p)
{
/* generate a register message for the temporary variable and
* insert it at the start of the procedure.
@@ -75,9 +71,7 @@ STATIC gen_regmes(tmp,score,code,p)
}
STATIC line_p newcode(code,tmp)
code_p code;
offset tmp;
static line_p newcode(code_p code, offset tmp)
{
/* Construct the EM code that will replace the reducible code,
* e.g. iv * c -> tmp
@@ -120,9 +114,7 @@ STATIC line_p newcode(code,tmp)
STATIC replcode(code,text)
code_p code;
line_p text;
static void replcode(code_p code, line_p text)
{
/* Replace old code (extending from code->co_lfirst to
* code->co_llast) by new code (headed by 'text').
@@ -149,8 +141,7 @@ STATIC replcode(code,text)
/* Note that the old code is still accessible via code->co_lfirst */
}
STATIC line_p add_code(pl, l)
line_p pl, l;
static line_p add_code(line_p pl, line_p l)
{
if (! pl) {
PREV(l) = 0;
@@ -170,9 +161,7 @@ STATIC line_p add_code(pl, l)
STATIC init_code(code,tmp)
code_p code;
offset tmp;
static void init_code(code_p code, offset tmp)
{
/* Generate code to set up the temporary local.
* For multiplication, its initial value is const*iv_expr,
@@ -238,9 +227,7 @@ STATIC init_code(code,tmp)
*p = l; /* new last instruction */
}
STATIC incr_code(code,tmp)
code_p code;
offset tmp;
static void incr_code(code_p code, offset tmp)
{
/* Generate code to increment the temporary local variable.
* The variable is incremented by
@@ -321,8 +308,7 @@ STATIC incr_code(code,tmp)
}
STATIC remcode(c)
code_p c;
static void remcode(code_p c)
{
line_p l, next;
@@ -334,9 +320,7 @@ STATIC remcode(c)
}
STATIC bool same_address(l1,l2,vars)
line_p l1,l2;
lset vars;
static bool same_address(line_p l1, line_p l2, lset vars)
{
/* See if l1 and l2 load the same address */
@@ -357,18 +341,17 @@ STATIC bool same_address(l1,l2,vars)
default:
return FALSE;
}
return FALSE;
}
STATIC bool same_expr(lb1,le1,lb2,le2)
line_p lb1,le1,lb2,le2;
static bool same_expr(line_p lb1, line_p le1, line_p lb2, line_p le2)
{
/* See if the code from lb1 to le1 is the same
* expression as the code from lb2 to le2.
*/
register line_p l1,l2;
line_p l1,l2;
l1 = lb1;
l2 = lb2;
@@ -395,9 +378,7 @@ STATIC bool same_expr(lb1,le1,lb2,le2)
}
}
STATIC bool same_code(c1,c2,vars)
code_p c1,c2;
lset vars;
static bool same_code(code_p c1, code_p c2, lset vars)
{
/* See if c1 and c2 compute the same expression. Two array
* references can be the same even if one is e.g a fetch
@@ -428,12 +409,11 @@ STATIC bool same_code(c1,c2,vars)
assert(FALSE);
}
/* NOTREACHED */
return FALSE;
}
STATIC code_p available(c,vars)
code_p c;
lset vars;
static code_p available(code_p c, lset vars)
{
/* See if the code is already available.
* If so, return a pointer to the first occurrence
@@ -452,8 +432,7 @@ STATIC code_p available(c,vars)
return (code_p) 0;
}
STATIC fix_header(lp)
loop_p lp;
static void fix_header(loop_p lp)
{
/* Check if a header block was added, and if so, add a branch to
* the entry block.
@@ -486,21 +465,19 @@ STATIC fix_header(lp)
}
}
STATIC reduce(code,vars)
code_p code;
lset vars;
static void reduce(code_p code, lset vars)
{
/* Perform the actual transformations. The code on the left
* gets transformed into the code on the right. Note that
* each piece of code is assigned a name, that will be
* used to describe the whole process.
*
* t = iv * 118; (init_code)
* do ---> do
* .. iv * 118 .. .. t .. (new_code)
* iv++; iv++;
* t += 118; (incr_code)
* od od
* t = iv * 118; (init_code)
* do ---> do
* .. iv * 118 .. .. t .. (new_code)
* iv++; iv++;
* t += 118; (incr_code)
* od od
*/
offset tmp;
@@ -543,11 +520,7 @@ STATIC reduce(code,vars)
STATIC try_multiply(lp,ivs,vars,b,mul)
loop_p lp;
lset ivs,vars;
bblock_p b;
line_p mul;
static void try_multiply(loop_p lp, lset ivs, lset vars, bblock_p b, line_p mul)
{
/* See if we can reduce the strength of the multiply
* instruction. If so, then set up the global common
@@ -605,11 +578,7 @@ STATIC try_multiply(lp,ivs,vars,b,mul)
STATIC try_leftshift(lp,ivs,vars,b,shft)
loop_p lp;
lset ivs,vars;
bblock_p b;
line_p shft;
static void try_leftshift(loop_p lp, lset ivs, lset vars, bblock_p b, line_p shft)
{
/* See if we can reduce the strength of the leftshift
* instruction. If so, then set up the global common
@@ -656,11 +625,7 @@ STATIC try_leftshift(lp,ivs,vars,b,shft)
}
STATIC try_array(lp,ivs,vars,b,arr)
loop_p lp;
lset ivs,vars;
bblock_p b;
line_p arr;
static void try_array(loop_p lp, lset ivs, lset vars, bblock_p b, line_p arr)
{
/* See if we can reduce the strength of the array reference
* instruction 'arr'.
@@ -710,7 +675,7 @@ STATIC try_array(lp,ivs,vars,b,arr)
STATIC clean_avail()
static void clean_avail()
{
Lindex i;
@@ -721,11 +686,12 @@ STATIC clean_avail()
}
strength_reduction(lp,ivs,vars)
loop_p lp; /* description of the loop */
lset ivs; /* set of induction variables of the loop */
lset vars; /* set of local variables changed in loop */
/*
* lp ==> description of the loop
* ivs ==> set of induction variables of the loop
* vars ==> set of local variables changed in loop
*/
void strength_reduction(loop_p lp, lset ivs, lset vars)
{
/* Find all expensive instructions (leftshift, multiply, array) and see
* if they can be reduced. We branch to several instruction-specific

View File

@@ -5,6 +5,6 @@
*/
/* S R _ R E D U C E . H */
extern strength_reduction(); /* (loop_p loop; lset ivs, vars)
* Perform streength reduction.
void strength_reduction(loop_p lp, lset ivs, lset vars);
/* Perform streength reduction.
*/

View File

@@ -29,9 +29,7 @@
/* Transformations on EM texts */
line_p move_pointer(tmp,dir)
offset tmp;
int dir;
line_p move_pointer(offset tmp, int dir)
{
/* Generate EM code to load/store a pointer variable
* onto/from the stack, depending on dir(ection).
@@ -66,9 +64,7 @@ line_p move_pointer(tmp,dir)
/* make_header */
STATIC copy_loops(b1,b2,except)
bblock_p b1,b2;
loop_p except;
static void copy_loops(bblock_p b1, bblock_p b2, loop_p except)
{
/* Copy the loopset of b2 to b1, except for 'except' */
@@ -84,8 +80,7 @@ STATIC copy_loops(b1,b2,except)
}
STATIC lab_id label(b)
bblock_p b;
static lab_id label(bblock_p b)
{
/* Find the label at the head of block b. If there is
* no such label yet, create one.
@@ -108,8 +103,7 @@ STATIC lab_id label(b)
}
STATIC adjust_jump(newtarg,oldtarg,c)
bblock_p newtarg,oldtarg,c;
static void adjust_jump(bblock_p newtarg, bblock_p oldtarg, bblock_p c)
{
/* If the last instruction of c is a jump to the
* old target, then change it into a jump to the
@@ -138,8 +132,7 @@ STATIC adjust_jump(newtarg,oldtarg,c)
}
make_header(lp)
loop_p lp;
void make_header(loop_p lp)
{
/* Make sure that the loop has a header block, i.e. a block
* has the loop entry block as its only successor and

View File

@@ -11,12 +11,12 @@
extern line_p move_pointer(); /* (offset tmp; int dir ) */
line_p move_pointer(offset tmp, int dir);
/* Generate EM code to load/store a pointer variable
* onto/from the stack, depending on dir(ection).
* We accept all kinds of pointer sizes.
*/
extern make_header() ; /* (loop_p lp) */
void make_header(loop_p lp);
/* Make sure that the loop has a header block, i.e. a block
* has the loop entry block as its only successor and
* that dominates the loop entry block.