This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[GIMPLE] Modify the value of a variable


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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]