From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18510 invoked by alias); 3 Jan 2008 10:32:43 -0000 Received: (qmail 18490 invoked by uid 22791); 3 Jan 2008 10:32:41 -0000 X-Spam-Check-By: sourceware.org Received: from styx.suse.cz (HELO mail.suse.cz) (82.119.242.94) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 03 Jan 2008 10:27:04 +0000 Received: from suse.cz (dhcp64.suse.cz [10.20.4.64]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.suse.cz (Postfix) with ESMTP id B9D3B6280C2; Thu, 3 Jan 2008 11:26:54 +0100 (CET) Date: Thu, 03 Jan 2008 10:32:00 -0000 From: Martin Jambor To: Rob Johnson Cc: gcc@gcc.gnu.org Subject: Re: plugin help: Inserting a function call in gimple code? Message-ID: <20080103102554.GA5061@dhcp64.suse.cz> Mail-Followup-To: Rob Johnson , gcc@gcc.gnu.org References: <477C1AA1.8000609@cs.sunysb.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-2 Content-Disposition: inline In-Reply-To: <477C1AA1.8000609@cs.sunysb.edu> User-Agent: Mutt/1.5.16 (2007-06-09) X-IsSubscribed: yes Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org X-SW-Source: 2008-01/txt/msg00025.txt.bz2 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 for instructions. > ---------------- > > when attempting to compile the code > > ----------------- > int main(int argc, char **argv) > { > return 0; > } > ----------------- > > HTH Martin