PROJECTS 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. 1. Better optimization.
  2. * More cse
  3. The techniques for doing full global cse are described in the
  4. red dragon book. It is likely to be slow and use a lot of memory,
  5. but it might be worth offering as an additional option.
  6. It is probably possible to extend cse to a few very frequent cases
  7. without so much expense.
  8. For example, it is not very hard to handle cse through if-then
  9. statements with no else clauses. Here's how to do it. On reaching a
  10. label, notice that the label's use-count is 1 and that the last
  11. preceding jump jumps conditionally to this label. Now you know it
  12. is a simple if-then statement. Remove from the hash table
  13. all the expressions that were entered since that jump insn
  14. and you can continue with cse.
  15. It is probably not hard to handle cse from the end of a loop
  16. around to the beginning, and a few loops would be greatly sped
  17. up by this.
  18. * Iteration variables and strength reduction.
  19. The red dragon book describes standard techniques for these kinds
  20. of loop optimization. But be careful! These optimization techniques
  21. don't always make the code better. You need to avoid performing
  22. the standard transformations unless they are greatly worth while.
  23. In many common cases it is possible to deduce that an iteration
  24. variable is always positive during the loop. This information
  25. may make it possible to use decrement-and-branch instructions
  26. whose branch conditions are inconvenient. For example, the 68000
  27. `dbra' instruction branches if the value was not equal to zero.
  28. Therefore, it is not applicable to `for (i = 10; i >= 0; i--)'
  29. unless the compiler can know that I will never be negative
  30. before it is decremented.
  31. * Special local optimizations.
  32. The instruction combiner finds only certain classes of local optimizations.
  33. For example, it cannot use the 68020 instruction `cmp2' because it would
  34. not think to combine the instructions that would be equivalent to a `cmp2'.
  35. In order to take advantage of such instructions, the combiner would need
  36. special hints as to which instructions to consider combining. To be
  37. generally useful, this feature would have to be controlled somehow
  38. by new information in the machine description.
  39. * Smarter reload pass.
  40. The reload pass as currently written can reload values only into registers
  41. that are reserved for reloading. This means that in order to use a
  42. register for reloading it must spill everything out of that register.
  43. It would be straightforward, though complicated, for reload1.c to keep
  44. track, during its scan, of which hard registers were available at each
  45. point in the function, and use for reloading even registers that were
  46. free only at the point they were needed. This would avoid much spilling
  47. and make better code.
  48. * Change the type of a variable.
  49. Sometimes a variable is declared as `int', it is assigned only once
  50. from a value of type `char', and then it is used only by comparison
  51. against constants. On many machines, better code would result if
  52. the variable had type `char'. If the compiler could detect this
  53. case, it could change the declaration of the variable and change
  54. all the places that use it.
  55. * Order of subexpressions.
  56. It might be possible to make better code by paying attention
  57. to the order in which to generate code for subexpressions of an expression.
  58. * Better code for switch statements.
  59. If a switch statement has only a few cases, a sequence of conditional
  60. branches is generated for it, rather than a jump table. It would
  61. be better to output a binary tree of branches.
  62. * Distributive law.
  63. *(X + 4 * (Y + C)) compiles better as *(X + 4*C + 4*Y)
  64. on some machines because of known addressing modes.
  65. It may be tricky to determine when, and for which machines,
  66. to use each alternative.
  67. 2. Simpler porting.
  68. Right now, describing the target machine's instructions is done
  69. cleanly, but describing its addressing mode is done with several
  70. ad-hoc macro definitions. Porting would be much easier if there were
  71. an RTL description for addressing modes like that for instructions.
  72. Tools analogous to genflags and genrecog would generate macros from
  73. this description.
  74. There would be one pattern in the address-description file for each
  75. kind of addressing, and this pattern would have:
  76. * the RTL expression for the address
  77. * C code to verify its validity (since that may depend on
  78. the exact data).
  79. * C code to print the address in assembler language.
  80. * C code to convert the address into a valid one, if it is not valid.
  81. (This would replace LEGITIMIZE_ADDRESS).
  82. * Register constraints for all indeterminates that appear
  83. in the RTL expression.
  84. 3. Other languages.
  85. Front ends for Pascal, Fortran, Algol, Cobol and Ada are desirable.
  86. Pascal requires the implementation of functions within functions.
  87. Some of the mechanisms for this already exist.
  88. 4. Generalize the machine model.
  89. 4.A. Parameters in registers.
  90. One some machines, conventions are that some parameters are passed
  91. in general registers. The compiler currently cannot handle this.
  92. This requires changes in the code in expr.c for function calls.
  93. For function entry, changes are required in stmt.c, and in
  94. layout_parms, and perhaps also in final and in register allocation,
  95. but the last should be minor.
  96. Where stmt.c now copies the stack slot into a pseudo register,
  97. instead copy the special argument register into a pseudo register.
  98. Use the pseudo register throughout the body of the function to
  99. represent the parameter. That way, parameters can still be spilled
  100. to the stack.
  101. 4.B. Jump-execute-next.
  102. Many recent machines have jumps which execute the following instruction
  103. before the instruction jumped to. To take advantage of this capability
  104. requires a new compiler pass that would reorder instructions when possible.
  105. After reload is a good place for it.
  106. 5. Add a profiling feature like Berkeley's -pg,
  107. or other debugging and measurement features.