diff options
author | Alexandre Oliva <oliva@adacore.com> | 2021-01-11 23:37:59 -0300 |
---|---|---|
committer | Alexandre Oliva <oliva@gnu.org> | 2021-01-11 23:37:59 -0300 |
commit | 640296c367f97a1b9974bfb60bb02c934d71baf4 (patch) | |
tree | df3eae8c2ec9b2891ef1e53258a47ccd24182fd4 /gcc/ssa-iterators.h | |
parent | ab88f3607233376c3145c320e92e71943a495bb5 (diff) | |
download | gcc-640296c367f97a1b9974bfb60bb02c934d71baf4.zip gcc-640296c367f97a1b9974bfb60bb02c934d71baf4.tar.gz gcc-640296c367f97a1b9974bfb60bb02c934d71baf4.tar.bz2 |
make FOR_EACH_IMM_USE_STMT safe for early exits
Use a dtor to automatically remove ITER from IMM_USE list in
FOR_EACH_IMM_USE_STMT.
for gcc/ChangeLog
* ssa-iterators.h (end_imm_use_stmt_traverse): Forward
declare.
(auto_end_imm_use_stmt_traverse): New struct.
(FOR_EACH_IMM_USE_STMT): Use it.
(BREAK_FROM_IMM_USE_STMT, RETURN_FROM_IMM_USE_STMT): Remove,
along with uses...
* gimple-ssa-strength-reduction.c: ... here, ...
* graphite-scop-detection.c: ... here, ...
* ipa-modref.c, ipa-pure-const.c, ipa-sra.c: ... here, ...
* tree-predcom.c, tree-ssa-ccp.c: ... here, ...
* tree-ssa-dce.c, tree-ssa-dse.c: ... here, ...
* tree-ssa-loop-ivopts.c, tree-ssa-math-opts.c: ... here, ...
* tree-ssa-phiprop.c, tree-ssa.c: ... here, ...
* tree-vect-slp.c: ... and here, ...
* doc/tree-ssa.texi: ... and the example here.
Diffstat (limited to 'gcc/ssa-iterators.h')
-rw-r--r-- | gcc/ssa-iterators.h | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/gcc/ssa-iterators.h b/gcc/ssa-iterators.h index c0b45b6..f70b0a4 100644 --- a/gcc/ssa-iterators.h +++ b/gcc/ssa-iterators.h @@ -77,29 +77,32 @@ struct imm_use_iterator !end_readonly_imm_use_p (&(ITER)); \ (void) ((DEST) = next_readonly_imm_use (&(ITER)))) -/* Use this iterator to visit each stmt which has a use of SSAVAR. */ +/* Forward declare for use in the class below. */ +static inline void end_imm_use_stmt_traverse (imm_use_iterator *); + +/* arrange to automatically call, upon descruction, end_imm_use_stmt_traverse + with a given pointer to imm_use_iterator. */ +struct auto_end_imm_use_stmt_traverse +{ + imm_use_iterator *imm; + auto_end_imm_use_stmt_traverse (imm_use_iterator *imm) + : imm (imm) {} + ~auto_end_imm_use_stmt_traverse () + { end_imm_use_stmt_traverse (imm); } +}; + +/* Use this iterator to visit each stmt which has a use of SSAVAR. The + destructor of the auto_end_imm_use_stmt_traverse object deals with removing + ITER from SSAVAR's IMM_USE list even when leaving the scope early. */ #define FOR_EACH_IMM_USE_STMT(STMT, ITER, SSAVAR) \ - for ((STMT) = first_imm_use_stmt (&(ITER), (SSAVAR)); \ + for (struct auto_end_imm_use_stmt_traverse \ + auto_end_imm_use_stmt_traverse \ + ((((STMT) = first_imm_use_stmt (&(ITER), (SSAVAR))), \ + &(ITER))); \ !end_imm_use_stmt_p (&(ITER)); \ (void) ((STMT) = next_imm_use_stmt (&(ITER)))) -/* Use this to terminate the FOR_EACH_IMM_USE_STMT loop early. Failure to - do so will result in leaving a iterator marker node in the immediate - use list, and nothing good will come from that. */ -#define BREAK_FROM_IMM_USE_STMT(ITER) \ - { \ - end_imm_use_stmt_traverse (&(ITER)); \ - break; \ - } - -/* Similarly for return. */ -#define RETURN_FROM_IMM_USE_STMT(ITER, VAL) \ - { \ - end_imm_use_stmt_traverse (&(ITER)); \ - return (VAL); \ - } - /* Use this iterator in combination with FOR_EACH_IMM_USE_STMT to get access to each occurrence of ssavar on the stmt returned by that iterator.. for instance: |