Pristine Ack-5.5
[Ack-5.5.git] / doc / ego / ic / ic5
1 .NH 2
2 The Intermediate Code construction phase
3 .PP
4 The first phase of the global optimizer,
5 called
6 .UL IC,
7 constructs a major part of the intermediate code.
8 To be specific, it produces:
9 .IP -
10 the EM text
11 .IP -
12 the object table
13 .IP -
14 part of the procedure table
15 .LP
16 The calling, change and use attributes of a procedure
17 and all its flags except the external and bodyseen flags
18 are computed by the next phase (Control Flow phase).
19 .PP
20 As explained before,
21 the intermediate code does not contain
22 any names of variables or procedures.
23 The normal identifiers are replaced by identifying
24 numbers.
25 Yet, the output of the global optimizer must
26 contain normal identifiers, as this
27 output is in Compact Assembly Language format.
28 We certainly want all externally visible names
29 to be the same in the input as in the output,
30 because the optimized EM module may be a library unit,
31 used by other modules.
32 IC dumps the names of all procedures and data labels
33 on two files:
34 .IP -
35 the procedure dump file, containing tuples (P_ID, procedure name)
36 .IP -
37 the data dump file, containing tuples (D_ID, data label name)
38 .LP
39 The names of instruction labels are not dumped,
40 as they are not visible outside the procedure
41 in which they are defined.
42 .PP
43 The input to IC consists of one or more files.
44 Each file is either an EM module in Compact Assembly Language
45 format, or a Unix archive file (library) containing such modules.
46 IC only extracts those modules from a library that are
47 needed somehow, just as a linker does.
48 It is advisable to present as much code
49 of the EM program as possible to the optimizer,
50 although it is not required to present the whole program.
51 If a procedure is called somewhere in the EM text,
52 but its body (text) is not included in the input,
53 its bodyseen flag in the procedure table will still
54 be off.
55 Whenever such a procedure is called,
56 we assume the worst case for everything;
57 it will change and use all variables it has access to,
58 it will call every procedure etc.
59 .sp
60 Similarly, if a data label is used
61 but not defined, the PSEUDO attribute in its data block
62 will be set to UNKNOWN.
63 .NH 3
64 Implementation
65 .PP
66 Part of the code for the EM Peephole Optimizer
67 .[
68 staveren peephole toplass
69 .]
70 has been used for IC.
71 Especially the routines that read and unravel
72 Compact Assembly Language and the identifier
73 lookup mechanism have been used.
74 New code was added to recognize objects,
75 build the object and procedure tables and to
76 output the intermediate code.
77 .PP
78 IC uses singly linked linear lists for both the
79 procedure and object table.
80 Hence there are no limits on the size of such
81 a table (except for the trivial fact that it must fit
82 in main memory).
83 Both tables are outputted after all EM code has
84 been processed.
85 IC reads the EM text of one entire procedure
86 at a time,
87 processes it and appends the modified code to
88 the EM text file.
89 EM code is represented internally as a doubly linked linear
90 list of EM instructions.
91 .PP
92 Objects are recognized by looking at the operands
93 of instructions that reference global data.
94 If we come across the instructions:
95 .DS
96 .TS
97 l l.
98 LDE X+6 -- Load Double External
99 LAE X+20        -- Load Address External
100 .TE
101 .DE
102 we conclude that the data block
103 preceded by the data label X contains an object
104 at offset 6 of size twice the word size,
105 and an object at offset 20 of unknown size.
106 .sp
107 A data block entry of the object table is allocated
108 at the first reference to a data label.
109 If this reference is a defining occurrence
110 or a INA pseudo instruction,
111 the label is not externally visible
112 .[~[
113 keizer architecture
114 .], section 11.1.4.3]
115 In this case, the external flag of the data block
116 is turned off.
117 If the first reference is an applied occurrence
118 or a EXA pseudo instruction, the flag is set.
119 We record this information, because the
120 optimizer may change the order of defining and
121 applied occurrences.
122 The INA and EXA pseudos are removed from the EM text.
123 They may be regenerated by the last phase
124 of the optimizer.
125 .sp
126 Similar rules hold for the procedure table
127 and the INP and EXP pseudos.
128 .NH 3
129 Source files of IC
130 .PP
131 The source files of IC consist
132 of the files ic.c, ic.h and several packages.
133 .UL ic.h
134 contains type definitions, macros and
135 variable declarations that may be used by
136 ic.c and by every package.
137 .UL ic.c
138 contains the definitions of these variables,
139 the procedure
140 .UL main
141 and some high level I/O routines used by main.
142 .sp
143 Every package xxx consists of two files.
144 ic_xxx.h contains type definitions,
145 macros, variable declarations and
146 procedure declarations that may be used by
147 every .c file that includes this .h file.
148 The file ic_xxx.c provides the
149 definitions of these variables and
150 the implementation of the declared procedures.
151 IC uses the following packages:
152 .IP lookup: 18
153 procedures that loop up procedure, data label
154 and instruction label names; procedures to dump
155 the procedure and data label names.
156 .IP lib:
157 one procedure that gets the next useful input module;
158 while scanning archives, it skips unnecessary modules.
159 .IP aux:
160 several auxiliary routines.
161 .IP io:
162 low-level I/O routines that unravel the Compact
163 Assembly Language.
164 .IP put:
165 routines that output the intermediate code
166 .LP