From 94bcb9878a743b144ea4b533cb10c0ef3ffd3031 Mon Sep 17 00:00:00 2001 From: nickysn Date: Thu, 7 Aug 2014 19:36:52 +0000 Subject: [PATCH] * reimplemented r28329 in a different way, as suggested by Jonas git-svn-id: trunk@28332 - --- compiler/cclasses.pas | 8 ++-- compiler/fmodule.pas | 39 ++-------------- compiler/i386/symcpu.pas | 2 + compiler/i8086/symcpu.pas | 4 +- compiler/symsym.pas | 19 ++++++++ compiler/x86/symx86.pas | 91 ++++++++++++++++++++++++++++++++++++-- compiler/x86_64/symcpu.pas | 2 + 7 files changed, 121 insertions(+), 44 deletions(-) diff --git a/compiler/cclasses.pas b/compiler/cclasses.pas index 0930634cb4..7fda9b697c 100644 --- a/compiler/cclasses.pas +++ b/compiler/cclasses.pas @@ -508,14 +508,14 @@ type destructor Destroy; override; procedure Clear; { finds an entry by key } - function Find(Key: Pointer; KeyLen: Integer): PHashSetItem; + function Find(Key: Pointer; KeyLen: Integer): PHashSetItem;virtual; { finds an entry, creates one if not exists } function FindOrAdd(Key: Pointer; KeyLen: Integer; - var Found: Boolean): PHashSetItem; + var Found: Boolean): PHashSetItem;virtual; { finds an entry, creates one if not exists } - function FindOrAdd(Key: Pointer; KeyLen: Integer): PHashSetItem; + function FindOrAdd(Key: Pointer; KeyLen: Integer): PHashSetItem;virtual; { returns Data by given Key } - function Get(Key: Pointer; KeyLen: Integer): TObject; + function Get(Key: Pointer; KeyLen: Integer): TObject;virtual; { removes an entry, returns False if entry wasn't there } function Remove(Entry: PHashSetItem): Boolean; property Count: LongWord read FCount; diff --git a/compiler/fmodule.pas b/compiler/fmodule.pas index 8117c80fc4..1146f3924d 100644 --- a/compiler/fmodule.pas +++ b/compiler/fmodule.pas @@ -142,10 +142,7 @@ interface checkforwarddefs, deflist, symlist : TFPObjectList; - ptrdefs : THashSet; { list of pointerdefs created in this module so we can reuse them (not saved/restored) } -{$ifdef x86} - x86ptrdefs : array [tx86pointertyp] of THashSet; -{$endif x86} + ptrdefs : tPtrDefHashSet; { list of pointerdefs created in this module so we can reuse them (not saved/restored) } arraydefs : THashSet; { list of single-element-arraydefs created in this module so we can reuse them (not saved/restored) } ansistrdef : tobject; { an ansistring def redefined for the current module } wpoinfo : tunitwpoinfobase; { whole program optimization-related information that is generated during the current run for this unit } @@ -517,9 +514,6 @@ implementation var n:string; fn:TPathStr; -{$ifdef x86} - ptrtyp:tx86pointertyp; -{$endif x86} begin if amodulename='' then n:=ChangeFileExt(ExtractFileName(afilename),'') @@ -573,13 +567,7 @@ implementation derefdataintflen:=0; deflist:=TFPObjectList.Create(false); symlist:=TFPObjectList.Create(false); -{$ifdef x86} - for ptrtyp in tx86pointertyp do - x86ptrdefs[ptrtyp]:=THashSet.Create(64,true,false); - ptrdefs:=x86ptrdefs[tcpupointerdefclass(cpointerdef).default_x86_data_pointer_type]; -{$else x86} - ptrdefs:=THashSet.Create(64,true,false); -{$endif x86} + ptrdefs:=cPtrDefHashSet.Create; arraydefs:=THashSet.Create(64,true,false); ansistrdef:=nil; wpoinfo:=nil; @@ -622,9 +610,6 @@ implementation var i : longint; current_debuginfo_reset : boolean; -{$ifdef x86} - ptrtyp : tx86pointertyp; -{$endif x86} begin if assigned(unitmap) then freemem(unitmap); @@ -696,13 +681,7 @@ implementation derefdata.free; deflist.free; symlist.free; -{$ifdef x86} - for ptrtyp in tx86pointertyp do - x86ptrdefs[ptrtyp].free; - ptrdefs:=nil; -{$else x86} ptrdefs.free; -{$endif x86} arraydefs.free; ansistrdef:=nil; wpoinfo.free; @@ -722,9 +701,6 @@ implementation var i : longint; current_debuginfo_reset : boolean; -{$ifdef x86} - ptrtyp : tx86pointertyp; -{$endif x86} begin if assigned(scanner) then begin @@ -767,17 +743,8 @@ implementation deflist:=TFPObjectList.Create(false); symlist.free; symlist:=TFPObjectList.Create(false); -{$ifdef x86} - for ptrtyp in tx86pointertyp do - begin - x86ptrdefs[ptrtyp].free; - x86ptrdefs[ptrtyp]:=THashSet.Create(64,true,false); - end; - ptrdefs:=x86ptrdefs[tcpupointerdefclass(cpointerdef).default_x86_data_pointer_type]; -{$else x86} ptrdefs.free; - ptrdefs:=THashSet.Create(64,true,false); -{$endif x86} + ptrdefs:=cPtrDefHashSet.Create; arraydefs.free; arraydefs:=THashSet.Create(64,true,false); wpoinfo.free; diff --git a/compiler/i386/symcpu.pas b/compiler/i386/symcpu.pas index 9fbc65bab5..9e88944f3e 100644 --- a/compiler/i386/symcpu.pas +++ b/compiler/i386/symcpu.pas @@ -207,5 +207,7 @@ begin cconstsym:=tcpuconstsym; cenumsym:=tcpuenumsym; csyssym:=tcpusyssym; + + cPtrDefHashSet:=tx86PtrDefHashSet; end. diff --git a/compiler/i8086/symcpu.pas b/compiler/i8086/symcpu.pas index f734a1b278..9617a45160 100644 --- a/compiler/i8086/symcpu.pas +++ b/compiler/i8086/symcpu.pas @@ -219,7 +219,7 @@ const implementation uses - globals, cpuinfo, verbose; + globals, cpuinfo, verbose, fmodule; function is_proc_far(p: tabstractprocdef): boolean; @@ -470,5 +470,7 @@ begin cconstsym:=tcpuconstsym; cenumsym:=tcpuenumsym; csyssym:=tcpusyssym; + + cPtrDefHashSet:=tx86PtrDefHashSet; end. diff --git a/compiler/symsym.pas b/compiler/symsym.pas index 6f7b88432a..1c7f9233b9 100644 --- a/compiler/symsym.pas +++ b/compiler/symsym.pas @@ -435,6 +435,14 @@ interface function GetCopy:tmacro; end; + { tPtrDefHashSet } + + tPtrDefHashSet = class(THashSet) + public + constructor Create;virtual; + end; + tPtrDefHashSetClass = class of tPtrDefHashSet; + var generrorsym : tsym; @@ -452,6 +460,7 @@ interface cconstsym: tconstsymclass; cenumsym: tenumsymclass; csyssym: tsyssymclass; + cPtrDefHashSet : tPtrDefHashSetClass = tPtrDefHashSet; { generate internal static field name based on regular field name } function internal_static_field_name(const fieldname: TSymStr): TSymStr; @@ -2690,4 +2699,14 @@ implementation Result:=p; end; + +{**************************************************************************** + tPtrDefHashSet + ****************************************************************************} + + constructor tPtrDefHashSet.Create; + begin + inherited Create(64,true,false); + end; + end. diff --git a/compiler/x86/symx86.pas b/compiler/x86/symx86.pas index 6f6484fbeb..500e4443c7 100644 --- a/compiler/x86/symx86.pas +++ b/compiler/x86/symx86.pas @@ -26,7 +26,7 @@ unit symx86; interface uses - globtype, + globtype, cclasses, symconst, symtype,symdef,symsym; type @@ -45,6 +45,24 @@ type end; tx86pointerdefclass = class of tx86pointerdef; + tx86PtrDefKey = packed record + def: tdef; + x86typ:tx86pointertyp; + end; + + { tx86PtrDefHashSet } + + tx86PtrDefHashSet = class(TPtrDefHashSet) + private + class procedure Key2FullKey(Key: Pointer; out FullKey: tx86PtrDefKey); + public + function Find(Key: Pointer; KeyLen: Integer): PHashSetItem;override; + function FindOrAdd(Key: Pointer; KeyLen: Integer; + var Found: Boolean): PHashSetItem;override; + function FindOrAdd(Key: Pointer; KeyLen: Integer): PHashSetItem;override; + function Get(Key: Pointer; KeyLen: Integer): TObject;override; + end; + { returns a pointerdef for def, reusing an existing one in case it exists in the current module } function getx86pointerdef(def: tdef;x86typ:tx86pointertyp): tpointerdef; @@ -52,17 +70,20 @@ type implementation uses - globals, verbose, cclasses, + globals, verbose, symbase, fmodule; function getx86pointerdef(def: tdef;x86typ:tx86pointertyp): tpointerdef; var res: PHashSetItem; oldsymtablestack: tsymtablestack; + key: tx86PtrDefKey; begin if not assigned(current_module) then internalerror(2011071101); - res:=current_module.x86ptrdefs[x86typ].FindOrAdd(@def,sizeof(def)); + key.def:=def; + key.x86typ:=x86typ; + res:=current_module.ptrdefs.FindOrAdd(@key,sizeof(key)); if not assigned(res^.Data) then begin { since these pointerdefs can be reused anywhere in the current @@ -167,5 +188,69 @@ implementation end; +{**************************************************************************** + tx86PtrDefHashSet +****************************************************************************} + + class procedure tx86PtrDefHashSet.Key2FullKey(Key: Pointer; out FullKey: tx86PtrDefKey); + type + pdef=^tdef; + begin + FullKey.def:=pdef(Key)^; + FullKey.x86typ:=tx86pointerdefclass(cpointerdef).default_x86_data_pointer_type; + end; + + function tx86PtrDefHashSet.Find(Key: Pointer; KeyLen: Integer): PHashSetItem; + var + FullKey: tx86PtrDefKey; + begin + if KeyLen=SizeOf(tdef) then + begin + Key2FullKey(Key, FullKey); + Result:=inherited Find(@FullKey, SizeOf(FullKey)); + end + else + Result:=inherited Find(Key, KeyLen); + end; + + function tx86PtrDefHashSet.FindOrAdd(Key: Pointer; KeyLen: Integer; var Found: Boolean): PHashSetItem; + var + FullKey: tx86PtrDefKey; + begin + if KeyLen=SizeOf(tdef) then + begin + Key2FullKey(Key, FullKey); + Result:=inherited FindOrAdd(@FullKey, SizeOf(FullKey), Found); + end + else + Result:=inherited FindOrAdd(Key, KeyLen, Found); + end; + + function tx86PtrDefHashSet.FindOrAdd(Key: Pointer; KeyLen: Integer): PHashSetItem; + var + FullKey: tx86PtrDefKey; + begin + if KeyLen=SizeOf(tdef) then + begin + Key2FullKey(Key, FullKey); + Result:=inherited FindOrAdd(@FullKey, SizeOf(FullKey)); + end + else + Result:=inherited FindOrAdd(Key, KeyLen); + end; + + function tx86PtrDefHashSet.Get(Key: Pointer; KeyLen: Integer): TObject; + var + FullKey: tx86PtrDefKey; + begin + if KeyLen=SizeOf(tdef) then + begin + Key2FullKey(Key, FullKey); + Result:=inherited Get(@FullKey, SizeOf(FullKey)); + end + else + Result:=inherited Get(Key, KeyLen); + end; + end. diff --git a/compiler/x86_64/symcpu.pas b/compiler/x86_64/symcpu.pas index 4e33d0ceb9..195634520c 100644 --- a/compiler/x86_64/symcpu.pas +++ b/compiler/x86_64/symcpu.pas @@ -207,5 +207,7 @@ begin cconstsym:=tcpuconstsym; cenumsym:=tcpuenumsym; csyssym:=tcpusyssym; + + cPtrDefHashSet:=tx86PtrDefHashSet; end.