rgcpu.pas 23 KB

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