Skip to content

Commit 475b8f3

Browse files
Diego NovilloDiego Novillo
authored andcommitted
Simplified GIMPLE IL builder functions.
* gimple.c (create_gimple_tmp): New. (get_expr_type): New. (build_assign): New. (build_type_cast): New. * gimple.h (enum ssa_mode): Define. (gimple_seq_set_location): New. * asan.c (build_check_stmt): Change some gimple_build_* calls to use build_assign and build_type_cast. From-SVN: r198056
1 parent 1395743 commit 475b8f3

File tree

4 files changed

+159
-51
lines changed

4 files changed

+159
-51
lines changed

gcc/ChangeLog

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
2013-04-18 Diego Novillo <[email protected]>
2+
3+
* gimple.c (create_gimple_tmp): New.
4+
(get_expr_type): New.
5+
(build_assign): New.
6+
(build_type_cast): New.
7+
* gimple.h (enum ssa_mode): Define.
8+
(gimple_seq_set_location): New.
9+
* asan.c (build_check_stmt): Change some gimple_build_* calls
10+
to use build_assign and build_type_cast.
11+
112
2013-04-18 Richard Biener <[email protected]>
213

314
* tree-vect-data-refs.c (vect_analyze_group_access): Properly

gcc/asan.c

Lines changed: 16 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,57 +1380,23 @@ build_check_stmt (location_t location, tree base, gimple_stmt_iterator *iter,
13801380
/* Slow path for 1, 2 and 4 byte accesses.
13811381
Test (shadow != 0)
13821382
& ((base_addr & 7) + (size_in_bytes - 1)) >= shadow). */
1383-
g = gimple_build_assign_with_ops (NE_EXPR,
1384-
make_ssa_name (boolean_type_node,
1385-
NULL),
1386-
shadow,
1387-
build_int_cst (shadow_type, 0));
1388-
gimple_set_location (g, location);
1389-
gsi_insert_after (&gsi, g, GSI_NEW_STMT);
1390-
t = gimple_assign_lhs (g);
1391-
1392-
g = gimple_build_assign_with_ops (BIT_AND_EXPR,
1393-
make_ssa_name (uintptr_type,
1394-
NULL),
1395-
base_addr,
1396-
build_int_cst (uintptr_type, 7));
1397-
gimple_set_location (g, location);
1398-
gsi_insert_after (&gsi, g, GSI_NEW_STMT);
1399-
1400-
g = gimple_build_assign_with_ops (NOP_EXPR,
1401-
make_ssa_name (shadow_type,
1402-
NULL),
1403-
gimple_assign_lhs (g), NULL_TREE);
1404-
gimple_set_location (g, location);
1405-
gsi_insert_after (&gsi, g, GSI_NEW_STMT);
1406-
1383+
gimple_seq seq = NULL;
1384+
gimple shadow_test = build_assign (NE_EXPR, shadow, 0);
1385+
gimple_seq_add_stmt (&seq, shadow_test);
1386+
gimple_seq_add_stmt (&seq, build_assign (BIT_AND_EXPR, base_addr, 7));
1387+
gimple_seq_add_stmt (&seq, build_type_cast (shadow_type,
1388+
gimple_seq_last (seq)));
14071389
if (size_in_bytes > 1)
1408-
{
1409-
g = gimple_build_assign_with_ops (PLUS_EXPR,
1410-
make_ssa_name (shadow_type,
1411-
NULL),
1412-
gimple_assign_lhs (g),
1413-
build_int_cst (shadow_type,
1414-
size_in_bytes - 1));
1415-
gimple_set_location (g, location);
1416-
gsi_insert_after (&gsi, g, GSI_NEW_STMT);
1417-
}
1418-
1419-
g = gimple_build_assign_with_ops (GE_EXPR,
1420-
make_ssa_name (boolean_type_node,
1421-
NULL),
1422-
gimple_assign_lhs (g),
1423-
shadow);
1424-
gimple_set_location (g, location);
1425-
gsi_insert_after (&gsi, g, GSI_NEW_STMT);
1426-
1427-
g = gimple_build_assign_with_ops (BIT_AND_EXPR,
1428-
make_ssa_name (boolean_type_node,
1429-
NULL),
1430-
t, gimple_assign_lhs (g));
1431-
gimple_set_location (g, location);
1432-
gsi_insert_after (&gsi, g, GSI_NEW_STMT);
1433-
t = gimple_assign_lhs (g);
1390+
gimple_seq_add_stmt (&seq,
1391+
build_assign (PLUS_EXPR, gimple_seq_last (seq),
1392+
size_in_bytes - 1));
1393+
gimple_seq_add_stmt (&seq, build_assign (GE_EXPR, gimple_seq_last (seq),
1394+
shadow));
1395+
gimple_seq_add_stmt (&seq, build_assign (BIT_AND_EXPR, shadow_test,
1396+
gimple_seq_last (seq)));
1397+
t = gimple_assign_lhs (gimple_seq_last (seq));
1398+
gimple_seq_set_location (seq, location);
1399+
gsi_insert_seq_after (&gsi, seq, GSI_CONTINUE_LINKING);
14341400
}
14351401
else
14361402
t = shadow;

gcc/gimple.c

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4207,4 +4207,105 @@ gimple_asm_clobbers_memory_p (const_gimple stmt)
42074207

42084208
return false;
42094209
}
4210+
4211+
4212+
/* Create and return an unnamed temporary. MODE indicates whether
4213+
this should be an SSA or NORMAL temporary. TYPE is the type to use
4214+
for the new temporary. */
4215+
4216+
tree
4217+
create_gimple_tmp (tree type, enum ssa_mode mode)
4218+
{
4219+
return (mode == M_SSA)
4220+
? make_ssa_name (type, NULL)
4221+
: create_tmp_var (type, NULL);
4222+
}
4223+
4224+
4225+
/* Return the expression type to use based on the CODE and type of
4226+
the given operand OP. If the expression CODE is a comparison,
4227+
the returned type is boolean_type_node. Otherwise, it returns
4228+
the type of OP. */
4229+
4230+
static tree
4231+
get_expr_type (enum tree_code code, tree op)
4232+
{
4233+
return (TREE_CODE_CLASS (code) == tcc_comparison)
4234+
? boolean_type_node
4235+
: TREE_TYPE (op);
4236+
}
4237+
4238+
4239+
/* Build a new gimple assignment. The LHS of the assignment is a new
4240+
temporary whose type matches the given expression. MODE indicates
4241+
whether the LHS should be an SSA or a normal temporary. CODE is
4242+
the expression code for the RHS. OP1 is the first operand and VAL
4243+
is an integer value to be used as the second operand. */
4244+
4245+
gimple
4246+
build_assign (enum tree_code code, tree op1, int val, enum ssa_mode mode)
4247+
{
4248+
tree op2 = build_int_cst (TREE_TYPE (op1), val);
4249+
tree lhs = create_gimple_tmp (get_expr_type (code, op1), mode);
4250+
return gimple_build_assign_with_ops (code, lhs, op1, op2);
4251+
}
4252+
4253+
gimple
4254+
build_assign (enum tree_code code, gimple g, int val, enum ssa_mode mode)
4255+
{
4256+
return build_assign (code, gimple_assign_lhs (g), val, mode);
4257+
}
4258+
4259+
4260+
/* Build and return a new GIMPLE assignment. The new assignment will
4261+
have the opcode CODE and operands OP1 and OP2. The type of the
4262+
expression on the RHS is inferred to be the type of OP1.
4263+
4264+
The LHS of the statement will be an SSA name or a GIMPLE temporary
4265+
in normal form depending on the type of builder invoking this
4266+
function. */
4267+
4268+
gimple
4269+
build_assign (enum tree_code code, tree op1, tree op2, enum ssa_mode mode)
4270+
{
4271+
tree lhs = create_gimple_tmp (get_expr_type (code, op1), mode);
4272+
return gimple_build_assign_with_ops (code, lhs, op1, op2);
4273+
}
4274+
4275+
gimple
4276+
build_assign (enum tree_code code, gimple op1, tree op2, enum ssa_mode mode)
4277+
{
4278+
return build_assign (code, gimple_assign_lhs (op1), op2, mode);
4279+
}
4280+
4281+
gimple
4282+
build_assign (enum tree_code code, tree op1, gimple op2, enum ssa_mode mode)
4283+
{
4284+
return build_assign (code, op1, gimple_assign_lhs (op2), mode);
4285+
}
4286+
4287+
gimple
4288+
build_assign (enum tree_code code, gimple op1, gimple op2, enum ssa_mode mode)
4289+
{
4290+
return build_assign (code, gimple_assign_lhs (op1), gimple_assign_lhs (op2),
4291+
mode);
4292+
}
4293+
4294+
4295+
/* Create and return a type cast assignment. This creates a NOP_EXPR
4296+
that converts OP to TO_TYPE. */
4297+
4298+
gimple
4299+
build_type_cast (tree to_type, tree op, enum ssa_mode mode)
4300+
{
4301+
tree lhs = create_gimple_tmp (to_type, mode);
4302+
return gimple_build_assign_with_ops (NOP_EXPR, lhs, op, NULL_TREE);
4303+
}
4304+
4305+
gimple
4306+
build_type_cast (tree to_type, gimple op, enum ssa_mode mode)
4307+
{
4308+
return build_type_cast (to_type, gimple_assign_lhs (op), mode);
4309+
}
4310+
42104311
#include "gt-gimple.h"

gcc/gimple.h

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ along with GCC; see the file COPYING3. If not see
3333

3434
typedef gimple gimple_seq_node;
3535

36+
/* Types of supported temporaries. GIMPLE temporaries may be symbols
37+
in normal form (i.e., regular decls) or SSA names. This enum is
38+
used by create_gimple_tmp to tell it what kind of temporary the
39+
caller wants. */
40+
enum ssa_mode {
41+
M_SSA = 0,
42+
M_NORMAL
43+
};
44+
3645
/* For each block, the PHI nodes that need to be rewritten are stored into
3746
these vectors. */
3847
typedef vec<gimple> gimple_vec;
@@ -720,6 +729,17 @@ union GTY ((desc ("gimple_statement_structure (&%h)"),
720729

721730
/* In gimple.c. */
722731

732+
/* Helper functions to build GIMPLE statements. */
733+
tree create_gimple_tmp (tree, enum ssa_mode = M_SSA);
734+
gimple build_assign (enum tree_code, tree, int, enum ssa_mode = M_SSA);
735+
gimple build_assign (enum tree_code, gimple, int, enum ssa_mode = M_SSA);
736+
gimple build_assign (enum tree_code, tree, tree, enum ssa_mode = M_SSA);
737+
gimple build_assign (enum tree_code, gimple, tree, enum ssa_mode = M_SSA);
738+
gimple build_assign (enum tree_code, tree, gimple, enum ssa_mode = M_SSA);
739+
gimple build_assign (enum tree_code, gimple, gimple, enum ssa_mode = M_SSA);
740+
gimple build_type_cast (tree, tree, enum ssa_mode = M_SSA);
741+
gimple build_type_cast (tree, gimple, enum ssa_mode = M_SSA);
742+
723743
/* Offset in bytes to the location of the operand vector.
724744
Zero if there is no operand vector for this tuple structure. */
725745
extern size_t const gimple_ops_offset_[];
@@ -1096,7 +1116,6 @@ gimple_seq_empty_p (gimple_seq s)
10961116
return s == NULL;
10971117
}
10981118

1099-
11001119
void gimple_seq_add_stmt (gimple_seq *, gimple);
11011120

11021121
/* Link gimple statement GS to the end of the sequence *SEQ_P. If
@@ -5326,4 +5345,15 @@ extern tree maybe_fold_or_comparisons (enum tree_code, tree, tree,
53265345
enum tree_code, tree, tree);
53275346

53285347
bool gimple_val_nonnegative_real_p (tree);
5348+
5349+
5350+
/* Set the location of all statements in SEQ to LOC. */
5351+
5352+
static inline void
5353+
gimple_seq_set_location (gimple_seq seq, location_t loc)
5354+
{
5355+
for (gimple_stmt_iterator i = gsi_start (seq); !gsi_end_p (i); gsi_next (&i))
5356+
gimple_set_location (gsi_stmt (i), loc);
5357+
}
5358+
53295359
#endif /* GCC_GIMPLE_H */

0 commit comments

Comments
 (0)