hlcgobj.pas 88 KB

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