Browse Source

* regallocation fixes

Jonas Maebe 25 years ago
parent
commit
60d858c278
4 changed files with 78 additions and 11 deletions
  1. 20 2
      compiler/cg386cal.pas
  2. 47 2
      compiler/cg386flw.pas
  3. 5 4
      compiler/cg386ld.pas
  4. 6 3
      compiler/tgeni386.pas

+ 20 - 2
compiler/cg386cal.pas

@@ -447,6 +447,9 @@ implementation
                    { dirty trick to avoid the secondcall below }
                    p^.methodpointer:=genzeronode(callparan);
                    p^.methodpointer^.location.loc:=LOC_REGISTER;
+{$ifndef noAllocEDI}
+                   getexplicitregister32(R_ESI);
+{$endif noAllocEDI}
                    p^.methodpointer^.location.register:=R_ESI;
                    { ARGHHH this is wrong !!!
                      if we can init from base class for a child
@@ -512,6 +515,9 @@ implementation
                                          { way to accept virtual static functions (PM)     }
                                          loadesi:=true;
                                          { if no VMT just use $0 bug0214 PM }
+{$ifndef noAllocEDI}
+                                         getexplicitregister32(R_ESI);
+{$endif noAllocEDI}
                                          if not(oo_has_vmt in pobjectdef(p^.methodpointer^.resulttype)^.objectoptions) then
                                            emit_const_reg(A_MOV,S_L,0,R_ESI)
                                          else
@@ -565,6 +571,9 @@ implementation
                                  begin
                                     { extended syntax of new }
                                     { ESI must be zero }
+{$ifndef noAllocEDI}
+                                    getexplicitregister32(R_ESI);
+{$endif noAllocEDI}
                                     emit_reg_reg(A_XOR,S_L,R_ESI,R_ESI);
                                     emit_reg(A_PUSH,S_L,R_ESI);
                                     { insert the vmt }
@@ -578,6 +587,9 @@ implementation
 
                                     { destructor with extended syntax called from dispose }
                                     { hdisposen always deliver LOC_REFERENCE          }
+{$ifndef noAllocEDI}
+                                    getexplicitregister32(R_ESI);
+{$endif noAllocEDI}
                                     emit_ref_reg(A_LEA,S_L,
                                       newreference(p^.methodpointer^.location.reference),R_ESI);
                                     del_reference(p^.methodpointer^.location.reference);
@@ -600,6 +612,9 @@ implementation
                                               end;
                                             else
                                               begin
+{$ifndef noAllocEDI}
+                                                 getexplicitregister32(R_ESI);
+{$endif noAllocEDI}
                                                  if (p^.methodpointer^.resulttype^.deftype=classrefdef) or
                                                     ((p^.methodpointer^.resulttype^.deftype=objectdef) and
                                                    pobjectdef(p^.methodpointer^.resulttype)^.is_class) then
@@ -1318,7 +1333,10 @@ implementation
 end.
 {
   $Log$
-  Revision 1.118  2000-01-20 12:14:47  florian
+  Revision 1.119  2000-01-21 12:17:41  jonas
+    * regallocation fixes
+
+  Revision 1.118  2000/01/20 12:14:47  florian
     * bug 793 fixed
 
   Revision 1.117  2000/01/16 22:17:11  peter
@@ -1433,4 +1451,4 @@ end.
   Revision 1.90.2.3  1999/06/22 13:30:08  peter
     * fixed return with packenum
 
-}
+}

+ 47 - 2
compiler/cg386flw.pas

@@ -625,12 +625,16 @@ do_jmp:
          getlabel(lastonlabel);
          push_int (1); { push type of exceptionframe }
          emitcall('FPC_PUSHEXCEPTADDR');
+         { allocate eax }
+         exprasmlist^.concat(new(pairegalloc,alloc(R_EAX)));
          emit_reg(A_PUSH,S_L,R_EAX);
          emitcall('FPC_SETJMP');
          emit_reg(A_PUSH,S_L,R_EAX);
          emit_reg_reg(A_TEST,S_L,R_EAX,R_EAX);
+         { deallocate eax }
+         exprasmlist^.concat(new(pairegalloc,dealloc(R_EAX)));
          emitjmp(C_NE,exceptlabel);
-
+   
          { try code }
          oldexceptblock:=aktexceptblock;
          aktexceptblock:=p^.left;
@@ -641,6 +645,8 @@ do_jmp:
 
          emitlab(exceptlabel);
          emitcall('FPC_POPADDRSTACK');
+         { allocate eax }
+         exprasmlist^.concat(new(pairegalloc,alloc(R_EAX)));
          emit_reg(A_POP,S_L,R_EAX);
          emit_reg_reg(A_TEST,S_L,R_EAX,R_EAX);
          emitjmp(C_E,endexceptlabel);
@@ -676,22 +682,36 @@ do_jmp:
            end
          else
            emitcall('FPC_RERAISE');
+         { deallocate eax }
+         exprasmlist^.concat(new(pairegalloc,dealloc(R_EAX)));
 
          { do some magic for exit in the try block }
          emitlab(exitexceptlabel);
          emitcall('FPC_POPADDRSTACK');
+         { allocate eax }
+         exprasmlist^.concat(new(pairegalloc,alloc(R_EAX)));
          emit_reg(A_POP,S_L,R_EAX);
          emitjmp(C_None,oldaktexitlabel);
+         { deallocate eax }
+         exprasmlist^.concat(new(pairegalloc,dealloc(R_EAX)));
 
          if assigned(aktbreaklabel) then
           begin
             emitlab(breakexceptlabel);
             emitcall('FPC_POPADDRSTACK');
+            { allocate eax }
+            exprasmlist^.concat(new(pairegalloc,alloc(R_EAX)));
             emit_reg(A_POP,S_L,R_EAX);
+            { deallocate eax }
+            exprasmlist^.concat(new(pairegalloc,dealloc(R_EAX)));
             emitjmp(C_None,oldaktbreaklabel);
             emitlab(continueexceptlabel);
             emitcall('FPC_POPADDRSTACK');
+            { allocate eax }
+            exprasmlist^.concat(new(pairegalloc,alloc(R_EAX)));
             emit_reg(A_POP,S_L,R_EAX);
+            { deallocate eax }
+            exprasmlist^.concat(new(pairegalloc,dealloc(R_EAX)));
             emitjmp(C_None,oldaktcontinuelabel);
           end;
 
@@ -721,6 +741,8 @@ do_jmp:
          emit_sym(A_PUSH,S_L,
            newasmsymbol(p^.excepttype^.vmt_mangledname));
          emitcall('FPC_CATCHES');
+         { allocate eax }
+         exprasmlist^.concat(new(pairegalloc,alloc(R_EAX)));
          emit_reg_reg(A_TEST,S_L,R_EAX,R_EAX);
          emitjmp(C_E,nextonlabel);
          ref.symbol:=nil;
@@ -732,6 +754,8 @@ do_jmp:
 
          emit_reg_ref(A_MOV,S_L,
            R_EAX,newreference(ref));
+         { deallocate eax }
+         exprasmlist^.concat(new(pairegalloc,dealloc(R_EAX)));
 
          if assigned(p^.right) then
            begin
@@ -800,10 +824,14 @@ do_jmp:
 
          push_int(1); { Type of stack-frame must be pushed}
          emitcall('FPC_PUSHEXCEPTADDR');
+         { allocate eax }
+         exprasmlist^.concat(new(pairegalloc,alloc(R_EAX)));
          emit_reg(A_PUSH,S_L,R_EAX);
          emitcall('FPC_SETJMP');
          emit_reg(A_PUSH,S_L,R_EAX);
          emit_reg_reg(A_TEST,S_L,R_EAX,R_EAX);
+         { deallocate eax }
+         exprasmlist^.concat(new(pairegalloc,dealloc(R_EAX)));
          emitjmp(C_NE,finallylabel);
 
          { try code }
@@ -826,6 +854,8 @@ do_jmp:
          aktexceptblock:=oldexceptblock;
          if codegenerror then
            exit;
+         { allocate eax }
+         exprasmlist^.concat(new(pairegalloc,alloc(R_EAX)));
          emit_reg(A_POP,S_L,R_EAX);
          emit_reg_reg(A_TEST,S_L,R_EAX,R_EAX);
          emitjmp(C_E,endfinallylabel);
@@ -840,22 +870,34 @@ do_jmp:
             emit_reg(A_DEC,S_L,R_EAX);
             emitjmp(C_Z,oldaktcontinuelabel);
           end;
+         { deallocate eax }
+         exprasmlist^.concat(new(pairegalloc,dealloc(R_EAX)));
          emitlab(reraiselabel);
          emitcall('FPC_RERAISE');
 
          { do some magic for exit,break,continue in the try block }
          emitlab(exitfinallylabel);
+         { allocate eax }
+         exprasmlist^.concat(new(pairegalloc,alloc(R_EAX)));
          emit_reg(A_POP,S_L,R_EAX);
          emit_const(A_PUSH,S_L,2);
          emitjmp(C_NONE,finallylabel);
          if assigned(aktbreaklabel) then
           begin
             emitlab(breakfinallylabel);
+            { allocate eax }
+             exprasmlist^.concat(new(pairegalloc,alloc(R_EAX)));
             emit_reg(A_POP,S_L,R_EAX);
+            { deallocate eax }
+            exprasmlist^.concat(new(pairegalloc,dealloc(R_EAX)));
             emit_const(A_PUSH,S_L,3);
             emitjmp(C_NONE,finallylabel);
             emitlab(continuefinallylabel);
+            { allocate eax }
+            exprasmlist^.concat(new(pairegalloc,alloc(R_EAX)));
             emit_reg(A_POP,S_L,R_EAX);
+            { deallocate eax }
+            exprasmlist^.concat(new(pairegalloc,alloc(R_EAX)));
             emit_const(A_PUSH,S_L,4);
             emitjmp(C_NONE,finallylabel);
           end;
@@ -885,7 +927,10 @@ do_jmp:
 end.
 {
   $Log$
-  Revision 1.66  2000-01-07 01:14:20  peter
+  Revision 1.67  2000-01-21 12:17:42  jonas
+    * regallocation fixes
+
+  Revision 1.66  2000/01/07 01:14:20  peter
     * updated copyright to 2000
 
   Revision 1.65  1999/12/22 23:30:06  peter

+ 5 - 4
compiler/cg386ld.pas

@@ -652,17 +652,15 @@ implementation
                                   emit_reg_reg(A_MOV,opsize,
                                     p^.right^.location.register,
                                     p^.left^.location.register);
-{$IfDef regallocfix}
                                  ungetregister(p^.right^.location.register);
-{$EndIf regallocfix}
                                 end
                               else
                                 Begin
                                   emit_reg_ref(A_MOV,opsize,
                                     p^.right^.location.register,
                                     newreference(p^.left^.location.reference));
-{$IfDef regallocfix}
                                   ungetregister(p^.right^.location.register);
+{$IfDef regallocfix}
                                   del_reference(p^.left^.location.reference);
 {$EndIf regallocfix}
                                 end;
@@ -1005,7 +1003,10 @@ implementation
 end.
 {
   $Log$
-  Revision 1.96  2000-01-09 12:35:01  jonas
+  Revision 1.97  2000-01-21 12:17:42  jonas
+    * regallocation fixes
+
+  Revision 1.96  2000/01/09 12:35:01  jonas
     * changed edi allocation to use getexplicitregister32/ungetregister
       (adapted tgeni386 a bit for this) and enabled it by default
     * fixed very big and stupid bug of mine in cg386mat that broke the

+ 6 - 3
compiler/tgeni386.pas

@@ -355,7 +355,7 @@ implementation
 
       begin
 {$ifndef noAllocEdi}
-         if r = R_EDI then
+         if r in [R_ESI,R_EDI] then
            begin
              exprasmlist^.concat(new(pairegalloc,dealloc(r)));
              exit;
@@ -549,7 +549,7 @@ implementation
 
       begin
 {$ifndef noAllocEdi}
-         if r = R_EDI then
+         if r in [R_ESI,R_EDI] then
            begin
              exprasmlist^.concat(new(pairegalloc,alloc(r)));
              getexplicitregister32 := r;
@@ -630,7 +630,10 @@ begin
 end.
 {
   $Log$
-  Revision 1.38  2000-01-09 12:35:02  jonas
+  Revision 1.39  2000-01-21 12:17:42  jonas
+    * regallocation fixes
+
+  Revision 1.38  2000/01/09 12:35:02  jonas
     * changed edi allocation to use getexplicitregister32/ungetregister
       (adapted tgeni386 a bit for this) and enabled it by default
     * fixed very big and stupid bug of mine in cg386mat that broke the