ra.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. /*
  7. * R E G I S T E R A L L O C A T I O N
  8. *
  9. */
  10. #define INFINITE 10000
  11. #define NRREGTYPES (reg_float+1)
  12. extern int nrinstrs; /* number of instructions of current procedure */
  13. extern line_p *instrmap;
  14. /* Dynamic array: instrmap[i] points to i'th instruction */
  15. extern cond_p alocaltab[NRREGTYPES][NRREGTYPES],
  16. alocaddrtab[NRREGTYPES][NRREGTYPES], aconsttab,
  17. adconsttab,aglobaltab,aproctab;
  18. extern cond_p olocaltab[NRREGTYPES],olocaddrtab[NRREGTYPES],
  19. oconsttab,odconsttab,oglobaltab,oproctab;
  20. extern cond_p regsav_cost;
  21. /* Register Allocation */
  22. typedef struct item *item_p;
  23. typedef struct allocation *alloc_p;
  24. typedef struct interval *interv_p;
  25. typedef struct time *time_p;
  26. extern short regs_available[]; /* contains #registers of every type */
  27. extern short use_any_as_pointer;/* indicates whether general registers
  28. can be used as pointers
  29. */
  30. /* A thing that can be put in a register is called an "item". The are several
  31. * types of items: a local variable, the address of a local variable,
  32. * the address of a global variable, the address of a procedure,
  33. * a word-size constant and a doubleword- size constant.
  34. */
  35. #define LOCALVAR 0
  36. #define LOCAL_ADDR 1
  37. #define GLOBL_ADDR 2
  38. #define PROC_ADDR 3
  39. #define CONST 4
  40. #define DCONST 5
  41. #define NO_ITEM 6
  42. #define NRITEMTYPES 6
  43. struct item {
  44. item_p it_next; /* link to next item is list */
  45. short it_type; /* its type; see above */
  46. short it_regtype; /* preferred type of register */
  47. short it_size; /* its size (in bytes) */
  48. short it_lastlive; /* temporary, used to build livetime */
  49. lset it_usage; /* all points in text where item is used*/
  50. interv_p it_lives; /* intervals during which item is live */
  51. bool it_desirable; /* should this item be put in reg.? */
  52. union {
  53. obj_p it_obj; /* for GLOBL_ADDR */
  54. proc_p it_proc; /* for PROC_ADDR */
  55. offset it_off; /* for others */
  56. } i_t;
  57. };
  58. /* A 'point in time' is defined by a (line,basic block) pair */
  59. struct time {
  60. line_p t_line; /* point in EM text */
  61. bblock_p t_bblock; /* its basic block */
  62. };
  63. struct interval {
  64. short i_start; /* number of first instruction */
  65. short i_stop; /* number of last instruction */
  66. interv_p i_next;
  67. };
  68. /* An item may be put in a register for the duration of a whole procedure
  69. * or part of a procedure (e.g. a loop). So a possible "allocation" looks
  70. * like: put item X in a register during the timespan T (which is a subset
  71. * of the timespan of the entire procedure). The packing process deals
  72. * with allocations, rather than items. One item may be part of several
  73. * possible allocations.
  74. */
  75. struct allocation {
  76. item_p al_item; /* the item to be put in a register */
  77. short al_id; /* unique identifying number */
  78. short al_regtype; /* the register type to be used */
  79. interv_p al_timespan; /* timespan during which item is in reg. */
  80. short al_profits; /* gains of putting item in register */
  81. cset al_rivals; /* set of allocations competing with it */
  82. short al_susecount; /* #usages during timespan (statically) */
  83. short al_dusecount; /* #usages (dynamically, estimate) */
  84. lset al_inits; /* points where reg. must be initialized */
  85. interv_p al_busy; /* used to compute rivals */
  86. short al_regnr; /* register nr.,if it is granted a reg. */
  87. offset al_dummy; /* dummy local variable,if granted a reg */
  88. alloc_p al_mates; /* link to allocations packed in same reg */
  89. alloc_p al_wholeproc; /* alloc. for whole proc as timespan */
  90. short al_cntrivals; /* # unpacked rivals ; used for cost estim. */
  91. bool al_isloop; /* true if timespan consists of loop */
  92. bool al_iswholeproc;/*true if timespan consists of whole proc*/
  93. alloc_p al_next; /* link to next one in a list */
  94. };
  95. extern short alloc_id; /* last al_id used for current procedure */
  96. #define LP_BLOCKS lp_extend->lpx_ra.lpx_blocks
  97. #define LP_HEADER lp_extend->lpx_ra.lpx_header
  98. #define B_BEGIN b_extend->bx_ra.bx_begin
  99. #define B_END b_extend->bx_ra.bx_end
  100. #define DLINK(l1,l2) l1->l_next=l2; l2->l_prev=l1
  101. struct item_descr {
  102. int id_type;
  103. int id_replindex;
  104. } ;
  105. extern struct item_descr itemtab[];
  106. #define newalloc() (alloc_p) newstruct(allocation)
  107. #define oldalloc(a) oldstruct(allocation,a)
  108. #define newitem() (item_p) newstruct(item)
  109. #define olditem(i) oldstruct(item,i)
  110. #define newtime() (time_p) newstruct(time)
  111. #define oldtime(t) oldstruct(time,t)
  112. #define newinterval() (interv_p) newstruct(interval)
  113. #define oldinterval(i) oldstruct(interval,i)