Pristine Ack-5.5
[Ack-5.5.git] / util / ego / ra / ra_lifet.c
1 /* $Id: ra_lifet.c,v 1.7 1994/06/24 10:27:50 ceriel Exp $ */
2 /*
3  * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
4  * See the copyright notice in the ACK home directory, in the file "Copyright".
5  */
6 /*  R E G I S T E R   A L L O C A T I O N
7  *
8  *  R A _ L I F E T I M E . C
9  */
10
11 #include <em_mnem.h>
12 #include <em_spec.h>
13 #include <em_pseu.h>
14 #include <em_reg.h>
15 #include <em_mes.h>
16 #include <em_ego.h>
17 #include "../share/types.h"
18 #include "../share/debug.h"
19 #include "../share/def.h"
20 #include "../share/global.h"
21 #include "../share/lset.h"
22 #include "../share/aux.h"
23 #include "../share/alloc.h"
24 #include "ra.h"
25 #include "ra_aux.h"
26 #include "ra_items.h"
27 #include "ra_lifet.h"
28
29
30 #define MSG_OFF(l)      aoff(ARG(l),2)
31 #define is_livemsg(l)   (INSTR(l) == ps_mes && aoff(ARG(l),0) == ms_ego && \
32                          aoff(ARG(l),1) == ego_live)
33 #define is_deadmsg(l)   (INSTR(l) == ps_mes && aoff(ARG(l),0) == ms_ego && \
34                          aoff(ARG(l),1) == ego_dead)
35
36 build_lifetimes(items)
37         item_p items[];
38 {
39         /* compute the it_lives attribute of every item; this is
40          * a list of intervals during which the item is live,
41          * i.e. its current value may be used.
42          * We traverse the EM text of the current procedure in
43          * lexical order. If we encounter a live-message, we store
44          * the number ('time') of the current instruction in the
45          * it_lastlive attribute of the concerning item. If we see
46          * a dead-message for that item, we know that the item is
47          * live in between these two pseudo's. If the first message
48          * appearing in the procedure is a dead-message, the item
49          * is live from time 0 (start of procedure) till now. (Note
50          * that it_lastlive is initially 0!).
51          * The lifetime ends on the last instruction before the
52          * dead-message that is not a live -or dead message.
53          */
54
55         register line_p l;
56         register short now;
57         item_p item;
58         short last_code;
59
60         last_code = 0;
61         for (now = 0; now < nrinstrs; now++) {
62                 l = instrmap[now];
63                 if (is_livemsg(l)) {
64                         item = item_of(MSG_OFF(l),items);
65                         /* A local variable that is never used is NOT an
66                          * item; yet, there may be a register message for it...
67                          */
68                         if(item != (item_p) 0) {
69                                 item->it_lastlive = last_code + 1;
70                         }
71                 } else {
72                         if (is_deadmsg(l)) {
73                                 item = item_of(MSG_OFF(l),items);
74                                 if (item != (item_p) 0) {
75                                         add_interval(item->it_lastlive,
76                                                last_code, &item->it_lives);
77                                 }
78                         } else {
79                                 last_code = now;
80                         }
81                 }
82         }
83 }