On Fri, 2014-05-16 at 18:10 +0800, Bin.Cheng wrote: > On Thu, May 15, 2014 at 6:31 PM, Oleg Endo <oleg.e...@t-online.de> wrote: > > > > How about the following. > > Instead of adding new hooks and inserting the pass to the general pass > > list, make the new > > pass class take the necessary callback functions directly. Then targets > > can just instantiate > > the pass, passing their impl of the callbacks, and insert the pass object > > into the pass list at > > a place that fits best for the target.
> Oh, I don't know we can do this in GCC. But yes, a target may want to > run it at some place that fits best for the target. > I think it's better than trying to come up with a scheme that so-so fits all. My idea would look like: // merge_paired_loadstore.h class merge_paired_loadstore : public rtl_opt_pass { public: struct delegate { virtual bool merge_paired_loadstore (rtx x, rtx y, ...) = 0; ... }; merge_paired_loadstore (gcc::context* ctx, const char* name, delegate* d); ... }; // <target>.cc #include "merge_paired_loadstore.h" static struct target_merge_loadstore_delegate : merge_paired_loadstore::delegate { virtual bool merge_paired_loadstore (...) { // code as if this was a freestanding target hook function }; } g_merge_loadstore_delegate; static void <target>_register_passes (void) { register_pass ( new merge_paired_loadstore (g, "merge_ls", &g_merge_loadstore_delegate), PASS_POS_INSERT_AFTER, "other pass", 1); } Then, later, maybe sometime in the future, if there's something like a class target, it'd look like: class my_target : public target, merge_paired_loadstore::delegate { ... virtual bool merge_paired_loadstore (...); }; Maybe it's a bit far fetched at the moment, but it would be a start. Cheers, Oleg