On March 15, 2021 7:31:46 PM GMT+01:00, Thomas Schwinge <tho...@codesourcery.com> wrote: >Hi! > >First time I'm using this API -- so the error certainly may be on my >side. ;-) > >What I'm doing, is a 'walk_gimple_seq', and in that one's >'callback_stmt', call 'walk_stmt_load_store_addr_ops', to collect >variable load/store/address-taken instances. This did seem quite >straight-forward, given the description; 'gcc/gimple-walk.c': > >/* For the statement STMT call the callbacks VISIT_LOAD, VISIT_STORE >and > VISIT_ADDR if non-NULL on loads, store and address-taken operands >passing the STMT, the base of the operand, the operand itself >containing > the base and DATA to it. The base will be either a decl, an indirect > reference (including TARGET_MEM_REF) or the argument of an address > expression. > Returns the results of these callbacks or'ed. */ > > bool > walk_stmt_load_store_addr_ops (gimple *stmt, void *data, > walk_stmt_load_store_addr_fn visit_load, > walk_stmt_load_store_addr_fn visit_store, > walk_stmt_load_store_addr_fn visit_addr) > { [...] } > >Indeed, given (Fortran) 'zzz = 1', we produce GIMPLE: > > gimple_assign <real_cst, zzz, 1.0e+0, NULL, NULL> > >..., and calling 'walk_stmt_load_store_addr_ops' on that, I see, as >expected, the 'visit_store' callback invoked, with 'rhs' and 'arg': >'<var_decl zzz>'. > >However, given (Fortran) 'zzz = r + r2', we produce GIMPLE: > > gimple_assign <plus_expr, zzz, r, r2, NULL> > >..., and calling 'walk_stmt_load_store_addr_ops' on that, I see, >unexpectedly, no callback at all invoked: neither 'visit_load', nor >'visit_store' (nor 'visit_address', obviously).
The variables involved are registers. You only get called on memory operands. >From a quick look at 'gcc/gimple-walk.c:walk_stmt_load_store_addr_ops', >this seems to intentionally be implemented in this way -- but I don't >understand the rationale? > > >Instead of 'walk_gimple_seq' -> 'callback_stmt' -> >'walk_stmt_load_store_addr_ops', do I need to use 'walk_gimple_seq' -> >'callback_op' -> "something"? Yes, if you want to visit register sets and uses as a well. Note you'll also see constants that way. Richard. > >Grüße > Thomas >----------------- >Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München >Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, >Frank Thürauf