Hi,

I work with a lot of code in C and Fortran. 
My main task is to select, which of the function parameters and global
variables are input (they are only read out), output (they are only written
down) or inout (both uses) in the function. I wish GCC internals helped me.
Maybe you have better solution...

I use GIMPLE - who have heard about it, knows its advantages -
language-independent IR for GCC.

I wrote a plugin which is dynamically linked as a library during compilation
(using -fplugin flag). I can gather global, local variables and parameters
for each function. I have an access to each statement in the function:


struct cgraph_node *node;
basic_block bb;
gimple_stmt_iterator gsi;

/* Iterating over the cgraph nodes */
for (node=cgraph_nodes; node; node=node->next) {
    /* Nodes without a body, and clone nodes are n t interesting. */
    if (!gimple_has_body_p (node->decl) || node->clone_of)
        continue;
    
    /* Push the context. */
    push_cfun (DECL_STRUCT_FUNCTION (node->decl));

    /* Itarating over the function parameters */
    for (parm = DECL_ARGUMENTS (cfun->decl); parm ; parm = DECL_CHAIN(parm))
{
            print_generic_expr(stdout, parm, 0);
    }

    /* Iterating over each basic block of a function */
    FOR_EACH_BB_FN (bb, cfun) {
        /*Iterating over each gimple statement in a basic block*/
        for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) {
            gimple stmt = gsi_stmt (gsi);
            print_gimple_stmt (stdout, stmt, 0, 0);
        }
    }
}



Are here any gcc experts who show me the simply way to resolve my problems?

 How to resolve a problem with pointers (especially arrays)? For example, we
have a GIMPLE function:

set_a (int * a)
{
  int * D.2701;
  D.2701 = a + 40;
  *D.2701 = 7;
}

This is equivalent code in C:

void set_a(int * a) {
    a[10] = 107;
}

GIMPLE tries to avoid operations on the left side of the assign sign. There
is a problem because I want to identify local variable (D.2701) with
function parameter (a). In this case "a" is output parameter. I could follow
a behavior of parameters in my plugin, but I suppose that GIMPLE makes
accessible better solution, doesn't it?


 For each statement, which is_gimple_assign(), I'm going to extract not
local variables and decide which of them is input/output/inout depending on
the assigment. Is there a simpler way?


If a function calls another, the intent of variables should be passed to the
first one. But what if the callee is in the other compilation unit? Does
anyone have knowledge of using LTO mode? 


Thank you for all the answers.
-- 
View this message in context: 
http://old.nabble.com/GIMPLE-and-intent-of-variables-tp32275433p32275433.html
Sent from the gcc - patches mailing list archive at Nabble.com.

Reply via email to