Преглед на файлове

* reduce number of (redundant) landing pads
* reduce number of (redundant) action lists

git-svn-id: branches/debug_eh@41470 -

florian преди 6 години
родител
ревизия
12a53ad454
променени са 2 файла, в които са добавени 33 реда и са изтрити 14 реда
  1. 2 2
      compiler/ncgflw.pas
  2. 31 12
      compiler/psabiehpi.pas

+ 2 - 2
compiler/ncgflw.pas

@@ -1437,11 +1437,11 @@ implementation
             if psabiehprocinfo.PopLandingPad(CurrentLandingPad) then
             if psabiehprocinfo.PopLandingPad(CurrentLandingPad) then
               exclude(flowcontrol,fc_catching_exceptions);
               exclude(flowcontrol,fc_catching_exceptions);
             CurrentAction:=psabiehprocinfo.CurrentAction;
             CurrentAction:=psabiehprocinfo.CurrentAction;
-            psabiehprocinfo.PopAction(CurrentAction);
+            psabiehprocinfo.FinalizeAndPopAction(CurrentAction);
 
 
             if not(fc_catching_exceptions in flowcontrol) then
             if not(fc_catching_exceptions in flowcontrol) then
               begin
               begin
-                ReRaiseLandingPad:=TPSABIEHAction.Create(nil);
+                ReRaiseLandingPad:=psabiehprocinfo.NoAction;
                 psabiehprocinfo.PushAction(ReRaiseLandingPad);
                 psabiehprocinfo.PushAction(ReRaiseLandingPad);
                 psabiehprocinfo.PushLandingPad(ReRaiseLandingPad);
                 psabiehprocinfo.PushLandingPad(ReRaiseLandingPad);
               end;
               end;

+ 31 - 12
compiler/psabiehpi.pas

@@ -64,6 +64,9 @@ unit psabiehpi;
            since a procedure which has one landing pad need to be covered completely by landing pads }
            since a procedure which has one landing pad need to be covered completely by landing pads }
          OutmostLandingPad: TPSABIEHAction;
          OutmostLandingPad: TPSABIEHAction;
 
 
+         { This is a "no action" action for re-use, normally equal to OutmostLandingPad }
+         NoAction: TPSABIEHAction;
+
          callsite_table_data,
          callsite_table_data,
          action_table_data,
          action_table_data,
          gcc_except_table_data : TAsmList;
          gcc_except_table_data : TAsmList;
@@ -83,6 +86,7 @@ unit psabiehpi;
          procedure PushAction(action: TPSABIEHAction);
          procedure PushAction(action: TPSABIEHAction);
          function CurrentAction: TPSABIEHAction;inline;
          function CurrentAction: TPSABIEHAction;inline;
          function PopAction(action: TPSABIEHAction): boolean;
          function PopAction(action: TPSABIEHAction): boolean;
+         function FinalizeAndPopAction(action: TPSABIEHAction): boolean;
          { a landing pad is also an action, however, when the landing pad is popped from the stack
          { a landing pad is also an action, however, when the landing pad is popped from the stack
            the area covered by this landing pad ends, i.e. it is popped at the beginning of the finally/except clause,
            the area covered by this landing pad ends, i.e. it is popped at the beginning of the finally/except clause,
            the action above is popped at the end of the finally/except clause, so if on clauses add new types, they
            the action above is popped at the end of the finally/except clause, so if on clauses add new types, they
@@ -237,6 +241,15 @@ implementation
 
 
 
 
     function tpsabiehprocinfo.PopAction(action: TPSABIEHAction): boolean;
     function tpsabiehprocinfo.PopAction(action: TPSABIEHAction): boolean;
+      begin
+        if CurrentAction<>action then
+          internalerror(2019022501);
+        actionstack.count:=actionstack.count-1;
+        result:=actionstack.count=0;
+      end;
+
+
+    function tpsabiehprocinfo.FinalizeAndPopAction(action: TPSABIEHAction): boolean;
       var
       var
         curpos: tasmlabel;
         curpos: tasmlabel;
       begin
       begin
@@ -404,6 +417,7 @@ implementation
             CreateNewPSABIEHCallsite(current_asmdata.CurrAsmList);
             CreateNewPSABIEHCallsite(current_asmdata.CurrAsmList);
 
 
             OutmostLandingPad:=TPSABIEHAction.Create(nil);
             OutmostLandingPad:=TPSABIEHAction.Create(nil);
+            NoAction:=OutmostLandingPad;
             PushAction(OutmostLandingPad);
             PushAction(OutmostLandingPad);
             PushLandingPad(OutmostLandingPad);
             PushLandingPad(OutmostLandingPad);
             OutmostLandingPad.AddAction(nil);
             OutmostLandingPad.AddAction(nil);
@@ -491,7 +505,7 @@ implementation
          begin
          begin
            CreateNewPSABIEHCallsite(list);
            CreateNewPSABIEHCallsite(list);
            PopLandingPad(CurrentLandingPad);
            PopLandingPad(CurrentLandingPad);
-           PopAction(OutmostLandingPad);
+           FinalizeAndPopAction(OutmostLandingPad);
          end;
          end;
       end;
       end;
 
 
@@ -505,7 +519,7 @@ implementation
     class procedure tpsabiehexceptionstatehandler.unget_exception_temps(list: TAsmList; const t: texceptiontemps);
     class procedure tpsabiehexceptionstatehandler.unget_exception_temps(list: TAsmList; const t: texceptiontemps);
       begin
       begin
         tg.ungettemp(list,t.reasonbuf);
         tg.ungettemp(list,t.reasonbuf);
-        (current_procinfo as tpsabiehprocinfo).PopAction((current_procinfo as tpsabiehprocinfo).CurrentAction);
+        (current_procinfo as tpsabiehprocinfo).FinalizeAndPopAction((current_procinfo as tpsabiehprocinfo).CurrentAction);
       end;
       end;
 
 
 
 
@@ -589,7 +603,7 @@ implementation
     class procedure tpsabiehexceptionstatehandler.free_exception(list: TAsmList; const t: texceptiontemps; const s: texceptionstate; a: aint;
     class procedure tpsabiehexceptionstatehandler.free_exception(list: TAsmList; const t: texceptiontemps; const s: texceptionstate; a: aint;
       endexceptlabel: tasmlabel; onlyfree: boolean);
       endexceptlabel: tasmlabel; onlyfree: boolean);
       begin
       begin
-        (current_procinfo as tpsabiehprocinfo).CreateNewPSABIEHCallsite(list);
+        { nothing to do }
       end;
       end;
 
 
 
 
@@ -607,12 +621,14 @@ implementation
             { Resume might not be called outside of an landing pad else
             { Resume might not be called outside of an landing pad else
               the unwind is immediatly terminated, so create an empty landing pad }
               the unwind is immediatly terminated, so create an empty landing pad }
             psabiehprocinfo:=current_procinfo as tpsabiehprocinfo;
             psabiehprocinfo:=current_procinfo as tpsabiehprocinfo;
-            psabiehprocinfo.CreateNewPSABIEHCallsite(list);
 
 
-            ReRaiseLandingPad:=TPSABIEHAction.Create(nil);
-            psabiehprocinfo.PushAction(ReRaiseLandingPad);
-            psabiehprocinfo.PushLandingPad(ReRaiseLandingPad);
-            ReRaiseLandingPad.AddAction(nil);
+            if psabiehprocinfo.landingpadstack.count>1 then
+              begin
+                psabiehprocinfo.CreateNewPSABIEHCallsite(list);
+
+                psabiehprocinfo.PushAction(psabiehprocinfo.NoAction);
+                psabiehprocinfo.PushLandingPad(psabiehprocinfo.NoAction);
+              end;
 
 
             pd:=search_system_proc('fpc_resume');
             pd:=search_system_proc('fpc_resume');
             cgpara1.init;
             cgpara1.init;
@@ -623,9 +639,12 @@ implementation
             { we do not have to clean up the stack, we never return }
             { we do not have to clean up the stack, we never return }
             cgpara1.done;
             cgpara1.done;
 
 
-            psabiehprocinfo.CreateNewPSABIEHCallsite(list);
-            psabiehprocinfo.PopLandingPad(psabiehprocinfo.CurrentLandingPad);
-            psabiehprocinfo.PopAction(ReRaiseLandingPad);
+            if psabiehprocinfo.landingpadstack.count>1 then
+              begin
+                psabiehprocinfo.CreateNewPSABIEHCallsite(list);
+                psabiehprocinfo.PopLandingPad(psabiehprocinfo.NoAction);
+                psabiehprocinfo.PopAction(psabiehprocinfo.NoAction);
+              end;
           end
           end
         else
         else
           begin
           begin
@@ -635,7 +654,7 @@ implementation
               begin
               begin
                 psabiehprocinfo.CreateNewPSABIEHCallsite(list);
                 psabiehprocinfo.CreateNewPSABIEHCallsite(list);
 
 
-                ReRaiseLandingPad:=TPSABIEHAction.Create(nil);
+                ReRaiseLandingPad:=psabiehprocinfo.NoAction;
                 psabiehprocinfo.PushAction(ReRaiseLandingPad);
                 psabiehprocinfo.PushAction(ReRaiseLandingPad);
                 psabiehprocinfo.PushLandingPad(ReRaiseLandingPad);
                 psabiehprocinfo.PushLandingPad(ReRaiseLandingPad);
               end
               end