rgcpu.pas 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  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,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);override;
  35. procedure do_spill_written(list:TAsmList;pos:tai;const spilltemp:treference;tempreg:tregister);override;
  36. function do_spill_replace(list : TAsmList;instr : taicpu;
  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);override;
  46. procedure do_spill_written(list:TAsmList;pos:tai;const spilltemp:treference;tempreg:tregister);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. l : tasmlabel;
  156. hreg : tregister;
  157. immshift: byte;
  158. a: aint;
  159. begin
  160. helplist:=TAsmList.create;
  161. { load consts entry }
  162. if getregtype(tempreg)=R_INTREGISTER then
  163. hreg:=getregisterinline(helplist,[R_SUBWHOLE])
  164. else
  165. hreg:=cg.getintregister(helplist,OS_ADDR);
  166. { Lets remove the bits we can fold in later and check if the result can be easily with an add or sub }
  167. a:=abs(spilltemp.offset);
  168. if GenerateThumbCode then
  169. begin
  170. {$ifdef DEBUG_SPILLING}
  171. helplist.concat(tai_comment.create(strpnew('Spilling: Use a_load_const_reg to fix spill offset')));
  172. {$endif}
  173. cg.a_load_const_reg(helplist,OS_ADDR,spilltemp.offset,hreg);
  174. cg.a_op_reg_reg(helplist,OP_ADD,OS_ADDR,current_procinfo.framepointer,hreg);
  175. reference_reset_base(tmpref,hreg,0,sizeof(aint));
  176. end
  177. else if is_shifter_const(a and not($FFF), immshift) then
  178. if spilltemp.offset > 0 then
  179. begin
  180. {$ifdef DEBUG_SPILLING}
  181. helplist.concat(tai_comment.create(strpnew('Spilling: Use ADD to fix spill offset')));
  182. {$endif}
  183. helplist.concat(taicpu.op_reg_reg_const(A_ADD, hreg, current_procinfo.framepointer,
  184. a and not($FFF)));
  185. reference_reset_base(tmpref, hreg, a and $FFF, sizeof(aint));
  186. end
  187. else
  188. begin
  189. {$ifdef DEBUG_SPILLING}
  190. helplist.concat(tai_comment.create(strpnew('Spilling: Use SUB to fix spill offset')));
  191. {$endif}
  192. helplist.concat(taicpu.op_reg_reg_const(A_SUB, hreg, current_procinfo.framepointer,
  193. a and not($FFF)));
  194. reference_reset_base(tmpref, hreg, -(a and $FFF), sizeof(aint));
  195. end
  196. else
  197. begin
  198. {$ifdef DEBUG_SPILLING}
  199. helplist.concat(tai_comment.create(strpnew('Spilling: Use a_load_const_reg to fix spill offset')));
  200. {$endif}
  201. cg.a_load_const_reg(helplist,OS_ADDR,spilltemp.offset,hreg);
  202. reference_reset_base(tmpref,current_procinfo.framepointer,0,sizeof(aint));
  203. tmpref.index:=hreg;
  204. end;
  205. if spilltemp.index<>NR_NO then
  206. internalerror(200401263);
  207. if is_store then
  208. helplist.concat(spilling_create_store(tempreg,tmpref))
  209. else
  210. helplist.concat(spilling_create_load(tmpref,tempreg));
  211. if getregtype(tempreg)=R_INTREGISTER then
  212. ungetregisterinline(helplist,hreg);
  213. list.insertlistafter(pos,helplist);
  214. helplist.free;
  215. end;
  216. function fix_spilling_offset(offset : ASizeInt) : boolean;
  217. begin
  218. result:=(abs(offset)>4095) or
  219. ((GenerateThumbCode) and ((offset<0) or (offset>1020)));
  220. end;
  221. procedure trgcpu.do_spill_read(list:TAsmList;pos:tai;const spilltemp:treference;tempreg:tregister);
  222. begin
  223. { don't load spilled register between
  224. mov lr,pc
  225. mov pc,r4
  226. but befure the mov lr,pc
  227. }
  228. if assigned(pos.previous) and
  229. (pos.typ=ait_instruction) and
  230. (taicpu(pos).opcode=A_MOV) and
  231. (taicpu(pos).oper[0]^.typ=top_reg) and
  232. (taicpu(pos).oper[0]^.reg=NR_R14) and
  233. (taicpu(pos).oper[1]^.typ=top_reg) and
  234. (taicpu(pos).oper[1]^.reg=NR_PC) then
  235. pos:=tai(pos.previous);
  236. if fix_spilling_offset(spilltemp.offset) then
  237. spilling_create_load_store(list, pos, spilltemp, tempreg, false)
  238. else
  239. inherited do_spill_read(list,pos,spilltemp,tempreg);
  240. end;
  241. procedure trgcpu.do_spill_written(list:TAsmList;pos:tai;const spilltemp:treference;tempreg:tregister);
  242. begin
  243. if fix_spilling_offset(spilltemp.offset) then
  244. spilling_create_load_store(list, pos, spilltemp, tempreg, true)
  245. else
  246. inherited do_spill_written(list,pos,spilltemp,tempreg);
  247. end;
  248. function trgcpu.do_spill_replace(list:TAsmList;instr:taicpu;orgreg:tsuperregister;const spilltemp:treference):boolean;
  249. var
  250. b : byte;
  251. begin
  252. result:=false;
  253. if abs(spilltemp.offset)>4095 then
  254. exit;
  255. { ldr can't set the flags }
  256. if instr.oppostfix=PF_S then
  257. exit;
  258. if GenerateThumbCode and
  259. (abs(spilltemp.offset)>1020) then
  260. exit;
  261. { Replace 'mov dst,orgreg' with 'ldr dst,spilltemp'
  262. and 'mov orgreg,src' with 'str dst,spilltemp' }
  263. with instr do
  264. begin
  265. if (opcode=A_MOV) and (ops=2) and (oper[1]^.typ=top_reg) and (oper[0]^.typ=top_reg) then
  266. begin
  267. if (getregtype(oper[0]^.reg)=regtype) and
  268. (get_alias(getsupreg(oper[0]^.reg))=orgreg) and
  269. (get_alias(getsupreg(oper[1]^.reg))<>orgreg) then
  270. begin
  271. { str expects the register in oper[0] }
  272. instr.loadreg(0,oper[1]^.reg);
  273. instr.loadref(1,spilltemp);
  274. opcode:=A_STR;
  275. result:=true;
  276. end
  277. else if (getregtype(oper[1]^.reg)=regtype) and
  278. (get_alias(getsupreg(oper[1]^.reg))=orgreg) and
  279. (get_alias(getsupreg(oper[0]^.reg))<>orgreg) then
  280. begin
  281. instr.loadref(1,spilltemp);
  282. opcode:=A_LDR;
  283. result:=true;
  284. end;
  285. end;
  286. end;
  287. end;
  288. procedure trgcpu.add_constraints(reg:tregister);
  289. var
  290. supreg,i : Tsuperregister;
  291. begin
  292. case getsubreg(reg) of
  293. { Let 32bit floats conflict with all double precision regs > 15
  294. (since these don't have 32 bit equivalents) }
  295. R_SUBFS:
  296. begin
  297. supreg:=getsupreg(reg);
  298. for i:=RS_D16 to RS_D31 do
  299. add_edge(supreg,i);
  300. end;
  301. end;
  302. end;
  303. function trgcpu.get_spill_subreg(r:tregister) : tsubregister;
  304. begin
  305. if (getregtype(r)<>R_MMREGISTER) then
  306. result:=defaultsub
  307. else
  308. result:=getsubreg(r);
  309. end;
  310. function GetITRemainderOp(originalOp:TAsmOp;remLevels:longint;var newOp: TAsmOp;var NeedsCondSwap:boolean) : TAsmOp;
  311. const
  312. remOps : array[1..3] of array[A_ITE..A_ITTTT] of TAsmOp = (
  313. (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),
  314. (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),
  315. (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));
  316. newOps : array[1..3] of array[A_ITE..A_ITTTT] of TAsmOp = (
  317. (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),
  318. (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),
  319. (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));
  320. needsSwap: array[1..3] of array[A_ITE..A_ITTTT] of Boolean = (
  321. (true ,false, true ,true ,false,false, true ,true ,true ,true ,false,false,false,false),
  322. (false,false, true ,false,true ,false, true ,true ,false,false,true ,true ,false,false),
  323. (false,false, false,false,false,false, true ,false,true ,false,true ,false,true ,false));
  324. begin
  325. result:=remOps[remLevels][originalOp];
  326. newOp:=newOps[remLevels][originalOp];
  327. NeedsCondSwap:=needsSwap[remLevels][originalOp];
  328. end;
  329. procedure trgcputhumb2.SplitITBlock(list: TAsmList; pos: tai);
  330. var
  331. hp : tai;
  332. level,itLevel : LongInt;
  333. remOp,newOp : TAsmOp;
  334. needsSwap : boolean;
  335. begin
  336. hp:=pos;
  337. level := 0;
  338. while assigned(hp) do
  339. begin
  340. if IsIT(taicpu(hp).opcode) then
  341. break
  342. else if hp.typ=ait_instruction then
  343. inc(level);
  344. hp:=tai(hp.Previous);
  345. end;
  346. if not assigned(hp) then
  347. internalerror(2012100801); // We are supposed to have found the ITxxx instruction here
  348. if (hp.typ<>ait_instruction) or
  349. (not IsIT(taicpu(hp).opcode)) then
  350. internalerror(2012100802); // Sanity check
  351. itLevel := GetITLevels(taicpu(hp).opcode);
  352. if level=itLevel then
  353. exit; // pos was the last instruction in the IT block anyway
  354. remOp:=GetITRemainderOp(taicpu(hp).opcode,itLevel-level,newOp,needsSwap);
  355. if (remOp=A_NONE) or
  356. (newOp=A_NONE) then
  357. Internalerror(2012100803);
  358. taicpu(hp).opcode:=newOp;
  359. if needsSwap then
  360. list.InsertAfter(taicpu.op_cond(remOp,inverse_cond(taicpu(hp).oper[0]^.cc)), pos)
  361. else
  362. list.InsertAfter(taicpu.op_cond(remOp,taicpu(hp).oper[0]^.cc), pos);
  363. end;
  364. procedure trgcputhumb2.do_spill_read(list:TAsmList;pos:tai;const spilltemp:treference;tempreg:tregister);
  365. var
  366. tmpref : treference;
  367. helplist : TAsmList;
  368. l : tasmlabel;
  369. hreg : tregister;
  370. begin
  371. { don't load spilled register between
  372. mov lr,pc
  373. mov pc,r4
  374. but before the mov lr,pc
  375. }
  376. if assigned(pos.previous) and
  377. (pos.typ=ait_instruction) and
  378. (taicpu(pos).opcode=A_MOV) and
  379. (taicpu(pos).oper[0]^.typ=top_reg) and
  380. (taicpu(pos).oper[0]^.reg=NR_R14) and
  381. (taicpu(pos).oper[1]^.typ=top_reg) and
  382. (taicpu(pos).oper[1]^.reg=NR_PC) then
  383. pos:=tai(pos.previous);
  384. if (pos.typ=ait_instruction) and
  385. (taicpu(pos).condition<>C_None) and
  386. (taicpu(pos).opcode<>A_B) then
  387. SplitITBlock(list, pos)
  388. else if (pos.typ=ait_instruction) and
  389. IsIT(taicpu(pos).opcode) then
  390. begin
  391. if not assigned(pos.Previous) then
  392. list.InsertBefore(tai_comment.Create('Dummy'), pos);
  393. pos:=tai(pos.Previous);
  394. end;
  395. if (spilltemp.offset>4095) or (spilltemp.offset<-255) then
  396. begin
  397. helplist:=TAsmList.create;
  398. reference_reset(tmpref,sizeof(aint));
  399. { create consts entry }
  400. current_asmdata.getjumplabel(l);
  401. cg.a_label(current_procinfo.aktlocaldata,l);
  402. tmpref.symboldata:=current_procinfo.aktlocaldata.last;
  403. current_procinfo.aktlocaldata.concat(tai_const.Create_32bit(spilltemp.offset));
  404. { load consts entry }
  405. if getregtype(tempreg)=R_INTREGISTER then
  406. hreg:=getregisterinline(helplist,[R_SUBWHOLE])
  407. else
  408. hreg:=cg.getintregister(helplist,OS_ADDR);
  409. tmpref.symbol:=l;
  410. tmpref.base:=NR_R15;
  411. helplist.concat(taicpu.op_reg_ref(A_LDR,hreg,tmpref));
  412. reference_reset_base(tmpref,current_procinfo.framepointer,0,sizeof(aint));
  413. tmpref.index:=hreg;
  414. if spilltemp.index<>NR_NO then
  415. internalerror(200401263);
  416. helplist.concat(spilling_create_load(tmpref,tempreg));
  417. if getregtype(tempreg)=R_INTREGISTER then
  418. ungetregisterinline(helplist,hreg);
  419. list.insertlistafter(pos,helplist);
  420. helplist.free;
  421. end
  422. else
  423. inherited do_spill_read(list,pos,spilltemp,tempreg);
  424. end;
  425. procedure trgcputhumb2.do_spill_written(list:TAsmList;pos:tai;const spilltemp:treference;tempreg:tregister);
  426. var
  427. tmpref : treference;
  428. helplist : TAsmList;
  429. l : tasmlabel;
  430. hreg : tregister;
  431. begin
  432. if (pos.typ=ait_instruction) and
  433. (taicpu(pos).condition<>C_None) and
  434. (taicpu(pos).opcode<>A_B) then
  435. SplitITBlock(list, pos)
  436. else if (pos.typ=ait_instruction) and
  437. IsIT(taicpu(pos).opcode) then
  438. begin
  439. if not assigned(pos.Previous) then
  440. list.InsertBefore(tai_comment.Create('Dummy'), pos);
  441. pos:=tai(pos.Previous);
  442. end;
  443. if (spilltemp.offset>4095) or (spilltemp.offset<-255) then
  444. begin
  445. helplist:=TAsmList.create;
  446. reference_reset(tmpref,sizeof(aint));
  447. { create consts entry }
  448. current_asmdata.getjumplabel(l);
  449. cg.a_label(current_procinfo.aktlocaldata,l);
  450. tmpref.symboldata:=current_procinfo.aktlocaldata.last;
  451. current_procinfo.aktlocaldata.concat(tai_const.Create_32bit(spilltemp.offset));
  452. { load consts entry }
  453. if getregtype(tempreg)=R_INTREGISTER then
  454. hreg:=getregisterinline(helplist,[R_SUBWHOLE])
  455. else
  456. hreg:=cg.getintregister(helplist,OS_ADDR);
  457. tmpref.symbol:=l;
  458. tmpref.base:=NR_R15;
  459. helplist.concat(taicpu.op_reg_ref(A_LDR,hreg,tmpref));
  460. if spilltemp.index<>NR_NO then
  461. internalerror(200401263);
  462. reference_reset_base(tmpref,current_procinfo.framepointer,0,sizeof(pint));
  463. tmpref.index:=hreg;
  464. helplist.concat(spilling_create_store(tempreg,tmpref));
  465. if getregtype(tempreg)=R_INTREGISTER then
  466. ungetregisterinline(helplist,hreg);
  467. list.insertlistafter(pos,helplist);
  468. helplist.free;
  469. end
  470. else
  471. inherited do_spill_written(list,pos,spilltemp,tempreg);
  472. end;
  473. procedure trgintcpu.add_cpu_interferences(p : tai);
  474. var
  475. r : tregister;
  476. begin
  477. if p.typ=ait_instruction then
  478. begin
  479. case taicpu(p).opcode of
  480. A_MLA,
  481. A_MUL:
  482. begin
  483. if current_settings.cputype<cpu_armv6 then
  484. add_edge(getsupreg(taicpu(p).oper[0]^.reg),getsupreg(taicpu(p).oper[1]^.reg));
  485. add_edge(getsupreg(taicpu(p).oper[0]^.reg),RS_R15);
  486. add_edge(getsupreg(taicpu(p).oper[1]^.reg),RS_R15);
  487. add_edge(getsupreg(taicpu(p).oper[2]^.reg),RS_R15);
  488. if taicpu(p).opcode=A_MLA then
  489. add_edge(getsupreg(taicpu(p).oper[3]^.reg),RS_R15);
  490. end;
  491. A_UMULL,
  492. A_UMLAL,
  493. A_SMULL,
  494. A_SMLAL:
  495. begin
  496. if current_settings.cputype<cpu_armv6 then
  497. begin
  498. add_edge(getsupreg(taicpu(p).oper[0]^.reg),getsupreg(taicpu(p).oper[1]^.reg));
  499. add_edge(getsupreg(taicpu(p).oper[1]^.reg),getsupreg(taicpu(p).oper[2]^.reg));
  500. add_edge(getsupreg(taicpu(p).oper[0]^.reg),getsupreg(taicpu(p).oper[2]^.reg));
  501. end;
  502. end;
  503. A_LDRB,
  504. A_STRB,
  505. A_STR,
  506. A_LDR,
  507. A_LDRH,
  508. A_STRH:
  509. { don't mix up the framepointer and stackpointer with pre/post indexed operations }
  510. if (taicpu(p).oper[1]^.typ=top_ref) and
  511. (taicpu(p).oper[1]^.ref^.addressmode in [AM_PREINDEXED,AM_POSTINDEXED]) then
  512. begin
  513. add_edge(getsupreg(taicpu(p).oper[1]^.ref^.base),getsupreg(current_procinfo.framepointer));
  514. { FIXME: temp variable r is needed here to avoid Internal error 20060521 }
  515. { while compiling the compiler. }
  516. r:=NR_STACK_POINTER_REG;
  517. if current_procinfo.framepointer<>r then
  518. add_edge(getsupreg(taicpu(p).oper[1]^.ref^.base),getsupreg(r));
  519. end;
  520. end;
  521. end;
  522. end;
  523. procedure trgintcputhumb.add_cpu_interferences(p: tai);
  524. var
  525. r : tregister;
  526. i,
  527. hr : longint;
  528. begin
  529. if p.typ=ait_instruction then
  530. begin
  531. { prevent that the register allocator merges registers with frame/stack pointer
  532. if an instruction writes to the register }
  533. if (taicpu(p).ops>=1) and (taicpu(p).oper[0]^.typ=top_reg) and
  534. (taicpu(p).spilling_get_operation_type(0) in [operand_write,operand_readwrite]) then
  535. begin
  536. { FIXME: temp variable r is needed here to avoid Internal error 20060521 }
  537. { while compiling the compiler. }
  538. r:=NR_STACK_POINTER_REG;
  539. add_edge(getsupreg(taicpu(p).oper[0]^.reg),getsupreg(r));
  540. add_edge(getsupreg(taicpu(p).oper[0]^.reg),getsupreg(current_procinfo.framepointer));
  541. end;
  542. if (taicpu(p).ops>=2) and (taicpu(p).oper[1]^.typ=top_reg) and
  543. (taicpu(p).spilling_get_operation_type(1) 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[1]^.reg),getsupreg(r));
  549. add_edge(getsupreg(taicpu(p).oper[1]^.reg),getsupreg(current_procinfo.framepointer));
  550. end;
  551. case taicpu(p).opcode of
  552. A_LDRB,
  553. A_STRB,
  554. A_STR,
  555. A_LDR,
  556. A_LDRH,
  557. A_STRH,
  558. A_LDRSB,
  559. A_LDRSH,
  560. A_LDRD,
  561. A_STRD:
  562. begin
  563. { add_edge handles precoloured registers already }
  564. for i:=RS_R8 to RS_R15 do
  565. begin
  566. add_edge(getsupreg(taicpu(p).oper[1]^.ref^.base),i);
  567. add_edge(getsupreg(taicpu(p).oper[1]^.ref^.index),i);
  568. add_edge(getsupreg(taicpu(p).oper[0]^.reg),i);
  569. end;
  570. end;
  571. end;
  572. end;
  573. end;
  574. end.