aoptcpub.pas 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. {
  2. Copyright (c) 1998-2002 by Jonas Maebe, member of the Free Pascal
  3. Development Team
  4. This unit contains several types and constants necessary for the
  5. optimizer to work on the ARM architecture
  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 aoptcpub; { Assembler OPTimizer CPU specific Base }
  20. {$i fpcdefs.inc}
  21. { enable the following define if memory references can have both a base and }
  22. { index register in 1 operand }
  23. { enable the following define if memory references can have a scaled index }
  24. { define RefsHaveScale}
  25. { enable the following define if memory references can have a segment }
  26. { override }
  27. { define RefsHaveSegment}
  28. Interface
  29. Uses
  30. cgbase,aasmtai,
  31. cpubase,aasmcpu,AOptBase;
  32. Type
  33. { type of a normal instruction }
  34. TInstr = Taicpu;
  35. PInstr = ^TInstr;
  36. { ************************************************************************* }
  37. { **************************** TCondRegs ********************************** }
  38. { ************************************************************************* }
  39. { Info about the conditional registers }
  40. TCondRegs = Object
  41. Constructor Init;
  42. Destructor Done;
  43. End;
  44. { ************************************************************************* }
  45. { **************************** TAoptBaseCpu ******************************* }
  46. { ************************************************************************* }
  47. TAoptBaseCpu = class(TAoptBase)
  48. function RegModifiedByInstruction(Reg: TRegister; p1: tai): boolean; override;
  49. End;
  50. { ************************************************************************* }
  51. { ******************************* Constants ******************************* }
  52. { ************************************************************************* }
  53. Const
  54. { the maximum number of things (registers, memory, ...) a single instruction }
  55. { changes }
  56. MaxCh = 3;
  57. {Oper index of operand that contains the source (reference) with a load }
  58. {instruction }
  59. LoadSrc = 0;
  60. {Oper index of operand that contains the destination (register) with a load }
  61. {instruction }
  62. LoadDst = 1;
  63. {Oper index of operand that contains the source (register) with a store }
  64. {instruction }
  65. StoreSrc = 0;
  66. {Oper index of operand that contains the destination (reference) with a load }
  67. {instruction }
  68. StoreDst = 1;
  69. aopt_uncondjmp = A_B;
  70. aopt_condjmp = A_B;
  71. Implementation
  72. { ************************************************************************* }
  73. { **************************** TCondRegs ********************************** }
  74. { ************************************************************************* }
  75. Constructor TCondRegs.init;
  76. Begin
  77. End;
  78. Destructor TCondRegs.Done; {$ifdef inl} inline; {$endif inl}
  79. Begin
  80. End;
  81. function TAoptBaseCpu.RegModifiedByInstruction(Reg: TRegister; p1: tai): boolean;
  82. var
  83. i : Longint;
  84. begin
  85. result:=false;
  86. if (p1.typ <> ait_instruction) then
  87. Exit;
  88. if SuperRegistersEqual(Reg, NR_DEFAULTFLAGS) then
  89. begin
  90. { Comparison instructions (and procedural jump) }
  91. if (taicpu(p1).opcode in [A_BL, A_CMP, A_CMN, A_TST, A_TEQ]) then
  92. Exit(True);
  93. { Instruction sets CPSR register due to S suffix (floating-point
  94. instructios won't raise false positives) }
  95. if (taicpu(p1).oppostfix = PF_S) then
  96. Exit(True);
  97. { Everything else (conditional instructions only read CPSR) }
  98. Exit;
  99. end;
  100. case taicpu(p1).opcode of
  101. A_LDR:
  102. begin
  103. { special handling for LDRD }
  104. if (taicpu(p1).oppostfix=PF_D) and (getsupreg(taicpu(p1).oper[0]^.reg)+1=getsupreg(Reg)) then
  105. begin
  106. result:=true;
  107. exit;
  108. end;
  109. end;
  110. else
  111. ;
  112. end;
  113. for i:=0 to taicpu(p1).ops-1 do
  114. case taicpu(p1).oper[i]^.typ of
  115. top_reg:
  116. if (taicpu(p1).oper[i]^.reg=Reg) and (taicpu(p1).spilling_get_operation_type(i) in [operand_write,operand_readwrite]) then
  117. exit(true);
  118. top_ref:
  119. begin
  120. if (taicpu(p1).spilling_get_operation_type_ref(i,Reg)<>operand_read) then
  121. exit(true);
  122. end
  123. else
  124. ;
  125. end;
  126. end;
  127. End.