rgcpu.pas 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. {
  2. Copyright (c) 1998-2003 by Florian Klaempfl
  3. This unit implements the arm specific class for the register
  4. allocator
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit rgcpu;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. aasmbase,aasmtai,aasmsym,aasmdata,aasmcpu,
  23. cgbase,cgutils,
  24. cpubase,
  25. {$ifdef DEBUG_SPILLING}
  26. cutils,
  27. {$endif}
  28. rgobj;
  29. type
  30. trgcpu = class(trgobj)
  31. private
  32. procedure spilling_create_load_store(list: TAsmList; pos: tai; const spilltemp:treference;tempreg:tregister; is_store: boolean);
  33. public
  34. procedure do_spill_read(list: TAsmList; pos: tai; const spilltemp: treference; tempreg: tregister; orgsupreg: tsuperregister); override;
  35. procedure do_spill_written(list: TAsmList; pos: tai; const spilltemp: treference; tempreg: tregister; orgsupreg: tsuperregister); override;
  36. function do_spill_replace(list : TAsmList;instr : tai_cpu_abstract_sym;
  37. orgreg : tsuperregister;const spilltemp : treference) : boolean;override;
  38. procedure add_constraints(reg:tregister);override;
  39. function get_spill_subreg(r:tregister) : tsubregister;override;
  40. end;
  41. trgcputhumb2 = class(trgobj)
  42. private
  43. procedure SplitITBlock(list:TAsmList;pos:tai);
  44. public
  45. procedure do_spill_read(list: TAsmList; pos: tai; const spilltemp: treference; tempreg: tregister; orgsupreg: tsuperregister); override;
  46. procedure do_spill_written(list: TAsmList; pos: tai; const spilltemp: treference; tempreg: tregister; orgsupreg: tsuperregister); override;
  47. end;
  48. trgintcputhumb2 = class(trgcputhumb2)
  49. procedure add_cpu_interferences(p : tai);override;
  50. end;
  51. trgintcpu = class(trgcpu)
  52. procedure add_cpu_interferences(p : tai);override;
  53. end;
  54. trgcputhumb = class(trgcpu)
  55. end;
  56. trgintcputhumb = class(trgcputhumb)
  57. procedure add_cpu_interferences(p: tai);override;
  58. end;
  59. implementation
  60. uses
  61. verbose,globtype,globals,cpuinfo,
  62. cgobj,
  63. procinfo;
  64. procedure trgintcputhumb2.add_cpu_interferences(p: tai);
  65. var
  66. r : tregister;
  67. hr : longint;
  68. begin
  69. if p.typ=ait_instruction then
  70. begin
  71. case taicpu(p).opcode of
  72. A_CBNZ,
  73. A_CBZ:
  74. begin
  75. for hr := RS_R8 to RS_R15 do
  76. add_edge(getsupreg(taicpu(p).oper[0]^.reg), hr);
  77. end;
  78. A_ADD,
  79. A_SUB,
  80. A_AND,
  81. A_BIC,
  82. A_EOR:
  83. begin
  84. if taicpu(p).ops = 3 then
  85. begin
  86. if (taicpu(p).oper[0]^.typ = top_reg) and
  87. (taicpu(p).oper[1]^.typ = top_reg) and
  88. (taicpu(p).oper[2]^.typ in [top_reg, top_shifterop]) then
  89. begin
  90. { if d == 13 || (d == 15 && S == ‘0’) || n == 15 || m IN [13,15] then UNPREDICTABLE; }
  91. add_edge(getsupreg(taicpu(p).oper[0]^.reg), RS_R13);
  92. if taicpu(p).oppostfix <> PF_S then
  93. add_edge(getsupreg(taicpu(p).oper[0]^.reg), RS_R15);
  94. add_edge(getsupreg(taicpu(p).oper[1]^.reg), RS_R15);
  95. if (taicpu(p).oper[2]^.typ = top_shifterop) and
  96. (taicpu(p).oper[2]^.shifterop^.rs <> NR_NO) then
  97. begin
  98. add_edge(getsupreg(taicpu(p).oper[2]^.shifterop^.rs), RS_R13);
  99. add_edge(getsupreg(taicpu(p).oper[2]^.shifterop^.rs), RS_R15);
  100. end
  101. else if (taicpu(p).oper[2]^.typ = top_reg) then
  102. begin
  103. add_edge(getsupreg(taicpu(p).oper[2]^.reg), RS_R13);
  104. add_edge(getsupreg(taicpu(p).oper[2]^.reg), RS_R15);
  105. end;
  106. end;
  107. end;
  108. end;
  109. A_MLA,
  110. A_MLS,
  111. A_MUL:
  112. begin
  113. if (current_settings.cputype<cpu_armv6) and (taicpu(p).opcode<>A_MLS) then
  114. add_edge(getsupreg(taicpu(p).oper[0]^.reg),getsupreg(taicpu(p).oper[1]^.reg));
  115. add_edge(getsupreg(taicpu(p).oper[0]^.reg),RS_R13);
  116. add_edge(getsupreg(taicpu(p).oper[0]^.reg),RS_R15);
  117. add_edge(getsupreg(taicpu(p).oper[1]^.reg),RS_R13);
  118. add_edge(getsupreg(taicpu(p).oper[1]^.reg),RS_R15);
  119. add_edge(getsupreg(taicpu(p).oper[2]^.reg),RS_R13);
  120. add_edge(getsupreg(taicpu(p).oper[2]^.reg),RS_R15);
  121. if taicpu(p).opcode<>A_MUL then
  122. begin
  123. add_edge(getsupreg(taicpu(p).oper[3]^.reg),RS_R13);
  124. add_edge(getsupreg(taicpu(p).oper[3]^.reg),RS_R15);
  125. end;
  126. end;
  127. A_LDRB,
  128. A_STRB,
  129. A_STR,
  130. A_LDR,
  131. A_LDRH,
  132. A_STRH,
  133. A_LDRSB,
  134. A_LDRSH,
  135. A_LDRD,
  136. A_STRD:
  137. { don't mix up the framepointer and stackpointer with pre/post indexed operations }
  138. if (taicpu(p).oper[1]^.typ=top_ref) and
  139. (taicpu(p).oper[1]^.ref^.addressmode in [AM_PREINDEXED,AM_POSTINDEXED]) then
  140. begin
  141. add_edge(getsupreg(taicpu(p).oper[1]^.ref^.base),getsupreg(current_procinfo.framepointer));
  142. { FIXME: temp variable r is needed here to avoid Internal error 20060521 }
  143. { while compiling the compiler. }
  144. r:=NR_STACK_POINTER_REG;
  145. if current_procinfo.framepointer<>r then
  146. add_edge(getsupreg(taicpu(p).oper[1]^.ref^.base),getsupreg(r));
  147. end;
  148. end;
  149. end;
  150. end;
  151. procedure trgcpu.spilling_create_load_store(list: TAsmList; pos: tai; const spilltemp:treference;tempreg:tregister; is_store: boolean);
  152. var
  153. tmpref : treference;
  154. helplist : TAsmList;
  155. hreg : tregister;
  156. immshift: byte;
  157. a: aint;
  158. begin
  159. helplist:=TAsmList.create;
  160. { load consts entry }
  161. if getregtype(tempreg)=R_INTREGISTER then
  162. hreg:=getregisterinline(helplist,[R_SUBWHOLE])
  163. else
  164. hreg:=cg.getintregister(helplist,OS_ADDR);
  165. { Lets remove the bits we can fold in later and check if the result can be easily with an add or sub }
  166. a:=abs(spilltemp.offset);
  167. if GenerateThumbCode then
  168. begin
  169. {$ifdef DEBUG_SPILLING}
  170. helplist.concat(tai_comment.create(strpnew('Spilling: Use a_load_const_reg to fix spill offset')));
  171. {$endif}
  172. cg.a_load_const_reg(helplist,OS_ADDR,spilltemp.offset,hreg);
  173. cg.a_op_reg_reg(helplist,OP_ADD,OS_ADDR,current_procinfo.framepointer,hreg);
  174. reference_reset_base(tmpref,hreg,0,sizeof(aint));
  175. end
  176. else if is_shifter_const(a and not($FFF), immshift) then
  177. if spilltemp.offset > 0 then
  178. begin
  179. {$ifdef DEBUG_SPILLING}
  180. helplist.concat(tai_comment.create(strpnew('Spilling: Use ADD to fix spill offset')));
  181. {$endif}
  182. helplist.concat(taicpu.op_reg_reg_const(A_ADD, hreg, current_procinfo.framepointer,
  183. a and not($FFF)));
  184. reference_reset_base(tmpref, hreg, a and $FFF, sizeof(aint));
  185. end
  186. else
  187. begin
  188. {$ifdef DEBUG_SPILLING}
  189. helplist.concat(tai_comment.create(strpnew('Spilling: Use SUB to fix spill offset')));
  190. {$endif}
  191. helplist.concat(taicpu.op_reg_reg_const(A_SUB, hreg, current_procinfo.framepointer,
  192. a and not($FFF)));
  193. reference_reset_base(tmpref, hreg, -(a and $FFF), sizeof(aint));
  194. end
  195. else
  196. begin
  197. {$ifdef DEBUG_SPILLING}
  198. helplist.concat(tai_comment.create(strpnew('Spilling: Use a_load_const_reg to fix spill offset')));
  199. {$endif}
  200. cg.a_load_const_reg(helplist,OS_ADDR,spilltemp.offset,hreg);
  201. reference_reset_base(tmpref,current_procinfo.framepointer,0,sizeof(aint));
  202. tmpref.index:=hreg;
  203. end;
  204. if spilltemp.index<>NR_NO then
  205. internalerror(200401263);
  206. if is_store then
  207. helplist.concat(spilling_create_store(tempreg,tmpref))
  208. else
  209. helplist.concat(spilling_create_load(tmpref,tempreg));
  210. if getregtype(tempreg)=R_INTREGISTER then
  211. ungetregisterinline(helplist,hreg);
  212. list.insertlistafter(pos,helplist);
  213. helplist.free;
  214. end;
  215. function fix_spilling_offset(offset : ASizeInt) : boolean;
  216. begin
  217. result:=(abs(offset)>4095) or
  218. ((GenerateThumbCode) and ((offset<0) or (offset>1020)));
  219. end;
  220. procedure trgcpu.do_spill_read(list: TAsmList; pos: tai; const spilltemp: treference; tempreg: tregister; orgsupreg: tsuperregister);
  221. begin
  222. { don't load spilled register between
  223. mov lr,pc
  224. mov pc,r4
  225. but befure the mov lr,pc
  226. }
  227. if assigned(pos.previous) and
  228. (pos.typ=ait_instruction) and
  229. (taicpu(pos).opcode=A_MOV) and
  230. (taicpu(pos).oper[0]^.typ=top_reg) and
  231. (taicpu(pos).oper[0]^.reg=NR_R14) and
  232. (taicpu(pos).oper[1]^.typ=top_reg) and
  233. (taicpu(pos).oper[1]^.reg=NR_PC) then
  234. pos:=tai(pos.previous);
  235. if fix_spilling_offset(spilltemp.offset) then
  236. spilling_create_load_store(list, pos, spilltemp, tempreg, false)
  237. else
  238. inherited;
  239. end;
  240. procedure trgcpu.do_spill_written(list: TAsmList; pos: tai; const spilltemp: treference; tempreg: tregister; orgsupreg: tsuperregister);
  241. begin
  242. if fix_spilling_offset(spilltemp.offset) then
  243. spilling_create_load_store(list, pos, spilltemp, tempreg, true)
  244. else
  245. inherited;
  246. end;
  247. function trgcpu.do_spill_replace(list:TAsmList;instr:tai_cpu_abstract_sym;orgreg:tsuperregister;const spilltemp:treference):boolean;
  248. begin
  249. result:=false;
  250. if abs(spilltemp.offset)>4095 then
  251. exit;
  252. { ldr can't set the flags }
  253. if taicpu(instr).oppostfix=PF_S then
  254. exit;
  255. if GenerateThumbCode and
  256. (abs(spilltemp.offset)>1020) then
  257. exit;
  258. { Replace 'mov dst,orgreg' with 'ldr dst,spilltemp'
  259. and 'mov orgreg,src' with 'str dst,spilltemp' }
  260. with instr do
  261. begin
  262. if (opcode=A_MOV) and (ops=2) and (oper[1]^.typ=top_reg) and (oper[0]^.typ=top_reg) then
  263. begin
  264. if (getregtype(oper[0]^.reg)=regtype) and
  265. (get_alias(getsupreg(oper[0]^.reg))=orgreg) and
  266. (get_alias(getsupreg(oper[1]^.reg))<>orgreg) then
  267. begin
  268. { do not replace if we're on Thumb, ldr/str cannot be used with rX>r7 }
  269. if GenerateThumbCode and
  270. (getsupreg(oper[1]^.reg)>RS_R7) then
  271. exit;
  272. { str expects the register in oper[0] }
  273. instr.loadreg(0,oper[1]^.reg);
  274. instr.loadref(1,spilltemp);
  275. opcode:=A_STR;
  276. result:=true;
  277. end
  278. else if (getregtype(oper[1]^.reg)=regtype) and
  279. (get_alias(getsupreg(oper[1]^.reg))=orgreg) and
  280. (get_alias(getsupreg(oper[0]^.reg))<>orgreg) then
  281. begin
  282. { do not replace if we're on Thumb, ldr/str cannot be used with rX>r7 }
  283. if GenerateThumbCode and
  284. (getsupreg(oper[0]^.reg)>RS_R7) then
  285. exit;
  286. instr.loadref(1,spilltemp);
  287. opcode:=A_LDR;
  288. result:=true;
  289. end;
  290. end;
  291. end;
  292. end;
  293. procedure trgcpu.add_constraints(reg:tregister);
  294. var
  295. supreg,i : Tsuperregister;
  296. begin
  297. case getsubreg(reg) of
  298. { Let 32bit floats conflict with all double precision regs > 15
  299. (since these don't have 32 bit equivalents) }
  300. R_SUBFS:
  301. begin
  302. supreg:=getsupreg(reg);
  303. for i:=RS_D16 to RS_D31 do
  304. add_edge(supreg,i);
  305. { further, we cannot use the odd single registers as the register
  306. allocator cannot handle overlapping registers so far }
  307. for i in [RS_S1,RS_S3,RS_S5,RS_S7,RS_S9,RS_S11,RS_S13,RS_S15,RS_S17,RS_S19,
  308. RS_S21,RS_S23,RS_S25,RS_S27,RS_S29,RS_S31] do
  309. add_edge(supreg,i);
  310. end;
  311. end;
  312. end;
  313. function trgcpu.get_spill_subreg(r:tregister) : tsubregister;
  314. begin
  315. if (getregtype(r)<>R_MMREGISTER) then
  316. result:=defaultsub
  317. else
  318. result:=getsubreg(r);
  319. end;
  320. function GetITRemainderOp(originalOp:TAsmOp;remLevels:longint;var newOp: TAsmOp;var NeedsCondSwap:boolean) : TAsmOp;
  321. const
  322. remOps : array[1..3] of array[A_ITE..A_ITTTT] of TAsmOp = (
  323. (A_IT,A_IT, A_IT,A_IT,A_IT,A_IT, A_IT,A_IT,A_IT,A_IT,A_IT,A_IT,A_IT,A_IT),
  324. (A_NONE,A_NONE, A_ITT,A_ITE,A_ITE,A_ITT, A_ITT,A_ITT,A_ITE,A_ITE,A_ITE,A_ITE,A_ITT,A_ITT),
  325. (A_NONE,A_NONE, A_NONE,A_NONE,A_NONE,A_NONE, A_ITTT,A_ITEE,A_ITET,A_ITTE,A_ITTE,A_ITET,A_ITEE,A_ITTT));
  326. newOps : array[1..3] of array[A_ITE..A_ITTTT] of TAsmOp = (
  327. (A_IT,A_IT, A_ITE,A_ITT,A_ITE,A_ITT, A_ITEE,A_ITTE,A_ITET,A_ITTT,A_ITEE,A_ITTE,A_ITET,A_ITTT),
  328. (A_NONE,A_NONE, A_IT,A_IT,A_IT,A_IT, A_ITE,A_ITT,A_ITE,A_ITT,A_ITE,A_ITT,A_ITE,A_ITT),
  329. (A_NONE,A_NONE, A_NONE,A_NONE,A_NONE,A_NONE, A_IT,A_IT,A_IT,A_IT,A_IT,A_IT,A_IT,A_IT));
  330. needsSwap: array[1..3] of array[A_ITE..A_ITTTT] of Boolean = (
  331. (true ,false, true ,true ,false,false, true ,true ,true ,true ,false,false,false,false),
  332. (false,false, true ,false,true ,false, true ,true ,false,false,true ,true ,false,false),
  333. (false,false, false,false,false,false, true ,false,true ,false,true ,false,true ,false));
  334. begin
  335. result:=remOps[remLevels][originalOp];
  336. newOp:=newOps[remLevels][originalOp];
  337. NeedsCondSwap:=needsSwap[remLevels][originalOp];
  338. end;
  339. procedure trgcputhumb2.SplitITBlock(list: TAsmList; pos: tai);
  340. var
  341. hp : tai;
  342. level,itLevel : LongInt;
  343. remOp,newOp : TAsmOp;
  344. needsSwap : boolean;
  345. begin
  346. hp:=pos;
  347. level := 0;
  348. while assigned(hp) do
  349. begin
  350. if IsIT(taicpu(hp).opcode) then
  351. break
  352. else if hp.typ=ait_instruction then
  353. inc(level);
  354. hp:=tai(hp.Previous);
  355. end;
  356. if not assigned(hp) then
  357. internalerror(2012100801); // We are supposed to have found the ITxxx instruction here
  358. if (hp.typ<>ait_instruction) or
  359. (not IsIT(taicpu(hp).opcode)) then
  360. internalerror(2012100802); // Sanity check
  361. itLevel := GetITLevels(taicpu(hp).opcode);
  362. if level=itLevel then
  363. exit; // pos was the last instruction in the IT block anyway
  364. remOp:=GetITRemainderOp(taicpu(hp).opcode,itLevel-level,newOp,needsSwap);
  365. if (remOp=A_NONE) or
  366. (newOp=A_NONE) then
  367. Internalerror(2012100803);
  368. taicpu(hp).opcode:=newOp;
  369. if needsSwap then
  370. list.InsertAfter(taicpu.op_cond(remOp,inverse_cond(taicpu(hp).oper[0]^.cc)), pos)
  371. else
  372. list.InsertAfter(taicpu.op_cond(remOp,taicpu(hp).oper[0]^.cc), pos);
  373. end;
  374. procedure trgcputhumb2.do_spill_read(list:TAsmList;pos:tai;const spilltemp:treference;tempreg:tregister;orgsupreg:tsuperregister);
  375. var
  376. tmpref : treference;
  377. helplist : TAsmList;
  378. l : tasmlabel;
  379. hreg : tregister;
  380. begin
  381. { don't load spilled register between
  382. mov lr,pc
  383. mov pc,r4
  384. but before the mov lr,pc
  385. }
  386. if assigned(pos.previous) and
  387. (pos.typ=ait_instruction) and
  388. (taicpu(pos).opcode=A_MOV) and
  389. (taicpu(pos).oper[0]^.typ=top_reg) and
  390. (taicpu(pos).oper[0]^.reg=NR_R14) and
  391. (taicpu(pos).oper[1]^.typ=top_reg) and
  392. (taicpu(pos).oper[1]^.reg=NR_PC) then
  393. pos:=tai(pos.previous);
  394. if (pos.typ=ait_instruction) and
  395. (taicpu(pos).condition<>C_None) and
  396. (taicpu(pos).opcode<>A_B) then
  397. SplitITBlock(list, pos)
  398. else if (pos.typ=ait_instruction) and
  399. IsIT(taicpu(pos).opcode) then
  400. begin
  401. if not assigned(pos.Previous) then
  402. list.InsertBefore(tai_comment.Create('Dummy'), pos);
  403. pos:=tai(pos.Previous);
  404. end;
  405. if (spilltemp.offset>4095) or (spilltemp.offset<-255) then
  406. begin
  407. helplist:=TAsmList.create;
  408. reference_reset(tmpref,sizeof(aint));
  409. { create consts entry }
  410. current_asmdata.getjumplabel(l);
  411. cg.a_label(current_procinfo.aktlocaldata,l);
  412. tmpref.symboldata:=current_procinfo.aktlocaldata.last;
  413. current_procinfo.aktlocaldata.concat(tai_const.Create_32bit(spilltemp.offset));
  414. { load consts entry }
  415. if getregtype(tempreg)=R_INTREGISTER then
  416. hreg:=getregisterinline(helplist,[R_SUBWHOLE])
  417. else
  418. hreg:=cg.getintregister(helplist,OS_ADDR);
  419. tmpref.symbol:=l;
  420. tmpref.base:=NR_R15;
  421. helplist.concat(taicpu.op_reg_ref(A_LDR,hreg,tmpref));
  422. reference_reset_base(tmpref,current_procinfo.framepointer,0,sizeof(aint));
  423. tmpref.index:=hreg;
  424. if spilltemp.index<>NR_NO then
  425. internalerror(200401263);
  426. helplist.concat(spilling_create_load(tmpref,tempreg));
  427. if getregtype(tempreg)=R_INTREGISTER then
  428. ungetregisterinline(helplist,hreg);
  429. list.insertlistafter(pos,helplist);
  430. helplist.free;
  431. end
  432. else
  433. inherited;
  434. end;
  435. procedure trgcputhumb2.do_spill_written(list:TAsmList;pos:tai;const spilltemp:treference;tempreg:tregister;orgsupreg:tsuperregister);
  436. var
  437. tmpref : treference;
  438. helplist : TAsmList;
  439. l : tasmlabel;
  440. hreg : tregister;
  441. begin
  442. if (pos.typ=ait_instruction) and
  443. (taicpu(pos).condition<>C_None) and
  444. (taicpu(pos).opcode<>A_B) then
  445. SplitITBlock(list, pos)
  446. else if (pos.typ=ait_instruction) and
  447. IsIT(taicpu(pos).opcode) then
  448. begin
  449. if not assigned(pos.Previous) then
  450. list.InsertBefore(tai_comment.Create('Dummy'), pos);
  451. pos:=tai(pos.Previous);
  452. end;
  453. if (spilltemp.offset>4095) or (spilltemp.offset<-255) then
  454. begin
  455. helplist:=TAsmList.create;
  456. reference_reset(tmpref,sizeof(aint));
  457. { create consts entry }
  458. current_asmdata.getjumplabel(l);
  459. cg.a_label(current_procinfo.aktlocaldata,l);
  460. tmpref.symboldata:=current_procinfo.aktlocaldata.last;
  461. current_procinfo.aktlocaldata.concat(tai_const.Create_32bit(spilltemp.offset));
  462. { load consts entry }
  463. if getregtype(tempreg)=R_INTREGISTER then
  464. hreg:=getregisterinline(helplist,[R_SUBWHOLE])
  465. else
  466. hreg:=cg.getintregister(helplist,OS_ADDR);
  467. tmpref.symbol:=l;
  468. tmpref.base:=NR_R15;
  469. helplist.concat(taicpu.op_reg_ref(A_LDR,hreg,tmpref));
  470. if spilltemp.index<>NR_NO then
  471. internalerror(200401263);
  472. reference_reset_base(tmpref,current_procinfo.framepointer,0,sizeof(pint));
  473. tmpref.index:=hreg;
  474. helplist.concat(spilling_create_store(tempreg,tmpref));
  475. if getregtype(tempreg)=R_INTREGISTER then
  476. ungetregisterinline(helplist,hreg);
  477. list.insertlistafter(pos,helplist);
  478. helplist.free;
  479. end
  480. else
  481. inherited;
  482. end;
  483. procedure trgintcpu.add_cpu_interferences(p : tai);
  484. var
  485. r : tregister;
  486. begin
  487. if p.typ=ait_instruction then
  488. begin
  489. case taicpu(p).opcode of
  490. A_MLA,
  491. A_MUL:
  492. begin
  493. if current_settings.cputype<cpu_armv6 then
  494. add_edge(getsupreg(taicpu(p).oper[0]^.reg),getsupreg(taicpu(p).oper[1]^.reg));
  495. add_edge(getsupreg(taicpu(p).oper[0]^.reg),RS_R15);
  496. add_edge(getsupreg(taicpu(p).oper[1]^.reg),RS_R15);
  497. add_edge(getsupreg(taicpu(p).oper[2]^.reg),RS_R15);
  498. if taicpu(p).opcode=A_MLA then
  499. add_edge(getsupreg(taicpu(p).oper[3]^.reg),RS_R15);
  500. end;
  501. A_UMULL,
  502. A_UMLAL,
  503. A_SMULL,
  504. A_SMLAL:
  505. begin
  506. add_edge(getsupreg(taicpu(p).oper[0]^.reg),getsupreg(taicpu(p).oper[1]^.reg));
  507. if current_settings.cputype<cpu_armv6 then
  508. begin
  509. add_edge(getsupreg(taicpu(p).oper[1]^.reg),getsupreg(taicpu(p).oper[2]^.reg));
  510. add_edge(getsupreg(taicpu(p).oper[0]^.reg),getsupreg(taicpu(p).oper[2]^.reg));
  511. end;
  512. end;
  513. A_LDRB,
  514. A_STRB,
  515. A_STR,
  516. A_LDR,
  517. A_LDRH,
  518. A_STRH:
  519. { don't mix up the framepointer and stackpointer with pre/post indexed operations }
  520. if (taicpu(p).oper[1]^.typ=top_ref) and
  521. (taicpu(p).oper[1]^.ref^.addressmode in [AM_PREINDEXED,AM_POSTINDEXED]) then
  522. begin
  523. add_edge(getsupreg(taicpu(p).oper[1]^.ref^.base),getsupreg(current_procinfo.framepointer));
  524. { FIXME: temp variable r is needed here to avoid Internal error 20060521 }
  525. { while compiling the compiler. }
  526. r:=NR_STACK_POINTER_REG;
  527. if current_procinfo.framepointer<>r then
  528. add_edge(getsupreg(taicpu(p).oper[1]^.ref^.base),getsupreg(r));
  529. end;
  530. end;
  531. end;
  532. end;
  533. procedure trgintcputhumb.add_cpu_interferences(p: tai);
  534. var
  535. r : tregister;
  536. i : longint;
  537. begin
  538. if p.typ=ait_instruction then
  539. begin
  540. { prevent that the register allocator merges registers with frame/stack pointer
  541. if an instruction writes to the register }
  542. if (taicpu(p).ops>=1) and (taicpu(p).oper[0]^.typ=top_reg) and
  543. (taicpu(p).spilling_get_operation_type(0) in [operand_write,operand_readwrite]) then
  544. begin
  545. { FIXME: temp variable r is needed here to avoid Internal error 20060521 }
  546. { while compiling the compiler. }
  547. r:=NR_STACK_POINTER_REG;
  548. add_edge(getsupreg(taicpu(p).oper[0]^.reg),getsupreg(r));
  549. add_edge(getsupreg(taicpu(p).oper[0]^.reg),getsupreg(current_procinfo.framepointer));
  550. end;
  551. if (taicpu(p).ops>=2) and (taicpu(p).oper[1]^.typ=top_reg) and
  552. (taicpu(p).spilling_get_operation_type(1) in [operand_write,operand_readwrite]) then
  553. begin
  554. { FIXME: temp variable r is needed here to avoid Internal error 20060521 }
  555. { while compiling the compiler. }
  556. r:=NR_STACK_POINTER_REG;
  557. add_edge(getsupreg(taicpu(p).oper[1]^.reg),getsupreg(r));
  558. add_edge(getsupreg(taicpu(p).oper[1]^.reg),getsupreg(current_procinfo.framepointer));
  559. end;
  560. case taicpu(p).opcode of
  561. A_LDRB,
  562. A_STRB,
  563. A_STR,
  564. A_LDR,
  565. A_LDRH,
  566. A_STRH,
  567. A_LDRSB,
  568. A_LDRSH,
  569. A_LDRD,
  570. A_STRD:
  571. begin
  572. { add_edge handles precoloured registers already }
  573. for i:=RS_R8 to RS_R15 do
  574. begin
  575. add_edge(getsupreg(taicpu(p).oper[1]^.ref^.base),i);
  576. add_edge(getsupreg(taicpu(p).oper[1]^.ref^.index),i);
  577. add_edge(getsupreg(taicpu(p).oper[0]^.reg),i);
  578. end;
  579. end;
  580. end;
  581. end;
  582. end;
  583. end.