diff options
author | dnovillo <dnovillo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2013-03-13 21:57:30 +0000 |
---|---|---|
committer | dnovillo <dnovillo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2013-03-13 21:57:30 +0000 |
commit | 9402409a6bd0d7d1f7358793f768bda3ec8a9574 (patch) | |
tree | 6a44fa653c7803af6421b09fdf6a5d4c30a9f1e9 /gcc/fortran/invoke.texi | |
parent | 580a987ea50fb573468c9e064d00f346f2536e59 (diff) | |
download | gcc-9402409a6bd0d7d1f7358793f768bda3ec8a9574.tar.gz |
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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/cxx-conversion@196640 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/fortran/invoke.texi')
0 files changed, 0 insertions, 0 deletions