ソースを参照

+ getsingletonarraydef() function to get a (reused if possible) def for
an array of one element of the specified type

git-svn-id: branches/jvmbackend@18773 -

Jonas Maebe 14 年 前
コミット
d1f424561e
2 ファイル変更29 行追加0 行削除
  1. 5 0
      compiler/fmodule.pas
  2. 24 0
      compiler/symdef.pas

+ 5 - 0
compiler/fmodule.pas

@@ -144,6 +144,7 @@ interface
         deflist,
         symlist       : TFPObjectList;
         ptrdefs       : THashSet; { 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) }
         wpoinfo       : tunitwpoinfobase; { whole program optimization-related information that is generated during the current run for this unit }
         globalsymtable,           { pointer to the global symtable of this unit }
         localsymtable : TSymtable;{ pointer to the local symtable of this unit }
@@ -527,6 +528,7 @@ implementation
         deflist:=TFPObjectList.Create(false);
         symlist:=TFPObjectList.Create(false);
         ptrdefs:=THashSet.Create(64,true,false);
+        arraydefs:=THashSet.Create(64,true,false);
         wpoinfo:=nil;
         checkforwarddefs:=TFPObjectList.Create(false);
         extendeddefs := TFPHashObjectList.Create(true);
@@ -643,6 +645,7 @@ implementation
         deflist.free;
         symlist.free;
         ptrdefs.free;
+        arraydefs.free;
         wpoinfo.free;
         checkforwarddefs.free;
         globalsymtable.free;
@@ -704,6 +707,8 @@ implementation
         symlist:=TFPObjectList.Create(false);
         ptrdefs.free;
         ptrdefs:=THashSet.Create(64,true,false);
+        arraydefs.free;
+        arraydefs:=THashSet.Create(64,true,false);
         wpoinfo.free;
         wpoinfo:=nil;
         checkforwarddefs.free;

+ 24 - 0
compiler/symdef.pas

@@ -963,6 +963,9 @@ interface
     { returns a pointerdef for def, reusing an existing one in case it exists
       in the current module }
     function getpointerdef(def: tdef): tpointerdef;
+    { returns an arraydef for an array containing a single array of def, resuing
+      an existing one in case it exists in the current module }
+    function getsingletonarraydef(def: tdef): tarraydef;
 
 implementation
 
@@ -6639,4 +6642,25 @@ implementation
         result:=tpointerdef(res^.Data);
       end;
 
+
+    function getsingletonarraydef(def: tdef): tarraydef;
+      var
+        res: PHashSetItem;
+      begin
+        if not assigned(current_module) then
+          internalerror(2011081301);
+        res:=current_module.arraydefs.FindOrAdd(@def,sizeof(def));
+        if not assigned(res^.Data) then
+          begin
+            { since these arraydef can be reused anywhere in the current
+              unit, add them to the global/staticsymtable }
+            symtablestack.push(current_module.localsymtable);
+            res^.Data:=tarraydef.create(0,1,s32inttype);
+            tarraydef(res^.Data).elementdef:=def;
+            symtablestack.pop(current_module.localsymtable);
+          end;
+        result:=tarraydef(res^.Data);
+      end;
+
+
 end.