1*38fd1498Szrj /* Header file for gimple statement walk support. 2*38fd1498Szrj Copyright (C) 2013-2018 Free Software Foundation, Inc. 3*38fd1498Szrj 4*38fd1498Szrj This file is part of GCC. 5*38fd1498Szrj 6*38fd1498Szrj GCC is free software; you can redistribute it and/or modify it under 7*38fd1498Szrj the terms of the GNU General Public License as published by the Free 8*38fd1498Szrj Software Foundation; either version 3, or (at your option) any later 9*38fd1498Szrj version. 10*38fd1498Szrj 11*38fd1498Szrj GCC is distributed in the hope that it will be useful, but WITHOUT ANY 12*38fd1498Szrj WARRANTY; without even the implied warranty of MERCHANTABILITY or 13*38fd1498Szrj FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14*38fd1498Szrj for more details. 15*38fd1498Szrj 16*38fd1498Szrj You should have received a copy of the GNU General Public License 17*38fd1498Szrj along with GCC; see the file COPYING3. If not see 18*38fd1498Szrj <http://www.gnu.org/licenses/>. */ 19*38fd1498Szrj 20*38fd1498Szrj #ifndef GCC_GIMPLE_WALK_H 21*38fd1498Szrj #define GCC_GIMPLE_WALK_H 22*38fd1498Szrj 23*38fd1498Szrj /* Convenience routines to walk all statements of a gimple function. 24*38fd1498Szrj Note that this is useful exclusively before the code is converted 25*38fd1498Szrj into SSA form. Once the program is in SSA form, the standard 26*38fd1498Szrj operand interface should be used to analyze/modify statements. */ 27*38fd1498Szrj struct walk_stmt_info 28*38fd1498Szrj { 29*38fd1498Szrj /* Points to the current statement being walked. */ 30*38fd1498Szrj gimple_stmt_iterator gsi; 31*38fd1498Szrj gimple *stmt; 32*38fd1498Szrj 33*38fd1498Szrj /* Additional data that the callback functions may want to carry 34*38fd1498Szrj through the recursion. */ 35*38fd1498Szrj void *info; 36*38fd1498Szrj 37*38fd1498Szrj /* Pointer map used to mark visited tree nodes when calling 38*38fd1498Szrj walk_tree on each operand. If set to NULL, duplicate tree nodes 39*38fd1498Szrj will be visited more than once. */ 40*38fd1498Szrj hash_set<tree> *pset; 41*38fd1498Szrj 42*38fd1498Szrj /* Operand returned by the callbacks. This is set when calling 43*38fd1498Szrj walk_gimple_seq. If the walk_stmt_fn or walk_tree_fn callback 44*38fd1498Szrj returns non-NULL, this field will contain the tree returned by 45*38fd1498Szrj the last callback. */ 46*38fd1498Szrj tree callback_result; 47*38fd1498Szrj 48*38fd1498Szrj /* Indicates whether the operand being examined may be replaced 49*38fd1498Szrj with something that matches is_gimple_val (if true) or something 50*38fd1498Szrj slightly more complicated (if false). "Something" technically 51*38fd1498Szrj means the common subset of is_gimple_lvalue and is_gimple_rhs, 52*38fd1498Szrj but we never try to form anything more complicated than that, so 53*38fd1498Szrj we don't bother checking. 54*38fd1498Szrj 55*38fd1498Szrj Also note that CALLBACK should update this flag while walking the 56*38fd1498Szrj sub-expressions of a statement. For instance, when walking the 57*38fd1498Szrj statement 'foo (&var)', the flag VAL_ONLY will initially be set 58*38fd1498Szrj to true, however, when walking &var, the operand of that 59*38fd1498Szrj ADDR_EXPR does not need to be a GIMPLE value. */ 60*38fd1498Szrj BOOL_BITFIELD val_only : 1; 61*38fd1498Szrj 62*38fd1498Szrj /* True if we are currently walking the LHS of an assignment. */ 63*38fd1498Szrj BOOL_BITFIELD is_lhs : 1; 64*38fd1498Szrj 65*38fd1498Szrj /* Optional. Set to true by the callback functions if they made any 66*38fd1498Szrj changes. */ 67*38fd1498Szrj BOOL_BITFIELD changed : 1; 68*38fd1498Szrj 69*38fd1498Szrj /* True if we're interested in location information. */ 70*38fd1498Szrj BOOL_BITFIELD want_locations : 1; 71*38fd1498Szrj 72*38fd1498Szrj /* True if we've removed the statement that was processed. */ 73*38fd1498Szrj BOOL_BITFIELD removed_stmt : 1; 74*38fd1498Szrj }; 75*38fd1498Szrj 76*38fd1498Szrj /* Callback for walk_gimple_stmt. Called for every statement found 77*38fd1498Szrj during traversal. The first argument points to the statement to 78*38fd1498Szrj walk. The second argument is a flag that the callback sets to 79*38fd1498Szrj 'true' if it the callback handled all the operands and 80*38fd1498Szrj sub-statements of the statement (the default value of this flag is 81*38fd1498Szrj 'false'). The third argument is an anonymous pointer to data 82*38fd1498Szrj to be used by the callback. */ 83*38fd1498Szrj typedef tree (*walk_stmt_fn) (gimple_stmt_iterator *, bool *, 84*38fd1498Szrj struct walk_stmt_info *); 85*38fd1498Szrj 86*38fd1498Szrj extern gimple *walk_gimple_seq_mod (gimple_seq *, walk_stmt_fn, walk_tree_fn, 87*38fd1498Szrj struct walk_stmt_info *); 88*38fd1498Szrj extern gimple *walk_gimple_seq (gimple_seq, walk_stmt_fn, walk_tree_fn, 89*38fd1498Szrj struct walk_stmt_info *); 90*38fd1498Szrj extern tree walk_gimple_op (gimple *, walk_tree_fn, struct walk_stmt_info *); 91*38fd1498Szrj extern tree walk_gimple_stmt (gimple_stmt_iterator *, walk_stmt_fn, 92*38fd1498Szrj walk_tree_fn, struct walk_stmt_info *); 93*38fd1498Szrj typedef bool (*walk_stmt_load_store_addr_fn) (gimple *, tree, tree, void *); 94*38fd1498Szrj extern bool walk_stmt_load_store_addr_ops (gimple *, void *, 95*38fd1498Szrj walk_stmt_load_store_addr_fn, 96*38fd1498Szrj walk_stmt_load_store_addr_fn, 97*38fd1498Szrj walk_stmt_load_store_addr_fn); 98*38fd1498Szrj extern bool walk_stmt_load_store_ops (gimple *, void *, 99*38fd1498Szrj walk_stmt_load_store_addr_fn, 100*38fd1498Szrj walk_stmt_load_store_addr_fn); 101*38fd1498Szrj #endif /* GCC_GIMPLE_WALK_H */ 102