public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Daniel Ptáček" <ptacek.daniel@gmail.com>
To: gcc-help@gcc.gnu.org
Subject: Plugin duplicating statements
Date: Thu, 13 Mar 2014 10:19:00 -0000	[thread overview]
Message-ID: <CAKWC6SVxp-_1QDvHT0Pjn0hn6e28C7nOjHgcFvo7Kn34MBc0kg@mail.gmail.com> (raw)

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

                 reply	other threads:[~2014-03-13  2:24 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAKWC6SVxp-_1QDvHT0Pjn0hn6e28C7nOjHgcFvo7Kn34MBc0kg@mail.gmail.com \
    --to=ptacek.daniel@gmail.com \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).