hlcgobj.pas 95 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175
  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;
  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. { create "safe copy" of a tlocation that can be used later: all
  350. registers used in the tlocation are copied to new ones, so that
  351. even if the original ones change, things stay the same (except if
  352. the original location was already a register, then the register is
  353. kept). Must only be used on lvalue locations.
  354. It's intended as some kind of replacement for a_loadaddr_ref_reg()
  355. for targets without pointers. }
  356. procedure g_reference_loc(list: TAsmList; def: tdef; const fromloc: tlocation; out toloc: tlocation); virtual; abstract;
  357. { routines migrated from ncgutil }
  358. procedure location_force_reg(list:TAsmList;var l:tlocation;src_size,dst_size:tdef;maybeconst:boolean);virtual;
  359. procedure location_force_fpureg(list:TAsmList;var l: tlocation;size: tdef;maybeconst:boolean);virtual;
  360. procedure location_force_mem(list:TAsmList;var l:tlocation;size:tdef);virtual;
  361. // procedure location_force_mmregscalar(list:TAsmList;var l: tlocation;size:tdef;maybeconst:boolean);virtual;abstract;
  362. // procedure location_force_mmreg(list:TAsmList;var l: tlocation;size:tdef;maybeconst:boolean);virtual;abstract;
  363. procedure maketojumpbool(list:TAsmList; p : tnode);virtual;
  364. procedure gen_proc_symbol(list:TAsmList);virtual;
  365. procedure gen_proc_symbol_end(list:TAsmList);virtual;
  366. procedure gen_load_para_value(list:TAsmList);virtual;
  367. private
  368. procedure gen_loadfpu_loc_cgpara(list: TAsmList; size: tdef; const l: tlocation;const cgpara: tcgpara;locintsize: longint);virtual;
  369. protected
  370. { Some targets have to put "something" in the function result
  371. location if it's not initialised by the Pascal code, e.g.
  372. stack-based architectures. By default it does nothing }
  373. procedure gen_load_uninitialized_function_result(list: TAsmList; pd: tprocdef; resdef: tdef; const resloc: tcgpara);virtual;
  374. public
  375. { load a tlocation into a cgpara }
  376. procedure gen_load_loc_cgpara(list: TAsmList; vardef: tdef; const l: tlocation; const cgpara: tcgpara);virtual;
  377. { load a cgpara into a tlocation }
  378. procedure gen_load_cgpara_loc(list: TAsmList; vardef: tdef; const para: TCGPara; var destloc: tlocation; reusepara: boolean);virtual;
  379. { load the function return value into the ABI-defined function return location }
  380. procedure gen_load_return_value(list:TAsmList);virtual;
  381. { extras refactored from other units }
  382. { queue the code/data generated for a procedure for writing out to
  383. the assembler/object file }
  384. procedure record_generated_code_for_procdef(pd: tprocdef; code, data: TAsmList); virtual;
  385. end;
  386. var
  387. {# Main high level code generator class }
  388. hlcg : thlcgobj;
  389. procedure destroy_hlcodegen;
  390. implementation
  391. uses
  392. globals,options,systems,
  393. fmodule,export,
  394. verbose,defutil,paramgr,symsym,
  395. ncon,
  396. cpuinfo,cgobj,tgobj,cutils,procinfo,
  397. ncgutil;
  398. procedure destroy_hlcodegen;
  399. begin
  400. hlcg.free;
  401. hlcg:=nil;
  402. end;
  403. { thlcgobj }
  404. constructor thlcgobj.create;
  405. begin
  406. end;
  407. procedure thlcgobj.init_register_allocators;
  408. begin
  409. cg.init_register_allocators;
  410. end;
  411. procedure thlcgobj.done_register_allocators;
  412. begin
  413. cg.done_register_allocators;
  414. end;
  415. procedure thlcgobj.set_regalloc_live_range_direction(dir: TRADirection);
  416. begin
  417. cg.set_regalloc_live_range_direction(dir);
  418. end;
  419. function thlcgobj.getintregister(list: TAsmList; size: tdef): Tregister;
  420. begin
  421. result:=cg.getintregister(list,def_cgsize(size));
  422. end;
  423. function thlcgobj.getaddressregister(list: TAsmList; size: tdef): Tregister;
  424. begin
  425. result:=cg.getaddressregister(list);
  426. end;
  427. function thlcgobj.getfpuregister(list: TAsmList; size: tdef): Tregister;
  428. begin
  429. result:=cg.getfpuregister(list,def_cgsize(size));
  430. end;
  431. (*
  432. function thlcgobj.getmmregister(list: TAsmList; size: tdef): Tregister;
  433. begin
  434. result:=cg.getmmregister(list,def_cgsize(size));
  435. end;
  436. *)
  437. function thlcgobj.getflagregister(list: TAsmList; size: tdef): Tregister;
  438. begin
  439. result:=cg.getflagregister(list,def_cgsize(size));
  440. end;
  441. function thlcgobj.getregisterfordef(list: TAsmList; size: tdef): Tregister;
  442. begin
  443. case def2regtyp(size) of
  444. R_INTREGISTER:
  445. result:=getintregister(list,size);
  446. R_ADDRESSREGISTER:
  447. result:=getaddressregister(list,size);
  448. R_FPUREGISTER:
  449. result:=getfpuregister(list,size);
  450. (*
  451. R_MMREGISTER:
  452. result:=getmmregister(list,size);
  453. *)
  454. else
  455. internalerror(2010122901);
  456. end;
  457. end;
  458. function thlcgobj.uses_registers(rt: Tregistertype): boolean;
  459. begin
  460. result:=cg.uses_registers(rt);
  461. end;
  462. procedure thlcgobj.do_register_allocation(list: TAsmList; headertai: tai);
  463. begin
  464. cg.do_register_allocation(list,headertai);
  465. end;
  466. procedure thlcgobj.translate_register(var reg: tregister);
  467. begin
  468. cg.translate_register(reg);
  469. end;
  470. procedure thlcgobj.a_label(list: TAsmList; l: tasmlabel); inline;
  471. begin
  472. cg.a_label(list,l);
  473. end;
  474. procedure thlcgobj.a_reg_alloc(list: TAsmList; r: tregister);
  475. begin
  476. cg.a_reg_alloc(list,r);
  477. end;
  478. procedure thlcgobj.a_reg_dealloc(list: TAsmList; r: tregister);
  479. begin
  480. cg.a_reg_dealloc(list,r);
  481. end;
  482. procedure thlcgobj.a_reg_sync(list: TAsmList; r: tregister);
  483. begin
  484. cg.a_reg_sync(list,r);
  485. end;
  486. procedure thlcgobj.a_load_reg_cgpara(list: TAsmList; size: tdef; r: tregister; const cgpara: TCGPara);
  487. var
  488. ref: treference;
  489. begin
  490. cgpara.check_simple_location;
  491. paramanager.alloccgpara(list,cgpara);
  492. case cgpara.location^.loc of
  493. LOC_REGISTER,LOC_CREGISTER:
  494. a_load_reg_reg(list,size,cgpara.def,r,cgpara.location^.register);
  495. LOC_REFERENCE,LOC_CREFERENCE:
  496. begin
  497. reference_reset_base(ref,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment);
  498. a_load_reg_ref(list,size,cgpara.def,r,ref);
  499. end;
  500. (*
  501. LOC_MMREGISTER,LOC_CMMREGISTER:
  502. a_loadmm_intreg_reg(list,size,cgpara.def,r,cgpara.location^.register,mms_movescalar);
  503. *)
  504. LOC_FPUREGISTER,LOC_CFPUREGISTER:
  505. begin
  506. tg.gethltemp(list,size,size.size,tt_normal,ref);
  507. a_load_reg_ref(list,size,size,r,ref);
  508. a_loadfpu_ref_cgpara(list,size,ref,cgpara);
  509. tg.ungettemp(list,ref);
  510. end
  511. else
  512. internalerror(2010120415);
  513. end;
  514. end;
  515. procedure thlcgobj.a_load_const_cgpara(list: TAsmList; tosize: tdef; a: aint; const cgpara: TCGPara);
  516. var
  517. ref : treference;
  518. begin
  519. cgpara.check_simple_location;
  520. paramanager.alloccgpara(list,cgpara);
  521. case cgpara.location^.loc of
  522. LOC_REGISTER,LOC_CREGISTER:
  523. a_load_const_reg(list,cgpara.def,a,cgpara.location^.register);
  524. LOC_REFERENCE,LOC_CREFERENCE:
  525. begin
  526. reference_reset_base(ref,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment);
  527. a_load_const_ref(list,cgpara.def,a,ref);
  528. end
  529. else
  530. internalerror(2010120416);
  531. end;
  532. end;
  533. procedure thlcgobj.a_load_ref_cgpara(list: TAsmList; size: tdef; const r: treference; const cgpara: TCGPara);
  534. var
  535. ref: treference;
  536. begin
  537. cgpara.check_simple_location;
  538. paramanager.alloccgpara(list,cgpara);
  539. case cgpara.location^.loc of
  540. LOC_REGISTER,LOC_CREGISTER:
  541. a_load_ref_reg(list,size,cgpara.def,r,cgpara.location^.register);
  542. LOC_REFERENCE,LOC_CREFERENCE:
  543. begin
  544. reference_reset_base(ref,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment);
  545. a_load_ref_ref(list,size,cgpara.def,r,ref);
  546. end
  547. (*
  548. LOC_MMREGISTER,LOC_CMMREGISTER:
  549. begin
  550. case location^.size of
  551. OS_F32,
  552. OS_F64,
  553. OS_F128:
  554. a_loadmm_ref_reg(list,cgpara.def,cgpara.def,r,location^.register,mms_movescalar);
  555. OS_M8..OS_M128,
  556. OS_MS8..OS_MS128:
  557. a_loadmm_ref_reg(list,cgpara.def,cgpara.def,r,location^.register,nil);
  558. else
  559. internalerror(2010120417);
  560. end;
  561. end
  562. *)
  563. else
  564. internalerror(2010120418);
  565. end;
  566. end;
  567. procedure thlcgobj.a_load_loc_cgpara(list: TAsmList; size: tdef; const l: tlocation; const cgpara: TCGPara);
  568. begin
  569. case l.loc of
  570. LOC_REGISTER,
  571. LOC_CREGISTER :
  572. a_load_reg_cgpara(list,size,l.register,cgpara);
  573. LOC_CONSTANT :
  574. a_load_const_cgpara(list,size,l.value,cgpara);
  575. LOC_CREFERENCE,
  576. LOC_REFERENCE :
  577. a_load_ref_cgpara(list,size,l.reference,cgpara);
  578. else
  579. internalerror(2010120419);
  580. end;
  581. end;
  582. procedure thlcgobj.a_loadaddr_ref_cgpara(list: TAsmList; fromsize, tosize: tdef; const r: treference; const cgpara: TCGPara);
  583. var
  584. hr : tregister;
  585. begin
  586. cgpara.check_simple_location;
  587. if cgpara.location^.loc in [LOC_CREGISTER,LOC_REGISTER] then
  588. begin
  589. paramanager.allocparaloc(list,cgpara.location);
  590. a_loadaddr_ref_reg(list,fromsize,tosize,r,cgpara.location^.register)
  591. end
  592. else
  593. begin
  594. hr:=getaddressregister(list,tosize);
  595. a_loadaddr_ref_reg(list,fromsize,tosize,r,hr);
  596. a_load_reg_cgpara(list,tosize,hr,cgpara);
  597. end;
  598. end;
  599. procedure thlcgobj.a_call_name_static(list: TAsmList; pd: tprocdef; const s: string);
  600. begin
  601. a_call_name(list,pd,s,false);
  602. end;
  603. procedure thlcgobj.a_call_name_inherited(list: TAsmList; pd: tprocdef; const s: string);
  604. begin
  605. a_call_name(list,pd,s,false);
  606. end;
  607. procedure thlcgobj.a_load_const_ref(list: TAsmList; tosize: tdef; a: aint; const ref: treference);
  608. var
  609. tmpreg: tregister;
  610. begin
  611. tmpreg:=getintregister(list,tosize);
  612. a_load_const_reg(list,tosize,a,tmpreg);
  613. a_load_reg_ref(list,tosize,tosize,tmpreg,ref);
  614. end;
  615. procedure thlcgobj.a_load_const_loc(list: TAsmList; tosize: tdef; a: aint; const loc: tlocation);
  616. begin
  617. case loc.loc of
  618. LOC_REFERENCE,LOC_CREFERENCE:
  619. a_load_const_ref(list,tosize,a,loc.reference);
  620. LOC_REGISTER,LOC_CREGISTER:
  621. a_load_const_reg(list,tosize,a,loc.register);
  622. { we don't have enough type information to handle these here
  623. LOC_SUBSETREG,LOC_CSUBSETREG:
  624. a_load_const_subsetreg(list,loc.size,a,loc.sreg);
  625. LOC_SUBSETREF,LOC_CSUBSETREF:
  626. a_load_const_subsetref(list,loc.size,a,loc.sref);
  627. }
  628. else
  629. internalerror(2010120401);
  630. end;
  631. end;
  632. procedure thlcgobj.a_load_reg_ref_unaligned(list: TAsmList; fromsize, tosize: tdef; register: tregister; const ref: treference);
  633. begin
  634. a_load_reg_ref(list,fromsize,tosize,register,ref);
  635. end;
  636. procedure thlcgobj.a_load_reg_loc(list: TAsmList; fromsize, tosize: tdef; reg: tregister; const loc: tlocation);
  637. begin
  638. case loc.loc of
  639. LOC_REFERENCE,LOC_CREFERENCE:
  640. a_load_reg_ref(list,fromsize,tosize,reg,loc.reference);
  641. LOC_REGISTER,LOC_CREGISTER:
  642. a_load_reg_reg(list,fromsize,tosize,reg,loc.register);
  643. { we don't have enough type information to handle these here
  644. LOC_SUBSETREG,LOC_CSUBSETREG:
  645. a_load_reg_subsetreg(list,fromsize,tosize,reg,loc.sreg);
  646. LOC_SUBSETREF,LOC_CSUBSETREF:
  647. a_load_reg_subsetref(list,fromsize,loc.size,reg,loc.sref);
  648. LOC_MMREGISTER,LOC_CMMREGISTER:
  649. a_loadmm_intreg_reg(list,fromsize,loc.size,reg,loc.register,mms_movescalar);
  650. }
  651. else
  652. internalerror(2010120402);
  653. end;
  654. end;
  655. procedure thlcgobj.a_load_ref_reg_unaligned(list: TAsmList; fromsize, tosize: tdef; const ref: treference; register: tregister);
  656. begin
  657. a_load_ref_reg(list,fromsize,tosize,ref,register);
  658. end;
  659. procedure thlcgobj.a_load_ref_ref(list: TAsmList; fromsize, tosize: tdef; const sref: treference; const dref: treference);
  660. var
  661. tmpreg: tregister;
  662. begin
  663. { verify if we have the same reference }
  664. if references_equal(sref,dref) then
  665. exit;
  666. tmpreg:=getintregister(list,tosize);
  667. a_load_ref_reg(list,fromsize,tosize,sref,tmpreg);
  668. a_load_reg_ref(list,tosize,tosize,tmpreg,dref);
  669. end;
  670. procedure thlcgobj.a_load_loc_reg(list: TAsmList; fromsize, tosize: tdef; const loc: tlocation; reg: tregister);
  671. begin
  672. case loc.loc of
  673. LOC_REFERENCE,LOC_CREFERENCE:
  674. a_load_ref_reg(list,fromsize,tosize,loc.reference,reg);
  675. LOC_REGISTER,LOC_CREGISTER:
  676. a_load_reg_reg(list,fromsize,tosize,loc.register,reg);
  677. LOC_CONSTANT:
  678. a_load_const_reg(list,tosize,loc.value,reg);
  679. { we don't have enough type information to handle these here
  680. LOC_SUBSETREG,LOC_CSUBSETREG:
  681. a_load_subsetreg_reg(list,fromsize,tosize,loc.sreg,reg);
  682. LOC_SUBSETREF,LOC_CSUBSETREF:
  683. a_load_subsetref_reg(list,fromsize,tosize,loc.sref,reg);
  684. }
  685. else
  686. internalerror(2010120201);
  687. end;
  688. end;
  689. procedure thlcgobj.a_load_loc_ref(list: TAsmList; fromsize, tosize: tdef; const loc: tlocation; const ref: treference);
  690. begin
  691. case loc.loc of
  692. LOC_REFERENCE,LOC_CREFERENCE:
  693. a_load_ref_ref(list,fromsize,tosize,loc.reference,ref);
  694. LOC_REGISTER,LOC_CREGISTER:
  695. a_load_reg_ref(list,fromsize,tosize,loc.register,ref);
  696. LOC_CONSTANT:
  697. a_load_const_ref(list,tosize,loc.value,ref);
  698. { we don't have enough type information to handle these here
  699. LOC_SUBSETREG,LOC_CSUBSETREG:
  700. a_load_subsetreg_ref(list,loc.size,tosize,loc.sreg,ref);
  701. LOC_SUBSETREF,LOC_CSUBSETREF:
  702. a_load_subsetref_ref(list,loc.size,tosize,loc.sref,ref);
  703. }
  704. else
  705. internalerror(2010120403);
  706. end;
  707. end;
  708. procedure thlcgobj.a_load_loc_subsetreg(list: TAsmList; fromsize, tosize, tosubsetsize: tdef; const loc: tlocation; const sreg: tsubsetregister);
  709. begin
  710. case loc.loc of
  711. LOC_REFERENCE,LOC_CREFERENCE:
  712. a_load_ref_subsetreg(list,fromsize,tosize,tosubsetsize,loc.reference,sreg);
  713. LOC_REGISTER,LOC_CREGISTER:
  714. a_load_reg_subsetreg(list,fromsize,tosize,tosubsetsize,loc.register,sreg);
  715. LOC_CONSTANT:
  716. a_load_const_subsetreg(list,tosize,tosubsetsize,loc.value,sreg);
  717. { we don't have enough type information to handle these here
  718. LOC_SUBSETREG,LOC_CSUBSETREG:
  719. a_load_subsetreg_subsetreg(list,loc.size,subsetsize,loc.sreg,sreg);
  720. LOC_SUBSETREF,LOC_CSUBSETREF:
  721. a_load_subsetref_subsetreg(list,loc.size,subsetsize,loc.sref,sreg);
  722. }
  723. else
  724. internalerror(2010120404);
  725. end;
  726. end;
  727. procedure thlcgobj.a_load_loc_subsetref(list: TAsmList; fromsize, tosize, tosubsetsize: tdef; const loc: tlocation; const sref: tsubsetreference);
  728. begin
  729. case loc.loc of
  730. LOC_REFERENCE,LOC_CREFERENCE:
  731. a_load_ref_subsetref(list,fromsize,tosize,tosubsetsize,loc.reference,sref);
  732. LOC_REGISTER,LOC_CREGISTER:
  733. a_load_reg_subsetref(list,fromsize,tosize,tosubsetsize,loc.register,sref);
  734. LOC_CONSTANT:
  735. a_load_const_subsetref(list,tosize,tosubsetsize,loc.value,sref);
  736. { we don't have enough type information to handle these here
  737. LOC_SUBSETREG,LOC_CSUBSETREG:
  738. a_load_subsetreg_subsetref(list,loc.size,subsetsize,loc.sreg,sref);
  739. LOC_SUBSETREF,LOC_CSUBSETREF:
  740. a_load_subsetref_subsetref(list,loc.size,subsetsize,loc.sref,sref);
  741. }
  742. else
  743. internalerror(2010120405);
  744. end;
  745. end;
  746. procedure thlcgobj.a_load_subsetreg_loc(list: TAsmlist; fromsize, fromsubsetsize, tosize: tdef; const sreg: tsubsetregister; const loc: tlocation);
  747. begin
  748. case loc.loc of
  749. LOC_REFERENCE,LOC_CREFERENCE:
  750. a_load_subsetreg_ref(list,fromsize,fromsubsetsize,tosize,sreg,loc.reference);
  751. LOC_REGISTER,LOC_CREGISTER:
  752. a_load_subsetreg_reg(list,fromsize,fromsubsetsize,tosize,sreg,loc.register);
  753. { we don't have enough type information to handle these here
  754. LOC_SUBSETREG,LOC_CSUBSETREG:
  755. a_load_subsetreg_subsetreg(list,subsetsize,loc.size,sreg,loc.sreg);
  756. LOC_SUBSETREF,LOC_CSUBSETREF:
  757. a_load_subsetreg_subsetref(list,subsetsize,loc.size,sreg,loc.sref);
  758. }
  759. else
  760. internalerror(2010120406);
  761. end;
  762. end;
  763. procedure thlcgobj.a_load_subsetref_loc(list: TAsmlist; fromsize, fromsubsetsize, tosize: tdef; const sref: tsubsetreference; const loc: tlocation);
  764. begin
  765. case loc.loc of
  766. LOC_REFERENCE,LOC_CREFERENCE:
  767. a_load_subsetref_ref(list,fromsize,fromsubsetsize,tosize,sref,loc.reference);
  768. LOC_REGISTER,LOC_CREGISTER:
  769. a_load_subsetref_reg(list,fromsize,fromsubsetsize,tosize,sref,loc.register);
  770. { we don't have enough type information to handle these here
  771. LOC_SUBSETREG,LOC_CSUBSETREG:
  772. a_load_subsetref_subsetreg(list,subsetsize,loc.size,sref,loc.sreg);
  773. LOC_SUBSETREF,LOC_CSUBSETREF:
  774. a_load_subsetref_subsetref(list,subsetsize,loc.size,sref,loc.sref);
  775. }
  776. else
  777. internalerror(2010120407);
  778. end;
  779. end;
  780. procedure thlcgobj.a_bit_test_reg_loc_reg(list: TAsmList; bitnumbersize, locsize, destsize: tdef; bitnumber: tregister; const loc: tlocation; destreg: tregister);
  781. var
  782. tmpreg: tregister;
  783. begin
  784. case loc.loc of
  785. LOC_REFERENCE,LOC_CREFERENCE:
  786. a_bit_test_reg_ref_reg(list,bitnumbersize,locsize,destsize,bitnumber,loc.reference,destreg);
  787. LOC_REGISTER,LOC_CREGISTER,
  788. LOC_SUBSETREG,LOC_CSUBSETREG,
  789. LOC_CONSTANT:
  790. begin
  791. case loc.loc of
  792. LOC_REGISTER,LOC_CREGISTER:
  793. tmpreg:=loc.register;
  794. (* we don't have enough type information to handle this here
  795. LOC_SUBSETREG,LOC_CSUBSETREG:
  796. begin
  797. tmpreg:=getintregister(list,loc.size);
  798. a_load_subsetreg_reg(list,loc.size,loc.size,loc.sreg,tmpreg);
  799. end;
  800. *)
  801. LOC_CONSTANT:
  802. begin
  803. tmpreg:=getintregister(list,locsize);
  804. a_load_const_reg(list,locsize,loc.value,tmpreg);
  805. end;
  806. end;
  807. a_bit_test_reg_reg_reg(list,bitnumbersize,locsize,destsize,bitnumber,tmpreg,destreg);
  808. end;
  809. { LOC_SUBSETREF is not possible, because sets are not (yet) bitpacked }
  810. else
  811. internalerror(2010120411);
  812. end;
  813. end;
  814. procedure thlcgobj.a_bit_test_const_loc_reg(list: TAsmList; locsize, destsize: tdef; bitnumber: aint; const loc: tlocation; destreg: tregister);
  815. begin
  816. case loc.loc of
  817. LOC_REFERENCE,LOC_CREFERENCE:
  818. a_bit_test_const_ref_reg(list,locsize,destsize,bitnumber,loc.reference,destreg);
  819. LOC_REGISTER,LOC_CREGISTER:
  820. a_bit_test_const_reg_reg(list,locsize,destsize,bitnumber,loc.register,destreg);
  821. (* we don't have enough type information to handle this here
  822. LOC_SUBSETREG,LOC_CSUBSETREG:
  823. a_bit_test_const_subsetreg_reg(list,loc.size,destsize,bitnumber,loc.sreg,destreg);
  824. *)
  825. { LOC_SUBSETREF is not possible, because sets are not (yet) bitpacked }
  826. else
  827. internalerror(2010120410);
  828. end;
  829. end;
  830. procedure thlcgobj.a_bit_set_reg_loc(list: TAsmList; doset: boolean; fromsize, tosize: tdef; bitnumber: tregister; const loc: tlocation);
  831. begin
  832. case loc.loc of
  833. LOC_REFERENCE:
  834. a_bit_set_reg_ref(list,doset,fromsize,tosize,bitnumber,loc.reference);
  835. LOC_CREGISTER:
  836. a_bit_set_reg_reg(list,doset,fromsize,tosize,bitnumber,loc.register);
  837. (* we don't have enough type information to handle this here
  838. { e.g. a 2-byte set in a record regvar }
  839. LOC_CSUBSETREG:
  840. begin
  841. { hard to do in-place in a generic way, so operate on a copy }
  842. tmpreg:=getintregister(list,loc.size);
  843. a_load_subsetreg_reg(list,loc.size,loc.size,loc.sreg,tmpreg);
  844. a_bit_set_reg_reg(list,doset,bitnumbersize,loc.size,bitnumber,tmpreg);
  845. a_load_reg_subsetreg(list,loc.size,loc.size,tmpreg,loc.sreg);
  846. end;
  847. *)
  848. { LOC_SUBSETREF is not possible, because sets are not (yet) bitpacked }
  849. else
  850. internalerror(2010120408)
  851. end;
  852. end;
  853. procedure thlcgobj.a_bit_set_const_loc(list: TAsmList; doset: boolean; tosize: tdef; bitnumber: aint; const loc: tlocation);
  854. begin
  855. case loc.loc of
  856. LOC_REFERENCE:
  857. a_bit_set_const_ref(list,doset,tosize,bitnumber,loc.reference);
  858. LOC_CREGISTER:
  859. a_bit_set_const_reg(list,doset,tosize,bitnumber,loc.register);
  860. (* we don't have enough type information to handle this here
  861. LOC_CSUBSETREG:
  862. a_bit_set_const_subsetreg(list,doset,loc.size,bitnumber,loc.sreg);
  863. *)
  864. { LOC_SUBSETREF is not possible, because sets are not (yet) bitpacked }
  865. else
  866. internalerror(2010120409)
  867. end;
  868. end;
  869. procedure thlcgobj.a_loadfpu_ref_ref(list: TAsmList; fromsize, tosize: tdef; const ref1, ref2: treference);
  870. var
  871. reg: tregister;
  872. regsize: tdef;
  873. begin
  874. if (fromsize.size>=tosize.size) then
  875. regsize:=fromsize
  876. else
  877. regsize:=tosize;
  878. reg:=getfpuregister(list,regsize);
  879. a_loadfpu_ref_reg(list,fromsize,regsize,ref1,reg);
  880. a_loadfpu_reg_ref(list,regsize,tosize,reg,ref2);
  881. end;
  882. procedure thlcgobj.a_loadfpu_loc_reg(list: TAsmList; fromsize, tosize: tdef; const loc: tlocation; const reg: tregister);
  883. begin
  884. case loc.loc of
  885. LOC_REFERENCE, LOC_CREFERENCE:
  886. a_loadfpu_ref_reg(list,fromsize,tosize,loc.reference,reg);
  887. LOC_FPUREGISTER, LOC_CFPUREGISTER:
  888. a_loadfpu_reg_reg(list,fromsize,tosize,loc.register,reg);
  889. else
  890. internalerror(2010120412);
  891. end;
  892. end;
  893. procedure thlcgobj.a_loadfpu_reg_loc(list: TAsmList; fromsize, tosize: tdef; const reg: tregister; const loc: tlocation);
  894. begin
  895. case loc.loc of
  896. LOC_REFERENCE, LOC_CREFERENCE:
  897. a_loadfpu_reg_ref(list,fromsize,tosize,reg,loc.reference);
  898. LOC_FPUREGISTER, LOC_CFPUREGISTER:
  899. a_loadfpu_reg_reg(list,fromsize,tosize,reg,loc.register);
  900. else
  901. internalerror(2010120413);
  902. end;
  903. end;
  904. procedure thlcgobj.a_loadfpu_reg_cgpara(list: TAsmList; fromsize: tdef; const r: tregister; const cgpara: TCGPara);
  905. var
  906. ref : treference;
  907. begin
  908. paramanager.alloccgpara(list,cgpara);
  909. case cgpara.location^.loc of
  910. LOC_FPUREGISTER,LOC_CFPUREGISTER:
  911. begin
  912. cgpara.check_simple_location;
  913. a_loadfpu_reg_reg(list,fromsize,cgpara.def,r,cgpara.location^.register);
  914. end;
  915. LOC_REFERENCE,LOC_CREFERENCE:
  916. begin
  917. cgpara.check_simple_location;
  918. reference_reset_base(ref,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment);
  919. a_loadfpu_reg_ref(list,fromsize,cgpara.def,r,ref);
  920. end;
  921. LOC_REGISTER,LOC_CREGISTER:
  922. begin
  923. { paramfpu_ref does the check_simpe_location check here if necessary }
  924. tg.gethltemp(list,fromsize,fromsize.size,tt_normal,ref);
  925. a_loadfpu_reg_ref(list,fromsize,fromsize,r,ref);
  926. a_loadfpu_ref_cgpara(list,fromsize,ref,cgpara);
  927. tg.Ungettemp(list,ref);
  928. end;
  929. else
  930. internalerror(2010120422);
  931. end;
  932. end;
  933. procedure thlcgobj.a_loadfpu_ref_cgpara(list: TAsmList; fromsize: tdef; const ref: treference; const cgpara: TCGPara);
  934. var
  935. href : treference;
  936. // hsize: tcgsize;
  937. begin
  938. case cgpara.location^.loc of
  939. LOC_FPUREGISTER,LOC_CFPUREGISTER:
  940. begin
  941. cgpara.check_simple_location;
  942. paramanager.alloccgpara(list,cgpara);
  943. a_loadfpu_ref_reg(list,fromsize,cgpara.def,ref,cgpara.location^.register);
  944. end;
  945. LOC_REFERENCE,LOC_CREFERENCE:
  946. begin
  947. cgpara.check_simple_location;
  948. reference_reset_base(href,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment);
  949. { concatcopy should choose the best way to copy the data }
  950. g_concatcopy(list,fromsize,ref,href);
  951. end;
  952. (* not yet supported
  953. LOC_REGISTER,LOC_CREGISTER:
  954. begin
  955. { force integer size }
  956. hsize:=int_cgsize(tcgsize2size[size]);
  957. {$ifndef cpu64bitalu}
  958. if (hsize in [OS_S64,OS_64]) then
  959. cg64.a_load64_ref_cgpara(list,ref,cgpara)
  960. else
  961. {$endif not cpu64bitalu}
  962. begin
  963. cgpara.check_simple_location;
  964. a_load_ref_cgpara(list,hsize,ref,cgpara)
  965. end;
  966. end
  967. *)
  968. else
  969. internalerror(2010120423);
  970. end;
  971. end;
  972. (*
  973. procedure thlcgobj.a_loadmm_reg_reg(list: TAsmList; fromsize, tosize: tdef; reg1, reg2: tregister; shuffle: pmmshuffle);
  974. begin
  975. cg.a_loadmm_reg_reg(list,def_cgsize(fromsize),def_cgsize(tosize),reg1,reg2,shuffle);
  976. end;
  977. procedure thlcgobj.a_loadmm_ref_reg(list: TAsmList; fromsize, tosize: tdef; const ref: treference; reg: tregister; shuffle: pmmshuffle);
  978. begin
  979. cg.a_loadmm_ref_reg(list,def_cgsize(fromsize),def_cgsize(tosize),ref,reg,shuffle);
  980. end;
  981. procedure thlcgobj.a_loadmm_reg_ref(list: TAsmList; fromsize, tosize: tdef; reg: tregister; const ref: treference; shuffle: pmmshuffle);
  982. begin
  983. cg.a_loadmm_reg_ref(list,def_cgsize(fromsize),def_cgsize(tosize),reg,ref,shuffle);
  984. end;
  985. procedure thlcgobj.a_loadmm_loc_reg(list: TAsmList; fromsize, tosize: tdef; const loc: tlocation; const reg: tregister; shuffle: pmmshuffle);
  986. begin
  987. case loc.loc of
  988. LOC_MMREGISTER,LOC_CMMREGISTER:
  989. a_loadmm_reg_reg(list,fromsize,tosize,loc.register,reg,shuffle);
  990. LOC_REFERENCE,LOC_CREFERENCE:
  991. a_loadmm_ref_reg(list,fromsize,tosize,loc.reference,reg,shuffle);
  992. LOC_REGISTER,LOC_CREGISTER:
  993. a_loadmm_intreg_reg(list,fromsize,tosize,loc.register,reg,shuffle);
  994. else
  995. internalerror(2010120414);
  996. end;
  997. end;
  998. procedure thlcgobj.a_loadmm_reg_loc(list: TAsmList; fromsize, tosize: tdef; const reg: tregister; const loc: tlocation; shuffle: pmmshuffle);
  999. begin
  1000. case loc.loc of
  1001. LOC_MMREGISTER,LOC_CMMREGISTER:
  1002. a_loadmm_reg_reg(list,fromsize,tosize,reg,loc.register,shuffle);
  1003. LOC_REFERENCE,LOC_CREFERENCE:
  1004. a_loadmm_reg_ref(list,fromsize,tosize,reg,loc.reference,shuffle);
  1005. else
  1006. internalerror(2010120415);
  1007. end;
  1008. end;
  1009. procedure thlcgobj.a_loadmm_reg_cgpara(list: TAsmList; fromsize: tdef; reg: tregister; const cgpara: TCGPara; shuffle: pmmshuffle);
  1010. var
  1011. href : treference;
  1012. begin
  1013. cgpara.check_simple_location;
  1014. paramanager.alloccgpara(list,cgpara);
  1015. case cgpara.location^.loc of
  1016. LOC_MMREGISTER,LOC_CMMREGISTER:
  1017. a_loadmm_reg_reg(list,fromsize,cgpara.def,reg,cgpara.location^.register,shuffle);
  1018. LOC_REFERENCE,LOC_CREFERENCE:
  1019. begin
  1020. reference_reset_base(href,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment);
  1021. a_loadmm_reg_ref(list,fromsize,cgpara.def,reg,href,shuffle);
  1022. end;
  1023. LOC_REGISTER,LOC_CREGISTER:
  1024. begin
  1025. if assigned(shuffle) and
  1026. not shufflescalar(shuffle) then
  1027. internalerror(2009112510);
  1028. a_loadmm_reg_intreg(list,deomsize,cgpara.def,reg,cgpara.location^.register,mms_movescalar);
  1029. end
  1030. else
  1031. internalerror(2010120427);
  1032. end;
  1033. end;
  1034. procedure thlcgobj.a_loadmm_ref_cgpara(list: TAsmList; fromsize: tdef; const ref: treference; const cgpara: TCGPara; shuffle: pmmshuffle);
  1035. var
  1036. hr : tregister;
  1037. hs : tmmshuffle;
  1038. begin
  1039. cgpara.check_simple_location;
  1040. hr:=cg.getmmregister(list,cgpara.size);
  1041. a_loadmm_ref_reg(list,deomsize,cgpara.def,ref,hr,shuffle);
  1042. if realshuffle(shuffle) then
  1043. begin
  1044. hs:=shuffle^;
  1045. removeshuffles(hs);
  1046. a_loadmm_reg_cgpara(list,cgpara.def,hr,cgpara,@hs);
  1047. end
  1048. else
  1049. a_loadmm_reg_cgpara(list,cgpara.def,hr,cgpara,shuffle);
  1050. end;
  1051. procedure thlcgobj.a_loadmm_loc_cgpara(list: TAsmList; fromsize: tdef; const loc: tlocation; const cgpara: TCGPara; shuffle: pmmshuffle);
  1052. begin
  1053. {$ifdef extdebug}
  1054. if def_cgsize(fromsize)<>loc.size then
  1055. internalerror(2010112105);
  1056. {$endif}
  1057. cg.a_loadmm_loc_cgpara(list,loc,cgpara,shuffle);
  1058. end;
  1059. procedure thlcgobj.a_opmm_reg_reg(list: TAsmList; Op: TOpCG; size: tdef; src, dst: tregister; shuffle: pmmshuffle);
  1060. begin
  1061. cg.a_opmm_reg_reg(list,op,def_cgsize(size),src,dst,shuffle);
  1062. end;
  1063. procedure thlcgobj.a_opmm_ref_reg(list: TAsmList; Op: TOpCG; size: tdef; const ref: treference; reg: tregister; shuffle: pmmshuffle);
  1064. begin
  1065. cg.a_opmm_ref_reg(list,op,def_cgsize(size),ref,reg,shuffle)
  1066. end;
  1067. procedure thlcgobj.a_opmm_loc_reg(list: TAsmList; Op: TOpCG; size: tdef; const loc: tlocation; reg: tregister; shuffle: pmmshuffle);
  1068. begin
  1069. cg.a_opmm_loc_reg(list,op,def_cgsize(size),loc,reg,shuffle);
  1070. end;
  1071. procedure thlcgobj.a_opmm_reg_ref(list: TAsmList; Op: TOpCG; size: tdef; reg: tregister; const ref: treference; shuffle: pmmshuffle);
  1072. begin
  1073. cg.a_opmm_reg_ref(list,op,def_cgsize(size),reg,ref,shuffle);
  1074. end;
  1075. *)
  1076. (*
  1077. procedure thlcgobj.a_loadmm_intreg_reg(list: TAsmList; fromsize, tosize: tdef; intreg, mmreg: tregister; shuffle: pmmshuffle);
  1078. begin
  1079. cg.a_loadmm_intreg_reg(list,def_cgsize(fromsize),def_cgsize(tosize),intreg,mmreg,shuffle);
  1080. end;
  1081. procedure thlcgobj.a_loadmm_reg_intreg(list: TAsmList; fromsize, tosize: tdef; mmreg, intreg: tregister; shuffle: pmmshuffle);
  1082. begin
  1083. cg.a_loadmm_reg_intreg(list,def_cgsize(fromsize),def_cgsize(tosize),mmreg,intreg,shuffle);
  1084. end;
  1085. *)
  1086. procedure thlcgobj.a_op_const_ref(list: TAsmList; Op: TOpCG; size: tdef; a: Aint; const ref: TReference);
  1087. var
  1088. tmpreg : tregister;
  1089. begin
  1090. tmpreg:=getintregister(list,size);
  1091. a_load_ref_reg(list,size,size,ref,tmpreg);
  1092. a_op_const_reg(list,op,size,a,tmpreg);
  1093. a_load_reg_ref(list,size,size,tmpreg,ref);
  1094. end;
  1095. procedure thlcgobj.a_op_const_subsetreg(list: TAsmList; Op: TOpCG; size, subsetsize: tdef; a: aint; const sreg: tsubsetregister);
  1096. var
  1097. tmpreg: tregister;
  1098. begin
  1099. tmpreg:=getintregister(list,size);
  1100. a_load_subsetreg_reg(list,size,subsetsize,size,sreg,tmpreg);
  1101. a_op_const_reg(list,op,size,a,tmpreg);
  1102. a_load_reg_subsetreg(list,size,size,subsetsize,tmpreg,sreg);
  1103. end;
  1104. procedure thlcgobj.a_op_const_subsetref(list: TAsmList; Op: TOpCG; size, subsetsize: tdef; a: aint; const sref: tsubsetreference);
  1105. var
  1106. tmpreg: tregister;
  1107. begin
  1108. tmpreg:=getintregister(list,size);
  1109. a_load_subsetref_reg(list,size,subsetsize,size,sref,tmpreg);
  1110. a_op_const_reg(list,op,size,a,tmpreg);
  1111. a_load_reg_subsetref(list,size,size,subsetsize,tmpreg,sref);
  1112. end;
  1113. procedure thlcgobj.a_op_const_loc(list: TAsmList; Op: TOpCG; size: tdef; a: Aint; const loc: tlocation);
  1114. begin
  1115. case loc.loc of
  1116. LOC_REGISTER, LOC_CREGISTER:
  1117. a_op_const_reg(list,op,size,a,loc.register);
  1118. LOC_REFERENCE, LOC_CREFERENCE:
  1119. a_op_const_ref(list,op,size,a,loc.reference);
  1120. { we don't have enough type information to handle these here
  1121. LOC_SUBSETREG, LOC_CSUBSETREG:
  1122. a_op_const_subsetreg(list,op,loc.size,loc.size,a,loc.sreg);
  1123. LOC_SUBSETREF, LOC_CSUBSETREF:
  1124. a_op_const_subsetref(list,op,loc.size,loc.size,a,loc.sref);
  1125. }
  1126. else
  1127. internalerror(2010120428);
  1128. end;
  1129. end;
  1130. procedure thlcgobj.a_op_reg_ref(list: TAsmList; Op: TOpCG; size: tdef; reg: TRegister; const ref: TReference);
  1131. var
  1132. tmpreg: tregister;
  1133. begin
  1134. case op of
  1135. OP_NOT,OP_NEG:
  1136. { handle it as "load ref,reg; op reg" }
  1137. begin
  1138. a_load_ref_reg(list,size,size,ref,reg);
  1139. a_op_reg_reg(list,op,size,reg,reg);
  1140. end;
  1141. else
  1142. begin
  1143. tmpreg:=getintregister(list,size);
  1144. a_load_ref_reg(list,size,size,ref,tmpreg);
  1145. a_op_reg_reg(list,op,size,tmpreg,reg);
  1146. end;
  1147. end;
  1148. end;
  1149. procedure thlcgobj.a_op_ref_reg(list: TAsmList; Op: TOpCG; size: tdef; const ref: TReference; reg: TRegister);
  1150. var
  1151. tmpreg: tregister;
  1152. begin
  1153. case op of
  1154. OP_NOT,OP_NEG:
  1155. { handle it as "load ref,reg; op reg" }
  1156. begin
  1157. a_load_ref_reg(list,size,size,ref,reg);
  1158. a_op_reg_reg(list,op,size,reg,reg);
  1159. end;
  1160. else
  1161. begin
  1162. tmpreg:=getintregister(list,size);
  1163. a_load_ref_reg(list,size,size,ref,tmpreg);
  1164. a_op_reg_reg(list,op,size,tmpreg,reg);
  1165. end;
  1166. end;
  1167. end;
  1168. procedure thlcgobj.a_op_reg_subsetreg(list: TAsmList; Op: TOpCG; opsize, destsize, destsubsetsize: tdef; reg: TRegister; const sreg: tsubsetregister);
  1169. var
  1170. tmpreg: tregister;
  1171. begin
  1172. tmpreg:=getintregister(list,opsize);
  1173. a_load_subsetreg_reg(list,destsize,destsubsetsize,opsize,sreg,tmpreg);
  1174. a_op_reg_reg(list,op,opsize,reg,tmpreg);
  1175. a_load_reg_subsetreg(list,opsize,destsize,destsubsetsize,tmpreg,sreg);
  1176. end;
  1177. procedure thlcgobj.a_op_reg_subsetref(list: TAsmList; Op: TOpCG; opsize, destsize, destsubsetsize: tdef; reg: TRegister; const sref: tsubsetreference);
  1178. var
  1179. tmpreg: tregister;
  1180. begin
  1181. tmpreg:=getintregister(list,opsize);
  1182. a_load_subsetref_reg(list,destsize,destsubsetsize,opsize,sref,tmpreg);
  1183. a_op_reg_reg(list,op,opsize,reg,tmpreg);
  1184. a_load_reg_subsetref(list,opsize,destsize,destsubsetsize,tmpreg,sref);
  1185. end;
  1186. procedure thlcgobj.a_op_reg_loc(list: TAsmList; Op: TOpCG; size: tdef; reg: tregister; const loc: tlocation);
  1187. begin
  1188. case loc.loc of
  1189. LOC_REGISTER, LOC_CREGISTER:
  1190. a_op_reg_reg(list,op,size,reg,loc.register);
  1191. LOC_REFERENCE, LOC_CREFERENCE:
  1192. a_op_reg_ref(list,op,size,reg,loc.reference);
  1193. { we don't have enough type information to handle these here
  1194. LOC_SUBSETREG, LOC_CSUBSETREG:
  1195. a_op_reg_subsetreg(list,op,loc.size,loc.size,reg,loc.sreg);
  1196. LOC_SUBSETREF, LOC_CSUBSETREF:
  1197. a_op_reg_subsetref(list,op,loc.size,loc.size,reg,loc.sref);
  1198. }
  1199. else
  1200. internalerror(2010120429);
  1201. end;
  1202. end;
  1203. procedure thlcgobj.a_op_ref_loc(list: TAsmList; Op: TOpCG; size: tdef; const ref: TReference; const loc: tlocation);
  1204. var
  1205. tmpreg: tregister;
  1206. begin
  1207. case loc.loc of
  1208. LOC_REGISTER,LOC_CREGISTER:
  1209. a_op_ref_reg(list,op,size,ref,loc.register);
  1210. LOC_REFERENCE,LOC_CREFERENCE:
  1211. begin
  1212. tmpreg:=getintregister(list,size);
  1213. a_load_ref_reg(list,size,size,ref,tmpreg);
  1214. a_op_reg_ref(list,op,size,tmpreg,loc.reference);
  1215. end;
  1216. { we don't have enough type information to handle these here
  1217. LOC_SUBSETREG, LOC_CSUBSETREG:
  1218. begin
  1219. tmpreg:=getintregister(list,loc.size);
  1220. a_load_subsetreg_reg(list,loc.size,loc.size,loc.sreg,tmpreg);
  1221. a_op_ref_reg(list,op,loc.size,ref,tmpreg);
  1222. a_load_reg_subsetreg(list,loc.size,loc.size,tmpreg,loc.sreg);
  1223. end;
  1224. LOC_SUBSETREF, LOC_CSUBSETREF:
  1225. begin
  1226. tmpreg:=getintregister(list,loc.size);
  1227. a_load_subsetreF_reg(list,loc.size,loc.size,loc.sref,tmpreg);
  1228. a_op_ref_reg(list,op,loc.size,ref,tmpreg);
  1229. a_load_reg_subsetref(list,loc.size,loc.size,tmpreg,loc.sref);
  1230. end;
  1231. }
  1232. else
  1233. internalerror(2010120429);
  1234. end;
  1235. end;
  1236. procedure thlcgobj.a_op_const_reg_reg(list: TAsmList; op: TOpCg; size: tdef; a: aint; src, dst: tregister);
  1237. begin
  1238. a_load_reg_reg(list,size,size,src,dst);
  1239. a_op_const_reg(list,op,size,a,dst);
  1240. end;
  1241. procedure thlcgobj.a_op_reg_reg_reg(list: TAsmList; op: TOpCg; size: tdef; src1, src2, dst: tregister);
  1242. var
  1243. tmpreg: tregister;
  1244. begin
  1245. if (dst<>src1) then
  1246. begin
  1247. a_load_reg_reg(list,size,size,src2,dst);
  1248. a_op_reg_reg(list,op,size,src1,dst);
  1249. end
  1250. else
  1251. begin
  1252. { can we do a direct operation on the target register ? }
  1253. if op in [OP_ADD,OP_MUL,OP_AND,OP_MOVE,OP_XOR,OP_IMUL,OP_OR] then
  1254. a_op_reg_reg(list,op,size,src2,dst)
  1255. else
  1256. begin
  1257. tmpreg:=getintregister(list,size);
  1258. a_load_reg_reg(list,size,size,src2,tmpreg);
  1259. a_op_reg_reg(list,op,size,src1,tmpreg);
  1260. a_load_reg_reg(list,size,size,tmpreg,dst);
  1261. end;
  1262. end;
  1263. end;
  1264. procedure thlcgobj.a_op_const_reg_reg_checkoverflow(list: TAsmList; op: TOpCg; size: tdef; a: aint; src, dst: tregister; setflags: boolean; var ovloc: tlocation);
  1265. begin
  1266. if not setflags then
  1267. a_op_const_reg_reg(list,op,size,a,src,dst)
  1268. else
  1269. internalerror(2010122910);
  1270. end;
  1271. procedure thlcgobj.a_op_reg_reg_reg_checkoverflow(list: TAsmList; op: TOpCg; size: tdef; src1, src2, dst: tregister; setflags: boolean; var ovloc: tlocation);
  1272. begin
  1273. if not setflags then
  1274. a_op_reg_reg_reg(list,op,size,src1,src2,dst)
  1275. else
  1276. internalerror(2010122911);
  1277. end;
  1278. procedure thlcgobj.a_cmp_const_reg_label(list: TAsmList; size: tdef; cmp_op: topcmp; a: aint; reg: tregister; l: tasmlabel);
  1279. var
  1280. tmpreg: tregister;
  1281. begin
  1282. tmpreg:=getintregister(list,size);
  1283. a_load_const_reg(list,size,a,tmpreg);
  1284. a_cmp_reg_reg_label(list,size,cmp_op,tmpreg,reg,l);
  1285. end;
  1286. procedure thlcgobj.a_cmp_const_ref_label(list: TAsmList; size: tdef; cmp_op: topcmp; a: aint; const ref: treference; l: tasmlabel);
  1287. var
  1288. tmpreg: tregister;
  1289. begin
  1290. tmpreg:=getintregister(list,size);
  1291. a_load_ref_reg(list,size,size,ref,tmpreg);
  1292. a_cmp_const_reg_label(list,size,cmp_op,a,tmpreg,l);
  1293. end;
  1294. procedure thlcgobj.a_cmp_const_loc_label(list: TAsmList; size: tdef; cmp_op: topcmp; a: aint; const loc: tlocation; l: tasmlabel);
  1295. begin
  1296. case loc.loc of
  1297. LOC_REGISTER,LOC_CREGISTER:
  1298. a_cmp_const_reg_label(list,size,cmp_op,a,loc.register,l);
  1299. LOC_REFERENCE,LOC_CREFERENCE:
  1300. a_cmp_const_ref_label(list,size,cmp_op,a,loc.reference,l);
  1301. { we don't have enough type information to handle these here
  1302. LOC_SUBSETREG, LOC_CSUBSETREG:
  1303. begin
  1304. tmpreg:=getintregister(list,size);
  1305. a_load_subsetreg_reg(list,loc.size,size,loc.sreg,tmpreg);
  1306. a_cmp_const_reg_label(list,size,cmp_op,a,tmpreg,l);
  1307. end;
  1308. LOC_SUBSETREF, LOC_CSUBSETREF:
  1309. begin
  1310. tmpreg:=getintregister(list,size);
  1311. a_load_subsetref_reg(list,loc.size,size,loc.sref,tmpreg);
  1312. a_cmp_const_reg_label(list,size,cmp_op,a,tmpreg,l);
  1313. end;
  1314. }
  1315. else
  1316. internalerror(2010120430);
  1317. end;
  1318. end;
  1319. procedure thlcgobj.a_cmp_ref_reg_label(list: TAsmList; size: tdef; cmp_op: topcmp; const ref: treference; reg: tregister; 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,tmpreg,reg,l);
  1326. end;
  1327. procedure thlcgobj.a_cmp_reg_ref_label(list: TAsmList; size: tdef; cmp_op: topcmp; reg: tregister; const ref: treference; l: tasmlabel);
  1328. var
  1329. tmpreg: tregister;
  1330. begin
  1331. tmpreg:=getintregister(list,size);
  1332. a_load_ref_reg(list,size,size,ref,tmpreg);
  1333. a_cmp_reg_reg_label(list,size,cmp_op,reg,tmpreg,l);
  1334. end;
  1335. procedure thlcgobj.a_cmp_subsetreg_reg_label(list: TAsmList; fromsize, fromsubsetsize, cmpsize: tdef; cmp_op: topcmp; const sreg: tsubsetregister; reg: tregister; l: tasmlabel);
  1336. var
  1337. tmpreg: tregister;
  1338. begin
  1339. tmpreg:=getintregister(list,cmpsize);
  1340. a_load_subsetreg_reg(list,fromsize,fromsubsetsize,cmpsize,sreg,tmpreg);
  1341. a_cmp_reg_reg_label(list,cmpsize,cmp_op,tmpreg,reg,l);
  1342. end;
  1343. procedure thlcgobj.a_cmp_subsetref_reg_label(list: TAsmList; fromsize, fromsubsetsize, cmpsize: tdef; cmp_op: topcmp; const sref: tsubsetreference; reg: tregister; l: tasmlabel);
  1344. var
  1345. tmpreg: tregister;
  1346. begin
  1347. tmpreg:=getintregister(list,cmpsize);
  1348. a_load_subsetref_reg(list,fromsize,fromsubsetsize,cmpsize,sref,tmpreg);
  1349. a_cmp_reg_reg_label(list,cmpsize,cmp_op,tmpreg,reg,l);
  1350. end;
  1351. procedure thlcgobj.a_cmp_loc_reg_label(list: TAsmList; size: tdef; cmp_op: topcmp; const loc: tlocation; reg: tregister; l: tasmlabel);
  1352. begin
  1353. case loc.loc of
  1354. LOC_REGISTER,
  1355. LOC_CREGISTER:
  1356. a_cmp_reg_reg_label(list,size,cmp_op,loc.register,reg,l);
  1357. LOC_REFERENCE,
  1358. LOC_CREFERENCE :
  1359. a_cmp_ref_reg_label(list,size,cmp_op,loc.reference,reg,l);
  1360. LOC_CONSTANT:
  1361. a_cmp_const_reg_label(list,size,cmp_op,loc.value,reg,l);
  1362. { we don't have enough type information to handle these here
  1363. LOC_SUBSETREG,
  1364. LOC_CSUBSETREG:
  1365. a_cmp_subsetreg_reg_label(list,loc.size,size,cmp_op,loc.sreg,reg,l);
  1366. LOC_SUBSETREF,
  1367. LOC_CSUBSETREF:
  1368. a_cmp_subsetref_reg_label(list,loc.size,size,cmp_op,loc.sref,reg,l);
  1369. }
  1370. else
  1371. internalerror(2010120431);
  1372. end;
  1373. end;
  1374. procedure thlcgobj.a_cmp_reg_loc_label(list: TAsmList; size: tdef; cmp_op: topcmp; reg: tregister; const loc: tlocation; l: tasmlabel);
  1375. begin
  1376. a_cmp_loc_reg_label(list,size,swap_opcmp(cmp_op),loc,reg,l);
  1377. end;
  1378. procedure thlcgobj.a_cmp_ref_loc_label(list: TAsmList; size: tdef; cmp_op: topcmp; const ref: treference; const loc: tlocation; l: tasmlabel);
  1379. var
  1380. tmpreg: tregister;
  1381. begin
  1382. case loc.loc of
  1383. LOC_REGISTER,LOC_CREGISTER:
  1384. a_cmp_ref_reg_label(list,size,cmp_op,ref,loc.register,l);
  1385. LOC_REFERENCE,LOC_CREFERENCE:
  1386. begin
  1387. tmpreg:=getintregister(list,size);
  1388. a_load_ref_reg(list,size,size,loc.reference,tmpreg);
  1389. a_cmp_ref_reg_label(list,size,cmp_op,ref,tmpreg,l);
  1390. end;
  1391. LOC_CONSTANT:
  1392. begin
  1393. a_cmp_const_ref_label(list,size,swap_opcmp(cmp_op),loc.value,ref,l);
  1394. end
  1395. { we don't have enough type information to handle these here
  1396. LOC_SUBSETREG, LOC_CSUBSETREG:
  1397. begin
  1398. tmpreg:=getintregister(list, size);
  1399. a_load_ref_reg(list,size,size,loc.reference,tmpreg);
  1400. a_cmp_subsetreg_reg_label(list,loc.size,size,swap_opcmp(cmp_op),loc.sreg,tmpreg,l);
  1401. end;
  1402. LOC_SUBSETREF, LOC_CSUBSETREF:
  1403. begin
  1404. tmpreg:=getintregister(list, size);
  1405. a_load_ref_reg(list,size,size,loc.reference,tmpreg);
  1406. a_cmp_subsetref_reg_label(list,loc.size,size,swap_opcmp(cmp_op),loc.sref,tmpreg,l);
  1407. end;
  1408. }
  1409. else
  1410. internalerror(2010120432);
  1411. end;
  1412. end;
  1413. procedure thlcgobj.g_concatcopy(list: TAsmList; size: tdef; const source, dest: treference);
  1414. begin
  1415. {
  1416. if use_vectorfpu(size) then
  1417. a_loadmm_ref_ref()
  1418. else
  1419. }
  1420. if size.typ<>floatdef then
  1421. a_load_ref_ref(list,size,size,source,dest)
  1422. else
  1423. a_loadfpu_ref_ref(list,size,size,source,dest);
  1424. end;
  1425. procedure thlcgobj.g_concatcopy_unaligned(list: TAsmList; size: tdef; const source, dest: treference);
  1426. begin
  1427. g_concatcopy(list,size,source,dest);
  1428. end;
  1429. procedure thlcgobj.g_rangecheck(list: TAsmList; const l: tlocation; fromdef, todef: tdef);
  1430. begin
  1431. if not(cs_check_range in current_settings.localswitches) then
  1432. exit;
  1433. internalerror(2011010610);
  1434. end;
  1435. procedure thlcgobj.g_profilecode(list: TAsmList);
  1436. begin
  1437. end;
  1438. procedure thlcgobj.location_force_reg(list: TAsmList; var l: tlocation; src_size, dst_size: tdef; maybeconst: boolean);
  1439. var
  1440. hregister,
  1441. hregister2: tregister;
  1442. hl : tasmlabel;
  1443. oldloc : tlocation;
  1444. begin
  1445. oldloc:=l;
  1446. hregister:=getregisterfordef(list,dst_size);
  1447. { load value in new register }
  1448. case l.loc of
  1449. {$ifdef cpuflags}
  1450. LOC_FLAGS :
  1451. cg.g_flags2reg(list,def_cgsize(dst_size),l.resflags,hregister);
  1452. {$endif cpuflags}
  1453. LOC_JUMP :
  1454. begin
  1455. a_label(list,current_procinfo.CurrTrueLabel);
  1456. a_load_const_reg(list,dst_size,1,hregister);
  1457. current_asmdata.getjumplabel(hl);
  1458. a_jmp_always(list,hl);
  1459. a_label(list,current_procinfo.CurrFalseLabel);
  1460. a_load_const_reg(list,dst_size,0,hregister);
  1461. a_label(list,hl);
  1462. end;
  1463. else
  1464. begin
  1465. { load_loc_reg can only handle size >= l.size, when the
  1466. new size is smaller then we need to adjust the size
  1467. of the orignal and maybe recalculate l.register for i386 }
  1468. if (dst_size.size<src_size.size) then
  1469. begin
  1470. hregister2:=getregisterfordef(list,src_size);
  1471. { prevent problems with memory locations -- at this high
  1472. level we cannot twiddle with the reference offset, since
  1473. that may not mean anything (e.g., it refers to fixed-sized
  1474. stack slots on Java) }
  1475. a_load_loc_reg(list,src_size,src_size,l,hregister2);
  1476. a_load_reg_reg(list,src_size,dst_size,hregister2,hregister);
  1477. end
  1478. else
  1479. a_load_loc_reg(list,src_size,dst_size,l,hregister);
  1480. end;
  1481. end;
  1482. if (l.loc <> LOC_CREGISTER) or
  1483. not maybeconst then
  1484. location_reset(l,LOC_REGISTER,def_cgsize(dst_size))
  1485. else
  1486. location_reset(l,LOC_CREGISTER,def_cgsize(dst_size));
  1487. l.register:=hregister;
  1488. { Release temp if it was a reference }
  1489. if oldloc.loc=LOC_REFERENCE then
  1490. location_freetemp(list,oldloc);
  1491. end;
  1492. procedure thlcgobj.location_force_fpureg(list: TAsmList; var l: tlocation; size: tdef; maybeconst: boolean);
  1493. var
  1494. reg : tregister;
  1495. href : treference;
  1496. begin
  1497. if (l.loc<>LOC_FPUREGISTER) and
  1498. ((l.loc<>LOC_CFPUREGISTER) or (not maybeconst)) then
  1499. begin
  1500. { if it's in an mm register, store to memory first }
  1501. if (l.loc in [LOC_MMREGISTER,LOC_CMMREGISTER]) then
  1502. internalerror(2011012903);
  1503. reg:=getfpuregister(list,size);
  1504. a_loadfpu_loc_reg(list,size,size,l,reg);
  1505. location_freetemp(list,l);
  1506. location_reset(l,LOC_FPUREGISTER,l.size);
  1507. l.register:=reg;
  1508. end;
  1509. end;
  1510. procedure thlcgobj.location_force_mem(list: TAsmList; var l: tlocation; size: tdef);
  1511. var
  1512. r : treference;
  1513. begin
  1514. case l.loc of
  1515. LOC_FPUREGISTER,
  1516. LOC_CFPUREGISTER :
  1517. begin
  1518. tg.gethltemp(list,size,size.size,tt_normal,r);
  1519. hlcg.a_loadfpu_reg_ref(list,size,size,l.register,r);
  1520. location_reset_ref(l,LOC_REFERENCE,l.size,0);
  1521. l.reference:=r;
  1522. end;
  1523. (*
  1524. LOC_MMREGISTER,
  1525. LOC_CMMREGISTER:
  1526. begin
  1527. tg.gethltemp(list,size,size.size,tt_normal,r);
  1528. cg.a_loadmm_reg_ref(list,l.size,l.size,l.register,r,mms_movescalar);
  1529. location_reset_ref(l,LOC_REFERENCE,l.size,0);
  1530. l.reference:=r;
  1531. end;
  1532. *)
  1533. LOC_CONSTANT,
  1534. LOC_REGISTER,
  1535. LOC_CREGISTER :
  1536. begin
  1537. tg.gethltemp(list,size,size.size,tt_normal,r);
  1538. hlcg.a_load_loc_ref(list,size,size,l,r);
  1539. location_reset_ref(l,LOC_REFERENCE,l.size,0);
  1540. l.reference:=r;
  1541. end;
  1542. (*
  1543. LOC_SUBSETREG,
  1544. LOC_CSUBSETREG,
  1545. LOC_SUBSETREF,
  1546. LOC_CSUBSETREF:
  1547. begin
  1548. tg.gethltemp(list,size,size.size,tt_normal,r);
  1549. cg.a_load_loc_ref(list,l.size,l,r);
  1550. location_reset_ref(l,LOC_REFERENCE,l.size,0);
  1551. l.reference:=r;
  1552. end;
  1553. *)
  1554. LOC_CREFERENCE,
  1555. LOC_REFERENCE : ;
  1556. else
  1557. internalerror(2011010304);
  1558. end;
  1559. end;
  1560. procedure thlcgobj.maketojumpbool(list: TAsmList; p: tnode);
  1561. {
  1562. produces jumps to true respectively false labels using boolean expressions
  1563. depending on whether the loading of regvars is currently being
  1564. synchronized manually (such as in an if-node) or automatically (most of
  1565. the other cases where this procedure is called), loadregvars can be
  1566. "lr_load_regvars" or "lr_dont_load_regvars"
  1567. }
  1568. var
  1569. storepos : tfileposinfo;
  1570. begin
  1571. if nf_error in p.flags then
  1572. exit;
  1573. storepos:=current_filepos;
  1574. current_filepos:=p.fileinfo;
  1575. if is_boolean(p.resultdef) then
  1576. begin
  1577. if is_constboolnode(p) then
  1578. begin
  1579. if Tordconstnode(p).value.uvalue<>0 then
  1580. a_jmp_always(list,current_procinfo.CurrTrueLabel)
  1581. else
  1582. a_jmp_always(list,current_procinfo.CurrFalseLabel)
  1583. end
  1584. else
  1585. begin
  1586. case p.location.loc of
  1587. (*
  1588. LOC_SUBSETREG,LOC_CSUBSETREG,
  1589. LOC_SUBSETREF,LOC_CSUBSETREF:
  1590. begin
  1591. tmpreg := cg.getintregister(list,OS_INT);
  1592. cg.a_load_loc_reg(list,OS_INT,p.location,tmpreg);
  1593. cg.a_cmp_const_reg_label(list,OS_INT,OC_NE,0,tmpreg,current_procinfo.CurrTrueLabel);
  1594. cg.a_jmp_always(list,current_procinfo.CurrFalseLabel);
  1595. end;
  1596. *)
  1597. LOC_CREGISTER,LOC_REGISTER,LOC_CREFERENCE,LOC_REFERENCE :
  1598. begin
  1599. a_cmp_const_loc_label(list,p.resultdef,OC_NE,0,p.location,current_procinfo.CurrTrueLabel);
  1600. a_jmp_always(list,current_procinfo.CurrFalseLabel);
  1601. end;
  1602. LOC_JUMP:
  1603. ;
  1604. {$ifdef cpuflags}
  1605. LOC_FLAGS :
  1606. begin
  1607. a_jmp_flags(list,p.location.resflags,current_procinfo.CurrTrueLabel);
  1608. a_jmp_always(list,current_procinfo.CurrFalseLabel);
  1609. end;
  1610. {$endif cpuflags}
  1611. else
  1612. begin
  1613. printnode(output,p);
  1614. internalerror(2011010418);
  1615. end;
  1616. end;
  1617. end;
  1618. end
  1619. else
  1620. internalerror(2011010419);
  1621. current_filepos:=storepos;
  1622. end;
  1623. procedure thlcgobj.gen_proc_symbol(list: TAsmList);
  1624. var
  1625. item,
  1626. previtem : TCmdStrListItem;
  1627. begin
  1628. previtem:=nil;
  1629. item := TCmdStrListItem(current_procinfo.procdef.aliasnames.first);
  1630. while assigned(item) do
  1631. begin
  1632. {$ifdef arm}
  1633. if current_settings.cputype in cpu_thumb2 then
  1634. list.concat(tai_thumb_func.create);
  1635. {$endif arm}
  1636. { "double link" all procedure entry symbols via .reference }
  1637. { directives on darwin, because otherwise the linker }
  1638. { sometimes strips the procedure if only on of the symbols }
  1639. { is referenced }
  1640. if assigned(previtem) and
  1641. (target_info.system in systems_darwin) then
  1642. list.concat(tai_directive.create(asd_reference,item.str));
  1643. if (cs_profile in current_settings.moduleswitches) or
  1644. (po_global in current_procinfo.procdef.procoptions) then
  1645. list.concat(Tai_symbol.createname_global(item.str,AT_FUNCTION,0))
  1646. else
  1647. list.concat(Tai_symbol.createname(item.str,AT_FUNCTION,0));
  1648. if assigned(previtem) and
  1649. (target_info.system in systems_darwin) then
  1650. list.concat(tai_directive.create(asd_reference,previtem.str));
  1651. if not(af_stabs_use_function_absolute_addresses in target_asm.flags) then
  1652. list.concat(Tai_function_name.create(item.str));
  1653. previtem:=item;
  1654. item := TCmdStrListItem(item.next);
  1655. end;
  1656. current_procinfo.procdef.procstarttai:=tai(list.last);
  1657. end;
  1658. procedure thlcgobj.gen_proc_symbol_end(list: TAsmList);
  1659. begin
  1660. list.concat(Tai_symbol_end.Createname(current_procinfo.procdef.mangledname));
  1661. current_procinfo.procdef.procendtai:=tai(list.last);
  1662. if (current_module.islibrary) then
  1663. if (current_procinfo.procdef.proctypeoption = potype_proginit) then
  1664. { setinitname may generate a new section -> don't add to the
  1665. current list, because we assume this remains a text section }
  1666. exportlib.setinitname(current_asmdata.AsmLists[al_exports],current_procinfo.procdef.mangledname);
  1667. if (current_procinfo.procdef.proctypeoption=potype_proginit) then
  1668. begin
  1669. if (target_info.system in (systems_darwin+[system_powerpc_macos])) and
  1670. not(current_module.islibrary) then
  1671. begin
  1672. new_section(list,sec_code,'',4);
  1673. list.concat(tai_symbol.createname_global(
  1674. target_info.cprefix+mainaliasname,AT_FUNCTION,0));
  1675. { keep argc, argv and envp properly on the stack }
  1676. cg.a_jmp_name(list,target_info.cprefix+'FPC_SYSTEMMAIN');
  1677. end;
  1678. end;
  1679. end;
  1680. { generates the code for incrementing the reference count of parameters and
  1681. initialize out parameters }
  1682. procedure init_paras(p:TObject;arg:pointer);
  1683. var
  1684. href : treference;
  1685. tmpreg : tregister;
  1686. list : TAsmList;
  1687. needs_inittable (*,
  1688. do_trashing *) : boolean;
  1689. begin
  1690. list:=TAsmList(arg);
  1691. if (tsym(p).typ=paravarsym) then
  1692. begin
  1693. needs_inittable:=is_managed_type(tparavarsym(p).vardef);
  1694. (*
  1695. do_trashing:=
  1696. (localvartrashing <> -1) and
  1697. (not assigned(tparavarsym(p).defaultconstsym)) and
  1698. not needs_inittable;
  1699. *)
  1700. case tparavarsym(p).varspez of
  1701. vs_value :
  1702. if needs_inittable then
  1703. begin
  1704. { variants are already handled by the call to fpc_variant_copy_overwrite if
  1705. they are passed by reference }
  1706. if not((tparavarsym(p).vardef.typ=variantdef) and
  1707. paramanager.push_addr_param(tparavarsym(p).varspez,tparavarsym(p).vardef,current_procinfo.procdef.proccalloption)) then
  1708. begin
  1709. location_get_data_ref(list,tparavarsym(p).initialloc,href,is_open_array(tparavarsym(p).vardef),sizeof(pint));
  1710. hlcg.g_incrrefcount(list,tparavarsym(p).vardef,href);
  1711. end;
  1712. end;
  1713. vs_out :
  1714. begin
  1715. if needs_inittable (*or
  1716. do_trashing*) then
  1717. begin
  1718. tmpreg:=cg.getaddressregister(list);
  1719. hlcg.a_load_loc_reg(list,tparavarsym(p).vardef,tparavarsym(p).vardef,tparavarsym(p).initialloc,tmpreg);
  1720. { we have no idea about the alignment at the callee side,
  1721. and the user also cannot specify "unaligned" here, so
  1722. assume worst case }
  1723. reference_reset_base(href,tmpreg,0,1);
  1724. (*
  1725. if do_trashing and
  1726. { needs separate implementation to trash open arrays }
  1727. { since their size is only known at run time }
  1728. not is_special_array(tparavarsym(p).vardef) then
  1729. { may be an open string, even if is_open_string() returns }
  1730. { false (for some helpers in the system unit) }
  1731. if not is_shortstring(tparavarsym(p).vardef) then
  1732. trash_reference(list,href,tparavarsym(p).vardef.size)
  1733. else
  1734. trash_reference(list,href,2);
  1735. *)
  1736. if needs_inittable then
  1737. hlcg.g_initialize(list,tparavarsym(p).vardef,href);
  1738. end;
  1739. end;
  1740. (*
  1741. else if do_trashing and
  1742. ([vo_is_funcret,vo_is_hidden_para] * tparavarsym(p).varoptions = [vo_is_funcret,vo_is_hidden_para]) then
  1743. begin
  1744. tmpreg:=cg.getaddressregister(list);
  1745. a_load_loc_reg(list,tparavarsym(p).vardef,tparavarsym(p).vardef,tparavarsym(p).initialloc,tmpreg);
  1746. { should always have standard alignment. If a function is assigned
  1747. to a non-aligned variable, the optimisation to pass this variable
  1748. directly as hidden function result must/cannot be performed
  1749. (see tcallnode.funcret_can_be_reused)
  1750. }
  1751. reference_reset_base(href,tmpreg,0,
  1752. used_align(tparavarsym(p).vardef.alignment,current_settings.alignment.localalignmin,current_settings.alignment.localalignmax));
  1753. { may be an open string, even if is_open_string() returns }
  1754. { false (for some helpers in the system unit) }
  1755. if not is_shortstring(tparavarsym(p).vardef) then
  1756. trash_reference(list,href,tparavarsym(p).vardef.size)
  1757. else
  1758. { an open string has at least size 2 }
  1759. trash_reference(list,href,2);
  1760. end
  1761. *)
  1762. end;
  1763. end;
  1764. end;
  1765. procedure thlcgobj.gen_load_para_value(list: TAsmList);
  1766. var
  1767. i: longint;
  1768. currpara: tparavarsym;
  1769. begin
  1770. if (po_assembler in current_procinfo.procdef.procoptions) then
  1771. exit;
  1772. { Copy parameters to local references/registers }
  1773. for i:=0 to current_procinfo.procdef.paras.count-1 do
  1774. begin
  1775. currpara:=tparavarsym(current_procinfo.procdef.paras[i]);
  1776. gen_load_cgpara_loc(list,currpara.vardef,currpara.paraloc[calleeside],currpara.initialloc,paramanager.param_use_paraloc(currpara.paraloc[calleeside]));
  1777. end;
  1778. { generate copies of call by value parameters, must be done before
  1779. the initialization and body is parsed because the refcounts are
  1780. incremented using the local copies }
  1781. // current_procinfo.procdef.parast.SymList.ForEachCall(@copyvalueparas,list);
  1782. if not(po_assembler in current_procinfo.procdef.procoptions) then
  1783. begin
  1784. { has to be done here rather than in gen_initialize_code, because
  1785. the initialisation code is generated a) later and b) with
  1786. rad_backwards, so the register allocator would generate
  1787. information as if this code comes before loading the parameters
  1788. from their original registers to their local location }
  1789. // if (localvartrashing <> -1) then
  1790. // current_procinfo.procdef.localst.SymList.ForEachCall(@trash_variable,list);
  1791. { initialize refcounted paras, and trash others. Needed here
  1792. instead of in gen_initialize_code, because when a reference is
  1793. intialised or trashed while the pointer to that reference is kept
  1794. in a regvar, we add a register move and that one again has to
  1795. come after the parameter loading code as far as the register
  1796. allocator is concerned }
  1797. current_procinfo.procdef.parast.SymList.ForEachCall(@init_paras,list);
  1798. end;
  1799. end;
  1800. procedure thlcgobj.gen_loadfpu_loc_cgpara(list: TAsmList; size: tdef; const l: tlocation; const cgpara: tcgpara; locintsize: longint);
  1801. begin
  1802. case l.loc of
  1803. (*
  1804. LOC_MMREGISTER,
  1805. LOC_CMMREGISTER:
  1806. case cgpara.location^.loc of
  1807. LOC_REFERENCE,
  1808. LOC_CREFERENCE,
  1809. LOC_MMREGISTER,
  1810. LOC_CMMREGISTER,
  1811. LOC_REGISTER,
  1812. LOC_CREGISTER :
  1813. cg.a_loadmm_reg_cgpara(list,locsize,l.register,cgpara,mms_movescalar);
  1814. LOC_FPUREGISTER,
  1815. LOC_CFPUREGISTER:
  1816. begin
  1817. tmploc:=l;
  1818. location_force_fpureg(list,tmploc,false);
  1819. cg.a_loadfpu_reg_cgpara(list,tmploc.size,tmploc.register,cgpara);
  1820. end;
  1821. else
  1822. internalerror(200204249);
  1823. end;
  1824. *)
  1825. LOC_FPUREGISTER,
  1826. LOC_CFPUREGISTER:
  1827. case cgpara.location^.loc of
  1828. (*
  1829. LOC_MMREGISTER,
  1830. LOC_CMMREGISTER:
  1831. begin
  1832. tmploc:=l;
  1833. location_force_mmregscalar(list,tmploc,false);
  1834. cg.a_loadmm_reg_cgpara(list,tmploc.size,tmploc.register,cgpara,mms_movescalar);
  1835. end;
  1836. *)
  1837. { Some targets pass floats in normal registers }
  1838. LOC_REGISTER,
  1839. LOC_CREGISTER,
  1840. LOC_REFERENCE,
  1841. LOC_CREFERENCE,
  1842. LOC_FPUREGISTER,
  1843. LOC_CFPUREGISTER:
  1844. hlcg.a_loadfpu_reg_cgpara(list,size,l.register,cgpara);
  1845. else
  1846. internalerror(2011010210);
  1847. end;
  1848. LOC_REFERENCE,
  1849. LOC_CREFERENCE:
  1850. case cgpara.location^.loc of
  1851. (*
  1852. LOC_MMREGISTER,
  1853. LOC_CMMREGISTER:
  1854. cg.a_loadmm_ref_cgpara(list,locsize,l.reference,cgpara,mms_movescalar);
  1855. *)
  1856. { Some targets pass floats in normal registers }
  1857. LOC_REGISTER,
  1858. LOC_CREGISTER,
  1859. LOC_REFERENCE,
  1860. LOC_CREFERENCE,
  1861. LOC_FPUREGISTER,
  1862. LOC_CFPUREGISTER:
  1863. hlcg.a_loadfpu_ref_cgpara(list,size,l.reference,cgpara);
  1864. else
  1865. internalerror(2011010211);
  1866. end;
  1867. LOC_REGISTER,
  1868. LOC_CREGISTER :
  1869. hlcg.a_load_loc_cgpara(list,size,l,cgpara);
  1870. else
  1871. internalerror(2011010212);
  1872. end;
  1873. end;
  1874. procedure thlcgobj.gen_load_uninitialized_function_result(list: TAsmList; pd: tprocdef; resdef: tdef; const resloc: tcgpara);
  1875. begin
  1876. { do nothing by default }
  1877. end;
  1878. procedure thlcgobj.gen_load_loc_cgpara(list: TAsmList; vardef: tdef; const l: tlocation; const cgpara: tcgpara);
  1879. begin
  1880. { Handle Floating point types differently
  1881. This doesn't depend on emulator settings, emulator settings should
  1882. be handled by cpupara }
  1883. if (vardef.typ=floatdef) or
  1884. { some ABIs return certain records in an fpu register }
  1885. (l.loc in [LOC_FPUREGISTER,LOC_CFPUREGISTER]) or
  1886. (assigned(cgpara.location) and
  1887. (cgpara.Location^.loc in [LOC_FPUREGISTER,LOC_CFPUREGISTER])) then
  1888. begin
  1889. gen_loadfpu_loc_cgpara(list,vardef,l,cgpara,vardef.size);
  1890. exit;
  1891. end;
  1892. case l.loc of
  1893. LOC_CONSTANT,
  1894. LOC_REGISTER,
  1895. LOC_CREGISTER,
  1896. LOC_REFERENCE,
  1897. LOC_CREFERENCE :
  1898. begin
  1899. hlcg.a_load_loc_cgpara(list,vardef,l,cgpara);
  1900. end;
  1901. (*
  1902. LOC_MMREGISTER,
  1903. LOC_CMMREGISTER:
  1904. begin
  1905. case l.size of
  1906. OS_F32,
  1907. OS_F64:
  1908. cg.a_loadmm_loc_cgpara(list,l,cgpara,mms_movescalar);
  1909. else
  1910. cg.a_loadmm_loc_cgpara(list,l,cgpara,nil);
  1911. end;
  1912. end;
  1913. *)
  1914. else
  1915. internalerror(2011010213);
  1916. end;
  1917. end;
  1918. procedure thlcgobj.gen_load_cgpara_loc(list: TAsmList; vardef: tdef; const para: TCGPara; var destloc: tlocation; reusepara: boolean);
  1919. var
  1920. href : treference;
  1921. begin
  1922. para.check_simple_location;
  1923. { skip e.g. empty records }
  1924. if (para.location^.loc = LOC_VOID) then
  1925. exit;
  1926. case destloc.loc of
  1927. LOC_REFERENCE :
  1928. begin
  1929. { If the parameter location is reused we don't need to copy
  1930. anything }
  1931. if not reusepara then
  1932. begin
  1933. reference_reset_base(href,para.location^.reference.index,para.location^.reference.offset,para.alignment);
  1934. a_load_ref_ref(list,para.def,para.def,href,destloc.reference);
  1935. end;
  1936. end;
  1937. { TODO other possible locations }
  1938. else
  1939. internalerror(2011010308);
  1940. end;
  1941. end;
  1942. procedure thlcgobj.gen_load_return_value(list: TAsmList);
  1943. var
  1944. ressym : tabstractnormalvarsym;
  1945. funcretloc : TCGPara;
  1946. begin
  1947. { Is the loading needed? }
  1948. if is_void(current_procinfo.procdef.returndef) or
  1949. (
  1950. (po_assembler in current_procinfo.procdef.procoptions) and
  1951. (not(assigned(current_procinfo.procdef.funcretsym)) or
  1952. (tabstractvarsym(current_procinfo.procdef.funcretsym).refs=0))
  1953. ) then
  1954. exit;
  1955. funcretloc:=current_procinfo.procdef.funcretloc[calleeside];
  1956. { constructors return self }
  1957. if (current_procinfo.procdef.proctypeoption=potype_constructor) then
  1958. ressym:=tabstractnormalvarsym(current_procinfo.procdef.parast.Find('self'))
  1959. else
  1960. ressym:=tabstractnormalvarsym(current_procinfo.procdef.funcretsym);
  1961. if (ressym.refs>0) or
  1962. is_managed_type(ressym.vardef) then
  1963. begin
  1964. { was: don't do anything if funcretloc.loc in [LOC_INVALID,LOC_REFERENCE] }
  1965. if not paramanager.ret_in_param(current_procinfo.procdef.returndef,current_procinfo.procdef.proccalloption) then
  1966. hlcg.gen_load_loc_cgpara(list,ressym.vardef,ressym.localloc,funcretloc);
  1967. end
  1968. else
  1969. gen_load_uninitialized_function_result(list,current_procinfo.procdef,ressym.vardef,funcretloc)
  1970. end;
  1971. procedure thlcgobj.record_generated_code_for_procdef(pd: tprocdef; code, data: TAsmList);
  1972. begin
  1973. { add the procedure to the al_procedures }
  1974. maybe_new_object_file(current_asmdata.asmlists[al_procedures]);
  1975. new_section(current_asmdata.asmlists[al_procedures],sec_code,lower(pd.mangledname),getprocalign);
  1976. current_asmdata.asmlists[al_procedures].concatlist(code);
  1977. { save local data (casetable) also in the same file }
  1978. if assigned(data) and
  1979. (not data.empty) then
  1980. current_asmdata.asmlists[al_procedures].concatlist(data);
  1981. end;
  1982. end.