ack/util/ego/cs/cs_vnm.c

336 lines
6.5 KiB
C
Raw Normal View History

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 13:58:05 +00:00
/* V A L U E N U M B E R I N G M E T H O D */
1991-03-05 12:16:17 +00:00
#include <em_mnem.h>
1984-11-26 13:58:05 +00:00
#include "../share/types.h"
#include "../share/global.h"
#include "../share/debug.h"
#include "../share/aux.h"
#include "cs.h"
#include "cs_alloc.h"
#include "cs_aux.h"
#include "cs_entity.h"
#include "cs_avail.h"
#include "cs_stack.h"
#include "cs_kill.h"
#include "cs_partit.h"
#include "cs_getent.h"
2018-02-05 21:09:30 +00:00
STATIC void push_entity(entity_p enp, line_p lfirst)
1984-11-26 13:58:05 +00:00
{
/* Build token and Push it. */
struct token tk;
tk.tk_vn = enp->en_vn;
tk.tk_size = enp->en_size;
tk.tk_lfirst = lfirst;
Push(&tk);
}
2018-02-05 21:09:30 +00:00
STATIC void put_expensive_load(bblock_p bp, line_p lnp, line_p lfirst,
entity_p enp)
1984-11-26 13:58:05 +00:00
{
struct avail av;
occur_p ocp;
av.av_instr = INSTR(lnp);
av.av_size = enp->en_size;
av.av_operand = enp->en_vn;
ocp = newoccur(lfirst, lnp, bp);
av_enter(&av, ocp, EXPENSIVE_LOAD);
}
2018-02-05 21:09:30 +00:00
STATIC void put_aar(bblock_p bp, line_p lnp, line_p lfirst, entity_p enp)
1984-11-26 13:58:05 +00:00
{
/* Enp points to an ENARRELEM. We do as if its address was computed. */
struct avail av;
occur_p ocp;
assert(enp->en_kind == ENARRELEM);
av.av_instr = op_aar;
av.av_size = ps;
av.av_ofirst = enp->en_arbase;
av.av_osecond = enp->en_index;
av.av_othird = enp->en_adesc;
ocp = newoccur(lfirst, lnp, bp);
av_enter(&av, ocp, TERNAIR_OP);
}
2018-02-05 21:09:30 +00:00
STATIC void push_avail(avail_p avp, line_p lfirst)
1984-11-26 13:58:05 +00:00
{
struct token tk;
tk.tk_vn = avp->av_result;
tk.tk_size = avp->av_size;
tk.tk_lfirst = lfirst;
Push(&tk);
}
2018-02-05 21:09:30 +00:00
STATIC void push_unair_op(bblock_p bp, line_p lnp, token_p tkp1)
1984-11-26 13:58:05 +00:00
{
struct avail av;
occur_p ocp;
av.av_instr = INSTR(lnp);
av.av_size = avsize(lnp);
av.av_operand = tkp1->tk_vn;
ocp = newoccur(tkp1->tk_lfirst, lnp, bp);
push_avail(av_enter(&av, ocp, UNAIR_OP), tkp1->tk_lfirst);
}
2018-02-05 21:09:30 +00:00
STATIC void push_binair_op(bblock_p bp, line_p lnp, token_p tkp1, token_p tkp2)
1984-11-26 13:58:05 +00:00
{
struct avail av;
occur_p ocp;
av.av_instr = INSTR(lnp);
av.av_size = avsize(lnp);
av.av_oleft = tkp1->tk_vn;
av.av_oright = tkp2->tk_vn;
ocp = newoccur(tkp1->tk_lfirst, lnp, bp);
push_avail(av_enter(&av, ocp, BINAIR_OP), tkp1->tk_lfirst);
}
2018-02-05 21:09:30 +00:00
STATIC void push_ternair_op(bblock_p bp, line_p lnp, token_p tkp1,
token_p tkp2, token_p tkp3)
1984-11-26 13:58:05 +00:00
{
struct avail av;
occur_p ocp;
av.av_instr = INSTR(lnp);
av.av_size = avsize(lnp);
av.av_ofirst = tkp1->tk_vn;
av.av_osecond = tkp2->tk_vn;
av.av_othird = tkp3->tk_vn;
ocp = newoccur(tkp1->tk_lfirst, lnp, bp);
push_avail(av_enter(&av, ocp, TERNAIR_OP), tkp1->tk_lfirst);
}
2018-02-05 21:09:30 +00:00
STATIC void fiddle_stack(line_p lnp)
1984-11-26 13:58:05 +00:00
{
/* The instruction in lnp does something to the valuenumber-stack. */
struct token dummy;
offset size;
/* Partly initialize dummy. */
dummy.tk_lfirst = lnp;
switch (INSTR(lnp)) {
default:
assert(FALSE);
break;
case op_lor:
dummy.tk_vn = newvalnum(); dummy.tk_size = ps;
Push(&dummy);
break;
case op_asp:
if ((size = off_set(lnp)) > 0) {
Pop(&dummy, size);
} else {
dummy.tk_vn = newvalnum();
dummy.tk_size = size;
Push(&dummy);
}
break;
case op_dup:
Dup(lnp);
break;
case op_ass:
case op_dus:
case op_exg:
case op_los:
/* Don't waste effort. */
clr_stack();
break;
case op_sig:
Pop(&dummy, (offset) ps);
break;
case op_lfr:
dummy.tk_vn = newvalnum();
dummy.tk_size = off_set(lnp);
Push(&dummy);
break;
case op_beq:
case op_bge:
case op_bgt:
case op_bne:
case op_ble:
case op_blt:
Pop(&dummy, (offset) ws);
Pop(&dummy, (offset) ws);
break;
case op_bra:
case op_csa:/* ??? */
case op_csb:/* ??? */
case op_gto:/* ??? */
case op_ret:/* ??? */
case op_rtt:/* ??? */
break;
case op_zeq:
case op_zge:
case op_zgt:
case op_zne:
case op_zle:
case op_zlt:
case op_trp:
Pop(&dummy, (offset) ws);
break;
case op_rck:
Pop(&dummy, (offset) ps);
break;
1984-11-26 13:58:05 +00:00
}
}
STATIC proc_p find_proc(vn)
valnum vn;
{
/* Find the procedure-identifier with valuenumber vn. */
entity_p enp;
enp = find_entity(vn);
if (enp != (entity_p) 0 && enp->en_kind == ENPROC)
return enp->en_pro;
return (proc_p) 0;
}
2018-02-05 21:09:30 +00:00
STATIC void side_effects(line_p lnp)
1984-11-26 13:58:05 +00:00
{
/* Lnp contains a cai or cal instruction. We try to find the callee
* and see what side-effects it has.
*/
struct token tk;
proc_p pp;
if (INSTR(lnp) == op_cai) {
Pop(&tk, (offset) ps);
pp = find_proc(tk.tk_vn);
} else {
assert(INSTR(lnp) == op_cal);
pp = PROC(lnp);
}
if (pp != (proc_p) 0) {
kill_call(pp);
} else {
kill_much();
}
}
2018-02-05 21:09:30 +00:00
STATIC void hopeless(int instr)
1984-11-26 13:58:05 +00:00
{
/* The effect of `instr' is too difficult to
* compute. We assume worst case behaviour.
*/
switch (instr) {
default:
assert(FALSE);
break;
case op_mon:
case op_str:
1991-10-02 13:03:31 +00:00
case op_nop: /* for volatiles */
1984-11-26 13:58:05 +00:00
/* We can't even trust "static" entities. */
kill_all();
clr_stack();
break;
case op_blm:
case op_bls:
case op_sts:
kill_much();
clr_stack();
break;
}
}
2018-02-05 21:09:30 +00:00
void vnm(bblock_p bp)
1984-11-26 13:58:05 +00:00
{
register line_p lnp;
register entity_p rep;
line_p lfirst;
struct token tk, tk1, tk2, tk3;
for (lnp = bp->b_start; lnp != (line_p) 0; lnp = lnp->l_next) {
rep = getentity(lnp, &lfirst);
switch (instrgroup(lnp)) {
case SIMPLE_LOAD:
push_entity(rep, lfirst);
break;
case LOAD_ARRAY:
put_aar(bp, lnp, lfirst, rep);
/* Fall through ... */
case EXPENSIVE_LOAD:
push_entity(rep, lfirst);
put_expensive_load(bp, lnp, lfirst, rep);
break;
case STORE_DIRECT:
kill_direct(rep);
Pop(&tk, rep->en_size);
rep->en_vn = tk.tk_vn;
break;
case STORE_ARRAY:
put_aar(bp, lnp, lfirst, rep);
/* Fall through ... */
case STORE_INDIR:
kill_indir(rep);
Pop(&tk, rep->en_size);
rep->en_vn = tk.tk_vn;
break;
case UNAIR_OP:
Pop(&tk1, op11size(lnp));
push_unair_op(bp, lnp, &tk1);
break;
case BINAIR_OP:
Pop(&tk2, op22size(lnp));
Pop(&tk1, op12size(lnp));
push_binair_op(bp, lnp, &tk1, &tk2);
break;
case TERNAIR_OP:
Pop(&tk3, op33size(lnp));
Pop(&tk2, op23size(lnp));
Pop(&tk1, op13size(lnp));
push_ternair_op(bp, lnp, &tk1, &tk2, &tk3);
break;
case KILL_ENTITY:
kill_direct(rep);
break;
case SIDE_EFFECTS:
side_effects(lnp);
break;
case FIDDLE_STACK:
fiddle_stack(lnp);
break;
case IGNORE:
break;
case HOPELESS:
hopeless(INSTR(lnp));
break;
case BBLOCK_END:
fiddle_stack(lnp);
1984-11-26 13:58:05 +00:00
break;
default:
assert(FALSE);
break;
}
}
}