2
0

cpupara.pas 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252
  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;calloption : tproccalloption) : 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;calloption : tproccalloption) : boolean;
  557. var
  558. classes: tx64paraclasses;
  559. numclasses: longint;
  560. begin
  561. if (tf_safecall_exceptions in target_info.flags) and
  562. (calloption=pocall_safecall) then
  563. begin
  564. result := true;
  565. exit;
  566. end;
  567. case def.typ of
  568. { for records it depends on their contents and size }
  569. recorddef,
  570. { make sure we handle 'procedure of object' correctly }
  571. procvardef:
  572. begin
  573. numclasses:=classify_argument(def,vs_value,def.size,classes,0);
  574. result:=(numclasses=0);
  575. end;
  576. else
  577. result:=inherited ret_in_param(def,calloption);
  578. end;
  579. end;
  580. function tx86_64paramanager.param_use_paraloc(const cgpara:tcgpara):boolean;
  581. var
  582. paraloc : pcgparalocation;
  583. begin
  584. if not assigned(cgpara.location) then
  585. internalerror(200410102);
  586. result:=true;
  587. { All locations are LOC_REFERENCE }
  588. paraloc:=cgpara.location;
  589. while assigned(paraloc) do
  590. begin
  591. if (paraloc^.loc<>LOC_REFERENCE) then
  592. begin
  593. result:=false;
  594. exit;
  595. end;
  596. paraloc:=paraloc^.next;
  597. end;
  598. end;
  599. { true if a parameter is too large to copy and only the address is pushed }
  600. function tx86_64paramanager.push_addr_param(varspez:tvarspez;def : tdef;calloption : tproccalloption) : boolean;
  601. var
  602. classes: tx64paraclasses;
  603. numclasses: longint;
  604. begin
  605. result:=false;
  606. { var,out,constref always require address }
  607. if varspez in [vs_var,vs_out,vs_constref] then
  608. begin
  609. result:=true;
  610. exit;
  611. end;
  612. { Only vs_const, vs_value here }
  613. case def.typ of
  614. formaldef :
  615. result:=true;
  616. recorddef :
  617. begin
  618. { MetroWerks Pascal: const records always passed by reference
  619. (for Mac OS X interfaces) }
  620. if (calloption=pocall_mwpascal) and
  621. (varspez=vs_const) then
  622. result:=true
  623. { Win ABI depends on size to pass it in a register or not }
  624. else if (target_info.system=system_x86_64_win64) then
  625. result:=not aggregate_in_registers_win64(varspez,def.size)
  626. { pass constant parameters that would be passed via memory by
  627. reference for non-cdecl/cppdecl, and make sure that the tmethod
  628. record (size=16) is passed the same way as a complex procvar }
  629. else if ((varspez=vs_const) and
  630. not(calloption in cdecl_pocalls)) or
  631. (def.size=16) then
  632. begin
  633. numclasses:=classify_argument(def,vs_value,def.size,classes,0);
  634. result:=numclasses=0;
  635. end
  636. else
  637. { SysV ABI always passes it as value parameter }
  638. result:=false;
  639. end;
  640. arraydef :
  641. begin
  642. { cdecl array of const need to be ignored and therefor be puhsed
  643. as value parameter with length 0 }
  644. if ((calloption in cdecl_pocalls) and
  645. is_array_of_const(def)) or
  646. is_dynamic_array(def) then
  647. result:=false
  648. else
  649. { pass all arrays by reference to be compatible with C (passing
  650. an array by value (= copying it on the stack) does not exist,
  651. because an array is the same as a pointer there }
  652. result:=true
  653. end;
  654. objectdef :
  655. begin
  656. { don't treat objects like records, because we only know wheter
  657. or not they'll have a VMT after the entire object is parsed
  658. -> if they are used as function result from one of their own
  659. methods, their size can still change after we've determined
  660. whether this function result should be returned by reference or
  661. by value }
  662. if is_object(def) then
  663. result:=true;
  664. end;
  665. variantdef,
  666. stringdef,
  667. procvardef,
  668. setdef :
  669. begin
  670. numclasses:=classify_argument(def,vs_value,def.size,classes,0);
  671. result:=numclasses=0;
  672. end;
  673. end;
  674. end;
  675. function tx86_64paramanager.get_volatile_registers_int(calloption : tproccalloption):tcpuregisterset;
  676. begin
  677. if target_info.system=system_x86_64_win64 then
  678. result:=[RS_RAX,RS_RCX,RS_RDX,RS_R8,RS_R9,RS_R10,RS_R11]
  679. else
  680. result:=[RS_RAX,RS_RCX,RS_RDX,RS_RSI,RS_RDI,RS_R8,RS_R9,RS_R10,RS_R11];
  681. end;
  682. function tx86_64paramanager.get_volatile_registers_mm(calloption : tproccalloption):tcpuregisterset;
  683. begin
  684. if target_info.system=system_x86_64_win64 then
  685. result:=[RS_XMM0..RS_XMM5]
  686. else
  687. result:=[RS_XMM0..RS_XMM15];
  688. end;
  689. function tx86_64paramanager.get_volatile_registers_fpu(calloption : tproccalloption):tcpuregisterset;
  690. begin
  691. result:=[RS_ST0..RS_ST7];
  692. end;
  693. procedure tx86_64paramanager.getintparaloc(pd : tabstractprocdef; nr : longint; var cgpara : tcgpara);
  694. var
  695. paraloc : pcgparalocation;
  696. def : tdef;
  697. begin
  698. def:=tparavarsym(pd.paras[nr-1]).vardef;
  699. cgpara.reset;
  700. cgpara.size:=def_cgsize(def);
  701. cgpara.intsize:=tcgsize2size[cgpara.size];
  702. cgpara.alignment:=get_para_align(pd.proccalloption);
  703. cgpara.def:=def;
  704. paraloc:=cgpara.add_location;
  705. with paraloc^ do
  706. begin
  707. size:=OS_INT;
  708. if target_info.system=system_x86_64_win64 then
  709. begin
  710. if nr<1 then
  711. internalerror(200304303)
  712. else if nr<=high(paraintsupregs_winx64)+1 then
  713. begin
  714. loc:=LOC_REGISTER;
  715. register:=newreg(R_INTREGISTER,paraintsupregs_winx64[nr-1],R_SUBWHOLE);
  716. end
  717. else
  718. begin
  719. loc:=LOC_REFERENCE;
  720. reference.index:=NR_STACK_POINTER_REG;
  721. reference.offset:=(nr-6)*sizeof(aint);
  722. end;
  723. end
  724. else
  725. begin
  726. if nr<1 then
  727. internalerror(200304303)
  728. else if nr<=high(paraintsupregs)+1 then
  729. begin
  730. loc:=LOC_REGISTER;
  731. register:=newreg(R_INTREGISTER,paraintsupregs[nr-1],R_SUBWHOLE);
  732. end
  733. else
  734. begin
  735. loc:=LOC_REFERENCE;
  736. reference.index:=NR_STACK_POINTER_REG;
  737. reference.offset:=(nr-6)*sizeof(aint);
  738. end;
  739. end;
  740. end;
  741. end;
  742. function tx86_64paramanager.get_funcretloc(p : tabstractprocdef; side: tcallercallee; forcetempdef: tdef): tcgpara;
  743. const
  744. intretregs: array[0..1] of tregister = (NR_FUNCTION_RETURN_REG,NR_FUNCTION_RETURN_REG_HIGH);
  745. mmretregs: array[0..1] of tregister = (NR_MM_RESULT_REG,NR_MM_RESULT_REG_HIGH);
  746. var
  747. classes: tx64paraclasses;
  748. i,
  749. numclasses: longint;
  750. intretregidx,
  751. mmretregidx: longint;
  752. retcgsize : tcgsize;
  753. paraloc : pcgparalocation;
  754. begin
  755. if set_common_funcretloc_info(p,forcetempdef,retcgsize,result) then
  756. exit;
  757. { integer sizes < 32 bit have to be sign/zero extended to 32 bit on
  758. the callee side (caller can expect those bits are valid) }
  759. if (side=calleeside) and
  760. (retcgsize in [OS_8,OS_S8,OS_16,OS_S16]) then
  761. begin
  762. retcgsize:=OS_S32;
  763. result.def:=s32inttype;
  764. result.intsize:=4;
  765. result.size:=retcgsize;
  766. end;
  767. { Return in FPU register? -> don't use classify_argument(), because
  768. currency and comp need special treatment here (they are integer class
  769. when passing as parameter, but LOC_FPUREGISTER as function result) }
  770. if result.def.typ=floatdef then
  771. begin
  772. paraloc:=result.add_location;
  773. case tfloatdef(result.def).floattype of
  774. s32real:
  775. begin
  776. paraloc^.loc:=LOC_MMREGISTER;
  777. paraloc^.register:=newreg(R_MMREGISTER,RS_MM_RESULT_REG,R_SUBMMS);
  778. paraloc^.size:=OS_F32;
  779. end;
  780. s64real:
  781. begin
  782. paraloc^.loc:=LOC_MMREGISTER;
  783. paraloc^.register:=newreg(R_MMREGISTER,RS_MM_RESULT_REG,R_SUBMMD);
  784. paraloc^.size:=OS_F64;
  785. end;
  786. { the first two only exist on targets with an x87, on others
  787. they are replace by int64 }
  788. s64currency,
  789. s64comp,
  790. s80real,
  791. sc80real:
  792. begin
  793. paraloc^.loc:=LOC_FPUREGISTER;
  794. paraloc^.register:=NR_FPU_RESULT_REG;
  795. paraloc^.size:=retcgsize;
  796. end;
  797. else
  798. internalerror(200405034);
  799. end;
  800. end
  801. else
  802. { Return in register }
  803. begin
  804. numclasses:=classify_argument(result.def,vs_value,result.def.size,classes,0);
  805. { this would mean a memory return }
  806. if (numclasses=0) then
  807. internalerror(2010021502);
  808. { this would mean an _m256 vector (valid, but not yet supported) }
  809. if (numclasses>2) then
  810. internalerror(2010021503);
  811. intretregidx:=0;
  812. mmretregidx:=0;
  813. for i:=0 to numclasses-1 do
  814. begin
  815. paraloc:=result.add_location;
  816. case classes[i] of
  817. X86_64_INTEGERSI_CLASS,
  818. X86_64_INTEGER_CLASS:
  819. begin
  820. paraloc^.loc:=LOC_REGISTER;
  821. paraloc^.register:=intretregs[intretregidx];
  822. if classes[i]=X86_64_INTEGER_CLASS then
  823. paraloc^.size:=OS_64
  824. else if result.intsize in [1,2,4] then
  825. paraloc^.size:=retcgsize
  826. else
  827. paraloc^.size:=OS_32;
  828. setsubreg(paraloc^.register,cgsize2subreg(R_INTREGISTER,paraloc^.size));
  829. inc(intretregidx);
  830. end;
  831. X86_64_SSE_CLASS,
  832. X86_64_SSEUP_CLASS,
  833. X86_64_SSESF_CLASS,
  834. X86_64_SSEDF_CLASS:
  835. begin
  836. paraloc^.loc:=LOC_MMREGISTER;
  837. paraloc^.register:=mmretregs[mmretregidx];
  838. case classes[i] of
  839. X86_64_SSESF_CLASS:
  840. begin
  841. setsubreg(paraloc^.register,R_SUBMMS);
  842. paraloc^.size:=OS_F32;
  843. end;
  844. X86_64_SSEDF_CLASS:
  845. begin
  846. setsubreg(paraloc^.register,R_SUBMMD);
  847. paraloc^.size:=OS_F64;
  848. end;
  849. else
  850. begin
  851. setsubreg(paraloc^.register,R_SUBMMWHOLE);
  852. paraloc^.size:=OS_M64;
  853. end;
  854. end;
  855. inc(mmretregidx);
  856. end;
  857. X86_64_NO_CLASS:
  858. begin
  859. { empty record/array }
  860. if (i<>0) or
  861. (numclasses<>1) then
  862. internalerror(2010060302);
  863. paraloc^.loc:=LOC_VOID;
  864. end;
  865. else
  866. internalerror(2010021504);
  867. end;
  868. end;
  869. end;
  870. end;
  871. procedure tx86_64paramanager.create_paraloc_info_intern(p : tabstractprocdef; side: tcallercallee;paras:tparalist;
  872. var intparareg,mmparareg,parasize:longint;varargsparas: boolean);
  873. var
  874. hp : tparavarsym;
  875. paradef : tdef;
  876. paraloc : pcgparalocation;
  877. subreg : tsubregister;
  878. pushaddr : boolean;
  879. paracgsize : tcgsize;
  880. loc : array[1..2] of tx64paraclass;
  881. needintloc,
  882. needmmloc,
  883. paralen,
  884. locidx,
  885. i,
  886. varalign,
  887. paraalign : longint;
  888. begin
  889. paraalign:=get_para_align(p.proccalloption);
  890. { Register parameters are assigned from left to right }
  891. for i:=0 to paras.count-1 do
  892. begin
  893. hp:=tparavarsym(paras[i]);
  894. paradef:=hp.vardef;
  895. pushaddr:=push_addr_param(hp.varspez,paradef,p.proccalloption);
  896. if pushaddr then
  897. begin
  898. loc[1]:=X86_64_INTEGER_CLASS;
  899. loc[2]:=X86_64_NO_CLASS;
  900. paracgsize:=OS_ADDR;
  901. paralen:=sizeof(pint);
  902. paradef:=getpointerdef(paradef);
  903. end
  904. else
  905. begin
  906. getvalueparaloc(hp.varspez,paradef,loc[1],loc[2]);
  907. paralen:=push_size(hp.varspez,paradef,p.proccalloption);
  908. paracgsize:=def_cgsize(paradef);
  909. { integer sizes < 32 bit have to be sign/zero extended to 32 bit
  910. on the caller side }
  911. if (side=callerside) and
  912. (paracgsize in [OS_8,OS_S8,OS_16,OS_S16]) then
  913. begin
  914. paracgsize:=OS_S32;
  915. paralen:=4;
  916. paradef:=s32inttype;
  917. end;
  918. end;
  919. { cheat for now, we should copy the value to an mm reg as well (FK) }
  920. if varargsparas and
  921. (target_info.system = system_x86_64_win64) and
  922. (paradef.typ = floatdef) then
  923. begin
  924. loc[2]:=X86_64_NO_CLASS;
  925. if paracgsize=OS_F64 then
  926. begin
  927. loc[1]:=X86_64_INTEGER_CLASS;
  928. paracgsize:=OS_64;
  929. paradef:=u64inttype;
  930. end
  931. else
  932. begin
  933. loc[1]:=X86_64_INTEGERSI_CLASS;
  934. paracgsize:=OS_32;
  935. paradef:=u32inttype;
  936. end;
  937. end;
  938. hp.paraloc[side].reset;
  939. hp.paraloc[side].size:=paracgsize;
  940. hp.paraloc[side].intsize:=paralen;
  941. hp.paraloc[side].Alignment:=paraalign;
  942. hp.paraloc[side].def:=paradef;
  943. if paralen>0 then
  944. begin
  945. { Enough registers free? }
  946. needintloc:=0;
  947. needmmloc:=0;
  948. for locidx:=low(loc) to high(loc) do
  949. case loc[locidx] of
  950. X86_64_INTEGER_CLASS,
  951. X86_64_INTEGERSI_CLASS:
  952. inc(needintloc);
  953. X86_64_SSE_CLASS,
  954. X86_64_SSESF_CLASS,
  955. X86_64_SSEDF_CLASS,
  956. X86_64_SSEUP_CLASS:
  957. inc(needmmloc);
  958. end;
  959. { the "-1" is because we can also use the current register }
  960. if ((target_info.system=system_x86_64_win64) and
  961. ((intparareg+needintloc-1 > high(paraintsupregs_winx64)) or
  962. (mmparareg+needmmloc-1 > high(parammsupregs_winx64)))) or
  963. ((target_info.system<>system_x86_64_win64) and
  964. ((intparareg+needintloc-1 > high(paraintsupregs)) or
  965. (mmparareg+needmmloc-1 > high(parammsupregs)))) then
  966. begin
  967. { If there are no registers available for any
  968. eightbyte of an argument, the whole argument is
  969. passed on the stack. }
  970. loc[low(loc)]:=X86_64_MEMORY_CLASS;
  971. for locidx:=succ(low(loc)) to high(loc) do
  972. loc[locidx]:=X86_64_NO_CLASS;
  973. end;
  974. locidx:=1;
  975. while (paralen>0) do
  976. begin
  977. if locidx>2 then
  978. internalerror(200501283);
  979. { Allocate }
  980. case loc[locidx] of
  981. X86_64_INTEGER_CLASS,
  982. X86_64_INTEGERSI_CLASS:
  983. begin
  984. paraloc:=hp.paraloc[side].add_location;
  985. paraloc^.loc:=LOC_REGISTER;
  986. if (paracgsize=OS_NO) or (loc[2]<>X86_64_NO_CLASS) then
  987. begin
  988. if loc[locidx]=X86_64_INTEGER_CLASS then
  989. begin
  990. paraloc^.size:=OS_INT;
  991. subreg:=R_SUBWHOLE;
  992. end
  993. else
  994. begin
  995. paraloc^.size:=OS_32;
  996. subreg:=R_SUBD;
  997. end;
  998. end
  999. else
  1000. begin
  1001. paraloc^.size:=paracgsize;
  1002. { s64comp is pushed in an int register }
  1003. if paraloc^.size=OS_C64 then
  1004. paraloc^.size:=OS_64;
  1005. subreg:=cgsize2subreg(R_INTREGISTER,paraloc^.size);
  1006. end;
  1007. { winx64 uses different registers }
  1008. if target_info.system=system_x86_64_win64 then
  1009. paraloc^.register:=newreg(R_INTREGISTER,paraintsupregs_winx64[intparareg],subreg)
  1010. else
  1011. paraloc^.register:=newreg(R_INTREGISTER,paraintsupregs[intparareg],subreg);
  1012. { matching mm register must be skipped }
  1013. if target_info.system=system_x86_64_win64 then
  1014. inc(mmparareg);
  1015. inc(intparareg);
  1016. dec(paralen,tcgsize2size[paraloc^.size]);
  1017. end;
  1018. X86_64_SSE_CLASS,
  1019. X86_64_SSESF_CLASS,
  1020. X86_64_SSEDF_CLASS,
  1021. X86_64_SSEUP_CLASS:
  1022. begin
  1023. paraloc:=hp.paraloc[side].add_location;
  1024. paraloc^.loc:=LOC_MMREGISTER;
  1025. case loc[locidx] of
  1026. X86_64_SSESF_CLASS:
  1027. begin
  1028. subreg:=R_SUBMMS;
  1029. paraloc^.size:=OS_F32;
  1030. end;
  1031. X86_64_SSEDF_CLASS:
  1032. begin
  1033. subreg:=R_SUBMMD;
  1034. paraloc^.size:=OS_F64;
  1035. end;
  1036. else
  1037. begin
  1038. subreg:=R_SUBMMWHOLE;
  1039. paraloc^.size:=OS_M64;
  1040. end;
  1041. end;
  1042. { winx64 uses different registers }
  1043. if target_info.system=system_x86_64_win64 then
  1044. paraloc^.register:=newreg(R_MMREGISTER,parammsupregs_winx64[mmparareg],subreg)
  1045. else
  1046. paraloc^.register:=newreg(R_MMREGISTER,parammsupregs[mmparareg],subreg);
  1047. { matching int register must be skipped }
  1048. if target_info.system=system_x86_64_win64 then
  1049. inc(intparareg);
  1050. inc(mmparareg);
  1051. dec(paralen,tcgsize2size[paraloc^.size]);
  1052. end;
  1053. X86_64_MEMORY_CLASS :
  1054. begin
  1055. paraloc:=hp.paraloc[side].add_location;
  1056. paraloc^.loc:=LOC_REFERENCE;
  1057. {Hack alert!!! We should modify int_cgsize to handle OS_128,
  1058. however, since int_cgsize is called in many places in the
  1059. compiler where only a few can already handle OS_128, fixing it
  1060. properly is out of the question to release 2.2.0 in time. (DM)}
  1061. if paracgsize=OS_128 then
  1062. if paralen=8 then
  1063. paraloc^.size:=OS_64
  1064. else if paralen=16 then
  1065. paraloc^.size:=OS_128
  1066. else
  1067. internalerror(200707143)
  1068. else if paracgsize in [OS_F32,OS_F64,OS_F80,OS_F128] then
  1069. paraloc^.size:=int_float_cgsize(paralen)
  1070. else
  1071. paraloc^.size:=int_cgsize(paralen);
  1072. if side=callerside then
  1073. paraloc^.reference.index:=NR_STACK_POINTER_REG
  1074. else
  1075. paraloc^.reference.index:=NR_FRAME_POINTER_REG;
  1076. varalign:=used_align(size_2_align(paralen),paraalign,paraalign);
  1077. paraloc^.reference.offset:=parasize;
  1078. parasize:=align(parasize+paralen,varalign);
  1079. paralen:=0;
  1080. end;
  1081. else
  1082. internalerror(2010053113);
  1083. end;
  1084. if (locidx<2) and
  1085. (loc[locidx+1]<>X86_64_NO_CLASS) then
  1086. inc(locidx);
  1087. end;
  1088. end
  1089. else
  1090. begin
  1091. paraloc:=hp.paraloc[side].add_location;
  1092. paraloc^.loc:=LOC_VOID;
  1093. end;
  1094. end;
  1095. { Register parameters are assigned from left-to-right, but the
  1096. offsets on the stack are right-to-left. There is no need
  1097. to reverse the offset, only adapt the calleeside with the
  1098. start offset of the first param on the stack }
  1099. if side=calleeside then
  1100. begin
  1101. for i:=0 to paras.count-1 do
  1102. begin
  1103. hp:=tparavarsym(paras[i]);
  1104. paraloc:=hp.paraloc[side].location;
  1105. while paraloc<>nil do
  1106. begin
  1107. with paraloc^ do
  1108. if (loc=LOC_REFERENCE) then
  1109. inc(reference.offset,target_info.first_parm_offset);
  1110. paraloc:=paraloc^.next;
  1111. end;
  1112. end;
  1113. end;
  1114. end;
  1115. function tx86_64paramanager.create_varargs_paraloc_info(p : tabstractprocdef; varargspara:tvarargsparalist):longint;
  1116. var
  1117. intparareg,mmparareg,
  1118. parasize : longint;
  1119. begin
  1120. intparareg:=0;
  1121. mmparareg:=0;
  1122. if target_info.system=system_x86_64_win64 then
  1123. parasize:=4*8
  1124. else
  1125. parasize:=0;
  1126. { calculate the registers for the normal parameters }
  1127. create_paraloc_info_intern(p,callerside,p.paras,intparareg,mmparareg,parasize,false);
  1128. { append the varargs }
  1129. create_paraloc_info_intern(p,callerside,varargspara,intparareg,mmparareg,parasize,true);
  1130. { store used no. of SSE registers, that needs to be passed in %AL }
  1131. varargspara.mmregsused:=mmparareg;
  1132. result:=parasize;
  1133. end;
  1134. function tx86_64paramanager.create_paraloc_info(p : tabstractprocdef; side: tcallercallee):longint;
  1135. var
  1136. intparareg,mmparareg,
  1137. parasize : longint;
  1138. begin
  1139. intparareg:=0;
  1140. mmparareg:=0;
  1141. if target_info.system=system_x86_64_win64 then
  1142. parasize:=4*8
  1143. else
  1144. parasize:=0;
  1145. create_paraloc_info_intern(p,side,p.paras,intparareg,mmparareg,parasize,false);
  1146. { Create Function result paraloc }
  1147. create_funcretloc_info(p,side);
  1148. { We need to return the size allocated on the stack }
  1149. result:=parasize;
  1150. end;
  1151. begin
  1152. paramanager:=tx86_64paramanager.create;
  1153. end.