Pristine Ack-5.5
[Ack-5.5.git] / doc / regadd.doc
1 .\" $Id: regadd.doc,v 1.5 1994/06/24 10:02:27 ceriel Exp $
2 .TL
3 Addition of register variables to an existing table.
4 .NH 1
5 Introduction
6 .PP
7 This is a short description of the newest feature in the
8 table driven code generator for the Amsterdam Compiler Kit.
9 It describes how to add register variables to an existing table.
10 This assumes a distribution of October 1983 or later.
11 It is not clear whether one should read this when starting with
12 a table for a new machine,
13 or waiting till the table is well debugged already.
14 .NH 1
15 Modifications to the table itself.
16 .NH 2
17 Register section
18 .PP
19 Just before the properties of the register one
20 of the following can be added:
21 .IP - 2
22 regvar
23 .IP -
24 regvar ( pointer )
25 .IP -
26 regvar ( loop )
27 .IP -
28 regvar ( float )
29 .LP
30 All register variables of one type must be of the same size,
31 and they may have no subregisters.
32 .NH 2
33 Codesection
34 .PP
35 .IP - 2
36 Two pseudo functions are added to the list allowed inside expressions:
37 .RS
38 .IP 1) 3
39 inreg ( expr ) has as a parameter the offset of a local,
40 and returns 0,1 or 2:
41 .RS
42 .IP 2: 3
43 if the variable is in a register.
44 .IP 1:
45 if the variable could be in a register but isn't.
46 .IP 0:
47 if the variable cannot be in a register.
48 .RE
49 .IP 2)
50 regvar ( expr ) returns the register associated with the variable.
51 Undefined if it is not in a register.
52 So regvar ( expr ) is defined if and only if inreg (expr ) == 2.
53 .RE
54 .IP -
55 It is now possible to remove() a register expression,
56 this is of course needed for a store into a register local.
57 .IP -
58 The return out of a procedure may now involve register restores,
59 so the special word 'return' in the table will invoke a user defined
60 function.
61 .NH 1
62 Modifications to mach.c
63 .PP
64 If register variables are used in a table, the program
65 .I cgg
66 will define the word REGVARS during compilation of the sources.
67 So the following functions described here should be bracketed
68 by #ifdef REGVARS and #endif.
69 .IP - 2
70 regscore(off,size,typ,freq,totyp) long off;
71 .br
72 This function should assign a score to a register variable,
73 the score should preferably be the estimated number of bytes
74 gained when it is put in a register.
75 Off and size are the offset and size of the variable,
76 typ is the type, that is reg_any, reg_pointer, reg_loop or reg_float.
77 Freq is the number of times it occurs statically, and totyp
78 is the type of the register it is planned to go into.
79 .br
80 Keep in mind that the gain should be net, that is the cost for
81 register save/restore sequences and the cost of initialisation
82 in the case of parameters should already be included.
83 .IP -
84 i_regsave()
85 .br
86 This function is called at the start of a procedure, just before
87 register saves are done.
88 It can be used to initialise some variables if needed.
89 .IP -
90 f_regsave()
91 .br
92 This function is called at end of the register save sequence.
93 It can be used to do the real saving if multiple register move
94 instructions are available.
95 .IP -
96 regsave(regstr,off,size) char *regstr; long off;
97 .br
98 Should either do the real saving or set up a table to have
99 it done by f_regsave.
100 Note that initialisation of parameters should also be done,
101 or planned here.
102 .IP -
103 regreturn()
104 .br
105 Should restore saved registers and return.
106 The function result is already in the function return area by now.
107 .NH 1
108 Examples
109 .PP
110 Here are some examples out of the PDP 11 table
111 .DS
112 lol inreg($1)==2| |             | regvar($1)                    | |
113
114 lil inreg($1)==2| |             | {regdef2, regvar($1)}         | |
115
116 stl inreg($1)==2| xsource2 |
117                         remove(regvar($1))
118                         move(%[1],regvar($1))              |       | |
119
120 inl inreg($1)==2| |     remove(regvar($1))
121                         "inc %(regvar($1)%)"
122                         setcc(regvar($1))          |       | |
123 .DE
124 .NH 1
125 Afterthoughts.
126 .PP
127 At the time of this writing the tables for the PDP 11 and the M68000 and
128 the VAX are converted, in all cases the two byte wordsize versions.
129 No big problems have occurred, but experience has shown that it is
130 necessary to check the table carefully for all patterns with locals in them.
131 Code may be generated that uses the memoryslot the local is not in.