c++cgccgimplegcc-plugins

Register a GIMPLE pass in gcc 5.1.0


Hi I've been doing gcc plugins for gcc 4.8 and 4.9 but I'm having a problem in gcc 5.1.0. The problem is that I can't register a GIMPLE pass in this new gcc version.

Here is an example plugin code:

int plugin_is_GPL_compatible;

static bool gateCheck(void)
{
    printf("BBBBB\n");
    return true;
}

static unsigned int executeCheck(void)
{
    printf("CCCCC\n");
    return 0;
}

const pass_data gimplePass =
{
    GIMPLE_PASS,    // opt type name
    "exampleChecker",  // name
    OPTGROUP_NONE,  // optinfo_flags
    TV_NONE,        // tv_id
    PROP_ssa,       // properties_required
    0,              // properties_provided
    0,              // properties_destroyed
    0,              // todo_flags_start
    0,              // todo_flags_finish
};

class passAttrChecker : public gimple_opt_pass
{
public:
    passAttrChecker(gcc::context* ctxt)
        : gimple_opt_pass(gimplePass, ctxt)
    {}

    bool gate (){return gateCheck();}
    unsigned int execute(){return executeCheck();}
};


extern int plugin_init(struct plugin_name_args* plugin_info,
                struct plugin_gcc_version* version)
{
    const char * name = "exampleChecker";
    struct register_pass_info pass_info;
    pass_info.pass = new passAttrChecker(g);
    pass_info.reference_pass_name = "ssa";
    pass_info.ref_pass_instance_number = 1;
    pass_info.pos_op = PASS_POS_INSERT_AFTER;
    register_callback(name, PLUGIN_PASS_MANAGER_SETUP, NULL, &pass_info);
    return 0;
}

When compiling some file with this plugin should be printed some B's and C's, but nothing is being printed.

The difference with gcc 4.9 is that the type "pass_data" has two less fields than before(has_gate and has_execute). Everything else seems to be like before. If someone knows what I'm doing wrong or what I'm missing, I'll appreciate the help.


Solution

  • I've already solved it. It was a pretty silly mistake. Now in gcc 5.1.0 the execute and gate methods from otp_pass recive one argument, instead of void.

    This way the example works:

    class passAttrChecker : public gimple_opt_pass
    {
    public:
        passAttrChecker(gcc::context* ctxt)
            : gimple_opt_pass(gimplePass, ctxt)
        {}
    
        bool gate (function *) 
        {
            std::cout << "GATE\n";
            return true;
        }
        unsigned int execute(function *)
        {
            std::cout << "EXECUTE\n";
            return 1;
        }
    };