r196640 - in /branches/cxx-conversion/gcc: asan...
dnovillo@gcc.gnu.org
dnovillo@gcc.gnu.org
Wed Mar 13 21:57:00 GMT 2013
Author: dnovillo
Date: Wed Mar 13 21:57:30 2013
New Revision: 196640
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=196640
Log:
This patch adds an initial implementation for a new helper type for
generating GIMPLE statements.
The type is called gimple_builder. There are two main variants:
gimple_builder_normal and gimple_builder_ssa. The difference between
the two is the temporaries they create. The 'normal' builder creates
temporaries in normal form (i.e., VAR_DECLs). The 'ssa' builder
creates SSA names.
The basic functionality is described in
http://gcc.gnu.org/wiki/cxx-conversion/gimple-generation. I expect it
to evolve as I address feedback on this initial implementation.
The patch implements the initial builder. It has enough functionality
to simplify the generation of 3 address assignments (the bulk of all
generated code).
To use the builder:
1- Declare an instance 'gb' of gimple_builder_normal or
gimple_builder_ssa. E.g., gimple_builder_ssa gb;
2- Use gb.add_* to add a new statement to it. This
returns an SSA name or VAR_DECL with the value of the added
statement.
3- Call gb.insert_*() to insert the sequence of statements in the
builder into a statement iterator.
For instance, in asan.c we generate the expression:
(shadow != 0) & (base_addr & 7) + (size_in_bytes - 1)) >= shadow).
with the following code:
-----------------------------------------------------------------------------
gimple_builder_ssa gb(location);
t = gb.add (NE_EXPR, shadow, 0);
tree t1 = gb.add (BIT_AND_EXPR, base_addr, 7);
t1 = gb.add_type_cast (shadow_type, t1);
if (size_in_bytes > 1)
t1 = gb.add (PLUS_EXPR, t1, size_in_bytes - 1);
t1 = gb.add (GE_EXPR, t1, shadow);
t = gb.add (BIT_AND_EXPR, t, t1);
gb.insert_after (&gsi, GSI_NEW_STMT);
-----------------------------------------------------------------------------
In contrast, the original code needed to generate the same expression
is significantly longer:
-----------------------------------------------------------------------------
g = gimple_build_assign_with_ops (NE_EXPR,
make_ssa_name (boolean_type_node,
NULL),
shadow,
build_int_cst (shadow_type, 0));
gimple_set_location (g, location);
gsi_insert_after (&gsi, g, GSI_NEW_STMT);
t = gimple_assign_lhs (g);
g = gimple_build_assign_with_ops (BIT_AND_EXPR,
make_ssa_name (uintptr_type,
NULL),
base_addr,
build_int_cst (uintptr_type, 7));
gimple_set_location (g, location);
gsi_insert_after (&gsi, g, GSI_NEW_STMT);
g = gimple_build_assign_with_ops (NOP_EXPR,
make_ssa_name (shadow_type,
NULL),
gimple_assign_lhs (g), NULL_TREE);
gimple_set_location (g, location);
gsi_insert_after (&gsi, g, GSI_NEW_STMT);
if (size_in_bytes > 1)
{
g = gimple_build_assign_with_ops (PLUS_EXPR,
make_ssa_name (shadow_type,
NULL),
gimple_assign_lhs (g),
build_int_cst (shadow_type,
size_in_bytes - 1));
gimple_set_location (g, location);
gsi_insert_after (&gsi, g, GSI_NEW_STMT);
}
g = gimple_build_assign_with_ops (GE_EXPR,
make_ssa_name (boolean_type_node,
NULL),
gimple_assign_lhs (g),
shadow);
gimple_set_location (g, location);
gsi_insert_after (&gsi, g, GSI_NEW_STMT);
g = gimple_build_assign_with_ops (BIT_AND_EXPR,
make_ssa_name (boolean_type_node,
NULL),
t, gimple_assign_lhs (g));
gimple_set_location (g, location);
gsi_insert_after (&gsi, g, GSI_NEW_STMT);
t = gimple_assign_lhs (g);
-----------------------------------------------------------------------------
I expect to add more facilities to the builder. Mainly, generation of
control flow altering statements which will automatically reflect on
the CFG.
I do not think the helper should replace all code generation, but it
should serve as a shorter/simpler way of generating GIMPLE IL in the
common cases.
Modified:
branches/cxx-conversion/gcc/asan.c
branches/cxx-conversion/gcc/gimple.c
branches/cxx-conversion/gcc/gimple.h
More information about the Gcc-cvs
mailing list