nllvmbas.pas 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. {
  2. Copyright (c) 2015 by Jonas Maebe
  3. This unit implements llvm support for some basic 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 nllvmbas;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. nbas,ncgbas;
  22. type
  23. tllvmtempinfoaccessor = class(ttempinfoaccessor)
  24. protected
  25. class procedure settempinfoflags(tempinfo: ptempinfo; const flags: ttempinfoflags); override;
  26. end;
  27. tllvmtempcreatenode = class(tcgtempcreatenode)
  28. procedure pass_generate_code;override;
  29. end;
  30. implementation
  31. uses
  32. aasmdata,
  33. cgbase,cgutils,
  34. llvmbase,aasmllvm
  35. ;
  36. {*****************************************************************************
  37. TLLVMTEMPINFOACCESSOR
  38. *****************************************************************************}
  39. class procedure tllvmtempinfoaccessor.settempinfoflags(tempinfo: ptempinfo; const flags: ttempinfoflags);
  40. begin
  41. { it is not possible to typecast between e.g. an integer and a record
  42. in a register, which is a problem if such a typecast is performed on
  43. an lvalue (since we then have to store it first to a temp in memory,
  44. which means we no longer have an lvalue).
  45. Disable regvars altogether since LLVM will put the values in registers
  46. anyway if possible/useful. }
  47. inherited settempinfoflags(tempinfo,flags-[ti_may_be_in_reg]);
  48. end;
  49. {*****************************************************************************
  50. TTEMPCREATENODE
  51. *****************************************************************************}
  52. procedure tllvmtempcreatenode.pass_generate_code;
  53. begin
  54. inherited;
  55. { if a temp is in a register and we never assign anything to it (e.g.
  56. because it's the register for an inlined function result that never
  57. gets assigned a value), then llvm will be confused the first time
  58. we try to read from it (since it's never been defined) -> always
  59. immediately assign undef to such registers }
  60. if tempinfo^.location.loc in [LOC_REGISTER,LOC_CREGISTER,LOC_FPUREGISTER,
  61. LOC_CFPUREGISTER,LOC_MMREGISTER,LOC_CMMREGISTER] then
  62. current_asmdata.CurrAsmList.concat(
  63. taillvm.op_reg_size_undef(la_bitcast,tempinfo^.location.register,tempinfo^.typedef)
  64. );
  65. end;
  66. begin
  67. ctempinfoaccessor:=tllvmtempinfoaccessor;
  68. ctempcreatenode:=tllvmtempcreatenode;
  69. end.