hlcgobj.pas 88 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026
  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. var
  823. tmpreg: tregister;
  824. begin
  825. case loc.loc of
  826. LOC_REFERENCE:
  827. a_bit_set_reg_ref(list,doset,fromsize,tosize,bitnumber,loc.reference);
  828. LOC_CREGISTER:
  829. a_bit_set_reg_reg(list,doset,fromsize,tosize,bitnumber,loc.register);
  830. (* we don't have enough type information to handle this here
  831. { e.g. a 2-byte set in a record regvar }
  832. LOC_CSUBSETREG:
  833. begin
  834. { hard to do in-place in a generic way, so operate on a copy }
  835. tmpreg:=getintregister(list,loc.size);
  836. a_load_subsetreg_reg(list,loc.size,loc.size,loc.sreg,tmpreg);
  837. a_bit_set_reg_reg(list,doset,bitnumbersize,loc.size,bitnumber,tmpreg);
  838. a_load_reg_subsetreg(list,loc.size,loc.size,tmpreg,loc.sreg);
  839. end;
  840. *)
  841. { LOC_SUBSETREF is not possible, because sets are not (yet) bitpacked }
  842. else
  843. internalerror(2010120408)
  844. end;
  845. end;
  846. procedure thlcgobj.a_bit_set_const_loc(list: TAsmList; doset: boolean; tosize: tdef; bitnumber: aint; const loc: tlocation);
  847. begin
  848. case loc.loc of
  849. LOC_REFERENCE:
  850. a_bit_set_const_ref(list,doset,tosize,bitnumber,loc.reference);
  851. LOC_CREGISTER:
  852. a_bit_set_const_reg(list,doset,tosize,bitnumber,loc.register);
  853. (* we don't have enough type information to handle this here
  854. LOC_CSUBSETREG:
  855. a_bit_set_const_subsetreg(list,doset,loc.size,bitnumber,loc.sreg);
  856. *)
  857. { LOC_SUBSETREF is not possible, because sets are not (yet) bitpacked }
  858. else
  859. internalerror(2010120409)
  860. end;
  861. end;
  862. procedure thlcgobj.a_loadfpu_ref_ref(list: TAsmList; fromsize, tosize: tdef; const ref1, ref2: treference);
  863. var
  864. reg: tregister;
  865. regsize: tdef;
  866. begin
  867. if (fromsize.size>=tosize.size) then
  868. regsize:=fromsize
  869. else
  870. regsize:=tosize;
  871. reg:=getfpuregister(list,regsize);
  872. a_loadfpu_ref_reg(list,fromsize,regsize,ref1,reg);
  873. a_loadfpu_reg_ref(list,regsize,tosize,reg,ref2);
  874. end;
  875. procedure thlcgobj.a_loadfpu_loc_reg(list: TAsmList; fromsize, tosize: tdef; const loc: tlocation; const reg: tregister);
  876. begin
  877. case loc.loc of
  878. LOC_REFERENCE, LOC_CREFERENCE:
  879. a_loadfpu_ref_reg(list,fromsize,tosize,loc.reference,reg);
  880. LOC_FPUREGISTER, LOC_CFPUREGISTER:
  881. a_loadfpu_reg_reg(list,fromsize,tosize,loc.register,reg);
  882. else
  883. internalerror(2010120412);
  884. end;
  885. end;
  886. procedure thlcgobj.a_loadfpu_reg_loc(list: TAsmList; fromsize, tosize: tdef; const reg: tregister; const loc: tlocation);
  887. begin
  888. case loc.loc of
  889. LOC_REFERENCE, LOC_CREFERENCE:
  890. a_loadfpu_reg_ref(list,fromsize,tosize,reg,loc.reference);
  891. LOC_FPUREGISTER, LOC_CFPUREGISTER:
  892. a_loadfpu_reg_reg(list,fromsize,tosize,reg,loc.register);
  893. else
  894. internalerror(2010120413);
  895. end;
  896. end;
  897. procedure thlcgobj.a_loadfpu_reg_cgpara(list: TAsmList; fromsize: tdef; const r: tregister; const cgpara: TCGPara);
  898. var
  899. ref : treference;
  900. begin
  901. paramanager.alloccgpara(list,cgpara);
  902. case cgpara.location^.loc of
  903. LOC_FPUREGISTER,LOC_CFPUREGISTER:
  904. begin
  905. cgpara.check_simple_location;
  906. a_loadfpu_reg_reg(list,fromsize,cgpara.def,r,cgpara.location^.register);
  907. end;
  908. LOC_REFERENCE,LOC_CREFERENCE:
  909. begin
  910. cgpara.check_simple_location;
  911. reference_reset_base(ref,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment);
  912. a_loadfpu_reg_ref(list,fromsize,cgpara.def,r,ref);
  913. end;
  914. LOC_REGISTER,LOC_CREGISTER:
  915. begin
  916. { paramfpu_ref does the check_simpe_location check here if necessary }
  917. tg.GetTemp(list,fromsize.size,fromsize.alignment,tt_normal,ref);
  918. a_loadfpu_reg_ref(list,fromsize,fromsize,r,ref);
  919. a_loadfpu_ref_cgpara(list,fromsize,ref,cgpara);
  920. tg.Ungettemp(list,ref);
  921. end;
  922. else
  923. internalerror(2010120422);
  924. end;
  925. end;
  926. procedure thlcgobj.a_loadfpu_ref_cgpara(list: TAsmList; fromsize: tdef; const ref: treference; const cgpara: TCGPara);
  927. var
  928. href : treference;
  929. // hsize: tcgsize;
  930. begin
  931. case cgpara.location^.loc of
  932. LOC_FPUREGISTER,LOC_CFPUREGISTER:
  933. begin
  934. cgpara.check_simple_location;
  935. paramanager.alloccgpara(list,cgpara);
  936. a_loadfpu_ref_reg(list,fromsize,cgpara.def,ref,cgpara.location^.register);
  937. end;
  938. LOC_REFERENCE,LOC_CREFERENCE:
  939. begin
  940. cgpara.check_simple_location;
  941. reference_reset_base(href,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment);
  942. { concatcopy should choose the best way to copy the data }
  943. g_concatcopy(list,fromsize,ref,href);
  944. end;
  945. (* not yet supported
  946. LOC_REGISTER,LOC_CREGISTER:
  947. begin
  948. { force integer size }
  949. hsize:=int_cgsize(tcgsize2size[size]);
  950. {$ifndef cpu64bitalu}
  951. if (hsize in [OS_S64,OS_64]) then
  952. cg64.a_load64_ref_cgpara(list,ref,cgpara)
  953. else
  954. {$endif not cpu64bitalu}
  955. begin
  956. cgpara.check_simple_location;
  957. a_load_ref_cgpara(list,hsize,ref,cgpara)
  958. end;
  959. end
  960. *)
  961. else
  962. internalerror(2010120423);
  963. end;
  964. end;
  965. (*
  966. procedure thlcgobj.a_loadmm_reg_reg(list: TAsmList; fromsize, tosize: tdef; reg1, reg2: tregister; shuffle: pmmshuffle);
  967. begin
  968. cg.a_loadmm_reg_reg(list,def_cgsize(fromsize),def_cgsize(tosize),reg1,reg2,shuffle);
  969. end;
  970. procedure thlcgobj.a_loadmm_ref_reg(list: TAsmList; fromsize, tosize: tdef; const ref: treference; reg: tregister; shuffle: pmmshuffle);
  971. begin
  972. cg.a_loadmm_ref_reg(list,def_cgsize(fromsize),def_cgsize(tosize),ref,reg,shuffle);
  973. end;
  974. procedure thlcgobj.a_loadmm_reg_ref(list: TAsmList; fromsize, tosize: tdef; reg: tregister; const ref: treference; shuffle: pmmshuffle);
  975. begin
  976. cg.a_loadmm_reg_ref(list,def_cgsize(fromsize),def_cgsize(tosize),reg,ref,shuffle);
  977. end;
  978. procedure thlcgobj.a_loadmm_loc_reg(list: TAsmList; fromsize, tosize: tdef; const loc: tlocation; const reg: tregister; shuffle: pmmshuffle);
  979. begin
  980. case loc.loc of
  981. LOC_MMREGISTER,LOC_CMMREGISTER:
  982. a_loadmm_reg_reg(list,fromsize,tosize,loc.register,reg,shuffle);
  983. LOC_REFERENCE,LOC_CREFERENCE:
  984. a_loadmm_ref_reg(list,fromsize,tosize,loc.reference,reg,shuffle);
  985. LOC_REGISTER,LOC_CREGISTER:
  986. a_loadmm_intreg_reg(list,fromsize,tosize,loc.register,reg,shuffle);
  987. else
  988. internalerror(2010120414);
  989. end;
  990. end;
  991. procedure thlcgobj.a_loadmm_reg_loc(list: TAsmList; fromsize, tosize: tdef; const reg: tregister; const loc: tlocation; shuffle: pmmshuffle);
  992. begin
  993. case loc.loc of
  994. LOC_MMREGISTER,LOC_CMMREGISTER:
  995. a_loadmm_reg_reg(list,fromsize,tosize,reg,loc.register,shuffle);
  996. LOC_REFERENCE,LOC_CREFERENCE:
  997. a_loadmm_reg_ref(list,fromsize,tosize,reg,loc.reference,shuffle);
  998. else
  999. internalerror(2010120415);
  1000. end;
  1001. end;
  1002. procedure thlcgobj.a_loadmm_reg_cgpara(list: TAsmList; fromsize: tdef; reg: tregister; const cgpara: TCGPara; shuffle: pmmshuffle);
  1003. var
  1004. href : treference;
  1005. begin
  1006. cgpara.check_simple_location;
  1007. paramanager.alloccgpara(list,cgpara);
  1008. case cgpara.location^.loc of
  1009. LOC_MMREGISTER,LOC_CMMREGISTER:
  1010. a_loadmm_reg_reg(list,fromsize,cgpara.def,reg,cgpara.location^.register,shuffle);
  1011. LOC_REFERENCE,LOC_CREFERENCE:
  1012. begin
  1013. reference_reset_base(href,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment);
  1014. a_loadmm_reg_ref(list,fromsize,cgpara.def,reg,href,shuffle);
  1015. end;
  1016. LOC_REGISTER,LOC_CREGISTER:
  1017. begin
  1018. if assigned(shuffle) and
  1019. not shufflescalar(shuffle) then
  1020. internalerror(2009112510);
  1021. a_loadmm_reg_intreg(list,deomsize,cgpara.def,reg,cgpara.location^.register,mms_movescalar);
  1022. end
  1023. else
  1024. internalerror(2010120427);
  1025. end;
  1026. end;
  1027. procedure thlcgobj.a_loadmm_ref_cgpara(list: TAsmList; fromsize: tdef; const ref: treference; const cgpara: TCGPara; shuffle: pmmshuffle);
  1028. var
  1029. hr : tregister;
  1030. hs : tmmshuffle;
  1031. begin
  1032. cgpara.check_simple_location;
  1033. hr:=cg.getmmregister(list,cgpara.size);
  1034. a_loadmm_ref_reg(list,deomsize,cgpara.def,ref,hr,shuffle);
  1035. if realshuffle(shuffle) then
  1036. begin
  1037. hs:=shuffle^;
  1038. removeshuffles(hs);
  1039. a_loadmm_reg_cgpara(list,cgpara.def,hr,cgpara,@hs);
  1040. end
  1041. else
  1042. a_loadmm_reg_cgpara(list,cgpara.def,hr,cgpara,shuffle);
  1043. end;
  1044. procedure thlcgobj.a_loadmm_loc_cgpara(list: TAsmList; fromsize: tdef; const loc: tlocation; const cgpara: TCGPara; shuffle: pmmshuffle);
  1045. begin
  1046. {$ifdef extdebug}
  1047. if def_cgsize(fromsize)<>loc.size then
  1048. internalerror(2010112105);
  1049. {$endif}
  1050. cg.a_loadmm_loc_cgpara(list,loc,cgpara,shuffle);
  1051. end;
  1052. procedure thlcgobj.a_opmm_reg_reg(list: TAsmList; Op: TOpCG; size: tdef; src, dst: tregister; shuffle: pmmshuffle);
  1053. begin
  1054. cg.a_opmm_reg_reg(list,op,def_cgsize(size),src,dst,shuffle);
  1055. end;
  1056. procedure thlcgobj.a_opmm_ref_reg(list: TAsmList; Op: TOpCG; size: tdef; const ref: treference; reg: tregister; shuffle: pmmshuffle);
  1057. begin
  1058. cg.a_opmm_ref_reg(list,op,def_cgsize(size),ref,reg,shuffle)
  1059. end;
  1060. procedure thlcgobj.a_opmm_loc_reg(list: TAsmList; Op: TOpCG; size: tdef; const loc: tlocation; reg: tregister; shuffle: pmmshuffle);
  1061. begin
  1062. cg.a_opmm_loc_reg(list,op,def_cgsize(size),loc,reg,shuffle);
  1063. end;
  1064. procedure thlcgobj.a_opmm_reg_ref(list: TAsmList; Op: TOpCG; size: tdef; reg: tregister; const ref: treference; shuffle: pmmshuffle);
  1065. begin
  1066. cg.a_opmm_reg_ref(list,op,def_cgsize(size),reg,ref,shuffle);
  1067. end;
  1068. *)
  1069. (*
  1070. procedure thlcgobj.a_loadmm_intreg_reg(list: TAsmList; fromsize, tosize: tdef; intreg, mmreg: tregister; shuffle: pmmshuffle);
  1071. begin
  1072. cg.a_loadmm_intreg_reg(list,def_cgsize(fromsize),def_cgsize(tosize),intreg,mmreg,shuffle);
  1073. end;
  1074. procedure thlcgobj.a_loadmm_reg_intreg(list: TAsmList; fromsize, tosize: tdef; mmreg, intreg: tregister; shuffle: pmmshuffle);
  1075. begin
  1076. cg.a_loadmm_reg_intreg(list,def_cgsize(fromsize),def_cgsize(tosize),mmreg,intreg,shuffle);
  1077. end;
  1078. *)
  1079. procedure thlcgobj.a_op_const_ref(list: TAsmList; Op: TOpCG; size: tdef; a: Aint; const ref: TReference);
  1080. var
  1081. tmpreg : tregister;
  1082. begin
  1083. tmpreg:=getintregister(list,size);
  1084. a_load_ref_reg(list,size,size,ref,tmpreg);
  1085. a_op_const_reg(list,op,size,a,tmpreg);
  1086. a_load_reg_ref(list,size,size,tmpreg,ref);
  1087. end;
  1088. procedure thlcgobj.a_op_const_subsetreg(list: TAsmList; Op: TOpCG; size, subsetsize: tdef; a: aint; const sreg: tsubsetregister);
  1089. var
  1090. tmpreg: tregister;
  1091. begin
  1092. tmpreg:=getintregister(list,size);
  1093. a_load_subsetreg_reg(list,size,subsetsize,size,sreg,tmpreg);
  1094. a_op_const_reg(list,op,size,a,tmpreg);
  1095. a_load_reg_subsetreg(list,size,size,subsetsize,tmpreg,sreg);
  1096. end;
  1097. procedure thlcgobj.a_op_const_subsetref(list: TAsmList; Op: TOpCG; size, subsetsize: tdef; a: aint; const sref: tsubsetreference);
  1098. var
  1099. tmpreg: tregister;
  1100. begin
  1101. tmpreg:=getintregister(list,size);
  1102. a_load_subsetref_reg(list,size,subsetsize,size,sref,tmpreg);
  1103. a_op_const_reg(list,op,size,a,tmpreg);
  1104. a_load_reg_subsetref(list,size,size,subsetsize,tmpreg,sref);
  1105. end;
  1106. procedure thlcgobj.a_op_const_loc(list: TAsmList; Op: TOpCG; size: tdef; a: Aint; const loc: tlocation);
  1107. begin
  1108. case loc.loc of
  1109. LOC_REGISTER, LOC_CREGISTER:
  1110. a_op_const_reg(list,op,size,a,loc.register);
  1111. LOC_REFERENCE, LOC_CREFERENCE:
  1112. a_op_const_ref(list,op,size,a,loc.reference);
  1113. { we don't have enough type information to handle these here
  1114. LOC_SUBSETREG, LOC_CSUBSETREG:
  1115. a_op_const_subsetreg(list,op,loc.size,loc.size,a,loc.sreg);
  1116. LOC_SUBSETREF, LOC_CSUBSETREF:
  1117. a_op_const_subsetref(list,op,loc.size,loc.size,a,loc.sref);
  1118. }
  1119. else
  1120. internalerror(2010120428);
  1121. end;
  1122. end;
  1123. procedure thlcgobj.a_op_reg_ref(list: TAsmList; Op: TOpCG; size: tdef; reg: TRegister; const ref: TReference);
  1124. var
  1125. tmpreg: tregister;
  1126. begin
  1127. case op of
  1128. OP_NOT,OP_NEG:
  1129. { handle it as "load ref,reg; op reg" }
  1130. begin
  1131. a_load_ref_reg(list,size,size,ref,reg);
  1132. a_op_reg_reg(list,op,size,reg,reg);
  1133. end;
  1134. else
  1135. begin
  1136. tmpreg:=getintregister(list,size);
  1137. a_load_ref_reg(list,size,size,ref,tmpreg);
  1138. a_op_reg_reg(list,op,size,tmpreg,reg);
  1139. end;
  1140. end;
  1141. end;
  1142. procedure thlcgobj.a_op_ref_reg(list: TAsmList; Op: TOpCG; size: tdef; const ref: TReference; reg: TRegister);
  1143. var
  1144. tmpreg: tregister;
  1145. begin
  1146. case op of
  1147. OP_NOT,OP_NEG:
  1148. { handle it as "load ref,reg; op reg" }
  1149. begin
  1150. a_load_ref_reg(list,size,size,ref,reg);
  1151. a_op_reg_reg(list,op,size,reg,reg);
  1152. end;
  1153. else
  1154. begin
  1155. tmpreg:=getintregister(list,size);
  1156. a_load_ref_reg(list,size,size,ref,tmpreg);
  1157. a_op_reg_reg(list,op,size,tmpreg,reg);
  1158. end;
  1159. end;
  1160. end;
  1161. procedure thlcgobj.a_op_reg_subsetreg(list: TAsmList; Op: TOpCG; opsize, destsize, destsubsetsize: tdef; reg: TRegister; const sreg: tsubsetregister);
  1162. var
  1163. tmpreg: tregister;
  1164. begin
  1165. tmpreg:=getintregister(list,opsize);
  1166. a_load_subsetreg_reg(list,destsize,destsubsetsize,opsize,sreg,tmpreg);
  1167. a_op_reg_reg(list,op,opsize,reg,tmpreg);
  1168. a_load_reg_subsetreg(list,opsize,destsize,destsubsetsize,tmpreg,sreg);
  1169. end;
  1170. procedure thlcgobj.a_op_reg_subsetref(list: TAsmList; Op: TOpCG; opsize, destsize, destsubsetsize: tdef; reg: TRegister; const sref: tsubsetreference);
  1171. var
  1172. tmpreg: tregister;
  1173. begin
  1174. tmpreg:=getintregister(list,opsize);
  1175. a_load_subsetref_reg(list,destsize,destsubsetsize,opsize,sref,tmpreg);
  1176. a_op_reg_reg(list,op,opsize,reg,tmpreg);
  1177. a_load_reg_subsetref(list,opsize,destsize,destsubsetsize,tmpreg,sref);
  1178. end;
  1179. procedure thlcgobj.a_op_reg_loc(list: TAsmList; Op: TOpCG; size: tdef; reg: tregister; const loc: tlocation);
  1180. begin
  1181. case loc.loc of
  1182. LOC_REGISTER, LOC_CREGISTER:
  1183. a_op_reg_reg(list,op,size,reg,loc.register);
  1184. LOC_REFERENCE, LOC_CREFERENCE:
  1185. a_op_reg_ref(list,op,size,reg,loc.reference);
  1186. { we don't have enough type information to handle these here
  1187. LOC_SUBSETREG, LOC_CSUBSETREG:
  1188. a_op_reg_subsetreg(list,op,loc.size,loc.size,reg,loc.sreg);
  1189. LOC_SUBSETREF, LOC_CSUBSETREF:
  1190. a_op_reg_subsetref(list,op,loc.size,loc.size,reg,loc.sref);
  1191. }
  1192. else
  1193. internalerror(2010120429);
  1194. end;
  1195. end;
  1196. procedure thlcgobj.a_op_ref_loc(list: TAsmList; Op: TOpCG; size: tdef; const ref: TReference; const loc: tlocation);
  1197. var
  1198. tmpreg: tregister;
  1199. begin
  1200. case loc.loc of
  1201. LOC_REGISTER,LOC_CREGISTER:
  1202. a_op_ref_reg(list,op,size,ref,loc.register);
  1203. LOC_REFERENCE,LOC_CREFERENCE:
  1204. begin
  1205. tmpreg:=getintregister(list,size);
  1206. a_load_ref_reg(list,size,size,ref,tmpreg);
  1207. a_op_reg_ref(list,op,size,tmpreg,loc.reference);
  1208. end;
  1209. { we don't have enough type information to handle these here
  1210. LOC_SUBSETREG, LOC_CSUBSETREG:
  1211. begin
  1212. tmpreg:=getintregister(list,loc.size);
  1213. a_load_subsetreg_reg(list,loc.size,loc.size,loc.sreg,tmpreg);
  1214. a_op_ref_reg(list,op,loc.size,ref,tmpreg);
  1215. a_load_reg_subsetreg(list,loc.size,loc.size,tmpreg,loc.sreg);
  1216. end;
  1217. LOC_SUBSETREF, LOC_CSUBSETREF:
  1218. begin
  1219. tmpreg:=getintregister(list,loc.size);
  1220. a_load_subsetreF_reg(list,loc.size,loc.size,loc.sref,tmpreg);
  1221. a_op_ref_reg(list,op,loc.size,ref,tmpreg);
  1222. a_load_reg_subsetref(list,loc.size,loc.size,tmpreg,loc.sref);
  1223. end;
  1224. }
  1225. else
  1226. internalerror(2010120429);
  1227. end;
  1228. end;
  1229. procedure thlcgobj.a_op_const_reg_reg(list: TAsmList; op: TOpCg; size: tdef; a: aint; src, dst: tregister);
  1230. begin
  1231. a_load_reg_reg(list,size,size,src,dst);
  1232. a_op_const_reg(list,op,size,a,dst);
  1233. end;
  1234. procedure thlcgobj.a_op_reg_reg_reg(list: TAsmList; op: TOpCg; size: tdef; src1, src2, dst: tregister);
  1235. var
  1236. tmpreg: tregister;
  1237. begin
  1238. if (dst<>src1) then
  1239. begin
  1240. a_load_reg_reg(list,size,size,src2,dst);
  1241. a_op_reg_reg(list,op,size,src1,dst);
  1242. end
  1243. else
  1244. begin
  1245. { can we do a direct operation on the target register ? }
  1246. if op in [OP_ADD,OP_MUL,OP_AND,OP_MOVE,OP_XOR,OP_IMUL,OP_OR] then
  1247. a_op_reg_reg(list,op,size,src2,dst)
  1248. else
  1249. begin
  1250. tmpreg:=getintregister(list,size);
  1251. a_load_reg_reg(list,size,size,src2,tmpreg);
  1252. a_op_reg_reg(list,op,size,src1,tmpreg);
  1253. a_load_reg_reg(list,size,size,tmpreg,dst);
  1254. end;
  1255. end;
  1256. end;
  1257. procedure thlcgobj.a_op_const_reg_reg_checkoverflow(list: TAsmList; op: TOpCg; size: tdef; a: aint; src, dst: tregister; setflags: boolean; var ovloc: tlocation);
  1258. begin
  1259. if not setflags then
  1260. a_op_const_reg_reg(list,op,size,a,src,dst)
  1261. else
  1262. internalerror(2010122910);
  1263. end;
  1264. procedure thlcgobj.a_op_reg_reg_reg_checkoverflow(list: TAsmList; op: TOpCg; size: tdef; src1, src2, dst: tregister; setflags: boolean; var ovloc: tlocation);
  1265. begin
  1266. if not setflags then
  1267. a_op_reg_reg_reg(list,op,size,src1,src2,dst)
  1268. else
  1269. internalerror(2010122911);
  1270. end;
  1271. procedure thlcgobj.a_cmp_const_reg_label(list: TAsmList; size: tdef; cmp_op: topcmp; a: aint; reg: tregister; l: tasmlabel);
  1272. var
  1273. tmpreg: tregister;
  1274. begin
  1275. tmpreg:=getintregister(list,size);
  1276. a_load_const_reg(list,size,a,tmpreg);
  1277. a_cmp_reg_reg_label(list,size,cmp_op,tmpreg,reg,l);
  1278. end;
  1279. procedure thlcgobj.a_cmp_const_ref_label(list: TAsmList; size: tdef; cmp_op: topcmp; a: aint; const ref: treference; l: tasmlabel);
  1280. var
  1281. tmpreg: tregister;
  1282. begin
  1283. tmpreg:=getintregister(list,size);
  1284. a_load_ref_reg(list,size,size,ref,tmpreg);
  1285. a_cmp_const_reg_label(list,size,cmp_op,a,tmpreg,l);
  1286. end;
  1287. procedure thlcgobj.a_cmp_const_loc_label(list: TAsmList; size: tdef; cmp_op: topcmp; a: aint; const loc: tlocation; l: tasmlabel);
  1288. var
  1289. tmpreg : tregister;
  1290. begin
  1291. case loc.loc of
  1292. LOC_REGISTER,LOC_CREGISTER:
  1293. a_cmp_const_reg_label(list,size,cmp_op,a,loc.register,l);
  1294. LOC_REFERENCE,LOC_CREFERENCE:
  1295. a_cmp_const_ref_label(list,size,cmp_op,a,loc.reference,l);
  1296. { we don't have enough type information to handle these here
  1297. LOC_SUBSETREG, LOC_CSUBSETREG:
  1298. begin
  1299. tmpreg:=getintregister(list,size);
  1300. a_load_subsetreg_reg(list,loc.size,size,loc.sreg,tmpreg);
  1301. a_cmp_const_reg_label(list,size,cmp_op,a,tmpreg,l);
  1302. end;
  1303. LOC_SUBSETREF, LOC_CSUBSETREF:
  1304. begin
  1305. tmpreg:=getintregister(list,size);
  1306. a_load_subsetref_reg(list,loc.size,size,loc.sref,tmpreg);
  1307. a_cmp_const_reg_label(list,size,cmp_op,a,tmpreg,l);
  1308. end;
  1309. }
  1310. else
  1311. internalerror(2010120430);
  1312. end;
  1313. end;
  1314. procedure thlcgobj.a_cmp_ref_reg_label(list: TAsmList; size: tdef; cmp_op: topcmp; const ref: treference; reg: tregister; l: tasmlabel);
  1315. var
  1316. tmpreg: tregister;
  1317. begin
  1318. tmpreg:=getintregister(list,size);
  1319. a_load_ref_reg(list,size,size,ref,tmpreg);
  1320. a_cmp_reg_reg_label(list,size,cmp_op,tmpreg,reg,l);
  1321. end;
  1322. procedure thlcgobj.a_cmp_reg_ref_label(list: TAsmList; size: tdef; cmp_op: topcmp; reg: tregister; const ref: treference; l: tasmlabel);
  1323. var
  1324. tmpreg: tregister;
  1325. begin
  1326. tmpreg:=getintregister(list,size);
  1327. a_load_ref_reg(list,size,size,ref,tmpreg);
  1328. a_cmp_reg_reg_label(list,size,cmp_op,reg,tmpreg,l);
  1329. end;
  1330. procedure thlcgobj.a_cmp_subsetreg_reg_label(list: TAsmList; fromsize, fromsubsetsize, cmpsize: tdef; cmp_op: topcmp; const sreg: tsubsetregister; reg: tregister; l: tasmlabel);
  1331. var
  1332. tmpreg: tregister;
  1333. begin
  1334. tmpreg:=getintregister(list,cmpsize);
  1335. a_load_subsetreg_reg(list,fromsize,fromsubsetsize,cmpsize,sreg,tmpreg);
  1336. a_cmp_reg_reg_label(list,cmpsize,cmp_op,tmpreg,reg,l);
  1337. end;
  1338. procedure thlcgobj.a_cmp_subsetref_reg_label(list: TAsmList; fromsize, fromsubsetsize, cmpsize: tdef; cmp_op: topcmp; const sref: tsubsetreference; reg: tregister; l: tasmlabel);
  1339. var
  1340. tmpreg: tregister;
  1341. begin
  1342. tmpreg:=getintregister(list,cmpsize);
  1343. a_load_subsetref_reg(list,fromsize,fromsubsetsize,cmpsize,sref,tmpreg);
  1344. a_cmp_reg_reg_label(list,cmpsize,cmp_op,tmpreg,reg,l);
  1345. end;
  1346. procedure thlcgobj.a_cmp_loc_reg_label(list: TAsmList; size: tdef; cmp_op: topcmp; const loc: tlocation; reg: tregister; l: tasmlabel);
  1347. begin
  1348. case loc.loc of
  1349. LOC_REGISTER,
  1350. LOC_CREGISTER:
  1351. a_cmp_reg_reg_label(list,size,cmp_op,loc.register,reg,l);
  1352. LOC_REFERENCE,
  1353. LOC_CREFERENCE :
  1354. a_cmp_ref_reg_label(list,size,cmp_op,loc.reference,reg,l);
  1355. LOC_CONSTANT:
  1356. a_cmp_const_reg_label(list,size,cmp_op,loc.value,reg,l);
  1357. { we don't have enough type information to handle these here
  1358. LOC_SUBSETREG,
  1359. LOC_CSUBSETREG:
  1360. a_cmp_subsetreg_reg_label(list,loc.size,size,cmp_op,loc.sreg,reg,l);
  1361. LOC_SUBSETREF,
  1362. LOC_CSUBSETREF:
  1363. a_cmp_subsetref_reg_label(list,loc.size,size,cmp_op,loc.sref,reg,l);
  1364. }
  1365. else
  1366. internalerror(2010120431);
  1367. end;
  1368. end;
  1369. procedure thlcgobj.a_cmp_reg_loc_label(list: TAsmList; size: tdef; cmp_op: topcmp; reg: tregister; const loc: tlocation; l: tasmlabel);
  1370. begin
  1371. a_cmp_loc_reg_label(list,size,swap_opcmp(cmp_op),loc,reg,l);
  1372. end;
  1373. procedure thlcgobj.a_cmp_ref_loc_label(list: TAsmList; size: tdef; cmp_op: topcmp; const ref: treference; const loc: tlocation; l: tasmlabel);
  1374. var
  1375. tmpreg: tregister;
  1376. begin
  1377. case loc.loc of
  1378. LOC_REGISTER,LOC_CREGISTER:
  1379. a_cmp_ref_reg_label(list,size,cmp_op,ref,loc.register,l);
  1380. LOC_REFERENCE,LOC_CREFERENCE:
  1381. begin
  1382. tmpreg:=getintregister(list,size);
  1383. a_load_ref_reg(list,size,size,loc.reference,tmpreg);
  1384. a_cmp_ref_reg_label(list,size,cmp_op,ref,tmpreg,l);
  1385. end;
  1386. LOC_CONSTANT:
  1387. begin
  1388. a_cmp_const_ref_label(list,size,swap_opcmp(cmp_op),loc.value,ref,l);
  1389. end
  1390. { we don't have enough type information to handle these here
  1391. LOC_SUBSETREG, LOC_CSUBSETREG:
  1392. begin
  1393. tmpreg:=getintregister(list, size);
  1394. a_load_ref_reg(list,size,size,loc.reference,tmpreg);
  1395. a_cmp_subsetreg_reg_label(list,loc.size,size,swap_opcmp(cmp_op),loc.sreg,tmpreg,l);
  1396. end;
  1397. LOC_SUBSETREF, LOC_CSUBSETREF:
  1398. begin
  1399. tmpreg:=getintregister(list, size);
  1400. a_load_ref_reg(list,size,size,loc.reference,tmpreg);
  1401. a_cmp_subsetref_reg_label(list,loc.size,size,swap_opcmp(cmp_op),loc.sref,tmpreg,l);
  1402. end;
  1403. }
  1404. else
  1405. internalerror(2010120432);
  1406. end;
  1407. end;
  1408. procedure thlcgobj.g_concatcopy(list: TAsmList; size: tdef; const source, dest: treference);
  1409. begin
  1410. {
  1411. if use_vectorfpu(size) then
  1412. a_loadmm_ref_ref()
  1413. else
  1414. }
  1415. if size.typ<>floatdef then
  1416. a_load_ref_ref(list,size,size,source,dest)
  1417. else
  1418. a_loadfpu_ref_ref(list,size,size,source,dest);
  1419. end;
  1420. procedure thlcgobj.g_concatcopy_unaligned(list: TAsmList; size: tdef; const source, dest: treference);
  1421. begin
  1422. g_concatcopy(list,size,source,dest);
  1423. end;
  1424. procedure thlcgobj.g_rangecheck(list: TAsmList; const l: tlocation; fromdef, todef: tdef);
  1425. begin
  1426. if not(cs_check_range in current_settings.localswitches) then
  1427. exit;
  1428. internalerror(2011010610);
  1429. end;
  1430. procedure thlcgobj.g_profilecode(list: TAsmList);
  1431. begin
  1432. end;
  1433. procedure thlcgobj.location_force_reg(list: TAsmList; var l: tlocation; src_size, dst_size: tdef; maybeconst: boolean);
  1434. var
  1435. hregister,
  1436. hregister2: tregister;
  1437. hl : tasmlabel;
  1438. oldloc : tlocation;
  1439. begin
  1440. oldloc:=l;
  1441. hregister:=getregisterfordef(list,dst_size);
  1442. { load value in new register }
  1443. case l.loc of
  1444. {$ifdef cpuflags}
  1445. LOC_FLAGS :
  1446. cg.g_flags2reg(list,def_cgsize(dst_size),l.resflags,hregister);
  1447. {$endif cpuflags}
  1448. LOC_JUMP :
  1449. begin
  1450. a_label(list,current_procinfo.CurrTrueLabel);
  1451. a_load_const_reg(list,dst_size,1,hregister);
  1452. current_asmdata.getjumplabel(hl);
  1453. a_jmp_always(list,hl);
  1454. a_label(list,current_procinfo.CurrFalseLabel);
  1455. a_load_const_reg(list,dst_size,0,hregister);
  1456. a_label(list,hl);
  1457. end;
  1458. else
  1459. begin
  1460. { load_loc_reg can only handle size >= l.size, when the
  1461. new size is smaller then we need to adjust the size
  1462. of the orignal and maybe recalculate l.register for i386 }
  1463. if (dst_size.size<src_size.size) then
  1464. begin
  1465. hregister2:=getregisterfordef(list,src_size);
  1466. { prevent problems with memory locations -- at this high
  1467. level we cannot twiddle with the reference offset, since
  1468. that may not mean anything (e.g., it refers to fixed-sized
  1469. stack slots on Java) }
  1470. a_load_loc_reg(list,src_size,src_size,l,hregister2);
  1471. a_load_reg_reg(list,src_size,dst_size,hregister2,hregister);
  1472. end
  1473. else
  1474. a_load_loc_reg(list,src_size,dst_size,l,hregister);
  1475. end;
  1476. end;
  1477. if (l.loc <> LOC_CREGISTER) or
  1478. not maybeconst then
  1479. location_reset(l,LOC_REGISTER,def_cgsize(dst_size))
  1480. else
  1481. location_reset(l,LOC_CREGISTER,def_cgsize(dst_size));
  1482. l.register:=hregister;
  1483. { Release temp if it was a reference }
  1484. if oldloc.loc=LOC_REFERENCE then
  1485. location_freetemp(list,oldloc);
  1486. end;
  1487. procedure thlcgobj.location_force_mem(list: TAsmList; var l: tlocation; size: tdef);
  1488. var
  1489. r : treference;
  1490. begin
  1491. case l.loc of
  1492. LOC_FPUREGISTER,
  1493. LOC_CFPUREGISTER :
  1494. begin
  1495. tg.GetTemp(list,TCGSize2Size[l.size],TCGSize2Size[l.size],tt_normal,r);
  1496. hlcg.a_loadfpu_reg_ref(list,size,size,l.register,r);
  1497. location_reset_ref(l,LOC_REFERENCE,l.size,0);
  1498. l.reference:=r;
  1499. end;
  1500. (*
  1501. LOC_MMREGISTER,
  1502. LOC_CMMREGISTER:
  1503. begin
  1504. tg.GetTemp(list,TCGSize2Size[l.size],TCGSize2Size[l.size],tt_normal,r);
  1505. cg.a_loadmm_reg_ref(list,l.size,l.size,l.register,r,mms_movescalar);
  1506. location_reset_ref(l,LOC_REFERENCE,l.size,0);
  1507. l.reference:=r;
  1508. end;
  1509. *)
  1510. LOC_CONSTANT,
  1511. LOC_REGISTER,
  1512. LOC_CREGISTER :
  1513. begin
  1514. tg.GetTemp(list,TCGSize2Size[l.size],TCGSize2Size[l.size],tt_normal,r);
  1515. hlcg.a_load_loc_ref(list,size,size,l,r);
  1516. location_reset_ref(l,LOC_REFERENCE,l.size,0);
  1517. l.reference:=r;
  1518. end;
  1519. (*
  1520. LOC_SUBSETREG,
  1521. LOC_CSUBSETREG,
  1522. LOC_SUBSETREF,
  1523. LOC_CSUBSETREF:
  1524. begin
  1525. tg.GetTemp(list,TCGSize2Size[l.size],TCGSize2Size[l.size],tt_normal,r);
  1526. cg.a_load_loc_ref(list,l.size,l,r);
  1527. location_reset_ref(l,LOC_REFERENCE,l.size,0);
  1528. l.reference:=r;
  1529. end;
  1530. *)
  1531. LOC_CREFERENCE,
  1532. LOC_REFERENCE : ;
  1533. else
  1534. internalerror(2011010304);
  1535. end;
  1536. end;
  1537. procedure thlcgobj.maketojumpbool(list: TAsmList; p: tnode);
  1538. {
  1539. produces jumps to true respectively false labels using boolean expressions
  1540. depending on whether the loading of regvars is currently being
  1541. synchronized manually (such as in an if-node) or automatically (most of
  1542. the other cases where this procedure is called), loadregvars can be
  1543. "lr_load_regvars" or "lr_dont_load_regvars"
  1544. }
  1545. var
  1546. opsize : tcgsize;
  1547. storepos : tfileposinfo;
  1548. tmpreg : tregister;
  1549. begin
  1550. if nf_error in p.flags then
  1551. exit;
  1552. storepos:=current_filepos;
  1553. current_filepos:=p.fileinfo;
  1554. if is_boolean(p.resultdef) then
  1555. begin
  1556. if is_constboolnode(p) then
  1557. begin
  1558. if Tordconstnode(p).value.uvalue<>0 then
  1559. a_jmp_always(list,current_procinfo.CurrTrueLabel)
  1560. else
  1561. a_jmp_always(list,current_procinfo.CurrFalseLabel)
  1562. end
  1563. else
  1564. begin
  1565. case p.location.loc of
  1566. (*
  1567. LOC_SUBSETREG,LOC_CSUBSETREG,
  1568. LOC_SUBSETREF,LOC_CSUBSETREF:
  1569. begin
  1570. tmpreg := cg.getintregister(list,OS_INT);
  1571. cg.a_load_loc_reg(list,OS_INT,p.location,tmpreg);
  1572. cg.a_cmp_const_reg_label(list,OS_INT,OC_NE,0,tmpreg,current_procinfo.CurrTrueLabel);
  1573. cg.a_jmp_always(list,current_procinfo.CurrFalseLabel);
  1574. end;
  1575. *)
  1576. LOC_CREGISTER,LOC_REGISTER,LOC_CREFERENCE,LOC_REFERENCE :
  1577. begin
  1578. a_cmp_const_loc_label(list,p.resultdef,OC_NE,0,p.location,current_procinfo.CurrTrueLabel);
  1579. a_jmp_always(list,current_procinfo.CurrFalseLabel);
  1580. end;
  1581. LOC_JUMP:
  1582. ;
  1583. {$ifdef cpuflags}
  1584. LOC_FLAGS :
  1585. begin
  1586. a_jmp_flags(list,p.location.resflags,current_procinfo.CurrTrueLabel);
  1587. a_jmp_always(list,current_procinfo.CurrFalseLabel);
  1588. end;
  1589. {$endif cpuflags}
  1590. else
  1591. begin
  1592. printnode(output,p);
  1593. internalerror(2011010418);
  1594. end;
  1595. end;
  1596. end;
  1597. end
  1598. else
  1599. internalerror(2011010419);
  1600. current_filepos:=storepos;
  1601. end;
  1602. procedure thlcgobj.gen_proc_symbol(list: TAsmList);
  1603. var
  1604. item,
  1605. previtem : TCmdStrListItem;
  1606. begin
  1607. previtem:=nil;
  1608. item := TCmdStrListItem(current_procinfo.procdef.aliasnames.first);
  1609. while assigned(item) do
  1610. begin
  1611. {$ifdef arm}
  1612. if current_settings.cputype in cpu_thumb2 then
  1613. list.concat(tai_thumb_func.create);
  1614. {$endif arm}
  1615. { "double link" all procedure entry symbols via .reference }
  1616. { directives on darwin, because otherwise the linker }
  1617. { sometimes strips the procedure if only on of the symbols }
  1618. { is referenced }
  1619. if assigned(previtem) and
  1620. (target_info.system in systems_darwin) then
  1621. list.concat(tai_directive.create(asd_reference,item.str));
  1622. if (cs_profile in current_settings.moduleswitches) or
  1623. (po_global in current_procinfo.procdef.procoptions) then
  1624. list.concat(Tai_symbol.createname_global(item.str,AT_FUNCTION,0))
  1625. else
  1626. list.concat(Tai_symbol.createname(item.str,AT_FUNCTION,0));
  1627. if assigned(previtem) and
  1628. (target_info.system in systems_darwin) then
  1629. list.concat(tai_directive.create(asd_reference,previtem.str));
  1630. if not(af_stabs_use_function_absolute_addresses in target_asm.flags) then
  1631. list.concat(Tai_function_name.create(item.str));
  1632. previtem:=item;
  1633. item := TCmdStrListItem(item.next);
  1634. end;
  1635. current_procinfo.procdef.procstarttai:=tai(list.last);
  1636. end;
  1637. procedure thlcgobj.gen_proc_symbol_end(list: TAsmList);
  1638. begin
  1639. list.concat(Tai_symbol_end.Createname(current_procinfo.procdef.mangledname));
  1640. current_procinfo.procdef.procendtai:=tai(list.last);
  1641. if (current_module.islibrary) then
  1642. if (current_procinfo.procdef.proctypeoption = potype_proginit) then
  1643. { setinitname may generate a new section -> don't add to the
  1644. current list, because we assume this remains a text section }
  1645. exportlib.setinitname(current_asmdata.AsmLists[al_exports],current_procinfo.procdef.mangledname);
  1646. if (current_procinfo.procdef.proctypeoption=potype_proginit) then
  1647. begin
  1648. if (target_info.system in (systems_darwin+[system_powerpc_macos])) and
  1649. not(current_module.islibrary) then
  1650. begin
  1651. new_section(list,sec_code,'',4);
  1652. list.concat(tai_symbol.createname_global(
  1653. target_info.cprefix+mainaliasname,AT_FUNCTION,0));
  1654. { keep argc, argv and envp properly on the stack }
  1655. cg.a_jmp_name(list,target_info.cprefix+'FPC_SYSTEMMAIN');
  1656. end;
  1657. end;
  1658. end;
  1659. procedure thlcgobj.gen_loadfpu_loc_cgpara(list: TAsmList; size: tdef; const l: tlocation; const cgpara: tcgpara; locintsize: longint);
  1660. begin
  1661. case l.loc of
  1662. (*
  1663. LOC_MMREGISTER,
  1664. LOC_CMMREGISTER:
  1665. case cgpara.location^.loc of
  1666. LOC_REFERENCE,
  1667. LOC_CREFERENCE,
  1668. LOC_MMREGISTER,
  1669. LOC_CMMREGISTER,
  1670. LOC_REGISTER,
  1671. LOC_CREGISTER :
  1672. cg.a_loadmm_reg_cgpara(list,locsize,l.register,cgpara,mms_movescalar);
  1673. LOC_FPUREGISTER,
  1674. LOC_CFPUREGISTER:
  1675. begin
  1676. tmploc:=l;
  1677. location_force_fpureg(list,tmploc,false);
  1678. cg.a_loadfpu_reg_cgpara(list,tmploc.size,tmploc.register,cgpara);
  1679. end;
  1680. else
  1681. internalerror(200204249);
  1682. end;
  1683. *)
  1684. LOC_FPUREGISTER,
  1685. LOC_CFPUREGISTER:
  1686. case cgpara.location^.loc of
  1687. (*
  1688. LOC_MMREGISTER,
  1689. LOC_CMMREGISTER:
  1690. begin
  1691. tmploc:=l;
  1692. location_force_mmregscalar(list,tmploc,false);
  1693. cg.a_loadmm_reg_cgpara(list,tmploc.size,tmploc.register,cgpara,mms_movescalar);
  1694. end;
  1695. *)
  1696. { Some targets pass floats in normal registers }
  1697. LOC_REGISTER,
  1698. LOC_CREGISTER,
  1699. LOC_REFERENCE,
  1700. LOC_CREFERENCE,
  1701. LOC_FPUREGISTER,
  1702. LOC_CFPUREGISTER:
  1703. hlcg.a_loadfpu_reg_cgpara(list,size,l.register,cgpara);
  1704. else
  1705. internalerror(2011010210);
  1706. end;
  1707. LOC_REFERENCE,
  1708. LOC_CREFERENCE:
  1709. case cgpara.location^.loc of
  1710. (*
  1711. LOC_MMREGISTER,
  1712. LOC_CMMREGISTER:
  1713. cg.a_loadmm_ref_cgpara(list,locsize,l.reference,cgpara,mms_movescalar);
  1714. *)
  1715. { Some targets pass floats in normal registers }
  1716. LOC_REGISTER,
  1717. LOC_CREGISTER,
  1718. LOC_REFERENCE,
  1719. LOC_CREFERENCE,
  1720. LOC_FPUREGISTER,
  1721. LOC_CFPUREGISTER:
  1722. hlcg.a_loadfpu_ref_cgpara(list,size,l.reference,cgpara);
  1723. else
  1724. internalerror(2011010211);
  1725. end;
  1726. LOC_REGISTER,
  1727. LOC_CREGISTER :
  1728. hlcg.a_load_loc_cgpara(list,size,l,cgpara);
  1729. else
  1730. internalerror(2011010212);
  1731. end;
  1732. end;
  1733. procedure thlcgobj.gen_load_uninitialized_function_result(list: TAsmList; pd: tprocdef; resdef: tdef; const resloc: tcgpara);
  1734. begin
  1735. { do nothing by default }
  1736. end;
  1737. procedure thlcgobj.gen_load_loc_cgpara(list: TAsmList; vardef: tdef; const l: tlocation; const cgpara: tcgpara);
  1738. begin
  1739. { Handle Floating point types differently
  1740. This doesn't depend on emulator settings, emulator settings should
  1741. be handled by cpupara }
  1742. if (vardef.typ=floatdef) or
  1743. { some ABIs return certain records in an fpu register }
  1744. (l.loc in [LOC_FPUREGISTER,LOC_CFPUREGISTER]) or
  1745. (assigned(cgpara.location) and
  1746. (cgpara.Location^.loc in [LOC_FPUREGISTER,LOC_CFPUREGISTER])) then
  1747. begin
  1748. gen_loadfpu_loc_cgpara(list,vardef,l,cgpara,vardef.size);
  1749. exit;
  1750. end;
  1751. case l.loc of
  1752. LOC_CONSTANT,
  1753. LOC_REGISTER,
  1754. LOC_CREGISTER,
  1755. LOC_REFERENCE,
  1756. LOC_CREFERENCE :
  1757. begin
  1758. hlcg.a_load_loc_cgpara(list,vardef,l,cgpara);
  1759. end;
  1760. (*
  1761. LOC_MMREGISTER,
  1762. LOC_CMMREGISTER:
  1763. begin
  1764. case l.size of
  1765. OS_F32,
  1766. OS_F64:
  1767. cg.a_loadmm_loc_cgpara(list,l,cgpara,mms_movescalar);
  1768. else
  1769. cg.a_loadmm_loc_cgpara(list,l,cgpara,nil);
  1770. end;
  1771. end;
  1772. *)
  1773. else
  1774. internalerror(2011010212);
  1775. end;
  1776. end;
  1777. procedure thlcgobj.gen_load_cgpara_loc(list: TAsmList; vardef: tdef; const para: TCGPara; var destloc: tlocation; reusepara: boolean);
  1778. var
  1779. href : treference;
  1780. begin
  1781. para.check_simple_location;
  1782. { skip e.g. empty records }
  1783. if (para.location^.loc = LOC_VOID) then
  1784. exit;
  1785. case destloc.loc of
  1786. LOC_REFERENCE :
  1787. begin
  1788. { If the parameter location is reused we don't need to copy
  1789. anything }
  1790. if not reusepara then
  1791. begin
  1792. reference_reset_base(href,para.location^.reference.index,para.location^.reference.offset,para.alignment);
  1793. a_load_ref_ref(list,para.def,para.def,href,destloc.reference);
  1794. end;
  1795. end;
  1796. { TODO other possible locations }
  1797. else
  1798. internalerror(2011010308);
  1799. end;
  1800. end;
  1801. procedure thlcgobj.gen_load_return_value(list: TAsmList);
  1802. var
  1803. ressym : tabstractnormalvarsym;
  1804. funcretloc : TCGPara;
  1805. begin
  1806. { Is the loading needed? }
  1807. if is_void(current_procinfo.procdef.returndef) or
  1808. (
  1809. (po_assembler in current_procinfo.procdef.procoptions) and
  1810. (not(assigned(current_procinfo.procdef.funcretsym)) or
  1811. (tabstractvarsym(current_procinfo.procdef.funcretsym).refs=0))
  1812. ) then
  1813. exit;
  1814. funcretloc:=current_procinfo.procdef.funcretloc[calleeside];
  1815. { constructors return self }
  1816. if (current_procinfo.procdef.proctypeoption=potype_constructor) then
  1817. ressym:=tabstractnormalvarsym(current_procinfo.procdef.parast.Find('self'))
  1818. else
  1819. ressym:=tabstractnormalvarsym(current_procinfo.procdef.funcretsym);
  1820. if (ressym.refs>0) or
  1821. is_managed_type(ressym.vardef) then
  1822. begin
  1823. { was: don't do anything if funcretloc.loc in [LOC_INVALID,LOC_REFERENCE] }
  1824. if not paramanager.ret_in_param(current_procinfo.procdef.returndef,current_procinfo.procdef.proccalloption) then
  1825. hlcg.gen_load_loc_cgpara(list,ressym.vardef,ressym.localloc,funcretloc);
  1826. end
  1827. else
  1828. gen_load_uninitialized_function_result(list,current_procinfo.procdef,ressym.vardef,funcretloc)
  1829. end;
  1830. procedure thlcgobj.record_generated_code_for_procdef(pd: tprocdef; code, data: TAsmList);
  1831. begin
  1832. { add the procedure to the al_procedures }
  1833. maybe_new_object_file(current_asmdata.asmlists[al_procedures]);
  1834. new_section(current_asmdata.asmlists[al_procedures],sec_code,lower(pd.mangledname),getprocalign);
  1835. current_asmdata.asmlists[al_procedures].concatlist(code);
  1836. { save local data (casetable) also in the same file }
  1837. if assigned(data) and
  1838. (not data.empty) then
  1839. current_asmdata.asmlists[al_procedures].concatlist(data);
  1840. end;
  1841. end.