aopt386.pas 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 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. {$ifdef newOptimizations}
  20. {$define foropt}
  21. {$define replacereg}
  22. {$define arithopt}
  23. {$define foldarithops}
  24. {$endif newOptimizations}
  25. Unit aopt386;
  26. Interface
  27. Uses
  28. aasm;
  29. Procedure Optimize(AsmL: PAasmOutput);
  30. Implementation
  31. Uses
  32. globtype,
  33. globals,
  34. DAOpt386,POpt386,CSOpt386;
  35. Procedure Optimize(AsmL: PAasmOutput);
  36. Var BlockStart, BlockEnd, HP: Pai;
  37. Begin
  38. {setup labeltable, always necessary}
  39. BlockStart := Pai(AsmL^.First);
  40. BlockEnd := DFAPass1(AsmL, BlockStart);
  41. {Blockend now either contains an ait_marker with Kind = AsmBlockStart, or nil}
  42. While Assigned(BlockStart) Do
  43. Begin
  44. {peephole optimizations}
  45. PeepHoleOptPass1(AsmL, BlockStart, BlockEnd);
  46. PeepHoleOptPass1(AsmL, BlockStart, BlockEnd);
  47. {data flow analyzer}
  48. If (cs_slowoptimize in aktglobalswitches) Then
  49. Begin
  50. If DFAPass2(
  51. {$ifdef statedebug}
  52. AsmL,
  53. {$endif statedebug}
  54. BlockStart, BlockEnd) Then
  55. {common subexpression elimination}
  56. CSE(AsmL, BlockStart, BlockEnd);
  57. End;
  58. {more peephole optimizations}
  59. PeepHoleOptPass2(AsmL, BlockStart, BlockEnd);
  60. {dispose labeltabel}
  61. ShutDownDFA;
  62. {continue where we left off, BlockEnd is either the start of an assembler
  63. block or nil}
  64. BlockStart := BlockEnd;
  65. While Assigned(BlockStart) And
  66. (BlockStart^.typ = ait_Marker) And
  67. (Pai_Marker(BlockStart)^.Kind = AsmBlockStart) Do
  68. Begin
  69. {we stopped at an assembler block, so skip it}
  70. Repeat
  71. BlockStart := Pai(BlockStart^.Next);
  72. Until (BlockStart^.Typ = Ait_Marker) And
  73. (Pai_Marker(Blockstart)^.Kind = AsmBlockEnd);
  74. {blockstart now contains a pai_marker(asmblockend)}
  75. If GetNextInstruction(BlockStart, HP) And
  76. ((HP^.typ <> ait_Marker) Or
  77. (Pai_Marker(HP)^.Kind <> AsmBlockStart)) Then
  78. {there is no assembler block anymore after the current one, so
  79. optimize the next block of "normal" instructions}
  80. BlockEnd := DFAPass1(AsmL, BlockStart)
  81. {otherwise, skip the next assembler block}
  82. Else BlockStart := HP;
  83. End
  84. End;
  85. End;
  86. End.
  87. {
  88. $Log$
  89. Revision 1.32 2000-02-09 13:22:44 peter
  90. * log truncated
  91. Revision 1.31 2000/01/07 01:14:19 peter
  92. * updated copyright to 2000
  93. Revision 1.30 1999/11/27 23:50:22 jonas
  94. + if you define "newOptimizations", all extra optimizations that
  95. require conditional defines will be activated (ie., it's equivalent
  96. to "-dreplacereg -darithopt -dforopt -dfoldarithops")
  97. Revision 1.29 1999/10/23 14:44:24 jonas
  98. * finally got around making GetNextInstruction return false when
  99. the current pai object is a AsmBlockStart marker
  100. * changed a loop in aopt386 which was incompatible with this change
  101. }