cpupara.pas 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255
  1. {
  2. Copyright (c) 2002 by Florian Klaempfl
  3. Generates the argument location information for x86-64 target
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit cpupara;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. globtype,
  22. cpubase,cgbase,cgutils,
  23. symconst,symtype,symsym,symdef,
  24. aasmtai,aasmdata,
  25. parabase,paramgr;
  26. type
  27. tx86_64paramanager = class(tparamanager)
  28. private
  29. procedure create_paraloc_info_intern(p : tabstractprocdef; side: tcallercallee;paras:tparalist;
  30. var intparareg,mmparareg,parasize:longint;varargsparas: boolean);
  31. public
  32. function param_use_paraloc(const cgpara:tcgpara):boolean;override;
  33. function push_addr_param(varspez:tvarspez;def : tdef;calloption : tproccalloption) : boolean;override;
  34. function ret_in_param(def:tdef;pd:tabstractprocdef):boolean;override;
  35. procedure getintparaloc(pd : tabstractprocdef; nr : longint; var cgpara : tcgpara);override;
  36. function get_volatile_registers_int(calloption : tproccalloption):tcpuregisterset;override;
  37. function get_volatile_registers_mm(calloption : tproccalloption):tcpuregisterset;override;
  38. function get_volatile_registers_fpu(calloption : tproccalloption):tcpuregisterset;override;
  39. function create_paraloc_info(p : tabstractprocdef; side: tcallercallee):longint;override;
  40. function create_varargs_paraloc_info(p : tabstractprocdef; varargspara:tvarargsparalist):longint;override;
  41. function get_funcretloc(p : tabstractprocdef; side: tcallercallee; forcetempdef: tdef): tcgpara;override;
  42. end;
  43. implementation
  44. uses
  45. cutils,verbose,
  46. systems,
  47. defutil,
  48. symtable;
  49. const
  50. paraintsupregs : array[0..5] of tsuperregister = (RS_RDI,RS_RSI,RS_RDX,RS_RCX,RS_R8,RS_R9);
  51. parammsupregs : array[0..7] of tsuperregister = (RS_XMM0,RS_XMM1,RS_XMM2,RS_XMM3,RS_XMM4,RS_XMM5,RS_XMM6,RS_XMM7);
  52. paraintsupregs_winx64 : array[0..3] of tsuperregister = (RS_RCX,RS_RDX,RS_R8,RS_R9);
  53. parammsupregs_winx64 : array[0..3] of tsuperregister = (RS_XMM0,RS_XMM1,RS_XMM2,RS_XMM3);
  54. {
  55. The argument classification code largely comes from libffi:
  56. ffi64.c - Copyright (c) 2002, 2007 Bo Thorsen <[email protected]>
  57. Copyright (c) 2008 Red Hat, Inc.
  58. x86-64 Foreign Function Interface
  59. Permission is hereby granted, free of charge, to any person obtaining
  60. a copy of this software and associated documentation files (the
  61. ``Software''), to deal in the Software without restriction, including
  62. without limitation the rights to use, copy, modify, merge, publish,
  63. distribute, sublicense, and/or sell copies of the Software, and to
  64. permit persons to whom the Software is furnished to do so, subject to
  65. the following conditions:
  66. The above copyright notice and this permission notice shall be included
  67. in all copies or substantial portions of the Software.
  68. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  69. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  70. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  71. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  72. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  73. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  74. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  75. DEALINGS IN THE SOFTWARE.
  76. ----------------------------------------------------------------------- *)
  77. }
  78. const
  79. MAX_PARA_CLASSES = 4;
  80. type
  81. tx64paraclass = (
  82. X86_64_NO_CLASS,
  83. X86_64_INTEGER_CLASS,X86_64_INTEGERSI_CLASS,
  84. X86_64_SSE_CLASS,X86_64_SSESF_CLASS,X86_64_SSEDF_CLASS,X86_64_SSEUP_CLASS,
  85. X86_64_X87_CLASS,X86_64_X87UP_CLASS,
  86. X86_64_COMPLEX_X87_CLASS,
  87. X86_64_MEMORY_CLASS
  88. );
  89. tx64paraclasses = array[0..MAX_PARA_CLASSES-1] of tx64paraclass;
  90. { Win64-specific helper }
  91. function aggregate_in_registers_win64(varspez:tvarspez;size:longint):boolean;
  92. begin
  93. { TODO: Temporary hack: vs_const parameters are always passed by reference for win64}
  94. result:=(varspez=vs_value) and (size in [1,2,4,8])
  95. end;
  96. (* x86-64 register passing implementation. See x86-64 ABI for details. Goal
  97. of this code is to classify each 8bytes of incoming argument by the register
  98. class and assign registers accordingly. *)
  99. (* Return the union class of CLASS1 and CLASS2.
  100. See the x86-64 PS ABI for details. *)
  101. function merge_classes(class1, class2: tx64paraclass): tx64paraclass;
  102. begin
  103. (* Rule #1: If both classes are equal, this is the resulting class. *)
  104. if (class1=class2) then
  105. exit(class1);
  106. (* Rule #2: If one of the classes is NO_CLASS, the resulting class is
  107. the other class. *)
  108. if (class1=X86_64_NO_CLASS) then
  109. exit(class2);
  110. if (class2=X86_64_NO_CLASS) then
  111. exit(class1);
  112. (* Rule #3: If one of the classes is MEMORY, the result is MEMORY. *)
  113. if (class1=X86_64_MEMORY_CLASS) or
  114. (class2=X86_64_MEMORY_CLASS) then
  115. exit(X86_64_MEMORY_CLASS);
  116. (* Rule #4: If one of the classes is INTEGER, the result is INTEGER. *)
  117. { 32 bit }
  118. if ((class1=X86_64_INTEGERSI_CLASS) and
  119. (class2=X86_64_SSESF_CLASS)) or
  120. ((class2=X86_64_INTEGERSI_CLASS) and
  121. (class1=X86_64_SSESF_CLASS)) then
  122. exit(X86_64_INTEGERSI_CLASS);
  123. { 64 bit }
  124. if (class1 in [X86_64_INTEGER_CLASS,X86_64_INTEGERSI_CLASS]) or
  125. (class2 in [X86_64_INTEGER_CLASS,X86_64_INTEGERSI_CLASS]) then
  126. exit(X86_64_INTEGER_CLASS);
  127. (* Rule #5: If one of the classes is X87, X87UP, or COMPLEX_X87 class,
  128. MEMORY is used. *)
  129. if (class1 in [X86_64_X87_CLASS,X86_64_X87UP_CLASS,X86_64_COMPLEX_X87_CLASS]) or
  130. (class2 in [X86_64_X87_CLASS,X86_64_X87UP_CLASS,X86_64_COMPLEX_X87_CLASS]) then
  131. exit(X86_64_MEMORY_CLASS);
  132. (* Rule #6: Otherwise class SSE is used. *)
  133. result:=X86_64_SSE_CLASS;
  134. end;
  135. (* Classify the argument of type TYPE and mode MODE.
  136. CLASSES will be filled by the register class used to pass each word
  137. of the operand. The number of words is returned. In case the parameter
  138. should be passed in memory, 0 is returned. As a special case for zero
  139. sized containers, classes[0] will be NO_CLASS and 1 is returned.
  140. real_size contains either def.size, or a value derived from
  141. def.bitpackedsize and the field offset denoting the number of bytes
  142. spanned by a bitpacked field
  143. See the x86-64 PS ABI for details.
  144. *)
  145. function classify_as_integer_argument(real_size: aint; var classes: tx64paraclasses; byte_offset: aint): longint;
  146. var
  147. size: aint;
  148. begin
  149. size:=byte_offset+real_size;
  150. if size<=4 then
  151. classes[0]:=X86_64_INTEGERSI_CLASS
  152. else
  153. classes[0]:=X86_64_INTEGER_CLASS;
  154. if size<=8 then
  155. result:=1
  156. else
  157. begin
  158. if size<=12 then
  159. classes[1]:=X86_64_INTEGERSI_CLASS
  160. else if (size<=16) then
  161. classes[1]:=X86_64_INTEGER_CLASS
  162. else
  163. internalerror(2010021401);
  164. result:=2;
  165. end
  166. end;
  167. function classify_argument(def: tdef; varspez: tvarspez; real_size: aint; var classes: tx64paraclasses; byte_offset: aint): longint; forward;
  168. function init_aggregate_classification(def: tdef; varspez: tvarspez; byte_offset: aint; out words: longint; out classes: tx64paraclasses): longint;
  169. var
  170. i: longint;
  171. begin
  172. words:=0;
  173. { win64 follows a different convention here }
  174. if (target_info.system=system_x86_64_win64) then
  175. begin
  176. if aggregate_in_registers_win64(varspez,def.size) then
  177. begin
  178. classes[0]:=X86_64_INTEGER_CLASS;
  179. result:=1;
  180. end
  181. else
  182. result:=0;
  183. exit;
  184. end;
  185. (* If the struct is larger than 32 bytes, pass it on the stack. *)
  186. if def.size > 32 then
  187. exit(0);
  188. { if a struct starts an offset not divisible by 8, it can span extra
  189. words }
  190. words:=(def.size+byte_offset mod 8+7) div 8;
  191. (* Zero sized arrays or structures are NO_CLASS. We return 0 to
  192. signal memory class, so handle it as special case. *)
  193. if (words=0) then
  194. begin
  195. classes[0]:=X86_64_NO_CLASS;
  196. exit(1);
  197. end;
  198. { we'll be merging the classes elements with the subclasses
  199. elements, so initialise them first }
  200. for i:=low(classes) to high(classes) do
  201. classes[i]:=X86_64_NO_CLASS;
  202. result:=words;
  203. end;
  204. function classify_aggregate_element(def: tdef; varspez: tvarspez; real_size: aint; var classes: tx64paraclasses; new_byte_offset: aint): longint;
  205. var
  206. subclasses: tx64paraclasses;
  207. i,
  208. pos: longint;
  209. begin
  210. result:=classify_argument(def,varspez,real_size,subclasses,new_byte_offset mod 8);
  211. if (result=0) then
  212. exit;
  213. pos:=new_byte_offset div 8;
  214. if result-1+pos>high(classes) then
  215. internalerror(2010053108);
  216. for i:=0 to result-1 do
  217. begin
  218. classes[i+pos] :=
  219. merge_classes(subclasses[i],classes[i+pos]);
  220. end;
  221. inc(result,pos);
  222. end;
  223. function finalize_aggregate_classification(def: tdef; words: longint; var classes: tx64paraclasses): longint;
  224. var
  225. i: longint;
  226. begin
  227. if (words>2) then
  228. begin
  229. (* When size > 16 bytes, if the first one isn't
  230. X86_64_SSE_CLASS or any other ones aren't
  231. X86_64_SSEUP_CLASS, everything should be passed in
  232. memory. *)
  233. if (classes[0]<>X86_64_SSE_CLASS) then
  234. exit(0);
  235. for i:=1 to words-1 do
  236. if (classes[i]<>X86_64_SSEUP_CLASS) then
  237. exit(0);
  238. end;
  239. (* Final merger cleanup. *)
  240. (* The first one must never be X86_64_SSEUP_CLASS or
  241. X86_64_X87UP_CLASS. *)
  242. if (classes[0]=X86_64_SSEUP_CLASS) or
  243. (classes[0]=X86_64_X87UP_CLASS) then
  244. internalerror(2010021402);
  245. for i:=0 to words-1 do
  246. begin
  247. (* If one class is MEMORY, everything should be passed in
  248. memory. *)
  249. if (classes[i]=X86_64_MEMORY_CLASS) then
  250. exit(0);
  251. (* The X86_64_SSEUP_CLASS should be always preceded by
  252. X86_64_SSE_CLASS or X86_64_SSEUP_CLASS. *)
  253. if (classes[i]=X86_64_SSEUP_CLASS) and
  254. (classes[i-1]<>X86_64_SSE_CLASS) and
  255. (classes[i-1]<>X86_64_SSEUP_CLASS) then
  256. classes[i]:=X86_64_SSE_CLASS;
  257. (* If X86_64_X87UP_CLASS isn't preceded by X86_64_X87_CLASS,
  258. everything should be passed in memory. *)
  259. if (classes[i]=X86_64_X87UP_CLASS) and
  260. (classes[i-1]<>X86_64_X87_CLASS) then
  261. exit(0);
  262. end;
  263. { FIXME: in case a record contains empty padding space, e.g. a
  264. "single" field followed by a "double", then we have a problem
  265. because the cgpara helpers cannot figure out that they should
  266. skip 4 bytes after storing the single (LOC_MMREGISTER with size
  267. OS_F32) to memory before storing the double -> for now scale
  268. such locations always up to 64 bits, although this loads/stores
  269. some superfluous data }
  270. { 1) the first part is 32 bit while there is still a second part }
  271. if (classes[1]<>X86_64_NO_CLASS) then
  272. case classes[0] of
  273. X86_64_INTEGERSI_CLASS:
  274. classes[0]:=X86_64_INTEGER_CLASS;
  275. X86_64_SSESF_CLASS:
  276. classes[0]:=X86_64_SSE_CLASS;
  277. end;
  278. { 2) the second part is 32 bit, but the total size is > 12 bytes }
  279. if (def.size>12) then
  280. case classes[1] of
  281. X86_64_INTEGERSI_CLASS:
  282. classes[1]:=X86_64_INTEGER_CLASS;
  283. X86_64_SSESF_CLASS:
  284. classes[1]:=X86_64_SSE_CLASS;
  285. end;
  286. result:=words;
  287. end;
  288. function classify_record(def: tdef; varspez: tvarspez; var classes: tx64paraclasses; byte_offset: aint): longint;
  289. var
  290. vs: tfieldvarsym;
  291. size,
  292. new_byte_offset: aint;
  293. i,
  294. words,
  295. num: longint;
  296. checkalignment: boolean;
  297. begin
  298. result:=init_aggregate_classification(def,varspez,byte_offset,words,classes);
  299. if (words=0) then
  300. exit;
  301. (* Merge the fields of the structure. *)
  302. for i:=0 to tabstractrecorddef(def).symtable.symlist.count-1 do
  303. begin
  304. if tsym(tabstractrecorddef(def).symtable.symlist[i]).typ<>fieldvarsym then
  305. continue;
  306. vs:=tfieldvarsym(tabstractrecorddef(def).symtable.symlist[i]);
  307. num:=-1;
  308. checkalignment:=true;
  309. if not tabstractrecordsymtable(tabstractrecorddef(def).symtable).is_packed then
  310. begin
  311. new_byte_offset:=byte_offset+vs.fieldoffset;
  312. size:=vs.vardef.size;
  313. end
  314. else
  315. begin
  316. new_byte_offset:=byte_offset+vs.fieldoffset div 8;
  317. if (vs.vardef.typ in [orddef,enumdef]) then
  318. begin
  319. { calculate the number of bytes spanned by
  320. this bitpacked field }
  321. size:=((vs.fieldoffset+vs.vardef.packedbitsize+7) div 8)-(vs.fieldoffset div 8);
  322. { our bitpacked fields are interpreted as always being
  323. aligned, because unlike in C we don't have char:1, int:1
  324. etc (so everything is basically a char:x) }
  325. checkalignment:=false;
  326. end
  327. else
  328. size:=vs.vardef.size;
  329. end;
  330. { If [..] an object [..] contains unaligned fields, it has class
  331. MEMORY }
  332. if checkalignment and
  333. (align(new_byte_offset,vs.vardef.structalignment)<>new_byte_offset) then
  334. begin
  335. result:=0;
  336. exit;
  337. end;
  338. num:=classify_aggregate_element(vs.vardef,varspez,size,classes,new_byte_offset);
  339. if (num=0) then
  340. exit(0);
  341. end;
  342. result:=finalize_aggregate_classification(def,words,classes);
  343. end;
  344. function classify_normal_array(def: tarraydef; varspez: tvarspez; var classes: tx64paraclasses; byte_offset: aint): longint;
  345. var
  346. i, elecount: aword;
  347. size,
  348. elesize,
  349. new_byte_offset,
  350. bitoffset: aint;
  351. words,
  352. num: longint;
  353. isbitpacked: boolean;
  354. begin
  355. result:=init_aggregate_classification(def,varspez,byte_offset,words,classes);
  356. if (words=0) then
  357. exit;
  358. isbitpacked:=is_packed_array(def);
  359. if not isbitpacked then
  360. begin
  361. elesize:=def.elesize;
  362. size:=elesize;
  363. end
  364. else
  365. begin
  366. elesize:=def.elepackedbitsize;
  367. bitoffset:=0;
  368. end;
  369. (* Merge the elements of the array. *)
  370. i:=0;
  371. elecount:=def.elecount;
  372. repeat
  373. if not isbitpacked then
  374. begin
  375. { size does not change }
  376. new_byte_offset:=byte_offset+i*elesize;
  377. { If [..] an object [..] contains unaligned fields, it has class
  378. MEMORY }
  379. if align(new_byte_offset,def.alignment)<>new_byte_offset then
  380. begin
  381. result:=0;
  382. exit;
  383. end;
  384. end
  385. else
  386. begin
  387. { calculate the number of bytes spanned by this bitpacked
  388. element }
  389. size:=((bitoffset+elesize+7) div 8)-(bitoffset div 8);
  390. new_byte_offset:=byte_offset+(elesize*i) div 8;
  391. { bit offset of next element }
  392. inc(bitoffset,elesize);
  393. end;
  394. num:=classify_aggregate_element(def.elementdef,varspez,size,classes,new_byte_offset);
  395. if (num=0) then
  396. exit(0);
  397. inc(i);
  398. until (i=elecount);
  399. result:=finalize_aggregate_classification(def,words,classes);
  400. end;
  401. function classify_argument(def: tdef; varspez: tvarspez; real_size: aint; var classes: tx64paraclasses; byte_offset: aint): longint;
  402. begin
  403. case def.typ of
  404. orddef,
  405. enumdef,
  406. pointerdef,
  407. classrefdef:
  408. result:=classify_as_integer_argument(real_size,classes,byte_offset);
  409. formaldef:
  410. result:=classify_as_integer_argument(voidpointertype.size,classes,byte_offset);
  411. floatdef:
  412. begin
  413. case tfloatdef(def).floattype of
  414. s32real:
  415. begin
  416. if byte_offset=0 then
  417. classes[0]:=X86_64_SSESF_CLASS
  418. else
  419. { if we have e.g. a record with two successive "single"
  420. fields, we need a 64 bit rather than a 32 bit load }
  421. classes[0]:=X86_64_SSE_CLASS;
  422. result:=1;
  423. end;
  424. s64real:
  425. begin
  426. classes[0]:=X86_64_SSEDF_CLASS;
  427. result:=1;
  428. end;
  429. s80real,
  430. sc80real:
  431. begin
  432. classes[0]:=X86_64_X87_CLASS;
  433. classes[1]:=X86_64_X87UP_CLASS;
  434. result:=2;
  435. end;
  436. s64comp,
  437. s64currency:
  438. begin
  439. classes[0]:=X86_64_INTEGER_CLASS;
  440. result:=1;
  441. end;
  442. s128real:
  443. begin
  444. classes[0]:=X86_64_SSE_CLASS;
  445. classes[1]:=X86_64_SSEUP_CLASS;
  446. result:=2;
  447. end;
  448. else
  449. internalerror(2010060301);
  450. end;
  451. end;
  452. recorddef:
  453. result:=classify_record(def,varspez,classes,byte_offset);
  454. objectdef:
  455. begin
  456. if is_object(def) then
  457. { pass by reference, like ppc and i386 }
  458. result:=0
  459. else
  460. { all kinds of pointer types: class, objcclass, interface, ... }
  461. result:=classify_as_integer_argument(voidpointertype.size,classes,byte_offset);
  462. end;
  463. setdef:
  464. begin
  465. if is_smallset(def) then
  466. result:=classify_as_integer_argument(def.size,classes,byte_offset)
  467. else
  468. result:=0;
  469. end;
  470. stringdef:
  471. begin
  472. if (tstringdef(def).stringtype in [st_shortstring,st_longstring]) then
  473. result:=0
  474. else
  475. result:=classify_as_integer_argument(def.size,classes,byte_offset);
  476. end;
  477. arraydef:
  478. begin
  479. { a dynamic array is treated like a pointer }
  480. if is_dynamic_array(def) then
  481. result:=classify_as_integer_argument(voidpointertype.size,classes,byte_offset)
  482. { other special arrays are passed on the stack }
  483. else if is_open_array(def) or
  484. is_array_of_const(def) then
  485. result:=0
  486. else
  487. { normal array }
  488. result:=classify_normal_array(tarraydef(def),varspez,classes,byte_offset);
  489. end;
  490. { the file record is definitely too big }
  491. filedef:
  492. result:=0;
  493. procvardef:
  494. begin
  495. if (po_methodpointer in tprocvardef(def).procoptions) then
  496. begin
  497. { treat as TMethod record }
  498. def:=search_system_type('TMETHOD').typedef;
  499. result:=classify_argument(def,varspez,def.size,classes,byte_offset);
  500. end
  501. else
  502. { pointer }
  503. result:=classify_as_integer_argument(def.size,classes,byte_offset);
  504. end;
  505. variantdef:
  506. begin
  507. { same as tvardata record }
  508. def:=search_system_type('TVARDATA').typedef;
  509. result:=classify_argument(def,varspez,def.size,classes,byte_offset);
  510. end;
  511. else
  512. internalerror(2010021405);
  513. end;
  514. end;
  515. procedure getvalueparaloc(varspez:tvarspez;def:tdef;var loc1,loc2:tx64paraclass);
  516. var
  517. size: aint;
  518. i: longint;
  519. classes: tx64paraclasses;
  520. numclasses: longint;
  521. begin
  522. { init the classes array, because even if classify_argument inits only
  523. one element we copy both to loc1/loc2 in case "1" is returned }
  524. for i:=low(classes) to high(classes) do
  525. classes[i]:=X86_64_NO_CLASS;
  526. { def.size internalerrors for open arrays and dynamic arrays, since
  527. their size cannot be determined at compile-time.
  528. classify_argument does not look at the realsize argument for arrays
  529. cases, but we obviously do have to pass something... }
  530. if is_special_array(def) then
  531. size:=-1
  532. else
  533. size:=def.size;
  534. numclasses:=classify_argument(def,varspez,size,classes,0);
  535. case numclasses of
  536. 0:
  537. begin
  538. loc1:=X86_64_MEMORY_CLASS;
  539. loc2:=X86_64_NO_CLASS;
  540. end;
  541. 1,2:
  542. begin
  543. { If the class is X87, X87UP or COMPLEX_X87, it is passed in memory }
  544. if classes[0] in [X86_64_X87_CLASS,X86_64_X87UP_CLASS,X86_64_COMPLEX_X87_CLASS] then
  545. classes[0]:=X86_64_MEMORY_CLASS;
  546. if classes[1] in [X86_64_X87_CLASS,X86_64_X87UP_CLASS,X86_64_COMPLEX_X87_CLASS] then
  547. classes[1]:=X86_64_MEMORY_CLASS;
  548. loc1:=classes[0];
  549. loc2:=classes[1];
  550. end
  551. else
  552. { 4 can only happen for _m256 vectors, not yet supported }
  553. internalerror(2010021501);
  554. end;
  555. end;
  556. function tx86_64paramanager.ret_in_param(def:tdef;pd:tabstractprocdef):boolean;
  557. var
  558. classes: tx64paraclasses;
  559. numclasses: longint;
  560. begin
  561. { this must be system independent safecall and record constructor result
  562. is always return in param }
  563. if (tf_safecall_exceptions in target_info.flags) and
  564. (pd.proccalloption=pocall_safecall) or
  565. ((pd.proctypeoption=potype_constructor)and is_record(def)) then
  566. begin
  567. result:=true;
  568. exit;
  569. end;
  570. case def.typ of
  571. { for records it depends on their contents and size }
  572. recorddef,
  573. { make sure we handle 'procedure of object' correctly }
  574. procvardef:
  575. begin
  576. numclasses:=classify_argument(def,vs_value,def.size,classes,0);
  577. result:=(numclasses=0);
  578. end;
  579. else
  580. result:=inherited ret_in_param(def,pd);
  581. end;
  582. end;
  583. function tx86_64paramanager.param_use_paraloc(const cgpara:tcgpara):boolean;
  584. var
  585. paraloc : pcgparalocation;
  586. begin
  587. if not assigned(cgpara.location) then
  588. internalerror(200410102);
  589. result:=true;
  590. { All locations are LOC_REFERENCE }
  591. paraloc:=cgpara.location;
  592. while assigned(paraloc) do
  593. begin
  594. if (paraloc^.loc<>LOC_REFERENCE) then
  595. begin
  596. result:=false;
  597. exit;
  598. end;
  599. paraloc:=paraloc^.next;
  600. end;
  601. end;
  602. { true if a parameter is too large to copy and only the address is pushed }
  603. function tx86_64paramanager.push_addr_param(varspez:tvarspez;def : tdef;calloption : tproccalloption) : boolean;
  604. var
  605. classes: tx64paraclasses;
  606. numclasses: longint;
  607. begin
  608. result:=false;
  609. { var,out,constref always require address }
  610. if varspez in [vs_var,vs_out,vs_constref] then
  611. begin
  612. result:=true;
  613. exit;
  614. end;
  615. { Only vs_const, vs_value here }
  616. case def.typ of
  617. formaldef :
  618. result:=true;
  619. recorddef :
  620. begin
  621. { MetroWerks Pascal: const records always passed by reference
  622. (for Mac OS X interfaces) }
  623. if (calloption=pocall_mwpascal) and
  624. (varspez=vs_const) then
  625. result:=true
  626. { Win ABI depends on size to pass it in a register or not }
  627. else if (target_info.system=system_x86_64_win64) then
  628. result:=not aggregate_in_registers_win64(varspez,def.size)
  629. { pass constant parameters that would be passed via memory by
  630. reference for non-cdecl/cppdecl, and make sure that the tmethod
  631. record (size=16) is passed the same way as a complex procvar }
  632. else if ((varspez=vs_const) and
  633. not(calloption in cdecl_pocalls)) or
  634. (def.size=16) then
  635. begin
  636. numclasses:=classify_argument(def,vs_value,def.size,classes,0);
  637. result:=numclasses=0;
  638. end
  639. else
  640. { SysV ABI always passes it as value parameter }
  641. result:=false;
  642. end;
  643. arraydef :
  644. begin
  645. { cdecl array of const need to be ignored and therefor be puhsed
  646. as value parameter with length 0 }
  647. if ((calloption in cdecl_pocalls) and
  648. is_array_of_const(def)) or
  649. is_dynamic_array(def) then
  650. result:=false
  651. else
  652. { pass all arrays by reference to be compatible with C (passing
  653. an array by value (= copying it on the stack) does not exist,
  654. because an array is the same as a pointer there }
  655. result:=true
  656. end;
  657. objectdef :
  658. begin
  659. { don't treat objects like records, because we only know wheter
  660. or not they'll have a VMT after the entire object is parsed
  661. -> if they are used as function result from one of their own
  662. methods, their size can still change after we've determined
  663. whether this function result should be returned by reference or
  664. by value }
  665. if is_object(def) then
  666. result:=true;
  667. end;
  668. variantdef,
  669. stringdef,
  670. procvardef,
  671. setdef :
  672. begin
  673. numclasses:=classify_argument(def,vs_value,def.size,classes,0);
  674. result:=numclasses=0;
  675. end;
  676. end;
  677. end;
  678. function tx86_64paramanager.get_volatile_registers_int(calloption : tproccalloption):tcpuregisterset;
  679. begin
  680. if target_info.system=system_x86_64_win64 then
  681. result:=[RS_RAX,RS_RCX,RS_RDX,RS_R8,RS_R9,RS_R10,RS_R11]
  682. else
  683. result:=[RS_RAX,RS_RCX,RS_RDX,RS_RSI,RS_RDI,RS_R8,RS_R9,RS_R10,RS_R11];
  684. end;
  685. function tx86_64paramanager.get_volatile_registers_mm(calloption : tproccalloption):tcpuregisterset;
  686. begin
  687. if target_info.system=system_x86_64_win64 then
  688. result:=[RS_XMM0..RS_XMM5]
  689. else
  690. result:=[RS_XMM0..RS_XMM15];
  691. end;
  692. function tx86_64paramanager.get_volatile_registers_fpu(calloption : tproccalloption):tcpuregisterset;
  693. begin
  694. result:=[RS_ST0..RS_ST7];
  695. end;
  696. procedure tx86_64paramanager.getintparaloc(pd : tabstractprocdef; nr : longint; var cgpara : tcgpara);
  697. var
  698. paraloc : pcgparalocation;
  699. def : tdef;
  700. begin
  701. def:=tparavarsym(pd.paras[nr-1]).vardef;
  702. cgpara.reset;
  703. cgpara.size:=def_cgsize(def);
  704. cgpara.intsize:=tcgsize2size[cgpara.size];
  705. cgpara.alignment:=get_para_align(pd.proccalloption);
  706. cgpara.def:=def;
  707. paraloc:=cgpara.add_location;
  708. with paraloc^ do
  709. begin
  710. size:=OS_INT;
  711. if target_info.system=system_x86_64_win64 then
  712. begin
  713. if nr<1 then
  714. internalerror(200304303)
  715. else if nr<=high(paraintsupregs_winx64)+1 then
  716. begin
  717. loc:=LOC_REGISTER;
  718. register:=newreg(R_INTREGISTER,paraintsupregs_winx64[nr-1],R_SUBWHOLE);
  719. end
  720. else
  721. begin
  722. loc:=LOC_REFERENCE;
  723. reference.index:=NR_STACK_POINTER_REG;
  724. reference.offset:=(nr-6)*sizeof(aint);
  725. end;
  726. end
  727. else
  728. begin
  729. if nr<1 then
  730. internalerror(200304303)
  731. else if nr<=high(paraintsupregs)+1 then
  732. begin
  733. loc:=LOC_REGISTER;
  734. register:=newreg(R_INTREGISTER,paraintsupregs[nr-1],R_SUBWHOLE);
  735. end
  736. else
  737. begin
  738. loc:=LOC_REFERENCE;
  739. reference.index:=NR_STACK_POINTER_REG;
  740. reference.offset:=(nr-6)*sizeof(aint);
  741. end;
  742. end;
  743. end;
  744. end;
  745. function tx86_64paramanager.get_funcretloc(p : tabstractprocdef; side: tcallercallee; forcetempdef: tdef): tcgpara;
  746. const
  747. intretregs: array[0..1] of tregister = (NR_FUNCTION_RETURN_REG,NR_FUNCTION_RETURN_REG_HIGH);
  748. mmretregs: array[0..1] of tregister = (NR_MM_RESULT_REG,NR_MM_RESULT_REG_HIGH);
  749. var
  750. classes: tx64paraclasses;
  751. i,
  752. numclasses: longint;
  753. intretregidx,
  754. mmretregidx: longint;
  755. retcgsize : tcgsize;
  756. paraloc : pcgparalocation;
  757. begin
  758. if set_common_funcretloc_info(p,forcetempdef,retcgsize,result) then
  759. exit;
  760. { integer sizes < 32 bit have to be sign/zero extended to 32 bit on
  761. the callee side (caller can expect those bits are valid) }
  762. if (side=calleeside) and
  763. (retcgsize in [OS_8,OS_S8,OS_16,OS_S16]) then
  764. begin
  765. retcgsize:=OS_S32;
  766. result.def:=s32inttype;
  767. result.intsize:=4;
  768. result.size:=retcgsize;
  769. end;
  770. { Return in FPU register? -> don't use classify_argument(), because
  771. currency and comp need special treatment here (they are integer class
  772. when passing as parameter, but LOC_FPUREGISTER as function result) }
  773. if result.def.typ=floatdef then
  774. begin
  775. paraloc:=result.add_location;
  776. case tfloatdef(result.def).floattype of
  777. s32real:
  778. begin
  779. paraloc^.loc:=LOC_MMREGISTER;
  780. paraloc^.register:=newreg(R_MMREGISTER,RS_MM_RESULT_REG,R_SUBMMS);
  781. paraloc^.size:=OS_F32;
  782. end;
  783. s64real:
  784. begin
  785. paraloc^.loc:=LOC_MMREGISTER;
  786. paraloc^.register:=newreg(R_MMREGISTER,RS_MM_RESULT_REG,R_SUBMMD);
  787. paraloc^.size:=OS_F64;
  788. end;
  789. { the first two only exist on targets with an x87, on others
  790. they are replace by int64 }
  791. s64currency,
  792. s64comp,
  793. s80real,
  794. sc80real:
  795. begin
  796. paraloc^.loc:=LOC_FPUREGISTER;
  797. paraloc^.register:=NR_FPU_RESULT_REG;
  798. paraloc^.size:=retcgsize;
  799. end;
  800. else
  801. internalerror(200405034);
  802. end;
  803. end
  804. else
  805. { Return in register }
  806. begin
  807. numclasses:=classify_argument(result.def,vs_value,result.def.size,classes,0);
  808. { this would mean a memory return }
  809. if (numclasses=0) then
  810. internalerror(2010021502);
  811. { this would mean an _m256 vector (valid, but not yet supported) }
  812. if (numclasses>2) then
  813. internalerror(2010021503);
  814. intretregidx:=0;
  815. mmretregidx:=0;
  816. for i:=0 to numclasses-1 do
  817. begin
  818. paraloc:=result.add_location;
  819. case classes[i] of
  820. X86_64_INTEGERSI_CLASS,
  821. X86_64_INTEGER_CLASS:
  822. begin
  823. paraloc^.loc:=LOC_REGISTER;
  824. paraloc^.register:=intretregs[intretregidx];
  825. if classes[i]=X86_64_INTEGER_CLASS then
  826. paraloc^.size:=OS_64
  827. else if result.intsize in [1,2,4] then
  828. paraloc^.size:=retcgsize
  829. else
  830. paraloc^.size:=OS_32;
  831. setsubreg(paraloc^.register,cgsize2subreg(R_INTREGISTER,paraloc^.size));
  832. inc(intretregidx);
  833. end;
  834. X86_64_SSE_CLASS,
  835. X86_64_SSEUP_CLASS,
  836. X86_64_SSESF_CLASS,
  837. X86_64_SSEDF_CLASS:
  838. begin
  839. paraloc^.loc:=LOC_MMREGISTER;
  840. paraloc^.register:=mmretregs[mmretregidx];
  841. case classes[i] of
  842. X86_64_SSESF_CLASS:
  843. begin
  844. setsubreg(paraloc^.register,R_SUBMMS);
  845. paraloc^.size:=OS_F32;
  846. end;
  847. X86_64_SSEDF_CLASS:
  848. begin
  849. setsubreg(paraloc^.register,R_SUBMMD);
  850. paraloc^.size:=OS_F64;
  851. end;
  852. else
  853. begin
  854. setsubreg(paraloc^.register,R_SUBMMWHOLE);
  855. paraloc^.size:=OS_M64;
  856. end;
  857. end;
  858. inc(mmretregidx);
  859. end;
  860. X86_64_NO_CLASS:
  861. begin
  862. { empty record/array }
  863. if (i<>0) or
  864. (numclasses<>1) then
  865. internalerror(2010060302);
  866. paraloc^.loc:=LOC_VOID;
  867. end;
  868. else
  869. internalerror(2010021504);
  870. end;
  871. end;
  872. end;
  873. end;
  874. procedure tx86_64paramanager.create_paraloc_info_intern(p : tabstractprocdef; side: tcallercallee;paras:tparalist;
  875. var intparareg,mmparareg,parasize:longint;varargsparas: boolean);
  876. var
  877. hp : tparavarsym;
  878. paradef : tdef;
  879. paraloc : pcgparalocation;
  880. subreg : tsubregister;
  881. pushaddr : boolean;
  882. paracgsize : tcgsize;
  883. loc : array[1..2] of tx64paraclass;
  884. needintloc,
  885. needmmloc,
  886. paralen,
  887. locidx,
  888. i,
  889. varalign,
  890. paraalign : longint;
  891. begin
  892. paraalign:=get_para_align(p.proccalloption);
  893. { Register parameters are assigned from left to right }
  894. for i:=0 to paras.count-1 do
  895. begin
  896. hp:=tparavarsym(paras[i]);
  897. paradef:=hp.vardef;
  898. pushaddr:=push_addr_param(hp.varspez,paradef,p.proccalloption);
  899. if pushaddr then
  900. begin
  901. loc[1]:=X86_64_INTEGER_CLASS;
  902. loc[2]:=X86_64_NO_CLASS;
  903. paracgsize:=OS_ADDR;
  904. paralen:=sizeof(pint);
  905. paradef:=getpointerdef(paradef);
  906. end
  907. else
  908. begin
  909. getvalueparaloc(hp.varspez,paradef,loc[1],loc[2]);
  910. paralen:=push_size(hp.varspez,paradef,p.proccalloption);
  911. paracgsize:=def_cgsize(paradef);
  912. { integer sizes < 32 bit have to be sign/zero extended to 32 bit
  913. on the caller side }
  914. if (side=callerside) and
  915. (paracgsize in [OS_8,OS_S8,OS_16,OS_S16]) then
  916. begin
  917. paracgsize:=OS_S32;
  918. paralen:=4;
  919. paradef:=s32inttype;
  920. end;
  921. end;
  922. { cheat for now, we should copy the value to an mm reg as well (FK) }
  923. if varargsparas and
  924. (target_info.system = system_x86_64_win64) and
  925. (paradef.typ = floatdef) then
  926. begin
  927. loc[2]:=X86_64_NO_CLASS;
  928. if paracgsize=OS_F64 then
  929. begin
  930. loc[1]:=X86_64_INTEGER_CLASS;
  931. paracgsize:=OS_64;
  932. paradef:=u64inttype;
  933. end
  934. else
  935. begin
  936. loc[1]:=X86_64_INTEGERSI_CLASS;
  937. paracgsize:=OS_32;
  938. paradef:=u32inttype;
  939. end;
  940. end;
  941. hp.paraloc[side].reset;
  942. hp.paraloc[side].size:=paracgsize;
  943. hp.paraloc[side].intsize:=paralen;
  944. hp.paraloc[side].Alignment:=paraalign;
  945. hp.paraloc[side].def:=paradef;
  946. if paralen>0 then
  947. begin
  948. { Enough registers free? }
  949. needintloc:=0;
  950. needmmloc:=0;
  951. for locidx:=low(loc) to high(loc) do
  952. case loc[locidx] of
  953. X86_64_INTEGER_CLASS,
  954. X86_64_INTEGERSI_CLASS:
  955. inc(needintloc);
  956. X86_64_SSE_CLASS,
  957. X86_64_SSESF_CLASS,
  958. X86_64_SSEDF_CLASS,
  959. X86_64_SSEUP_CLASS:
  960. inc(needmmloc);
  961. end;
  962. { the "-1" is because we can also use the current register }
  963. if ((target_info.system=system_x86_64_win64) and
  964. ((intparareg+needintloc-1 > high(paraintsupregs_winx64)) or
  965. (mmparareg+needmmloc-1 > high(parammsupregs_winx64)))) or
  966. ((target_info.system<>system_x86_64_win64) and
  967. ((intparareg+needintloc-1 > high(paraintsupregs)) or
  968. (mmparareg+needmmloc-1 > high(parammsupregs)))) then
  969. begin
  970. { If there are no registers available for any
  971. eightbyte of an argument, the whole argument is
  972. passed on the stack. }
  973. loc[low(loc)]:=X86_64_MEMORY_CLASS;
  974. for locidx:=succ(low(loc)) to high(loc) do
  975. loc[locidx]:=X86_64_NO_CLASS;
  976. end;
  977. locidx:=1;
  978. while (paralen>0) do
  979. begin
  980. if locidx>2 then
  981. internalerror(200501283);
  982. { Allocate }
  983. case loc[locidx] of
  984. X86_64_INTEGER_CLASS,
  985. X86_64_INTEGERSI_CLASS:
  986. begin
  987. paraloc:=hp.paraloc[side].add_location;
  988. paraloc^.loc:=LOC_REGISTER;
  989. if (paracgsize=OS_NO) or (loc[2]<>X86_64_NO_CLASS) then
  990. begin
  991. if loc[locidx]=X86_64_INTEGER_CLASS then
  992. begin
  993. paraloc^.size:=OS_INT;
  994. subreg:=R_SUBWHOLE;
  995. end
  996. else
  997. begin
  998. paraloc^.size:=OS_32;
  999. subreg:=R_SUBD;
  1000. end;
  1001. end
  1002. else
  1003. begin
  1004. paraloc^.size:=paracgsize;
  1005. { s64comp is pushed in an int register }
  1006. if paraloc^.size=OS_C64 then
  1007. paraloc^.size:=OS_64;
  1008. subreg:=cgsize2subreg(R_INTREGISTER,paraloc^.size);
  1009. end;
  1010. { winx64 uses different registers }
  1011. if target_info.system=system_x86_64_win64 then
  1012. paraloc^.register:=newreg(R_INTREGISTER,paraintsupregs_winx64[intparareg],subreg)
  1013. else
  1014. paraloc^.register:=newreg(R_INTREGISTER,paraintsupregs[intparareg],subreg);
  1015. { matching mm register must be skipped }
  1016. if target_info.system=system_x86_64_win64 then
  1017. inc(mmparareg);
  1018. inc(intparareg);
  1019. dec(paralen,tcgsize2size[paraloc^.size]);
  1020. end;
  1021. X86_64_SSE_CLASS,
  1022. X86_64_SSESF_CLASS,
  1023. X86_64_SSEDF_CLASS,
  1024. X86_64_SSEUP_CLASS:
  1025. begin
  1026. paraloc:=hp.paraloc[side].add_location;
  1027. paraloc^.loc:=LOC_MMREGISTER;
  1028. case loc[locidx] of
  1029. X86_64_SSESF_CLASS:
  1030. begin
  1031. subreg:=R_SUBMMS;
  1032. paraloc^.size:=OS_F32;
  1033. end;
  1034. X86_64_SSEDF_CLASS:
  1035. begin
  1036. subreg:=R_SUBMMD;
  1037. paraloc^.size:=OS_F64;
  1038. end;
  1039. else
  1040. begin
  1041. subreg:=R_SUBMMWHOLE;
  1042. paraloc^.size:=OS_M64;
  1043. end;
  1044. end;
  1045. { winx64 uses different registers }
  1046. if target_info.system=system_x86_64_win64 then
  1047. paraloc^.register:=newreg(R_MMREGISTER,parammsupregs_winx64[mmparareg],subreg)
  1048. else
  1049. paraloc^.register:=newreg(R_MMREGISTER,parammsupregs[mmparareg],subreg);
  1050. { matching int register must be skipped }
  1051. if target_info.system=system_x86_64_win64 then
  1052. inc(intparareg);
  1053. inc(mmparareg);
  1054. dec(paralen,tcgsize2size[paraloc^.size]);
  1055. end;
  1056. X86_64_MEMORY_CLASS :
  1057. begin
  1058. paraloc:=hp.paraloc[side].add_location;
  1059. paraloc^.loc:=LOC_REFERENCE;
  1060. {Hack alert!!! We should modify int_cgsize to handle OS_128,
  1061. however, since int_cgsize is called in many places in the
  1062. compiler where only a few can already handle OS_128, fixing it
  1063. properly is out of the question to release 2.2.0 in time. (DM)}
  1064. if paracgsize=OS_128 then
  1065. if paralen=8 then
  1066. paraloc^.size:=OS_64
  1067. else if paralen=16 then
  1068. paraloc^.size:=OS_128
  1069. else
  1070. internalerror(200707143)
  1071. else if paracgsize in [OS_F32,OS_F64,OS_F80,OS_F128] then
  1072. paraloc^.size:=int_float_cgsize(paralen)
  1073. else
  1074. paraloc^.size:=int_cgsize(paralen);
  1075. if side=callerside then
  1076. paraloc^.reference.index:=NR_STACK_POINTER_REG
  1077. else
  1078. paraloc^.reference.index:=NR_FRAME_POINTER_REG;
  1079. varalign:=used_align(size_2_align(paralen),paraalign,paraalign);
  1080. paraloc^.reference.offset:=parasize;
  1081. parasize:=align(parasize+paralen,varalign);
  1082. paralen:=0;
  1083. end;
  1084. else
  1085. internalerror(2010053113);
  1086. end;
  1087. if (locidx<2) and
  1088. (loc[locidx+1]<>X86_64_NO_CLASS) then
  1089. inc(locidx);
  1090. end;
  1091. end
  1092. else
  1093. begin
  1094. paraloc:=hp.paraloc[side].add_location;
  1095. paraloc^.loc:=LOC_VOID;
  1096. end;
  1097. end;
  1098. { Register parameters are assigned from left-to-right, but the
  1099. offsets on the stack are right-to-left. There is no need
  1100. to reverse the offset, only adapt the calleeside with the
  1101. start offset of the first param on the stack }
  1102. if side=calleeside then
  1103. begin
  1104. for i:=0 to paras.count-1 do
  1105. begin
  1106. hp:=tparavarsym(paras[i]);
  1107. paraloc:=hp.paraloc[side].location;
  1108. while paraloc<>nil do
  1109. begin
  1110. with paraloc^ do
  1111. if (loc=LOC_REFERENCE) then
  1112. inc(reference.offset,target_info.first_parm_offset);
  1113. paraloc:=paraloc^.next;
  1114. end;
  1115. end;
  1116. end;
  1117. end;
  1118. function tx86_64paramanager.create_varargs_paraloc_info(p : tabstractprocdef; varargspara:tvarargsparalist):longint;
  1119. var
  1120. intparareg,mmparareg,
  1121. parasize : longint;
  1122. begin
  1123. intparareg:=0;
  1124. mmparareg:=0;
  1125. if target_info.system=system_x86_64_win64 then
  1126. parasize:=4*8
  1127. else
  1128. parasize:=0;
  1129. { calculate the registers for the normal parameters }
  1130. create_paraloc_info_intern(p,callerside,p.paras,intparareg,mmparareg,parasize,false);
  1131. { append the varargs }
  1132. create_paraloc_info_intern(p,callerside,varargspara,intparareg,mmparareg,parasize,true);
  1133. { store used no. of SSE registers, that needs to be passed in %AL }
  1134. varargspara.mmregsused:=mmparareg;
  1135. result:=parasize;
  1136. end;
  1137. function tx86_64paramanager.create_paraloc_info(p : tabstractprocdef; side: tcallercallee):longint;
  1138. var
  1139. intparareg,mmparareg,
  1140. parasize : longint;
  1141. begin
  1142. intparareg:=0;
  1143. mmparareg:=0;
  1144. if target_info.system=system_x86_64_win64 then
  1145. parasize:=4*8
  1146. else
  1147. parasize:=0;
  1148. create_paraloc_info_intern(p,side,p.paras,intparareg,mmparareg,parasize,false);
  1149. { Create Function result paraloc }
  1150. create_funcretloc_info(p,side);
  1151. { We need to return the size allocated on the stack }
  1152. result:=parasize;
  1153. end;
  1154. begin
  1155. paramanager:=tx86_64paramanager.create;
  1156. end.