rgcpu.pas 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. This unit implements the Risc-V 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. rgobj;
  26. type
  27. trgcpu = class(trgobj)
  28. procedure do_spill_read(list: TAsmList; pos: tai; const spilltemp: treference; tempreg: tregister; orgsupreg: tsuperregister); override;
  29. procedure do_spill_written(list: TAsmList; pos: tai; const spilltemp: treference; tempreg: tregister; orgsupreg: tsuperregister); override;
  30. end;
  31. trgintcpu = class(trgcpu)
  32. end;
  33. implementation
  34. uses
  35. verbose, cutils,globtype,
  36. cgobj,
  37. procinfo;
  38. procedure trgcpu.do_spill_read(list: TAsmList; pos: tai; const spilltemp: treference; tempreg: tregister; orgsupreg: tsuperregister);
  39. var
  40. tmpref : treference;
  41. helplist : TAsmList;
  42. hreg : tregister;
  43. helpins: Taicpu;
  44. begin
  45. if not is_imm12(spilltemp.offset) then
  46. begin
  47. helplist:=tasmlist.create;
  48. if getregtype(tempreg)=R_INTREGISTER then
  49. hreg:=tempreg
  50. else
  51. hreg:=cg.getintregister(helplist,OS_ADDR);
  52. if (spilltemp.offset and $800)<>0 then
  53. helplist.concat(taicpu.op_reg_const(A_LUI,hreg,((spilltemp.offset shr 12)+1) and $FFFFF))
  54. else
  55. helplist.concat(taicpu.op_reg_const(A_LUI,hreg,(spilltemp.offset shr 12) and $FFFFF));
  56. helplist.concat(taicpu.op_reg_reg_const(A_ADDI,hreg,hreg,SarSmallint(spilltemp.offset shl 4,4)));
  57. helplist.concat(taicpu.op_reg_reg_reg(A_ADD,hreg,hreg,spilltemp.base));
  58. reference_reset_base(tmpref,hreg,0,ctempposinvalid,sizeof(aint),[]);
  59. helpins:=spilling_create_load(tmpref,tempreg);
  60. helplist.concat(helpins);
  61. list.insertlistafter(pos,helplist);
  62. helplist.free;
  63. end
  64. else
  65. inherited;
  66. end;
  67. procedure trgcpu.do_spill_written(list: TAsmList; pos: tai; const spilltemp: treference; tempreg: tregister; orgsupreg: tsuperregister);
  68. var
  69. tmpref : treference;
  70. helplist : tasmlist;
  71. hreg : tregister;
  72. begin
  73. if not is_imm12(spilltemp.offset) then
  74. begin
  75. helplist:=tasmlist.create;
  76. if getregtype(tempreg)=R_INTREGISTER then
  77. hreg:=getregisterinline(helplist,[R_SUBWHOLE])
  78. else
  79. hreg:=cg.getintregister(helplist,OS_ADDR);
  80. if (spilltemp.offset and $800)<>0 then
  81. helplist.concat(taicpu.op_reg_const(A_LUI,hreg,((spilltemp.offset shr 12)+1) and $FFFFF))
  82. else
  83. helplist.concat(taicpu.op_reg_const(A_LUI,hreg,(spilltemp.offset shr 12) and $FFFFF));
  84. helplist.concat(taicpu.op_reg_reg_const(A_ADDI,hreg,hreg,SarSmallint(spilltemp.offset shl 4,4)));
  85. helplist.concat(taicpu.op_reg_reg_reg(A_ADD,hreg,hreg,spilltemp.base));
  86. reference_reset_base(tmpref,hreg,0,ctempposinvalid,sizeof(aint),[]);
  87. helplist.concat(spilling_create_store(tempreg,tmpref));
  88. if getregtype(tempreg)=R_INTREGISTER then
  89. ungetregisterinline(helplist,hreg);
  90. list.insertlistafter(pos,helplist);
  91. helplist.free;
  92. end
  93. else
  94. inherited;
  95. end;
  96. end.