aopt386.pas 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. {
  2. $Id$
  3. Copyright (c) 1998 by Jonas Maebe
  4. This unit calls the optimization procedures to optimize the assembler
  5. code for i386+
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. ****************************************************************************
  18. }
  19. Unit aopt386;
  20. Interface
  21. Uses
  22. aasm;
  23. Procedure Optimize(AsmL: PAasmOutput);
  24. Implementation
  25. Uses
  26. globtype,
  27. globals,
  28. DAOpt386,POpt386,CSOpt386;
  29. Procedure Optimize(AsmL: PAasmOutput);
  30. Var BlockStart, BlockEnd, HP: Pai;
  31. Begin
  32. {setup labeltable, always necessary}
  33. BlockStart := Pai(AsmL^.First);
  34. BlockEnd := DFAPass1(AsmL, BlockStart);
  35. {Blockend now either contains an ait_marker with Kind = AsmBlockStart, or nil}
  36. While Assigned(BlockStart) Do
  37. Begin
  38. {peephole optimizations}
  39. PeepHoleOptPass1(AsmL, BlockStart, BlockEnd);
  40. PeepHoleOptPass1(AsmL, BlockStart, BlockEnd);
  41. {data flow analyzer}
  42. If (cs_slowoptimize in aktglobalswitches) Then
  43. Begin
  44. If DFAPass2(
  45. {$ifdef statedebug}
  46. AsmL,
  47. {$endif statedebug}
  48. BlockStart, BlockEnd) Then
  49. {common subexpression elimination}
  50. CSE(AsmL, BlockStart, BlockEnd);
  51. End;
  52. {more peephole optimizations}
  53. PeepHoleOptPass2(AsmL, BlockStart, BlockEnd);
  54. {dispose labeltabel}
  55. ShutDownDFA;
  56. {continue where we left off, BlockEnd is either the start of an assembler
  57. block or nil}
  58. BlockStart := BlockEnd;
  59. While Assigned(BlockStart) And
  60. (BlockStart^.typ = ait_Marker) And
  61. (Pai_Marker(BlockStart)^.Kind = AsmBlockStart) Do
  62. Begin
  63. {we stopped at an assembler block, so skip it}
  64. Repeat
  65. BlockStart := Pai(BlockStart^.Next);
  66. Until (BlockStart^.Typ = Ait_Marker) And
  67. (Pai_Marker(Blockstart)^.Kind = AsmBlockEnd);
  68. {blockstart now contains a pai_marker(asmblockend)}
  69. If GetNextInstruction(BlockStart, HP) And
  70. ((HP^.typ <> ait_Marker) Or
  71. (Pai_Marker(HP)^.Kind <> AsmBlockStart)) Then
  72. {there is no assembler block anymore after the current one, so
  73. optimize the next block of "normal" instructions}
  74. BlockEnd := DFAPass1(AsmL, BlockStart)
  75. {otherwise, skip the next assembler block}
  76. Else BlockStart := HP;
  77. End
  78. End;
  79. End;
  80. End.
  81. {
  82. $Log$
  83. Revision 1.29 1999-10-23 14:44:24 jonas
  84. * finally got around making GetNextInstruction return false when
  85. the current pai object is a AsmBlockStart marker
  86. * changed a loop in aopt386 which was incompatible with this change
  87. Revision 1.28 1999/05/08 20:39:02 jonas
  88. + some comments
  89. Revision 1.27 1999/04/18 17:57:17 jonas
  90. * fix for crash when the first instruction of a sequence that gets
  91. optimized is removed (this situation can't occur aymore now)
  92. Revision 1.26 1999/03/31 13:55:03 peter
  93. * assembler inlining working for ag386bin
  94. Revision 1.25 1998/12/29 19:58:27 jonas
  95. * fixed crash when there are two asm blocks right after each other
  96. Revision 1.24 1998/12/29 18:48:23 jonas
  97. + optimize pascal code surrounding assembler blocks
  98. Revision 1.23 1998/12/11 00:02:43 peter
  99. + globtype,tokens,version unit splitted from globals
  100. Revision 1.22 1998/08/19 16:07:57 jonas
  101. * changed optimizer switches + cleanup of DestroyRefs in daopt386.pas
  102. Revision 1.21 1998/08/06 19:40:29 jonas
  103. * removed $ before and after Log in comment
  104. Revision 1.20 1998/08/05 16:00:08 florian
  105. * some fixes for ansi strings
  106. * log to Log changed
  107. }