Bladeren bron

* unified usage of MatchOpType
* fixed generic MatchOpType

git-svn-id: trunk@36145 -

florian 8 jaren geleden
bovenliggende
commit
4a43d992f5
5 gewijzigde bestanden met toevoegingen van 20 en 35 verwijderingen
  1. 2 2
      compiler/aoptutils.pas
  2. 4 10
      compiler/avr/aoptcpu.pas
  3. 5 4
      compiler/i8086/aoptcpu.pas
  4. 8 18
      compiler/x86/aoptx86.pas
  5. 1 1
      compiler/x86_64/aoptcpu.pas

+ 2 - 2
compiler/aoptutils.pas

@@ -39,13 +39,13 @@ unit aoptutils;
 
     function MatchOpType(const p : taicpu; type0: toptype) : Boolean;
       begin
-        Result:=(p.oper[0]^.typ=type0);
+        Result:=(p.ops=1) and (p.oper[0]^.typ=type0);
       end;
 
 
     function MatchOpType(const p : taicpu; type0,type1 : toptype) : Boolean;
       begin
-        Result:=(p.oper[0]^.typ=type0) and (p.oper[0]^.typ=type1);
+        Result:=(p.ops=2) and (p.oper[0]^.typ=type0) and (p.oper[1]^.typ=type1);
       end;
 
 

+ 4 - 10
compiler/avr/aoptcpu.pas

@@ -30,7 +30,7 @@ Unit aoptcpu;
 
 Interface
 
-uses cpubase, cgbase, aasmtai, aopt,AoptObj, aoptcpub;
+uses cpubase,cgbase,aasmtai,aopt,AoptObj,aoptcpub;
 
 Type
   TCpuAsmOptimizer = class(TAsmOptimizer)
@@ -54,6 +54,7 @@ Implementation
     verbose,
     cpuinfo,
     aasmbase,aasmcpu,aasmdata,
+    aoptutils,
     globals,globtype,
     cgutils;
 
@@ -126,13 +127,6 @@ Implementation
     end;
 
 
-  function MatchOpType(const instr : tai;ot0,ot1 : toptype) : Boolean;
-    begin
-      Result:=(taicpu(instr).ops=2) and
-        (taicpu(instr).oper[0]^.typ=ot0) and
-        (taicpu(instr).oper[1]^.typ=ot1);
-    end;
-
 {$ifdef DEBUG_AOPTCPU}
   procedure TCpuAsmOptimizer.DebugMsg(const s: string;p : tai);
     begin
@@ -312,11 +306,11 @@ Implementation
                       into
                       cpi/ldi reg1, imm
                     }
-                    if MatchOpType(p,top_reg,top_const) and
+                    if MatchOpType(taicpu(p),top_reg,top_const) and
                        GetNextInstructionUsingReg(p, hp1, taicpu(p).oper[0]^.reg) and
                        MatchInstruction(hp1,[A_CP,A_MOV],2) and
                        (not RegModifiedBetween(taicpu(p).oper[0]^.reg, p, hp1)) and
-                       MatchOpType(hp1,top_reg,top_reg) and
+                       MatchOpType(taicpu(hp1),top_reg,top_reg) and
                        (getsupreg(taicpu(hp1).oper[0]^.reg) in [16..31]) and
                        (taicpu(hp1).oper[1]^.reg=taicpu(p).oper[0]^.reg) then
                       begin

+ 5 - 4
compiler/i8086/aoptcpu.pas

@@ -42,7 +42,8 @@ unit aoptcpu;
       globals,
       verbose,
       cpuinfo,
-      aasmcpu;
+      aasmcpu,
+      aoptutils;
 
     function TCpuAsmOptimizer.PeepHoleOptPass1Cpu(var p : tai) : boolean;
       var
@@ -57,15 +58,15 @@ unit aoptcpu;
                 A_MOV:
                   begin
                     if MatchInstruction(p,A_MOV,[S_W]) and
-                      MatchOpType(p,top_ref,top_reg) and
+                      MatchOpType(taicpu(p),top_ref,top_reg) and
 
                       GetNextInstruction(p, hp1) and
                       MatchInstruction(hp1,A_MOV,[S_W]) and
-                      MatchOpType(hp1,top_ref,top_reg) and
+                      MatchOpType(taicpu(hp1),top_ref,top_reg) and
 
                       GetNextInstruction(hp1, hp2) and
                       MatchInstruction(hp2,A_MOV,[S_W]) and
-                      MatchOpType(hp2,top_reg,top_reg) and
+                      MatchOpType(taicpu(hp2),top_reg,top_reg) and
 
                       not(OpsEqual(taicpu(p).oper[1]^,taicpu(hp1).oper[1]^)) and
 

+ 8 - 18
compiler/x86/aoptx86.pas

@@ -83,8 +83,6 @@ unit aoptx86;
       and having an offset }
     function MatchReferenceWithOffset(const ref : treference;base,index : TRegister) : Boolean;
 
-    function MatchOpType(const instr : tai;ot0,ot1 : toptype) : Boolean;
-
   implementation
 
     uses
@@ -216,14 +214,6 @@ unit aoptx86;
       end;
 
 
-    function MatchOpType(const instr : tai;ot0,ot1 : toptype) : Boolean;
-      begin
-        Result:=(taicpu(instr).ops=2) and
-          (taicpu(instr).oper[0]^.typ=ot0) and
-          (taicpu(instr).oper[1]^.typ=ot1);
-      end;
-
-
 {$ifdef DEBUG_AOPTCPU}
     procedure TX86AsmOptimizer.DebugMsg(const s: string;p : tai);
       begin
@@ -899,7 +889,7 @@ unit aoptx86;
             (tai(hp1).typ = ait_instruction) then
             begin
               if IsExitCode(hp1) and
-                MatchOpType(p,top_reg,top_ref) and
+                MatchOpType(taicpu(p),top_reg,top_ref) and
                 (taicpu(p).oper[1]^.ref^.base = current_procinfo.FramePointer) and
                 not(assigned(current_procinfo.procdef.funcretsym) and
                    (taicpu(p).oper[1]^.ref^.offset < tabstractnormalvarsym(current_procinfo.procdef.funcretsym).localloc.reference.offset)) and
@@ -921,7 +911,7 @@ unit aoptx86;
                   mov reg1, mem1
                   test/cmp x, reg1
               }
-              else if MatchOpType(p,top_reg,top_ref) and
+              else if MatchOpType(taicpu(p),top_reg,top_ref) and
                   MatchInstruction(hp1,A_CMP,A_TEST,[taicpu(p).opsize]) and
                   (taicpu(hp1).oper[1]^.typ = top_ref) and
                    RefsEqual(taicpu(p).oper[1]^.ref^, taicpu(hp1).oper[1]^.ref^) then
@@ -1351,7 +1341,7 @@ unit aoptx86;
              (taicpu(p).oper[2]^.reg = taicpu(p).oper[1]^.reg))) and
            GetLastInstruction(p,hp1) and
            MatchInstruction(hp1,A_MOV,[]) and
-           MatchOpType(hp1,top_reg,top_reg) and
+           MatchOpType(taicpu(hp1),top_reg,top_reg) and
            ((taicpu(hp1).oper[1]^.reg = taicpu(p).oper[1]^.reg) or
             ((taicpu(hp1).opsize=S_L) and (taicpu(p).opsize=S_Q) and SuperRegistersEqual(taicpu(hp1).oper[1]^.reg,taicpu(p).oper[1]^.reg))) then
           begin
@@ -1423,7 +1413,7 @@ unit aoptx86;
             or ((taicpu(p).oper[0]^.typ = top_ref) and
              (taicpu(p).oper[0]^.ref^.refaddr = addr_no))
            }
-           MatchOpType(p,top_reg,top_reg);
+           MatchOpType(taicpu(p),top_reg,top_reg);
       end;
 
 
@@ -1632,9 +1622,9 @@ unit aoptx86;
         if not(GetNextInstruction(p, hp1)) then
           exit;
 
-        if MatchOpType(p,top_const,top_reg) and
+        if MatchOpType(taicpu(p),top_const,top_reg) and
           MatchInstruction(hp1,A_AND,[]) and
-          MatchOpType(hp1,top_const,top_reg) and
+          MatchOpType(taicpu(hp1),top_const,top_reg) and
           (getsupreg(taicpu(p).oper[1]^.reg) = getsupreg(taicpu(hp1).oper[1]^.reg)) and
           { the second register must contain the first one, so compare their subreg types }
           (getsubreg(taicpu(p).oper[1]^.reg)<=getsubreg(taicpu(hp1).oper[1]^.reg)) and
@@ -1654,7 +1644,7 @@ unit aoptx86;
             Result:=true;
             exit;
           end
-        else if MatchOpType(p,top_const,top_reg) and
+        else if MatchOpType(taicpu(p),top_const,top_reg) and
           MatchInstruction(hp1,A_MOVZX,[]) and
           (taicpu(hp1).oper[0]^.typ = top_reg) and
           MatchOperand(taicpu(p).oper[1]^,taicpu(hp1).oper[1]^) and
@@ -1688,7 +1678,7 @@ unit aoptx86;
                     hp1.free;
                   end;
               end
-        else if MatchOpType(p,top_const,top_reg) and
+        else if MatchOpType(taicpu(p),top_const,top_reg) and
           MatchInstruction(hp1,A_MOVSX{$ifdef x86_64},A_MOVSXD{$endif x86_64},[]) and
           (taicpu(hp1).oper[0]^.typ = top_reg) and
           MatchOperand(taicpu(p).oper[1]^,taicpu(hp1).oper[1]^) and

+ 1 - 1
compiler/x86_64/aoptcpu.pas

@@ -43,7 +43,7 @@ uses
   cutils,
   verbose,
   cgutils,
-  aoptobj,
+  aoptobj,aoptutils,
   aasmbase, aasmdata, aasmcpu,
   itcpugas;