mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-18 04:09:11 +02:00
* continue const. propagation after a for loop when possible
This commit is contained in:
parent
bcea5581de
commit
4c8e802dd3
@ -50,7 +50,7 @@ unit optconstprop;
|
|||||||
|
|
||||||
will not result in any constant propagation.
|
will not result in any constant propagation.
|
||||||
}
|
}
|
||||||
function do_optconstpropagate(var rootnode : tnode) : tnode;
|
function do_optconstpropagate(var rootnode : tnode;var changed: boolean) : tnode;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
@ -136,7 +136,9 @@ unit optconstprop;
|
|||||||
{ play safe and set the result which is check below }
|
{ play safe and set the result which is check below }
|
||||||
result:=replaceBasicAssign(tfornode(n).t1, arg, tree_modified2);
|
result:=replaceBasicAssign(tfornode(n).t1, arg, tree_modified2);
|
||||||
tree_modified:=tree_modified or tree_modified2;
|
tree_modified:=tree_modified or tree_modified2;
|
||||||
if result and (pi_dfaavailable in current_procinfo.flags) then
|
if result and (pi_dfaavailable in current_procinfo.flags) and
|
||||||
|
{ play safe }
|
||||||
|
assigned(tfornode(n).t2.optinfo) and assigned(tassignmentnode(arg).left.optinfo) then
|
||||||
begin
|
begin
|
||||||
CalcDefSum(tfornode(n).t2);
|
CalcDefSum(tfornode(n).t2);
|
||||||
{ the constant can propagete if is is not the counter variable ... }
|
{ the constant can propagete if is is not the counter variable ... }
|
||||||
@ -146,9 +148,8 @@ unit optconstprop;
|
|||||||
{ and no definition in the loop? }
|
{ and no definition in the loop? }
|
||||||
not(DFASetIn(tfornode(n).t2.optinfo^.defsum,tassignmentnode(arg).left.optinfo^.index)) then
|
not(DFASetIn(tfornode(n).t2.optinfo^.defsum,tassignmentnode(arg).left.optinfo^.index)) then
|
||||||
begin
|
begin
|
||||||
replaceBasicAssign(tfornode(n).t2, arg, tree_modified3);
|
result:=replaceBasicAssign(tfornode(n).t2, arg, tree_modified3);
|
||||||
tree_modified:=tree_modified or tree_modified3;
|
tree_modified:=tree_modified or tree_modified3;
|
||||||
result:=false;
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
result:=false;
|
result:=false;
|
||||||
@ -383,22 +384,15 @@ unit optconstprop;
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function do_optconstpropagate(var rootnode: tnode): tnode;
|
function do_optconstpropagate(var rootnode: tnode;var changed: boolean): tnode;
|
||||||
var
|
|
||||||
changed: boolean;
|
|
||||||
runsimplify : Boolean;
|
|
||||||
begin
|
begin
|
||||||
{$ifdef DEBUG_CONSTPROP}
|
{$ifdef DEBUG_CONSTPROP}
|
||||||
writeln('************************ before constant propagation ***************************');
|
writeln('************************ before constant propagation ***************************');
|
||||||
printnode(rootnode);
|
printnode(rootnode);
|
||||||
{$endif DEBUG_CONSTPROP}
|
{$endif DEBUG_CONSTPROP}
|
||||||
runsimplify:=false;
|
changed:=false;
|
||||||
repeat
|
foreachnodestatic(pm_postandagain, rootnode, @propagate, @changed);
|
||||||
changed:=false;
|
if changed then
|
||||||
foreachnodestatic(pm_postandagain, rootnode, @propagate, @changed);
|
|
||||||
runsimplify:=runsimplify or changed;
|
|
||||||
until changed=false;
|
|
||||||
if runsimplify then
|
|
||||||
doinlinesimplify(rootnode);
|
doinlinesimplify(rootnode);
|
||||||
{$ifdef DEBUG_CONSTPROP}
|
{$ifdef DEBUG_CONSTPROP}
|
||||||
writeln('************************ after constant propagation ***************************');
|
writeln('************************ after constant propagation ***************************');
|
||||||
|
@ -1199,7 +1199,7 @@ implementation
|
|||||||
procedure tcgprocinfo.OptimizeNodeTree;
|
procedure tcgprocinfo.OptimizeNodeTree;
|
||||||
var
|
var
|
||||||
i : integer;
|
i : integer;
|
||||||
RedoDFA: Boolean;
|
RedoDFA, changed: Boolean;
|
||||||
{RedoDFA : boolean;}
|
{RedoDFA : boolean;}
|
||||||
begin
|
begin
|
||||||
{ do this before adding the entry code else the tail recursion recognition won't work,
|
{ do this before adding the entry code else the tail recursion recognition won't work,
|
||||||
@ -1210,7 +1210,12 @@ implementation
|
|||||||
do_opttail(code,procdef);
|
do_opttail(code,procdef);
|
||||||
|
|
||||||
if cs_opt_constant_propagate in current_settings.optimizerswitches then
|
if cs_opt_constant_propagate in current_settings.optimizerswitches then
|
||||||
do_optconstpropagate(code);
|
begin
|
||||||
|
changed:=false;
|
||||||
|
repeat
|
||||||
|
do_optconstpropagate(code,changed);
|
||||||
|
until not(changed);
|
||||||
|
end;
|
||||||
|
|
||||||
if (cs_opt_nodedfa in current_settings.optimizerswitches) and
|
if (cs_opt_nodedfa in current_settings.optimizerswitches) and
|
||||||
{ creating dfa is not always possible }
|
{ creating dfa is not always possible }
|
||||||
@ -1222,10 +1227,14 @@ implementation
|
|||||||
RedoDFA:=false;
|
RedoDFA:=false;
|
||||||
|
|
||||||
if cs_opt_constant_propagate in current_settings.optimizerswitches then
|
if cs_opt_constant_propagate in current_settings.optimizerswitches then
|
||||||
do_optconstpropagate(code);
|
begin
|
||||||
|
changed:=false;
|
||||||
if RedoDFA then
|
repeat
|
||||||
dfabuilder.redodfainfo(code);
|
do_optconstpropagate(code,changed);
|
||||||
|
if changed then
|
||||||
|
dfabuilder.redodfainfo(code);
|
||||||
|
until not(changed);
|
||||||
|
end;
|
||||||
|
|
||||||
if (cs_opt_loopstrength in current_settings.optimizerswitches)
|
if (cs_opt_loopstrength in current_settings.optimizerswitches)
|
||||||
{ our induction variable strength reduction doesn't like
|
{ our induction variable strength reduction doesn't like
|
||||||
|
Loading…
Reference in New Issue
Block a user