浏览代码

+ 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}
 
 { $define DEBUG_OPTALLOC}
+{ $define DEBUG_INSTRUCTIONREGISTERDEPENDENCIES}
 
   Interface
 
@@ -381,6 +382,9 @@ Unit aopt;
       begin
         p:=casmoptimizer.Create(AsmL);
         p.Optimize;
+{$ifdef DEBUG_INSTRUCTIONREGISTERDEPENDENCIES}
+        p.Debug_InsertInstrRegisterDependencyInfo;
+{$endif DEBUG_INSTRUCTIONREGISTERDEPENDENCIES}
         p.free
       end;
 

+ 31 - 0
compiler/aoptobj.pas

@@ -350,6 +350,11 @@ Unit AoptObj;
         function PeepHoleOptPass1Cpu(var p: tai): boolean; virtual;
         function PeepHoleOptPass2Cpu(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;
 
        Function ArrayRefsEq(const r1, r2: TReference): Boolean;
@@ -1572,4 +1577,30 @@ Unit AoptObj;
         result := false;
       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.