Browse Source

* constrained sitofp is not yet supported in LLVM for all targets

git-svn-id: trunk@43885 -
Jonas Maebe 5 years ago
parent
commit
31ef82b9c6
4 changed files with 56 additions and 3 deletions
  1. 1 0
      .gitattributes
  2. 48 0
      compiler/llvm/llvmfeatures.pas
  3. 2 1
      compiler/llvm/llvminfo.pas
  4. 5 2
      compiler/llvm/nllvmcnv.pas

+ 1 - 0
.gitattributes

@@ -350,6 +350,7 @@ compiler/llvm/itllvm.pas svneol=native#text/plain
 compiler/llvm/llvmbase.pas svneol=native#text/plain
 compiler/llvm/llvmcfi.pas svneol=native#text/plain
 compiler/llvm/llvmdef.pas svneol=native#text/plain
+compiler/llvm/llvmfeatures.pas svneol=native#text/plain
 compiler/llvm/llvminfo.pas svneol=native#text/plain
 compiler/llvm/llvmnode.pas svneol=native#text/plain
 compiler/llvm/llvmpara.pas svneol=native#text/plain

+ 48 - 0
compiler/llvm/llvmfeatures.pas

@@ -0,0 +1,48 @@
+{
+    Copyright (c) 2020 by Jonas Maebe
+
+    Basic Processor information for LLVM
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ ****************************************************************************
+}
+{$i fpcdefs.inc}
+
+unit llvmfeatures;
+
+interface
+
+function llvm_constrained_si64tofp_support: boolean;
+
+implementation
+
+uses
+  globals,
+  llvminfo;
+
+function llvm_constrained_si64tofp_support: boolean;
+  begin
+{$if defined(i386) or defined(x86_64)}
+    { LLVM has a custom implementation for these platforms }
+    result:=true;
+{$else}
+    result:=llvmflag_generic_constrained_si64tofp in llvmversion_properties[current_settings.llvmversion];
+{$endif}
+  end;
+
+
+end.
+

+ 2 - 1
compiler/llvm/llvminfo.pas

@@ -50,7 +50,8 @@ type
      llvmflag_memcpy_indiv_align,           { memcpy intrinsic supports separate alignment for source and dest }
      llvmflag_null_pointer_valid,           { supports "llvmflag_null_pointer_valid" attribute, which indicates access to nil should not be optimized as undefined behaviour }
      llvmflag_constrained_fptrunc_fpext,    { supports constrained fptrunc and fpext intrinsics }
-     llvmflag_constrained_fptoi_itofp       { supports constrained fptosi/fptoui/uitofp/sitofp instrinsics }
+     llvmflag_constrained_fptoi_itofp,      { supports constrained fptosi/fptoui/uitofp/sitofp instrinsics }
+     llvmflag_generic_constrained_si64tofp  { supports sitofp for 64 bit signed integers on all targets }
    );
    tllvmversionflags = set of tllvmversionflag;
 

+ 5 - 2
compiler/llvm/nllvmcnv.pas

@@ -66,7 +66,7 @@ implementation
 uses
   globtype,globals,cutils,verbose,
   aasmbase,aasmdata,
-  llvmbase,llvminfo,aasmllvm,aasmllvmmetadata,llvmdef,
+  llvmbase,llvminfo,llvmfeatures,aasmllvm,aasmllvmmetadata,llvmdef,
   procinfo,
   ncal,ncon,
   symconst,symdef,defutil,
@@ -119,7 +119,10 @@ function tllvmtypeconvnode.first_int_to_real: tnode;
        (torddef(left.resultdef).ordtype<>scurrency) and
        ((left.resultdef.size>=resultdef.size) or
         ((torddef(left.resultdef).ordtype=u64bit) and
-         (tfloatdef(resultdef).floattype=s80real))) then
+         (tfloatdef(resultdef).floattype=s80real))) and
+       (llvm_constrained_si64tofp_support or
+        (torddef(left.resultdef).ordtype<>s64bit) or
+        (tfloatdef(resultdef).floattype<>s64real)) then
       begin
         { in case rounding may have to be applied, use the intrinsic }
         exceptmode:=llvm_constrainedexceptmodestring;