aopt386.pas 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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,i386,DAOpt386,POpt386,CSOpt386;
  28. Procedure Optimize(AsmL: PAasmOutput);
  29. Var BlockStart, BlockEnd: Pai;
  30. Begin
  31. {setup labeltable, always necessary}
  32. BlockStart := Pai(AsmL^.First);
  33. BlockEnd := DFAPass1(AsmL, BlockStart);
  34. {Blockend now either contains an ait_marker with Kind = AsmBlockStart, or nil}
  35. While Assigned(BlockStart) Do
  36. Begin
  37. {peephole optimizations}
  38. PeepHoleOptPass1(AsmL, BlockStart, BlockEnd);
  39. PeepHoleOptPass1(AsmL, BlockStart, BlockEnd);
  40. {data flow analyzer}
  41. If (cs_slowoptimize in aktglobalswitches) Then
  42. Begin
  43. If DFAPass2(AsmL, BlockStart, BlockEnd) Then
  44. {common subexpression elimination}
  45. CSE(AsmL, BlockStart, BlockEnd);
  46. End;
  47. {more peephole optimizations}
  48. PeepHoleOptPass2(AsmL, BlockStart, BlockEnd);
  49. {dispose labeltabel}
  50. ShutDownDFA;
  51. If Assigned(BlockEnd) And
  52. GetNextInstruction(BlockEnd, BlockStart) Then
  53. {we stopped at an assmbler block, so skip it}
  54. Begin
  55. While GetNextInstruction(BlockStart, BlockStart) And
  56. ((BlockStart^.Typ <> Ait_Marker) Or
  57. (Pai_Marker(Blockstart)^.Kind <> AsmBlockEnd)) Do;
  58. If GetNextInstruction(BlockStart, BlockStart) Then
  59. BlockEnd := DFAPass1(AsmL, BlockStart)
  60. Else BlockStart := Nil
  61. End
  62. Else BlockStart := Nil;
  63. End;
  64. End;
  65. End.
  66. {
  67. $Log$
  68. Revision 1.24 1998-12-29 18:48:23 jonas
  69. + optimize pascal code surrounding assembler blocks
  70. Revision 1.23 1998/12/11 00:02:43 peter
  71. + globtype,tokens,version unit splitted from globals
  72. Revision 1.22 1998/08/19 16:07:57 jonas
  73. * changed optimizer switches + cleanup of DestroyRefs in daopt386.pas
  74. Revision 1.21 1998/08/06 19:40:29 jonas
  75. * removed $ before and after Log in comment
  76. Revision 1.20 1998/08/05 16:00:08 florian
  77. * some fixes for ansi strings
  78. * log to Log changed
  79. }