Run through clang-format.

This commit is contained in:
David Given 2016-08-21 19:38:54 +02:00
parent 1b66b63eae
commit 918f300513

View file

@ -29,7 +29,7 @@
int calnr; int calnr;
int complete_program; int complete_program;
calcnt_p cchead; /* call-count info of current proc */ calcnt_p cchead; /* call-count info of current proc */
STATIC long space = 0; STATIC long space = 0;
STATIC long total_size = 0; STATIC long total_size = 0;
@ -42,8 +42,8 @@ STATIC int kp_temps = 0;
int Ssubst; int Ssubst;
#ifdef VERBOSE #ifdef VERBOSE
int Senv,Srecursive,Slocals,Sinstrlab,Sparsefails,Spremoved,Scals; int Senv, Srecursive, Slocals, Sinstrlab, Sparsefails, Spremoved, Scals;
int Sbig_caller,Sdispensable,Schangedcallee,Sbigcallee,Sspace,Szeroratio; int Sbig_caller, Sdispensable, Schangedcallee, Sbigcallee, Sspace, Szeroratio;
#endif #endif
/* P A S S 1 /* P A S S 1
@ -56,10 +56,9 @@ int Sbig_caller,Sdispensable,Schangedcallee,Sbigcallee,Sspace,Szeroratio;
* The call descriptors are put in a file (calfile). * The call descriptors are put in a file (calfile).
*/ */
pass1(lnam,bnam,cnam) pass1(lnam, bnam, cnam) char* lnam, *bnam, *cnam;
char *lnam, *bnam, *cnam;
{ {
FILE *f, *gf, *cf, *ccf; /* The EM input, the basic block graph, FILE* f, *gf, *cf, *ccf; /* The EM input, the basic block graph,
* the call-list file and the calcnt file. * the call-list file and the calcnt file.
*/ */
long laddr; long laddr;
@ -67,26 +66,29 @@ pass1(lnam,bnam,cnam)
short kind; short kind;
line_p l; line_p l;
f = openfile(lnam,"r"); f = openfile(lnam, "r");
gf = openfile(bnam,"r"); gf = openfile(bnam, "r");
cf = openfile(cnam,"w"); cf = openfile(cnam, "w");
ccf = openfile(ccname,"w"); ccf = openfile(ccname, "w");
mesregs = Lempty_set(); mesregs = Lempty_set();
apriori(fproc); apriori(fproc);
/* use information from the procedure table to /* use information from the procedure table to
* see which calls certainly cannot be expanded. * see which calls certainly cannot be expanded.
*/ */
while(TRUE) { while (TRUE)
{
laddr = ftell(f); laddr = ftell(f);
if (!getunit(gf,f,&kind,&g,&l,&curproc,TRUE)) break; if (!getunit(gf, f, &kind, &g, &l, &curproc, TRUE))
break;
/* Read the control flow graph and EM text of /* Read the control flow graph and EM text of
* one procedure and analyze it. * one procedure and analyze it.
*/ */
if (kind == LDATA) { if (kind == LDATA)
remunit(LDATA,(proc_p) 0,l); {
remunit(LDATA, (proc_p)0, l);
continue; continue;
} }
OUTTRACE("flow graph of proc %d read",curproc->p_id); OUTTRACE("flow graph of proc %d read", curproc->p_id);
assert(INSTR(g->b_start) == ps_pro); assert(INSTR(g->b_start) == ps_pro);
curproc->p_start = g; curproc->p_start = g;
curproc->P_LADDR = laddr; curproc->P_LADDR = laddr;
@ -94,16 +96,17 @@ pass1(lnam,bnam,cnam)
/* address of graph in basic block file */ /* address of graph in basic block file */
curproc->P_SIZE = proclength(curproc); /* #instructions */ curproc->P_SIZE = proclength(curproc); /* #instructions */
total_size += curproc->P_SIZE; total_size += curproc->P_SIZE;
if (BIG_PROC(curproc)) { if (BIG_PROC(curproc))
{
/* curproc is too large to be expanded in line */ /* curproc is too large to be expanded in line */
UNSUITABLE(curproc); UNSUITABLE(curproc);
} }
calnr = 0; calnr = 0;
anal_proc(curproc,cf,ccf); anal_proc(curproc, cf, ccf);
OUTTRACE("proc %d processed",curproc->p_id); OUTTRACE("proc %d processed", curproc->p_id);
remunit(LTEXT,curproc,(line_p) 0); remunit(LTEXT, curproc, (line_p)0);
/* remove control flow graph + text */ /* remove control flow graph + text */
OUTTRACE("graph of proc %d removed",curproc->p_id); OUTTRACE("graph of proc %d removed", curproc->p_id);
Ldeleteset(mesregs); Ldeleteset(mesregs);
mesregs = Lempty_set(); mesregs = Lempty_set();
} }
@ -113,55 +116,58 @@ pass1(lnam,bnam,cnam)
fclose(ccf); fclose(ccf);
} }
/* P A S S 2 /* P A S S 2
* *
* Pass 2 reads the calfile and determines which calls should * Pass 2 reads the calfile and determines which calls should
* be expanded in line. It does not use the EM text. * be expanded in line. It does not use the EM text.
*/ */
STATIC char cname2[128] = TMP_DIR; STATIC char cname2[128] = TMP_DIR;
pass2(cnam,space) pass2(cnam, space) char* cnam;
char *cnam; long space;
long space;
{ {
FILE *cf, *cf2, *ccf; FILE* cf, *cf2, *ccf;
call_p c,a; call_p c, a;
cf = openfile(cnam,"r"); cf = openfile(cnam, "r");
cf2 = openfile(cname2,"w"); cf2 = openfile(cname2, "w");
ccf = openfile(ccname,"r"); ccf = openfile(ccname, "r");
while ((c = getcall(cf)) != (call_p) 0) { while ((c = getcall(cf)) != (call_p)0)
{
/* process all calls */ /* process all calls */
if (SUITABLE(c->cl_proc) && anal_params(c)) { if (SUITABLE(c->cl_proc) && anal_params(c))
{
/* called proc. may be put in line */ /* called proc. may be put in line */
/* see which parameters may be put in line */ /* see which parameters may be put in line */
assign_ratio(c); /* assign a rank */ assign_ratio(c); /* assign a rank */
a = abstract(c); /* abstract essential info */ a = abstract(c); /* abstract essential info */
append_abstract(a,a->cl_caller); append_abstract(a, a->cl_caller);
/* put it in call-list of calling proc. */ /* put it in call-list of calling proc. */
putcall(c,cf2,(short) 0); putcall(c, cf2, (short)0);
} else { }
else
{
rem_call(c); rem_call(c);
} }
} }
select_calls(fproc,ccf,space); select_calls(fproc, ccf, space);
fclose(cf); if (! kp_temps) unlink(cnam); fclose(cf);
if (!kp_temps)
unlink(cnam);
fclose(cf2); fclose(cf2);
fclose(ccf); if (! kp_temps) unlink(ccname); fclose(ccf);
cf2 = openfile(cname2,"r"); if (!kp_temps)
add_actuals(fproc,cf2); unlink(ccname);
cf2 = openfile(cname2, "r");
add_actuals(fproc, cf2);
cleancals(fproc); /* remove calls that were not selected */ cleancals(fproc); /* remove calls that were not selected */
/* add actual parameters to each selected call */ /* add actual parameters to each selected call */
fclose(cf2); if (! kp_temps) unlink(cname2); fclose(cf2);
if (!kp_temps)
unlink(cname2);
} }
/* P A S S 3 /* P A S S 3
* *
* pass 3 reads the substitution file and performs all * pass 3 reads the substitution file and performs all
@ -170,67 +176,76 @@ pass2(cnam,space)
* EM textfile. * EM textfile.
*/ */
pass3(lnam, lnam2) char* lnam, *lnam2;
pass3(lnam,lnam2)
char *lnam,*lnam2;
{ {
bool verbose = TRUE; bool verbose = TRUE;
FILE *lfile, *lfilerand, *lfile2, *sfile; FILE* lfile, *lfilerand, *lfile2, *sfile;
call_p c,next; call_p c, next;
line_p l,startscan,cal; line_p l, startscan, cal;
short lastcid; /* last call-id seen */ short lastcid; /* last call-id seen */
lfile = openfile(lnam, "r"); lfile = openfile(lnam, "r");
lfilerand = openfile(lnam, "r"); lfilerand = openfile(lnam, "r");
lfile2 = openfile(lnam2,"w"); lfile2 = openfile(lnam2, "w");
if (verbose) { if (verbose)
sfile = openfile(sname,"w"); {
sfile = openfile(sname, "w");
} }
mesregs = Lempty_set(); mesregs = Lempty_set();
while ((l = get_text(lfile,&curproc)) != (line_p) 0) { while ((l = get_text(lfile, &curproc)) != (line_p)0)
if (curproc == (proc_p) 0) { {
if (curproc == (proc_p)0)
{
/* Just a data-unit; no real instructions */ /* Just a data-unit; no real instructions */
putlines(l->l_next,lfile2); putlines(l->l_next, lfile2);
oldline(l); oldline(l);
continue; continue;
} }
if (IS_DISPENSABLE(curproc)) { if (IS_DISPENSABLE(curproc))
liquidate(curproc,l->l_next); {
} else { liquidate(curproc, l->l_next);
}
else
{
startscan = l->l_next; startscan = l->l_next;
lastcid = 0; lastcid = 0;
for (c = curproc->P_CALS; c != (call_p) 0; c = next) { for (c = curproc->P_CALS; c != (call_p)0; c = next)
{
next = c->cl_cdr; next = c->cl_cdr;
cal = scan_to_cal(startscan,c->cl_id - lastcid); cal = scan_to_cal(startscan, c->cl_id - lastcid);
assert (cal != (line_p) 0); assert(cal != (line_p)0);
startscan = scan_to_cal(cal->l_next,1); startscan = scan_to_cal(cal->l_next, 1);
/* next CAL */ /* next CAL */
lastcid = c->cl_id; lastcid = c->cl_id;
/* next CAL after current one */ /* next CAL after current one */
substitute(lfilerand,c,cal,l->l_next); substitute(lfilerand, c, cal, l->l_next);
if (verbose) { if (verbose)
putcall(c,sfile,0); {
} else { putcall(c, sfile, 0);
}
else
{
rem_call(c); rem_call(c);
} }
} }
} }
putlines(l->l_next,lfile2); putlines(l->l_next, lfile2);
Ldeleteset(mesregs); Ldeleteset(mesregs);
mesregs = Lempty_set(); mesregs = Lempty_set();
oldline(l); oldline(l);
} }
fclose(lfile); fclose(lfile);
fclose(lfile2); fclose(lfile2);
if (verbose) { if (verbose)
{
fclose(sfile); fclose(sfile);
if (! kp_temps) unlink(sname); if (!kp_temps)
unlink(sname);
} }
} }
STATIC il_extptab(ptab) STATIC il_extptab(ptab)
proc_p ptab; proc_p ptab;
{ {
/* Allocate space for extension of proctable entries. /* Allocate space for extension of proctable entries.
* Also, initialise some of the fields just allocated. * Also, initialise some of the fields just allocated.
@ -238,7 +253,8 @@ STATIC il_extptab(ptab)
register proc_p p; register proc_p p;
for (p = ptab; p != (proc_p) 0; p = p->p_next) { for (p = ptab; p != (proc_p)0; p = p->p_next)
{
p->p_extend = newilpx(); p->p_extend = newilpx();
p->P_ORGLABELS = p->p_nrlabels; p->P_ORGLABELS = p->p_nrlabels;
p->P_ORGLOCALS = p->p_localbytes; p->P_ORGLOCALS = p->p_localbytes;
@ -246,13 +262,14 @@ STATIC il_extptab(ptab)
} }
STATIC il_cleanptab(ptab) STATIC il_cleanptab(ptab)
proc_p ptab; proc_p ptab;
{ {
/* De-allocate space for extensions */ /* De-allocate space for extensions */
register proc_p p; register proc_p p;
for (p = ptab; p != (proc_p) 0; p = p->p_next) { for (p = ptab; p != (proc_p)0; p = p->p_next)
{
oldilpx(p->p_extend); oldilpx(p->p_extend);
} }
} }
@ -262,55 +279,55 @@ Sdiagnostics()
{ {
/* print statictical information */ /* print statictical information */
fprintf(stderr,"STATISTICS:\n"); fprintf(stderr, "STATISTICS:\n");
fprintf(stderr,"Info about procedures:\n"); fprintf(stderr, "Info about procedures:\n");
fprintf(stderr,"environment accessed: %d\n",Senv); fprintf(stderr, "environment accessed: %d\n", Senv);
fprintf(stderr,"recursive: %d\n",Srecursive); fprintf(stderr, "recursive: %d\n", Srecursive);
fprintf(stderr,"too many locals: %d\n",Slocals); fprintf(stderr, "too many locals: %d\n", Slocals);
fprintf(stderr,"instr. lab in data block: %d\n",Sinstrlab); fprintf(stderr, "instr. lab in data block: %d\n", Sinstrlab);
fprintf(stderr,"procedures removed: %d\n",Spremoved); fprintf(stderr, "procedures removed: %d\n", Spremoved);
fprintf(stderr,"\nInfo about calls:\n"); fprintf(stderr, "\nInfo about calls:\n");
fprintf(stderr,"total number of calls: %d\n",Scals); fprintf(stderr, "total number of calls: %d\n", Scals);
fprintf(stderr,"total number of calls substituted: %d\n",Ssubst); fprintf(stderr, "total number of calls substituted: %d\n", Ssubst);
fprintf(stderr,"parser failed: %d\n",Sparsefails); fprintf(stderr, "parser failed: %d\n", Sparsefails);
fprintf(stderr,"caller too big: %d\n",Sbig_caller); fprintf(stderr, "caller too big: %d\n", Sbig_caller);
fprintf(stderr,"caller dispensable: %d\n",Sdispensable); fprintf(stderr, "caller dispensable: %d\n", Sdispensable);
fprintf(stderr,"callee is changed: %d\n",Schangedcallee); fprintf(stderr, "callee is changed: %d\n", Schangedcallee);
fprintf(stderr,"callee too big: %d\n",Sbigcallee); fprintf(stderr, "callee too big: %d\n", Sbigcallee);
fprintf(stderr,"no space available: %d\n",Sspace); fprintf(stderr, "no space available: %d\n", Sspace);
fprintf(stderr,"zero ratio: %d\n",Szeroratio); fprintf(stderr, "zero ratio: %d\n", Szeroratio);
} }
#endif #endif
il_flags(p) il_flags(p) char* p;
char *p;
{ {
switch(*p++) { switch (*p++)
case 's': {
while (*p != '\0') { case 's':
space = 10*space +*p++ -'0'; while (*p != '\0')
} {
break; space = 10 * space + *p++ - '0';
case 'a': }
complete_program = 1; break;
break; case 'a':
case 't': complete_program = 1;
strcpy(cname, "."); break;
strcpy(ccname, "."); case 't':
strcpy(sname, "."); strcpy(cname, ".");
strcpy(cname2, "."); strcpy(ccname, ".");
kp_temps = 1; strcpy(sname, ".");
break; strcpy(cname2, ".");
kp_temps = 1;
break;
} }
} }
main(argc,argv) main(argc, argv) int argc;
int argc; char* argv[];
char *argv[];
{ {
FILE *f; FILE* f;
go(argc,argv,no_action,no_action,no_action,il_flags); go(argc, argv, no_action, no_action, no_action, il_flags);
il_extptab(fproc); /* add extended data structures */ il_extptab(fproc); /* add extended data structures */
strcat(cname, "/ego.i1.XXXXXX"); strcat(cname, "/ego.i1.XXXXXX");
strcat(ccname, "/ego.i2.XXXXXX"); strcat(ccname, "/ego.i2.XXXXXX");
@ -320,18 +337,19 @@ main(argc,argv)
mktemp(ccname); mktemp(ccname);
mktemp(sname); mktemp(sname);
mktemp(cname2); mktemp(cname2);
pass1(lname,bname,cname); /* grep calls, analyse procedures */ pass1(lname, bname, cname); /* grep calls, analyse procedures */
space = total_size * space / 100 ; space = total_size * space / 100;
pass2(cname,space); /* select calls to be expanded */ pass2(cname, space); /* select calls to be expanded */
pass3(lname,lname2); /* do substitutions */ pass3(lname, lname2); /* do substitutions */
f = openfile(dname2,"w"); f = openfile(dname2, "w");
il_cleanptab(fproc); /* remove extended data structures */ il_cleanptab(fproc); /* remove extended data structures */
putdtable(fdblock,f); putdtable(fdblock, f);
f = openfile(pname2,"w"); f = openfile(pname2, "w");
putptable(fproc,f,FALSE); putptable(fproc, f, FALSE);
report("inline substitutions",Ssubst); report("inline substitutions", Ssubst);
#ifdef VERBOSE #ifdef VERBOSE
if (verbose_flag) { if (verbose_flag)
{
Sdiagnostics(); Sdiagnostics();
} }
#endif #endif