+ track usage of flags by using a new register RS_/NR_DEFAULTFLAGS

git-svn-id: trunk@22179 -
This commit is contained in:
florian 2012-08-22 19:37:51 +00:00
parent 66d83bc3d2
commit d8161c185c
10 changed files with 53 additions and 6 deletions

View File

@ -855,6 +855,7 @@ unit cgcpu;
end
else
list.concat(taicpu.op_reg_reg_reg_reg(asmop,dst,overflowreg,src2,src1));
a_reg_alloc(list,NR_DEFAULTFLAGS);
if op=OP_IMUL then
begin
shifterop_reset(so);
@ -1365,6 +1366,7 @@ unit cgcpu;
tmpreg : tregister;
b : byte;
begin
a_reg_alloc(list,NR_DEFAULTFLAGS);
if is_shifter_const(a,b) then
list.concat(taicpu.op_reg_const(A_CMP,reg,a))
{ CMN reg,0 and CMN reg,$80000000 are different from CMP reg,$ffffffff
@ -1378,6 +1380,7 @@ unit cgcpu;
list.concat(taicpu.op_reg_reg(A_CMP,reg,tmpreg));
end;
a_jmp_cond(list,cmp_op,l);
a_reg_dealloc(list,NR_DEFAULTFLAGS);
end;
@ -1388,8 +1391,10 @@ unit cgcpu;
procedure tcgarm.a_cmp_reg_reg_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;reg1,reg2 : tregister;l : tasmlabel);
begin
a_reg_alloc(list,NR_DEFAULTFLAGS);
list.concat(taicpu.op_reg_reg(A_CMP,reg2,reg1));
a_jmp_cond(list,cmp_op,l);
a_reg_dealloc(list,NR_DEFAULTFLAGS);
end;
@ -2246,6 +2251,7 @@ unit cgcpu;
hflags:=ovloc.resflags;
inverse_flags(hflags);
cg.a_jmp_flags(list,hflags,hl);
cg.a_reg_dealloc(list,NR_DEFAULTFLAGS);
end;
else
internalerror(200409281);
@ -3373,6 +3379,7 @@ unit cgcpu;
end
else
list.concat(taicpu.op_reg_reg_reg_reg(asmop,dst,overflowreg,src2,src1));
a_reg_alloc(list,NR_DEFAULTFLAGS);
if op=OP_IMUL then
begin
shifterop_reset(so);

View File

@ -291,6 +291,9 @@ unit cpubase;
{ Offset where the parent framepointer is pushed }
PARENT_FRAMEPOINTER_OFFSET = 0;
NR_DEFAULTFLAGS = NR_CPSR_C;
RS_DEFAULTFLAGS = RS_CPSR_C;
{ Low part of 64bit return value }
function NR_FUNCTION_RESULT64_LOW_REG: tregister;{$ifdef USEINLINE}inline;{$endif USEINLINE}
function RS_FUNCTION_RESULT64_LOW_REG: shortint;{$ifdef USEINLINE}inline;{$endif USEINLINE}

View File

@ -295,11 +295,13 @@ interface
case nodetype of
equaln:
begin
cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CMP,left.location.register,right.location.register));
location.resflags:=F_EQ;
end;
unequaln:
begin
cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CMP,left.location.register,right.location.register));
location.resflags:=F_NE;
end;
@ -313,6 +315,7 @@ interface
swapleftright;
tmpreg:=cg.getintregister(current_asmdata.CurrAsmList,location.size);
current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg_reg(A_AND,tmpreg,left.location.register,right.location.register));
cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CMP,tmpreg,right.location.register));
location.resflags:=F_EQ;
end;
@ -352,6 +355,7 @@ interface
if not(left.location.loc in [LOC_CREGISTER,LOC_REGISTER]) then
hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,true);
dummyreg:=cg.getintregister(current_asmdata.CurrAsmList,location.size);
cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_reg_reg(A_ORR,dummyreg,left.location.register64.reglo,left.location.register64.reghi),PF_S));
end
else
@ -364,6 +368,7 @@ interface
begin
location_reset(location,LOC_FLAGS,OS_NO);
location.resflags:=getresflags(unsigned);
cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CMP,left.location.register64.reghi,right.location.register64.reghi));
if current_settings.cputype in cpu_thumb2 then
begin
@ -379,6 +384,7 @@ interface
{ operation requiring proper N, Z and V flags ? }
begin
location_reset(location,LOC_JUMP,OS_NO);
cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CMP,left.location.register64.reghi,right.location.register64.reghi));
{ the jump the sequence is a little bit hairy }
case nodetype of
@ -388,6 +394,7 @@ interface
{ cheat a little bit for the negative test }
toggleflag(nf_swapped);
cg.a_jmp_flags(current_asmdata.CurrAsmList,getresflags(false),current_procinfo.CurrFalseLabel);
cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
toggleflag(nf_swapped);
end;
lten,gten:
@ -404,14 +411,17 @@ interface
else
nodetype:=ltn;
cg.a_jmp_flags(current_asmdata.CurrAsmList,getresflags(unsigned),current_procinfo.CurrFalseLabel);
cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
nodetype:=oldnodetype;
end;
end;
cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CMP,left.location.register64.reglo,right.location.register64.reglo));
{ the comparisaion of the low dword have to be
always unsigned! }
cg.a_jmp_flags(current_asmdata.CurrAsmList,getresflags(true),current_procinfo.CurrTrueLabel);
cg.a_jmp_always(current_asmdata.CurrAsmList,current_procinfo.CurrFalseLabel);
cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
end;
end;
end;
@ -448,7 +458,7 @@ interface
unsigned:=not(is_signed(left.resultdef)) or
not(is_signed(right.resultdef));
cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
if right.location.loc = LOC_CONSTANT then
begin
if is_shifter_const(right.location.value,b) then

View File

@ -168,8 +168,10 @@ implementation
current_asmdata.getjumplabel(l2);
reference_reset_symbol(href,l1,0,const_align(8));
cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
current_asmdata.CurrAsmList.concat(Taicpu.op_reg_const(A_CMP,left.location.register,0));
cg.a_jmp_flags(current_asmdata.CurrAsmList,F_GE,l2);
cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
hregister:=cg.getfpuregister(current_asmdata.CurrAsmList,OS_F64);
new_section(current_asmdata.asmlists[al_typedconsts],sec_rodata_norel,l1.name,const_align(8));
@ -316,6 +318,7 @@ implementation
location_reset(location,LOC_REGISTER,def_cgsize(resultdef));
hreg1:=cg.getintregister(current_asmdata.CurrAsmList,location.size);
cg.g_flags2reg(current_asmdata.CurrAsmList,location.size,resflags,hreg1);
cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
if (is_cbool(resultdef)) then
cg.a_op_reg_reg(current_asmdata.CurrAsmList,OP_NEG,location.size,hreg1,hreg1);

View File

@ -308,6 +308,7 @@ implementation
LOC_SUBSETREG,LOC_CSUBSETREG,LOC_SUBSETREF,LOC_CSUBSETREF :
begin
hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,true);
cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
current_asmdata.CurrAsmList.concat(taicpu.op_reg_const(A_CMP,left.location.register,0));
location_reset(location,LOC_FLAGS,OS_NO);
location.resflags:=F_EQ;

View File

@ -1012,7 +1012,10 @@ implementation
case l.loc of
{$ifdef cpuflags}
LOC_FLAGS :
cg.g_flags2reg(list,OS_INT,l.resflags,hregister);
begin
cg.g_flags2reg(list,OS_INT,l.resflags,hregister);
cg.a_reg_dealloc(list,NR_DEFAULTFLAGS);
end;
{$endif cpuflags}
LOC_JUMP :
begin
@ -1101,7 +1104,10 @@ implementation
case l.loc of
{$ifdef cpuflags}
LOC_FLAGS :
cg.g_flags2reg(list,dst_cgsize,l.resflags,hregister);
begin
cg.g_flags2reg(list,dst_cgsize,l.resflags,hregister);
cg.a_reg_dealloc(list,NR_DEFAULTFLAGS);
end;
{$endif cpuflags}
LOC_JUMP :
begin

View File

@ -3405,7 +3405,10 @@ implementation
case l.loc of
{$ifdef cpuflags}
LOC_FLAGS :
g_flags2reg(list,dst_size,l.resflags,hregister);
begin
g_flags2reg(list,dst_size,l.resflags,hregister);
cg.a_reg_dealloc(list,NR_DEFAULTFLAGS);
end;
{$endif cpuflags}
LOC_JUMP :
begin
@ -3582,6 +3585,7 @@ implementation
LOC_FLAGS :
begin
a_jmp_flags(list,p.location.resflags,current_procinfo.CurrTrueLabel);
a_reg_dealloc(list,NR_DEFAULTFLAGS);
a_jmp_always(list,current_procinfo.CurrFalseLabel);
end;
{$endif cpuflags}

View File

@ -240,6 +240,7 @@ interface
location_reset(location,LOC_REGISTER,def_cgsize(resultdef));
location.register:=cg.getintregister(current_asmdata.CurrAsmList,location.size);
cg.g_flags2reg(current_asmdata.CurrAsmList,location.size,resflags,location.register);
cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
if (is_cbool(resultdef)) then
cg.a_op_reg_reg(current_asmdata.CurrAsmList,OP_NEG,location.size,location.register,location.register);
current_procinfo.CurrTrueLabel:=oldTrueLabel;

View File

@ -946,11 +946,15 @@ implementation
if left.location.size in [OS_S64,OS_64] then
begin
cg.g_flags2reg(current_asmdata.CurrAsmList,OS_32,right.location.resflags,left.location.register64.reglo);
cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
cg.a_load_const_reg(current_asmdata.CurrAsmList,OS_32,0,left.location.register64.reghi);
end
else
{$endif cpu32bitalu}
cg.g_flags2reg(current_asmdata.CurrAsmList,left.location.size,right.location.resflags,left.location.register);
begin
cg.g_flags2reg(current_asmdata.CurrAsmList,left.location.size,right.location.resflags,left.location.register);
cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
end;
LOC_REFERENCE:
{ i386 has a hack in its code generator so that it can
deal with 64 bit locations in this parcticular case }
@ -960,16 +964,21 @@ implementation
r64.reglo:=cg.getintregister(current_asmdata.CurrAsmList,OS_32);
r64.reghi:=cg.getintregister(current_asmdata.CurrAsmList,OS_32);
cg.g_flags2reg(current_asmdata.CurrAsmList,OS_32,right.location.resflags,r64.reglo);
cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
cg.a_load_const_reg(current_asmdata.CurrAsmList,OS_32,0,r64.reghi);
cg64.a_load64_reg_ref(current_asmdata.CurrAsmList,r64,left.location.reference);
end
else
{$endif cpu32bitalu}
cg.g_flags2ref(current_asmdata.CurrAsmList,left.location.size,right.location.resflags,left.location.reference);
begin
cg.g_flags2ref(current_asmdata.CurrAsmList,left.location.size,right.location.resflags,left.location.reference);
cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
end;
LOC_SUBSETREG,LOC_SUBSETREF:
begin
r:=cg.getintregister(current_asmdata.CurrAsmList,left.location.size);
cg.g_flags2reg(current_asmdata.CurrAsmList,left.location.size,right.location.resflags,r);
cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
hlcg.a_load_reg_loc(current_asmdata.CurrAsmList,left.resultdef,left.resultdef,r,left.location);
end;
else
@ -984,6 +993,7 @@ implementation
r64.reglo:=cg.getintregister(current_asmdata.CurrAsmList,OS_32);
r64.reghi:=cg.getintregister(current_asmdata.CurrAsmList,OS_32);
cg.g_flags2reg(current_asmdata.CurrAsmList,OS_32,right.location.resflags,r64.reglo);
cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
cg.a_load_const_reg(current_asmdata.CurrAsmList,OS_32,0,r64.reghi);
cg64.a_op64_reg_reg(current_asmdata.CurrAsmList,OP_NEG,OS_S64,
r64,r64);
@ -994,6 +1004,7 @@ implementation
begin
r:=cg.getintregister(current_asmdata.CurrAsmList,left.location.size);
cg.g_flags2reg(current_asmdata.CurrAsmList,left.location.size,right.location.resflags,r);
cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
cg.a_op_reg_reg(current_asmdata.CurrAsmList,OP_NEG,left.location.size,r,r);
hlcg.a_load_reg_loc(current_asmdata.CurrAsmList,left.resultdef,left.resultdef,r,left.location);
end

View File

@ -337,6 +337,7 @@ implementation
LOC_FLAGS :
begin
cg.a_jmp_flags(list,p.location.resflags,current_procinfo.CurrTrueLabel);
cg.a_reg_dealloc(list,NR_DEFAULTFLAGS);
cg.a_jmp_always(list,current_procinfo.CurrFalseLabel);
end;
{$endif cpuflags}