mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-11-05 05:29:34 +01:00
* gprof profiling support
* some additional safety checks git-svn-id: trunk@3290 -
This commit is contained in:
parent
29a1a31598
commit
b46f7259ca
@ -26,7 +26,7 @@ unit cgcpu;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
globtype, symtype, symdef,
|
globtype, symtype, symdef, symsym,
|
||||||
cgbase, cgobj,
|
cgbase, cgobj,
|
||||||
aasmbase, aasmcpu, aasmtai,aasmdata,
|
aasmbase, aasmcpu, aasmtai,aasmdata,
|
||||||
cpubase, cpuinfo, cgutils, rgcpu,
|
cpubase, cpuinfo, cgutils, rgcpu,
|
||||||
@ -167,6 +167,9 @@ type
|
|||||||
{ emits code to store the given value a into the TOC (if not already in there), and load it from there
|
{ emits code to store the given value a into the TOC (if not already in there), and load it from there
|
||||||
as well }
|
as well }
|
||||||
procedure loadConstantPIC(list : TAsmList; size : TCGSize; a : aint; reg : TRegister);
|
procedure loadConstantPIC(list : TAsmList; size : TCGSize; a : aint; reg : TRegister);
|
||||||
|
|
||||||
|
procedure profilecode_savepara(para : tparavarsym; list : TAsmList);
|
||||||
|
procedure profilecode_restorepara(para : tparavarsym; list : TAsmList);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
const
|
const
|
||||||
@ -180,9 +183,9 @@ const
|
|||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
sysutils,
|
sysutils, cclasses,
|
||||||
globals, verbose, systems, cutils,
|
globals, verbose, systems, cutils,
|
||||||
symconst, symsym, fmodule,
|
symconst, fmodule,
|
||||||
rgobj, tgobj, cpupi, procinfo, paramgr, cpupara;
|
rgobj, tgobj, cpupi, procinfo, paramgr, cpupara;
|
||||||
|
|
||||||
function ref2string(const ref : treference) : string;
|
function ref2string(const ref : treference) : string;
|
||||||
@ -669,6 +672,7 @@ procedure tcgppc.a_load_const_reg(list: TAsmList; size: TCGSize; a: aint;
|
|||||||
procedure loadConstantNormal(list: TAsmList; size : TCgSize; a: aint; reg: TRegister);
|
procedure loadConstantNormal(list: TAsmList; size : TCgSize; a: aint; reg: TRegister);
|
||||||
var
|
var
|
||||||
extendssign : boolean;
|
extendssign : boolean;
|
||||||
|
instr : taicpu;
|
||||||
begin
|
begin
|
||||||
if (lo(a) = 0) and (hi(a) <> 0) then begin
|
if (lo(a) = 0) and (hi(a) <> 0) then begin
|
||||||
{ load only upper 32 bits, and shift }
|
{ load only upper 32 bits, and shift }
|
||||||
@ -734,6 +738,11 @@ var
|
|||||||
op: TAsmOp;
|
op: TAsmOp;
|
||||||
ref2: TReference;
|
ref2: TReference;
|
||||||
begin
|
begin
|
||||||
|
if not (fromsize in [OS_8, OS_S8, OS_16, OS_S16, OS_32, OS_S32, OS_64, OS_S64]) then
|
||||||
|
internalerror(2002090903);
|
||||||
|
if not (tosize in [OS_8, OS_S8, OS_16, OS_S16, OS_32, OS_S32, OS_64, OS_S64]) then
|
||||||
|
internalerror(2002090905);
|
||||||
|
|
||||||
ref2 := ref;
|
ref2 := ref;
|
||||||
fixref(list, ref2, tosize);
|
fixref(list, ref2, tosize);
|
||||||
if tosize in [OS_S8..OS_S64] then
|
if tosize in [OS_S8..OS_S64] then
|
||||||
@ -772,7 +781,7 @@ begin
|
|||||||
{$ENDIF EXTDEBUG}
|
{$ENDIF EXTDEBUG}
|
||||||
|
|
||||||
if not (fromsize in [OS_8, OS_S8, OS_16, OS_S16, OS_32, OS_S32, OS_64, OS_S64]) then
|
if not (fromsize in [OS_8, OS_S8, OS_16, OS_S16, OS_32, OS_S32, OS_64, OS_S64]) then
|
||||||
internalerror(2002090902);
|
internalerror(2002090904);
|
||||||
ref2 := ref;
|
ref2 := ref;
|
||||||
fixref(list, ref2, tosize);
|
fixref(list, ref2, tosize);
|
||||||
{ the caller is expected to have adjusted the reference already
|
{ the caller is expected to have adjusted the reference already
|
||||||
@ -1300,12 +1309,44 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure tcgppc.profilecode_savepara(para : tparavarsym; list : TAsmList);
|
||||||
|
begin
|
||||||
|
case (para.paraloc[calleeside].location^.loc) of
|
||||||
|
LOC_REGISTER, LOC_CREGISTER:
|
||||||
|
a_load_reg_ref(list, OS_INT, para.paraloc[calleeside].Location^.size,
|
||||||
|
para.paraloc[calleeside].Location^.register, para.localloc.reference);
|
||||||
|
LOC_FPUREGISTER, LOC_CFPUREGISTER:
|
||||||
|
a_loadfpu_reg_ref(list, para.paraloc[calleeside].Location^.size,
|
||||||
|
para.paraloc[calleeside].Location^.register, para.localloc.reference);
|
||||||
|
LOC_MMREGISTER, LOC_CMMREGISTER:
|
||||||
|
// not supported
|
||||||
|
internalerror(2006041801);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure tcgppc.profilecode_restorepara(para : tparavarsym; list : TAsmList);
|
||||||
|
begin
|
||||||
|
case (para.paraloc[calleeside].Location^.loc) of
|
||||||
|
LOC_REGISTER, LOC_CREGISTER:
|
||||||
|
a_load_ref_reg(list, para.paraloc[calleeside].Location^.size, OS_INT,
|
||||||
|
para.localloc.reference, para.paraloc[calleeside].Location^.register);
|
||||||
|
LOC_FPUREGISTER, LOC_CFPUREGISTER:
|
||||||
|
a_loadfpu_ref_reg(list, para.paraloc[calleeside].Location^.size,
|
||||||
|
para.localloc.reference, para.paraloc[calleeside].Location^.register);
|
||||||
|
LOC_MMREGISTER, LOC_CMMREGISTER:
|
||||||
|
// not supported
|
||||||
|
internalerror(2006041802);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure tcgppc.g_profilecode(list: TAsmList);
|
procedure tcgppc.g_profilecode(list: TAsmList);
|
||||||
begin
|
begin
|
||||||
// TODO: save GPRs
|
current_procinfo.procdef.paras.ForEachCall(TObjectListCallback(@profilecode_savepara), list);
|
||||||
a_call_name_direct(list, '_mcount', false, true);
|
|
||||||
// TODO: restore GPRs
|
a_call_name_direct(list, '_mcount', false, true);
|
||||||
|
|
||||||
|
current_procinfo.procdef.paras.ForEachCall(TObjectListCallback(@profilecode_restorepara), list);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ Generates the entry code of a procedure/function.
|
{ Generates the entry code of a procedure/function.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user