On Sun, 2021-10-10 at 23:04 +0530, Shubham Narlawar via Gcc wrote: > Hello, > > Is there a direct way to print the name of the function call in gimple > call > statement? > > For example - > > void bar() { > a = foo(); //gimple* stmt > } > > I want to print "foo" from the above gimple*. > > I traced debug_gimple_stmt(gimple*) but it seems complex to just print > "foo".
Bear in mind that not every gimple call is calling a specific function; it could be a jump through a function pointer. tree fn_ptr = gimple_call_fn (call); However, for simple cases like the above, fn_ptr will be an ADDR_EXPR node, and the zeroth operand of the ADDR_EXPR node will get you the fndecl (of "foo"). tree fn_decl = TREE_OPERAND (fn_ptr, 0); Given a decl, you can then use: tree identifier = DECL_NAME (fn_decl); to get the identifier node for the decl ("foo"). Finally, you can use const char *str = IDENTIFIER_POINTER (identifier) to get a 0-terminated string from the identifier that you can print. Hope this is helpful Dave