2 The Intermediate Code construction phase
4 The first phase of the global optimizer,
7 constructs a major part of the intermediate code.
8 To be specific, it produces:
14 part of the procedure table
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).
21 the intermediate code does not contain
22 any names of variables or procedures.
23 The normal identifiers are replaced by identifying
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
35 the procedure dump file, containing tuples (P_ID, procedure name)
37 the data dump file, containing tuples (D_ID, data label name)
39 The names of instruction labels are not dumped,
40 as they are not visible outside the procedure
41 in which they are defined.
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
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.
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.
66 Part of the code for the EM Peephole Optimizer
68 staveren peephole toplass
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.
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
83 Both tables are outputted after all EM code has
85 IC reads the EM text of one entire procedure
87 processes it and appends the modified code to
89 EM code is represented internally as a doubly linked linear
90 list of EM instructions.
92 Objects are recognized by looking at the operands
93 of instructions that reference global data.
94 If we come across the instructions:
98 LDE X+6 -- Load Double External
99 LAE X+20 -- Load Address External
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.
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
114 .], section 11.1.4.3]
115 In this case, the external flag of the data block
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
122 The INA and EXA pseudos are removed from the EM text.
123 They may be regenerated by the last phase
126 Similar rules hold for the procedure table
127 and the INP and EXP pseudos.
131 The source files of IC consist
132 of the files ic.c, ic.h and several packages.
134 contains type definitions, macros and
135 variable declarations that may be used by
136 ic.c and by every package.
138 contains the definitions of these variables,
141 and some high level I/O routines used by main.
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:
153 procedures that loop up procedure, data label
154 and instruction label names; procedures to dump
155 the procedure and data label names.
157 one procedure that gets the next useful input module;
158 while scanning archives, it skips unnecessary modules.
160 several auxiliary routines.
162 low-level I/O routines that unravel the Compact
165 routines that output the intermediate code