diff options
author | florian <florian@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2018-07-22 13:11:21 +0000 |
---|---|---|
committer | florian <florian@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2018-07-22 13:11:21 +0000 |
commit | 42ca2d8c685355c7c952cdab65acf0b3615c328a (patch) | |
tree | 5e4745d6d36a89d8d22bd89af9500e362b3fe0e8 | |
parent | 65c01806a1a26e325ffd2f8cf0b4d5e885c792f9 (diff) | |
download | fpc-42ca2d8c685355c7c952cdab65acf0b3615c328a.tar.gz |
* 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: https://svn.freepascal.org/svn/fpc/branches/laksen@39483 3ad0048d-3df7-0310-abae-a5850022a9f2
-rw-r--r-- | riscv_new/compiler/nadd.pas | 2 | ||||
-rw-r--r-- | riscv_new/compiler/nutils.pas | 20 |
2 files changed, 18 insertions, 4 deletions
diff --git a/riscv_new/compiler/nadd.pas b/riscv_new/compiler/nadd.pas index 42de054299..c32d454bbc 100644 --- a/riscv_new/compiler/nadd.pas +++ b/riscv_new/compiler/nadd.pas @@ -1008,7 +1008,7 @@ implementation end; end { 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 case nodetype of andn,orn: diff --git a/riscv_new/compiler/nutils.pas b/riscv_new/compiler/nutils.pas index c6d1b1e804..2ebd6f05dc 100644 --- a/riscv_new/compiler/nutils.pas +++ b/riscv_new/compiler/nutils.pas @@ -54,6 +54,14 @@ interface then the parent node is processed again } 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; staticforeachnodefunction = function(var n: tnode; arg: pointer): foreachnoderesult; @@ -117,7 +125,7 @@ interface function genloadfield(n: tnode; const fieldname: string): tnode; { 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; { count the number of nodes in the node tree, rough estimation how large the tree "node" is } @@ -1334,13 +1342,19 @@ implementation 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_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 result:=fen_norecurse_true; end; - function might_have_sideeffects(n : tnode) : boolean; + + function might_have_sideeffects(n : tnode; const flags : tmhs_flags) : boolean; begin - result:=foreachnodestatic(n,@check_for_sideeffect,nil); + result:=foreachnodestatic(n,@check_for_sideeffect,@flags); end; var |