mirror of
https://github.com/byteworksinc/ORCA-C.git
synced 2025-01-21 06:30:41 +00:00
Generate even better code for constant returns.
If the return value is just a numeric constant or static address, it can simply be loaded right before the RTL instruction, avoiding any data movement. This could actually be applied to a somewhat broader class of expressions, but for now it only applies to numeric or address constants, for which it is clearly correct.
This commit is contained in:
parent
e910eda623
commit
854a6779a9
59
Gen.pas
59
Gen.pas
@ -6975,29 +6975,37 @@ procedure GenTree {op: icptr};
|
|||||||
size: integer; {localSize + parameterSize}
|
size: integer; {localSize + parameterSize}
|
||||||
lab1: integer; {label}
|
lab1: integer; {label}
|
||||||
valuePushed: boolean; {return value pushed on stack?}
|
valuePushed: boolean; {return value pushed on stack?}
|
||||||
|
evaluateAtEnd: boolean; {evaluate return val right before rtl?}
|
||||||
|
|
||||||
begin {GenRetRev}
|
begin {GenRetRev}
|
||||||
size := localSize + parameterSize;
|
size := localSize + parameterSize;
|
||||||
|
evaluateAtEnd := false;
|
||||||
|
|
||||||
{calculate return value, if necessary}
|
{calculate return value, if necessary}
|
||||||
if op^.opcode = pc_rev then begin
|
if op^.opcode = pc_rev then begin
|
||||||
valuePushed := namePushed or debugFlag or profileFlag
|
if op^.left^.opcode in [pc_ldc,pc_lca,pc_lao,pc_lad] then begin
|
||||||
or ((parameterSize <> 0) and (size > 253));
|
evaluateAtEnd := true;
|
||||||
if valuePushed then
|
valuePushed := false;
|
||||||
gLong.preference := onStack
|
|
||||||
else
|
|
||||||
gLong.preference := A_X;
|
|
||||||
GenTree(op^.left);
|
|
||||||
if op^.optype in [cgByte,cgUByte,cgWord,cgUWord] then begin
|
|
||||||
if valuePushed then
|
|
||||||
GenImplied(m_pha)
|
|
||||||
else
|
|
||||||
GenImplied(m_tay);
|
|
||||||
end {if}
|
end {if}
|
||||||
else {if op^.optype in [cgLong,cgULong] then} begin
|
else begin
|
||||||
valuePushed := gLong.where = onStack;
|
valuePushed := namePushed or debugFlag or profileFlag
|
||||||
if not valuePushed then
|
or ((parameterSize <> 0) and (size > 253));
|
||||||
GenImplied(m_tay);
|
if valuePushed then
|
||||||
|
gLong.preference := onStack
|
||||||
|
else
|
||||||
|
gLong.preference := A_X;
|
||||||
|
GenTree(op^.left);
|
||||||
|
if op^.optype in [cgByte,cgUByte,cgWord,cgUWord] then begin
|
||||||
|
if valuePushed then
|
||||||
|
GenImplied(m_pha)
|
||||||
|
else
|
||||||
|
GenImplied(m_tay);
|
||||||
|
end {if}
|
||||||
|
else {if op^.optype in [cgLong,cgULong] then} begin
|
||||||
|
valuePushed := gLong.where = onStack;
|
||||||
|
if not valuePushed then
|
||||||
|
GenImplied(m_tay);
|
||||||
|
end; {else}
|
||||||
end; {else}
|
end; {else}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -7048,8 +7056,9 @@ procedure GenTree {op: icptr};
|
|||||||
if op^.optype in [cgLong,cgULong] then
|
if op^.optype in [cgLong,cgULong] then
|
||||||
GenImplied(m_plx);
|
GenImplied(m_plx);
|
||||||
end {if}
|
end {if}
|
||||||
else if size = 2 then
|
else if not evaluateAtEnd then
|
||||||
GenImplied(m_tya);
|
if size = 2 then
|
||||||
|
GenImplied(m_tya);
|
||||||
end {if}
|
end {if}
|
||||||
else
|
else
|
||||||
case op^.optype of {load the value to return}
|
case op^.optype of {load the value to return}
|
||||||
@ -7121,14 +7130,24 @@ procedure GenTree {op: icptr};
|
|||||||
{put return value in correct place}
|
{put return value in correct place}
|
||||||
case op^.optype of
|
case op^.optype of
|
||||||
cgByte,cgUByte,cgWord,cgUWord: begin
|
cgByte,cgUByte,cgWord,cgUWord: begin
|
||||||
if size <> 2 then
|
if evaluateAtEnd then
|
||||||
|
GenTree(op^.left)
|
||||||
|
else if size <> 2 then
|
||||||
GenImplied(m_tya);
|
GenImplied(m_tya);
|
||||||
if toolParms then {save value on stack for tools}
|
if toolParms then {save value on stack for tools}
|
||||||
GenNative(m_sta_s, direct, returnSize+1, nil, 0);
|
GenNative(m_sta_s, direct, returnSize+1, nil, 0);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
cgLong,cgULong,cgReal,cgDouble,cgComp,cgExtended: begin
|
cgLong,cgULong,cgReal,cgDouble,cgComp,cgExtended: begin
|
||||||
if size <> 2 then
|
if evaluateAtEnd then begin
|
||||||
|
gLong.preference := A_X;
|
||||||
|
GenTree(op^.left);
|
||||||
|
if gLong.where = onStack then begin
|
||||||
|
GenImplied(m_pla);
|
||||||
|
GenImplied(m_plx);
|
||||||
|
end; {if}
|
||||||
|
end {if}
|
||||||
|
else if size <> 2 then
|
||||||
GenImplied(m_tya);
|
GenImplied(m_tya);
|
||||||
if toolParms then begin {save value on stack for tools}
|
if toolParms then begin {save value on stack for tools}
|
||||||
GenNative(m_sta_s, direct, returnSize+1, nil, 0);
|
GenNative(m_sta_s, direct, returnSize+1, nil, 0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user