Browse Source

* allocate locals in a better way, so that we don't get 2 extra wasted locals per function

git-svn-id: branches/wasm@48330 -
nickysn 4 years ago
parent
commit
4d99fb3352
2 changed files with 19 additions and 24 deletions
  1. 19 21
      compiler/wasm32/cpupi.pas
  2. 0 3
      compiler/wasm32/hlcgcpu.pas

+ 19 - 21
compiler/wasm32/cpupi.pas

@@ -84,7 +84,7 @@ implementation
 
     procedure tcpuprocinfo.postprocess_code;
 
-      function findfirst_tai_local(asmlist: TAsmList): tai_local;
+      function findfirst_tai_functype(asmlist: TAsmList): tai_functype;
         var
           hp: tai;
         begin
@@ -94,9 +94,9 @@ implementation
           hp:=tai(asmlist.first);
           while assigned(hp) do
             begin
-              if hp.typ=ait_local then
+              if hp.typ=ait_functype then
                 begin
-                  result:=tai_local(hp);
+                  result:=tai_functype(hp);
                   exit;
                 end;
               hp:=tai(hp.Next);
@@ -128,27 +128,25 @@ implementation
       var
        templist : TAsmList;
        l : TWasmLocal;
-       first_tai_local, last_tai_local: tai_local;
+       first: Boolean;
+       local: tai_local;
       begin
-        templist := TAsmList.create;
-        l := ttgwasm(tg).localvars.first;
-        while Assigned(l) do begin
-          templist.Concat( tai_local.create(l.typ));
-          l := l.nextseq;
-        end;
-        aktproccode.insertListBefore(findfirst_tai_local(aktproccode),templist);
-        templist.Free;
-
-        first_tai_local:=findfirst_tai_local(aktproccode);
-        if assigned(first_tai_local) then
+        templist:=TAsmList.create;
+        local:=nil;
+        first:=true;
+        l:=ttgwasm(tg).localvars.first;
+        while Assigned(l) do
           begin
-            first_tai_local.first:=true;
-            { also find the last tai_local in the group }
-            last_tai_local:=first_tai_local;
-            while assigned(last_tai_local.Next) and (tai(last_tai_local.Next).typ=ait_local) do
-              last_tai_local:=tai_local(last_tai_local.Next);
-            last_tai_local.last:=true;
+            local:=tai_local.create(l.typ);
+            local.first:=first;
+            first:=false;
+            templist.Concat(local);
+            l:=l.nextseq;
           end;
+        if assigned(local) then
+          local.last:=true;
+        aktproccode.insertListAfter(findfirst_tai_functype(aktproccode),templist);
+        templist.Free;
 
         replace_local_frame_pointer(aktproccode);
 

+ 0 - 3
compiler/wasm32/hlcgcpu.pas

@@ -1406,9 +1406,6 @@ implementation
       ttgwasm(tg).allocframepointer(list,pd.frame_pointer_ref);
       ttgwasm(tg).allocbasepointer(list,pd.base_pointer_ref);
 
-      list.Concat(tai_local.create(wbt_i32,FRAME_POINTER_SYM)); //TWasmBasicType
-      list.Concat(tai_local.create(wbt_i32,BASE_POINTER_SYM)); //TWasmBasicType
-
       g_fingerprint(list);
 
       list.Concat(taicpu.op_sym(a_global_get,current_asmdata.RefAsmSymbol(STACK_POINTER_SYM,AT_LABEL)));