nllvmmat.pas 4.0 KB

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