OSDN Git Service

[pf3gnuchains/gcc-fork.git] / gcc / PROJECTS
1 Haifa scheduler (haifa-sched.c, loop.[ch], unroll.[ch], genattrtab.c):
2 (contact law@cygnus.com before starting any serious haifa work)
3
4   * Fix all the formatting problems.  Simple, mindless work.
5
6   * Fix/add comments throughout the code.  Many of the comments are from
7   the old scheduler and are out of date and misleading.  Many new hunks
8   of code don't have sufficient comments and documentation.  Those which
9   do have comments need to be rewritten to use complete sentences and
10   proper formatting.
11
12   * Someone needs make one (or more) passes over the scheduler as a whole to
13   just clean it up.  Try to move the machine dependent bits into the target
14   files where they belong, avoid re-creating functions where or near
15   equivalents already exist (ie is_conditional_branch and friends), etc., etc.
16
17   * Document the new scheduling options.  Remove those options which are
18   not really useful (like reverse scheduling for example).  In general
19   the haifa scheduler adds _way_ too many options.  I'm definitely of the
20   opinion that gcc already has too many -foptions, and haifa doesn't help
21   that situation.
22
23   * Testing and benchmarking.    We've converted a few ports to using the
24   Haifa scheduler (hppa, sparc, ppc, alpha).  We need to continue testing
25   and benchmarking the new scheduler on additional targets.
26
27   We need to have some kind of docs for how to best describe a machine to
28   the haifa scheduler to get good performance.  Some existing ports have
29   been tuned to deal with the old scheduler -- they may need to be tuned
30   to generate good schedules with haifa.
31
32   
33
34 Improvements to global cse and partial redundancy elimination:
35
36 The current implementation of global cse uses partial redundancy elimination
37 as described in Chow's thesis.
38
39 Long term we want to use lazy code motion as the basis for partial redundancy
40 elimination.  lcm will find as many (or more) redunancies *and* it will
41 place the remaining computations at computationally optimal placement points
42 within the function.  This reduces the number of redundant operations performed
43 as well as reducing register lifetimes.  My experiments have shown that the
44 cases were the current PRE code hurts performance are greatly helped by using
45 lazy code motion.
46
47 lcm also provides the underlying framework for several additional optimizations
48 such as shrink wrapping, spill code motion, dead store elimination, and generic
49 load/store motion (all the other examples are subcases of load/store motion).
50
51 It can probably also be used to improve the reg-stack pass of the compiler.
52
53 Contact law@cygnus.com if you're interested in working on lazy code motion.
54
55 -------------
56
57 The old PROJECTS file.  Stuff I know has been done has been deleted.
58 Stuff in progress has a contact name associated with it.
59 has been 
60
61 1. Better optimization.
62
63 * Constants in unused inline functions
64
65 It would be nice to delay output of string constants so that string
66 constants mentioned in unused inline functions are never generated.
67 Perhaps this would also take care of string constants in dead code.
68
69 The difficulty is in finding a clean way for the RTL which refers
70 to the constant (currently, only by an assembler symbol name)
71 to point to the constant and cause it to be output.
72
73 * Optimize a sequence of if statements whose conditions are exclusive.
74
75 It is possible to optimize 
76
77     if (x == 1) ...;
78     if (x == 2) ...;
79     if (x == 3) ...;
80
81 into
82
83     if (x == 1) ...;
84     else if (x == 2) ...;
85     else if (x == 3) ...;
86
87 provided that x is not altered by the contents of the if statements.
88
89 It's not certain whether this is worth doing.  Perhaps programmers
90 nearly always write the else's themselves, leaving few opportunities
91 to improve anything.
92
93 * Un-cse.
94
95 Perhaps we should have an un-cse step right after cse, which tries to
96 replace a reg with its value if the value can be substituted for the
97 reg everywhere, if that looks like an improvement.  Which is if the
98 reg is used only a few times.  Use rtx_cost to determine if the
99 change is really an improvement.
100
101 * Clean up how cse works.
102
103 The scheme is that each value has just one hash entry.  The
104 first_same_value and next_same_value chains are no longer needed.
105
106 For arithmetic, each hash table elt has the following slots:
107
108 * Operation.  This is an rtx code.
109 * Mode.
110 * Operands 0, 1 and 2.  These point to other hash table elements.
111
112 So, if we want to enter (PLUS:SI (REG:SI 30) (CONST_INT 104)), we
113 first enter (CONST_INT 104) and find the entry that (REG:SI 30) now
114 points to.  Then we put these elts into operands 0 and 1 of a new elt.
115 We put PLUS and SI into the new elt.
116
117 Registers and mem refs would never be entered into the table as such.
118 However, the values they contain would be entered.  There would be a
119 table indexed by regno which points at the hash entry for the value in
120 that reg.
121
122 The hash entry index now plays the role of a qty number.
123 We still need qty_first_reg, reg_next_eqv, etc. to record which regs
124 share a particular qty.
125
126 When a reg is used whose contents are unknown, we need to create a
127 hash table entry whose contents say "unknown", as a place holder for
128 whatever the reg contains.  If that reg is added to something, then
129 the hash entry for the sum will refer to the "unknown" entry.  Use
130 UNKNOWN for the rtx code in this entry.  This replaces make_new_qty.
131
132 For a constant, a unique hash entry would be made based on the
133 value of the constant.
134
135 What about MEM?  Each time a memory address is referenced, we need a
136 qty (a hash table elt) to represent what is in it.  (Just as for a
137 register.)  If this isn't known, create one, just as for a reg whose
138 contents are unknown.
139
140 We need a way to find all mem refs that still contain a certain value.
141 Do this with a chain of hash elts (for memory addresses) that point to
142 locations that hold the value.  The hash elt for the value itself should
143 point to the start of the chain.  It would be good for the hash elt
144 for an address to point to the hash elt for the contents of that address
145 (but this ptr can be null if the contents have never been entered).
146
147 With this data structure, nothing need ever be invalidated except
148 the lists of which regs or mems hold a particular value.  It is easy
149 to see if there is a reg or mem that is equiv to a particular value.
150 If the value is constant, it is always explicitly constant.
151
152 * Support more general tail-recursion among different functions.
153
154 This might be possible under certain circumstances, such as when
155 the argument lists of the functions have the same lengths.
156 Perhaps it could be done with a special declaration.
157
158 You would need to verify in the calling function that it does not
159 use the addresses of any local variables and does not use setjmp.
160
161 * Put short statics vars at low addresses and use short addressing mode?
162
163 Useful on the 68000/68020 and perhaps on the 32000 series,
164 provided one has a linker that works with the feature.
165 This is said to make a 15% speedup on the 68000.
166
167 * Keep global variables in registers.
168
169 Here is a scheme for doing this.  A global variable, or a local variable
170 whose address is taken, can be kept in a register for an entire function
171 if it does not use non-constant memory addresses and (for globals only)
172 does not call other functions.  If the entire function does not meet
173 this criterion, a loop may.
174
175 The VAR_DECL for such a variable would have to have two RTL expressions:
176 the true home in memory, and the pseudo-register used temporarily. 
177 It is necessary to emit insns to copy the memory location into the
178 pseudo-register at the beginning of the function or loop, and perhaps
179 back out at the end.  These insns should have REG_EQUIV notes so that,
180 if the pseudo-register does not get a hard register, it is spilled into
181 the memory location which exists in any case.
182
183 The easiest way to set up these insns is to modify the routine
184 put_var_into_stack so that it does not apply to the entire function
185 (sparing any loops which contain nothing dangerous) and to call it at
186 the end of the function regardless of where in the function the
187 address of a local variable is taken.  It would be called
188 unconditionally at the end of the function for all relevant global
189 variables.
190
191 For debugger output, the thing to do is to invent a new binding level
192 around the appropriate loop and define the variable name as a register
193 variable with that scope.
194
195 * Live-range splitting.
196
197 Currently a variable is allocated a hard register either for the full
198 extent of its use or not at all.  Sometimes it would be good to
199 allocate a variable a hard register for just part of a function; for
200 example, through a particular loop where the variable is mostly used,
201 or outside of a particular loop where the variable is not used.  (The
202 latter is nice because it might let the variable be in a register most
203 of the time even though the loop needs all the registers.)
204
205 Contact meissner@cygnus.com before starting any work on live range
206 splitting.
207
208 * Detect dead stores into memory?
209
210 A store into memory is dead if it is followed by another store into
211 the same location; and, in between, there is no reference to anything
212 that might be that location (including no reference to a variable
213 address).
214
215 This can be modeled as a partial redundancy elimination/lazy code motion
216 problem.  Contact law@cygnus.com before working on dead store elimination
217 optimizations.
218
219 * Loop optimization.
220
221 Strength reduction and iteration variable elimination could be
222 smarter.  They should know how to decide which iteration variables are
223 not worth making explicit because they can be computed as part of an
224 address calculation.  Based on this information, they should decide
225 when it is desirable to eliminate one iteration variable and create
226 another in its place.
227
228 It should be possible to compute what the value of an iteration
229 variable will be at the end of the loop, and eliminate the variable
230 within the loop by computing that value at the loop end.
231
232 When a loop has a simple increment that adds 1,
233 instead of jumping in after the increment,
234 decrement the loop count and jump to the increment.
235 This allows aob insns to be used.
236
237 * Using constraints on values.
238
239 Many operations could be simplified based on knowledge of the
240 minimum and maximum possible values of a register at any particular time.
241 These limits could come from the data types in the tree, via rtl generation,
242 or they can be deduced from operations that are performed.  For example,
243 the result of an `and' operation one of whose operands is 7 must be in
244 the range 0 to 7.  Compare instructions also tell something about the
245 possible values of the operand, in the code beyond the test.
246
247 Value constraints can be used to determine the results of a further
248 comparison.  They can also indicate that certain `and' operations are
249 redundant.  Constraints might permit a decrement and branch
250 instruction that checks zeroness to be used when the user has
251 specified to exit if negative.
252
253 * Change the type of a variable.
254
255 Sometimes a variable is declared as `int', it is assigned only once
256 from a value of type `char', and then it is used only by comparison
257 against constants.  On many machines, better code would result if
258 the variable had type `char'.  If the compiler could detect this
259 case, it could change the declaration of the variable and change
260 all the places that use it.
261
262 * Better handling for very sparse switches.
263
264 There may be cases where it would be better to compile a switch
265 statement to use a fixed hash table rather than the current
266 combination of jump tables and binary search.
267
268 * Order of subexpressions.
269
270 It might be possible to make better code by paying attention
271 to the order in which to generate code for subexpressions of an expression.
272
273 * More code motion.
274
275 Consider hoisting common code up past conditional branches or tablejumps.
276
277 Contact law@cygnus.com before working on code hoisting.
278
279 * Trace scheduling.
280
281 This technique is said to be able to figure out which way a jump
282 will usually go, and rearrange the code to make that path the
283 faster one.
284
285 * Distributive law.
286
287 The C expression *(X + 4 * (Y + C)) compiles better on certain
288 machines if rewritten as *(X + 4*C + 4*Y) because of known addressing
289 modes.  It may be tricky to determine when, and for which machines, to
290 use each alternative.
291
292 Some work has been done on this, in combine.c.
293
294 * Can optimize by changing if (x) y; else z; into z; if (x) y;
295 if z and x do not interfere and z has no effects not undone by y.
296 This is desirable if z is faster than jumping.
297
298 * For a two-insn loop on the 68020, such as
299   foo:  movb    a2@+,a3@+
300         jne     foo
301 it is better to insert dbeq d0,foo before the jne.
302 d0 can be a junk register.  The challenge is to fit this into
303 a portable framework: when can you detect this situation and
304 still be able to allocate a junk register?
305
306 2. Simpler porting.
307
308 Right now, describing the target machine's instructions is done
309 cleanly, but describing its addressing mode is done with several
310 ad-hoc macro definitions.  Porting would be much easier if there were
311 an RTL description for addressing modes like that for instructions.
312 Tools analogous to genflags and genrecog would generate macros from
313 this description.
314
315 There would be one pattern in the address-description file for each
316 kind of addressing, and this pattern would have:
317
318   * the RTL expression for the address
319   * C code to verify its validity (since that may depend on
320     the exact data).
321   * C code to print the address in assembler language.
322   * C code to convert the address into a valid one, if it is not valid.
323     (This would replace LEGITIMIZE_ADDRESS).
324   * Register constraints for all indeterminates that appear
325     in the RTL expression.
326
327 3. Other languages.
328
329 Front ends for Pascal, Fortran, Algol, Cobol, Modula-2 and Ada are
330 desirable.
331
332 Pascal, Modula-2 and Ada require the implementation of functions
333 within functions.  Some of the mechanisms for this already exist.
334
335 4. More extensions.
336
337 * Generated unique labels.  Have some way of generating distinct labels
338 for use in extended asm statements.  I don't know what a good syntax would
339 be.
340
341 * A way of defining a structure containing a union, in which the choice of
342 union alternative is controlled by a previous structure component.
343
344 Here is a possible syntax for this.
345
346 struct foo {
347   enum { INT, DOUBLE } code;
348   auto union { case INT: int i; case DOUBLE: double d;} value : code;
349 };
350
351 * Allow constructor expressions as lvalues, like this:
352
353         (struct foo) {a, b, c} = foo();
354
355 This would call foo, which returns a structure, and then store the
356 several components of the structure into the variables a, b, and c.
357
358 5. Generalize the machine model.
359
360 * Some new compiler features may be needed to do a good job on machines
361 where static data needs to be addressed using base registers.
362
363 * Some machines have two stacks in different areas of memory, one used
364 for scalars and another for large objects.  The compiler does not
365 now have a way to understand this.
366
367 6. Useful warnings.
368
369 * Warn about statements that are undefined because the order of
370 evaluation of increment operators makes a big difference.  Here is an
371 example:
372
373     *foo++ = hack (*foo);
374
375 7. Better documentation of how GCC works and how to port it.
376
377 Here is an outline proposed by Allan Adler.
378
379 I.    Overview of this document
380 II.   The machines on which GCC is implemented
381     A. Prose description of those characteristics of target machines and
382        their operating systems which are pertinent to the implementation
383        of GCC.
384         i. target machine characteristics
385         ii. comparison of this system of machine characteristics with
386             other systems of machine specification currently in use
387     B. Tables of the characteristics of the target machines on which
388        GCC is implemented.
389     C. A priori restrictions on the values of characteristics of target 
390        machines, with special reference to those parts of the source code
391        which entail those restrictions
392         i. restrictions on individual characteristics 
393         ii. restrictions involving relations between various characteristics
394     D. The use of GCC as a cross-compiler 
395         i. cross-compilation to existing machines
396         ii. cross-compilation to non-existent machines
397     E. Assumptions which are made regarding the target machine
398         i.  assumptions regarding the architecture of the target machine
399         ii. assumptions regarding the operating system of the target machine
400         iii. assumptions regarding software resident on the target machine
401         iv. where in the source code these assumptions are in effect made
402 III.   A systematic approach to writing the files tm.h and xm.h
403     A. Macros which require special care or skill
404     B. Examples, with special reference to the underlying reasoning
405 IV.    A systematic approach to writing the machine description file md
406     A. Minimal viable sets of insn descriptions
407     B. Examples, with special reference to the underlying reasoning
408 V.     Uses of the file aux-output.c
409 VI.    Specification of what constitutes correct performance of an 
410        implementation of GCC
411     A. The components of GCC
412     B. The itinerary of a C program through GCC
413     C. A system of benchmark programs
414     D. What your RTL and assembler should look like with these benchmarks
415     E. Fine tuning for speed and size of compiled code
416 VII.   A systematic procedure for debugging an implementation of GCC
417     A. Use of GDB
418         i. the macros in the file .gdbinit for GCC
419         ii. obstacles to the use of GDB
420             a. functions implemented as macros can't be called in GDB
421     B. Debugging without GDB
422         i. How to turn off the normal operation of GCC and access specific
423            parts of GCC
424     C. Debugging tools
425     D. Debugging the parser
426         i. how machine macros and insn definitions affect the parser
427     E. Debugging the recognizer
428         i. how machine macros and insn definitions affect the recognizer
429
430 ditto for other components
431
432 VIII. Data types used by GCC, with special reference to restrictions not 
433       specified in the formal definition of the data type
434 IX.   References to the literature for the algorithms used in GCC
435