Browse Source

* write proper register locations when doing ssa, resolves #7552

git-svn-id: trunk@18278 -
florian 14 years ago
parent
commit
68dd23b5a2
3 changed files with 78 additions and 5 deletions
  1. 55 5
      compiler/aasmtai.pas
  2. 7 0
      compiler/ncgutil.pas
  3. 16 0
      compiler/rgobj.pas

+ 55 - 5
compiler/aasmtai.pas

@@ -84,7 +84,9 @@ interface
           ait_regalloc,
           ait_tempalloc,
           { used to mark assembler blocks and inlined functions }
-          ait_marker
+          ait_marker,
+          { used to describe a new location of a variable }
+          ait_varloc
           );
 
         taiconst_type = (
@@ -170,7 +172,8 @@ interface
           'cut',
           'regalloc',
           'tempalloc',
-          'marker'
+          'marker',
+          'varloc'
           );
 
     type
@@ -233,14 +236,15 @@ interface
         a new ait type!                                                              }
       SkipInstr = [ait_comment, ait_symbol,ait_section
                    ,ait_stab, ait_function_name, ait_force_line
-                   ,ait_regalloc, ait_tempalloc, ait_symbol_end, ait_directive];
+                   ,ait_regalloc, ait_tempalloc, ait_symbol_end, ait_directive
+                   ,ait_varloc];
 
       { ait_* types which do not have line information (and hence which are of type
         tai, otherwise, they are of type tailineinfo }
       SkipLineInfo =[ait_label,
                      ait_regalloc,ait_tempalloc,
                      ait_stab,ait_function_name,
-                     ait_cutobject,ait_marker,ait_align,ait_section,ait_comment,
+                     ait_cutobject,ait_marker,ait_varloc,ait_align,ait_section,ait_comment,
                      ait_const,
 {$ifdef arm}
                      ait_thumb_func,
@@ -645,6 +649,16 @@ interface
         end;
         tai_align_class = class of tai_align_abstract;
 
+        tai_varloc = class(tai)
+           newlocation : tregister;
+           varsym : tsym;
+           constructor create(sym : tsym;loc : tregister);
+           constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
+           procedure ppuwrite(ppufile:tcompilerppufile);override;
+           procedure buildderefimpl;override;
+           procedure derefimpl;override;
+        end;
+
     var
       { array with all class types for tais }
       aiclass : taiclassarray;
@@ -757,6 +771,39 @@ implementation
       end;
 
 
+    constructor tai_varloc.create(sym: tsym; loc: tregister);
+      begin
+        inherited Create;
+        typ:=ait_varloc;
+        newlocation:=loc;
+        varsym:=sym;
+      end;
+
+
+    constructor tai_varloc.ppuload(t: taitype; ppufile: tcompilerppufile);
+      begin
+        inherited ppuload(t, ppufile);
+      end;
+
+
+    procedure tai_varloc.ppuwrite(ppufile: tcompilerppufile);
+      begin
+        inherited ppuwrite(ppufile);
+      end;
+
+
+    procedure tai_varloc.buildderefimpl;
+      begin
+        inherited buildderefimpl;
+      end;
+
+
+    procedure tai_varloc.derefimpl;
+      begin
+        inherited derefimpl;
+      end;
+
+
 {****************************************************************************
                              TAI
  ****************************************************************************}
@@ -2426,5 +2473,8 @@ implementation
         ppufile.putbyte(fillop);
         ppufile.putbyte(byte(use_op));
       end;
-
+begin
+  { taitype should fit into a 4 byte set for speed reasons }
+  if ord(high(taitype))>31 then
+    internalerror(201108181);
 end.

+ 7 - 0
compiler/ncgutil.pas

@@ -2799,6 +2799,8 @@ implementation
         oldhi, newhi: tregister;
 {$endif not cpu64bitalu}
         ressym: tsym;
+        { moved sym }
+        sym : tsym;
       end;
 
 
@@ -2830,6 +2832,7 @@ implementation
                       exit;
 {$endif not cpu64bitalu}
                   tabstractnormalvarsym(tloadnode(n).symtableentry).localloc.register := rr^.new;
+                  rr^.sym := tabstractnormalvarsym(tloadnode(n).symtableentry);
                   result := fen_norecurse_true;
                 end;
             end;
@@ -2875,6 +2878,7 @@ implementation
           exit;
         rr.old := n.location.register;
         rr.ressym := nil;
+        rr.sym := nil;
       {$ifndef cpu64bitalu}
         rr.oldhi := NR_NO;
       {$endif not cpu64bitalu}
@@ -2938,6 +2942,9 @@ implementation
               internalerror(2006090920);
           end;
 
+        if assigned(rr.sym) then
+          list.concat(tai_varloc.create(rr.sym,rr.new));
+
         { now that we've change the loadn/temp, also change the node result location }
       {$ifndef cpu64bitalu}
         if (n.location.size in [OS_64,OS_S64]) then

+ 16 - 0
compiler/rgobj.pas

@@ -1676,6 +1676,22 @@ unit rgobj;
                           end;
                       end;
                   end;
+              ait_varloc:
+                begin
+                  if cs_asm_source in current_settings.globalswitches then
+                    begin
+                      setsupreg(tai_varloc(p).newlocation,reginfo[getsupreg(tai_varloc(p).newlocation)].colour);
+                      hp:=Tai_comment.Create(strpnew('Var '+tai_varloc(p).varsym.realname+' located in register '+
+                        std_regname(tai_varloc(p).newlocation)));
+                      list.insertafter(hp,p);
+                    end;
+                  q:=tai(p.next);
+                  list.remove(p);
+                  p.free;
+                  p:=q;
+                  continue;
+                end;
+
               ait_instruction:
                 with Taicpu(p) do
                   begin