This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Extracting the size of a variable from its tree representation
- From: Amittai Aviram <amittai dot aviram at yale dot edu>
- To: gcc-help at gcc dot gnu dot org
- Date: Sat, 7 Jul 2012 02:55:44 -0400
- Subject: Extracting the size of a variable from its tree representation
I have written a modification of the function "lower_omp_clauses" inside gcc/omp-low.c . Whenever this function encounters an OpenMP reduction clause, my code needs to get the type and size of the reduction variable. (By size, I mean the integer constant equal to the result of the sizeof operator applied to that variable.) I have managed to do this so far for C target code, but I've run into a problem with a Fortran program that has a reduction on a variable of type "double precision" (i.e., double). My code reports the type, correctly, as REAL_TYPE, but it reports the size erroneously as 0 instead of 8.
Here is a reduced version of how I go about trying to gather my information. What should I be doing instead, particularly to get the size?
lower_reduction_clauses (tree clauses, gimple_seq *stmt_seqp, omp_context *ctx)
{
tree c;
/* ... */
for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
{
tree var, ref, new_var;
enum tree_code code;
enum tree_code new_var_type;
size_t new_var_size;
location_t clause_loc = OMP_CLAUSE_LOCATION (c);
var = OMP_CLAUSE_DECL (c);
new_var = lookup_decl (var, ctx);
if (is_reference (var))
new_var = build_simple_mem_ref_loc (clause_loc, new_var);
ref = build_outer_var_ref (var, ctx);
code = OMP_CLAUSE_REDUCTION_CODE (c);
new_var_type = TREE_CODE(TREE_TYPE(new_var));
new_var_size = (size_t)(new_var->var_decl.common.common.common.size->
int_cst.int_cst.low / 8);
/* ... */
}
/* ... */
}
Thanks!
Amittai Aviram
PhD Student in Computer Science
Yale University
646 483 2639
amittai.aviram@yale.edu
http://www.amittai.com