cgobj.pas 91 KB

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