* gimple.h: Remove all includes. (recalculate_side_effects): Move prototype to gimplify.h. * Makefile.in (PLUGIN_HEADERS): Add flattened gimple.h includes. * gengtype.c (open_base_files): Add gimple.h include list. * gimplify.h (recalculate_side_effects): Relocate prototype here. * gimple.c: Adjust include list. (recalculate_side_effects): Move to gimplify.c. * gimplify.c: Adjust include list. (recalculate_side_effects): Relocate from gimple.c. * alias.c: Add required include files removed from gimple.h. * asan.c: Likewise. * builtins.c: Likewise. * calls.c: Likewise. * cfgexpand.c: Likewise. * cfgloop.c: Likewise. * cfgloopmanip.c: Likewise. * cgraphbuild.c: Likewise. * cgraph.c: Likewise. * cgraphclones.c: Likewise. * cgraphunit.c: Likewise. * cilk-common.c: Likewise. * data-streamer.c: Likewise. * data-streamer-in.c: Likewise. * data-streamer-out.c: Likewise. * dse.c: Likewise. * dwarf2out.c: Likewise. * emit-rtl.c: Likewise. * except.c: Likewise. * expr.c: Likewise. * fold-const.c: Likewise. * function.c: Likewise. * gimple-builder.c: Likewise. * gimple-expr.c: Likewise. * gimple-fold.c: Likewise. * gimple-iterator.c: Likewise. * gimple-low.c: Likewise. * gimple-pretty-print.c: Likewise. * gimple-ssa-isolate-paths.c: Likewise. * gimple-ssa-strength-reduction.c: Likewise. * gimple-streamer-in.c: Likewise. * gimple-streamer-out.c: Likewise. * gimple-walk.c: Likewise. * gimplify-me.c: Likewise. * graphite-blocking.c: Likewise. * graphite.c: Likewise. * graphite-clast-to-gimple.c: Likewise. * graphite-dependences.c: Likewise. * graphite-interchange.c: Likewise. * graphite-optimize-isl.c: Likewise. * graphite-poly.c: Likewise. * graphite-scop-detection.c: Likewise. * graphite-sese-to-poly.c: Likewise. * internal-fn.c: Likewise. * ipa.c: Likewise. * ipa-cp.c: Likewise. * ipa-devirt.c: Likewise. * ipa-inline-analysis.c: Likewise. * ipa-inline.c: Likewise. * ipa-profile.c: Likewise. * ipa-prop.c: Likewise. * ipa-pure-const.c: Likewise. * ipa-reference.c: Likewise. * ipa-split.c: Likewise. * ipa-utils.c: Likewise. * langhooks.c: Likewise. * lto-cgraph.c: Likewise. * lto-compress.c: Likewise. * lto-opts.c: Likewise. * lto-section-in.c: Likewise. * lto-section-out.c: Likewise. * lto-streamer.c: Likewise. * lto-streamer-in.c: Likewise. * lto-streamer-out.c: Likewise. * omp-low.c: Likewise. * opts-global.c: Likewise. * passes.c: Likewise. * predict.c: Likewise. * profile.c: Likewise. * sese.c: Likewise. * stmt.c: Likewise. * stor-layout.c: Likewise. * symtab.c: Likewise. * targhooks.c: Likewise. * toplev.c: Likewise. * tracer.c: Likewise. * trans-mem.c: Likewise. * tree-affine.c: Likewise. * tree.c: Likewise. * tree-call-cdce.c: Likewise. * tree-cfg.c: Likewise. * tree-cfgcleanup.c: Likewise. * tree-chrec.c: Likewise. * tree-complex.c: Likewise. * tree-data-ref.c: Likewise. * tree-dfa.c: Likewise. * tree-eh.c: Likewise. * tree-emutls.c: Likewise. * tree-if-conv.c: Likewise. * tree-inline.c: Likewise. * tree-into-ssa.c: Likewise. * tree-loop-distribution.c: Likewise. * tree-nested.c: Likewise. * tree-nrv.c: Likewise. * tree-object-size.c: Likewise. * tree-outof-ssa.c: Likewise. * tree-parloops.c: Likewise. * tree-phinodes.c: Likewise. * tree-predcom.c: Likewise. * tree-pretty-print.c: Likewise. * tree-profile.c: Likewise. * tree-scalar-evolution.c: Likewise. * tree-sra.c: Likewise. * tree-ssa-address.c: Likewise. * tree-ssa-alias.c: Likewise. * tree-ssa.c: Likewise. * tree-ssa-ccp.c: Likewise. * tree-ssa-coalesce.c: Likewise. * tree-ssa-copy.c: Likewise. * tree-ssa-copyrename.c: Likewise. * tree-ssa-dce.c: Likewise. * tree-ssa-dom.c: Likewise. * tree-ssa-dse.c: Likewise. * tree-ssa-forwprop.c: Likewise. * tree-ssa-ifcombine.c: Likewise. * tree-ssa-live.c: Likewise. * tree-ssa-loop.c: Likewise. * tree-ssa-loop-ch.c: Likewise. * tree-ssa-loop-im.c: Likewise. * tree-ssa-loop-ivcanon.c: Likewise. * tree-ssa-loop-ivopts.c: Likewise. * tree-ssa-loop-manip.c: Likewise. * tree-ssa-loop-niter.c: Likewise. * tree-ssa-loop-prefetch.c: Likewise. * tree-ssa-loop-unswitch.c: Likewise. * tree-ssa-math-opts.c: Likewise. * tree-ssanames.c: Likewise. * tree-ssa-operands.c: Likewise. * tree-ssa-phiopt.c: Likewise. * tree-ssa-phiprop.c: Likewise. * tree-ssa-pre.c: Likewise. * tree-ssa-propagate.c: Likewise. * tree-ssa-reassoc.c: Likewise. * tree-ssa-sccvn.c: Likewise. * tree-ssa-sink.c: Likewise. * tree-ssa-strlen.c: Likewise. * tree-ssa-structalias.c: Likewise. * tree-ssa-tail-merge.c: Likewise. * tree-ssa-ter.c: Likewise. * tree-ssa-threadedge.c: Likewise. * tree-ssa-threadupdate.c: Likewise. * tree-ssa-uncprop.c: Likewise. * tree-ssa-uninit.c: Likewise. * tree-stdarg.c: Likewise. * tree-streamer.c: Likewise. * tree-streamer-in.c: Likewise. * tree-streamer-out.c: Likewise. * tree-switch-conversion.c: Likewise. * tree-tailcall.c: Likewise. * tree-vect-data-refs.c: Likewise. * tree-vect-generic.c: Likewise. * tree-vect-loop.c: Likewise. * tree-vect-loop-manip.c: Likewise. * tree-vectorizer.c: Likewise. * tree-vect-patterns.c: Likewise. * tree-vect-slp.c: Likewise. * tree-vect-stmts.c: Likewise. * tree-vrp.c: Likewise. * tsan.c: Likewise. * ubsan.c: Likewise. * value-prof.c: Likewise. * varpool.c: Likewise. * var-tracking.c: Likewise. * vtable-verify.c: Likewise. * ada/gcc-interface/trans.c: Add required include files from gimple.h. * c/c-typeck.c: Add required include files from gimple.h. * c-family/c-common.c: Add required include files from gimple.h. * c-family/c-gimplify.c: Likewise * c-family/cilk.c: Likewise * cp/class.c: Add required include files from gimple.h. * cp/cp-gimplify.c: Likewise * cp/decl2.c: Likewise * cp/init.c: Likewise * cp/optimize.c: Likewise * cp/pt.c: Likewise * cp/semantics.c: Likewise * cp/tree.c: Likewise * cp/typeck.c: Likewise * cp/vtable-class-hierarchy.c: Likewise * fortran/trans.c: Add required include files from gimple.h. * fortran/trans-expr.c: Likewise * fortran/trans-openmp.c: Likewise * go/gofrontend/expressions.cc: Add required include files from gimple.h. * go/gofrontend/gogo-tree.cc: Likewise * go/gofrontend/types.cc: Likewise * go/go-gcc.cc: Likewise * go/go-lang.c: Likewise * java/java-gimplify.c: Add required include files from gimple.h. * lto/lto.c: Add required include files from gimple.h. * lto/lto-lang.c: Likewise * lto/lto-object.c: Likewise * lto/lto-partition.c: Likewise * lto/lto-symtab.c: Likewise * objc/objc-act.c: Add required include files from gimple.h. * config/darwin.c: Add required include files removed from gimple.h. * config/aarch64/aarch64-builtins.c: Likewise. * config/aarch64/aarch64.c: Likewise. * config/alpha/alpha.c: Likewise. * config/i386/i386.c: Likewise. * config/i386/winnt.c: Likewise. * config/ia64/ia64.c: Likewise. * config/m32c/m32c.c: Likewise. * config/mep/mep.c: Likewise. * config/mips/mips.c: Likewise. * config/rs6000/rs6000.c: Likewise. * config/s390/s390.c: Likewise. * config/sh/sh.c: Likewise. * config/sparc/sparc.c: Likewise. * config/spu/spu.c: Likewise. * config/stormy16/stormy16.c: Likewise. * config/tilegx/tilegx.c: Likewise. * config/tilepro/tilepro.c: Likewise. * config/xtensa/xtensa.c: Likewise. * testsuite/gcc.dg/plugin/finish_unit_plugin.c: Add required include files removed from gimple.h. * testsuite/gcc.dg/plugin/ggcplug.c: Likewise. * testsuite/gcc.dg/plugin/one_time_plugin.c: Likewise. * testsuite/gcc.dg/plugin/selfassign.c: Likewise. * testsuite/gcc.dg/plugin/start_unit_plugin.c: Likewise. * testsuite/g++.dg/plugin/selfassign.c: Likewise. From-SVN: r205272
321 lines
9.7 KiB
C
321 lines
9.7 KiB
C
/* Tree lowering to gimple for middle end use only.
|
|
This converts the GENERIC functions-as-trees tree representation into
|
|
the GIMPLE form.
|
|
Copyright (C) 2013 Free Software Foundation, Inc.
|
|
Major work done by Sebastian Pop <s.pop@laposte.net>,
|
|
Diego Novillo <dnovillo@redhat.com> and Jason Merrill <jason@redhat.com>.
|
|
|
|
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 "stmt.h"
|
|
#include "stor-layout.h"
|
|
#include "basic-block.h"
|
|
#include "tree-ssa-alias.h"
|
|
#include "internal-fn.h"
|
|
#include "tree-eh.h"
|
|
#include "gimple-expr.h"
|
|
#include "is-a.h"
|
|
#include "gimple.h"
|
|
#include "gimple-iterator.h"
|
|
#include "gimplify.h"
|
|
#include "gimplify-me.h"
|
|
#include "gimple-ssa.h"
|
|
#include "stringpool.h"
|
|
#include "tree-ssanames.h"
|
|
|
|
|
|
/* Expand EXPR to list of gimple statements STMTS. GIMPLE_TEST_F specifies
|
|
the predicate that will hold for the result. If VAR is not NULL, make the
|
|
base variable of the final destination be VAR if suitable. */
|
|
|
|
tree
|
|
force_gimple_operand_1 (tree expr, gimple_seq *stmts,
|
|
gimple_predicate gimple_test_f, tree var)
|
|
{
|
|
enum gimplify_status ret;
|
|
location_t saved_location;
|
|
|
|
*stmts = NULL;
|
|
|
|
/* gimple_test_f might be more strict than is_gimple_val, make
|
|
sure we pass both. Just checking gimple_test_f doesn't work
|
|
because most gimple predicates do not work recursively. */
|
|
if (is_gimple_val (expr)
|
|
&& (*gimple_test_f) (expr))
|
|
return expr;
|
|
|
|
push_gimplify_context (gimple_in_ssa_p (cfun), true);
|
|
saved_location = input_location;
|
|
input_location = UNKNOWN_LOCATION;
|
|
|
|
if (var)
|
|
{
|
|
if (gimple_in_ssa_p (cfun) && is_gimple_reg (var))
|
|
var = make_ssa_name (var, NULL);
|
|
expr = build2 (MODIFY_EXPR, TREE_TYPE (var), var, expr);
|
|
}
|
|
|
|
if (TREE_CODE (expr) != MODIFY_EXPR
|
|
&& TREE_TYPE (expr) == void_type_node)
|
|
{
|
|
gimplify_and_add (expr, stmts);
|
|
expr = NULL_TREE;
|
|
}
|
|
else
|
|
{
|
|
ret = gimplify_expr (&expr, stmts, NULL, gimple_test_f, fb_rvalue);
|
|
gcc_assert (ret != GS_ERROR);
|
|
}
|
|
|
|
input_location = saved_location;
|
|
pop_gimplify_context (NULL);
|
|
|
|
return expr;
|
|
}
|
|
|
|
/* Expand EXPR to list of gimple statements STMTS. If SIMPLE is true,
|
|
force the result to be either ssa_name or an invariant, otherwise
|
|
just force it to be a rhs expression. If VAR is not NULL, make the
|
|
base variable of the final destination be VAR if suitable. */
|
|
|
|
tree
|
|
force_gimple_operand (tree expr, gimple_seq *stmts, bool simple, tree var)
|
|
{
|
|
return force_gimple_operand_1 (expr, stmts,
|
|
simple ? is_gimple_val : is_gimple_reg_rhs,
|
|
var);
|
|
}
|
|
|
|
/* Invoke force_gimple_operand_1 for EXPR with parameters GIMPLE_TEST_F
|
|
and VAR. If some statements are produced, emits them at GSI.
|
|
If BEFORE is true. the statements are appended before GSI, otherwise
|
|
they are appended after it. M specifies the way GSI moves after
|
|
insertion (GSI_SAME_STMT or GSI_CONTINUE_LINKING are the usual values). */
|
|
|
|
tree
|
|
force_gimple_operand_gsi_1 (gimple_stmt_iterator *gsi, tree expr,
|
|
gimple_predicate gimple_test_f,
|
|
tree var, bool before,
|
|
enum gsi_iterator_update m)
|
|
{
|
|
gimple_seq stmts;
|
|
|
|
expr = force_gimple_operand_1 (expr, &stmts, gimple_test_f, var);
|
|
|
|
if (!gimple_seq_empty_p (stmts))
|
|
{
|
|
if (before)
|
|
gsi_insert_seq_before (gsi, stmts, m);
|
|
else
|
|
gsi_insert_seq_after (gsi, stmts, m);
|
|
}
|
|
|
|
return expr;
|
|
}
|
|
|
|
/* Invoke force_gimple_operand_1 for EXPR with parameter VAR.
|
|
If SIMPLE is true, force the result to be either ssa_name or an invariant,
|
|
otherwise just force it to be a rhs expression. If some statements are
|
|
produced, emits them at GSI. If BEFORE is true, the statements are
|
|
appended before GSI, otherwise they are appended after it. M specifies
|
|
the way GSI moves after insertion (GSI_SAME_STMT or GSI_CONTINUE_LINKING
|
|
are the usual values). */
|
|
|
|
tree
|
|
force_gimple_operand_gsi (gimple_stmt_iterator *gsi, tree expr,
|
|
bool simple_p, tree var, bool before,
|
|
enum gsi_iterator_update m)
|
|
{
|
|
return force_gimple_operand_gsi_1 (gsi, expr,
|
|
simple_p
|
|
? is_gimple_val : is_gimple_reg_rhs,
|
|
var, before, m);
|
|
}
|
|
|
|
/* Some transformations like inlining may invalidate the GIMPLE form
|
|
for operands. This function traverses all the operands in STMT and
|
|
gimplifies anything that is not a valid gimple operand. Any new
|
|
GIMPLE statements are inserted before *GSI_P. */
|
|
|
|
void
|
|
gimple_regimplify_operands (gimple stmt, gimple_stmt_iterator *gsi_p)
|
|
{
|
|
size_t i, num_ops;
|
|
tree lhs;
|
|
gimple_seq pre = NULL;
|
|
gimple post_stmt = NULL;
|
|
|
|
push_gimplify_context (gimple_in_ssa_p (cfun));
|
|
|
|
switch (gimple_code (stmt))
|
|
{
|
|
case GIMPLE_COND:
|
|
gimplify_expr (gimple_cond_lhs_ptr (stmt), &pre, NULL,
|
|
is_gimple_val, fb_rvalue);
|
|
gimplify_expr (gimple_cond_rhs_ptr (stmt), &pre, NULL,
|
|
is_gimple_val, fb_rvalue);
|
|
break;
|
|
case GIMPLE_SWITCH:
|
|
gimplify_expr (gimple_switch_index_ptr (stmt), &pre, NULL,
|
|
is_gimple_val, fb_rvalue);
|
|
break;
|
|
case GIMPLE_OMP_ATOMIC_LOAD:
|
|
gimplify_expr (gimple_omp_atomic_load_rhs_ptr (stmt), &pre, NULL,
|
|
is_gimple_val, fb_rvalue);
|
|
break;
|
|
case GIMPLE_ASM:
|
|
{
|
|
size_t i, noutputs = gimple_asm_noutputs (stmt);
|
|
const char *constraint, **oconstraints;
|
|
bool allows_mem, allows_reg, is_inout;
|
|
|
|
oconstraints
|
|
= (const char **) alloca ((noutputs) * sizeof (const char *));
|
|
for (i = 0; i < noutputs; i++)
|
|
{
|
|
tree op = gimple_asm_output_op (stmt, i);
|
|
constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op)));
|
|
oconstraints[i] = constraint;
|
|
parse_output_constraint (&constraint, i, 0, 0, &allows_mem,
|
|
&allows_reg, &is_inout);
|
|
gimplify_expr (&TREE_VALUE (op), &pre, NULL,
|
|
is_inout ? is_gimple_min_lval : is_gimple_lvalue,
|
|
fb_lvalue | fb_mayfail);
|
|
}
|
|
for (i = 0; i < gimple_asm_ninputs (stmt); i++)
|
|
{
|
|
tree op = gimple_asm_input_op (stmt, i);
|
|
constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op)));
|
|
parse_input_constraint (&constraint, 0, 0, noutputs, 0,
|
|
oconstraints, &allows_mem, &allows_reg);
|
|
if (TREE_ADDRESSABLE (TREE_TYPE (TREE_VALUE (op))) && allows_mem)
|
|
allows_reg = 0;
|
|
if (!allows_reg && allows_mem)
|
|
gimplify_expr (&TREE_VALUE (op), &pre, NULL,
|
|
is_gimple_lvalue, fb_lvalue | fb_mayfail);
|
|
else
|
|
gimplify_expr (&TREE_VALUE (op), &pre, NULL,
|
|
is_gimple_asm_val, fb_rvalue);
|
|
}
|
|
}
|
|
break;
|
|
default:
|
|
/* NOTE: We start gimplifying operands from last to first to
|
|
make sure that side-effects on the RHS of calls, assignments
|
|
and ASMs are executed before the LHS. The ordering is not
|
|
important for other statements. */
|
|
num_ops = gimple_num_ops (stmt);
|
|
for (i = num_ops; i > 0; i--)
|
|
{
|
|
tree op = gimple_op (stmt, i - 1);
|
|
if (op == NULL_TREE)
|
|
continue;
|
|
if (i == 1 && (is_gimple_call (stmt) || is_gimple_assign (stmt)))
|
|
gimplify_expr (&op, &pre, NULL, is_gimple_lvalue, fb_lvalue);
|
|
else if (i == 2
|
|
&& is_gimple_assign (stmt)
|
|
&& num_ops == 2
|
|
&& get_gimple_rhs_class (gimple_expr_code (stmt))
|
|
== GIMPLE_SINGLE_RHS)
|
|
gimplify_expr (&op, &pre, NULL,
|
|
rhs_predicate_for (gimple_assign_lhs (stmt)),
|
|
fb_rvalue);
|
|
else if (i == 2 && is_gimple_call (stmt))
|
|
{
|
|
if (TREE_CODE (op) == FUNCTION_DECL)
|
|
continue;
|
|
gimplify_expr (&op, &pre, NULL, is_gimple_call_addr, fb_rvalue);
|
|
}
|
|
else
|
|
gimplify_expr (&op, &pre, NULL, is_gimple_val, fb_rvalue);
|
|
gimple_set_op (stmt, i - 1, op);
|
|
}
|
|
|
|
lhs = gimple_get_lhs (stmt);
|
|
/* If the LHS changed it in a way that requires a simple RHS,
|
|
create temporary. */
|
|
if (lhs && !is_gimple_reg (lhs))
|
|
{
|
|
bool need_temp = false;
|
|
|
|
if (is_gimple_assign (stmt)
|
|
&& num_ops == 2
|
|
&& get_gimple_rhs_class (gimple_expr_code (stmt))
|
|
== GIMPLE_SINGLE_RHS)
|
|
gimplify_expr (gimple_assign_rhs1_ptr (stmt), &pre, NULL,
|
|
rhs_predicate_for (gimple_assign_lhs (stmt)),
|
|
fb_rvalue);
|
|
else if (is_gimple_reg (lhs))
|
|
{
|
|
if (is_gimple_reg_type (TREE_TYPE (lhs)))
|
|
{
|
|
if (is_gimple_call (stmt))
|
|
{
|
|
i = gimple_call_flags (stmt);
|
|
if ((i & ECF_LOOPING_CONST_OR_PURE)
|
|
|| !(i & (ECF_CONST | ECF_PURE)))
|
|
need_temp = true;
|
|
}
|
|
if (stmt_can_throw_internal (stmt))
|
|
need_temp = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (is_gimple_reg_type (TREE_TYPE (lhs)))
|
|
need_temp = true;
|
|
else if (TYPE_MODE (TREE_TYPE (lhs)) != BLKmode)
|
|
{
|
|
if (is_gimple_call (stmt))
|
|
{
|
|
tree fndecl = gimple_call_fndecl (stmt);
|
|
|
|
if (!aggregate_value_p (TREE_TYPE (lhs), fndecl)
|
|
&& !(fndecl && DECL_RESULT (fndecl)
|
|
&& DECL_BY_REFERENCE (DECL_RESULT (fndecl))))
|
|
need_temp = true;
|
|
}
|
|
else
|
|
need_temp = true;
|
|
}
|
|
}
|
|
if (need_temp)
|
|
{
|
|
tree temp = create_tmp_reg (TREE_TYPE (lhs), NULL);
|
|
if (gimple_in_ssa_p (cfun))
|
|
temp = make_ssa_name (temp, NULL);
|
|
gimple_set_lhs (stmt, temp);
|
|
post_stmt = gimple_build_assign (lhs, temp);
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
|
|
if (!gimple_seq_empty_p (pre))
|
|
gsi_insert_seq_before (gsi_p, pre, GSI_SAME_STMT);
|
|
if (post_stmt)
|
|
gsi_insert_after (gsi_p, post_stmt, GSI_NEW_STMT);
|
|
|
|
pop_gimplify_context (NULL);
|
|
}
|
|
|
|
|