summaryrefslogtreecommitdiff
path: root/gcc/gimple-builder.c
diff options
context:
space:
mode:
authoramacleod <amacleod@138bc75d-0d04-0410-961f-82ee72b054a4>2013-09-26 13:23:31 +0000
committeramacleod <amacleod@138bc75d-0d04-0410-961f-82ee72b054a4>2013-09-26 13:23:31 +0000
commit9a4a334838250399f91cb29d193efeb869ead77e (patch)
tree0bdac19cc1c197b2e326293eb4c1344554b4e7b5 /gcc/gimple-builder.c
parent688425e8fb82effae7a31357f9166c0cf10dbd7d (diff)
downloadgcc-9a4a334838250399f91cb29d193efeb869ead77e.tar.gz
2013-09-26 Andrew MacLeod <amacleod@redhat.com>
* gimple.c (gimple_replace_lhs): Move to tree-ssa.c and rename. (struct count_ptr_d, count_ptr_derefs, count_uses_and_derefs): Move to tree-ssa.c (create_gimple_tmp): Delete. (get_expr_type, build_assign, build_type_cast): Move to... * gimple-builder.c: New File. (get_expr_type): Relocate from gimple.c. (build_assign, build_type_cast): Change to only create ssanames. * gimple.h: Move prototypes to... * gimple-builder.h: New File. Here. * tree-ssa.h: And here. * tree-ssa.c (struct count_ptr_d, count_ptr_derefs, count_uses_and_derefs): Relocate from gimple.c. (gimple_replace_ssa_lhs): Renamed gimple_replace_ssa from gimple.c * tree-ssa-reassoc.c (repropagate_negates): Use gimple_replace_ssa_lhs. * tree-ssa-math-opts (execute_cse_reciprocals): Use gimple_replace_ssa_lhs. * asan.c: Include gimple-builder.h. * Makefile.in: Add gimple-builder.o. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@202945 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/gimple-builder.c')
-rw-r--r--gcc/gimple-builder.c118
1 files changed, 118 insertions, 0 deletions
diff --git a/gcc/gimple-builder.c b/gcc/gimple-builder.c
new file mode 100644
index 00000000000..665c8020b93
--- /dev/null
+++ b/gcc/gimple-builder.c
@@ -0,0 +1,118 @@
+/* Functions for high level gimple building routines.
+ Copyright (C) 2013 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3. If not see
+<http://www.gnu.org/licenses/>. */
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tree.h"
+#include "gimple.h"
+#include "tree-ssa.h"
+
+
+/* Return the expression type to use based on the CODE and type of
+ the given operand OP. If the expression CODE is a comparison,
+ the returned type is boolean_type_node. Otherwise, it returns
+ the type of OP. */
+
+static tree
+get_expr_type (enum tree_code code, tree op)
+{
+ return (TREE_CODE_CLASS (code) == tcc_comparison)
+ ? boolean_type_node
+ : TREE_TYPE (op);
+}
+
+
+/* Build a new gimple assignment. The LHS of the assignment is a new
+ temporary whose type matches the given expression. MODE indicates
+ whether the LHS should be an SSA or a normal temporary. CODE is
+ the expression code for the RHS. OP1 is the first operand and VAL
+ is an integer value to be used as the second operand. */
+
+gimple
+build_assign (enum tree_code code, tree op1, int val, tree lhs)
+{
+ tree op2 = build_int_cst (TREE_TYPE (op1), val);
+ if (lhs == NULL_TREE)
+ lhs = make_ssa_name (get_expr_type (code, op1), NULL);
+ return gimple_build_assign_with_ops (code, lhs, op1, op2);
+}
+
+gimple
+build_assign (enum tree_code code, gimple g, int val, tree lhs )
+{
+ return build_assign (code, gimple_assign_lhs (g), val, lhs);
+}
+
+
+/* Build and return a new GIMPLE assignment. The new assignment will
+ have the opcode CODE and operands OP1 and OP2. The type of the
+ expression on the RHS is inferred to be the type of OP1.
+
+ The LHS of the statement will be an SSA name or a GIMPLE temporary
+ in normal form depending on the type of builder invoking this
+ function. */
+
+gimple
+build_assign (enum tree_code code, tree op1, tree op2, tree lhs)
+{
+ if (lhs == NULL_TREE)
+ lhs = make_ssa_name (get_expr_type (code, op1), NULL);
+ return gimple_build_assign_with_ops (code, lhs, op1, op2);
+}
+
+gimple
+build_assign (enum tree_code code, gimple op1, tree op2, tree lhs)
+{
+ return build_assign (code, gimple_assign_lhs (op1), op2, lhs);
+}
+
+gimple
+build_assign (enum tree_code code, tree op1, gimple op2, tree lhs)
+{
+ return build_assign (code, op1, gimple_assign_lhs (op2), lhs);
+}
+
+gimple
+build_assign (enum tree_code code, gimple op1, gimple op2, tree lhs)
+{
+ return build_assign (code, gimple_assign_lhs (op1), gimple_assign_lhs (op2),
+ lhs);
+}
+
+
+/* Create and return a type cast assignment. This creates a NOP_EXPR
+ that converts OP to TO_TYPE. */
+
+gimple
+build_type_cast (tree to_type, tree op, tree lhs)
+{
+ if (lhs == NULL_TREE)
+ lhs = make_ssa_name (to_type, NULL);
+ return gimple_build_assign_with_ops (NOP_EXPR, lhs, op, NULL_TREE);
+}
+
+gimple
+build_type_cast (tree to_type, gimple op, tree lhs)
+{
+ return build_type_cast (to_type, gimple_assign_lhs (op), lhs);
+}
+
+
+