hlcgobj.pas 83 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872
  1. {
  2. Copyright (c) 1998-2010 by Florian Klaempfl and Jonas Maebe
  3. Member of the Free Pascal development team
  4. This unit implements the basic high level 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. Abstract high level code generator unit. This contains the base class
  20. that either lowers most code to the regular code generator, or that
  21. has to be implemented/overridden for higher level targets (such as LLVM).
  22. }
  23. unit hlcgobj;
  24. {$i fpcdefs.inc}
  25. { define hlcginline}
  26. interface
  27. uses
  28. cclasses,globtype,constexp,
  29. cpubase,cgbase,cgutils,parabase,
  30. aasmbase,aasmtai,aasmdata,aasmcpu,
  31. symconst,symtype,symdef,rgobj,
  32. node
  33. ;
  34. type
  35. {# @abstract(Abstract high level code generator)
  36. This class implements an abstract instruction generator. All
  37. methods of this class are generic and are mapped to low level code
  38. generator methods by default. They have to be overridden for higher
  39. level targets
  40. }
  41. { thlcgobj }
  42. thlcgobj = class
  43. public
  44. {************************************************}
  45. { basic routines }
  46. constructor create;
  47. {# Initialize the register allocators needed for the codegenerator.}
  48. procedure init_register_allocators;virtual;
  49. {# Clean up the register allocators needed for the codegenerator.}
  50. procedure done_register_allocators;virtual;
  51. {# Set whether live_start or live_end should be updated when allocating registers, needed when e.g. generating initcode after the rest of the code. }
  52. procedure set_regalloc_live_range_direction(dir: TRADirection);virtual;
  53. {# Gets a register suitable to do integer operations on.}
  54. function getintregister(list:TAsmList;size:tdef):Tregister;virtual;
  55. {# Gets a register suitable to do integer operations on.}
  56. function getaddressregister(list:TAsmList;size:tdef):Tregister;virtual;
  57. function getfpuregister(list:TAsmList;size:tdef):Tregister;virtual;
  58. // we don't have high level defs yet that translate into all mm cgsizes
  59. // function getmmregister(list:TAsmList;size:tdef):Tregister;virtual;
  60. function getflagregister(list:TAsmList;size:tdef):Tregister;virtual;
  61. function getregisterfordef(list: TAsmList;size:tdef):Tregister;virtual;
  62. {Does the generic cg need SIMD registers, like getmmxregister? Or should
  63. the cpu specific child cg object have such a method?}
  64. function uses_registers(rt:Tregistertype):boolean; inline;
  65. procedure do_register_allocation(list:TAsmList;headertai:tai); inline;
  66. procedure translate_register(var reg : tregister); inline;
  67. {# Emit a label to the instruction stream. }
  68. procedure a_label(list : TAsmList;l : tasmlabel); inline;
  69. {# Allocates register r by inserting a pai_realloc record }
  70. procedure a_reg_alloc(list : TAsmList;r : tregister); inline;
  71. {# Deallocates register r by inserting a pa_regdealloc record}
  72. procedure a_reg_dealloc(list : TAsmList;r : tregister); inline;
  73. { Synchronize register, make sure it is still valid }
  74. procedure a_reg_sync(list : TAsmList;r : tregister); inline;
  75. {# Pass a parameter, which is located in a register, to a routine.
  76. This routine should push/send the parameter to the routine, as
  77. required by the specific processor ABI and routine modifiers.
  78. It must generate register allocation information for the cgpara in
  79. case it consists of cpuregisters.
  80. @param(size size of the operand in the register)
  81. @param(r register source of the operand)
  82. @param(cgpara where the parameter will be stored)
  83. }
  84. procedure a_load_reg_cgpara(list : TAsmList;size : tdef;r : tregister;const cgpara : TCGPara);virtual;
  85. {# Pass a parameter, which is a constant, to a routine.
  86. A generic version is provided. This routine should
  87. be overridden for optimization purposes if the cpu
  88. permits directly sending this type of parameter.
  89. It must generate register allocation information for the cgpara in
  90. case it consists of cpuregisters.
  91. @param(size size of the operand in constant)
  92. @param(a value of constant to send)
  93. @param(cgpara where the parameter will be stored)
  94. }
  95. procedure a_load_const_cgpara(list : TAsmList;tosize : tdef;a : aint;const cgpara : TCGPara);virtual;
  96. {# Pass the value of a parameter, which is located in memory, to a routine.
  97. A generic version is provided. This routine should
  98. be overridden for optimization purposes if the cpu
  99. permits directly sending this type of parameter.
  100. It must generate register allocation information for the cgpara in
  101. case it consists of cpuregisters.
  102. @param(size size of the operand in constant)
  103. @param(r Memory reference of value to send)
  104. @param(cgpara where the parameter will be stored)
  105. }
  106. procedure a_load_ref_cgpara(list : TAsmList;size : tdef;const r : treference;const cgpara : TCGPara);virtual;
  107. {# Pass the value of a parameter, which can be located either in a register or memory location,
  108. to a routine.
  109. A generic version is provided.
  110. @param(l location of the operand to send)
  111. @param(nr parameter number (starting from one) of routine (from left to right))
  112. @param(cgpara where the parameter will be stored)
  113. }
  114. procedure a_load_loc_cgpara(list : TAsmList;size : tdef; const l : tlocation;const cgpara : TCGPara);virtual;
  115. {# Pass the address of a reference to a routine. This routine
  116. will calculate the address of the reference, and pass this
  117. calculated address as a parameter.
  118. It must generate register allocation information for the cgpara in
  119. case it consists of cpuregisters.
  120. A generic version is provided. This routine should
  121. be overridden for optimization purposes if the cpu
  122. permits directly sending this type of parameter.
  123. @param(fromsize type of the reference we are taking the address of)
  124. @param(tosize type of the pointer that we get as a result)
  125. @param(r reference to get address from)
  126. }
  127. procedure a_loadaddr_ref_cgpara(list : TAsmList;fromsize, tosize : tdef;const r : treference;const cgpara : TCGPara);virtual;
  128. { Remarks:
  129. * If a method specifies a size you have only to take care
  130. of that number of bits, i.e. load_const_reg with OP_8 must
  131. only load the lower 8 bit of the specified register
  132. the rest of the register can be undefined
  133. if necessary the compiler will call a method
  134. to zero or sign extend the register
  135. * The a_load_XX_XX with OP_64 needn't to be
  136. implemented for 32 bit
  137. processors, the code generator takes care of that
  138. * the addr size is for work with the natural pointer
  139. size
  140. * the procedures without fpu/mm are only for integer usage
  141. * normally the first location is the source and the
  142. second the destination
  143. }
  144. {# Emits instruction to call the method specified by symbol name.
  145. This routine must be overridden for each new target cpu.
  146. }
  147. procedure a_call_name(list : TAsmList;pd : tprocdef;const s : string; weak: boolean);virtual;abstract;
  148. procedure a_call_reg(list : TAsmList;pd : tabstractprocdef;reg : tregister);virtual;abstract;
  149. procedure a_call_ref(list : TAsmList;pd : tabstractprocdef;ref : treference);virtual;abstract;
  150. { same as a_call_name, might be overridden on certain architectures to emit
  151. static calls without usage of a got trampoline }
  152. procedure a_call_name_static(list : TAsmList;pd : tprocdef;const s : string);virtual;
  153. { same as a_call_name, might be overridden on certain architectures to emit
  154. special static calls for inherited methods }
  155. procedure a_call_name_inherited(list : TAsmList;pd : tprocdef;const s : string);virtual;
  156. { move instructions }
  157. procedure a_load_const_reg(list : TAsmList;tosize : tdef;a : aint;register : tregister);virtual;abstract;
  158. procedure a_load_const_ref(list : TAsmList;tosize : tdef;a : aint;const ref : treference);virtual;
  159. procedure a_load_const_loc(list : TAsmList;tosize : tdef;a : aint;const loc : tlocation);virtual;
  160. procedure a_load_reg_ref(list : TAsmList;fromsize, tosize : tdef;register : tregister;const ref : treference);virtual;abstract;
  161. procedure a_load_reg_ref_unaligned(list : TAsmList;fromsize, tosize : tdef;register : tregister;const ref : treference);virtual;
  162. procedure a_load_reg_reg(list : TAsmList;fromsize, tosize : tdef;reg1,reg2 : tregister);virtual;abstract;
  163. procedure a_load_reg_loc(list : TAsmList;fromsize, tosize : tdef;reg : tregister;const loc: tlocation);virtual;
  164. procedure a_load_ref_reg(list : TAsmList;fromsize, tosize : tdef;const ref : treference;register : tregister);virtual;abstract;
  165. procedure a_load_ref_reg_unaligned(list : TAsmList;fromsize, tosize : tdef;const ref : treference;register : tregister);virtual;
  166. procedure a_load_ref_ref(list : TAsmList;fromsize, tosize : tdef;const sref : treference;const dref : treference);virtual;
  167. procedure a_load_loc_reg(list : TAsmList;fromsize, tosize : tdef; const loc: tlocation; reg : tregister);virtual;
  168. procedure a_load_loc_ref(list : TAsmList;fromsize, tosize: tdef; const loc: tlocation; const ref : treference);virtual;
  169. procedure a_load_loc_subsetreg(list : TAsmList;fromsize, tosize, tosubsetsize: tdef; const loc: tlocation; const sreg : tsubsetregister);virtual;
  170. procedure a_load_loc_subsetref(list : TAsmList;fromsize, tosize, tosubsetsize: tdef; const loc: tlocation; const sref : tsubsetreference);virtual;
  171. procedure a_loadaddr_ref_reg(list : TAsmList;fromsize, tosize : tdef;const ref : treference;r : tregister);virtual;abstract;
  172. { The subset stuff still need a transformation to thlcgobj }
  173. procedure a_load_subsetreg_reg(list : TAsmList; fromsize, fromsubsetsize, tosize: tdef; const sreg: tsubsetregister; destreg: tregister); virtual; abstract;
  174. procedure a_load_reg_subsetreg(list : TAsmList; fromsize, tosize, tosubsetsize: tdef; fromreg: tregister; const sreg: tsubsetregister); virtual; abstract;
  175. procedure a_load_subsetreg_subsetreg(list: TAsmlist; fromsize, fromsubsetsize, tosize, tosubsetsize : tdef; const fromsreg, tosreg: tsubsetregister); virtual; abstract;
  176. procedure a_load_subsetreg_ref(list : TAsmList; fromsize, fromsubsetsize, tosize: tdef; const sreg: tsubsetregister; const destref: treference); virtual; abstract;
  177. procedure a_load_ref_subsetreg(list : TAsmList; fromsize, tosize,tosubsetsize: tdef; const fromref: treference; const sreg: tsubsetregister); virtual; abstract;
  178. procedure a_load_const_subsetreg(list: TAsmlist; tosize, tosubsetsize: tdef; a: aint; const sreg: tsubsetregister); virtual; abstract;
  179. procedure a_load_subsetreg_loc(list: TAsmlist; fromsize, fromsubsetsize, tosize: tdef; const sreg: tsubsetregister; const loc: tlocation); virtual;
  180. procedure a_load_subsetref_reg(list : TAsmList; fromsize, fromsubsetsize, tosize: tdef; const sref: tsubsetreference; destreg: tregister); virtual; abstract;
  181. procedure a_load_reg_subsetref(list : TAsmList; fromsize, tosubsetsize, tosize: tdef; fromreg: tregister; const sref: tsubsetreference); virtual; abstract;
  182. procedure a_load_subsetref_subsetref(list: TAsmlist; fromsize, fromsubsetsize, tosize, tosubsetsize : tdef; const fromsref, tosref: tsubsetreference); virtual; abstract;
  183. procedure a_load_subsetref_ref(list : TAsmList; fromsize, fromsubsetsize, tosize: tdef; const sref: tsubsetreference; const destref: treference); virtual; abstract;
  184. procedure a_load_ref_subsetref(list : TAsmList; fromsize, tosize, tosubsetsize: tdef; const fromref: treference; const sref: tsubsetreference); virtual; abstract;
  185. procedure a_load_const_subsetref(list: TAsmlist; tosize, tosubsetsize: tdef; a: aint; const sref: tsubsetreference); virtual; abstract;
  186. procedure a_load_subsetref_loc(list: TAsmlist; fromsize, fromsubsetsize, tosize: tdef; const sref: tsubsetreference; const loc: tlocation); virtual;
  187. procedure a_load_subsetref_subsetreg(list: TAsmlist; fromsize, fromsubsetsize, tosize, tosubsetsize : tdef; const fromsref: tsubsetreference; const tosreg: tsubsetregister); virtual; abstract;
  188. procedure a_load_subsetreg_subsetref(list: TAsmlist; fromsize, fromsubsetsize, tosize, tosubsetsize : tdef; const fromsreg: tsubsetregister; const tosref: tsubsetreference); virtual; abstract;
  189. { bit test instructions (still need transformation to thlcgobj) }
  190. procedure a_bit_test_reg_reg_reg(list : TAsmList; bitnumbersize,valuesize,destsize: tdef;bitnumber,value,destreg: tregister); virtual; abstract;
  191. procedure a_bit_test_const_ref_reg(list: TAsmList; fromsize, destsize: tdef; bitnumber: aint; const ref: treference; destreg: tregister); virtual; abstract;
  192. procedure a_bit_test_const_reg_reg(list: TAsmList; setregsize, destsize: tdef; bitnumber: aint; setreg, destreg: tregister); virtual; abstract;
  193. procedure a_bit_test_const_subsetreg_reg(list: TAsmList; fromsize, fromsubsetsize, destsize: tdef; bitnumber: aint; const setreg: tsubsetregister; destreg: tregister); virtual; abstract;
  194. procedure a_bit_test_reg_ref_reg(list: TAsmList; bitnumbersize, refsize, destsize: tdef; bitnumber: tregister; const ref: treference; destreg: tregister); virtual; abstract;
  195. procedure a_bit_test_reg_loc_reg(list: TAsmList; bitnumbersize, locsize, destsize: tdef; bitnumber: tregister; const loc: tlocation; destreg: tregister);virtual;
  196. procedure a_bit_test_const_loc_reg(list: TAsmList; locsize, destsize: tdef; bitnumber: aint; const loc: tlocation; destreg: tregister);virtual;
  197. { bit set/clear instructions (still need transformation to thlcgobj) }
  198. procedure a_bit_set_reg_reg(list : TAsmList; doset: boolean; bitnumbersize, destsize: tdef; bitnumber,dest: tregister); virtual; abstract;
  199. procedure a_bit_set_const_ref(list: TAsmList; doset: boolean;destsize: tdef; bitnumber: aint; const ref: treference); virtual; abstract;
  200. procedure a_bit_set_const_reg(list: TAsmList; doset: boolean; destsize: tdef; bitnumber: aint; destreg: tregister); virtual; abstract;
  201. procedure a_bit_set_const_subsetreg(list: TAsmList; doset: boolean; destsize, destsubsetsize: tdef; bitnumber: aint; const destreg: tsubsetregister); virtual; abstract;
  202. procedure a_bit_set_reg_ref(list: TAsmList; doset: boolean; fromsize, tosize: tdef; bitnumber: tregister; const ref: treference); virtual; abstract;
  203. procedure a_bit_set_reg_loc(list: TAsmList; doset: boolean; fromsize, tosize: tdef; bitnumber: tregister; const loc: tlocation);virtual;
  204. procedure a_bit_set_const_loc(list: TAsmList; doset: boolean; tosize: tdef; bitnumber: aint; const loc: tlocation);virtual;
  205. { bit scan instructions (still need transformation to thlcgobj) }
  206. procedure a_bit_scan_reg_reg(list: TAsmList; reverse: boolean; size: tdef; src, dst: tregister); virtual; abstract;
  207. { fpu move instructions }
  208. procedure a_loadfpu_reg_reg(list: TAsmList; fromsize, tosize: tdef; reg1, reg2: tregister); virtual; abstract;
  209. procedure a_loadfpu_ref_reg(list: TAsmList; fromsize, tosize: tdef; const ref: treference; reg: tregister); virtual; abstract;
  210. procedure a_loadfpu_reg_ref(list: TAsmList; fromsize, tosize: tdef; reg: tregister; const ref: treference); virtual; abstract;
  211. procedure a_loadfpu_ref_ref(list: TAsmList; fromsize, tosize: tdef; const ref1,ref2: treference);virtual;
  212. procedure a_loadfpu_loc_reg(list: TAsmList; fromsize, tosize: tdef; const loc: tlocation; const reg: tregister);virtual;
  213. procedure a_loadfpu_reg_loc(list: TAsmList; fromsize, tosize: tdef; const reg: tregister; const loc: tlocation);virtual;
  214. procedure a_loadfpu_reg_cgpara(list : TAsmList;fromsize: tdef;const r : tregister;const cgpara : TCGPara);virtual;
  215. procedure a_loadfpu_ref_cgpara(list : TAsmList;fromsize : tdef;const ref : treference;const cgpara : TCGPara);virtual;
  216. { vector register move instructions }
  217. // we don't have high level defs yet that translate into all mm cgsizes
  218. {
  219. procedure a_loadmm_reg_reg(list: TAsmList; fromsize, tosize: tdef;reg1, reg2: tregister;shuffle : pmmshuffle); virtual;
  220. procedure a_loadmm_ref_reg(list: TAsmList; fromsize, tosize: tdef;const ref: treference; reg: tregister;shuffle : pmmshuffle); virtual;
  221. procedure a_loadmm_reg_ref(list: TAsmList; fromsize, tosize: tdef;reg: tregister; const ref: treference;shuffle : pmmshuffle); virtual;
  222. procedure a_loadmm_loc_reg(list: TAsmList; fromsize, tosize: tdef; const loc: tlocation; const reg: tregister;shuffle : pmmshuffle);virtual;
  223. procedure a_loadmm_reg_loc(list: TAsmList; fromsize, tosize: tdef; const reg: tregister; const loc: tlocation;shuffle : pmmshuffle);virtual;
  224. procedure a_loadmm_reg_cgpara(list: TAsmList; fromsize: tdef; reg: tregister;const cgpara : TCGPara;shuffle : pmmshuffle); virtual;
  225. procedure a_loadmm_ref_cgpara(list: TAsmList; fromsize: tdef; const ref: treference;const cgpara : TCGPara;shuffle : pmmshuffle); virtual;
  226. procedure a_loadmm_loc_cgpara(list: TAsmList; fromsize: tdef; const loc: tlocation; const cgpara : TCGPara;shuffle : pmmshuffle); virtual;
  227. procedure a_opmm_reg_reg(list: TAsmList; Op: TOpCG; size : tdef;src,dst: tregister;shuffle : pmmshuffle); virtual;
  228. procedure a_opmm_ref_reg(list: TAsmList; Op: TOpCG; size : tdef;const ref: treference; reg: tregister;shuffle : pmmshuffle); virtual;
  229. procedure a_opmm_loc_reg(list: TAsmList; Op: TOpCG; size : tdef;const loc: tlocation; reg: tregister;shuffle : pmmshuffle); virtual;
  230. procedure a_opmm_reg_ref(list: TAsmList; Op: TOpCG; size : tdef;reg: tregister;const ref: treference; shuffle : pmmshuffle); virtual;
  231. }
  232. // we don't have high level defs yet that translate into all mm cgsizes
  233. // procedure a_loadmm_intreg_reg(list: TAsmList; fromsize, tosize : tdef; intreg, mmreg: tregister; shuffle: pmmshuffle); virtual;
  234. // procedure a_loadmm_reg_intreg(list: TAsmList; fromsize, tosize : tdef; mmreg, intreg: tregister; shuffle : pmmshuffle); virtual;
  235. { basic arithmetic operations }
  236. { note: for operators which require only one argument (not, neg), use }
  237. { the op_reg_reg, op_reg_ref or op_reg_loc methods and keep in mind }
  238. { that in this case the *second* operand is used as both source and }
  239. { destination (JM) }
  240. procedure a_op_const_reg(list : TAsmList; Op: TOpCG; size: tdef; a: Aint; reg: TRegister); virtual; abstract;
  241. procedure a_op_const_ref(list : TAsmList; Op: TOpCG; size: tdef; a: Aint; const ref: TReference); virtual;
  242. procedure a_op_const_subsetreg(list : TAsmList; Op : TOpCG; size, subsetsize : tdef; a : aint; const sreg: tsubsetregister); virtual;
  243. procedure a_op_const_subsetref(list : TAsmList; Op : TOpCG; size, subsetsize : tdef; a : aint; const sref: tsubsetreference); virtual;
  244. procedure a_op_const_loc(list : TAsmList; Op: TOpCG; size: tdef; a: Aint; const loc: tlocation);virtual;
  245. procedure a_op_reg_reg(list : TAsmList; Op: TOpCG; size: tdef; reg1, reg2: TRegister); virtual; abstract;
  246. procedure a_op_reg_ref(list : TAsmList; Op: TOpCG; size: tdef; reg: TRegister; const ref: TReference); virtual;
  247. procedure a_op_ref_reg(list : TAsmList; Op: TOpCG; size: tdef; const ref: TReference; reg: TRegister); virtual;
  248. procedure a_op_reg_subsetreg(list: TAsmList; Op: TOpCG; opsize, destsize, destsubsetsize: tdef; reg: TRegister; const sreg: tsubsetregister); virtual;
  249. procedure a_op_reg_subsetref(list: TAsmList; Op: TOpCG; opsize, destsize, destsubsetsize: tdef; reg: TRegister; const sref: tsubsetreference); virtual;
  250. procedure a_op_reg_loc(list : TAsmList; Op: TOpCG; size: tdef; reg: tregister; const loc: tlocation);virtual;
  251. procedure a_op_ref_loc(list : TAsmList; Op: TOpCG; size: tdef; const ref: TReference; const loc: tlocation);virtual;
  252. { trinary operations for processors that support them, 'emulated' }
  253. { on others. None with "ref" arguments since I don't think there }
  254. { are any processors that support it (JM) }
  255. procedure a_op_const_reg_reg(list: TAsmList; op: TOpCg; size: tdef; a: aint; src, dst: tregister); virtual;
  256. procedure a_op_reg_reg_reg(list: TAsmList; op: TOpCg; size: tdef; src1, src2, dst: tregister); virtual;
  257. procedure a_op_const_reg_reg_checkoverflow(list: TAsmList; op: TOpCg; size: tdef; a: aint; src, dst: tregister;setflags : boolean;var ovloc : tlocation); virtual;
  258. procedure a_op_reg_reg_reg_checkoverflow(list: TAsmList; op: TOpCg; size: tdef; src1, src2, dst: tregister;setflags : boolean;var ovloc : tlocation); virtual;
  259. { comparison operations }
  260. procedure a_cmp_const_reg_label(list : TAsmList;size : tdef;cmp_op : topcmp;a : aint;reg : tregister;
  261. l : tasmlabel);virtual;
  262. procedure a_cmp_const_ref_label(list : TAsmList;size : tdef;cmp_op : topcmp;a : aint;const ref : treference;
  263. l : tasmlabel); virtual;
  264. procedure a_cmp_const_loc_label(list: TAsmList; size: tdef;cmp_op: topcmp; a: aint; const loc: tlocation;
  265. l : tasmlabel);virtual;
  266. procedure a_cmp_reg_reg_label(list : TAsmList;size : tdef;cmp_op : topcmp;reg1,reg2 : tregister;l : tasmlabel); virtual; abstract;
  267. procedure a_cmp_ref_reg_label(list : TAsmList;size : tdef;cmp_op : topcmp; const ref: treference; reg : tregister; l : tasmlabel); virtual;
  268. procedure a_cmp_reg_ref_label(list : TAsmList;size : tdef;cmp_op : topcmp;reg : tregister; const ref: treference; l : tasmlabel); virtual;
  269. procedure a_cmp_subsetreg_reg_label(list: TAsmList; fromsize, fromsubsetsize, cmpsize: tdef; cmp_op: topcmp; const sreg: tsubsetregister; reg: tregister; l: tasmlabel); virtual;
  270. procedure a_cmp_subsetref_reg_label(list: TAsmList; fromsize, fromsubsetsize, cmpsize: tdef; cmp_op: topcmp; const sref: tsubsetreference; reg: tregister; l: tasmlabel); virtual;
  271. procedure a_cmp_loc_reg_label(list : TAsmList;size : tdef;cmp_op : topcmp; const loc: tlocation; reg : tregister; l : tasmlabel);virtual;
  272. procedure a_cmp_reg_loc_label(list : TAsmList;size : tdef;cmp_op : topcmp; reg: tregister; const loc: tlocation; l : tasmlabel);virtual;
  273. procedure a_cmp_ref_loc_label(list: TAsmList; size: tdef;cmp_op: topcmp; const ref: treference; const loc: tlocation; l : tasmlabel);virtual;
  274. procedure a_jmp_always(list : TAsmList;l: tasmlabel); virtual;abstract;
  275. {$ifdef cpuflags}
  276. procedure a_jmp_flags(list : TAsmList;const f : TResFlags;l: tasmlabel); virtual; abstract;
  277. {# Depending on the value to check in the flags, either sets the register reg to one (if the flag is set)
  278. or zero (if the flag is cleared). The size parameter indicates the destination size register.
  279. }
  280. procedure g_flags2reg(list: TAsmList; size: tdef; const f: tresflags; reg: TRegister); virtual; abstract;
  281. procedure g_flags2ref(list: TAsmList; size: tdef; const f: tresflags; const ref:TReference); virtual; abstract;
  282. {$endif cpuflags}
  283. // procedure g_maybe_testself(list : TAsmList;reg:tregister);
  284. // procedure g_maybe_testvmt(list : TAsmList;reg:tregister;objdef:tobjectdef);
  285. {# This should emit the opcode to copy len bytes from the source
  286. to destination.
  287. It must be overridden for each new target processor.
  288. @param(source Source reference of copy)
  289. @param(dest Destination reference of copy)
  290. }
  291. procedure g_concatcopy(list : TAsmList;size: tdef; const source,dest : treference);virtual;
  292. {# This should emit the opcode to copy len bytes from the an unaligned source
  293. to destination.
  294. It must be overridden for each new target processor.
  295. @param(source Source reference of copy)
  296. @param(dest Destination reference of copy)
  297. }
  298. procedure g_concatcopy_unaligned(list : TAsmList;size: tdef; const source,dest : treference);virtual;
  299. {# This should emit the opcode to a shortrstring from the source
  300. to destination.
  301. @param(source Source reference of copy)
  302. @param(dest Destination reference of copy)
  303. }
  304. // procedure g_copyshortstring(list : TAsmList;const source,dest : treference;len:byte);
  305. // procedure g_copyvariant(list : TAsmList;const source,dest : treference);
  306. procedure g_incrrefcount(list : TAsmList;t: tdef; const ref: treference);virtual;abstract;
  307. procedure g_decrrefcount(list : TAsmList;t: tdef; const ref: treference);virtual;abstract;
  308. procedure g_initialize(list : TAsmList;t : tdef;const ref : treference);virtual;abstract;
  309. procedure g_finalize(list : TAsmList;t : tdef;const ref : treference);virtual;abstract;
  310. {# Generates range checking code. It is to note
  311. that this routine does not need to be overridden,
  312. as it takes care of everything.
  313. @param(p Node which contains the value to check)
  314. @param(todef Type definition of node to range check)
  315. }
  316. procedure g_rangecheck(list: TAsmList; const l:tlocation; fromdef,todef: tdef); virtual; abstract;
  317. {# Generates overflow checking code for a node }
  318. procedure g_overflowcheck(list: TAsmList; const Loc:tlocation; def:tdef); virtual; abstract;
  319. procedure g_overflowCheck_loc(List:TAsmList;const Loc:TLocation;def:TDef;var ovloc : tlocation);virtual; abstract;
  320. // procedure g_copyvaluepara_openarray(list : TAsmList;const ref:treference;const lenloc:tlocation;elesize:aint;destreg:tregister);virtual;
  321. // procedure g_releasevaluepara_openarray(list : TAsmList;const l:tlocation);virtual;
  322. {# Emits instructions when compilation is done in profile
  323. mode (this is set as a command line option). The default
  324. behavior does nothing, should be overridden as required.
  325. }
  326. procedure g_profilecode(list : TAsmList);virtual;
  327. {# Emits instruction for allocating @var(size) bytes at the stackpointer
  328. @param(size Number of bytes to allocate)
  329. }
  330. procedure g_stackpointer_alloc(list : TAsmList;size : longint);virtual; abstract;
  331. {# Emits instruction for allocating the locals in entry
  332. code of a routine. This is one of the first
  333. routine called in @var(genentrycode).
  334. @param(localsize Number of bytes to allocate as locals)
  335. }
  336. procedure g_proc_entry(list : TAsmList;localsize : longint;nostackframe:boolean);virtual; abstract;
  337. {# Emits instructions for returning from a subroutine.
  338. Should also restore the framepointer and stack.
  339. @param(parasize Number of bytes of parameters to deallocate from stack)
  340. }
  341. procedure g_proc_exit(list : TAsmList;parasize:longint;nostackframe:boolean);virtual; abstract;
  342. procedure g_intf_wrapper(list: TAsmList; procdef: tprocdef; const labelname: string; ioffset: longint);virtual; abstract;
  343. procedure g_adjust_self_value(list:TAsmList;procdef: tprocdef;ioffset: aint);virtual; abstract;
  344. function g_indirect_sym_load(list:TAsmList;const symname: string; weak: boolean): tregister;virtual; abstract;
  345. { generate a stub which only purpose is to pass control the given external method,
  346. setting up any additional environment before doing so (if required).
  347. The default implementation issues a jump instruction to the external name. }
  348. // procedure g_external_wrapper(list : TAsmList; procdef: tprocdef; const externalname: string); virtual;
  349. { routines migrated from ncgutil }
  350. procedure location_force_reg(list:TAsmList;var l:tlocation;src_size,dst_size:tdef;maybeconst:boolean);virtual;
  351. procedure location_force_fpureg(list:TAsmList;var l: tlocation;size: tdef;maybeconst:boolean);virtual;abstract;
  352. procedure location_force_mem(list:TAsmList;var l:tlocation;size:tdef);virtual;abstract;
  353. // procedure location_force_mmregscalar(list:TAsmList;var l: tlocation;size:tdef;maybeconst:boolean);virtual;abstract;
  354. // procedure location_force_mmreg(list:TAsmList;var l: tlocation;size:tdef;maybeconst:boolean);virtual;abstract;
  355. procedure maketojumpbool(list:TAsmList; p : tnode);virtual;abstract;
  356. procedure gen_proc_symbol(list:TAsmList);virtual;
  357. procedure gen_proc_symbol_end(list:TAsmList);virtual;
  358. private
  359. procedure gen_loadfpu_loc_cgpara(list: TAsmList; size: tdef; const l: tlocation;const cgpara: tcgpara;locintsize: longint);virtual;
  360. protected
  361. { Some targets have to put "something" in the function result
  362. location if it's not initialised by the Pascal code, e.g.
  363. stack-based architectures. By default it does nothing }
  364. procedure gen_load_uninitialized_function_result(list: TAsmList; pd: tprocdef; resdef: tdef; const resloc: tcgpara);virtual;
  365. public
  366. { load a tlocation into a cgpara }
  367. procedure gen_load_loc_cgpara(list: TAsmList; vardef: tdef; const l: tlocation; const cgpara: tcgpara);virtual;
  368. { load the function return value into the ABI-defined function return location }
  369. procedure gen_load_return_value(list:TAsmList);virtual;
  370. { extras refactored from other units }
  371. { queue the code/data generated for a procedure for writing out to
  372. the assembler/object file }
  373. procedure record_generated_code_for_procdef(pd: tprocdef; code, data: TAsmList); virtual;
  374. end;
  375. var
  376. {# Main high level code generator class }
  377. hlcg : thlcgobj;
  378. procedure destroy_hlcodegen;
  379. implementation
  380. uses
  381. globals,options,systems,
  382. fmodule,export,
  383. verbose,defutil,paramgr,symsym,
  384. cpuinfo,cgobj,tgobj,cutils,procinfo,
  385. ncgutil;
  386. procedure destroy_hlcodegen;
  387. begin
  388. hlcg.free;
  389. hlcg:=nil;
  390. end;
  391. { thlcgobj }
  392. constructor thlcgobj.create;
  393. begin
  394. end;
  395. procedure thlcgobj.init_register_allocators;
  396. begin
  397. cg.init_register_allocators;
  398. end;
  399. procedure thlcgobj.done_register_allocators;
  400. begin
  401. cg.done_register_allocators;
  402. end;
  403. procedure thlcgobj.set_regalloc_live_range_direction(dir: TRADirection);
  404. begin
  405. cg.set_regalloc_live_range_direction(dir);
  406. end;
  407. function thlcgobj.getintregister(list: TAsmList; size: tdef): Tregister;
  408. begin
  409. result:=cg.getintregister(list,def_cgsize(size));
  410. end;
  411. function thlcgobj.getaddressregister(list: TAsmList; size: tdef): Tregister;
  412. begin
  413. result:=cg.getaddressregister(list);
  414. end;
  415. function thlcgobj.getfpuregister(list: TAsmList; size: tdef): Tregister;
  416. begin
  417. result:=cg.getfpuregister(list,def_cgsize(size));
  418. end;
  419. (*
  420. function thlcgobj.getmmregister(list: TAsmList; size: tdef): Tregister;
  421. begin
  422. result:=cg.getmmregister(list,def_cgsize(size));
  423. end;
  424. *)
  425. function thlcgobj.getflagregister(list: TAsmList; size: tdef): Tregister;
  426. begin
  427. result:=cg.getflagregister(list,def_cgsize(size));
  428. end;
  429. function thlcgobj.getregisterfordef(list: TAsmList; size: tdef): Tregister;
  430. begin
  431. case def2regtyp(size) of
  432. R_INTREGISTER:
  433. result:=getintregister(list,size);
  434. R_ADDRESSREGISTER:
  435. result:=getaddressregister(list,size);
  436. R_FPUREGISTER:
  437. result:=getfpuregister(list,size);
  438. (*
  439. R_MMREGISTER:
  440. result:=getmmregister(list,size);
  441. *)
  442. else
  443. internalerror(2010122901);
  444. end;
  445. end;
  446. function thlcgobj.uses_registers(rt: Tregistertype): boolean;
  447. begin
  448. result:=cg.uses_registers(rt);
  449. end;
  450. procedure thlcgobj.do_register_allocation(list: TAsmList; headertai: tai);
  451. begin
  452. cg.do_register_allocation(list,headertai);
  453. end;
  454. procedure thlcgobj.translate_register(var reg: tregister);
  455. begin
  456. cg.translate_register(reg);
  457. end;
  458. procedure thlcgobj.a_label(list: TAsmList; l: tasmlabel); inline;
  459. begin
  460. cg.a_label(list,l);
  461. end;
  462. procedure thlcgobj.a_reg_alloc(list: TAsmList; r: tregister);
  463. begin
  464. cg.a_reg_alloc(list,r);
  465. end;
  466. procedure thlcgobj.a_reg_dealloc(list: TAsmList; r: tregister);
  467. begin
  468. cg.a_reg_dealloc(list,r);
  469. end;
  470. procedure thlcgobj.a_reg_sync(list: TAsmList; r: tregister);
  471. begin
  472. cg.a_reg_sync(list,r);
  473. end;
  474. procedure thlcgobj.a_load_reg_cgpara(list: TAsmList; size: tdef; r: tregister; const cgpara: TCGPara);
  475. var
  476. ref: treference;
  477. begin
  478. cgpara.check_simple_location;
  479. paramanager.alloccgpara(list,cgpara);
  480. case cgpara.location^.loc of
  481. LOC_REGISTER,LOC_CREGISTER:
  482. a_load_reg_reg(list,size,cgpara.def,r,cgpara.location^.register);
  483. LOC_REFERENCE,LOC_CREFERENCE:
  484. begin
  485. reference_reset_base(ref,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment);
  486. a_load_reg_ref(list,size,cgpara.def,r,ref);
  487. end;
  488. (*
  489. LOC_MMREGISTER,LOC_CMMREGISTER:
  490. a_loadmm_intreg_reg(list,size,cgpara.def,r,cgpara.location^.register,mms_movescalar);
  491. *)
  492. LOC_FPUREGISTER,LOC_CFPUREGISTER:
  493. begin
  494. tg.GetTemp(list,size.size,size.alignment,tt_normal,ref);
  495. a_load_reg_ref(list,size,size,r,ref);
  496. a_loadfpu_ref_cgpara(list,size,ref,cgpara);
  497. tg.Ungettemp(list,ref);
  498. end
  499. else
  500. internalerror(2010120415);
  501. end;
  502. end;
  503. procedure thlcgobj.a_load_const_cgpara(list: TAsmList; tosize: tdef; a: aint; const cgpara: TCGPara);
  504. var
  505. ref : treference;
  506. begin
  507. cgpara.check_simple_location;
  508. paramanager.alloccgpara(list,cgpara);
  509. case cgpara.location^.loc of
  510. LOC_REGISTER,LOC_CREGISTER:
  511. a_load_const_reg(list,cgpara.def,a,cgpara.location^.register);
  512. LOC_REFERENCE,LOC_CREFERENCE:
  513. begin
  514. reference_reset_base(ref,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment);
  515. a_load_const_ref(list,cgpara.def,a,ref);
  516. end
  517. else
  518. internalerror(2010120416);
  519. end;
  520. end;
  521. procedure thlcgobj.a_load_ref_cgpara(list: TAsmList; size: tdef; const r: treference; const cgpara: TCGPara);
  522. var
  523. ref: treference;
  524. begin
  525. cgpara.check_simple_location;
  526. paramanager.alloccgpara(list,cgpara);
  527. case cgpara.location^.loc of
  528. LOC_REGISTER,LOC_CREGISTER:
  529. a_load_ref_reg(list,size,cgpara.def,r,cgpara.location^.register);
  530. LOC_REFERENCE,LOC_CREFERENCE:
  531. begin
  532. reference_reset_base(ref,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment);
  533. a_load_ref_ref(list,size,cgpara.def,r,ref);
  534. end
  535. (*
  536. LOC_MMREGISTER,LOC_CMMREGISTER:
  537. begin
  538. case location^.size of
  539. OS_F32,
  540. OS_F64,
  541. OS_F128:
  542. a_loadmm_ref_reg(list,cgpara.def,cgpara.def,r,location^.register,mms_movescalar);
  543. OS_M8..OS_M128,
  544. OS_MS8..OS_MS128:
  545. a_loadmm_ref_reg(list,cgpara.def,cgpara.def,r,location^.register,nil);
  546. else
  547. internalerror(2010120417);
  548. end;
  549. end
  550. *)
  551. else
  552. internalerror(2010120418);
  553. end;
  554. end;
  555. procedure thlcgobj.a_load_loc_cgpara(list: TAsmList; size: tdef; const l: tlocation; const cgpara: TCGPara);
  556. begin
  557. case l.loc of
  558. LOC_REGISTER,
  559. LOC_CREGISTER :
  560. a_load_reg_cgpara(list,size,l.register,cgpara);
  561. LOC_CONSTANT :
  562. a_load_const_cgpara(list,size,l.value,cgpara);
  563. LOC_CREFERENCE,
  564. LOC_REFERENCE :
  565. a_load_ref_cgpara(list,size,l.reference,cgpara);
  566. else
  567. internalerror(2010120419);
  568. end;
  569. end;
  570. procedure thlcgobj.a_loadaddr_ref_cgpara(list: TAsmList; fromsize, tosize: tdef; const r: treference; const cgpara: TCGPara);
  571. var
  572. hr : tregister;
  573. begin
  574. cgpara.check_simple_location;
  575. if cgpara.location^.loc in [LOC_CREGISTER,LOC_REGISTER] then
  576. begin
  577. paramanager.allocparaloc(list,cgpara.location);
  578. a_loadaddr_ref_reg(list,fromsize,tosize,r,cgpara.location^.register)
  579. end
  580. else
  581. begin
  582. hr:=getaddressregister(list,tosize);
  583. a_loadaddr_ref_reg(list,fromsize,tosize,r,hr);
  584. a_load_reg_cgpara(list,tosize,hr,cgpara);
  585. end;
  586. end;
  587. procedure thlcgobj.a_call_name_static(list: TAsmList; pd: tprocdef; const s: string);
  588. begin
  589. a_call_name(list,pd,s,false);
  590. end;
  591. procedure thlcgobj.a_call_name_inherited(list: TAsmList; pd: tprocdef; const s: string);
  592. begin
  593. a_call_name(list,pd,s,false);
  594. end;
  595. procedure thlcgobj.a_load_const_ref(list: TAsmList; tosize: tdef; a: aint; const ref: treference);
  596. var
  597. tmpreg: tregister;
  598. begin
  599. tmpreg:=getintregister(list,tosize);
  600. a_load_const_reg(list,tosize,a,tmpreg);
  601. a_load_reg_ref(list,tosize,tosize,tmpreg,ref);
  602. end;
  603. procedure thlcgobj.a_load_const_loc(list: TAsmList; tosize: tdef; a: aint; const loc: tlocation);
  604. begin
  605. case loc.loc of
  606. LOC_REFERENCE,LOC_CREFERENCE:
  607. a_load_const_ref(list,tosize,a,loc.reference);
  608. LOC_REGISTER,LOC_CREGISTER:
  609. a_load_const_reg(list,tosize,a,loc.register);
  610. { we don't have enough type information to handle these here
  611. LOC_SUBSETREG,LOC_CSUBSETREG:
  612. a_load_const_subsetreg(list,loc.size,a,loc.sreg);
  613. LOC_SUBSETREF,LOC_CSUBSETREF:
  614. a_load_const_subsetref(list,loc.size,a,loc.sref);
  615. }
  616. else
  617. internalerror(2010120401);
  618. end;
  619. end;
  620. procedure thlcgobj.a_load_reg_ref_unaligned(list: TAsmList; fromsize, tosize: tdef; register: tregister; const ref: treference);
  621. begin
  622. a_load_reg_ref(list,fromsize,tosize,register,ref);
  623. end;
  624. procedure thlcgobj.a_load_reg_loc(list: TAsmList; fromsize, tosize: tdef; reg: tregister; const loc: tlocation);
  625. begin
  626. case loc.loc of
  627. LOC_REFERENCE,LOC_CREFERENCE:
  628. a_load_reg_ref(list,fromsize,tosize,reg,loc.reference);
  629. LOC_REGISTER,LOC_CREGISTER:
  630. a_load_reg_reg(list,fromsize,tosize,reg,loc.register);
  631. { we don't have enough type information to handle these here
  632. LOC_SUBSETREG,LOC_CSUBSETREG:
  633. a_load_reg_subsetreg(list,fromsize,tosize,reg,loc.sreg);
  634. LOC_SUBSETREF,LOC_CSUBSETREF:
  635. a_load_reg_subsetref(list,fromsize,loc.size,reg,loc.sref);
  636. LOC_MMREGISTER,LOC_CMMREGISTER:
  637. a_loadmm_intreg_reg(list,fromsize,loc.size,reg,loc.register,mms_movescalar);
  638. }
  639. else
  640. internalerror(2010120402);
  641. end;
  642. end;
  643. procedure thlcgobj.a_load_ref_reg_unaligned(list: TAsmList; fromsize, tosize: tdef; const ref: treference; register: tregister);
  644. begin
  645. a_load_ref_reg(list,fromsize,tosize,ref,register);
  646. end;
  647. procedure thlcgobj.a_load_ref_ref(list: TAsmList; fromsize, tosize: tdef; const sref: treference; const dref: treference);
  648. var
  649. tmpreg: tregister;
  650. begin
  651. { verify if we have the same reference }
  652. if references_equal(sref,dref) then
  653. exit;
  654. tmpreg:=getintregister(list,tosize);
  655. a_load_ref_reg(list,fromsize,tosize,sref,tmpreg);
  656. a_load_reg_ref(list,tosize,tosize,tmpreg,dref);
  657. end;
  658. procedure thlcgobj.a_load_loc_reg(list: TAsmList; fromsize, tosize: tdef; const loc: tlocation; reg: tregister);
  659. begin
  660. case loc.loc of
  661. LOC_REFERENCE,LOC_CREFERENCE:
  662. a_load_ref_reg(list,fromsize,tosize,loc.reference,reg);
  663. LOC_REGISTER,LOC_CREGISTER:
  664. a_load_reg_reg(list,fromsize,tosize,loc.register,reg);
  665. LOC_CONSTANT:
  666. a_load_const_reg(list,tosize,loc.value,reg);
  667. { we don't have enough type information to handle these here
  668. LOC_SUBSETREG,LOC_CSUBSETREG:
  669. a_load_subsetreg_reg(list,fromsize,tosize,loc.sreg,reg);
  670. LOC_SUBSETREF,LOC_CSUBSETREF:
  671. a_load_subsetref_reg(list,fromsize,tosize,loc.sref,reg);
  672. }
  673. else
  674. internalerror(2010120201);
  675. end;
  676. end;
  677. procedure thlcgobj.a_load_loc_ref(list: TAsmList; fromsize, tosize: tdef; const loc: tlocation; const ref: treference);
  678. begin
  679. case loc.loc of
  680. LOC_REFERENCE,LOC_CREFERENCE:
  681. a_load_ref_ref(list,fromsize,tosize,loc.reference,ref);
  682. LOC_REGISTER,LOC_CREGISTER:
  683. a_load_reg_ref(list,fromsize,tosize,loc.register,ref);
  684. LOC_CONSTANT:
  685. a_load_const_ref(list,tosize,loc.value,ref);
  686. { we don't have enough type information to handle these here
  687. LOC_SUBSETREG,LOC_CSUBSETREG:
  688. a_load_subsetreg_ref(list,loc.size,tosize,loc.sreg,ref);
  689. LOC_SUBSETREF,LOC_CSUBSETREF:
  690. a_load_subsetref_ref(list,loc.size,tosize,loc.sref,ref);
  691. }
  692. else
  693. internalerror(2010120403);
  694. end;
  695. end;
  696. procedure thlcgobj.a_load_loc_subsetreg(list: TAsmList; fromsize, tosize, tosubsetsize: tdef; const loc: tlocation; const sreg: tsubsetregister);
  697. begin
  698. case loc.loc of
  699. LOC_REFERENCE,LOC_CREFERENCE:
  700. a_load_ref_subsetreg(list,fromsize,tosize,tosubsetsize,loc.reference,sreg);
  701. LOC_REGISTER,LOC_CREGISTER:
  702. a_load_reg_subsetreg(list,fromsize,tosize,tosubsetsize,loc.register,sreg);
  703. LOC_CONSTANT:
  704. a_load_const_subsetreg(list,tosize,tosubsetsize,loc.value,sreg);
  705. { we don't have enough type information to handle these here
  706. LOC_SUBSETREG,LOC_CSUBSETREG:
  707. a_load_subsetreg_subsetreg(list,loc.size,subsetsize,loc.sreg,sreg);
  708. LOC_SUBSETREF,LOC_CSUBSETREF:
  709. a_load_subsetref_subsetreg(list,loc.size,subsetsize,loc.sref,sreg);
  710. }
  711. else
  712. internalerror(2010120404);
  713. end;
  714. end;
  715. procedure thlcgobj.a_load_loc_subsetref(list: TAsmList; fromsize, tosize, tosubsetsize: tdef; const loc: tlocation; const sref: tsubsetreference);
  716. begin
  717. case loc.loc of
  718. LOC_REFERENCE,LOC_CREFERENCE:
  719. a_load_ref_subsetref(list,fromsize,tosize,tosubsetsize,loc.reference,sref);
  720. LOC_REGISTER,LOC_CREGISTER:
  721. a_load_reg_subsetref(list,fromsize,tosize,tosubsetsize,loc.register,sref);
  722. LOC_CONSTANT:
  723. a_load_const_subsetref(list,tosize,tosubsetsize,loc.value,sref);
  724. { we don't have enough type information to handle these here
  725. LOC_SUBSETREG,LOC_CSUBSETREG:
  726. a_load_subsetreg_subsetref(list,loc.size,subsetsize,loc.sreg,sref);
  727. LOC_SUBSETREF,LOC_CSUBSETREF:
  728. a_load_subsetref_subsetref(list,loc.size,subsetsize,loc.sref,sref);
  729. }
  730. else
  731. internalerror(2010120405);
  732. end;
  733. end;
  734. procedure thlcgobj.a_load_subsetreg_loc(list: TAsmlist; fromsize, fromsubsetsize, tosize: tdef; const sreg: tsubsetregister; const loc: tlocation);
  735. begin
  736. case loc.loc of
  737. LOC_REFERENCE,LOC_CREFERENCE:
  738. a_load_subsetreg_ref(list,fromsize,fromsubsetsize,tosize,sreg,loc.reference);
  739. LOC_REGISTER,LOC_CREGISTER:
  740. a_load_subsetreg_reg(list,fromsize,fromsubsetsize,tosize,sreg,loc.register);
  741. { we don't have enough type information to handle these here
  742. LOC_SUBSETREG,LOC_CSUBSETREG:
  743. a_load_subsetreg_subsetreg(list,subsetsize,loc.size,sreg,loc.sreg);
  744. LOC_SUBSETREF,LOC_CSUBSETREF:
  745. a_load_subsetreg_subsetref(list,subsetsize,loc.size,sreg,loc.sref);
  746. }
  747. else
  748. internalerror(2010120406);
  749. end;
  750. end;
  751. procedure thlcgobj.a_load_subsetref_loc(list: TAsmlist; fromsize, fromsubsetsize, tosize: tdef; const sref: tsubsetreference; const loc: tlocation);
  752. begin
  753. case loc.loc of
  754. LOC_REFERENCE,LOC_CREFERENCE:
  755. a_load_subsetref_ref(list,fromsize,fromsubsetsize,tosize,sref,loc.reference);
  756. LOC_REGISTER,LOC_CREGISTER:
  757. a_load_subsetref_reg(list,fromsize,fromsubsetsize,tosize,sref,loc.register);
  758. { we don't have enough type information to handle these here
  759. LOC_SUBSETREG,LOC_CSUBSETREG:
  760. a_load_subsetref_subsetreg(list,subsetsize,loc.size,sref,loc.sreg);
  761. LOC_SUBSETREF,LOC_CSUBSETREF:
  762. a_load_subsetref_subsetref(list,subsetsize,loc.size,sref,loc.sref);
  763. }
  764. else
  765. internalerror(2010120407);
  766. end;
  767. end;
  768. procedure thlcgobj.a_bit_test_reg_loc_reg(list: TAsmList; bitnumbersize, locsize, destsize: tdef; bitnumber: tregister; const loc: tlocation; destreg: tregister);
  769. var
  770. tmpreg: tregister;
  771. begin
  772. case loc.loc of
  773. LOC_REFERENCE,LOC_CREFERENCE:
  774. a_bit_test_reg_ref_reg(list,bitnumbersize,locsize,destsize,bitnumber,loc.reference,destreg);
  775. LOC_REGISTER,LOC_CREGISTER,
  776. LOC_SUBSETREG,LOC_CSUBSETREG,
  777. LOC_CONSTANT:
  778. begin
  779. case loc.loc of
  780. LOC_REGISTER,LOC_CREGISTER:
  781. tmpreg:=loc.register;
  782. (* we don't have enough type information to handle this here
  783. LOC_SUBSETREG,LOC_CSUBSETREG:
  784. begin
  785. tmpreg:=getintregister(list,loc.size);
  786. a_load_subsetreg_reg(list,loc.size,loc.size,loc.sreg,tmpreg);
  787. end;
  788. *)
  789. LOC_CONSTANT:
  790. begin
  791. tmpreg:=getintregister(list,locsize);
  792. a_load_const_reg(list,locsize,loc.value,tmpreg);
  793. end;
  794. end;
  795. a_bit_test_reg_reg_reg(list,bitnumbersize,locsize,destsize,bitnumber,tmpreg,destreg);
  796. end;
  797. { LOC_SUBSETREF is not possible, because sets are not (yet) bitpacked }
  798. else
  799. internalerror(2010120411);
  800. end;
  801. end;
  802. procedure thlcgobj.a_bit_test_const_loc_reg(list: TAsmList; locsize, destsize: tdef; bitnumber: aint; const loc: tlocation; destreg: tregister);
  803. begin
  804. case loc.loc of
  805. LOC_REFERENCE,LOC_CREFERENCE:
  806. a_bit_test_const_ref_reg(list,locsize,destsize,bitnumber,loc.reference,destreg);
  807. LOC_REGISTER,LOC_CREGISTER:
  808. a_bit_test_const_reg_reg(list,locsize,destsize,bitnumber,loc.register,destreg);
  809. (* we don't have enough type information to handle this here
  810. LOC_SUBSETREG,LOC_CSUBSETREG:
  811. a_bit_test_const_subsetreg_reg(list,loc.size,destsize,bitnumber,loc.sreg,destreg);
  812. *)
  813. { LOC_SUBSETREF is not possible, because sets are not (yet) bitpacked }
  814. else
  815. internalerror(2010120410);
  816. end;
  817. end;
  818. procedure thlcgobj.a_bit_set_reg_loc(list: TAsmList; doset: boolean; fromsize, tosize: tdef; bitnumber: tregister; const loc: tlocation);
  819. var
  820. tmpreg: tregister;
  821. begin
  822. case loc.loc of
  823. LOC_REFERENCE:
  824. a_bit_set_reg_ref(list,doset,fromsize,tosize,bitnumber,loc.reference);
  825. LOC_CREGISTER:
  826. a_bit_set_reg_reg(list,doset,fromsize,tosize,bitnumber,loc.register);
  827. (* we don't have enough type information to handle this here
  828. { e.g. a 2-byte set in a record regvar }
  829. LOC_CSUBSETREG:
  830. begin
  831. { hard to do in-place in a generic way, so operate on a copy }
  832. tmpreg:=getintregister(list,loc.size);
  833. a_load_subsetreg_reg(list,loc.size,loc.size,loc.sreg,tmpreg);
  834. a_bit_set_reg_reg(list,doset,bitnumbersize,loc.size,bitnumber,tmpreg);
  835. a_load_reg_subsetreg(list,loc.size,loc.size,tmpreg,loc.sreg);
  836. end;
  837. *)
  838. { LOC_SUBSETREF is not possible, because sets are not (yet) bitpacked }
  839. else
  840. internalerror(2010120408)
  841. end;
  842. end;
  843. procedure thlcgobj.a_bit_set_const_loc(list: TAsmList; doset: boolean; tosize: tdef; bitnumber: aint; const loc: tlocation);
  844. begin
  845. case loc.loc of
  846. LOC_REFERENCE:
  847. a_bit_set_const_ref(list,doset,tosize,bitnumber,loc.reference);
  848. LOC_CREGISTER:
  849. a_bit_set_const_reg(list,doset,tosize,bitnumber,loc.register);
  850. (* we don't have enough type information to handle this here
  851. LOC_CSUBSETREG:
  852. a_bit_set_const_subsetreg(list,doset,loc.size,bitnumber,loc.sreg);
  853. *)
  854. { LOC_SUBSETREF is not possible, because sets are not (yet) bitpacked }
  855. else
  856. internalerror(2010120409)
  857. end;
  858. end;
  859. procedure thlcgobj.a_loadfpu_ref_ref(list: TAsmList; fromsize, tosize: tdef; const ref1, ref2: treference);
  860. var
  861. reg: tregister;
  862. regsize: tdef;
  863. begin
  864. if (fromsize.size>=tosize.size) then
  865. regsize:=fromsize
  866. else
  867. regsize:=tosize;
  868. reg:=getfpuregister(list,regsize);
  869. a_loadfpu_ref_reg(list,fromsize,regsize,ref1,reg);
  870. a_loadfpu_reg_ref(list,regsize,tosize,reg,ref2);
  871. end;
  872. procedure thlcgobj.a_loadfpu_loc_reg(list: TAsmList; fromsize, tosize: tdef; const loc: tlocation; const reg: tregister);
  873. begin
  874. case loc.loc of
  875. LOC_REFERENCE, LOC_CREFERENCE:
  876. a_loadfpu_ref_reg(list,fromsize,tosize,loc.reference,reg);
  877. LOC_FPUREGISTER, LOC_CFPUREGISTER:
  878. a_loadfpu_reg_reg(list,fromsize,tosize,loc.register,reg);
  879. else
  880. internalerror(2010120412);
  881. end;
  882. end;
  883. procedure thlcgobj.a_loadfpu_reg_loc(list: TAsmList; fromsize, tosize: tdef; const reg: tregister; const loc: tlocation);
  884. begin
  885. case loc.loc of
  886. LOC_REFERENCE, LOC_CREFERENCE:
  887. a_loadfpu_reg_ref(list,fromsize,tosize,reg,loc.reference);
  888. LOC_FPUREGISTER, LOC_CFPUREGISTER:
  889. a_loadfpu_reg_reg(list,fromsize,tosize,reg,loc.register);
  890. else
  891. internalerror(2010120413);
  892. end;
  893. end;
  894. procedure thlcgobj.a_loadfpu_reg_cgpara(list: TAsmList; fromsize: tdef; const r: tregister; const cgpara: TCGPara);
  895. var
  896. ref : treference;
  897. begin
  898. paramanager.alloccgpara(list,cgpara);
  899. case cgpara.location^.loc of
  900. LOC_FPUREGISTER,LOC_CFPUREGISTER:
  901. begin
  902. cgpara.check_simple_location;
  903. a_loadfpu_reg_reg(list,fromsize,cgpara.def,r,cgpara.location^.register);
  904. end;
  905. LOC_REFERENCE,LOC_CREFERENCE:
  906. begin
  907. cgpara.check_simple_location;
  908. reference_reset_base(ref,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment);
  909. a_loadfpu_reg_ref(list,fromsize,cgpara.def,r,ref);
  910. end;
  911. LOC_REGISTER,LOC_CREGISTER:
  912. begin
  913. { paramfpu_ref does the check_simpe_location check here if necessary }
  914. tg.GetTemp(list,fromsize.size,fromsize.alignment,tt_normal,ref);
  915. a_loadfpu_reg_ref(list,fromsize,fromsize,r,ref);
  916. a_loadfpu_ref_cgpara(list,fromsize,ref,cgpara);
  917. tg.Ungettemp(list,ref);
  918. end;
  919. else
  920. internalerror(2010120422);
  921. end;
  922. end;
  923. procedure thlcgobj.a_loadfpu_ref_cgpara(list: TAsmList; fromsize: tdef; const ref: treference; const cgpara: TCGPara);
  924. var
  925. href : treference;
  926. // hsize: tcgsize;
  927. begin
  928. case cgpara.location^.loc of
  929. LOC_FPUREGISTER,LOC_CFPUREGISTER:
  930. begin
  931. cgpara.check_simple_location;
  932. paramanager.alloccgpara(list,cgpara);
  933. a_loadfpu_ref_reg(list,fromsize,cgpara.def,ref,cgpara.location^.register);
  934. end;
  935. LOC_REFERENCE,LOC_CREFERENCE:
  936. begin
  937. cgpara.check_simple_location;
  938. reference_reset_base(href,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment);
  939. { concatcopy should choose the best way to copy the data }
  940. g_concatcopy(list,fromsize,ref,href);
  941. end;
  942. (* not yet supported
  943. LOC_REGISTER,LOC_CREGISTER:
  944. begin
  945. { force integer size }
  946. hsize:=int_cgsize(tcgsize2size[size]);
  947. {$ifndef cpu64bitalu}
  948. if (hsize in [OS_S64,OS_64]) then
  949. cg64.a_load64_ref_cgpara(list,ref,cgpara)
  950. else
  951. {$endif not cpu64bitalu}
  952. begin
  953. cgpara.check_simple_location;
  954. a_load_ref_cgpara(list,hsize,ref,cgpara)
  955. end;
  956. end
  957. *)
  958. else
  959. internalerror(2010120423);
  960. end;
  961. end;
  962. (*
  963. procedure thlcgobj.a_loadmm_reg_reg(list: TAsmList; fromsize, tosize: tdef; reg1, reg2: tregister; shuffle: pmmshuffle);
  964. begin
  965. cg.a_loadmm_reg_reg(list,def_cgsize(fromsize),def_cgsize(tosize),reg1,reg2,shuffle);
  966. end;
  967. procedure thlcgobj.a_loadmm_ref_reg(list: TAsmList; fromsize, tosize: tdef; const ref: treference; reg: tregister; shuffle: pmmshuffle);
  968. begin
  969. cg.a_loadmm_ref_reg(list,def_cgsize(fromsize),def_cgsize(tosize),ref,reg,shuffle);
  970. end;
  971. procedure thlcgobj.a_loadmm_reg_ref(list: TAsmList; fromsize, tosize: tdef; reg: tregister; const ref: treference; shuffle: pmmshuffle);
  972. begin
  973. cg.a_loadmm_reg_ref(list,def_cgsize(fromsize),def_cgsize(tosize),reg,ref,shuffle);
  974. end;
  975. procedure thlcgobj.a_loadmm_loc_reg(list: TAsmList; fromsize, tosize: tdef; const loc: tlocation; const reg: tregister; shuffle: pmmshuffle);
  976. begin
  977. case loc.loc of
  978. LOC_MMREGISTER,LOC_CMMREGISTER:
  979. a_loadmm_reg_reg(list,fromsize,tosize,loc.register,reg,shuffle);
  980. LOC_REFERENCE,LOC_CREFERENCE:
  981. a_loadmm_ref_reg(list,fromsize,tosize,loc.reference,reg,shuffle);
  982. LOC_REGISTER,LOC_CREGISTER:
  983. a_loadmm_intreg_reg(list,fromsize,tosize,loc.register,reg,shuffle);
  984. else
  985. internalerror(2010120414);
  986. end;
  987. end;
  988. procedure thlcgobj.a_loadmm_reg_loc(list: TAsmList; fromsize, tosize: tdef; const reg: tregister; const loc: tlocation; shuffle: pmmshuffle);
  989. begin
  990. case loc.loc of
  991. LOC_MMREGISTER,LOC_CMMREGISTER:
  992. a_loadmm_reg_reg(list,fromsize,tosize,reg,loc.register,shuffle);
  993. LOC_REFERENCE,LOC_CREFERENCE:
  994. a_loadmm_reg_ref(list,fromsize,tosize,reg,loc.reference,shuffle);
  995. else
  996. internalerror(2010120415);
  997. end;
  998. end;
  999. procedure thlcgobj.a_loadmm_reg_cgpara(list: TAsmList; fromsize: tdef; reg: tregister; const cgpara: TCGPara; shuffle: pmmshuffle);
  1000. var
  1001. href : treference;
  1002. begin
  1003. cgpara.check_simple_location;
  1004. paramanager.alloccgpara(list,cgpara);
  1005. case cgpara.location^.loc of
  1006. LOC_MMREGISTER,LOC_CMMREGISTER:
  1007. a_loadmm_reg_reg(list,fromsize,cgpara.def,reg,cgpara.location^.register,shuffle);
  1008. LOC_REFERENCE,LOC_CREFERENCE:
  1009. begin
  1010. reference_reset_base(href,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment);
  1011. a_loadmm_reg_ref(list,fromsize,cgpara.def,reg,href,shuffle);
  1012. end;
  1013. LOC_REGISTER,LOC_CREGISTER:
  1014. begin
  1015. if assigned(shuffle) and
  1016. not shufflescalar(shuffle) then
  1017. internalerror(2009112510);
  1018. a_loadmm_reg_intreg(list,deomsize,cgpara.def,reg,cgpara.location^.register,mms_movescalar);
  1019. end
  1020. else
  1021. internalerror(2010120427);
  1022. end;
  1023. end;
  1024. procedure thlcgobj.a_loadmm_ref_cgpara(list: TAsmList; fromsize: tdef; const ref: treference; const cgpara: TCGPara; shuffle: pmmshuffle);
  1025. var
  1026. hr : tregister;
  1027. hs : tmmshuffle;
  1028. begin
  1029. cgpara.check_simple_location;
  1030. hr:=cg.getmmregister(list,cgpara.size);
  1031. a_loadmm_ref_reg(list,deomsize,cgpara.def,ref,hr,shuffle);
  1032. if realshuffle(shuffle) then
  1033. begin
  1034. hs:=shuffle^;
  1035. removeshuffles(hs);
  1036. a_loadmm_reg_cgpara(list,cgpara.def,hr,cgpara,@hs);
  1037. end
  1038. else
  1039. a_loadmm_reg_cgpara(list,cgpara.def,hr,cgpara,shuffle);
  1040. end;
  1041. procedure thlcgobj.a_loadmm_loc_cgpara(list: TAsmList; fromsize: tdef; const loc: tlocation; const cgpara: TCGPara; shuffle: pmmshuffle);
  1042. begin
  1043. {$ifdef extdebug}
  1044. if def_cgsize(fromsize)<>loc.size then
  1045. internalerror(2010112105);
  1046. {$endif}
  1047. cg.a_loadmm_loc_cgpara(list,loc,cgpara,shuffle);
  1048. end;
  1049. procedure thlcgobj.a_opmm_reg_reg(list: TAsmList; Op: TOpCG; size: tdef; src, dst: tregister; shuffle: pmmshuffle);
  1050. begin
  1051. cg.a_opmm_reg_reg(list,op,def_cgsize(size),src,dst,shuffle);
  1052. end;
  1053. procedure thlcgobj.a_opmm_ref_reg(list: TAsmList; Op: TOpCG; size: tdef; const ref: treference; reg: tregister; shuffle: pmmshuffle);
  1054. begin
  1055. cg.a_opmm_ref_reg(list,op,def_cgsize(size),ref,reg,shuffle)
  1056. end;
  1057. procedure thlcgobj.a_opmm_loc_reg(list: TAsmList; Op: TOpCG; size: tdef; const loc: tlocation; reg: tregister; shuffle: pmmshuffle);
  1058. begin
  1059. cg.a_opmm_loc_reg(list,op,def_cgsize(size),loc,reg,shuffle);
  1060. end;
  1061. procedure thlcgobj.a_opmm_reg_ref(list: TAsmList; Op: TOpCG; size: tdef; reg: tregister; const ref: treference; shuffle: pmmshuffle);
  1062. begin
  1063. cg.a_opmm_reg_ref(list,op,def_cgsize(size),reg,ref,shuffle);
  1064. end;
  1065. *)
  1066. (*
  1067. procedure thlcgobj.a_loadmm_intreg_reg(list: TAsmList; fromsize, tosize: tdef; intreg, mmreg: tregister; shuffle: pmmshuffle);
  1068. begin
  1069. cg.a_loadmm_intreg_reg(list,def_cgsize(fromsize),def_cgsize(tosize),intreg,mmreg,shuffle);
  1070. end;
  1071. procedure thlcgobj.a_loadmm_reg_intreg(list: TAsmList; fromsize, tosize: tdef; mmreg, intreg: tregister; shuffle: pmmshuffle);
  1072. begin
  1073. cg.a_loadmm_reg_intreg(list,def_cgsize(fromsize),def_cgsize(tosize),mmreg,intreg,shuffle);
  1074. end;
  1075. *)
  1076. procedure thlcgobj.a_op_const_ref(list: TAsmList; Op: TOpCG; size: tdef; a: Aint; const ref: TReference);
  1077. var
  1078. tmpreg : tregister;
  1079. begin
  1080. tmpreg:=getintregister(list,size);
  1081. a_load_ref_reg(list,size,size,ref,tmpreg);
  1082. a_op_const_reg(list,op,size,a,tmpreg);
  1083. a_load_reg_ref(list,size,size,tmpreg,ref);
  1084. end;
  1085. procedure thlcgobj.a_op_const_subsetreg(list: TAsmList; Op: TOpCG; size, subsetsize: tdef; a: aint; const sreg: tsubsetregister);
  1086. var
  1087. tmpreg: tregister;
  1088. begin
  1089. tmpreg:=getintregister(list,size);
  1090. a_load_subsetreg_reg(list,size,subsetsize,size,sreg,tmpreg);
  1091. a_op_const_reg(list,op,size,a,tmpreg);
  1092. a_load_reg_subsetreg(list,size,size,subsetsize,tmpreg,sreg);
  1093. end;
  1094. procedure thlcgobj.a_op_const_subsetref(list: TAsmList; Op: TOpCG; size, subsetsize: tdef; a: aint; const sref: tsubsetreference);
  1095. var
  1096. tmpreg: tregister;
  1097. begin
  1098. tmpreg:=getintregister(list,size);
  1099. a_load_subsetref_reg(list,size,subsetsize,size,sref,tmpreg);
  1100. a_op_const_reg(list,op,size,a,tmpreg);
  1101. a_load_reg_subsetref(list,size,size,subsetsize,tmpreg,sref);
  1102. end;
  1103. procedure thlcgobj.a_op_const_loc(list: TAsmList; Op: TOpCG; size: tdef; a: Aint; const loc: tlocation);
  1104. begin
  1105. case loc.loc of
  1106. LOC_REGISTER, LOC_CREGISTER:
  1107. a_op_const_reg(list,op,size,a,loc.register);
  1108. LOC_REFERENCE, LOC_CREFERENCE:
  1109. a_op_const_ref(list,op,size,a,loc.reference);
  1110. { we don't have enough type information to handle these here
  1111. LOC_SUBSETREG, LOC_CSUBSETREG:
  1112. a_op_const_subsetreg(list,op,loc.size,loc.size,a,loc.sreg);
  1113. LOC_SUBSETREF, LOC_CSUBSETREF:
  1114. a_op_const_subsetref(list,op,loc.size,loc.size,a,loc.sref);
  1115. }
  1116. else
  1117. internalerror(2010120428);
  1118. end;
  1119. end;
  1120. procedure thlcgobj.a_op_reg_ref(list: TAsmList; Op: TOpCG; size: tdef; reg: TRegister; const ref: TReference);
  1121. var
  1122. tmpreg: tregister;
  1123. begin
  1124. case op of
  1125. OP_NOT,OP_NEG:
  1126. { handle it as "load ref,reg; op reg" }
  1127. begin
  1128. a_load_ref_reg(list,size,size,ref,reg);
  1129. a_op_reg_reg(list,op,size,reg,reg);
  1130. end;
  1131. else
  1132. begin
  1133. tmpreg:=getintregister(list,size);
  1134. a_load_ref_reg(list,size,size,ref,tmpreg);
  1135. a_op_reg_reg(list,op,size,tmpreg,reg);
  1136. end;
  1137. end;
  1138. end;
  1139. procedure thlcgobj.a_op_ref_reg(list: TAsmList; Op: TOpCG; size: tdef; const ref: TReference; reg: TRegister);
  1140. var
  1141. tmpreg: tregister;
  1142. begin
  1143. case op of
  1144. OP_NOT,OP_NEG:
  1145. { handle it as "load ref,reg; op reg" }
  1146. begin
  1147. a_load_ref_reg(list,size,size,ref,reg);
  1148. a_op_reg_reg(list,op,size,reg,reg);
  1149. end;
  1150. else
  1151. begin
  1152. tmpreg:=getintregister(list,size);
  1153. a_load_ref_reg(list,size,size,ref,tmpreg);
  1154. a_op_reg_reg(list,op,size,tmpreg,reg);
  1155. end;
  1156. end;
  1157. end;
  1158. procedure thlcgobj.a_op_reg_subsetreg(list: TAsmList; Op: TOpCG; opsize, destsize, destsubsetsize: tdef; reg: TRegister; const sreg: tsubsetregister);
  1159. var
  1160. tmpreg: tregister;
  1161. begin
  1162. tmpreg:=getintregister(list,opsize);
  1163. a_load_subsetreg_reg(list,destsize,destsubsetsize,opsize,sreg,tmpreg);
  1164. a_op_reg_reg(list,op,opsize,reg,tmpreg);
  1165. a_load_reg_subsetreg(list,opsize,destsize,destsubsetsize,tmpreg,sreg);
  1166. end;
  1167. procedure thlcgobj.a_op_reg_subsetref(list: TAsmList; Op: TOpCG; opsize, destsize, destsubsetsize: tdef; reg: TRegister; const sref: tsubsetreference);
  1168. var
  1169. tmpreg: tregister;
  1170. begin
  1171. tmpreg:=getintregister(list,opsize);
  1172. a_load_subsetref_reg(list,destsize,destsubsetsize,opsize,sref,tmpreg);
  1173. a_op_reg_reg(list,op,opsize,reg,tmpreg);
  1174. a_load_reg_subsetref(list,opsize,destsize,destsubsetsize,tmpreg,sref);
  1175. end;
  1176. procedure thlcgobj.a_op_reg_loc(list: TAsmList; Op: TOpCG; size: tdef; reg: tregister; const loc: tlocation);
  1177. begin
  1178. case loc.loc of
  1179. LOC_REGISTER, LOC_CREGISTER:
  1180. a_op_reg_reg(list,op,size,reg,loc.register);
  1181. LOC_REFERENCE, LOC_CREFERENCE:
  1182. a_op_reg_ref(list,op,size,reg,loc.reference);
  1183. { we don't have enough type information to handle these here
  1184. LOC_SUBSETREG, LOC_CSUBSETREG:
  1185. a_op_reg_subsetreg(list,op,loc.size,loc.size,reg,loc.sreg);
  1186. LOC_SUBSETREF, LOC_CSUBSETREF:
  1187. a_op_reg_subsetref(list,op,loc.size,loc.size,reg,loc.sref);
  1188. }
  1189. else
  1190. internalerror(2010120429);
  1191. end;
  1192. end;
  1193. procedure thlcgobj.a_op_ref_loc(list: TAsmList; Op: TOpCG; size: tdef; const ref: TReference; const loc: tlocation);
  1194. var
  1195. tmpreg: tregister;
  1196. begin
  1197. case loc.loc of
  1198. LOC_REGISTER,LOC_CREGISTER:
  1199. a_op_ref_reg(list,op,size,ref,loc.register);
  1200. LOC_REFERENCE,LOC_CREFERENCE:
  1201. begin
  1202. tmpreg:=getintregister(list,size);
  1203. a_load_ref_reg(list,size,size,ref,tmpreg);
  1204. a_op_reg_ref(list,op,size,tmpreg,loc.reference);
  1205. end;
  1206. { we don't have enough type information to handle these here
  1207. LOC_SUBSETREG, LOC_CSUBSETREG:
  1208. begin
  1209. tmpreg:=getintregister(list,loc.size);
  1210. a_load_subsetreg_reg(list,loc.size,loc.size,loc.sreg,tmpreg);
  1211. a_op_ref_reg(list,op,loc.size,ref,tmpreg);
  1212. a_load_reg_subsetreg(list,loc.size,loc.size,tmpreg,loc.sreg);
  1213. end;
  1214. LOC_SUBSETREF, LOC_CSUBSETREF:
  1215. begin
  1216. tmpreg:=getintregister(list,loc.size);
  1217. a_load_subsetreF_reg(list,loc.size,loc.size,loc.sref,tmpreg);
  1218. a_op_ref_reg(list,op,loc.size,ref,tmpreg);
  1219. a_load_reg_subsetref(list,loc.size,loc.size,tmpreg,loc.sref);
  1220. end;
  1221. }
  1222. else
  1223. internalerror(2010120429);
  1224. end;
  1225. end;
  1226. procedure thlcgobj.a_op_const_reg_reg(list: TAsmList; op: TOpCg; size: tdef; a: aint; src, dst: tregister);
  1227. begin
  1228. a_load_reg_reg(list,size,size,src,dst);
  1229. a_op_const_reg(list,op,size,a,dst);
  1230. end;
  1231. procedure thlcgobj.a_op_reg_reg_reg(list: TAsmList; op: TOpCg; size: tdef; src1, src2, dst: tregister);
  1232. var
  1233. tmpreg: tregister;
  1234. begin
  1235. if (dst<>src1) then
  1236. begin
  1237. a_load_reg_reg(list,size,size,src2,dst);
  1238. a_op_reg_reg(list,op,size,src1,dst);
  1239. end
  1240. else
  1241. begin
  1242. { can we do a direct operation on the target register ? }
  1243. if op in [OP_ADD,OP_MUL,OP_AND,OP_MOVE,OP_XOR,OP_IMUL,OP_OR] then
  1244. a_op_reg_reg(list,op,size,src2,dst)
  1245. else
  1246. begin
  1247. tmpreg:=getintregister(list,size);
  1248. a_load_reg_reg(list,size,size,src2,tmpreg);
  1249. a_op_reg_reg(list,op,size,src1,tmpreg);
  1250. a_load_reg_reg(list,size,size,tmpreg,dst);
  1251. end;
  1252. end;
  1253. end;
  1254. procedure thlcgobj.a_op_const_reg_reg_checkoverflow(list: TAsmList; op: TOpCg; size: tdef; a: aint; src, dst: tregister; setflags: boolean; var ovloc: tlocation);
  1255. begin
  1256. if not setflags then
  1257. a_op_const_reg_reg(list,op,size,a,src,dst)
  1258. else
  1259. internalerror(2010122910);
  1260. end;
  1261. procedure thlcgobj.a_op_reg_reg_reg_checkoverflow(list: TAsmList; op: TOpCg; size: tdef; src1, src2, dst: tregister; setflags: boolean; var ovloc: tlocation);
  1262. begin
  1263. if not setflags then
  1264. a_op_reg_reg_reg(list,op,size,src1,src2,dst)
  1265. else
  1266. internalerror(2010122911);
  1267. end;
  1268. procedure thlcgobj.a_cmp_const_reg_label(list: TAsmList; size: tdef; cmp_op: topcmp; a: aint; reg: tregister; l: tasmlabel);
  1269. var
  1270. tmpreg: tregister;
  1271. begin
  1272. tmpreg:=getintregister(list,size);
  1273. a_load_const_reg(list,size,a,tmpreg);
  1274. a_cmp_reg_reg_label(list,size,cmp_op,tmpreg,reg,l);
  1275. end;
  1276. procedure thlcgobj.a_cmp_const_ref_label(list: TAsmList; size: tdef; cmp_op: topcmp; a: aint; const ref: treference; l: tasmlabel);
  1277. var
  1278. tmpreg: tregister;
  1279. begin
  1280. tmpreg:=getintregister(list,size);
  1281. a_load_ref_reg(list,size,size,ref,tmpreg);
  1282. a_cmp_const_reg_label(list,size,cmp_op,a,tmpreg,l);
  1283. end;
  1284. procedure thlcgobj.a_cmp_const_loc_label(list: TAsmList; size: tdef; cmp_op: topcmp; a: aint; const loc: tlocation; l: tasmlabel);
  1285. var
  1286. tmpreg : tregister;
  1287. begin
  1288. case loc.loc of
  1289. LOC_REGISTER,LOC_CREGISTER:
  1290. a_cmp_const_reg_label(list,size,cmp_op,a,loc.register,l);
  1291. LOC_REFERENCE,LOC_CREFERENCE:
  1292. a_cmp_const_ref_label(list,size,cmp_op,a,loc.reference,l);
  1293. { we don't have enough type information to handle these here
  1294. LOC_SUBSETREG, LOC_CSUBSETREG:
  1295. begin
  1296. tmpreg:=getintregister(list,size);
  1297. a_load_subsetreg_reg(list,loc.size,size,loc.sreg,tmpreg);
  1298. a_cmp_const_reg_label(list,size,cmp_op,a,tmpreg,l);
  1299. end;
  1300. LOC_SUBSETREF, LOC_CSUBSETREF:
  1301. begin
  1302. tmpreg:=getintregister(list,size);
  1303. a_load_subsetref_reg(list,loc.size,size,loc.sref,tmpreg);
  1304. a_cmp_const_reg_label(list,size,cmp_op,a,tmpreg,l);
  1305. end;
  1306. }
  1307. else
  1308. internalerror(2010120430);
  1309. end;
  1310. end;
  1311. procedure thlcgobj.a_cmp_ref_reg_label(list: TAsmList; size: tdef; cmp_op: topcmp; const ref: treference; reg: tregister; l: tasmlabel);
  1312. var
  1313. tmpreg: tregister;
  1314. begin
  1315. tmpreg:=getintregister(list,size);
  1316. a_load_ref_reg(list,size,size,ref,tmpreg);
  1317. a_cmp_reg_reg_label(list,size,cmp_op,tmpreg,reg,l);
  1318. end;
  1319. procedure thlcgobj.a_cmp_reg_ref_label(list: TAsmList; size: tdef; cmp_op: topcmp; reg: tregister; const ref: treference; l: tasmlabel);
  1320. var
  1321. tmpreg: tregister;
  1322. begin
  1323. tmpreg:=getintregister(list,size);
  1324. a_load_ref_reg(list,size,size,ref,tmpreg);
  1325. a_cmp_reg_reg_label(list,size,cmp_op,reg,tmpreg,l);
  1326. end;
  1327. procedure thlcgobj.a_cmp_subsetreg_reg_label(list: TAsmList; fromsize, fromsubsetsize, cmpsize: tdef; cmp_op: topcmp; const sreg: tsubsetregister; reg: tregister; l: tasmlabel);
  1328. var
  1329. tmpreg: tregister;
  1330. begin
  1331. tmpreg:=getintregister(list,cmpsize);
  1332. a_load_subsetreg_reg(list,fromsize,fromsubsetsize,cmpsize,sreg,tmpreg);
  1333. a_cmp_reg_reg_label(list,cmpsize,cmp_op,tmpreg,reg,l);
  1334. end;
  1335. procedure thlcgobj.a_cmp_subsetref_reg_label(list: TAsmList; fromsize, fromsubsetsize, cmpsize: tdef; cmp_op: topcmp; const sref: tsubsetreference; reg: tregister; l: tasmlabel);
  1336. var
  1337. tmpreg: tregister;
  1338. begin
  1339. tmpreg:=getintregister(list,cmpsize);
  1340. a_load_subsetref_reg(list,fromsize,fromsubsetsize,cmpsize,sref,tmpreg);
  1341. a_cmp_reg_reg_label(list,cmpsize,cmp_op,tmpreg,reg,l);
  1342. end;
  1343. procedure thlcgobj.a_cmp_loc_reg_label(list: TAsmList; size: tdef; cmp_op: topcmp; const loc: tlocation; reg: tregister; l: tasmlabel);
  1344. begin
  1345. case loc.loc of
  1346. LOC_REGISTER,
  1347. LOC_CREGISTER:
  1348. a_cmp_reg_reg_label(list,size,cmp_op,loc.register,reg,l);
  1349. LOC_REFERENCE,
  1350. LOC_CREFERENCE :
  1351. a_cmp_ref_reg_label(list,size,cmp_op,loc.reference,reg,l);
  1352. LOC_CONSTANT:
  1353. a_cmp_const_reg_label(list,size,cmp_op,loc.value,reg,l);
  1354. { we don't have enough type information to handle these here
  1355. LOC_SUBSETREG,
  1356. LOC_CSUBSETREG:
  1357. a_cmp_subsetreg_reg_label(list,loc.size,size,cmp_op,loc.sreg,reg,l);
  1358. LOC_SUBSETREF,
  1359. LOC_CSUBSETREF:
  1360. a_cmp_subsetref_reg_label(list,loc.size,size,cmp_op,loc.sref,reg,l);
  1361. }
  1362. else
  1363. internalerror(2010120431);
  1364. end;
  1365. end;
  1366. procedure thlcgobj.a_cmp_reg_loc_label(list: TAsmList; size: tdef; cmp_op: topcmp; reg: tregister; const loc: tlocation; l: tasmlabel);
  1367. begin
  1368. a_cmp_loc_reg_label(list,size,swap_opcmp(cmp_op),loc,reg,l);
  1369. end;
  1370. procedure thlcgobj.a_cmp_ref_loc_label(list: TAsmList; size: tdef; cmp_op: topcmp; const ref: treference; const loc: tlocation; l: tasmlabel);
  1371. var
  1372. tmpreg: tregister;
  1373. begin
  1374. case loc.loc of
  1375. LOC_REGISTER,LOC_CREGISTER:
  1376. a_cmp_ref_reg_label(list,size,cmp_op,ref,loc.register,l);
  1377. LOC_REFERENCE,LOC_CREFERENCE:
  1378. begin
  1379. tmpreg:=getintregister(list,size);
  1380. a_load_ref_reg(list,size,size,loc.reference,tmpreg);
  1381. a_cmp_ref_reg_label(list,size,cmp_op,ref,tmpreg,l);
  1382. end;
  1383. LOC_CONSTANT:
  1384. begin
  1385. a_cmp_const_ref_label(list,size,swap_opcmp(cmp_op),loc.value,ref,l);
  1386. end
  1387. { we don't have enough type information to handle these here
  1388. LOC_SUBSETREG, LOC_CSUBSETREG:
  1389. begin
  1390. tmpreg:=getintregister(list, size);
  1391. a_load_ref_reg(list,size,size,loc.reference,tmpreg);
  1392. a_cmp_subsetreg_reg_label(list,loc.size,size,swap_opcmp(cmp_op),loc.sreg,tmpreg,l);
  1393. end;
  1394. LOC_SUBSETREF, LOC_CSUBSETREF:
  1395. begin
  1396. tmpreg:=getintregister(list, size);
  1397. a_load_ref_reg(list,size,size,loc.reference,tmpreg);
  1398. a_cmp_subsetref_reg_label(list,loc.size,size,swap_opcmp(cmp_op),loc.sref,tmpreg,l);
  1399. end;
  1400. }
  1401. else
  1402. internalerror(2010120432);
  1403. end;
  1404. end;
  1405. procedure thlcgobj.g_concatcopy(list: TAsmList; size: tdef; const source, dest: treference);
  1406. begin
  1407. {
  1408. if use_vectorfpu(size) then
  1409. a_loadmm_ref_ref()
  1410. else
  1411. }
  1412. if size.typ<>floatdef then
  1413. a_load_ref_ref(list,size,size,source,dest)
  1414. else
  1415. a_loadfpu_ref_ref(list,size,size,source,dest);
  1416. end;
  1417. procedure thlcgobj.g_concatcopy_unaligned(list: TAsmList; size: tdef; const source, dest: treference);
  1418. begin
  1419. g_concatcopy(list,size,source,dest);
  1420. end;
  1421. procedure thlcgobj.g_profilecode(list: TAsmList);
  1422. begin
  1423. end;
  1424. procedure thlcgobj.location_force_reg(list: TAsmList; var l: tlocation; src_size, dst_size: tdef; maybeconst: boolean);
  1425. var
  1426. hregister,
  1427. hregister2: tregister;
  1428. hl : tasmlabel;
  1429. oldloc : tlocation;
  1430. begin
  1431. oldloc:=l;
  1432. hregister:=getregisterfordef(list,dst_size);
  1433. { load value in new register }
  1434. case l.loc of
  1435. {$ifdef cpuflags}
  1436. LOC_FLAGS :
  1437. cg.g_flags2reg(list,def_cgsize(dst_size),l.resflags,hregister);
  1438. {$endif cpuflags}
  1439. LOC_JUMP :
  1440. begin
  1441. a_label(list,current_procinfo.CurrTrueLabel);
  1442. a_load_const_reg(list,dst_size,1,hregister);
  1443. current_asmdata.getjumplabel(hl);
  1444. a_jmp_always(list,hl);
  1445. a_label(list,current_procinfo.CurrFalseLabel);
  1446. a_load_const_reg(list,dst_size,0,hregister);
  1447. a_label(list,hl);
  1448. end;
  1449. else
  1450. begin
  1451. { load_loc_reg can only handle size >= l.size, when the
  1452. new size is smaller then we need to adjust the size
  1453. of the orignal and maybe recalculate l.register for i386 }
  1454. if (dst_size.size<src_size.size) then
  1455. begin
  1456. hregister2:=getregisterfordef(list,src_size);
  1457. { prevent problems with memory locations -- at this high
  1458. level we cannot twiddle with the reference offset, since
  1459. that may not mean anything (e.g., it refers to fixed-sized
  1460. stack slots on Java) }
  1461. a_load_loc_reg(list,src_size,src_size,l,hregister2);
  1462. a_load_reg_reg(list,src_size,dst_size,hregister2,hregister);
  1463. end
  1464. else
  1465. a_load_loc_reg(list,src_size,dst_size,l,hregister);
  1466. end;
  1467. end;
  1468. if (l.loc <> LOC_CREGISTER) or
  1469. not maybeconst then
  1470. location_reset(l,LOC_REGISTER,def_cgsize(dst_size))
  1471. else
  1472. location_reset(l,LOC_CREGISTER,def_cgsize(dst_size));
  1473. l.register:=hregister;
  1474. { Release temp if it was a reference }
  1475. if oldloc.loc=LOC_REFERENCE then
  1476. location_freetemp(list,oldloc);
  1477. end;
  1478. procedure thlcgobj.gen_proc_symbol(list: TAsmList);
  1479. var
  1480. item,
  1481. previtem : TCmdStrListItem;
  1482. begin
  1483. previtem:=nil;
  1484. item := TCmdStrListItem(current_procinfo.procdef.aliasnames.first);
  1485. while assigned(item) do
  1486. begin
  1487. {$ifdef arm}
  1488. if current_settings.cputype in cpu_thumb2 then
  1489. list.concat(tai_thumb_func.create);
  1490. {$endif arm}
  1491. { "double link" all procedure entry symbols via .reference }
  1492. { directives on darwin, because otherwise the linker }
  1493. { sometimes strips the procedure if only on of the symbols }
  1494. { is referenced }
  1495. if assigned(previtem) and
  1496. (target_info.system in systems_darwin) then
  1497. list.concat(tai_directive.create(asd_reference,item.str));
  1498. if (cs_profile in current_settings.moduleswitches) or
  1499. (po_global in current_procinfo.procdef.procoptions) then
  1500. list.concat(Tai_symbol.createname_global(item.str,AT_FUNCTION,0))
  1501. else
  1502. list.concat(Tai_symbol.createname(item.str,AT_FUNCTION,0));
  1503. if assigned(previtem) and
  1504. (target_info.system in systems_darwin) then
  1505. list.concat(tai_directive.create(asd_reference,previtem.str));
  1506. if not(af_stabs_use_function_absolute_addresses in target_asm.flags) then
  1507. list.concat(Tai_function_name.create(item.str));
  1508. previtem:=item;
  1509. item := TCmdStrListItem(item.next);
  1510. end;
  1511. current_procinfo.procdef.procstarttai:=tai(list.last);
  1512. end;
  1513. procedure thlcgobj.gen_proc_symbol_end(list: TAsmList);
  1514. begin
  1515. list.concat(Tai_symbol_end.Createname(current_procinfo.procdef.mangledname(true)));
  1516. current_procinfo.procdef.procendtai:=tai(list.last);
  1517. if (current_module.islibrary) then
  1518. if (current_procinfo.procdef.proctypeoption = potype_proginit) then
  1519. { setinitname may generate a new section -> don't add to the
  1520. current list, because we assume this remains a text section }
  1521. exportlib.setinitname(current_asmdata.AsmLists[al_exports],current_procinfo.procdef.mangledname(false));
  1522. if (current_procinfo.procdef.proctypeoption=potype_proginit) then
  1523. begin
  1524. if (target_info.system in (systems_darwin+[system_powerpc_macos])) and
  1525. not(current_module.islibrary) then
  1526. begin
  1527. new_section(list,sec_code,'',4);
  1528. list.concat(tai_symbol.createname_global(
  1529. target_info.cprefix+mainaliasname,AT_FUNCTION,0));
  1530. { keep argc, argv and envp properly on the stack }
  1531. cg.a_jmp_name(list,target_info.cprefix+'FPC_SYSTEMMAIN');
  1532. end;
  1533. end;
  1534. end;
  1535. procedure thlcgobj.gen_loadfpu_loc_cgpara(list: TAsmList; size: tdef; const l: tlocation; const cgpara: tcgpara; locintsize: longint);
  1536. begin
  1537. case l.loc of
  1538. (*
  1539. LOC_MMREGISTER,
  1540. LOC_CMMREGISTER:
  1541. case cgpara.location^.loc of
  1542. LOC_REFERENCE,
  1543. LOC_CREFERENCE,
  1544. LOC_MMREGISTER,
  1545. LOC_CMMREGISTER,
  1546. LOC_REGISTER,
  1547. LOC_CREGISTER :
  1548. cg.a_loadmm_reg_cgpara(list,locsize,l.register,cgpara,mms_movescalar);
  1549. LOC_FPUREGISTER,
  1550. LOC_CFPUREGISTER:
  1551. begin
  1552. tmploc:=l;
  1553. location_force_fpureg(list,tmploc,false);
  1554. cg.a_loadfpu_reg_cgpara(list,tmploc.size,tmploc.register,cgpara);
  1555. end;
  1556. else
  1557. internalerror(200204249);
  1558. end;
  1559. *)
  1560. LOC_FPUREGISTER,
  1561. LOC_CFPUREGISTER:
  1562. case cgpara.location^.loc of
  1563. (*
  1564. LOC_MMREGISTER,
  1565. LOC_CMMREGISTER:
  1566. begin
  1567. tmploc:=l;
  1568. location_force_mmregscalar(list,tmploc,false);
  1569. cg.a_loadmm_reg_cgpara(list,tmploc.size,tmploc.register,cgpara,mms_movescalar);
  1570. end;
  1571. *)
  1572. { Some targets pass floats in normal registers }
  1573. LOC_REGISTER,
  1574. LOC_CREGISTER,
  1575. LOC_REFERENCE,
  1576. LOC_CREFERENCE,
  1577. LOC_FPUREGISTER,
  1578. LOC_CFPUREGISTER:
  1579. hlcg.a_loadfpu_reg_cgpara(list,size,l.register,cgpara);
  1580. else
  1581. internalerror(2011010210);
  1582. end;
  1583. LOC_REFERENCE,
  1584. LOC_CREFERENCE:
  1585. case cgpara.location^.loc of
  1586. (*
  1587. LOC_MMREGISTER,
  1588. LOC_CMMREGISTER:
  1589. cg.a_loadmm_ref_cgpara(list,locsize,l.reference,cgpara,mms_movescalar);
  1590. *)
  1591. { Some targets pass floats in normal registers }
  1592. LOC_REGISTER,
  1593. LOC_CREGISTER,
  1594. LOC_REFERENCE,
  1595. LOC_CREFERENCE,
  1596. LOC_FPUREGISTER,
  1597. LOC_CFPUREGISTER:
  1598. hlcg.a_loadfpu_ref_cgpara(list,size,l.reference,cgpara);
  1599. else
  1600. internalerror(2011010211);
  1601. end;
  1602. LOC_REGISTER,
  1603. LOC_CREGISTER :
  1604. hlcg.a_load_loc_cgpara(list,size,l,cgpara);
  1605. else
  1606. internalerror(2011010212);
  1607. end;
  1608. end;
  1609. procedure thlcgobj.gen_load_uninitialized_function_result(list: TAsmList; pd: tprocdef; resdef: tdef; const resloc: tcgpara);
  1610. begin
  1611. { do nothing by default }
  1612. end;
  1613. procedure thlcgobj.gen_load_loc_cgpara(list: TAsmList; vardef: tdef; const l: tlocation; const cgpara: tcgpara);
  1614. begin
  1615. { Handle Floating point types differently
  1616. This doesn't depend on emulator settings, emulator settings should
  1617. be handled by cpupara }
  1618. if (vardef.typ=floatdef) or
  1619. { some ABIs return certain records in an fpu register }
  1620. (l.loc in [LOC_FPUREGISTER,LOC_CFPUREGISTER]) or
  1621. (assigned(cgpara.location) and
  1622. (cgpara.Location^.loc in [LOC_FPUREGISTER,LOC_CFPUREGISTER])) then
  1623. begin
  1624. gen_loadfpu_loc_cgpara(list,vardef,l,cgpara,vardef.size);
  1625. exit;
  1626. end;
  1627. case l.loc of
  1628. LOC_CONSTANT,
  1629. LOC_REGISTER,
  1630. LOC_CREGISTER,
  1631. LOC_REFERENCE,
  1632. LOC_CREFERENCE :
  1633. begin
  1634. hlcg.a_load_loc_cgpara(list,vardef,l,cgpara);
  1635. end;
  1636. (*
  1637. LOC_MMREGISTER,
  1638. LOC_CMMREGISTER:
  1639. begin
  1640. case l.size of
  1641. OS_F32,
  1642. OS_F64:
  1643. cg.a_loadmm_loc_cgpara(list,l,cgpara,mms_movescalar);
  1644. else
  1645. cg.a_loadmm_loc_cgpara(list,l,cgpara,nil);
  1646. end;
  1647. end;
  1648. *)
  1649. else
  1650. internalerror(2011010212);
  1651. end;
  1652. end;
  1653. procedure thlcgobj.gen_load_return_value(list: TAsmList);
  1654. var
  1655. ressym : tabstractnormalvarsym;
  1656. funcretloc : TCGPara;
  1657. begin
  1658. { Is the loading needed? }
  1659. if is_void(current_procinfo.procdef.returndef) or
  1660. (
  1661. (po_assembler in current_procinfo.procdef.procoptions) and
  1662. (not(assigned(current_procinfo.procdef.funcretsym)) or
  1663. (tabstractvarsym(current_procinfo.procdef.funcretsym).refs=0))
  1664. ) then
  1665. exit;
  1666. funcretloc:=current_procinfo.procdef.funcretloc[calleeside];
  1667. { constructors return self }
  1668. if (current_procinfo.procdef.proctypeoption=potype_constructor) then
  1669. ressym:=tabstractnormalvarsym(current_procinfo.procdef.parast.Find('self'))
  1670. else
  1671. ressym:=tabstractnormalvarsym(current_procinfo.procdef.funcretsym);
  1672. if (ressym.refs>0) or
  1673. is_managed_type(ressym.vardef) then
  1674. begin
  1675. { was: don't do anything if funcretloc.loc in [LOC_INVALID,LOC_REFERENCE] }
  1676. if not paramanager.ret_in_param(current_procinfo.procdef.returndef,current_procinfo.procdef.proccalloption) then
  1677. hlcg.gen_load_loc_cgpara(list,ressym.vardef,ressym.localloc,funcretloc);
  1678. end
  1679. else
  1680. gen_load_uninitialized_function_result(list,current_procinfo.procdef,ressym.vardef,funcretloc)
  1681. end;
  1682. procedure thlcgobj.record_generated_code_for_procdef(pd: tprocdef; code, data: TAsmList);
  1683. begin
  1684. { add the procedure to the al_procedures }
  1685. maybe_new_object_file(current_asmdata.asmlists[al_procedures]);
  1686. new_section(current_asmdata.asmlists[al_procedures],sec_code,lower(pd.mangledname(true)),getprocalign);
  1687. current_asmdata.asmlists[al_procedures].concatlist(code);
  1688. { save local data (casetable) also in the same file }
  1689. if assigned(data) and
  1690. (not data.empty) then
  1691. current_asmdata.asmlists[al_procedures].concatlist(data);
  1692. end;
  1693. end.