aoptcpub.pas 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. case taicpu(p1).opcode of
  87. A_LDR:
  88. { special handling for LDRD }
  89. if (taicpu(p1).oppostfix=PF_D) and (getsupreg(taicpu(p1).oper[0]^.reg)+1=getsupreg(Reg)) then
  90. begin
  91. result:=true;
  92. exit;
  93. end;
  94. end;
  95. for i:=0 to taicpu(p1).ops-1 do
  96. case taicpu(p1).oper[i]^.typ of
  97. top_reg:
  98. if (taicpu(p1).oper[i]^.reg=Reg) and (taicpu(p1).spilling_get_operation_type(i) in [operand_write,operand_readwrite]) then
  99. exit(true);
  100. top_ref:
  101. if (taicpu(p1).spilling_get_operation_type_ref(i,Reg)<>operand_read) then
  102. exit(true);
  103. end;
  104. end;
  105. End.