rgcpu.pas 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  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; orgsupreg: tsuperregister); override;
  35. procedure do_spill_written(list: TAsmList; pos: tai; const spilltemp: treference; tempreg: tregister; orgsupreg: tsuperregister); override;
  36. procedure add_constraints(reg:tregister);override;
  37. function get_spill_subreg(r:tregister) : tsubregister;override;
  38. end;
  39. trgcputhumb2 = class(trgobj)
  40. private
  41. procedure SplitITBlock(list:TAsmList;pos:tai);
  42. public
  43. procedure do_spill_read(list: TAsmList; pos: tai; const spilltemp: treference; tempreg: tregister; orgsupreg: tsuperregister); override;
  44. procedure do_spill_written(list: TAsmList; pos: tai; const spilltemp: treference; tempreg: tregister; orgsupreg: tsuperregister); override;
  45. end;
  46. trgintcputhumb2 = class(trgcputhumb2)
  47. procedure add_cpu_interferences(p : tai);override;
  48. end;
  49. trgintcpu = class(trgcpu)
  50. procedure add_cpu_interferences(p : tai);override;
  51. end;
  52. trgcputhumb = class(trgcpu)
  53. end;
  54. trgintcputhumb = class(trgcputhumb)
  55. procedure add_cpu_interferences(p: tai);override;
  56. end;
  57. implementation
  58. uses
  59. verbose,globtype,globals,cpuinfo,
  60. cgobj,
  61. procinfo;
  62. procedure trgintcputhumb2.add_cpu_interferences(p: tai);
  63. var
  64. r : tregister;
  65. hr : longint;
  66. begin
  67. if p.typ=ait_instruction then
  68. begin
  69. case taicpu(p).opcode of
  70. A_CBNZ,
  71. A_CBZ:
  72. begin
  73. for hr := RS_R8 to RS_R15 do
  74. add_edge(getsupreg(taicpu(p).oper[0]^.reg), hr);
  75. end;
  76. A_ADD,
  77. A_SUB,
  78. A_AND,
  79. A_BIC,
  80. A_EOR:
  81. begin
  82. if taicpu(p).ops = 3 then
  83. begin
  84. if (taicpu(p).oper[0]^.typ = top_reg) and
  85. (taicpu(p).oper[1]^.typ = top_reg) and
  86. (taicpu(p).oper[2]^.typ in [top_reg, top_shifterop]) then
  87. begin
  88. { if d == 13 || (d == 15 && S == ‘0’) || n == 15 || m IN [13,15] then UNPREDICTABLE; }
  89. add_edge(getsupreg(taicpu(p).oper[0]^.reg), RS_R13);
  90. if taicpu(p).oppostfix <> PF_S then
  91. add_edge(getsupreg(taicpu(p).oper[0]^.reg), RS_R15);
  92. add_edge(getsupreg(taicpu(p).oper[1]^.reg), RS_R15);
  93. if (taicpu(p).oper[2]^.typ = top_shifterop) and
  94. (taicpu(p).oper[2]^.shifterop^.rs <> NR_NO) then
  95. begin
  96. add_edge(getsupreg(taicpu(p).oper[2]^.shifterop^.rs), RS_R13);
  97. add_edge(getsupreg(taicpu(p).oper[2]^.shifterop^.rs), RS_R15);
  98. end
  99. else if (taicpu(p).oper[2]^.typ = top_reg) then
  100. begin
  101. add_edge(getsupreg(taicpu(p).oper[2]^.reg), RS_R13);
  102. add_edge(getsupreg(taicpu(p).oper[2]^.reg), RS_R15);
  103. end;
  104. end;
  105. end;
  106. end;
  107. A_MLA,
  108. A_MUL:
  109. begin
  110. if current_settings.cputype<cpu_armv6 then
  111. add_edge(getsupreg(taicpu(p).oper[0]^.reg),getsupreg(taicpu(p).oper[1]^.reg));
  112. add_edge(getsupreg(taicpu(p).oper[0]^.reg),RS_R13);
  113. add_edge(getsupreg(taicpu(p).oper[0]^.reg),RS_R15);
  114. add_edge(getsupreg(taicpu(p).oper[1]^.reg),RS_R13);
  115. add_edge(getsupreg(taicpu(p).oper[1]^.reg),RS_R15);
  116. add_edge(getsupreg(taicpu(p).oper[2]^.reg),RS_R13);
  117. add_edge(getsupreg(taicpu(p).oper[2]^.reg),RS_R15);
  118. if taicpu(p).opcode=A_MLA then
  119. begin
  120. add_edge(getsupreg(taicpu(p).oper[3]^.reg),RS_R13);
  121. add_edge(getsupreg(taicpu(p).oper[3]^.reg),RS_R15);
  122. end;
  123. end;
  124. A_LDRB,
  125. A_STRB,
  126. A_STR,
  127. A_LDR,
  128. A_LDRH,
  129. A_STRH,
  130. A_LDRSB,
  131. A_LDRSH,
  132. A_LDRD,
  133. A_STRD:
  134. { don't mix up the framepointer and stackpointer with pre/post indexed operations }
  135. if (taicpu(p).oper[1]^.typ=top_ref) and
  136. (taicpu(p).oper[1]^.ref^.addressmode in [AM_PREINDEXED,AM_POSTINDEXED]) then
  137. begin
  138. add_edge(getsupreg(taicpu(p).oper[1]^.ref^.base),getsupreg(current_procinfo.framepointer));
  139. { FIXME: temp variable r is needed here to avoid Internal error 20060521 }
  140. { while compiling the compiler. }
  141. r:=NR_STACK_POINTER_REG;
  142. if current_procinfo.framepointer<>r then
  143. add_edge(getsupreg(taicpu(p).oper[1]^.ref^.base),getsupreg(r));
  144. end;
  145. end;
  146. end;
  147. end;
  148. procedure trgcpu.spilling_create_load_store(list: TAsmList; pos: tai; const spilltemp:treference;tempreg:tregister; is_store: boolean);
  149. var
  150. tmpref : treference;
  151. helplist : TAsmList;
  152. l : tasmlabel;
  153. hreg : tregister;
  154. immshift: byte;
  155. a: aint;
  156. begin
  157. helplist:=TAsmList.create;
  158. { load consts entry }
  159. if getregtype(tempreg)=R_INTREGISTER then
  160. hreg:=getregisterinline(helplist,[R_SUBWHOLE])
  161. else
  162. hreg:=cg.getintregister(helplist,OS_ADDR);
  163. { Lets remove the bits we can fold in later and check if the result can be easily with an add or sub }
  164. a:=abs(spilltemp.offset);
  165. if GenerateThumbCode then
  166. begin
  167. {$ifdef DEBUG_SPILLING}
  168. helplist.concat(tai_comment.create(strpnew('Spilling: Use a_load_const_reg to fix spill offset')));
  169. {$endif}
  170. cg.a_load_const_reg(helplist,OS_ADDR,spilltemp.offset,hreg);
  171. cg.a_op_reg_reg(helplist,OP_ADD,OS_ADDR,current_procinfo.framepointer,hreg);
  172. reference_reset_base(tmpref,hreg,0,sizeof(aint));
  173. end
  174. else if is_shifter_const(a and not($FFF), immshift) then
  175. if spilltemp.offset > 0 then
  176. begin
  177. {$ifdef DEBUG_SPILLING}
  178. helplist.concat(tai_comment.create(strpnew('Spilling: Use ADD to fix spill offset')));
  179. {$endif}
  180. helplist.concat(taicpu.op_reg_reg_const(A_ADD, hreg, current_procinfo.framepointer,
  181. a and not($FFF)));
  182. reference_reset_base(tmpref, hreg, a and $FFF, sizeof(aint));
  183. end
  184. else
  185. begin
  186. {$ifdef DEBUG_SPILLING}
  187. helplist.concat(tai_comment.create(strpnew('Spilling: Use SUB to fix spill offset')));
  188. {$endif}
  189. helplist.concat(taicpu.op_reg_reg_const(A_SUB, hreg, current_procinfo.framepointer,
  190. a and not($FFF)));
  191. reference_reset_base(tmpref, hreg, -(a and $FFF), sizeof(aint));
  192. end
  193. else
  194. begin
  195. {$ifdef DEBUG_SPILLING}
  196. helplist.concat(tai_comment.create(strpnew('Spilling: Use a_load_const_reg to fix spill offset')));
  197. {$endif}
  198. cg.a_load_const_reg(helplist,OS_ADDR,spilltemp.offset,hreg);
  199. reference_reset_base(tmpref,current_procinfo.framepointer,0,sizeof(aint));
  200. tmpref.index:=hreg;
  201. end;
  202. if spilltemp.index<>NR_NO then
  203. internalerror(200401263);
  204. if is_store then
  205. helplist.concat(spilling_create_store(tempreg,tmpref))
  206. else
  207. helplist.concat(spilling_create_load(tmpref,tempreg));
  208. if getregtype(tempreg)=R_INTREGISTER then
  209. ungetregisterinline(helplist,hreg);
  210. list.insertlistafter(pos,helplist);
  211. helplist.free;
  212. end;
  213. function fix_spilling_offset(offset : ASizeInt) : boolean;
  214. begin
  215. result:=(abs(offset)>4095) or
  216. ((GenerateThumbCode) and ((offset<0) or (offset>1020)));
  217. end;
  218. procedure trgcpu.do_spill_read(list: TAsmList; pos: tai; const spilltemp: treference; tempreg: tregister; orgsupreg: tsuperregister);
  219. begin
  220. { don't load spilled register between
  221. mov lr,pc
  222. mov pc,r4
  223. but befure the mov lr,pc
  224. }
  225. if assigned(pos.previous) and
  226. (pos.typ=ait_instruction) and
  227. (taicpu(pos).opcode=A_MOV) and
  228. (taicpu(pos).oper[0]^.typ=top_reg) and
  229. (taicpu(pos).oper[0]^.reg=NR_R14) and
  230. (taicpu(pos).oper[1]^.typ=top_reg) and
  231. (taicpu(pos).oper[1]^.reg=NR_PC) then
  232. pos:=tai(pos.previous);
  233. if fix_spilling_offset(spilltemp.offset) then
  234. spilling_create_load_store(list, pos, spilltemp, tempreg, false)
  235. else
  236. inherited;
  237. end;
  238. procedure trgcpu.do_spill_written(list: TAsmList; pos: tai; const spilltemp: treference; tempreg: tregister; orgsupreg: tsuperregister);
  239. begin
  240. if fix_spilling_offset(spilltemp.offset) then
  241. spilling_create_load_store(list, pos, spilltemp, tempreg, true)
  242. else
  243. inherited;
  244. end;
  245. procedure trgcpu.add_constraints(reg:tregister);
  246. var
  247. supreg,i : Tsuperregister;
  248. begin
  249. case getsubreg(reg) of
  250. { Let 32bit floats conflict with all double precision regs > 15
  251. (since these don't have 32 bit equivalents) }
  252. R_SUBFS:
  253. begin
  254. supreg:=getsupreg(reg);
  255. for i:=RS_D16 to RS_D31 do
  256. add_edge(supreg,i);
  257. end;
  258. end;
  259. end;
  260. function trgcpu.get_spill_subreg(r:tregister) : tsubregister;
  261. begin
  262. if (getregtype(r)<>R_MMREGISTER) then
  263. result:=defaultsub
  264. else
  265. result:=getsubreg(r);
  266. end;
  267. function GetITRemainderOp(originalOp:TAsmOp;remLevels:longint;var newOp: TAsmOp;var NeedsCondSwap:boolean) : TAsmOp;
  268. const
  269. remOps : array[1..3] of array[A_ITE..A_ITTTT] of TAsmOp = (
  270. (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),
  271. (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),
  272. (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));
  273. newOps : array[1..3] of array[A_ITE..A_ITTTT] of TAsmOp = (
  274. (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),
  275. (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),
  276. (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));
  277. needsSwap: array[1..3] of array[A_ITE..A_ITTTT] of Boolean = (
  278. (true ,false, true ,true ,false,false, true ,true ,true ,true ,false,false,false,false),
  279. (false,false, true ,false,true ,false, true ,true ,false,false,true ,true ,false,false),
  280. (false,false, false,false,false,false, true ,false,true ,false,true ,false,true ,false));
  281. begin
  282. result:=remOps[remLevels][originalOp];
  283. newOp:=newOps[remLevels][originalOp];
  284. NeedsCondSwap:=needsSwap[remLevels][originalOp];
  285. end;
  286. procedure trgcputhumb2.SplitITBlock(list: TAsmList; pos: tai);
  287. var
  288. hp : tai;
  289. level,itLevel : LongInt;
  290. remOp,newOp : TAsmOp;
  291. needsSwap : boolean;
  292. begin
  293. hp:=pos;
  294. level := 0;
  295. while assigned(hp) do
  296. begin
  297. if IsIT(taicpu(hp).opcode) then
  298. break
  299. else if hp.typ=ait_instruction then
  300. inc(level);
  301. hp:=tai(hp.Previous);
  302. end;
  303. if not assigned(hp) then
  304. internalerror(2012100801); // We are supposed to have found the ITxxx instruction here
  305. if (hp.typ<>ait_instruction) or
  306. (not IsIT(taicpu(hp).opcode)) then
  307. internalerror(2012100802); // Sanity check
  308. itLevel := GetITLevels(taicpu(hp).opcode);
  309. if level=itLevel then
  310. exit; // pos was the last instruction in the IT block anyway
  311. remOp:=GetITRemainderOp(taicpu(hp).opcode,itLevel-level,newOp,needsSwap);
  312. if (remOp=A_NONE) or
  313. (newOp=A_NONE) then
  314. Internalerror(2012100803);
  315. taicpu(hp).opcode:=newOp;
  316. if needsSwap then
  317. list.InsertAfter(taicpu.op_cond(remOp,inverse_cond(taicpu(hp).oper[0]^.cc)), pos)
  318. else
  319. list.InsertAfter(taicpu.op_cond(remOp,taicpu(hp).oper[0]^.cc), pos);
  320. end;
  321. procedure trgcputhumb2.do_spill_read(list:TAsmList;pos:tai;const spilltemp:treference;tempreg:tregister;orgsupreg:tsuperregister);
  322. var
  323. tmpref : treference;
  324. helplist : TAsmList;
  325. l : tasmlabel;
  326. hreg : tregister;
  327. begin
  328. { don't load spilled register between
  329. mov lr,pc
  330. mov pc,r4
  331. but before the mov lr,pc
  332. }
  333. if assigned(pos.previous) and
  334. (pos.typ=ait_instruction) and
  335. (taicpu(pos).opcode=A_MOV) and
  336. (taicpu(pos).oper[0]^.typ=top_reg) and
  337. (taicpu(pos).oper[0]^.reg=NR_R14) and
  338. (taicpu(pos).oper[1]^.typ=top_reg) and
  339. (taicpu(pos).oper[1]^.reg=NR_PC) then
  340. pos:=tai(pos.previous);
  341. if (pos.typ=ait_instruction) and
  342. (taicpu(pos).condition<>C_None) and
  343. (taicpu(pos).opcode<>A_B) then
  344. SplitITBlock(list, pos)
  345. else if (pos.typ=ait_instruction) and
  346. IsIT(taicpu(pos).opcode) then
  347. begin
  348. if not assigned(pos.Previous) then
  349. list.InsertBefore(tai_comment.Create('Dummy'), pos);
  350. pos:=tai(pos.Previous);
  351. end;
  352. if (spilltemp.offset>4095) or (spilltemp.offset<-255) then
  353. begin
  354. helplist:=TAsmList.create;
  355. reference_reset(tmpref,sizeof(aint));
  356. { create consts entry }
  357. current_asmdata.getjumplabel(l);
  358. cg.a_label(current_procinfo.aktlocaldata,l);
  359. tmpref.symboldata:=current_procinfo.aktlocaldata.last;
  360. current_procinfo.aktlocaldata.concat(tai_const.Create_32bit(spilltemp.offset));
  361. { load consts entry }
  362. if getregtype(tempreg)=R_INTREGISTER then
  363. hreg:=getregisterinline(helplist,[R_SUBWHOLE])
  364. else
  365. hreg:=cg.getintregister(helplist,OS_ADDR);
  366. tmpref.symbol:=l;
  367. tmpref.base:=NR_R15;
  368. helplist.concat(taicpu.op_reg_ref(A_LDR,hreg,tmpref));
  369. reference_reset_base(tmpref,current_procinfo.framepointer,0,sizeof(aint));
  370. tmpref.index:=hreg;
  371. if spilltemp.index<>NR_NO then
  372. internalerror(200401263);
  373. helplist.concat(spilling_create_load(tmpref,tempreg));
  374. if getregtype(tempreg)=R_INTREGISTER then
  375. ungetregisterinline(helplist,hreg);
  376. list.insertlistafter(pos,helplist);
  377. helplist.free;
  378. end
  379. else
  380. inherited;
  381. end;
  382. procedure trgcputhumb2.do_spill_written(list:TAsmList;pos:tai;const spilltemp:treference;tempreg:tregister;orgsupreg:tsuperregister);
  383. var
  384. tmpref : treference;
  385. helplist : TAsmList;
  386. l : tasmlabel;
  387. hreg : tregister;
  388. begin
  389. if (pos.typ=ait_instruction) and
  390. (taicpu(pos).condition<>C_None) and
  391. (taicpu(pos).opcode<>A_B) then
  392. SplitITBlock(list, pos)
  393. else if (pos.typ=ait_instruction) and
  394. IsIT(taicpu(pos).opcode) then
  395. begin
  396. if not assigned(pos.Previous) then
  397. list.InsertBefore(tai_comment.Create('Dummy'), pos);
  398. pos:=tai(pos.Previous);
  399. end;
  400. if (spilltemp.offset>4095) or (spilltemp.offset<-255) then
  401. begin
  402. helplist:=TAsmList.create;
  403. reference_reset(tmpref,sizeof(aint));
  404. { create consts entry }
  405. current_asmdata.getjumplabel(l);
  406. cg.a_label(current_procinfo.aktlocaldata,l);
  407. tmpref.symboldata:=current_procinfo.aktlocaldata.last;
  408. current_procinfo.aktlocaldata.concat(tai_const.Create_32bit(spilltemp.offset));
  409. { load consts entry }
  410. if getregtype(tempreg)=R_INTREGISTER then
  411. hreg:=getregisterinline(helplist,[R_SUBWHOLE])
  412. else
  413. hreg:=cg.getintregister(helplist,OS_ADDR);
  414. tmpref.symbol:=l;
  415. tmpref.base:=NR_R15;
  416. helplist.concat(taicpu.op_reg_ref(A_LDR,hreg,tmpref));
  417. if spilltemp.index<>NR_NO then
  418. internalerror(200401263);
  419. reference_reset_base(tmpref,current_procinfo.framepointer,0,sizeof(pint));
  420. tmpref.index:=hreg;
  421. helplist.concat(spilling_create_store(tempreg,tmpref));
  422. if getregtype(tempreg)=R_INTREGISTER then
  423. ungetregisterinline(helplist,hreg);
  424. list.insertlistafter(pos,helplist);
  425. helplist.free;
  426. end
  427. else
  428. inherited;
  429. end;
  430. procedure trgintcpu.add_cpu_interferences(p : tai);
  431. var
  432. r : tregister;
  433. begin
  434. if p.typ=ait_instruction then
  435. begin
  436. case taicpu(p).opcode of
  437. A_MLA,
  438. A_MUL:
  439. begin
  440. if current_settings.cputype<cpu_armv6 then
  441. add_edge(getsupreg(taicpu(p).oper[0]^.reg),getsupreg(taicpu(p).oper[1]^.reg));
  442. add_edge(getsupreg(taicpu(p).oper[0]^.reg),RS_R15);
  443. add_edge(getsupreg(taicpu(p).oper[1]^.reg),RS_R15);
  444. add_edge(getsupreg(taicpu(p).oper[2]^.reg),RS_R15);
  445. if taicpu(p).opcode=A_MLA then
  446. add_edge(getsupreg(taicpu(p).oper[3]^.reg),RS_R15);
  447. end;
  448. A_UMULL,
  449. A_UMLAL,
  450. A_SMULL,
  451. A_SMLAL:
  452. begin
  453. if current_settings.cputype<cpu_armv6 then
  454. begin
  455. add_edge(getsupreg(taicpu(p).oper[0]^.reg),getsupreg(taicpu(p).oper[1]^.reg));
  456. add_edge(getsupreg(taicpu(p).oper[1]^.reg),getsupreg(taicpu(p).oper[2]^.reg));
  457. add_edge(getsupreg(taicpu(p).oper[0]^.reg),getsupreg(taicpu(p).oper[2]^.reg));
  458. end;
  459. end;
  460. A_LDRB,
  461. A_STRB,
  462. A_STR,
  463. A_LDR,
  464. A_LDRH,
  465. A_STRH:
  466. { don't mix up the framepointer and stackpointer with pre/post indexed operations }
  467. if (taicpu(p).oper[1]^.typ=top_ref) and
  468. (taicpu(p).oper[1]^.ref^.addressmode in [AM_PREINDEXED,AM_POSTINDEXED]) then
  469. begin
  470. add_edge(getsupreg(taicpu(p).oper[1]^.ref^.base),getsupreg(current_procinfo.framepointer));
  471. { FIXME: temp variable r is needed here to avoid Internal error 20060521 }
  472. { while compiling the compiler. }
  473. r:=NR_STACK_POINTER_REG;
  474. if current_procinfo.framepointer<>r then
  475. add_edge(getsupreg(taicpu(p).oper[1]^.ref^.base),getsupreg(r));
  476. end;
  477. end;
  478. end;
  479. end;
  480. procedure trgintcputhumb.add_cpu_interferences(p: tai);
  481. var
  482. r : tregister;
  483. i,
  484. hr : longint;
  485. begin
  486. if p.typ=ait_instruction then
  487. begin
  488. { prevent that the register allocator merges registers with frame/stack pointer
  489. if an instruction writes to the register }
  490. if (taicpu(p).ops>=1) and (taicpu(p).oper[0]^.typ=top_reg) and
  491. (taicpu(p).spilling_get_operation_type(0) in [operand_write,operand_readwrite]) then
  492. begin
  493. { FIXME: temp variable r is needed here to avoid Internal error 20060521 }
  494. { while compiling the compiler. }
  495. r:=NR_STACK_POINTER_REG;
  496. add_edge(getsupreg(taicpu(p).oper[0]^.reg),getsupreg(r));
  497. add_edge(getsupreg(taicpu(p).oper[0]^.reg),getsupreg(current_procinfo.framepointer));
  498. end;
  499. if (taicpu(p).ops>=2) and (taicpu(p).oper[1]^.typ=top_reg) and
  500. (taicpu(p).spilling_get_operation_type(1) in [operand_write,operand_readwrite]) then
  501. begin
  502. { FIXME: temp variable r is needed here to avoid Internal error 20060521 }
  503. { while compiling the compiler. }
  504. r:=NR_STACK_POINTER_REG;
  505. add_edge(getsupreg(taicpu(p).oper[1]^.reg),getsupreg(r));
  506. add_edge(getsupreg(taicpu(p).oper[1]^.reg),getsupreg(current_procinfo.framepointer));
  507. end;
  508. case taicpu(p).opcode of
  509. A_LDRB,
  510. A_STRB,
  511. A_STR,
  512. A_LDR,
  513. A_LDRH,
  514. A_STRH,
  515. A_LDRSB,
  516. A_LDRSH,
  517. A_LDRD,
  518. A_STRD:
  519. begin
  520. { add_edge handles precoloured registers already }
  521. for i:=RS_R8 to RS_R15 do
  522. begin
  523. add_edge(getsupreg(taicpu(p).oper[1]^.ref^.base),i);
  524. add_edge(getsupreg(taicpu(p).oper[1]^.ref^.index),i);
  525. add_edge(getsupreg(taicpu(p).oper[0]^.reg),i);
  526. end;
  527. end;
  528. end;
  529. end;
  530. end;
  531. end.