mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-17 01:59:18 +02:00
+ nmat refactored to have simplify
git-svn-id: trunk@142 -
This commit is contained in:
parent
9c717f2a35
commit
e920b10d7a
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
Copyright (c) 2000-2002 by Florian Klaempfl
|
Copyright (c) 2000-2005 by Florian Klaempfl
|
||||||
|
|
||||||
Type checking and register allocation for math nodes
|
Type checking and register allocation for math nodes
|
||||||
|
|
||||||
@ -32,6 +32,7 @@ interface
|
|||||||
tmoddivnode = class(tbinopnode)
|
tmoddivnode = class(tbinopnode)
|
||||||
function pass_1 : tnode;override;
|
function pass_1 : tnode;override;
|
||||||
function det_resulttype:tnode;override;
|
function det_resulttype:tnode;override;
|
||||||
|
function simplify : tnode;override;
|
||||||
protected
|
protected
|
||||||
{$ifndef cpu64bit}
|
{$ifndef cpu64bit}
|
||||||
{ override the following if you want to implement }
|
{ override the following if you want to implement }
|
||||||
@ -46,6 +47,7 @@ interface
|
|||||||
tshlshrnode = class(tbinopnode)
|
tshlshrnode = class(tbinopnode)
|
||||||
function pass_1 : tnode;override;
|
function pass_1 : tnode;override;
|
||||||
function det_resulttype:tnode;override;
|
function det_resulttype:tnode;override;
|
||||||
|
function simplify : tnode;override;
|
||||||
{$ifndef cpu64bit}
|
{$ifndef cpu64bit}
|
||||||
{ override the following if you want to implement }
|
{ override the following if you want to implement }
|
||||||
{ parts explicitely in the code generator (CEC)
|
{ parts explicitely in the code generator (CEC)
|
||||||
@ -61,6 +63,7 @@ interface
|
|||||||
constructor create(expr : tnode);virtual;
|
constructor create(expr : tnode);virtual;
|
||||||
function pass_1 : tnode;override;
|
function pass_1 : tnode;override;
|
||||||
function det_resulttype:tnode;override;
|
function det_resulttype:tnode;override;
|
||||||
|
function simplify : tnode;override;
|
||||||
end;
|
end;
|
||||||
tunaryminusnodeclass = class of tunaryminusnode;
|
tunaryminusnodeclass = class of tunaryminusnode;
|
||||||
|
|
||||||
@ -68,6 +71,7 @@ interface
|
|||||||
constructor create(expr : tnode);virtual;
|
constructor create(expr : tnode);virtual;
|
||||||
function pass_1 : tnode;override;
|
function pass_1 : tnode;override;
|
||||||
function det_resulttype:tnode;override;
|
function det_resulttype:tnode;override;
|
||||||
|
function simplify : tnode;override;
|
||||||
{$ifdef state_tracking}
|
{$ifdef state_tracking}
|
||||||
function track_state_pass(exec_known:boolean):boolean;override;
|
function track_state_pass(exec_known:boolean):boolean;override;
|
||||||
{$endif}
|
{$endif}
|
||||||
@ -80,7 +84,6 @@ interface
|
|||||||
cunaryminusnode : tunaryminusnodeclass;
|
cunaryminusnode : tunaryminusnodeclass;
|
||||||
cnotnode : tnotnodeclass;
|
cnotnode : tnotnodeclass;
|
||||||
|
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
@ -96,11 +99,47 @@ implementation
|
|||||||
TMODDIVNODE
|
TMODDIVNODE
|
||||||
****************************************************************************}
|
****************************************************************************}
|
||||||
|
|
||||||
|
function tmoddivnode.simplify:tnode;
|
||||||
|
var
|
||||||
|
t : tnode;
|
||||||
|
rd,ld : torddef;
|
||||||
|
rv,lv : tconstexprint;
|
||||||
|
begin
|
||||||
|
result:=nil;
|
||||||
|
|
||||||
|
if is_constintnode(right) and is_constintnode(left) then
|
||||||
|
begin
|
||||||
|
rd:=torddef(right.resulttype.def);
|
||||||
|
ld:=torddef(left.resulttype.def);
|
||||||
|
|
||||||
|
rv:=tordconstnode(right).value;
|
||||||
|
lv:=tordconstnode(left).value;
|
||||||
|
|
||||||
|
case nodetype of
|
||||||
|
modn:
|
||||||
|
if (torddef(ld).typ <> u64bit) or
|
||||||
|
(torddef(rd).typ <> u64bit) then
|
||||||
|
t:=genintconstnode(lv mod rv)
|
||||||
|
else
|
||||||
|
t:=genintconstnode(int64(qword(lv) mod qword(rv)));
|
||||||
|
divn:
|
||||||
|
if (torddef(ld).typ <> u64bit) or
|
||||||
|
(torddef(rd).typ <> u64bit) then
|
||||||
|
t:=genintconstnode(lv div rv)
|
||||||
|
else
|
||||||
|
t:=genintconstnode(int64(qword(lv) div qword(rv)));
|
||||||
|
end;
|
||||||
|
result:=t;
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
function tmoddivnode.det_resulttype:tnode;
|
function tmoddivnode.det_resulttype:tnode;
|
||||||
var
|
var
|
||||||
hp,t : tnode;
|
hp,t : tnode;
|
||||||
rd,ld : torddef;
|
rd,ld : torddef;
|
||||||
rv,lv : tconstexprint;
|
rv : tconstexprint;
|
||||||
begin
|
begin
|
||||||
result:=nil;
|
result:=nil;
|
||||||
resulttypepass(left);
|
resulttypepass(left);
|
||||||
@ -131,28 +170,11 @@ implementation
|
|||||||
{ recover }
|
{ recover }
|
||||||
rv:=1;
|
rv:=1;
|
||||||
end;
|
end;
|
||||||
if is_constintnode(left) then
|
end;
|
||||||
begin
|
|
||||||
lv:=tordconstnode(left).value;
|
|
||||||
|
|
||||||
case nodetype of
|
result:=simplify;
|
||||||
modn:
|
if assigned(result) then
|
||||||
if (torddef(ld).typ <> u64bit) or
|
|
||||||
(torddef(rd).typ <> u64bit) then
|
|
||||||
t:=genintconstnode(lv mod rv)
|
|
||||||
else
|
|
||||||
t:=genintconstnode(int64(qword(lv) mod qword(rv)));
|
|
||||||
divn:
|
|
||||||
if (torddef(ld).typ <> u64bit) or
|
|
||||||
(torddef(rd).typ <> u64bit) then
|
|
||||||
t:=genintconstnode(lv div rv)
|
|
||||||
else
|
|
||||||
t:=genintconstnode(int64(qword(lv) div qword(rv)));
|
|
||||||
end;
|
|
||||||
result:=t;
|
|
||||||
exit;
|
exit;
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ allow operator overloading }
|
{ allow operator overloading }
|
||||||
t:=self;
|
t:=self;
|
||||||
@ -425,18 +447,11 @@ implementation
|
|||||||
TSHLSHRNODE
|
TSHLSHRNODE
|
||||||
****************************************************************************}
|
****************************************************************************}
|
||||||
|
|
||||||
function tshlshrnode.det_resulttype:tnode;
|
function tshlshrnode.simplify:tnode;
|
||||||
var
|
var
|
||||||
t : tnode;
|
t : tnode;
|
||||||
begin
|
begin
|
||||||
result:=nil;
|
result:=nil;
|
||||||
resulttypepass(left);
|
|
||||||
resulttypepass(right);
|
|
||||||
set_varstate(right,vs_used,[vsf_must_be_valid]);
|
|
||||||
set_varstate(left,vs_used,[vsf_must_be_valid]);
|
|
||||||
if codegenerror then
|
|
||||||
exit;
|
|
||||||
|
|
||||||
{ constant folding }
|
{ constant folding }
|
||||||
if is_constintnode(left) and is_constintnode(right) then
|
if is_constintnode(left) and is_constintnode(right) then
|
||||||
begin
|
begin
|
||||||
@ -450,6 +465,25 @@ implementation
|
|||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
function tshlshrnode.det_resulttype:tnode;
|
||||||
|
var
|
||||||
|
t : tnode;
|
||||||
|
begin
|
||||||
|
result:=nil;
|
||||||
|
resulttypepass(left);
|
||||||
|
resulttypepass(right);
|
||||||
|
set_varstate(right,vs_used,[vsf_must_be_valid]);
|
||||||
|
set_varstate(left,vs_used,[vsf_must_be_valid]);
|
||||||
|
if codegenerror then
|
||||||
|
exit;
|
||||||
|
|
||||||
|
result:=simplify;
|
||||||
|
if assigned(result) then
|
||||||
|
exit;
|
||||||
|
|
||||||
{ allow operator overloading }
|
{ allow operator overloading }
|
||||||
t:=self;
|
t:=self;
|
||||||
if isbinaryoverloaded(t) then
|
if isbinaryoverloaded(t) then
|
||||||
@ -535,16 +569,9 @@ implementation
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function tunaryminusnode.det_resulttype : tnode;
|
function tunaryminusnode.simplify:tnode;
|
||||||
var
|
|
||||||
t : tnode;
|
|
||||||
begin
|
begin
|
||||||
result:=nil;
|
result:=nil;
|
||||||
resulttypepass(left);
|
|
||||||
set_varstate(left,vs_used,[vsf_must_be_valid]);
|
|
||||||
if codegenerror then
|
|
||||||
exit;
|
|
||||||
|
|
||||||
{ constant folding }
|
{ constant folding }
|
||||||
if is_constintnode(left) then
|
if is_constintnode(left) then
|
||||||
begin
|
begin
|
||||||
@ -558,6 +585,22 @@ implementation
|
|||||||
left:=nil;
|
left:=nil;
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
function tunaryminusnode.det_resulttype : tnode;
|
||||||
|
var
|
||||||
|
t : tnode;
|
||||||
|
begin
|
||||||
|
result:=nil;
|
||||||
|
resulttypepass(left);
|
||||||
|
set_varstate(left,vs_used,[vsf_must_be_valid]);
|
||||||
|
if codegenerror then
|
||||||
|
exit;
|
||||||
|
|
||||||
|
result:=simplify;
|
||||||
|
if assigned(result) then
|
||||||
|
exit;
|
||||||
|
|
||||||
resulttype:=left.resulttype;
|
resulttype:=left.resulttype;
|
||||||
if (left.resulttype.def.deftype=floatdef) then
|
if (left.resulttype.def.deftype=floatdef) then
|
||||||
@ -666,26 +709,19 @@ implementation
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function tnotnode.det_resulttype : tnode;
|
function tnotnode.simplify:tnode;
|
||||||
var
|
var
|
||||||
|
v : tconstexprint;
|
||||||
t : tnode;
|
t : tnode;
|
||||||
tt : ttype;
|
tt : ttype;
|
||||||
v : tconstexprint;
|
|
||||||
begin
|
begin
|
||||||
result:=nil;
|
result:=nil;
|
||||||
resulttypepass(left);
|
|
||||||
set_varstate(left,vs_used,[]);
|
|
||||||
if codegenerror then
|
|
||||||
exit;
|
|
||||||
|
|
||||||
resulttype:=left.resulttype;
|
|
||||||
|
|
||||||
{ Try optmimizing ourself away }
|
{ Try optmimizing ourself away }
|
||||||
if left.nodetype=notn then
|
if left.nodetype=notn then
|
||||||
begin
|
begin
|
||||||
{ Double not. Remove both }
|
{ Double not. Remove both }
|
||||||
result:=Tnotnode(left).left;
|
result:=Tnotnode(left).left;
|
||||||
Tnotnode(left).left:=nil;
|
tnotnode(left).left:=nil;
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -739,6 +775,24 @@ implementation
|
|||||||
result:=t;
|
result:=t;
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
function tnotnode.det_resulttype : tnode;
|
||||||
|
var
|
||||||
|
t : tnode;
|
||||||
|
begin
|
||||||
|
result:=nil;
|
||||||
|
resulttypepass(left);
|
||||||
|
set_varstate(left,vs_used,[]);
|
||||||
|
if codegenerror then
|
||||||
|
exit;
|
||||||
|
|
||||||
|
resulttype:=left.resulttype;
|
||||||
|
|
||||||
|
result:=simplify;
|
||||||
|
if assigned(result) then
|
||||||
|
exit;
|
||||||
|
|
||||||
if is_boolean(resulttype.def) then
|
if is_boolean(resulttype.def) then
|
||||||
begin
|
begin
|
||||||
|
Loading…
Reference in New Issue
Block a user