nx86cal.pas 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Common x86 support for call nodes
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit nx86cal;
  18. {$i fpcdefs.inc}
  19. interface
  20. { $define AnsiStrRef}
  21. uses
  22. symdef,
  23. cgutils,
  24. ncgcal,parabase;
  25. type
  26. { tx86callnode }
  27. tx86callnode = class(tcgcallnode)
  28. protected
  29. procedure do_release_unused_return_value;override;
  30. procedure set_result_location(realresdef: tstoreddef);override;
  31. function can_call_ref(var ref: treference):boolean;override;
  32. function do_call_ref(ref: treference): tcgpara;override;
  33. end;
  34. implementation
  35. uses
  36. globtype,cgobj,
  37. cgbase,cpubase,cgx86,cga,aasmdata,aasmcpu,
  38. hlcgobj;
  39. {*****************************************************************************
  40. TX86CALLNODE
  41. *****************************************************************************}
  42. procedure tx86callnode.do_release_unused_return_value;
  43. begin
  44. case location.loc of
  45. LOC_FPUREGISTER :
  46. begin
  47. { release FPU stack }
  48. emit_reg(A_FSTP,S_NO,NR_FPU_RESULT_REG);
  49. tcgx86(cg).dec_fpu_stack;
  50. end
  51. else
  52. inherited do_release_unused_return_value;
  53. end;
  54. end;
  55. procedure tx86callnode.set_result_location(realresdef: tstoreddef);
  56. begin
  57. if (retloc.location^.loc=LOC_FPUREGISTER) then
  58. begin
  59. tcgx86(cg).inc_fpu_stack;
  60. location_reset(location,LOC_FPUREGISTER,retloc.location^.size);
  61. location.register:=retloc.location^.register;
  62. end
  63. else
  64. inherited set_result_location(realresdef);
  65. end;
  66. function tx86callnode.can_call_ref(var ref: treference): boolean;
  67. const
  68. {$if defined(i8086)}
  69. save_all_regs=[pocall_pascal];
  70. {$elseif defined(i386)}
  71. save_all_regs=[pocall_far16,pocall_oldfpccall];
  72. {$elseif defined(x86_64)}
  73. save_all_regs=[];
  74. {$endif}
  75. begin
  76. tcgx86(cg).make_simple_ref(current_asmdata.CurrAsmList,ref);
  77. { do not use a ref. for calling conventions which allocate all registers, the reg. allocator cannot handle this, see
  78. also issue #28639, I were not able to create a simple example though to cause the resulting endless spilling }
  79. result:=((getsupreg(ref.base)<first_int_imreg) and (getsupreg(ref.index)<first_int_imreg)) or
  80. not(procdefinition.proccalloption in save_all_regs);
  81. end;
  82. function tx86callnode.do_call_ref(ref: treference): tcgpara;
  83. begin
  84. current_asmdata.CurrAsmList.concat(taicpu.op_ref(A_CALL,S_NO,ref));
  85. result:=hlcg.get_call_result_cgpara(procdefinition,typedef)
  86. end;
  87. end.