diff --git a/compiler/fmodule.pas b/compiler/fmodule.pas index 2404f478ed..8117c80fc4 100644 --- a/compiler/fmodule.pas +++ b/compiler/fmodule.pas @@ -44,7 +44,7 @@ interface uses cutils,cclasses,cfileutl, globtype,finput,ogbase, - symbase,symsym, + symbase,symconst,symsym,symcpu, wpobase, aasmbase,aasmtai,aasmdata; @@ -143,6 +143,9 @@ interface 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} 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 } @@ -514,6 +517,9 @@ implementation var n:string; fn:TPathStr; +{$ifdef x86} + ptrtyp:tx86pointertyp; +{$endif x86} begin if amodulename='' then n:=ChangeFileExt(ExtractFileName(afilename),'') @@ -567,7 +573,13 @@ 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} arraydefs:=THashSet.Create(64,true,false); ansistrdef:=nil; wpoinfo:=nil; @@ -610,6 +622,9 @@ implementation var i : longint; current_debuginfo_reset : boolean; +{$ifdef x86} + ptrtyp : tx86pointertyp; +{$endif x86} begin if assigned(unitmap) then freemem(unitmap); @@ -681,7 +696,13 @@ 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; @@ -701,6 +722,9 @@ implementation var i : longint; current_debuginfo_reset : boolean; +{$ifdef x86} + ptrtyp : tx86pointertyp; +{$endif x86} begin if assigned(scanner) then begin @@ -743,8 +767,17 @@ 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} arraydefs.free; arraydefs:=THashSet.Create(64,true,false); wpoinfo.free; diff --git a/compiler/x86/symx86.pas b/compiler/x86/symx86.pas index 45c93a8cd3..6f6484fbeb 100644 --- a/compiler/x86/symx86.pas +++ b/compiler/x86/symx86.pas @@ -45,10 +45,41 @@ type end; tx86pointerdefclass = class of tx86pointerdef; + { returns a pointerdef for def, reusing an existing one in case it exists + in the current module } + function getx86pointerdef(def: tdef;x86typ:tx86pointertyp): tpointerdef; + implementation uses - globals, verbose; + globals, verbose, cclasses, + symbase, fmodule; + + function getx86pointerdef(def: tdef;x86typ:tx86pointertyp): tpointerdef; + var + res: PHashSetItem; + oldsymtablestack: tsymtablestack; + begin + if not assigned(current_module) then + internalerror(2011071101); + res:=current_module.x86ptrdefs[x86typ].FindOrAdd(@def,sizeof(def)); + if not assigned(res^.Data) then + begin + { since these pointerdefs can be reused anywhere in the current + unit, add them to the global/staticsymtable } + oldsymtablestack:=symtablestack; + { do not simply push/pop current_module.localsymtable, because + that can have side-effects (e.g., it removes helpers) } + symtablestack:=nil; + res^.Data:=tx86pointerdefclass(cpointerdef).createx86(def,x86typ); + if assigned(current_module.localsymtable) then + current_module.localsymtable.insertdef(tdef(res^.Data)) + else + current_module.globalsymtable.insertdef(tdef(res^.Data)); + symtablestack:=oldsymtablestack; + end; + result:=tpointerdef(res^.Data); + end; {**************************************************************************** tx86pointerdef