1994-06-24 11:31:16 +00:00
|
|
|
/* $Id$ */
|
1987-03-09 19:15:41 +00:00
|
|
|
/*
|
|
|
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
|
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
|
|
*/
|
1984-11-26 15:04:22 +00:00
|
|
|
/* S H A R E D F I L E
|
|
|
|
*
|
|
|
|
* G O . C
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2016-08-21 20:01:19 +00:00
|
|
|
#include <unistd.h>
|
1984-11-26 15:04:22 +00:00
|
|
|
#include "types.h"
|
|
|
|
#include "debug.h"
|
|
|
|
#include "global.h"
|
|
|
|
#include "get.h"
|
|
|
|
#include "put.h"
|
|
|
|
#include "lset.h"
|
|
|
|
#include "map.h"
|
|
|
|
#include "alloc.h"
|
|
|
|
#include "go.h"
|
2016-08-21 20:01:19 +00:00
|
|
|
#include "files.h"
|
1984-11-26 15:04:22 +00:00
|
|
|
|
2016-08-21 16:51:36 +00:00
|
|
|
STATIC bool report_flag = FALSE; /* report #optimizations found? */
|
1991-10-29 09:24:48 +00:00
|
|
|
#ifdef DEBUG
|
2016-08-21 16:51:36 +00:00
|
|
|
STATIC bool core_flag = FALSE; /* report core usage? */
|
1991-10-29 09:24:48 +00:00
|
|
|
#endif
|
1984-11-26 15:04:22 +00:00
|
|
|
|
2017-11-15 21:29:27 +00:00
|
|
|
STATIC void mach_init(char* machfile, void (*phase_machinit)(void *))
|
1984-11-26 15:04:22 +00:00
|
|
|
{
|
|
|
|
/* Read target machine dependent information */
|
|
|
|
|
2016-08-21 16:51:36 +00:00
|
|
|
FILE* f;
|
1984-11-26 15:04:22 +00:00
|
|
|
|
2022-07-17 18:47:53 +00:00
|
|
|
f = openfile(machfile, "rb");
|
2016-08-21 16:51:36 +00:00
|
|
|
fscanf(f, "%d", &ws);
|
|
|
|
fscanf(f, "%d", &ps);
|
|
|
|
if (ws != ps && ps != 2 * ws)
|
|
|
|
error("illegal pointer size");
|
1987-03-16 15:14:52 +00:00
|
|
|
(*phase_machinit)(f);
|
1984-11-26 15:04:22 +00:00
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
|
2018-03-08 23:51:07 +00:00
|
|
|
void go(int argc, char * const *argv,
|
2017-11-15 21:29:27 +00:00
|
|
|
void (*initialize)(void *), void (*optimize)(void *),
|
|
|
|
void (*phase_machinit)(void *), void (*proc_flag)(void *))
|
1984-11-26 15:04:22 +00:00
|
|
|
{
|
2016-08-21 20:01:19 +00:00
|
|
|
struct files* files = findfiles(argc, argv);
|
2016-08-21 16:51:36 +00:00
|
|
|
FILE* f, *gf, *f2, *gf2; /* The EM input and output and
|
1984-11-26 15:04:22 +00:00
|
|
|
* the basic block graphs input and output
|
|
|
|
*/
|
|
|
|
bblock_p g;
|
|
|
|
line_p l;
|
|
|
|
short kind;
|
|
|
|
int i;
|
2016-08-21 16:51:36 +00:00
|
|
|
char* p;
|
1990-08-01 14:33:08 +00:00
|
|
|
bool time_opt = TRUE;
|
1984-11-26 15:04:22 +00:00
|
|
|
|
|
|
|
linecount = 0;
|
2016-08-21 20:01:19 +00:00
|
|
|
opterr = 0;
|
|
|
|
for (;;)
|
2016-08-21 16:51:36 +00:00
|
|
|
{
|
2016-08-21 20:01:19 +00:00
|
|
|
int opt = getopt(files->argc, files->argv, "STM:CQV");
|
|
|
|
if (opt == -1)
|
|
|
|
break;
|
|
|
|
|
|
|
|
switch (opt)
|
2016-08-21 16:51:36 +00:00
|
|
|
{
|
1984-11-26 15:04:22 +00:00
|
|
|
case 'S':
|
|
|
|
time_opt = FALSE;
|
|
|
|
break;
|
2016-08-21 20:01:19 +00:00
|
|
|
|
1984-11-26 15:04:22 +00:00
|
|
|
case 'T':
|
|
|
|
time_opt = TRUE;
|
|
|
|
break;
|
2016-08-21 20:01:19 +00:00
|
|
|
|
1984-11-26 15:04:22 +00:00
|
|
|
case 'M':
|
2016-08-21 20:01:19 +00:00
|
|
|
mach_init(optarg, phase_machinit);
|
1984-11-26 15:04:22 +00:00
|
|
|
break;
|
2016-08-21 20:01:19 +00:00
|
|
|
|
1984-11-26 15:04:22 +00:00
|
|
|
case 'C':
|
1991-10-29 09:24:48 +00:00
|
|
|
#ifdef DEBUG
|
1984-11-26 15:04:22 +00:00
|
|
|
core_flag = TRUE;
|
1991-10-29 09:24:48 +00:00
|
|
|
#endif
|
1984-11-26 15:04:22 +00:00
|
|
|
break;
|
2016-08-21 20:01:19 +00:00
|
|
|
|
1984-11-26 15:04:22 +00:00
|
|
|
case 'Q':
|
|
|
|
report_flag = TRUE;
|
|
|
|
break;
|
2016-08-21 20:01:19 +00:00
|
|
|
|
1984-11-26 15:04:22 +00:00
|
|
|
case 'V':
|
|
|
|
verbose_flag = TRUE;
|
|
|
|
break;
|
2016-08-21 20:01:19 +00:00
|
|
|
|
|
|
|
case '?':
|
|
|
|
proc_flag(argv[optind - 1]);
|
1984-11-26 15:04:22 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
time_space_ratio = (time_opt ? 100 : 0);
|
2016-08-21 20:01:19 +00:00
|
|
|
fproc = getptable(files->pname_in); /* proc table */
|
|
|
|
fdblock = getdtable(files->dname_in); /* data block table */
|
2017-11-15 21:29:27 +00:00
|
|
|
(*initialize)(NULL);
|
2016-08-21 16:51:36 +00:00
|
|
|
if (optimize == no_action)
|
|
|
|
return;
|
2022-07-17 18:47:53 +00:00
|
|
|
f = openfile(files->lname_in, "rb");
|
|
|
|
gf = openfile(files->bname_in, "rb");
|
|
|
|
f2 = openfile(files->lname_out, "wb");
|
|
|
|
gf2 = openfile(files->bname_out, "wb");
|
1984-11-26 15:04:22 +00:00
|
|
|
mesregs = Lempty_set();
|
2016-08-21 16:51:36 +00:00
|
|
|
while (getunit(gf, f, &kind, &g, &l, &curproc, TRUE))
|
|
|
|
{
|
1984-11-26 15:04:22 +00:00
|
|
|
/* Read the control flow graph and EM text of
|
|
|
|
* one procedure and optimize it.
|
|
|
|
*/
|
2016-08-21 16:51:36 +00:00
|
|
|
if (kind == LDATA)
|
|
|
|
{
|
|
|
|
putunit(LDATA, (proc_p)0, l, gf2, f2);
|
1984-11-26 15:04:22 +00:00
|
|
|
continue;
|
|
|
|
}
|
2016-08-21 16:51:36 +00:00
|
|
|
OUTTRACE("flow graph of proc %d read", curproc->p_id);
|
1984-11-26 15:04:22 +00:00
|
|
|
curproc->p_start = g;
|
|
|
|
/* The global variable curproc points to the
|
|
|
|
* current procedure. It is set by getgraph
|
|
|
|
*/
|
1987-03-16 15:14:52 +00:00
|
|
|
(*optimize)(curproc);
|
2016-08-21 16:51:36 +00:00
|
|
|
putunit(LTEXT, curproc, (line_p)0, gf2, f2);
|
1984-11-26 15:04:22 +00:00
|
|
|
/* output control flow graph + text */
|
2016-08-21 16:51:36 +00:00
|
|
|
OUTTRACE("graph of proc %d outputted", curproc->p_id);
|
1984-11-26 15:04:22 +00:00
|
|
|
Ldeleteset(mesregs);
|
|
|
|
mesregs = Lempty_set();
|
|
|
|
}
|
|
|
|
fclose(f);
|
|
|
|
fclose(f2);
|
|
|
|
fclose(gf);
|
|
|
|
fclose(gf2);
|
2022-07-17 18:47:53 +00:00
|
|
|
f = openfile(files->dname_out, "wb");
|
2016-08-21 16:51:36 +00:00
|
|
|
putdtable(fdblock, f);
|
1990-05-31 13:54:33 +00:00
|
|
|
/* fclose(f); done by putdtable */
|
2022-07-17 18:47:53 +00:00
|
|
|
f = openfile(files->pname_out, "wb");
|
2016-08-21 16:51:36 +00:00
|
|
|
putptable(fproc, f, TRUE);
|
1990-05-31 13:54:33 +00:00
|
|
|
/* fclose(f); done by putptable */
|
1984-11-26 15:04:22 +00:00
|
|
|
core_usage();
|
|
|
|
}
|
|
|
|
|
2017-11-15 21:29:27 +00:00
|
|
|
/* ARGSUSED */
|
|
|
|
void no_action(void *vp) {}
|
1984-11-26 15:04:22 +00:00
|
|
|
|
2016-08-21 20:01:19 +00:00
|
|
|
void core_usage(void)
|
1984-11-26 15:04:22 +00:00
|
|
|
{
|
1988-09-02 13:55:54 +00:00
|
|
|
#ifdef DEBUG
|
2016-08-21 16:51:36 +00:00
|
|
|
if (core_flag)
|
|
|
|
{
|
1984-11-26 15:04:22 +00:00
|
|
|
coreusage();
|
|
|
|
}
|
1988-09-02 13:55:54 +00:00
|
|
|
#endif
|
1984-11-26 15:04:22 +00:00
|
|
|
}
|
|
|
|
|
2016-08-21 20:01:19 +00:00
|
|
|
void report(char* s, int n)
|
1984-11-26 15:04:22 +00:00
|
|
|
{
|
|
|
|
/* Report number of optimizations found, if report_flag is set */
|
|
|
|
|
2016-08-21 16:51:36 +00:00
|
|
|
if (report_flag)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s: %d\n", s, n);
|
1984-11-26 15:04:22 +00:00
|
|
|
}
|
|
|
|
}
|