cgcpu.pas 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. {
  2. $Id$
  3. Copyright (c) 2002 by Florian Klaempfl
  4. This unit implements the code generator for the x86-64.
  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 cgcpu;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. cgbase,cgobj,cgx86,
  23. aasmbase,aasmtai,aasmcpu,
  24. cpubase,cpuinfo,cpupara,parabase,
  25. node,symconst,rgx86,procinfo;
  26. type
  27. tcgx86_64 = class(tcgx86)
  28. procedure init_register_allocators;override;
  29. procedure g_proc_exit(list : taasmoutput;parasize:longint;nostackframe:boolean);override;
  30. end;
  31. implementation
  32. uses
  33. globtype,globals,verbose,systems,cutils,
  34. symdef,symsym,defutil,paramgr,
  35. rgobj,tgobj,rgcpu;
  36. procedure Tcgx86_64.init_register_allocators;
  37. begin
  38. inherited init_register_allocators;
  39. if cs_create_pic in aktmoduleswitches then
  40. rg[R_INTREGISTER]:=trgcpu.create(R_INTREGISTER,R_SUBWHOLE,[RS_RAX,RS_RDX,RS_RCX,RS_RSI,RS_RDI,
  41. RS_R8,RS_R9,RS_R10,RS_R11,RS_R12,RS_R13,RS_R14,RS_R15],first_int_imreg,[RS_EBP,RS_EBX])
  42. else
  43. rg[R_INTREGISTER]:=trgcpu.create(R_INTREGISTER,R_SUBWHOLE,[RS_RAX,RS_RDX,RS_RCX,RS_RBX,RS_RSI,RS_RDI,
  44. RS_R8,RS_R9,RS_R10,RS_R11,RS_R12,RS_R13,RS_R14,RS_R15],first_int_imreg,[RS_EBP]);
  45. rg[R_MMREGISTER]:=trgcpu.create(R_MMREGISTER,R_SUBNONE,[RS_XMM0,RS_XMM1,RS_XMM2,RS_XMM3,RS_XMM4,RS_XMM5,RS_XMM6,RS_XMM7,
  46. RS_XMM8,RS_XMM9,RS_XMM10,RS_XMM11,RS_XMM12,RS_XMM13,RS_XMM14,RS_XMM15],first_mm_imreg,[]);
  47. rgfpu:=Trgx86fpu.create;
  48. end;
  49. procedure tcgx86_64.g_proc_exit(list : taasmoutput;parasize:longint;nostackframe:boolean);
  50. var
  51. stacksize : longint;
  52. begin
  53. { Release PIC register }
  54. if cs_create_pic in aktmoduleswitches then
  55. list.concat(tai_regalloc.dealloc(NR_PIC_OFFSET_REG,nil));
  56. { remove stackframe }
  57. if not nostackframe then
  58. begin
  59. if (current_procinfo.framepointer=NR_STACK_POINTER_REG) then
  60. begin
  61. stacksize:=current_procinfo.calc_stackframe_size;
  62. if (stacksize<>0) then
  63. cg.a_op_const_reg(list,OP_ADD,OS_ADDR,stacksize,current_procinfo.framepointer);
  64. end
  65. else
  66. list.concat(Taicpu.op_none(A_LEAVE,S_NO));
  67. list.concat(tai_regalloc.dealloc(NR_FRAME_POINTER_REG,nil));
  68. end;
  69. list.concat(Taicpu.Op_none(A_RET,S_NO));
  70. end;
  71. begin
  72. cg:=tcgx86_64.create;
  73. {$ifndef cpu64bit}
  74. cg64:=tcg64f64.create;
  75. {$endif cpu64bit}
  76. end.
  77. {
  78. $Log$
  79. Revision 1.19 2004-11-01 17:44:27 florian
  80. * cg64f64 isn't used anymore
  81. Revision 1.18 2004/10/24 20:01:08 peter
  82. * remove saveregister calling convention
  83. Revision 1.17 2004/10/05 20:41:02 peter
  84. * more spilling rewrites
  85. Revision 1.16 2004/09/21 17:25:13 peter
  86. * paraloc branch merged
  87. Revision 1.15.4.1 2004/08/31 20:43:06 peter
  88. * paraloc patch
  89. Revision 1.15 2004/07/09 23:30:13 jonas
  90. * changed first_sse_imreg to first_mm_imreg
  91. Revision 1.14 2004/06/20 08:55:32 florian
  92. * logs truncated
  93. Revision 1.13 2004/06/16 20:07:11 florian
  94. * dwarf branch merged
  95. Revision 1.12.2.6 2004/05/27 23:36:18 peter
  96. * nostackframe procdirective added
  97. Revision 1.12.2.5 2004/05/02 21:34:01 florian
  98. * i386 compilation fixed
  99. Revision 1.12.2.4 2004/05/02 20:20:59 florian
  100. * started to fix callee side result value handling
  101. Revision 1.12.2.3 2004/05/01 11:12:24 florian
  102. * spilling of registers with size<>4 fixed
  103. }