cgobj.pas 109 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. Member of the Free Pascal development team
  5. This unit implements the basic code generator object
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. ****************************************************************************
  18. }
  19. {# @abstract(Abstract code generator unit)
  20. Abstreact code generator unit. This contains the base class
  21. to implement for all new supported processors.
  22. WARNING: None of the routines implemented in these modules,
  23. or their descendants, should use the temp. allocator, as
  24. these routines may be called inside genentrycode, and the
  25. stack frame is already setup!
  26. }
  27. unit cgobj;
  28. {$i fpcdefs.inc}
  29. interface
  30. uses
  31. {$ifdef delphi}
  32. dmisc,
  33. {$endif}
  34. cclasses,globtype,
  35. cpubase,cpuinfo,cgbase,
  36. aasmbase,aasmtai,aasmcpu,
  37. symconst,symbase,symtype,symdef,symtable,rgobj
  38. ;
  39. type
  40. talignment = (AM_NATURAL,AM_NONE,AM_2BYTE,AM_4BYTE,AM_8BYTE);
  41. {# @abstract(Abstract code generator)
  42. This class implements an abstract instruction generator. Some of
  43. the methods of this class are generic, while others must
  44. be overriden for all new processors which will be supported
  45. by Free Pascal. For 32-bit processors, the base class
  46. sould be @link(tcg64f32) and not @var(tcg).
  47. }
  48. tcg = class
  49. public
  50. alignment : talignment;
  51. rg : array[tregistertype] of trgobj;
  52. t_times:cardinal;
  53. {$ifdef flowgraph}
  54. aktflownode:word;
  55. {$endif}
  56. {************************************************}
  57. { basic routines }
  58. constructor create;
  59. {# Initialize the register allocators needed for the codegenerator.}
  60. procedure init_register_allocators;virtual;
  61. {# Clean up the register allocators needed for the codegenerator.}
  62. procedure done_register_allocators;virtual;
  63. {$ifdef flowgraph}
  64. procedure init_flowgraph;
  65. procedure done_flowgraph;
  66. {$endif}
  67. {# Gets a register suitable to do integer operations on.}
  68. function getintregister(list:Taasmoutput;size:Tcgsize):Tregister;virtual;
  69. {# Gets a register suitable to do integer operations on.}
  70. function getaddressregister(list:Taasmoutput):Tregister;virtual;
  71. function getfpuregister(list:Taasmoutput;size:Tcgsize):Tregister;virtual;
  72. function getmmregister(list:Taasmoutput;size:Tcgsize):Tregister;virtual;
  73. function getflagregister(list:Taasmoutput;size:Tcgsize):Tregister;virtual;abstract;
  74. {Does the generic cg need SIMD registers, like getmmxregister? Or should
  75. the cpu specific child cg object have such a method?}
  76. procedure ungetregister(list:Taasmoutput;r:Tregister);virtual;
  77. procedure ungetreference(list:Taasmoutput;const r:Treference);virtual;
  78. procedure add_reg_instruction(instr:Tai;r:tregister);virtual;
  79. procedure add_move_instruction(instr:Taicpu);virtual;
  80. function uses_registers(rt:Tregistertype):boolean;virtual;
  81. {# Get a specific register.}
  82. procedure getexplicitregister(list:Taasmoutput;r:Tregister);virtual;
  83. {# Get multiple registers specified.}
  84. procedure allocexplicitregisters(list:Taasmoutput;rt:Tregistertype;r:Tcpuregisterset);virtual;
  85. {# Free multiple registers specified.}
  86. procedure deallocexplicitregisters(list:Taasmoutput;rt:Tregistertype;r:Tcpuregisterset);virtual;
  87. procedure do_register_allocation(list:Taasmoutput;headertai:tai);virtual;
  88. function makeregsize(list:Taasmoutput;reg:Tregister;size:Tcgsize):Tregister;
  89. {# Emit a label to the instruction stream. }
  90. procedure a_label(list : taasmoutput;l : tasmlabel);virtual;
  91. {# Allocates register r by inserting a pai_realloc record }
  92. procedure a_reg_alloc(list : taasmoutput;r : tregister);
  93. {# Deallocates register r by inserting a pa_regdealloc record}
  94. procedure a_reg_dealloc(list : taasmoutput;r : tregister);
  95. {# Pass a parameter, which is located in a register, to a routine.
  96. This routine should push/send the parameter to the routine, as
  97. required by the specific processor ABI and routine modifiers.
  98. This must be overriden for each CPU target.
  99. @param(size size of the operand in the register)
  100. @param(r register source of the operand)
  101. @param(locpara where the parameter will be stored)
  102. }
  103. procedure a_param_reg(list : taasmoutput;size : tcgsize;r : tregister;const locpara : tparalocation);virtual;
  104. {# Pass a parameter, which is a constant, to a routine.
  105. A generic version is provided. This routine should
  106. be overriden for optimization purposes if the cpu
  107. permits directly sending this type of parameter.
  108. @param(size size of the operand in constant)
  109. @param(a value of constant to send)
  110. @param(locpara where the parameter will be stored)
  111. }
  112. procedure a_param_const(list : taasmoutput;size : tcgsize;a : aint;const locpara : tparalocation);virtual;
  113. {# Pass the value of a parameter, which is located in memory, to a routine.
  114. A generic version is provided. This routine should
  115. be overriden for optimization purposes if the cpu
  116. permits directly sending this type of parameter.
  117. @param(size size of the operand in constant)
  118. @param(r Memory reference of value to send)
  119. @param(locpara where the parameter will be stored)
  120. }
  121. procedure a_param_ref(list : taasmoutput;size : tcgsize;const r : treference;const locpara : tparalocation);virtual;
  122. {# Pass the value of a parameter, which can be located either in a register or memory location,
  123. to a routine.
  124. A generic version is provided.
  125. @param(l location of the operand to send)
  126. @param(nr parameter number (starting from one) of routine (from left to right))
  127. @param(locpara where the parameter will be stored)
  128. }
  129. procedure a_param_loc(list : taasmoutput;const l : tlocation;const locpara : tparalocation);
  130. {# Pass the address of a reference to a routine. This routine
  131. will calculate the address of the reference, and pass this
  132. calculated address as a parameter.
  133. A generic version is provided. This routine should
  134. be overriden for optimization purposes if the cpu
  135. permits directly sending this type of parameter.
  136. @param(r reference to get address from)
  137. @param(nr parameter number (starting from one) of routine (from left to right))
  138. }
  139. procedure a_paramaddr_ref(list : taasmoutput;const r : treference;const locpara : tparalocation);virtual;
  140. { Copies a whole memory block to the stack, the locpara must be a memory location }
  141. procedure a_param_copy_ref(list : taasmoutput;size : aint;const r : treference;const locpara : tparalocation);
  142. { Remarks:
  143. * If a method specifies a size you have only to take care
  144. of that number of bits, i.e. load_const_reg with OP_8 must
  145. only load the lower 8 bit of the specified register
  146. the rest of the register can be undefined
  147. if necessary the compiler will call a method
  148. to zero or sign extend the register
  149. * The a_load_XX_XX with OP_64 needn't to be
  150. implemented for 32 bit
  151. processors, the code generator takes care of that
  152. * the addr size is for work with the natural pointer
  153. size
  154. * the procedures without fpu/mm are only for integer usage
  155. * normally the first location is the source and the
  156. second the destination
  157. }
  158. { Copy a parameter to a (temporary) reference }
  159. procedure a_loadany_param_ref(list : taasmoutput;const locpara : tparalocation;const ref:treference;shuffle : pmmshuffle);virtual;
  160. { Copy a parameter to a register }
  161. procedure a_loadany_param_reg(list : taasmoutput;const locpara : tparalocation;const reg:tregister;shuffle : pmmshuffle);virtual;
  162. {# Emits instruction to call the method specified by symbol name.
  163. This routine must be overriden for each new target cpu.
  164. There is no a_call_ref because loading the reference will use
  165. a temp register on most cpu's resulting in conflicts with the
  166. registers used for the parameters (PFV)
  167. }
  168. procedure a_call_name(list : taasmoutput;const s : string);virtual; abstract;
  169. procedure a_call_reg(list : taasmoutput;reg : tregister);virtual;abstract;
  170. { move instructions }
  171. procedure a_load_const_reg(list : taasmoutput;size : tcgsize;a : aint;register : tregister);virtual; abstract;
  172. procedure a_load_const_ref(list : taasmoutput;size : tcgsize;a : aint;const ref : treference);virtual;
  173. procedure a_load_const_loc(list : taasmoutput;a : aint;const loc : tlocation);
  174. procedure a_load_reg_ref(list : taasmoutput;fromsize,tosize : tcgsize;register : tregister;const ref : treference);virtual; abstract;
  175. procedure a_load_reg_reg(list : taasmoutput;fromsize,tosize : tcgsize;reg1,reg2 : tregister);virtual; abstract;
  176. procedure a_load_reg_loc(list : taasmoutput;fromsize : tcgsize;reg : tregister;const loc: tlocation);
  177. procedure a_load_ref_reg(list : taasmoutput;fromsize,tosize : tcgsize;const ref : treference;register : tregister);virtual; abstract;
  178. procedure a_load_ref_ref(list : taasmoutput;fromsize,tosize : tcgsize;const sref : treference;const dref : treference);virtual;
  179. procedure a_load_loc_reg(list : taasmoutput;tosize: tcgsize; const loc: tlocation; reg : tregister);
  180. procedure a_load_loc_ref(list : taasmoutput;tosize: tcgsize; const loc: tlocation; const ref : treference);
  181. procedure a_loadaddr_ref_reg(list : taasmoutput;const ref : treference;r : tregister);virtual; abstract;
  182. { fpu move instructions }
  183. procedure a_loadfpu_reg_reg(list: taasmoutput; size:tcgsize; reg1, reg2: tregister); virtual; abstract;
  184. procedure a_loadfpu_ref_reg(list: taasmoutput; size: tcgsize; const ref: treference; reg: tregister); virtual; abstract;
  185. procedure a_loadfpu_reg_ref(list: taasmoutput; size: tcgsize; reg: tregister; const ref: treference); virtual; abstract;
  186. procedure a_loadfpu_loc_reg(list: taasmoutput; const loc: tlocation; const reg: tregister);
  187. procedure a_loadfpu_reg_loc(list: taasmoutput; size: tcgsize; const reg: tregister; const loc: tlocation);
  188. procedure a_paramfpu_reg(list : taasmoutput;size : tcgsize;const r : tregister;const locpara : tparalocation);virtual;
  189. procedure a_paramfpu_ref(list : taasmoutput;size : tcgsize;const ref : treference;const locpara : tparalocation);virtual;
  190. { vector register move instructions }
  191. procedure a_loadmm_reg_reg(list: taasmoutput; fromsize, tosize : tcgsize;reg1, reg2: tregister;shuffle : pmmshuffle); virtual; abstract;
  192. procedure a_loadmm_ref_reg(list: taasmoutput; fromsize, tosize : tcgsize;const ref: treference; reg: tregister;shuffle : pmmshuffle); virtual; abstract;
  193. procedure a_loadmm_reg_ref(list: taasmoutput; fromsize, tosize : tcgsize;reg: tregister; const ref: treference;shuffle : pmmshuffle); virtual; abstract;
  194. procedure a_loadmm_loc_reg(list: taasmoutput; size: tcgsize; const loc: tlocation; const reg: tregister;shuffle : pmmshuffle);
  195. procedure a_loadmm_reg_loc(list: taasmoutput; size: tcgsize; const reg: tregister; const loc: tlocation;shuffle : pmmshuffle);
  196. procedure a_parammm_reg(list: taasmoutput; size: tcgsize; reg: tregister;const locpara : tparalocation;shuffle : pmmshuffle); virtual;
  197. procedure a_parammm_ref(list: taasmoutput; size: tcgsize; const ref: treference;const locpara : tparalocation;shuffle : pmmshuffle); virtual;
  198. procedure a_parammm_loc(list: taasmoutput; const loc: tlocation; const locpara : tparalocation;shuffle : pmmshuffle); virtual;
  199. procedure a_opmm_reg_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;src,dst: tregister;shuffle : pmmshuffle); virtual;abstract;
  200. procedure a_opmm_ref_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;const ref: treference; reg: tregister;shuffle : pmmshuffle); virtual;
  201. procedure a_opmm_loc_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;const loc: tlocation; reg: tregister;shuffle : pmmshuffle); virtual;
  202. procedure a_opmm_reg_ref(list: taasmoutput; Op: TOpCG; size : tcgsize;reg: tregister;const ref: treference; shuffle : pmmshuffle); virtual;
  203. { basic arithmetic operations }
  204. { note: for operators which require only one argument (not, neg), use }
  205. { the op_reg_reg, op_reg_ref or op_reg_loc methods and keep in mind }
  206. { that in this case the *second* operand is used as both source and }
  207. { destination (JM) }
  208. procedure a_op_const_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; a: Aint; reg: TRegister); virtual; abstract;
  209. procedure a_op_const_ref(list : taasmoutput; Op: TOpCG; size: TCGSize; a: Aint; const ref: TReference); virtual;
  210. procedure a_op_const_loc(list : taasmoutput; Op: TOpCG; a: Aint; const loc: tlocation);
  211. procedure a_op_reg_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; reg1, reg2: TRegister); virtual; abstract;
  212. procedure a_op_reg_ref(list : taasmoutput; Op: TOpCG; size: TCGSize; reg: TRegister; const ref: TReference); virtual;
  213. procedure a_op_ref_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; const ref: TReference; reg: TRegister); virtual;
  214. procedure a_op_reg_loc(list : taasmoutput; Op: TOpCG; reg: tregister; const loc: tlocation);
  215. procedure a_op_ref_loc(list : taasmoutput; Op: TOpCG; const ref: TReference; const loc: tlocation);
  216. { trinary operations for processors that support them, 'emulated' }
  217. { on others. None with "ref" arguments since I don't think there }
  218. { are any processors that support it (JM) }
  219. procedure a_op_const_reg_reg(list: taasmoutput; op: TOpCg; size: tcgsize; a: aint; src, dst: tregister); virtual;
  220. procedure a_op_reg_reg_reg(list: taasmoutput; op: TOpCg; size: tcgsize; src1, src2, dst: tregister); virtual;
  221. { comparison operations }
  222. procedure a_cmp_const_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aint;reg : tregister;
  223. l : tasmlabel);virtual; abstract;
  224. procedure a_cmp_const_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aint;const ref : treference;
  225. l : tasmlabel); virtual;
  226. procedure a_cmp_const_loc_label(list: taasmoutput; size: tcgsize;cmp_op: topcmp; a: aint; const loc: tlocation;
  227. l : tasmlabel);
  228. procedure a_cmp_reg_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;reg1,reg2 : tregister;l : tasmlabel); virtual; abstract;
  229. procedure a_cmp_ref_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; const ref: treference; reg : tregister; l : tasmlabel); virtual;
  230. procedure a_cmp_reg_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;reg : tregister; const ref: treference; l : tasmlabel); virtual;
  231. procedure a_cmp_loc_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; const loc: tlocation; reg : tregister; l : tasmlabel);
  232. procedure a_cmp_ref_loc_label(list: taasmoutput; size: tcgsize;cmp_op: topcmp; const ref: treference; const loc: tlocation;
  233. l : tasmlabel);
  234. procedure a_jmp_name(list : taasmoutput;const s : string); virtual; abstract;
  235. procedure a_jmp_always(list : taasmoutput;l: tasmlabel); virtual; abstract;
  236. procedure a_jmp_flags(list : taasmoutput;const f : TResFlags;l: tasmlabel); virtual; abstract;
  237. {# Depending on the value to check in the flags, either sets the register reg to one (if the flag is set)
  238. or zero (if the flag is cleared). The size parameter indicates the destination size register.
  239. }
  240. procedure g_flags2reg(list: taasmoutput; size: TCgSize; const f: tresflags; reg: TRegister); virtual; abstract;
  241. procedure g_flags2ref(list: taasmoutput; size: TCgSize; const f: tresflags; const ref:TReference); virtual;
  242. {
  243. This routine tries to optimize the const_reg opcode, and should be
  244. called at the start of a_op_const_reg. It returns the actual opcode
  245. to emit, and the constant value to emit. If this routine returns
  246. TRUE, @var(no) instruction should be emitted (.eg : imul reg by 1 )
  247. @param(op The opcode to emit, returns the opcode which must be emitted)
  248. @param(a The constant which should be emitted, returns the constant which must
  249. be emitted)
  250. @param(reg The register to emit the opcode with, returns the register with
  251. which the opcode will be emitted)
  252. }
  253. function optimize_op_const_reg(list: taasmoutput; var op: topcg; var a : aint; var reg: tregister): boolean;virtual;
  254. {#
  255. This routine is used in exception management nodes. It should
  256. save the exception reason currently in the FUNCTION_RETURN_REG. The
  257. save should be done either to a temp (pointed to by href).
  258. or on the stack (pushing the value on the stack).
  259. The size of the value to save is OS_S32. The default version
  260. saves the exception reason to a temp. memory area.
  261. }
  262. procedure g_exception_reason_save(list : taasmoutput; const href : treference);virtual;
  263. {#
  264. This routine is used in exception management nodes. It should
  265. save the exception reason constant. The
  266. save should be done either to a temp (pointed to by href).
  267. or on the stack (pushing the value on the stack).
  268. The size of the value to save is OS_S32. The default version
  269. saves the exception reason to a temp. memory area.
  270. }
  271. procedure g_exception_reason_save_const(list : taasmoutput; const href : treference; a: aint);virtual;
  272. {#
  273. This routine is used in exception management nodes. It should
  274. load the exception reason to the FUNCTION_RETURN_REG. The saved value
  275. should either be in the temp. area (pointed to by href , href should
  276. *NOT* be freed) or on the stack (the value should be popped).
  277. The size of the value to save is OS_S32. The default version
  278. saves the exception reason to a temp. memory area.
  279. }
  280. procedure g_exception_reason_load(list : taasmoutput; const href : treference);virtual;
  281. procedure g_maybe_testself(list : taasmoutput;reg:tregister);
  282. procedure g_maybe_testvmt(list : taasmoutput;reg:tregister;objdef:tobjectdef);
  283. {# This should emit the opcode to copy len bytes from the source
  284. to destination, if loadref is true, it assumes that it first must load
  285. the source address from the memory location where
  286. source points to.
  287. It must be overriden for each new target processor.
  288. @param(source Source reference of copy)
  289. @param(dest Destination reference of copy)
  290. @param(delsource Indicates if the source reference's resources should be freed)
  291. @param(loadref Is the source reference a pointer to the actual source (TRUE), is it the actual source address (FALSE))
  292. }
  293. procedure g_concatcopy(list : taasmoutput;const source,dest : treference;len : aint;delsource,loadref : boolean);virtual; abstract;
  294. {# This should emit the opcode to a shortrstring from the source
  295. to destination, if loadref is true, it assumes that it first must load
  296. the source address from the memory location where
  297. source points to.
  298. @param(source Source reference of copy)
  299. @param(dest Destination reference of copy)
  300. @param(delsource Indicates if the source reference's resources should be freed)
  301. @param(loadref Is the source reference a pointer to the actual source (TRUE), is it the actual source address (FALSE))
  302. }
  303. procedure g_copyshortstring(list : taasmoutput;const source,dest : treference;len:byte;delsource,loadref : boolean);
  304. procedure g_incrrefcount(list : taasmoutput;t: tdef; const ref: treference;loadref : boolean);
  305. procedure g_decrrefcount(list : taasmoutput;t: tdef; const ref: treference;loadref : boolean);
  306. procedure g_initialize(list : taasmoutput;t : tdef;const ref : treference;loadref : boolean);
  307. procedure g_finalize(list : taasmoutput;t : tdef;const ref : treference;loadref : boolean);
  308. {# Generates range checking code. It is to note
  309. that this routine does not need to be overriden,
  310. as it takes care of everything.
  311. @param(p Node which contains the value to check)
  312. @param(todef Type definition of node to range check)
  313. }
  314. procedure g_rangecheck(list: taasmoutput; const l:tlocation; fromdef,todef: tdef); virtual;
  315. {# Generates overflow checking code for a node }
  316. procedure g_overflowcheck(list: taasmoutput; const l:tlocation; def:tdef); virtual; abstract;
  317. procedure g_copyvaluepara_openarray(list : taasmoutput;const ref, lenref:treference;elesize:aint);virtual;
  318. procedure g_releasevaluepara_openarray(list : taasmoutput;const ref:treference);virtual;
  319. {# Emits instructions when compilation is done in profile
  320. mode (this is set as a command line option). The default
  321. behavior does nothing, should be overriden as required.
  322. }
  323. procedure g_profilecode(list : taasmoutput);virtual;
  324. {# Emits instruction for allocating @var(size) bytes at the stackpointer
  325. @param(size Number of bytes to allocate)
  326. }
  327. procedure g_stackpointer_alloc(list : taasmoutput;size : longint);virtual; abstract;
  328. {# Emits instruction for allocating the locals in entry
  329. code of a routine. This is one of the first
  330. routine called in @var(genentrycode).
  331. @param(localsize Number of bytes to allocate as locals)
  332. }
  333. procedure g_proc_entry(list : taasmoutput;localsize : longint;nostackframe:boolean);virtual; abstract;
  334. {# Emits instructions for returning from a subroutine.
  335. Should also restore the framepointer and stack.
  336. @param(parasize Number of bytes of parameters to deallocate from stack)
  337. }
  338. procedure g_proc_exit(list : taasmoutput;parasize:longint;nostackframe:boolean);virtual;abstract;
  339. {# This routine is called when generating the code for the entry point
  340. of a routine. It should save all registers which are not used in this
  341. routine, and which should be declared as saved in the std_saved_registers
  342. set.
  343. This routine is mainly used when linking to code which is generated
  344. by ABI-compliant compilers (like GCC), to make sure that the reserved
  345. registers of that ABI are not clobbered.
  346. @param(usedinproc Registers which are used in the code of this routine)
  347. }
  348. procedure g_save_standard_registers(list:Taasmoutput);virtual;abstract;
  349. {# This routine is called when generating the code for the exit point
  350. of a routine. It should restore all registers which were previously
  351. saved in @var(g_save_standard_registers).
  352. @param(usedinproc Registers which are used in the code of this routine)
  353. }
  354. procedure g_restore_standard_registers(list:Taasmoutput);virtual;abstract;
  355. procedure g_save_all_registers(list : taasmoutput);virtual;abstract;
  356. procedure g_restore_all_registers(list : taasmoutput;const funcretparaloc:tparalocation);virtual;abstract;
  357. end;
  358. {$ifndef cpu64bit}
  359. {# @abstract(Abstract code generator for 64 Bit operations)
  360. This class implements an abstract code generator class
  361. for 64 Bit operations.
  362. }
  363. tcg64 = class
  364. { Allocates 64 Bit register r by inserting a pai_realloc record }
  365. procedure a_reg_alloc(list : taasmoutput;r : tregister64);virtual;abstract;
  366. { Deallocates 64 Bit register r by inserting a pa_regdealloc record}
  367. procedure a_reg_dealloc(list : taasmoutput;r : tregister64);virtual;abstract;
  368. procedure a_load64_const_ref(list : taasmoutput;value : int64;const ref : treference);virtual;abstract;
  369. procedure a_load64_reg_ref(list : taasmoutput;reg : tregister64;const ref : treference);virtual;abstract;
  370. procedure a_load64_ref_reg(list : taasmoutput;const ref : treference;reg : tregister64);virtual;abstract;
  371. procedure a_load64_reg_reg(list : taasmoutput;regsrc,regdst : tregister64);virtual;abstract;
  372. procedure a_load64_const_reg(list : taasmoutput;value : int64;reg : tregister64);virtual;abstract;
  373. procedure a_load64_loc_reg(list : taasmoutput;const l : tlocation;reg : tregister64);virtual;abstract;
  374. procedure a_load64_loc_ref(list : taasmoutput;const l : tlocation;const ref : treference);virtual;abstract;
  375. procedure a_load64_const_loc(list : taasmoutput;value : int64;const l : tlocation);virtual;abstract;
  376. procedure a_load64_reg_loc(list : taasmoutput;reg : tregister64;const l : tlocation);virtual;abstract;
  377. procedure a_load64high_reg_ref(list : taasmoutput;reg : tregister;const ref : treference);virtual;abstract;
  378. procedure a_load64low_reg_ref(list : taasmoutput;reg : tregister;const ref : treference);virtual;abstract;
  379. procedure a_load64high_ref_reg(list : taasmoutput;const ref : treference;reg : tregister);virtual;abstract;
  380. procedure a_load64low_ref_reg(list : taasmoutput;const ref : treference;reg : tregister);virtual;abstract;
  381. procedure a_load64high_loc_reg(list : taasmoutput;const l : tlocation;reg : tregister);virtual;abstract;
  382. procedure a_load64low_loc_reg(list : taasmoutput;const l : tlocation;reg : tregister);virtual;abstract;
  383. procedure a_op64_ref_reg(list : taasmoutput;op:TOpCG;const ref : treference;reg : tregister64);virtual;abstract;
  384. procedure a_op64_reg_reg(list : taasmoutput;op:TOpCG;regsrc,regdst : tregister64);virtual;abstract;
  385. procedure a_op64_reg_ref(list : taasmoutput;op:TOpCG;regsrc : tregister64;const ref : treference);virtual;abstract;
  386. procedure a_op64_const_reg(list : taasmoutput;op:TOpCG;value : int64;regdst : tregister64);virtual;abstract;
  387. procedure a_op64_const_ref(list : taasmoutput;op:TOpCG;value : int64;const ref : treference);virtual;abstract;
  388. procedure a_op64_const_loc(list : taasmoutput;op:TOpCG;value : int64;const l: tlocation);virtual;abstract;
  389. procedure a_op64_reg_loc(list : taasmoutput;op:TOpCG;reg : tregister64;const l : tlocation);virtual;abstract;
  390. procedure a_op64_loc_reg(list : taasmoutput;op:TOpCG;const l : tlocation;reg64 : tregister64);virtual;abstract;
  391. procedure a_op64_const_reg_reg(list: taasmoutput;op:TOpCG;value : int64;regsrc,regdst : tregister64);virtual;
  392. procedure a_op64_reg_reg_reg(list: taasmoutput;op:TOpCG;regsrc1,regsrc2,regdst : tregister64);virtual;
  393. procedure a_param64_reg(list : taasmoutput;reg64 : tregister64;const loc : tparalocation);virtual;abstract;
  394. procedure a_param64_const(list : taasmoutput;value : int64;const loc : tparalocation);virtual;abstract;
  395. procedure a_param64_ref(list : taasmoutput;const r : treference;const loc : tparalocation);virtual;abstract;
  396. procedure a_param64_loc(list : taasmoutput;const l : tlocation;const loc : tparalocation);virtual;abstract;
  397. {
  398. This routine tries to optimize the const_reg opcode, and should be
  399. called at the start of a_op64_const_reg. It returns the actual opcode
  400. to emit, and the constant value to emit. If this routine returns
  401. TRUE, @var(no) instruction should be emitted (.eg : imul reg by 1 )
  402. @param(op The opcode to emit, returns the opcode which must be emitted)
  403. @param(a The constant which should be emitted, returns the constant which must
  404. be emitted)
  405. @param(reg The register to emit the opcode with, returns the register with
  406. which the opcode will be emitted)
  407. }
  408. function optimize64_op_const_reg(list: taasmoutput; var op: topcg; var a : int64; var reg: tregister64): boolean;virtual;abstract;
  409. { override to catch 64bit rangechecks }
  410. procedure g_rangecheck64(list: taasmoutput; const l:tlocation; fromdef,todef: tdef);virtual;abstract;
  411. end;
  412. {$endif cpu64bit}
  413. procedure reference_release(list: taasmoutput; const ref : treference);
  414. { tlocation handling }
  415. procedure location_reset(var l : tlocation;lt:TCGLoc;lsize:TCGSize);
  416. procedure location_release(list: taasmoutput; const l : tlocation);
  417. procedure location_freetemp(list: taasmoutput; const l : tlocation);
  418. procedure location_copy(var destloc:tlocation; const sourceloc : tlocation);
  419. procedure location_swap(var destloc,sourceloc : tlocation);
  420. var
  421. {# Main code generator class }
  422. cg : tcg;
  423. {$ifndef cpu64bit}
  424. {# Code generator class for all operations working with 64-Bit operands }
  425. cg64 : tcg64;
  426. {$endif cpu64bit}
  427. implementation
  428. uses
  429. globals,options,systems,
  430. verbose,defutil,paramgr,
  431. tgobj,cutils,
  432. cgutils;
  433. const
  434. { Please leave this here, this module should NOT use
  435. exprasmlist, the lists are always passed as arguments.
  436. Declaring it as string here results in an error when compiling (PFV) }
  437. exprasmlist = 'error';
  438. {*****************************************************************************
  439. basic functionallity
  440. ******************************************************************************}
  441. constructor tcg.create;
  442. begin
  443. end;
  444. {*****************************************************************************
  445. register allocation
  446. ******************************************************************************}
  447. procedure tcg.init_register_allocators;
  448. begin
  449. fillchar(rg,sizeof(rg),0);
  450. add_reg_instruction_hook:={$ifdef FPCPROCVAR}@{$endif}add_reg_instruction;
  451. end;
  452. procedure tcg.done_register_allocators;
  453. begin
  454. { Safety }
  455. fillchar(rg,sizeof(rg),0);
  456. add_reg_instruction_hook:=nil;
  457. end;
  458. {$ifdef flowgraph}
  459. procedure Tcg.init_flowgraph;
  460. begin
  461. aktflownode:=0;
  462. end;
  463. procedure Tcg.done_flowgraph;
  464. begin
  465. end;
  466. {$endif}
  467. function tcg.getintregister(list:Taasmoutput;size:Tcgsize):Tregister;
  468. begin
  469. if not assigned(rg[R_INTREGISTER]) then
  470. internalerror(200312122);
  471. result:=rg[R_INTREGISTER].getregister(list,cgsize2subreg(size));
  472. end;
  473. function tcg.getfpuregister(list:Taasmoutput;size:Tcgsize):Tregister;
  474. begin
  475. if not assigned(rg[R_FPUREGISTER]) then
  476. internalerror(200312123);
  477. result:=rg[R_FPUREGISTER].getregister(list,cgsize2subreg(size));
  478. end;
  479. function tcg.getmmregister(list:Taasmoutput;size:Tcgsize):Tregister;
  480. begin
  481. if not assigned(rg[R_MMREGISTER]) then
  482. internalerror(200312124);
  483. result:=rg[R_MMREGISTER].getregister(list,cgsize2subreg(size));
  484. end;
  485. function tcg.getaddressregister(list:Taasmoutput):Tregister;
  486. begin
  487. if assigned(rg[R_ADDRESSREGISTER]) then
  488. result:=rg[R_ADDRESSREGISTER].getregister(list,R_SUBWHOLE)
  489. else
  490. begin
  491. if not assigned(rg[R_INTREGISTER]) then
  492. internalerror(200312121);
  493. result:=rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  494. end;
  495. end;
  496. function Tcg.makeregsize(list:Taasmoutput;reg:Tregister;size:Tcgsize):Tregister;
  497. var
  498. subreg:Tsubregister;
  499. begin
  500. subreg:=cgsize2subreg(size);
  501. result:=reg;
  502. setsubreg(result,subreg);
  503. { notify RA }
  504. if result<>reg then
  505. list.concat(tai_regalloc.resize(result));
  506. end;
  507. procedure tcg.getexplicitregister(list:Taasmoutput;r:Tregister);
  508. begin
  509. if not assigned(rg[getregtype(r)]) then
  510. internalerror(200312125);
  511. rg[getregtype(r)].getexplicitregister(list,r);
  512. end;
  513. procedure tcg.ungetregister(list:Taasmoutput;r:Tregister);
  514. begin
  515. if not assigned(rg[getregtype(r)]) then
  516. internalerror(200312126);
  517. rg[getregtype(r)].ungetregister(list,r);
  518. end;
  519. procedure tcg.ungetreference(list:Taasmoutput;const r:Treference);
  520. begin
  521. if r.base<>NR_NO then
  522. ungetregister(list,r.base);
  523. if r.index<>NR_NO then
  524. ungetregister(list,r.index);
  525. end;
  526. procedure tcg.allocexplicitregisters(list:Taasmoutput;rt:Tregistertype;r:Tcpuregisterset);
  527. begin
  528. if assigned(rg[rt]) then
  529. rg[rt].allocexplicitregisters(list,r)
  530. else
  531. internalerror(200310092);
  532. end;
  533. procedure tcg.deallocexplicitregisters(list:Taasmoutput;rt:Tregistertype;r:Tcpuregisterset);
  534. begin
  535. if assigned(rg[rt]) then
  536. rg[rt].deallocexplicitregisters(list,r)
  537. else
  538. internalerror(200310093);
  539. end;
  540. function tcg.uses_registers(rt:Tregistertype):boolean;
  541. begin
  542. if assigned(rg[rt]) then
  543. result:=rg[rt].uses_registers
  544. else
  545. result:=false;
  546. end;
  547. procedure tcg.add_reg_instruction(instr:Tai;r:tregister);
  548. var
  549. rt : tregistertype;
  550. begin
  551. rt:=getregtype(r);
  552. { Only add it when a register allocator is configured.
  553. No IE can be generated, because the VMT is written
  554. without a valid rg[] }
  555. if assigned(rg[rt]) then
  556. rg[rt].add_reg_instruction(instr,r);
  557. end;
  558. procedure tcg.add_move_instruction(instr:Taicpu);
  559. var
  560. rt : tregistertype;
  561. begin
  562. rt:=getregtype(instr.oper[O_MOV_SOURCE]^.reg);
  563. if assigned(rg[rt]) then
  564. rg[rt].add_move_instruction(instr)
  565. else
  566. internalerror(200310095);
  567. end;
  568. procedure tcg.do_register_allocation(list:Taasmoutput;headertai:tai);
  569. var
  570. rt : tregistertype;
  571. begin
  572. for rt:=R_FPUREGISTER to R_SPECIALREGISTER do
  573. begin
  574. if assigned(rg[rt]) then
  575. rg[rt].do_register_allocation(list,headertai);
  576. end;
  577. { running the other register allocator passes could require addition int/addr. registers
  578. when spilling so run int/addr register allocation at the end }
  579. if assigned(rg[R_INTREGISTER]) then
  580. rg[R_INTREGISTER].do_register_allocation(list,headertai);
  581. if assigned(rg[R_ADDRESSREGISTER]) then
  582. rg[R_ADDRESSREGISTER].do_register_allocation(list,headertai);
  583. end;
  584. procedure tcg.a_reg_alloc(list : taasmoutput;r : tregister);
  585. begin
  586. list.concat(tai_regalloc.alloc(r));
  587. end;
  588. procedure tcg.a_reg_dealloc(list : taasmoutput;r : tregister);
  589. begin
  590. list.concat(tai_regalloc.dealloc(r));
  591. end;
  592. procedure tcg.a_label(list : taasmoutput;l : tasmlabel);
  593. begin
  594. list.concat(tai_label.create(l));
  595. end;
  596. {*****************************************************************************
  597. for better code generation these methods should be overridden
  598. ******************************************************************************}
  599. procedure tcg.a_param_reg(list : taasmoutput;size : tcgsize;r : tregister;const locpara : tparalocation);
  600. var
  601. ref : treference;
  602. begin
  603. case locpara.loc of
  604. LOC_REGISTER,LOC_CREGISTER:
  605. a_load_reg_reg(list,size,locpara.size,r,locpara.register);
  606. LOC_REFERENCE,LOC_CREFERENCE:
  607. begin
  608. reference_reset(ref);
  609. ref.base:=locpara.reference.index;
  610. ref.offset:=locpara.reference.offset;
  611. a_load_reg_ref(list,size,locpara.size,r,ref);
  612. end
  613. else
  614. internalerror(2002071004);
  615. end;
  616. end;
  617. procedure tcg.a_param_const(list : taasmoutput;size : tcgsize;a : aint;const locpara : tparalocation);
  618. var
  619. ref : treference;
  620. begin
  621. case locpara.loc of
  622. LOC_REGISTER,LOC_CREGISTER:
  623. a_load_const_reg(list,locpara.size,a,locpara.register);
  624. LOC_REFERENCE,LOC_CREFERENCE:
  625. begin
  626. reference_reset(ref);
  627. ref.base:=locpara.reference.index;
  628. ref.offset:=locpara.reference.offset;
  629. a_load_const_ref(list,locpara.size,a,ref);
  630. end
  631. else
  632. internalerror(2002071004);
  633. end;
  634. end;
  635. procedure tcg.a_param_ref(list : taasmoutput;size : tcgsize;const r : treference;const locpara : tparalocation);
  636. var
  637. ref : treference;
  638. begin
  639. case locpara.loc of
  640. LOC_REGISTER,LOC_CREGISTER:
  641. a_load_ref_reg(list,size,locpara.size,r,locpara.register);
  642. LOC_REFERENCE,LOC_CREFERENCE:
  643. begin
  644. reference_reset(ref);
  645. ref.base:=locpara.reference.index;
  646. ref.offset:=locpara.reference.offset;
  647. { use concatcopy, because it can also be a float which fails when
  648. load_ref_ref is used }
  649. g_concatcopy(list,r,ref,tcgsize2size[size],false,false);
  650. end
  651. else
  652. internalerror(2002071004);
  653. end;
  654. end;
  655. procedure tcg.a_param_loc(list : taasmoutput;const l:tlocation;const locpara : tparalocation);
  656. begin
  657. case l.loc of
  658. LOC_REGISTER,
  659. LOC_CREGISTER :
  660. a_param_reg(list,l.size,l.register,locpara);
  661. LOC_CONSTANT :
  662. a_param_const(list,l.size,l.value,locpara);
  663. LOC_CREFERENCE,
  664. LOC_REFERENCE :
  665. a_param_ref(list,l.size,l.reference,locpara);
  666. else
  667. internalerror(2002032211);
  668. end;
  669. end;
  670. procedure tcg.a_paramaddr_ref(list : taasmoutput;const r : treference;const locpara : tparalocation);
  671. var
  672. hr : tregister;
  673. begin
  674. hr:=getaddressregister(list);
  675. a_loadaddr_ref_reg(list,r,hr);
  676. ungetregister(list,hr);
  677. a_param_reg(list,OS_ADDR,hr,locpara);
  678. end;
  679. procedure tcg.a_param_copy_ref(list : taasmoutput;size : aint;const r : treference;const locpara : tparalocation);
  680. var
  681. ref : treference;
  682. begin
  683. if not(locpara.loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  684. internalerror(2003010901);
  685. reference_reset_base(ref,locpara.reference.index,locpara.reference.offset);
  686. g_concatcopy(list,r,ref,size,false,false);
  687. end;
  688. procedure tcg.a_loadany_param_ref(list : taasmoutput;const locpara : tparalocation;const ref:treference;shuffle : pmmshuffle);
  689. begin
  690. case locpara.loc of
  691. LOC_CREGISTER,
  692. LOC_REGISTER:
  693. begin
  694. {$ifndef cpu64bit}
  695. if (locpara.size in [OS_S64,OS_64]) then
  696. begin
  697. getexplicitregister(list,locpara.registerlow);
  698. getexplicitregister(list,locpara.registerhigh);
  699. ungetregister(list,locpara.registerlow);
  700. ungetregister(list,locpara.registerhigh);
  701. cg64.a_load64_reg_ref(list,locpara.register64,ref)
  702. end
  703. else
  704. {$endif cpu64bit}
  705. begin
  706. getexplicitregister(list,locpara.register);
  707. ungetregister(list,locpara.register);
  708. a_load_reg_ref(list,locpara.size,locpara.size,locpara.register,ref);
  709. end;
  710. end;
  711. LOC_MMREGISTER,
  712. LOC_CMMREGISTER:
  713. begin
  714. getexplicitregister(list,locpara.register);
  715. ungetregister(list,locpara.register);
  716. a_loadmm_reg_ref(list,locpara.size,locpara.size,locpara.register,ref,shuffle);
  717. end;
  718. LOC_FPUREGISTER,
  719. LOC_CFPUREGISTER:
  720. begin
  721. getexplicitregister(list,locpara.register);
  722. ungetregister(list,locpara.register);
  723. a_loadfpu_reg_ref(list,locpara.size,locpara.register,ref);
  724. end;
  725. else
  726. internalerror(2002081302);
  727. end;
  728. end;
  729. procedure tcg.a_loadany_param_reg(list : taasmoutput;const locpara : tparalocation;const reg:tregister;shuffle : pmmshuffle);
  730. var
  731. href : treference;
  732. begin
  733. case locpara.loc of
  734. LOC_CREGISTER,
  735. LOC_REGISTER:
  736. begin
  737. if not(locpara.size in [OS_S64,OS_64]) then
  738. begin
  739. getexplicitregister(list,locpara.register);
  740. ungetregister(list,locpara.register);
  741. {
  742. This is now a normal imaginary register, allocated the usual way (JM)
  743. getexplicitregister(list,reg);
  744. }
  745. a_load_reg_reg(list,locpara.size,locpara.size,locpara.register,reg)
  746. end
  747. else
  748. internalerror(2003053011);
  749. end;
  750. LOC_CFPUREGISTER,
  751. LOC_FPUREGISTER:
  752. begin
  753. getexplicitregister(list,locpara.register);
  754. ungetregister(list,locpara.register);
  755. {
  756. This is now a normal imaginary register, allocated the usual way (JM)
  757. getexplicitregister(list,reg);
  758. }
  759. a_loadfpu_reg_reg(list,locpara.size,locpara.register,reg);
  760. end;
  761. LOC_MMREGISTER,
  762. LOC_CMMREGISTER:
  763. begin
  764. getexplicitregister(list,locpara.register);
  765. ungetregister(list,locpara.register);
  766. {
  767. This is now a normal imaginary register, allocated the usual way (JM)
  768. getexplicitregister(list,reg);
  769. }
  770. a_loadmm_reg_reg(list,locpara.size,locpara.size,locpara.register,reg,shuffle);
  771. end;
  772. LOC_REFERENCE,
  773. LOC_CREFERENCE:
  774. begin
  775. reference_reset_base(href,locpara.reference.index,locpara.reference.offset);
  776. {
  777. This is now a normal imaginary register, allocated the usual way (JM)
  778. getexplicitregister(list,reg);
  779. }
  780. a_load_ref_reg(list,locpara.size,locpara.size,href,reg);
  781. end;
  782. else
  783. internalerror(2003053010);
  784. end
  785. end;
  786. {****************************************************************************
  787. some generic implementations
  788. ****************************************************************************}
  789. procedure tcg.a_load_ref_ref(list : taasmoutput;fromsize,tosize : tcgsize;const sref : treference;const dref : treference);
  790. var
  791. tmpreg: tregister;
  792. begin
  793. { verify if we have the same reference }
  794. if references_equal(sref,dref) then
  795. exit;
  796. tmpreg:=getintregister(list,tosize);
  797. a_load_ref_reg(list,fromsize,tosize,sref,tmpreg);
  798. a_load_reg_ref(list,tosize,tosize,tmpreg,dref);
  799. ungetregister(list,tmpreg);
  800. end;
  801. procedure tcg.a_load_const_ref(list : taasmoutput;size : tcgsize;a : aint;const ref : treference);
  802. var
  803. tmpreg: tregister;
  804. begin
  805. tmpreg:=getintregister(list,size);
  806. a_load_const_reg(list,size,a,tmpreg);
  807. a_load_reg_ref(list,size,size,tmpreg,ref);
  808. ungetregister(list,tmpreg);
  809. end;
  810. procedure tcg.a_load_const_loc(list : taasmoutput;a : aint;const loc: tlocation);
  811. begin
  812. case loc.loc of
  813. LOC_REFERENCE,LOC_CREFERENCE:
  814. a_load_const_ref(list,loc.size,a,loc.reference);
  815. LOC_REGISTER,LOC_CREGISTER:
  816. a_load_const_reg(list,loc.size,a,loc.register);
  817. else
  818. internalerror(200203272);
  819. end;
  820. end;
  821. procedure tcg.a_load_reg_loc(list : taasmoutput;fromsize : tcgsize;reg : tregister;const loc: tlocation);
  822. begin
  823. case loc.loc of
  824. LOC_REFERENCE,LOC_CREFERENCE:
  825. a_load_reg_ref(list,fromsize,loc.size,reg,loc.reference);
  826. LOC_REGISTER,LOC_CREGISTER:
  827. a_load_reg_reg(list,fromsize,loc.size,reg,loc.register);
  828. else
  829. internalerror(200203271);
  830. end;
  831. end;
  832. procedure tcg.a_load_loc_reg(list : taasmoutput; tosize: tcgsize; const loc: tlocation; reg : tregister);
  833. begin
  834. case loc.loc of
  835. LOC_REFERENCE,LOC_CREFERENCE:
  836. a_load_ref_reg(list,loc.size,tosize,loc.reference,reg);
  837. LOC_REGISTER,LOC_CREGISTER:
  838. a_load_reg_reg(list,loc.size,tosize,loc.register,reg);
  839. LOC_CONSTANT:
  840. a_load_const_reg(list,tosize,loc.value,reg);
  841. else
  842. internalerror(200109092);
  843. end;
  844. end;
  845. procedure tcg.a_load_loc_ref(list : taasmoutput;tosize: tcgsize; const loc: tlocation; const ref : treference);
  846. begin
  847. case loc.loc of
  848. LOC_REFERENCE,LOC_CREFERENCE:
  849. a_load_ref_ref(list,loc.size,tosize,loc.reference,ref);
  850. LOC_REGISTER,LOC_CREGISTER:
  851. a_load_reg_ref(list,loc.size,tosize,loc.register,ref);
  852. LOC_CONSTANT:
  853. a_load_const_ref(list,tosize,loc.value,ref);
  854. else
  855. internalerror(200109302);
  856. end;
  857. end;
  858. function tcg.optimize_op_const_reg(list: taasmoutput; var op: topcg; var a : aint; var reg:tregister): boolean;
  859. var
  860. powerval : longint;
  861. begin
  862. optimize_op_const_reg := false;
  863. case op of
  864. { or with zero returns same result }
  865. OP_OR : if a = 0 then optimize_op_const_reg := true;
  866. { and with max returns same result }
  867. OP_AND : if (a = high(a)) then optimize_op_const_reg := true;
  868. { division by 1 returns result }
  869. OP_DIV :
  870. begin
  871. if a = 1 then
  872. optimize_op_const_reg := true
  873. else if ispowerof2(int64(a), powerval) then
  874. begin
  875. a := powerval;
  876. op:= OP_SHR;
  877. end;
  878. exit;
  879. end;
  880. OP_IDIV:
  881. begin
  882. if a = 1 then
  883. optimize_op_const_reg := true
  884. else if ispowerof2(int64(a), powerval) then
  885. begin
  886. a := powerval;
  887. op:= OP_SAR;
  888. end;
  889. exit;
  890. end;
  891. OP_MUL,OP_IMUL:
  892. begin
  893. if a = 1 then
  894. optimize_op_const_reg := true
  895. else if ispowerof2(int64(a), powerval) then
  896. begin
  897. a := powerval;
  898. op:= OP_SHL;
  899. end;
  900. exit;
  901. end;
  902. OP_SAR,OP_SHL,OP_SHR:
  903. begin
  904. if a = 0 then
  905. optimize_op_const_reg := true;
  906. exit;
  907. end;
  908. end;
  909. end;
  910. procedure tcg.a_loadfpu_loc_reg(list: taasmoutput; const loc: tlocation; const reg: tregister);
  911. begin
  912. case loc.loc of
  913. LOC_REFERENCE, LOC_CREFERENCE:
  914. a_loadfpu_ref_reg(list,loc.size,loc.reference,reg);
  915. LOC_FPUREGISTER, LOC_CFPUREGISTER:
  916. a_loadfpu_reg_reg(list,loc.size,loc.register,reg);
  917. else
  918. internalerror(200203301);
  919. end;
  920. end;
  921. procedure tcg.a_loadfpu_reg_loc(list: taasmoutput; size: tcgsize; const reg: tregister; const loc: tlocation);
  922. begin
  923. case loc.loc of
  924. LOC_REFERENCE, LOC_CREFERENCE:
  925. a_loadfpu_reg_ref(list,size,reg,loc.reference);
  926. LOC_FPUREGISTER, LOC_CFPUREGISTER:
  927. a_loadfpu_reg_reg(list,size,reg,loc.register);
  928. else
  929. internalerror(48991);
  930. end;
  931. end;
  932. procedure tcg.a_paramfpu_reg(list : taasmoutput;size : tcgsize;const r : tregister;const locpara : tparalocation);
  933. var
  934. ref : treference;
  935. begin
  936. case locpara.loc of
  937. LOC_FPUREGISTER,LOC_CFPUREGISTER:
  938. a_loadfpu_reg_reg(list,size,r,locpara.register);
  939. LOC_REFERENCE,LOC_CREFERENCE:
  940. begin
  941. reference_reset(ref);
  942. ref.base:=locpara.reference.index;
  943. ref.offset:=locpara.reference.offset;
  944. a_loadfpu_reg_ref(list,size,r,ref);
  945. end
  946. else
  947. internalerror(2002071004);
  948. end;
  949. end;
  950. procedure tcg.a_paramfpu_ref(list : taasmoutput;size : tcgsize;const ref : treference;const locpara : tparalocation);
  951. var
  952. href : treference;
  953. begin
  954. case locpara.loc of
  955. LOC_FPUREGISTER,LOC_CFPUREGISTER:
  956. a_loadfpu_ref_reg(list,size,ref,locpara.register);
  957. LOC_REFERENCE,LOC_CREFERENCE:
  958. begin
  959. reference_reset(href);
  960. href.base:=locpara.reference.index;
  961. href.offset:=locpara.reference.offset;
  962. { concatcopy should choose the best way to copy the data }
  963. g_concatcopy(list,ref,href,tcgsize2size[size],false,false);
  964. end
  965. else
  966. internalerror(200402201);
  967. end;
  968. end;
  969. procedure tcg.a_op_const_ref(list : taasmoutput; Op: TOpCG; size: TCGSize; a: aint; const ref: TReference);
  970. var
  971. tmpreg: tregister;
  972. begin
  973. tmpreg:=getintregister(list,size);
  974. a_load_ref_reg(list,size,size,ref,tmpreg);
  975. a_op_const_reg(list,op,size,a,tmpreg);
  976. a_load_reg_ref(list,size,size,tmpreg,ref);
  977. ungetregister(list,tmpreg);
  978. end;
  979. procedure tcg.a_op_const_loc(list : taasmoutput; Op: TOpCG; a: aint; const loc: tlocation);
  980. begin
  981. case loc.loc of
  982. LOC_REGISTER, LOC_CREGISTER:
  983. a_op_const_reg(list,op,loc.size,a,loc.register);
  984. LOC_REFERENCE, LOC_CREFERENCE:
  985. a_op_const_ref(list,op,loc.size,a,loc.reference);
  986. else
  987. internalerror(200109061);
  988. end;
  989. end;
  990. procedure tcg.a_op_reg_ref(list : taasmoutput; Op: TOpCG; size: TCGSize;reg: TRegister; const ref: TReference);
  991. var
  992. tmpreg: tregister;
  993. begin
  994. tmpreg:=getintregister(list,size);
  995. a_load_ref_reg(list,size,size,ref,tmpreg);
  996. a_op_reg_reg(list,op,size,reg,tmpreg);
  997. a_load_reg_ref(list,size,size,tmpreg,ref);
  998. ungetregister(list,tmpreg);
  999. end;
  1000. procedure tcg.a_op_ref_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; const ref: TReference; reg: TRegister);
  1001. var
  1002. tmpreg: tregister;
  1003. begin
  1004. case op of
  1005. OP_NOT,OP_NEG:
  1006. { handle it as "load ref,reg; op reg" }
  1007. begin
  1008. a_load_ref_reg(list,size,size,ref,reg);
  1009. a_op_reg_reg(list,op,size,reg,reg);
  1010. end;
  1011. else
  1012. begin
  1013. tmpreg:=getintregister(list,size);
  1014. a_load_ref_reg(list,size,size,ref,tmpreg);
  1015. a_op_reg_reg(list,op,size,tmpreg,reg);
  1016. ungetregister(list,tmpreg);
  1017. end;
  1018. end;
  1019. end;
  1020. procedure tcg.a_op_reg_loc(list : taasmoutput; Op: TOpCG; reg: tregister; const loc: tlocation);
  1021. begin
  1022. case loc.loc of
  1023. LOC_REGISTER, LOC_CREGISTER:
  1024. a_op_reg_reg(list,op,loc.size,reg,loc.register);
  1025. LOC_REFERENCE, LOC_CREFERENCE:
  1026. a_op_reg_ref(list,op,loc.size,reg,loc.reference);
  1027. else
  1028. internalerror(200109061);
  1029. end;
  1030. end;
  1031. procedure tcg.a_op_ref_loc(list : taasmoutput; Op: TOpCG; const ref: TReference; const loc: tlocation);
  1032. var
  1033. tmpreg: tregister;
  1034. begin
  1035. case loc.loc of
  1036. LOC_REGISTER,LOC_CREGISTER:
  1037. a_op_ref_reg(list,op,loc.size,ref,loc.register);
  1038. LOC_REFERENCE,LOC_CREFERENCE:
  1039. begin
  1040. tmpreg:=getintregister(list,loc.size);
  1041. a_load_ref_reg(list,loc.size,loc.size,ref,tmpreg);
  1042. a_op_reg_ref(list,op,loc.size,tmpreg,loc.reference);
  1043. ungetregister(list,tmpreg);
  1044. end;
  1045. else
  1046. internalerror(200109061);
  1047. end;
  1048. end;
  1049. procedure Tcg.a_op_const_reg_reg(list:Taasmoutput;op:Topcg;size:Tcgsize;
  1050. a:aint;src,dst:Tregister);
  1051. begin
  1052. a_load_reg_reg(list,size,size,src,dst);
  1053. a_op_const_reg(list,op,size,a,dst);
  1054. end;
  1055. procedure tcg.a_op_reg_reg_reg(list: taasmoutput; op: TOpCg;
  1056. size: tcgsize; src1, src2, dst: tregister);
  1057. var
  1058. tmpreg: tregister;
  1059. begin
  1060. if (dst<>src1) then
  1061. begin
  1062. a_load_reg_reg(list,size,size,src2,dst);
  1063. a_op_reg_reg(list,op,size,src1,dst);
  1064. end
  1065. else
  1066. begin
  1067. tmpreg:=getintregister(list,size);
  1068. a_load_reg_reg(list,size,size,src2,tmpreg);
  1069. a_op_reg_reg(list,op,size,src1,tmpreg);
  1070. a_load_reg_reg(list,size,size,tmpreg,dst);
  1071. ungetregister(list,tmpreg);
  1072. end;
  1073. end;
  1074. procedure tcg.a_cmp_const_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aint;const ref : treference;
  1075. l : tasmlabel);
  1076. var
  1077. tmpreg: tregister;
  1078. begin
  1079. tmpreg:=getintregister(list,size);
  1080. a_load_ref_reg(list,size,size,ref,tmpreg);
  1081. a_cmp_const_reg_label(list,size,cmp_op,a,tmpreg,l);
  1082. ungetregister(list,tmpreg);
  1083. end;
  1084. procedure tcg.a_cmp_const_loc_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aint;const loc : tlocation;
  1085. l : tasmlabel);
  1086. begin
  1087. case loc.loc of
  1088. LOC_REGISTER,LOC_CREGISTER:
  1089. a_cmp_const_reg_label(list,size,cmp_op,a,loc.register,l);
  1090. LOC_REFERENCE,LOC_CREFERENCE:
  1091. a_cmp_const_ref_label(list,size,cmp_op,a,loc.reference,l);
  1092. else
  1093. internalerror(200109061);
  1094. end;
  1095. end;
  1096. procedure tcg.a_cmp_ref_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; const ref: treference; reg : tregister; l : tasmlabel);
  1097. var
  1098. tmpreg: tregister;
  1099. begin
  1100. tmpreg:=getintregister(list,size);
  1101. a_load_ref_reg(list,size,size,ref,tmpreg);
  1102. a_cmp_reg_reg_label(list,size,cmp_op,tmpreg,reg,l);
  1103. ungetregister(list,tmpreg);
  1104. end;
  1105. procedure tcg.a_cmp_reg_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; reg : tregister; const ref: treference; l : tasmlabel);
  1106. var
  1107. tmpreg: tregister;
  1108. begin
  1109. tmpreg:=getintregister(list,size);
  1110. a_load_ref_reg(list,size,size,ref,tmpreg);
  1111. a_cmp_reg_reg_label(list,size,cmp_op,reg,tmpreg,l);
  1112. ungetregister(list,tmpreg);
  1113. end;
  1114. procedure tcg.a_cmp_loc_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; const loc: tlocation; reg : tregister; l : tasmlabel);
  1115. begin
  1116. case loc.loc of
  1117. LOC_REGISTER,
  1118. LOC_CREGISTER:
  1119. a_cmp_reg_reg_label(list,size,cmp_op,loc.register,reg,l);
  1120. LOC_REFERENCE,
  1121. LOC_CREFERENCE :
  1122. a_cmp_ref_reg_label(list,size,cmp_op,loc.reference,reg,l);
  1123. LOC_CONSTANT:
  1124. a_cmp_const_reg_label(list,size,cmp_op,loc.value,reg,l);
  1125. else
  1126. internalerror(200203231);
  1127. end;
  1128. end;
  1129. procedure tcg.a_cmp_ref_loc_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;const ref: treference;const loc : tlocation;
  1130. l : tasmlabel);
  1131. var
  1132. tmpreg: tregister;
  1133. begin
  1134. case loc.loc of
  1135. LOC_REGISTER,LOC_CREGISTER:
  1136. a_cmp_ref_reg_label(list,size,cmp_op,ref,loc.register,l);
  1137. LOC_REFERENCE,LOC_CREFERENCE:
  1138. begin
  1139. tmpreg:=getintregister(list,size);
  1140. a_load_ref_reg(list,size,size,loc.reference,tmpreg);
  1141. a_cmp_ref_reg_label(list,size,cmp_op,ref,tmpreg,l);
  1142. ungetregister(list,tmpreg);
  1143. end
  1144. else
  1145. internalerror(200109061);
  1146. end;
  1147. end;
  1148. procedure tcg.a_loadmm_loc_reg(list: taasmoutput; size: tcgsize; const loc: tlocation; const reg: tregister;shuffle : pmmshuffle);
  1149. begin
  1150. case loc.loc of
  1151. LOC_MMREGISTER,LOC_CMMREGISTER:
  1152. a_loadmm_reg_reg(list,loc.size,size,loc.register,reg,shuffle);
  1153. LOC_REFERENCE,LOC_CREFERENCE:
  1154. a_loadmm_ref_reg(list,loc.size,size,loc.reference,reg,shuffle);
  1155. else
  1156. internalerror(200310121);
  1157. end;
  1158. end;
  1159. procedure tcg.a_loadmm_reg_loc(list: taasmoutput; size: tcgsize; const reg: tregister; const loc: tlocation;shuffle : pmmshuffle);
  1160. begin
  1161. case loc.loc of
  1162. LOC_MMREGISTER,LOC_CMMREGISTER:
  1163. a_loadmm_reg_reg(list,size,loc.size,reg,loc.register,shuffle);
  1164. LOC_REFERENCE,LOC_CREFERENCE:
  1165. a_loadmm_reg_ref(list,size,loc.size,reg,loc.reference,shuffle);
  1166. else
  1167. internalerror(200310122);
  1168. end;
  1169. end;
  1170. procedure tcg.a_parammm_reg(list: taasmoutput; size: tcgsize; reg: tregister;const locpara : tparalocation;shuffle : pmmshuffle);
  1171. var
  1172. ref : treference;
  1173. begin
  1174. case locpara.loc of
  1175. LOC_MMREGISTER,LOC_CMMREGISTER:
  1176. a_loadmm_reg_reg(list,size,locpara.size,reg,locpara.register,shuffle);
  1177. LOC_REFERENCE,LOC_CREFERENCE:
  1178. begin
  1179. reference_reset(ref);
  1180. ref.base:=locpara.reference.index;
  1181. ref.offset:=locpara.reference.offset;
  1182. a_loadmm_reg_ref(list,size,locpara.size,reg,ref,shuffle);
  1183. end
  1184. else
  1185. internalerror(200310123);
  1186. end;
  1187. end;
  1188. procedure tcg.a_parammm_ref(list: taasmoutput; size: tcgsize;const ref: treference;const locpara : tparalocation;shuffle : pmmshuffle);
  1189. var
  1190. hr : tregister;
  1191. hs : tmmshuffle;
  1192. begin
  1193. hr:=getmmregister(list,locpara.size);
  1194. a_loadmm_ref_reg(list,size,locpara.size,ref,hr,shuffle);
  1195. if realshuffle(shuffle) then
  1196. begin
  1197. hs:=shuffle^;
  1198. removeshuffles(hs);
  1199. a_parammm_reg(list,locpara.size,hr,locpara,@hs);
  1200. end
  1201. else
  1202. a_parammm_reg(list,locpara.size,hr,locpara,shuffle);
  1203. ungetregister(list,hr);
  1204. end;
  1205. procedure tcg.a_parammm_loc(list: taasmoutput;const loc: tlocation; const locpara : tparalocation;shuffle : pmmshuffle);
  1206. begin
  1207. case loc.loc of
  1208. LOC_MMREGISTER,LOC_CMMREGISTER:
  1209. a_parammm_reg(list,loc.size,loc.register,locpara,shuffle);
  1210. LOC_REFERENCE,LOC_CREFERENCE:
  1211. a_parammm_ref(list,loc.size,loc.reference,locpara,shuffle);
  1212. else
  1213. internalerror(200310123);
  1214. end;
  1215. end;
  1216. procedure tcg.a_opmm_ref_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;const ref: treference; reg: tregister;shuffle : pmmshuffle);
  1217. var
  1218. hr : tregister;
  1219. hs : tmmshuffle;
  1220. begin
  1221. hr:=getmmregister(list,size);
  1222. a_loadmm_ref_reg(list,size,size,ref,hr,shuffle);
  1223. if realshuffle(shuffle) then
  1224. begin
  1225. hs:=shuffle^;
  1226. removeshuffles(hs);
  1227. a_opmm_reg_reg(list,op,size,hr,reg,@hs);
  1228. end
  1229. else
  1230. a_opmm_reg_reg(list,op,size,hr,reg,shuffle);
  1231. ungetregister(list,hr);
  1232. end;
  1233. procedure tcg.a_opmm_reg_ref(list: taasmoutput; Op: TOpCG; size : tcgsize;reg: tregister; const ref: treference; shuffle : pmmshuffle);
  1234. var
  1235. hr : tregister;
  1236. hs : tmmshuffle;
  1237. begin
  1238. hr:=getmmregister(list,size);
  1239. a_loadmm_ref_reg(list,size,size,ref,hr,shuffle);
  1240. if realshuffle(shuffle) then
  1241. begin
  1242. hs:=shuffle^;
  1243. removeshuffles(hs);
  1244. a_opmm_reg_reg(list,op,size,reg,hr,@hs);
  1245. a_loadmm_reg_ref(list,size,size,hr,ref,@hs);
  1246. end
  1247. else
  1248. begin
  1249. a_opmm_reg_reg(list,op,size,reg,hr,shuffle);
  1250. a_loadmm_reg_ref(list,size,size,hr,ref,shuffle);
  1251. end;
  1252. ungetregister(list,hr);
  1253. end;
  1254. procedure tcg.a_opmm_loc_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;const loc: tlocation; reg: tregister;shuffle : pmmshuffle);
  1255. begin
  1256. case loc.loc of
  1257. LOC_CMMREGISTER,LOC_MMREGISTER:
  1258. a_opmm_reg_reg(list,op,size,loc.register,reg,shuffle);
  1259. LOC_CREFERENCE,LOC_REFERENCE:
  1260. a_opmm_ref_reg(list,op,size,loc.reference,reg,shuffle);
  1261. else
  1262. internalerror(200312232);
  1263. end;
  1264. end;
  1265. procedure tcg.g_copyshortstring(list : taasmoutput;const source,dest : treference;len:byte;delsource,loadref : boolean);
  1266. var
  1267. paraloc1,paraloc2,paraloc3 : tparalocation;
  1268. begin
  1269. {$ifdef FPC}
  1270. {$warning FIX ME!}
  1271. {$endif}
  1272. paraloc1:=paramanager.getintparaloc(pocall_default,1);
  1273. paraloc2:=paramanager.getintparaloc(pocall_default,2);
  1274. paraloc3:=paramanager.getintparaloc(pocall_default,3);
  1275. paramanager.allocparaloc(list,paraloc3);
  1276. a_paramaddr_ref(list,dest,paraloc3);
  1277. paramanager.allocparaloc(list,paraloc2);
  1278. if loadref then
  1279. a_param_ref(list,OS_ADDR,source,paraloc2)
  1280. else
  1281. a_paramaddr_ref(list,source,paraloc2);
  1282. if delsource then
  1283. reference_release(list,source);
  1284. paramanager.allocparaloc(list,paraloc1);
  1285. a_param_const(list,OS_INT,len,paraloc1);
  1286. paramanager.freeparaloc(list,paraloc3);
  1287. paramanager.freeparaloc(list,paraloc2);
  1288. paramanager.freeparaloc(list,paraloc1);
  1289. allocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1290. a_call_name(list,'FPC_SHORTSTR_ASSIGN');
  1291. deallocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1292. end;
  1293. procedure tcg.g_incrrefcount(list : taasmoutput;t: tdef; const ref: treference;loadref : boolean);
  1294. var
  1295. href : treference;
  1296. incrfunc : string;
  1297. paraloc1,paraloc2 : tparalocation;
  1298. begin
  1299. paraloc1:=paramanager.getintparaloc(pocall_default,1);
  1300. paraloc2:=paramanager.getintparaloc(pocall_default,2);
  1301. { These functions should not change the registers (they use
  1302. the saveregister proc directive }
  1303. if is_interfacecom(t) then
  1304. incrfunc:='FPC_INTF_INCR_REF'
  1305. else if is_ansistring(t) then
  1306. {$ifdef ansistring_bits}
  1307. begin
  1308. case Tstringdef(t).string_typ of
  1309. st_ansistring16:
  1310. incrfunc:='FPC_ANSISTR16_INCR_REF';
  1311. st_ansistring32:
  1312. incrfunc:='FPC_ANSISTR32_INCR_REF';
  1313. st_ansistring64:
  1314. incrfunc:='FPC_ANSISTR64_INCR_REF';
  1315. end;
  1316. end
  1317. {$else}
  1318. incrfunc:='FPC_ANSISTR_INCR_REF'
  1319. {$endif}
  1320. else if is_widestring(t) then
  1321. incrfunc:='FPC_WIDESTR_INCR_REF'
  1322. else if is_dynamic_array(t) then
  1323. incrfunc:='FPC_DYNARRAY_INCR_REF'
  1324. else
  1325. incrfunc:='';
  1326. { call the special incr function or the generic addref }
  1327. if incrfunc<>'' then
  1328. begin
  1329. { these functions get the pointer by value }
  1330. paramanager.allocparaloc(list,paraloc1);
  1331. a_param_ref(list,OS_ADDR,ref,paraloc1);
  1332. paramanager.freeparaloc(list,paraloc1);
  1333. allocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1334. a_call_name(list,incrfunc);
  1335. deallocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1336. end
  1337. else
  1338. begin
  1339. reference_reset_symbol(href,tstoreddef(t).get_rtti_label(initrtti),0);
  1340. paramanager.allocparaloc(list,paraloc2);
  1341. a_paramaddr_ref(list,href,paraloc2);
  1342. paramanager.allocparaloc(list,paraloc1);
  1343. if loadref then
  1344. a_param_ref(list,OS_ADDR,ref,paraloc1)
  1345. else
  1346. a_paramaddr_ref(list,ref,paraloc1);
  1347. paramanager.freeparaloc(list,paraloc1);
  1348. paramanager.freeparaloc(list,paraloc2);
  1349. allocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1350. a_call_name(list,'FPC_ADDREF');
  1351. deallocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1352. end;
  1353. end;
  1354. procedure tcg.g_decrrefcount(list : taasmoutput;t: tdef; const ref: treference; loadref:boolean);
  1355. var
  1356. hreg : tregister;
  1357. href : treference;
  1358. decrfunc : string;
  1359. needrtti : boolean;
  1360. paraloc1,paraloc2 : tparalocation;
  1361. begin
  1362. paraloc1:=paramanager.getintparaloc(pocall_default,1);
  1363. paraloc2:=paramanager.getintparaloc(pocall_default,2);
  1364. needrtti:=false;
  1365. if is_interfacecom(t) then
  1366. decrfunc:='FPC_INTF_DECR_REF'
  1367. else if is_ansistring(t) then
  1368. {$ifdef ansistring_bits}
  1369. begin
  1370. case Tstringdef(t).string_typ of
  1371. st_ansistring16:
  1372. decrfunc:='FPC_ANSISTR16_DECR_REF';
  1373. st_ansistring32:
  1374. decrfunc:='FPC_ANSISTR32_DECR_REF';
  1375. st_ansistring64:
  1376. decrfunc:='FPC_ANSISTR64_DECR_REF';
  1377. end;
  1378. end
  1379. {$else}
  1380. decrfunc:='FPC_ANSISTR_DECR_REF'
  1381. {$endif}
  1382. else if is_widestring(t) then
  1383. decrfunc:='FPC_WIDESTR_DECR_REF'
  1384. else if is_dynamic_array(t) then
  1385. begin
  1386. decrfunc:='FPC_DYNARRAY_DECR_REF';
  1387. needrtti:=true;
  1388. end
  1389. else
  1390. decrfunc:='';
  1391. { call the special decr function or the generic decref }
  1392. if decrfunc<>'' then
  1393. begin
  1394. if needrtti then
  1395. begin
  1396. reference_reset_symbol(href,tstoreddef(t).get_rtti_label(initrtti),0);
  1397. paramanager.allocparaloc(list,paraloc2);
  1398. a_paramaddr_ref(list,href,paraloc2);
  1399. end;
  1400. paramanager.allocparaloc(list,paraloc1);
  1401. if loadref then
  1402. a_param_ref(list,OS_ADDR,ref,paraloc1)
  1403. else
  1404. a_paramaddr_ref(list,ref,paraloc1);
  1405. paramanager.freeparaloc(list,paraloc1);
  1406. if needrtti then
  1407. paramanager.freeparaloc(list,paraloc2);
  1408. allocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1409. a_call_name(list,decrfunc);
  1410. deallocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1411. end
  1412. else
  1413. begin
  1414. reference_reset_symbol(href,tstoreddef(t).get_rtti_label(initrtti),0);
  1415. paramanager.allocparaloc(list,paraloc2);
  1416. a_paramaddr_ref(list,href,paraloc2);
  1417. paramanager.allocparaloc(list,paraloc1);
  1418. if loadref then
  1419. a_param_ref(list,OS_ADDR,ref,paraloc1)
  1420. else
  1421. a_paramaddr_ref(list,ref,paraloc1);
  1422. paramanager.freeparaloc(list,paraloc1);
  1423. paramanager.freeparaloc(list,paraloc2);
  1424. allocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1425. a_call_name(list,'FPC_DECREF');
  1426. deallocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1427. end;
  1428. { Temp locations need always to be reset to 0 }
  1429. if tg.istemp(ref) then
  1430. begin
  1431. if loadref then
  1432. begin
  1433. hreg:=getaddressregister(list);
  1434. a_load_ref_reg(list,OS_ADDR,OS_ADDR,ref,hreg);
  1435. reference_reset_base(href,hreg,0);
  1436. a_load_const_ref(list,OS_ADDR,0,href);
  1437. ungetregister(list,hreg);
  1438. end
  1439. else
  1440. a_load_const_ref(list,OS_ADDR,0,ref);
  1441. end;
  1442. end;
  1443. procedure tcg.g_initialize(list : taasmoutput;t : tdef;const ref : treference;loadref : boolean);
  1444. var
  1445. href : treference;
  1446. paraloc1,paraloc2 : tparalocation;
  1447. begin
  1448. paraloc1:=paramanager.getintparaloc(pocall_default,1);
  1449. paraloc2:=paramanager.getintparaloc(pocall_default,2);
  1450. if is_ansistring(t) or
  1451. is_widestring(t) or
  1452. is_interfacecom(t) or
  1453. is_dynamic_array(t) then
  1454. a_load_const_ref(list,OS_ADDR,0,ref)
  1455. else
  1456. begin
  1457. reference_reset_symbol(href,tstoreddef(t).get_rtti_label(initrtti),0);
  1458. paramanager.allocparaloc(list,paraloc2);
  1459. a_paramaddr_ref(list,href,paraloc2);
  1460. paramanager.allocparaloc(list,paraloc1);
  1461. if loadref then
  1462. a_param_ref(list,OS_ADDR,ref,paraloc1)
  1463. else
  1464. a_paramaddr_ref(list,ref,paraloc1);
  1465. paramanager.freeparaloc(list,paraloc1);
  1466. paramanager.freeparaloc(list,paraloc2);
  1467. allocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1468. a_call_name(list,'FPC_INITIALIZE');
  1469. deallocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1470. end;
  1471. end;
  1472. procedure tcg.g_finalize(list : taasmoutput;t : tdef;const ref : treference;loadref : boolean);
  1473. var
  1474. hreg : tregister;
  1475. href : treference;
  1476. paraloc1,paraloc2 : tparalocation;
  1477. begin
  1478. paraloc1:=paramanager.getintparaloc(pocall_default,1);
  1479. paraloc2:=paramanager.getintparaloc(pocall_default,2);
  1480. if is_ansistring(t) or
  1481. is_widestring(t) or
  1482. is_interfacecom(t) then
  1483. begin
  1484. g_decrrefcount(list,t,ref,loadref);
  1485. { Temp locations are already reset to 0 }
  1486. if not tg.istemp(ref) then
  1487. begin
  1488. if loadref then
  1489. begin
  1490. hreg:=getaddressregister(list);
  1491. a_load_ref_reg(list,OS_ADDR,OS_ADDR,ref,hreg);
  1492. reference_reset_base(href,hreg,0);
  1493. a_load_const_ref(list,OS_ADDR,0,href);
  1494. ungetregister(list,hreg);
  1495. end
  1496. else
  1497. a_load_const_ref(list,OS_ADDR,0,ref);
  1498. end;
  1499. end
  1500. else
  1501. begin
  1502. reference_reset_symbol(href,tstoreddef(t).get_rtti_label(initrtti),0);
  1503. paramanager.allocparaloc(list,paraloc2);
  1504. a_paramaddr_ref(list,href,paraloc2);
  1505. paramanager.allocparaloc(list,paraloc1);
  1506. if loadref then
  1507. a_param_ref(list,OS_ADDR,ref,paraloc1)
  1508. else
  1509. a_paramaddr_ref(list,ref,paraloc1);
  1510. paramanager.freeparaloc(list,paraloc1);
  1511. paramanager.freeparaloc(list,paraloc2);
  1512. allocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1513. a_call_name(list,'FPC_FINALIZE');
  1514. deallocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1515. end;
  1516. end;
  1517. procedure tcg.g_rangecheck(list: taasmoutput; const l:tlocation;fromdef,todef: tdef);
  1518. { generate range checking code for the value at location p. The type }
  1519. { type used is checked against todefs ranges. fromdef (p.resulttype.def) }
  1520. { is the original type used at that location. When both defs are equal }
  1521. { the check is also insert (needed for succ,pref,inc,dec) }
  1522. {$ifndef ver1_0}
  1523. const
  1524. aintmax=high(aint);
  1525. {$endif}
  1526. var
  1527. neglabel : tasmlabel;
  1528. hreg : tregister;
  1529. lto,hto,
  1530. lfrom,hfrom : TConstExprInt;
  1531. from_signed: boolean;
  1532. {$ifdef ver1_0}
  1533. aintmax : aint;
  1534. {$endif ver1_0}
  1535. begin
  1536. {$ifdef ver1_0}
  1537. {$ifdef cpu64bit}
  1538. { this is required to prevent incorrect code }
  1539. aintmax:=$7fffffff;
  1540. aintmax:=int64(aintmax shl 16) or int64($ffff);
  1541. aintmax:=int64(aintmax shl 16) or int64($ffff);
  1542. {$else cpu64bit}
  1543. aintmax:=high(aint);
  1544. {$endif cpu64bit}
  1545. {$endif}
  1546. { range checking on and range checkable value? }
  1547. if not(cs_check_range in aktlocalswitches) or
  1548. not(fromdef.deftype in [orddef,enumdef,arraydef]) then
  1549. exit;
  1550. {$ifndef cpu64bit}
  1551. { handle 64bit rangechecks separate for 32bit processors }
  1552. if is_64bit(fromdef) or is_64bit(todef) then
  1553. begin
  1554. cg64.g_rangecheck64(list,l,fromdef,todef);
  1555. exit;
  1556. end;
  1557. {$endif cpu64bit}
  1558. { only check when assigning to scalar, subranges are different, }
  1559. { when todef=fromdef then the check is always generated }
  1560. getrange(fromdef,lfrom,hfrom);
  1561. getrange(todef,lto,hto);
  1562. from_signed := is_signed(fromdef);
  1563. { no range check if from and to are equal and are both longint/dword }
  1564. { (if we have a 32bit processor) or int64/qword, since such }
  1565. { operations can at most cause overflows (JM) }
  1566. { Note that these checks are mostly processor independent, they only }
  1567. { have to be changed once we introduce 64bit subrange types }
  1568. {$ifdef cpu64bit}
  1569. if (fromdef = todef) and
  1570. (fromdef.deftype=orddef) and
  1571. (((((torddef(fromdef).typ = s64bit) and
  1572. (lfrom = low(int64)) and
  1573. (hfrom = high(int64))) or
  1574. ((torddef(fromdef).typ = u64bit) and
  1575. (lfrom = low(qword)) and
  1576. (hfrom = high(qword)))))) then
  1577. exit;
  1578. {$else cpu64bit}
  1579. if (fromdef = todef) and
  1580. (fromdef.deftype=orddef) and
  1581. (((((torddef(fromdef).typ = s32bit) and
  1582. (lfrom = low(longint)) and
  1583. (hfrom = high(longint))) or
  1584. ((torddef(fromdef).typ = u32bit) and
  1585. (lfrom = low(cardinal)) and
  1586. (hfrom = high(cardinal)))))) then
  1587. exit;
  1588. {$endif cpu64bit}
  1589. { if the from-range falls completely in the to-range, no check }
  1590. { is necessary. Don't do this conversion for the largest unsigned type }
  1591. if (todef<>fromdef) and
  1592. (from_signed or (hfrom>=0)) and
  1593. (lto<=lfrom) and (hto>=hfrom) then
  1594. exit;
  1595. { generate the rangecheck code for the def where we are going to }
  1596. { store the result }
  1597. { use the trick that }
  1598. { a <= x <= b <=> 0 <= x-a <= b-a <=> unsigned(x-a) <= unsigned(b-a) }
  1599. { To be able to do that, we have to make sure however that either }
  1600. { fromdef and todef are both signed or unsigned, or that we leave }
  1601. { the parts < 0 and > maxlongint out }
  1602. { is_signed now also works for arrays (it checks the rangetype) (JM) }
  1603. if from_signed xor is_signed(todef) then
  1604. begin
  1605. if from_signed then
  1606. { from is signed, to is unsigned }
  1607. begin
  1608. { if high(from) < 0 -> always range error }
  1609. if (hfrom < 0) or
  1610. { if low(to) > maxlongint also range error }
  1611. (lto > aintmax) then
  1612. begin
  1613. a_call_name(list,'FPC_RANGEERROR');
  1614. exit
  1615. end;
  1616. { from is signed and to is unsigned -> when looking at to }
  1617. { as an signed value, it must be < maxaint (otherwise }
  1618. { it will become negative, which is invalid since "to" is unsigned) }
  1619. if hto < 0 then
  1620. hto := aintmax;
  1621. end
  1622. else
  1623. { from is unsigned, to is signed }
  1624. begin
  1625. if (lfrom > aintmax) or
  1626. (hto < 0) then
  1627. begin
  1628. a_call_name(list,'FPC_RANGEERROR');
  1629. exit
  1630. end;
  1631. { from is unsigned and to is signed -> when looking at to }
  1632. { as an unsigned value, it must be >= 0 (since negative }
  1633. { values are the same as values > maxlongint) }
  1634. if lto < 0 then
  1635. lto := 0;
  1636. end;
  1637. end;
  1638. hreg:=getintregister(list,OS_INT);
  1639. a_load_loc_reg(list,OS_INT,l,hreg);
  1640. a_op_const_reg(list,OP_SUB,OS_INT,aint(lto),hreg);
  1641. objectlibrary.getlabel(neglabel);
  1642. a_cmp_const_reg_label(list,OS_INT,OC_BE,aint(hto-lto),hreg,neglabel);
  1643. { !!! should happen right after the compare (JM) }
  1644. ungetregister(list,hreg);
  1645. a_call_name(list,'FPC_RANGEERROR');
  1646. a_label(list,neglabel);
  1647. end;
  1648. procedure tcg.g_flags2ref(list: taasmoutput; size: TCgSize; const f: tresflags; const ref:TReference);
  1649. var
  1650. tmpreg : tregister;
  1651. begin
  1652. tmpreg:=getintregister(list,size);
  1653. g_flags2reg(list,size,f,tmpreg);
  1654. a_load_reg_ref(list,size,size,tmpreg,ref);
  1655. ungetregister(list,tmpreg);
  1656. end;
  1657. procedure tcg.g_maybe_testself(list : taasmoutput;reg:tregister);
  1658. var
  1659. OKLabel : tasmlabel;
  1660. paraloc1 : tparalocation;
  1661. begin
  1662. if (cs_check_object in aktlocalswitches) or
  1663. (cs_check_range in aktlocalswitches) then
  1664. begin
  1665. objectlibrary.getlabel(oklabel);
  1666. a_cmp_const_reg_label(list,OS_ADDR,OC_NE,0,reg,oklabel);
  1667. paraloc1:=paramanager.getintparaloc(pocall_default,1);
  1668. paramanager.allocparaloc(list,paraloc1);
  1669. a_param_const(list,OS_INT,210,paraloc1);
  1670. paramanager.freeparaloc(list,paraloc1);
  1671. a_call_name(list,'FPC_HANDLEERROR');
  1672. a_label(list,oklabel);
  1673. end;
  1674. end;
  1675. procedure tcg.g_maybe_testvmt(list : taasmoutput;reg:tregister;objdef:tobjectdef);
  1676. var
  1677. hrefvmt : treference;
  1678. paraloc1,paraloc2 : tparalocation;
  1679. begin
  1680. paraloc1:=paramanager.getintparaloc(pocall_default,1);
  1681. paraloc2:=paramanager.getintparaloc(pocall_default,2);
  1682. if (cs_check_object in aktlocalswitches) then
  1683. begin
  1684. reference_reset_symbol(hrefvmt,objectlibrary.newasmsymbol(objdef.vmt_mangledname,AB_EXTERNAL,AT_DATA),0);
  1685. paramanager.allocparaloc(list,paraloc2);
  1686. a_paramaddr_ref(list,hrefvmt,paraloc2);
  1687. paramanager.allocparaloc(list,paraloc1);
  1688. a_param_reg(list,OS_ADDR,reg,paraloc1);
  1689. paramanager.freeparaloc(list,paraloc1);
  1690. paramanager.freeparaloc(list,paraloc2);
  1691. allocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1692. a_call_name(list,'FPC_CHECK_OBJECT_EXT');
  1693. deallocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1694. end
  1695. else
  1696. if (cs_check_range in aktlocalswitches) then
  1697. begin
  1698. paramanager.allocparaloc(list,paraloc1);
  1699. a_param_reg(list,OS_ADDR,reg,paraloc1);
  1700. paramanager.freeparaloc(list,paraloc1);
  1701. allocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1702. a_call_name(list,'FPC_CHECK_OBJECT');
  1703. deallocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1704. end;
  1705. end;
  1706. {*****************************************************************************
  1707. Entry/Exit Code Functions
  1708. *****************************************************************************}
  1709. procedure tcg.g_copyvaluepara_openarray(list : taasmoutput;const ref, lenref:treference;elesize:aint);
  1710. var
  1711. sizereg,sourcereg,destreg : tregister;
  1712. paraloc1,paraloc2,paraloc3 : tparalocation;
  1713. begin
  1714. { because ppc abi doesn't support dynamic stack allocation properly
  1715. open array value parameters are copied onto the heap
  1716. }
  1717. { allocate two registers for len and source }
  1718. sizereg:=getintregister(list,OS_INT);
  1719. sourcereg:=getintregister(list,OS_ADDR);
  1720. destreg:=getintregister(list,OS_ADDR);
  1721. { calculate necessary memory }
  1722. a_load_ref_reg(list,OS_INT,OS_INT,lenref,sizereg);
  1723. a_op_const_reg(list,OP_ADD,OS_INT,1,sizereg);
  1724. a_op_const_reg(list,OP_IMUL,OS_INT,elesize,sizereg);
  1725. { load source }
  1726. a_load_ref_reg(list,OS_ADDR,OS_ADDR,ref,sourcereg);
  1727. { do getmem call }
  1728. paraloc1:=paramanager.getintparaloc(pocall_default,1);
  1729. paramanager.allocparaloc(list,paraloc1);
  1730. a_param_reg(list,OS_INT,sizereg,paraloc1);
  1731. paramanager.freeparaloc(list,paraloc1);
  1732. allocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1733. a_call_name(list,'FPC_GETMEM');
  1734. deallocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1735. a_load_reg_reg(list,OS_ADDR,OS_ADDR,NR_FUNCTION_RESULT_REG,destreg);
  1736. a_load_reg_ref(list,OS_ADDR,OS_ADDR,NR_FUNCTION_RESULT_REG,ref);
  1737. { do move call }
  1738. paraloc1:=paramanager.getintparaloc(pocall_default,1);
  1739. paraloc2:=paramanager.getintparaloc(pocall_default,2);
  1740. paraloc3:=paramanager.getintparaloc(pocall_default,3);
  1741. { load size }
  1742. paramanager.allocparaloc(list,paraloc3);
  1743. a_param_reg(list,OS_INT,sizereg,paraloc3);
  1744. { load destination }
  1745. paramanager.allocparaloc(list,paraloc2);
  1746. a_param_reg(list,OS_ADDR,destreg,paraloc2);
  1747. { load source }
  1748. paramanager.allocparaloc(list,paraloc1);
  1749. a_param_reg(list,OS_ADDR,sourcereg,paraloc1);
  1750. paramanager.freeparaloc(list,paraloc3);
  1751. paramanager.freeparaloc(list,paraloc2);
  1752. paramanager.freeparaloc(list,paraloc1);
  1753. allocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1754. a_call_name(list,'FPC_MOVE');
  1755. deallocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1756. { release used registers }
  1757. ungetregister(list,sizereg);
  1758. ungetregister(list,sourcereg);
  1759. ungetregister(list,destreg);
  1760. end;
  1761. procedure tcg.g_releasevaluepara_openarray(list : taasmoutput;const ref:treference);
  1762. var
  1763. paraloc : tparalocation;
  1764. begin
  1765. { do move call }
  1766. paraloc:=paramanager.getintparaloc(pocall_default,1);
  1767. { load source }
  1768. paramanager.allocparaloc(list,paraloc);
  1769. a_param_ref(list,OS_ADDR,ref,paraloc);
  1770. paramanager.freeparaloc(list,paraloc);
  1771. allocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1772. a_call_name(list,'FPC_FREEMEM');
  1773. deallocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1774. end;
  1775. procedure tcg.g_profilecode(list : taasmoutput);
  1776. begin
  1777. end;
  1778. procedure tcg.g_exception_reason_save(list : taasmoutput; const href : treference);
  1779. begin
  1780. a_load_reg_ref(list, OS_INT, OS_INT, NR_FUNCTION_RESULT_REG, href);
  1781. end;
  1782. procedure tcg.g_exception_reason_save_const(list : taasmoutput; const href : treference; a: aint);
  1783. begin
  1784. a_load_const_ref(list, OS_INT, a, href);
  1785. end;
  1786. procedure tcg.g_exception_reason_load(list : taasmoutput; const href : treference);
  1787. begin
  1788. a_load_ref_reg(list, OS_INT, OS_INT, href, NR_FUNCTION_RESULT_REG);
  1789. end;
  1790. {*****************************************************************************
  1791. TCG64
  1792. *****************************************************************************}
  1793. {$ifndef cpu64bit}
  1794. procedure tcg64.a_op64_const_reg_reg(list: taasmoutput;op:TOpCG;value : int64; regsrc,regdst : tregister64);
  1795. begin
  1796. a_load64_reg_reg(list,regsrc,regdst);
  1797. a_op64_const_reg(list,op,value,regdst);
  1798. end;
  1799. procedure tcg64.a_op64_reg_reg_reg(list: taasmoutput;op:TOpCG;regsrc1,regsrc2,regdst : tregister64);
  1800. var
  1801. tmpreg64 : tregister64;
  1802. begin
  1803. { when src1=dst then we need to first create a temp to prevent
  1804. overwriting src1 with src2 }
  1805. if (regsrc1.reghi=regdst.reghi) or
  1806. (regsrc1.reglo=regdst.reghi) or
  1807. (regsrc1.reghi=regdst.reglo) or
  1808. (regsrc1.reglo=regdst.reglo) then
  1809. begin
  1810. tmpreg64.reglo:=cg.getintregister(list,OS_32);
  1811. tmpreg64.reghi:=cg.getintregister(list,OS_32);
  1812. a_load64_reg_reg(list,regsrc2,tmpreg64);
  1813. a_op64_reg_reg(list,op,regsrc1,tmpreg64);
  1814. a_load64_reg_reg(list,tmpreg64,regdst);
  1815. end
  1816. else
  1817. begin
  1818. a_load64_reg_reg(list,regsrc2,regdst);
  1819. a_op64_reg_reg(list,op,regsrc1,regdst);
  1820. end;
  1821. end;
  1822. {$endif cpu64bit}
  1823. {****************************************************************************
  1824. TReference
  1825. ****************************************************************************}
  1826. procedure reference_release(list: taasmoutput; const ref : treference);
  1827. begin
  1828. cg.ungetreference(list,ref);
  1829. end;
  1830. {****************************************************************************
  1831. TLocation
  1832. ****************************************************************************}
  1833. procedure location_reset(var l : tlocation;lt:TCGLoc;lsize:TCGSize);
  1834. begin
  1835. FillChar(l,sizeof(tlocation),0);
  1836. l.loc:=lt;
  1837. l.size:=lsize;
  1838. {$ifdef arm}
  1839. if l.loc in [LOC_REFERENCE,LOC_CREFERENCE] then
  1840. l.reference.signindex:=1;
  1841. {$endif arm}
  1842. end;
  1843. procedure location_release(list: taasmoutput; const l : tlocation);
  1844. begin
  1845. case l.loc of
  1846. LOC_REGISTER,LOC_CREGISTER :
  1847. begin
  1848. cg.ungetregister(list,l.register);
  1849. {$ifndef cpu64bit}
  1850. if l.size in [OS_64,OS_S64] then
  1851. cg.ungetregister(list,l.registerhigh);
  1852. {$endif cpu64bit}
  1853. end;
  1854. LOC_FPUREGISTER,LOC_CFPUREGISTER :
  1855. cg.ungetregister(list,l.register);
  1856. LOC_CREFERENCE,LOC_REFERENCE :
  1857. cg.ungetreference(list, l.reference);
  1858. end;
  1859. end;
  1860. procedure location_freetemp(list:taasmoutput; const l : tlocation);
  1861. begin
  1862. if (l.loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  1863. tg.ungetiftemp(list,l.reference);
  1864. end;
  1865. procedure location_copy(var destloc:tlocation; const sourceloc : tlocation);
  1866. begin
  1867. destloc:=sourceloc;
  1868. end;
  1869. procedure location_swap(var destloc,sourceloc : tlocation);
  1870. var
  1871. swapl : tlocation;
  1872. begin
  1873. swapl := destloc;
  1874. destloc := sourceloc;
  1875. sourceloc := swapl;
  1876. end;
  1877. initialization
  1878. ;
  1879. finalization
  1880. cg.free;
  1881. {$ifndef cpu64bit}
  1882. cg64.free;
  1883. {$endif cpu64bit}
  1884. end.
  1885. {
  1886. $Log$
  1887. Revision 1.165 2004-06-16 20:07:07 florian
  1888. * dwarf branch merged
  1889. Revision 1.164 2004/05/22 23:34:27 peter
  1890. tai_regalloc.allocation changed to ratype to notify rgobj of register size changes
  1891. Revision 1.163 2004/04/29 19:56:36 daniel
  1892. * Prepare compiler infrastructure for multiple ansistring types
  1893. Revision 1.162 2004/04/18 07:52:43 florian
  1894. * fixed web bug 3048: comparision of dyn. arrays
  1895. Revision 1.161.2.17 2004/06/13 10:51:16 florian
  1896. * fixed several register allocator problems (sparc/arm)
  1897. Revision 1.161.2.16 2004/06/02 16:07:00 peter
  1898. * fixed op64_reg_reg_reg to not override src when src=dst
  1899. Revision 1.161.2.15 2004/05/30 17:54:13 florian
  1900. + implemented cmp64bit
  1901. * started to fix spilling
  1902. * fixed int64 sub partially
  1903. Revision 1.161.2.14 2004/05/30 12:07:54 florian
  1904. * fixed loading/saving of exception reason for CPUs where RETURN and RESULT registers of functions are differently named
  1905. Revision 1.161.2.13 2004/05/27 23:36:18 peter
  1906. * nostackframe procdirective added
  1907. Revision 1.161.2.12 2004/05/10 21:28:34 peter
  1908. * section_smartlink enabled for gas under linux
  1909. Revision 1.161.2.11 2004/05/03 19:06:34 peter
  1910. * fixed range checking
  1911. Revision 1.161.2.10 2004/05/02 20:20:59 florian
  1912. * started to fix callee side result value handling
  1913. Revision 1.161.2.9 2004/05/02 12:45:32 peter
  1914. * enabled cpuhasfixedstack for x86-64 again
  1915. * fixed size of temp allocation for parameters
  1916. Revision 1.161.2.8 2004/05/01 16:02:09 peter
  1917. * POINTER_SIZE replaced with sizeof(aint)
  1918. * aint,aword,tconst*int moved to globtype
  1919. Revision 1.161.2.7 2004/05/01 11:12:23 florian
  1920. * spilling of registers with size<>4 fixed
  1921. Revision 1.161.2.6 2004/04/28 21:46:22 peter
  1922. * fix 1.0.x bootstrap of maxaint
  1923. Revision 1.161.2.5 2004/04/27 18:18:25 peter
  1924. * aword -> aint
  1925. Revision 1.161.2.4 2004/04/26 16:09:16 peter
  1926. * fixed infinite loop with 64bit rangecheck
  1927. Revision 1.161.2.3 2004/04/26 15:54:33 peter
  1928. * small x86-64 fixes
  1929. Revision 1.161.2.2 2004/04/24 20:13:24 florian
  1930. * fixed x86-64 exception handling
  1931. Revision 1.161.2.1 2004/04/18 16:55:37 peter
  1932. * procedure entry and exit code restructured, some x86 specific
  1933. things are removed from the generic ncgutil code and moved to
  1934. the target depend cg.g_proc_entry and cg.g_proc_exit that now
  1935. contain all the code during startup including stackframe allocation
  1936. only the saving of registers is excluded from this code
  1937. Revision 1.161 2004/03/06 20:35:19 florian
  1938. * fixed arm compilation
  1939. * cleaned up code generation for exported linux procedures
  1940. Revision 1.160 2004/03/02 00:36:33 olle
  1941. * big transformation of Tai_[const_]Symbol.Create[data]name*
  1942. Revision 1.159 2004/02/27 10:21:05 florian
  1943. * top_symbol killed
  1944. + refaddr to treference added
  1945. + refsymbol to treference added
  1946. * top_local stuff moved to an extra record to save memory
  1947. + aint introduced
  1948. * tppufile.get/putint64/aint implemented
  1949. Revision 1.158 2004/02/20 22:16:34 florian
  1950. * handling of float parameters passed in mm registers fixed
  1951. Revision 1.157 2004/02/12 15:54:03 peter
  1952. * make extcycle is working again
  1953. Revision 1.156 2004/02/08 18:08:59 jonas
  1954. * fixed regvars support. Needs -doldregvars to activate. Only tested with
  1955. ppc, other processors should however only require maxregvars and
  1956. maxfpuregvars constants in cpubase.pas. Remember to take scratch-
  1957. registers into account when defining that value.
  1958. Revision 1.155 2004/02/04 22:01:13 peter
  1959. * first try to get cpupara working for x86_64
  1960. Revision 1.154 2004/02/03 22:32:53 peter
  1961. * renamed xNNbittype to xNNinttype
  1962. * renamed registers32 to registersint
  1963. * replace some s32bit,u32bit with torddef([su]inttype).def.typ
  1964. Revision 1.153 2004/01/31 17:45:17 peter
  1965. * Change several $ifdef i386 to x86
  1966. * Change several OS_32 to OS_INT/OS_ADDR
  1967. Revision 1.152 2004/01/22 22:12:21 peter
  1968. * g_finalize needs to reset to nil after decr_ref
  1969. * support loadref in decr_ref reset to nil
  1970. Revision 1.151 2004/01/21 22:13:20 peter
  1971. * decrrefcount resets temps to nil
  1972. Revision 1.150 2004/01/21 21:01:34 peter
  1973. * fixed stackchecking for register calling
  1974. Revision 1.149 2004/01/20 12:59:36 florian
  1975. * common addnode code for x86-64 and i386
  1976. Revision 1.148 2004/01/12 22:11:38 peter
  1977. * use localalign info for alignment for locals and temps
  1978. * sparc fpu flags branching added
  1979. * moved powerpc copy_valye_openarray to generic
  1980. Revision 1.147 2004/01/11 23:56:19 daniel
  1981. * Experiment: Compress strings to save memory
  1982. Did not save a single byte of mem; clearly the core size is boosted by
  1983. temporary memory usage...
  1984. Revision 1.146 2003/12/26 14:02:30 peter
  1985. * sparc updates
  1986. * use registertype in spill_register
  1987. Revision 1.145 2003/12/26 13:19:16 florian
  1988. * rtl and compiler compile with -Cfsse2
  1989. Revision 1.144 2003/12/24 00:10:02 florian
  1990. - delete parameter in cg64 methods removed
  1991. Revision 1.143 2003/12/23 14:38:07 florian
  1992. + second_floataddsse implemented
  1993. Revision 1.142 2003/12/22 19:00:17 florian
  1994. * fixed some x86-64 issues
  1995. Revision 1.141 2003/12/21 19:42:42 florian
  1996. * fixed ppc inlining stuff
  1997. * fixed wrong unit writing
  1998. + added some sse stuff
  1999. Revision 1.140 2003/12/15 21:39:39 florian
  2000. * improved register allocation of generic a_param_const and a_param_ref
  2001. Revision 1.139 2003/12/15 21:25:48 peter
  2002. * reg allocations for imaginary register are now inserted just
  2003. before reg allocation
  2004. * tregister changed to enum to allow compile time check
  2005. * fixed several tregister-tsuperregister errors
  2006. Revision 1.138 2003/12/12 17:16:17 peter
  2007. * rg[tregistertype] added in tcg
  2008. Revision 1.137 2003/12/06 22:11:47 jonas
  2009. + allocate volatile registers around calls to procedures declared with
  2010. "saveregisters" on non-x86 processors
  2011. Revision 1.136 2003/12/06 01:15:22 florian
  2012. * reverted Peter's alloctemp patch; hopefully properly
  2013. Revision 1.135 2003/12/03 23:13:19 peter
  2014. * delayed paraloc allocation, a_param_*() gets extra parameter
  2015. if it needs to allocate temp or real paralocation
  2016. * optimized/simplified int-real loading
  2017. Revision 1.134 2003/11/05 23:05:13 florian
  2018. * elesize of g_copyvaluepara_openarray changed
  2019. + g_releaesvaluepara_openarray added
  2020. Revision 1.133 2003/10/19 01:34:30 florian
  2021. * some ppc stuff fixed
  2022. * memory leak fixed
  2023. Revision 1.132 2003/10/17 15:25:18 florian
  2024. * fixed more ppc stuff
  2025. Revision 1.131 2003/10/17 14:38:32 peter
  2026. * 64k registers supported
  2027. * fixed some memory leaks
  2028. Revision 1.130 2003/10/13 01:23:13 florian
  2029. * some ideas for mm support implemented
  2030. Revision 1.129 2003/10/11 16:06:42 florian
  2031. * fixed some MMX<->SSE
  2032. * started to fix ppc, needs an overhaul
  2033. + stabs info improve for spilling, not sure if it works correctly/completly
  2034. - MMX_SUPPORT removed from Makefile.fpc
  2035. Revision 1.128 2003/10/10 17:48:13 peter
  2036. * old trgobj moved to x86/rgcpu and renamed to trgx86fpu
  2037. * tregisteralloctor renamed to trgobj
  2038. * removed rgobj from a lot of units
  2039. * moved location_* and reference_* to cgobj
  2040. * first things for mmx register allocation
  2041. Revision 1.127 2003/10/09 21:31:37 daniel
  2042. * Register allocator splitted, ans abstract now
  2043. Revision 1.126 2003/10/01 20:34:48 peter
  2044. * procinfo unit contains tprocinfo
  2045. * cginfo renamed to cgbase
  2046. * moved cgmessage to verbose
  2047. * fixed ppc and sparc compiles
  2048. Revision 1.125 2003/09/28 17:55:03 peter
  2049. * parent framepointer changed to hidden parameter
  2050. * tloadparentfpnode added
  2051. Revision 1.124 2003/09/28 13:40:13 peter
  2052. * a_call_ref removed
  2053. Revision 1.123 2003/09/25 21:26:24 peter
  2054. * remove obsolete tparalocation.sp_fixup
  2055. Revision 1.122 2003/09/23 20:37:16 peter
  2056. * fpc_check_object(_ext) has saveregisters and doesn't need
  2057. saving of registers
  2058. Revision 1.121 2003/09/10 08:31:47 marco
  2059. * Patch from Peter for paraloc
  2060. Revision 1.120 2003/09/09 20:59:27 daniel
  2061. * Adding register allocation order
  2062. Revision 1.119 2003/09/07 22:09:34 peter
  2063. * preparations for different default calling conventions
  2064. * various RA fixes
  2065. Revision 1.118 2003/09/03 15:55:00 peter
  2066. * NEWRA branch merged
  2067. Revision 1.117 2003/09/03 11:18:36 florian
  2068. * fixed arm concatcopy
  2069. + arm support in the common compiler sources added
  2070. * moved some generic cg code around
  2071. + tfputype added
  2072. * ...
  2073. Revision 1.116.2.4 2003/08/29 17:28:59 peter
  2074. * next batch of updates
  2075. Revision 1.116.2.3 2003/08/28 18:35:07 peter
  2076. * tregister changed to cardinal
  2077. Revision 1.116.2.2 2003/08/27 20:23:55 peter
  2078. * remove old ra code
  2079. Revision 1.116.2.1 2003/08/27 19:55:54 peter
  2080. * first tregister patch
  2081. Revision 1.116 2003/08/17 16:59:20 jonas
  2082. * fixed regvars so they work with newra (at least for ppc)
  2083. * fixed some volatile register bugs
  2084. + -dnotranslation option for -dnewra, which causes the registers not to
  2085. be translated from virtual to normal registers. Requires support in
  2086. the assembler writer as well, which is only implemented in aggas/
  2087. agppcgas currently
  2088. Revision 1.115 2003/07/23 11:01:14 jonas
  2089. * several rg.allocexplicitregistersint/rg.deallocexplicitregistersint
  2090. pairs round calls to helpers
  2091. Revision 1.114 2003/07/06 17:58:22 peter
  2092. * framepointer fixes for sparc
  2093. * parent framepointer code more generic
  2094. Revision 1.113 2003/07/02 22:18:04 peter
  2095. * paraloc splitted in callerparaloc,calleeparaloc
  2096. * sparc calling convention updates
  2097. Revision 1.112 2003/06/13 21:19:30 peter
  2098. * current_procdef removed, use current_procinfo.procdef instead
  2099. Revision 1.111 2003/06/12 21:11:10 peter
  2100. * ungetregisterfpu gets size parameter
  2101. Revision 1.110 2003/06/12 16:43:07 peter
  2102. * newra compiles for sparc
  2103. Revision 1.109 2003/06/07 18:57:04 jonas
  2104. + added freeintparaloc
  2105. * ppc get/freeintparaloc now check whether the parameter regs are
  2106. properly allocated/deallocated (and get an extra list para)
  2107. * ppc a_call_* now internalerrors if pi_do_call is not yet set
  2108. * fixed lot of missing pi_do_call's
  2109. Revision 1.108 2003/06/06 14:43:02 peter
  2110. * g_copyopenarrayvalue gets length reference
  2111. * don't copy open arrays for cdecl
  2112. Revision 1.107 2003/06/03 21:11:09 peter
  2113. * cg.a_load_* get a from and to size specifier
  2114. * makeregsize only accepts newregister
  2115. * i386 uses generic tcgnotnode,tcgunaryminus
  2116. Revision 1.106 2003/06/03 13:01:59 daniel
  2117. * Register allocator finished
  2118. Revision 1.105 2003/06/01 21:38:06 peter
  2119. * getregisterfpu size parameter added
  2120. * op_const_reg size parameter added
  2121. * sparc updates
  2122. Revision 1.104 2003/06/01 01:02:39 peter
  2123. * generic a_call_ref
  2124. Revision 1.103 2003/05/30 23:57:08 peter
  2125. * more sparc cleanup
  2126. * accumulator removed, splitted in function_return_reg (called) and
  2127. function_result_reg (caller)
  2128. Revision 1.102 2003/05/30 23:49:18 jonas
  2129. * a_load_loc_reg now has an extra size parameter for the destination
  2130. register (properly fixes what I worked around in revision 1.106 of
  2131. ncgutil.pas)
  2132. Revision 1.101 2003/05/30 21:40:00 jonas
  2133. * fixed bug in a_load_loc_ref (the source instead of dest size was passed
  2134. to a_load_reg_ref in case of a register)
  2135. Revision 1.100 2003/05/30 12:36:13 jonas
  2136. * use as little different registers on the ppc until newra is released,
  2137. since every used register must be saved
  2138. Revision 1.99 2003/05/23 14:27:35 peter
  2139. * remove some unit dependencies
  2140. * current_procinfo changes to store more info
  2141. Revision 1.98 2003/05/15 18:58:53 peter
  2142. * removed selfpointer_offset, vmtpointer_offset
  2143. * tvarsym.adjusted_address
  2144. * address in localsymtable is now in the real direction
  2145. * removed some obsolete globals
  2146. Revision 1.97 2003/05/13 19:14:41 peter
  2147. * failn removed
  2148. * inherited result code check moven to pexpr
  2149. Revision 1.96 2003/05/11 21:37:03 peter
  2150. * moved implicit exception frame from ncgutil to psub
  2151. * constructor/destructor helpers moved from cobj/ncgutil to psub
  2152. Revision 1.95 2003/05/09 17:47:02 peter
  2153. * self moved to hidden parameter
  2154. * removed hdisposen,hnewn,selfn
  2155. Revision 1.94 2003/05/01 12:23:46 jonas
  2156. * fix for op_reg_reg_reg in case the destination is the same as the first
  2157. source register
  2158. Revision 1.93 2003/04/29 07:28:52 michael
  2159. + Patch from peter to fix wrong pushing of ansistring function results in open array
  2160. Revision 1.92 2003/04/27 11:21:32 peter
  2161. * aktprocdef renamed to current_procinfo.procdef
  2162. * procinfo renamed to current_procinfo
  2163. * procinfo will now be stored in current_module so it can be
  2164. cleaned up properly
  2165. * gen_main_procsym changed to create_main_proc and release_main_proc
  2166. to also generate a tprocinfo structure
  2167. * fixed unit implicit initfinal
  2168. Revision 1.91 2003/04/27 07:29:50 peter
  2169. * current_procinfo.procdef cleanup, current_procdef is now always nil when parsing
  2170. a new procdef declaration
  2171. * aktprocsym removed
  2172. * lexlevel removed, use symtable.symtablelevel instead
  2173. * implicit init/final code uses the normal genentry/genexit
  2174. * funcret state checking updated for new funcret handling
  2175. Revision 1.90 2003/04/26 20:57:17 florian
  2176. * fixed para locations of fpc_class_new helper call
  2177. Revision 1.89 2003/04/26 17:21:08 florian
  2178. * fixed passing of fpu values by fpu register
  2179. Revision 1.88 2003/04/23 20:16:03 peter
  2180. + added currency support based on int64
  2181. + is_64bit for use in cg units instead of is_64bitint
  2182. * removed cgmessage from n386add, replace with internalerrors
  2183. Revision 1.87 2003/04/23 14:42:07 daniel
  2184. * Further register allocator work. Compiler now smaller with new
  2185. allocator than without.
  2186. * Somebody forgot to adjust ppu version number
  2187. Revision 1.86 2003/04/23 13:20:34 peter
  2188. * fix self passing to fpc_help_fail
  2189. Revision 1.85 2003/04/23 12:35:34 florian
  2190. * fixed several issues with powerpc
  2191. + applied a patch from Jonas for nested function calls (PowerPC only)
  2192. * ...
  2193. Revision 1.84 2003/04/22 14:33:38 peter
  2194. * removed some notes/hints
  2195. Revision 1.83 2003/04/22 13:47:08 peter
  2196. * fixed C style array of const
  2197. * fixed C array passing
  2198. * fixed left to right with high parameters
  2199. Revision 1.82 2003/04/22 10:09:34 daniel
  2200. + Implemented the actual register allocator
  2201. + Scratch registers unavailable when new register allocator used
  2202. + maybe_save/maybe_restore unavailable when new register allocator used
  2203. Revision 1.81 2003/04/06 21:11:23 olle
  2204. * changed newasmsymbol to newasmsymboldata for data symbols
  2205. Revision 1.80 2003/03/28 19:16:56 peter
  2206. * generic constructor working for i386
  2207. * remove fixed self register
  2208. * esi added as address register for i386
  2209. Revision 1.79 2003/03/22 18:07:18 jonas
  2210. + add used scratch registers to usedintbyproc for non-i386
  2211. Revision 1.78 2003/03/11 21:46:24 jonas
  2212. * lots of new regallocator fixes, both in generic and ppc-specific code
  2213. (ppc compiler still can't compile the linux system unit though)
  2214. Revision 1.77 2003/02/19 22:00:14 daniel
  2215. * Code generator converted to new register notation
  2216. - Horribily outdated todo.txt removed
  2217. Revision 1.76 2003/01/31 22:47:48 peter
  2218. * maybe_testself now really uses the passed register
  2219. Revision 1.75 2003/01/30 21:46:35 peter
  2220. * maybe_testvmt added
  2221. Revision 1.74 2003/01/17 12:45:40 daniel
  2222. * Fixed internalerror 200301081 problem
  2223. Revision 1.73 2003/01/13 14:54:34 daniel
  2224. * Further work to convert codegenerator register convention;
  2225. internalerror bug fixed.
  2226. Revision 1.72 2003/01/09 22:00:53 florian
  2227. * fixed some PowerPC issues
  2228. Revision 1.71 2003/01/09 20:41:10 florian
  2229. * fixed broken PowerPC compiler
  2230. Revision 1.70 2003/01/08 18:43:56 daniel
  2231. * Tregister changed into a record
  2232. Revision 1.69 2002/12/24 15:56:50 peter
  2233. * stackpointer_alloc added for adjusting ESP. Win32 needs
  2234. this for the pageprotection
  2235. Revision 1.68 2002/12/20 18:14:04 peter
  2236. * removed some runerror and writeln
  2237. Revision 1.67 2002/12/14 15:02:03 carl
  2238. * maxoperands -> max_operands (for portability in rautils.pas)
  2239. * fix some range-check errors with loadconst
  2240. + add ncgadd unit to m68k
  2241. * some bugfix of a_param_reg with LOC_CREFERENCE
  2242. Revision 1.66 2002/11/25 17:43:16 peter
  2243. * splitted defbase in defutil,symutil,defcmp
  2244. * merged isconvertable and is_equal into compare_defs(_ext)
  2245. * made operator search faster by walking the list only once
  2246. Revision 1.65 2002/11/17 16:27:31 carl
  2247. * document flags2reg
  2248. Revision 1.64 2002/11/16 17:06:28 peter
  2249. * return error 210 for failed self test
  2250. Revision 1.63 2002/11/15 01:58:46 peter
  2251. * merged changes from 1.0.7 up to 04-11
  2252. - -V option for generating bug report tracing
  2253. - more tracing for option parsing
  2254. - errors for cdecl and high()
  2255. - win32 import stabs
  2256. - win32 records<=8 are returned in eax:edx (turned off by default)
  2257. - heaptrc update
  2258. - more info for temp management in .s file with EXTDEBUG
  2259. Revision 1.62 2002/10/16 19:01:43 peter
  2260. + $IMPLICITEXCEPTIONS switch to turn on/off generation of the
  2261. implicit exception frames for procedures with initialized variables
  2262. and for constructors. The default is on for compatibility
  2263. Revision 1.61 2002/10/05 12:43:23 carl
  2264. * fixes for Delphi 6 compilation
  2265. (warning : Some features do not work under Delphi)
  2266. Revision 1.60 2002/10/02 18:20:52 peter
  2267. * Copy() is now internal syssym that calls compilerprocs
  2268. Revision 1.59 2002/09/17 18:54:02 jonas
  2269. * a_load_reg_reg() now has two size parameters: source and dest. This
  2270. allows some optimizations on architectures that don't encode the
  2271. register size in the register name.
  2272. Revision 1.58 2002/09/09 19:29:29 peter
  2273. * fixed dynarr_decr_ref call
  2274. Revision 1.57 2002/09/07 15:25:01 peter
  2275. * old logs removed and tabs fixed
  2276. Revision 1.56 2002/09/01 21:04:47 florian
  2277. * several powerpc related stuff fixed
  2278. Revision 1.55 2002/09/01 17:05:43 florian
  2279. + added abstract tcg.g_removevaluepara_openarray
  2280. Revision 1.54 2002/09/01 12:09:27 peter
  2281. + a_call_reg, a_call_loc added
  2282. * removed exprasmlist references
  2283. Revision 1.53 2002/08/19 18:17:48 carl
  2284. + optimize64_op_const_reg implemented (optimizes 64-bit constant opcodes)
  2285. * more fixes to m68k for 64-bit operations
  2286. Revision 1.52 2002/08/17 22:09:43 florian
  2287. * result type handling in tcgcal.pass_2 overhauled
  2288. * better tnode.dowrite
  2289. * some ppc stuff fixed
  2290. Revision 1.51 2002/08/17 09:23:33 florian
  2291. * first part of procinfo rewrite
  2292. Revision 1.50 2002/08/16 14:24:57 carl
  2293. * issameref() to test if two references are the same (then emit no opcodes)
  2294. + ret_in_reg to replace ret_in_acc
  2295. (fix some register allocation bugs at the same time)
  2296. + save_std_register now has an extra parameter which is the
  2297. usedinproc registers
  2298. Revision 1.49 2002/08/15 08:13:54 carl
  2299. - a_load_sym_ofs_reg removed
  2300. * loadvmt now calls loadaddr_ref_reg instead
  2301. Revision 1.48 2002/08/14 19:26:02 carl
  2302. + routine to optimize opcodes with constants
  2303. Revision 1.47 2002/08/11 14:32:26 peter
  2304. * renamed current_library to objectlibrary
  2305. Revision 1.46 2002/08/11 13:24:11 peter
  2306. * saving of asmsymbols in ppu supported
  2307. * asmsymbollist global is removed and moved into a new class
  2308. tasmlibrarydata that will hold the info of a .a file which
  2309. corresponds with a single module. Added librarydata to tmodule
  2310. to keep the library info stored for the module. In the future the
  2311. objectfiles will also be stored to the tasmlibrarydata class
  2312. * all getlabel/newasmsymbol and friends are moved to the new class
  2313. Revision 1.45 2002/08/10 17:15:20 jonas
  2314. * register parameters are now LOC_CREGISTER instead of LOC_REGISTER
  2315. Revision 1.44 2002/08/09 19:10:05 carl
  2316. - moved new_exception and free_exception to ncgutils
  2317. Revision 1.43 2002/08/05 18:27:48 carl
  2318. + more more more documentation
  2319. + first version include/exclude (can't test though, not enough scratch for i386 :()...
  2320. Revision 1.42 2002/08/04 19:08:21 carl
  2321. + added generic exception support (still does not work!)
  2322. + more documentation
  2323. Revision 1.41 2002/07/30 20:50:43 florian
  2324. * the code generator knows now if parameters are in registers
  2325. Revision 1.40 2002/07/29 21:16:02 florian
  2326. * some more ppc fixes
  2327. Revision 1.39 2002/07/28 15:56:00 jonas
  2328. + tcg64.a_op64_const_reg_reg() and tcg64.a_op64_reg_reg_reg() methods +
  2329. generic implementation
  2330. Revision 1.38 2002/07/27 19:53:51 jonas
  2331. + generic implementation of tcg.g_flags2ref()
  2332. * tcg.flags2xxx() now also needs a size parameter
  2333. Revision 1.37 2002/07/20 11:57:53 florian
  2334. * types.pas renamed to defbase.pas because D6 contains a types
  2335. unit so this would conflicts if D6 programms are compiled
  2336. + Willamette/SSE2 instructions to assembler added
  2337. }