Просмотр исходного кода

* might_have_sideeffects gets flags: if mhs_exceptions is passed, nodes which might cause an exception are considered as having a side effect

git-svn-id: branches/laksen/riscv_new@39483 -
(cherry picked from commit 32a58ba7d10605f9ccd0563f69ce7511d1e812f0)
florian 7 лет назад
Родитель
Сommit
4e5fb2c6a8
2 измененных файлов с 18 добавлено и 4 удалено
  1. 1 1
      compiler/nadd.pas
  2. 17 3
      compiler/nutils.pas

+ 1 - 1
compiler/nadd.pas

@@ -1011,7 +1011,7 @@ implementation
                     end;
                     end;
                   end
                   end
                 { short to full boolean evalution possible and useful? }
                 { short to full boolean evalution possible and useful? }
-                else if not(might_have_sideeffects(right)) and not(cs_full_boolean_eval in localswitches) then
+                else if not(might_have_sideeffects(right,[mhs_exceptions])) and not(cs_full_boolean_eval in localswitches) then
                   begin
                   begin
                     case nodetype of
                     case nodetype of
                       andn,orn:
                       andn,orn:

+ 17 - 3
compiler/nutils.pas

@@ -54,6 +54,14 @@ interface
                             then the parent node is processed again }
                             then the parent node is processed again }
                           pm_postandagain);
                           pm_postandagain);
 
 
+
+    tmhs_flag = (
+      { exceptions (overflow, sigfault etc.) are considered as side effect }
+      mhs_exceptions
+    );
+    tmhs_flags = set of tmhs_flag;
+    pmhs_flags = ^tmhs_flags;
+
     foreachnodefunction = function(var n: tnode; arg: pointer): foreachnoderesult of object;
     foreachnodefunction = function(var n: tnode; arg: pointer): foreachnoderesult of object;
     staticforeachnodefunction = function(var n: tnode; arg: pointer): foreachnoderesult;
     staticforeachnodefunction = function(var n: tnode; arg: pointer): foreachnoderesult;
 
 
@@ -117,7 +125,7 @@ interface
     function genloadfield(n: tnode; const fieldname: string): tnode;
     function genloadfield(n: tnode; const fieldname: string): tnode;
 
 
     { returns true, if the tree given might have side effects }
     { returns true, if the tree given might have side effects }
-    function might_have_sideeffects(n : tnode) : boolean;
+    function might_have_sideeffects(n : tnode;const flags : tmhs_flags = []) : boolean;
 
 
     { returns true, if n contains nodes which might be conditionally executed }
     { returns true, if n contains nodes which might be conditionally executed }
     function has_conditional_nodes(n : tnode) : boolean;
     function has_conditional_nodes(n : tnode) : boolean;
@@ -1371,13 +1379,19 @@ implementation
              in_finalize_x,in_new_x,in_dispose_x,in_exit,in_copy_x,in_initialize_x,in_leave,in_cycle,
              in_finalize_x,in_new_x,in_dispose_x,in_exit,in_copy_x,in_initialize_x,in_leave,in_cycle,
              in_and_assign_x_y,in_or_assign_x_y,in_xor_assign_x_y,in_sar_assign_x_y,in_shl_assign_x_y,
              in_and_assign_x_y,in_or_assign_x_y,in_xor_assign_x_y,in_sar_assign_x_y,in_shl_assign_x_y,
              in_shr_assign_x_y,in_rol_assign_x_y,in_ror_assign_x_y,in_neg_assign_x,in_not_assign_x])
              in_shr_assign_x_y,in_rol_assign_x_y,in_ror_assign_x_y,in_neg_assign_x,in_not_assign_x])
+          ) or
+          ((mhs_exceptions in pmhs_flags(arg)^) and
+           ((n.nodetype in [derefn,vecn]) or
+            ((n.nodetype in [addn,subn,muln,divn,slashn,unaryminusn]) and (n.localswitches*[cs_check_overflow,cs_check_range]<>[]))
+           )
           ) then
           ) then
           result:=fen_norecurse_true;
           result:=fen_norecurse_true;
       end;
       end;
 
 
-    function might_have_sideeffects(n : tnode) : boolean;
+
+    function might_have_sideeffects(n : tnode; const flags : tmhs_flags) : boolean;
       begin
       begin
-        result:=foreachnodestatic(n,@check_for_sideeffect,nil);
+        result:=foreachnodestatic(n,@check_for_sideeffect,@flags);
       end;
       end;