Преглед изворни кода

+ added new compiler debug ifdef DEBUG_INSTRUCTIONREGISTERDEPENDENCIES, which
adds instruction register usage info to the assembly output (only register
reads for now, but register writes will also be added later). Useful for
debugging InstructionLoadsFromReg and other similar functions.

git-svn-id: trunk@35967 -

nickysn пре 8 година
родитељ
комит
7ea0429d40
2 измењених фајлова са 35 додато и 0 уклоњено
  1. 4 0
      compiler/aopt.pas
  2. 31 0
      compiler/aoptobj.pas

+ 4 - 0
compiler/aopt.pas

@@ -26,6 +26,7 @@ Unit aopt;
 {$i fpcdefs.inc}
 {$i fpcdefs.inc}
 
 
 { $define DEBUG_OPTALLOC}
 { $define DEBUG_OPTALLOC}
+{ $define DEBUG_INSTRUCTIONREGISTERDEPENDENCIES}
 
 
   Interface
   Interface
 
 
@@ -381,6 +382,9 @@ Unit aopt;
       begin
       begin
         p:=casmoptimizer.Create(AsmL);
         p:=casmoptimizer.Create(AsmL);
         p.Optimize;
         p.Optimize;
+{$ifdef DEBUG_INSTRUCTIONREGISTERDEPENDENCIES}
+        p.Debug_InsertInstrRegisterDependencyInfo;
+{$endif DEBUG_INSTRUCTIONREGISTERDEPENDENCIES}
         p.free
         p.free
       end;
       end;
 
 

+ 31 - 0
compiler/aoptobj.pas

@@ -350,6 +350,11 @@ Unit AoptObj;
         function PeepHoleOptPass1Cpu(var p: tai): boolean; virtual;
         function PeepHoleOptPass1Cpu(var p: tai): boolean; virtual;
         function PeepHoleOptPass2Cpu(var p: tai): boolean; virtual;
         function PeepHoleOptPass2Cpu(var p: tai): boolean; virtual;
         function PostPeepHoleOptsCpu(var p: tai): boolean; virtual;
         function PostPeepHoleOptsCpu(var p: tai): boolean; virtual;
+
+        { insert debug comments about which registers are read and written by
+          each instruction. Useful for debugging the InstructionLoadsFromReg and
+          other similar functions. }
+        procedure Debug_InsertInstrRegisterDependencyInfo; virtual;
       End;
       End;
 
 
        Function ArrayRefsEq(const r1, r2: TReference): Boolean;
        Function ArrayRefsEq(const r1, r2: TReference): Boolean;
@@ -1572,4 +1577,30 @@ Unit AoptObj;
         result := false;
         result := false;
       end;
       end;
 
 
+
+    procedure TAOptObj.Debug_InsertInstrRegisterDependencyInfo;
+      var
+        p: tai;
+        ri: tregisterindex;
+        reg: TRegister;
+        commentstr: AnsiString;
+      begin
+        p:=tai(AsmL.First);
+        while (p<>AsmL.Last) Do
+          begin
+            if p.typ=ait_instruction then
+              begin
+                commentstr:='Instruction reads';
+                for ri in tregisterindex do
+                  begin
+                    reg:=regnumber_table[ri];
+                    if (reg<>NR_NO) and InstructionLoadsFromReg(reg,p) then
+                      commentstr:=commentstr+' '+std_regname(reg);
+                  end;
+                AsmL.InsertAfter(tai_comment.Create(strpnew(commentstr)),p);
+              end;
+            p:=tai(p.next);
+          end;
+      end;
+
 End.
 End.