cgobj.pas 83 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072
  1. {
  2. Copyright (c) 1998-2005 by Florian Klaempfl
  3. Member of the Free Pascal development team
  4. This unit implements the basic code generator object
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. {# @abstract(Abstract code generator unit)
  19. Abstreact code generator unit. This contains the base class
  20. to implement for all new supported processors.
  21. WARNING: None of the routines implemented in these modules,
  22. or their descendants, should use the temp. allocator, as
  23. these routines may be called inside genentrycode, and the
  24. stack frame is already setup!
  25. }
  26. unit cgobj;
  27. {$i fpcdefs.inc}
  28. interface
  29. uses
  30. cclasses,globtype,
  31. cpubase,cgbase,cgutils,parabase,
  32. aasmbase,aasmtai,aasmcpu,
  33. symconst,symbase,symtype,symdef,symtable,rgobj
  34. ;
  35. type
  36. talignment = (AM_NATURAL,AM_NONE,AM_2BYTE,AM_4BYTE,AM_8BYTE);
  37. {# @abstract(Abstract code generator)
  38. This class implements an abstract instruction generator. Some of
  39. the methods of this class are generic, while others must
  40. be overriden for all new processors which will be supported
  41. by Free Pascal. For 32-bit processors, the base class
  42. sould be @link(tcg64f32) and not @var(tcg).
  43. }
  44. tcg = class
  45. public
  46. alignment : talignment;
  47. rg : array[tregistertype] of trgobj;
  48. t_times : longint;
  49. {$ifdef flowgraph}
  50. aktflownode:word;
  51. {$endif}
  52. {************************************************}
  53. { basic routines }
  54. constructor create;
  55. {# Initialize the register allocators needed for the codegenerator.}
  56. procedure init_register_allocators;virtual;
  57. {# Clean up the register allocators needed for the codegenerator.}
  58. procedure done_register_allocators;virtual;
  59. {$ifdef flowgraph}
  60. procedure init_flowgraph;
  61. procedure done_flowgraph;
  62. {$endif}
  63. {# Gets a register suitable to do integer operations on.}
  64. function getintregister(list:Taasmoutput;size:Tcgsize):Tregister;virtual;
  65. {# Gets a register suitable to do integer operations on.}
  66. function getaddressregister(list:Taasmoutput):Tregister;virtual;
  67. function getfpuregister(list:Taasmoutput;size:Tcgsize):Tregister;virtual;
  68. function getmmregister(list:Taasmoutput;size:Tcgsize):Tregister;virtual;
  69. function getflagregister(list:Taasmoutput;size:Tcgsize):Tregister;virtual;abstract;
  70. {Does the generic cg need SIMD registers, like getmmxregister? Or should
  71. the cpu specific child cg object have such a method?}
  72. procedure add_reg_instruction(instr:Tai;r:tregister);virtual;
  73. procedure add_move_instruction(instr:Taicpu);virtual;
  74. function uses_registers(rt:Tregistertype):boolean;virtual;
  75. {# Get a specific register.}
  76. procedure getcpuregister(list:Taasmoutput;r:Tregister);virtual;
  77. procedure ungetcpuregister(list:Taasmoutput;r:Tregister);virtual;
  78. {# Get multiple registers specified.}
  79. procedure alloccpuregisters(list:Taasmoutput;rt:Tregistertype;r:Tcpuregisterset);virtual;
  80. {# Free multiple registers specified.}
  81. procedure dealloccpuregisters(list:Taasmoutput;rt:Tregistertype;r:Tcpuregisterset);virtual;
  82. procedure allocallcpuregisters(list:Taasmoutput);virtual;
  83. procedure deallocallcpuregisters(list:Taasmoutput);virtual;
  84. procedure do_register_allocation(list:Taasmoutput;headertai:tai);virtual;
  85. function makeregsize(list:Taasmoutput;reg:Tregister;size:Tcgsize):Tregister;
  86. {# Emit a label to the instruction stream. }
  87. procedure a_label(list : taasmoutput;l : tasmlabel);virtual;
  88. {# Allocates register r by inserting a pai_realloc record }
  89. procedure a_reg_alloc(list : taasmoutput;r : tregister);
  90. {# Deallocates register r by inserting a pa_regdealloc record}
  91. procedure a_reg_dealloc(list : taasmoutput;r : tregister);
  92. { Synchronize register, make sure it is still valid }
  93. procedure a_reg_sync(list : taasmoutput;r : tregister);
  94. {# Pass a parameter, which is located in a register, to a routine.
  95. This routine should push/send the parameter to the routine, as
  96. required by the specific processor ABI and routine modifiers.
  97. This must be overriden for each CPU target.
  98. @param(size size of the operand in the register)
  99. @param(r register source of the operand)
  100. @param(cgpara where the parameter will be stored)
  101. }
  102. procedure a_param_reg(list : taasmoutput;size : tcgsize;r : tregister;const cgpara : TCGPara);virtual;
  103. {# Pass a parameter, which is a constant, to a routine.
  104. A generic version is provided. This routine should
  105. be overriden for optimization purposes if the cpu
  106. permits directly sending this type of parameter.
  107. @param(size size of the operand in constant)
  108. @param(a value of constant to send)
  109. @param(cgpara where the parameter will be stored)
  110. }
  111. procedure a_param_const(list : taasmoutput;size : tcgsize;a : aint;const cgpara : TCGPara);virtual;
  112. {# Pass the value of a parameter, which is located in memory, to a routine.
  113. A generic version is provided. This routine should
  114. be overriden for optimization purposes if the cpu
  115. permits directly sending this type of parameter.
  116. @param(size size of the operand in constant)
  117. @param(r Memory reference of value to send)
  118. @param(cgpara where the parameter will be stored)
  119. }
  120. procedure a_param_ref(list : taasmoutput;size : tcgsize;const r : treference;const cgpara : TCGPara);virtual;
  121. {# Pass the value of a parameter, which can be located either in a register or memory location,
  122. to a routine.
  123. A generic version is provided.
  124. @param(l location of the operand to send)
  125. @param(nr parameter number (starting from one) of routine (from left to right))
  126. @param(cgpara where the parameter will be stored)
  127. }
  128. procedure a_param_loc(list : taasmoutput;const l : tlocation;const cgpara : TCGPara);
  129. {# Pass the address of a reference to a routine. This routine
  130. will calculate the address of the reference, and pass this
  131. calculated address as a parameter.
  132. A generic version is provided. This routine should
  133. be overriden for optimization purposes if the cpu
  134. permits directly sending this type of parameter.
  135. @param(r reference to get address from)
  136. @param(nr parameter number (starting from one) of routine (from left to right))
  137. }
  138. procedure a_paramaddr_ref(list : taasmoutput;const r : treference;const cgpara : TCGPara);virtual;
  139. { Remarks:
  140. * If a method specifies a size you have only to take care
  141. of that number of bits, i.e. load_const_reg with OP_8 must
  142. only load the lower 8 bit of the specified register
  143. the rest of the register can be undefined
  144. if necessary the compiler will call a method
  145. to zero or sign extend the register
  146. * The a_load_XX_XX with OP_64 needn't to be
  147. implemented for 32 bit
  148. processors, the code generator takes care of that
  149. * the addr size is for work with the natural pointer
  150. size
  151. * the procedures without fpu/mm are only for integer usage
  152. * normally the first location is the source and the
  153. second the destination
  154. }
  155. {# Emits instruction to call the method specified by symbol name.
  156. This routine must be overriden for each new target cpu.
  157. There is no a_call_ref because loading the reference will use
  158. a temp register on most cpu's resulting in conflicts with the
  159. registers used for the parameters (PFV)
  160. }
  161. procedure a_call_name(list : taasmoutput;const s : string);virtual; abstract;
  162. procedure a_call_reg(list : taasmoutput;reg : tregister);virtual; abstract;
  163. procedure a_call_ref(list : taasmoutput;ref : treference);virtual; abstract;
  164. { move instructions }
  165. procedure a_load_const_reg(list : taasmoutput;size : tcgsize;a : aint;register : tregister);virtual; abstract;
  166. procedure a_load_const_ref(list : taasmoutput;size : tcgsize;a : aint;const ref : treference);virtual;
  167. procedure a_load_const_loc(list : taasmoutput;a : aint;const loc : tlocation);
  168. procedure a_load_reg_ref(list : taasmoutput;fromsize,tosize : tcgsize;register : tregister;const ref : treference);virtual; abstract;
  169. procedure a_load_reg_reg(list : taasmoutput;fromsize,tosize : tcgsize;reg1,reg2 : tregister);virtual; abstract;
  170. procedure a_load_reg_loc(list : taasmoutput;fromsize : tcgsize;reg : tregister;const loc: tlocation);
  171. procedure a_load_ref_reg(list : taasmoutput;fromsize,tosize : tcgsize;const ref : treference;register : tregister);virtual; abstract;
  172. procedure a_load_ref_ref(list : taasmoutput;fromsize,tosize : tcgsize;const sref : treference;const dref : treference);virtual;
  173. procedure a_load_loc_reg(list : taasmoutput;tosize: tcgsize; const loc: tlocation; reg : tregister);
  174. procedure a_load_loc_ref(list : taasmoutput;tosize: tcgsize; const loc: tlocation; const ref : treference);
  175. procedure a_loadaddr_ref_reg(list : taasmoutput;const ref : treference;r : tregister);virtual; abstract;
  176. { fpu move instructions }
  177. procedure a_loadfpu_reg_reg(list: taasmoutput; size:tcgsize; reg1, reg2: tregister); virtual; abstract;
  178. procedure a_loadfpu_ref_reg(list: taasmoutput; size: tcgsize; const ref: treference; reg: tregister); virtual; abstract;
  179. procedure a_loadfpu_reg_ref(list: taasmoutput; size: tcgsize; reg: tregister; const ref: treference); virtual; abstract;
  180. procedure a_loadfpu_loc_reg(list: taasmoutput; const loc: tlocation; const reg: tregister);
  181. procedure a_loadfpu_reg_loc(list: taasmoutput; size: tcgsize; const reg: tregister; const loc: tlocation);
  182. procedure a_paramfpu_reg(list : taasmoutput;size : tcgsize;const r : tregister;const cgpara : TCGPara);virtual;
  183. procedure a_paramfpu_ref(list : taasmoutput;size : tcgsize;const ref : treference;const cgpara : TCGPara);virtual;
  184. { vector register move instructions }
  185. procedure a_loadmm_reg_reg(list: taasmoutput; fromsize, tosize : tcgsize;reg1, reg2: tregister;shuffle : pmmshuffle); virtual; abstract;
  186. procedure a_loadmm_ref_reg(list: taasmoutput; fromsize, tosize : tcgsize;const ref: treference; reg: tregister;shuffle : pmmshuffle); virtual; abstract;
  187. procedure a_loadmm_reg_ref(list: taasmoutput; fromsize, tosize : tcgsize;reg: tregister; const ref: treference;shuffle : pmmshuffle); virtual; abstract;
  188. procedure a_loadmm_loc_reg(list: taasmoutput; size: tcgsize; const loc: tlocation; const reg: tregister;shuffle : pmmshuffle);
  189. procedure a_loadmm_reg_loc(list: taasmoutput; size: tcgsize; const reg: tregister; const loc: tlocation;shuffle : pmmshuffle);
  190. procedure a_parammm_reg(list: taasmoutput; size: tcgsize; reg: tregister;const cgpara : TCGPara;shuffle : pmmshuffle); virtual;
  191. procedure a_parammm_ref(list: taasmoutput; size: tcgsize; const ref: treference;const cgpara : TCGPara;shuffle : pmmshuffle); virtual;
  192. procedure a_parammm_loc(list: taasmoutput; const loc: tlocation; const cgpara : TCGPara;shuffle : pmmshuffle); virtual;
  193. procedure a_opmm_reg_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;src,dst: tregister;shuffle : pmmshuffle); virtual;abstract;
  194. procedure a_opmm_ref_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;const ref: treference; reg: tregister;shuffle : pmmshuffle); virtual;
  195. procedure a_opmm_loc_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;const loc: tlocation; reg: tregister;shuffle : pmmshuffle); virtual;
  196. procedure a_opmm_reg_ref(list: taasmoutput; Op: TOpCG; size : tcgsize;reg: tregister;const ref: treference; shuffle : pmmshuffle); virtual;
  197. { basic arithmetic operations }
  198. { note: for operators which require only one argument (not, neg), use }
  199. { the op_reg_reg, op_reg_ref or op_reg_loc methods and keep in mind }
  200. { that in this case the *second* operand is used as both source and }
  201. { destination (JM) }
  202. procedure a_op_const_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; a: Aint; reg: TRegister); virtual; abstract;
  203. procedure a_op_const_ref(list : taasmoutput; Op: TOpCG; size: TCGSize; a: Aint; const ref: TReference); virtual;
  204. procedure a_op_const_loc(list : taasmoutput; Op: TOpCG; a: Aint; const loc: tlocation);
  205. procedure a_op_reg_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; reg1, reg2: TRegister); virtual; abstract;
  206. procedure a_op_reg_ref(list : taasmoutput; Op: TOpCG; size: TCGSize; reg: TRegister; const ref: TReference); virtual;
  207. procedure a_op_ref_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; const ref: TReference; reg: TRegister); virtual;
  208. procedure a_op_reg_loc(list : taasmoutput; Op: TOpCG; reg: tregister; const loc: tlocation);
  209. procedure a_op_ref_loc(list : taasmoutput; Op: TOpCG; const ref: TReference; const loc: tlocation);
  210. { trinary operations for processors that support them, 'emulated' }
  211. { on others. None with "ref" arguments since I don't think there }
  212. { are any processors that support it (JM) }
  213. procedure a_op_const_reg_reg(list: taasmoutput; op: TOpCg; size: tcgsize; a: aint; src, dst: tregister); virtual;
  214. procedure a_op_reg_reg_reg(list: taasmoutput; op: TOpCg; size: tcgsize; src1, src2, dst: tregister); virtual;
  215. procedure a_op_const_reg_reg_checkoverflow(list: taasmoutput; op: TOpCg; size: tcgsize; a: aint; src, dst: tregister;setflags : boolean;var ovloc : tlocation); virtual;
  216. procedure a_op_reg_reg_reg_checkoverflow(list: taasmoutput; op: TOpCg; size: tcgsize; src1, src2, dst: tregister;setflags : boolean;var ovloc : tlocation); virtual;
  217. { comparison operations }
  218. procedure a_cmp_const_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aint;reg : tregister;
  219. l : tasmlabel);virtual; abstract;
  220. procedure a_cmp_const_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aint;const ref : treference;
  221. l : tasmlabel); virtual;
  222. procedure a_cmp_const_loc_label(list: taasmoutput; size: tcgsize;cmp_op: topcmp; a: aint; const loc: tlocation;
  223. l : tasmlabel);
  224. procedure a_cmp_reg_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;reg1,reg2 : tregister;l : tasmlabel); virtual; abstract;
  225. procedure a_cmp_ref_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; const ref: treference; reg : tregister; l : tasmlabel); virtual;
  226. procedure a_cmp_reg_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;reg : tregister; const ref: treference; l : tasmlabel); virtual;
  227. procedure a_cmp_loc_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; const loc: tlocation; reg : tregister; l : tasmlabel);
  228. procedure a_cmp_ref_loc_label(list: taasmoutput; size: tcgsize;cmp_op: topcmp; const ref: treference; const loc: tlocation;
  229. l : tasmlabel);
  230. procedure a_jmp_name(list : taasmoutput;const s : string); virtual; abstract;
  231. procedure a_jmp_always(list : taasmoutput;l: tasmlabel); virtual; abstract;
  232. procedure a_jmp_flags(list : taasmoutput;const f : TResFlags;l: tasmlabel); virtual; abstract;
  233. {# Depending on the value to check in the flags, either sets the register reg to one (if the flag is set)
  234. or zero (if the flag is cleared). The size parameter indicates the destination size register.
  235. }
  236. procedure g_flags2reg(list: taasmoutput; size: TCgSize; const f: tresflags; reg: TRegister); virtual; abstract;
  237. procedure g_flags2ref(list: taasmoutput; size: TCgSize; const f: tresflags; const ref:TReference); virtual;
  238. {
  239. This routine tries to optimize the const_reg opcode, and should be
  240. called at the start of a_op_const_reg. It returns the actual opcode
  241. to emit, and the constant value to emit. If this routine returns
  242. TRUE, @var(no) instruction should be emitted (.eg : imul reg by 1 )
  243. @param(op The opcode to emit, returns the opcode which must be emitted)
  244. @param(a The constant which should be emitted, returns the constant which must
  245. be emitted)
  246. @param(reg The register to emit the opcode with, returns the register with
  247. which the opcode will be emitted)
  248. }
  249. function optimize_op_const_reg(list: taasmoutput; var op: topcg; var a : aint; var reg: tregister): boolean;virtual;
  250. {#
  251. This routine is used in exception management nodes. It should
  252. save the exception reason currently in the FUNCTION_RETURN_REG. The
  253. save should be done either to a temp (pointed to by href).
  254. or on the stack (pushing the value on the stack).
  255. The size of the value to save is OS_S32. The default version
  256. saves the exception reason to a temp. memory area.
  257. }
  258. procedure g_exception_reason_save(list : taasmoutput; const href : treference);virtual;
  259. {#
  260. This routine is used in exception management nodes. It should
  261. save the exception reason constant. The
  262. save should be done either to a temp (pointed to by href).
  263. or on the stack (pushing the value on the stack).
  264. The size of the value to save is OS_S32. The default version
  265. saves the exception reason to a temp. memory area.
  266. }
  267. procedure g_exception_reason_save_const(list : taasmoutput; const href : treference; a: aint);virtual;
  268. {#
  269. This routine is used in exception management nodes. It should
  270. load the exception reason to the FUNCTION_RETURN_REG. The saved value
  271. should either be in the temp. area (pointed to by href , href should
  272. *NOT* be freed) or on the stack (the value should be popped).
  273. The size of the value to save is OS_S32. The default version
  274. saves the exception reason to a temp. memory area.
  275. }
  276. procedure g_exception_reason_load(list : taasmoutput; const href : treference);virtual;
  277. procedure g_maybe_testself(list : taasmoutput;reg:tregister);
  278. procedure g_maybe_testvmt(list : taasmoutput;reg:tregister;objdef:tobjectdef);
  279. {# This should emit the opcode to copy len bytes from the source
  280. to destination.
  281. It must be overriden for each new target processor.
  282. @param(source Source reference of copy)
  283. @param(dest Destination reference of copy)
  284. }
  285. procedure g_concatcopy(list : taasmoutput;const source,dest : treference;len : aint);virtual; abstract;
  286. {# This should emit the opcode to copy len bytes from the an unaligned source
  287. to destination.
  288. It must be overriden for each new target processor.
  289. @param(source Source reference of copy)
  290. @param(dest Destination reference of copy)
  291. }
  292. procedure g_concatcopy_unaligned(list : taasmoutput;const source,dest : treference;len : aint);virtual;
  293. {# This should emit the opcode to a shortrstring from the source
  294. to destination.
  295. @param(source Source reference of copy)
  296. @param(dest Destination reference of copy)
  297. }
  298. procedure g_copyshortstring(list : taasmoutput;const source,dest : treference;len:byte);
  299. procedure g_incrrefcount(list : taasmoutput;t: tdef; const ref: treference);
  300. procedure g_decrrefcount(list : taasmoutput;t: tdef; const ref: treference);
  301. procedure g_initialize(list : taasmoutput;t : tdef;const ref : treference);
  302. procedure g_finalize(list : taasmoutput;t : tdef;const ref : treference);
  303. {# Generates range checking code. It is to note
  304. that this routine does not need to be overriden,
  305. as it takes care of everything.
  306. @param(p Node which contains the value to check)
  307. @param(todef Type definition of node to range check)
  308. }
  309. procedure g_rangecheck(list: taasmoutput; const l:tlocation; fromdef,todef: tdef); virtual;
  310. {# Generates overflow checking code for a node }
  311. procedure g_overflowcheck(list: taasmoutput; const Loc:tlocation; def:tdef); virtual;abstract;
  312. procedure g_overflowCheck_loc(List:TAasmOutput;const Loc:TLocation;def:TDef;ovloc : tlocation);virtual;
  313. procedure g_copyvaluepara_openarray(list : taasmoutput;const ref:treference;const lenloc:tlocation;elesize:aint;destreg:tregister);virtual;
  314. procedure g_releasevaluepara_openarray(list : taasmoutput;const l:tlocation);virtual;
  315. {# Emits instructions when compilation is done in profile
  316. mode (this is set as a command line option). The default
  317. behavior does nothing, should be overriden as required.
  318. }
  319. procedure g_profilecode(list : taasmoutput);virtual;
  320. {# Emits instruction for allocating @var(size) bytes at the stackpointer
  321. @param(size Number of bytes to allocate)
  322. }
  323. procedure g_stackpointer_alloc(list : taasmoutput;size : longint);virtual; abstract;
  324. {# Emits instruction for allocating the locals in entry
  325. code of a routine. This is one of the first
  326. routine called in @var(genentrycode).
  327. @param(localsize Number of bytes to allocate as locals)
  328. }
  329. procedure g_proc_entry(list : taasmoutput;localsize : longint;nostackframe:boolean);virtual; abstract;
  330. {# Emits instructions for returning from a subroutine.
  331. Should also restore the framepointer and stack.
  332. @param(parasize Number of bytes of parameters to deallocate from stack)
  333. }
  334. procedure g_proc_exit(list : taasmoutput;parasize:longint;nostackframe:boolean);virtual;abstract;
  335. {# This routine is called when generating the code for the entry point
  336. of a routine. It should save all registers which are not used in this
  337. routine, and which should be declared as saved in the std_saved_registers
  338. set.
  339. This routine is mainly used when linking to code which is generated
  340. by ABI-compliant compilers (like GCC), to make sure that the reserved
  341. registers of that ABI are not clobbered.
  342. @param(usedinproc Registers which are used in the code of this routine)
  343. }
  344. procedure g_save_standard_registers(list:Taasmoutput);virtual;
  345. {# This routine is called when generating the code for the exit point
  346. of a routine. It should restore all registers which were previously
  347. saved in @var(g_save_standard_registers).
  348. @param(usedinproc Registers which are used in the code of this routine)
  349. }
  350. procedure g_restore_standard_registers(list:Taasmoutput);virtual;
  351. procedure g_intf_wrapper(list: TAAsmoutput; procdef: tprocdef; const labelname: string; ioffset: longint);virtual;abstract;
  352. procedure g_adjust_self_value(list:taasmoutput;procdef: tprocdef;ioffset: aint);virtual;
  353. end;
  354. {$ifndef cpu64bit}
  355. {# @abstract(Abstract code generator for 64 Bit operations)
  356. This class implements an abstract code generator class
  357. for 64 Bit operations.
  358. }
  359. tcg64 = class
  360. procedure a_load64_const_ref(list : taasmoutput;value : int64;const ref : treference);virtual;abstract;
  361. procedure a_load64_reg_ref(list : taasmoutput;reg : tregister64;const ref : treference);virtual;abstract;
  362. procedure a_load64_ref_reg(list : taasmoutput;const ref : treference;reg : tregister64);virtual;abstract;
  363. procedure a_load64_reg_reg(list : taasmoutput;regsrc,regdst : tregister64);virtual;abstract;
  364. procedure a_load64_const_reg(list : taasmoutput;value : int64;reg : tregister64);virtual;abstract;
  365. procedure a_load64_loc_reg(list : taasmoutput;const l : tlocation;reg : tregister64);virtual;abstract;
  366. procedure a_load64_loc_ref(list : taasmoutput;const l : tlocation;const ref : treference);virtual;abstract;
  367. procedure a_load64_const_loc(list : taasmoutput;value : int64;const l : tlocation);virtual;abstract;
  368. procedure a_load64_reg_loc(list : taasmoutput;reg : tregister64;const l : tlocation);virtual;abstract;
  369. procedure a_load64high_reg_ref(list : taasmoutput;reg : tregister;const ref : treference);virtual;abstract;
  370. procedure a_load64low_reg_ref(list : taasmoutput;reg : tregister;const ref : treference);virtual;abstract;
  371. procedure a_load64high_ref_reg(list : taasmoutput;const ref : treference;reg : tregister);virtual;abstract;
  372. procedure a_load64low_ref_reg(list : taasmoutput;const ref : treference;reg : tregister);virtual;abstract;
  373. procedure a_load64high_loc_reg(list : taasmoutput;const l : tlocation;reg : tregister);virtual;abstract;
  374. procedure a_load64low_loc_reg(list : taasmoutput;const l : tlocation;reg : tregister);virtual;abstract;
  375. procedure a_op64_ref_reg(list : taasmoutput;op:TOpCG;size : tcgsize;const ref : treference;reg : tregister64);virtual;abstract;
  376. procedure a_op64_reg_reg(list : taasmoutput;op:TOpCG;size : tcgsize;regsrc,regdst : tregister64);virtual;abstract;
  377. procedure a_op64_reg_ref(list : taasmoutput;op:TOpCG;size : tcgsize;regsrc : tregister64;const ref : treference);virtual;abstract;
  378. procedure a_op64_const_reg(list : taasmoutput;op:TOpCG;size : tcgsize;value : int64;regdst : tregister64);virtual;abstract;
  379. procedure a_op64_const_ref(list : taasmoutput;op:TOpCG;size : tcgsize;value : int64;const ref : treference);virtual;abstract;
  380. procedure a_op64_const_loc(list : taasmoutput;op:TOpCG;size : tcgsize;value : int64;const l: tlocation);virtual;abstract;
  381. procedure a_op64_reg_loc(list : taasmoutput;op:TOpCG;size : tcgsize;reg : tregister64;const l : tlocation);virtual;abstract;
  382. procedure a_op64_loc_reg(list : taasmoutput;op:TOpCG;size : tcgsize;const l : tlocation;reg64 : tregister64);virtual;abstract;
  383. procedure a_op64_const_reg_reg(list: taasmoutput;op:TOpCG;size : tcgsize;value : int64;regsrc,regdst : tregister64);virtual;
  384. procedure a_op64_reg_reg_reg(list: taasmoutput;op:TOpCG;size : tcgsize;regsrc1,regsrc2,regdst : tregister64);virtual;
  385. procedure a_op64_const_reg_reg_checkoverflow(list: taasmoutput;op:TOpCG;size : tcgsize;value : int64;regsrc,regdst : tregister64;setflags : boolean;var ovloc : tlocation);virtual;
  386. procedure a_op64_reg_reg_reg_checkoverflow(list: taasmoutput;op:TOpCG;size : tcgsize;regsrc1,regsrc2,regdst : tregister64;setflags : boolean;var ovloc : tlocation);virtual;
  387. procedure a_param64_reg(list : taasmoutput;reg64 : tregister64;const loc : TCGPara);virtual;abstract;
  388. procedure a_param64_const(list : taasmoutput;value : int64;const loc : TCGPara);virtual;abstract;
  389. procedure a_param64_ref(list : taasmoutput;const r : treference;const loc : TCGPara);virtual;abstract;
  390. procedure a_param64_loc(list : taasmoutput;const l : tlocation;const loc : TCGPara);virtual;abstract;
  391. {
  392. This routine tries to optimize the const_reg opcode, and should be
  393. called at the start of a_op64_const_reg. It returns the actual opcode
  394. to emit, and the constant value to emit. If this routine returns
  395. TRUE, @var(no) instruction should be emitted (.eg : imul reg by 1 )
  396. @param(op The opcode to emit, returns the opcode which must be emitted)
  397. @param(a The constant which should be emitted, returns the constant which must
  398. be emitted)
  399. @param(reg The register to emit the opcode with, returns the register with
  400. which the opcode will be emitted)
  401. }
  402. function optimize64_op_const_reg(list: taasmoutput; var op: topcg; var a : int64; var reg: tregister64): boolean;virtual;abstract;
  403. { override to catch 64bit rangechecks }
  404. procedure g_rangecheck64(list: taasmoutput; const l:tlocation; fromdef,todef: tdef);virtual;abstract;
  405. end;
  406. {$endif cpu64bit}
  407. var
  408. {# Main code generator class }
  409. cg : tcg;
  410. {$ifndef cpu64bit}
  411. {# Code generator class for all operations working with 64-Bit operands }
  412. cg64 : tcg64;
  413. {$endif cpu64bit}
  414. implementation
  415. uses
  416. globals,options,systems,
  417. verbose,defutil,paramgr,symsym,
  418. tgobj,cutils,procinfo;
  419. const
  420. { Please leave this here, this module should NOT use
  421. exprasmlist, the lists are always passed as arguments.
  422. Declaring it as string here results in an error when compiling (PFV) }
  423. exprasmlist = 'error';
  424. {*****************************************************************************
  425. basic functionallity
  426. ******************************************************************************}
  427. constructor tcg.create;
  428. begin
  429. end;
  430. {*****************************************************************************
  431. register allocation
  432. ******************************************************************************}
  433. procedure tcg.init_register_allocators;
  434. begin
  435. fillchar(rg,sizeof(rg),0);
  436. add_reg_instruction_hook:=@add_reg_instruction;
  437. end;
  438. procedure tcg.done_register_allocators;
  439. begin
  440. { Safety }
  441. fillchar(rg,sizeof(rg),0);
  442. add_reg_instruction_hook:=nil;
  443. end;
  444. {$ifdef flowgraph}
  445. procedure Tcg.init_flowgraph;
  446. begin
  447. aktflownode:=0;
  448. end;
  449. procedure Tcg.done_flowgraph;
  450. begin
  451. end;
  452. {$endif}
  453. function tcg.getintregister(list:Taasmoutput;size:Tcgsize):Tregister;
  454. begin
  455. if not assigned(rg[R_INTREGISTER]) then
  456. internalerror(200312122);
  457. result:=rg[R_INTREGISTER].getregister(list,cgsize2subreg(size));
  458. end;
  459. function tcg.getfpuregister(list:Taasmoutput;size:Tcgsize):Tregister;
  460. begin
  461. if not assigned(rg[R_FPUREGISTER]) then
  462. internalerror(200312123);
  463. result:=rg[R_FPUREGISTER].getregister(list,cgsize2subreg(size));
  464. end;
  465. function tcg.getmmregister(list:Taasmoutput;size:Tcgsize):Tregister;
  466. begin
  467. if not assigned(rg[R_MMREGISTER]) then
  468. internalerror(2003121214);
  469. result:=rg[R_MMREGISTER].getregister(list,cgsize2subreg(size));
  470. end;
  471. function tcg.getaddressregister(list:Taasmoutput):Tregister;
  472. begin
  473. if assigned(rg[R_ADDRESSREGISTER]) then
  474. result:=rg[R_ADDRESSREGISTER].getregister(list,R_SUBWHOLE)
  475. else
  476. begin
  477. if not assigned(rg[R_INTREGISTER]) then
  478. internalerror(200312121);
  479. result:=rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  480. end;
  481. end;
  482. function Tcg.makeregsize(list:Taasmoutput;reg:Tregister;size:Tcgsize):Tregister;
  483. var
  484. subreg:Tsubregister;
  485. begin
  486. subreg:=cgsize2subreg(size);
  487. result:=reg;
  488. setsubreg(result,subreg);
  489. { notify RA }
  490. if result<>reg then
  491. list.concat(tai_regalloc.resize(result));
  492. end;
  493. procedure tcg.getcpuregister(list:Taasmoutput;r:Tregister);
  494. begin
  495. if not assigned(rg[getregtype(r)]) then
  496. internalerror(200312125);
  497. rg[getregtype(r)].getcpuregister(list,r);
  498. end;
  499. procedure tcg.ungetcpuregister(list:Taasmoutput;r:Tregister);
  500. begin
  501. if not assigned(rg[getregtype(r)]) then
  502. internalerror(200312126);
  503. rg[getregtype(r)].ungetcpuregister(list,r);
  504. end;
  505. procedure tcg.alloccpuregisters(list:Taasmoutput;rt:Tregistertype;r:Tcpuregisterset);
  506. begin
  507. if assigned(rg[rt]) then
  508. rg[rt].alloccpuregisters(list,r)
  509. else
  510. internalerror(200310092);
  511. end;
  512. procedure tcg.allocallcpuregisters(list:Taasmoutput);
  513. begin
  514. alloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  515. {$ifndef i386}
  516. alloccpuregisters(list,R_FPUREGISTER,paramanager.get_volatile_registers_fpu(pocall_default));
  517. {$ifdef cpumm}
  518. alloccpuregisters(list,R_MMREGISTER,paramanager.get_volatile_registers_mm(pocall_default));
  519. {$endif cpumm}
  520. {$endif i386}
  521. end;
  522. procedure tcg.dealloccpuregisters(list:Taasmoutput;rt:Tregistertype;r:Tcpuregisterset);
  523. begin
  524. if assigned(rg[rt]) then
  525. rg[rt].dealloccpuregisters(list,r)
  526. else
  527. internalerror(200310093);
  528. end;
  529. procedure tcg.deallocallcpuregisters(list:Taasmoutput);
  530. begin
  531. dealloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  532. {$ifndef i386}
  533. dealloccpuregisters(list,R_FPUREGISTER,paramanager.get_volatile_registers_fpu(pocall_default));
  534. {$ifdef cpumm}
  535. dealloccpuregisters(list,R_MMREGISTER,paramanager.get_volatile_registers_mm(pocall_default));
  536. {$endif cpumm}
  537. {$endif i386}
  538. end;
  539. function tcg.uses_registers(rt:Tregistertype):boolean;
  540. begin
  541. if assigned(rg[rt]) then
  542. result:=rg[rt].uses_registers
  543. else
  544. result:=false;
  545. end;
  546. procedure tcg.add_reg_instruction(instr:Tai;r:tregister);
  547. var
  548. rt : tregistertype;
  549. begin
  550. rt:=getregtype(r);
  551. { Only add it when a register allocator is configured.
  552. No IE can be generated, because the VMT is written
  553. without a valid rg[] }
  554. if assigned(rg[rt]) then
  555. rg[rt].add_reg_instruction(instr,r);
  556. end;
  557. procedure tcg.add_move_instruction(instr:Taicpu);
  558. var
  559. rt : tregistertype;
  560. begin
  561. rt:=getregtype(instr.oper[O_MOV_SOURCE]^.reg);
  562. if assigned(rg[rt]) then
  563. rg[rt].add_move_instruction(instr)
  564. else
  565. internalerror(200310095);
  566. end;
  567. procedure tcg.do_register_allocation(list:Taasmoutput;headertai:tai);
  568. var
  569. rt : tregistertype;
  570. begin
  571. for rt:=R_FPUREGISTER to R_SPECIALREGISTER do
  572. begin
  573. if assigned(rg[rt]) then
  574. rg[rt].do_register_allocation(list,headertai);
  575. end;
  576. { running the other register allocator passes could require addition int/addr. registers
  577. when spilling so run int/addr register allocation at the end }
  578. if assigned(rg[R_INTREGISTER]) then
  579. rg[R_INTREGISTER].do_register_allocation(list,headertai);
  580. if assigned(rg[R_ADDRESSREGISTER]) then
  581. rg[R_ADDRESSREGISTER].do_register_allocation(list,headertai);
  582. end;
  583. procedure tcg.a_reg_alloc(list : taasmoutput;r : tregister);
  584. begin
  585. list.concat(tai_regalloc.alloc(r,nil));
  586. end;
  587. procedure tcg.a_reg_dealloc(list : taasmoutput;r : tregister);
  588. begin
  589. list.concat(tai_regalloc.dealloc(r,nil));
  590. end;
  591. procedure tcg.a_reg_sync(list : taasmoutput;r : tregister);
  592. var
  593. instr : tai;
  594. begin
  595. instr:=tai_regalloc.sync(r);
  596. list.concat(instr);
  597. add_reg_instruction(instr,r);
  598. end;
  599. procedure tcg.a_label(list : taasmoutput;l : tasmlabel);
  600. begin
  601. list.concat(tai_label.create(l));
  602. end;
  603. {*****************************************************************************
  604. for better code generation these methods should be overridden
  605. ******************************************************************************}
  606. procedure tcg.a_param_reg(list : taasmoutput;size : tcgsize;r : tregister;const cgpara : TCGPara);
  607. var
  608. ref : treference;
  609. begin
  610. cgpara.check_simple_location;
  611. case cgpara.location^.loc of
  612. LOC_REGISTER,LOC_CREGISTER:
  613. a_load_reg_reg(list,size,cgpara.location^.size,r,cgpara.location^.register);
  614. LOC_REFERENCE,LOC_CREFERENCE:
  615. begin
  616. reference_reset_base(ref,cgpara.location^.reference.index,cgpara.location^.reference.offset);
  617. a_load_reg_ref(list,size,cgpara.location^.size,r,ref);
  618. end
  619. else
  620. internalerror(2002071004);
  621. end;
  622. end;
  623. procedure tcg.a_param_const(list : taasmoutput;size : tcgsize;a : aint;const cgpara : TCGPara);
  624. var
  625. ref : treference;
  626. begin
  627. cgpara.check_simple_location;
  628. case cgpara.location^.loc of
  629. LOC_REGISTER,LOC_CREGISTER:
  630. a_load_const_reg(list,cgpara.location^.size,a,cgpara.location^.register);
  631. LOC_REFERENCE,LOC_CREFERENCE:
  632. begin
  633. reference_reset_base(ref,cgpara.location^.reference.index,cgpara.location^.reference.offset);
  634. a_load_const_ref(list,cgpara.location^.size,a,ref);
  635. end
  636. else
  637. internalerror(2002071004);
  638. end;
  639. end;
  640. procedure tcg.a_param_ref(list : taasmoutput;size : tcgsize;const r : treference;const cgpara : TCGPara);
  641. var
  642. ref : treference;
  643. begin
  644. cgpara.check_simple_location;
  645. case cgpara.location^.loc of
  646. LOC_REGISTER,LOC_CREGISTER:
  647. a_load_ref_reg(list,size,cgpara.location^.size,r,cgpara.location^.register);
  648. LOC_REFERENCE,LOC_CREFERENCE:
  649. begin
  650. reference_reset(ref);
  651. ref.base:=cgpara.location^.reference.index;
  652. ref.offset:=cgpara.location^.reference.offset;
  653. { use concatcopy, because it can also be a float which fails when
  654. load_ref_ref is used }
  655. g_concatcopy(list,r,ref,tcgsize2size[size]);
  656. end
  657. else
  658. internalerror(2002071004);
  659. end;
  660. end;
  661. procedure tcg.a_param_loc(list : taasmoutput;const l:tlocation;const cgpara : TCGPara);
  662. begin
  663. case l.loc of
  664. LOC_REGISTER,
  665. LOC_CREGISTER :
  666. a_param_reg(list,l.size,l.register,cgpara);
  667. LOC_CONSTANT :
  668. a_param_const(list,l.size,l.value,cgpara);
  669. LOC_CREFERENCE,
  670. LOC_REFERENCE :
  671. a_param_ref(list,l.size,l.reference,cgpara);
  672. else
  673. internalerror(2002032211);
  674. end;
  675. end;
  676. procedure tcg.a_paramaddr_ref(list : taasmoutput;const r : treference;const cgpara : TCGPara);
  677. var
  678. hr : tregister;
  679. begin
  680. cgpara.check_simple_location;
  681. hr:=getaddressregister(list);
  682. a_loadaddr_ref_reg(list,r,hr);
  683. a_param_reg(list,OS_ADDR,hr,cgpara);
  684. end;
  685. {****************************************************************************
  686. some generic implementations
  687. ****************************************************************************}
  688. procedure tcg.a_load_ref_ref(list : taasmoutput;fromsize,tosize : tcgsize;const sref : treference;const dref : treference);
  689. var
  690. tmpreg: tregister;
  691. begin
  692. { verify if we have the same reference }
  693. if references_equal(sref,dref) then
  694. exit;
  695. tmpreg:=getintregister(list,tosize);
  696. a_load_ref_reg(list,fromsize,tosize,sref,tmpreg);
  697. a_load_reg_ref(list,tosize,tosize,tmpreg,dref);
  698. end;
  699. procedure tcg.a_load_const_ref(list : taasmoutput;size : tcgsize;a : aint;const ref : treference);
  700. var
  701. tmpreg: tregister;
  702. begin
  703. tmpreg:=getintregister(list,size);
  704. a_load_const_reg(list,size,a,tmpreg);
  705. a_load_reg_ref(list,size,size,tmpreg,ref);
  706. end;
  707. procedure tcg.a_load_const_loc(list : taasmoutput;a : aint;const loc: tlocation);
  708. begin
  709. case loc.loc of
  710. LOC_REFERENCE,LOC_CREFERENCE:
  711. a_load_const_ref(list,loc.size,a,loc.reference);
  712. LOC_REGISTER,LOC_CREGISTER:
  713. a_load_const_reg(list,loc.size,a,loc.register);
  714. else
  715. internalerror(200203272);
  716. end;
  717. end;
  718. procedure tcg.a_load_reg_loc(list : taasmoutput;fromsize : tcgsize;reg : tregister;const loc: tlocation);
  719. begin
  720. case loc.loc of
  721. LOC_REFERENCE,LOC_CREFERENCE:
  722. a_load_reg_ref(list,fromsize,loc.size,reg,loc.reference);
  723. LOC_REGISTER,LOC_CREGISTER:
  724. a_load_reg_reg(list,fromsize,loc.size,reg,loc.register);
  725. else
  726. internalerror(200203271);
  727. end;
  728. end;
  729. procedure tcg.a_load_loc_reg(list : taasmoutput; tosize: tcgsize; const loc: tlocation; reg : tregister);
  730. begin
  731. case loc.loc of
  732. LOC_REFERENCE,LOC_CREFERENCE:
  733. a_load_ref_reg(list,loc.size,tosize,loc.reference,reg);
  734. LOC_REGISTER,LOC_CREGISTER:
  735. a_load_reg_reg(list,loc.size,tosize,loc.register,reg);
  736. LOC_CONSTANT:
  737. a_load_const_reg(list,tosize,loc.value,reg);
  738. else
  739. internalerror(200109092);
  740. end;
  741. end;
  742. procedure tcg.a_load_loc_ref(list : taasmoutput;tosize: tcgsize; const loc: tlocation; const ref : treference);
  743. begin
  744. case loc.loc of
  745. LOC_REFERENCE,LOC_CREFERENCE:
  746. a_load_ref_ref(list,loc.size,tosize,loc.reference,ref);
  747. LOC_REGISTER,LOC_CREGISTER:
  748. a_load_reg_ref(list,loc.size,tosize,loc.register,ref);
  749. LOC_CONSTANT:
  750. a_load_const_ref(list,tosize,loc.value,ref);
  751. else
  752. internalerror(200109302);
  753. end;
  754. end;
  755. function tcg.optimize_op_const_reg(list: taasmoutput; var op: topcg; var a : aint; var reg:tregister): boolean;
  756. var
  757. powerval : longint;
  758. begin
  759. optimize_op_const_reg := false;
  760. case op of
  761. { or with zero returns same result }
  762. OP_OR : if a = 0 then optimize_op_const_reg := true;
  763. { and with max returns same result }
  764. OP_AND : if (a = high(a)) then optimize_op_const_reg := true;
  765. { division by 1 returns result }
  766. OP_DIV :
  767. begin
  768. if a = 1 then
  769. optimize_op_const_reg := true
  770. else if ispowerof2(int64(a), powerval) then
  771. begin
  772. a := powerval;
  773. op:= OP_SHR;
  774. end;
  775. exit;
  776. end;
  777. OP_IDIV:
  778. begin
  779. if a = 1 then
  780. optimize_op_const_reg := true
  781. else if ispowerof2(int64(a), powerval) then
  782. begin
  783. a := powerval;
  784. op:= OP_SAR;
  785. end;
  786. exit;
  787. end;
  788. OP_MUL,OP_IMUL:
  789. begin
  790. if a = 1 then
  791. optimize_op_const_reg := true
  792. else if ispowerof2(int64(a), powerval) then
  793. begin
  794. a := powerval;
  795. op:= OP_SHL;
  796. end;
  797. exit;
  798. end;
  799. OP_SAR,OP_SHL,OP_SHR:
  800. begin
  801. if a = 0 then
  802. optimize_op_const_reg := true;
  803. exit;
  804. end;
  805. end;
  806. end;
  807. procedure tcg.a_loadfpu_loc_reg(list: taasmoutput; const loc: tlocation; const reg: tregister);
  808. begin
  809. case loc.loc of
  810. LOC_REFERENCE, LOC_CREFERENCE:
  811. a_loadfpu_ref_reg(list,loc.size,loc.reference,reg);
  812. LOC_FPUREGISTER, LOC_CFPUREGISTER:
  813. a_loadfpu_reg_reg(list,loc.size,loc.register,reg);
  814. else
  815. internalerror(200203301);
  816. end;
  817. end;
  818. procedure tcg.a_loadfpu_reg_loc(list: taasmoutput; size: tcgsize; const reg: tregister; const loc: tlocation);
  819. begin
  820. case loc.loc of
  821. LOC_REFERENCE, LOC_CREFERENCE:
  822. a_loadfpu_reg_ref(list,size,reg,loc.reference);
  823. LOC_FPUREGISTER, LOC_CFPUREGISTER:
  824. a_loadfpu_reg_reg(list,size,reg,loc.register);
  825. else
  826. internalerror(48991);
  827. end;
  828. end;
  829. procedure tcg.a_paramfpu_reg(list : taasmoutput;size : tcgsize;const r : tregister;const cgpara : TCGPara);
  830. var
  831. ref : treference;
  832. begin
  833. case cgpara.location^.loc of
  834. LOC_FPUREGISTER,LOC_CFPUREGISTER:
  835. begin
  836. cgpara.check_simple_location;
  837. a_loadfpu_reg_reg(list,size,r,cgpara.location^.register);
  838. end;
  839. LOC_REFERENCE,LOC_CREFERENCE:
  840. begin
  841. cgpara.check_simple_location;
  842. reference_reset_base(ref,cgpara.location^.reference.index,cgpara.location^.reference.offset);
  843. a_loadfpu_reg_ref(list,size,r,ref);
  844. end;
  845. LOC_REGISTER,LOC_CREGISTER:
  846. begin
  847. { paramfpu_ref does the check_simpe_location check here if necessary }
  848. tg.GetTemp(list,TCGSize2Size[size],tt_normal,ref);
  849. a_loadfpu_reg_ref(list,size,r,ref);
  850. a_paramfpu_ref(list,size,ref,cgpara);
  851. tg.Ungettemp(list,ref);
  852. end;
  853. else
  854. internalerror(2002071004);
  855. end;
  856. end;
  857. procedure tcg.a_paramfpu_ref(list : taasmoutput;size : tcgsize;const ref : treference;const cgpara : TCGPara);
  858. var
  859. href : treference;
  860. begin
  861. cgpara.check_simple_location;
  862. case cgpara.location^.loc of
  863. LOC_FPUREGISTER,LOC_CFPUREGISTER:
  864. a_loadfpu_ref_reg(list,size,ref,cgpara.location^.register);
  865. LOC_REFERENCE,LOC_CREFERENCE:
  866. begin
  867. reference_reset_base(href,cgpara.location^.reference.index,cgpara.location^.reference.offset);
  868. { concatcopy should choose the best way to copy the data }
  869. g_concatcopy(list,ref,href,tcgsize2size[size]);
  870. end;
  871. else
  872. internalerror(200402201);
  873. end;
  874. end;
  875. procedure tcg.a_op_const_ref(list : taasmoutput; Op: TOpCG; size: TCGSize; a: aint; const ref: TReference);
  876. var
  877. tmpreg : tregister;
  878. begin
  879. tmpreg:=getintregister(list,size);
  880. a_load_ref_reg(list,size,size,ref,tmpreg);
  881. a_op_const_reg(list,op,size,a,tmpreg);
  882. a_load_reg_ref(list,size,size,tmpreg,ref);
  883. end;
  884. procedure tcg.a_op_const_loc(list : taasmoutput; Op: TOpCG; a: aint; const loc: tlocation);
  885. begin
  886. case loc.loc of
  887. LOC_REGISTER, LOC_CREGISTER:
  888. a_op_const_reg(list,op,loc.size,a,loc.register);
  889. LOC_REFERENCE, LOC_CREFERENCE:
  890. a_op_const_ref(list,op,loc.size,a,loc.reference);
  891. else
  892. internalerror(200109061);
  893. end;
  894. end;
  895. procedure tcg.a_op_reg_ref(list : taasmoutput; Op: TOpCG; size: TCGSize;reg: TRegister; const ref: TReference);
  896. var
  897. tmpreg : tregister;
  898. begin
  899. tmpreg:=getintregister(list,size);
  900. a_load_ref_reg(list,size,size,ref,tmpreg);
  901. a_op_reg_reg(list,op,size,reg,tmpreg);
  902. a_load_reg_ref(list,size,size,tmpreg,ref);
  903. end;
  904. procedure tcg.a_op_ref_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; const ref: TReference; reg: TRegister);
  905. var
  906. tmpreg: tregister;
  907. begin
  908. case op of
  909. OP_NOT,OP_NEG:
  910. { handle it as "load ref,reg; op reg" }
  911. begin
  912. a_load_ref_reg(list,size,size,ref,reg);
  913. a_op_reg_reg(list,op,size,reg,reg);
  914. end;
  915. else
  916. begin
  917. tmpreg:=getintregister(list,size);
  918. a_load_ref_reg(list,size,size,ref,tmpreg);
  919. a_op_reg_reg(list,op,size,tmpreg,reg);
  920. end;
  921. end;
  922. end;
  923. procedure tcg.a_op_reg_loc(list : taasmoutput; Op: TOpCG; reg: tregister; const loc: tlocation);
  924. begin
  925. case loc.loc of
  926. LOC_REGISTER, LOC_CREGISTER:
  927. a_op_reg_reg(list,op,loc.size,reg,loc.register);
  928. LOC_REFERENCE, LOC_CREFERENCE:
  929. a_op_reg_ref(list,op,loc.size,reg,loc.reference);
  930. else
  931. internalerror(200109061);
  932. end;
  933. end;
  934. procedure tcg.a_op_ref_loc(list : taasmoutput; Op: TOpCG; const ref: TReference; const loc: tlocation);
  935. var
  936. tmpreg: tregister;
  937. begin
  938. case loc.loc of
  939. LOC_REGISTER,LOC_CREGISTER:
  940. a_op_ref_reg(list,op,loc.size,ref,loc.register);
  941. LOC_REFERENCE,LOC_CREFERENCE:
  942. begin
  943. tmpreg:=getintregister(list,loc.size);
  944. a_load_ref_reg(list,loc.size,loc.size,ref,tmpreg);
  945. a_op_reg_ref(list,op,loc.size,tmpreg,loc.reference);
  946. end;
  947. else
  948. internalerror(200109061);
  949. end;
  950. end;
  951. procedure Tcg.a_op_const_reg_reg(list:Taasmoutput;op:Topcg;size:Tcgsize;
  952. a:aint;src,dst:Tregister);
  953. begin
  954. a_load_reg_reg(list,size,size,src,dst);
  955. a_op_const_reg(list,op,size,a,dst);
  956. end;
  957. procedure tcg.a_op_reg_reg_reg(list: taasmoutput; op: TOpCg;
  958. size: tcgsize; src1, src2, dst: tregister);
  959. var
  960. tmpreg: tregister;
  961. begin
  962. if (dst<>src1) then
  963. begin
  964. a_load_reg_reg(list,size,size,src2,dst);
  965. a_op_reg_reg(list,op,size,src1,dst);
  966. end
  967. else
  968. begin
  969. tmpreg:=getintregister(list,size);
  970. a_load_reg_reg(list,size,size,src2,tmpreg);
  971. a_op_reg_reg(list,op,size,src1,tmpreg);
  972. a_load_reg_reg(list,size,size,tmpreg,dst);
  973. end;
  974. end;
  975. procedure tcg.a_op_const_reg_reg_checkoverflow(list: taasmoutput; op: TOpCg; size: tcgsize; a: aint; src, dst: tregister;setflags : boolean;var ovloc : tlocation);
  976. begin
  977. a_op_const_reg_reg(list,op,size,a,src,dst);
  978. ovloc.loc:=LOC_VOID;
  979. end;
  980. procedure tcg.a_op_reg_reg_reg_checkoverflow(list: taasmoutput; op: TOpCg; size: tcgsize; src1, src2, dst: tregister;setflags : boolean;var ovloc : tlocation);
  981. begin
  982. a_op_reg_reg_reg(list,op,size,src1,src2,dst);
  983. ovloc.loc:=LOC_VOID;
  984. end;
  985. procedure tcg.a_cmp_const_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aint;const ref : treference;
  986. l : tasmlabel);
  987. var
  988. tmpreg: tregister;
  989. begin
  990. tmpreg:=getintregister(list,size);
  991. a_load_ref_reg(list,size,size,ref,tmpreg);
  992. a_cmp_const_reg_label(list,size,cmp_op,a,tmpreg,l);
  993. end;
  994. procedure tcg.a_cmp_const_loc_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aint;const loc : tlocation;
  995. l : tasmlabel);
  996. begin
  997. case loc.loc of
  998. LOC_REGISTER,LOC_CREGISTER:
  999. a_cmp_const_reg_label(list,size,cmp_op,a,loc.register,l);
  1000. LOC_REFERENCE,LOC_CREFERENCE:
  1001. a_cmp_const_ref_label(list,size,cmp_op,a,loc.reference,l);
  1002. else
  1003. internalerror(200109061);
  1004. end;
  1005. end;
  1006. procedure tcg.a_cmp_ref_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; const ref: treference; reg : tregister; l : tasmlabel);
  1007. var
  1008. tmpreg: tregister;
  1009. begin
  1010. tmpreg:=getintregister(list,size);
  1011. a_load_ref_reg(list,size,size,ref,tmpreg);
  1012. a_cmp_reg_reg_label(list,size,cmp_op,tmpreg,reg,l);
  1013. end;
  1014. procedure tcg.a_cmp_reg_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; reg : tregister; const ref: treference; l : tasmlabel);
  1015. var
  1016. tmpreg: tregister;
  1017. begin
  1018. tmpreg:=getintregister(list,size);
  1019. a_load_ref_reg(list,size,size,ref,tmpreg);
  1020. a_cmp_reg_reg_label(list,size,cmp_op,reg,tmpreg,l);
  1021. end;
  1022. procedure tcg.a_cmp_loc_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; const loc: tlocation; reg : tregister; l : tasmlabel);
  1023. begin
  1024. case loc.loc of
  1025. LOC_REGISTER,
  1026. LOC_CREGISTER:
  1027. a_cmp_reg_reg_label(list,size,cmp_op,loc.register,reg,l);
  1028. LOC_REFERENCE,
  1029. LOC_CREFERENCE :
  1030. a_cmp_ref_reg_label(list,size,cmp_op,loc.reference,reg,l);
  1031. LOC_CONSTANT:
  1032. a_cmp_const_reg_label(list,size,cmp_op,loc.value,reg,l);
  1033. else
  1034. internalerror(200203231);
  1035. end;
  1036. end;
  1037. procedure tcg.a_cmp_ref_loc_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;const ref: treference;const loc : tlocation;
  1038. l : tasmlabel);
  1039. var
  1040. tmpreg: tregister;
  1041. begin
  1042. case loc.loc of
  1043. LOC_REGISTER,LOC_CREGISTER:
  1044. a_cmp_ref_reg_label(list,size,cmp_op,ref,loc.register,l);
  1045. LOC_REFERENCE,LOC_CREFERENCE:
  1046. begin
  1047. tmpreg:=getintregister(list,size);
  1048. a_load_ref_reg(list,size,size,loc.reference,tmpreg);
  1049. a_cmp_ref_reg_label(list,size,cmp_op,ref,tmpreg,l);
  1050. end
  1051. else
  1052. internalerror(200109061);
  1053. end;
  1054. end;
  1055. procedure tcg.a_loadmm_loc_reg(list: taasmoutput; size: tcgsize; const loc: tlocation; const reg: tregister;shuffle : pmmshuffle);
  1056. begin
  1057. case loc.loc of
  1058. LOC_MMREGISTER,LOC_CMMREGISTER:
  1059. a_loadmm_reg_reg(list,loc.size,size,loc.register,reg,shuffle);
  1060. LOC_REFERENCE,LOC_CREFERENCE:
  1061. a_loadmm_ref_reg(list,loc.size,size,loc.reference,reg,shuffle);
  1062. else
  1063. internalerror(200310121);
  1064. end;
  1065. end;
  1066. procedure tcg.a_loadmm_reg_loc(list: taasmoutput; size: tcgsize; const reg: tregister; const loc: tlocation;shuffle : pmmshuffle);
  1067. begin
  1068. case loc.loc of
  1069. LOC_MMREGISTER,LOC_CMMREGISTER:
  1070. a_loadmm_reg_reg(list,size,loc.size,reg,loc.register,shuffle);
  1071. LOC_REFERENCE,LOC_CREFERENCE:
  1072. a_loadmm_reg_ref(list,size,loc.size,reg,loc.reference,shuffle);
  1073. else
  1074. internalerror(200310122);
  1075. end;
  1076. end;
  1077. procedure tcg.a_parammm_reg(list: taasmoutput; size: tcgsize; reg: tregister;const cgpara : TCGPara;shuffle : pmmshuffle);
  1078. var
  1079. href : treference;
  1080. begin
  1081. cgpara.check_simple_location;
  1082. case cgpara.location^.loc of
  1083. LOC_MMREGISTER,LOC_CMMREGISTER:
  1084. a_loadmm_reg_reg(list,size,cgpara.location^.size,reg,cgpara.location^.register,shuffle);
  1085. LOC_REFERENCE,LOC_CREFERENCE:
  1086. begin
  1087. reference_reset_base(href,cgpara.location^.reference.index,cgpara.location^.reference.offset);
  1088. a_loadmm_reg_ref(list,size,cgpara.location^.size,reg,href,shuffle);
  1089. end
  1090. else
  1091. internalerror(200310123);
  1092. end;
  1093. end;
  1094. procedure tcg.a_parammm_ref(list: taasmoutput; size: tcgsize;const ref: treference;const cgpara : TCGPara;shuffle : pmmshuffle);
  1095. var
  1096. hr : tregister;
  1097. hs : tmmshuffle;
  1098. begin
  1099. cgpara.check_simple_location;
  1100. hr:=getmmregister(list,cgpara.location^.size);
  1101. a_loadmm_ref_reg(list,size,cgpara.location^.size,ref,hr,shuffle);
  1102. if realshuffle(shuffle) then
  1103. begin
  1104. hs:=shuffle^;
  1105. removeshuffles(hs);
  1106. a_parammm_reg(list,cgpara.location^.size,hr,cgpara,@hs);
  1107. end
  1108. else
  1109. a_parammm_reg(list,cgpara.location^.size,hr,cgpara,shuffle);
  1110. end;
  1111. procedure tcg.a_parammm_loc(list: taasmoutput;const loc: tlocation; const cgpara : TCGPara;shuffle : pmmshuffle);
  1112. begin
  1113. case loc.loc of
  1114. LOC_MMREGISTER,LOC_CMMREGISTER:
  1115. a_parammm_reg(list,loc.size,loc.register,cgpara,shuffle);
  1116. LOC_REFERENCE,LOC_CREFERENCE:
  1117. a_parammm_ref(list,loc.size,loc.reference,cgpara,shuffle);
  1118. else
  1119. internalerror(200310123);
  1120. end;
  1121. end;
  1122. procedure tcg.a_opmm_ref_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;const ref: treference; reg: tregister;shuffle : pmmshuffle);
  1123. var
  1124. hr : tregister;
  1125. hs : tmmshuffle;
  1126. begin
  1127. hr:=getmmregister(list,size);
  1128. a_loadmm_ref_reg(list,size,size,ref,hr,shuffle);
  1129. if realshuffle(shuffle) then
  1130. begin
  1131. hs:=shuffle^;
  1132. removeshuffles(hs);
  1133. a_opmm_reg_reg(list,op,size,hr,reg,@hs);
  1134. end
  1135. else
  1136. a_opmm_reg_reg(list,op,size,hr,reg,shuffle);
  1137. end;
  1138. procedure tcg.a_opmm_reg_ref(list: taasmoutput; Op: TOpCG; size : tcgsize;reg: tregister; const ref: treference; shuffle : pmmshuffle);
  1139. var
  1140. hr : tregister;
  1141. hs : tmmshuffle;
  1142. begin
  1143. hr:=getmmregister(list,size);
  1144. a_loadmm_ref_reg(list,size,size,ref,hr,shuffle);
  1145. if realshuffle(shuffle) then
  1146. begin
  1147. hs:=shuffle^;
  1148. removeshuffles(hs);
  1149. a_opmm_reg_reg(list,op,size,reg,hr,@hs);
  1150. a_loadmm_reg_ref(list,size,size,hr,ref,@hs);
  1151. end
  1152. else
  1153. begin
  1154. a_opmm_reg_reg(list,op,size,reg,hr,shuffle);
  1155. a_loadmm_reg_ref(list,size,size,hr,ref,shuffle);
  1156. end;
  1157. end;
  1158. procedure tcg.a_opmm_loc_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;const loc: tlocation; reg: tregister;shuffle : pmmshuffle);
  1159. begin
  1160. case loc.loc of
  1161. LOC_CMMREGISTER,LOC_MMREGISTER:
  1162. a_opmm_reg_reg(list,op,size,loc.register,reg,shuffle);
  1163. LOC_CREFERENCE,LOC_REFERENCE:
  1164. a_opmm_ref_reg(list,op,size,loc.reference,reg,shuffle);
  1165. else
  1166. internalerror(200312232);
  1167. end;
  1168. end;
  1169. procedure tcg.g_concatcopy_unaligned(list : taasmoutput;const source,dest : treference;len : aint);
  1170. begin
  1171. g_concatcopy(list,source,dest,len);
  1172. end;
  1173. procedure tcg.g_copyshortstring(list : taasmoutput;const source,dest : treference;len:byte);
  1174. var
  1175. cgpara1,cgpara2,cgpara3 : TCGPara;
  1176. begin
  1177. cgpara1.init;
  1178. cgpara2.init;
  1179. cgpara3.init;
  1180. paramanager.getintparaloc(pocall_default,1,cgpara1);
  1181. paramanager.getintparaloc(pocall_default,2,cgpara2);
  1182. paramanager.getintparaloc(pocall_default,3,cgpara3);
  1183. paramanager.allocparaloc(list,cgpara3);
  1184. a_paramaddr_ref(list,dest,cgpara3);
  1185. paramanager.allocparaloc(list,cgpara2);
  1186. a_paramaddr_ref(list,source,cgpara2);
  1187. paramanager.allocparaloc(list,cgpara1);
  1188. a_param_const(list,OS_INT,len,cgpara1);
  1189. paramanager.freeparaloc(list,cgpara3);
  1190. paramanager.freeparaloc(list,cgpara2);
  1191. paramanager.freeparaloc(list,cgpara1);
  1192. allocallcpuregisters(list);
  1193. a_call_name(list,'FPC_SHORTSTR_ASSIGN');
  1194. deallocallcpuregisters(list);
  1195. cgpara3.done;
  1196. cgpara2.done;
  1197. cgpara1.done;
  1198. end;
  1199. procedure tcg.g_incrrefcount(list : taasmoutput;t: tdef; const ref: treference);
  1200. var
  1201. href : treference;
  1202. incrfunc : string;
  1203. cgpara1,cgpara2 : TCGPara;
  1204. begin
  1205. cgpara1.init;
  1206. cgpara2.init;
  1207. paramanager.getintparaloc(pocall_default,1,cgpara1);
  1208. paramanager.getintparaloc(pocall_default,2,cgpara2);
  1209. if is_interfacecom(t) then
  1210. incrfunc:='FPC_INTF_INCR_REF'
  1211. else if is_ansistring(t) then
  1212. incrfunc:='FPC_ANSISTR_INCR_REF'
  1213. else if is_widestring(t) then
  1214. incrfunc:='FPC_WIDESTR_INCR_REF'
  1215. else if is_dynamic_array(t) then
  1216. incrfunc:='FPC_DYNARRAY_INCR_REF'
  1217. else
  1218. incrfunc:='';
  1219. { call the special incr function or the generic addref }
  1220. if incrfunc<>'' then
  1221. begin
  1222. paramanager.allocparaloc(list,cgpara1);
  1223. { these functions get the pointer by value }
  1224. a_param_ref(list,OS_ADDR,ref,cgpara1);
  1225. paramanager.freeparaloc(list,cgpara1);
  1226. allocallcpuregisters(list);
  1227. a_call_name(list,incrfunc);
  1228. deallocallcpuregisters(list);
  1229. end
  1230. else
  1231. begin
  1232. reference_reset_symbol(href,tstoreddef(t).get_rtti_label(initrtti),0);
  1233. paramanager.allocparaloc(list,cgpara2);
  1234. a_paramaddr_ref(list,href,cgpara2);
  1235. paramanager.allocparaloc(list,cgpara1);
  1236. a_paramaddr_ref(list,ref,cgpara1);
  1237. paramanager.freeparaloc(list,cgpara1);
  1238. paramanager.freeparaloc(list,cgpara2);
  1239. allocallcpuregisters(list);
  1240. a_call_name(list,'FPC_ADDREF');
  1241. deallocallcpuregisters(list);
  1242. end;
  1243. cgpara2.done;
  1244. cgpara1.done;
  1245. end;
  1246. procedure tcg.g_decrrefcount(list : taasmoutput;t: tdef; const ref: treference);
  1247. var
  1248. href : treference;
  1249. decrfunc : string;
  1250. needrtti : boolean;
  1251. cgpara1,cgpara2 : TCGPara;
  1252. tempreg1,tempreg2 : TRegister;
  1253. begin
  1254. cgpara1.init;
  1255. cgpara2.init;
  1256. paramanager.getintparaloc(pocall_default,1,cgpara1);
  1257. paramanager.getintparaloc(pocall_default,2,cgpara2);
  1258. needrtti:=false;
  1259. if is_interfacecom(t) then
  1260. decrfunc:='FPC_INTF_DECR_REF'
  1261. else if is_ansistring(t) then
  1262. decrfunc:='FPC_ANSISTR_DECR_REF'
  1263. else if is_widestring(t) then
  1264. decrfunc:='FPC_WIDESTR_DECR_REF'
  1265. else if is_dynamic_array(t) then
  1266. begin
  1267. decrfunc:='FPC_DYNARRAY_DECR_REF';
  1268. needrtti:=true;
  1269. end
  1270. else
  1271. decrfunc:='';
  1272. { call the special decr function or the generic decref }
  1273. if decrfunc<>'' then
  1274. begin
  1275. if needrtti then
  1276. begin
  1277. reference_reset_symbol(href,tstoreddef(t).get_rtti_label(initrtti),0);
  1278. tempreg2:=getaddressregister(list);
  1279. a_loadaddr_ref_reg(list,href,tempreg2);
  1280. end;
  1281. tempreg1:=getaddressregister(list);
  1282. a_loadaddr_ref_reg(list,ref,tempreg1);
  1283. if needrtti then
  1284. begin
  1285. paramanager.allocparaloc(list,cgpara2);
  1286. a_param_reg(list,OS_ADDR,tempreg2,cgpara2);
  1287. paramanager.freeparaloc(list,cgpara2);
  1288. end;
  1289. paramanager.allocparaloc(list,cgpara1);
  1290. a_param_reg(list,OS_ADDR,tempreg1,cgpara1);
  1291. paramanager.freeparaloc(list,cgpara1);
  1292. allocallcpuregisters(list);
  1293. a_call_name(list,decrfunc);
  1294. deallocallcpuregisters(list);
  1295. end
  1296. else
  1297. begin
  1298. reference_reset_symbol(href,tstoreddef(t).get_rtti_label(initrtti),0);
  1299. paramanager.allocparaloc(list,cgpara2);
  1300. a_paramaddr_ref(list,href,cgpara2);
  1301. paramanager.allocparaloc(list,cgpara1);
  1302. a_paramaddr_ref(list,ref,cgpara1);
  1303. paramanager.freeparaloc(list,cgpara1);
  1304. paramanager.freeparaloc(list,cgpara2);
  1305. allocallcpuregisters(list);
  1306. a_call_name(list,'FPC_DECREF');
  1307. deallocallcpuregisters(list);
  1308. end;
  1309. cgpara2.done;
  1310. cgpara1.done;
  1311. end;
  1312. procedure tcg.g_initialize(list : taasmoutput;t : tdef;const ref : treference);
  1313. var
  1314. href : treference;
  1315. cgpara1,cgpara2 : TCGPara;
  1316. begin
  1317. cgpara1.init;
  1318. cgpara2.init;
  1319. paramanager.getintparaloc(pocall_default,1,cgpara1);
  1320. paramanager.getintparaloc(pocall_default,2,cgpara2);
  1321. if is_ansistring(t) or
  1322. is_widestring(t) or
  1323. is_interfacecom(t) or
  1324. is_dynamic_array(t) then
  1325. a_load_const_ref(list,OS_ADDR,0,ref)
  1326. else
  1327. begin
  1328. reference_reset_symbol(href,tstoreddef(t).get_rtti_label(initrtti),0);
  1329. paramanager.allocparaloc(list,cgpara2);
  1330. a_paramaddr_ref(list,href,cgpara2);
  1331. paramanager.allocparaloc(list,cgpara1);
  1332. a_paramaddr_ref(list,ref,cgpara1);
  1333. paramanager.freeparaloc(list,cgpara1);
  1334. paramanager.freeparaloc(list,cgpara2);
  1335. allocallcpuregisters(list);
  1336. a_call_name(list,'FPC_INITIALIZE');
  1337. deallocallcpuregisters(list);
  1338. end;
  1339. cgpara1.done;
  1340. cgpara2.done;
  1341. end;
  1342. procedure tcg.g_finalize(list : taasmoutput;t : tdef;const ref : treference);
  1343. var
  1344. href : treference;
  1345. cgpara1,cgpara2 : TCGPara;
  1346. begin
  1347. cgpara1.init;
  1348. cgpara2.init;
  1349. paramanager.getintparaloc(pocall_default,1,cgpara1);
  1350. paramanager.getintparaloc(pocall_default,2,cgpara2);
  1351. if is_ansistring(t) or
  1352. is_widestring(t) or
  1353. is_interfacecom(t) then
  1354. begin
  1355. g_decrrefcount(list,t,ref);
  1356. a_load_const_ref(list,OS_ADDR,0,ref);
  1357. end
  1358. else
  1359. begin
  1360. reference_reset_symbol(href,tstoreddef(t).get_rtti_label(initrtti),0);
  1361. paramanager.allocparaloc(list,cgpara2);
  1362. a_paramaddr_ref(list,href,cgpara2);
  1363. paramanager.allocparaloc(list,cgpara1);
  1364. a_paramaddr_ref(list,ref,cgpara1);
  1365. paramanager.freeparaloc(list,cgpara1);
  1366. paramanager.freeparaloc(list,cgpara2);
  1367. allocallcpuregisters(list);
  1368. a_call_name(list,'FPC_FINALIZE');
  1369. deallocallcpuregisters(list);
  1370. end;
  1371. cgpara1.done;
  1372. cgpara2.done;
  1373. end;
  1374. procedure tcg.g_rangecheck(list: taasmoutput; const l:tlocation;fromdef,todef: tdef);
  1375. { generate range checking code for the value at location p. The type }
  1376. { type used is checked against todefs ranges. fromdef (p.resulttype.def) }
  1377. { is the original type used at that location. When both defs are equal }
  1378. { the check is also insert (needed for succ,pref,inc,dec) }
  1379. const
  1380. aintmax=high(aint);
  1381. var
  1382. neglabel : tasmlabel;
  1383. hreg : tregister;
  1384. lto,hto,
  1385. lfrom,hfrom : TConstExprInt;
  1386. from_signed: boolean;
  1387. begin
  1388. { range checking on and range checkable value? }
  1389. if not(cs_check_range in aktlocalswitches) or
  1390. not(fromdef.deftype in [orddef,enumdef,arraydef]) then
  1391. exit;
  1392. {$ifndef cpu64bit}
  1393. { handle 64bit rangechecks separate for 32bit processors }
  1394. if is_64bit(fromdef) or is_64bit(todef) then
  1395. begin
  1396. cg64.g_rangecheck64(list,l,fromdef,todef);
  1397. exit;
  1398. end;
  1399. {$endif cpu64bit}
  1400. { only check when assigning to scalar, subranges are different, }
  1401. { when todef=fromdef then the check is always generated }
  1402. getrange(fromdef,lfrom,hfrom);
  1403. getrange(todef,lto,hto);
  1404. from_signed := is_signed(fromdef);
  1405. { no range check if from and to are equal and are both longint/dword }
  1406. { (if we have a 32bit processor) or int64/qword, since such }
  1407. { operations can at most cause overflows (JM) }
  1408. { Note that these checks are mostly processor independent, they only }
  1409. { have to be changed once we introduce 64bit subrange types }
  1410. {$ifdef cpu64bit}
  1411. if (fromdef = todef) and
  1412. (fromdef.deftype=orddef) and
  1413. (((((torddef(fromdef).typ = s64bit) and
  1414. (lfrom = low(int64)) and
  1415. (hfrom = high(int64))) or
  1416. ((torddef(fromdef).typ = u64bit) and
  1417. (lfrom = low(qword)) and
  1418. (hfrom = high(qword)))))) then
  1419. exit;
  1420. {$else cpu64bit}
  1421. if (fromdef = todef) and
  1422. (fromdef.deftype=orddef) and
  1423. (((((torddef(fromdef).typ = s32bit) and
  1424. (lfrom = low(longint)) and
  1425. (hfrom = high(longint))) or
  1426. ((torddef(fromdef).typ = u32bit) and
  1427. (lfrom = low(cardinal)) and
  1428. (hfrom = high(cardinal)))))) then
  1429. exit;
  1430. {$endif cpu64bit}
  1431. { if the from-range falls completely in the to-range, no check }
  1432. { is necessary. Don't do this conversion for the largest unsigned type }
  1433. if (todef<>fromdef) and
  1434. (from_signed or (hfrom>=0)) and
  1435. (lto<=lfrom) and (hto>=hfrom) then
  1436. exit;
  1437. { generate the rangecheck code for the def where we are going to }
  1438. { store the result }
  1439. { use the trick that }
  1440. { a <= x <= b <=> 0 <= x-a <= b-a <=> unsigned(x-a) <= unsigned(b-a) }
  1441. { To be able to do that, we have to make sure however that either }
  1442. { fromdef and todef are both signed or unsigned, or that we leave }
  1443. { the parts < 0 and > maxlongint out }
  1444. { is_signed now also works for arrays (it checks the rangetype) (JM) }
  1445. if from_signed xor is_signed(todef) then
  1446. begin
  1447. if from_signed then
  1448. { from is signed, to is unsigned }
  1449. begin
  1450. { if high(from) < 0 -> always range error }
  1451. if (hfrom < 0) or
  1452. { if low(to) > maxlongint also range error }
  1453. (lto > aintmax) then
  1454. begin
  1455. a_call_name(list,'FPC_RANGEERROR');
  1456. exit
  1457. end;
  1458. { from is signed and to is unsigned -> when looking at to }
  1459. { as an signed value, it must be < maxaint (otherwise }
  1460. { it will become negative, which is invalid since "to" is unsigned) }
  1461. if hto > aintmax then
  1462. hto := aintmax;
  1463. end
  1464. else
  1465. { from is unsigned, to is signed }
  1466. begin
  1467. if (lfrom > aintmax) or
  1468. (hto < 0) then
  1469. begin
  1470. a_call_name(list,'FPC_RANGEERROR');
  1471. exit
  1472. end;
  1473. { from is unsigned and to is signed -> when looking at to }
  1474. { as an unsigned value, it must be >= 0 (since negative }
  1475. { values are the same as values > maxlongint) }
  1476. if lto < 0 then
  1477. lto := 0;
  1478. end;
  1479. end;
  1480. hreg:=getintregister(list,OS_INT);
  1481. a_load_loc_reg(list,OS_INT,l,hreg);
  1482. a_op_const_reg(list,OP_SUB,OS_INT,aint(lto),hreg);
  1483. objectlibrary.getjumplabel(neglabel);
  1484. {
  1485. if from_signed then
  1486. a_cmp_const_reg_label(list,OS_INT,OC_GTE,aint(hto-lto),hreg,neglabel)
  1487. else
  1488. }
  1489. {$ifdef cpu64bit}
  1490. if qword(hto-lto)>qword(aintmax) then
  1491. a_cmp_const_reg_label(list,OS_INT,OC_BE,aintmax,hreg,neglabel)
  1492. else
  1493. {$endif cpu64bit}
  1494. a_cmp_const_reg_label(list,OS_INT,OC_BE,aint(hto-lto),hreg,neglabel);
  1495. a_call_name(list,'FPC_RANGEERROR');
  1496. a_label(list,neglabel);
  1497. end;
  1498. procedure tcg.g_overflowCheck_loc(List:TAasmOutput;const Loc:TLocation;def:TDef;ovloc : tlocation);
  1499. begin
  1500. g_overflowCheck(list,loc,def);
  1501. end;
  1502. procedure tcg.g_flags2ref(list: taasmoutput; size: TCgSize; const f: tresflags; const ref:TReference);
  1503. var
  1504. tmpreg : tregister;
  1505. begin
  1506. tmpreg:=getintregister(list,size);
  1507. g_flags2reg(list,size,f,tmpreg);
  1508. a_load_reg_ref(list,size,size,tmpreg,ref);
  1509. end;
  1510. procedure tcg.g_maybe_testself(list : taasmoutput;reg:tregister);
  1511. var
  1512. OKLabel : tasmlabel;
  1513. cgpara1 : TCGPara;
  1514. begin
  1515. if (cs_check_object in aktlocalswitches) or
  1516. (cs_check_range in aktlocalswitches) then
  1517. begin
  1518. objectlibrary.getjumplabel(oklabel);
  1519. a_cmp_const_reg_label(list,OS_ADDR,OC_NE,0,reg,oklabel);
  1520. cgpara1.init;
  1521. paramanager.getintparaloc(pocall_default,1,cgpara1);
  1522. paramanager.allocparaloc(list,cgpara1);
  1523. a_param_const(list,OS_INT,210,cgpara1);
  1524. paramanager.freeparaloc(list,cgpara1);
  1525. a_call_name(list,'FPC_HANDLEERROR');
  1526. a_label(list,oklabel);
  1527. cgpara1.done;
  1528. end;
  1529. end;
  1530. procedure tcg.g_maybe_testvmt(list : taasmoutput;reg:tregister;objdef:tobjectdef);
  1531. var
  1532. hrefvmt : treference;
  1533. cgpara1,cgpara2 : TCGPara;
  1534. begin
  1535. cgpara1.init;
  1536. cgpara2.init;
  1537. paramanager.getintparaloc(pocall_default,1,cgpara1);
  1538. paramanager.getintparaloc(pocall_default,2,cgpara2);
  1539. if (cs_check_object in aktlocalswitches) then
  1540. begin
  1541. reference_reset_symbol(hrefvmt,objectlibrary.newasmsymbol(objdef.vmt_mangledname,AB_EXTERNAL,AT_DATA),0);
  1542. paramanager.allocparaloc(list,cgpara2);
  1543. a_paramaddr_ref(list,hrefvmt,cgpara2);
  1544. paramanager.allocparaloc(list,cgpara1);
  1545. a_param_reg(list,OS_ADDR,reg,cgpara1);
  1546. paramanager.freeparaloc(list,cgpara1);
  1547. paramanager.freeparaloc(list,cgpara2);
  1548. allocallcpuregisters(list);
  1549. a_call_name(list,'FPC_CHECK_OBJECT_EXT');
  1550. deallocallcpuregisters(list);
  1551. end
  1552. else
  1553. if (cs_check_range in aktlocalswitches) then
  1554. begin
  1555. paramanager.allocparaloc(list,cgpara1);
  1556. a_param_reg(list,OS_ADDR,reg,cgpara1);
  1557. paramanager.freeparaloc(list,cgpara1);
  1558. allocallcpuregisters(list);
  1559. a_call_name(list,'FPC_CHECK_OBJECT');
  1560. deallocallcpuregisters(list);
  1561. end;
  1562. cgpara1.done;
  1563. cgpara2.done;
  1564. end;
  1565. {*****************************************************************************
  1566. Entry/Exit Code Functions
  1567. *****************************************************************************}
  1568. procedure tcg.g_copyvaluepara_openarray(list : taasmoutput;const ref:treference;const lenloc:tlocation;elesize:aint;destreg:tregister);
  1569. var
  1570. sizereg,sourcereg,lenreg : tregister;
  1571. cgpara1,cgpara2,cgpara3 : TCGPara;
  1572. begin
  1573. { because some abis don't support dynamic stack allocation properly
  1574. open array value parameters are copied onto the heap
  1575. }
  1576. { calculate necessary memory }
  1577. { read/write operations on one register make the life of the register allocator hard }
  1578. if not(lenloc.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  1579. begin
  1580. lenreg:=getintregister(list,OS_INT);
  1581. a_load_loc_reg(list,OS_INT,lenloc,lenreg);
  1582. end
  1583. else
  1584. lenreg:=lenloc.register;
  1585. sizereg:=getintregister(list,OS_INT);
  1586. a_op_const_reg_reg(list,OP_ADD,OS_INT,1,lenreg,sizereg);
  1587. a_op_const_reg(list,OP_IMUL,OS_INT,elesize,sizereg);
  1588. { load source }
  1589. sourcereg:=getaddressregister(list);
  1590. a_loadaddr_ref_reg(list,ref,sourcereg);
  1591. { do getmem call }
  1592. cgpara1.init;
  1593. paramanager.getintparaloc(pocall_default,1,cgpara1);
  1594. paramanager.allocparaloc(list,cgpara1);
  1595. a_param_reg(list,OS_INT,sizereg,cgpara1);
  1596. paramanager.freeparaloc(list,cgpara1);
  1597. allocallcpuregisters(list);
  1598. a_call_name(list,'FPC_GETMEM');
  1599. deallocallcpuregisters(list);
  1600. cgpara1.done;
  1601. { return the new address }
  1602. a_load_reg_reg(list,OS_ADDR,OS_ADDR,NR_FUNCTION_RESULT_REG,destreg);
  1603. { do move call }
  1604. cgpara1.init;
  1605. cgpara2.init;
  1606. cgpara3.init;
  1607. paramanager.getintparaloc(pocall_default,1,cgpara1);
  1608. paramanager.getintparaloc(pocall_default,2,cgpara2);
  1609. paramanager.getintparaloc(pocall_default,3,cgpara3);
  1610. { load size }
  1611. paramanager.allocparaloc(list,cgpara3);
  1612. a_param_reg(list,OS_INT,sizereg,cgpara3);
  1613. { load destination }
  1614. paramanager.allocparaloc(list,cgpara2);
  1615. a_param_reg(list,OS_ADDR,destreg,cgpara2);
  1616. { load source }
  1617. paramanager.allocparaloc(list,cgpara1);
  1618. a_param_reg(list,OS_ADDR,sourcereg,cgpara1);
  1619. paramanager.freeparaloc(list,cgpara3);
  1620. paramanager.freeparaloc(list,cgpara2);
  1621. paramanager.freeparaloc(list,cgpara1);
  1622. allocallcpuregisters(list);
  1623. a_call_name(list,'FPC_MOVE');
  1624. deallocallcpuregisters(list);
  1625. cgpara3.done;
  1626. cgpara2.done;
  1627. cgpara1.done;
  1628. end;
  1629. procedure tcg.g_releasevaluepara_openarray(list : taasmoutput;const l:tlocation);
  1630. var
  1631. cgpara1 : TCGPara;
  1632. begin
  1633. { do move call }
  1634. cgpara1.init;
  1635. paramanager.getintparaloc(pocall_default,1,cgpara1);
  1636. { load source }
  1637. paramanager.allocparaloc(list,cgpara1);
  1638. a_param_loc(list,l,cgpara1);
  1639. paramanager.freeparaloc(list,cgpara1);
  1640. allocallcpuregisters(list);
  1641. a_call_name(list,'FPC_FREEMEM');
  1642. deallocallcpuregisters(list);
  1643. cgpara1.done;
  1644. end;
  1645. procedure tcg.g_save_standard_registers(list:Taasmoutput);
  1646. var
  1647. href : treference;
  1648. size : longint;
  1649. r : integer;
  1650. begin
  1651. { Get temp }
  1652. size:=0;
  1653. for r:=low(saved_standard_registers) to high(saved_standard_registers) do
  1654. if saved_standard_registers[r] in rg[R_INTREGISTER].used_in_proc then
  1655. inc(size,sizeof(aint));
  1656. if size>0 then
  1657. begin
  1658. tg.GetTemp(list,size,tt_noreuse,current_procinfo.save_regs_ref);
  1659. { Copy registers to temp }
  1660. href:=current_procinfo.save_regs_ref;
  1661. for r:=low(saved_standard_registers) to high(saved_standard_registers) do
  1662. begin
  1663. if saved_standard_registers[r] in rg[R_INTREGISTER].used_in_proc then
  1664. begin
  1665. a_load_reg_ref(list,OS_ADDR,OS_ADDR,newreg(R_INTREGISTER,saved_standard_registers[r],R_SUBWHOLE),href);
  1666. inc(href.offset,sizeof(aint));
  1667. end;
  1668. include(rg[R_INTREGISTER].preserved_by_proc,saved_standard_registers[r]);
  1669. end;
  1670. end;
  1671. end;
  1672. procedure tcg.g_restore_standard_registers(list:Taasmoutput);
  1673. var
  1674. href : treference;
  1675. r : integer;
  1676. hreg : tregister;
  1677. begin
  1678. { Copy registers from temp }
  1679. href:=current_procinfo.save_regs_ref;
  1680. for r:=low(saved_standard_registers) to high(saved_standard_registers) do
  1681. if saved_standard_registers[r] in rg[R_INTREGISTER].used_in_proc then
  1682. begin
  1683. hreg:=newreg(R_INTREGISTER,saved_standard_registers[r],R_SUBWHOLE);
  1684. { Allocate register so the optimizer does remove the load }
  1685. a_reg_alloc(list,hreg);
  1686. a_load_ref_reg(list,OS_ADDR,OS_ADDR,href,hreg);
  1687. inc(href.offset,sizeof(aint));
  1688. end;
  1689. tg.UnGetTemp(list,current_procinfo.save_regs_ref);
  1690. end;
  1691. procedure tcg.g_profilecode(list : taasmoutput);
  1692. begin
  1693. end;
  1694. procedure tcg.g_exception_reason_save(list : taasmoutput; const href : treference);
  1695. begin
  1696. a_load_reg_ref(list, OS_INT, OS_INT, NR_FUNCTION_RESULT_REG, href);
  1697. end;
  1698. procedure tcg.g_exception_reason_save_const(list : taasmoutput; const href : treference; a: aint);
  1699. begin
  1700. a_load_const_ref(list, OS_INT, a, href);
  1701. end;
  1702. procedure tcg.g_exception_reason_load(list : taasmoutput; const href : treference);
  1703. begin
  1704. a_load_ref_reg(list, OS_INT, OS_INT, href, NR_FUNCTION_RESULT_REG);
  1705. end;
  1706. procedure tcg.g_adjust_self_value(list:taasmoutput;procdef: tprocdef;ioffset: aint);
  1707. var
  1708. hsym : tsym;
  1709. href : treference;
  1710. paraloc : tcgparalocation;
  1711. begin
  1712. { calculate the parameter info for the procdef }
  1713. if not procdef.has_paraloc_info then
  1714. begin
  1715. procdef.requiredargarea:=paramanager.create_paraloc_info(procdef,callerside);
  1716. procdef.has_paraloc_info:=true;
  1717. end;
  1718. hsym:=tsym(procdef.parast.search('self'));
  1719. if not(assigned(hsym) and
  1720. (hsym.typ=paravarsym)) then
  1721. internalerror(200305251);
  1722. paraloc:=tparavarsym(hsym).paraloc[callerside].location^;
  1723. case paraloc.loc of
  1724. LOC_REGISTER:
  1725. cg.a_op_const_reg(list,OP_SUB,paraloc.size,ioffset,paraloc.register);
  1726. LOC_REFERENCE:
  1727. begin
  1728. { offset in the wrapper needs to be adjusted for the stored
  1729. return address }
  1730. reference_reset_base(href,paraloc.reference.index,paraloc.reference.offset+sizeof(aint));
  1731. cg.a_op_const_ref(list,OP_SUB,paraloc.size,ioffset,href);
  1732. end
  1733. else
  1734. internalerror(200309189);
  1735. end;
  1736. end;
  1737. {*****************************************************************************
  1738. TCG64
  1739. *****************************************************************************}
  1740. {$ifndef cpu64bit}
  1741. procedure tcg64.a_op64_const_reg_reg(list: taasmoutput;op:TOpCG;size : tcgsize;value : int64; regsrc,regdst : tregister64);
  1742. begin
  1743. a_load64_reg_reg(list,regsrc,regdst);
  1744. a_op64_const_reg(list,op,size,value,regdst);
  1745. end;
  1746. procedure tcg64.a_op64_reg_reg_reg(list: taasmoutput;op:TOpCG;size : tcgsize;regsrc1,regsrc2,regdst : tregister64);
  1747. var
  1748. tmpreg64 : tregister64;
  1749. begin
  1750. { when src1=dst then we need to first create a temp to prevent
  1751. overwriting src1 with src2 }
  1752. if (regsrc1.reghi=regdst.reghi) or
  1753. (regsrc1.reglo=regdst.reghi) or
  1754. (regsrc1.reghi=regdst.reglo) or
  1755. (regsrc1.reglo=regdst.reglo) then
  1756. begin
  1757. tmpreg64.reglo:=cg.getintregister(list,OS_32);
  1758. tmpreg64.reghi:=cg.getintregister(list,OS_32);
  1759. a_load64_reg_reg(list,regsrc2,tmpreg64);
  1760. a_op64_reg_reg(list,op,size,regsrc1,tmpreg64);
  1761. a_load64_reg_reg(list,tmpreg64,regdst);
  1762. end
  1763. else
  1764. begin
  1765. a_load64_reg_reg(list,regsrc2,regdst);
  1766. a_op64_reg_reg(list,op,size,regsrc1,regdst);
  1767. end;
  1768. end;
  1769. procedure tcg64.a_op64_const_reg_reg_checkoverflow(list: taasmoutput;op:TOpCG;size : tcgsize;value : int64;regsrc,regdst : tregister64;setflags : boolean;var ovloc : tlocation);
  1770. begin
  1771. a_op64_const_reg_reg(list,op,size,value,regsrc,regdst);
  1772. ovloc.loc:=LOC_VOID;
  1773. end;
  1774. procedure tcg64.a_op64_reg_reg_reg_checkoverflow(list: taasmoutput;op:TOpCG;size : tcgsize;regsrc1,regsrc2,regdst : tregister64;setflags : boolean;var ovloc : tlocation);
  1775. begin
  1776. a_op64_reg_reg_reg(list,op,size,regsrc1,regsrc2,regdst);
  1777. ovloc.loc:=LOC_VOID;
  1778. end;
  1779. {$endif cpu64bit}
  1780. initialization
  1781. ;
  1782. finalization
  1783. cg.free;
  1784. {$ifndef cpu64bit}
  1785. cg64.free;
  1786. {$endif cpu64bit}
  1787. end.