cgobj.pas 83 KB

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