PROJECTS 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. * Using constraints on values.
  32. Many operations could be simplified based on knowledge of the
  33. minimum and maximum possible values of a register at any particular time.
  34. These limits could come from the data types in the tree, via rtl generation,
  35. or they can be deduced from operations that are performed. For example,
  36. the result of an `and' operation one of whose operands is 7 must be in
  37. the range 0 to 7. Compare instructions also tell something about the
  38. possible values of the operand, in the code beyond the test.
  39. Value constraints can be used to determine the results of a further
  40. comparison. They can also indicate that certain `and' operations are
  41. redundant. Constraints might permit a decrement and branch
  42. instruction that checks zeroness to be used when the user has
  43. specified to exit if negative.
  44. * Smarter reload pass.
  45. The reload pass as currently written can reload values only into registers
  46. that are reserved for reloading. This means that in order to use a
  47. register for reloading it must spill everything out of that register.
  48. It would be straightforward, though complicated, for reload1.c to keep
  49. track, during its scan, of which hard registers were available at each
  50. point in the function, and use for reloading even registers that were
  51. free only at the point they were needed. This would avoid much spilling
  52. and make better code.
  53. * Change the type of a variable.
  54. Sometimes a variable is declared as `int', it is assigned only once
  55. from a value of type `char', and then it is used only by comparison
  56. against constants. On many machines, better code would result if
  57. the variable had type `char'. If the compiler could detect this
  58. case, it could change the declaration of the variable and change
  59. all the places that use it.
  60. * Order of subexpressions.
  61. It might be possible to make better code by paying attention
  62. to the order in which to generate code for subexpressions of an expression.
  63. * Better code for switch statements.
  64. If a switch statement has only a few cases, a sequence of conditional
  65. branches is generated for it, rather than a jump table. It would
  66. be better to output a binary tree of branches.
  67. * Distributive law.
  68. The C expression *(X + 4 * (Y + C)) compiles better on certain
  69. machines if rewritten as *(X + 4*C + 4*Y) because of known addressing
  70. modes. It may be tricky to determine when, and for which machines, to
  71. use each alternative.
  72. * Jump-execute-next.
  73. Many recent machines have jumps which optionally execute the following
  74. instruction before the instruction jumped to, either conditionally or
  75. unconditionally. To take advantage of this capability requires a new
  76. compiler pass that would reorder instructions when possible. After
  77. reload may be a good place for it.
  78. On some machines, the result of a load from memory is not available
  79. until after the following instruction. The easiest way to support
  80. these machines is to output each RTL load instruction as two assembler
  81. instructions, the second being a no-op. Putting useful instructions
  82. after the load instructions may be a similar task to putting them
  83. after jump instructions.
  84. * Pipeline scheduling.
  85. On many machines, code gets faster if instructions are reordered
  86. so that pipelines are kept full. Doing the best possible job of this
  87. requires knowing which functional units each kind of instruction executes
  88. in and how long the functional unit stays busy with it. Then the
  89. goal is to reorder the instructions to keep many functional units
  90. busy but never feed them so fast they must wait.
  91. 2. Simpler porting.
  92. Right now, describing the target machine's instructions is done
  93. cleanly, but describing its addressing mode is done with several
  94. ad-hoc macro definitions. Porting would be much easier if there were
  95. an RTL description for addressing modes like that for instructions.
  96. Tools analogous to genflags and genrecog would generate macros from
  97. this description.
  98. There would be one pattern in the address-description file for each
  99. kind of addressing, and this pattern would have:
  100. * the RTL expression for the address
  101. * C code to verify its validity (since that may depend on
  102. the exact data).
  103. * C code to print the address in assembler language.
  104. * C code to convert the address into a valid one, if it is not valid.
  105. (This would replace LEGITIMIZE_ADDRESS).
  106. * Register constraints for all indeterminates that appear
  107. in the RTL expression.
  108. 3. Other languages.
  109. Front ends for Pascal, Fortran, Algol, Cobol, Modula-2 and Ada are
  110. desirable.
  111. Pascal, Modula-2 and Ada require the implementation of functions
  112. within functions. Some of the mechanisms for this already exist.
  113. 4. Generalize the machine model.
  114. Some new compiler features may be needed to do a good job on machines
  115. where static data needs to be addressed using base registers.
  116. Some machines have two stacks in different areas of memory, one used
  117. for scalars and another for large objects. The compiler does not
  118. now have a way to understand this.