Selaa lähdekoodia

* Adding register allocation order

daniel 22 vuotta sitten
vanhempi
commit
49e539ac8d
6 muutettua tiedostoa jossa 68 lisäystä ja 43 poistoa
  1. 7 1
      compiler/cgobj.pas
  2. 4 11
      compiler/i386/rgcpu.pas
  3. 7 4
      compiler/pmodules.pas
  4. 7 4
      compiler/psub.pas
  5. 24 22
      compiler/rgobj.pas
  6. 19 1
      compiler/x86/cgx86.pas

+ 7 - 1
compiler/cgobj.pas

@@ -64,6 +64,9 @@ unit cgobj;
           {                 basic routines                 }
           constructor create;
 
+          procedure init_register_allocators;virtual;abstract;
+          procedure done_register_allocators;virtual;abstract;
+
           { returns the tcgsize corresponding with the size of reg }
           class function reg_cgsize(const reg: tregister) : tcgsize; virtual;
 
@@ -1536,7 +1539,10 @@ finalization
 end.
 {
   $Log$
-  Revision 1.119  2003-09-07 22:09:34  peter
+  Revision 1.120  2003-09-09 20:59:27  daniel
+    * Adding register allocation order
+
+  Revision 1.119  2003/09/07 22:09:34  peter
     * preparations for different default calling conventions
     * various RA fixes
 

+ 4 - 11
compiler/i386/rgcpu.pas

@@ -38,8 +38,6 @@ unit rgcpu;
        trgcpu = class(trgobj)
           fpuvaroffset : byte;
 
-          constructor create;override;
-
           { to keep the same allocation order as with the old routines }
           procedure add_constraints(reg:Tregister);override;
 
@@ -87,13 +85,6 @@ unit rgcpu;
 {                               trgcpu                                   }
 {************************************************************************}
 
-    constructor Trgcpu.create;
-      begin
-        inherited create;
-        cpu_registers:=6;
-      end;
-
-
     procedure Trgcpu.add_constraints(reg:Tregister);
     var
       supreg : tsuperregister;
@@ -250,12 +241,14 @@ unit rgcpu;
 
 
 initialization
-  crgobj:=trgcpu;
 end.
 
 {
   $Log$
-  Revision 1.33  2003-09-07 22:09:35  peter
+  Revision 1.34  2003-09-09 20:59:27  daniel
+    * Adding register allocation order
+
+  Revision 1.33  2003/09/07 22:09:35  peter
     * preparations for different default calling conventions
     * various RA fixes
 

+ 7 - 4
compiler/pmodules.pas

@@ -40,7 +40,7 @@ implementation
        globals,verbose,fmodule,finput,fppu,
        symconst,symbase,symtype,symdef,symsym,symtable,
        aasmbase,aasmtai,aasmcpu,
-       cgbase,cpuinfo,rgobj,
+       cgbase,cpuinfo,cgobj,
        ncgutil,
        link,assemble,import,export,gendef,ppu,comprsrc,
        cresstr,cpubase,
@@ -727,7 +727,7 @@ implementation
         current_module.procinfo:=current_procinfo;
         current_procinfo.procdef:=pd;
         { start register allocator }
-        rg:=crgobj.create;
+        cg.init_register_allocators;
         { return procdef }
         create_main_proc:=pd;
       end;
@@ -741,7 +741,7 @@ implementation
            not(current_procinfo.procdef=pd) then
          internalerror(200304276);
         { remove register allocator }
-        rg.free;
+        cg.done_register_allocators;
         { remove procinfo }
         current_module.procinfo:=nil;
         current_procinfo.free;
@@ -1471,7 +1471,10 @@ implementation
 end.
 {
   $Log$
-  Revision 1.123  2003-09-09 15:55:44  peter
+  Revision 1.124  2003-09-09 20:59:27  daniel
+    * Adding register allocation order
+
+  Revision 1.123  2003/09/09 15:55:44  peter
     * use register with least interferences in spillregister
 
   Revision 1.122  2003/09/07 22:09:35  peter

+ 7 - 4
compiler/psub.pas

@@ -89,7 +89,7 @@ implementation
        scanner,
        pbase,pstatmnt,pdecl,pdecsub,pexports,
        { codegen }
-       tgobj,rgobj,
+       tgobj,rgobj,cgobj,
        ncgutil,regvars
        {$ifndef NOOPT}
          {$ifdef i386}
@@ -610,7 +610,7 @@ implementation
         tg.setfirsttemp(firsttemp_offset);
 
         { Create register allocator }
-        rg:=crgobj.create;
+        cg.init_register_allocators;
 
 {$warning FIXME!!}
         { FIXME!! If a procedure contains assembler blocks (or is pure assembler), }
@@ -757,7 +757,7 @@ implementation
         remove_from_symtablestack;
 
         { restore }
-        rg.free;
+        cg.done_register_allocators;
         templist.free;
         rg:=oldrg;
         aktmaxfpuregisters:=oldaktmaxfpuregisters;
@@ -1315,7 +1315,10 @@ begin
 end.
 {
   $Log$
-  Revision 1.143  2003-09-09 15:55:44  peter
+  Revision 1.144  2003-09-09 20:59:27  daniel
+    * Adding register allocation order
+
+  Revision 1.143  2003/09/09 15:55:44  peter
     * use register with least interferences in spillregister
 
   Revision 1.142  2003/09/07 22:09:35  peter

+ 24 - 22
compiler/rgobj.pas

@@ -162,6 +162,7 @@ unit rgobj;
           { contain all registers of type "xxx" that aren't currently    }
           { allocated                                                    }
           lastintreg,maxintreg:Tsuperregister;
+          usable_registers:string[32];
           unusedregsint,usableregsint:Tsuperregisterset;
           unusedregsaddr,usableregsaddr:Tsuperregisterset;
           unusedregsfpu,usableregsfpu : Tsuperregisterset;
@@ -193,7 +194,7 @@ unit rgobj;
           { tries to hold the amount of times which the current tree is processed  }
           t_times: longint;
 
-          constructor create;virtual;
+          constructor create(Acpu_registers:byte;const Ausable:string);
           destructor destroy;virtual;
 
           {# Allocate a general purpose register
@@ -396,8 +397,6 @@ unit rgobj;
        reg_not_saved = $7fffffff;
 
      var
-       {# This is the class instance used to access the register allocator class }
-       crgobj : trgobjclass;
        rg : trgobj;
 
      { trerefence handling }
@@ -461,7 +460,8 @@ unit rgobj;
        globals,verbose,
        cgobj,tgobj,regvars;
 
-    constructor Trgobj.create;
+    constructor Trgobj.create(Acpu_registers:byte;const Ausable:string);
+
      begin
        used_in_proc_int := [];
        used_in_proc_other:=[];
@@ -469,7 +469,7 @@ unit rgobj;
        resetusableregisters;
        lastintreg:=0;
        maxintreg:=first_int_imreg;
-       cpu_registers:=0;
+       cpu_registers:=Acpu_registers;
        unusedregsint:=[0..254]; { 255 (RS_INVALID) can't be used }
        unusedregsfpu:=usableregsfpu;
        unusedregsmm:=usableregsmm;
@@ -486,6 +486,7 @@ unit rgobj;
         by 255.}
        fillchar(movelist,sizeof(movelist),0);
        worklist_moves:=Tlinkedlist.create;
+       usable_registers:=Ausable;
        abtlist:='';
        fillchar(colour,sizeof(colour),RS_INVALID);
      end;
@@ -1668,7 +1669,7 @@ unit rgobj;
 
     var adj:Pstring;
         i,j,k:byte;
-        n,a:Tsuperregister;
+        n,a,c:Tsuperregister;
         adj_colours,colourednodes:set of Tsuperregister;
         w:char;
 
@@ -1698,16 +1699,19 @@ unit rgobj;
           {Assume a spill by default...}
           spillednodes:=spillednodes+char(n);
           {Search for a colour not in this list.}
-          for k:=first_int_supreg to last_int_supreg do
-            if not(k in adj_colours) then
-              begin
-                colour[n]:=k;
-                dec(spillednodes[0]);  {Colour found: no spill.}
-                include(colourednodes,n);
-                if n in used_in_proc_int then
-                  include(used_in_proc_int,k);
-                break;
-              end;
+          for k:=1 to length(usable_registers) do
+            begin
+              c:=Tsuperregister(usable_registers[k]);
+              if not(c in adj_colours) then
+                begin
+                  colour[n]:=c;
+                  dec(spillednodes[0]);  {Colour found: no spill.}
+                  include(colourednodes,n);
+                  if n in used_in_proc_int then
+                    include(used_in_proc_int,c);
+                  break;
+                end;
+            end;
         end;
       {Finally colour the nodes that were coalesced.}
       for i:=1 to length(coalescednodes) do
@@ -2213,16 +2217,14 @@ unit rgobj;
       end;
 
 
-initialization
-  { This check is required because rgcpu is initialized before rgobj
-    when compiling with FPC 1.0.x (PFV) }
-  if not assigned(crgobj) then
-    crgobj:=trgobj;
 end.
 
 {
   $Log$
-  Revision 1.72  2003-09-09 15:55:44  peter
+  Revision 1.73  2003-09-09 20:59:27  daniel
+    * Adding register allocation order
+
+  Revision 1.72  2003/09/09 15:55:44  peter
     * use register with least interferences in spillregister
 
   Revision 1.71  2003/09/07 22:09:35  peter

+ 19 - 1
compiler/x86/cgx86.pas

@@ -37,6 +37,9 @@ unit cgx86;
     type
       tcgx86 = class(tcg)
 
+        procedure init_register_allocators;override;
+        procedure done_register_allocators;override;
+
         { passing parameters, per default the parameter is pushed }
         { nr gives the number of the parameter (enumerated from   }
         { left to right), this allows to move the parameter to    }
@@ -163,6 +166,18 @@ unit cgx86;
                        This is private property, keep out! :)
 ****************************************************************************}
 
+    procedure Tcgx86.init_register_allocators;
+
+    begin
+      rg:=Trgcpu.create(6,#0#1#2#3#4#5);
+    end;
+
+    procedure Tcgx86.done_register_allocators;
+
+    begin
+      rg.free;
+    end;
+
     procedure tcgx86.sizes2load(s1,s2 : tcgsize; var op: tasmop; var s3: topsize);
 
        begin
@@ -1557,7 +1572,10 @@ unit cgx86;
 end.
 {
   $Log$
-  Revision 1.61  2003-09-07 22:09:35  peter
+  Revision 1.62  2003-09-09 20:59:27  daniel
+    * Adding register allocation order
+
+  Revision 1.61  2003/09/07 22:09:35  peter
     * preparations for different default calling conventions
     * various RA fixes