Forráskód Böngészése

+ hlcg/llvm support for unary minus
o converted tcgunaryminusnode.emit_float_sign_change() to use a tdef instead
of tcgsize

git-svn-id: branches/hlcgllvm@27002 -

Jonas Maebe 11 éve
szülő
commit
fcbde1d6e9
5 módosított fájl, 110 hozzáadás és 17 törlés
  1. 1 0
      .gitattributes
  2. 1 1
      compiler/llvm/llvmnode.pas
  3. 86 0
      compiler/llvm/nllvmmat.pas
  4. 1 0
      compiler/mips/ncpumat.pas
  5. 21 16
      compiler/ncgmat.pas

+ 1 - 0
.gitattributes

@@ -331,6 +331,7 @@ compiler/llvm/nllvmadd.pas svneol=native#text/plain
 compiler/llvm/nllvmcnv.pas svneol=native#text/plain
 compiler/llvm/nllvmcon.pas svneol=native#text/plain
 compiler/llvm/nllvmld.pas svneol=native#text/plain
+compiler/llvm/nllvmmat.pas svneol=native#text/plain
 compiler/llvm/nllvmmem.pas svneol=native#text/plain
 compiler/llvm/nllvmutil.pas svneol=native#text/plain
 compiler/llvm/rgllvm.pas svneol=native#text/plain

+ 1 - 1
compiler/llvm/llvmnode.pas

@@ -37,7 +37,7 @@ implementation
     ncgbas,ncgflw,ncgcnv,ncgld,ncgmem,ncgcon,ncgset,
     ncgadd, ncgcal,ncgmat,ncginl,
     tgllvm,hlcgllvm,
-    nllvmadd,nllvmcnv,nllvmcon,nllvmld,nllvmmem,
+    nllvmadd,nllvmcnv,nllvmcon,nllvmld,nllvmmat,nllvmmem,
     nllvmutil,
     llvmpara;
 

+ 86 - 0
compiler/llvm/nllvmmat.pas

@@ -0,0 +1,86 @@
+{
+    Copyright (c) 2014 Jonas Maebe
+
+    Generate LLVM IR for math nodes
+
+    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.
+
+ ****************************************************************************
+}
+unit nllvmmat;
+
+{$i fpcdefs.inc}
+
+interface
+
+uses
+  symtype,
+  node, nmat, ncgmat, cgbase;
+
+type
+  Tllvmunaryminusnode = class(tcgunaryminusnode)
+    procedure emit_float_sign_change(r: tregister; _size : tdef);override;
+  end;
+
+implementation
+
+uses
+  globtype, systems,
+  cutils, verbose, globals,
+  symconst, symdef,
+  aasmbase, aasmllvm, aasmtai, aasmdata,
+  defutil,
+  procinfo,
+  hlcgobj, pass_2,
+  ncon,
+  llvmbase,
+  ncgutil, cgutils;
+
+{*****************************************************************************
+                               Tllvmunaryminusnode
+*****************************************************************************}
+
+procedure Tllvmunaryminusnode.emit_float_sign_change(r: tregister; _size : tdef);
+var
+  zeroreg: tregister;
+begin
+  if _size.typ<>floatdef then
+    internalerror(2014012212);
+  zeroreg:=hlcg.getfpuregister(current_asmdata.CurrAsmList,_size);
+  case tfloatdef(_size).floattype of
+    s32real,s64real:
+      current_asmdata.CurrAsmList.concat(taillvm.op_reg_size_fpconst_size(la_bitcast,zeroreg,_size,0,_size));
+    { comp and currency are handled as int64 at the llvm level }
+    s64comp,
+    s64currency:
+      { sc80floattype instead of _size, see comment in thlcgllvm.a_loadfpu_ref_reg }
+      current_asmdata.CurrAsmList.concat(taillvm.op_reg_size_const_size(la_sitofp,zeroreg,s64inttype,0,sc80floattype));
+{$ifdef cpuextended}
+    s80real,sc80real:
+      current_asmdata.CurrAsmList.concat(taillvm.op_reg_size_fpconst80_size(la_bitcast,zeroreg,_size,0.0,_size));
+{$endif cpuextended}
+  end;
+  current_asmdata.CurrAsmList.Concat(taillvm.op_reg_size_reg_reg(la_fsub,r,_size,zeroreg,r));
+end;
+
+
+begin
+(*
+  cmoddivnode := tllvmmoddivnode;
+  cshlshrnode := tllvmshlshrnode;
+  cnotnode    := tllvmnotnode;
+*)
+  cunaryminusnode := Tllvmunaryminusnode;
+end.

+ 1 - 0
compiler/mips/ncpumat.pas

@@ -28,6 +28,7 @@ unit ncpumat;
 interface
 
 uses
+  symtype,
   node, nmat, ncgmat, cgbase;
 
 type

+ 21 - 16
compiler/ncgmat.pas

@@ -26,6 +26,7 @@ unit ncgmat;
 interface
 
     uses
+      symtype,
       node,nmat,cpubase,cgbase;
 
     type
@@ -41,7 +42,7 @@ interface
            point values are stored in the register
            in IEEE-754 format.
          }
-         procedure emit_float_sign_change(r: tregister; _size : tcgsize);virtual;
+         procedure emit_float_sign_change(r: tregister; _size : tdef);virtual;
 {$ifdef SUPPORT_MMX}
          procedure second_mmx;virtual;abstract;
 {$endif SUPPORT_MMX}
@@ -128,7 +129,7 @@ implementation
     uses
       globtype,systems,
       cutils,verbose,globals,
-      symtable,symconst,symtype,symdef,aasmbase,aasmtai,aasmdata,aasmcpu,defutil,
+      symtable,symconst,symdef,aasmbase,aasmtai,aasmdata,aasmcpu,defutil,
       parabase,
       pass_2,
       ncon,
@@ -142,7 +143,7 @@ implementation
                           TCGUNARYMINUSNODE
 *****************************************************************************}
 
-    procedure tcgunaryminusnode.emit_float_sign_change(r: tregister; _size : tcgsize);
+    procedure tcgunaryminusnode.emit_float_sign_change(r: tregister; _size : tdef);
       var
         href,
         href2 : treference;
@@ -150,24 +151,28 @@ implementation
         { get a temporary memory reference to store the floating
           point value
         }
-        tg.gettemp(current_asmdata.CurrAsmList,tcgsize2size[_size],tcgsize2size[_size],tt_normal,href);
+        tg.gethltemp(current_asmdata.CurrAsmList,_size,_size.size,tt_normal,href);
         { store the floating point value in the temporary memory area }
-        cg.a_loadfpu_reg_ref(current_asmdata.CurrAsmList,_size,_size,r,href);
+        hlcg.a_loadfpu_reg_ref(current_asmdata.CurrAsmList,_size,_size,r,href);
         { only single and double ieee are supported, for little endian
           the signed bit is in the second dword }
         href2:=href;
-        case _size of
-          OS_F64 :
+        if _size.typ<>floatdef then
+          internalerror(2014012211);
+        case tfloatdef(_size).floattype of
+          s64real,
+          s64comp,
+          s64currency:
             if target_info.endian = endian_little then
               inc(href2.offset,4);
-          OS_F32 :
+          s32real :
             ;
           else
             internalerror(200406021);
         end;
         { flip sign-bit (bit 31/63) of single/double }
-        cg.a_op_const_ref(current_asmdata.CurrAsmList,OP_XOR,OS_32,aint($80000000),href2);
-        cg.a_loadfpu_ref_reg(current_asmdata.CurrAsmList,_size,_size,href,r);
+        hlcg.a_op_const_ref(current_asmdata.CurrAsmList,OP_XOR,u32inttype,aint($80000000),href2);
+        hlcg.a_loadfpu_ref_reg(current_asmdata.CurrAsmList,_size,_size,href,r);
         tg.ungetiftemp(current_asmdata.CurrAsmList,href);
       end;
 
@@ -209,21 +214,21 @@ implementation
           LOC_CREFERENCE :
             begin
               location.register:=cg.getfpuregister(current_asmdata.CurrAsmList,location.size);
-              cg.a_loadfpu_ref_reg(current_asmdata.CurrAsmList,
-                 left.location.size,location.size,
+              hlcg.a_loadfpu_ref_reg(current_asmdata.CurrAsmList,
+                 left.resultdef,resultdef,
                  left.location.reference,location.register);
-              emit_float_sign_change(location.register,def_cgsize(left.resultdef));
+              emit_float_sign_change(location.register,left.resultdef);
             end;
           LOC_FPUREGISTER:
             begin
                location.register:=left.location.register;
-               emit_float_sign_change(location.register,def_cgsize(left.resultdef));
+               emit_float_sign_change(location.register,left.resultdef);
             end;
           LOC_CFPUREGISTER:
             begin
                location.register:=cg.getfpuregister(current_asmdata.CurrAsmList,location.size);
-               cg.a_loadfpu_reg_reg(current_asmdata.CurrAsmList,left.location.size,location.size,left.location.register,location.register);
-               emit_float_sign_change(location.register,def_cgsize(left.resultdef));
+               hlcg.a_loadfpu_reg_reg(current_asmdata.CurrAsmList,left.resultdef,resultdef,left.location.register,location.register);
+               emit_float_sign_change(location.register,left.resultdef);
             end;
           else
             internalerror(200306021);