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