ra_lifet.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* $Id$ */
  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. #include <em_mnem.h>
  11. #include <em_spec.h>
  12. #include <em_pseu.h>
  13. #include <em_reg.h>
  14. #include <em_mes.h>
  15. #include <em_ego.h>
  16. #include "../share/types.h"
  17. #include "../share/debug.h"
  18. #include "../share/def.h"
  19. #include "../share/global.h"
  20. #include "../share/lset.h"
  21. #include "../share/aux.h"
  22. #include "../share/alloc.h"
  23. #include "ra.h"
  24. #include "ra_aux.h"
  25. #include "ra_items.h"
  26. #include "ra_lifet.h"
  27. #include "ra_interv.h"
  28. #include "ra_profits.h"
  29. #define MSG_OFF(l) aoff(ARG(l),2)
  30. #define is_livemsg(l) (INSTR(l) == ps_mes && aoff(ARG(l),0) == ms_ego && \
  31. aoff(ARG(l),1) == ego_live)
  32. #define is_deadmsg(l) (INSTR(l) == ps_mes && aoff(ARG(l),0) == ms_ego && \
  33. aoff(ARG(l),1) == ego_dead)
  34. void build_lifetimes(item_p items[])
  35. {
  36. /* compute the it_lives attribute of every item; this is
  37. * a list of intervals during which the item is live,
  38. * i.e. its current value may be used.
  39. * We traverse the EM text of the current procedure in
  40. * lexical order. If we encounter a live-message, we store
  41. * the number ('time') of the current instruction in the
  42. * it_lastlive attribute of the concerning item. If we see
  43. * a dead-message for that item, we know that the item is
  44. * live in between these two pseudo's. If the first message
  45. * appearing in the procedure is a dead-message, the item
  46. * is live from time 0 (start of procedure) till now. (Note
  47. * that it_lastlive is initially 0!).
  48. * The lifetime ends on the last instruction before the
  49. * dead-message that is not a live -or dead message.
  50. */
  51. line_p l;
  52. short now;
  53. item_p item;
  54. short last_code;
  55. last_code = 0;
  56. for (now = 0; now < nrinstrs; now++) {
  57. l = instrmap[now];
  58. if (is_livemsg(l)) {
  59. item = item_of(MSG_OFF(l),items);
  60. /* A local variable that is never used is NOT an
  61. * item; yet, there may be a register message for it...
  62. */
  63. if(item != (item_p) 0) {
  64. item->it_lastlive = last_code + 1;
  65. }
  66. } else {
  67. if (is_deadmsg(l)) {
  68. item = item_of(MSG_OFF(l),items);
  69. if (item != (item_p) 0) {
  70. add_interval(item->it_lastlive,
  71. last_code, &item->it_lives);
  72. }
  73. } else {
  74. last_code = now;
  75. }
  76. }
  77. }
  78. }