public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Martin Jambor <mjambor@suse.cz>
To: Rob Johnson <rob@cs.sunysb.edu>
Cc: gcc@gcc.gnu.org
Subject: Re: plugin help: Inserting a function call in gimple code?
Date: Thu, 03 Jan 2008 10:32:00 -0000	[thread overview]
Message-ID: <20080103102554.GA5061@dhcp64.suse.cz> (raw)
In-Reply-To: <477C1AA1.8000609@cs.sunysb.edu>

Hi,

On Wed, Jan 02, 2008 at 06:13:37PM -0500, Rob Johnson wrote:
> I'm experimenting with the gimple plugin infrastructure and I'm having 
> trouble instrumenting code in a way that is compatible with the optimizer.  
> Here's a simple example that is intended to insert the function call 
> "__memcheck_register_argv(argc, argv)" at the beginning of main.  The code 
> runs during pass_plugin_gimple (which comes right after pass_apply_inline 
> in passes.c) and works great with -O0, but causes the compiler to crash 
> with -O1 or higher.
>
> -------------------------------------
> tree argv_registrar_type;
> tree argv_registrar;
> tree argv_registrar_call;
>
> argv_registrar_type = build_function_type_list (void_type_node,
>                                                 integer_type_node,
>                                                 build_pointer_type
>                                                 (build_pointer_type
>                                                  (char_type_node)),
>                                                 NULL_TREE);
> argv_registrar = build_fn_decl ("__memcheck_register_argv",
>                                 argv_registrar_type);
> argv_registrar_call = build_call_expr (argv_registrar, 2,
>                                        DECL_ARGUMENTS (cfun->decl),
>                                        TREE_CHAIN (DECL_ARGUMENTS
>                                                    (cfun->decl)));

DECL_ARGUMENTS is a tree chain of PARM_DECLs and in SSA GIMPLE, scalar
operands  (integers  and  pointer  are  both  scalar,  is_gimple_reg()
predicate is there to identify  variables that need to be converted to
SSA) need to be SSA_NAMEs of declarations (PARM_DECLs and VAR_DECLs in
particular).

Therefore I suspect you need to create a different chain of respective
SSA_NAMES and pass that to build_call_expr().  You can get the default
SSA_NAME by calling gimple_default_def().

> bsi_insert_before (&iter, argv_registrar_call, BSI_SAME_STMT);
> ---------------------------------------
>
> With -O1, I get the compiler failure
>
> ---------------
> test.c: In function 'main':
> test.c:2: error: expected an SSA_NAME object
> test.c:2: error: in statement
> __memcheck_register_argv (argc, argv);
> test.c:2: internal compiler error: verify_ssa failed
> Please submit a full bug report,
> with preprocessed source if appropriate.
> See <URL:http://gcc.gnu.org/bugs.html> for instructions.
> ----------------
>
> when attempting to compile the code
>
> -----------------
> int main(int argc, char **argv)
> {
>   return 0;
> }
> -----------------
>
>

HTH

Martin

  reply	other threads:[~2008-01-03 10:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-02 23:15 Rob Johnson
2008-01-03 10:32 ` Martin Jambor [this message]
2008-01-03 21:26   ` Rob Johnson

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=20080103102554.GA5061@dhcp64.suse.cz \
    --to=mjambor@suse.cz \
    --cc=gcc@gcc.gnu.org \
    --cc=rob@cs.sunysb.edu \
    /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).