On 09/15/2015 03:38 PM, Aditya K wrote:
> I started with one of the test cases in the plugin testsuite "def_plugin.c".
> Pasted the code for convenience.
> I want to traverse all the loops in a function.
>
> Maybe use, loops_for_fn (DECL_STRUCT_FUNCTION (fndef)), but this does not
> seem to work.
>
>
> /* Callback function to invoke after GCC finishes a function definition. */
I guess, loop structure is initialized much later within the optimization
pipeline. I.e., PLUGIN_FINISH_PARSE_FUNCTION is invoked before all optimizers,
and (natural) loops are discovered by the "loopinit" pass.
Perhaps, you could try registering a pass using
register_callback (..., PLUGIN_PASS_MANAGER_SETUP, ...)
and make it run within pass_tree_loop (see gcc/passes.def for details). You
should also specify 'PROP_loops' in 'properties_required' of your 'pass_data'
structure. Then 'loops_for_fn' should work.
'selfassign.c' is a good example of a plugin which creates an optimization pass
(and 'dumb_plugin.c' is a good minimal example).
--
Regards,
Mikhail Maltsev