[GIMPLE] Modify the value of a variable

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

 



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



[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