nllvmmat.pas 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. {
  2. Copyright (c) 2014 Jonas Maebe
  3. Generate LLVM IR for math 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 nllvmmat;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. symtype,
  22. node, nmat, ncgmat, cgbase;
  23. type
  24. tllvmmoddivnode = class(tcgmoddivnode)
  25. procedure pass_generate_code; override;
  26. end;
  27. Tllvmunaryminusnode = class(tcgunaryminusnode)
  28. procedure emit_float_sign_change(r: tregister; _size : tdef);override;
  29. end;
  30. implementation
  31. uses
  32. globtype, systems,
  33. cutils, verbose, globals,
  34. symconst, symdef,
  35. aasmbase, aasmllvm, aasmtai, aasmdata,
  36. defutil,
  37. procinfo,
  38. hlcgobj, pass_2,
  39. ncon,
  40. llvmbase,
  41. ncgutil, cgutils;
  42. {*****************************************************************************
  43. tllvmmoddivnode
  44. *****************************************************************************}
  45. procedure tllvmmoddivnode.pass_generate_code;
  46. var
  47. op: tllvmop;
  48. begin
  49. secondpass(left);
  50. secondpass(right);
  51. if is_signed(left.resultdef) then
  52. if nodetype=divn then
  53. op:=la_sdiv
  54. else
  55. op:=la_srem
  56. else if nodetype=divn then
  57. op:=la_udiv
  58. else
  59. op:=la_urem;
  60. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,resultdef,true);
  61. if right.location.loc<>LOC_CONSTANT then
  62. hlcg.location_force_reg(current_asmdata.CurrAsmList,right.location,right.resultdef,resultdef,true);
  63. location_reset(location,LOC_REGISTER,def_cgsize(resultdef));
  64. location.register:=hlcg.getintregister(current_asmdata.CurrAsmList,resultdef);
  65. if right.location.loc=LOC_CONSTANT then
  66. current_asmdata.CurrAsmList.concat(taillvm.op_reg_size_reg_const(op,location.register,resultdef,left.location.register,right.location.value))
  67. else
  68. current_asmdata.CurrAsmList.concat(taillvm.op_reg_size_reg_reg(op,location.register,resultdef,left.location.register,right.location.register))
  69. end;
  70. {*****************************************************************************
  71. Tllvmunaryminusnode
  72. *****************************************************************************}
  73. procedure Tllvmunaryminusnode.emit_float_sign_change(r: tregister; _size : tdef);
  74. var
  75. zeroreg: tregister;
  76. begin
  77. if _size.typ<>floatdef then
  78. internalerror(2014012212);
  79. zeroreg:=hlcg.getfpuregister(current_asmdata.CurrAsmList,_size);
  80. case tfloatdef(_size).floattype of
  81. s32real,s64real:
  82. current_asmdata.CurrAsmList.concat(taillvm.op_reg_size_fpconst_size(la_bitcast,zeroreg,_size,0,_size));
  83. { comp and currency are handled as int64 at the llvm level }
  84. s64comp,
  85. s64currency:
  86. { sc80floattype instead of _size, see comment in thlcgllvm.a_loadfpu_ref_reg }
  87. current_asmdata.CurrAsmList.concat(taillvm.op_reg_size_const_size(la_sitofp,zeroreg,s64inttype,0,sc80floattype));
  88. {$ifdef cpuextended}
  89. s80real,sc80real:
  90. current_asmdata.CurrAsmList.concat(taillvm.op_reg_size_fpconst80_size(la_bitcast,zeroreg,_size,0.0,_size));
  91. {$endif cpuextended}
  92. end;
  93. current_asmdata.CurrAsmList.Concat(taillvm.op_reg_size_reg_reg(la_fsub,r,_size,zeroreg,r));
  94. end;
  95. begin
  96. cmoddivnode := tllvmmoddivnode;
  97. (*
  98. cshlshrnode := tllvmshlshrnode;
  99. cnotnode := tllvmnotnode;
  100. *)
  101. cunaryminusnode := Tllvmunaryminusnode;
  102. end.