hlcgobj.pas 94 KB

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