Plugin duplicating statements

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,
i'm trying to write an experimental GCC plugin with pass, which
duplicates gimple statements in a certain basic block, but i have a
problem with renaming symbols to SSA form.

I'm iterating over statements in the block and putting deep copies of
them into vector. Then i'm retrieving the copies from the vector,
renaming them and inserting at the end of the block. It works fine for
the gimple assigns, but for gimple calls i'm getting segmentation
fault. Even if i call only "create_new_def_for" and not inserting the
copied statement. My pass seems to finish "successfully", so it looks
like a problem, i'm causing for another passes.
My pass is registred right after the "ssa" pass. Here's my code:

unsigned execute() {
    basic_block bb;
    gimple_stmt_iterator gsi;
    vector<gimple> stmt_queue;
    gimple g;
    FOR_EACH_BB(bb) {
        if (bb->index != 3) continue; //Block number 3 is what i want
to duplicate

        for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
            g = gsi_stmt(gsi);
            stmt_queue.push_back(gimple_copy(g));
        }
        gimple copy;
        def_operand_p def;
        gsi = gsi_last_bb(bb);
        for (int i = 0; i < stmt_queue.size(); i++) {
            copy = stmt_queue.at(i);
            if (is_gimple_assign(copy)) { //Removing this condition
causes SIGSEGV
                def = single_ssa_def_operand(copy, SSA_OP_DEF);
                create_new_def_for(gimple_op(copy, 1), copy, def);
                gsi_insert_after(&gsi, copy, GSI_NEW_STMT);
            }
        }
    }
    return 1;
}

This si an example of how test code looks like after the ssa pass (only bb 3):
<bb 3>:
  _2 = test (5);
  x_3 = x_1 + _2;

And this is after my pass (when duplicating all gimple statements):
<bb 3>:
  _2 = test (5);
  x_3 = x_1 + _2;
  _6 = test (5);
  x_7 = x_1 + _2;

The original code in C is "x += test(5);"

I'm new to developing GCC plugins and i'm trying to understand its
internals. I would really appreciate any help with solving this
problem and understanding why is the code after my pass corrupted and
causing internal compiler error.

Thanks




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux