gccgimplegcc-plugins

GCC plugins API : Gimple pass


I've been looking into online resources on writing GCC plugins. I'm currently using GCC version 7.3.0. I attempted writing a simple plugin that contained a callback which would be called upon PLUGIN_FINISH_TYPE. It worked fine.

Next, I'm trying to write a plugin that uses a "gimple pass" similar to the example listed here. However, struct gimple_opt_pass does not seem to exist.

I tried looking for header files that declare this struct. I found that tree-pass.h has the following code block :-

/* Description of GIMPLE pass.  */
class gimple_opt_pass : public opt_pass
{
protected:
  gimple_opt_pass (const pass_data& data, gcc::context *ctxt)
    : opt_pass (data, ctxt)
  {
  }
};
  1. How can I see this from within my plugin? I don't seem to be able to use this in the way as described in the link above.
  2. With the current GCC plugin API, is it possible to write a pure C plugin(as opposed to having to use C++).

Solution

  • I've found the answer. The API for GCC plugins changed dramatically from 4.8 to 4.9. Uptil 4.8, gimple_opt_class was a structure that you could create an instance of and use with register_pass_info. From 4.9 onward, it is a class that you would need to inherit from, create an instance of and use with register_pass_info.

    In order to be able to use pure C plugins with GCC, it would seem like using the API for version below and including 4.8 would be the solution. 4.6 seems to be working fine for me, but does to seem to have debug/dump functionality in it.