mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-11-04 20:59:58 +01:00
+ calculate loop unrolling using node_count_weighted which takes care of nodes generating no code
* optimized unrolling calculation git-svn-id: trunk@38688 -
This commit is contained in:
parent
512328deee
commit
c59bd8c29a
@ -123,6 +123,8 @@ interface
|
|||||||
rough estimation how large the tree "node" is }
|
rough estimation how large the tree "node" is }
|
||||||
function node_count(node : tnode) : dword;
|
function node_count(node : tnode) : dword;
|
||||||
|
|
||||||
|
function node_count_weighted(node : tnode) : dword;
|
||||||
|
|
||||||
{ returns true, if the value described by node is constant/immutable, this approximation is safe
|
{ returns true, if the value described by node is constant/immutable, this approximation is safe
|
||||||
if no dirty tricks like buffer overflows or pointer magic are used }
|
if no dirty tricks like buffer overflows or pointer magic are used }
|
||||||
function is_const(node : tnode) : boolean;
|
function is_const(node : tnode) : boolean;
|
||||||
@ -1359,6 +1361,22 @@ implementation
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
function donodecount_weighted(var n: tnode; arg: pointer): foreachnoderesult;
|
||||||
|
begin
|
||||||
|
if not(n.nodetype in [blockn,statementn,callparan,nothingn]) then
|
||||||
|
inc(nodecount);
|
||||||
|
result:=fen_false;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
function node_count_weighted(node : tnode) : dword;
|
||||||
|
begin
|
||||||
|
nodecount:=0;
|
||||||
|
foreachnodestatic(node,@donodecount_weighted,nil);
|
||||||
|
result:=nodecount;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
function is_const(node : tnode) : boolean;
|
function is_const(node : tnode) : boolean;
|
||||||
begin
|
begin
|
||||||
result:=is_constnode(node) or
|
result:=is_constnode(node) or
|
||||||
|
|||||||
@ -51,13 +51,17 @@ unit optloop;
|
|||||||
|
|
||||||
function number_unrolls(node : tnode) : cardinal;
|
function number_unrolls(node : tnode) : cardinal;
|
||||||
begin
|
begin
|
||||||
|
{ calculate how often a loop shall be unrolled.
|
||||||
|
|
||||||
|
The term (60*ord(node_count_weighted(node)<15)) is used to get small loops unrolled more often as
|
||||||
|
the counter management takes more time in this case. }
|
||||||
{$ifdef i386}
|
{$ifdef i386}
|
||||||
{ multiply by 2 for CPUs with a long pipeline }
|
{ multiply by 2 for CPUs with a long pipeline }
|
||||||
if current_settings.optimizecputype in [cpu_Pentium4] then
|
if current_settings.optimizecputype in [cpu_Pentium4] then
|
||||||
number_unrolls:=60 div node_count(node)
|
number_unrolls:=trunc(round((60+(60*ord(node_count_weighted(node)<15)))/max(node_count_weighted(node),1)))
|
||||||
else
|
else
|
||||||
{$endif i386}
|
{$endif i386}
|
||||||
number_unrolls:=30 div node_count(node);
|
number_unrolls:=trunc(round((30+(60*ord(node_count_weighted(node)<15)))/max(node_count_weighted(node),1)));
|
||||||
|
|
||||||
if number_unrolls=0 then
|
if number_unrolls=0 then
|
||||||
number_unrolls:=1;
|
number_unrolls:=1;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user