瀏覽代碼

* lots of new regallocator fixes, both in generic and ppc-specific code
(ppc compiler still can't compile the linux system unit though)

Jonas Maebe 22 年之前
父節點
當前提交
d168ae15df

+ 23 - 11
compiler/cgobj.pas

@@ -599,7 +599,8 @@ unit cgobj;
               begin
                  if locpara.sp_fixup<>0 then
                    begin
-                      t.enum:=stack_pointer_reg;
+                      t.enum:=R_INTREGISTER;;
+                      t.number:=NR_STACK_POINTER_REG;
                       a_op_const_reg(list,OP_ADD,locpara.sp_fixup,t);
                    end;
                  reference_reset(ref);
@@ -704,9 +705,9 @@ unit cgobj;
         if size in [OS_8,OS_S8] then
           if (rg.countunusedregsint = 0) then
             begin
-              if dref.base.enum<>R_INTREGISTER then
+              if (dref.base.enum<>R_NO) and (dref.base.enum<>R_INTREGISTER) then
                 internalerror(200302037);
-              if dref.index.enum<>R_INTREGISTER then
+              if (dref.index.enum<>R_NO) and (dref.index.enum<>R_INTREGISTER) then
                 internalerror(200302037);
                 
               if (dref.base.number shr 8<>RS_EBX) and
@@ -923,7 +924,8 @@ unit cgobj;
               begin
                  if locpara.sp_fixup<>0 then
                    begin
-                      t.enum:=stack_pointer_reg;
+                      t.enum:=R_INTREGISTER;
+                      t.number:=NR_STACK_POINTER_REG;
                       a_op_const_reg(list,OP_ADD,locpara.sp_fixup,t);
                    end;
                  reference_reset(ref);
@@ -1509,8 +1511,10 @@ unit cgobj;
       hregister : tregister;
       spr,acc : Tregister;
      begin
-        acc.enum:=accumulator;
-        spr.enum:=SELF_POINTER_REG;
+        acc.enum:=R_INTREGISTER;
+        acc.number:=NR_ACCUMULATOR;
+        spr.enum:=R_INTREGISTER;
+        spr.number:=NR_SELF_POINTER_REG;
         if is_class(procinfo._class) then
           begin
             if (cs_implicit_exceptions in aktmoduleswitches) then
@@ -1563,7 +1567,8 @@ unit cgobj;
       hregister : tregister;
         spr : Tregister;
       begin
-        spr.enum:=SELF_POINTER_REG;
+        spr.enum:=R_INTREGISTER;
+        spr.number:=NR_SELF_POINTER_REG;
         if is_class(procinfo._class) then
          begin
            { 2nd parameter  : flag }
@@ -1612,7 +1617,8 @@ unit cgobj;
         hregister : tregister;
         spr : Tregister;
       begin
-        spr.enum:=SELF_POINTER_REG;
+        spr.enum:=R_INTREGISTER;
+        spr.number:=NR_SELF_POINTER_REG;
         if is_class(procinfo._class) then
           begin
             {
@@ -1676,7 +1682,8 @@ unit cgobj;
     var r:Tregister;
 
      begin
-       r.enum:=accumulator;
+       r.enum:=R_INTREGISTER;;
+       r.number:=NR_ACCUMULATOR;
        a_load_reg_ref(list, OS_S32, r, href);
      end;
 
@@ -1692,7 +1699,8 @@ unit cgobj;
     var r:Tregister;
 
      begin
-       r.enum:=accumulator;
+       r.enum:=R_INTREGISTER;;
+       r.number:=NR_ACCUMULATOR;
        a_load_ref_reg(list, OS_S32, href, r);
      end;
 
@@ -1721,7 +1729,11 @@ finalization
 end.
 {
   $Log$
-  Revision 1.77  2003-02-19 22:00:14  daniel
+  Revision 1.78  2003-03-11 21:46:24  jonas
+    * lots of new regallocator fixes, both in generic and ppc-specific code
+      (ppc compiler still can't compile the linux system unit though)
+
+  Revision 1.77  2003/02/19 22:00:14  daniel
     * Code generator converted to new register notation
     - Horribily outdated todo.txt removed
 

+ 9 - 3
compiler/ncgutil.pas

@@ -262,7 +262,8 @@ implementation
        cg.a_param_const(list,OS_S32,1,paramanager.getintparaloc(1));
        cg.a_call_name(list,'FPC_PUSHEXCEPTADDR');
 
-       r.enum:=accumulator;
+       r.enum:=R_INTREGISTER;
+       r.number:=NR_ACCUMULATOR;
        cg.a_param_reg(list,OS_ADDR,r,paramanager.getintparaloc(1));
        cg.a_call_name(list,'FPC_SETJMP');
 
@@ -282,7 +283,8 @@ implementation
          if not onlyfree then
           begin
             cg.g_exception_reason_load(list, href);
-            r.enum:=accumulator;
+            r.enum:=R_INTREGISTER;
+            r.number:=NR_ACCUMULATOR;
             cg.a_cmp_const_reg_label(list,OS_S32,OC_EQ,a,r,endexceptlabel);
           end;
      end;
@@ -1994,7 +1996,11 @@ function returns in a register and the caller receives it in an other one}
 end.
 {
   $Log$
-  Revision 1.78  2003-02-26 21:15:43  daniel
+  Revision 1.79  2003-03-11 21:46:24  jonas
+    * lots of new regallocator fixes, both in generic and ppc-specific code
+      (ppc compiler still can't compile the linux system unit though)
+
+  Revision 1.78  2003/02/26 21:15:43  daniel
     * Fixed the optimizer
 
   Revision 1.77  2003/02/19 22:00:14  daniel

+ 6 - 2
compiler/nld.pas

@@ -590,7 +590,7 @@ implementation
                       result:=ccallnode.createintern('fpc_ansistr_append_char',hp)
                     else if is_shortstring(tbinarynode(right).right.resulttype.def) then
                       result:=ccallnode.createintern('fpc_ansistr_append_shortstring',hp)
-                    else if is_ansistring(tbinarynode(right).right.resulttype.def) then
+                    else
                       result:=ccallnode.createintern('fpc_ansistr_append_ansistring',hp);
                     tbinarynode(right).right:=nil;
                     left:=nil;
@@ -1257,7 +1257,11 @@ begin
 end.
 {
   $Log$
-  Revision 1.80  2003-01-07 16:52:58  jonas
+  Revision 1.81  2003-03-11 21:46:24  jonas
+    * lots of new regallocator fixes, both in generic and ppc-specific code
+      (ppc compiler still can't compile the linux system unit though)
+
+  Revision 1.80  2003/01/07 16:52:58  jonas
     * fixed ansistring+char and ansistring+shortstring optimizations (those
       cases were always handled as ansistring+ansistring due to
       typeconversions inserted by the add-node)

+ 200 - 111
compiler/powerpc/cgcpu.pas

@@ -364,7 +364,7 @@ const
          { 64 bit stuff should be handled separately }
          if size in [OS_64,OS_S64] then
            internalerror(200109236);
-         op := storeinstr[tcgsize2unsigned[size],ref2.index.enum<>R_NO,false];
+         op := storeinstr[tcgsize2unsigned[size],ref2.index.number<>NR_NO,false];
          a_load_store(list,op,reg,ref2);
          if freereg then
            cg.free_scratch_reg(list,ref2.base);
@@ -396,7 +396,7 @@ const
             internalerror(2002090902);
           ref2 := ref;
           freereg := fixref(list,ref2);
-          op := loadinstr[size,ref2.index.enum<>R_NO,false];
+          op := loadinstr[size,ref2.index.number<>NR_NO,false];
           a_load_store(list,op,reg,ref2);
           if freereg then
             free_scratch_reg(list,ref2.base);
@@ -410,11 +410,11 @@ const
      procedure tcgppc.a_load_reg_reg(list : taasmoutput;fromsize, tosize : tcgsize;reg1,reg2 : tregister);
 
        begin
-         if reg1.enum>lastreg then
-            internalerror(200301081);
-         if reg2.enum>lastreg then
-            internalerror(200301081);
-         if (reg1.enum <> reg2.enum) or
+         if reg1.enum<>R_INTREGISTER then
+           internalerror(200303101);
+         if reg2.enum<>R_INTREGISTER then
+           internalerror(200303102);
+         if (reg1.number<>reg2.number) or
             (tcgsize2size[tosize] < tcgsize2size[fromsize]) or
             ((tcgsize2size[tosize] = tcgsize2size[fromsize]) and
              (tosize <> fromsize) and
@@ -471,7 +471,7 @@ const
           end;
          ref2 := ref;
          freereg := fixref(list,ref2);
-         op := fpuloadinstr[size,ref2.index.enum <> R_NO,false];
+         op := fpuloadinstr[size,ref2.index.number <> NR_NO,false];
          a_load_store(list,op,reg,ref2);
          if freereg then
            cg.free_scratch_reg(list,ref2.base);
@@ -495,7 +495,7 @@ const
            internalerror(200201122);
          ref2 := ref;
          freereg := fixref(list,ref2);
-         op := fpustoreinstr[size,ref2.index.enum <> R_NO,false];
+         op := fpustoreinstr[size,ref2.index.number <> NR_NO,false];
          a_load_store(list,op,reg,ref2);
          if freereg then
            cg.free_scratch_reg(list,ref2.base);
@@ -535,8 +535,8 @@ const
           end;
 
       begin
-        if src.enum>lastreg then
-          internalerror(200301081);
+         if src.enum<>R_INTREGISTER then
+           internalerror(200303102);
         if op = OP_SUB then
           begin
 {$ifopt q+}
@@ -653,7 +653,7 @@ const
           OP_OR:
             { try to use rlwimi }
             if gotrlwi and
-               (src.enum = dst.enum) then
+               (src.number = dst.number) then
               begin
                 scratchreg := get_scratch_reg_int(list,OS_INT);
                 list.concat(taicpu.op_reg_const(A_LI,scratchreg,-1));
@@ -942,7 +942,7 @@ const
      { sum of the size necessary for local variables and the maximum possible   }
      { combined size of ALL the parameters of a procedure called by the current }
      { one                                                                      }
-     var regcounter,firstregfpu,firstreggpr : TRegister;
+     var regcounter,firstregfpu,firstreggpr, regcounter2 : TRegister;
          href : treference;
          usesfpr,usesgpr,gotgot : boolean;
          parastart : aword;
@@ -956,13 +956,20 @@ const
         { procedure, but currently this isn't checked, so save them always         }
         { following is the entry code as described in "Altivec Programming }
         { Interface Manual", bar the saving of AltiVec registers           }
-        rsp.enum:=stack_pointer_reg;
+        rsp.enum:=R_INTREGISTER;
+        rsp.number:=NR_STACK_POINTER_REG;;
         a_reg_alloc(list,rsp);
-        r.enum:=R_0;
+        r.enum:=R_INTREGISTER;
+        r.number:=NR_R0;
         a_reg_alloc(list,r);
         { allocate registers containing reg parameters }
+        regcounter2.enum := R_INTREGISTER;
+        regcounter2.number := NR_R3;
         for regcounter.enum := R_3 to R_10 do
-          a_reg_alloc(list,regcounter);
+          begin
+            a_reg_alloc(list,regcounter2);
+            inc(regcounter2.number,NR_R1-NR_R0);
+          end;
 
         usesfpr:=false;
         for regcounter.enum:=R_F14 to R_F31 do
@@ -974,19 +981,25 @@ const
             end;
 
         usesgpr:=false;
+        regcounter2.enum := R_INTREGISTER;
+        regcounter2.number := NR_R14;
         for regcounter.enum:=R_14 to R_31 do
-          if regcounter.enum in rg.usedbyproc then
-            begin
-               usesgpr:=true;
-               firstreggpr:=regcounter;
-               break;
-            end;
+          begin
+            if regcounter.enum in rg.usedbyproc then
+              begin
+                 usesgpr:=true;
+                 firstreggpr:=regcounter;
+                 break;
+              end;
+           inc(regcounter2.number,NR_R1-NR_R0);
+         end;
 
         { save link register? }
         if (procinfo.flags and pi_do_call)<>0 then
           begin
              { save return address... }
-             r.enum:=R_0;
+             r.enum:=R_INTREGISTER;
+             r.number:=NR_R0;
              list.concat(taicpu.op_reg(A_MFLR,r));
              { ... in caller's rframe }
              reference_reset_base(href,rsp,4);
@@ -996,7 +1009,8 @@ const
 
         if usesfpr or usesgpr then
           begin
-             r.enum:=R_11;
+             r.enum:=R_INTREGISTER;
+             r.number:=NR_R11;
              a_reg_alloc(list,r);
              { save end of fpr save area }
              list.concat(taicpu.op_reg_reg_const(A_ORI,r,rsp,0));
@@ -1004,7 +1018,7 @@ const
 
         { calculate the size of the locals }
         if usesgpr then
-          inc(localsize,(ord(R_31)-ord(firstreggpr.enum)+1)*4);
+          inc(localsize,(NR_R31-firstreggpr.number+1)*4);
         if usesfpr then
           inc(localsize,(ord(R_F31)-ord(firstregfpu.enum)+1)*8);
 
@@ -1017,7 +1031,8 @@ const
 
         tppcprocinfo(procinfo).localsize:=localsize;
 
-        r.enum:=R_1;
+        r.enum:=R_INTREGISTER;
+        r.number:=NR_STACK_POINTER_REG;
         reference_reset_base(href,r,-localsize);
         a_load_store(list,A_STWU,r,href);
 
@@ -1043,7 +1058,8 @@ const
                  end;
 
              { compute end of gpr save area }
-             r.enum:=R_11;
+             r.enum:=R_INTREGISTER;
+             r.number:=NR_R11;
              list.concat(taicpu.op_reg_reg_const(A_ADDI,r,r,-(ord(R_F31)-ord(firstregfpu.enum)+1)*8));
           end;
 
@@ -1059,12 +1075,14 @@ const
              else
                a_call_name(objectlibrary.newasmsymbol('_savegpr_'+tostr(ord(firstreggpr)-ord(R_14)+14))
              }
-             r.enum:=R_11;
-             reference_reset_base(href,r,-(ord(R_31)-ord(firstreggpr.enum)+1)*4);
+             r.enum:=R_INTREGISTER;
+             r.number:=NR_R11;
+             reference_reset_base(href,r,-((NR_R31-firstreggpr.number) div (NR_R1-NR_R0)+1)*4);
              list.concat(taicpu.op_reg_ref(A_STMW,firstreggpr,href));
           end;
 
-        r.enum:=R_11;
+        r.enum:=R_INTREGISTER;
+        r.number:=NR_R11;
         if usesfpr or usesgpr then
           a_reg_dealloc(list,r);
 
@@ -1076,7 +1094,8 @@ const
                begin
                   {!!!!!!!!!!!!!}
                end;
-             r.enum:=R_31;
+             r.enum:=R_INTREGISTER;
+             r.number:=NR_R31;
              r2.enum:=R_LR;
              a_reg_alloc(list,r);
              { place GOT ptr in r31 }
@@ -1095,15 +1114,20 @@ const
     procedure tcgppc.g_return_from_proc_sysv(list : taasmoutput;parasize : aword);
 
       var
-         regcounter,firstregfpu,firstreggpr : TRegister;
+         regcounter,firstregfpu,firstreggpr, regcounter2 : TRegister;
          href : treference;
          usesfpr,usesgpr,genret : boolean;
          r,r2:Tregister;
 
       begin
         { release parameter registers }
+        regcounter2.enum := R_INTREGISTER;
+        regcounter2.number := NR_R3;
         for regcounter.enum := R_3 to R_10 do
-          a_reg_dealloc(list,regcounter);
+          begin
+            a_reg_dealloc(list,regcounter2);
+            inc(regcounter2.number,NR_R1-NR_R0);
+          end;
         { AltiVec context restore, not yet implemented !!! }
 
         usesfpr:=false;
@@ -1116,21 +1140,28 @@ const
             end;
 
         usesgpr:=false;
+        regcounter2.enum := R_INTREGISTER;
+        regcounter2.number := NR_R14;
         for regcounter.enum:=R_14 to R_30 do
-          if regcounter.enum in rg.usedbyproc then
-            begin
-               usesgpr:=true;
-               firstreggpr:=regcounter;
-               break;
-            end;
+          begin
+            if regcounter.enum in rg.usedbyproc then
+              begin
+                 usesgpr:=true;
+                 firstreggpr:=regcounter2;
+                 break;
+              end;
+            inc(regcounter2.number,NR_R1-NR_R0);
+          end;
 
         { no return (blr) generated yet }
         genret:=true;
         if usesgpr then
           begin
              { address of gpr save area to r11 }
-             r.enum:=R_1;
-             r2.enum:=R_11;
+             r.enum:=R_INTREGISTER;
+             r.number:=NR_STACK_POINTER_REG;
+             r2.enum:=R_INTREGISTER;
+             r2.number:=NR_R11;
              if usesfpr then
                list.concat(taicpu.op_reg_reg_const(A_ADDI,r2,r,tppcprocinfo(procinfo).localsize-(ord(R_F31)-ord(firstregfpu.enum)+1)*8))
              else
@@ -1149,7 +1180,8 @@ const
         if usesfpr then
           begin
              { address of fpr save area to r11 }
-             r.enum:=R_11;
+             r.enum:=R_INTREGISTER;
+             r.number:=NR_R11;
              list.concat(taicpu.op_reg_reg_const(A_ADDI,r,r,(ord(R_F31)-ord(firstregfpu.enum)+1)*8));
              {
              if (procinfo.flags and pi_do_call)<>0 then
@@ -1166,14 +1198,17 @@ const
         if genret then
           begin
              { adjust r1 }
-             r.enum:=R_1;
+             r.enum:=R_INTREGISTER;
+             r.number:=NR_R1;
              a_op_const_reg(list,OP_ADD,tppcprocinfo(procinfo).localsize,r);
              { load link register? }
              if (procinfo.flags and pi_do_call)<>0 then
                begin
-                  r.enum:=stack_pointer_reg;
+                  r.enum:=R_INTREGISTER;
+                  r.number:=NR_STACK_POINTER_REG;
                   reference_reset_base(href,r,4);
-                  r.enum:=R_0;
+                  r.enum:=R_INTREGISTER;
+                  r.number:=NR_R0;
                   list.concat(taicpu.op_reg_ref(A_LWZ,r,href));
                   list.concat(taicpu.op_reg(A_MTLR,r));
                end;
@@ -1186,7 +1221,7 @@ const
      the save area right below the address the stackpointer point to.
      Returns the actual used save area size.}
 
-     var regcounter,firstregfpu,firstreggpr: TRegister;
+     var regcounter,firstregfpu,firstreggpr, regcounter2: TRegister;
          usesfpr,usesgpr: boolean;
          href : treference;
          offset: integer;
@@ -1203,14 +1238,18 @@ const
           end;
 
       usesgpr:=false;
+      r.enum := R_INTREGISTER;
+      r.number := NR_R13;
       for regcounter.enum:=R_13 to R_31 do
-        if regcounter.enum in rg.usedbyproc then
-          begin
-             usesgpr:=true;
-             firstreggpr:=regcounter;
-             break;
-          end;
-
+        begin
+          if regcounter.enum in rg.usedbyproc then
+            begin
+               usesgpr:=true;
+               firstreggpr:=r;
+               break;
+            end;
+          inc(r.number,NR_R1-NR_R0);
+        end;
       offset:= 0;
 
       { save floating-point registers }
@@ -1218,7 +1257,8 @@ const
         for regcounter.enum := firstregfpu.enum to R_F31 do
           begin
             offset:= offset - 8;
-            r.enum:=stack_pointer_reg;
+            r.enum:=R_INTREGISTER;
+            r.number:=NR_STACK_POINTER_REG;
             reference_reset_base(href, r, offset);
             list.concat(taicpu.op_reg_ref(A_STFD, regcounter, href));
           end;
@@ -1229,19 +1269,24 @@ const
         if firstreggpr.enum < R_30 then
           begin
             offset:= offset - 4 * (ord(R_31) - ord(firstreggpr.enum) + 1);
-            r.enum:=stack_pointer_reg;
+            r.enum:=R_INTREGISTER;
+            r.number:=NR_STACK_POINTER_REG;
             reference_reset_base(href,r,offset);
             list.concat(taicpu.op_reg_ref(A_STMW,firstreggpr,href));
               {STMW stores multiple registers}
           end
         else
           begin
+            regcounter2 := firstreggpr;
+            convert_register_to_enum(firstreggpr);
             for regcounter.enum := firstreggpr.enum to R_31 do
               begin
                 offset:= offset - 4;
-                r.enum:=stack_pointer_reg;
+                r.enum:=R_INTREGISTER;
+                r.number:=NR_STACK_POINTER_REG;
                 reference_reset_base(href, r, offset);
-                list.concat(taicpu.op_reg_ref(A_STW, regcounter, href));
+                list.concat(taicpu.op_reg_ref(A_STW, regcounter2, href));
+                inc(regcounter2.number,NR_R1-NR_R0);
               end;
           end;
 
@@ -1254,7 +1299,7 @@ const
     {Generates code which restores used non-volatile registers from
     the save area right below the address the stackpointer point to.}
 
-     var regcounter,firstregfpu,firstreggpr: TRegister;
+     var regcounter,firstregfpu,firstreggpr,regcounter2: TRegister;
          usesfpr,usesgpr: boolean;
          href : treference;
          offset: integer;
@@ -1271,13 +1316,18 @@ const
           end;
 
       usesgpr:=false;
+      r.enum := R_INTREGISTER;
+      r.number := NR_R13;
       for regcounter.enum:=R_13 to R_31 do
-        if regcounter.enum in rg.usedbyproc then
-          begin
-             usesgpr:=true;
-             firstreggpr:=regcounter;
-             break;
-          end;
+        begin
+          if regcounter.enum in rg.usedbyproc then
+            begin
+               usesgpr:=true;
+               firstreggpr:=r;
+               break;
+            end;
+          inc(r.number,NR_R1-NR_R0);
+        end;
 
       offset:= 0;
 
@@ -1286,7 +1336,8 @@ const
         for regcounter.enum := firstregfpu.enum to R_F31 do
           begin
             offset:= offset - 8;
-            r.enum:=stack_pointer_reg;
+            r.enum:=R_INTREGISTER;
+            r.number:=NR_STACK_POINTER_REG;
             reference_reset_base(href, r, offset);
             list.concat(taicpu.op_reg_ref(A_LFD, regcounter, href));
           end;
@@ -1297,19 +1348,24 @@ const
         if firstreggpr.enum < R_30 then
           begin
             offset:= offset - 4 * (ord(R_31) - ord(firstreggpr.enum) + 1);
-            r.enum:=stack_pointer_reg;
+            r.enum:=R_INTREGISTER;
+            r.number:=NR_STACK_POINTER_REG;
             reference_reset_base(href,r,offset); //-220
             list.concat(taicpu.op_reg_ref(A_LMW,firstreggpr,href));
               {LMW loads multiple registers}
           end
         else
           begin
+            regcounter2 := firstreggpr;
+            convert_register_to_enum(firstreggpr);
             for regcounter.enum := firstreggpr.enum to R_31 do
               begin
                 offset:= offset - 4;
-                r.enum:=stack_pointer_reg;
+                r.enum:=R_INTREGISTER;
+                r.number:=NR_STACK_POINTER_REG;
                 reference_reset_base(href, r, offset);
-                list.concat(taicpu.op_reg_ref(A_LWZ, regcounter, href));
+                list.concat(taicpu.op_reg_ref(A_LWZ, regcounter2, href));
+                inc(regcounter2.number,NR_R1-NR_R0);
               end;
           end;
 
@@ -1326,7 +1382,7 @@ const
      const
          macosLinkageAreaSize = 24;
 
-     var regcounter: TRegister;
+     var regcounter,regcounter2: TRegister;
          href : treference;
          registerSaveAreaSize : longint;
          r,r2,rsp:Tregister;
@@ -1337,14 +1393,22 @@ const
         { procedure, but currently this isn't checked, so save them always         }
         { following is the entry code as described in "Altivec Programming }
         { Interface Manual", bar the saving of AltiVec registers           }
-        r.enum:=R_0;
-        rsp.enum:=stack_pointer_reg;
+        r.enum:=R_INTREGISTER;
+        r.number:=NR_R0;
+        rsp.enum:=R_INTREGISTER;
+        rsp.number:=NR_STACK_POINTER_REG;
         a_reg_alloc(list,rsp);
         a_reg_alloc(list,r);
 
         { allocate registers containing reg parameters }
+        regcounter2.enum := R_INTREGISTER;
+        regcounter2.number := NR_R3;
         for regcounter.enum := R_3 to R_10 do
-          a_reg_alloc(list,regcounter);
+          begin
+            a_reg_alloc(list,regcounter2);
+            inc(regcounter2.number,NR_R1-NR_R0);
+          end;
+
         {TODO: Allocate fp and altivec parameter registers also}
 
         { save return address in callers frame}
@@ -1392,7 +1456,8 @@ const
         localsize:=align(localsize,16);
         tppcprocinfo(procinfo).localsize:=localsize;
 
-        r.enum:=R_1;
+        r.enum:=R_INTREGISTER;
+        r.number:=NR_STACK_POINTER_REG;
         reference_reset_base(href,r,-localsize);
         a_load_store(list,A_STWU,r,href);
           { this also stores the old stack pointer in the new stack frame }
@@ -1401,17 +1466,24 @@ const
     procedure tcgppc.g_return_from_proc_mac(list : taasmoutput;parasize : aword);
 
       var
-        regcounter: TRegister;
+        regcounter, regcounter2: TRegister;
         href : treference;
         r,r2,rsp:Tregister;
       begin
         { release parameter registers }
+        regcounter2.enum := R_INTREGISTER;
+        regcounter2.number := NR_R3;
         for regcounter.enum := R_3 to R_10 do
-          a_reg_dealloc(list,regcounter);
+          begin
+            a_reg_dealloc(list,regcounter2);
+            inc(regcounter2.number,NR_R1-NR_R0);
+          end;
         {TODO: Release fp and altivec parameter registers also}
 
-        r.enum:=R_0;
-        rsp.enum:=stack_pointer_reg;
+        r.enum:=R_INTREGISTER;
+        r.number:=NR_R0;
+        rsp.enum:=R_INTREGISTER;
+        rsp.number:=NR_STACK_POINTER_REG;
         a_reg_alloc(list,r);
 
         { restore stack pointer }
@@ -1424,7 +1496,8 @@ const
         { restore the CR if necessary from callers frame
             ( !!! always done currently ) }
         reference_reset_base(href,rsp,LA_CR);
-        r.enum:=R_0;
+        r.enum:=R_INTREGISTER;
+        r.number:=NR_R0;
         list.concat(taicpu.op_reg_ref(A_LWZ,r,href));
         r2.enum:=R_CR;
         list.concat(taicpu.op_reg_reg(A_MTSPR,r,r2));
@@ -1446,7 +1519,8 @@ const
         *)
 
         { restore return address from callers frame }
-        r.enum:=R_0;
+        r.enum:=R_INTREGISTER;
+        r.number:=NR_R0;
         r2.enum:=R_LR;
         reference_reset_base(href,rsp,8);
         list.concat(taicpu.op_reg_ref(A_LWZ,r,href));
@@ -1478,7 +1552,7 @@ const
            begin
              if target_info.system = system_powerpc_macos then
                begin
-                 if ref2.base.enum <> R_NO then
+                 if ref2.base.number <> NR_NO then
                    internalerror(2002103102); //TODO: Implement this if needed
 
                  if macos_direct_globals then
@@ -1487,8 +1561,9 @@ const
                      tmpref.offset := ref2.offset;
                      tmpref.symbol := ref2.symbol;
                      tmpref.symaddr := refs_full;
-                     tmpref.base.enum := R_NO;
-                     r2.enum:=R_TOC;
+                     tmpref.base.number := NR_NO;
+                     r2.enum:=R_INTREGISTER;
+                     r2.number:=NR_RTOC;
                      list.concat(taicpu.op_reg_reg_ref(A_ADDI,r,r2,tmpref));
                    end
                  else
@@ -1498,7 +1573,8 @@ const
                      tmpref.symbol := ref2.symbol;
                      tmpref.offset := ref2.offset;
                      tmpref.symaddr := refs_full;
-                     tmpref.base.enum:= R_TOC;
+                     tmpref.base.enum := R_INTREGISTER;
+                     tmpref.base.number := NR_RTOC;
                      list.concat(taicpu.op_reg_ref(A_LWZ,tmpreg,tmpref));
 
                      reference_reset(tmpref);
@@ -1519,7 +1595,7 @@ const
                  tmpref.offset := ref2.offset;
                  tmpref.symbol := ref2.symbol;
                  tmpref.symaddr := refs_ha;
-                 if ref2.base .enum<> R_NO then
+                 if ref2.base .number<> NR_NO then
                    begin
                      list.concat(taicpu.op_reg_reg_ref(A_ADDIS,r,
                        ref2.base,tmpref));
@@ -1531,7 +1607,7 @@ const
                    end
                  else
                    list.concat(taicpu.op_reg_ref(A_LIS,r,tmpref));
-                 tmpref.base.enum := R_NO;
+                 tmpref.base.number := NR_NO;
                  tmpref.symaddr := refs_l;
                  { can be folded with one of the next instructions by the }
                  { optimizer probably                                     }
@@ -1539,16 +1615,16 @@ const
                end
            end
          else if ref2.offset <> 0 Then
-           if ref2.base.enum <> R_NO then
+           if ref2.base.number <> NR_NO then
              a_op_const_reg_reg(list,OP_ADD,OS_32,ref2.offset,ref2.base,r)
            { FixRef makes sure that "(ref.index <> R_NO) and (ref.offset <> 0)" never}
            { occurs, so now only ref.offset has to be loaded                         }
            else
              a_load_const_reg(list,OS_32,ref2.offset,r)
-         else if ref.index.enum <> R_NO Then
+         else if ref.index.number <> NR_NO Then
            list.concat(taicpu.op_reg_reg_reg(A_ADD,r,ref2.base,ref2.index))
-         else if (ref2.base.enum <> R_NO) and
-                 (r.enum <> ref2.base.enum) then
+         else if (ref2.base.number <> NR_NO) and
+                 (r.number <> ref2.base.number) then
            list.concat(taicpu.op_reg_reg(A_MR,r,ref2.base));
          if freereg then
            cg.free_scratch_reg(list,ref2.base);
@@ -1606,7 +1682,7 @@ const
             orgsrc := false;
           end
         else if not issimpleref(source) or
-                ((source.index.enum <> R_NO) and
+                ((source.index.number <> NR_NO) and
                  ((source.offset + longint(len)) > high(smallint))) then
           begin
             src.base := get_scratch_reg_address(list);
@@ -1622,7 +1698,7 @@ const
           reference_release(list,source);
         { load the address of dest into dst.base }
         if not issimpleref(dest) or
-           ((dest.index.enum <> R_NO) and
+           ((dest.index.number <> NR_NO) and
             ((dest.offset + longint(len)) > high(smallint))) then
           begin
             dst.base := get_scratch_reg_address(list);
@@ -1684,7 +1760,8 @@ const
 
         if (len and 4) <> 0 then
           begin
-            r.enum:=R_0;
+            r.enum:=R_INTREGISTER;
+            r.number:=NR_R0;
             a_reg_alloc(list,r);
             a_load_ref_reg(list,OS_32,src,r);
             a_load_reg_ref(list,OS_32,r,dst);
@@ -1695,7 +1772,8 @@ const
        { copy the leftovers }
        if (len and 2) <> 0 then
          begin
-           r.enum:=R_0;
+           r.enum:=R_INTREGISTER;
+           r.number:=NR_R0;
            a_reg_alloc(list,r);
            a_load_ref_reg(list,OS_16,src,r);
            a_load_reg_ref(list,OS_16,r,dst);
@@ -1705,7 +1783,8 @@ const
          end;
        if (len and 1) <> 0 then
          begin
-           r.enum:=R_0;
+           r.enum:=R_INTREGISTER;
+           r.number:=NR_R0;
            a_reg_alloc(list,r);
            a_load_ref_reg(list,OS_8,src,r);
            a_load_reg_ref(list,OS_8,r,dst);
@@ -1753,15 +1832,15 @@ const
     function tcgppc.issimpleref(const ref: treference): boolean;
 
       begin
-        if (ref.base.enum = R_NO) and
-           (ref.index.enum <> R_NO) then
+        if (ref.base.number = NR_NO) and
+           (ref.index.number <> NR_NO) then
           internalerror(200208101);
         result :=
           not(assigned(ref.symbol)) and
-          (((ref.index.enum = R_NO) and
+          (((ref.index.number = NR_NO) and
             (ref.offset >= low(smallint)) and
             (ref.offset <= high(smallint))) or
-           ((ref.index.enum <> R_NO) and
+           ((ref.index.number <> NR_NO) and
             (ref.offset = 0)));
       end;
 
@@ -1772,9 +1851,11 @@ const
          tmpreg: tregister;
        begin
          result := false;
-         if (ref.base.enum <> R_NO) then
+         if (ref.base.number = NR_NO) then
+           ref.base := ref.index;
+         if (ref.base.number <> NR_NO) then
            begin
-             if (ref.index.enum <> R_NO) and
+             if (ref.index.number <> NR_NO) and
                 ((ref.offset <> 0) or assigned(ref.symbol)) then
                begin
                  result := true;
@@ -1791,13 +1872,13 @@ const
                    begin
                      list.concat(taicpu.op_reg_reg_reg(
                        A_ADD,tmpreg,ref.base,ref.index));
-                     ref.index.enum := R_NO;
+                     ref.index.number := NR_NO;
                    end;
                  ref.base := tmpreg;
                end
            end
          else
-           if ref.index.enum <> R_NO then
+           if ref.index.number <> NR_NO then
              internalerror(200208102);
        end;
 
@@ -1879,14 +1960,14 @@ const
         r : Tregister;
 
       begin
-        tmpreg.enum := R_NO;
+        tmpreg.number := NR_NO;
         if assigned(ref.symbol) or
            (cardinal(ref.offset-low(smallint)) >
             high(smallint)-low(smallint)) then
           begin
             if target_info.system = system_powerpc_macos then
               begin
-                if ref.base.enum <> R_NO then
+                if ref.base.number <> NR_NO then
                   begin
                     if macos_direct_globals then
                       begin
@@ -1906,7 +1987,8 @@ const
                         tmpref.symaddr := refs_full;
                         tmpref.base:= tmpreg;
 
-                        r.enum:=R_TOC;
+                        r.enum:=R_INTREGISTER;
+                        r.number:=NR_RTOC;
                         list.concat(taicpu.op_reg_reg_reg(A_ADD,tmpreg,
                             ref.base,r));
                         list.concat(taicpu.op_reg_ref(op,reg,tmpref));
@@ -1918,7 +2000,8 @@ const
                         tmpref.symbol := ref.symbol;
                         tmpref.offset := ref.offset;
                         tmpref.symaddr := refs_full;
-                        tmpref.base.enum:= R_TOC;
+                        tmpref.base.enum:= R_INTREGISTER;
+                        tmpref.base.number:= NR_RTOC;
                         list.concat(taicpu.op_reg_ref(A_LWZ,tmpreg,tmpref));
                         list.concat(taicpu.op_reg_reg_reg(A_ADD,tmpreg,
                             ref.base,tmpreg));
@@ -1941,7 +2024,8 @@ const
                         tmpref.symbol := ref.symbol;
                         tmpref.offset := ref.offset;
                         tmpref.symaddr := refs_full;
-                        tmpref.base.enum:= R_TOC;
+                        tmpref.base.enum:= R_INTREGISTER;
+                        tmpref.base.number:= NR_RTOC;
                         list.concat(taicpu.op_reg_ref(op,reg,tmpref));
                       end
                     else
@@ -1951,7 +2035,8 @@ const
                         tmpref.symbol := ref.symbol;
                         tmpref.offset := ref.offset;
                         tmpref.symaddr := refs_full;
-                        tmpref.base.enum:= R_TOC;
+                        tmpref.base.enum:= R_INTREGISTER;
+                        tmpref.base.number:= NR_R0;
                         list.concat(taicpu.op_reg_ref(A_LWZ,tmpreg,tmpref));
 
                         reference_reset(tmpref);
@@ -1971,7 +2056,7 @@ const
                 tmpref.symbol := ref.symbol;
                 tmpref.offset := ref.offset;
                 tmpref.symaddr := refs_ha;
-                if ref.base.enum <> R_NO then
+                if ref.base.number <> NR_NO then
                   list.concat(taicpu.op_reg_reg_ref(A_ADDIS,tmpreg,
                     ref.base,tmpref))
                 else
@@ -1983,7 +2068,7 @@ const
           end
         else
           list.concat(taicpu.op_reg_ref(op,reg,ref));
-        if (tmpreg.enum <> R_NO) then
+        if (tmpreg.number <> NR_NO) then
           free_scratch_reg(list,tmpreg);
       end;
 
@@ -2107,7 +2192,11 @@ begin
 end.
 {
   $Log$
-  Revision 1.71  2003-02-19 22:00:16  daniel
+  Revision 1.72  2003-03-11 21:46:24  jonas
+    * lots of new regallocator fixes, both in generic and ppc-specific code
+      (ppc compiler still can't compile the linux system unit though)
+
+  Revision 1.71  2003/02/19 22:00:16  daniel
     * Code generator converted to new register notation
     - Horribily outdated todo.txt removed
 

+ 7 - 1
compiler/powerpc/cpubase.pas

@@ -218,6 +218,8 @@ uses
       NR_R27 = $1C00; NR_R28 = $1D00; NR_R29 = $1E00;
       NR_R30 = $1F00; NR_R31 = $2000;
 
+      NR_RTOC = NR_R3;
+
     {Super registers:}
       RS_R0 = $01; RS_R1 = $02; RS_R2 = $03;
       RS_R3 = $04; RS_R4 = $05; RS_R5 = $06;
@@ -874,7 +876,11 @@ implementation
 end.
 {
   $Log$
-  Revision 1.44  2003-02-19 22:00:16  daniel
+  Revision 1.45  2003-03-11 21:46:24  jonas
+    * lots of new regallocator fixes, both in generic and ppc-specific code
+      (ppc compiler still can't compile the linux system unit though)
+
+  Revision 1.44  2003/02/19 22:00:16  daniel
     * Code generator converted to new register notation
     - Horribily outdated todo.txt removed
 

+ 34 - 19
compiler/powerpc/cpupara.pas

@@ -55,12 +55,14 @@ unit cpupara;
          else if nr<=8 then
            begin
               result.loc:=LOC_REGISTER;
-              result.register.enum:=Toldregister(longint(R_2)+nr);
+              result.register.enum:=R_INTREGISTER;
+              result.register.number:=NR_R2+nr*(NR_R1-NR_R0);
            end
          else
            begin
               result.loc:=LOC_REFERENCE;
-              result.reference.index.enum:=stack_pointer_reg;
+              result.reference.index.enum:=R_INTREGISTER;
+              result.reference.index.number:=NR_STACK_POINTER_REG;
               result.reference.offset:=(nr-8)*4;
            end;
       end;
@@ -132,23 +134,25 @@ unit cpupara;
       procedure assignintreg;
 
         begin
-           if nextintreg.enum<=R_10 then
+           if nextintreg.number<=NR_R10 then
              begin
                 hp.paraloc.loc:=LOC_REGISTER;
                 hp.paraloc.register:=nextintreg;
-                inc(nextintreg.enum);
+                inc(nextintreg.number,NR_R1-NR_R0);
              end
            else
               begin
                  hp.paraloc.loc:=LOC_REFERENCE;
-                 hp.paraloc.reference.index.enum:=stack_pointer_reg;
+                 hp.paraloc.reference.index.enum:=R_INTREGISTER;
+                 hp.paraloc.reference.index.number:=NR_STACK_POINTER_REG;
                  hp.paraloc.reference.offset:=stack_offset;
                  inc(stack_offset,4);
              end;
         end;
 
       begin
-         nextintreg.enum:=R_3;
+         nextintreg.enum:=R_INTREGISTER;
+         nextintreg.number:=NR_R3;
          nextfloatreg.enum:=R_F1;
          nextmmreg.enum:=R_M1;
          stack_offset:=0;
@@ -156,7 +160,7 @@ unit cpupara;
          if not is_void(p.rettype.def) then
            begin
               if not(ret_in_reg(p.rettype.def,p.proccalloption)) then
-                inc(nextintreg.enum);
+                inc(nextintreg.number,NR_R1-NR_R0);
            end;
 
          { frame pointer for nested procedures? }
@@ -176,22 +180,23 @@ unit cpupara;
                       if hp.paraloc.size = OS_NO then
                         hp.paraloc.size := OS_ADDR;
                       is_64bit := hp.paraloc.size in [OS_64,OS_S64];
-                      if nextintreg.enum<=Toldregister(ord(R_10)-ord(is_64bit))  then
+                      if nextintreg.number<=(NR_R10-ord(is_64bit)*(NR_R1-NR_R0))  then
                         begin
                            hp.paraloc.loc:=LOC_REGISTER;
                            hp.paraloc.registerlow:=nextintreg;
-                           inc(nextintreg.enum);
+                           inc(nextintreg.number,NR_R1-NR_R0);
                            if is_64bit then
                              begin
                                hp.paraloc.registerhigh:=nextintreg;
-                               inc(nextintreg.enum);
+                               inc(nextintreg.number,NR_R1-NR_R0);
                              end;
                         end
                       else
                          begin
-                            nextintreg.enum := R_11;
+                            nextintreg.number := NR_R11;
                             hp.paraloc.loc:=LOC_REFERENCE;
-                            hp.paraloc.reference.index.enum:=stack_pointer_reg;
+                            hp.paraloc.reference.index.enum:=R_INTREGISTER;
+                            hp.paraloc.reference.index.number:=NR_STACK_POINTER_REG;
                             hp.paraloc.reference.offset:=stack_offset;
                             if not is_64bit then
                               inc(stack_offset,4)
@@ -203,12 +208,12 @@ unit cpupara;
                    begin
                       if hp.paratyp in [vs_var,vs_out] then
                         begin
-                            if nextintreg.enum<=R_10 then
+                            if nextintreg.number<=NR_R10 then
                              begin
                                 hp.paraloc.size:=OS_ADDR;
                                 hp.paraloc.loc:=LOC_REGISTER;
                                 hp.paraloc.register:=nextintreg;
-                                inc(nextintreg.enum);
+                                inc(nextintreg.number,NR_R1-NR_R0);
                              end
                            else
                               begin
@@ -242,7 +247,8 @@ unit cpupara;
                       else
                         begin
                            hp.paraloc.loc:=LOC_REFERENCE;
-                           hp.paraloc.reference.index.enum:=stack_pointer_reg;
+                           hp.paraloc.reference.index.enum:=R_INTREGISTER;
+                           hp.paraloc.reference.index.number:=NR_STACK_POINTER_REG;
                            hp.paraloc.reference.offset:=stack_offset;
                            inc(stack_offset,hp.paratype.def.size);
                         end;
@@ -261,10 +267,14 @@ unit cpupara;
             enumdef:
               begin
                 getfuncretparaloc.loc:=LOC_REGISTER;
-                getfuncretparaloc.register.enum:=R_3;
+                getfuncretparaloc.register.enum:=R_INTREGISTER;
+                getfuncretparaloc.register.number:=NR_R3;
                 getfuncretparaloc.size:=def_cgsize(p.rettype.def);
                 if getfuncretparaloc.size in [OS_S64,OS_64] then
-                  getfuncretparaloc.registerhigh.enum:=R_4;
+                  begin
+                    getfuncretparaloc.registerhigh.enum:=R_INTREGISTER;
+                    getfuncretparaloc.registerhigh.number:=NR_R4;
+                  end;
               end;
             floatdef:
               begin
@@ -288,7 +298,8 @@ unit cpupara;
             errordef:
               begin
                 getfuncretparaloc.loc:=LOC_REGISTER;
-                getfuncretparaloc.register.enum:=R_3;
+                getfuncretparaloc.register.enum:=R_INTREGISTER;
+                getfuncretparaloc.register.number:=NR_R3;
                 getfuncretparaloc.size:=OS_ADDR;
               end;
             else
@@ -302,7 +313,11 @@ begin
 end.
 {
   $Log$
-  Revision 1.22  2003-01-09 22:00:53  florian
+  Revision 1.23  2003-03-11 21:46:24  jonas
+    * lots of new regallocator fixes, both in generic and ppc-specific code
+      (ppc compiler still can't compile the linux system unit though)
+
+  Revision 1.22  2003/01/09 22:00:53  florian
     * fixed some PowerPC issues
 
   Revision 1.21  2003/01/09 20:41:10  florian

+ 33 - 18
compiler/powerpc/nppcadd.pas

@@ -164,19 +164,29 @@ interface
       begin
         if (right.location.loc in [LOC_REGISTER,LOC_FPUREGISTER]) and
            (cmpop or
-            (location.register.enum <> right.location.register.enum)) then
+            ((location.register.enum = R_INTREGISTER) and
+             (location.register.number <> right.location.register.number)) or
+              (location.register.enum <> right.location.register.enum)) then
           begin
-            rg.ungetregisterint(exprasmlist,right.location.register);
+            if (right.location.register.enum = R_INTREGISTER) then
+              rg.ungetregisterint(exprasmlist,right.location.register)
+            else
+              rg.ungetregister(exprasmlist,right.location.register);
             if is_64bitint(right.resulttype.def) then
-              rg.ungetregisterint(exprasmlist,right.location.registerhigh);
+              rg.ungetregisterint(exprasmlist,right.location.registerhigh)
           end;
         if (left.location.loc in [LOC_REGISTER,LOC_FPUREGISTER]) and
            (cmpop or
-            (location.register.enum <> left.location.register.enum)) then
+            ((location.register.enum = R_INTREGISTER) and
+             (location.register.number <> left.location.register.number)) or
+              (location.register.enum <> left.location.register.enum)) then
           begin
-            rg.ungetregisterint(exprasmlist,left.location.register);
+            if (left.location.register.enum = R_INTREGISTER) then
+              rg.ungetregisterint(exprasmlist,left.location.register)
+            else
+              rg.ungetregister(exprasmlist,left.location.register);
             if is_64bitint(left.resulttype.def) then
-              rg.ungetregisterint(exprasmlist,left.location.registerhigh);
+              rg.ungetregisterint(exprasmlist,left.location.registerhigh)
           end;
       end;
 
@@ -223,7 +233,7 @@ interface
         if (right.location.loc = LOC_CONSTANT) then
           begin
 {$ifdef extdebug}
-            if (right.location.size in [OS_64,OS_S64]) and (hi(right.location.valueqword)<>0) and ((hi(right.location.valueqword)<>-1) or unsigned) then
+            if (right.location.size in [OS_64,OS_S64]) and (hi(right.location.valueqword)<>0) and ((hi(right.location.valueqword)<>cardinal(-1)) or unsigned) then
               internalerror(2002080301);
 {$endif extdebug}
             if (nodetype in [equaln,unequaln]) then
@@ -562,7 +572,7 @@ interface
         load_left_right(cmpop,false);
 
         if not(cmpop) and
-           (location.register.enum = R_NO) then
+           (location.register.number = NR_NO) then
           location.register := rg.getregisterint(exprasmlist,OS_INT);
 
         case nodetype of
@@ -939,14 +949,15 @@ interface
                          tempreg64);
                     end;
 
-                  r.enum:=R_0;
+                  r.enum:=R_INTREGISTER;
+                  r.number:=NR_R0;
                   cg.a_reg_alloc(exprasmlist,r);
                   exprasmlist.concat(taicpu.op_reg_reg_reg(A_OR_,r,
                     tempreg64.reglo,tempreg64.reghi));
                   cg.a_reg_dealloc(exprasmlist,r);
-                  if (tempreg64.reglo.enum <> left.location.registerlow.enum) then
+                  if (tempreg64.reglo.number <> left.location.registerlow.number) then
                     cg.free_scratch_reg(exprasmlist,tempreg64.reglo);
-                  if (tempreg64.reghi.enum <> left.location.registerhigh.enum) then
+                  if (tempreg64.reghi.number <> left.location.registerhigh.number) then
                     cg.free_scratch_reg(exprasmlist,tempreg64.reghi);
 
                   location_reset(location,LOC_FLAGS,OS_NO);
@@ -954,7 +965,7 @@ interface
                 end;
               xorn,orn,andn,addn:
                 begin
-                  if (location.registerlow.enum = R_NO) then
+                  if (location.registerlow.number = NR_NO) then
                     begin
                       location.registerlow := rg.getregisterint(exprasmlist,OS_INT);
                       location.registerhigh := rg.getregisterint(exprasmlist,OS_INT);
@@ -976,7 +987,7 @@ interface
 
                   if left.location.loc <> LOC_CONSTANT then
                     begin
-                      if (location.registerlow.enum = R_NO) then
+                      if (location.registerlow.number = NR_NO) then
                         begin
                          location.registerlow := rg.getregisterint(exprasmlist,OS_INT);
                          location.registerhigh := rg.getregisterint(exprasmlist,OS_INT);
@@ -994,7 +1005,7 @@ interface
                     end
                   else if ((left.location.valueqword shr 32) = 0) then
                     begin
-                      if (location.registerlow.enum = R_NO) then
+                      if (location.registerlow.number = NR_NO) then
                         begin
                          location.registerlow := rg.getregisterint(exprasmlist,OS_INT);
                          location.registerhigh := rg.getregisterint(exprasmlist,OS_INT);
@@ -1022,7 +1033,7 @@ interface
                   else if (aword(left.location.valueqword) = 0) then
                     begin
                       // (const32 shl 32) - reg64
-                      if (location.registerlow.enum = R_NO) then
+                      if (location.registerlow.number = NR_NO) then
                         begin
                          location.registerlow := rg.getregisterint(exprasmlist,OS_INT);
                          location.registerhigh := rg.getregisterint(exprasmlist,OS_INT);
@@ -1042,7 +1053,7 @@ interface
                         def_cgsize(left.resulttype.def),true);
                       if (left.location.loc = LOC_REGISTER) then
                         location.register64 := left.location.register64
-                      else if (location.registerlow.enum = R_NO) then
+                      else if (location.registerlow.number = NR_NO) then
                         begin
                          location.registerlow := rg.getregisterint(exprasmlist,OS_INT);
                          location.registerhigh := rg.getregisterint(exprasmlist,OS_INT);
@@ -1368,7 +1379,7 @@ interface
          load_left_right(cmpop, (cs_check_overflow in aktlocalswitches) and
             (nodetype in [addn,subn,muln]));
 
-         if (location.register.enum = R_NO) and
+         if (location.register.number = NR_NO) and
             not(cmpop) then
            location.register := rg.getregisterint(exprasmlist,OS_INT);
 
@@ -1468,7 +1479,11 @@ begin
 end.
 {
   $Log$
-  Revision 1.23  2003-03-10 18:11:41  olle
+  Revision 1.24  2003-03-11 21:46:24  jonas
+    * lots of new regallocator fixes, both in generic and ppc-specific code
+      (ppc compiler still can't compile the linux system unit though)
+
+  Revision 1.23  2003/03/10 18:11:41  olle
     * changed ungetregister to ungetregisterint in tppcaddnode.clear_left_right
 
   Revision 1.22  2003/02/19 22:00:16  daniel

+ 8 - 4
compiler/powerpc/nppccnv.pas

@@ -223,7 +223,7 @@ implementation
          if (left.location.loc = LOC_REGISTER) or
             ((left.location.loc = LOC_CREGISTER) and
              not signed) then
-           rg.ungetregister(exprasmlist,leftreg)
+           rg.ungetregisterint(exprasmlist,leftreg)
          else
            cg.free_scratch_reg(exprasmlist,valuereg);
 
@@ -298,7 +298,7 @@ implementation
                   hreg2,1));
                 exprasmlist.concat(taicpu.op_reg_reg_reg(A_SUBFE,hreg1,hreg1,
                   hreg2));
-                rg.ungetregister(exprasmlist,hreg2);
+                rg.ungetregisterint(exprasmlist,hreg2);
               end;
             LOC_FLAGS :
               begin
@@ -394,7 +394,11 @@ begin
 end.
 {
   $Log$
-  Revision 1.29  2003-02-19 22:00:16  daniel
+  Revision 1.30  2003-03-11 21:46:24  jonas
+    * lots of new regallocator fixes, both in generic and ppc-specific code
+      (ppc compiler still can't compile the linux system unit though)
+
+  Revision 1.29  2003/02/19 22:00:16  daniel
     * Code generator converted to new register notation
     - Horribily outdated todo.txt removed
 
@@ -483,4 +487,4 @@ end.
   Revision 1.5  2002/04/06 18:13:02  jonas
     * several powerpc-related additions and fixes
 
-}
+}

+ 13 - 8
compiler/powerpc/nppcmat.pas

@@ -142,17 +142,17 @@ implementation
              begin
                exprasmlist.concat(taicpu.op_reg_reg_reg(A_MULLW,resultreg,
                  divider,resultreg));
-               rg.ungetregister(exprasmlist,divider);
+               rg.ungetregisterint(exprasmlist,divider);
                exprasmlist.concat(taicpu.op_reg_reg_reg(A_SUB,location.register,
                  numerator,resultreg));
                cg.free_scratch_reg(exprasmlist,resultreg);
                resultreg := location.register;
              end
            else
-             rg.ungetregister(exprasmlist,divider);
+             rg.ungetregisterint(exprasmlist,divider);
            end;
        { free used registers }
-        if numerator.enum <> resultreg.enum then
+        if numerator.number <> resultreg.number then
           rg.ungetregisterint(exprasmlist,numerator);
         { set result location }
         location.loc:=LOC_REGISTER;
@@ -268,7 +268,8 @@ implementation
                    end;
 
                  rg.getexplicitregisterint(exprasmlist,NR_R0);
-                 r.enum:=R_0;
+                 r.enum:=R_INTREGISTER;
+                 r.number:=NR_R0;
                  exprasmlist.concat(taicpu.op_reg_reg_const(A_SUBFIC,
                    r,hregister1,32));
                  exprasmlist.concat(taicpu.op_reg_reg_reg(asmop1,
@@ -285,12 +286,12 @@ implementation
                    location.registerhigh,location.registerhigh,r));
                  exprasmlist.concat(taicpu.op_reg_reg_reg(asmop1,
                    location.registerlow,hregisterlow,hregister1));
-                 rg.ungetregister(exprasmlist,r);
+                 rg.ungetregisterint(exprasmlist,r);
 
                  if right.location.loc in [LOC_CREFERENCE,LOC_REFERENCE] then
                    cg.free_scratch_reg(exprasmlist,hregister1)
                  else
-                   rg.ungetregister(exprasmlist,hregister1);
+                   rg.ungetregisterint(exprasmlist,hregister1);
                end
            end
          else
@@ -326,7 +327,7 @@ implementation
                   cg.a_op_reg_reg_reg(exprasmlist,op,OS_32,hregister2,
                     hregister1,resultreg);
 
-                  rg.ungetregister(exprasmlist,hregister2);
+                  rg.ungetregisterint(exprasmlist,hregister2);
                 end;
            end;
       end;
@@ -508,7 +509,11 @@ begin
 end.
 {
   $Log$
-  Revision 1.23  2003-02-19 22:00:16  daniel
+  Revision 1.24  2003-03-11 21:46:24  jonas
+    * lots of new regallocator fixes, both in generic and ppc-specific code
+      (ppc compiler still can't compile the linux system unit though)
+
+  Revision 1.23  2003/02/19 22:00:16  daniel
     * Code generator converted to new register notation
     - Horribily outdated todo.txt removed
 

+ 14 - 2
compiler/rgobj.pas

@@ -613,7 +613,15 @@ unit rgobj;
          end
        else
 {         getexplicitregisterint:=getregisterint(list,r and $ff);}
-          internalerror(200301103);
+{$ifndef i386}
+          // not very cleanm I know :/ The self pointer is allocated a lot
+          // more than necessary (in tcgselfnode.pass_2), but a lot of those
+          // allocations are necessary for the optimizer.
+          // The i386 doesn't care, probably because esi isn't a normal
+          // allocatable register (JM)
+          if (r <> NR_SELF_POINTER_REG) then
+{$endif i386}
+            internalerror(200301103);
     end;
 
 
@@ -1342,7 +1350,11 @@ end.
 
 {
   $Log$
-  Revision 1.30  2003-03-09 21:18:59  olle
+  Revision 1.31  2003-03-11 21:46:24  jonas
+    * lots of new regallocator fixes, both in generic and ppc-specific code
+      (ppc compiler still can't compile the linux system unit though)
+
+  Revision 1.30  2003/03/09 21:18:59  olle
     + added cutils to the uses clause
 
   Revision 1.29  2003/03/08 20:36:41  daniel

+ 7 - 3
compiler/tgobj.pas

@@ -438,9 +438,9 @@ unit tgobj;
          { ref.index = R_NO was missing
            led to problems with local arrays
            with lower bound > 0 (PM) }
-         if ref.base.enum<>R_INTREGISTER then
+         if (ref.base.enum<>R_NO) and (ref.base.enum<>R_INTREGISTER) then
            internalerror(200301225);
-         if ref.index.enum<>R_INTREGISTER then
+         if (ref.index.enum<>R_NO) and (ref.index.enum<>R_INTREGISTER) then
            internalerror(200301225);
          if procinfo.framepointer.enum<>R_INTREGISTER then
            internalerror(200301225);
@@ -542,7 +542,11 @@ finalization
 end.
 {
   $Log$
-  Revision 1.26  2003-02-19 22:00:15  daniel
+  Revision 1.27  2003-03-11 21:46:24  jonas
+    * lots of new regallocator fixes, both in generic and ppc-specific code
+      (ppc compiler still can't compile the linux system unit though)
+
+  Revision 1.26  2003/02/19 22:00:15  daniel
     * Code generator converted to new register notation
     - Horribily outdated todo.txt removed