cgobj.pas 96 KB

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