mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-04 15:50:30 +02:00
+ propagate constants across call nodes
git-svn-id: trunk@44184 -
This commit is contained in:
parent
a0ed685036
commit
e350264db1
@ -76,8 +76,8 @@ unit optconstprop;
|
|||||||
var
|
var
|
||||||
st2, oldnode: tnode;
|
st2, oldnode: tnode;
|
||||||
old: pnode;
|
old: pnode;
|
||||||
changed, tree_modified2,tree_modified3: boolean;
|
changed, tree_modified2, tree_modified3: boolean;
|
||||||
written : Boolean;
|
written, tree_modified4, tree_modified5: Boolean;
|
||||||
begin
|
begin
|
||||||
result:=true;
|
result:=true;
|
||||||
|
|
||||||
@ -87,6 +87,8 @@ unit optconstprop;
|
|||||||
tree_modified:=false;
|
tree_modified:=false;
|
||||||
tree_modified2:=false;
|
tree_modified2:=false;
|
||||||
tree_modified3:=false;
|
tree_modified3:=false;
|
||||||
|
tree_modified4:=false;
|
||||||
|
tree_modified5:=false;
|
||||||
|
|
||||||
{ while it might be usefull, to use foreach to iterate all nodes, it is safer to
|
{ while it might be usefull, to use foreach to iterate all nodes, it is safer to
|
||||||
iterate manually here so we have full controll how all nodes are processed }
|
iterate manually here so we have full controll how all nodes are processed }
|
||||||
@ -94,7 +96,8 @@ unit optconstprop;
|
|||||||
{ We cannot analyze beyond those nodes, so we terminate to be on the safe side }
|
{ We cannot analyze beyond those nodes, so we terminate to be on the safe side }
|
||||||
if (n.nodetype in [addrn,derefn,asmn,casen,whilerepeatn,labeln,continuen,breakn,
|
if (n.nodetype in [addrn,derefn,asmn,casen,whilerepeatn,labeln,continuen,breakn,
|
||||||
tryexceptn,raisen,tryfinallyn,onn,loadparentfpn,loadvmtaddrn,guidconstn,rttin,addoptn,asn,goton,
|
tryexceptn,raisen,tryfinallyn,onn,loadparentfpn,loadvmtaddrn,guidconstn,rttin,addoptn,asn,goton,
|
||||||
objcselectorn,objcprotocoln]) then
|
objcselectorn,objcprotocoln,
|
||||||
|
arrayconstructorn,arrayconstructorrangen]) then
|
||||||
exit(false)
|
exit(false)
|
||||||
else if n.nodetype=assignn then
|
else if n.nodetype=assignn then
|
||||||
begin
|
begin
|
||||||
@ -219,7 +222,23 @@ unit optconstprop;
|
|||||||
result:=false;
|
result:=false;
|
||||||
end
|
end
|
||||||
else if n.nodetype=calln then
|
else if n.nodetype=calln then
|
||||||
exit(false)
|
begin
|
||||||
|
{ only propagate simply variables which are regable, this means that their address is not
|
||||||
|
taken }
|
||||||
|
if (tassignmentnode(arg).left.nodetype=loadn) and
|
||||||
|
(tabstractvarsym(tloadnode(tassignmentnode(arg).left).symtableentry).varregable in [vr_fpureg,vr_mmreg,vr_intreg]) then
|
||||||
|
begin
|
||||||
|
result:=replaceBasicAssign(tnode(tcallnode(n).callinitblock), arg, tree_modified);
|
||||||
|
result:=result and replaceBasicAssign(tcallnode(n).left, arg, tree_modified2);
|
||||||
|
result:=result and replaceBasicAssign(tcallnode(n).vmt_entry, arg, tree_modified3);
|
||||||
|
result:=result and replaceBasicAssign(tcallnode(n).right, arg, tree_modified4);
|
||||||
|
result:=result and replaceBasicAssign(tnode(tcallnode(n).callcleanupblock), arg, tree_modified5);
|
||||||
|
tree_modified:=tree_modified or tree_modified2 or tree_modified3 or tree_modified4 or tree_modified5;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
result:=false;
|
||||||
|
exit;
|
||||||
|
end
|
||||||
else if n.InheritsFrom(tbinarynode) then
|
else if n.InheritsFrom(tbinarynode) then
|
||||||
begin
|
begin
|
||||||
result:=replaceBasicAssign(tbinarynode(n).left, arg, tree_modified);
|
result:=replaceBasicAssign(tbinarynode(n).left, arg, tree_modified);
|
||||||
|
Loading…
Reference in New Issue
Block a user