mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-16 10:19:17 +02:00
* unified usage of MatchOpType
* fixed generic MatchOpType git-svn-id: trunk@36145 -
This commit is contained in:
parent
4a8a7c210a
commit
4a43d992f5
@ -39,13 +39,13 @@ unit aoptutils;
|
|||||||
|
|
||||||
function MatchOpType(const p : taicpu; type0: toptype) : Boolean;
|
function MatchOpType(const p : taicpu; type0: toptype) : Boolean;
|
||||||
begin
|
begin
|
||||||
Result:=(p.oper[0]^.typ=type0);
|
Result:=(p.ops=1) and (p.oper[0]^.typ=type0);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function MatchOpType(const p : taicpu; type0,type1 : toptype) : Boolean;
|
function MatchOpType(const p : taicpu; type0,type1 : toptype) : Boolean;
|
||||||
begin
|
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;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ Unit aoptcpu;
|
|||||||
|
|
||||||
Interface
|
Interface
|
||||||
|
|
||||||
uses cpubase, cgbase, aasmtai, aopt,AoptObj, aoptcpub;
|
uses cpubase,cgbase,aasmtai,aopt,AoptObj,aoptcpub;
|
||||||
|
|
||||||
Type
|
Type
|
||||||
TCpuAsmOptimizer = class(TAsmOptimizer)
|
TCpuAsmOptimizer = class(TAsmOptimizer)
|
||||||
@ -54,6 +54,7 @@ Implementation
|
|||||||
verbose,
|
verbose,
|
||||||
cpuinfo,
|
cpuinfo,
|
||||||
aasmbase,aasmcpu,aasmdata,
|
aasmbase,aasmcpu,aasmdata,
|
||||||
|
aoptutils,
|
||||||
globals,globtype,
|
globals,globtype,
|
||||||
cgutils;
|
cgutils;
|
||||||
|
|
||||||
@ -126,13 +127,6 @@ Implementation
|
|||||||
end;
|
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}
|
{$ifdef DEBUG_AOPTCPU}
|
||||||
procedure TCpuAsmOptimizer.DebugMsg(const s: string;p : tai);
|
procedure TCpuAsmOptimizer.DebugMsg(const s: string;p : tai);
|
||||||
begin
|
begin
|
||||||
@ -312,11 +306,11 @@ Implementation
|
|||||||
into
|
into
|
||||||
cpi/ldi reg1, imm
|
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
|
GetNextInstructionUsingReg(p, hp1, taicpu(p).oper[0]^.reg) and
|
||||||
MatchInstruction(hp1,[A_CP,A_MOV],2) and
|
MatchInstruction(hp1,[A_CP,A_MOV],2) and
|
||||||
(not RegModifiedBetween(taicpu(p).oper[0]^.reg, p, hp1)) 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
|
(getsupreg(taicpu(hp1).oper[0]^.reg) in [16..31]) and
|
||||||
(taicpu(hp1).oper[1]^.reg=taicpu(p).oper[0]^.reg) then
|
(taicpu(hp1).oper[1]^.reg=taicpu(p).oper[0]^.reg) then
|
||||||
begin
|
begin
|
||||||
|
@ -42,7 +42,8 @@ unit aoptcpu;
|
|||||||
globals,
|
globals,
|
||||||
verbose,
|
verbose,
|
||||||
cpuinfo,
|
cpuinfo,
|
||||||
aasmcpu;
|
aasmcpu,
|
||||||
|
aoptutils;
|
||||||
|
|
||||||
function TCpuAsmOptimizer.PeepHoleOptPass1Cpu(var p : tai) : boolean;
|
function TCpuAsmOptimizer.PeepHoleOptPass1Cpu(var p : tai) : boolean;
|
||||||
var
|
var
|
||||||
@ -57,15 +58,15 @@ unit aoptcpu;
|
|||||||
A_MOV:
|
A_MOV:
|
||||||
begin
|
begin
|
||||||
if MatchInstruction(p,A_MOV,[S_W]) and
|
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
|
GetNextInstruction(p, hp1) and
|
||||||
MatchInstruction(hp1,A_MOV,[S_W]) 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
|
GetNextInstruction(hp1, hp2) and
|
||||||
MatchInstruction(hp2,A_MOV,[S_W]) 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
|
not(OpsEqual(taicpu(p).oper[1]^,taicpu(hp1).oper[1]^)) and
|
||||||
|
|
||||||
|
@ -83,8 +83,6 @@ unit aoptx86;
|
|||||||
and having an offset }
|
and having an offset }
|
||||||
function MatchReferenceWithOffset(const ref : treference;base,index : TRegister) : Boolean;
|
function MatchReferenceWithOffset(const ref : treference;base,index : TRegister) : Boolean;
|
||||||
|
|
||||||
function MatchOpType(const instr : tai;ot0,ot1 : toptype) : Boolean;
|
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
@ -216,14 +214,6 @@ unit aoptx86;
|
|||||||
end;
|
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}
|
{$ifdef DEBUG_AOPTCPU}
|
||||||
procedure TX86AsmOptimizer.DebugMsg(const s: string;p : tai);
|
procedure TX86AsmOptimizer.DebugMsg(const s: string;p : tai);
|
||||||
begin
|
begin
|
||||||
@ -899,7 +889,7 @@ unit aoptx86;
|
|||||||
(tai(hp1).typ = ait_instruction) then
|
(tai(hp1).typ = ait_instruction) then
|
||||||
begin
|
begin
|
||||||
if IsExitCode(hp1) and
|
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
|
(taicpu(p).oper[1]^.ref^.base = current_procinfo.FramePointer) and
|
||||||
not(assigned(current_procinfo.procdef.funcretsym) and
|
not(assigned(current_procinfo.procdef.funcretsym) and
|
||||||
(taicpu(p).oper[1]^.ref^.offset < tabstractnormalvarsym(current_procinfo.procdef.funcretsym).localloc.reference.offset)) 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
|
mov reg1, mem1
|
||||||
test/cmp x, reg1
|
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
|
MatchInstruction(hp1,A_CMP,A_TEST,[taicpu(p).opsize]) and
|
||||||
(taicpu(hp1).oper[1]^.typ = top_ref) and
|
(taicpu(hp1).oper[1]^.typ = top_ref) and
|
||||||
RefsEqual(taicpu(p).oper[1]^.ref^, taicpu(hp1).oper[1]^.ref^) then
|
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
|
(taicpu(p).oper[2]^.reg = taicpu(p).oper[1]^.reg))) and
|
||||||
GetLastInstruction(p,hp1) and
|
GetLastInstruction(p,hp1) and
|
||||||
MatchInstruction(hp1,A_MOV,[]) 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).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
|
((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
|
begin
|
||||||
@ -1423,7 +1413,7 @@ unit aoptx86;
|
|||||||
or ((taicpu(p).oper[0]^.typ = top_ref) and
|
or ((taicpu(p).oper[0]^.typ = top_ref) and
|
||||||
(taicpu(p).oper[0]^.ref^.refaddr = addr_no))
|
(taicpu(p).oper[0]^.ref^.refaddr = addr_no))
|
||||||
}
|
}
|
||||||
MatchOpType(p,top_reg,top_reg);
|
MatchOpType(taicpu(p),top_reg,top_reg);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -1632,9 +1622,9 @@ unit aoptx86;
|
|||||||
if not(GetNextInstruction(p, hp1)) then
|
if not(GetNextInstruction(p, hp1)) then
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
if MatchOpType(p,top_const,top_reg) and
|
if MatchOpType(taicpu(p),top_const,top_reg) and
|
||||||
MatchInstruction(hp1,A_AND,[]) 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
|
(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 }
|
{ 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
|
(getsubreg(taicpu(p).oper[1]^.reg)<=getsubreg(taicpu(hp1).oper[1]^.reg)) and
|
||||||
@ -1654,7 +1644,7 @@ unit aoptx86;
|
|||||||
Result:=true;
|
Result:=true;
|
||||||
exit;
|
exit;
|
||||||
end
|
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
|
MatchInstruction(hp1,A_MOVZX,[]) and
|
||||||
(taicpu(hp1).oper[0]^.typ = top_reg) and
|
(taicpu(hp1).oper[0]^.typ = top_reg) and
|
||||||
MatchOperand(taicpu(p).oper[1]^,taicpu(hp1).oper[1]^) and
|
MatchOperand(taicpu(p).oper[1]^,taicpu(hp1).oper[1]^) and
|
||||||
@ -1688,7 +1678,7 @@ unit aoptx86;
|
|||||||
hp1.free;
|
hp1.free;
|
||||||
end;
|
end;
|
||||||
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
|
MatchInstruction(hp1,A_MOVSX{$ifdef x86_64},A_MOVSXD{$endif x86_64},[]) and
|
||||||
(taicpu(hp1).oper[0]^.typ = top_reg) and
|
(taicpu(hp1).oper[0]^.typ = top_reg) and
|
||||||
MatchOperand(taicpu(p).oper[1]^,taicpu(hp1).oper[1]^) and
|
MatchOperand(taicpu(p).oper[1]^,taicpu(hp1).oper[1]^) and
|
||||||
|
@ -43,7 +43,7 @@ uses
|
|||||||
cutils,
|
cutils,
|
||||||
verbose,
|
verbose,
|
||||||
cgutils,
|
cgutils,
|
||||||
aoptobj,
|
aoptobj,aoptutils,
|
||||||
aasmbase, aasmdata, aasmcpu,
|
aasmbase, aasmdata, aasmcpu,
|
||||||
itcpugas;
|
itcpugas;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user