public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* [GIMPLE] Modify the value of a variable
@ 2012-03-23 19:27 Sergio Aldea
  0 siblings, 0 replies; only message in thread
From: Sergio Aldea @ 2012-03-23 19:27 UTC (permalink / raw)
  To: gcc-help

Hi,

I'm writing a plugin that needs to modify the code. I've inserted the  
plugin after the "cfg" pass.
I'm trying to modify the value of an integer-type variable. Let's say  
that I have the following code:

int before_pragma = 1;
//...more code...
#pragma omp parallel for
for (i=0; i<N; i++) { ... }
printf("Value of before_pragma: %d\n",before_pragma);



When the pragma is recognized, the plugin has to add a new statement  
before the pragma, modifying the value of an existing variable. For  
example:

int before_pragma = 1;
//..more code...
before_pragma = 15;
#pragma omp parallel for
for (i=0; i<N; i++) { ... }
printf("Value of before_pragma: %d\n",before_pragma);

To do that, I've written the following code:

tree before_pragma_var = build_decl (UNKNOWN_LOCATION, VAR_DECL,  
get_identifier("before_pragma"), integer_type_node);
tree number = build_int_cst (integer_type_node,15);
gimple assign = gimple_build_assign (before_pragma_var,number);
gsi_insert_before (&gsi, assign, GSI_NEW_STMT);

which inserts a NEW version of the variable. This is an extract of the  
dump file generated after the SSA pass:

before_pragma_2 = 1;
...
before_pragma_9 = 15;
__builtin_GOMP_parallel_start (main._omp_fn.0, &.omp_data_o.1, 0);
main._omp_fn.0 (&.omp_data_o.1);
__builtin_GOMP_parallel_end ();
D.3214_10 = (const char * restrict) &"before_pragma: %d\n"[0];
printf (D.3214_10, before_pragma_2);

How can I tell the compiler to update the subsequent readings of the variable?

Maybe I'm focusing the problem in the wrong way. Maybe I have to  
directly modify the variable declaration, instead of creating a new  
assignment.
I'm just starting to learn how to manipulate the gimple tree, and I've  
search how to do that, but I wasn't able to find it.

Thank you in advance for your help,

   Sergio

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2012-03-23 19:27 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-23 19:27 [GIMPLE] Modify the value of a variable Sergio Aldea

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).