cgobj.pas 86 KB

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